public function access() { $uid = (int) $this->input->get('uid'); if ($this->_space_show($uid)) { $this->member_msg(lang('m-207')); } else { redirect(dr_space_url($uid), 'refresh'); } }
/** * 会员空间页 */ private function _space($uid, $is_domain = 0) { if (!MEMBER_OPEN_SPACE) { $this->member_msg(lang('m-111')); } define('IS_SPACE', $uid); $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/space/default/'); $this->member_msg(lang('m-234')); } if (!$space['status']) { $this->member_msg(lang('m-235')); } // 判断是否是自定义域名 if (!$is_domain && $this->_space_show($uid)) { redirect(dr_member_url('api/access', array('uid' => $uid)), 'refresh'); exit; } // 格式化空间信息 $space = $this->field_format_value($this->get_cache('member', 'spacefield'), $space, 1); $style = $space['style'] ? $space['style'] : 'default'; $theme = MEMBER_URL . 'templates/space/' . $style . '/'; $member = $this->member_model->get_member($uid); // 会员组使用权限判断 if (!$member['allowspace']) { $this->member_msg(lang('m-364')); } $action = str_replace(array('\\', '/', '..', '<', '>'), '', $this->input->get('action', TRUE)); $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)->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)->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(SITE_SEOJOIN, array_reverse($temp)); $this->template->assign(array('meta_title' => ($data['content_title'] ? $data['content_title'] . SITE_SEOJOIN : '') . $data['title'] . SITE_SEOJOIN . $catstr . SITE_SEOJOIN . $space['name'], 'meta_keywords' => $data['keywords'], 'meta_description' => dr_strcut(dr_clearhtml($data['content']), 200, ''))); break; case 'sns': // sns部分 $template = $this->_sns($space); 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', $uid)->update('space', array('hits' => $space['hits'] + 1)); // 空间地址 $space['url'] = dr_space_url($uid); // 会员姓名 $space['mname'] = $space['cname'] = $member['name']; // 我收藏的 $favorite = array(); if ($this->uid) { $temp = $this->db->where('uid', $this->uid)->get('sns_feed_favorite')->result_array(); if ($temp) { foreach ($temp as $t) { $favorite[] = $t['fid']; } unset($temp); } } $this->template->assign(array('uid' => $uid, 'style' => $style, 'theme' => $theme, 'space' => $space + $member, 'spaceid' => $uid, 'tableid' => (int) substr((string) $uid, -1, 1), 'selected' => $selected, 'category' => $category, 'favorite' => $favorite, 'space_count' => array('feed' => $this->db->where('uid', $uid)->count_all_results('sns_feed'), 'fans' => $this->db->where('uid', $uid)->count_all_results('sns_follow'), 'follow' => $this->db->where('fid', $uid)->count_all_results('sns_follow')))); $this->template->space($style); $this->template->display($template); exit; }
/** * OAuth绑定 */ public function bang() { $appid = dr_safe_replace($this->input->get('id')); $oauth = (require FCPATH . 'config/oauth.php'); $config = $oauth[$appid]; if (!$config) { $this->msg(lang('m-047')); } $config['url'] = SITE_URL . 'member/index.php?c=account&m=bang&id=' . $appid; // 回调地址设置 $this->load->library('OAuth2'); // OAuth $code = $this->input->get('code', TRUE); $oauth = $this->oauth2->provider($appid, $config); if (!$code) { // 登录授权页 try { $oauth->authorize(); } catch (OAuth2_Exception $e) { $this->msg(lang('m-048') . ' - ' . $e); } } else { // 回调返回数据 try { $user = $oauth->get_user_info($oauth->access($code)); if (is_array($user) && $user['oid']) { if ($uid = $this->member_model->OAuth_bang($appid, $user)) { $this->msg(dr_lang('m-049', dr_space_url($uid))); } else { // 绑定积分处理 if (!$this->db->where('uid', $this->uid)->where('type', 0)->where('mark', 'bang_' . $appid)->count_all_results('member_scorelog_' . $this->member['tableid'])) { $this->member_model->update_score(0, $this->uid, (int) $this->member_rule['bang_experience'], 'bang_' . $appid, 'lang,m-059'); } // 绑定虚拟币处理 if (!$this->db->where('uid', $this->uid)->where('type', 1)->where('mark', 'bang_' . $appid)->count_all_results('member_scorelog_' . $this->member['tableid'])) { $this->member_model->update_score(1, $this->uid, (int) $this->member_rule['bang_score'], 'bang_' . $appid, 'lang,m-059'); } $this->msg(lang('m-050'), dr_url('account/oauth'), 1, 3); } } else { $this->msg(lang('m-051')); } } catch (OAuth2_Exception $e) { $this->msg(lang('m-051') . ' - ' . $e); } } }