converted to unix-style eol
[www-register-wizard.git] / libraries / Trackback.php
index 9988492..844e503 100644 (file)
-<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');\r
-/**\r
- * CodeIgniter\r
- *\r
- * An open source application development framework for PHP 4.3.2 or newer\r
- *\r
- * @package            CodeIgniter\r
- * @author             ExpressionEngine Dev Team\r
- * @copyright  Copyright (c) 2008, EllisLab, Inc.\r
- * @license            http://codeigniter.com/user_guide/license.html\r
- * @link               http://codeigniter.com\r
- * @since              Version 1.0\r
- * @filesource\r
- */\r
-\r
-// ------------------------------------------------------------------------\r
-\r
-/**\r
- * Trackback Class\r
- *\r
- * Trackback Sending/Receiving Class\r
- *\r
- * @package            CodeIgniter\r
- * @subpackage Libraries\r
- * @category   Trackbacks\r
- * @author             ExpressionEngine Dev Team\r
- * @link               http://codeigniter.com/user_guide/libraries/trackback.html\r
- */\r
-class CI_Trackback {\r
-               \r
-       var $time_format        = 'local';\r
-       var $charset            = 'UTF-8';\r
-       var $data                       = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');\r
-       var $convert_ascii      = TRUE;\r
-       var $response           = '';\r
-       var $error_msg          = array();\r
-\r
-       /**\r
-        * Constructor\r
-        *\r
-        * @access      public\r
-        */\r
-       function CI_Trackback()\r
-       {\r
-               log_message('debug', "Trackback Class Initialized");\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Send Trackback\r
-        *\r
-        * @access      public\r
-        * @param       array\r
-        * @return      bool\r
-        */     \r
-       function send($tb_data)\r
-       {               \r
-               if ( ! is_array($tb_data))\r
-               {\r
-                       $this->set_error('The send() method must be passed an array');\r
-                       return FALSE;\r
-               }\r
-               \r
-               // Pre-process the Trackback Data\r
-               foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item)\r
-               {\r
-                       if ( ! isset($tb_data[$item]))\r
-                       {\r
-                               $this->set_error('Required item missing: '.$item);\r
-                               return FALSE;\r
-                       }\r
-                       \r
-                       switch ($item)\r
-                       {\r
-                               case 'ping_url' : $$item = $this->extract_urls($tb_data[$item]);\r
-                                       break;\r
-                               case 'excerpt'  : $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item]))));\r
-                                       break;\r
-                               case 'url'              : $$item = str_replace('&#45;', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))));\r
-                                       break;\r
-                               default                 : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item])));\r
-                                       break;\r
-                       }\r
-\r
-                       // Convert High ASCII Characters\r
-                       if ($this->convert_ascii == TRUE)\r
-                       {\r
-                               if ($item == 'excerpt')\r
-                               {\r
-                                       $$item = $this->convert_ascii($$item);\r
-                               }\r
-                               elseif ($item == 'title')\r
-                               {\r
-                                       $$item = $this->convert_ascii($$item);\r
-                               }\r
-                               elseif($item == 'blog_name')\r
-                               {\r
-                                       $$item = $this->convert_ascii($$item);\r
-                               }\r
-                       }\r
-               }\r
-\r
-               // Build the Trackback data string\r
-               $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset'];\r
-               \r
-               $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset);\r
-                               \r
-               // Send Trackback(s)\r
-               $return = TRUE;\r
-               if (count($ping_url) > 0)\r
-               {\r
-                       foreach ($ping_url as $url)\r
-                       {\r
-                               if ($this->process($url, $data) == FALSE)\r
-                               {\r
-                                       $return = FALSE;\r
-                               }\r
-                       }       \r
-               }\r
-\r
-               return $return;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Receive Trackback  Data\r
-        *\r
-        * This function simply validates the incoming TB data.\r
-        * It returns false on failure and true on success.\r
-        * If the data is valid it is set to the $this->data array\r
-        * so that it can be inserted into a database.\r
-        *\r
-        * @access      public\r
-        * @return      bool\r
-        */     \r
-       function receive()\r
-       {                                       \r
-               foreach (array('url', 'title', 'blog_name', 'excerpt') as $val)\r
-               {\r
-                       if ( ! isset($_POST[$val]) OR $_POST[$val] == '')\r
-                       {\r
-                               $this->set_error('The following required POST variable is missing: '.$val);\r
-                               return FALSE;\r
-                       }\r
-                       \r
-                       $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset']));\r
-       \r
-                       if ($val != 'url' && function_exists('mb_convert_encoding'))\r
-                       {\r
-                               $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']);\r
-                       }\r
-                       \r
-                       $_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]);\r
-                       \r
-                       if ($val == 'excerpt')\r
-                       {\r
-                               $_POST['excerpt'] = $this->limit_characters($_POST['excerpt']);\r
-                       }\r
-                       \r
-                       $this->data[$val] = $_POST[$val];\r
-               }\r
-\r
-               return TRUE;\r
-       }       \r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Send Trackback Error Message\r
-        *\r
-        * Allows custom errors to be set.  By default it\r
-        * sends the "incomplete information" error, as that's\r
-        * the most common one.\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      void\r
-        */     \r
-       function send_error($message = 'Incomplete Information')\r
-       {\r
-               echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>";\r
-               exit;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Send Trackback Success Message\r
-        *\r
-        * This should be called when a trackback has been\r
-        * successfully received and inserted.\r
-        *\r
-        * @access      public\r
-        * @return      void\r
-        */             \r
-       function send_success()\r
-       {\r
-               echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>0</error>\n</response>";\r
-               exit;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Fetch a particular item\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      string\r
-        */     \r
-       function data($item)\r
-       {\r
-               return ( ! isset($this->data[$item])) ? '' : $this->data[$item];\r
-       }\r
-\r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Process Trackback\r
-        *\r
-        * Opens a socket connection and passes the data to\r
-        * the server.  Returns true on success, false on failure\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @param       string\r
-        * @return      bool\r
-        */     \r
-       function process($url, $data)\r
-       {\r
-               $target = parse_url($url);\r
-       \r
-               // Open the socket\r
-               if ( ! $fp = @fsockopen($target['host'], 80))\r
-               {\r
-                       $this->set_error('Invalid Connection: '.$url);\r
-                       return FALSE;\r
-               }\r
-\r
-               // Build the path\r
-               $ppath = ( ! isset($target['path'])) ? $url : $target['path'];\r
-               \r
-               $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath;\r
-\r
-               // Add the Trackback ID to the data string\r
-               if ($id = $this->get_id($url))\r
-               {\r
-                       $data = "tb_id=".$id."&".$data;\r
-               }\r
-\r
-               // Transfer the data\r
-               fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" );\r
-               fputs ($fp, "Host: " . $target['host'] . "\r\n" );\r
-               fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" );\r
-               fputs ($fp, "Content-length: " . strlen($data) . "\r\n" );\r
-               fputs ($fp, "Connection: close\r\n\r\n" );\r
-               fputs ($fp, $data);\r
-\r
-               // Was it successful?\r
-               $this->response = "";\r
-               \r
-               while( ! feof($fp))\r
-               {\r
-                       $this->response .= fgets($fp, 128);\r
-               }\r
-               @fclose($fp);\r
-               \r
-               if ( ! eregi("<error>0</error>", $this->response))\r
-               {\r
-                       $message = 'An unknown error was encountered';\r
-                       \r
-                       if (preg_match("/<message>(.*?)<\/message>/is", $this->response, $match))\r
-                       {\r
-                               $message = trim($match['1']);\r
-                       }\r
-                       \r
-                       $this->set_error($message);\r
-                       return FALSE;\r
-               }\r
-\r
-               return TRUE;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Extract Trackback URLs\r
-        *\r
-        * This function lets multiple trackbacks be sent.\r
-        * It takes a string of URLs (separated by comma or\r
-        * space) and puts each URL into an array\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      string\r
-        */     \r
-       function extract_urls($urls)\r
-       {               \r
-               // Remove the pesky white space and replace with a comma.\r
-               $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls);\r
-               \r
-               // If they use commas get rid of the doubles.\r
-               $urls = str_replace(",,", ",", $urls);\r
-               \r
-               // Remove any comma that might be at the end\r
-               if (substr($urls, -1) == ",")\r
-               {\r
-                       $urls = substr($urls, 0, -1);\r
-               }\r
-                               \r
-               // Break into an array via commas\r
-               $urls = preg_split('/[,]/', $urls);\r
-               \r
-               // Removes duplicates\r
-               $urls = array_unique($urls);\r
-               \r
-               array_walk($urls, array($this, 'validate_url'));\r
-               \r
-               return $urls;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Validate URL\r
-        *\r
-        * Simply adds "http://" if missing\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      string\r
-        */     \r
-       function validate_url($url)\r
-       {\r
-               $url = trim($url);\r
-\r
-               if (substr($url, 0, 4) != "http")\r
-               {\r
-                       $url = "http://".$url;\r
-               }\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Find the Trackback URL's ID\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      string\r
-        */     \r
-       function get_id($url)\r
-       {       \r
-               $tb_id = "";\r
-               \r
-               if (strstr($url, '?'))\r
-               {\r
-                       $tb_array = explode('/', $url);\r
-                       $tb_end   = $tb_array[count($tb_array)-1];\r
-                       \r
-                       if ( ! is_numeric($tb_end))\r
-                       {\r
-                               $tb_end  = $tb_array[count($tb_array)-2];\r
-                       }\r
-                       \r
-                       $tb_array = explode('=', $tb_end);\r
-                       $tb_id  = $tb_array[count($tb_array)-1];\r
-               }\r
-               else\r
-               {\r
-                       if (ereg("/$", $url))\r
-                       {\r
-                               $url = substr($url, 0, -1);\r
-                       }\r
-                               \r
-                       $tb_array = explode('/', $url);\r
-                       $tb_id  = $tb_array[count($tb_array)-1];\r
-                       \r
-                       if ( ! is_numeric($tb_id))\r
-                       {\r
-                               $tb_id  = $tb_array[count($tb_array)-2];\r
-                       }\r
-               }       \r
-                               \r
-               if ( ! preg_match ("/^([0-9]+)$/", $tb_id))\r
-               {\r
-                       return false;\r
-               }\r
-               else\r
-               {\r
-                       return $tb_id;\r
-               }               \r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Convert Reserved XML characters to Entities\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      string\r
-        */\r
-       function convert_xml($str)\r
-       {\r
-               $temp = '__TEMP_AMPERSANDS__';\r
-               \r
-               $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);\r
-               $str = preg_replace("/&(\w+);/",  "$temp\\1;", $str);\r
-               \r
-               $str = str_replace(array("&","<",">","\"", "'", "-"),\r
-                                                  array("&amp;", "&lt;", "&gt;", "&quot;", "&#39;", "&#45;"),\r
-                                                  $str);\r
-                       \r
-               $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);\r
-               $str = preg_replace("/$temp(\w+);/","&\\1;", $str);\r
-                       \r
-               return $str;\r
-       }       \r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Character limiter\r
-        *\r
-        * Limits the string based on the character count. Will preserve complete words.\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @param       integer\r
-        * @param       string\r
-        * @return      string\r
-        */\r
-       function limit_characters($str, $n = 500, $end_char = '&#8230;')\r
-       {\r
-               if (strlen($str) < $n)\r
-               {\r
-                       return $str;\r
-               }\r
-\r
-               $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));\r
-       \r
-               if (strlen($str) <= $n)\r
-               {\r
-                       return $str;\r
-               }\r
-                                                                               \r
-               $out = "";\r
-               foreach (explode(' ', trim($str)) as $val)\r
-               {\r
-                       $out .= $val.' ';                       \r
-                       if (strlen($out) >= $n)\r
-                       {\r
-                               return trim($out).$end_char;\r
-                       }               \r
-               }\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * High ASCII to Entities\r
-        *\r
-        * Converts Hight ascii text and MS Word special chars\r
-        * to character entities\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      string\r
-        */\r
-       function convert_ascii($str)\r
-       {\r
-          $count       = 1;\r
-          $out = '';\r
-          $temp        = array();\r
-               \r
-          for ($i = 0, $s = strlen($str); $i < $s; $i++)\r
-          {\r
-                  $ordinal = ord($str[$i]);\r
-               \r
-                  if ($ordinal < 128)\r
-                  {\r
-                          $out .= $str[$i];                    \r
-                  }\r
-                  else\r
-                  {\r
-                          if (count($temp) == 0)\r
-                          {\r
-                                  $count = ($ordinal < 224) ? 2 : 3;\r
-                          }\r
-                       \r
-                          $temp[] = $ordinal;\r
-                       \r
-                          if (count($temp) == $count)\r
-                          {\r
-                                  $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);\r
-       \r
-                                  $out .= '&#'.$number.';';\r
-                                  $count = 1;\r
-                                  $temp = array();\r
-                          }\r
-                  }\r
-          }\r
-       \r
-          return $out;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Set error message\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @return      void\r
-        */     \r
-       function set_error($msg)\r
-       {\r
-               log_message('error', $msg);\r
-               $this->error_msg[] = $msg;\r
-       }\r
-       \r
-       // --------------------------------------------------------------------\r
-       \r
-       /**\r
-        * Show error messages\r
-        *\r
-        * @access      public\r
-        * @param       string\r
-        * @param       string\r
-        * @return      string\r
-        */     \r
-       function display_errors($open = '<p>', $close = '</p>')\r
-       {       \r
-               $str = '';\r
-               foreach ($this->error_msg as $val)\r
-               {\r
-                       $str .= $open.$val.$close;\r
-               }\r
-       \r
-               return $str;\r
-       }\r
-\r
-}\r
-// END Trackback Class\r
-\r
-/* End of file Trackback.php */\r
+<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+/**
+ * CodeIgniter
+ *
+ * An open source application development framework for PHP 4.3.2 or newer
+ *
+ * @package            CodeIgniter
+ * @author             ExpressionEngine Dev Team
+ * @copyright  Copyright (c) 2008, EllisLab, Inc.
+ * @license            http://codeigniter.com/user_guide/license.html
+ * @link               http://codeigniter.com
+ * @since              Version 1.0
+ * @filesource
+ */
+
+// ------------------------------------------------------------------------
+
+/**
+ * Trackback Class
+ *
+ * Trackback Sending/Receiving Class
+ *
+ * @package            CodeIgniter
+ * @subpackage Libraries
+ * @category   Trackbacks
+ * @author             ExpressionEngine Dev Team
+ * @link               http://codeigniter.com/user_guide/libraries/trackback.html
+ */
+class CI_Trackback {
+               
+       var $time_format        = 'local';
+       var $charset            = 'UTF-8';
+       var $data                       = array('url' => '', 'title' => '', 'excerpt' => '', 'blog_name' => '', 'charset' => '');
+       var $convert_ascii      = TRUE;
+       var $response           = '';
+       var $error_msg          = array();
+
+       /**
+        * Constructor
+        *
+        * @access      public
+        */
+       function CI_Trackback()
+       {
+               log_message('debug', "Trackback Class Initialized");
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Send Trackback
+        *
+        * @access      public
+        * @param       array
+        * @return      bool
+        */     
+       function send($tb_data)
+       {               
+               if ( ! is_array($tb_data))
+               {
+                       $this->set_error('The send() method must be passed an array');
+                       return FALSE;
+               }
+               
+               // Pre-process the Trackback Data
+               foreach (array('url', 'title', 'excerpt', 'blog_name', 'ping_url') as $item)
+               {
+                       if ( ! isset($tb_data[$item]))
+                       {
+                               $this->set_error('Required item missing: '.$item);
+                               return FALSE;
+                       }
+                       
+                       switch ($item)
+                       {
+                               case 'ping_url' : $$item = $this->extract_urls($tb_data[$item]);
+                                       break;
+                               case 'excerpt'  : $$item = $this->limit_characters($this->convert_xml(strip_tags(stripslashes($tb_data[$item]))));
+                                       break;
+                               case 'url'              : $$item = str_replace('&#45;', '-', $this->convert_xml(strip_tags(stripslashes($tb_data[$item]))));
+                                       break;
+                               default                 : $$item = $this->convert_xml(strip_tags(stripslashes($tb_data[$item])));
+                                       break;
+                       }
+
+                       // Convert High ASCII Characters
+                       if ($this->convert_ascii == TRUE)
+                       {
+                               if ($item == 'excerpt')
+                               {
+                                       $$item = $this->convert_ascii($$item);
+                               }
+                               elseif ($item == 'title')
+                               {
+                                       $$item = $this->convert_ascii($$item);
+                               }
+                               elseif($item == 'blog_name')
+                               {
+                                       $$item = $this->convert_ascii($$item);
+                               }
+                       }
+               }
+
+               // Build the Trackback data string
+               $charset = ( ! isset($tb_data['charset'])) ? $this->charset : $tb_data['charset'];
+               
+               $data = "url=".rawurlencode($url)."&title=".rawurlencode($title)."&blog_name=".rawurlencode($blog_name)."&excerpt=".rawurlencode($excerpt)."&charset=".rawurlencode($charset);
+                               
+               // Send Trackback(s)
+               $return = TRUE;
+               if (count($ping_url) > 0)
+               {
+                       foreach ($ping_url as $url)
+                       {
+                               if ($this->process($url, $data) == FALSE)
+                               {
+                                       $return = FALSE;
+                               }
+                       }       
+               }
+
+               return $return;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Receive Trackback  Data
+        *
+        * This function simply validates the incoming TB data.
+        * It returns false on failure and true on success.
+        * If the data is valid it is set to the $this->data array
+        * so that it can be inserted into a database.
+        *
+        * @access      public
+        * @return      bool
+        */     
+       function receive()
+       {                                       
+               foreach (array('url', 'title', 'blog_name', 'excerpt') as $val)
+               {
+                       if ( ! isset($_POST[$val]) OR $_POST[$val] == '')
+                       {
+                               $this->set_error('The following required POST variable is missing: '.$val);
+                               return FALSE;
+                       }
+                       
+                       $this->data['charset'] = ( ! isset($_POST['charset'])) ? 'auto' : strtoupper(trim($_POST['charset']));
+       
+                       if ($val != 'url' && function_exists('mb_convert_encoding'))
+                       {
+                               $_POST[$val] = mb_convert_encoding($_POST[$val], $this->charset, $this->data['charset']);
+                       }
+                       
+                       $_POST[$val] = ($val != 'url') ? $this->convert_xml(strip_tags($_POST[$val])) : strip_tags($_POST[$val]);
+                       
+                       if ($val == 'excerpt')
+                       {
+                               $_POST['excerpt'] = $this->limit_characters($_POST['excerpt']);
+                       }
+                       
+                       $this->data[$val] = $_POST[$val];
+               }
+
+               return TRUE;
+       }       
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Send Trackback Error Message
+        *
+        * Allows custom errors to be set.  By default it
+        * sends the "incomplete information" error, as that's
+        * the most common one.
+        *
+        * @access      public
+        * @param       string
+        * @return      void
+        */     
+       function send_error($message = 'Incomplete Information')
+       {
+               echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>1</error>\n<message>".$message."</message>\n</response>";
+               exit;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Send Trackback Success Message
+        *
+        * This should be called when a trackback has been
+        * successfully received and inserted.
+        *
+        * @access      public
+        * @return      void
+        */             
+       function send_success()
+       {
+               echo "<?xml version=\"1.0\" encoding=\"utf-8\"?".">\n<response>\n<error>0</error>\n</response>";
+               exit;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Fetch a particular item
+        *
+        * @access      public
+        * @param       string
+        * @return      string
+        */     
+       function data($item)
+       {
+               return ( ! isset($this->data[$item])) ? '' : $this->data[$item];
+       }
+
+       // --------------------------------------------------------------------
+       
+       /**
+        * Process Trackback
+        *
+        * Opens a socket connection and passes the data to
+        * the server.  Returns true on success, false on failure
+        *
+        * @access      public
+        * @param       string
+        * @param       string
+        * @return      bool
+        */     
+       function process($url, $data)
+       {
+               $target = parse_url($url);
+       
+               // Open the socket
+               if ( ! $fp = @fsockopen($target['host'], 80))
+               {
+                       $this->set_error('Invalid Connection: '.$url);
+                       return FALSE;
+               }
+
+               // Build the path
+               $ppath = ( ! isset($target['path'])) ? $url : $target['path'];
+               
+               $path = (isset($target['query']) && $target['query'] != "") ? $ppath.'?'.$target['query'] : $ppath;
+
+               // Add the Trackback ID to the data string
+               if ($id = $this->get_id($url))
+               {
+                       $data = "tb_id=".$id."&".$data;
+               }
+
+               // Transfer the data
+               fputs ($fp, "POST " . $path . " HTTP/1.0\r\n" );
+               fputs ($fp, "Host: " . $target['host'] . "\r\n" );
+               fputs ($fp, "Content-type: application/x-www-form-urlencoded\r\n" );
+               fputs ($fp, "Content-length: " . strlen($data) . "\r\n" );
+               fputs ($fp, "Connection: close\r\n\r\n" );
+               fputs ($fp, $data);
+
+               // Was it successful?
+               $this->response = "";
+               
+               while( ! feof($fp))
+               {
+                       $this->response .= fgets($fp, 128);
+               }
+               @fclose($fp);
+               
+               if ( ! eregi("<error>0</error>", $this->response))
+               {
+                       $message = 'An unknown error was encountered';
+                       
+                       if (preg_match("/<message>(.*?)<\/message>/is", $this->response, $match))
+                       {
+                               $message = trim($match['1']);
+                       }
+                       
+                       $this->set_error($message);
+                       return FALSE;
+               }
+
+               return TRUE;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Extract Trackback URLs
+        *
+        * This function lets multiple trackbacks be sent.
+        * It takes a string of URLs (separated by comma or
+        * space) and puts each URL into an array
+        *
+        * @access      public
+        * @param       string
+        * @return      string
+        */     
+       function extract_urls($urls)
+       {               
+               // Remove the pesky white space and replace with a comma.
+               $urls = preg_replace("/\s*(\S+)\s*/", "\\1,", $urls);
+               
+               // If they use commas get rid of the doubles.
+               $urls = str_replace(",,", ",", $urls);
+               
+               // Remove any comma that might be at the end
+               if (substr($urls, -1) == ",")
+               {
+                       $urls = substr($urls, 0, -1);
+               }
+                               
+               // Break into an array via commas
+               $urls = preg_split('/[,]/', $urls);
+               
+               // Removes duplicates
+               $urls = array_unique($urls);
+               
+               array_walk($urls, array($this, 'validate_url'));
+               
+               return $urls;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Validate URL
+        *
+        * Simply adds "http://" if missing
+        *
+        * @access      public
+        * @param       string
+        * @return      string
+        */     
+       function validate_url($url)
+       {
+               $url = trim($url);
+
+               if (substr($url, 0, 4) != "http")
+               {
+                       $url = "http://".$url;
+               }
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Find the Trackback URL's ID
+        *
+        * @access      public
+        * @param       string
+        * @return      string
+        */     
+       function get_id($url)
+       {       
+               $tb_id = "";
+               
+               if (strstr($url, '?'))
+               {
+                       $tb_array = explode('/', $url);
+                       $tb_end   = $tb_array[count($tb_array)-1];
+                       
+                       if ( ! is_numeric($tb_end))
+                       {
+                               $tb_end  = $tb_array[count($tb_array)-2];
+                       }
+                       
+                       $tb_array = explode('=', $tb_end);
+                       $tb_id  = $tb_array[count($tb_array)-1];
+               }
+               else
+               {
+                       if (ereg("/$", $url))
+                       {
+                               $url = substr($url, 0, -1);
+                       }
+                               
+                       $tb_array = explode('/', $url);
+                       $tb_id  = $tb_array[count($tb_array)-1];
+                       
+                       if ( ! is_numeric($tb_id))
+                       {
+                               $tb_id  = $tb_array[count($tb_array)-2];
+                       }
+               }       
+                               
+               if ( ! preg_match ("/^([0-9]+)$/", $tb_id))
+               {
+                       return false;
+               }
+               else
+               {
+                       return $tb_id;
+               }               
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Convert Reserved XML characters to Entities
+        *
+        * @access      public
+        * @param       string
+        * @return      string
+        */
+       function convert_xml($str)
+       {
+               $temp = '__TEMP_AMPERSANDS__';
+               
+               $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
+               $str = preg_replace("/&(\w+);/",  "$temp\\1;", $str);
+               
+               $str = str_replace(array("&","<",">","\"", "'", "-"),
+                                                  array("&amp;", "&lt;", "&gt;", "&quot;", "&#39;", "&#45;"),
+                                                  $str);
+                       
+               $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
+               $str = preg_replace("/$temp(\w+);/","&\\1;", $str);
+                       
+               return $str;
+       }       
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Character limiter
+        *
+        * Limits the string based on the character count. Will preserve complete words.
+        *
+        * @access      public
+        * @param       string
+        * @param       integer
+        * @param       string
+        * @return      string
+        */
+       function limit_characters($str, $n = 500, $end_char = '&#8230;')
+       {
+               if (strlen($str) < $n)
+               {
+                       return $str;
+               }
+
+               $str = preg_replace("/\s+/", ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str));
+       
+               if (strlen($str) <= $n)
+               {
+                       return $str;
+               }
+                                                                               
+               $out = "";
+               foreach (explode(' ', trim($str)) as $val)
+               {
+                       $out .= $val.' ';                       
+                       if (strlen($out) >= $n)
+                       {
+                               return trim($out).$end_char;
+                       }               
+               }
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * High ASCII to Entities
+        *
+        * Converts Hight ascii text and MS Word special chars
+        * to character entities
+        *
+        * @access      public
+        * @param       string
+        * @return      string
+        */
+       function convert_ascii($str)
+       {
+          $count       = 1;
+          $out = '';
+          $temp        = array();
+               
+          for ($i = 0, $s = strlen($str); $i < $s; $i++)
+          {
+                  $ordinal = ord($str[$i]);
+               
+                  if ($ordinal < 128)
+                  {
+                          $out .= $str[$i];                    
+                  }
+                  else
+                  {
+                          if (count($temp) == 0)
+                          {
+                                  $count = ($ordinal < 224) ? 2 : 3;
+                          }
+                       
+                          $temp[] = $ordinal;
+                       
+                          if (count($temp) == $count)
+                          {
+                                  $number = ($count == 3) ? (($temp['0'] % 16) * 4096) + (($temp['1'] % 64) * 64) + ($temp['2'] % 64) : (($temp['0'] % 32) * 64) + ($temp['1'] % 64);
+       
+                                  $out .= '&#'.$number.';';
+                                  $count = 1;
+                                  $temp = array();
+                          }
+                  }
+          }
+       
+          return $out;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Set error message
+        *
+        * @access      public
+        * @param       string
+        * @return      void
+        */     
+       function set_error($msg)
+       {
+               log_message('error', $msg);
+               $this->error_msg[] = $msg;
+       }
+       
+       // --------------------------------------------------------------------
+       
+       /**
+        * Show error messages
+        *
+        * @access      public
+        * @param       string
+        * @param       string
+        * @return      string
+        */     
+       function display_errors($open = '<p>', $close = '</p>')
+       {       
+               $str = '';
+               foreach ($this->error_msg as $val)
+               {
+                       $str .= $open.$val.$close;
+               }
+       
+               return $str;
+       }
+
+}
+// END Trackback Class
+
+/* End of file Trackback.php */
 /* Location: ./system/libraries/Trackback.php */
\ No newline at end of file