Skip to content

Commit

Permalink
Squashed 'AMP/' changes from 02792f1..c7057a2
Browse files Browse the repository at this point in the history
c7057a2 optimizational function. For issues https://holmesian.org/AMP-for-Typecho#comment-7425.

git-subtree-dir: AMP
git-subtree-split: c7057a2c2f637b4722c74b167c3b1e1dcd75f95c
  • Loading branch information
holmesian committed May 1, 2018
1 parent 36f0a58 commit 5ead07a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 17 additions & 3 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function getArticle($target)
$tempTarget = explode('.', $target)[0];
$article = $this->getArticleBySlug($tempTarget);
if (isset($article['isblank'])) {
$article = $article = $this->getArticleByCid($tempTarget);
$article = $this->getArticleByCid($tempTarget);
}
return $article;
}
Expand Down Expand Up @@ -366,8 +366,9 @@ public function MakeArticleList($linkType = 'amp', $page = 0, $pageSize = 0)

private function GetPostImg()
{

$text = $this->article['text'];

$pattern = '/\<img.*?src\=\"(.*?)\"[^>]*>/i';
$patternMD = '/\!\[.*?\]\((http(s)?:\/\/.*?(jpg|png))/i';
$patternMDfoot = '/\[.*?\]:\s*(http(s)?:\/\/.*?(jpg|png))/i';
Expand All @@ -379,8 +380,21 @@ private function GetPostImg()
preg_match("/(?:\()(.*)(?:\))/i", $img[0], $result);
$img_url = $img[1];
} else {
$img_url = $this->defaultPIC;
//正文里没找到图片就去附件里找
$attsrc=Typecho_Widget::widget('Widget_Contents_Attachment_Related', 'parentId=' . $this->article['cid'])->stack;
$att='';
foreach ($attsrc as $attimg){
$att=$att.$attimg['text'];
}
if (preg_match($pattern, $att, $img)) {//附件里只需要匹配img标签的内容
preg_match("/(?:\()(.*)(?:\))/i", $img[0], $result);
$img_url = $img[1];
}else{//附件里再找不到就调LOGO了
$img_url = $this->defaultPIC;
}
}


try {
list($width, $height, $type, $attr) = @getimagesize($img_url);
$imgData=array(
Expand Down
4 changes: 2 additions & 2 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
*
* @package AMP-MIP
* @author Holmesian
* @version 0.6.0
* @version 0.6.1
* @link https://holmesian.org
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

class AMP_Plugin implements Typecho_Plugin_Interface
{
private static $version = '0.6.0';
private static $version = '0.6.1';

public static function activate()
{
Expand Down

0 comments on commit 5ead07a

Please sign in to comment.