function categorycache($cachename, $identifier = '')
{
    global $_G;
    $cachearray = array('categorysort', 'sortlist', 'channellist', 'arealist', 'usergroup');
    $cachename = in_array($cachename, $cachearray) ? $cachename : '';
    $sortdatalist = $areadatalist = $channeldatalist = array();
    if ($cachename == 'categorysort') {
        $sortlist = $templatedata = $stemplatedata = $ptemplatedata = $btemplatedata = $template = array();
        $query = DB::query("SELECT t.sortid AS sortid, tt.optionid, tt.title, tt.type, tt.unit, tt.rules, tt.identifier, tt.description, tv.required, tv.unchangeable, tv.search, tv.subjectshow, tv.visitedshow, tv.orderbyshow, tt.expiration, tt.protect\n\t\t\tFROM " . DB::table('category_sort') . " t\n\t\t\tLEFT JOIN " . DB::table('category_sortvar') . " tv ON t.sortid=tv.sortid\n\t\t\tLEFT JOIN " . DB::table('category_sortoption') . " tt ON tv.optionid=tt.optionid\n\t\t\tWHERE tv.available='1'\n\t\t\tORDER BY tv.displayorder");
        while ($data = DB::fetch($query)) {
            $data['rules'] = unserialize($data['rules']);
            $sortid = $data['sortid'];
            $optionid = $data['optionid'];
            $sortlist[$sortid][$optionid] = array('title' => dhtmlspecialchars($data['title']), 'type' => dhtmlspecialchars($data['type']), 'unit' => dhtmlspecialchars($data['unit']), 'identifier' => dhtmlspecialchars($data['identifier']), 'description' => dhtmlspecialchars($data['description']), 'required' => intval($data['required']), 'unchangeable' => intval($data['unchangeable']), 'search' => intval($data['search']), 'subjectshow' => intval($data['subjectshow']), 'visitedshow' => intval($data['visitedshow']), 'orderbyshow' => intval($data['orderbyshow']), 'expiration' => intval($data['expiration']), 'protect' => unserialize($data['protect']));
            if (in_array($data['type'], array('select', 'checkbox', 'radio', 'intermediary'))) {
                if ($data['rules']['choices']) {
                    $choices = array();
                    foreach (explode("\n", $data['rules']['choices']) as $item) {
                        list($index, $choice) = explode('=', $item);
                        $choices[trim($index)] = trim($choice);
                    }
                    $sortlist[$sortid][$optionid]['choices'] = $choices;
                } else {
                    $sortlist[$sortid][$optionid]['choices'] = array();
                }
                if ($data['type'] == 'select') {
                    $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : 108;
                }
            } elseif (in_array($data['type'], array('text', 'textarea', 'calendar'))) {
                $sortlist[$sortid][$optionid]['maxlength'] = intval($data['rules']['maxlength']);
                if ($data['type'] == 'textarea') {
                    $sortlist[$sortid][$optionid]['rowsize'] = $data['rules']['rowsize'] ? intval($data['rules']['rowsize']) : 20;
                    $sortlist[$sortid][$optionid]['colsize'] = $data['rules']['colsize'] ? intval($data['rules']['colsize']) : 10;
                } else {
                    $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : '';
                }
                if (in_array($data['type'], array('text', 'textarea'))) {
                    $sortlist[$sortid][$optionid]['defaultvalue'] = $data['rules']['defaultvalue'];
                }
            } elseif ($data['type'] == 'image') {
                $sortlist[$sortid][$optionid]['maxwidth'] = intval($data['rules']['maxwidth']);
                $sortlist[$sortid][$optionid]['maxheight'] = intval($data['rules']['maxheight']);
                $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : '';
            } elseif (in_array($data['type'], array('number', 'range'))) {
                $sortlist[$sortid][$optionid]['inputsize'] = $data['rules']['inputsize'] ? intval($data['rules']['inputsize']) : '';
                $sortlist[$sortid][$optionid]['maxnum'] = intval($data['rules']['maxnum']);
                $sortlist[$sortid][$optionid]['minnum'] = intval($data['rules']['minnum']);
                if ($data['rules']['searchtxt']) {
                    $sortlist[$sortid][$optionid]['searchtxt'] = explode(',', $data['rules']['searchtxt']);
                }
                $sortlist[$sortid][$optionid]['defaultvalue'] = $data['rules']['defaultvalue'];
            } elseif ($data['type'] == 'phone') {
                $sortlist[$sortid][$optionid]['numbercheck'] = $data['rules']['numbercheck'] ? intval($data['rules']['numbercheck']) : 0;
                if ($data['rules']['numberrange']) {
                    foreach (explode("\n", $data['rules']['numberrange']) as $num) {
                        $numchoices[] = $num;
                    }
                    $sortlist[$sortid][$optionid]['numberrange'] = $numchoices;
                }
            }
        }
        $query = DB::query("SELECT sortid, description, template, stemplate, sttemplate, ptemplate, btemplate, vtemplate, ntemplate, rtemplate, perpage FROM " . DB::table('category_sort') . "");
        while ($data = DB::fetch($query)) {
            $templatedata[$data['sortid']] = str_replace('"', '\\"', $data['template']);
            $stemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['stemplate']);
            $sttemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['sttemplate']);
            $ptemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['ptemplate']);
            $btemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['btemplate']);
            $vtemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['vtemplate']);
            $ntemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['ntemplate']);
            $rtemplatedata[$data['sortid']] = str_replace('"', '\\"', $data['rtemplate']);
            $perpage[$data['sortid']] = $data['perpage'];
        }
        $data['sortoption'] = $data['template'] = array();
        foreach ($sortlist as $sortid => $option) {
            $template['viewthread'] = $templatedata[$sortid];
            $template['subject'] = $stemplatedata[$sortid];
            $template['subjecttext'] = $sttemplatedata[$sortid];
            $template['post'] = $ptemplatedata[$sortid];
            $template['visit'] = $vtemplatedata[$sortid];
            $template['neighborhood'] = $ntemplatedata[$sortid];
            $template['recommend'] = $rtemplatedata[$sortid];
            $template['perpage'] = $perpage[$sortid];
            $blocktemplate = unserialize(stripslashes($btemplatedata[$sortid]));
            $templateblock = array();
            if ($blocktemplate) {
                foreach ($blocktemplate as $stylename => $style) {
                    if (preg_match('/^(.*?)(\\[loop)/is', $style, $match)) {
                        $templateblock[$stylename]['header'] = trim($match[1]);
                    }
                    if (strrpos($style, '[/loop]')) {
                        $templateblock[$stylename]['footer'] = substr($style, strrpos($style, '[/loop]') + 8);
                    }
                    $match = array();
                    if (preg_match('/\\[loop\\](.*?)\\[\\/loop]/is', $style, $match)) {
                        $templateblock[$stylename]['loop'] = trim($match[1]);
                    } else {
                        $templateblock[$stylename]['loop'] = $style;
                    }
                }
            }
            save_syscache('category_option_' . $sortid, $option);
            save_syscache('category_template_' . $sortid, $template);
            save_syscache('category_template_block_' . $sortid, $templateblock);
        }
    } elseif ($cachename == 'sortlist') {
        $query = DB::query("SELECT sortid, cid, name, expiration, imgnum, threads FROM " . DB::table('category_sort') . " ORDER BY displayorder");
        while ($data = DB::fetch($query)) {
            $sortdatalist[$data['cid']][$data['sortid']] = array('name' => $data['name'], 'expiration' => $data['expiration'], 'imgnum' => $data['imgnum'], 'cid' => $data['cid'], 'threads' => $data['threads']);
        }
        $query = DB::query("SELECT cid, identifier FROM " . DB::table('category_channel') . " ORDER BY displayorder");
        while ($data = DB::fetch($query)) {
            save_syscache('category_sortlist_' . $data['identifier'], $sortdatalist[$data['cid']]);
        }
    } elseif ($cachename == 'arealist') {
        $query = DB::query("SELECT aid, aup, cid, type, title FROM " . DB::table('category_area') . " ORDER BY displayorder");
        while ($data = DB::fetch($query)) {
            if ($data['type'] == 'city') {
                $areadatalist[$data['cid']][$data['type']][$data['aid']] = $data['title'];
            } else {
                $areadatalist[$data['cid']][$data['type']][$data['aup']][$data['aid']] = $data['title'];
            }
        }
        $query = DB::query("SELECT cid, identifier FROM " . DB::table('category_channel') . " ORDER BY displayorder");
        while ($data = DB::fetch($query)) {
            save_syscache('category_arealist_' . $data['identifier'], $areadatalist[$data['cid']]);
        }
    } elseif ($cachename == 'channellist') {
        $query = DB::query("SELECT cid, title, identifier, logo, status, managegid, listmode, mapinfo, imageinfo, seoinfo FROM " . DB::table('category_channel') . " ORDER BY displayorder");
        while ($data = DB::fetch($query)) {
            $mapinfo = unserialize($data['mapinfo']);
            $seoinfo = unserialize($data['seoinfo']);
            $channeldatalist[$data['identifier']] = array('title' => $data['title'], 'cid' => $data['cid'], 'logo' => get_logoimg($data['logo']), 'status' => $data['status'], 'listmode' => $data['listmode'], 'mapkey' => $mapinfo['key'], 'managegid' => unserialize($data['managegid']), 'imageinfo' => unserialize($data['imageinfo']), 'seoinfo' => $seoinfo);
        }
        save_syscache('category_channellist', $channeldatalist);
    } elseif ($cachename == 'usergroup') {
        $query = DB::query("SELECT gid, title, type, icon, allowpost, postdayper, allowpush, pushdayper, allowrecommend, recommenddayper, allowhighlight, highlightdayper FROM " . DB::table('category_' . $identifier . '_usergroup') . " ORDER BY gid");
        while ($data = DB::fetch($query)) {
            $usergrouplist[$data['gid']] = $data;
            save_syscache('category_group_' . $identifier . '_' . $data['gid'], $data);
        }
        save_syscache('category_usergrouplist_' . $identifier, $usergrouplist);
    }
}
Exemple #2
0
$actionarray = array('list', 'member');
$action = $_G['gp_action'] && in_array($_G['gp_action'], $actionarray) ? $_G['gp_action'] : 'list';
$districtlist = array();
if ($arealist) {
    foreach ($arealist['district'] as $districtarray) {
        foreach ($districtarray as $did => $district) {
            $districtlist[$did] = $district;
        }
    }
}
require_once libfile('function/category');
$_G['category_threadlist'] = $threadids = $memberlist = array();
$isgroupadmin = 0;
if (!empty($gid)) {
    $usergroup = DB::fetch_first("SELECT * FROM " . DB::table('category_' . $modidentifier . '_usergroup') . " WHERE gid='{$gid}'");
    $usergroup['banner'] = $usergroup['banner'] ? get_logoimg($usergroup['banner']) : '';
    $navtitle = $usergroup['title'] . ' - ';
    $query = DB::query("SELECT cm.threads, m.uid, m.username FROM " . DB::table('category_' . $modidentifier . '_member') . " cm\n\t\t\tLEFT JOIN " . DB::table('common_member') . " m ON cm.uid=m.uid\n\t\t\tWHERE cm.groupid='{$gid}' ORDER BY cm.threads DESC LIMIT 5");
    while ($member = DB::fetch($query)) {
        $memberlist[$member['uid']]['username'] = $member['username'];
        $memberlist[$member['uid']]['avatar'] = category_uc_avatar($member['uid'], 'small');
        $memberlist[$member['uid']]['threads'] = $member['threads'];
    }
    $isgroupadmin = $_G['uid'] == $usergroup['manageuid'] || $channel['managegid'][$_G['groupid']] ? 1 : 0;
    if ($action == 'list') {
        loadcache(array('category_option_' . $sortid, 'category_template_' . $sortid));
        $sortoptionarray = $_G['cache']['category_option_' . $sortid];
        $templatearray = $_G['cache']['category_template_' . $sortid]['subject'];
        $rtemplatearray = $_G['cache']['category_template_' . $sortid]['recommend'];
        $recommendlist = recommendsort($sortid, $sortoptionarray, $gid, $rtemplatearray, $districtlist, $modurl);
        $page = $_G['page'];