西安网站建设
在线咨询

扫描二维码分享到微信

phpcms多模型相关文章插件v1.0插件bug修复

2020-06-28

phpcms多模型相关文章插件v1.0

phpcms在后台添加文章的时候,可以选择相关文章。这本来是一个很好的功能,但是却只能选择相同模型的文章,不能跨模型选择文章。今天发布的这个插件就是解决这个问题的。

使用方法:

1:下载插件包  phpcms多模型相关文章插件.zip

2:解压后把relation文件夹复制到moudles文件夹下。

3:后台模块管理安装relation模块;

4:模块多模型相关文章安装,然后安装成功后会提示创建成功,您可以使用多模型相关文章功能

 

5 : 现在可以去添加一个文章,然后点击相关文章按钮进行测试,发现我们可以选择多个模型的栏目了。

 

6:选择相关文章保存后,访问这篇文章。可以看到下载模型的文章出现在新闻模型的文章中。

插件bug修复:

找到\phpcms\modules\content\classes\content_tag.class.php

并找到插件文件\phpcms\modules\relation\src\content_tag.class.php

要修改以上2个文件,具体教程看下面:

修复必须手动选择相关文章的bug。修复后,没有手动选择相关文章时,可以根据关键词自动相关文章:

\phpcms\modules\content\classes\content_tag.class.php

找到“相关文章标签”:

public function relation($data) {

         $catid = intval($data['catid']);

         $modelid = intval($data['modelid']);

         if(!$this->set_modelid($catid) && $modelid) {

              $this->db->set_model($modelid);

              $this->tablename = $this->db->table_name;

         } elseif(!$this->set_modelid($catid)) {

              return false;

         }

         $order = $data['order'];

         $sql = "`status`=99";

         $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

         if($data['relation']) {

              $relations = explode('|',trim($data['relation'],'|'));

              $relations = array_diff($relations, array(null));

              $relations = implode(',',$relations);

              $sql = " `id` IN ($relations)";

              $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

         } elseif($data['keywords']) {

              $keywords = str_replace(array('%',"'"), '',$data['keywords']);

              $keywords_arr = explode(' ',$keywords);

              $key_array = array();

              $number = 0;

              $i =1;

              $sql .= " AND catid='$catid'";

              foreach ($keywords_arr as $_k) {

                   $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');

                   $r = $this->db->select($sql2, '*', $limit, '','','id');

                   $number += count($r);

                   foreach ($r as $id=>$v) {

                       if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;

                       $i++;

                   }

                   if($data['limit']<$number) break;

              }

         }

         if($data['id']) unset($key_array[$data['id']]);

         return $key_array;

     }

 

修改为:

public function relation($data) {

         $catid = intval($data['catid']);

         $modelid = intval($data['modelid']);

         if(!$this->set_modelid($catid) && $modelid) {

              $this->db->set_model($modelid);

              $this->tablename = $this->db->table_name;

         } elseif(!$this->set_modelid($catid)) {

              return false;

         }

         $order = $data['order'];

         $sql = "`status`=99";

         $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

         if($data['relation']) {

              $relations = explode(',',$data['relation']);

              foreach ($relations as $key => $value) {

                   //类别id|模型id

                   $modelid_arr[] =  explode('|',$value);

              }

              foreach ($modelid_arr as $akey => $avalue) {

                   //模型id组成的数组

                   $modelid_narr[] =  $avalue[1];

                   //id组成的数组

                   $catidsarr[] = $avalue[0];

              }

              //去除重复的modelid

              $modelid_newarr = array_unique($modelid_narr);

              //存储多模型所有的查询结果。以模型id为键,值为一个结果数组

              $data1= array();

              foreach ($modelid_newarr as $key1 => $value1) {             

                   $relation= array();

                   foreach ($modelid_arr as $key2 => $value2) {

 

                       if($value2[1] == $value1){

                            $relation[] = $value2[0];

                       }

 

                   }

                   if(sizeof($relation)>0){

                       $catids_str = implode(',', $relation);

                       $sql = " `id` IN ($catids_str)";

                   }else{

                       $sql="";

                   }

             

     

                   $this->db->set_model($value1);

                   $this->tablename = $this->db->table_name;

                   $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

                   $data1= array_merge($data1, $key_array);

             }

         }elseif($data['keywords']) {

 

              $keywords = str_replace(array('%',"'"), '',$data['keywords']);

              $keywords_arr = explode(' ',$keywords);

              $key_array = array();

              $number = 0;

              $i =1;

              $sql .= " AND catid='$catid'";

              foreach ($keywords_arr as $_k) {

                   $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');

                   $r = $this->db->select($sql2, '*', $limit, '','','id');

                   $number += count($r);

                   foreach ($r as $id=>$v) {

                       if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;

                       $i++;

                   }

                   if($data['limit']<$number) break;

              }

              $data1 = $key_array;

         }

         return $data1;

     }

    

 

 

