欢迎来到 HiMCBBS 论坛~

想在这里休息会么?和我们共度美好时光吧~

加入QQ群:879016948 获得最新公告,并与群友们一起聊天吹水!

注册 登录
22331144

软件资源 Emlog模板添加每日60秒读世界独立页面

22331144

成员
注册
2024-03-10
消息
75
金粒
金粒1,643粒
钻石
钻石0颗
嗨币
嗨币0元
  • 主题 作者
  • #1
[FONT=Tahoma, "]最近看各个站点都有的每日六十秒读世界的文章或者页面,大多数实现方式大致两种:一种是emlog中相关的插件或者采集,此方法虽然配置简单、方便,但是这个采集文章内容具有很强的时效性,需要每日定时访问触发采集才能发布文章;

[FONT=Tahoma, "]一种是直接引用别人的六十秒读世界的api,此方法最大的优点是不用设置采集和发布大量文章,但是形式是仅仅的一张图片,这就过于简单的了,那有还有比前两种更好点又不太简单的实现方式?答案有是有的,其实就是将接口写在主题中。[/FONT]
[FONT=Tahoma, "]实现方式[/FONT]
[FONT=Tahoma, "]1.在模板主题的module.php文件添加以下函数[/FONT]
PHP:
<?php
//独立页面-每日60秒
function luyu_sixtys(){
$date = file_get_contents("https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items");
$date = json_decode($date);
$content = $date->data[0]->content;
$content = preg_replace(\'/(<a.*?>[\\s\\S]*?<\\/a>)/\',\'\',$content);
$pattern =\'<img.*?src="(.*?)">\';
preg_match($pattern,$content,$matches);
$src_path = $matches[1];
$src = imagecreatefromstring(file_get_contents($src_path));
$info = getimagesize($src_path);
$x = 0;
$y = 0;
$width = 720;
$height = 350;
$final_width = 720;
$final_height = round($final_width * $height / $width);
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
$ext = pathinfo($src_path, PATHINFO_EXTENSION);
$rand_name = date("Ymd") . "." . $ext;
$url= BLOG_URL;
if (!file_exists("content/uploadfile/60s")){
    mkdir ("content/uploadfile/60s",0777,true);
}
imagejpeg($new_image,"content/uploadfile/60s/".$rand_name);
imagedestroy($src);
imagedestroy($new_image);
$content = strip_tags($content,\'<p>\');
$content = \'<img class="" src="\'.$url.\'/content/uploadfile/60s/\'.$rand_name.\'" />\'.$content;
  return $content;
};
?>
2.在自己使用的模板创建独立页面,以60s.php为例,根据各自的主题在文章内容部分添加调用显示。
PHP:
<?php echo luyu_sixtys()?>
[/FONT]
 
后退
顶部