Exemplo n.º 1
0
 public function edit()
 {
     if (IS_POST) {
         if (!empty($_POST['photos_alt']) && !empty($_POST['photos_url'])) {
             foreach ($_POST['photos_url'] as $key => $url) {
                 $photourl = $this->removeUploadImage($this->imgFolder, $url);
                 $_POST['smeta']['photo'][] = array("url" => $photourl, "alt" => $_POST['photos_alt'][$key]);
             }
         }
         $_POST['smeta']['photo'] = list_sort_by($_POST['smeta']['photo'], "alt");
         $_POST['smeta'] = json_encode($_POST['smeta']);
         $_POST['post_date'] = strtotime($_POST['post_date']);
         $_POST['post_content'] = htmlspecialchars($_POST['post_content']);
         $_POST['post_pic'] = $this->removeUploadImage($this->imgFolder, $_POST['post_pic']);
         $result = $this->model_obj->save($_POST);
         if ($result) {
             $this->success("编辑成功!");
         } else {
             $this->error("编辑失败!");
         }
     } else {
         $id = $_REQUEST['id'];
         if (empty($id)) {
             $this->redirect("PCustom/index");
         }
         $info = $this->model_obj->where("id={$id}")->find();
         $this->assign($info);
         $this->assign("smeta", json_decode($info['smeta'], true));
         $this->commonParam();
         $this->display();
     }
 }
Exemplo n.º 2
0
 public function show()
 {
     $dirpath = $this->dirpath();
     $dirup = $this->dirup();
     import("ORG.Io.Dir");
     $dir = new Dir($dirpath);
     $dirlist = $dir->toArray();
     if (strpos($dirup, 'Template') > 0) {
         $this->assign('dirup', $dirup);
     }
     if (empty($dirlist)) {
         $this->error('该文件夹下面没有任何文件!');
     }
     if ($_GET['mytpl']) {
         foreach ($dirlist as $key => $value) {
             if (strpos($value['filename'], 'my_') === false) {
                 unset($dirlist[$key]);
             }
         }
     }
     $_SESSION['tpl_reurl'] = C('cms_admin') . '?s=Admin/Tpl/Show/id/' . str_replace('/', '*', $dirpath);
     if ($dirup && $dirup != '.') {
         $this->assign('dirup', $dirup);
     }
     $this->assign('mytpl', $_GET['mytpl']);
     $this->assign('dir', list_sort_by($dirlist, 'mtime', 'desc'));
     $this->assign('dirpath', $dirpath);
     $this->display('./views/admin/tpl_show.html');
 }
Exemplo n.º 3
0
 public function index()
 {
     $catList = $this->paperCategoryModel->getCategoryList(array('status' => 1));
     if (count($catList)) {
         $cat_ids = array_column($catList, 'id');
         $catList = array_combine($cat_ids, $catList);
         $map['category'] = array('in', array_merge($cat_ids, array(0)));
     } else {
         $map['category'] = 0;
         $catList = array();
     }
     $map['status'] = 1;
     $pageArtiles = $this->paperModel->getList($map, 'id,title,sort,category');
     foreach ($pageArtiles as $val) {
         $val['type'] = 'article';
         if ($val['category'] == 0) {
             $catList[] = $val;
         } else {
             $catList[$val['category']]['children'][] = $val;
         }
     }
     $catListSort = list_sort_by($catList, 'sort');
     $this->assign('cat_list', $catListSort);
     $aId = I('id', 0, 'intval');
     if ($aId == 0) {
         foreach ($catList as $val) {
             if ($val['type'] == 'article') {
                 $aId = $val['id'];
                 break;
             } else {
                 if ($val['children'][0]['id']) {
                     $aId = $val['children'][0]['id'];
                     break;
                 }
             }
         }
     }
     if ($aId) {
         $pageArtiles = array_combine(array_column($pageArtiles, 'id'), $pageArtiles);
         $contentTitle = $pageArtiles[$aId];
         $this->assign('content_title', $contentTitle);
         if ($pageArtiles[$aId]['category'] != 0) {
             $cate = $catList[$pageArtiles[$aId]['category']];
             $this->assign('cate', $cate);
             $this->assign('top_id', $cate['id']);
         } else {
             $this->assign('top_id', 0);
             $this->assign('id', $aId);
         }
     }
     $data = $this->paperModel->getData($aId);
     $this->assign('data', $data);
     $this->display();
 }
Exemplo n.º 4
0
/**
 * 根据皮肤列表,获取皮肤详细信息
 * @param $skinList 皮肤列表
 * @return array
 * @author 郑钟良<*****@*****.**>
 */
function getSkinInfoList($skinList)
{
    $skinInfoList = array();
    foreach ($skinList as $path) {
        $skinConf = (include SKIN_PATH . 'Skins/' . $path . '/config.php');
        $skin['value'] = $path;
        $skin['name'] = $skinConf['name'];
        $skin['sort'] = $skinConf['sort'];
        $skin['thumb_url'] = SKIN_PATH . 'Skins/' . $path . '/thumb.png';
        $skinInfoList[] = $skin;
    }
    unset($path, $skin);
    $skinInfoList = list_sort_by($skinInfoList, 'sort', 'asc');
    return $skinInfoList;
}
Exemplo n.º 5
0
/**
 * 根据皮肤列表,获取皮肤详细信息
 * @param $skinList 皮肤列表
 * @return array
 * @author 郑钟良<*****@*****.**>
 */