第二种方法:

或者直接将插件里的\phpcms\modules\relation\src\content_tag.class.php

里的

public function relation($data) {

           $catid = intval($data['catid']);

           $modelid = intval($data['modelid']);

           if(!$this->set_modelid($catid) && $modelid) {

                 $this->db->set_model($modelid);

                 $this->tablename = $this->db->table_name;

           } elseif(!$this->set_modelid($catid)) {

                 return false;

           }

           $order = $data['order'];

           $sql = "`status`=99";

           $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

           if($data['relation']) {

                 $relations = explode(',',$data['relation']);

                

                 foreach ($relations as $key => $value) {

                      //类别id|模型id

                      $modelid_arr[] =  explode('|',$value);

                 }

                 foreach ($modelid_arr as $akey => $avalue) {

                      //模型id组成的数组

                      $modelid_narr[] =  $avalue[1];

                      //id组成的数组

                      $catidsarr[] = $avalue[0];

                 }

                

                 //去除重复的modelid

                 $modelid_newarr = array_unique($modelid_narr);

 

                

                 //存储多模型所有的查询结果。以模型id为键,值为一个结果数组

                 $data1= array();

 

                 foreach ($modelid_newarr as $key1 => $value1) {               

                 $relation= array();

                 foreach ($modelid_arr as $key2 => $value2) {

 

                      if($value2[1] == $value1){

                            $relation[] = $value2[0];

                      }

 

                 }

 

 

                 if(sizeof($relation)>0){

                     $catids_str = implode(',', $relation);

 

                      $sql = " `id` IN ($catids_str)";

                 }else{

                      $sql="";

                 }

                

     

                 $this->db->set_model($value1);

                 $this->tablename = $this->db->table_name;

                

 

                      $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

             

               

                       $data1= array_merge($data1, $key_array);

                     

                     

               }

 

             

                

          

           }

          

           return $data1;

      }

 

修改为:

public function relation($data) {

           $catid = intval($data['catid']);

           $modelid = intval($data['modelid']);

           if(!$this->set_modelid($catid) && $modelid) {

                 $this->db->set_model($modelid);

                 $this->tablename = $this->db->table_name;

           } elseif(!$this->set_modelid($catid)) {

                 return false;

           }

           $order = $data['order'];

           $sql = "`status`=99";

           $limit = $data['id'] ? $data['limit']+1 : $data['limit'];

           if($data['relation']) {

                 $relations = explode(',',$data['relation']);

                 foreach ($relations as $key => $value) {

                      //类别id|模型id

                      $modelid_arr[] =  explode('|',$value);

                 }

                 foreach ($modelid_arr as $akey => $avalue) {

                      //模型id组成的数组

                      $modelid_narr[] =  $avalue[1];

                      //id组成的数组

                      $catidsarr[] = $avalue[0];

                 }

                 //去除重复的modelid

                 $modelid_newarr = array_unique($modelid_narr);

                 //存储多模型所有的查询结果。以模型id为键,值为一个结果数组

                 $data1= array();

                 foreach ($modelid_newarr as $key1 => $value1) {               

                      $relation= array();

                      foreach ($modelid_arr as $key2 => $value2) {

 

                            if($value2[1] == $value1){

                                  $relation[] = $value2[0];

                            }

 

                      }

                      if(sizeof($relation)>0){

                            $catids_str = implode(',', $relation);

                            $sql = " `id` IN ($catids_str)";

                      }else{

                            $sql="";

                      }

                

     

                      $this->db->set_model($value1);

                      $this->tablename = $this->db->table_name;

                      $key_array = $this->db->select($sql, '*', $limit, $order,'','id');

                      $data1= array_merge($data1, $key_array);

               }

           }elseif($data['keywords']) {

 

                 $keywords = str_replace(array('%',"'"), '',$data['keywords']);

                 $keywords_arr = explode(' ',$keywords);

                 $key_array = array();

                 $number = 0;

                 $i =1;

                 $sql .= " AND catid='$catid'";

                 foreach ($keywords_arr as $_k) {

                      $sql2 = $sql." AND `keywords` LIKE '%$_k%'".(isset($data['id']) && intval($data['id']) ? " AND `id` != '".abs(intval($data['id']))."'" : '');

                      $r = $this->db->select($sql2, '*', $limit, '','','id');

                      $number += count($r);

                      foreach ($r as $id=>$v) {

                            if($i<= $data['limit'] && !in_array($id, $key_array)) $key_array[$id] = $v;

                            $i++;

                      }

                      if($data['limit']<$number) break;

                 }

                 $data1 = $key_array;

           }

           return $data1;

      }

     



