Ejemplo n.º 1
0
 /**
  * 模块扩展内容页
  */
 protected function _extend($id = NULL, $return = FALSE)
 {
     // 缓存查询结果
     $name = (SITE_MOBILE === TRUE ? 'm' : '') . 'extend' . $this->dir . SITE_ID . $id;
     $data = $this->get_cache_data($name);
     if (!$data) {
         $mod = $this->get_cache('module-' . SITE_ID . '-' . $this->dir);
         if (!$mod) {
             if ($return) {
                 return NULL;
             }
             $this->msg(lang('m-148'));
         }
         $this->load->model('content_model');
         $data = $this->content_model->get_extend($id);
         if (!$data) {
             if ($return) {
                 return NULL;
             }
             $this->goto_404_page(dr_lang('mod-45', $id));
         }
         $content = $this->get_cache_data('show' . $this->dir . SITE_ID . $data['cid']);
         if (!$content) {
             $content = $this->get_cache_data('extend-show' . $this->dir . SITE_ID . $data['cid']);
         }
         if (!$content) {
             $content = $this->content_model->get($data['cid']);
             $this->set_cache_data('extend-show' . $this->dir . SITE_ID . $data['cid'], $content, $mod['setting']['show_cache']);
         }
         if (!$content) {
             if ($return) {
                 return NULL;
             }
             $this->goto_404_page(dr_lang('mod-30', $data['cid']));
         }
         $data = $data + $content;
         $data['curl'] = $content['url'];
         // 检测转向字段
         $redirect = 0;
         foreach ($mod['extend'] as $t) {
             if ($t['fieldtype'] == 'Redirect' && $data[$t['fieldname']]) {
                 if (MODULE_HTML) {
                     $redirect = 1;
                     $data['goto_url'] = $data[$t['fieldname']];
                     break;
                 } else {
                     redirect($data[$t['fieldname']], 'location', 301);
                     exit;
                 }
             }
         }
         $cat = $mod['category'][$data['catid']];
         // 上一篇
         $data['prev_page'] = $this->link->where('cid', (int) $data['cid'])->where('id<', $id)->order_by('displayorder desc,id desc')->limit(1)->get($this->content_model->prefix . '_extend')->row_array();
         // 下一篇
         $data['next_page'] = $this->link->where('cid', (int) $data['cid'])->where('id>', $id)->order_by('displayorder desc,id asc')->limit(1)->get($this->content_model->prefix . '_extend')->row_array();
         // 缓存数据
         if ($data['uid'] != $this->uid) {
             $data = $this->set_cache_data($name, $data, $mod['setting']['show_cache']);
         }
     } else {
         $mod = $this->get_cache('module-' . SITE_ID . '-' . $this->dir);
         $cat = $mod['category'][$data['catid']];
     }
     // 拒绝访问判断
     if ($cat['permission'][$this->markrule]['show']) {
         $this->msg(lang('m-338'));
     }
     // 格式化输出自定义字段
     $fields = $mod['field'];
     $fields = $cat['field'] ? array_merge($fields, $cat['field']) : $fields;
     $fields = $fields + $mod['extend'];
     $fields['inputtime'] = array('fieldtype' => 'Date');
     $data = $this->field_format_value($fields, $data, 1);
     // 栏目下级或者同级栏目
     list($parent, $related) = $this->_related_cat($mod, $data['catid']);
     $this->template->assign($data);
     $this->template->assign(dr_extend_seo($mod, $data));
     $this->template->assign(array('cat' => $cat, 'params' => array('catid' => $data['catid']), 'parent' => $parent, 'related' => $related, 'urlrule' => $this->mobile ? dr_mobile_extend_url($this->dir, $id, '{page}') : dr_extend_url($mod, $data, '{page}')));
     $tpl = $cat['setting']['template']['extend'];
     $tpl = $tpl ? $tpl : 'extend.html';
     if (!$return) {
         $this->template->display($tpl);
     }
     // 存在转向字段时处理方式
     return array($data, $redirect ? 'go' : $tpl);
 }
