2 // vim: tabstop=2:shiftwidth=2
4 /* ==========================================================================================
5 * Trackback 2.0 for Nucleus CMS
6 * ==========================================================================================
7 * This program is free software and open source software; you can redistribute
8 * it and/or modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the License,
10 * or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit
20 * http://www.gnu.org/licenses/gpl.html
21 * ==========================================================================================
24 class NP_TrackBack_XMLParser {
25 function NP_TrackBack_XMLParser(){
26 $this->parser = xml_parser_create();
27 xml_set_object($this->parser, $this);
28 xml_set_element_handler($this->parser, "_open", "_close");
29 xml_set_character_data_handler($this->parser, "_cdata");
31 $this->isError = false;
32 $this->inTarget = false;
35 function parse($data){
36 $this->words = array();
37 xml_parse($this->parser, $data);
38 $errcode = xml_get_error_code($this->parser);
39 if ( $errcode != XML_ERROR_NONE ) {
40 $this->isError = true;
41 $this->message = 'XML Parse Error: ' . xml_error_string($errcode) . ' in '. xml_get_current_line_number($this->parser);
43 return $this->message;
47 xml_parser_free($this->parser);
50 function _open($parser, $name, $attribute){
53 $this->inTarget = 'MESSAGE';
56 $this->inTarget = 'ERROR';
61 function _close($parser, $name){
62 if( $name == $this->inTarget ) $this->inTarget = null;
65 function _cdata($parser, $data){
66 switch( $this->inTarget ){
68 $this->message = trim($data);
71 $this->isError = ($data ? true : false);
77 class NP_TrackBack extends NucleusPlugin {
78 var $useCurl = 1; // use curl? 2:precheck+read by curl, 1: read by curl 0: fread
80 //modify start+++++++++
81 function _createItemLink($itemid, $b){
82 global $CONF, $manager;
83 $blogurl = $b->getURL();
87 $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
88 $blogurl = $b_tmp->getURL();
91 $blogurl = $CONF['IndexURL'];
92 if ($CONF['URLMode'] != 'pathinfo'){
93 $blogurl = $CONF['Self'];
97 if ($CONF['URLMode'] == 'pathinfo'){
98 if(substr($blogurl, -1) == '/') $blogurl = substr($blogurl,0,-1);
101 $itemUrlOrg = $CONF['ItemURL'];
102 $CONF['ItemURL'] = $blogurl;
103 $itemLink = createItemLink($itemid,'');
104 $CONF['ItemURL'] = $itemUrlOrg;
108 //modify end+++++++++
110 /**************************************************************************************
111 * SKIN VARS, TEMPLATE VARS AND ACTIONS
115 * TrackBack data can be inserted using skinvars (or templatevars)
117 function doSkinVar($skinType, $what = '', $tb_id = '', $amount = 'limit-1') {
119 global $itemid, $manager, $CONF;
121 //modify start+++++++++
122 if(eregi('limit', $tb_id)){
126 $amount = eregi_replace("limit", "", $amount);
127 $amount = intval($amount);
128 //modify end+++++++++
130 if ($tb_id == '') $tb_id = intval($itemid);
133 $isAcceptPing = $this->isAcceptTrackBack($tb_id);
135 //if( $skinType == 'template' && (! $isAcceptPing ) ){
141 // Insert Auto-discovery RDF code
145 // if($skinType == 'item')
157 /* Backwards compatibility with SpamCheck API 1*/
162 //$manager->notify('SpamCheck', array ('spamcheck' => & $spamcheck));
164 if (isset($spamcheck['result']) && $spamcheck['result'] == true){
168 if( ($skinType == 'item') && (!$spam) && $isAcceptPing )
170 $this->insertCode($tb_id);
173 // Insert TrackBack URL
177 // echo $this->getTrackBackUrl($tb_id);
179 echo $this->getTrackBackUrl($tb_id);
181 echo 'Sorry, no trackback pings are accepted.';
185 // Insert manual ping URL
187 case 'manualpingformlink':
188 echo $this->getManualPingUrl($tb_id);
192 echo $manager->addTicketToUrl($CONF['PluginURL'] . 'trackback/index.php?action=ping&id=' . intval($tb_id));
195 // Insert TrackBack count
197 $count = $this->getTrackBackCount($tb_id);
199 case 0: echo TEMPLATE::fill($this->getOption('tplTbNone'), array('number' => $count)); break;
200 case 1: echo TEMPLATE::fill($this->getOption('tplTbOne'), array('number' => $count)); break;
201 default: echo TEMPLATE::fill($this->getOption('tplTbMore'), array('number' => $count)); break;
205 // Shows the TrackBack list
208 //modify start+++++++++
209 // $this->showList($tb_id);
210 $this->showList($tb_id, $amount);
211 //modify end+++++++++
216 echo $this->getRequiredURL($tb_id);
219 // shows the Local list
221 $this->showLocalList($tb_id);
231 * When used in templates, the tb_id will be determined by the itemid there
233 function doTemplateVar(&$item, $what = '') {
234 $this->doSkinVar('template', $what, $item->itemid);
237 function doTemplateCommentsVar(&$item, &$comment, $what = ''){
238 $this->doSkinVar('templatecomments', $what, $item->itemid);
242 * A trackback ping is to be received on the URL
243 * http://yourdomain.com/item/1234.trackback
244 * Extra variables to be passed along are url, title, excerpt, blog_name
246 function event_InitSkinParse(&$data) {
247 global $CONF, $itemid;
248 $format = requestVar('format');
250 if ($CONF['URLMode'] == 'pathinfo') {
251 if (preg_match('/(\/|\.)(trackback)(\/|$)/', serverVar('PATH_INFO'), $matches)) {
252 $format = $matches[2];
256 if ($format == 'trackback' && $data['type'] == 'item')
258 $errorMsg = $this->handlePing(intval($itemid));
261 $this->xmlResponse($errorMsg);
263 $this->xmlResponse();
270 * A trackback ping is to be received on the URL
271 * http://yourdomain.com/action.php?action=plugin&name=TrackBack&tb_id=1234
272 * Extra variables to be passed along are url, title, excerpt, blog_name
274 function doAction($type)
276 global $CONF,$manager;
277 $aActionsNotToCheck = array(
284 if (!in_array($type, $aActionsNotToCheck)) {
285 if (!$manager->checkTicket()) return _ERROR_BADTICKET;
290 // When no action type is given, assume it's a ping
292 $errorMsg = $this->handlePing();
295 $this->xmlResponse($errorMsg);
297 $this->xmlResponse();
302 $errorMsg = $this->handlePing();
304 $this->showManualPingError(intRequestVar('tb_id'), $errorMsg);
306 $this->showManualPingSuccess(intRequestVar('tb_id'));
309 // Show manual ping form
312 // $this->showManualPingForm(intRequestVar('tb_id'));
313 $tb_id = intRequestVar('tb_id');
314 $isAcceptPing = $this->isAcceptTrackBack($tb_id);
317 $this->showManualPingForm($tb_id);
319 echo 'Sorry, no trackback pings are accepted.';
326 $this->getURIfromLink(html_entity_decode(requestVar('tb_link')));
328 $url = addslashes($url);
329 $url = $this->_utf8_to_javascript($url);
331 $title = addslashes($title);
332 $title = $this->_utf8_to_javascript($title);
334 echo "tbDone('" . requestVar('tb_link') . "', '" . $url . "', '" . $title . "');";
340 return $this->redirect(intRequestVar('tb_id'), requestVar('urlHash'));
344 echo $this->showLeftList(intRequestVar('tb_id'), intRequestVar('amount'));
347 // delete a trackback(local)
349 $err = $this->deleteLocal(intRequestVar('tb_id'), intRequestVar('from_id'));
352 header('Location: ' . serverVar('HTTP_REFERER'));
359 function doIf($key = '', $value = '')
362 //echo "key: $key, value: $value";
364 switch( strtolower($key) ){
367 if( $value == '' ) $value = 'yes';
368 $value = ( $value == 'no' || (! $value) ) ? false : true;
372 $ret = $this->isAcceptTrackBack($itemid);
374 $ret = $this->isAcceptTrackBack();
375 return ( $value == false ) ? (! $ret) : $ret;
378 if( $value == '' ) $value = 'yes';
379 $value = ( $value == 'no' || (! $value) ) ? false : true;
383 $ret = $this->isEnableLinkCheck($itemid);
385 return ( $value == false ) ? (! $ret) : $ret;
392 /**************************************************************************************
397 * Show a list of left trackbacks for this ID
399 function showLeftList($tb_id, $offset = 0, $amount = 99999999) {
400 global $manager, $blog, $CONF;
410 UNIX_TIMESTAMP(timestamp) AS timestamp
412 '.sql_table('plugin_tb').'
414 tb_id = '.intval($tb_id).' AND
420 $query .= ' LIMIT '.intval($offset).', ' .intval($amount);
421 $res = sql_query($query);
422 while ($row = mysql_fetch_array($res))
425 $row['blog_name'] = htmlspecialchars($row['blog_name'], ENT_QUOTES);
426 $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES);
427 $row['excerpt'] = htmlspecialchars($row['excerpt'], ENT_QUOTES);
428 if (_CHARSET != 'UTF-8') {
429 //modify start+++++++++
430 $row['blog_name'] = $this->_restore_to_utf8($row['blog_name']);
431 $row['title'] = $this->_restore_to_utf8($row['title']);
432 $row['excerpt'] = $this->_restore_to_utf8($row['excerpt']);
433 //modify end+++++++++
434 $row['blog_name'] = $this->_utf8_to_entities($row['blog_name']);
435 $row['title'] = $this->_utf8_to_entities($row['title']);
436 $row['excerpt'] = $this->_utf8_to_entities($row['excerpt']);
439 'action' => $this->getTrackBackUrl($tb_id),
440 'form' => $this->getManualPingUrl($tb_id),
441 'name' => $row['blog_name'],
442 'title' => $row['title'],
443 'excerpt' => $this->_cut_string($row['excerpt'], 400),
444 'url' => htmlspecialchars($row['url'], ENT_QUOTES),
445 'date' => htmlspecialchars(strftime($this->getOption('dateFormat'), $row['timestamp']), ENT_QUOTES)
449 if( $this->getOption('HideUrl') == 'yes' )
450 $iVars['url'] = $CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=redirect&tb_id=' . $tb_id . '&urlHash=' . $row['urlHash'];
452 $iVars['url'] = $row['url'];
455 $out[] = TEMPLATE::fill($this->getOption('tplItem'), $iVars);
457 mysql_free_result($res);
459 return @join("\n",$out);
463 * Show a list of all trackbacks for this ID
465 function showList($tb_id, $amount = 0) {
466 $tb_id = intval($tb_id);
467 global $manager, $blog, $CONF, $member;
469 $enableHideurl = true;
472 strstr(serverVar('HTTP_USER_AGENT'),'Hatena Diary Track Forward Agent')
473 || strstr(serverVar('HTTP_USER_AGENT'),'NP_TrackBack')
474 || strstr(serverVar('HTTP_USER_AGENT'),'TBPingLinkLookup')
475 || strstr(serverVar('HTTP_USER_AGENT'),'MT::Plugin::BanNoReferTb')
476 || strstr(serverVar('HTTP_USER_AGENT'),'livedoorBlog')
478 $enableHideurl = false;
491 UNIX_TIMESTAMP(timestamp) AS timestamp
493 '.sql_table('plugin_tb').'
495 tb_id = '.$tb_id .' AND
508 UNIX_TIMESTAMP(timestamp) AS timestamp
510 '.sql_table('plugin_tb').'
512 tb_id = '.intval($tb_id) .' AND
517 if( $amount == '-1' )
518 $query .= ' LIMIT 9999999';
520 $query .= ' LIMIT '.intval($amount);
523 $res = sql_query($query);
526 'action' => $this->getTrackBackUrl(intval($tb_id)),
527 'form' => $this->getManualPingUrl(intval($tb_id)),
528 'required' => $this->getRequiredURL(intval($tb_id)),
531 if ($member->isLoggedIn() && $member->isAdmin()){
532 $adminurl = htmlspecialchars($manager->addTicketToUrl($CONF['PluginURL'] . 'trackback/index.php?action=list&id=' . intval($tb_id)), ENT_QUOTES);
533 $pingformurl = htmlspecialchars($manager->addTicketToUrl($CONF['PluginURL'] . 'trackback/index.php?action=ping&id=' . intval($tb_id)), ENT_QUOTES);
534 $gVars['admin'] = '<a href="' . $adminurl . '" target="_blank">[admin]</a>';
535 $gVars['pingform'] = '<a href="' . $pingformurl . '" target="_blank">[pingform]</a>';
538 echo TEMPLATE::fill($this->getOption('tplHeader'), $gVars);
541 while ($amount != 0 && $row = mysql_fetch_array($res))
544 $row['blog_name'] = htmlspecialchars($row['blog_name'], ENT_QUOTES);
545 $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES);
546 $row['excerpt'] = htmlspecialchars($row['excerpt'], ENT_QUOTES);
550 if (_CHARSET != 'UTF-8') {
551 //modify start+++++++++
553 $row['blog_name'] = $this->_utf8_to_entities($row['blog_name']);
554 $row['title'] = $this->_utf8_to_entities($row['title']);
555 $row['excerpt'] = $this->_utf8_to_entities($row['excerpt']);
557 $row['blog_name'] = $this->_restore_to_utf8($row['blog_name']);
558 $row['title'] = $this->_restore_to_utf8($row['title']);
559 $row['excerpt'] = $this->_restore_to_utf8($row['excerpt']);
561 $row['blog_name'] = mb_convert_encoding($row['blog_name'], _CHARSET, 'UTF-8');
562 $row['title'] = mb_convert_encoding($row['title'], _CHARSET, 'UTF-8');
563 $row['excerpt'] = mb_convert_encoding($row['excerpt'], _CHARSET, 'UTF-8');
564 //modify end+++++++++
567 //modify start+++++++++
570 'action' => $this->getTrackBackUrl($tb_id),
571 'form' => $this->getManualPingUrl($tb_id),
572 'name' => $row['blog_name'],
573 'title' => $row['title'],
574 'excerpt' => $row['excerpt'],
575 'url' => htmlspecialchars($row['url'], ENT_QUOTES),
576 'date' => htmlspecialchars(strftime($this->getOption('dateFormat'), $row['timestamp'] + ($blog->getTimeOffset() * 3600)), ENT_QUOTES)
580 'action' => $this->getTrackBackUrl($tb_id),
581 'form' => $this->getManualPingUrl($tb_id),
582 'name' => htmlspecialchars($row['blog_name'], ENT_QUOTES),
583 'title' => htmlspecialchars($row['title'], ENT_QUOTES),
584 'excerpt' => htmlspecialchars($this->_cut_string($row['excerpt'], 400), ENT_QUOTES),
585 'url' => htmlspecialchars($row['url'], ENT_QUOTES),
586 'date' => htmlspecialchars(strftime($this->getOption('dateFormat'), $row['timestamp']), ENT_QUOTES)
590 if( $enableHideurl && $this->getOption('HideUrl') == 'yes' )
591 $iVars['url'] = $CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=redirect&tb_id=' . intval($tb_id) . '&urlHash=' . $row['urlHash'];
593 $iVars['url'] = $row['url'];
596 //modify end+++++++++
597 echo TEMPLATE::fill($this->getOption('tplItem'), $iVars);
601 //modify start+++++++++
606 '.sql_table('plugin_tb').'
608 tb_id = '.intval($tb_id) .' AND
613 $result = sql_query($q);
614 $total = mysql_result($result,0,0);
616 if($amount != -1 && $total > $amount){
617 $leftcount = $total - $amount;
619 echo '<script type="text/javascript" src="' . $this->getAdminURL() . 'detectlist.php?tb_id='.intval($tb_id).'&amount='.intval($amount).'"></script>';
623 <a name="restoftrackback" id="restoftrackback"></a>
624 <div id="tbshownavi"><a href="#restoftrackback" onclick="resttbStart(); return false;" id="tbshow">Show left <?php echo $leftcount;?> Trackbacks</a></div>
625 <div id="tbhidenavi" style="display: none;"><a href="#restoftrackback" onclick="hideresttb(); return false;">Hide <?php echo $leftcount;?> Trackbacks</a></div>
626 <div id="resttb"></div>
630 //modify end+++++++++
632 if (mysql_num_rows($res) == 0)
634 echo TEMPLATE::fill($this->getOption('tplEmpty'), $gVars);
636 mysql_free_result($res);
638 echo TEMPLATE::fill($this->getOption('tplFooter'), $gVars);
643 * Returns the TrackBack count for a TrackBack item
645 function getTrackBackCount($tb_id) {
646 return quickQuery('SELECT COUNT(*) as result FROM ' . sql_table('plugin_tb') . ' WHERE tb_id='.intval($tb_id).' AND block = 0');
650 * Returns the manual ping URL
652 function getManualPingUrl($itemid) {
654 return $CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=form&tb_id='.$itemid;
658 * Show the manual ping form
660 function showManualPingError($itemid, $status = '') {
663 $form = true; $error = true; $success = false;
664 sendContentType('text/html', 'admin-trackback', _CHARSET);
665 //modify start+++++++++
666 // include ($this->getDirectory() . '/templates/form.html');
667 require_once($this->getDirectory() . '/template.php');
668 $mTemplate = new Trackback_Template(null, $this->getDirectory());
669 $mTemplate->set ('CONF', $CONF);
670 $mTemplate->set ('itemid', $itemid);
671 $mTemplate->set ('form', $form);
672 $mTemplate->set ('error', $error);
673 $mTemplate->set ('success', $success);
674 $mTemplate->set ('status', $status);
675 $mTemplate->template('templates/form.html');
676 echo $mTemplate->fetch();
677 //modify end+++++++++
680 function showManualPingSuccess($itemid, $status = '') {
683 $form = false; $error = false; $success = true;
684 sendContentType('text/html', 'admin-trackback', _CHARSET);
685 //modify start+++++++++
686 //include ($this->getDirectory() . '/templates/form.html');
687 require_once($this->getDirectory() . '/template.php');
688 $mTemplate = new Trackback_Template(null, $this->getDirectory());
689 $mTemplate->set ('CONF', $CONF);
690 $mTemplate->set ('itemid', $itemid);
691 $mTemplate->set ('form', $form);
692 $mTemplate->set ('error', $error);
693 $mTemplate->set ('success', $success);
694 $mTemplate->set ('status', $status);
695 $mTemplate->template('templates/form.html');
696 echo $mTemplate->fetch();
697 //modify end+++++++++
700 function showManualPingForm($itemid, $text = '') {
703 $form = true; $error = false; $success = false;
705 // Check if we are allowed to accept pings
706 if ( !$this->isAcceptTrackBack($itemid) ) {
707 $text = 'Sorry, no trackback pings are accepted';
708 $form = false; $error = true;
711 sendContentType('text/html', 'admin-trackback', _CHARSET);
712 //modify start+++++++++
713 //include ($this->getDirectory() . '/templates/form.html');
714 require_once($this->getDirectory() . '/template.php');
715 $mTemplate = new Trackback_Template(null, $this->getDirectory());
716 $mTemplate->set ('CONF', $CONF);
717 $mTemplate->set ('itemid', $itemid);
718 $mTemplate->set ('form', $form);
719 $mTemplate->set ('error', $error);
720 $mTemplate->set ('success', $success);
721 $mTemplate->set ('status', $status);
722 $mTemplate->template('templates/form.html');
723 echo $mTemplate->fetch();
724 //modify end+++++++++
728 * Returns the trackback URL
730 function getTrackBackUrl($itemid) {
731 global $CONF, $manager;
732 return $CONF['ActionURL'] . '?action=plugin&name=TrackBack&tb_id='.$itemid;
736 * Insert RDF code for item
738 function insertCode($itemid) {
739 $itemid = intval($itemid);
740 global $manager, $CONF;
742 $item = & $manager->getItem($itemid, 0, 0);
743 $blog = & $manager->getBlog(getBlogIDFromItemID($item['itemid']));
746 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
747 $uri = createItemLink($item['itemid'],'');
749 $uri = $this->_createItemLink($item['itemid'],$blog);
751 $title = strip_tags($item['title']);
752 $desc = strip_tags($item['body']);
753 $desc = $this->_cut_string($desc, 200);
754 $desc = htmlspecialchars($desc, ENT_QUOTES);
758 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
759 xmlns:dc="http://purl.org/dc/elements/1.1/"
760 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
762 rdf:about="<?php echo $uri; ?>"
763 dc:identifier="<?php echo $uri; ?>"
764 dc:title="<?php echo $title; ?>"
765 dc:description="<?php echo $desc; ?>"
766 trackback:ping="<?php echo $this->getTrackBackUrl($itemid)?>"
767 dc:date="<?php echo strftime('%Y-%m-%dT%H:%M:%S')?>" />
774 * Retrieving TrackBack Pings (when __mode=rss)
776 function rssResponse($tb_id) {
777 $itemid = intval($itemid);
778 global $manager, $CONF;
779 $item =& $manager->getItem($tb_id, 0, 0);
783 $blog =& $manager->getBlog(getBlogIDFromItemID($item['itemid']));
785 $blog_name = $blog->getName();
786 $title = $item['title'];
787 $excerpt = $item['body'];
789 //modify start+++++++++
791 if (_CHARSET != 'UTF-8')
793 $title = $this->_convert_to_utf8($title, $encoding);
794 $excerpt = $this->_convert_to_utf8($excerpt, $encoding);
795 $blog_name = $this->_convert_to_utf8($blog_name, $encoding);
798 $title = $this->_decode_entities(strip_tags($title));
799 $excerpt = $this->_decode_entities(strip_tags($excerpt));
800 $blog_name = $this->_decode_entities(strip_tags($blog_name));
803 $title = $this->_restore_to_utf8($title);
804 $excerpt = $this->_restore_to_utf8($excerpt);
805 $blog_name = $this->_restore_to_utf8($blog_name);
806 //modify end+++++++++
808 $excerpt = $this->_cut_string($excerpt, 200);
811 //modify start+++++++++
813 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
814 $url = createItemLink($item['itemid'],'');
816 $url = $this->_createItemLink($item['itemid'],$blog);
817 //modify end+++++++++
819 // Use UTF-8 charset for output
820 header('Content-Type: text/xml');
821 echo "<","?xml version='1.0' encoding='UTF-8'?",">\n";
824 echo "\t<error>0</error>\n";
825 echo "\t<rss version='0.91'>\n";
826 echo "\t\t<channel>\n";
827 echo "\t\t\t<title>".htmlspecialchars($title, ENT_QUOTES)."</title>\n";
828 echo "\t\t\t<link>".htmlspecialchars($url, ENT_QUOTES)."</link>\n";
829 echo "\t\t\t<description>".htmlspecialchars($excerpt, ENT_QUOTES)."</description>\n";
831 $query = 'SELECT url, blog_name, excerpt, title, UNIX_TIMESTAMP(timestamp) as timestamp FROM '.sql_table('plugin_tb').' WHERE tb_id='.intval($tb_id).' AND block = 0 ORDER BY timestamp DESC';
832 $res = sql_query($query);
833 while ($o = mysql_fetch_object($res))
835 // No need to do conversion, because it is already UTF-8
837 'url' => htmlspecialchars($o->url, ENT_QUOTES),
838 'blogname' => htmlspecialchars($this->_restore_to_utf8($o->blog_name), ENT_QUOTES),
839 'timestamp' => strftime('%Y-%m-%d',$o->timestamp),
840 'title' => htmlspecialchars($this->_restore_to_utf8($o->title), ENT_QUOTES),
841 'excerpt' => htmlspecialchars($this->_restore_to_utf8($o->excerpt), ENT_QUOTES),
842 'tburl' => $this->getTrackBackUrl($tb_id)
846 echo "\t\t\t<item>\n";
847 echo "\t\t\t\t<title>".$data['title']."</title>\n";
848 echo "\t\t\t\t<link>".$data['url']."</link>\n";
849 echo "\t\t\t\t<description>".$data['excerpt']."</description>\n";
850 echo "\t\t\t</item>\n";
852 echo "\t\t</channel>\n";
859 $this->xmlResponse(_ERROR_NOSUCHITEM);
866 /**************************************************************************************
867 * SENDING AND RECEIVING TRACKBACK PINGS
871 * Send a Trackback ping to another website
873 function sendPing($itemid, $title, $url, $excerpt, $blog_name, $ping_url, $utf8flag=0)
875 $tempEncording = ($utf8flag)? 'UTF-8': _CHARSET;
877 // 1. Check some basic things
878 if (!$this->canSendPing()) {
879 return 'You\'re not allowed to send pings';
882 if ($this->getOption('SendPings') == 'no') {
883 return 'Sending trackback pings is disabled';
886 if ($ping_url == '') {
887 return 'No ping URL';
890 // 2. Check if protocol is correct http URL
891 $parsed_url = parse_url($ping_url);
893 if ($parsed_url['scheme'] != 'http' || $parsed_url['host'] == '')
894 return 'Bad ping URL';
896 $port = ($parsed_url['port']) ? $parsed_url['port'] : 80;
898 // 3. Create contents
899 if($tempEncording != _CHARSET){
900 $title = mb_convert_encoding($title, $tempEncording, _CHARSET);
901 $excerpt = mb_convert_encoding($excerpt, $tempEncording, _CHARSET);
902 $blog_name = mb_convert_encoding($blog_name, $tempEncording, _CHARSET);
906 $content = 'title=' . urlencode( $title );
907 $content .= '&url=' . urlencode( $url );
908 $content .= '&excerpt=' . urlencode( $excerpt );
909 $content .= '&blog_name=' . urlencode( $blog_name );
911 // 4. Prepare HTTP request
912 $request = 'POST ' . $parsed_url['path'];
914 if ($parsed_url['query'] != '')
915 $request .= '?' . $parsed_url['query'];
917 $request .= " HTTP/1.1\r\n";
918 $request .= "Accept: */*\r\n";
919 $request .= "User-Agent: " . $this->userAgent . "\r\n";
920 $request .= ( $port == 80 )?
921 "Host: " . $parsed_url['host'] . "\r\n":
922 "Host: " . $parsed_url['host'] . ":" . $port . "\r\n";
923 $request .= "Cache-Control: no-cache\r\n";
924 $request .= "Connection: Close\r\n";
925 $request .= "Content-Length: " . strlen( $content ) . "\r\n";
926 $request .= ($utf8flag)?
927 "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n":
928 "Content-Type: application/x-www-form-urlencoded; charset="._CHARSET."\r\n";
930 $request .= $content;
932 $socket = fsockopen( $parsed_url['host'], $port, $errno, $errstr );
934 return 'Could not send ping: '.$errstr.' ('.$errno.')';
936 // 5. Execute HTTP request
937 fputs($socket, $request);
939 // 6. Receive response
941 while (!feof($socket)) {
942 $result .= fgets($socket, 4096);
947 //modify start+++++++++
948 list($header, $body) = split("\r\n\r\n", $result, 2);
949 preg_match("/HTTP\/1\.[0-1] ([0-9]+) ([^\r\n]*)\r?\n/", $header, $httpresp);
950 $respCd = $httpresp[1];
951 $respMsg = $httpresp[2];
953 if( $respCd != 200 ){
954 return 'An error occurred: HTTP Error: [' . $respCd . '] ' . $respMsg;
957 if( function_exists('xml_parser_create') ){
958 $p = new NP_TrackBack_XMLParser();
962 return 'An error occurred: ' . htmlspecialchars($p->message, ENT_QUOTES);
965 if ( strstr($DATA[1],'<error>0</error>') === false ){
966 preg_match("/<message>(.*?)<\/message>/",$DATA[1],$error_message);
967 if( $error_message[1] )
968 return 'An error occurred: '.htmlspecialchars($error_message[1], ENT_QUOTES);
970 return 'An error occurred: fatal error.';
976 //modify end+++++++++
979 * Handle a Trackback ping sent to this website
981 function handlePing($tb_id = 0) {
987 //modify start+++++++++
990 //modify end+++++++++
992 $tb_id = intRequestVar('tb_id');
994 $rss = requestVar('__mode') == 'rss';
996 $enableLinkCheck = $this->isEnableLinkCheck($tb_id);
997 $block = ( $enableLinkCheck ) ? true : false ;
1001 return 'TrackBack ID is missing (tb_id)';
1004 if ((!$manager->existsItem($tb_id,0,0)) && ($this->getOption('CheckIDs') == 'yes')) {
1005 return _ERROR_NOSUCHITEM;
1008 // 0. Check if we need to output the list as rss
1010 $this->rssResponse($tb_id);
1014 // check: accept pings.
1015 $blogId = getBlogIDFromItemID($tb_id);
1016 $isAcceptPing = $this->isAcceptTrackBack($tb_id);
1018 if (! $isAcceptPing)
1019 return 'Sorry, no trackback pings are accepted.';
1022 // 1. Get attributes
1023 //modify start+++++++++
1024 $b =& $manager->getBlog($blogId);
1025 //modify end+++++++++
1026 $url = requestVar('url');
1027 $title = requestVar('title');
1028 $excerpt = requestVar('excerpt');
1029 $blog_name = requestVar('blog_name');
1031 if( $url && preg_match('/https?:\/\/([^\/]+)/', $url, $matches) ){
1032 if( gethostbynamel($matches[1]) === FALSE )
1033 return 'URL is invalid (url)';
1035 return 'URL is missing or invalid (url)';
1038 // 2. Conversion of encoding...
1039 //modify start+++++++++
1040 /* if (preg_match ("/;\s*charset=([^\n]+)/is", $_SERVER["CONTENT_TYPE"], $regs))
1041 $encoding = strtoupper(trim($regs[1]));
1043 $encoding = $this->_detect_encoding($excerpt);
1045 $encoding = $this->_detect_encoding($excerpt);
1046 //modify end+++++++++
1048 //modify start+++++++++
1049 if (_CHARSET != 'UTF-8'){
1050 $title = $this->_strip_controlchar(strip_tags(mb_convert_encoding($title, _CHARSET, $encoding)));
1051 $excerpt = $this->_strip_controlchar(strip_tags(mb_convert_encoding($excerpt, _CHARSET, $encoding)));
1052 $blog_name = $this->_strip_controlchar(strip_tags(mb_convert_encoding($blog_name, _CHARSET, $encoding)));
1054 $title = $this->_strip_controlchar($this->_convert_to_utf8($title, $encoding));
1055 $excerpt = $this->_strip_controlchar($this->_convert_to_utf8($excerpt, $encoding));
1056 $blog_name = $this->_strip_controlchar($this->_convert_to_utf8($blog_name, $encoding));
1058 $title = $this->_decode_entities(strip_tags($title));
1059 $excerpt = $this->_decode_entities(strip_tags($excerpt));
1060 $blog_name = $this->_decode_entities(strip_tags($blog_name));
1062 //modify end+++++++++
1064 // 4. Save data in the DB
1069 '.sql_table('plugin_tb').'
1071 url = \''.mysql_real_escape_string($url).'\' AND
1072 tb_id = \''.intval($tb_id).'\'
1075 if (mysql_num_rows($res) != 0)
1077 // Existing TB, update it
1081 '.sql_table('plugin_tb').'
1083 title = "'.mysql_real_escape_string($title).'",
1084 excerpt = "'.mysql_real_escape_string($excerpt).'",
1085 blog_name = "'.mysql_real_escape_string($blog_name).'",
1086 timestamp = '.mysqldate(time()).'
1088 url = "'.mysql_real_escape_string($url).'" AND
1089 tb_id = "'.$tb_id.'"
1092 //modify start+++++++++
1093 $rows = mysql_fetch_assoc($res);
1094 $spam = ( $rows['block'] || $rows['spam'] ) ? true : false;
1097 '.sql_table('plugin_tb').'
1099 title = \''.mysql_real_escape_string($title).'\',
1100 excerpt = \''.mysql_real_escape_string($excerpt).'\',
1101 blog_name = \''.mysql_real_escape_string($blog_name).'\',
1102 timestamp = '.mysqldate($b->getCorrectTime()).'
1104 url = \''.mysql_real_escape_string($url).'\' AND
1105 tb_id = \''.mysql_real_escape_string(intval($tb_id)).'\'
1107 //modify end+++++++++
1110 return 'Could not update trackback data: '.mysql_error();
1117 $res = @sql_query('SELECT id FROM '.sql_table('plugin_tb').' WHERE block = 1 and url = \''.mysql_real_escape_string($url).'\'' );
1118 if (mysql_num_rows($res) != 0) {
1119 // NP_Trackback has blocked tb !
1120 ACTIONLOG :: add(INFO, "Trackback: Duplicated Blocked Trackback [ignore] (itemid:$tb_id from: $url)");
1121 return 'Sorry, trackback ping is not accepted.';
1125 // 4. SPAM check (for SpamCheck API 2 /w compat. API 1)
1126 $spamcheck = array (
1127 'type' => 'trackback',
1130 'excerpt' => $excerpt,
1131 'blogname' => $blog_name,
1136 /* Backwards compatibility with SpamCheck API 1*/
1137 'data' => $url . "\n" . $title . "\n" . $excerpt . "\n" . $blog_name . "\n" . serverVar('HTTP_USER_AGENT'),
1141 $manager->notify('SpamCheck', array ('spamcheck' => & $spamcheck));
1143 if (isset($spamcheck['result']) && $spamcheck['result'] == true)
1148 // 5. Content check (TO DO)
1149 if($spam == false || $enableLinkCheck == 'ignore' ) //modify
1152 // $contents = $this->retrieveUrl ($url);
1154 // if (preg_match("/(".preg_quote($_SERVER["REQUEST_URI"], '/').")|(".preg_quote($_SERVER["SERVER_NAME"], '/').")/i", $contents)) {
1157 if( $enableLinkCheck ){
1158 $contents = $this->retrieveUrl($url);
1160 $linkArray = $this->getPermaLinksFromText($contents);
1161 $itemLink = $this->_createItemLink($tb_id, $b);
1162 $itemLinkPat = '{^' . preg_quote($itemLink) .'}i';
1163 $itemLinkPat = str_replace('&','&(amp;)?', $itemLinkPat);
1165 foreach($linkArray as $l) {
1166 if(preg_match($itemLinkPat, $l)){
1167 ACTIONLOG :: add(INFO, "Trackback: LinkCheck OK. (link: $l pat: $itemLinkPat )");
1173 $cnt = @count($linkArray);
1174 if( $enableLinkCheck == 'ignore' ){
1175 ACTIONLOG :: add(INFO, "Trackback: LinkCheck NG. [ignore] (itemid:$tb_id from: $url cnt: $cnt pat: $itemLinkPat)");
1176 return 'Sorry, trackback ping is not accepted.';
1178 ACTIONLOG :: add(INFO, "Trackback: LinkCheck NG. [block] (itemid:$tb_id from: $url cnt: $cnt pat: $itemLinkPat");
1185 // 6. Determine if Trackback is safe...
1186 //modify start+++++++++
1187 // $block = $spam == true || $link == false;
1188 // $block = $spam == true ;
1189 //modify end+++++++++
1191 if ( $enableLinkCheck )
1192 $block = ($spam == true || $link == false);
1194 $block = $spam == true ;
1196 // New TB, insert it
1200 '.sql_table('plugin_tb').'
1202 tb_id = "'.$tb_id.'",
1203 block = "'.($block ? '1' : '0').'",
1204 spam = "'.($spam ? '1' : '0').'",
1205 link = "'.($link ? '1' : '0').'",
1206 url = "'.mysql_real_escape_string($url).'",
1207 title = "'.mysql_real_escape_string($title).'",
1208 excerpt = "'.mysql_real_escape_string($excerpt).'",
1209 blog_name = "'.mysql_real_escape_string($blog_name).'",
1210 timestamp = '.mysqldate(time()).'
1213 //modify start+++++++++
1216 '.sql_table('plugin_tb').'
1218 tb_id = \''.mysql_real_escape_string(intval($tb_id)).'\',
1219 block = \''.($block ? '1' : '0').'\',
1220 spam = \''.($spam ? '1' : '0').'\',
1221 link = \''.($link ? '1' : '0').'\',
1222 url = \''.mysql_real_escape_string($url).'\',
1223 title = \''.mysql_real_escape_string($title).'\',
1224 excerpt = \''.mysql_real_escape_string($excerpt).'\',
1225 blog_name = \''.mysql_real_escape_string($blog_name).'\',
1226 timestamp = '.mysqldate($b->getCorrectTime()).'
1228 //modify end+++++++++
1230 $res = @sql_query($query);
1233 return 'Could not save trackback data, possibly because of a double entry: ' . mysql_error() . $query;
1237 // 7. Send notification e-mail if needed
1238 $notifyAddrs = $this->getOption('NotifyEmail');
1239 $notifyAddrs = ( $notifyAddrs ? $notifyAddrs . ';' : '')
1240 . $this->getBlogOption($blogId ,'NotifyEmailBlog');
1242 if ($notifyAddrs && $spam == false)
1249 'excerpt' => $excerpt,
1250 'blogname' => $blog_name
1253 //modify start+++++++++
1258 'title' => mb_convert_encoding($title, 'ISO-2022-JP', _CHARSET),
1259 'excerpt' => mb_convert_encoding($excerpt, 'ISO-2022-JP', _CHARSET),
1260 'blogname' => mb_convert_encoding($blog_name, 'ISO-2022-JP', _CHARSET)
1263 //maybe not needed because japanese version has "mb_send_mail" in function notify
1264 //modify end+++++++++
1266 $mailto_title = TEMPLATE::fill($this->notificationMailTitle, $vars);
1267 $mailto_msg = TEMPLATE::fill($this->notificationMail, $vars);
1269 global $CONF, $DIR_LIBS;
1271 // make sure notification class is loaded
1272 if (!class_exists('notification'))
1273 include($DIR_LIBS . 'NOTIFICATION.php');
1275 $notify = new NOTIFICATION($notifyAddrs);
1276 $notify->notify($mailto_title, $mailto_msg , $CONF['AdminEmail']);
1278 //mod by cles+++++++++++
1279 if ($manager->pluginInstalled('NP_Cache')){
1280 $p =& $manager->getPlugin('NP_Cache');
1281 $p->setCurrentBlog($tb_id);
1282 $p->cleanItem($tb_id);
1283 $p->cleanArray(array('index'));
1285 //mod by cles end +++++++++++
1289 return 'Sorry, trackback ping is not accepted.';
1293 function xmlResponse($errorMessage = '')
1295 header('Content-Type: text/xml');
1297 echo "<","?xml version='1.0' encoding='UTF-8'?",">\n";
1298 echo "<response>\n";
1301 echo "\t<error>1</error>\n\t<message>",htmlspecialchars($errorMessage, ENT_QUOTES),"</message>\n";
1303 echo "\t<error>0</error>\n";
1310 * Check if member may send ping (check if logged in)
1312 function canSendPing() {
1314 return $member->isLoggedIn() || $this->xmlrpc;
1319 function redirect($tb_id, $urlHash){
1321 $query = 'SELECT url FROM '.sql_table('plugin_tb').' WHERE tb_id='.intval($tb_id).' and md5(url)="'.$urlHash.'"';
1322 $res = sql_query($query);
1324 $url = $CONF['SiteURL'];
1326 if ($o = mysql_fetch_object($res)) {
1327 $url = htmlspecialchars($o->url, ENT_QUOTES);
1330 $url = stripslashes($url);
1331 $url = str_replace('&','&',$url);
1332 $url = str_replace('<','<',$url);
1333 $url = str_replace('>','>',$url);
1334 $url = str_replace('"','"',$url);
1336 header('Location: '.$url);
1339 function getRequiredURL($itemid){
1341 $blog = & $manager->getBlog(getBlogIDFromItemID($item['itemid']));
1342 if( $this->isEnableLinkCheck($itemid) )
1343 return $this->_createItemLink($itemid, $blog);
1347 function isEnableLinkCheck($itemid){
1348 $blogid = getBlogIDFromItemID($itemid);
1350 switch( $this->getItemOption($itemid, 'isAcceptW/OLink') ){
1352 $def = $this->getBlogOption($blogid, 'isAcceptW/OLinkDef');
1356 return $def; // block or ignore
1362 ACTIONLOG :: add(INFO, "Trackback: Unknown Option (itemid:$itemid, value:$val)");
1367 var $acceptTrackbacks = array();
1368 function isAcceptTrackBack($itemid = null){
1369 if( $itemid && isset($acceptTrackbacks[$itemid]) )
1370 return $acceptTrackbacks[$itemid] === true;
1373 if( $this->getOption('AcceptPing') == 'yes' ){
1376 $bid = getBlogIDFromItemID(intval($itemid));
1379 $bid = $blog->getID();
1382 if( $this->getBlogOption($bid, "AllowTrackBack") == 'yes' ){
1384 $ret = ( $this->getItemOption(intval($itemid), 'ItemAcceptPing') == 'yes' ) ? true : false ;
1393 $acceptTrackbacks[$itemid] = $ret;
1394 return $ret === true;
1399 /**************************************************************************************
1403 function event_SendTrackback($data) {
1406 // Enable sending trackbacks for the XML-RPC API, otherwise we would
1407 // get an error because the current user is not exactly logged in.
1408 $this->xmlrpc = true;
1410 $itemid = $data['tb_id'];
1411 $item = &$manager->getItem($itemid, 0, 0);
1412 if (!$item) return; // don't ping for draft & future
1413 if ($item['draft']) return; // don't ping on draft items
1415 // gather some more information, needed to send the ping (blog name, etc)
1416 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
1417 $blog_name = $blog->getName();
1419 $title = $data['title'] != '' ? $data['title'] : $item['title'];
1420 $title = strip_tags($title);
1422 $excerpt = $data['body'] != '' ? $data['body'] : $item['body'];
1423 $excerpt = strip_tags($excerpt);
1424 $excerpt = $this->_cut_string($excerpt, 200);
1426 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
1427 //$url = createItemLink($itemid);
1428 $url = $this->_createItemLink($itemid, $blog);
1430 while (list(,$url) = each($data['urls'])) {
1431 $res = $this->sendPing($itemid, $title, $url, $excerpt, $blog_name, $url);
1432 if ($res) ACTIONLOG::add(WARNING, 'TrackBack Error:' . $res . ' (' . $url . ')');
1436 function event_RetrieveTrackback($data) {
1442 UNIX_TIMESTAMP(timestamp) AS timestamp
1444 '.sql_table('plugin_tb').'
1446 tb_id = '.intval($data['tb_id']).' AND
1452 while ($row = mysql_fetch_array($res)) {
1455 'title' => $row['title'],
1456 'url' => $row['url'],
1460 $data['trackbacks'][] = $trackback;
1464 function event_BookmarkletExtraHead($data) {
1466 list ($NP_TB_URL,) = $this->getURIfromLink(requestVar('loglink'));
1469 function event_PrepareItemForEdit($data) {
1470 // if (!$this->getOption('AutoXMLHttp'))
1471 if ($this->getOption('AutoXMLHttp') == 'no')
1473 // The space between body and more is to make sure we didn't join 2 words accidently....
1474 $this->larray = $this->autoDiscovery($data['item']['body'].' '.$data['item']['more']);
1479 * After an item has been added to the database, send out a ping if requested
1480 * (trackback_ping_url variable in request)
1482 function event_PostAddItem($data) {
1483 $this->pingTrackback($data);
1486 function event_PreUpdateItem($data) {
1487 $this->pingTrackback($data);
1491 * Add trackback options to add item form/bookmarklet
1493 function event_AddItemFormExtras($data) {
1495 // global $NP_TB_URL;
1500 <!--modify start+++++++++-->
1501 <!-- <label for="plug_tb_url">TrackBack Ping URL:</label>
1502 <input type="text" value="<?php if (isSet($NP_TB_URL)) {echo $NP_TB_URL;} ?>" id="plug_tb_url" name="trackback_ping_url" size="60" />
1504 <!--modify end+++++++++-->
1505 <label for="plug_tb_url">TrackBack URL:</label><br />
1506 <textarea id="plug_tb_url" name="trackback_ping_url" cols="60" rows="5" style="font:normal xx-small Tahoma, Arial, verdana ;"></textarea>
1507 <input type="button" name="btnAdd" value="<?php echo _TB_LIST_IT?>" onClick="AddStart()" />
1512 // if ($this->getOption('AutoXMLHttp'))
1513 if ($this->getOption('AutoXMLHttp') == 'yes')
1517 <input type="button" name="discoverit" value="Auto Discover" onclick="tbSetup();" />
1518 <img id='tb_busy' src='<?php echo $this->getAdminURL(); ?>busy.gif' style="display:none;" /><br />
1519 <div id="tb_auto_title"></div>
1520 <table border="1"><tbody id="tb_ping_list"></tbody></table>
1521 <input type="hidden" id="tb_url_amount" name="tb_url_amount" value="0" />
1525 $this->jsautodiscovery();
1533 * Add trackback options to edit item form/bookmarklet
1535 function event_EditItemFormExtras($data) {
1538 <!-- <input type="text" value="" id="plug_tb_url" name="trackback_ping_url" size="60" /><br />-->
1541 <label for="plug_tb_url">TrackBack URL:</label><br />
1542 <textarea id="plug_tb_url" name="trackback_ping_url" cols="60" rows="5" style="font:normal xx-small Tahoma, Arial, verdana ;"></textarea>
1543 <input type="button" name="btnAdd" value="<?php echo _TB_LIST_IT?>" onClick="AddStart()" />
1546 // if ($this->getOption('AutoXMLHttp'))
1547 if ($this->getOption('AutoXMLHttp') == 'yes')
1553 <input type="button" name="discoverit" value="Auto Discover" onclick="tbSetup();" />
1554 <img id='tb_busy' src='<?php echo $this->getAdminURL(); ?>busy.gif' style="display:none;" /><br />
1555 <div id="tb_auto_title"></div>
1556 <table border="1"><tbody id="tb_ping_list"></tbody></table>
1557 <input type="hidden" id="tb_url_amount" name="tb_url_amount" value="0" />
1561 $this->jsautodiscovery();
1565 if (count($this->larray) > 0)
1568 Auto Discovered Ping URL's:<br />
1570 echo '<input type="hidden" name="tb_url_amount" value="'.count($this->larray).'" />';
1574 while (list($url, $title) = each ($this->larray))
1576 //modify start+++++++++
1577 if (_CHARSET != 'UTF-8') {
1578 $title = $this->_utf8_to_entities($title);
1579 $title = mb_convert_encoding($title, _CHARSET, 'UTF-8');
1581 //modify end+++++++++
1583 echo '<input type="checkbox" name="tb_url_'.$i.
1584 '" value="'.$url.'" id="tb_url_'.$i.
1585 '" /><label for="tb_url_'.$i.'" title="'.$url.'">'.$title.'</label><br />';
1597 * Insert Javascript AutoDiscovery routines
1599 function jsautodiscovery()
1604 <script type='text/javascript' src='<?php echo $this->getAdminURL(); ?>autodetect.php'></script>
1611 function pingTrackback($data) {
1612 global $manager, $CONF;
1614 $ping_urls_count = 0;
1615 $ping_urls = array();
1616 $utf8flag = array();
1617 $localflag = array();
1619 $ping_url = requestVar('trackback_ping_url');
1620 //modify start+++++++++
1623 $ping_urls[0] = $ping_url;
1627 if (trim($ping_url)) {
1628 $ping_urlsTemp = array();
1629 $ping_urlsTemp = preg_split("/[\s,]+/", trim($ping_url));
1630 for($i=0;$i<count($ping_urlsTemp);$i++){
1631 $ping_urls[] = trim($ping_urlsTemp[$i]);
1635 //modify end+++++++++
1637 $tb_url_amount = requestVar('tb_url_amount');
1638 for ($i=0;$i<$tb_url_amount;$i++) {
1639 $tb_temp_url = requestVar('tb_url_'.$i);
1641 $ping_urls[$ping_urls_count] = $tb_temp_url;
1642 $utf8flag[$ping_urls_count] = (requestVar('tb_url_'.$i.'_utf8') == 'on')? 1: 0;
1643 $localflag[$ping_urls_count] = (requestVar('tb_url_'.$i.'_local') == 'on')? 1: 0;
1648 if ($ping_urls_count <= 0) {
1652 $itemid = $data['itemid'];
1653 $item = &$manager->getItem($itemid, 0, 0);
1654 if (!$item) return; // don't ping for draft & future
1655 if ($item['draft']) return; // don't ping on draft items
1657 // gather some more information, needed to send the ping (blog name, etc)
1658 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
1659 $blog_name = $blog->getName();
1661 $title = $data['title'] != '' ? $data['title'] : $item['title'];
1662 $title = strip_tags($title);
1664 $excerpt = $data['body'] != '' ? $data['body'] : $item['body'];
1665 $excerpt = strip_tags($excerpt);
1666 $excerpt = $this->_cut_string($excerpt, 200);
1669 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
1670 $url = createItemLink($itemid);
1672 $url = $this->_createItemLink($item['itemid'],$blog);
1674 // send the ping(s) (add errors to actionlog)
1675 for ($i=0; $i<count($ping_urls); $i++) {
1676 if( ! $localflag[$i] )
1677 $res = $this->sendPing($itemid, $title, $url, $excerpt, $blog_name, $ping_urls[$i], $utf8flag[$i]);
1679 $res = $this->handleLocalPing($itemid, $title, $excerpt, $blog_name, $ping_urls[$i]);
1680 if ($res) ACTIONLOG::add(WARNING, 'TrackBack Error:' . $res . ' (' . $ping_urls[$i] . ')');
1687 /**************************************************************************************
1692 * Auto-Discovery of TrackBack Ping URLs based on HTML story
1694 function autoDiscovery($text)
1696 $links = $this->getPermaLinksFromText($text);
1699 for ($i = 0; $i < count($links); $i++)
1701 list ($url, $title) = $this->getURIfromLink($links[$i]);
1704 $result[$url] = $title;
1711 * Auto-Discovery of TrackBack Ping URLs based on single link
1713 function getURIfromLink($link)
1716 // Check to see if the cache contains this link
1717 $res = sql_query('SELECT url, title FROM '.sql_table('plugin_tb_lookup').' WHERE link=\''.mysql_real_escape_string($link).'\'');
1719 if ($row = mysql_fetch_array($res))
1721 if ($row['title'] != '')
1723 //modify start+++++++++
1724 if (_CHARSET != 'UTF-8'){
1725 $row['title'] = mb_convert_encoding($row['title'], 'UTF-8', _CHARSET);
1726 $row['title'] = $this->_decode_entities($row['title']);
1728 //modify end+++++++++
1730 $row['url'], $row['title']
1736 $row['url'], $row['url']
1742 if (($rdf = $this->getRDFFromLink($link)) !== false)
1744 // Get PING attribute
1745 if (($uri = $this->getAttributeFromRDF($rdf, 'trackback:ping')) !== false)
1747 // Get TITLE attribute
1748 if (($title = $this->getAttributeFromRDF($rdf, 'dc:title')) !== false)
1750 // Get CREATOR attribute
1751 if (($author = $this->getAttributeFromRDF($rdf, 'dc:creator')) !== false)
1753 $title = $author. ": " . $title;
1756 $uri = $this->_decode_entities($uri);
1757 //modify start+++++++++
1758 if (_CHARSET != 'UTF-8')
1759 $convertedTitle = mb_convert_encoding($title, _CHARSET, 'UTF-8');
1761 $convertedTitle = $title;
1764 $res = sql_query("INSERT INTO ".sql_table('plugin_tb_lookup')." (link, url, title) VALUES ('".mysql_real_escape_string($link)."','".mysql_real_escape_string($uri)."','".mysql_real_escape_string($title)."')");
1767 $res = sql_query("INSERT INTO ".sql_table('plugin_tb_lookup')." (link, url, title) VALUES ('".mysql_real_escape_string($link)."','".mysql_real_escape_string($uri)."','".mysql_real_escape_string($convertedTitle)."')");
1768 //modify end+++++++++
1769 $title = $this->_decode_entities($title);
1777 $uri = html_entity_decode($uri, ENT_COMPAT);
1780 $res = sql_query("INSERT INTO ".sql_table('plugin_tb_lookup')." (link, url, title) VALUES ('".mysql_real_escape_string($link)."','".mysql_real_escape_string($uri)."','')");
1790 $res = sql_query("INSERT INTO ".sql_table('plugin_tb_lookup')." (link, url, title) VALUES ('".mysql_real_escape_string($link)."','','')");
1792 return array ('', '');
1796 * Detect links used in HTML code
1798 function getPermaLinksFromText($text)
1802 if (preg_match_all('/<[aA] +([^>]+)>/', $text, $array, PREG_SET_ORDER))
1804 for ($i = 0; $i < count($array); $i++)
1806 if( preg_match('/s?https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:@&=+$,%#]+/', $array[$i][1], $matches) )
1807 $links[$matches[0]] = 1;
1811 return array_keys($links);
1815 * Retrieve RDF code from external link
1817 function getRDFFromLink($link)
1819 if ($content = $this->getContents($link))
1821 preg_match_all('/(<rdf:RDF.*?<\/rdf:RDF>)/sm', $content, $rdfs, PREG_SET_ORDER);
1823 if (count($rdfs) > 1)
1825 for ($i = 0; $i < count($rdfs); $i++)
1827 if (preg_match('|dc:identifier="'.preg_quote($link).'"|ms',$rdfs[$i][1]))
1829 return $rdfs[$i][1];
1835 // No need to check the identifier
1844 * Retrieve the contents of an external (X)HTML document
1846 function getContents($link) {
1848 // Use cURL extention if available
1849 if (function_exists("curl_init") && $this->useCurl == 2)
1851 // Make HEAD request
1853 @curl_setopt($ch, CURLOPT_URL, $link);
1854 @curl_setopt($ch, CURLOPT_HEADER, true);
1855 @curl_setopt($ch, CURLOPT_NOBODY, true);
1856 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
1857 @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
1858 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1859 @curl_setopt($ch, CURLOPT_TIMEOUT, 20);
1860 @curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
1862 $headers = curl_exec($ch);
1865 // Check if the link points to a (X)HTML document
1866 if (preg_match('/Content-Type: (text\/html|application\/xhtml+xml)/i', $headers))
1868 return $this->retrieveUrl ($link);
1875 return $this->retrieveUrl ($link);
1880 * Get a single attribute from RDF
1882 function getAttributeFromRDF($rdf, $attribute)
1884 if (preg_match('/'.$attribute.'="([^"]+)"/', $rdf, $matches))
1897 /**************************************************************************************/
1898 /* Internal helper functions for dealing with external file retrieval */
1900 function retrieveUrl ($url) {
1902 $ua = ini_set('user_agent', $this->userAgent);
1904 if (function_exists('curl_init') && $this->useCurl > 0)
1908 @curl_setopt($ch, CURLOPT_URL, $url);
1909 @curl_setopt($ch, CURLOPT_HEADER, 1);
1910 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1911 @curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
1912 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
1913 @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
1914 @curl_setopt($ch, CURLOPT_TIMEOUT, 20);
1915 @curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
1917 // Retrieve response
1918 $raw = curl_exec($ch);
1919 $info = curl_getinfo($ch);
1921 // Split into headers and contents
1922 $headers = substr($raw, 0, $info['header_size']);
1923 $contents = substr($raw, $info['header_size']);
1927 elseif ($fp = @fopen ($url, "r"))
1930 // $contents = fread($fp, 8192);
1932 while (!feof($fp)) {
1933 $contents .= fread($fp, 8192);
1941 ini_set('user_agent', $ua);
1944 // Next normalize the encoding to UTF8...
1945 $contents = $this->_convert_to_utf8_auto($contents, $headers);
1951 /**************************************************************************************/
1952 /* Internal helper functions for dealing with encodings and entities */
1954 var $entities_default = array (
1955 '"' => '"',
1957 ''' => ''',
1962 //modify start+++++++++
1963 function _restore_to_utf8($contents)
1965 if (_CHARSET != 'UTF-8')
1967 $contents = mb_convert_encoding($contents, 'UTF-8', _CHARSET);
1969 $contents = $this->_decode_entities(strip_tags($contents));
1972 //modify end+++++++++
1973 function _detect_encoding($string)
1975 //modify start+++++++++
1976 if (function_exists('mb_convert_encoding')) {
1977 $encoding = (preg_match ("/;\s*charset=([^\n]+)/is", serverVar("CONTENT_TYPE"), $regs))?
1978 strtoupper(trim($regs[1])):
1981 if ( ($encoding !="") && ((mb_http_input("P") == "") || ( strtolower( ini_get("mbstring.http_input") ) == "pass")) ) {
1984 $encoding = mb_detect_encoding($string, 'UTF-8,EUC-JP,SJIS,ISO-8859-1,ASCII,JIS');
1986 return ( $encoding ) ? $encoding : 'ISO-8859-1';
1988 //modify end+++++++++
1989 if (!ereg("[\x80-\xFF]", $string) && !ereg("\x1B", $string))
1992 if (!ereg("[\x80-\xFF]", $string) && ereg("\x1B", $string))
1993 return 'ISO-2022-JP';
1995 if (preg_match("/^([\x01-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF][\x80-\xBF])+$/", $string) == 1)
1998 if (preg_match("/^([\x01-\x7F]|\x8E[\xA0-\xDF]|\x8F[xA1-\xFE][\xA1-\xFE]|[\xA1-\xFE][\xA1-\xFE])+$/", $string) == 1)
2001 if (preg_match("/^([\x01-\x7F]|[\xA0-\xDF]|[\x81-\xFC][\x40-\xFC])+$/", $string) == 1)
2004 return 'ISO-8859-1';
2007 function _convert_to_utf8($contents, $encoding)
2011 //modify start+++++++++
2012 // if (!$done && function_exists('iconv'))
2015 // $result = @iconv($encoding, 'UTF-8//IGNORE', $contents);
2019 // $contents = $result;
2024 if(!$done && function_exists('mb_convert_encoding'))
2027 if( function_exists('mb_substitute_character') ){
2028 @mb_substitute_character('none');
2030 $result = @mb_convert_encoding($contents, 'UTF-8', $encoding );
2034 $contents = $result;
2039 if (!$done && function_exists('iconv'))
2042 $result = @iconv($encoding, 'UTF-8//IGNORE', $contents);
2046 $contents = $result;
2050 //modify end+++++++++
2054 function _convert_to_utf8_auto($contents, $headers = '')
2056 /* IN: string in unknown encoding, headers received during transfer
2057 * OUT: string in UTF-8 encoding
2060 $str = substr($contents, 0, 4096);
2061 $len = strlen($str);
2067 $ord = ord($str[$pos]);
2069 if ($ord > 32 && $ord < 128)
2075 // Detection of encoding, check headers
2076 if (preg_match ("/;\s*charset=([^\n]+)/is", $headers, $regs))
2077 $encoding = strtoupper(trim($regs[1]));
2079 // Then check meta inside document
2080 if (preg_match ("/;\s*charset=([^\"']+)/is", $out, $regs))
2081 $encoding = strtoupper(trim($regs[1]));
2083 // Then check xml declaration
2084 if (preg_match("/<\?xml.+encoding\s*=\s*[\"|']([^\"']+)[\"|']\s*\?>/i", $out, $regs))
2085 $encoding = strtoupper(trim($regs[1]));
2088 return $this->_convert_to_utf8($contents, $encoding);
2091 function _decode_entities($string)
2093 /* IN: string in UTF-8 containing entities
2094 * OUT: string in UTF-8 without entities
2097 /// Convert all hexadecimal entities to decimal entities
2098 $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', "'&#'.hexdec('\\1').';'", $string);
2101 // Deal with invalid cp1251 numeric entities
2102 $string = strtr($string, $_entities['cp1251']);
2104 // Convert all named entities to numeric entities
2105 $string = strtr($string, $this->entities_default);
2106 $string = strtr($string, $_entities['named']);
2108 // Convert all numeric entities to UTF-8
2109 $string = preg_replace('/&#([0-9]+);/e', "'&#x'.dechex('\\1').';'", $string);
2110 $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', "NP_TrackBack::_hex_to_utf8('\\1')", $string);
2115 function _hex_to_utf8($s){
2116 return entity::_hex_to_utf8($s);
2119 function _utf8_to_entities($string)
2121 /* IN: string in UTF-8 encoding
2122 * OUT: string consisting of only characters ranging from 0x00 to 0x7f,
2123 * using numeric entities to represent the other characters
2126 $len = strlen ($string);
2132 $ascii = ord (substr ($string, $pos, 1));
2136 $byte[1] = ord(substr ($string, $pos, 1)) - 0xF0;
2137 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2138 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2139 $byte[4] = ord(substr ($string, $pos + 3, 1)) - 0x80;
2141 $char_code = ($byte[1] << 18) + ($byte[2] << 12) + ($byte[3] << 6) + $byte[4];
2144 elseif (($ascii >= 0xE0) && ($ascii < 0xF0))
2146 $byte[1] = ord(substr ($string, $pos, 1)) - 0xE0;
2147 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2148 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2150 $char_code = ($byte[1] << 12) + ($byte[2] << 6) + $byte[3];
2153 elseif (($ascii >= 0xC0) && ($ascii < 0xE0))
2155 $byte[1] = ord(substr ($string, $pos, 1)) - 0xC0;
2156 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2158 $char_code = ($byte[1] << 6) + $byte[2];
2163 $char_code = ord(substr ($string, $pos, 1));
2167 if ($char_code < 0x80)
2168 $out .= chr($char_code);
2170 $out .= '&#'. str_pad($char_code, 5, '0', STR_PAD_LEFT) . ';';
2176 function _utf8_to_javascript($string)
2178 /* IN: string in UTF-8 encoding
2179 * OUT: string consisting of only characters ranging from 0x00 to 0x7f,
2180 * using javascript escapes to represent the other characters
2183 $len = strlen ($string);
2189 $ascii = ord (substr ($string, $pos, 1));
2193 $byte[1] = ord(substr ($string, $pos, 1)) - 0xF0;
2194 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2195 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2196 $byte[4] = ord(substr ($string, $pos + 3, 1)) - 0x80;
2198 $char_code = ($byte[1] << 18) + ($byte[2] << 12) + ($byte[3] << 6) + $byte[4];
2201 elseif (($ascii >= 0xE0) && ($ascii < 0xF0))
2203 $byte[1] = ord(substr ($string, $pos, 1)) - 0xE0;
2204 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2205 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2207 $char_code = ($byte[1] << 12) + ($byte[2] << 6) + $byte[3];
2210 elseif (($ascii >= 0xC0) && ($ascii < 0xE0))
2212 $byte[1] = ord(substr ($string, $pos, 1)) - 0xC0;
2213 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2215 $char_code = ($byte[1] << 6) + $byte[2];
2220 $char_code = ord(substr ($string, $pos, 1));
2224 if ($char_code < 0x80)
2225 $out .= chr($char_code);
2227 $out .= '\\u'. str_pad(dechex($char_code), 4, '0', STR_PAD_LEFT);
2233 function _cut_string($string, $dl = 0) {
2235 $defaultLength = $dl > 0 ? $dl : $this->getOption('defaultLength');
2237 if ($defaultLength < 1)
2244 for ($i = 0; $i < strlen($string); $i++)
2246 $value = ord($string[$i]);
2250 if ($value >= 192 && $value <= 223)
2252 elseif ($value >= 224 && $value <= 239)
2254 elseif ($value >= 240 && $value <= 247)
2257 if ($lastvalue <= 223 && $value >= 223 &&
2258 $count >= $defaultLength - $border)
2260 return substr($string, 0, $i) . '...';
2263 // Chinese and Japanese characters are
2264 // wider than Latin characters
2269 elseif ($string[$i] == '/' || $string[$i] == '?' ||
2270 $string[$i] == '-' || $string[$i] == ':' ||
2271 $string[$i] == ',' || $string[$i] == ';')
2273 if ($count >= $defaultLength - $border)
2274 return substr($string, 0, $i) . '...';
2276 elseif ($string[$i] == ' ')
2278 if ($count >= $defaultLength - $border)
2279 return substr($string, 0, $i) . '...';
2282 if ($count == $defaultLength)
2283 return substr($string, 0, $i + 1) . '...';
2285 $lastvalue = $value;
2293 function _cut_string($string, $dl = 0) {
2294 $maxLength = $dl > 0 ? $dl : $this->getOption('defaultLength');
2298 if (strlen($string) > $maxLength)
2299 $string = mb_strimwidth($string, 0, $maxLength, '...', _CHARSET);
2304 function _strip_controlchar($string){
\r $string = preg_replace("/[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]+/","",$string);
2305 $string = str_replace("\0","",$string);
2309 //modify start+++++++++
2310 function checkTableVersion(){
2311 $res = sql_query("SHOW FIELDS from ".sql_table('plugin_tb') );
2312 $fieldnames = array();
2313 while ($co = mysql_fetch_assoc($res)) {
2314 if($co['Field'] == 'block') return true;
2318 //modify end+++++++++
2320 /*---------------------------------------------------------------------------------- */
2322 /*---------------------------------------------------------------------------------- */
2324 * Handle an incoming TrackBack ping and save the data in the database
2326 function handleLocalPing($itemid, $title, $excerpt, $blog_name, $ping_url){
2328 $ping_url = trim($ping_url);
2330 if( preg_match("/^.+tb_id=([0-9]+)$/",$ping_url,$idnum) ){
2331 $tb_id = intval($idnum[1]);
2332 } elseif ( preg_match("/([0-9]+)\.trackback/",$ping_url,$idnum) ){
2333 $tb_id = intval($idnum[1]);
2334 } elseif ( preg_match("/itemid=([0-9]+)/",$ping_url,$idnum) ){
2335 $tb_id = intval($idnum[1]);
2338 if ((!$manager->existsItem($tb_id,0,0)) && ($this->getOption('CheckIDs') == 'yes'))
2339 return _ERROR_NOSUCHITEM . "[ $tb_id ]";
2341 // save data in the DB
2342 $query = 'INSERT INTO ' . sql_table('plugin_tb_lc') . " (tb_id, from_id) VALUES ('".intval($tb_id)."','".intval($itemid)."')";
2343 $res = @sql_query($query);
2345 return 'Could not save trackback data, possibly because of a double entry: ' . mysql_error();
2349 * Show the list of TrackBack pings for a certain Trackback ID
2351 function showLocalList($tb_id) {
2352 global $CONF, $manager;
2355 $query = 'SELECT t.from_id as from_id , i.ititle as ititle, i.ibody as ibody, i.itime as itime, i.iblog as iblog FROM '.sql_table('plugin_tb_lc').' as t, '.sql_table('item').' as i WHERE t.tb_id='.intval($tb_id) .' and i.inumber=t.from_id ORDER BY i.itime DESC';
2356 $res = sql_query($query);
2359 'tburl' => $this->getTrackBackUrl($tb_id)
2362 // when no TrackBack pings are found
2363 if (!$res || mysql_num_rows($res) == 0) {
2364 echo TEMPLATE::fill($this->getOption('tplLocalEmpty'), $vars);
2368 // when TrackBack pings are found
2369 echo TEMPLATE::fill($this->getOption('tplLocalHeader'), $vars);
2371 while ($o = mysql_fetch_object($res)) {
2372 $canDelete = $this->canDelete($tb_id);
2374 'url' => createItemLink($o->from_id),
2375 'blogname' => htmlspecialchars(getBlogNameFromID($o->iblog)),
2376 'timestamp' => strftime('%Y-%m-%d',strtotime($o->itime)),
2377 'title' => htmlspecialchars($o->ititle),
2378 'excerpt' => htmlspecialchars(shorten(strip_tags($o->ibody),200,'...')),
2379 'delete' => $canDelete?'<a href="'. $manager->addTicketToUrl($CONF['ActionURL'].'?action=plugin&name=TrackBack&type=deletelc&tb_id='.intval($tb_id).'&from_id='.intval($o->from_id)).'">[delete]</a>':'',
2380 'tburl' => $this->getTrackBackUrl($tb_id),
2381 'commentcount'=> quickQuery('SELECT COUNT(*) as result FROM '.sql_table('comment').' WHERE citem=' . intval($o->from_id))
2383 echo TEMPLATE::fill($this->getOption('tplLocalItem'), $data);
2385 echo TEMPLATE::fill($this->getOption('tplLocalFooter'), $vars);
2389 * Delete a TrackBack item, redirect to referer
2391 function deleteLocal($tb_id, $from_id) {
2392 if (!$this->canDelete($tb_id))
2393 return 'You\'re not allowed to delete this trackback item';
2394 $query = 'DELETE FROM ' . sql_table('plugin_tb_lc') . " WHERE tb_id='" . intval($tb_id) . "' and from_id='" . intval($from_id) ."'";
2399 function canDelete($tb_id) {
2400 global $member, $manager;
2402 if ( ! $member->isLoggedIn() ) return 0;
2404 $checkIDs = $this->getOption('CheckIDs');
2405 $itemExists =& $manager->existsItem($tb_id,0,0);
2407 // if CheckIDs option is set, check if member canEdit($tb_id)
2408 // if CheckIDs option is not set, and item exists, check if member canEdit($tb_id)
2409 // if CheckIDs option is not set, and item does not exists, check if member isAdmin()
2411 if (($checkIDs == 'yes') || ($itemExists))
2412 return $member->canAlterItem($tb_id);
2414 return $member->isAdmin();
2417 /**************************************************************************************/
2418 /* Plugin API calls, for installation, configuration and setup */
2420 function getName() { return 'TrackBack'; }
2421 function getAuthor() { return 'rakaz + nakahara21 + hsur'; }
2422 function getURL() { return 'http://blog.cles.jp/np_cles/category/31/subcatid/3'; }
2423 function getVersion() { return '2.0.3 jp10'; }
2424 function getDescription() { return _TB_DESCRIPTION; }
2426 //modify start+++++++++
2428 function getTableList() { return array(sql_table("plugin_tb"), sql_table("plugin_tb_lookup")); }
2429 function getEventList() { return array('QuickMenu','PostAddItem','AddItemFormExtras','EditItemFormExtras','PreUpdateItem','PrepareItemForEdit', 'BookmarkletExtraHead'); }
2431 function getTableList() { return array(sql_table("plugin_tb"), sql_table("plugin_tb_lookup"), sql_table('plugin_tb_lc')); }
2433 function getEventList() { return array('QuickMenu','PostAddItem','AddItemFormExtras','EditItemFormExtras','PreUpdateItem','PrepareItemForEdit', 'BookmarkletExtraHead', 'RetrieveTrackback', 'SendTrackback', 'InitSkinParse'); }
2434 //modify end+++++++++
2435 function getMinNucleusVersion() { return 330; }
2437 function supportsFeature($feature) {
2439 case 'SqlTablePrefix':
2441 //modify start+++++++++
2444 //modify end+++++++++
2451 function hasAdminArea() { return 1; }
2453 function event_QuickMenu(&$data) {
2454 global $member, $nucleus, $blogid;
2456 // only show to admins
2457 if (!$member->isLoggedIn() || !$member->isAdmin()) return;
2462 'title' => 'Trackback',
2463 'url' => $this->getAdminURL(),
2464 'tooltip' => 'Manage your trackbacks'
2469 function install() {
2470 $this->createOption('AcceptPing', _TB_AcceptPing,'yesno','yes');
2471 $this->createOption('SendPings', _TB_SendPings,'yesno','yes');
2472 $this->createOption('AutoXMLHttp', _TB_AutoXMLHttp, 'yesno', 'yes');
2473 $this->createOption('CheckIDs', _TB_CheckIDs,'yesno','yes');
2475 $this->createOption('tplHeader', _TB_tplHeader, 'textarea', _TB_tplHeader_VAL);
2476 $this->createOption('tplEmpty', _TB_tplEmpty, 'textarea', _TB_tplEmpty_VAL);
2477 $this->createOption('tplItem', _TB_tplItem, 'textarea', _TB_tplItem_VAL);
2478 $this->createOption('tplFooter', _TB_tplFooter, 'textarea', _TB_tplFooter_VAL);
2480 $this->createOption('tplLocalHeader', _TB_tplLocalHeader, 'textarea', _TB_tplLocalHeader_VAL);
2481 $this->createOption('tplLocalEmpty', _TB_tplLocalEmpty, 'textarea', _TB_tplLocalEmpty_VAL);
2482 $this->createOption('tplLocalItem', _TB_tplLocalItem, 'textarea', _TB_tplLocalItem_VAL);
2483 $this->createOption('tplLocalFooter', _TB_tplLocalFooter, 'textarea', _TB_tplLocalFooter_VAL);
2486 $this->createOption('tplTbNone', _TB_tplTbNone, 'text', "No Trackbacks");
2487 $this->createOption('tplTbOne', _TB_tplTbOne, 'text', "1 Trackback");
2488 $this->createOption('tplTbMore', _TB_tplTbMore, 'text', "<%number%> Trackbacks");
2489 $this->createOption('dateFormat', _TB_dateFormat, 'text', _TB_dateFormat_VAL);
2491 $this->createOption('NotifyEmail', _TB_NotifyEmail,'text','');
2492 $this->createOption('DropTable', _TB_DropTable,'yesno','no');
2494 $this->createOption('HideUrl',_TB_HideUrl,'yesno','yes');
2495 $this->createOption('ajaxEnabled',_TB_ajaxEnabled,'yesno','no');
2497 $this->createItemOption('ItemAcceptPing',_TB_ItemAcceptPing,'yesno','yes');
2498 $this->createItemOption('isAcceptW/OLink',_TB_isAcceptWOLink,'select','default', _TB_isAcceptWOLink_VAL);
2500 $this->createBlogOption('NotifyEmailBlog', _TB_NotifyEmailBlog,'text','');
2501 $this->createBlogOption('isAcceptW/OLinkDef',_TB_isAcceptWOLinkDef,'select','block', _TB_isAcceptWOLinkDef_VAL);
2502 $this->createBlogOption('AllowTrackBack',_TB_AllowTrackBack,'yesno','yes');
2507 CREATE TABLE IF NOT EXISTS
2508 ".sql_table('plugin_tb')."
2510 `id` INT(11) NOT NULL AUTO_INCREMENT,
2511 `tb_id` INT(11) NOT NULL,
2512 `url` TEXT NOT NULL,
2513 `block` TINYINT(4) NOT NULL,
2514 `spam` TINYINT(4) NOT NULL,
2515 `link` TINYINT(4) NOT NULL,
2519 `timestamp` DATETIME,
2526 CREATE TABLE IF NOT EXISTS
2527 ".sql_table('plugin_tb_lookup')."
2529 `link` TEXT NOT NULL,
2530 `url` TEXT NOT NULL,
2533 PRIMARY KEY (`link` (100))
2536 //modify start+++++++++
2537 @sql_query('ALTER TABLE `' . sql_table('plugin_tb') . '` ADD INDEX `tb_id_block_timestamp_idx` ( `tb_id`, `block`, `timestamp` DESC )');
2538 @sql_query('CREATE TABLE IF NOT EXISTS ' . sql_table('plugin_tb_lc'). ' (tb_id int(11) not null, from_id int(11) not null, PRIMARY KEY (tb_id,from_id))');
2539 //modify end+++++++++
2542 function uninstall() {
2543 if ($this->getOption('DropTable') == 'yes') {
2544 sql_query ('DROP TABLE '.sql_table('plugin_tb'));
2545 sql_query ('DROP TABLE '.sql_table('plugin_tb_lookup'));
2546 sql_query ("DROP table ".sql_table('plugin_tb_lc'));
2551 // include language file for this plugin
2552 $language = ereg_replace( '[\\|/]', '', getLanguageName());
2553 if (file_exists($this->getDirectory().'language/'.$language.'.php'))
2554 include_once($this->getDirectory().'language/'.$language.'.php');
2556 include_once($this->getDirectory().'language/'.'english.php');
2557 $this->notificationMail = _TB_NORTIFICATION_MAIL_BODY;
2558 $this->notificationMailTitle = _TB_NORTIFICATION_MAIL_TITLE;
2560 $this->userAgent = 'NucleusCMS NP_TrackBack plugin ( '.$this->getVersion().' )';