标签: phpcms PHP CMS 多模型相关文章插件 phpcms多模型相关文章插件 插件 相关文章插件

上一篇:phpcms v9禁止提交信息到官网方法详解-解决phpcms后台慢的问题-最佳解决方法
下一篇:phpcms正则替换-替换br-替换img-替换<---正则替换分页pages-手机端分页 正则替换增加m目录分页

网站栏目

建站知识 酷站欣赏 网站优化 网络营销 网站安全 行业新闻 公司新闻 建站工具


最新文章

css 如何让pc端不显示 手机端

css 如何让pc端不显示 手机端显示-html+css实现电脑端显示(隐藏)手机端隐藏(显示)htm...

apache伪静态排除目录规则

apache伪静态排除目录规则:排除某个文件夹:方法1:RewriteRule ^(statics|api|uploa...

CKEditor跨站脚本漏洞(CKEdito

CNVD-IDCNVD-2020-16705公开日期2020-03-11危害级别中影响产品CKEditor CKEditor 4 ...

RGCMS建站管理系统(一款基于tp5

RGCMS建站管理系统(一款基于tp5 1框架(Thinkphp5 1)好用的PHP建站管理系统)睿谷信...

织梦cms(dedecms)用SQL语句批

织梦cms(dedecms)用SQL语句批量替换为空的字段1、备份数据库2、后台-系统-SQL工具,...


相关内容

phpcms会员注册短信验证插件-短

phpcms会员注册短信验证插件-短信通短信接口安装说明一、短信通安装步骤1、备份网站根...

PHPCMS v9短信验证码互亿无线

插件说明本插件系互亿无线针对phpcms V9 0短信插件开发,插件内的所有文件均为对原文...

phpcms v9建网站 php格式化

用PHPCMS V9 建站时,经常会用到时间标签,它是通用标签调用-日期时间格式化,适用全...

phpcms v9建站 ajax列表分页

phpcms v9建站 ajax列表分页加载更多直接下载:phpcms v9建站 ajax列表分页加载更...

PHPCMS V9建网站 定时发布文

PHPCMS V9建网站 定时发布文章的插件点击下载插件教程:PHPCMS V9 定时发布文章的...

phpcms v9 Tag伪静态 url静

PhpCms v9 Tag伪静态 url静态化,网站建设测试可用  首先确认我们的需求:http: ...

PHPCMS V9 TAG标签的URL伪静

PHPCMS V9网站TAG标签的URL伪静态设置和分页BUG修复最近在使用PHPCMS V9建一个站的时...

PHPCMS V9编辑器HTML/JS/php代

PHPCMS V9后台编辑器添加HTML JS 代码而不解析对于大部人来说是很鸡肋的东西,但对...


COPYRIGHT (©)2018-2019 西安黑米网络 | 西安网站建设 |  百度地图|  网站地图|  标签 |  会员登录  |  会员注册  |  最近更新时间: 2020-06-28 15:08:33