抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

Emlog 文章内容功能三合一

忙里偷闲
先唠叨几句,
已经好久没更新了
手机弄Emlog后台模板,弄的我眼睛疲劳,
这次弄完就不打算弄后台模板了,
我自己,已经够用了,
不折腾了后台了,太累了,
就在这两天发布,大家请关注吧!
上次群里的人说要这个功能,现在我就发布了
好了言归正传!
我说的文章内容功能三合一就是
1.文章内容添加文章索引,我这里是调用H2的
2.文章内容有含有标签的添加链接
3.文章内容有外链的添加nofollow

关键代码添加到Module.php文件中

 
  1. function article_index($content , $domain) {  
  2.             global $CACHE;  
  3.             $tag_cache = $CACHE->readCache('tags');  
  4.             $matches = array();  
  5.             $ul_li = '';  
  6.             $r = "/

    ([^<]+)<\/h2>/im";  

  7.     if(preg_match_all($r,$content,$matches)) {  
  8.            foreach($matches[1] as $num => $title) {  
  9.            $content = str_replace($matches[0][$num], '"title-'.$num.'">'.$title.'', $content);  
  10.            $ul_li .= '
  11. "#title-'.$num.'" title="'.$title.'">'.$title."
  12. \n";  
  13.              }  
  14.  $content = "\n 
  15.  [文章目录] 
  16.  \n" . $ul_li . " 
  17.  

\n" . $content;  

  •  }  
  •  foreach($tag_cache as $value){  
  •                 $tag_url = Url::tag($value['tagurl']);  
  •                 $keyword = $value['tagname'];  
  •                 $cleankeyword = stripslashes($keyword);  
  •                 $url = "{$cleankeyword}";  
  •                 $regEx = '\'(?!((<.*?)|($cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?))\'s';  
  •                 $content = preg_replace($regEx,$url,$content);          
  • }  
  • preg_match_all('/href="(.*?)"/', $log_content$matches);  
  •     if ($matches) {  
  •         foreach ($matches[1] as $val) {  
  •             if (strpos($val$domain) === false) {  
  •                 $log_content = str_replace('href="' . $val . '"', 'href="' . $val . '" rel="external nofollow" ', $log_content);  
  •             }  
  •         }  
  •     }  
  • preg_match_all('/src="(.*?)"/', $log_content$matches);  
  •     if ($matches) {  
  •         foreach ($matches[1] as $val) {  
  •             if (strpos($val$domain) === false) {  
  •                 $log_content = str_replace('src="' . $val . '"', 'src="' . $val . '" rel="external nofollow" ', $log_content);  
  •             }  
  •         }  
  •     }  
  • return $content;  
  • }  
  • ?>  
  • 添加Css样式

     
    1.  #article-index {  
    2.  border1px dashed #dedfe1;  
    3.  floatleft;  
    4.  margin: 0 20px 20px 0;  
    5.  padding: 0 6px;  
    6.  width280px;  
    7.  line-height24px;  
    8. }  
    9. #article-index b {  
    10.  border-bottom1px dashed #ddd;  
    11.  displayblock;  
    12.  line-height30px;  
    13.  padding: 0 4px;  
    14. }  
    15. #index-ul {  
    16.  margin5px;  
    17.  line-height: 1.8;  
    18. }  
    19. #index-ul li {  
    20.  backgroundnone repeat scroll 0 0 transparent;  
    21.  list-style-typedecimal;  
    22.  padding4px 10px;  
    23.  border-left1px solid #e2e2e2;  
    24.  border-bottom1px solid #e2e2e2;  
    25. }  
    26. #index-ul li {  
    27.  list-stylecircle outside none;  
    28. }  

    最后,打开echo_log.php文件

    查找

     
    1. echo $log_content; ?>  

    替换(当然你们自己改过,就不是找这个咯)

     
    1. echo article_index($log_content);?>  

    完工,祝大家好运,转载请著名地方哦,手机码字不容易啊

     

    emlog功能文章
    版权属于:

    疯狂老司机

    本文链接:

    https://crazyus.net/posts/articledirectory(转载时请注明本文出处及文章链接)

    7 评论

    既然来了就吐个槽吧

    撰写评论~

    单词 u7skn8第五个字符是什么?
    1. Avatar
      102X网 网友

      感谢楼主分享

    2. Avatar
      污桐 网友

      老司机就是老司机,不同凡响,很实用 😃

    3. Avatar
      纬八路 网友

      好多代码

    4. Avatar
      Mrxn 网友

      老哥这个很实用!要是可以修正一下,比如代码片段里面的不要加上tag的链接就完美了

    5. Avatar
      疯佬 管理员

      @Mrxn:代码片段,还真没考虑到!你不说还真没注意!

    6. Avatar
      Mrxn 网友

      @老司机:嗯 可以考虑遇见pre标签内的不执行替换, 我才发现另外一个不算bug的bug,比如文章中有个链接 http://xxx.com/info.php,而系统恰好有PHP标签和info标签的话,就会很尴尬.因为内链替换会把链接加上标签链接...不过这个不好解决(我认为...或许正册匹配到是URL的不替换?) 其实也可以不用解决 也可以当成一种挑战 试试 -_- 嘿嘿 反正pre标签解决了就基本上完美了

    7. Avatar
      疯佬 管理员

      @Mrxn:嗯,有空在折腾这功能,不急!而且我的的代码高亮,不好弄!

    Music Icon🎵 未加载歌曲
    00:00
    00:00
    暂无歌词
    Power by 疯狂老司机