/** * 检查用户是否有对应权限 * @param type $map 方法[模块/控制器/方法],为空自动获取 * @return type */ public function isCompetence($map = '') { //超级管理员 if (\Admin\Service\User::getInstance()->isAdministrator()) { return true; } if (!is_array($map)) { //子角色列表 $child = explode(',', D("Admin/Role")->getArrchildid(\Admin\Service\User::getInstance()->role_id)); if (!empty($map)) { $map = trim($map, '/'); $map = explode('/', $map); if (empty($map)) { return false; } } else { $map = array(MODULE_NAME, CONTROLLER_NAME, ACTION_NAME); } if (count($map) >= 3) { list($app, $controller, $action) = $map; } elseif (count($map) == 1) { $app = MODULE_NAME; $controller = CONTROLLER_NAME; $action = $map[0]; } elseif (count($map) == 2) { $app = MODULE_NAME; list($controller, $action) = $map; } $map = array('role_id' => array('IN', $child), 'app' => $app, 'controller' => $controller, 'action' => $action); } $count = $this->where($map)->count(); return $count ? true : false; }
public function index() { if (IS_AJAX) { $this->ajaxReturn(array('status' => 1)); return true; } $this->assign("SUBMENU_CONFIG", json_encode(D("Admin/Menu")->getMenuList())); $this->assign('userInfo', User::getInstance()->getInfo()); $this->assign('role_name', D('Admin/Role')->getRoleIdName(User::getInstance()->role_id)); $this->display(); }
public function public_verifypass() { $password = I("get.password"); if (empty($password)) { $this->error("密码不能为空!"); } //验证密码 $user = D('Admin/User')->getUserInfo((int) User::getInstance()->id, $password); if (!empty($user)) { $this->success("密码正确!"); } else { $this->error("密码错误!"); } }
/** * 记录日志 * @param type $message 说明 */ public function record($message, $status = 0) { $fangs = 'GET'; if (IS_AJAX) { $fangs = 'Ajax'; } else { if (IS_POST) { $fangs = 'POST'; } } $data = array('uid' => \Admin\Service\User::getInstance()->id ?: 0, 'status' => $status, 'info' => "提示语:{$message}<br/>模块:" . MODULE_NAME . ",控制器:" . CONTROLLER_NAME . ",方法:" . ACTION_NAME . "<br/>请求方式:{$fangs}", 'get' => $_SERVER['HTTP_REFERER']); $this->create($data); return $this->add() !== false ? true : false; }
protected function _initialize() { //检查是否后台登录,后台登录下优先级最高,用于权限判断 if (\Admin\Service\User::getInstance()->id) { define('IN_ADMIN', true); $this->isadmin = 1; $this->upname = \Admin\Service\User::getInstance()->username; $this->upuserid = \Admin\Service\User::getInstance()->id; } else { $this->upname = service('Passport')->username; $this->upuserid = service('Passport')->userid; $this->groupid = service('Passport')->groupid ? service('Passport')->groupid : 8; } parent::_initialize(); }
public function delete() { $id = I('get.id'); if (empty($id)) { $this->error("没有指定删除对象!"); } if ((int) $id == User::getInstance()->id) { $this->error("你不能删除你自己!"); } //执行删除 if (D('Admin/User')->deleteUser($id)) { $this->success("删除成功!"); } else { $this->error(D('Admin/User')->getError() ?: '删除失败!'); } }
/** * 按父ID查找菜单子项 * @param integer $parentid 父菜单ID * @param integer $with_self 是否包括他自己 */ public function adminMenu($parentid, $with_self = false) { //父节点ID $parentid = (int) $parentid; $result = $this->where(array('parentid' => $parentid, 'status' => 1))->order('listorder ASC,id ASC')->select(); if (empty($result)) { $result = array(); } if ($with_self) { $parentInfo = $this->where(array('id' => $parentid))->find(); $result2[] = $parentInfo ? $parentInfo : array(); $result = array_merge($result2, $result); } //是否超级管理员 if (\Admin\Service\User::getInstance()->isAdministrator()) { //如果角色为 1 直接通过 return $result; } $array = array(); //子角色列表 $child = explode(',', D("Admin/Role")->getArrchildid(\Admin\Service\User::getInstance()->role_id)); foreach ($result as $v) { //方法 $action = $v['action']; //条件 $where = array('app' => $v['app'], 'controller' => $v['controller'], 'action' => $action, 'role_id' => array('IN', $child)); //如果是菜单项 if ($v['type'] == 0) { $where['controller'] .= $v['id']; $where['action'] .= $v['id']; } //public开头的通过 if (preg_match('/^public_/', $action)) { $array[] = $v; } else { if (preg_match('/^ajax_([a-z]+)_/', $action, $_match)) { $action = $_match[1]; } //是否有权限 if (D('Admin/Access')->isCompetence($where)) { $array[] = $v; } } } return $array; }
/** * 验证登录 * @return boolean */ private function competence() { //检查是否登录 $uid = (int) User::getInstance()->isLogin(); if (empty($uid)) { return false; } //获取当前登录用户信息 $userInfo = User::getInstance()->getInfo(); if (empty($userInfo)) { User::getInstance()->logout(); return false; } //是否锁定 if (!$userInfo['status']) { User::getInstance()->logout(); $this->error('您的帐号已经被锁定!', U('Public/login')); return false; } return $userInfo; }
public function update_show() { if (isset($_POST['dosubmit'])) { extract($_POST, EXTR_SKIP); //模型ID $modelid = intval($_POST['modelid']); if ($modelid) { $model = ContentModel::getInstance($modelid); //更新最新发布的X条信息 if ($type == 'lastinput') { $offset = 0; } else { $page = max(intval($page), 1); $offset = $pagesize * ($page - 1); } $where = array(); $order = 'ASC'; //设置状态 $where["status"] = array("EQ", 99); if (!isset($first) && is_array($catids) && $catids[0] > 0) { //把选择需要生成的栏目id写入缓存 F("html_show_" . \Admin\Service\User::getInstance()->id, $catids); $catids = implode(',', $catids); $where['catid'] = array("IN", $catids); $first = 1; } elseif (count($catids) == 1 && $catids[0] == 0) { //不限制栏目 $catids = array(); foreach ($this->categorys as $catid => $cat) { $cat = getCategory($cat['catid']); if ($cat['child'] || $cat['type'] != 0) { continue; } $setting = $cat['setting']; if (!$setting['content_ishtml']) { continue; } $catids[] = $catid; } //把选择需要生成的栏目id写入缓存 F("html_show_" . \Admin\Service\User::getInstance()->id, $catids); $catids = implode(',', $catids); $where['catid'] = array("IN", $catids); $first = 1; } elseif ($first) { //获取缓存 $catids = F("html_show_" . \Admin\Service\User::getInstance()->id); $catids = implode(',', $catids); $where['catid'] = array("IN", $catids); } else { $first = 0; } if (count($catids) == 1 && $catids[0] == 0) { $this->assign("waitSecond", 200); $this->success("更新完成...", U("Content/Createhtml/update_show")); exit; } //更新最新发布的 if ($type == 'lastinput' && $number) { $offset = 0; //获取更新最新发布的多少条 $pagesize = $number; $order = 'DESC'; } elseif ($type == 'date') { //以时间段更新 if ($fromdate) { $fromtime = strtotime($fromdate . ' 00:00:00'); $where["inputtime"] = array("EGT", $fromtime); } if ($fromdate && $todate) { $totime = strtotime($todate . ' 23:59:59'); $where["inputtime"] = array(array("EGT", $fromtime), array("ELT", $fromtime), 'and'); } } elseif ($type == 'id') { //以id段更新 //起始id $fromid = intval($fromid); //结束id $toid = intval($toid); if ($fromid) { $where["id"] = array("EGT", $fromid); } if ($fromid && $toid) { $where["id"] = array(array("EGT", $fromid), array("ELT", $toid), 'and'); } } if (!isset($total) && $type != 'lastinput') { //统计总数 $rs = $model->where($where)->count(); $total = $rs; $pages = ceil($total / $pagesize); $start = 1; } $data = $model->relation(true)->where($where)->order(array("id" => $order))->limit($offset . "," . $pagesize)->select(); foreach ($data as $r) { //转向地址信息无需生成 if ($r['islink']) { continue; } $model->dataMerger($r); $this->Html->show($r); } if ($pages > $page) { $page++; $http_url = __SELF__; $creatednum = $offset + count($data); $percent = round($creatednum / $total, 2) * 100; $message = "共需更新 <font color=\"red\">{$total}</font> 条信息 - 已完成 <font color=\"red\">{$creatednum}</font> 条(<font color=\"red\">{$percent}%</font>)"; $forward = $start ? U("Content/Createhtml/update_show", "type={$type}&dosubmit=1&first={$first}&fromid={$fromid}&toid={$toid}&fromdate={$fromdate}&todate={$todate}&pagesize={$pagesize}&page={$page}&pages={$pages}&total={$total}&modelid={$modelid}") : preg_replace("/&page=([0-9]+)&pages=([0-9]+)&total=([0-9]+)/", "&page={$page}&pages={$pages}&total={$total}", $http_url); $this->assign("waitSecond", 200); $this->success($message, $forward); } else { //删除缓存 F("html_show_" . \Admin\Service\User::getInstance()->id, NULL); $this->success("更新完成! ...", U("Content/Createhtml/update_show")); } } else { //当没有选择模型时,需要按照栏目来更新 if (!isset($set_catid)) { if ($catids[0] != 0) { $update_url_catids = $catids; } else { foreach ($this->categorys as $catid => $cat) { $cat = getCategory($cat['catid']); if ($cat['child'] || $cat['type'] != 0) { continue; } $setting = $cat['setting']; if (!$setting['content_ishtml']) { continue; } $update_url_catids[] = $catid; } } //生成需要更新生成的栏目ID缓存 F("update_html_catid" . \Admin\Service\User::getInstance()->id, $update_url_catids); $this->assign("waitSecond", 200); $this->success("开始更新 ...", U("Content/Createhtml/update_show", "set_catid=1&pagesize={$pagesize}&dosubmit=1")); exit; } if (count($catids) == 1 && $catids[0] == 0) { $this->success("更新完成! ...", U("Content/Createhtml/update_show")); exit; } $catid_arr = F("update_html_catid" . \Admin\Service\User::getInstance()->id); $autoid = $autoid ? intval($autoid) : 0; if (!isset($catid_arr[$autoid])) { $this->success("更新完成! ...", U("Content/Createhtml/update_show")); exit; } $catid = $catid_arr[$autoid]; $modelid = getCategory($catid, 'modelid'); $model = ContentModel::getInstance($modelid); $page = max(intval($page), 1); $offset = $pagesize * ($page - 1); $where = array(); $where['status'] = array("EQ", 99); $where['catid'] = array("EQ", $catid); $order = 'ASC'; if (!isset($total)) { //统计总数 $rs = $model->where($where)->count(); $total = $rs; $pages = ceil($total / $pagesize); $start = 1; } $data = $model->relation(true)->where($where)->order(array("id" => $order))->limit($offset . "," . $pagesize)->select(); foreach ($data as $r) { if ($r['islink']) { continue; } $model->dataMerger($r); $this->Html->show($r); } if ($pages > $page) { $page++; $http_url = __SELF__; $creatednum = $offset + count($data); $percent = round($creatednum / $total, 2) * 100; $message = "【" . getCategory($catid, 'catname') . "】 有 <font color=\"red\">{$total}</font> 条信息 - 已完成 <font color=\"red\">{$creatednum}</font> 条(<font color=\"red\">{$percent}%</font>)"; $forward = $start ? U("Content/Createhtml/update_show", "type={$type}&dosubmit=1&first={$first}&fromid={$fromid}&toid={$toid}&fromdate={$fromdate}&todate={$todate}&pagesize={$pagesize}&page={$page}&pages={$pages}&total={$total}&autoid={$autoid}&set_catid=1") : preg_replace("/&page=([0-9]+)&pages=([0-9]+)&total=([0-9]+)/", "&page={$page}&pages={$pages}&total={$total}", $http_url); $this->assign("waitSecond", 200); $this->success($message, $forward); } else { $autoid++; $forward = U("Content/Createhtml/update_show", "set_catid=1&pagesize={$pagesize}&dosubmit=1&autoid={$autoid}"); $this->assign("waitSecond", 200); $this->success("开始更新 .." . getCategory($catid, 'catname') . " ...", $forward); } } } else { $modelid = I('get.modelid', 0, 'intval'); $this->Tree->icon = array(' │ ', ' ├─ ', ' └─ '); $this->Tree->nbsp = ' '; $categorys = array(); if (!empty($this->categorys)) { foreach ($this->categorys as $catid => $r) { $r = getCategory($r['catid']); if ($r['type'] != 0 && $r['child'] == 0) { continue; } if ($modelid && $modelid != $r['modelid']) { continue; } if ($r['child'] == 0) { $setting = $r['setting']; if (!$setting['content_ishtml']) { continue; } } $r['disabled'] = $r['child'] ? 'disabled' : ''; $categorys[$catid] = $r; } } $str = "<option value='\$catid' \$selected \$disabled>\$spacer \$catname</option>"; $this->Tree->init($categorys); $string .= $this->Tree->get_tree(0, $str); $this->assign("models", $this->model); $this->assign("string", $string); $this->assign("modelid", $modelid); $this->display(); } }
/** +---------------------------------------------------------- * 取得当前认证号的所有权限列表 +---------------------------------------------------------- * @param integer $authId 用户ID +---------------------------------------------------------- * @access public +---------------------------------------------------------- */ public static function getAccessList($authId) { //用户信息 $userInfo = User::getInstance()->getInfo(); if (empty($userInfo)) { return false; } //角色ID $role_id = $userInfo['role_id']; //检查角色 $roleinfo = D('Admin/Role')->where(array('id' => $role_id))->find(); if (empty($roleinfo) || empty($roleinfo['status'])) { return false; } //该角色全部权限 $access = D('Admin/Access')->getAccessList($role_id); $accessList = array(); foreach ($access as $acc) { $app = strtoupper($acc['app']); $controller = strtoupper($acc['controller']); $action = strtoupper($acc['action']); $accessList[$app][$controller][$action] = $action; } return $accessList; }
/** * 检查该菜单是否已经添加过 * @param type $mid 菜单ID * @return boolean */ public function isExist($mid) { return $this->where(array('mid' => $mid, "userid" => \Admin\Service\User::getInstance()->id))->count(); }
/** * 信息锁定 * @param type $catid 栏目ID * @param type $id 信息ID * @param type $userid 用户名ID * @param type $username 用户名 * @return type */ public function locking($catid, $id, $userid = 0) { $db = M("Locking"); $time = time(); //锁定有效时间 $Lock_the_effective_time = 300; if (empty($userid)) { $userid = \Admin\Service\User::getInstance()->id; } $where = array(); $where['catid'] = array("EQ", $catid); $where['id'] = array("EQ", $id); $where['locktime'] = array("EGT", $time - $Lock_the_effective_time); $info = $db->where($where)->find(); if ($info && $info['userid'] != \Admin\Service\User::getInstance()->id) { $this->error = 'o(︶︿︶)o 唉,该信息已经被用户【<font color=\\"red\\">' . $info['username'] . '</font>】锁定~请稍后在修改!'; return false; } //删除失效的 $where = array(); $where['locktime'] = array("LT", $time - $Lock_the_effective_time); $db->where($where)->delete(); return true; }
/** * 栏目选择 * @param string $file 栏目缓存文件名 * @param intval/array $catid 别选中的ID,多选是可以是数组 * @param string $str 属性 * @param string $default_option 默认选项 * @param intval $modelid 按所属模型筛选 * @param intval $type 栏目类型 * @param intval $onlysub 只可选择子栏目 * @param intval $is_push 加载权限表模型 ,获取会员组ID值,以备下面投入判断用 */ public static function select_category($catid = 0, $str = '', $default_option = '', $modelid = 0, $type = -1, $onlysub = 0, $is_push = 0) { $tree = new \Tree(); $result = cache('Category'); $string = '<select ' . $str . '>'; if ($default_option) { $string .= "<option value='0'>{$default_option}</option>"; } //加载权限表模型 ,获取会员组ID值,以备下面投入判断用 if ($is_push) { $priv = M('CategoryPriv'); //用户组 if (defined('IN_ADMIN') && IN_ADMIN) { //后台 $user_groupid = \Admin\Service\User::getInstance()->role_id; } else { $user_groupid = service('Passport')->groupid ?: 8; } } if (is_array($result)) { foreach ($result as $r) { $r = getCategory($r['catid']); //检查当前会员组,在该栏目处是否允许投稿? if ($is_push == '1' and $r['child'] == '0') { $where = array('catid' => $r['catid'], 'roleid' => $user_groupid, 'action' => 'add'); if (defined("IN_ADMIN") && IN_ADMIN) { $where['is_admin'] = 1; } else { $where['is_admin'] = 0; } $array = $priv->where($where)->find(); if (!$array) { continue; } } $r['selected'] = ''; if (is_array($catid)) { $r['selected'] = in_array($r['catid'], $catid) ? 'selected' : ''; } elseif (is_numeric($catid)) { $r['selected'] = $catid == $r['catid'] ? 'selected' : ''; } $r['html_disabled'] = "0"; if (!empty($onlysub) && $r['child'] != 0) { $r['html_disabled'] = "1"; } $categorys[$r['catid']] = $r; if ($modelid && $r['modelid'] != $modelid) { unset($categorys[$r['catid']]); } } } $str = "<option value='\$catid' \$selected>\$spacer \$catname</option>;"; $str2 = "<optgroup label='\$spacer \$catname'></optgroup>"; $tree->init($categorys); $string .= $tree->get_tree_category(0, $str, $str2); $string .= '</select>'; return $string; }
/** * 添加内容 * @param type $data 数据 * @return boolean */ public function add($data = '') { if (empty($data)) { if (!empty($this->data)) { $data = $this->data; // 重置数据 $this->data = array(); } else { $this->error = L('_DATA_TYPE_INVALID_'); return false; } } $this->catid = (int) $data['catid']; $this->modelid = getCategory($this->catid, 'modelid'); //取得表单令牌验证码 $data[C("TOKEN_NAME")] = $_POST[C("TOKEN_NAME")]; //标签 tag('content_add_begin', $data); //栏目数据 $catidinfo = getCategory($data['catid']); if (empty($catidinfo)) { $this->error = '获取不到栏目数据!'; return false; } //setting配置 $catidsetting = $catidinfo['setting']; //前台投稿状态判断 if (!defined('IN_ADMIN') || defined('IN_ADMIN') && IN_ADMIN == false) { //前台投稿,根据栏目配置和用户配置 $Member_group = cache("Member_group"); $groupid = service('Passport')->groupid; //如果会员组设置中设置,投稿不需要审核,直接无视栏目设置 if ($Member_group[$groupid]['allowpostverify']) { $data['status'] = 99; } else { //前台投稿是否需要审核 if ($catidsetting['member_check']) { $data['status'] = 1; } else { $data['status'] = 99; } } //添加用户名 $data['username'] = service('Passport')->username; $data['sysadd'] = 0; } else { //添加用户名 $data['username'] = \Admin\Service\User::getInstance()->username; $data['sysadd'] = 1; } //检查真实发表时间,如果有时间转换为时间戳 if ($data['inputtime'] && !is_numeric($data['inputtime'])) { $data['inputtime'] = strtotime($data['inputtime']); } elseif (!$data['inputtime']) { $data['inputtime'] = time(); } //更新时间处理 if ($data['updatetime'] && !is_numeric($data['updatetime'])) { $data['updatetime'] = strtotime($data['updatetime']); } elseif (!$data['updatetime']) { $data['updatetime'] = time(); } //自动提取摘要,如果有设置自动提取,且description为空,且有内容字段才执行 $this->description($data); $model = ContentModel::getInstance($this->modelid); $content_input = new \content_input($this->modelid); //保存一份旧数据 $oldata = $data; $data = $content_input->get($data, 1); if ($data) { $data = $model->relation(true)->create($data, 1); if (false == $data) { $this->error = $model->getError(); $this->tokenRecovery($oldata); return false; } } else { $this->error = $content_input->getError(); $this->tokenRecovery($oldata); return false; } //自动提取缩略图,从content 中提取 $this->getThumb($data); $oldata['thumb'] = $data['thumb']; //添加内容 $this->id = $id = $data['id'] = $oldata['id'] = $model->relation(true)->add($data); if (false == $id) { $this->error = $model->getError(); $this->tokenRecovery($oldata); return false; } //转向地址 $urls = array(); if ($data['islink'] == 1) { $urls['url'] = $_POST['linkurl']; } else { //生成该篇地址 $urls = $this->generateUrl($data); } $oldata['url'] = $data['url'] = $urls['url']; //更新url $model->token(false)->where(array('id' => $id))->save(array('url' => $data['url'])); $content_update = new \content_update($this->modelid); $status = $content_update->update($oldata); //发布到其他栏目,只能后台发布才可以使用该功能 if (defined('IN_ADMIN') && IN_ADMIN) { if (is_array($_POST['othor_catid'])) { foreach ($_POST['othor_catid'] as $classid => $v) { if ($this->catid == $classid) { continue; } $othor_catid[] = $classid; } //去除重复 $othor_catid = array_unique($othor_catid); $this->othor_catid($othor_catid, $urls['url'], $data, $this->modelid); } } //字段合并 $model->dataMerger($data); //更新附件状态,把相关附件和文章进行管理 $attachment = service('Attachment'); $attachment->api_update('', 'c-' . $data['catid'] . '-' . $id, 2); //标签 tag('content_add_end', $data); //生成相关 $generatelish = 0; if (defined('IN_ADMIN') && IN_ADMIN) { //是否生成内容页 if ($catidsetting['generatehtml']) { //生成静态 if ($catidsetting['content_ishtml'] && $data['status'] == 99) { $this->Html->show($data); } } //生成列表 if ((int) $catidsetting['generatelish'] > 0) { $generatelish = (int) $catidsetting['generatelish']; } } switch ($generatelish) { //生成当前栏目 case 1: $this->Html->category($data['catid']); break; //生成首页 //生成首页 case 2: $this->Html->index(); break; //生成父栏目 //生成父栏目 case 3: if ($catidinfo['parentid']) { $this->Html->category($catidinfo['parentid']); } break; //生成当前栏目与父栏目 //生成当前栏目与父栏目 case 4: $this->Html->category($data['catid']); if ($catidinfo['parentid']) { $this->Html->category($catidinfo['parentid']); } break; //生成父栏目与首页 //生成父栏目与首页 case 5: if ($catidinfo['parentid']) { $this->Html->category($catidinfo['parentid']); } $this->Html->index(); break; //生成当前栏目、父栏目与首页 //生成当前栏目、父栏目与首页 case 6: $this->Html->category($data['catid']); $this->Html->createRelationHtml($data['catid']); $this->Html->index(); break; } //生成上一篇下一篇 if ($data['status'] == 99) { $this->relatedContent($this->catid, $this->id, 'add'); } return $id; }
public function public_lock_renewal() { $catid = I('get.catid', 0, 'intval'); $id = I('get.id', 0, 'intval'); $userid = User::getInstance()->id; $time = time(); if ($catid && $id && $userid) { M('Locking')->where(array('id' => $id, 'catid' => $catid, 'userid' => $userid))->save(array('locktime' => $time)); } }
public function changyong() { if (IS_POST) { //被选中的菜单项 $menuidAll = explode(',', I('post.menuid', '')); if (is_array($menuidAll) && count($menuidAll) > 0) { //取得菜单数据 $menu_info = cache('Menu'); $addPanel = array(); //检测数据合法性 foreach ($menuidAll as $menuid) { if (empty($menu_info[$menuid])) { continue; } $info = array('mid' => $menuid, 'userid' => User::getInstance()->id, 'name' => $menu_info[$menuid]['name'], 'url' => "{$menu_info[$menuid]['app']}/{$menu_info[$menuid]['controller']}/{$menu_info[$menuid]['action']}"); $addPanel[] = $info; } if (D('Admin/AdminPanel')->addPanel($addPanel)) { $this->success("添加成功!", U("Public/changyong")); } else { $error = D('Admin/AdminPanel')->getError(); $this->error($error ? $error : '添加失败!'); } } else { D('Admin/AdminPanel')->where(array("userid" => \Admin\Service\User::getInstance()->id))->delete(); $this->error("常用菜单清除成功!"); } } else { //菜单缓存 $result = cache("Menu"); $json = array(); foreach ($result as $rs) { if ($rs['status'] == 0) { continue; } $data = array('id' => $rs['id'], 'nocheck' => $rs['type'] ? 0 : 1, 'checked' => $rs['id'], 'parentid' => $rs['parentid'], 'name' => $rs['name'], 'checked' => D("Admin/AdminPanel")->isExist($rs['id']) ? true : false); $json[] = $data; } $this->assign('json', json_encode($json))->display(); } }