[ Index ]

WordPress Source Cross Reference

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  $title     = $_POST['title'];
  35  $excerpt   = $_POST['excerpt'];
  36  $blog_name = $_POST['blog_name'];
  37  $charset   = $_POST['charset'];
  38  
  39  if ($charset)
  40      $charset = strtoupper( trim($charset) );
  41  else
  42      $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS';
  43  
  44  if ( function_exists('mb_convert_encoding') ) { // For international trackbacks
  45      $title     = mb_convert_encoding($title, get_settings('blog_charset'), $charset);
  46      $excerpt   = mb_convert_encoding($excerpt, get_settings('blog_charset'), $charset);
  47      $blog_name = mb_convert_encoding($blog_name, get_settings('blog_charset'), $charset);
  48  }
  49  
  50  if ( is_single() || is_page() ) 
  51      $tb_id = $posts[0]->ID;
  52  
  53  if ( !intval( $tb_id ) )
  54      trackback_response(1, 'I really need an ID for this to work.');
  55  
  56  if (empty($title) && empty($tb_url) && empty($blog_name)) {
  57      // If it doesn't look like a trackback at all...
  58      wp_redirect(get_permalink($tb_id));
  59      exit;
  60  }
  61  
  62  if ( !empty($tb_url) && !empty($title) && !empty($tb_url) ) {
  63      header('Content-Type: text/xml; charset=' . get_option('blog_charset') );
  64  
  65      $pingstatus = $wpdb->get_var("SELECT ping_status FROM $wpdb->posts WHERE ID = $tb_id");
  66  
  67      if ( 'open' != $pingstatus )
  68          trackback_response(1, 'Sorry, trackbacks are closed for this item.');
  69  
  70      $title =  wp_specialchars( strip_tags( $title ) );
  71      $excerpt = strip_tags($excerpt);
  72      if ( function_exists('mb_strcut') ) { // For international trackbacks
  73          $excerpt = mb_strcut($excerpt, 0, 252, get_settings('blog_charset')) . '...';
  74          $title = mb_strcut($title, 0, 250, get_settings('blog_charset')) . '...';
  75      } else {
  76          $excerpt = (strlen($excerpt) > 255) ? substr($excerpt, 0, 252) . '...' : $excerpt;
  77          $title = (strlen($title) > 250) ? substr($title, 0, 250) . '...' : $title;
  78      }
  79  
  80      $comment_post_ID = $tb_id;
  81      $comment_author = $blog_name;
  82      $comment_author_email = '';
  83      $comment_author_url = $tb_url;
  84      $comment_content = "<strong>$title</strong>\n\n$excerpt";
  85      $comment_type = 'trackback';
  86  
  87      $dupe = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND comment_author_url = '$comment_author_url'");
  88      if ( $dupe )
  89          trackback_response(1, 'We already have a ping from that URI for this post.');
  90  
  91      $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type');
  92  
  93      wp_new_comment($commentdata);
  94  
  95      do_action('trackback_post', $wpdb->insert_id);
  96      trackback_response(0);
  97  }
  98  ?>

Your comment here...

Name: Location:
Comments:


List: Classes | Functions | Variables | Constants | Tables

Generated: Sat Jul 15 11:57:04 2006 Courtesy of Taragana