コード例 #1
0
 protected function _index()
 {
     // 搜索参数
     $get = $this->input->get(NULL, TRUE);
     $get = isset($get['rewrite']) ? dr_rewrite_decode($get['rewrite']) : $get;
     $_GET['page'] = max(1, (int) $get['page']);
     $get['keyword'] = str_replace(array('%', ' '), array('', '%'), $get['keyword']);
     unset($get['c'], $get['m'], $get['page']);
     $where = '';
     if ($get) {
         $field = $this->get_cache('member', 'field');
         $space = $this->get_cache('member', 'spacefield');
         foreach ($get as $name => $v) {
             if (isset($space[$name]) && $space[$name]['fieldtype'] == 'Linkage') {
                 // 组合空间字段的联动菜单
                 $link = dr_linkage($space[$name]['setting']['option']['linkage'], $v);
                 if ($link) {
                     if ($link['child']) {
                         $where .= 'IN_' . $name . '=' . $link['childids'] . ' ';
                     } else {
                         $where .= $name . '=' . $link['ii'] . ' ';
                     }
                 }
             } elseif (isset($field[$name]) && $field[$name]['fieldtype'] == 'Linkage') {
                 // 组合会员字段的联动菜单
                 $link = dr_linkage($field[$name]['setting']['option']['linkage'], $v);
                 if ($link) {
                     if ($link['child']) {
                         $where .= 'IN_' . $name . '=' . $link['childids'] . ' ';
                     } else {
                         $where .= $name . '=' . $link['ii'] . ' ';
                     }
                 }
             } else {
                 $where .= $name . '=' . $v . ' ';
             }
         }
     }
     $this->template->assign(array('get' => $get, 'where' => $where, 'params' => $get, 'keyword' => $get['keyword'], 'urlrule' => dr_space_search_url($get, 'page', '[page]'), 'meta_title' => $this->space['title'], 'meta_keywords' => $this->space['keywords'], 'meta_description' => $this->space['description']));
     $this->template->display('index.html');
 }
コード例 #2
0
 /**
  * 条件查询
  *
  * @param	object	$select	查询对象
  * @param	array	$param	条件参数
  * @param	intval	$cid	文档id
  * @return	array	
  */
 private function _extend_where(&$select, $param, $cid)
 {
     $_param = array();
     // 缓存文件名称
     $this->cache_file = md5($this->duri->uri(1) . $this->uid . $cid . SITE_ID . $this->input->ip_address() . $this->input->user_agent());
     // 存在POST提交时,重新生成缓存文件
     if (IS_POST) {
         $data = $this->input->post('data');
         foreach ($data as $i => $t) {
             if ($t == '') {
                 unset($data[$i]);
             }
         }
         $this->cache->file->save($this->cache_file, $data, 3600);
         $param['search'] = 1;
         unset($_GET['page']);
     }
     // 存在search参数时,读取缓存文件
     if ($param['search'] == 1) {
         $data = $this->cache->file->get($this->cache_file);
         $_param['search'] = 1;
         if (isset($data['keyword']) && $data['keyword'] != '' && $data['field']) {
             $field = $this->field ? $this->field : $this->ci->get_cache('module-' . SITE_ID . '-' . $this->mdir, 'extend');
             if ($data['field'] == 'id') {
                 // 按id查询
                 $id = array();
                 $ids = explode(',', $data['keyword']);
                 foreach ($ids as $i) {
                     $id[] = (int) $i;
                 }
                 $select->where_in('id', $id);
             } elseif ($field[$data['field']]['fieldtype'] == 'Linkage' && $field[$data['field']]['setting']['option']['linkage']) {
                 // 联动菜单搜索
                 if (is_numeric($data['keyword'])) {
                     // 联动菜单id查询
                     $link = dr_linkage($field[$data['field']]['setting']['option']['linkage'], (int) $data['keyword'], 0, 'childids');
                     if ($link) {
                         $select->where($data['field'] . ' IN (' . $link . ')');
                     }
                 } else {
                     // 联动菜单名称查询
                     $id = (int) $this->ci->get_cache('linkid-' . SITE_ID, $field[$data['field']]['setting']['option']['linkage']);
                     if ($id) {
                         $select->where($data['field'] . ' IN (select id from `' . $select->dbprefix('linkage_data_' . $id) . '` where `name` like "%' . $data['keyword'] . '%")');
                     }
                 }
             } else {
                 $select->like($data['field'], urldecode($data['keyword']));
             }
         }
         // 时间搜索
         if (isset($data['start']) && $data['start']) {
             $data['end'] = strtotime(date('Y-m-d 23:59:59', $data['end'] ? $data['end'] : SYS_TIME));
             $data['start'] = strtotime(date('Y-m-d 00:00:00', $data['start']));
             $select->where('updatetime BETWEEN ' . $data['start'] . ' AND ' . $data['end']);
         } elseif (isset($data['end']) && $data['end']) {
             $data['end'] = strtotime(date('Y-m-d 23:59:59', $data['end']));
             $data['start'] = 0;
             $select->where('updatetime BETWEEN ' . $data['start'] . ' AND ' . $data['end']);
         }
     }
     // 类别判断
     if (isset($param['type'])) {
         $_param['type'] = (int) $param['type'];
         $select->where('mytype', (int) $param['type']);
     }
     $select->where('cid', (int) $cid);
     return $_param;
 }
