b2evolution

Multilingual multiuser multiblog engine

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

Source for file _functions_trackback.php

Documentation is available at _functions_trackback.php

  1. <?php
  2. /**
  3.  * Trackback functions
  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 evocore
  10.  * @author This file built upon code from original b2 - http://cafelog.com/
  11.  */
  12. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  13.  
  14. /**
  15.  * trackbacks(-)
  16.  *
  17.  * Do multiple trackbacks
  18.  *
  19.  * fplanque: added
  20.  */
  21. function trackbacks$post_trackbacks$content$post_title$post_ID )
  22. {
  23.     echo "<div class=\"panelinfo\">\n";
  24.     echo "<h3>"T_('Sending trackbacks...')"</h3>\n";
  25.     if(empty($post_trackbacks))
  26.     {
  27.         echo "<p>"T_('No trackback to be sent.')"</p>\n";
  28.     }
  29.     else
  30.     {
  31.         $excerpt (strlen(strip_tags($content)) 255substr(strip_tags($content)0252).'...' strip_tags($content);
  32.         echo "<p>"T_('Excerpt to be sent:')" $excerpt</p>\n";
  33.         $trackback_urls split('( )+'$post_trackbacks,10);        // fplanque: ;
  34.         foreach($trackback_urls as $tb_url)
  35.         {    // trackback each url:
  36.             $tb_url trim($tb_url);
  37.             ifempty$tb_url ) ) continue;
  38.             trackback($tb_url$post_title$excerpt$post_ID);
  39.         }
  40.         echo "<p>"T_('Trackbacks done.')"</p>\n";
  41.     }
  42.     echo "</div>\n";
  43. }
  44.  
  45. /*
  46.  * trackback(-)
  47.  *
  48.  * sending Trackback to single URL:
  49.  * TODO: add autodiscovery
  50.  */
  51. function trackback(
  52.     $trackback_url,
  53.     $title,
  54.     $excerpt,
  55.     $ID// post ID
  56. {
  57.     global $ItemCache;
  58.  
  59.     echo "<p>"T_('Sending trackback to:')" $trackback_url ...\n";
  60.  
  61.     $title urlencode($title);
  62.     $excerpt urlencode($excerpt);
  63.     $blog_name urlencode(get_bloginfo('name'));
  64.     $Item $ItemCache->get_by_ID$ID );
  65.     $url rawurlencode$Item->gen_permalink(''''false'&') );
  66.     // dis is the trackback stuff to be sent:
  67.     $query_string "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt";
  68.     // echo "url:$trackback_url<br>$sending:$query_string<br />";
  69.     if (strstr($trackback_url'?'))
  70.     {
  71.         echo '[get]';
  72.         $trackback_url .= "&".$query_string;;
  73.         flush();
  74.         $fp fopen($trackback_url'r');
  75.         $result fread($fp4096);
  76.         fclose($fp);
  77. /* debug code
  78.         $debug_file = 'trackback.log';
  79.         $fp = fopen($debug_file, 'a');
  80.         fwrite($fp, "\n*****\nTrackback URL query:\n\n$trackback_url\n\nResponse:\n\n");
  81.         fwrite($fp, $result);
  82.         fwrite($fp, "\n\n");
  83.         fclose($fp);
  84. */
  85.  
  86.     }
  87.     else
  88.     {
  89.         echo '[post]';
  90.         $trackback_url parse_url($trackback_url);
  91.         $port = isset($trackback_url['port']$trackback_url['port'80;
  92.         $http_request  'POST '.$trackback_url['path']." HTTP/1.0\r\n";
  93.         $http_request .= 'Host: '.$trackback_url['host']."\r\n";
  94.         $http_request .= 'Content-Type: application/x-www-form-urlencoded'."\r\n";
  95.         $http_request .= 'Content-Length: '.strlen($query_string)."\r\n";
  96.         $http_request .= "\r\n";
  97.         $http_request .= $query_string;
  98.         flush();
  99.         $fs fsockopen($trackback_url['host']$port);
  100.         fputs($fs$http_request);
  101.         $result '';
  102.         while(!feof($fs)) {
  103.             $result .= fgets($fs4096);
  104.         }
  105. /* debug code
  106.         $debug_file = 'trackback.log';
  107.         $fp = fopen($debug_file, 'a');
  108.         fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n$result");
  109.         while(!@feof($fs)) {
  110.             fwrite($fp, @fgets($fs, 4096));
  111.         }
  112.         fwrite($fp, "\n\n");
  113.         fclose($fp);
  114. */
  115.         fclose($fs);
  116.     }
  117.     echo "<br \>"T_('Response:')" $result</p>\n";
  118.     return $result;
  119. }
  120.  
  121. function trackback_response($error 0$error_message '')
  122. {    // trackback - reply
  123.     echo '<?xml version="1.0" encoding="iso-8859-1"?'.">\n";
  124.     echo "<response>\n";
  125.     echo "<error>$error</error>\n";
  126.     echo "<message>$error_message</message>\n";
  127.     echo "</response>";
  128.     die();
  129. }
  130.  
  131.  
  132. /*
  133.  * TEMPLATE FUNCTIONS:
  134.  */
  135.  
  136.  
  137.  
  138. /*****
  139.  * Trackback tags
  140.  *****/
  141.  
  142. /**
  143.  *
  144.  * @deprecated deprecated by {@link Item::trackback_url()}
  145.  */
  146. function trackback_url($display 1)
  147. {
  148.     global $htsrv_url$id;
  149.     global $Settings;
  150.  
  151.     if$Settings->get('links_extrapath') )
  152.     {
  153.         $tb_url "$htsrv_url/trackback.php/$id";
  154.     }
  155.     else
  156.     {
  157.         $tb_url "$htsrv_url/trackback.php?tb_id=$id";
  158.     }
  159.     if ($display{
  160.         echo $tb_url;
  161.     else {
  162.         return $tb_url;
  163.     }
  164. }
  165.  
  166. /**
  167.  * trackback_number(-)
  168.  * @deprecated deprecated by {@link Item::feedback_link()}
  169.  */
  170. function trackback_number$zero='#'$one='#'$more='#' )
  171. {
  172.     if$zero == '#' $zero T_('Trackback (0)');
  173.     if$one == '#' $one T_('Trackback (1)');
  174.     if$more == '#' $more T_('Trackbacks (%d)');
  175.  
  176.     global $id$tablecomments$tb$querycount$cache_trackbacknumber$use_cache;
  177.     $number generic_ctp_number($id'trackbacks');
  178.     if ($number == 0{
  179.         $blah $zero;
  180.     elseif ($number == 1{
  181.         $blah $one;
  182.     elseif ($number  1{
  183.         $n $number;
  184.         $more str_replace('%d'$n$more);
  185.         $blah $more;
  186.     }
  187.     echo $blah;
  188. }
  189.  
  190. /**
  191.  * Displays link to the trackback page
  192.  * @deprecated deprecated by {@link Item::feedback_link()}
  193.  */
  194. function trackback_link($file='',$c=0,$pb=0)
  195. {
  196.     global $id;
  197.     if( ($file == ''|| ($file == '/')    )
  198.         $file get_bloginfo('blogurl');
  199.     echo url_add_param$file'p='.$id );
  200.     if$c == )
  201.     {    // include comments
  202.         echo '&amp;c=1';
  203.     }
  204.     echo '&amp;tb=1';
  205.     if$pb == )
  206.     {    // include pingback
  207.         echo '&amp;pb=1';
  208.     }
  209.     echo '#trackbacks';
  210. }
  211.  
  212. /**
  213.  *
  214.  * @deprecated deprecated by {@link Item::feedback_link()}
  215.  */
  216. function trackback_popup_link($zero='#'$one='#'$more='#'$CSSclass='')
  217. {
  218.     global $blog$id$b2trackbackpopupfile$b2commentsjavascript;
  219.     echo '<a href="';
  220.     if ($b2commentsjavascript{
  221.         echo url_add_paramget_bloginfo('blogurl')'template=popup&amp;p='.$id.'&amp;tb=1' );
  222.         echo '" onclick="b2open(this.href); return false"';
  223.     else {
  224.         // if comments_popup_script() is not in the template, display simple comment link
  225.         trackback_link();
  226.         echo '"';
  227.     }
  228.     if (!empty($CSSclass)) {
  229.         echo ' class="'.$CSSclass.'"';
  230.     }
  231.     echo '>';
  232.     trackback_number($zero$one$more);
  233.     echo '</a>';
  234. }
  235.  
  236. /**
  237.  * This adds trackback autodiscovery information
  238.  *
  239.  * @deprecated deprecated by {@link Item::trackback_rdf()}
  240.  */
  241. function trackback_rdf($timezone=0)
  242. {
  243.     global $id$blogfilename;    // fplanque added: $blogfilename
  244.     // if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) {
  245.     // fplanque WARNING: this isn't a very clean way to validate :/
  246.     // fplanque added: html comments (not perfect but better way of validating!)
  247.         echo "<!--\n";
  248.         echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '."\n";
  249.         echo '    xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
  250.         echo '    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n";
  251.         echo '<rdf:Description'."\n";
  252.         echo '    rdf:about="';
  253.         permalink_single();
  254.         echo '"'."\n";
  255.         echo '    dc:identifier="';
  256.         permalink_single();
  257.         echo '"'."\n";
  258.         echo '    dc:title="'.format_to_output(get_the_title(),'xmlattr').'"'."\n";
  259.         echo '    trackback:ping="'.trackback_url(0).'" />'."\n";
  260.         echo '</rdf:RDF>';
  261.         echo "-->\n";
  262.     // }
  263. }
  264.  
  265. /*****
  266.  * /Trackback tags
  267.  *****/
  268.  
  269.  
  270.  
  271.  
  272.  
  273. ?>

Documentation generated on Tue, 20 May 2008 01:55:05 +0200 by phpDocumentor 1.4.2