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 extends NucleusPlugin {
25 var $useCurl = 1; // use curl? 2:precheck+read by curl, 1: read by curl 0: fread
27 //modify start+++++++++
28 function _createItemLink($itemid, $b){
29 global $CONF, $manager;
30 $blogurl = $b->getURL();
34 $b_tmp =& $manager->getBlog($CONF['DefaultBlog']);
35 $blogurl = $b_tmp->getURL();
38 $blogurl = $CONF['IndexURL'];
39 if ($CONF['URLMode'] != 'pathinfo'){
40 $blogurl = $CONF['Self'];
44 if ($CONF['URLMode'] == 'pathinfo'){
45 if(substr($blogurl, -1) == '/') $blogurl = substr($blogurl,0,-1);
48 $itemUrlOrg = $CONF['ItemURL'];
49 $CONF['ItemURL'] = $blogurl;
50 $itemLink = createItemLink($itemid,'');
51 $CONF['ItemURL'] = $itemUrlOrg;
57 /**************************************************************************************
58 * SKIN VARS, TEMPLATE VARS AND ACTIONS
62 * TrackBack data can be inserted using skinvars (or templatevars)
64 function doSkinVar($skinType, $what = '', $tb_id = '', $amount = 'limit-1') {
66 global $itemid, $manager, $CONF;
68 //modify start+++++++++
69 if(eregi('limit', $tb_id)){
73 $amount = eregi_replace("limit", "", $amount);
74 $amount = intval($amount);
77 if ($tb_id == '') $tb_id = intval($itemid);
80 $isAcceptPing = $this->isAcceptTrackBack($tb_id);
82 //if( $skinType == 'template' && (! $isAcceptPing ) ){
88 // Insert Auto-discovery RDF code
92 // if($skinType == 'item')
104 /* Backwards compatibility with SpamCheck API 1*/
109 //$manager->notify('SpamCheck', array ('spamcheck' => & $spamcheck));
111 if (isset($spamcheck['result']) && $spamcheck['result'] == true){
115 if( ($skinType == 'item') && (!$spam) && $isAcceptPing )
117 $this->insertCode($tb_id);
120 // Insert TrackBack URL
124 // echo $this->getTrackBackUrl($tb_id);
126 echo $this->getTrackBackUrl($tb_id);
128 echo 'Sorry, no trackback pings are accepted.';
132 // Insert manual ping URL
134 case 'manualpingformlink':
135 echo $this->getManualPingUrl($tb_id);
139 echo $manager->addTicketToUrl($CONF['PluginURL'] . 'trackback/index.php?action=ping&id=' . intval($tb_id));
142 // Insert TrackBack count
144 $count = $this->getTrackBackCount($tb_id);
146 case 0: echo TEMPLATE::fill($this->getOption('tplTbNone'), array('number' => $count)); break;
147 case 1: echo TEMPLATE::fill($this->getOption('tplTbOne'), array('number' => $count)); break;
148 default: echo TEMPLATE::fill($this->getOption('tplTbMore'), array('number' => $count)); break;
152 // Shows the TrackBack list
155 //modify start+++++++++
156 // $this->showList($tb_id);
157 $this->showList($tb_id, $amount);
158 //modify end+++++++++
163 echo $this->getRequiredURL($tb_id);
166 // shows the Local list
168 $this->showLocalList($tb_id);
178 * When used in templates, the tb_id will be determined by the itemid there
180 function doTemplateVar(&$item, $what = '') {
181 $this->doSkinVar('template', $what, $item->itemid);
185 * A trackback ping is to be received on the URL
186 * http://yourdomain.com/item/1234.trackback
187 * Extra variables to be passed along are url, title, excerpt, blog_name
189 function event_InitSkinParse(&$data) {
190 global $CONF, $itemid;
191 $format = requestVar('format');
193 if ($CONF['URLMode'] == 'pathinfo') {
194 if (preg_match('/(\/|\.)(trackback)(\/|$)/', serverVar('PATH_INFO'), $matches)) {
195 $format = $matches[2];
199 if ($format == 'trackback' && $data['type'] == 'item')
201 $errorMsg = $this->handlePing(intval($itemid));
204 $this->xmlResponse($errorMsg);
206 $this->xmlResponse();
213 * A trackback ping is to be received on the URL
214 * http://yourdomain.com/action.php?action=plugin&name=TrackBack&tb_id=1234
215 * Extra variables to be passed along are url, title, excerpt, blog_name
217 function doAction($type)
219 global $CONF,$manager;
220 $aActionsNotToCheck = array(
227 if (!in_array($type, $aActionsNotToCheck)) {
228 if (!$manager->checkTicket()) return _ERROR_BADTICKET;
233 // When no action type is given, assume it's a ping
235 $errorMsg = $this->handlePing();
238 $this->xmlResponse($errorMsg);
240 $this->xmlResponse();
245 $errorMsg = $this->handlePing();
247 $this->showManualPingError(intRequestVar('tb_id'), $errorMsg);
249 $this->showManualPingSuccess(intRequestVar('tb_id'));
252 // Show manual ping form
255 // $this->showManualPingForm(intRequestVar('tb_id'));
256 $tb_id = intRequestVar('tb_id');
257 $isAcceptPing = $this->isAcceptTrackBack($tb_id);
260 $this->showManualPingForm($tb_id);
262 echo 'Sorry, no trackback pings are accepted.';
269 $this->getURIfromLink(html_entity_decode(requestVar('tb_link')));
271 $url = addslashes($url);
272 $url = $this->_utf8_to_javascript($url);
274 $title = addslashes($title);
275 $title = $this->_utf8_to_javascript($title);
277 echo "tbDone('" . requestVar('tb_link') . "', '" . $url . "', '" . $title . "');";
283 return $this->redirect(intRequestVar('tb_id'), requestVar('urlHash'));
287 echo $this->showLeftList(intRequestVar('tb_id'), intRequestVar('amount'));
290 // delete a trackback(local)
292 $err = $this->deleteLocal(intRequestVar('tb_id'), intRequestVar('from_id'));
295 header('Location: ' . serverVar('HTTP_REFERER'));
302 function doIf($key = '', $value = '')
305 //echo "key: $key, value: $value";
307 switch( strtolower($key) ){
310 if( $value == '' ) $value = 'yes';
311 $value = ( $value == 'no' || (! $value) ) ? false : true;
315 $ret = $this->isAcceptTrackBack($itemid);
317 $ret = $this->isAcceptTrackBack();
318 return ( $value == false ) ? (! $ret) : $ret;
321 if( $value == '' ) $value = 'yes';
322 $value = ( $value == 'no' || (! $value) ) ? false : true;
326 $ret = $this->isEnableLinkCheck($itemid);
328 return ( $value == false ) ? (! $ret) : $ret;
335 /**************************************************************************************
340 * Show a list of left trackbacks for this ID
342 function showLeftList($tb_id, $offset = 0, $amount = 99999999) {
343 global $manager, $blog, $CONF;
353 UNIX_TIMESTAMP(timestamp) AS timestamp
355 '.sql_table('plugin_tb').'
357 tb_id = '.intval($tb_id).' AND
363 $query .= ' LIMIT '.intval($offset).', ' .intval($amount);
364 $res = sql_query($query);
365 while ($row = mysql_fetch_array($res))
368 $row['blog_name'] = htmlspecialchars($row['blog_name'], ENT_QUOTES);
369 $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES);
370 $row['excerpt'] = htmlspecialchars($row['excerpt'], ENT_QUOTES);
371 if (_CHARSET != 'UTF-8') {
372 //modify start+++++++++
373 $row['blog_name'] = $this->_restore_to_utf8($row['blog_name']);
374 $row['title'] = $this->_restore_to_utf8($row['title']);
375 $row['excerpt'] = $this->_restore_to_utf8($row['excerpt']);
376 //modify end+++++++++
377 $row['blog_name'] = $this->_utf8_to_entities($row['blog_name']);
378 $row['title'] = $this->_utf8_to_entities($row['title']);
379 $row['excerpt'] = $this->_utf8_to_entities($row['excerpt']);
382 'action' => $this->getTrackBackUrl($tb_id),
383 'form' => $this->getManualPingUrl($tb_id),
384 'name' => $row['blog_name'],
385 'title' => $row['title'],
386 'excerpt' => $this->_cut_string($row['excerpt'], 400),
387 'url' => htmlspecialchars($row['url'], ENT_QUOTES),
388 'date' => htmlspecialchars(strftime($this->getOption('dateFormat'), $row['timestamp']), ENT_QUOTES)
392 if( $this->getOption('HideUrl') == 'yes' )
393 $iVars['url'] = $CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=redirect&tb_id=' . $tb_id . '&urlHash=' . $row['urlHash'];
395 $iVars['url'] = $row['url'];
398 $out[] = TEMPLATE::fill($this->getOption('tplItem'), $iVars);
400 mysql_free_result($res);
402 return @join("\n",$out);
406 * Show a list of all trackbacks for this ID
408 function showList($tb_id, $amount = 0) {
409 $tb_id = intval($tb_id);
410 global $manager, $blog, $CONF, $member;
412 $enableHideurl = true;
415 strstr(serverVar('HTTP_USER_AGENT'),'Hatena Diary Track Forward Agent')
416 || strstr(serverVar('HTTP_USER_AGENT'),'NP_TrackBack')
417 || strstr(serverVar('HTTP_USER_AGENT'),'TBPingLinkLookup')
418 || strstr(serverVar('HTTP_USER_AGENT'),'MT::Plugin::BanNoReferTb')
419 || strstr(serverVar('HTTP_USER_AGENT'),'livedoorBlog')
421 $enableHideurl = false;
434 UNIX_TIMESTAMP(timestamp) AS timestamp
436 '.sql_table('plugin_tb').'
438 tb_id = '.$tb_id .' AND
451 UNIX_TIMESTAMP(timestamp) AS timestamp
453 '.sql_table('plugin_tb').'
455 tb_id = '.intval($tb_id) .' AND
460 if( $amount == '-1' )
461 $query .= ' LIMIT 9999999';
463 $query .= ' LIMIT '.intval($amount);
466 $res = sql_query($query);
469 'action' => $this->getTrackBackUrl(intval($tb_id)),
470 'form' => $this->getManualPingUrl(intval($tb_id)),
471 'required' => $this->getRequiredURL(intval($tb_id)),
474 if ($member->isLoggedIn() && $member->isAdmin()){
475 $adminurl = htmlspecialchars($manager->addTicketToUrl($CONF['PluginURL'] . 'trackback/index.php?action=list&id=' . intval($tb_id)), ENT_QUOTES);
476 $pingformurl = htmlspecialchars($manager->addTicketToUrl($CONF['PluginURL'] . 'trackback/index.php?action=ping&id=' . intval($tb_id)), ENT_QUOTES);
477 $gVars['admin'] = '<a href="' . $adminurl . '" target="_blank">[admin]</a>';
478 $gVars['pingform'] = '<a href="' . $pingformurl . '" target="_blank">[pingform]</a>';
481 echo TEMPLATE::fill($this->getOption('tplHeader'), $gVars);
484 while ($amount != 0 && $row = mysql_fetch_array($res))
487 $row['blog_name'] = htmlspecialchars($row['blog_name'], ENT_QUOTES);
488 $row['title'] = htmlspecialchars($row['title'], ENT_QUOTES);
489 $row['excerpt'] = htmlspecialchars($row['excerpt'], ENT_QUOTES);
493 if (_CHARSET != 'UTF-8') {
494 //modify start+++++++++
496 $row['blog_name'] = $this->_utf8_to_entities($row['blog_name']);
497 $row['title'] = $this->_utf8_to_entities($row['title']);
498 $row['excerpt'] = $this->_utf8_to_entities($row['excerpt']);
500 $row['blog_name'] = $this->_restore_to_utf8($row['blog_name']);
501 $row['title'] = $this->_restore_to_utf8($row['title']);
502 $row['excerpt'] = $this->_restore_to_utf8($row['excerpt']);
504 $row['blog_name'] = mb_convert_encoding($row['blog_name'], _CHARSET, 'UTF-8');
505 $row['title'] = mb_convert_encoding($row['title'], _CHARSET, 'UTF-8');
506 $row['excerpt'] = mb_convert_encoding($row['excerpt'], _CHARSET, 'UTF-8');
507 //modify end+++++++++
510 //modify start+++++++++
513 'action' => $this->getTrackBackUrl($tb_id),
514 'form' => $this->getManualPingUrl($tb_id),
515 'name' => $row['blog_name'],
516 'title' => $row['title'],
517 'excerpt' => $row['excerpt'],
518 'url' => htmlspecialchars($row['url'], ENT_QUOTES),
519 'date' => htmlspecialchars(strftime($this->getOption('dateFormat'), $row['timestamp'] + ($blog->getTimeOffset() * 3600)), ENT_QUOTES)
523 'action' => $this->getTrackBackUrl($tb_id),
524 'form' => $this->getManualPingUrl($tb_id),
525 'name' => htmlspecialchars($row['blog_name'], ENT_QUOTES),
526 'title' => htmlspecialchars($row['title'], ENT_QUOTES),
527 'excerpt' => htmlspecialchars($this->_cut_string($row['excerpt'], 400), ENT_QUOTES),
528 'url' => htmlspecialchars($row['url'], ENT_QUOTES),
529 'date' => htmlspecialchars(strftime($this->getOption('dateFormat'), $row['timestamp']), ENT_QUOTES)
533 if( $enableHideurl && $this->getOption('HideUrl') == 'yes' )
534 $iVars['url'] = $CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=redirect&tb_id=' . intval($tb_id) . '&urlHash=' . $row['urlHash'];
536 $iVars['url'] = $row['url'];
539 //modify end+++++++++
540 echo TEMPLATE::fill($this->getOption('tplItem'), $iVars);
544 //modify start+++++++++
549 '.sql_table('plugin_tb').'
551 tb_id = '.intval($tb_id) .' AND
556 $result = sql_query($q);
557 $total = mysql_result($result,0,0);
559 if($amount != -1 && $total > $amount){
560 $leftcount = $total - $amount;
562 echo '<script type="text/javascript" src="' . $this->getAdminURL() . 'detectlist.php?tb_id='.intval($tb_id).'&amount='.intval($amount).'"></script>';
566 <a name="restoftrackback" id="restoftrackback"></a>
567 <div id="tbshownavi"><a href="#restoftrackback" onclick="resttbStart(); return false;" id="tbshow">Show left <?php echo $leftcount;?> Trackbacks</a></div>
568 <div id="tbhidenavi" style="display: none;"><a href="#restoftrackback" onclick="hideresttb(); return false;">Hide <?php echo $leftcount;?> Trackbacks</a></div>
569 <div id="resttb"></div>
573 //modify end+++++++++
575 if (mysql_num_rows($res) == 0)
577 echo TEMPLATE::fill($this->getOption('tplEmpty'), $gVars);
579 mysql_free_result($res);
581 echo TEMPLATE::fill($this->getOption('tplFooter'), $gVars);
586 * Returns the TrackBack count for a TrackBack item
588 function getTrackBackCount($tb_id) {
589 return quickQuery('SELECT COUNT(*) as result FROM ' . sql_table('plugin_tb') . ' WHERE tb_id='.intval($tb_id).' AND block = 0');
593 * Returns the manual ping URL
595 function getManualPingUrl($itemid) {
597 return $CONF['ActionURL'] . '?action=plugin&name=TrackBack&type=form&tb_id='.$itemid;
601 * Show the manual ping form
603 function showManualPingError($itemid, $status = '') {
606 $form = true; $error = true; $success = false;
607 sendContentType('text/html', 'admin-trackback', _CHARSET);
608 //modify start+++++++++
609 // include ($this->getDirectory() . '/templates/form.html');
610 require_once($this->getDirectory() . '/template.php');
611 $mTemplate = new Trackback_Template(null, $this->getDirectory());
612 $mTemplate->set ('CONF', $CONF);
613 $mTemplate->set ('itemid', $itemid);
614 $mTemplate->set ('form', $form);
615 $mTemplate->set ('error', $error);
616 $mTemplate->set ('success', $success);
617 $mTemplate->set ('status', $status);
618 $mTemplate->template('templates/form.html');
619 echo $mTemplate->fetch();
620 //modify end+++++++++
623 function showManualPingSuccess($itemid, $status = '') {
626 $form = false; $error = false; $success = true;
627 sendContentType('text/html', 'admin-trackback', _CHARSET);
628 //modify start+++++++++
629 //include ($this->getDirectory() . '/templates/form.html');
630 require_once($this->getDirectory() . '/template.php');
631 $mTemplate = new Trackback_Template(null, $this->getDirectory());
632 $mTemplate->set ('CONF', $CONF);
633 $mTemplate->set ('itemid', $itemid);
634 $mTemplate->set ('form', $form);
635 $mTemplate->set ('error', $error);
636 $mTemplate->set ('success', $success);
637 $mTemplate->set ('status', $status);
638 $mTemplate->template('templates/form.html');
639 echo $mTemplate->fetch();
640 //modify end+++++++++
643 function showManualPingForm($itemid, $text = '') {
646 $form = true; $error = false; $success = false;
648 // Check if we are allowed to accept pings
649 if ( !$this->isAcceptTrackBack($itemid) ) {
650 $text = 'Sorry, no trackback pings are accepted';
651 $form = false; $error = true;
654 sendContentType('text/html', 'admin-trackback', _CHARSET);
655 //modify start+++++++++
656 //include ($this->getDirectory() . '/templates/form.html');
657 require_once($this->getDirectory() . '/template.php');
658 $mTemplate = new Trackback_Template(null, $this->getDirectory());
659 $mTemplate->set ('CONF', $CONF);
660 $mTemplate->set ('itemid', $itemid);
661 $mTemplate->set ('form', $form);
662 $mTemplate->set ('error', $error);
663 $mTemplate->set ('success', $success);
664 $mTemplate->set ('status', $status);
665 $mTemplate->template('templates/form.html');
666 echo $mTemplate->fetch();
667 //modify end+++++++++
671 * Returns the trackback URL
673 function getTrackBackUrl($itemid) {
674 global $CONF, $manager;
675 return $CONF['ActionURL'] . '?action=plugin&name=TrackBack&tb_id='.$itemid;
679 * Insert RDF code for item
681 function insertCode($itemid) {
682 $itemid = intval($itemid);
683 global $manager, $CONF;
685 $item = & $manager->getItem($itemid, 0, 0);
686 $blog = & $manager->getBlog(getBlogIDFromItemID($item['itemid']));
689 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
690 $uri = createItemLink($item['itemid'],'');
692 $uri = $this->_createItemLink($item['itemid'],$blog);
694 $title = strip_tags($item['title']);
695 $desc = strip_tags($item['body']);
696 $desc = $this->_cut_string($desc, 200);
697 $desc = htmlspecialchars($desc, ENT_QUOTES);
701 <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
702 xmlns:dc="http://purl.org/dc/elements/1.1/"
703 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
705 rdf:about="<?php echo $uri; ?>"
706 dc:identifier="<?php echo $uri; ?>"
707 dc:title="<?php echo $title; ?>"
708 dc:description="<?php echo $desc; ?>"
709 trackback:ping="<?php echo $this->getTrackBackUrl($itemid)?>"
710 dc:date="<?php echo strftime('%Y-%m-%dT%H:%M:%S')?>" />
717 * Retrieving TrackBack Pings (when __mode=rss)
719 function rssResponse($tb_id) {
720 $itemid = intval($itemid);
721 global $manager, $CONF;
722 $item =& $manager->getItem($tb_id, 0, 0);
726 $blog =& $manager->getBlog(getBlogIDFromItemID($item['itemid']));
728 $blog_name = $blog->getName();
729 $title = $item['title'];
730 $excerpt = $item['body'];
732 //modify start+++++++++
734 if (_CHARSET != 'UTF-8')
736 $title = $this->_convert_to_utf8($title, $encoding);
737 $excerpt = $this->_convert_to_utf8($excerpt, $encoding);
738 $blog_name = $this->_convert_to_utf8($blog_name, $encoding);
741 $title = $this->_decode_entities(strip_tags($title));
742 $excerpt = $this->_decode_entities(strip_tags($excerpt));
743 $blog_name = $this->_decode_entities(strip_tags($blog_name));
746 $title = $this->_restore_to_utf8($title);
747 $excerpt = $this->_restore_to_utf8($excerpt);
748 $blog_name = $this->_restore_to_utf8($blog_name);
749 //modify end+++++++++
751 $excerpt = $this->_cut_string($excerpt, 200);
754 //modify start+++++++++
756 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
757 $url = createItemLink($item['itemid'],'');
759 $url = $this->_createItemLink($item['itemid'],$blog);
760 //modify end+++++++++
762 // Use UTF-8 charset for output
763 header('Content-Type: text/xml');
764 echo "<","?xml version='1.0' encoding='UTF-8'?",">\n";
767 echo "\t<error>0</error>\n";
768 echo "\t<rss version='0.91'>\n";
769 echo "\t\t<channel>\n";
770 echo "\t\t\t<title>".htmlspecialchars($title, ENT_QUOTES)."</title>\n";
771 echo "\t\t\t<link>".htmlspecialchars($url, ENT_QUOTES)."</link>\n";
772 echo "\t\t\t<description>".htmlspecialchars($excerpt, ENT_QUOTES)."</description>\n";
774 $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';
775 $res = sql_query($query);
776 while ($o = mysql_fetch_object($res))
778 // No need to do conversion, because it is already UTF-8
780 'url' => htmlspecialchars($o->url, ENT_QUOTES),
781 'blogname' => htmlspecialchars($this->_restore_to_utf8($o->blog_name), ENT_QUOTES),
782 'timestamp' => strftime('%Y-%m-%d',$o->timestamp),
783 'title' => htmlspecialchars($this->_restore_to_utf8($o->title), ENT_QUOTES),
784 'excerpt' => htmlspecialchars($this->_restore_to_utf8($o->excerpt), ENT_QUOTES),
785 'tburl' => $this->getTrackBackUrl($tb_id)
789 echo "\t\t\t<item>\n";
790 echo "\t\t\t\t<title>".$data['title']."</title>\n";
791 echo "\t\t\t\t<link>".$data['url']."</link>\n";
792 echo "\t\t\t\t<description>".$data['excerpt']."</description>\n";
793 echo "\t\t\t</item>\n";
795 echo "\t\t</channel>\n";
802 $this->xmlResponse(_ERROR_NOSUCHITEM);
809 /**************************************************************************************
810 * SENDING AND RECEIVING TRACKBACK PINGS
814 * Send a Trackback ping to another website
816 function sendPing($itemid, $title, $url, $excerpt, $blog_name, $ping_url, $utf8flag=0)
818 $tempEncording = ($utf8flag)? 'UTF-8': _CHARSET;
820 // 1. Check some basic things
821 if (!$this->canSendPing()) {
822 return 'You\'re not allowed to send pings';
825 if ($this->getOption('SendPings') == 'no') {
826 return 'Sending trackback pings is disabled';
829 if ($ping_url == '') {
830 return 'No ping URL';
833 // 2. Check if protocol is correct http URL
834 $parsed_url = parse_url($ping_url);
836 if ($parsed_url['scheme'] != 'http' || $parsed_url['host'] == '')
837 return 'Bad ping URL';
839 $port = ($parsed_url['port']) ? $parsed_url['port'] : 80;
841 // 3. Create contents
842 if($tempEncording != _CHARSET){
843 $title = mb_convert_encoding($title, $tempEncording, _CHARSET);
844 $excerpt = mb_convert_encoding($excerpt, $tempEncording, _CHARSET);
845 $blog_name = mb_convert_encoding($blog_name, $tempEncording, _CHARSET);
849 $content = 'title=' . urlencode( $title );
850 $content .= '&url=' . urlencode( $url );
851 $content .= '&excerpt=' . urlencode( $excerpt );
852 $content .= '&blog_name=' . urlencode( $blog_name );
854 # $user_agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
855 $user_agent = 'NP_TrackBack/'. $this->getVersion();
857 // 4. Prepare HTTP request
858 $request = 'POST ' . $parsed_url['path'];
860 if ($parsed_url['query'] != '')
861 $request .= '?' . $parsed_url['query'];
863 $request .= " HTTP/1.1\r\n";
864 $request .= "Accept: */*\r\n";
865 $request .= "User-Agent: " . $user_agent . "\r\n";
866 $request .= ( $port == 80 )?
867 "Host: " . $parsed_url['host'] . "\r\n":
868 "Host: " . $parsed_url['host'] . ":" . $port . "\r\n";
869 $request .= "Connection: Keep-Alive\r\n";
870 $request .= "Cache-Control: no-cache\r\n";
871 $request .= "Connection: Close\r\n";
872 $request .= "Content-Length: " . strlen( $content ) . "\r\n";
873 $request .= ($utf8flag)?
874 "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n":
875 "Content-Type: application/x-www-form-urlencoded; charset="._CHARSET."\r\n";
877 $request .= $content;
879 $socket = fsockopen( $parsed_url['host'], $port, $errno, $errstr );
881 return 'Could not send ping: '.$errstr.' ('.$errno.')';
883 // 5. Execute HTTP request
884 fputs($socket, $request);
886 // 6. Receive response
888 while (!feof($socket)) {
889 $result .= fgets($socket, 4096);
894 // instead of parsing the XML, just check for the error string
895 // [TODO] extract real error message and return that
896 //modify start+++++++++
898 $DATA = split("\r\n\r\n", $result, 2);
899 preg_match("/HTTP\/1\.[0-1] ([0-9]+) ([^\r\n]*)\r?\n/",$DATA[0],$httpresp);
900 $respCd = $httpresp[1];
901 $respMsg = $httpresp[2];
903 if( $respCd != 200 ){
904 return 'An error occurred: HTTP Error: [' . $respCd . '] ' . $respMsg;
906 if ( strstr($DATA[1],'<error>0</error>') === false ){
907 preg_match("/<message>(.*?)<\/message>/",$DATA[1],$error_message);
908 if( $error_message[1] )
909 return 'An error occurred: '.htmlspecialchars($error_message[1], ENT_QUOTES);
911 return 'An error occurred: fatal error.';
914 //modify end+++++++++
917 * Handle a Trackback ping sent to this website
919 function handlePing($tb_id = 0) {
925 //modify start+++++++++
928 //modify end+++++++++
930 $tb_id = intRequestVar('tb_id');
932 $rss = requestVar('__mode') == 'rss';
934 $enableLinkCheck = $this->isEnableLinkCheck($tb_id);
935 $block = ( $enableLinkCheck ) ? true : false ;
939 return 'TrackBack ID is missing (tb_id)';
942 if ((!$manager->existsItem($tb_id,0,0)) && ($this->getOption('CheckIDs') == 'yes')) {
943 return _ERROR_NOSUCHITEM;
946 // 0. Check if we need to output the list as rss
948 $this->rssResponse($tb_id);
952 // check: accept pings.
953 $blogId = getBlogIDFromItemID($tb_id);
954 $isAcceptPing = $this->isAcceptTrackBack($tb_id);
957 return 'Sorry, no trackback pings are accepted.';
961 //modify start+++++++++
962 $b =& $manager->getBlog($blogId);
963 //modify end+++++++++
964 $url = requestVar('url');
965 $title = requestVar('title');
966 $excerpt = requestVar('excerpt');
967 $blog_name = requestVar('blog_name');
969 if( $url && preg_match('/https?:\/\/([^\/]+)/', $url, $matches) ){
970 if( gethostbynamel($matches[1]) === FALSE )
971 return 'URL is invalid (url)';
973 return 'URL is missing or invalid (url)';
976 // 2. Conversion of encoding...
977 //modify start+++++++++
978 /* if (preg_match ("/;\s*charset=([^\n]+)/is", $_SERVER["CONTENT_TYPE"], $regs))
979 $encoding = strtoupper(trim($regs[1]));
981 $encoding = $this->_detect_encoding($excerpt);
983 $encoding = $this->_detect_encoding($excerpt);
984 //modify end+++++++++
986 //modify start+++++++++
987 if (_CHARSET != 'UTF-8'){
988 $title = $this->_strip_controlchar(strip_tags(mb_convert_encoding($title, _CHARSET, $encoding)));
989 $excerpt = $this->_strip_controlchar(strip_tags(mb_convert_encoding($excerpt, _CHARSET, $encoding)));
990 $blog_name = $this->_strip_controlchar(strip_tags(mb_convert_encoding($blog_name, _CHARSET, $encoding)));
992 $title = $this->_strip_controlchar($this->_convert_to_utf8($title, $encoding));
993 $excerpt = $this->_strip_controlchar($this->_convert_to_utf8($excerpt, $encoding));
994 $blog_name = $this->_strip_controlchar($this->_convert_to_utf8($blog_name, $encoding));
996 $title = $this->_decode_entities(strip_tags($title));
997 $excerpt = $this->_decode_entities(strip_tags($excerpt));
998 $blog_name = $this->_decode_entities(strip_tags($blog_name));
1000 //modify end+++++++++
1002 // 4. Save data in the DB
1007 '.sql_table('plugin_tb').'
1009 url = \''.mysql_real_escape_string($url).'\' AND
1010 tb_id = \''.intval($tb_id).'\'
1013 if (mysql_num_rows($res) != 0)
1015 // Existing TB, update it
1019 '.sql_table('plugin_tb').'
1021 title = "'.mysql_real_escape_string($title).'",
1022 excerpt = "'.mysql_real_escape_string($excerpt).'",
1023 blog_name = "'.mysql_real_escape_string($blog_name).'",
1024 timestamp = '.mysqldate(time()).'
1026 url = "'.mysql_real_escape_string($url).'" AND
1027 tb_id = "'.$tb_id.'"
1030 //modify start+++++++++
1031 $rows = mysql_fetch_assoc($res);
1032 $spam = ( $rows['block'] || $rows['spam'] ) ? true : false;
1035 '.sql_table('plugin_tb').'
1037 title = \''.mysql_real_escape_string($title).'\',
1038 excerpt = \''.mysql_real_escape_string($excerpt).'\',
1039 blog_name = \''.mysql_real_escape_string($blog_name).'\',
1040 timestamp = '.mysqldate($b->getCorrectTime()).'
1042 url = \''.mysql_real_escape_string($url).'\' AND
1043 tb_id = \''.mysql_real_escape_string(intval($tb_id)).'\'
1045 //modify end+++++++++
1048 return 'Could not update trackback data: '.mysql_error();
1053 // 4. SPAM check (for SpamCheck API 2 /w compat. API 1)
1054 $spamcheck = array (
1055 'type' => 'trackback',
1058 'excerpt' => $excerpt,
1059 'blogname' => $blog_name,
1064 /* Backwards compatibility with SpamCheck API 1*/
1065 'data' => $url . "\n" . $title . "\n" . $excerpt . "\n" . $blog_name . "\n" . serverVar('HTTP_USER_AGENT'),
1069 $manager->notify('SpamCheck', array ('spamcheck' => & $spamcheck));
1071 if (isset($spamcheck['result']) && $spamcheck['result'] == true)
1076 // 5. Content check (TO DO)
1077 if($spam == false || $enableLinkCheck == 'ignore' ) //modify
1080 // $contents = $this->retrieveUrl ($url);
1082 // if (preg_match("/(".preg_quote($_SERVER["REQUEST_URI"], '/').")|(".preg_quote($_SERVER["SERVER_NAME"], '/').")/i", $contents)) {
1085 if( $enableLinkCheck ){
1086 $contents = $this->retrieveUrl($url);
1088 $linkArray = $this->getPermaLinksFromText($contents);
1089 $itemLink = $this->_createItemLink($tb_id, $b);
1090 $itemLinkPat = '{^' . preg_quote($itemLink) .'}i';
1091 $itemLinkPat = str_replace('&','&(amp;)?', $itemLinkPat);
1093 foreach($linkArray as $l) {
1094 if(preg_match($itemLinkPat, $l)){
1095 ACTIONLOG :: add(INFO, "Trackback: LinkCheck OK. (link: $l pat: $itemLinkPat )");
1101 $cnt = @count($linkArray);
1102 if( $enableLinkCheck == 'ignore' ){
1103 ACTIONLOG :: add(INFO, "Trackback: LinkCheck NG. [ignore] (itemid:$tb_id from: $url cnt: $cnt pat: $itemLinkPat)");
1104 return 'Sorry, trackback ping is not accepted.';
1106 ACTIONLOG :: add(INFO, "Trackback: LinkCheck NG. [block] (itemid:$tb_id from: $url cnt: $cnt pat: $itemLinkPat");
1113 // 6. Determine if Trackback is safe...
1114 //modify start+++++++++
1115 // $block = $spam == true || $link == false;
1116 // $block = $spam == true ;
1117 //modify end+++++++++
1119 if ( $enableLinkCheck )
1120 $block = ($spam == true || $link == false);
1122 $block = $spam == true ;
1124 // New TB, insert it
1128 '.sql_table('plugin_tb').'
1130 tb_id = "'.$tb_id.'",
1131 block = "'.($block ? '1' : '0').'",
1132 spam = "'.($spam ? '1' : '0').'",
1133 link = "'.($link ? '1' : '0').'",
1134 url = "'.mysql_real_escape_string($url).'",
1135 title = "'.mysql_real_escape_string($title).'",
1136 excerpt = "'.mysql_real_escape_string($excerpt).'",
1137 blog_name = "'.mysql_real_escape_string($blog_name).'",
1138 timestamp = '.mysqldate(time()).'
1141 //modify start+++++++++
1144 '.sql_table('plugin_tb').'
1146 tb_id = \''.mysql_real_escape_string(intval($tb_id)).'\',
1147 block = \''.($block ? '1' : '0').'\',
1148 spam = \''.($spam ? '1' : '0').'\',
1149 link = \''.($link ? '1' : '0').'\',
1150 url = \''.mysql_real_escape_string($url).'\',
1151 title = \''.mysql_real_escape_string($title).'\',
1152 excerpt = \''.mysql_real_escape_string($excerpt).'\',
1153 blog_name = \''.mysql_real_escape_string($blog_name).'\',
1154 timestamp = '.mysqldate($b->getCorrectTime()).'
1156 //modify end+++++++++
1158 $res = @sql_query($query);
1161 return 'Could not save trackback data, possibly because of a double entry: ' . mysql_error() . $query;
1165 // 7. Send notification e-mail if needed
1166 $notifyAddrs = $this->getOption('NotifyEmail');
1167 $notifyAddrs = ( $notifyAddrs ? $notifyAddrs . ';' : '')
1168 . $this->getBlogOption($blogId ,'NotifyEmailBlog');
1170 if ($notifyAddrs && $spam == false)
1177 'excerpt' => $excerpt,
1178 'blogname' => $blog_name
1181 //modify start+++++++++
1186 'title' => mb_convert_encoding($title, 'ISO-2022-JP', _CHARSET),
1187 'excerpt' => mb_convert_encoding($excerpt, 'ISO-2022-JP', _CHARSET),
1188 'blogname' => mb_convert_encoding($blog_name, 'ISO-2022-JP', _CHARSET)
1191 //maybe not needed because japanese version has "mb_send_mail" in function notify
1192 //modify end+++++++++
1194 $mailto_title = TEMPLATE::fill($this->notificationMailTitle, $vars);
1195 $mailto_msg = TEMPLATE::fill($this->notificationMail, $vars);
1197 global $CONF, $DIR_LIBS;
1199 // make sure notification class is loaded
1200 if (!class_exists('notification'))
1201 include($DIR_LIBS . 'NOTIFICATION.php');
1203 $notify = new NOTIFICATION($notifyAddrs);
1204 $notify->notify($mailto_title, $mailto_msg , $CONF['AdminEmail']);
1206 //mod by cles+++++++++++
1207 if ($manager->pluginInstalled('NP_Cache')){
1208 $p =& $manager->getPlugin('NP_Cache');
1209 $p->setCurrentBlog($tb_id);
1210 $p->cleanItem($tb_id);
1211 $p->cleanArray(array('index'));
1213 //mod by cles end +++++++++++
1217 return 'Sorry, trackback ping is not accepted.';
1221 function xmlResponse($errorMessage = '')
1223 header('Content-Type: text/xml');
1225 echo "<","?xml version='1.0' encoding='UTF-8'?",">\n";
1226 echo "<response>\n";
1229 echo "\t<error>1</error>\n\t<message>",htmlspecialchars($errorMessage, ENT_QUOTES),"</message>\n";
1231 echo "\t<error>0</error>\n";
1238 * Check if member may send ping (check if logged in)
1240 function canSendPing() {
1242 return $member->isLoggedIn() || $this->xmlrpc;
1247 function redirect($tb_id, $urlHash){
1249 $query = 'SELECT url FROM '.sql_table('plugin_tb').' WHERE tb_id='.intval($tb_id).' and md5(url)="'.$urlHash.'"';
1250 $res = sql_query($query);
1252 $url = $CONF['SiteURL'];
1254 if ($o = mysql_fetch_object($res)) {
1255 $url = htmlspecialchars($o->url, ENT_QUOTES);
1258 $url = stripslashes($url);
1259 $url = str_replace('&','&',$url);
1260 $url = str_replace('<','<',$url);
1261 $url = str_replace('>','>',$url);
1262 $url = str_replace('"','"',$url);
1264 header('Location: '.$url);
1267 function getRequiredURL($itemid){
1269 $blog = & $manager->getBlog(getBlogIDFromItemID($item['itemid']));
1270 if( $this->isEnableLinkCheck($itemid) )
1271 return $this->_createItemLink($itemid, $blog);
1275 function isEnableLinkCheck($itemid){
1276 $blogid = getBlogIDFromItemID($itemid);
1278 switch( $this->getItemOption($itemid, 'isAcceptW/OLink') ){
1280 $def = $this->getBlogOption($blogid, 'isAcceptW/OLinkDef');
1284 return $def; // block or ignore
1290 ACTIONLOG :: add(INFO, "Trackback: Unknown Option (itemid:$itemid, value:$val)");
1295 var $acceptTrackbacks = array();
1296 function isAcceptTrackBack($itemid = null){
1297 if( $itemid && isset($acceptTrackbacks[$itemid]) )
1298 return $acceptTrackbacks[$itemid] === true;
1301 if( $this->getOption('AcceptPing') == 'yes' ){
1304 $bid = getBlogIDFromItemID(intval($itemid));
1307 $bid = $blog->getID();
1310 if( $this->getBlogOption($bid, "AllowTrackBack") == 'yes' ){
1312 $ret = ( $this->getItemOption(intval($itemid), 'ItemAcceptPing') == 'yes' ) ? true : false ;
1321 $acceptTrackbacks[$itemid] = $ret;
1322 return $ret === true;
1327 /**************************************************************************************
1331 function event_SendTrackback($data) {
1334 // Enable sending trackbacks for the XML-RPC API, otherwise we would
1335 // get an error because the current user is not exactly logged in.
1336 $this->xmlrpc = true;
1338 $itemid = $data['tb_id'];
1339 $item = &$manager->getItem($itemid, 0, 0);
1340 if (!$item) return; // don't ping for draft & future
1341 if ($item['draft']) return; // don't ping on draft items
1343 // gather some more information, needed to send the ping (blog name, etc)
1344 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
1345 $blog_name = $blog->getName();
1347 $title = $data['title'] != '' ? $data['title'] : $item['title'];
1348 $title = strip_tags($title);
1350 $excerpt = $data['body'] != '' ? $data['body'] : $item['body'];
1351 $excerpt = strip_tags($excerpt);
1352 $excerpt = $this->_cut_string($excerpt, 200);
1354 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
1355 //$url = createItemLink($itemid);
1356 $url = $this->_createItemLink($itemid, $blog);
1358 while (list(,$url) = each($data['urls'])) {
1359 $res = $this->sendPing($itemid, $title, $url, $excerpt, $blog_name, $url);
1360 if ($res) ACTIONLOG::add(WARNING, 'TrackBack Error:' . $res . ' (' . $url . ')');
1364 function event_RetrieveTrackback($data) {
1370 UNIX_TIMESTAMP(timestamp) AS timestamp
1372 '.sql_table('plugin_tb').'
1374 tb_id = '.intval($data['tb_id']).' AND
1380 while ($row = mysql_fetch_array($res)) {
1383 'title' => $row['title'],
1384 'url' => $row['url'],
1388 $data['trackbacks'][] = $trackback;
1392 function event_BookmarkletExtraHead($data) {
1394 list ($NP_TB_URL,) = $this->getURIfromLink(requestVar('loglink'));
1397 function event_PrepareItemForEdit($data) {
1398 // if (!$this->getOption('AutoXMLHttp'))
1399 if ($this->getOption('AutoXMLHttp') == 'no')
1401 // The space between body and more is to make sure we didn't join 2 words accidently....
1402 $this->larray = $this->autoDiscovery($data['item']['body'].' '.$data['item']['more']);
1407 * After an item has been added to the database, send out a ping if requested
1408 * (trackback_ping_url variable in request)
1410 function event_PostAddItem($data) {
1411 $this->pingTrackback($data);
1414 function event_PreUpdateItem($data) {
1415 $this->pingTrackback($data);
1419 * Add trackback options to add item form/bookmarklet
1421 function event_AddItemFormExtras($data) {
1423 // global $NP_TB_URL;
1428 <!--modify start+++++++++-->
1429 <!-- <label for="plug_tb_url">TrackBack Ping URL:</label>
1430 <input type="text" value="<?php if (isSet($NP_TB_URL)) {echo $NP_TB_URL;} ?>" id="plug_tb_url" name="trackback_ping_url" size="60" />
1432 <!--modify end+++++++++-->
1433 <label for="plug_tb_url">TrackBack URL:</label><br />
1434 <textarea id="plug_tb_url" name="trackback_ping_url" cols="60" rows="5" style="font:normal xx-small Tahoma, Arial, verdana ;"></textarea>
1435 <input type="button" name="btnAdd" value="<?php echo _TB_LIST_IT?>" onClick="AddStart()" />
1440 // if ($this->getOption('AutoXMLHttp'))
1441 if ($this->getOption('AutoXMLHttp') == 'yes')
1445 <input type="button" name="discoverit" value="Auto Discover" onclick="tbSetup();" />
1446 <img id='tb_busy' src='<?php echo $this->getAdminURL(); ?>busy.gif' style="display:none;" /><br />
1447 <div id="tb_auto_title"></div>
1448 <table border="1"><tbody id="tb_ping_list"></tbody></table>
1449 <input type="hidden" id="tb_url_amount" name="tb_url_amount" value="0" />
1453 $this->jsautodiscovery();
1461 * Add trackback options to edit item form/bookmarklet
1463 function event_EditItemFormExtras($data) {
1466 <!-- <input type="text" value="" id="plug_tb_url" name="trackback_ping_url" size="60" /><br />-->
1469 <label for="plug_tb_url">TrackBack URL:</label><br />
1470 <textarea id="plug_tb_url" name="trackback_ping_url" cols="60" rows="5" style="font:normal xx-small Tahoma, Arial, verdana ;"></textarea>
1471 <input type="button" name="btnAdd" value="<?php echo _TB_LIST_IT?>" onClick="AddStart()" />
1474 // if ($this->getOption('AutoXMLHttp'))
1475 if ($this->getOption('AutoXMLHttp') == 'yes')
1481 <input type="button" name="discoverit" value="Auto Discover" onclick="tbSetup();" />
1482 <img id='tb_busy' src='<?php echo $this->getAdminURL(); ?>busy.gif' style="display:none;" /><br />
1483 <div id="tb_auto_title"></div>
1484 <table border="1"><tbody id="tb_ping_list"></tbody></table>
1485 <input type="hidden" id="tb_url_amount" name="tb_url_amount" value="0" />
1489 $this->jsautodiscovery();
1493 if (count($this->larray) > 0)
1496 Auto Discovered Ping URL's:<br />
1498 echo '<input type="hidden" name="tb_url_amount" value="'.count($this->larray).'" />';
1502 while (list($url, $title) = each ($this->larray))
1504 //modify start+++++++++
1505 if (_CHARSET != 'UTF-8') {
1506 $title = $this->_utf8_to_entities($title);
1507 $title = mb_convert_encoding($title, _CHARSET, 'UTF-8');
1509 //modify end+++++++++
1511 echo '<input type="checkbox" name="tb_url_'.$i.
1512 '" value="'.$url.'" id="tb_url_'.$i.
1513 '" /><label for="tb_url_'.$i.'" title="'.$url.'">'.$title.'</label><br />';
1525 * Insert Javascript AutoDiscovery routines
1527 function jsautodiscovery()
1532 <script type='text/javascript' src='<?php echo $this->getAdminURL(); ?>autodetect.php'></script>
1539 function pingTrackback($data) {
1540 global $manager, $CONF;
1542 $ping_urls_count = 0;
1543 $ping_urls = array();
1544 $utf8flag = array();
1545 $localflag = array();
1547 $ping_url = requestVar('trackback_ping_url');
1548 //modify start+++++++++
1551 $ping_urls[0] = $ping_url;
1555 if (trim($ping_url)) {
1556 $ping_urlsTemp = array();
1557 $ping_urlsTemp = preg_split("/[\s,]+/", trim($ping_url));
1558 for($i=0;$i<count($ping_urlsTemp);$i++){
1559 $ping_urls[] = trim($ping_urlsTemp[$i]);
1563 //modify end+++++++++
1565 $tb_url_amount = requestVar('tb_url_amount');
1566 for ($i=0;$i<$tb_url_amount;$i++) {
1567 $tb_temp_url = requestVar('tb_url_'.$i);
1569 $ping_urls[$ping_urls_count] = $tb_temp_url;
1570 $utf8flag[$ping_urls_count] = (requestVar('tb_url_'.$i.'_utf8') == 'on')? 1: 0;
1571 $localflag[$ping_urls_count] = (requestVar('tb_url_'.$i.'_local') == 'on')? 1: 0;
1576 if ($ping_urls_count <= 0) {
1580 $itemid = $data['itemid'];
1581 $item = &$manager->getItem($itemid, 0, 0);
1582 if (!$item) return; // don't ping for draft & future
1583 if ($item['draft']) return; // don't ping on draft items
1585 // gather some more information, needed to send the ping (blog name, etc)
1586 $blog =& $manager->getBlog(getBlogIDFromItemID($itemid));
1587 $blog_name = $blog->getName();
1589 $title = $data['title'] != '' ? $data['title'] : $item['title'];
1590 $title = strip_tags($title);
1592 $excerpt = $data['body'] != '' ? $data['body'] : $item['body'];
1593 $excerpt = strip_tags($excerpt);
1594 $excerpt = $this->_cut_string($excerpt, 200);
1597 $CONF['ItemURL'] = preg_replace('/\/$/', '', $blog->getURL());
1598 $url = createItemLink($itemid);
1600 $url = $this->_createItemLink($item['itemid'],$blog);
1602 // send the ping(s) (add errors to actionlog)
1603 for ($i=0; $i<count($ping_urls); $i++) {
1604 if( ! $localflag[$i] )
1605 $res = $this->sendPing($itemid, $title, $url, $excerpt, $blog_name, $ping_urls[$i], $utf8flag[$i]);
1607 $res = $this->handleLocalPing($itemid, $title, $excerpt, $blog_name, $ping_urls[$i]);
1608 if ($res) ACTIONLOG::add(WARNING, 'TrackBack Error:' . $res . ' (' . $ping_urls[$i] . ')');
1615 /**************************************************************************************
1620 * Auto-Discovery of TrackBack Ping URLs based on HTML story
1622 function autoDiscovery($text)
1624 $links = $this->getPermaLinksFromText($text);
1627 for ($i = 0; $i < count($links); $i++)
1629 list ($url, $title) = $this->getURIfromLink($links[$i]);
1632 $result[$url] = $title;
1639 * Auto-Discovery of TrackBack Ping URLs based on single link
1641 function getURIfromLink($link)
1644 // Check to see if the cache contains this link
1645 $res = sql_query('SELECT url, title FROM '.sql_table('plugin_tb_lookup').' WHERE link=\''.mysql_real_escape_string($link).'\'');
1647 if ($row = mysql_fetch_array($res))
1649 if ($row['title'] != '')
1651 //modify start+++++++++
1652 if (_CHARSET != 'UTF-8'){
1653 $row['title'] = mb_convert_encoding($row['title'], 'UTF-8', _CHARSET);
1654 $row['title'] = $this->_decode_entities($row['title']);
1656 //modify end+++++++++
1658 $row['url'], $row['title']
1664 $row['url'], $row['url']
1670 if (($rdf = $this->getRDFFromLink($link)) !== false)
1672 // Get PING attribute
1673 if (($uri = $this->getAttributeFromRDF($rdf, 'trackback:ping')) !== false)
1675 // Get TITLE attribute
1676 if (($title = $this->getAttributeFromRDF($rdf, 'dc:title')) !== false)
1678 // Get CREATOR attribute
1679 if (($author = $this->getAttributeFromRDF($rdf, 'dc:creator')) !== false)
1681 $title = $author. ": " . $title;
1684 $uri = $this->_decode_entities($uri);
1685 //modify start+++++++++
1686 if (_CHARSET != 'UTF-8')
1687 $convertedTitle = mb_convert_encoding($title, _CHARSET, 'UTF-8');
1689 $convertedTitle = $title;
1692 $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)."')");
1695 $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)."')");
1696 //modify end+++++++++
1697 $title = $this->_decode_entities($title);
1705 $uri = html_entity_decode($uri, ENT_COMPAT);
1708 $res = sql_query("INSERT INTO ".sql_table('plugin_tb_lookup')." (link, url, title) VALUES ('".mysql_real_escape_string($link)."','".mysql_real_escape_string($uri)."','')");
1718 $res = sql_query("INSERT INTO ".sql_table('plugin_tb_lookup')." (link, url, title) VALUES ('".mysql_real_escape_string($link)."','','')");
1720 return array ('', '');
1724 * Detect links used in HTML code
1726 function getPermaLinksFromText($text)
1730 if (preg_match_all('/<[aA] +([^>]+)>/', $text, $array, PREG_SET_ORDER))
1732 for ($i = 0; $i < count($array); $i++)
1734 //if( preg_match('/s?https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:@&=+$,%#]+/', $array[$i][1], $matches) )
1735 if( preg_match('/s?https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/:@&=+$,%]+/', $array[$i][1], $matches) )
1736 $links[$matches[0]] = 1;
1740 return array_keys($links);
1744 * Retrieve RDF code from external link
1746 function getRDFFromLink($link)
1748 if ($content = $this->getContents($link))
1750 preg_match_all('/(<rdf:RDF.*?<\/rdf:RDF>)/sm', $content, $rdfs, PREG_SET_ORDER);
1752 if (count($rdfs) > 1)
1754 for ($i = 0; $i < count($rdfs); $i++)
1756 if (preg_match('|dc:identifier="'.preg_quote($link).'"|ms',$rdfs[$i][1]))
1758 return $rdfs[$i][1];
1764 // No need to check the identifier
1773 * Retrieve the contents of an external (X)HTML document
1775 function getContents($link) {
1777 // Use cURL extention if available
1778 if (function_exists("curl_init") && $this->useCurl == 2)
1780 // Make HEAD request
1782 @curl_setopt($ch, CURLOPT_URL, $link);
1783 @curl_setopt($ch, CURLOPT_HEADER, true);
1784 @curl_setopt($ch, CURLOPT_NOBODY, true);
1785 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
1786 @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
1787 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1788 @curl_setopt($ch, CURLOPT_TIMEOUT, 20);
1789 @curl_setopt($ch, CURLOPT_USERAGENT, 'NP_TrackBack/'. $this->getVersion());
1791 $headers = curl_exec($ch);
1794 // Check if the link points to a (X)HTML document
1795 if (preg_match('/Content-Type: (text\/html|application\/xhtml+xml)/i', $headers))
1797 return $this->retrieveUrl ($link);
1804 return $this->retrieveUrl ($link);
1809 * Get a single attribute from RDF
1811 function getAttributeFromRDF($rdf, $attribute)
1813 if (preg_match('/'.$attribute.'="([^"]+)"/', $rdf, $matches))
1826 /**************************************************************************************/
1827 /* Internal helper functions for dealing with external file retrieval */
1829 function retrieveUrl ($url) {
1831 $ua = ini_set('user_agent', 'NP_TrackBack/'. $this->getVersion());
1833 if (function_exists('curl_init') && $this->useCurl > 0)
1837 @curl_setopt($ch, CURLOPT_URL, $url);
1838 @curl_setopt($ch, CURLOPT_HEADER, 1);
1839 @curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
1840 @curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
1841 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
1842 @curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
1843 @curl_setopt($ch, CURLOPT_TIMEOUT, 20);
1844 @curl_setopt($ch, CURLOPT_USERAGENT, 'NP_TrackBack/'. $this->getVersion());
1846 // Retrieve response
1847 $raw = curl_exec($ch);
1848 $info = curl_getinfo($ch);
1850 // Split into headers and contents
1851 $headers = substr($raw, 0, $info['header_size']);
1852 $contents = substr($raw, $info['header_size']);
1856 elseif ($fp = @fopen ($url, "r"))
1859 // $contents = fread($fp, 8192);
1861 while (!feof($fp)) {
1862 $contents .= fread($fp, 8192);
1870 ini_set('user_agent', $ua);
1873 // Next normalize the encoding to UTF8...
1874 $contents = $this->_convert_to_utf8_auto($contents, $headers);
1880 /**************************************************************************************/
1881 /* Internal helper functions for dealing with encodings and entities */
1883 var $entities_default = array (
1884 '"' => '"',
1886 ''' => ''',
1891 //modify start+++++++++
1892 function _restore_to_utf8($contents)
1894 if (_CHARSET != 'UTF-8')
1896 $contents = mb_convert_encoding($contents, 'UTF-8', _CHARSET);
1898 $contents = $this->_decode_entities(strip_tags($contents));
1901 //modify end+++++++++
1902 function _detect_encoding($string)
1904 //modify start+++++++++
1905 if (function_exists('mb_convert_encoding')) {
1906 $encoding = (preg_match ("/;\s*charset=([^\n]+)/is", serverVar("CONTENT_TYPE"), $regs))?
1907 strtoupper(trim($regs[1])):
1910 if ( ($encoding !="") && ((mb_http_input("P") == "") || ( strtolower( ini_get("mbstring.http_input") ) == "pass")) ) {
1913 $encoding = mb_detect_encoding($string, 'UTF-8,EUC-JP,SJIS,ISO-8859-1,ASCII,JIS');
1915 return ( $encoding ) ? $encoding : 'ISO-8859-1';
1917 //modify end+++++++++
1918 if (!ereg("[\x80-\xFF]", $string) && !ereg("\x1B", $string))
1921 if (!ereg("[\x80-\xFF]", $string) && ereg("\x1B", $string))
1922 return 'ISO-2022-JP';
1924 if (preg_match("/^([\x01-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF][\x80-\xBF])+$/", $string) == 1)
1927 if (preg_match("/^([\x01-\x7F]|\x8E[\xA0-\xDF]|\x8F[xA1-\xFE][\xA1-\xFE]|[\xA1-\xFE][\xA1-\xFE])+$/", $string) == 1)
1930 if (preg_match("/^([\x01-\x7F]|[\xA0-\xDF]|[\x81-\xFC][\x40-\xFC])+$/", $string) == 1)
1933 return 'ISO-8859-1';
1936 function _convert_to_utf8($contents, $encoding)
1940 //modify start+++++++++
1941 // if (!$done && function_exists('iconv'))
1944 // $result = @iconv($encoding, 'UTF-8//IGNORE', $contents);
1948 // $contents = $result;
1953 if(!$done && function_exists('mb_convert_encoding'))
1956 if( function_exists('mb_substitute_character') ){
1957 @mb_substitute_character('none');
1959 $result = @mb_convert_encoding($contents, 'UTF-8', $encoding );
1963 $contents = $result;
1968 if (!$done && function_exists('iconv'))
1971 $result = @iconv($encoding, 'UTF-8//IGNORE', $contents);
1975 $contents = $result;
1979 //modify end+++++++++
1983 function _convert_to_utf8_auto($contents, $headers = '')
1985 /* IN: string in unknown encoding, headers received during transfer
1986 * OUT: string in UTF-8 encoding
1989 $str = substr($contents, 0, 4096);
1990 $len = strlen($str);
1996 $ord = ord($str[$pos]);
1998 if ($ord > 32 && $ord < 128)
2004 // Detection of encoding, check headers
2005 if (preg_match ("/;\s*charset=([^\n]+)/is", $headers, $regs))
2006 $encoding = strtoupper(trim($regs[1]));
2008 // Then check meta inside document
2009 if (preg_match ("/;\s*charset=([^\"']+)/is", $out, $regs))
2010 $encoding = strtoupper(trim($regs[1]));
2012 // Then check xml declaration
2013 if (preg_match("/<\?xml.+encoding\s*=\s*[\"|']([^\"']+)[\"|']\s*\?>/i", $out, $regs))
2014 $encoding = strtoupper(trim($regs[1]));
2017 return $this->_convert_to_utf8($contents, $encoding);
2020 function _decode_entities($string)
2022 /* IN: string in UTF-8 containing entities
2023 * OUT: string in UTF-8 without entities
2026 /// Convert all hexadecimal entities to decimal entities
2027 $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', "'&#'.hexdec('\\1').';'", $string);
2030 // Deal with invalid cp1251 numeric entities
2031 $string = strtr($string, $_entities['cp1251']);
2033 // Convert all named entities to numeric entities
2034 $string = strtr($string, $this->entities_default);
2035 $string = strtr($string, $_entities['named']);
2037 // Convert all numeric entities to UTF-8
2038 $string = preg_replace('/&#([0-9]+);/e', "'&#x'.dechex('\\1').';'", $string);
2039 $string = preg_replace('/&#[Xx]([0-9A-Fa-f]+);/e', "NP_TrackBack::_hex_to_utf8('\\1')", $string);
2044 function _hex_to_utf8($s){
2045 return entity::_hex_to_utf8($s);
2048 function _utf8_to_entities($string)
2050 /* IN: string in UTF-8 encoding
2051 * OUT: string consisting of only characters ranging from 0x00 to 0x7f,
2052 * using numeric entities to represent the other characters
2055 $len = strlen ($string);
2061 $ascii = ord (substr ($string, $pos, 1));
2065 $byte[1] = ord(substr ($string, $pos, 1)) - 0xF0;
2066 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2067 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2068 $byte[4] = ord(substr ($string, $pos + 3, 1)) - 0x80;
2070 $char_code = ($byte[1] << 18) + ($byte[2] << 12) + ($byte[3] << 6) + $byte[4];
2073 elseif (($ascii >= 0xE0) && ($ascii < 0xF0))
2075 $byte[1] = ord(substr ($string, $pos, 1)) - 0xE0;
2076 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2077 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2079 $char_code = ($byte[1] << 12) + ($byte[2] << 6) + $byte[3];
2082 elseif (($ascii >= 0xC0) && ($ascii < 0xE0))
2084 $byte[1] = ord(substr ($string, $pos, 1)) - 0xC0;
2085 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2087 $char_code = ($byte[1] << 6) + $byte[2];
2092 $char_code = ord(substr ($string, $pos, 1));
2096 if ($char_code < 0x80)
2097 $out .= chr($char_code);
2099 $out .= '&#'. str_pad($char_code, 5, '0', STR_PAD_LEFT) . ';';
2105 function _utf8_to_javascript($string)
2107 /* IN: string in UTF-8 encoding
2108 * OUT: string consisting of only characters ranging from 0x00 to 0x7f,
2109 * using javascript escapes to represent the other characters
2112 $len = strlen ($string);
2118 $ascii = ord (substr ($string, $pos, 1));
2122 $byte[1] = ord(substr ($string, $pos, 1)) - 0xF0;
2123 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2124 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2125 $byte[4] = ord(substr ($string, $pos + 3, 1)) - 0x80;
2127 $char_code = ($byte[1] << 18) + ($byte[2] << 12) + ($byte[3] << 6) + $byte[4];
2130 elseif (($ascii >= 0xE0) && ($ascii < 0xF0))
2132 $byte[1] = ord(substr ($string, $pos, 1)) - 0xE0;
2133 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2134 $byte[3] = ord(substr ($string, $pos + 2, 1)) - 0x80;
2136 $char_code = ($byte[1] << 12) + ($byte[2] << 6) + $byte[3];
2139 elseif (($ascii >= 0xC0) && ($ascii < 0xE0))
2141 $byte[1] = ord(substr ($string, $pos, 1)) - 0xC0;
2142 $byte[2] = ord(substr ($string, $pos + 1, 1)) - 0x80;
2144 $char_code = ($byte[1] << 6) + $byte[2];
2149 $char_code = ord(substr ($string, $pos, 1));
2153 if ($char_code < 0x80)
2154 $out .= chr($char_code);
2156 $out .= '\\u'. str_pad(dechex($char_code), 4, '0', STR_PAD_LEFT);
2162 function _cut_string($string, $dl = 0) {
2164 $defaultLength = $dl > 0 ? $dl : $this->getOption('defaultLength');
2166 if ($defaultLength < 1)
2173 for ($i = 0; $i < strlen($string); $i++)
2175 $value = ord($string[$i]);
2179 if ($value >= 192 && $value <= 223)
2181 elseif ($value >= 224 && $value <= 239)
2183 elseif ($value >= 240 && $value <= 247)
2186 if ($lastvalue <= 223 && $value >= 223 &&
2187 $count >= $defaultLength - $border)
2189 return substr($string, 0, $i) . '...';
2192 // Chinese and Japanese characters are
2193 // wider than Latin characters
2198 elseif ($string[$i] == '/' || $string[$i] == '?' ||
2199 $string[$i] == '-' || $string[$i] == ':' ||
2200 $string[$i] == ',' || $string[$i] == ';')
2202 if ($count >= $defaultLength - $border)
2203 return substr($string, 0, $i) . '...';
2205 elseif ($string[$i] == ' ')
2207 if ($count >= $defaultLength - $border)
2208 return substr($string, 0, $i) . '...';
2211 if ($count == $defaultLength)
2212 return substr($string, 0, $i + 1) . '...';
2214 $lastvalue = $value;
2222 function _cut_string($string, $dl = 0) {
2223 $maxLength = $dl > 0 ? $dl : $this->getOption('defaultLength');
2227 if (strlen($string) > $maxLength)
2228 $string = mb_strimwidth($string, 0, $maxLength, '...', _CHARSET);
2233 function _strip_controlchar($string){
2234 $string = preg_replace("/[\x01-\x08\x0b\x0c\x0e-\x1f\x7f]+/","",$string);
2235 $string = str_replace("\0","",$string);
2239 //modify start+++++++++
2240 function checkTableVersion(){
2241 $res = sql_query("SHOW FIELDS from ".sql_table('plugin_tb') );
2242 $fieldnames = array();
2243 while ($co = mysql_fetch_assoc($res)) {
2244 if($co['Field'] == 'block') return true;
2248 //modify end+++++++++
2250 /*---------------------------------------------------------------------------------- */
2252 /*---------------------------------------------------------------------------------- */
2254 * Handle an incoming TrackBack ping and save the data in the database
2256 function handleLocalPing($itemid, $title, $excerpt, $blog_name, $ping_url){
2258 $ping_url = trim($ping_url);
2260 if( preg_match("/^.+tb_id=([0-9]+)$/",$ping_url,$idnum) ){
2261 $tb_id = intval($idnum[1]);
2262 } elseif ( preg_match("/([0-9]+)\.trackback/",$ping_url,$idnum) ){
2263 $tb_id = intval($idnum[1]);
2264 } elseif ( preg_match("/itemid=([0-9]+)/",$ping_url,$idnum) ){
2265 $tb_id = intval($idnum[1]);
2268 if ((!$manager->existsItem($tb_id,0,0)) && ($this->getOption('CheckIDs') == 'yes'))
2269 return _ERROR_NOSUCHITEM . "[ $tb_id ]";
2271 // save data in the DB
2272 $query = 'INSERT INTO ' . sql_table('plugin_tb_lc') . " (tb_id, from_id) VALUES ('".intval($tb_id)."','".intval($itemid)."')";
2273 $res = @sql_query($query);
2275 return 'Could not save trackback data, possibly because of a double entry: ' . mysql_error();
2279 * Show the list of TrackBack pings for a certain Trackback ID
2281 function showLocalList($tb_id) {
2282 global $CONF, $manager;
2285 $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';
2286 $res = sql_query($query);
2289 'tburl' => $this->getTrackBackUrl($tb_id)
2292 // when no TrackBack pings are found
2293 if (!$res || mysql_num_rows($res) == 0) {
2294 echo TEMPLATE::fill($this->getOption('tplLocalEmpty'), $vars);
2298 // when TrackBack pings are found
2299 echo TEMPLATE::fill($this->getOption('tplLocalHeader'), $vars);
2301 while ($o = mysql_fetch_object($res)) {
2302 $canDelete = $this->canDelete($tb_id);
2304 'url' => createItemLink($o->from_id),
2305 'blogname' => htmlspecialchars(getBlogNameFromID($o->iblog)),
2306 'timestamp' => strftime('%Y-%m-%d',strtotime($o->itime)),
2307 'title' => htmlspecialchars($o->ititle),
2308 'excerpt' => htmlspecialchars(shorten(strip_tags($o->ibody),200,'...')),
2309 '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>':'',
2310 'tburl' => $this->getTrackBackUrl($tb_id),
2311 'commentcount'=> quickQuery('SELECT COUNT(*) as result FROM '.sql_table('comment').' WHERE citem=' . intval($o->from_id))
2313 echo TEMPLATE::fill($this->getOption('tplLocalItem'), $data);
2315 echo TEMPLATE::fill($this->getOption('tplLocalFooter'), $vars);
2319 * Delete a TrackBack item, redirect to referer
2321 function deleteLocal($tb_id, $from_id) {
2322 if (!$this->canDelete($tb_id))
2323 return 'You\'re not allowed to delete this trackback item';
2324 $query = 'DELETE FROM ' . sql_table('plugin_tb_lc') . " WHERE tb_id='" . intval($tb_id) . "' and from_id='" . intval($from_id) ."'";
2329 function canDelete($tb_id) {
2330 global $member, $manager;
2332 if ( ! $member->isLoggedIn() ) return 0;
2334 $checkIDs = $this->getOption('CheckIDs');
2335 $itemExists =& $manager->existsItem($tb_id,0,0);
2337 // if CheckIDs option is set, check if member canEdit($tb_id)
2338 // if CheckIDs option is not set, and item exists, check if member canEdit($tb_id)
2339 // if CheckIDs option is not set, and item does not exists, check if member isAdmin()
2341 if (($checkIDs == 'yes') || ($itemExists))
2342 return $member->canAlterItem($tb_id);
2344 return $member->isAdmin();
2347 /**************************************************************************************/
2348 /* Plugin API calls, for installation, configuration and setup */
2350 function getName() { return 'TrackBack'; }
2351 function getAuthor() { return 'rakaz + nakahara21 + hsur'; }
2352 function getURL() { return 'http://blog.cles.jp/np_cles/category/31/subcatid/3'; }
2353 function getVersion() { return '2.0.3 jp10'; }
2354 function getDescription() { return _TB_DESCRIPTION; }
2356 //modify start+++++++++
2358 function getTableList() { return array(sql_table("plugin_tb"), sql_table("plugin_tb_lookup")); }
2359 function getEventList() { return array('QuickMenu','PostAddItem','AddItemFormExtras','EditItemFormExtras','PreUpdateItem','PrepareItemForEdit', 'BookmarkletExtraHead'); }
2361 function getTableList() { return array(sql_table("plugin_tb"), sql_table("plugin_tb_lookup"), sql_table('plugin_tb_lc')); }
2363 function getEventList() { return array('QuickMenu','PostAddItem','AddItemFormExtras','EditItemFormExtras','PreUpdateItem','PrepareItemForEdit', 'BookmarkletExtraHead', 'RetrieveTrackback', 'SendTrackback', 'InitSkinParse'); }
2364 //modify end+++++++++
2365 function getMinNucleusVersion() { return 330; }
2367 function supportsFeature($feature) {
2369 case 'SqlTablePrefix':
2371 //modify start+++++++++
2374 //modify end+++++++++
2381 function hasAdminArea() { return 1; }
2383 function event_QuickMenu(&$data) {
2384 global $member, $nucleus, $blogid;
2386 // only show to admins
2387 if (!$member->isLoggedIn() || !$member->isAdmin()) return;
2392 'title' => 'Trackback',
2393 'url' => $this->getAdminURL(),
2394 'tooltip' => 'Manage your trackbacks'
2399 function install() {
2400 $this->createOption('AcceptPing', _TB_AcceptPing,'yesno','yes');
2401 $this->createOption('SendPings', _TB_SendPings,'yesno','yes');
2402 $this->createOption('AutoXMLHttp', _TB_AutoXMLHttp, 'yesno', 'yes');
2403 $this->createOption('CheckIDs', _TB_CheckIDs,'yesno','yes');
2405 $this->createOption('tplHeader', _TB_tplHeader, 'textarea', _TB_tplHeader_VAL);
2406 $this->createOption('tplEmpty', _TB_tplEmpty, 'textarea', _TB_tplEmpty_VAL);
2407 $this->createOption('tplItem', _TB_tplItem, 'textarea', _TB_tplItem_VAL);
2408 $this->createOption('tplFooter', _TB_tplFooter, 'textarea', _TB_tplFooter_VAL);
2410 $this->createOption('tplLocalHeader', _TB_tplLocalHeader, 'textarea', _TB_tplLocalHeader_VAL);
2411 $this->createOption('tplLocalEmpty', _TB_tplLocalEmpty, 'textarea', _TB_tplLocalEmpty_VAL);
2412 $this->createOption('tplLocalItem', _TB_tplLocalItem, 'textarea', _TB_tplLocalItem_VAL);
2413 $this->createOption('tplLocalFooter', _TB_tplLocalFooter, 'textarea', _TB_tplLocalFooter_VAL);
2416 $this->createOption('tplTbNone', _TB_tplTbNone, 'text', "No Trackbacks");
2417 $this->createOption('tplTbOne', _TB_tplTbOne, 'text', "1 Trackback");
2418 $this->createOption('tplTbMore', _TB_tplTbMore, 'text', "<%number%> Trackbacks");
2419 $this->createOption('dateFormat', _TB_dateFormat, 'text', _TB_dateFormat_VAL);
2421 $this->createOption('NotifyEmail', _TB_NotifyEmail,'text','');
2422 $this->createOption('DropTable', _TB_DropTable,'yesno','no');
2424 $this->createOption('HideUrl',_TB_HideUrl,'yesno','yes');
2425 $this->createOption('ajaxEnabled',_TB_ajaxEnabled,'yesno','no');
2427 $this->createItemOption('ItemAcceptPing',_TB_ItemAcceptPing,'yesno','yes');
2428 $this->createItemOption('isAcceptW/OLink',_TB_isAcceptWOLink,'select','default', _TB_isAcceptWOLink_VAL);
2430 $this->createBlogOption('NotifyEmailBlog', _TB_NotifyEmailBlog,'text','');
2431 $this->createBlogOption('isAcceptW/OLinkDef',_TB_isAcceptWOLinkDef,'select','block', _TB_isAcceptWOLinkDef_VAL);
2432 $this->createBlogOption('AllowTrackBack',_TB_AllowTrackBack,'yesno','yes');
2437 CREATE TABLE IF NOT EXISTS
2438 ".sql_table('plugin_tb')."
2440 `id` INT(11) NOT NULL AUTO_INCREMENT,
2441 `tb_id` INT(11) NOT NULL,
2442 `url` TEXT NOT NULL,
2443 `block` TINYINT(4) NOT NULL,
2444 `spam` TINYINT(4) NOT NULL,
2445 `link` TINYINT(4) NOT NULL,
2449 `timestamp` DATETIME,
2456 CREATE TABLE IF NOT EXISTS
2457 ".sql_table('plugin_tb_lookup')."
2459 `link` TEXT NOT NULL,
2460 `url` TEXT NOT NULL,
2463 PRIMARY KEY (`link` (100))
2466 //modify start+++++++++
2467 @sql_query('ALTER TABLE `' . sql_table('plugin_tb') . '` ADD INDEX `tb_id_block_timestamp_idx` ( `tb_id`, `block`, `timestamp` DESC )');
2468 @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))');
2469 //modify end+++++++++
2472 function uninstall() {
2473 if ($this->getOption('DropTable') == 'yes') {
2474 sql_query ('DROP TABLE '.sql_table('plugin_tb'));
2475 sql_query ('DROP TABLE '.sql_table('plugin_tb_lookup'));
2476 sql_query ("DROP table ".sql_table('plugin_tb_lc'));
2481 // include language file for this plugin
2482 $language = ereg_replace( '[\\|/]', '', getLanguageName());
2483 if (file_exists($this->getDirectory().'language/'.$language.'.php'))
2484 include_once($this->getDirectory().'language/'.$language.'.php');
2486 include_once($this->getDirectory().'language/'.'english.php');
2487 $this->notificationMail = _TB_NORTIFICATION_MAIL_BODY;
2488 $this->notificationMailTitle = _TB_NORTIFICATION_MAIL_TITLE;