コード例 #3
0
 /**
  * 条件查询
  *
  * @param	object	$select	查询对象
  * @param	intval	$where	是否搜索
  * @return	intval	
  */
 protected function _where(&$select, $param)
 {
     // 存在POST提交时
     if (IS_POST) {
         $search = $this->input->post('data');
         $param['keyword'] = $search['keyword'];
         $param['start'] = $search['start'];
         $param['end'] = $search['end'];
         $param['field'] = $search['field'];
     }
     // 相对于内容
     if ($this->cid) {
         $select->where('cid', $this->cid);
     }
     // 权限筛选
     if ($this->ids) {
         $select->where_in('cid', $this->ids);
     }
     // 存在search参数时,读取缓存文件
     if ($param) {
         if (isset($param['keyword']) && $param['keyword'] != '') {
             $field = $this->field;
             $param['field'] = $param['field'] ? $param['field'] : 'subject';
             if ($param['field'] == 'id') {
                 // 按id查询
                 $id = array();
                 $ids = explode(',', $param['keyword']);
                 foreach ($ids as $i) {
                     $id[] = (int) $i;
                 }
                 $select->where_in('id', $id);
             } elseif ($field[$param['field']]['fieldtype'] == 'Linkage' && $field[$param['field']]['setting']['option']['linkage']) {
                 // 联动菜单搜索
                 if (is_numeric($param['keyword'])) {
                     // 联动菜单id查询
                     $link = dr_linkage($field[$param['field']]['setting']['option']['linkage'], (int) $param['keyword'], 0, 'childids');
                     if ($link) {
                         $select->where($param['field'] . ' IN (' . $link . ')');
                     }
                 } else {
                     // 联动菜单名称查询
                     $id = (int) $this->ci->get_cache('linkid-' . SITE_ID, $field[$param['field']]['setting']['option']['linkage']);
                     if ($id) {
                         $select->where($param['field'] . ' IN (select id from `' . $select->dbprefix('linkage_data_' . $id) . '` where `name` like "%' . $param['keyword'] . '%")');
                     }
                 }
             } else {
                 $select->like($param['field'], urldecode($param['keyword']));
             }
         }
         // 时间搜索
         if (isset($param['start']) && $param['start']) {
             $param['end'] = strtotime(date('Y-m-d 23:59:59', $param['end'] ? $param['end'] : SYS_TIME));
             $param['start'] = strtotime(date('Y-m-d 00:00:00', $param['start']));
             $select->where('inputtime BETWEEN ' . $param['start'] . ' AND ' . $param['end']);
         } elseif (isset($param['end']) && $param['end']) {
             $param['end'] = strtotime(date('Y-m-d 23:59:59', $param['end']));
             $param['start'] = 0;
             $select->where('inputtime BETWEEN ' . $param['start'] . ' AND ' . $param['end']);
         }
     }
     return $param;
 }
