分类扩展

分类扩展

基于当前分类,获取根分类,同级分类,子级分类及当前分类所在树
最后修改时间:09月02日 23:43,查看次数:89

MD5值:3D17A1602DC34CC9CBCA4FC3E93C56AE

上传插件

方法一

直接通过后台的【本地后台上传插件】,将下载过来的ZIP包直接上传解压。

优点:操作便捷!

缺点:部分主机会解压失败

方法二

下载插件后,本地解压,并通过FTP将 文件夹 上传到 plugins 目录下。

优点:安装比较顺利。

缺点:可能需要你懂点网建知识,会一点点小编程

安装插件

上传成功后的插件会在【未安装插件】列表中,请点击安装

图片

安装后,会显示到【已安装列表】,这时候插件是不可用状态,请点击状态,变成【绿标】即表示插件安装成功

图片

参数调整

您在安装过程中,因为一些原因,没有配置好参数,可以在这里进行配置

图片

快捷栏目管理

系统支持插件的一些配置信息自定义到:左侧菜单/全局区/内容区,这大块上,以方便维护人员快速进入

图片

图片



内容介绍

基于当前分类,获取根分类,同级分类,子级分类及当前分类所在树,前台代码如下:

<?php
/**
 * 分类扩展<前台应用>
 * @作者 phpok.com
 * @版本 4.7.199
 * @授权 http://www.phpok.com/lgpl.html PHPOK开源授权协议:GNU Lesser General Public License
 * @时间 2017年04月20日 11时14分
**/
class www_catelistext extends phpok_plugin
{
    public $me;
    public function __construct()
    {
        parent::plugin();
        $this->me = $this->_info();
    }

    public function ap_project_index_after()
    {
        $page_rs = $this->tpl->val('page_rs');
        if(!$page_rs){
            return false;
        }
        if(!$page_rs['cate']){
            return false;
        }
        $this->cate_ext($page_rs);
    }

    public function ap_content_index_after()
    {
        $page_rs = $this->tpl->val('page_rs');
        if(!$page_rs){
            return false;
        }
        if(!$page_rs['cate']){
            return false;
        }
        $this->cate_ext($page_rs);
    }

    private function cate_ext($page_rs)
    {
        $catelist = phpok("_catelist",'pid='.$page_rs['id']);
        $data = array();
        $cate_rs = $this->tpl->val('cate_rs');
        if($cate_rs){
            $data['cate'] = $cate_rs;
        }
        $cate_parent_rs = $this->tpl->val('cate_parent_rs');
        if($cate_parent_rs){
            $data['parent'] = $cate_parent_rs;
        }

        $cate_root = $this->tpl->val('cate_root');
        if(!$cate_root){
            $cate_root = $this->tpl->val('cate_root_rs');
        }
        if($cate_root){
            $data['root'] = $cate_root;
        }
        //基于分类生成lead
        if($data['cate']){
            $lead = array();
            $i = 0;
            $lead[$i] = $data['cate'];
            $i++;
            if($data['parent']){
                $lead[$i] = $data['parent'];
                $i++;
                $this->_lead_parent($lead,$data['parent']['parent_id'],$data['root']['id'],$catelist['all'],$i);
            }
            krsort($lead);
            $data['lead'] = $lead;
        }
        //第一级子菜单
        $i=0;
        $treelist = array();
        if($data['lead']){
            $count = count($data['lead']);
            foreach($catelist['sublist'] as $key=>$value){
                $tmp = $value;
                $tmp['_level'] = 1;
                $treelist[$i] = $tmp;
                $i++;
                if($value['id'] == $data['lead'][($count-1)]['id']){
                    $ext_treelist = $this->_lead_son($data['lead'],$catelist['all']);
                    if($ext_treelist){
                        foreach($ext_treelist as $k=>$v){
                            $treelist[$i] = $v;
                            $i++;
                        }
                    }
                }
            }
        }else{
            foreach($catelist['sublist'] as $key=>$value){
                $tmp = $value;
                $tmp['_level'] = 1;
                $treelist[$i] = $tmp;
                $i++;
            }
        }
        //高亮
        if($data['lead'] && $treelist){
            $ids = array();
            foreach($data['lead'] as $key=>$value){
                $ids[] = $value['id'];
            }
            foreach($treelist as $key=>$value){
                if(in_array($value['id'],$ids)){
                    $tmp = $value;
                    $tmp['_highlight'] = true;
                    $treelist[$key] = $tmp;
                }
            }
        }
        $data['tree'] = $treelist;
        $titlelist = ($this->me && $this->me['param'] && $this->me['param']['select_title']) ? explode(",",$this->me['param']['select_title']) : array(0=>'筛选');
        $data['treelist'] = array(array('title'=>$titlelist[0],'rslist'=>$catelist['sublist']));
        if($lead && $ids){
            $tmplist = array();
            $i=0;
            foreach($lead as $key=>$value){
                $tmp = array();
                foreach($catelist['all'] as $k=>$v){
                    if($v['parent_id'] == $value['parent_id']){
                        if(in_array($v['id'],$ids)){
                            $v['_highlight'] = true;
                        }
                        $tmp[] = $v;
                    }
                }
                if($tmp){
                    $tmptitle = $titlelist[$i] ? $titlelist[$i] : '筛选';
                    $tmplist[$i] = array('title'=>$tmptitle,'rslist'=>$tmp);
                    $i++;
                    unset($tmp);
                }
            }
            if($cate_rs){
                $tmp = array();
                foreach($catelist['all'] as $k=>$v){
                    if($v['parent_id'] == $cate_rs['id']){
                        if(in_array($v['id'],$ids)){
                            $v['_highlight'] = true;
                        }
                        $tmp[] = $v;
                    }
                }
                if($tmp){
                    $tmptitle = $titlelist[$i] ? $titlelist[$i] : '筛选';
                    $tmplist[$i] = array('title'=>$tmptitle,'rslist'=>$tmp);
                    $i++;
                    unset($tmp);
                }
            }
            $data['treelist'] = $tmplist;
            unset($tmplist);
        }
        $identifier = ($this->me && $this->me['param'] && $this->me['param']['cate_sign']) ? $this->me['param']['cate_sign'] : 'cateinfo';
        $this->assign($identifier,$data);
    }

