Example #1
0
 /**
  * 远程请求代理
  *
  * @access public
  * @return void
  */
 public function feed()
 {
     $this->user->pass('subscriber');
     $client = Typecho_Http_Client::get();
     if ($client) {
         $client->setHeader('User-Agent', $this->options->generator)->send('http://typecho.org/feed/');
         /** 匹配内容体 */
         $response = $client->getResponseBody();
         preg_match_all("/<item>\\s*<title>([^>]*)<\\/title>\\s*<link>([^>]*)<\\/link>\\s*<guid>[^>]*<\\/guid>\\s*<pubDate>([^>]*)<\\/pubDate>/is", $response, $matches);
         $data = array();
         if ($matches) {
             foreach ($matches[0] as $key => $val) {
                 $data[] = array('title' => $matches[1][$key], 'link' => $matches[2][$key], 'date' => Typecho_I18n::dateWord(strtotime($matches[3][$key]), $this->options->gmtTime + $this->options->timezone));
                 if ($key > 3) {
                     break;
                 }
             }
         }
         if (!empty($data)) {
             Typecho_Cookie::set('__typecho_feed', Typecho_Json::encode($data));
         }
         $this->response->throwJson($data);
         return;
     }
     throw new Typecho_Widget_Exception(_t('禁止访问'), 403);
 }
Example #2
0
 /**
  * 抛出json回执信息
  *
  * @access public
  * @param string $message 消息体
  * @return void
  */
 public function throwJson($message)
 {
     /** 设置http头信息 */
     $this->setContentType('application/json');
     /** Typecho_Json */
     require_once 'Typecho/Json.php';
     echo Typecho_Json::encode($message);
     /** 终止后续输出 */
     exit;
 }