コード例 #4
0
ファイル: C_Model.php プロジェクト: surgeon-xie/jxseo
 /**
  * 条件查询
  *
  * @param	object	$select	查询对象
  * @param	array	$param	条件参数
  * @return	array	
  */
 private function _where(&$select, $param)
 {
     $uri = $this->duri->uri(1);
     $catid = (int) $_POST['data']['catid'];
     if ($catid) {
         if (strpos($uri, 'catid/') === FALSE) {
             $uri .= '/catid/' . $catid;
         } else {
             $data = $this->duri->uri2ci($uri);
             $uri = str_replace('catid/' . (int) $data['param']['catid'], 'catid/' . $catid, $uri);
             unset($data);
         }
     } elseif (strpos($uri, 'catid/') === FALSE) {
         $uri .= '/catid/0/';
     }
     unset($catid);
     $_param = array();
     $this->cache_file = md5($uri . $this->uid . SITE_ID . $this->input->ip_address() . $this->input->user_agent());
     // 缓存文件名称
     // 存在POST提交时,重新生成缓存文件
     if (IS_POST) {
         $data = $this->input->post('data');
         foreach ($data as $i => $t) {
             if (!$t) {
                 unset($data[$i]);
             }
         }
         $this->cache->file->save($this->cache_file, $data, 3600);
         $param['search'] = 1;
         unset($_GET['page']);
     }
     // 存在search参数时,读取缓存文件
     if ($param['search'] == 1) {
         $data = $this->cache->file->get($this->cache_file);
         $_param['search'] = 1;
         if (isset($data['keyword']) && $data['keyword'] && $data['field']) {
             $field = $this->ci->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'field');
             if ($data['field'] == 'id') {
                 // 按id查询
                 $id = array();
                 $ids = explode(',', $data['keyword']);
                 foreach ($ids as $i) {
                     $id[] = (int) $i;
                 }
                 $select->where_in('id', $id);
             } elseif ($field[$data['field']]['fieldtype'] == 'Linkage' && $field[$data['field']]['setting']['option']['linkage']) {
                 // 联动菜单搜索
                 if (is_numeric($data['keyword'])) {
                     // 联动菜单id查询
                     $link = dr_linkage($field[$data['field']]['setting']['option']['linkage'], (int) $data['keyword'], 0, 'childids');
                     if ($link) {
                         $select->where($data['field'] . ' IN (' . $link . ')');
                     }
                 } else {
                     // 联动菜单名称查询
                     $id = (int) $this->ci->get_cache('linkid-' . SITE_ID, $field[$data['field']]['setting']['option']['linkage']);
                     if ($id) {
                         $select->where($data['field'] . ' IN (select id from `' . $select->dbprefix('linkage_data_' . $id) . '` where `name` like "%' . $data['keyword'] . '%")');
                     }
                 }
             } else {
                 $select->like($data['field'], urldecode($data['keyword']));
             }
         }
         // 时间搜索
         if (isset($data['start']) && $data['start']) {
             $data['end'] = strtotime(date('Y-m-d 23:59:59', $data['end'] ? $data['end'] : SYS_TIME));
             $data['start'] = strtotime(date('Y-m-d 00:00:00', $data['start']));
             $select->where('updatetime BETWEEN ' . $data['start'] . ' AND ' . $data['end']);
         } elseif (isset($data['end']) && $data['end']) {
             $data['end'] = strtotime(date('Y-m-d 23:59:59', $data['end']));
             $data['start'] = 0;
             $select->where('updatetime BETWEEN ' . $data['start'] . ' AND ' . $data['end']);
         }
         if (isset($data['catid'])) {
             $param['catid'] = $data['catid'];
         }
     }
     if (isset($param['flag'])) {
         $_param['flag'] = $param['flag'];
         $select->where('flag', $param['flag']);
     }
     if (isset($param['catid']) && $param['catid']) {
         $_param['catid'] = $param['catid'];
         $cat = $this->ci->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'category', $param['catid']);
         if ($cat['child']) {
             $select->where_in('catid', explode(',', $cat['childids']));
         } else {
             $select->where('catid', $param['catid']);
         }
     }
     if ($this->where) {
         $select->where($this->where);
     }
     return $_param;
 }
