3 global $DIR_PLUGINS, $DIR_LIBS;
4 if (version_compare(phpversion(), "5.0.1", ">=")) {
5 require_once($DIR_PLUGINS . "updatepingserver/xmlrpc.inc");
6 require_once($DIR_PLUGINS . "updatepingserver/xmlrpcs.inc");
8 include_once($DIR_LIBS . "xmlrpc.inc.php");
9 include_once($DIR_LIBS . "xmlrpcs.inc.php");
12 class NP_UpdatePingServer extends NucleusPlugin
19 return 'XML-RPC Updateping Server';
29 return 'http://shizuki.kinezumi.net';
37 function getDescription()
39 return _NP_PINGSERVER_DESCRIPTION;
42 function getEventList()
51 $this->createOption('desclen', _NP_PINGSERVER_GLOBALOPTION_DESCLEN, 'text',
53 $this->createOption('addstr', _NP_PINGSERVER_GLOBALOPTION_ADDSTR, 'text',
55 $this->createOption('dateformat', _NP_PINGSERVER_GLOBALOPTION_DATEFORMAT, 'text',
57 $this->createOption('listHeader', _NP_PINGSERVER_GLOBALOPTION_LISTHEADER, 'text',
58 _NP_PINGSERVER_GLOBALOPTION_LISTHEADER_VALUE);
59 $this->createOption('listFooter', _NP_PINGSERVER_GLOBALOPTION_LISTFOOTER, 'text',
60 _NP_PINGSERVER_GLOBALOPTION_LISTFOOTER_VALUE);
61 $this->createOption('listBody', _NP_PINGSERVER_GLOBALOPTION_LISTBODY, 'textarea',
62 _NP_PINGSERVER_GLOBALOPTION_LISTBODY_VALUE);
63 $this->createOption('logFlag', _NP_PINGSERVER_GLOBALOPTION_LOGFLAG, 'yesno',
65 $this->createOption('dataMaxHold', _NP_PINGSERVER_GLOBALOPTION_DATAMAXHOLD, 'text',
67 $this->createOption('quickmenu', _NP_PINGSERVER_GLOBALOPTION_QUICKMENU, 'yesno',
69 $this->createOption('dbFlag', _NP_PINGSERVER_GLOBALOPTION_DBFLAG, 'yesno',
71 // $this->createOption('reserved', _NP_PINGSERVER_GLOBALOPTION_RESERVED, 'text',
72 // _NP_PINGSERVER_GLOBALOPTION_RESERVED_VALUE);
73 // $this->createOption('reserved', _NP_PINGSERVER_GLOBALOPTION_RESERVED, 'text',
74 // _NP_PINGSERVER_GLOBALOPTION_RESERVED_VALUE);
75 $table_q = 'CREATE TABLE IF NOT EXISTS ' . sql_table('plug_updatepingserver_sitedata') . ' ('
76 . ' pingid INT(11) NOT NULL AUTO_INCREMENT, '
77 . ' updatetime INT(12) NOT NULL, '
78 . ' btitle VARCHAR(255) NOT NULL, '
79 . ' burl VARCHAR(255) NOT NULL, '
80 . ' feedurl VARCHAR(255) NOT NULL, '
81 . ' PRIMARY KEY (pingid) '
84 $table_q = 'CREATE TABLE IF NOT EXISTS ' . sql_table('plug_updatepingserver_changes') . ' ('
85 . ' id INT(11) NOT NULL AUTO_INCREMENT, '
86 . ' updatetime TIMESTAMP NOT NULL, '
87 . ' changestext VARCHAR(7) NOT NULL, '
88 . ' UNIQUE KEY changestext (changestext), '
89 . ' PRIMARY KEY (id) '
92 $table_q = 'CREATE TABLE IF NOT EXISTS ' . sql_table('plug_updatepingserver_modules') . ' ('
93 . ' moduleid INT(11) NOT NULL AUTO_INCREMENT, '
94 . ' modulename VARCHAR(255) NOT NULL, '
95 . ' moduleorder INT(11) NOT NULL, '
96 . ' UNIQUE KEY modulename (modulename), '
97 . ' PRIMARY KEY (moduleid) '
100 $this->moduleAdmin =& new moduleAdmin('UpdatePingServer');
101 $moduleNames = array();
102 $handle = @fopen($this->getDirectory() . "preinstallmodules.txt", "r");
104 while (!feof($handle)) {
105 $moduleNames[] = fgets($handle);
109 if (!empty($moduleNames)) {
110 foreach ($moduleNames as $moduleName) {
111 if (!empty($moduleName)) {
112 $this->moduleAdmin->_moduleInstall($moduleName);
120 if ($this->getOption('dbFlag') == 'yes') {
121 $tables = $this->getTableList();
122 foreach ($tables as $table) {
123 sql_query('DROP TABLE IF EXISTS ' . $table);
128 function supportsFeature($what)
131 case 'SqlTablePrefix':
138 function event_QuickMenu(&$data)
140 // only show when option enabled
141 if ($this->getOption('quickmenu') != 'yes') return;
144 // only show to admins
145 if (!($member->isLoggedIn() && $member->isAdmin())) return;
150 'title' => _NP_PINGSERVER_QUICKMENU_TITLE,
151 'url' => $this->getAdminURL(),
152 'tooltip' => _NP_PINGSERVER_QUICKMENU_TOOLTIP
157 function getTableList()
160 sql_table('plug_updatepingserver_modules'),
161 sql_table('plug_updatepingserver_changes'),
162 sql_table('plug_updatepingserver_sitedata')
164 if (!is_array($this->moduleAdmin->moduleList)) {
165 $this->moduleAdmin->getModuleList();
167 $listEneries = $this->moduleAdmin->moduleList;
168 if (is_array($listEneries)) {
169 foreach($listEneries as $listEnery) {
170 $this->moduleAdmin->_loadModule($listEnery);
171 if (method_exists($this->moduleAdmin->modules[$listEnery], 'getModuleTableList')) {
172 $moduleTables = $this->moduleAdmin->modules[$listEnery]->getModuleTableList();
174 $tables = array_merge($tables, $moduleTables);
180 function hasAdminArea()
188 $langfile = $this->getDirectory() . 'language/' . $CONF['Language'] . '.php';
189 if (!file_exists($langfile)) {
190 $langfile = $this->getDirectory() . 'language/english.php';
192 include_once($langfile);
193 require_once($this->getDirectory() . 'modules/moduleAdmin.php');
194 include_once($this->getDirectory() . 'sharedFunctions.php');
195 if (@mysql_query('SELECT * FROM ' . sql_table('plug_updatepingserver_modules'))) {
196 $this->moduleAdmin =& new moduleAdmin('UpdatePingServer');
200 function updatepingEventNotify($eventName, $data)
202 if (!is_array($this->moduleAdmin->moduleList)) {
203 $this->moduleAdmin->getModuleList();
205 $listEneries = $this->moduleAdmin->moduleList;
206 if (is_array($listEneries)) {
207 foreach($listEneries as $listEnery) {
208 $this->moduleAdmin->_loadModule($listEnery);
209 $eventMethod = 'np_updatePingServerEvent_' . $eventName;
210 if (method_exists($this->moduleAdmin->modules[$listEnery], $eventMethod)) {
211 $data['myPlugin'] = $this;
212 call_user_func(array(&$this->moduleAdmin->modules[$listEnery], $eventMethod), $data);
218 function weblogUpdates($msg)
221 for ($i = 0; $i < $msg->getNumParams(); $i++) {
223 $title = $msg->getParam($i);
224 $title = $title->scalarval();
225 } else if ($i == 1) {
226 $url = $msg->getParam($i);
227 $url = $url->scalarval();
228 } else if ($i == 3) {
229 $furl = $msg->getParam($i);
230 $furl = $furl->scalarval();
231 if (!preg_match("/^(http)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/", $furl)) {
240 'siteTitle' => $title,
245 'siteTitle' => &$title,
246 'response' => &$response,
247 'message' => &$message,
248 'siteData' => &$siteData,
250 $this->updatepingEventNotify('receivePing', $moduleData);
252 $GLOBALS['xmlrpc_defencoding'] = 'UTF-8';
254 $this->updateTable($siteData);
255 if ($this->getOption('logFlag') == 'yes') {
256 addToLog(INFO, 'Updateping Server Received ping. from:' . $title);
258 $flerror = new xmlrpcval(0, 'boolean');
260 $message = new xmlrpcval('Thanks for your update ping.');
262 $message = new xmlrpcval($message);
265 'flerror' => $flerror,
266 'message' => $message
268 $value = new xmlrpcval($values, 'struct');
269 return new xmlrpcresp($value);
271 $eCode = $GLOBALS['xmlrpcerruser'] + 21;
273 $message = 'Your updateping can not received.';
275 return new xmlrpcresp(0, $eCode, $message);
279 function changesOutput()
281 $last = intGetVar('last');
292 . sql_table('plug_updatepingserver_sitedata');
295 . ' updatetime > ' . (strtotime($upd) - $last);
297 $query .= ' ORDER BY updatetime DESC';
304 $this->updatepingEventNotify('changesOutput', $eventData);
306 $res = sql_query($query);
307 if (mysql_num_rows($res)) {
309 while ($list = mysql_fetch_assoc($res)) {
310 $when = (strtotime($upd) - $list['updatetime']);
311 $list = array_map($sharedFunctions->_hsc, $list);
314 . ' name="' . $list['btitle'] . '"'
315 . ' url="' . $list['burl'] . '"'
316 . ' rssUrl="' . $list['feedurl'] . '"'
317 . ' when="' . $when . '"'
323 . sql_table('plug_updatepingserver_changes');
324 $ver = quickQuery($que);
326 $out = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . "\n"
327 . '<weblogUpdates version="2" updated="' . $upd . '" count="' . $ver . '">' . "\n"
329 . '</weblogUpdates>';
330 header("Content-Type: text/xml");
332 $query = 'REPLACE ' . sql_table('plug_updatepingserver_changes')
334 . ' changestext = "changes"';
342 function updateTable($data)
344 $sharedFunctions = new sharedFunctions();
347 . sql_table('plug_updatepingserver_sitedata')
357 . $sharedFunctions->quoteSmart($data['siteTitle']) . ', '
358 . $sharedFunctions->quoteSmart($data['siteURL']) . ', '
359 . $sharedFunctions->quoteSmart($data['feedURL'])
363 . ' COUNT(pingid) as result '
365 . sql_table('plug_updatepingserver_sitedata');
366 if (quickQuery($query) > $this->getOption('dataMaxHold')) {
367 $query = 'DELETE FROM '
368 . sql_table('plug_updatepingserver_sitedata')
376 function doSkinVar($skinType, $amount = 5)
378 if (empty($amount)) $amount = 5;
379 echo $this->getOption('listHeader');
381 . ' updatetime as tstamp, '
382 . ' btitle as blogtitle, '
383 . ' burl as blogurl, '
384 . ' etitle as entrytitle, '
385 . ' eurl as entryurl, '
386 . ' edesc as entrydesc '
388 . sql_table('plug_updatepingserver_feeddata')
393 $res = sql_query($query);
394 $len = $this->getOption('desclen');
395 $add = $this->getOption('addstr');
396 while ($values = mysql_fetch_assoc($res)) {
397 $values['formatdate'] = strftime($this->getOption('dateformat'), $values['tstamp']);
398 $values = array_map(array(&$this, '_hsc'), $values);
399 $values['entrydesc'] = shorten($values['entrydesc'], $len, $add);
400 echo TEMPLATE::fill($this->getOption('listBody'), $values);
402 echo $this->getOption('listFooter');
405 function doTemplateVar(&$item, $amount = 5)
407 if (empty($amount)) $amount = 5;
408 $this->doSkinVar('template', $amount);
411 function doItemVar($item, $amount = 5)
413 if (empty($amount)) $amount = 5;
414 $this->doSkinVar('item', $amount);
417 function doAction($type)
422 global $HTTP_RAW_POST_DATA;
423 $HTTP_RAW_POST_DATA = '<' . '?xml version="1.0"?' . '>
425 <methodName>weblogUpdates.ping</methodName>
428 <value>YOUR WEBLOG NAME HERE</value>
431 <value>http://shizuki.kinezumi.net</value>
436 $parser = xml_parser_create();
437 xml_parse_into_struct($parser, $GLOBALS['HTTP_RAW_POST_DATA'], $vals, $index);
438 xml_parser_free($parser);
439 $method = $vals[$index['METHODNAME'][0]]['value'];
440 $GLOBALS['xmlrpc_internalencoding'] = _CHARSET;
441 $GLOBALS['xmlrpc_defencoding'] = 'UTF-8';
454 if (!version_compare(phpversion(), "5.0.0", "=<")) {// && !is_array($GLOBALS['xmlrpc_valid_parents'])) {
455 $GLOBALS['xmlrpc_valid_parents'] = array(
456 'BOOLEAN' => array('VALUE'),
457 'I4' => array('VALUE'),
458 'INT' => array('VALUE'),
459 'STRING' => array('VALUE'),
460 'DOUBLE' => array('VALUE'),
461 'DATETIME.ISO8601' => array('VALUE'),
462 'BASE64' => array('VALUE'),
463 'ARRAY' => array('VALUE'),
464 'STRUCT' => array('VALUE'),
465 'PARAM' => array('PARAMS'),
466 'METHODNAME' => array('METHODCALL'),
467 'PARAMS' => array('METHODCALL', 'METHODRESPONSE'),
468 'MEMBER' => array('STRUCT'),
469 'NAME' => array('MEMBER'),
470 'DATA' => array('ARRAY'),
471 'FAULT' => array('METHODRESPONSE'),
472 'VALUE' => array('MEMBER', 'DATA', 'PARAM', 'FAULT'),
476 $svr =& new xmlrpc_server($map);
480 $this->changesOutput();