文章第一张图片 > 系统图库
* @param $obj
* @return 获取文章头图
*/
function get_postthumb($obj) {
if(isset($obj->fields->thumb)){
return $obj->fields->thumb;
}
preg_match( "/
]+src\s*=\s*['\"]([^'\"]+)['\"][^>]*>/ ", $obj->content, $matches );
if(isset($matches[1])){
return $matches[1];
}
preg_match( "/!\[(.*?)\]\((.*?)\)/ ", $obj->content, $matches );
if(isset($matches[2])) {
return$matches[2];
}
$thumbPath = __DIR__ .'/static/medias/featureimages/';
$files = scandir($thumbPath);
$thumbs = [];
for ($i = 0; $i < count($files); $i++) {
if(is_file($thumbPath . $files[$i])){
$thumbs[] = $files[$i];
}
}
return Helper::options()->themeUrl .'/static/medias/featureimages/'. $thumbs[rand(0, count($thumbs) - 1)];
}
/**
* @param $obj 对象
* @return string 上一页url
*/
function getPrevPageLink($obj){
ob_start();
$obj->pagelink("prev", "prev");
$pageLink = ob_get_contents();
ob_end_clean();
preg_match("/]+href\s*=\s*['\"]([^'\"]+)['\"][^>]*>/", $pageLink, $matches);
if(isset($matches[1])){
return $matches[1];
}
return "#";
}
/**
* @param $obj 对象
* @return string 下一页url
*/
function getNextPageLink($obj){
ob_start();
$obj->pageLink("next", "next");
$pageLink = ob_get_contents();
ob_end_clean();
preg_match("/]+href\s*=\s*['\"]([^'\"]+)['\"][^>]*>/", $pageLink, $matches);
if(isset($matches[1])){
return $matches[1];
}
return "#";
}