/** * 会员空间页 */ private function _space($uid) { if (!MEMBER_OPEN_SPACE) { $this->member_msg(lang('m-111')); } $this->load->model('space_model'); $this->load->model('space_category_model'); $space = $this->space_model->get($uid); if (!$space) { $this->template->assign('theme', MEMBER_PATH . 'templates/default/'); $this->member_msg(lang('m-234')); } if (!$space['status']) { $this->member_msg(lang('m-235')); } $space = $this->field_format_value($this->get_cache('member', 'spacefield'), $space, 1); $style = $space['style'] ? $space['style'] : 'default'; $theme = MEMBER_URL . 'templates/' . $style . '/'; $action = $this->input->get('action'); $member = $this->member_model->get_member($uid); $selected = 0; // 默认选中首页菜单 $category = $this->space_category_model->get_data(0, $uid, 1); switch ($action) { case 'category': // 栏目处理 $id = (int) $this->input->get('id'); $cat = $category[$id]; if (!$cat) { $this->msg(lang('m-315')); } switch ($cat['type']) { case 0: // 外链 if (!$cat['link']) { $this->msg(lang('m-316')); } redirect($cat['link'], 'location', 301); return NULL; break; case 1: // 模型 $model = $this->get_cache('space-model', $cat['modelid']); if (!$model) { $this->msg(lang('m-317')); } $template = 'list_' . $model['table'] . '.html'; // 选中顶级栏目 $temp = explode(',', $cat['pids']); $selected = $temp[1] ? $temp[1] : $id; break; case 2: // 单页 $template = 'page.html'; // 选中顶级栏目 $temp = explode(',', $cat['pids']); $selected = $temp[1] ? $temp[1] : $id; // 单页验证是否存在子栏目 if ($cat['child']) { $temp = explode(',', $cat['childids']); if (isset($temp[1]) && $category[$temp[1]]) { $id = $temp[1]; $cat = $category[$id]; } } break; } // 栏目下级或者同级栏目 $related = $parent = array(); if ($cat['pid']) { foreach ($category as $t) { if ($t['pid'] == $cat['pid']) { $related[] = $t; if ($cat['child']) { $parent = $cat; } else { $parent = $category[$t['pid']]; } } } } elseif ($cat['child']) { $parent = $cat; foreach ($category as $t) { if ($t['pid'] == $cat['id']) { $related[] = $t; } } } $this->template->assign(array('cat' => $cat, 'catid' => $id, 'parent' => $parent, 'related' => $related, 'modelid' => $cat['modelid'], 'urlrule' => dr_space_list_url($uid, $id, TRUE))); if ($cat['title']) { $title = $cat['title']; } else { $title = implode('-', array_reverse(explode('{-}', dr_space_catpos($uid, $id, '{-}', FALSE)))) . '-' . $space['name']; } $this->template->assign(array('meta_title' => $title, 'meta_keywords' => $cat['keywords'], 'meta_description' => $cat['description'])); break; case 'show': // 内容处理 $id = (int) $this->input->get('id'); $mid = (int) $this->input->get('mid'); $mod = $this->get_cache('space-model', $mid); if (!$mod) { $this->msg(lang('m-317')); } $name = $this->db->dbprefix('space_' . $mod['table']) . '-space-show-' . $id; $data = $this->get_cache_data($name); if (!$data) { $this->load->model('space_content_model'); $this->space_content_model->tablename = $this->db->dbprefix('space_' . $mod['table']); $data = $this->space_content_model->get($uid, $id); if (!$data) { $this->msg(lang('m-303')); } if (!$data['status'] && $data['uid'] != $this->uid) { $this->msg(lang('m-318')); } $cat = $category[$data['catid']]; if (!$cat) { $this->msg(lang('m-315')); } // 检测转向字段 foreach ($mod['field'] as $t) { if ($t['fieldtype'] == 'Redirect' && $data[$t['fieldname']]) { redirect($data[$t['fieldname']], 'location', 301); exit; } } // 上一篇文章 $data['prev_page'] = $this->db->where('catid', $data['catid'])->where('id<', $id)->where('status', 1)->select('title,id,updatetime')->order_by('id desc')->limit(1)->get($this->space_content_model->tablename)->row_array(); // 下一篇文章 $data['next_page'] = $this->db->where('catid', $data['catid'])->where('id>', $id)->where('status', 1)->select('title,id,updatetime')->order_by('id asc')->limit(1)->get($this->space_content_model->tablename)->row_array(); $this->set_cache_data($name, $data, 360000); } else { $cat = $category[$data['catid']]; if (!$cat) { $this->msg(lang('m-315')); } } // 格式化输出自定义字段 $fields = $mod['field']; $fields['inputtime'] = array('fieldtype' => 'Date'); $fields['updatetime'] = array('fieldtype' => 'Date'); $data = $this->field_format_value($fields, $data, max(1, (int) $this->input->get('page'))); // 栏目下级或者同级栏目 $related = $parent = array(); if ($cat['pid']) { foreach ($category as $t) { if ($t['pid'] == $cat['pid']) { $related[] = $t; if ($cat['child']) { $parent = $cat; } else { $parent = $category[$t['pid']]; } } } } elseif ($cat['child']) { $parent = $cat; foreach ($category as $t) { if ($t['pid'] == $cat['id']) { $related[] = $t; } } } $template = 'show_' . $mod['table'] . '.html'; // 选中顶级栏目 $temp = explode(',', $cat['pids']); $selected = $temp[1] ? $temp[1] : $cat['id']; $this->template->assign($data); $this->template->assign(array('cat' => $cat, 'catid' => $cat['id'], 'parent' => $parent, 'related' => $related, 'modelid' => $cat['modelid'])); $temp = dr_space_catpos($uid, $cat['id'], '{-}', FALSE); $temp = explode('{-}', $temp); $catstr = implode('-', array_reverse($temp)); $this->template->assign(array('meta_title' => ($data['content_title'] ? $data['content_title'] . '-' : '') . $data['title'] . '-' . $catstr . '-' . $space['name'], 'meta_keywords' => $data['keywords'], 'meta_description' => dr_strcut(dr_clearhtml($data['content']), 200, ''))); break; default: // 首页或者其他自定义页面 $template = $action ? $action . '.html' : 'index.html'; $this->template->assign(array('meta_title' => $space['title'] ? $space['title'] : $space['name'], 'meta_keywords' => $space['keywords'], 'meta_description' => $space['description'])); break; } // 更新访问量pv $this->db->where('uid', (int) $uid)->update('space', array('hits' => $space['hits'] + 1)); $space['mname'] = $member['name']; $this->template->assign(array('theme' => $theme, 'space' => $space + $member, 'spaceid' => $uid, 'tableid' => (int) substr((string) $uid, -1, 1), 'selected' => $selected, 'category' => $category)); $this->template->space($style); $this->template->display($template); }
/** * 会员空间模型栏目面包屑导航 * * @param intval $uid 会员id * @param intval $catid 栏目id * @param string $symbol 面包屑间隔符号 * @param string $url 是否显示URL * @return string */ function dr_space_catpos($uid, $catid, $symbol = ' > ', $url = TRUE) { if (!$uid || !$catid) { return NULL; } $ci =& get_instance(); $ci->load->model('space_category_model'); $cat = $ci->space_category_model->get_data(0, $uid, 1); if (!isset($cat[$catid])) { return NULL; } $name = array(); $array = explode(',', $cat[$catid]['pids']); foreach ($array as $id) { if ($id && $cat[$id]) { $name[] = $url ? "<a href=\"" . dr_space_list_url($uid, $id) . "\">{$cat[$id]['name']}</a>" : $cat[$id]['name']; } } $name[] = $url ? "<a href=\"" . dr_space_list_url($uid, $catid) . "\">{$cat[$catid]['name']}</a>" : $cat[$catid]['name']; return implode($symbol, $name); }
/** * 首页 */ public function index() { $is_edit = $this->get_cache('member', 'setting', 'space', 'category') ? 0 : 1; if (IS_POST) { $ids = $this->input->post('ids', TRUE); if ($this->input->post('action') == 'order') { if (!$ids) { exit(dr_json(0, lang('013'))); } $data = $this->input->post('data'); foreach ($ids as $id) { $this->db->where('id', (int) $id)->where('uid', (int) $this->uid)->update($this->space_category_model->tablename, $data[$id]); } exit(dr_json(1, lang('000'))); } elseif ($this->input->post('action') == 'del' && $is_edit) { if (!$ids) { exit(dr_json(0, lang('013'))); } $this->space_category_model->del($ids); exit(dr_json(1, lang('000'))); } } $this->load->library('dtree'); $this->dtree->icon = array(' │ ', ' ├─ ', ' └─ '); $this->dtree->nbsp = ' '; $tree = array(); $this->space_category_model->repair($this->uid); $data = $this->space_category_model->get_data(0, 0, 1); if ($data) { foreach ($data as $t) { switch ($t['showid']) { case 0: $t['show'] = lang('m-293'); break; case 1: $t['show'] = lang('m-294'); break; case 2: $t['show'] = lang('m-295'); break; case 3: $t['show'] = lang('m-296'); break; } switch ($t['type']) { case 0: $t['model'] = lang('m-313'); break; case 1: $t['model'] = $this->get_cache('space-model', $t['modelid'], 'name'); break; case 2: $t['model'] = lang('m-314'); break; } $t['option'] = '<a href="' . dr_space_list_url($this->uid, $t['id']) . '" target="_blank">' . lang('m-345') . '</a>'; $t['add'] = $t['type'] ? " <a href='" . dr_member_url('category/add') . "&pid=" . $t['id'] . "&type=" . $t['type'] . "&mid=" . $t['modelid'] . "'>[ " . lang('m-298') . " ]</a>" : ''; $t['add'] = $is_edit ? $t['add'] : ''; $tree[$t['id']] = $t; } } $str = "<tr class='' style='height:35px;'>"; $str .= "<td align='right'><input name='ids[]' type='checkbox' class='dr_select' value='\$id' /></td>"; $str .= "<td align='center'><input class='input-text displayorder' type='text' name='data[\$id][displayorder]' value='\$displayorder' /></td>"; $str .= "<td class='ajax'>\$spacer<a href='" . dr_member_url('category/edit') . "&id=\$id'>\$name</a> \$add</td>"; $str .= "<td align='center'>\$model</td>"; $str .= "<td align='center'>\$show</td>"; $str .= "<td align='center'>\$option</td>"; $str .= "</tr>"; $this->dtree->init($tree); $this->template->assign(array('list' => $this->dtree->get_tree(0, $str), 'page' => (int) $this->input->get('page'), 'is_edit' => $is_edit)); $this->template->display('category_index.html'); }