function arrToTree($data, $pid) { foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $id .= arrToTree($data, $v['id']); $id .= $v['id'] . ','; } } return $id; }
function arrToTree($data, $pid) { $tree = array(); foreach ($data as $k => $v) { if ($v['pid'] == $pid) { $v['pid'] = arrToTree($data, $v['id']); $tree[] = $v; } } return $tree; }
public function menu() { $this->checkUser(); if (isset($_SESSION[C('USER_AUTH_KEY')])) { //显示菜单项 $menu = array(); if (isset($_SESSION['menu' . $_SESSION[C('USER_AUTH_KEY')]])) { //如果已经缓存,直接读取缓存 $menu = $_SESSION['menu' . $_SESSION[C('USER_AUTH_KEY')]]; } else { //读取数据库模块列表生成菜单项 $node = M("Node"); $map['level'] = 2; $map['status'] = 1; $list = $node->where($map)->field('id,name,pid,title')->order('sort asc')->select(); $accessList = $_SESSION['_ACCESS_LIST']; foreach ($list as $key => $module) { if (isset($accessList[strtoupper(APP_NAME)][strtoupper($module['name'])]) || $_SESSION['administrator']) { //设置模块访问权限 $module['access'] = 1; $menu[$key] = $module; } } //缓存菜单访问 $_SESSION['menu' . $_SESSION[C('USER_AUTH_KEY')]] = $menu; } if (isset($_GET['tag'])) { $tag = $_GET['tag']; if (0 == $tag) { $this->assign('menuTitle', '扩展功能'); } else { $mapid['id'] = array('eq', $tag); $node = M("Node"); $title = $list = $node->where($mapid)->getField('title'); $this->assign('menuTitle', $title); } $this->assign('menuTag', $tag); } else { $this->assign('menuTitle', '内容管理'); } $this->assign('menu', $menu); } //显示站点栏目 $cate = new CategoryModel(); $this->cate = $list = $cate->getMyCategory(); //加载栏目 $menu = $cate->getMyCategory1(); //加载栏目 $menu = arrToTree($menu, 0); $tree = outMenuNode($menu); $this->assign('tree', $tree); $this->display(); }
public function getMenu() { //显示菜单项 $menu = array(); //读取数据库模块列表生成菜单项 $node = D("Node"); $map['status'] = array("egt", 0); $list = $node->where($map)->field('id,pid,name,title,level,sort,status')->order('level,sort')->select(); foreach ($list as $key => $module) { //设置模块访问权限 $module['access'] = 1; $menu[$key] = $module; } $menu = arrToTree($menu, 0); return $menu; }
public function index() { if (method_exists($this, '_filter')) { $this->_filter($map); } $id = I('id'); $catdata = D('Category')->where('status=1')->find($id); //获取所有子类id $catlist = D('Category')->where('status=1')->select(); $idlist = $id . ',' . arrToTree($catlist, $id); $idlist = substr($idlist, 0, strlen($idlist) - 1); $map['catid'] = array('in', $idlist); $name = $this->getActionName(); //获取分页设置 $Model = M('Model'); $map['table'] = array('eq', $name); $pageinfo = $Model->where($map)->find(); $Form = M($name); import("@.ORG.Page"); //导入分页类 $count = $Form->where($map)->count(); //计算总数 $Page = new Page($count, $pageinfo['listrows']); $list = $Form->where($map)->limit($Page->firstRow . ',' . $Page->listRows)->order('listorder,id desc')->select(); // 设置分页显示 $Page->setConfig('header', $pageinfo['header']); $Page->setConfig('first', $pageinfo['first']); $Page->setConfig('last', $pageinfo['last']); $Page->setConfig('prev', $pageinfo['prev']); $Page->setConfig('next', $pageinfo['next']); $Page->setConfig('theme', $pageinfo['theme']); $page = $Page->show(); $position = D('Common')->getPosition($id); foreach ($position as $value) { $title = $value['catname'] . "_" . $title; } $title = substr($title, 0, strlen($title) - 1); $this->seo($catdata['title'] ? $catdata['title'] : $title, $catdata['keywords'] ? $catdata['keywords'] : C(SITE_KEYWORDS), $catdata['description'] ? $catdata['description'] : C(SITE_DESCRIPTION), $position); $this->assign("data", $catdata); $this->assign("page", $page); $this->assign("list", $list); $this->display(); }
public function index() { $id = $_GET['id']; $catdata = D('Category')->where('status=1')->find($id); //获取所有子类id $catlist = D('Category')->where('status=1')->select(); $idlist = $id . ',' . arrToTree($catlist, $id); $idlist = substr($idlist, 0, strlen($idlist) - 1); $map['catid'] = array('in', $idlist); $name = $this->getActionName(); //获取分页设置 $Model = M('Model'); $map['table'] = array('eq', $name); $pageinfo = $Model->where($map)->find(); $Form = M($name); import("@.ORG.Page"); //导入分页类 $count = $Form->where($map)->count(); //计算总数 $Page = new Page($count, $pageinfo['listrows']); $list = $Form->where($map)->limit('0,' . $Page->nowPage * $Page->listRows)->order('id desc')->select(); //$Page->firstRow. // 设置分页显示 $Page->setConfig('header', $pageinfo['header']); $Page->setConfig('first', $pageinfo['first']); $Page->setConfig('last', $pageinfo['last']); $Page->setConfig('prev', $pageinfo['prev']); $Page->setConfig('next', $pageinfo['next']); $Page->setConfig('theme', $pageinfo['theme']); $page = $Page->show(); $Page->setConfig('next', '查看更多'); $Page->setConfig('theme', '%downPage%'); $downPage = $Page->show(); $this->assign("catdata", $catdata); $this->assign("page", $page); $this->assign("downPage", $downPage); $this->assign("list", $list); $this->seo($catdata['title'] ? $catdata['title'] : C(SITE_NAME), $catdata['keywords'] ? $catdata['keywords'] : C(SITE_KEYWORDS), $catdata['description'] ? $catdata['description'] : C(SITE_DESCRIPTION), D('Common')->getPosition($id)); $this->display(); }
public function role() { $role = D('Role'); //获取当前用户组项目权限信息 $roleId = isset($_GET['id']) ? $_GET['id'] : ''; $nodeRoleList = array(); if (!empty($roleId)) { $this->assign("selectRoleId", $roleId); //获取当前角色的操作权限列表 $list = $role->getNodeRoleList($roleId); foreach ($list as $vo) { $nodeRoleList[$vo['id']] = $vo['id']; } } if (isset($_SESSION[C('USER_AUTH_KEY')])) { //显示菜单项 $menu = array(); //读取数据库模块列表生成菜单项 $node = M("Node"); $where['status'] = array('egt', 0); $list = $node->where($where)->field('id,pid,name,title,level')->order('level,sort')->select(); $accessList = $_SESSION['_ACCESS_LIST']; foreach ($list as $key => $module) { if (isset($accessList[strtoupper(APP_NAME)][strtoupper($module['name'])]) || $_SESSION['administrator']) { //设置模块访问权限 $module['access'] = 1; $menu[$key] = $module; } } $menu = arrToTree($menu, 0); $tree = outMenu($menu, $nodeRoleList); $this->assign('tree', $tree); } C('SHOW_RUN_TIME', false); // 运行时间显示 C('SHOW_PAGE_TRACE', false); $this->display(); return; }
public function _photo($attr, $content) { $tag = $this->parseXmlAttr($attr, 'photo'); $result = !empty($tag['result']) ? $tag['result'] : 'photo'; $catlist = D('Category')->where('status=1')->select(); $idlist = $tag['catid'] . ',' . arrToTree($catlist, $tag['catid']); $idlist = substr($idlist, 0, strlen($idlist) - 1); $map .= "'status=1"; $map .= $tag['catid'] ? " and catid in ({$idlist})'" : "'"; $sql = "M('Photo')->"; $sql .= "where({$map})->"; $sql .= $tag['field'] ? "field('{$tag['field']}')->" : ""; $sql .= $tag['order'] ? "order('{$tag['order']}')->" : ""; $sql .= $tag['num'] ? "limit({$tag['num']})->" : ""; $sql .= "select()"; //下面拼接输出语句 $parsestr = '<?php $_result=' . $sql . ';'; $parsestr .= 'foreach($_result as $key=>$' . $result . '):?>'; $parsestr .= $content; //解析在article标签中的内容 $parsestr .= '<?php endforeach;?>'; return $parsestr; }
function _initialize() { header("Content-Type:text/html; charset=utf-8"); import('@.ORG.Util.Cookie'); import('@.ORG.Alipay'); //栏目导航 $nav_list = D('Category')->where('pid=0 AND status=1')->order('listorder')->select(); if (is_array($nav_list)) { foreach ($nav_list as $key => $val) { $nav_list[$key] = $this->changurl($val, $val['catdir']); //地址转化 $nav_list[$key]['sub_nav'] = D('Category')->where('pid=' . $val['id'] . ' AND status=1')->order('listorder')->select(); //查询二级栏目 foreach ($nav_list[$key]['sub_nav'] as $key2 => $val2) { $nav_list[$key]['sub_nav'][$key2] = $this->changurl($val2, $val2['catdir']); $nav_list[$key]['sub_nav'][$key2]['sub_sub_nav'] = D('Category')->where('pid=' . $val2['id'] . ' AND status=1')->order('listorder')->select(); //查询三级栏目 foreach ($nav_list[$key]['sub_nav'][$key2]['sub_sub_nav'] as $key3 => $val3) { $nav_list[$key]['sub_nav'][$key2]['sub_sub_nav'][$key3] = $this->changurl($val3, $val3['catdir']); } } } } $this->assign('nav_list', $nav_list); //栏目分类 $node = D("Category"); $map['status'] = array("egt", 0); $list = $node->where($map)->order('level,listorder')->select(); $categorylist = arrToTree($list, 0); $this->categorylist = $categorylist; //底部信息中心 $xxzx = 141; $footer_catdata = D('Category')->where('status=1')->find($xxzx); //获取所有子类id $footer_catlist = D('Category')->where('status=1')->order('listorder desc')->select(); $footer_catlist1 = getChildIdArray($footer_catlist, $xxzx); $footer_info = $footer_catlist1; $footer_catlist = getChildId($footer_catlist, $xxzx); $footer_catlist = substr($footer_catlist, 0, strlen($footer_catlist) - 1); $xxzx_info = D("Article")->where("catid in ({$footer_catlist})")->select(); foreach ($xxzx_info as $k => $v) { $catid = intval($v['catid']); $footer_info[$catid]['child'][] = $v; } $this->footer_info = $footer_info; //获取综合微信下的分类 $zcategorylist = arrToTree($list, 53); $this->zcategorylist = $zcategorylist; //每日流量统计 $tjdate = D('Tjdate'); $map['create_date'] = array('eq', date('Ymd', time())); $vl = $tjdate->where($map)->find(); if ($vl) { $tjdate->id = $vl['id']; $tjdate->create_num = $vl['create_num'] + 1; $tjdate->save(); } else { $tjdate->create_date = date('Ymd', time()); $tjdate->create_num = 1; $tjdate->add(); } //页面流量统计 $tjurl = D('Tjurl'); $map['create_url'] = __SELF__; $vla = $tjurl->where($map)->find(); if ($vla) { $tjurl->id = $vla['id']; $tjurl->create_num = $vla['create_num'] + 1; $tjurl->save(); } else { $tjurl->create_url = __SELF__; $tjurl->create_num = 1; $tjurl->add(); } //印象码 define("PRIVATE_KEY", "f8e0e8a892f46bfddff0255da50fd46e"); $this->YXM_PUBLIC_KEY = "b20672750e25c094064ddc29ec6b8de9"; $this->YXM_localsec_url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . __ROOT__ . "/Data/localsec/"; $this->iscomment = C('ISCOMMENT'); //是否开启评论功能 $this->commenttype = C('COMMENTTYPE'); //评论选择 $this->sitename = C('SITE_NAME'); //站点名称 $this->isaddaccount = C('ISADDACCOUNT'); //是否开启游客提交公号功能 $this->xfintergral = C('XFINTERGRAL'); //发布促销活动消费积分 }