예제 #1
0
 /**
  * send
  * This method sends a trackback to the trackback_url saved in it. The 
  * data array of the trackback object can be completed by submitting the
  * necessary data through the $data parameter of this method.
  * The following data has to be set to call this method:
  *              'title'             Title of the weblog entry sending the trackback.
  *              'url'               URL of the weblog entry sending the trackback.
  *              'excerpt'           Excerpt of the weblog entry sending the trackback.
  *              'blog_name'         Name of the weblog sending the trackback.
  *              'trackback_url'     URL to send the trackback to.
  * Services_Trackback::send() requires PEAR::HTTP_Request. The options for the HTTP_Request
  * object are stored in the global options array using the key 'http_request'.
  *
  * @since 0.3.0
  * @access public
  * @param string $data Additional data to complete the trackback.
  * @return mixed True on success, otherwise PEAR_Error.
  */
 function send($data = null)
 {
     // Load HTTP_Request
     @(require_once 'HTTP/Request.php');
     if (!class_exists('HTTP_Request')) {
         return PEAR::raiseError('Unable to load PEAR::HTTP_Request.');
     }
     // Consistancy check
     if (!isset($data)) {
         $data = array();
     }
     $this->_data = array_merge($this->_data, $data);
     $necessaryData = array('title', 'url', 'excerpt', 'blog_name', 'trackback_url');
     $res = $this->_checkData($necessaryData);
     if (PEAR::isError($res)) {
         return $res;
     }
     // Get URL
     $url = str_replace('&', '&', $this->_data['trackback_url']);
     // Changed in 0.5.0 All HTTP_Request options are now supported.
     $options = $this->_options['httpRequest'];
     $options['timeout'] = $this->_options['timeout'];
     // Create new HTTP_Request
     $req = new HTTP_Request($url, $options);
     $req->setMethod(HTTP_REQUEST_METHOD_POST);
     // Add HTTP headers
     $req->addHeader("User-Agent", $options['useragent']);
     // Adding data to send
     $req->addPostData('url', $this->_data['url']);
     $req->addPostData('title', $this->_data['title']);
     $req->addPostData('blog_name', $this->_data['blog_name']);
     $req->addPostData('excerpt', strip_tags($this->_data['excerpt']));
     // Send POST request
     $res = $req->sendRequest();
     if (PEAR::isError($res)) {
         return $res;
     }
     // Check return code
     if ($req->getResponseCode() != 200) {
         return PEAR::raiseError('Host returned Error ' . $req->getRequestCode() . '.');
     }
     return $this->_interpretTrackbackResponse($req->getResponseBody());
 }