phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file trackback.php

Documentation is available at trackback.php

  1. <?php
  2. /**
  3.  * This file handles trackback requests
  4.  *
  5.  * This file is part of Quam Plures - {@link http://quamplures.net/}
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
  10.  *  Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  11.  *
  12.  *  {@internal License choice
  13.  *  - If you have received this file as part of a package, please find the license.txt file in
  14.  *    the same folder or the closest folder above for complete license terms.
  15.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  16.  *    then you must choose one of the following licenses before using the file:
  17.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  18.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  19.  *  }}}
  20.  *
  21.  *  {@internal Open Source relicensing agreement:
  22.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  23.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  24.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  25.  *  }}}
  26.  *
  27.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  28.  * @author blueyed: Daniel HAHLER
  29.  * @author fplanque: Francois PLANQUE
  30.  *
  31.  * @package pond
  32.  */
  33.  
  34.  
  35. /**
  36.  * Initialize everything:
  37.  */
  38. require_once dirname(__FILE__).'/../qp_config/_config.php';
  39.  
  40. require_once $inc_path.'_main.inc.php';
  41.  
  42. /**
  43.  * Send a trackback response and exits.
  44.  *
  45.  * @param integer Error code
  46.  * @param string Error message
  47.  */
  48. function trackback_response$error 0$error_message '' )
  49. // trackback - reply
  50.     global $io_charset;
  51.  
  52.     echo '<?xml version="1.0" encoding="'.$io_charset.'"?'.">\n";
  53.     echo "<response>\n";
  54.     echo "<error>$error</error>\n";
  55.     echo "<message>$error_message</message>\n";
  56.     echo "</response>";
  57.     exit(0);
  58. }
  59.  
  60. // statuses allowed for acting on:
  61. $show_statuses array'published''protected''private' );
  62.  
  63. param'tb_id''integer' );
  64. param'url''string' );
  65. param'title''string' );
  66. param'excerpt''html' );
  67. param'blog_name''string' );
  68.  
  69.  
  70. ifempty($tb_id) )
  71. // No parameter for ID, get if from URL:
  72.     $path_elements explode'/'$ReqPath30 );
  73.     $tb_id intval$path_elements[count($path_elements)-1);
  74. }
  75.  
  76.  
  77. ifempty($_GET['__mode']) )
  78. // some MT extension (AFAIK), that we do not support
  79.     return;
  80. }
  81.  
  82. ifempty($tb_id) )
  83. {
  84.     trackback_response1'No trackback post ID given.' )// exits
  85. }
  86. ifempty($url) )
  87. {
  88.     trackback_response1'No url to your permanent entry given.' )// exits
  89. }
  90.  
  91. @header('Content-Type: text/xml');
  92.  
  93. $ItemCache get_Cache'ItemCache' );
  94. if!$commented_Item $ItemCache->get_by_ID$tb_idfalse ) ) )
  95. {
  96.     trackback_response1'Sorry, the requested post doesn\'t exist.' )// exits
  97. }
  98.  
  99. if!$Blog $commented_Item->get_Blog() ) )
  100. {
  101.     trackback_response1'Sorry, could not get the post\'s weblog.' )// exits
  102. }
  103.  
  104. if$Blog->get('allowtrackbacks') )
  105. {
  106.     trackback_response1'Sorry, this weblog does not allow you to trackback its posts.' )// exits
  107. }
  108.  
  109. // Commented out again, because it's comment specific: if( ! $commented_Item->can_comment( NULL ) )
  110. // "BeforeTrackbackInsert" should be hooked instead!
  111. if$commented_Item->comment_status != 'open' )
  112. {
  113.     trackback_response1'Sorry, this item does not accept trackbacks.' )// exits
  114. }
  115.  
  116.  
  117. // CHECK content
  118. if$error validate_url$url'commenting' ) )
  119. {
  120.     $Messages->addT_('Supplied URL is invalid: ').$error'error' );
  121. }
  122.  
  123. if$Messages->count('error') )
  124. {
  125.     trackback_response1$Messages->get_string'''''all'"\n" ) )// exits
  126. }
  127.  
  128.  
  129. $title strip_tags($title);
  130. $title (strlen($title255substr($title0252).'...' $title;
  131. $excerpt strip_tags($excerpt);
  132. $excerpt (strlen($excerpt255substr($excerpt0252).'...' $excerpt;
  133. $blog_name htmlspecialchars($blog_name);
  134. $blog_name (strlen($blog_name255substr($blog_name0252).'...' $blog_name;
  135.  
  136. $comment '';
  137. ifempty($title) )
  138. {
  139.     $comment .= '<strong>'.$title.'</strong>';
  140.  
  141.     ifempty($excerpt) )
  142.     {
  143.         $comment .= '<br />';
  144.     }
  145. }
  146. $comment .= $excerpt;
  147.  
  148. $comment format_to_post$comment1)// includes antispam
  149. ifempty($comment) )
  150. // comment should not be empty!
  151.     $Messages->addT_('Please do not send empty comment')'error' );
  152. }
  153.  
  154.  
  155. /**
  156.  * @global Comment Trackback object
  157.  */
  158. $Comment new Comment();
  159. $Comment->set'type''trackback' );
  160. $Comment->set_Item$commented_Item );
  161. $Comment->set'author'$blog_name );
  162. $Comment->set'author_url'$url );
  163. $Comment->set'author_IP'$Hit->IP );
  164. $Comment->set'date'date('Y-m-d H:i:s'$localtimenow ) );
  165. $Comment->set'content'$comment );
  166. // Assign default status for new comments:
  167. $Comment->set'status'$commented_Item->Blog->get_setting('new_feedback_status') );
  168.  
  169.  
  170. // Trigger event, which may add a message of category "error":
  171. $Plugins->trigger_event'BeforeTrackbackInsert'array'Comment' => $Comment ) );
  172.  
  173.  
  174. // Display errors:
  175. if$errstring $Messages->get_string'Cannot insert trackback, please correct these errors:''' ) )
  176. {
  177.     trackback_response(1$errstring);
  178.     // tblue> Note: the spec at <http://www.sixapart.com/pronet/docs/trackback_spec>
  179.     //    only shows error code 1 in the example response
  180.     //    and we also only check for code 1 in TB answers.
  181. }
  182.  
  183.  
  184. // Record trackback into DB:
  185. $Comment->dbinsert();
  186.  
  187.  
  188. if$Comment->ID == )
  189. {
  190.     // Exit silently! Wz don't want to give an easy tool to try and pass the filters.
  191.     trackback_response0'ok' );
  192. }
  193.  
  194.  
  195. /*
  196.  * ----------------------------
  197.  * New trackback notification:
  198.  * ----------------------------
  199.  */
  200. // TODO: dh> this should only send published feedback probably and should also use "outbound_notifications_mode"
  201. $Comment->send_email_notifications();
  202.  
  203.  
  204. // Trigger event: a Plugin should cleanup any temporary data here..
  205. // fp>> WARNING: won't be called if trackback gets deleted by antispam
  206. $Plugins->trigger_event'AfterTrackbackInsert'array'Comment' => $Comment ) );
  207.  
  208.  
  209. // fp>TODO: warn about moderation
  210. trackback_response0'ok' );
  211.  
  212.  
  213. ?>