function getSkinInfoList($skinList)
{
    $skinInfoList = array();
    $skinUrl = getRootUrl() . preg_replace('|^' . ONETHINK_ADDON_PATH . '|', 'Addons/', SKIN_PATH);
    foreach ($skinList as $path) {
        $skinConf = (include SKIN_PATH . 'Skins/' . $path . '/config.php');
        $skin['value'] = $path;
        $skin['name'] = $skinConf['name'];
        $skin['sort'] = $skinConf['sort'];
        $skin['thumb_url'] = $skinUrl . 'Skins/' . $path . '/thumb.png';
        $skinInfoList[] = $skin;
    }
    unset($path, $skin);
    $skinInfoList = list_sort_by($skinInfoList, 'sort', 'asc');
    return $skinInfoList;
}
Exemplo n.º 6
0
 /**
  * 获取插件列表
  * 
  * @param string $addon_dir        	
  */
 public function getList($addon_dir = '', $type = 0)
 {
     if (!$addon_dir) {
         $addon_dir = ONETHINK_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->select();
     foreach ($list as $addon) {
         $addon['is_weixin'] = file_exists($addon_dir . $addon['name'] . '/Model/WeixinAddonModel.class.php');
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
             $addons[$value]['is_weixin'] = file_exists($addon_dir . $value . '/Model/WeixinAddonModel.class.php');
         }
     }
     foreach ($addons as $key => $val) {
         if ($type == 1 && !$val['is_weixin'] || $type == 0 && $val['is_weixin']) {
             unset($addons[$key]);
         }
     }
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Exemplo n.º 7
0
 /**
  * 获取插件列表
  * @param string $addon_dir
  */
 public function getList($addon_dir = '')
 {
     if (!$addon_dir) {
         $addon_dir = ZS_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->select();
     foreach ($list as $addon) {
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             $admin_list = $obj->admin_list;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
             if ($admin_list) {
                 $addons[$value]['has_adminlist'] = 1;
             } else {
                 $addons[$value]['has_adminlist'] = 0;
             }
         }
     }
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Exemplo n.º 8
0
 /**
  * 获取插件列表
  * @param string $addon_dir
  * @param int $limit
  * @return array|bool
  */
 public function getList($addon_dir = '', $limit = 0)
 {
     if (!$addon_dir) {
         $addon_dir = Addon_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     if ($dirs === false || !File::file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return false;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->limit($limit)->select();
     foreach ($list as $addon) {
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 $addons[$value]['status'] = 99;
             }
         } else {
             //todo 已安装的
         }
     }
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', 99 => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
 public function index()
 {
     $dirpath = $this->dirpath();
     //当前目录
     $dirlast = $this->dirlast();
     //上一层目录
     import("ORG.Util.Dir");
     $dir = new Dir($dirpath);
     $list_dir = $dir->toArray();
     if (empty($list_dir)) {
         $this->error('该文件夹下面没有文件!');
     }
     foreach ($list_dir as $key => $value) {
         $list_dir[$key]['pathfile'] = dami_url_repalce($value['path'], 'desc') . '|' . $value['filename'];
     }
     $_SESSION['tpl_jumpurl'] = '?s=Tpl/index/id/' . dami_url_repalce($dirpath, 'desc');
     if ($dirlast && $dirlast != '.') {
         $this->assign('dirlast', dami_url_repalce($dirlast, 'desc'));
     }
     $this->assign('dirpath', $dirpath);
     $this->assign('list_dir', list_sort_by($list_dir, 'mtime', 'desc'));
     $this->display('index');
 }
Exemplo n.º 10
0
 /**
  * 获取用户初始化后积分值
  * @param $role_id 当前初始化角色
  * @param $uid 初始化用户
  * @param $value 初始化角色积分配置值
  * @return array
  * @author 郑钟良<*****@*****.**>
  */
 private function getUserScore($role_id, $uid, $value)
 {
     $roleConfigModel = M('RoleConfig');
     $userRoleModel = M('UserRole');
     $map['role_id'] = array('neq', $role_id);
     $map['uid'] = $uid;
     $map['init'] = 1;
     $role_list = $userRoleModel->where($map)->select();
     $role_ids = array_column($role_list, 'role_id');
     $map_config['role_id'] = array('in', $role_ids);
     $map_config['name'] = 'score';
     $config_list = $roleConfigModel->where($map_config)->field('value')->select();
     $change = array();
     foreach ($config_list as &$val) {
         $val = json_decode($val['value'], true);
     }
     unset($val);
     unset($config_list[0]['score1']);
     foreach ($value as $key => $val) {
         $config_list = list_sort_by($config_list, $key, 'desc');
         if ($val > $config_list[0][$key]) {
             $change[$key] = $val - $config_list[0][$key];
         } else {
             $change[$key] = 0;
         }
     }
     return $change;
 }
 /**
  * 获取插件列表
  * @param string $addon_dir
  */
 public function getList($addon_dir = '')
 {
     if (!$addon_dir) {
         $addon_dir = ONETHINK_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     //TODO 新增模块插件的支持
     /* $modules=D('Module')->getAll();
        foreach($modules as $m){
            if($m['is_setup']){
                $module_dir=APP_PATH.$m['name'].'/Addons/';
                if(!file_exists($module_dir)){
                    continue;
                }
                $tmp_dirs = array_map('basename',glob($module_dir.'*', GLOB_ONLYDIR));
                $dirs=array_merge($dirs,$tmp_dirs);
            }
        }*/
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = L('_THE_PLUGIN_DIRECTORY_IS_NOT_READABLE_OR_NOT_');
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->select();
     foreach ($list as $addon) {
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record(L('_PLUGIN_') . $value . L('_THE_ENTRY_FILE_DOES_NOT_EXIST_WITH_EXCLAMATION_'));
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
         }
     }
     //dump($list);exit;
     int_to_string($addons, array('status' => array(-1 => L('_DAMAGE_'), 0 => L('_DISABLE_'), 1 => L('_ENABLE_'), null => L('_NOT_INSTALLED_'))));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Exemplo n.º 12
0
/**
 * 将list_to_tree的树还原成列表
 * @param  array  $tree 原来的树
 * @param  string $child 孩子节点的键
 * @param  string $order 排序显示的键,一般是主键 升序排列
 * @param  array  $list 过渡用的中间数组,
 * @return array        返回排过序的列表数组
 * @author yangweijie <*****@*****.**>
 */
function tree_to_list($tree, $child = '_child', $order = 'id', &$list = array())
{
    if (is_array($tree)) {
        $refer = array();
        foreach ($tree as $key => $value) {
            $reffer = $value;
            if (isset($reffer[$child])) {
                unset($reffer[$child]);
                tree_to_list($value[$child], $child, $order, $list);
            }
            $list[] = $reffer;
        }
        $list = list_sort_by($list, $order, $sortby = 'asc');
    }
    return $list;
}
Exemplo n.º 13
0
 /**
  * 编辑页面初始化
  * @author huajie <*****@*****.**>
  */
 public function edit()
 {
     $id = I('get.id', '');
     if (empty($id)) {
         $this->error('参数不能为空!');
     }
     /*获取一条记录的详细数据*/
     $Model = M('Model');
     $data = $Model->field(true)->find($id);
     if (!$data) {
         $this->error($Model->getError());
     }
     $data['attribute_list'] = empty($data['attribute_list']) ? '' : explode(",", $data['attribute_list']);
     $fields = M('Attribute')->where(array('model_id' => $data['id']))->getField('id,name,title,is_show', true);
     $fields = empty($fields) ? array() : $fields;
     // 是否继承了其他模型
     if ($data['extend'] != 0) {
         $extend_fields = M('Attribute')->where(array('model_id' => $data['extend']))->getField('id,name,title,is_show', true);
         $fields += $extend_fields;
     }
     // 梳理属性的可见性
     foreach ($fields as $key => $field) {
         if (!empty($data['attribute_list']) && !in_array($field['id'], $data['attribute_list'])) {
             $fields[$key]['is_show'] = 0;
         }
     }
     // 获取模型排序字段
     $field_sort = json_decode($data['field_sort'], true);
     if (!empty($field_sort)) {
         foreach ($field_sort as $group => $ids) {
             foreach ($ids as $key => $value) {
                 $fields[$value]['group'] = $group;
                 $fields[$value]['sort'] = $key;
             }
         }
     }
     // 模型字段列表排序
     $fields = list_sort_by($fields, "sort");
     $this->assign('fields', $fields);
     $this->assign('info', $data);
     $this->meta_title = '编辑模型';
     $this->display();
 }
Exemplo n.º 14
0
 /**
  * 获取插件列表
  * @param string $addon_dir
  */
 public function getList($addon_dir = '')
 {
     if (!$addon_dir) {
         $addon_dir = ONETHINK_ADDON_PATH;
     }
     $dirs = array_map('basename', glob($addon_dir . '*', GLOB_ONLYDIR));
     //TODO 新增模块插件的支持
     /* $modules=D('Module')->getAll();
        foreach($modules as $m){
            if($m['is_setup']){
                $module_dir=APP_PATH.$m['name'].'/Addons/';
                if(!file_exists($module_dir)){
                    continue;
                }
                $tmp_dirs = array_map('basename',glob($module_dir.'*', GLOB_ONLYDIR));
                $dirs=array_merge($dirs,$tmp_dirs);
            }
        }*/
     if ($dirs === FALSE || !file_exists($addon_dir)) {
         $this->error = '插件目录不可读或者不存在';
         return FALSE;
     }
     $addons = array();
     $where['name'] = array('in', $dirs);
     $list = $this->where($where)->field(true)->select();
     foreach ($list as $addon) {
         $addon['uninstall'] = 0;
         $addons[$addon['name']] = $addon;
     }
     foreach ($dirs as $value) {
         if (!isset($addons[$value])) {
             $class = get_addon_class($value);
             if (!class_exists($class)) {
                 // 实例化插件失败忽略执行
                 \Think\Log::record('插件' . $value . '的入口文件不存在!');
                 continue;
             }
             $obj = new $class();
             $addons[$value] = $obj->info;
             if ($addons[$value]) {
                 $addons[$value]['uninstall'] = 1;
                 unset($addons[$value]['status']);
             }
         }
     }
     //dump($list);exit;
     int_to_string($addons, array('status' => array(-1 => '损坏', 0 => '禁用', 1 => '启用', null => '未安装')));
     $addons = list_sort_by($addons, 'uninstall', 'desc');
     return $addons;
 }
Exemplo n.º 15
0
/**
 *  arclist解析函数
 *
 * @access    public
 * @param     object  $refObj  引用对象
 * @param     object  $ctag  标签
 * @param     int  $typeid  栏目ID
 * @param     int  $row  调用行数
 * @param     int  $titlelen  字符串长度
 * @param     int  $infolen  描述信息长度
 * @param     int  $imgwidth  图片宽度
 * @param     int  $imgheight  图片高度
 * @param     string  $listtype  列表类型
 * @param     string  $orderby  排列顺序
 * @param     string  $keyword  关键词
 * @param     string  $innertext  底层模板
 * @param     int  $arcid  文档ID
 * @param     string  $idlist  ID列表
 * @param     int  $channelid  频道ID
 * @param     string  $limit  限制
 * @param     string  $att  属性
 * @param     string  $order  排序类型
 * @param     int  $subday  天内
 * @param     string  $noflag  属性标记
 * @param     string  $tagid  标签id
 * @param     string  $pagesize  显示条数
 * @param     string  $isweight  是否需要对检索出来的内容按照weight排序
 * @return    string
 */
function lib_arclistDone(&$refObj, &$ctag, $typeid = 0, $row = 10, $col = 1, $titlelen = 30, $infolen = 160, $imgwidth = 120, $imgheight = 90, $listtype = 'all', $orderby = 'default', $keyword = '', $innertext = '', $arcid = 0, $idlist = '', $channelid = 0, $limit = '', $att = '', $order = 'desc', $subday = 0, $noflag = '', $tagid = '', $pagesize = 0, $isweight = 'N')
{
    global $dsql, $PubFields, $cfg_keyword_like, $cfg_index_cache, $_arclistEnv, $envs, $cfg_cache_type, $cfg_digg_update;
    $row = AttDef($row, 10);
    $titlelen = AttDef($titlelen, 30);
    $infolen = AttDef($infolen, 160);
    $imgwidth = AttDef($imgwidth, 120);
    $imgheight = AttDef($imgheight, 120);
    $listtype = AttDef($listtype, 'all');
    $arcid = AttDef($arcid, 0);
    $channelid = AttDef($channelid, 0);
    $orderby = AttDef($orderby, 'default');
    $orderWay = AttDef($order, 'desc');
    $subday = AttDef($subday, 0);
    $pagesize = AttDef($pagesize, 0);
    $line = $row;
    $orderby = strtolower($orderby);
    $keyword = trim($keyword);
    $innertext = trim($innertext);
    $tablewidth = $ctag->GetAtt('tablewidth');
    $writer = $ctag->GetAtt('writer');
    if ($tablewidth == "") {
        $tablewidth = 100;
    }
    if (empty($col)) {
        $col = 1;
    }
    $colWidth = ceil(100 / $col);
    $tablewidth = $tablewidth . "%";
    $colWidth = $colWidth . "%";
    //记录属性,以便分页样式统一调用
    $attarray = compact("row", "titlelen", 'infolen', 'imgwidth', 'imgheight', 'listtype', 'arcid', 'channelid', 'orderby', 'orderWay', 'subday', 'pagesize', 'orderby', 'keyword', 'tablewidth', 'col', 'colWidth');
    if ($innertext == '') {
        $innertext = GetSysTemplets('part_arclist.htm');
    }
    if (@$ctag->GetAtt('getall') == 1) {
        $getall = 1;
    } else {
        $getall = 0;
    }
    if ($att == '0') {
        $att = '';
    }
    if ($att == '3') {
        $att = 'f';
    }
    if ($att == '1') {
        $att = 'h';
    }
    $orwheres = array();
    $maintable = '#@__archives';
    //按不同情况设定SQL条件 排序方式
    if ($idlist == '') {
        if ($orderby == 'near' && $cfg_keyword_like == 'N') {
            $keyword = '';
        }
        if ($writer == 'this') {
            $wmid = isset($refObj->Fields['mid']) ? $refObj->Fields['mid'] : 0;
            $orwheres[] = " arc.mid = '{$wmid}' ";
        }
        //时间限制(用于调用最近热门文章、热门评论之类),这里的时间只能计算到天,否则缓存功能将无效
        if ($subday > 0) {
            $ntime = gmmktime(0, 0, 0, gmdate('m'), gmdate('d'), gmdate('Y'));
            $limitday = $ntime - $subday * 24 * 3600;
            $orwheres[] = " arc.senddate > {$limitday} ";
        }
        //关键字条件
        if ($keyword != '') {
            $keyword = str_replace(',', '|', $keyword);
            $orwheres[] = " CONCAT(arc.title,arc.keywords) REGEXP '{$keyword}' ";
        }
        //文档属性
        if (preg_match('/commend/i', $listtype)) {
            $orwheres[] = " FIND_IN_SET('c', arc.flag)>0  ";
        }
        if (preg_match('/image/i', $listtype)) {
            $orwheres[] = " FIND_IN_SET('p', arc.flag)>0  ";
        }
        if ($att != '') {
            $flags = explode(',', $att);
            for ($i = 0; isset($flags[$i]); $i++) {
                $orwheres[] = " FIND_IN_SET('{$flags[$i]}', arc.flag)>0 ";
            }
        }
        if (!empty($typeid) && $typeid != 'top') {
            //指定了多个栏目时,不再获取子类的id
            if (preg_match('#,#', $typeid)) {
                //指定了getall属性或主页模板例外
                if ($getall == 1 || empty($refObj->Fields['typeid'])) {
                    $typeids = explode(',', $typeid);
                    foreach ($typeids as $ttid) {
                        $typeidss[] = GetSonIds($ttid);
                    }
                    $typeidStr = join(',', $typeidss);
                    $typeidss = explode(',', $typeidStr);
                    $typeidssok = array_unique($typeidss);
                    $typeid = join(',', $typeidssok);
                }
                $orwheres[] = " arc.typeid IN ({$typeid}) ";
            } else {
                //处理交叉栏目
                $CrossID = '';
                if ($ctag->GetAtt('cross') == '1') {
                    $arr = $dsql->GetOne("SELECT `id`,`topid`,`cross`,`crossid`,`ispart`,`typename` FROM `#@__arctype` WHERE id='{$typeid}' ");
                    if ($arr['cross'] == 0 || $arr['cross'] == 2 && trim($arr['crossid'] == '')) {
                        $orwheres[] = ' arc.typeid IN (' . GetSonIds($typeid) . ')';
                    } else {
                        $selquery = '';
                        if ($arr['cross'] == 1) {
                            $selquery = "SELECT id,topid FROM `#@__arctype` WHERE typename LIKE '{$arr['typename']}' AND id<>'{$typeid}' AND topid<>'{$typeid}'  ";
                        } else {
                            $arr['crossid'] = preg_replace('#[^0-9,]#', '', trim($arr['crossid']));
                            if ($arr['crossid'] != '') {
                                $selquery = "SELECT id,topid FROM `#@__arctype` WHERE id IN('{$arr['crossid']}') AND id<>'{$typeid}' AND topid<>'{$typeid}'  ";
                            }
                        }
                        if ($selquery != '') {
                            $dsql->SetQuery($selquery);
                            $dsql->Execute();
                            while ($arr = $dsql->GetArray()) {
                                $CrossID .= $CrossID == '' ? $arr['id'] : ',' . $arr['id'];
                            }
                        }
                    }
                }
                if ($CrossID == '') {
                    $orwheres[] = ' arc.typeid IN (' . GetSonIds($typeid) . ')';
                } else {
                    $orwheres[] = ' arc.typeid IN (' . GetSonIds($typeid) . ',' . $CrossID . ')';
                }
            }
        }
        //频道ID
        if (preg_match('#spec#i', $listtype)) {
            $channelid == -1;
        }
        if (!empty($channelid)) {
            $orwheres[] = " And arc.channel = '{$channelid}' ";
        }
        if (!empty($noflag)) {
            if (!preg_match('#,#', $noflag)) {
                $orwheres[] = " FIND_IN_SET('{$noflag}', arc.flag)<1 ";
            } else {
                $noflags = explode(',', $noflag);
                foreach ($noflags as $noflag) {
                    if (trim($noflag) == '') {
                        continue;
                    }
                    $orwheres[] = " FIND_IN_SET('{$noflag}', arc.flag)<1 ";
                }
            }
        }
        $orwheres[] = ' arc.arcrank > -1 ';
        //由于这个条件会导致缓存功能失去意义,因此取消
        //if($arcid!=0) $orwheres[] = " arc.id<>'$arcid' ";
    }
    //文档排序的方式
    $ordersql = '';
    if ($orderby == 'hot' || $orderby == 'click') {
        $ordersql = " ORDER BY arc.click {$orderWay}";
    } else {
        if ($orderby == 'sortrank' || $orderby == 'pubdate') {
            $ordersql = " ORDER BY arc.sortrank {$orderWay}";
        } else {
            if ($orderby == 'id') {
                $ordersql = "  ORDER BY arc.id {$orderWay}";
            } else {
                if ($orderby == 'near') {
                    $ordersql = " ORDER BY ABS(arc.id - " . $arcid . ")";
                } else {
                    if ($orderby == 'lastpost') {
                        $ordersql = "  ORDER BY arc.lastpost {$orderWay}";
                    } else {
                        if ($orderby == 'scores') {
                            $ordersql = "  ORDER BY arc.scores {$orderWay}";
                        } else {
                            if ($orderby == 'goodpost') {
                                $ordersql = " order by arc.goodpost {$orderWay}";
                            } else {
                                if ($orderby == 'badpost') {
                                    $ordersql = " order by arc.badpost {$orderWay}";
                                } else {
                                    if ($orderby == 'rand') {
                                        $ordersql = "  ORDER BY rand()";
                                    } else {
                                        $ordersql = " ORDER BY arc.sortrank {$orderWay}";
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    //limit条件
    $limit = trim(preg_replace('#limit#is', '', $limit));
    if ($limit != '') {
        $limitsql = " LIMIT {$limit} ";
        $limitarr = explode(',', $limit);
        $line = isset($limitarr[1]) ? $limitarr[1] : $line;
    } else {
        $limitsql = " LIMIT 0,{$line} ";
    }
    $orwhere = '';
    if (isset($orwheres[0])) {
        $orwhere = join(' And ', $orwheres);
        $orwhere = preg_replace("#^ And#is", '', $orwhere);
        $orwhere = preg_replace("#And[ ]{1,}And#is", 'And ', $orwhere);
    }
    if ($orwhere != '') {
        $orwhere = " WHERE {$orwhere} ";
    }
    //获取附加表信息
    $addfield = trim($ctag->GetAtt('addfields'));
    $addfieldsSql = '';
    $addfieldsSqlJoin = '';
    if ($addfield != '' && !empty($channelid)) {
        $row = $dsql->GetOne("SELECT addtable FROM `#@__channeltype` WHERE id='{$channelid}' ");
        if (isset($row['addtable']) && trim($row['addtable']) != '') {
            $addtable = trim($row['addtable']);
            $addfields = explode(',', $addfield);
            $row['addtable'] = trim($row['addtable']);
            $addfieldsSql = ",addf." . join(',addf.', $addfields);
            $addfieldsSqlJoin = " LEFT JOIN `{$addtable}` addf ON addf.aid = arc.id ";
        }
    }
    $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,\r\n        tp.namerule2,tp.ispart,tp.moresite,tp.siteurl,tp.sitepath\r\n        {$addfieldsSql}\r\n        FROM `{$maintable}` arc LEFT JOIN `#@__arctype` tp on arc.typeid=tp.id\r\n        {$addfieldsSqlJoin}\r\n        {$orwhere} {$ordersql} {$limitsql}";
    //统一hash
    $taghash = md5(serialize($ctag) . $typeid);
    $needSaveCache = true;
    //进行tagid的默认处理
    if ($pagesize > 0) {
        $tagid = AttDef($tagid, 'tag' . $taghash);
    }
    if ($idlist != '' || $GLOBALS['_arclistEnv'] == 'index' || $cfg_index_cache == 0) {
        $needSaveCache = false;
    } else {
        $idlist = GetArclistCache($taghash);
        if ($idlist != '') {
            $needSaveCache = false;
        }
        //如果使用的是内容缓存,直接返回结果
        if ($cfg_cache_type == 'content' && $idlist != '') {
            $idlist = $idlist == 0 ? '' : $idlist;
            return $idlist;
        }
    }
    //指定了id或使用缓存中的id
    if ($idlist != '') {
        $query = "SELECT arc.*,tp.typedir,tp.typename,tp.corank,tp.isdefault,tp.defaultname,tp.namerule,tp.namerule2,tp.ispart,\r\n            tp.moresite,tp.siteurl,tp.sitepath\r\n            {$addfieldsSql}\r\n             FROM `{$maintable}` arc left join `#@__arctype` tp on arc.typeid=tp.id\r\n             {$addfieldsSqlJoin}\r\n          WHERE arc.id in({$idlist}) {$ordersql} ";
    }
    // 好评差评缓存更新
    if ($cfg_digg_update > 0) {
        if ($orderby == 'goodpost' || $orderby == 'badpost') {
            $t1 = ExecTime();
            $postsql = "SELECT arc.id,arc.goodpost,arc.badpost,arc.scores\r\n\t\t\t\tFROM `{$maintable}` arc\r\n\t\t\t\t{$orwhere} {$ordersql} {$limitsql}";
            if ($idlist != '') {
                $postsql = "SELECT arc.id,arc.goodpost,arc.badpost,arc.scores\r\n\t\t\t\t\t FROM `{$maintable}` arc \r\n\t\t\t\t  WHERE arc.id in({$idlist}) {$ordersql} ";
            }
            $dsql->SetQuery($query);
            $dsql->Execute('lit');
            while ($row = $dsql->GetArray('lit')) {
                $prefix = 'diggCache';
                $key = 'aid-' . $row['id'];
                $cacherow = GetCache($prefix, $key);
                $setsql = array();
                if (!empty($cacherow['scores']) && $cacherow['scores'] != $row['scores']) {
                    $setsql[] = "scores = {$cacherow['scores']}";
                }
                if (!empty($cacherow['goodpost']) && $cacherow['goodpost'] != $row['goodpost']) {
                    $setsql[] = "goodpost = {$cacherow['goodpost']}";
                }
                if (!empty($cacherow['badpost']) && $cacherow['badpost'] != $row['badpost']) {
                    $setsql[] = "badpost = {$cacherow['badpost']}";
                }
                $setsql = implode(',', $setsql);
                $sql = "UPDATE `{$maintable}` SET {$setsql} WHERE id='{$row['id']}'";
                if (!empty($setsql)) {
                    $dsql->ExecuteNoneQuery($sql);
                }
            }
            //echo ExecTime()-$t1;
        }
    }
    $dsql->SetQuery($query);
    $dsql->Execute('al');
    //$row = $dsql->GetArray("al");
    $artlist = '';
    if ($pagesize > 0) {
        $artlist .= "    <div id='{$tagid}'>\r\n";
    }
    if ($col > 1) {
        $artlist = "<table width='{$tablewidth}' border='0' cellspacing='0' cellpadding='0'>\r\n";
    }
    $dtp2 = new DedeTagParse();
    $dtp2->SetNameSpace('field', '[', ']');
    $dtp2->LoadString($innertext);
    $GLOBALS['autoindex'] = 0;
    $ids = array();
    $orderWeight = array();
    for ($i = 0; $i < $line; $i++) {
        if ($col > 1) {
            $artlist .= "<tr>\r\n";
        }
        for ($j = 0; $j < $col; $j++) {
            if ($col > 1) {
                $artlist .= "    <td width='{$colWidth}'>\r\n";
            }
            if ($row = $dsql->GetArray("al")) {
                $ids[] = $row['id'];
                //处理一些特殊字段
                $row['info'] = $row['infos'] = cn_substr($row['description'], $infolen);
                $row['id'] = $row['id'];
                if ($row['corank'] > 0 && $row['arcrank'] == 0) {
                    $row['arcrank'] = $row['corank'];
                }
                $row['filename'] = $row['arcurl'] = GetFileUrl($row['id'], $row['typeid'], $row['senddate'], $row['title'], $row['ismake'], $row['arcrank'], $row['namerule'], $row['typedir'], $row['money'], $row['filename'], $row['moresite'], $row['siteurl'], $row['sitepath']);
                $row['typeurl'] = GetTypeUrl($row['typeid'], $row['typedir'], $row['isdefault'], $row['defaultname'], $row['ispart'], $row['namerule2'], $row['moresite'], $row['siteurl'], $row['sitepath']);
                if ($row['litpic'] == '-' || $row['litpic'] == '') {
                    $row['litpic'] = $GLOBALS['cfg_cmspath'] . '/images/defaultpic.gif';
                }
                if (!preg_match("#^http:\\/\\/#i", $row['litpic']) && $GLOBALS['cfg_multi_site'] == 'Y') {
                    $row['litpic'] = $GLOBALS['cfg_mainsite'] . $row['litpic'];
                }
                $row['picname'] = $row['litpic'];
                $row['stime'] = GetDateMK($row['pubdate']);
                $row['typelink'] = "<a href='" . $row['typeurl'] . "'>" . $row['typename'] . "</a>";
                $row['image'] = "<img src='" . $row['picname'] . "' border='0' width='{$imgwidth}' height='{$imgheight}' alt='" . preg_replace("#['><]#", "", $row['title']) . "'>";
                $row['imglink'] = "<a href='" . $row['filename'] . "'>" . $row['image'] . "</a>";
                $row['fulltitle'] = $row['title'];
                $row['title'] = cn_substr($row['title'], $titlelen);
                if ($row['color'] != '') {
                    $row['title'] = "<font color='" . $row['color'] . "'>" . $row['title'] . "</font>";
                }
                if (preg_match('#b#', $row['flag'])) {
                    $row['title'] = "<strong>" . $row['title'] . "</strong>";
                }
                //$row['title'] = "<b>".$row['title']."</b>";
                $row['textlink'] = "<a href='" . $row['filename'] . "'>" . $row['title'] . "</a>";
                $row['plusurl'] = $row['phpurl'] = $GLOBALS['cfg_phpurl'];
                $row['memberurl'] = $GLOBALS['cfg_memberurl'];
                $row['templeturl'] = $GLOBALS['cfg_templeturl'];
                if (is_array($dtp2->CTags)) {
                    foreach ($dtp2->CTags as $k => $ctag) {
                        if ($ctag->GetName() == 'array') {
                            //传递整个数组,在runphp模式中有特殊作用
                            $dtp2->Assign($k, $row);
                        } else {
                            if (isset($row[$ctag->GetName()])) {
                                $dtp2->Assign($k, $row[$ctag->GetName()]);
                            } else {
                                $dtp2->Assign($k, '');
                            }
                        }
                    }
                    $GLOBALS['autoindex']++;
                }
                if ($pagesize > 0) {
                    if ($GLOBALS['autoindex'] <= $pagesize) {
                        $liststr = $dtp2->GetResult();
                        $artlist .= $liststr . "\r\n";
                    } else {
                        $artlist .= "";
                        $orderWeight[] = array('weight' => $row['weight'], 'arclist' => '');
                    }
                } else {
                    $liststr = $dtp2->GetResult();
                    $artlist .= $liststr . "\r\n";
                }
                $orderWeight[] = array('weight' => $row['weight'], 'arclist' => $liststr);
            } else {
                $artlist .= '';
            }
            // 进行判断,如果启用排序则内容输出为重新排序后的内容
            // var_dump($isweight=='y' && count($orderWeight) == $line);
            $isweight = strtolower($isweight);
            if ($isweight == 'y') {
                $artlist = '';
                $orderWeight = list_sort_by($orderWeight, 'weight', 'asc');
                foreach ($orderWeight as $vv) {
                    $artlist .= $vv['arclist'];
                }
            }
            if ($col > 1) {
                $artlist .= "    </td>\r\n";
            }
        }
        //Loop Col
        if ($col > 1) {
            $i += $col - 1;
        }
        if ($col > 1) {
            $artlist .= "    </tr>\r\n";
        }
    }
    //loop line
    if ($col > 1) {
        $artlist .= "    </table>\r\n";
    }
    $dsql->FreeResult("al");
    $idsstr = join(',', $ids);
    //分页特殊处理
    if ($pagesize > 0) {
        $artlist .= "    </div>\r\n";
        $row = $dsql->GetOne("SELECT tagid FROM #@__arcmulti WHERE tagid='{$tagid}'");
        $uptime = time();
        $attstr = addslashes(serialize($attarray));
        $innertext = addslashes($innertext);
        if (!is_array($row)) {
            $query = "\r\n          INSERT INTO #@__arcmulti(tagid,uptime,innertext,pagesize,arcids,ordersql,addfieldsSql,addfieldsSqlJoin,attstr)\r\n          VALUES('{$tagid}','{$uptime}','{$innertext}','{$pagesize}','{$idsstr}','{$ordersql}','{$addfieldsSql}','{$addfieldsSqlJoin}','{$attstr}');\r\n        ";
            $dsql->ExecuteNoneQuery($query);
        } else {
            $query = "UPDATE `#@__arcmulti`\r\n           SET\r\n           uptime='{$uptime}',\r\n           innertext='{$innertext}',\r\n           pagesize='{$pagesize}',\r\n           arcids='{$idsstr}',\r\n           ordersql='{$ordersql}',\r\n           addfieldsSql='{$addfieldsSql}',\r\n           addfieldsSqlJoin='{$addfieldsSqlJoin}',\r\n           attstr='{$attstr}'\r\n           WHERE tagid='{$tagid}'\r\n        ";
            $dsql->ExecuteNoneQuery($query);
        }
    }
    //保存ID缓存
    if ($needSaveCache) {
        if ($idsstr == '') {
            $idsstr = '0';
        }
        if ($cfg_cache_type == 'content' && $idsstr != '0') {
            $idsstr = addslashes($artlist);
        }
        $inquery = "INSERT INTO `#@__arccache`(`md5hash`,`uptime`,`cachedata`) VALUES ('" . $taghash . "','" . time() . "', '{$idsstr}'); ";
        $dsql->ExecuteNoneQuery("DELETE FROM `#@__arccache` WHERE md5hash='" . $taghash . "' ");
        $dsql->ExecuteNoneQuery($inquery);
    }
    return $artlist;
}
Exemplo n.º 16
0
 /**
  * 获取分类 (转成多维数组)
  *@param  array   id,type =0  包含自身  type=1  不包含自身
  *@return  array  多维数组
  *@create 2015-2-4
  *@author  lck
  */
 public function get_cate($id, $type = 0)
 {
     $where = array();
     //包含自身
     if ($id != 0 && $type == 0) {
         $where['fullpath'] = array('like', "%{$id}%");
     }
     //不包含本身
     if ($id != 0 && $type == 1) {
         $where['fullpath'] = array('like', "%" . $id . "," . "%");
     }
     $list = $this->where($where)->order('sort asc')->select();
     foreach ($list as &$val) {
         $val['deep'] = count(explode(',', $val['fullpath']));
     }
     //计算深度
     $list_arr = list_sort_by($list, 'deep', 'asc');
     $list_last = end($list_arr);
     $deep_max = $list_last['deep'];
     $deep_min = $list_arr[0]['deep'];
     // 数组横向转纵向
     for ($i = $deep_max; $i >= $deep_min; $i--) {
         foreach ($list as &$val) {
             if ($val['deep'] == $i) {
                 $pid = end(explode(',', $val['path']));
                 foreach ($list as &$cat) {
                     if ($cat['id'] == $pid) {
                         if (!is_array($cat['child'])) {
                             $cat['child'] = array();
                             array_push($cat['child'], $val);
                         } else {
                             array_push($cat['child'], $val);
                         }
                     }
                 }
             }
         }
     }
     // 取得最上层的数据
     $arr = array();
     foreach ($list as $key => $vall) {
         if ($vall['deep'] == $deep_min) {
             array_push($arr, $vall);
         }
     }
     $list = NULL;
     return $arr;
 }