[ PHPXref.com ] [ Generated: Tue Apr 1 10:47:01 2008 ] [ WordPress 2.5 ]
[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> wp-trackback.php (source)

   1  <?php
   2  
   3  if (empty($wp)) {
   4      require_once('./wp-config.php');
   5      wp('tb=1');
   6  }
   7  
   8  function trackback_response($error = 0, $error_message = '') {
   9      header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
  10      if ($error) {
  11          echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
  12          echo "<response>\n";
  13          echo "<error>1</error>\n";
  14          echo "<message>$error_message</message>\n";
  15          echo "</response>";
  16          die();
  17      } else {
  18          echo '<?xml version="1.0" encoding="utf-8"?'.">\n";
  19          echo "<response>\n";
  20          echo "<error>0</error>\n";
  21          echo "</response>";
  22      }
  23  }
  24  
  25  // trackback is done by a POST
  26  $request_array = 'HTTP_POST_VARS';
  27  
  28  if ( !$_GET['tb_id'] ) {
  29      $tb_id = explode('/', $_SERVER['REQUEST_URI']);
  30      $tb_id = intval( $tb_id[ count($tb_id) - 1 ] );
  31  }
  32  
  33  $tb_url  = $_POST['url'];
  34  $charset = $_POST['charset'];
  35  
  36  // These three are stripslashed here so that they can be properly escaped after mb_convert_encoding()
  37  $title     = stripslashes($_POST['title']);
  38  $excerpt   = stripslashes($_POST['excerpt']);
  39  $blog_name = stripslashes($_POST['blog_name']);
  40  
  41  if ($charset)
  42      $charset = strtoupper( trim($charset) );
  43  else
  44      $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
  45  
  46  // No valid uses for UTF-7
  47  if ( false !== strpos($charset, 'UTF-7') )
  48      die;
  49  
  50  if ( function_exists('mb_convert_encoding') ) { // For international trackbacks
  51      $title     = mb_convert_encoding($title, get_option('blog_charset'), $charset);
  52      $excerpt   = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset);
  53      $blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset);
  54  }
  55  
  56  // Now that mb_convert_encoding() has been given a swing, we need to escape these three
  57  $title     = $wpdb->escape($title);
  58  $excerpt   = $wpdb->escape($excerpt);
  59  $blog_name = $wpdb->escape($blog_name);
  60  
  61  if ( is_single() || is_page() )
  62      $tb_id = $posts[0]->ID;
  63  
  64  if ( !intval( $tb_id ) )
  65      trackback_response(1, 'I really need an ID for this to work.');
  66  
  67  if (empty($title) && empty($tb_url) && empty($blog_name)) {
  68      // If it doesn't look like a trackback at all...
  69      wp_redirect(get_permalink($tb_id));
  70      exit;
  71  }
  72  
  73  if ( !empty($tb_url) && !empty($title) ) {
  74      header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
  75  
  76      if ( !pings_open($tb_id) )
  77          trackback_response(1, 'Sorry, trackbacks are closed for this item.');
  78  
  79      $title =  wp_html_excerpt( $title, 250 ).'...';
  80      $excerpt = wp_html_excerpt( $excerpt, 252 ).'...';
  81  
  82      $comment_post_ID = (int) $tb_id;
  83      $comment_author = $blog_name;
  84      $comment_author_email = '';
  85      $comment_author_url = $tb_url;
  86      $comment_content = "<strong>$title</strong>\n\n$excerpt";
  87      $comment_type = 'trackback';
  88  
  89      $dupe = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_author_url = '$comment_author_url'");
  90      if ( $dupe )
  91          trackback_response(1, 'We already have a ping from that URL for this post.');
  92  
  93      $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
  94  
  95      wp_new_comment($commentdata);
  96  
  97      do_action('trackback_post', $wpdb->insert_id);
  98      trackback_response(0);
  99  }
 100  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]