b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: htsrv ] [ index: htsrv ] [ all elements ]

Source for file trackback.php

Documentation is available at trackback.php

  1. <?php
  2. /**
  3.  * This file handles trackback requests
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package htsrv
  10.  */
  11.  
  12. /**
  13.  * Initialize everything:
  14.  */
  15. require_once (dirname(__FILE__).'/../b2evocore/_main.php');
  16.  
  17. // statuses allowed for acting on:
  18. $show_statuses array'published''protected''private' );
  19.  
  20. param'tb_id''integer' );
  21. param'url''string' );
  22. param'title''string' );
  23. param'excerpt''html' );
  24. param'blog_name''string' );
  25. if(empty($tb_id))
  26. {    // No parameter for ID, get if from URL:
  27.     $path_elements explode'/'$ReqPath30 );
  28.     $tb_id intval$path_elements[count($path_elements)-1);
  29. }
  30.  
  31. if ((strlen(''.$tb_id)) && (empty($HTTP_GET_VARS['__mode'])) && (strlen(''.$url)))
  32. {
  33.     @header('Content-Type: text/xml');
  34.  
  35.     $comment_post_ID $tb_id;
  36.     $postdata get_postdata($comment_post_ID);
  37.     $blog $postdata['Blog'];
  38.     $blogparams get_blogparams_by_ID$blog );
  39.  
  40.     if!get_bloginfo('allowtrackbacks'$blogparams) )
  41.     {
  42.         trackback_response(1'Sorry, this weblog does not allow you to trackback its posts.');
  43.     }
  44.     if$postdata['comments'!= 'open' )
  45.     {
  46.         trackback_response1'Sorry, this item does not accept comments.' );
  47.     }
  48.  
  49.     $title strip_tags($title);
  50.     $title (strlen($title255substr($title0252).'...' $title;
  51.     $excerpt strip_tags($excerpt);
  52.     $excerpt (strlen($excerpt255substr($excerpt0252).'...' $excerpt;
  53.     $blog_name htmlspecialchars($blog_name);
  54.     $blog_name (strlen($blog_name255substr($blog_name0252).'...' $blog_name;
  55.  
  56.     $comment "<strong>$title</strong><br />$excerpt";
  57.  
  58.     $original_comment $comment;
  59.  
  60.     $user_ip $_SERVER['REMOTE_ADDR'];
  61.     $user_ip explode','$user_ip );
  62.     $user_ip $user_ip[0];
  63.     $user_domain gethostbyaddr($user_ip);
  64.     $now date('Y-m-d H:i:s'$localtimenow );
  65.  
  66.     // CHECK and FORMAT content
  67.     if$error validate_url$url$comments_allowed_uri_scheme ) )
  68.     {
  69.         errors_addT_('Supplied URL is invalid: ').$error );
  70.     }
  71.  
  72.     $comment format_to_post($comment,1,1);
  73.     ifempty($comment) )
  74.     // comment should not be empty!
  75.         errors_addT_('Please do not send empty comment') );
  76.     }
  77.     elseifantispam_checkstrip_tags($comment) ) )
  78.     {
  79.         errors_addT_('Supplied comment is invalid') );
  80.     }
  81.  
  82.     if$errstring errors_string'Cannot insert trackback, please correct these errors:''' ) )
  83.     {
  84.         trackback_response(2$errstring);    // TODO: check that error code 2 is ok
  85.         die();
  86.     }
  87.  
  88.     $comment_author $blog_name;
  89.     $comment_author_email '';
  90.     $comment_author_url $url;
  91.  
  92.     $query "INSERT INTO $tablecomments( comment_post_ID, comment_type, comment_author,
  93.                                                                                 comment_author_email, comment_author_url, comment_author_IP,
  94.                                                                                 comment_date, comment_content)
  95.                         VALUES( $comment_post_ID, 'trackback', '".$DB->escape($comment_author)."',
  96.                                         '".$DB->escape($comment_author_email)."', '".$DB->escape($comment_author_url)."', '".$DB->escape($user_ip)."',
  97.                                         '$now', '".$DB->escape($comment)."' )";
  98.     if!$DB->query$query ) )
  99.     {
  100.         trackback_response(2"There is an error with the database, it can't store your comment...<br />Contact the <a href=\"mailto:$admin_email\">webmaster</a>");    // TODO: check that error code 2 is ok
  101.         die ();
  102.     }
  103.  
  104.  
  105.     /*
  106.      * New trackback notification:
  107.      */
  108.     $authordata get_userdata($postdata['Author_ID']);
  109.     ifget_user_info'notify'$authordata ) )
  110.     {    // Author wants to be notified:
  111.         locale_temp_switchget_user_info'locale'$authordata ) );
  112.         $recipient get_user_info'email'$authordata );
  113.         $subject sprintfT_('New trackback on your post #%d "%s"')$comment_post_ID$postdata['Title');
  114.  
  115.         // fplanque added:
  116.         $comment_blogparams get_blogparams_by_ID$blog );
  117.  
  118.         $notify_message  sprintfT_('New trackback on your post #%d "%s"')$comment_post_ID$postdata['Title')."\n";
  119.         $notify_message .= url_add_paramget_bloginfo('blogurl'$comment_blogparams)"p=$comment_post_ID&tb=1\n\n"'&' );
  120.         $notify_message .= T_('Website')."$comment_author (IP: $user_ip , $user_domain)\n";
  121.         $notify_message .= T_('Url')."$comment_author_url\n";
  122.         $notify_message .= T_('Excerpt').": \n".$original_comment."\n\n";
  123.         $notify_message .= T_('Edit/Delete').': '.$admin_url.'/b2browse.php?blog='.$blog.'&p='.$comment_post_ID."&c=1\n\n";
  124.  
  125.         send_mail$recipient$subject$notify_message$notify_from );
  126.         locale_restore_previous();
  127.  
  128.     }
  129.  
  130.     trackback_response(0,'ok');
  131.  
  132.  
  133. }
  134.  
  135.  
  136. ?>

Documentation generated on Tue, 20 May 2008 01:52:03 +0200 by phpDocumentor 1.4.2