[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/comments/ -> _trackback.funcs.php (source)

   1  <?php
   2  /**

   3   * This file implements trackback functions.

   4   *

   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}.

   9   * Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.

  10   *

  11   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)

  12   *

  13   * {@internal Open Source relicensing agreement:

  14   * Daniel HAHLER grants Francois PLANQUE the right to license

  15   * Daniel HAHLER's contributions to this file and the b2evolution project

  16   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  17   * }}

  18   *

  19   * @package evocore

  20   *

  21   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  22   * @author cafelog (team)

  23   * @author blueyed: Daniel HAHLER.

  24   * @author fplanque: Francois PLANQUE.

  25   * @author jmuto: Jun MUTO

  26   * @author sakichan: Nobuo SAKIYAMA.

  27   * @author vegarg: Vegar BERG GULDAL.

  28   *

  29   * @version $Id: _trackback.funcs.php,v 1.1 2007/06/25 10:59:40 fplanque Exp $

  30   */
  31  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  32  
  33  
  34  /**

  35   * trackbacks(-)

  36   *

  37   * Do multiple trackbacks

  38   *

  39   * fplanque: added

  40   */
  41  function trackbacks( $post_trackbacks, $content, $post_title, $post_ID )
  42  {
  43      global $Messages;
  44  
  45      $excerpt = (strlen(strip_tags($content)) > 255) ? substr(strip_tags($content), 0, 252).'...' : strip_tags($content);
  46      $Messages->add( T_('Excerpt sent in trackbacks:').' '.$excerpt, 'note' );
  47      $trackback_urls = split('( )+', $post_trackbacks,10);        // fplanque: ;

  48      foreach($trackback_urls as $tb_url)
  49      { // trackback each url:
  50          $tb_url = trim($tb_url);
  51          if( empty( $tb_url ) ) continue;
  52          trackback($tb_url, $post_title, $excerpt, $post_ID);
  53      }
  54  }
  55  
  56  
  57  /**

  58   * Send Trackback to single URL

  59   *

  60   * trackback(-)

  61   *

  62   * @todo add autodiscovery

  63   */
  64  function trackback(
  65      $trackback_url,
  66      $title,
  67      $excerpt,
  68      $ID) // post ID
  69  {
  70      global $app_name, $app_version, $Blog;
  71  
  72      echo '<p>', T_('Sending trackback to:'), ' ', htmlspecialchars($trackback_url), " ...\n";
  73  
  74      $title = rawurlencode($title);
  75      $excerpt = rawurlencode($excerpt);
  76      $blog_name = rawurlencode($Blog->get( 'name' ));
  77      $ItemCache = & get_Cache( 'ItemCache' );
  78      $Item = & $ItemCache->get_by_ID( $ID );
  79      $url = rawurlencode( $Item->get_permanent_url('', '', '&') );
  80      // dis is the trackback stuff to be sent:

  81      $query_string = "title=$title&url=$url&blog_name=$blog_name&excerpt=$excerpt";
  82      // echo "url:$trackback_url<br>$sending:$query_string<br />";

  83  
  84      $result = '';
  85      if (strstr($trackback_url, '?'))
  86      {
  87          echo '[get]';
  88          $trackback_url .= "&".$query_string;;
  89          flush();
  90          if( $fp = fopen($trackback_url, 'r') )
  91          {
  92              // blueyed>> why do we here just read the first 4kb, but in the POSTed response everything?

  93              // fp>> this is dirty code... I've never really reviewed it entirely. Feel free to refactor as much as needed.

  94              $result = fread($fp, 4096);
  95              fclose($fp);
  96  
  97              /* debug code

  98              $debug_file = 'trackback.log';

  99              $fp = fopen($debug_file, 'a');

 100              fwrite($fp, "\n*****\nTrackback URL query:\n\n$trackback_url\n\nResponse:\n\n");

 101              fwrite($fp, $result);

 102              fwrite($fp, "\n\n");

 103              fclose($fp);

 104              */
 105          }
 106  
 107      }
 108      else
 109      {
 110          echo '[post]';
 111          $trackback_url = parse_url($trackback_url);
 112          if( ! empty($trackback_url['host']) && ! empty($trackback_url['path']) )
 113          { // Only try trackback if we have host and path:
 114              $port = isset($trackback_url['port']) ? $trackback_url['port'] : 80;
 115              $http_request  = 'POST '.$trackback_url['path']." HTTP/1.0\r\n";
 116              $http_request .= 'Host: '.$trackback_url['host']."\r\n";
 117              $http_request .= 'Content-Type: application/x-www-form-urlencoded'."\r\n";
 118              $http_request .= 'Content-Length: '.strlen($query_string)."\r\n";
 119              $http_request .= "User-Agent: $app_name/$app_version\r\n";
 120              $http_request .= "\r\n";
 121              $http_request .= $query_string;
 122              flush();
 123              if( $fs = @fsockopen($trackback_url['host'], $port, $errno, $errst, 20) ) // this timeout is just for setting up the socket
 124              {
 125                  // Set timeout for data:

 126                  if( function_exists('stream_set_timeout') )
 127                  {
 128                      stream_set_timeout( $fs, 20 ); // PHP 4.3.0

 129                  }
 130                  else
 131                  {
 132                      socket_set_timeout( $fs, 20 ); // PHP 4

 133                  }
 134                  fputs($fs, $http_request);
 135                  $result = '';
 136                  while(!feof($fs))
 137                  {
 138                      $result .= fgets($fs, 4096);
 139                  }
 140  
 141                  /* debug code

 142                  $debug_file = 'trackback.log';

 143                  $fp = fopen($debug_file, 'a');

 144                  fwrite($fp, "\n*****\nRequest:\n\n$http_request\n\nResponse:\n\n$result");

 145                  while(!@feof($fs)) {

 146                      fwrite($fp, @fgets($fs, 4096));

 147                  }

 148                  fwrite($fp, "\n\n");

 149                  fclose($fp);

 150                  */
 151  
 152                  fclose($fs);
 153              }
 154          }
 155      }
 156      // extract the error code and message, then make the error code readable

 157      if ( preg_match("/<error>[\r\n\t ]*(\d+)[\r\n\t ]*<\/error>/", $result, $error) )
 158      {
 159          preg_match("/<message>(.*?)<\/message>/", $result, $error_message);
 160  
 161          $message = isset($error_message[1]) ? $error_message[1] : '';
 162  
 163          switch ($error[1]) {
 164              case '0':
 165                  $result_message = '[' . T_('Succeeded') . '] ' . $message;
 166                  break;
 167              case '1':
 168                  $result_message = '[' . T_('Failed') . '] ' . $message;
 169                  break;
 170              default:
 171                  $result_message = '[' . T_('Unknown error') . ' (' . $error[1] . ')] ' . $message;
 172                  break;
 173          }
 174      }
 175      else
 176      {
 177          $result_message = T_('No valid trackback response. Maybe the given url is not a Trackback url.') . ' &quot;' . $result . '&quot;';
 178      }
 179      echo '<br />', T_('Response:'), ' ', strip_tags($result_message), "</p>\n";
 180      return $result;
 181  }
 182  
 183  
 184  
 185  /**

 186   * @deprecated deprecated by {@link Item::feedback_link()}

 187   */
 188  function trackback_number( $zero='#', $one='#', $more='#', $post_ID = NULL )
 189  {
 190      if( $zero == '#' ) $zero = T_('Trackback (0)');
 191      if( $one == '#' ) $one = T_('Trackback (1)');
 192      if( $more == '#' ) $more = T_('Trackbacks (%d)');
 193  
 194      if( empty( $post_ID ) )
 195      {
 196          global $id;
 197          $post_ID = $id;
 198      }
 199      $number = generic_ctp_number($post_ID, 'trackbacks');
 200      if ($number == 0) {
 201          $blah = $zero;
 202      } elseif ($number == 1) {
 203          $blah = $one;
 204      } elseif ($number  > 1) {
 205          $n = $number;
 206          $more = str_replace('%d', $n, $more);
 207          $blah = $more;
 208      }
 209      echo $blah;
 210  }
 211  
 212  
 213  /*

 214   * $Log: _trackback.funcs.php,v $

 215   * Revision 1.1  2007/06/25 10:59:40  fplanque

 216   * MODULES (refactored MVC)

 217   *

 218   * Revision 1.14  2007/05/09 00:58:54  fplanque

 219   * massive cleanup of old functions

 220   *

 221   * Revision 1.13  2007/04/26 00:11:08  fplanque

 222   * (c) 2007

 223   *

 224   * Revision 1.12  2007/03/24 20:41:16  fplanque

 225   * Refactored a lot of the link junk.

 226   * Made options blog specific.

 227   * Some junk still needs to be cleaned out. Will do asap.

 228   *

 229   * Revision 1.11  2006/12/12 02:53:57  fplanque

 230   * Activated new item/comments controllers + new editing navigation

 231   * Some things are unfinished yet. Other things may need more testing.

 232   *

 233   * Revision 1.10  2006/09/15 23:42:15  blueyed

 234   * Fixed possible E_NOTICE when sending a successful trackback

 235   *

 236   * Revision 1.9  2006/08/21 16:07:44  fplanque

 237   * refactoring

 238   *

 239   * Revision 1.8  2006/08/19 07:56:31  fplanque

 240   * Moved a lot of stuff out of the automatic instanciation in _main.inc

 241   *

 242   * Revision 1.7  2006/07/04 17:32:30  fplanque

 243   * no message

 244   */
 245  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics