Exemplo n.º 1
0
 function do_manage($stype = 'normal')
 {
     $cid = (int) $_GET['cid'];
     $pid = $_GET['pid'];
     //$stype OR $stype = iACP::$app_do;
     $stype_map = array('inbox' => '0', 'normal' => '1', 'trash' => '2', 'examine' => '3', 'off' => '4');
     $map_where = array();
     //status:[0:草稿][1:正常][2:回收][3:待审核][4:不合格]
     //postype: [0:用户][1:管理员]
     $stype && ($this->_status = $stype_map[$stype]);
     if (isset($_GET['pt']) && $_GET['pt'] != '') {
         $this->_postype = (int) $_GET['pt'];
     }
     $sql = "WHERE `status`='{$this->_status}'";
     $this->_postype === 'all' or $sql .= " AND `postype`='{$this->_postype}'";
     if (iACP::MP("ARTICLE.VIEW")) {
         $_GET['userid'] && ($sql .= iPHP::where($_GET['userid'], 'userid'));
     } else {
         $sql .= iPHP::where(iMember::$userid, 'userid');
     }
     if (isset($_GET['pid']) && $pid != '-1') {
         $uri_array['pid'] = $pid;
         if (empty($_GET['pid'])) {
             $sql .= " AND `pid`=''";
         } else {
             iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
             map::init('prop', $this->appid);
             $map_where += map::where($pid);
         }
     }
     $cp_cids = iACP::CP('__CID__', 'cs');
     //取得所有有权限的栏目ID
     if ($cp_cids) {
         if (is_array($cp_cids)) {
             if ($cid) {
                 array_search($cid, $cp_cids) === false && iACP::permission_msg('栏目[cid:' . $cid . ']', $ret);
             } else {
                 $cids = $cp_cids;
             }
         } else {
             $cids = $cid;
         }
         if ($_GET['sub'] && $cid) {
             $cids = $this->categoryApp->get_ids($cid, true);
             array_push($cids, $cid);
         }
         if ($_GET['scid'] && $cid) {
             iPHP::import(iPHP_APP_CORE . '/iMAP.class.php');
             map::init('category', $this->appid);
             $map_where += map::where($cids);
         } else {
             $sql .= iPHP::where($cids, 'cid');
         }
     } else {
         $sql .= iPHP::where('-1', 'cid');
     }
     if ($_GET['keywords']) {
         $kws = $_GET['keywords'];
         switch ($_GET['st']) {
             case "title":
                 $sql .= " AND `title` REGEXP '{$kws}'";
                 break;
             case "tag":
                 $sql .= " AND `tags` REGEXP '{$kws}'";
                 break;
             case "source":
                 $sql .= " AND `source` REGEXP '{$kws}'";
                 break;
             case "weight":
                 $sql .= " AND `weight`='{$kws}'";
                 break;
             case "id":
                 $sql .= " AND `id` REGEXP '{$kws}'";
                 break;
             case "tkd":
                 $sql .= " AND CONCAT(title,keywords,description) REGEXP '{$kws}'";
                 break;
         }
     }
     $_GET['title'] && ($sql .= " AND `title` like '%{$_GET['title']}%'");
     $_GET['tag'] && ($sql .= " AND `tags` REGEXP '[[:<:]]" . preg_quote(rawurldecode($_GET['tag']), '/') . "[[:>:]]'");
     $_GET['starttime'] && ($sql .= " AND `pubdate`>='" . iPHP::str2time($_GET['starttime'] . " 00:00:00") . "'");
     $_GET['endtime'] && ($sql .= " AND `pubdate`<='" . iPHP::str2time($_GET['endtime'] . " 23:59:59") . "'");
     isset($_GET['pic']) && ($sql .= " AND `haspic` ='" . ($_GET['pic'] ? 1 : 0) . "'");
     isset($_GET['userid']) && ($uri_array['userid'] = (int) $_GET['userid']);
     isset($_GET['keyword']) && ($uri_array['keyword'] = $_GET['keyword']);
     isset($_GET['tag']) && ($uri_array['tag'] = $_GET['tag']);
     isset($_GET['pt']) && ($uri_array['pt'] = $_GET['pt']);
     isset($_GET['cid']) && ($uri_array['cid'] = $_GET['cid']);
     $uri_array && ($uri = http_build_query($uri_array));
     $orderby = $_GET['orderby'] ? $_GET['orderby'] : "id DESC";
     $maxperpage = $_GET['perpage'] > 0 ? (int) $_GET['perpage'] : 20;
     if ($map_where) {
         $map_sql = iCMS::map_sql($map_where);
         $sql = ",({$map_sql}) map {$sql} AND `id` = map.`iid`";
     }
     $total = iPHP::total(false, articleTable::count_sql($sql), "G");
     iPHP::pagenav($total, $maxperpage, "篇文章");
     $limit = 'LIMIT ' . iPHP::$offset . ',' . $maxperpage;
     if ($map_sql || iPHP::$offset) {
         // if($map_sql){
         $ids_array = iDB::all("\n                    SELECT `id` FROM `#iCMS@__article` {$sql}\n                    ORDER BY {$orderby} {$limit}\n                ");
         //iDB::debug(1);
         $ids = iCMS::get_ids($ids_array);
         $ids = $ids ? $ids : '0';
         $sql = "WHERE `id` IN({$ids})";
         // }else{
         // $sql = ",(
         // SELECT `id` AS aid FROM `#iCMS@__article` {$sql}
         // ORDER BY {$orderby} {$limit}
         // ) AS art WHERE `id` = art.aid ";
         // }
         $limit = '';
     }
     $rs = iDB::all("SELECT * FROM `#iCMS@__article` {$sql} ORDER BY {$orderby} {$limit}");
     //iDB::debug(1);
     $_count = count($rs);
     include iACP::view("article.manage");
 }