为phpcms v9 后台增加按类别查找的功能,且不影响升级。

这是我第一次按phpcms v9的二次开发规则来做的一个简单开发。

v9中可以用 MY_xxx.php 继承 xxx.php 控制的开发,不影响升级,我以为模板也可以这样命名(但是不行的)。

效果如下,如果本栏目没设置类别,那么不会显示类别下拉框。

 

首先,找到 phpcms/modules/content/content.php  并复制一份,命名为MY_content.php

然后修改 MY_content.php

class MY_content extends admin{

  替换为

class MY_content extends content {

然后把 init函数修改了下,增加的部分在 以ikodota标记的(其实修改的很少)。

public function init() {

        $show_header = $show_dialog  = $show_pc_hash = '';

        if(isset($_GET['catid']) && $_GET['catid'] && $this->categorys[$_GET['catid']]['siteid']==$this->siteid) {

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

        $category = $this->categorys[$catid];

        $modelid = $category['modelid'];

            $admin_username = param::get_cookie('admin_username');

            //查询当前的工作流

            $setting = string2array($category['setting']);

            $workflowid = $setting['workflowid'];

            $workflows = getcache('workflow_'.$this->siteid,'commons');

            $workflows = $workflows[$workflowid];

            $workflows_setting = string2array($workflows['setting']);



            //将有权限的级别放到新数组中

            $admin_privs = array();

            foreach($workflows_setting as $_k=>$_v) {

                if(empty($_v)) continue;

                foreach($_v as $_value) {

                    if($_value==$admin_username) $admin_privs[$_k] = $_k;

                }

            }

            //工作流审核级别

            $workflow_steps = $workflows['steps'];

            $workflow_menu = '';

            $steps = isset($_GET['steps']) ? intval($_GET['steps']) : 0;

            //工作流权限判断

            if($_SESSION['roleid']!=1 && $steps && !in_array($steps,$admin_privs)) showmessage(L('permission_to_operate'));

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

            if($this->db->table_name==$this->db->db_tablepre) showmessage(L('model_table_not_exists'));;

            $status = $steps ? $steps : 99;

            if(isset($_GET['reject'])) $status = 0;

            $where = 'catid='.$catid.' AND status='.$status;

            //搜索

            
            //ikodota.bof
            //增加按类别搜索
            if(isset($_GET['typeid']) && !empty($_GET['typeid'])) {
                
                $typeid =  $_GET['typeid'];
                $where .= " AND `typeid` = '$typeid' ";
            }
            //ikodota.eof

            if(isset($_GET['start_time']) && $_GET['start_time']) {

                $start_time = strtotime($_GET['start_time']);

                $where .= " AND `inputtime` > '$start_time'";

            }

            if(isset($_GET['end_time']) && $_GET['end_time']) {

                $end_time = strtotime($_GET['end_time']);

                $where .= " AND `inputtime` < '$end_time'";

            }

            if($start_time>$end_time) showmessage(L('starttime_than_endtime'));

            if(isset($_GET['keyword']) && !empty($_GET['keyword'])) {

                $type_array = array('title','description','username');

                $searchtype = intval($_GET['searchtype']);

                if($searchtype < 3) {

                    $searchtype = $type_array[$searchtype];

                    $keyword = strip_tags(trim($_GET['keyword']));

                    $where .= " AND `$searchtype` like '%$keyword%'";

                } elseif($searchtype==3) {

                    $keyword = intval($_GET['keyword']);

                    $where .= " AND `id`='$keyword'";

                }

            }

            if(isset($_GET['posids']) && !empty($_GET['posids'])) {

                $posids = $_GET['posids']==1 ? intval($_GET['posids']) : 0;

                $where .= " AND `posids` = '$posids'";

            }

            

            $datas = $this->db->listinfo($where,'id desc',$_GET['page']);

            $pages = $this->db->pages;

            $pc_hash = $_SESSION['pc_hash'];

            for($i=1;$i<=$workflow_steps;$i++) {

                if($_SESSION['roleid']!=1 && !in_array($i,$admin_privs)) continue;

                $current = $steps==$i ? 'class=on' : '';

                $r = $this->db->get_one(array('catid'=>$catid,'status'=>$i));

                $newimg = $r ? '<img src="'.IMG_PATH.'icon/new.png" style="padding-bottom:2px" οnclick="window.location.href=\'?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'\'">' : '';

                $workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&steps='.$i.'&pc_hash='.$pc_hash.'" '.$current.' ><em>'.L('workflow_'.$i).$newimg.'</em></a><span>|</span>';

            }

            if($workflow_menu) {

                $current = isset($_GET['reject']) ? 'class=on' : '';

                $workflow_menu .= '<a href="?m=content&c=content&a=&menuid='.$_GET['menuid'].'&catid='.$catid.'&pc_hash='.$pc_hash.'&reject=1" '.$current.' ><em>'.L('reject').'</em></a><span>|</span>';

            }

            include $this->admin_tpl('MY_content_list');

        } else {

            include $this->admin_tpl('content_quick');

        }

    }

 

另外,为了让模板也能保持升级不变把:

include $this->admin_tpl('content_list'); 改为了

include $this->admin_tpl('MY_content_list');

 

所以,把模板文件:phpcms/modules/content/templates/content_list.tpl.php 复制一份,并改为 MY_content_list.tpl.php(这里用MY_是为了记住是自己修改的)

然后在 MY_content_list.tpl.php模板文件中的

<select name="posids"><option value='' <?php if($_GET['posids']=='') echo 'selected';?>><?php echo L('all');?></option>

之前增加一下代码。

<!--ikodota.bof-->
                <?php $TYPE = getcache('type_content','commons');
                if(defined('IN_ADMIN')  && !defined('HTML'))pc_base::load_sys_class("get_model", "model", 0);
                $get_db = new get_model();
                $r = $get_db->sql_query("SELECT usable_type FROM v9_category WHERE catid='$catid' ORDER BY catid DESC LIMIT 20");
                while(($s = $get_db->fetch_next()) != false) {
                    $a[] = $s;
                    //var_dump($a);
                }
                $data = $a;unset($a); //计算出本栏目下的类别ID
                

                if(is_array($data)) foreach($data AS $rra) { 
                    $arrtype = substr($rra[usable_type], 1, -1);
                    $arrtype = explode(',',$arrtype);
                }

                
                 if(count($arrtype)>1) {
                     echo '<select name="typeid">';
                    echo '<option value="0">类别</option>';
                    foreach($arrtype AS $t) { 
                 ?>
                     <option value="<?php echo $t; ?>" <?php if($_GET['typeid']==$t) echo 'selected';?>><?php echo $TYPE[$t]['name'];?></option>

                <?php 
                    }
                    echo '</select>';
                }
                
                ?>
                <!--ikodota.eof-->

 

这种方法也许不是最优方法,却是最快、最简单的实现一些功能的捷径,还不影响升级。

-----------------------------------

补充:删除那些不需要修改的方法。如add(),edit()等等。。这样免得系统会重复调用方法而消耗更多资源。这就是为什么我上面不敢肯定说是最优方法的原因。

转载于:https://www.cnblogs.com/ikodota/archive/2012/06/13/phpcms_v9_content_search_by_typeid.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值