Exemple #1
0
 /**
  * 重定向函数
  *
  * @access public
  * @param string $location 重定向路径
  * @param boolean $isPermanently 是否为永久重定向
  * @return void
  */
 public function redirect($location, $isPermanently = false)
 {
     /** Typecho_Common */
     require_once 'Typecho/Common.php';
     $location = Typecho_Common::safeUrl($location);
     if ($isPermanently) {
         header('Location: ' . $location, false, 301);
         exit;
     } else {
         header('Location: ' . $location, false, 302);
         exit;
     }
 }
Exemple #2
0
 /**
  * pingbackPing
  *
  * @param string $source
  * @param string $target
  * @access public
  * @return void
  */
 public function pingbackPing($source, $target)
 {
     /** 检查源地址是否存在*/
     if (!($http = Typecho_Http_Client::get())) {
         return new IXR_Error(16, _t('源地址服务器错误'));
     }
     try {
         $http->setTimeout(5)->send($source);
         $response = $http->getResponseBody();
         if (200 == $http->getResponseStatus()) {
             if (!$http->getResponseHeader('x-pingback')) {
                 preg_match_all("/<link[^>]*rel=[\"']([^\"']*)[\"'][^>]*href=[\"']([^\"']*)[\"'][^>]*>/i", $response, $out);
                 if (!isset($out[1]['pingback'])) {
                     return new IXR_Error(50, _t('源地址不支持PingBack'));
                 }
             }
         } else {
             return new IXR_Error(16, _t('源地址服务器错误'));
         }
     } catch (Exception $e) {
         return new IXR_Error(16, _t('源地址服务器错误'));
     }
     /** 检查目标地址是否正确*/
     $pathInfo = Typecho_Common::url(substr($target, strlen($this->options->index)), '/');
     $post = Typecho_Router::match($pathInfo);
     /** 这样可以得到cid或者slug*/
     if (!$post instanceof Widget_Archive || !$post->have() || !$post->is('single')) {
         return new IXR_Error(33, _t('这个目标地址不存在'));
     }
     if ($post) {
         /** 检查是否可以ping*/
         if ($post->allowPing) {
             /** 现在可以ping了,但是还得检查下这个pingback是否已经存在了*/
             $pingNum = $this->db->fetchObject($this->db->select(array('COUNT(coid)' => 'num'))->from('table.comments')->where('table.comments.cid = ? AND table.comments.url = ? AND table.comments.type <> ?', $post->cid, $source, 'comment'))->num;
             if ($pingNum <= 0) {
                 /** 现在开始插入以及邮件提示了 $response就是第一行请求时返回的数组*/
                 preg_match("/\\<title\\>([^<]*?)\\<\\/title\\>/is", $response, $matchTitle);
                 $finalTitle = Typecho_Common::removeXSS(trim(strip_tags($matchTitle[1])));
                 /** 干掉html tag,只留下<a>*/
                 $text = Typecho_Common::stripTags($response, '<a href="">');
                 /** 此处将$target quote,留着后面用*/
                 $pregLink = preg_quote($target);
                 /** 找出含有target链接的最长的一行作为$finalText*/
                 $finalText = '';
                 $lines = explode("\n", $text);
                 foreach ($lines as $line) {
                     $line = trim($line);
                     if (NULL != $line) {
                         if (preg_match("|<a[^>]*href=[\"']{$pregLink}[\"'][^>]*>(.*?)</a>|", $line)) {
                             if (strlen($line) > strlen($finalText)) {
                                 /** <a>也要干掉,*/
                                 $finalText = Typecho_Common::stripTags($line);
                             }
                         }
                     }
                 }
                 /** 截取一段字*/
                 if (NULL == trim($finalText)) {
                     return new IXR_Error('17', _t('源地址中不包括目标地址'));
                 }
                 $finalText = '[...]' . Typecho_Common::subStr($finalText, 0, 200, '') . '[...]';
                 $pingback = array('cid' => $post->cid, 'created' => $this->options->gmtTime, 'agent' => $this->request->getAgent(), 'ip' => $this->request->getIp(), 'author' => $finalTitle, 'url' => Typecho_Common::safeUrl($source), 'text' => $finalText, 'ownerId' => $post->author->uid, 'type' => 'pingback', 'status' => $this->options->commentsRequireModeration ? 'waiting' : 'approved');
                 /** 加入plugin */
                 $pingback = $this->pluginHandle()->pingback($pingback, $post);
                 /** 执行插入*/
                 $insertId = $this->singletonWidget('Widget_Abstract_Comments')->insert($pingback);
                 /** 评论完成接口 */
                 $this->pluginHandle()->finishPingback($this);
                 return $insertId;
                 /** todo:发送邮件提示*/
             } else {
                 return new IXR_Error(48, _t('PingBack已经存在'));
             }
         } else {
             return IXR_Error(49, _t('目标地址禁止Ping'));
         }
     } else {
         return new IXR_Error(33, _t('这个目标地址不存在'));
     }
 }
Exemple #3
0
 /**
  * 重定向函数
  *
  * @access public
  * @param string $location 重定向路径
  * @param boolean $isPermanently 是否为永久重定向
  * @return void
  */
 public function redirect($location, $isPermanently = false)
 {
     /** Typecho_Common */
     require_once 'Typecho/Common.php';
     $location = Typecho_Common::safeUrl($location);
     if ($isPermanently) {
         header('Location: ' . $location, false, 301);
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <html><head>
 <title>301 Moved Permanently</title>
 </head><body>
 <h1>Moved Permanently</h1>
 <p>The document has moved <a href="' . $location . '">here</a>.</p>
 </body></html>';
         exit;
     } else {
         header('Location: ' . $location, false, 302);
         echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <html><head>
 <title>302 Moved Temporarily</title>
 </head><body>
 <h1>Moved Temporarily</h1>
 <p>The document has moved <a href="' . $location . '">here</a>.</p>
 </body></html>';
         exit;
     }
 }