Ejemplo n.º 2
0
 public function edit_extend($_data, $data)
 {
     // 参数判断
     if (!$data || !$_data) {
         return FALSE;
     }
     // 修改之前挂钩点
     $data['edit'] = $_data;
     $this->hooks->call_hook('extend_edit_before', $data);
     unset($data['edit']);
     // 被退回处理
     if (isset($data[1]['back']) && $this->admin) {
         $backinfo = array('uid' => $this->uid, 'author' => $this->admin['username'], 'rolename' => $this->admin['role']['name'], 'optiontime' => SYS_TIME, 'backcontent' => $data[1]['back']);
         unset($data[1]['back']);
     }
     // 格式化字段值
     $data = $this->get_content_extend_data($data, $_data);
     // 生成url地址
     $data[1]['url'] = dr_extend_url($this->ci->get_cache('MODULE-' . SITE_ID . '-' . $this->mdir), array_merge($_data, $data[1]));
     // 更新索引表
     $this->link->where('id', $_data['id'])->update($this->prefix . '_extend_index', array('uid' => $data[1]['uid'], 'catid' => $data[1]['catid'], 'status' => $data[1]['status']));
     if ($data[1]['status'] == 9) {
         // 提交为审核通过状态
         $data[1]['id'] = $data[0]['id'] = $_data['id'];
         $data[0]['uid'] = $data[1]['uid'];
         $data[0]['cid'] = $data[1]['cid'];
         $data[0]['catid'] = $data[1]['catid'];
         // 副表以5w左右数据量无限分表
         $data[1]['tableid'] = $_data['tableid'] ? $_data['tableid'] : floor($_data['id'] / 50000);
         if (!$this->link->query("SHOW TABLES LIKE '" . $this->prefix . '_extend_data_' . $data[1]['tableid'] . "'")->row_array()) {
             // 附表不存在时创建附表
             $sql = $this->link->query("SHOW CREATE TABLE `{$this->prefix}_extend_data_0`")->row_array();
             $this->link->query(str_replace(array($sql['Table'], 'CREATE TABLE '), array($this->prefix . '_extend_data_' . $data[1]['tableid'], 'CREATE TABLE IF NOT EXISTS '), $sql['Create Table']));
         }
         // 主表更新
         if ($this->link->where('id', $_data['id'])->count_all_results($this->prefix . '_extend')) {
             $this->link->where('id', $_data['id'])->update($this->prefix . '_extend', $data[1]);
         } else {
             $this->link->replace($this->prefix . '_extend', $data[1]);
         }
         // 副表
         $this->link->replace($this->prefix . '_extend_data_' . $data[1]['tableid'], $data[0]);
         // 审核表
         if ($_data['status'] < 9) {
             $this->link->where('id', $_data['id'])->delete($this->prefix . '_extend_verify');
         }
         // 更新内容表时间
         $this->link->where('id', $data[1]['cid'])->update($this->prefix, array('updatetime' => SYS_TIME));
     } else {
         // 检查合并审核数据
         $content = $data[0] ? array_merge($data[0], $data[1]) : $data[1];
         if (!$content) {
             return FALSE;
         }
         $content['title'] = $this->content['title'];
         // 更新主表
         $this->link->where('id', (int) $_data['id'])->update($this->prefix . '_extend', array('status' => $data[1]['status']));
         // 更新审核表
         $this->link->replace($this->prefix . '_extend_verify', array('id' => $_data['id'], 'uid' => $data[1]['uid'], 'cid' => $data[1]['cid'], 'catid' => $data[1]['catid'], 'author' => $data[1]['author'], 'status' => $data[1]['status'], 'content' => dr_array2string($content), 'backuid' => (int) $this->uid, 'backinfo' => $this->admin ? dr_array2string($backinfo) : '', 'inputtime' => SYS_TIME));
     }
     $this->ci->clear_cache((SITE_MOBILE === TRUE ? 'm' : '') . 'extend' . $this->mdir . SITE_ID . $id);
     // 修改之后挂钩点
     $data['edit'] = $_data;
     $this->hooks->call_hook('extend_edit_after', $data);
     // 修改之后执行的方法
     $this->_edit_extend($data);
     return $_data['id'];
 }
 /**
  * 更新URL
  */
 public function url()
 {
     $cfile = SITE_ID . APP_DIR . $this->uid . $this->input->ip_address() . '_content_url';
     if (IS_POST) {
         $catid = $this->input->post('catid');
         $query = $this->link;
         if (count($catid) > 1 || $catid[0]) {
             $query->where_in('catid', $catid);
             if (count($this->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'category')) == count($catid)) {
                 $catid = 0;
             }
         } else {
             $catid = 0;
         }
         // 统计数量
         $total = $query->count_all_results($this->content_model->prefix . '_index');
         $this->cache->file->save($cfile, array('catid' => $catid, 'total' => $total), 10000);
         if ($total) {
             $this->system_log('站点【#' . SITE_ID . '】模块【' . APP_DIR . '】更新URL地址#' . $total);
             // 记录日志
             $this->mini_msg(dr_lang('132', $total), dr_url(APP_DIR . '/home/url', array('todo' => 1)), 2);
         } else {
             $this->mini_msg(lang('133'));
         }
     }
     // 处理url
     if ($this->input->get('todo')) {
         $page = max(1, (int) $this->input->get('page'));
         $psize = 100;
         // 每页处理的数量
         $cache = $this->cache->file->get($cfile);
         if ($cache) {
             $total = $cache['total'];
             $catid = $cache['catid'];
         } else {
             $catid = 0;
             $total = $this->link->count_all_results($this->content_model->prefix);
         }
         $tpage = ceil($total / $psize);
         // 总页数
         if ($page > $tpage) {
             // 更新完成删除缓存
             $this->cache->file->delete($cfile);
             $this->mini_msg(lang('360'), NULL, 1);
         }
         $module = $this->get_cache('module-' . SITE_ID . '-' . APP_DIR);
         $table = $this->content_model->prefix;
         if ($catid) {
             $this->link->where_in('catid', $catid);
         }
         $data = $this->link->limit($psize, $psize * ($page - 1))->order_by('id DESC')->get($table)->result_array();
         foreach ($data as $t) {
             $url = dr_show_url($module, $t);
             $this->link->update($table, array('url' => $url), 'id=' . $t['id']);
             if ($module['extend']) {
                 $extend = $this->link->where('cid', (int) $t['id'])->order_by('id DESC')->get($table . '_extend')->result_array();
                 if ($extend) {
                     foreach ($extend as $e) {
                         $this->link->where('id=', (int) $e['id'])->update($table . '_extend', array('url' => dr_extend_url($module, $e)));
                     }
                 }
             }
         }
         $this->mini_msg(dr_lang('135', "{$tpage}/{$page}"), dr_url(APP_DIR . '/home/url', array('todo' => 1, 'page' => $page + 1)), 2, 0);
     } else {
         $this->template->assign(array('menu' => $this->get_menu($this->_get_content_menu()), 'select' => $this->select_category($this->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'category'), 0, 'id="dr_synid" name=\'catid[]\' multiple style="width:200px;height:250px;"', '')));
         $this->template->display('content_url.html');
     }
 }
