Exemple #1
0
 /**
  * 获取扩展字段
  * 
  * @access private
  * @param Widget_Abstract_Contents $content
  * @return array
  */
 private function getPostExtended(Widget_Abstract_Contents $content)
 {
     //根据客户端显示来判断是否显示html代码
     $agent = $this->request->getAgent();
     $text = '';
     switch (true) {
         case false !== strpos($agent, 'wp-iphone'):
             // wordpress iphone客户端
         // wordpress iphone客户端
         case false !== strpos($agent, 'wp-blackberry'):
             // 黑莓
         // 黑莓
         case false !== strpos($agent, 'wp-andriod'):
             // andriod
         // andriod
         case false !== strpos($agent, 'plain-text'):
             // 这是预留给第三方开发者的接口, 用于强行调用非所见即所得数据
             $text = $content->text;
             break;
         default:
             $text = $content->content;
             break;
     }
     $post = explode('<!--more-->', $text, 2);
     return array(Typecho_Common::fixHtml($post[0]), isset($post[1]) ? Typecho_Common::fixHtml($post[1]) : NULL);
 }
Exemple #2
0
 /**
  * 获取文章内容摘要
  *
  * @access protected
  * @return string
  */
 protected function ___excerpt()
 {
     $contents = explode('<!--more-->', $this->text);
     list($excerpt) = $contents;
     $excerpt = $this->pluginHandle(__CLASS__)->trigger($plugged)->excerpt($excerpt, $this);
     if (!$plugged) {
         $excerpt = Typecho_Common::cutParagraph($excerpt);
     }
     return Typecho_Common::fixHtml($this->pluginHandle(__CLASS__)->excerptEx($excerpt, $this));
 }
Exemple #3
0
 /**
  * 获取文章内容摘要
  *
  * @access protected
  * @return string
  */
 protected function ___excerpt()
 {
     if ($this->hidden) {
         return $this->text;
     }
     $content = $this->pluginHandle(__CLASS__)->trigger($plugged)->excerpt($this->text, $this);
     if (!$plugged) {
         $content = $this->isMarkdown ? MarkdownExtraExtended::defaultTransform($content) : Typecho_Common::cutParagraph($content);
     }
     $contents = explode('<!--more-->', $content);
     list($excerpt) = $contents;
     return Typecho_Common::fixHtml($this->pluginHandle(__CLASS__)->excerptEx($excerpt, $this));
 }
Exemple #4
0
 /**
  * 获取文章内容摘要
  *
  * @access protected
  * @return string
  */
 protected function ___excerpt()
 {
     if ($this->hidden) {
         return $this->text;
     }
     $content = $this->pluginHandle(__CLASS__)->trigger($plugged)->excerpt($this->text, $this);
     if (!$plugged) {
         $content = $this->isMarkdown ? $this->markdown($content) : $this->autoP($content);
     }
     $contents = explode('<!--more-->', $content);
     list($excerpt) = $contents;
     return Typecho_Common::fixHtml($this->pluginHandle(__CLASS__)->excerptEx($excerpt, $this));
 }
Exemple #5
0
 /**
  * 同步文章到新浪微博
  *
  * @access public
  * @param $content $class
  * @return status
  */
 public static function TsinaSync($content, $class)
 {
     //获取插件的配置
     $config = self::getWeiboSyncCfg();
     //如果不是文章编辑(对象$class属于Widget_Abstract_Contents,是否等于对象的值Widget_Contents_Post_Edit,它继承Widget_Abstract_Contents对象),则直接返回内容
     if (!is_a($class, 'Widget_Contents_Post_Edit')) {
         return $content;
     }
     if ($config->sina_mode == '1') {
         if (!$class->request->is("do=publish") || $class->request->is("do=publish") && !$class->have()) {
             return $content;
         }
     } else {
         if (!$class->request->is("do=publish") || $class->request->is("do=publish") && !empty($class->request->cid)) {
             return $content;
         }
     }
     $format = $config->sina_format ? $config->sina_format : '我在TypeCodes上发表了一篇文章《{title}》,链接地址{link}';
     $title = $content['title'];
     $link = self::SinaShortUrl($content['permalink']);
     //如果插件配置中出现了{more}标签,即需要提取文章的摘要信息
     if (strpos($format, '{more}') !== false) {
         if (strpos($content['text'], '<!--more-->') !== false) {
             $more_t = explode('<!--more-->', $content['text']);
             list($more) = $more_t;
             $more = Typecho_Common::fixHtml(Typecho_Common::cutParagraph($more));
             $more = Typecho_Common::subStr(strip_tags($more), 0, 60, '...');
         } else {
             $more = $content['text'];
             $more = Typecho_Common::fixHtml(Typecho_Common::cutParagraph($more));
             $more = Typecho_Common::subStr(strip_tags($more), 0, 60, '...');
         }
     } else {
         $more = "";
     }
     $search = array('{title}', '{link}', '{more}');
     $replace = array($title, $link, $more);
     $format = str_replace($search, $replace, $format);
     $post_img = '';
     if ($config->sina_imgflag) {
         $content_substr = mb_substr($content['text'], 0, 900, 'utf-8');
         if (preg_match('/!\\[[^\\]]*]\\((https):\\/\\/[^\\)]*\\.(png|jpg)(.*)\\)/i', $content_substr, $img_match)) {
             if (preg_match('/(https:\\/\\/)[^>]*?\\.(png|jpg)/i', $img_match[0], $img_match_retult)) {
                 $post_img = $img_match_retult[0];
             }
         }
     }
     self::PostWeibo($format, $post_img);
     return $content;
 }