    private function _lead_son($lead,$catelist)
    {
        $i = 0;
        $treelist = array();
        $count = count($lead);
        $current = current($lead);
        $cate = end($lead);
        if(!$count || $count < 1){
            return false;
        }
        if($count == 1){
            foreach($catelist as $key=>$value){
                if($value['parent_id'] != $cate['id']){
                    continue;
                }
                $tmp = $value;
                $tmp['_level'] = 1;
                $tmp['_space'] = ' ';
                $treelist[$i] = $tmp;
                $i++;
            }
            return $treelist;
        }
        $tmp_i = 1;
        foreach($lead as $key=>$value){
            if($value['id'] != $current['id'] && $value['id'] != $cate['id']){
                $tmp = $value;
                $tmp['_level'] = $tmp_i;
                $space = '';
                for($m=0;$m<$tmp_i;$m++){
                    $space .= ' ';
                }
                $tmp['_space'] = $space;
                $treelist[$i] = $tmp;
                $i++;
                $tmp_i++;
            }
        }
        $tmplist = false;
        foreach($catelist as $key=>$value){
            if($value['parent_id'] == $cate['id']){
                $tmplist = true;
                break;
            }
        }
        if(!$tmplist){
            foreach($catelist as $key=>$value){
                if($value['parent_id'] != $cate['parent_id']){
                    continue;
                }
                $tmp = $value;
                $tmp['_level'] = $tmp_i;
                $space = '';
                for($m=0;$m<$tmp_i;$m++){
                    $space .= ' ';
                }
                $tmp['_space'] = $space;
                $treelist[$i] = $tmp;
                $i++;
            }
            return $treelist;
        }
        $tmp = $cate;
        $tmp['_level'] = $tmp_i;
        $space = '';
        for($m=0;$m<$tmp_i;$m++){
            $space .= ' ';
        }
        $tmp['_space'] = $space;
        $treelist[$i] = $tmp;
        $i++;
        $tmp_i++;
        foreach($catelist as $key=>$value){
            if($value['parent_id'] != $cate['id']){
                continue;
            }
            $tmp = $value;
            $tmp['_level'] = $tmp_i;
            $space = '';
            for($m=0;$m<$tmp_i;$m++){
                $space .= ' ';
            }
            $tmp['_space'] = $space;
            $treelist[$i] = $tmp;
            $i++;
        }
        return $treelist;
    }

    private function _lead_parent(&$lead,$parent_id,$root_id,$cate_all,$i=0)
    {
        if($parent_id && $root_id && $parent_id != $root_id){
            $parent = $cate_all[$parent_id];
            $lead[$i] = $parent;
            $i++;
            $this->_lead_parent($lead,$parent['parent_id'],$root_id,$cate_all,$i);
        }
    }
    
}


论坛咨询