Ejemplo n.º 4
0
 /**
  * 更新URL
  */
 public function url()
 {
     $cfile = SITE_ID . APP_DIR . $this->uid . $this->input->ip_address() . '_content_url';
     if (IS_POST) {
         $catid = $this->input->post('catid');
         $query = $this->link;
         if (count($catid) > 1 || $catid[0]) {
             $query->where_in('catid', $catid);
         }
         $data = $query->select('id')->get($this->content_model->prefix . '_index')->result_array();
         if ($data) {
             $id = array();
             foreach ($data as $t) {
                 $id[] = $t['id'];
             }
             $this->cache->file->save($cfile, $id, 7200);
             // 缓存搜索结果->id
             $this->mini_msg(dr_lang('132', count($id)), dr_url(APP_DIR . '/home/url', array('todo' => 1)), 2);
         } else {
             $this->mini_msg(lang('133'));
         }
     }
     if ($this->input->get('todo')) {
         $id = $this->cache->file->get($cfile);
         // 取缓存搜索结果->id
         if (!$id) {
             $this->mini_msg(lang('134'));
         }
         $page = max(1, (int) $this->input->get('page'));
         $psize = 50;
         $total = count($id);
         $tpage = ceil($total / $psize);
         // 总页数
         if ($page > $tpage) {
             // 更新完成删除缓存
             $this->cache->file->delete($cfile);
             $this->mini_msg(lang('360'), NULL, 1);
         }
         $module = $this->get_cache('module-' . SITE_ID . '-' . APP_DIR);
         $table = $this->content_model->prefix;
         $data = $this->link->where_in('id', $id)->limit($psize, $psize * ($page - 1))->order_by('id DESC')->get($table)->result_array();
         foreach ($data as $t) {
             $url = dr_show_url($module, $t);
             $this->link->update($table, array('url' => $url), 'id=' . $t['id']);
             if ($module['extend']) {
                 $extend = $this->link->where('cid', $t['id'])->order_by('id DESC')->get($table . '_extend')->result_array();
                 if ($extend) {
                     foreach ($extend as $e) {
                         $url = dr_extend_url($module, $e);
                         $this->link->update($table . '_extend', array('url' => $url), 'id=' . (int) $e['id']);
                     }
                 }
             }
         }
         $this->mini_msg(dr_lang('135', "{$tpage}/{$page}"), dr_url(APP_DIR . '/home/url', array('todo' => 1, 'page' => $page + 1)), 2, 0);
     } else {
         $this->template->assign(array('menu' => $this->get_menu(array(lang('136') => APP_DIR . '/admin/home/url', lang('001') => 'admin/module/cache')), 'select' => $this->select_category($this->get_cache('module-' . SITE_ID . '-' . APP_DIR, 'category'), 0, 'id="dr_synid" name=\'catid[]\' multiple style="width:200px;height:250px;"', '')));
         $this->template->display('content_url.html');
     }
 }