コード例 #5
0
 /**
  * 内容关联字段数据读取
  */
 public function related()
 {
     // 强制将模板设置为后台
     $this->template->admin();
     // 登陆判断
     if (!$this->uid) {
         $this->admin_msg(lang('m-039'));
     }
     // 参数判断
     $dirname = $this->input->get('module');
     if (!$dirname) {
         $this->admin_msg(lang('m-101'));
     }
     // 站点选择
     $site = (int) $_GET['site'];
     $site = $site ? $site : SITE_ID;
     // 模块缓存判断
     $module = $this->get_cache('module-' . $site . '-' . $dirname);
     if (!$module) {
         $this->admin_msg(dr_lang('m-102', $dirname));
     }
     // 加载后台用到的语言包
     $this->lang->load('admin');
     $this->lang->load('template');
     $db = $this->site[$site];
     $field = $module['field'];
     $category = $module['category'];
     $field['id'] = array('name' => 'Id', 'ismain' => 1, 'fieldtype' => 'Text', 'fieldname' => 'id');
     if ($this->member['adminid']) {
         $field['author'] = array('name' => lang('101'), 'ismain' => 1, 'fieldtype' => 'Text', 'fieldname' => 'author');
     } else {
         $db->where('uid', $this->uid);
     }
     if (IS_POST) {
         $data = $this->input->post('data');
         $catid = (int) $this->input->post('catid');
         if ($catid) {
             $db->where_in('catid', $category[$catid]['catids']);
         }
         if (isset($data['keyword']) && $data['keyword'] && $data['field'] && isset($field[$data['field']])) {
             if ($data['field'] == 'id') {
                 // id搜索
                 $id = array();
                 $ids = explode(',', $data['keyword']);
                 foreach ($ids as $i) {
                     $id[] = (int) $i;
                 }
                 $db->where_in('id', $id);
             } elseif ($field[$data['field']]['fieldtype'] == 'Linkage' && $field[$data['field']]['setting']['option']['linkage']) {
                 // 联动菜单搜索
                 if (is_numeric($data['keyword'])) {
                     // 联动菜单id查询
                     $link = dr_linkage($field[$data['field']]['setting']['option']['linkage'], (int) $data['keyword'], 0, 'childids');
                     if ($link) {
                         $db->where($data['field'] . ' IN (' . $link . ')');
                     }
                 } else {
                     // 联动菜单名称查询
                     $id = (int) $this->get_cache('linkid-' . SITE_ID, $field[$data['field']]['setting']['option']['linkage']);
                     if ($id) {
                         $db->where($data['field'] . ' IN (select id from `' . $db->dbprefix('linkage_data_' . $id) . '` where `name` like "%' . $data['keyword'] . '%")');
                     }
                 }
             } else {
                 // 其他模糊搜索
                 $db->like($data['field'], urldecode($data['keyword']));
             }
         }
     }
     // 搜索结果显示条数
     $limit = (int) $_GET['limit'];
     $limit = $limit ? $limit : 50;
     sort($field);
     $list = $db->limit($limit)->order_by('updatetime DESC')->select('id,title,updatetime,url')->get($site . '_' . $dirname)->result_array();
     // 栏目选择
     $tree = array();
     $select = '<select name="catid">';
     $select .= "<option value='0'> -- </option>";
     if (is_array($category)) {
         foreach ($category as $t) {
             $t['selected'] = $catid == $t['id'] ? 'selected' : '';
             $t['html_disabled'] = 0;
             unset($t['permission'], $t['setting'], $t['catids'], $t['url']);
             $tree[$t['id']] = $t;
         }
     }
     $str = "<option value='\$id' \$selected>\$spacer \$name</option>";
     $str2 = "<optgroup label='\$spacer \$name'></optgroup>";
     $this->load->library('dtree');
     $this->dtree->init($tree);
     $select .= $this->dtree->get_tree_category(0, $str, $str2);
     $select .= '</select>';
     $this->template->assign(array('list' => $list, 'param' => $data, 'field' => $field, 'select' => $select));
     $this->template->display('related.html', 'admin');
 }
コード例 #6
0
 private function _where($table, $name, $value, $field)
 {
     if (strpos($value, '%') === 0 && strrchr($value, '%') === '%') {
         // like 条件
         return '`' . $table . '`.`' . $name . '` LIKE "' . $this->db->escape_str($value) . '"';
     } elseif (preg_match('/[0-9]+,[0-9]+/', $value)) {
         // BETWEEN 条件
         list($s, $e) = explode(',', $value);
         return '`' . $table . '`.`' . $name . '` BETWEEN ' . (int) $s . ' AND ' . intval($e ? $e : SYS_TIME);
     } elseif (isset($field['fieldtype']) && $field['fieldtype'] == 'Linkage') {
         // 联动菜单
         $data = dr_linkage($field['setting']['option']['linkage'], $value);
         if ($data) {
             if ($data['child']) {
                 return '`' . $table . '`.`' . $name . '` IN (' . $data['childids'] . ')';
             } else {
                 return '`' . $table . '`.`' . $name . '`=' . intval($data['ii']);
             }
         }
     } elseif (is_numeric($value)) {
         return '`' . $table . '`.`' . $name . '`=' . $value;
     } else {
         return '`' . $table . '`.`' . $name . '`="' . $this->db->escape_str($value) . '"';
     }
 }
コード例 #7
0
 public function _set_where_field_prefix($where, $field, $prefix, $myfield = array())
 {
     if ($where) {
         foreach ($where as $i => $t) {
             if (isset($field[$t['name']])) {
                 $where[$i]['use'] = 1;
                 $where[$i]['name'] = "`{$prefix}`.`{$t['name']}`";
                 if ($myfield && $myfield[$t['name']]['fieldtype'] == 'Linkage') {
                     // 联动菜单
                     $data = dr_linkage($myfield[$t['name']]['setting']['option']['linkage'], $t['value']);
                     if ($data) {
                         if ($data['child']) {
                             $where[$i]['adj'] = 'IN';
                             $where[$i]['value'] = $data['childids'];
                         } else {
                             $where[$i]['value'] = intval($data['ii']);
                         }
                     }
                 }
             } else {
                 $where[$i]['use'] = $t['use'] ? 1 : 0;
             }
         }
     }
     return $where;
 }