前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >朋友圈 Circle 出炉了

朋友圈 Circle 出炉了

作者头像
Dabenshi
发布2024-04-03 09:15:55
630
发布2024-04-03 09:15:55
举报
文章被收录于专栏:DabenshiDabenshi

写之前特意拜访了各大博主的“朋友圈”,基本都是以RSS为基础(聚合订阅)。那么简单了(前提需要有RSS源,基本都有)废话不多说直接开始吧!不想组织文字了?

第一步:RSS调用定义变量标签(安全起见,只能贴出部分代码)

代码语言:javascript
复制
if( $buffer === false ) {

include_once (RSSPlugins::Check(ENGINE_DIR . '/rss.class.php'));

$xml = new RSSxmlParser( stripslashes( $value['url'] ), $value['news_max'] );

$xml->pre_parse( 0 );

$tpl->load_template( $value['template'] . '.tpl' );

foreach ( $xml->content as $content ) {

if ( isset($content['title']) ) {
$content['title'] = trim(strip_tags( $content['title'] ));
} else $content['title'] = "";

if ( isset($content['category']) ) {
$content['category'] = trim( strip_tags( $content['category'] ) );
} else $content['category'] = "";

if ( isset($content['author']) ) {
$content['author'] = trim( strip_tags( $content['author'] ) );
} else $content['author'] = "";

if( $value['tmax'] and dle_strlen( $content['title'], $config['charset'] ) > $value['tmax'] ) $content['title'] = dle_substr( $content['title'], 0, $value['tmax'], $config['charset'] ) . " ...";

if (stripos ( $tpl->copy_template, "{image-" ) !== false) {

$images = array();
preg_match_all('/(img|src)=("|\')[^"\'>]+/i', $content['description'], $media);
$data=preg_replace('/(img|src)("|\'|="|=\')(.*)/i',"$3",$media[0]);

foreach($data as $url) {
$info = pathinfo($url);
if (isset($info['extension'])) {
if ($info['filename'] == "spoiler-plus" OR $info['filename'] == "spoiler-minus" OR strpos($info['dirname'], 'engine/data/emoticons') !== false) continue;
$info['extension'] = strtolower($info['extension']);
if (($info['extension'] == 'jpg') || ($info['extension'] == 'jpeg') || ($info['extension'] == 'gif') || ($info['extension'] == 'png') || ($info['extension'] == 'webp') || ($info['extension'] == 'bmp') || ($info['extension'] == 'avif')) array_push($images, $url);
}
}

if ( count($images) ) {

$i=0;

foreach($images as $url) {
$i++;
$tpl->copy_template = str_replace( '{image-'.$i.'}', $url, $tpl->copy_template );
$tpl->copy_template = str_replace( '[image-'.$i.']', "", $tpl->copy_template );
$tpl->copy_template = str_replace( '[/image-'.$i.']', "", $tpl->copy_template );
}

} elseif( $content['image'] ) {
$tpl->copy_template = str_replace( '{image-1}', $content['image'], $tpl->copy_template );
$tpl->copy_template = str_replace( '[image-1]', "", $tpl->copy_template );
$tpl->copy_template = str_replace( '[/image-1]', "", $tpl->copy_template );
}

$tpl->copy_template = preg_replace( "#\[image-(.+?)\](.+?)\[/image-(.+?)\]#is", "", $tpl->copy_template );
$tpl->copy_template = preg_replace( "#\\{image-(.+?)\\}#i", "{THEME}/dleimages/no_image.jpg", $tpl->copy_template );

}

$content['description'] = str_replace( "<br>", " ", str_replace( "<br />", " ", $content['description'] ) );
$content['description'] = strip_tags( $content['description'] );
$content['description'] = trim( $content['description'] );

if( $value['dmax'] and dle_strlen( $content['description'], $config['charset'] ) > $value['dmax'] ) {

$content['description'] = dle_substr( $content['description'], 0, $value['dmax'], $config['charset'] );

if( ($temp_dmax = dle_strrpos( $content['description'], ' ', $config['charset'] )) ) $content['description'] = dle_substr( $content['description'], 0, $temp_dmax, $config['charset'] );

$content['description'] .= " ...";

}

$content['link'] = htmlspecialchars ($content['link'], ENT_QUOTES, $config['charset']);

$tpl->set( '', $content['title'] );
$tpl->set( '{news}', $content['description'] );
$tpl->set( '[link]', "<a href=\"{$content['link']}\" target=\"_blank\">" );
$tpl->set( '[/link]', "</a>" );
$tpl->set( '{link}', $content['link'] );
$tpl->set( '{category}', $content['category'] );
$tpl->set( '{author}', $content['author'] );
$tpl->set( '{date}', langdate( $value['rss_date_format'], $content['date'] ) );

$news_date = $content['date'];
$tpl->copy_template = preg_replace_callback ( "#\{date=(.+?)\}#i", "formdate", $tpl->copy_template );

$tpl->compile( 'rss_info' );

}

if( isset($tpl->result['rss_info']) AND $tpl->result['rss_info'] ) {
$buffer = $tpl->result['rss_info'];
} else $buffer = '';


$tpl->result['rss_info'] = '';
$tpl->clear();

create_cache( "informer_" . $value['id'], $buffer, $config['skin'] );

}

第二步:编写样式并将变量标签引入其中(围绕主题样式或套用主题样式,预览效果更佳!)

代码语言:javascript
复制
<div class="card [fixed]<!--fxd-->[/fixed] mb-5">
    <div class="card-body">
        <div class="row">
            <div class="col-md-12">
                <a href="{full-link}" class="text-dark">
                    <img src="{THEME}/images/blog.svg" class="catimg"><b class="title shtitle m-0">[link][/link]</b>
                </a>
                <p class="auth mt-1" style="font-size: 16px;opacity: 0.7;"></p>
                <div class="noimg" style="color: #6b6e84;font-size: 1rem;">
                    <div class="text">{news}</div>
                </div>
            </div>
        </div>
    </div>
    <div class="card-footer">
        <ul class="list-inline m-0 text-muted f90 isize">
            <li class="list-inline-item auth d-none d-sm-inline">
                <img src="{THEME}/images/noavatar.png" class="sava">{author}</li>
            <li class="list-inline-item"><i class="zmdi zmdi-calendar-check" style="font-size: 17px;color: #ac92ec8c;vertical-align: middle;"></i> {date=Y.m.d}</li>
            <li class="list-inline-item"><i class="zmdi zmdi-check-all" style="font-size: 17px;color: #4fc1e994;"></i> Undefined</li>
            <li class="list-inline-item"><i class="zmdi zmdi-comment-outline" style="color: #F6BB42;"></i> Undefined</li>
        </ul>
    </div>
</div>

添加杜老师说RSS时,发现无法获取{author}值,这就很郁闷了。一番思索决定先看一下杜老师说RSS XML结构,结果有发现!:<author>标签中的信息包含在<name>标签中。那好办了

代码语言:javascript
复制
$atom = $item->children("http://www.w3.org/2005/Atom"); // 选择Atom命名空间下的子节点

if ($atom->author) { // 判断是否存在author标签
    $authorName = (string) $atom->author->name; // 获取author标签中的信息,并转换为字符串类型
    $this->content[$i]['author'] = $authorName; // 将信息存储到$content数组中指定索引位置的author属性
}

这样问题就解决了,最后说一下圈子的位置:位于导航栏-Circle 用时一天半,完美竣工?

本文参与?腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-10-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客?前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与?腾讯云自媒体分享计划? ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com