예제 #1
0
 /**
  * 更新栏目缓存
  * array(
  *     '栏目ID' => array(
  *                     ...栏目信息
  *                     ...模型表名称
  *                 ),
  * );
  */
 public function cacheAction($show = 0, $site_id = 0)
 {
     $this->category->repair();
     //递归修复栏目数据
     $site_id = $site_id ? $site_id : ($_GET['siteid'] ? $_GET['siteid'] : $this->siteid);
     $model = $this->get_model('content', $site_id);
     $data = $this->category->getData($site_id);
     //数据库查询最新数据
     $siteid = $this->category->getSiteId($site_id);
     $category = $category_dir = $count = array();
     foreach ($data as $t) {
         $catid = $t['catid'];
         $category[$catid] = $t;
         if ($t['typeid'] == 1) {
             $category[$catid]['tablename'] = $model[$t['modelid']]['tablename'];
             $category[$catid]['modelname'] = $model[$t['modelid']]['modelname'];
         }
         $category[$catid]['arrchilds'] = $catid;
         //所有子栏目集,默认当前栏目ID
         if ($t['typeid'] != 3) {
             if ($t['child']) {
                 $category[$catid]['arrchilds'] = $this->category->child($catid) . $catid;
             }
             //统计数据
             $count[$catid]['items'] = (int) $this->content->_count($site_id, 'catid IN (' . $category[$catid]['arrchilds'] . ') and `status`<>0');
             if ($site_id == $siteid) {
                 $category[$catid]['items'] = $count[$catid]['items'];
                 $this->category->update(array('items' => $count[$catid]['items']), 'catid=' . $catid);
             }
         }
         //把预定义的 HTML 实体转换为字符
         $category[$catid]['content'] = htmlspecialchars_decode($category[$catid]['content']);
         //转换setting
         $category[$catid]['setting'] = string2array($category[$catid]['setting']);
         //更新分页数量
         if (empty($t['pagesize'])) {
             $pcat = $this->category->getParentData($catid);
             $category[$catid]['pagesize'] = $pcat['pagesize'] ? $pcat['pagesize'] : $this->site['SITE_SEARCH_PAGE'];
             $this->category->update(array('pagesize' => $category[$catid]['pagesize']), 'catid=' . $catid);
         }
     }
     //更新URL与栏目模型id集合
     foreach ($data as $t) {
         $category[$t['catid']]['url'] = $url = $this->getCaturl($t);
         $this->category->update(array('url' => $url), 'catid=' . $t['catid']);
         $category_dir[$t['catdir']] = $t['catid'];
         if ($t['child'] == 0) {
             $category[$t['catid']]['arrmodelid'][] = $t['modelid'];
         } else {
             $category[$t['catid']]['arrmodelid'] = array();
             $ids = _catposids($t['catid'], null, $category);
             $ids = explode(',', $ids);
             foreach ($ids as $id) {
                 if ($id && $id != $t['catid']) {
                     $category[$t['catid']]['arrmodelid'][] = $category[$id]['modelid'];
                 }
             }
         }
         $category[$t['catid']]['arrmodelid'] = array_unique($category[$t['catid']]['arrmodelid']);
     }
     //保存到缓存文件
     if ($site_id == $siteid) {
         $this->cache->set('category_' . $siteid, $category);
     } else {
         $this->cache->set('category_' . $site_id, $count);
     }
     $this->cache->set('category_dir_' . $site_id, $category_dir);
     $show or $this->adminMsg(lang('a-update'), url('admin/category/index'), 3, 1, 1);
 }
예제 #2
0
/**
 * 栏目下级ID集合
 * @param  $catid
 * @param  $catids
 * @return string 返回栏目所有下级ID
 */
function _catposids($catid, $catids = '', $category)
{
    if (empty($catid)) {
        return false;
    }
    $row = $category[$catid];
    $catids = $catid . ',';
    if ($row['child'] && $row['arrchildid']) {
        $id = explode(',', $row['arrchildid']);
        foreach ($id as $t) {
            $catids .= _catposids($t, $catids, $category);
        }
    }
    return $catids;
}