| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * @brief pings, a plugin for Dotclear 2 |
|---|
| 4 | * |
|---|
| 5 | * @package Dotclear |
|---|
| 6 | * @subpackage Plugins |
|---|
| 7 | * |
|---|
| 8 | * @copyright Olivier Meunier & Association Dotclear |
|---|
| 9 | * @copyright GPL-2.0-only |
|---|
| 10 | */ |
|---|
| 11 | |
|---|
| 12 | if (!defined('DC_RC_PATH')) {return;} |
|---|
| 13 | |
|---|
| 14 | class pingsAPI extends xmlrpcClient |
|---|
| 15 | { |
|---|
| 16 | public static function doPings($srv_uri, $site_name, $site_url) |
|---|
| 17 | { |
|---|
| 18 | $o = new self($srv_uri); |
|---|
| 19 | $o->timeout = 3; |
|---|
| 20 | |
|---|
| 21 | $rsp = $o->query('weblogUpdates.ping', $site_name, $site_url); |
|---|
| 22 | |
|---|
| 23 | if (isset($rsp['flerror']) && $rsp['flerror']) { |
|---|
| 24 | throw new Exception($rsp['message']); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | return true; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | class pingsAdminBehaviors |
|---|
| 32 | { |
|---|
| 33 | public static function pingJS() |
|---|
| 34 | { |
|---|
| 35 | global $core; |
|---|
| 36 | |
|---|
| 37 | $res = |
|---|
| 38 | "<script type=\"text/javascript\">\n" . |
|---|
| 39 | dcPage::jsVar('dotclear.msg.check_all', __('Check all')) . "\n" . |
|---|
| 40 | "</script>\n" . |
|---|
| 41 | dcPage::jsLoad(dcPage::getPF('pings/js/post.js')); |
|---|
| 42 | |
|---|
| 43 | return $res; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public static function pingsFormItems($main, $sidebar, $post) |
|---|
| 47 | { |
|---|
| 48 | $core = &$GLOBALS['core']; |
|---|
| 49 | if (!$core->blog->settings->pings->pings_active) { |
|---|
| 50 | return; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | $pings_uris = $core->blog->settings->pings->pings_uris; |
|---|
| 54 | if (empty($pings_uris) || !is_array($pings_uris)) { |
|---|
| 55 | return; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (!empty($_POST['pings_do']) && is_array($_POST['pings_do'])) { |
|---|
| 59 | $pings_do = $_POST['pings_do']; |
|---|
| 60 | } else { |
|---|
| 61 | $pings_do = array(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | $item = '<h5 class="ping-services">' . __('Pings') . '</h5>'; |
|---|
| 65 | $i = 0; |
|---|
| 66 | foreach ($pings_uris as $k => $v) { |
|---|
| 67 | $item .= |
|---|
| 68 | '<p class="ping-services"><label for="pings_do-' . $i . '" class="classic">' . |
|---|
| 69 | form::checkbox(array('pings_do[]', 'pings_do-' . $i), html::escapeHTML($v), in_array($v, $pings_do), 'check-ping-services') . ' ' . |
|---|
| 70 | html::escapeHTML($k) . '</label></p>'; |
|---|
| 71 | $i++; |
|---|
| 72 | } |
|---|
| 73 | $sidebar['options-box']['items']['pings'] = $item; |
|---|
| 74 | |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | public static function doPings($cur, $post_id) |
|---|
| 78 | { |
|---|
| 79 | if (empty($_POST['pings_do']) || !is_array($_POST['pings_do'])) { |
|---|
| 80 | return; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | $core = &$GLOBALS['core']; |
|---|
| 84 | if (!$core->blog->settings->pings->pings_active) { |
|---|
| 85 | return; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | $pings_uris = $core->blog->settings->pings->pings_uris; |
|---|
| 89 | if (empty($pings_uris) || !is_array($pings_uris)) { |
|---|
| 90 | return; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | foreach ($_POST['pings_do'] as $uri) { |
|---|
| 94 | if (in_array($uri, $pings_uris)) { |
|---|
| 95 | try { |
|---|
| 96 | pingsAPI::doPings($uri, $core->blog->name, $core->blog->url); |
|---|
| 97 | } catch (Exception $e) {} |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | class pingsCoreBehaviour |
|---|
| 104 | { |
|---|
| 105 | public static function doPings($blog, $ids) |
|---|
| 106 | { |
|---|
| 107 | if (!$blog->settings->pings->pings_active) { |
|---|
| 108 | return; |
|---|
| 109 | } |
|---|
| 110 | if (!$blog->settings->pings->pings_auto) { |
|---|
| 111 | return; |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | $pings_uris = $blog->settings->pings->pings_uris; |
|---|
| 115 | if (empty($pings_uris) || !is_array($pings_uris)) { |
|---|
| 116 | return; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | foreach ($pings_uris as $uri) { |
|---|
| 120 | try { |
|---|
| 121 | pingsAPI::doPings($uri, $blog->name, $blog->url); |
|---|
| 122 | } catch (Exception $e) {} |
|---|
| 123 | } |
|---|
| 124 | } |
|---|
| 125 | } |
|---|