Ejemplo n.º 1
0
function build_cache_styles()
{
    global $_G;
    $stylevars = $styledata = array();
    $defaultstyleid = $_G['setting']['styleid'];
    foreach (C::t('common_stylevar')->range() as $var) {
        $stylevars[$var['styleid']][$var['variable']] = $var['substitute'];
    }
    foreach (C::t('common_style')->fetch_all_data(true) as $data) {
        $data['tpldir'] = $data['directory'];
        $data = array_merge($data, (array) $stylevars[$data['styleid']]);
        $datanew = array();
        $data['imgdir'] = $data['imgdir'] ? $data['imgdir'] : STATICURL . 'image/common';
        $data['styleimgdir'] = $data['styleimgdir'] ? $data['styleimgdir'] : $data['imgdir'];
        foreach ($data as $k => $v) {
            if (substr($k, -7, 7) == 'bgcolor') {
                $newkey = substr($k, 0, -7) . 'bgcode';
                $datanew[$newkey] = setcssbackground($data, $k);
            }
        }
        $data = array_merge($data, $datanew);
        if (strstr($data['boardimg'], ',')) {
            $flash = explode(",", $data['boardimg']);
            $flash[0] = trim($flash[0]);
            $flash[0] = preg_match('/^http:\\/\\//i', $flash[0]) ? $flash[0] : $data['styleimgdir'] . '/' . $flash[0];
            $data['boardlogo'] = "<embed src=\"" . $flash[0] . "\" width=\"" . trim($flash[1]) . "\" height=\"" . trim($flash[2]) . "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed>";
        } else {
            $data['boardimg'] = preg_match('/^http:\\/\\//i', $data['boardimg']) ? $data['boardimg'] : $data['styleimgdir'] . '/' . $data['boardimg'];
            $data['boardlogo'] = "<img src=\"{$data['boardimg']}\" alt=\"" . $_G['setting']['bbname'] . "\" border=\"0\" />";
        }
        $data['bold'] = $data['nobold'] ? 'normal' : 'bold';
        $contentwidthint = intval($data['contentwidth']);
        $contentwidthint = $contentwidthint ? $contentwidthint : 600;
        if ($data['extstyle']) {
            list($data['extstyle'], $data['defaultextstyle']) = explode('|', $data['extstyle']);
            $extstyle = explode("\t", $data['extstyle']);
            $data['extstyle'] = array();
            foreach ($extstyle as $dir) {
                if (file_exists($extstylefile = DISCUZ_ROOT . $data['tpldir'] . '/style/' . $dir . '/style.css')) {
                    if ($data['defaultextstyle'] == $dir) {
                        $data['defaultextstyle'] = $data['tpldir'] . '/style/' . $dir;
                    }
                    $content = file_get_contents($extstylefile);
                    if (preg_match('/\\[name\\](.+?)\\[\\/name\\]/i', $content, $r1) && preg_match('/\\[iconbgcolor](.+?)\\[\\/iconbgcolor]/i', $content, $r2)) {
                        $data['extstyle'][] = array($data['tpldir'] . '/style/' . $dir, $r1[1], $r2[1]);
                    }
                }
            }
        }
        $data['verhash'] = random(3);
        $styledata[] = $data;
    }
    foreach ($styledata as $data) {
        savecache('style_' . $data['styleid'], $data);
        if ($defaultstyleid == $data['styleid']) {
            savecache('style_default', $data);
        }
        writetocsscache($data);
    }
}
Ejemplo n.º 2
0
function updatecache($cachename = '')
{
    global $db, $bbname, $tablepre, $maxbdays;
    static $cachescript = array('settings' => array('settings'), 'forums' => array('forums'), 'icons' => array('icons'), 'ranks' => array('ranks'), 'usergroups' => array('usergroups'), 'request' => array('request'), 'medals' => array('medals'), 'magics' => array('magics'), 'topicadmin' => array('modreasons'), 'archiver' => array('advs_archiver'), 'register' => array('advs_register'), 'faqs' => array('faqs'), 'secqaa' => array('secqaa'), 'censor' => array('censor'), 'ipbanned' => array('ipbanned'), 'smilies' => array('smilies_js'), 'index' => array('announcements', 'onlinelist', 'forumlinks', 'advs_index'), 'forumdisplay' => array('smilies', 'announcements_forum', 'globalstick', 'floatthreads', 'forums', 'icons', 'onlinelist', 'advs_forumdisplay'), 'viewthread' => array('smilies', 'smileytypes', 'forums', 'usergroups', 'ranks', 'bbcodes', 'smilies', 'advs_viewthread', 'tags_viewthread', 'custominfo', 'groupicon'), 'post' => array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'icons'), 'profilefields' => array('fields_required', 'fields_optional'), 'viewpro' => array('fields_required', 'fields_optional', 'custominfo'), 'bbcodes' => array('bbcodes', 'smilies', 'smileytypes'));
    if ($maxbdays) {
        $cachescript['birthdays'] = array('birthdays');
        $cachescript['index'][] = 'birthdays_index';
    }
    $updatelist = empty($cachename) ? array_values($cachescript) : (is_array($cachename) ? array('0' => $cachename) : array(array('0' => $cachename)));
    $updated = array();
    foreach ($updatelist as $value) {
        foreach ($value as $cname) {
            if (empty($updated) || !in_array($cname, $updated)) {
                $updated[] = $cname;
                getcachearray($cname);
            }
        }
    }
    foreach ($cachescript as $script => $cachenames) {
        if (empty($cachename) || !is_array($cachename) && in_array($cachename, $cachenames) || is_array($cachename) && array_intersect($cachename, $cachenames)) {
            $cachedata = '';
            $query = $db->query("SELECT data FROM {$tablepre}caches WHERE cachename in(" . implodeids($cachenames) . ")");
            while ($data = $db->fetch_array($query)) {
                $cachedata .= $data['data'];
            }
            writetocache($script, $cachenames, $cachedata);
        }
    }
    if (!$cachename || $cachename == 'styles') {
        $stylevars = $styledata = $styleicons = array();
        $defaultstyleid = $db->result_first("SELECT value FROM {$tablepre}settings WHERE variable = 'styleid'");
        list(, $imagemaxwidth) = explode("\t", $db->result_first("SELECT value FROM {$tablepre}settings WHERE variable = 'zoomstatus'"));
        $imagemaxwidth = $imagemaxwidth ? $imagemaxwidth : 600;
        $imagemaxwidthint = intval($imagemaxwidth);
        $query = $db->query("SELECT sv.* FROM {$tablepre}stylevars sv LEFT JOIN {$tablepre}styles s ON s.styleid = sv.styleid AND (s.available=1 OR s.styleid='{$defaultstyleid}')");
        while ($var = $db->fetch_array($query)) {
            $stylevars[$var['styleid']][$var['variable']] = $var['substitute'];
        }
        $query = $db->query("SELECT s.*, t.directory AS tpldir FROM {$tablepre}styles s LEFT JOIN {$tablepre}templates t ON s.templateid=t.templateid WHERE s.available=1 OR s.styleid='{$defaultstyleid}'");
        while ($data = $db->fetch_array($query)) {
            $data = array_merge($data, $stylevars[$data['styleid']]);
            $datanew = array();
            $data['imgdir'] = $data['imgdir'] ? $data['imgdir'] : 'images/default';
            $data['styleimgdir'] = $data['styleimgdir'] ? $data['styleimgdir'] : $data['imgdir'];
            foreach ($data as $k => $v) {
                if (substr($k, -7, 7) == 'bgcolor') {
                    $newkey = substr($k, 0, -7) . 'bgcode';
                    $datanew[$newkey] = setcssbackground($data, $k);
                }
            }
            $data = array_merge($data, $datanew);
            $styleicons[$data['styleid']] = $data['menuhover'];
            if (strstr($data['boardimg'], ',')) {
                $flash = explode(",", $data['boardimg']);
                $flash[0] = trim($flash[0]);
                $flash[0] = preg_match('/^http:\\/\\//i', $flash[0]) ? $flash[0] : $data['styleimgdir'] . '/' . $flash[0];
                $data['boardlogo'] = "<embed src=\"" . $flash[0] . "\" width=\"" . trim($flash[1]) . "\" height=\"" . trim($flash[2]) . "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed>";
            } else {
                $data['boardimg'] = preg_match('/^http:\\/\\//i', $data['boardimg']) ? $data['boardimg'] : $data['styleimgdir'] . '/' . $data['boardimg'];
                $data['boardlogo'] = "<img src=\"{$data['boardimg']}\" alt=\"{$bbname}\" border=\"0\" />";
            }
            $data['bold'] = $data['nobold'] ? 'normal' : 'bold';
            $contentwidthint = intval($data['contentwidth']);
            $contentwidthint = $contentwidthint ? $contentwidthint : 600;
            if (substr(trim($data['contentwidth']), -1, 1) != '%') {
                if (substr(trim($imagemaxwidth), -1, 1) != '%') {
                    $data['imagemaxwidth'] = $imagemaxwidthint > $contentwidthint ? $contentwidthint : $imagemaxwidthint;
                } else {
                    $data['imagemaxwidth'] = intval($contentwidthint * $imagemaxwidthint / 100);
                }
            } else {
                if (substr(trim($imagemaxwidth), -1, 1) != '%') {
                    $data['imagemaxwidth'] = '%' . $imagemaxwidthint;
                } else {
                    $data['imagemaxwidth'] = ($imagemaxwidthint > $contentwidthint ? $contentwidthint : $imagemaxwidthint) . '%';
                }
            }
            $data['verhash'] = random(3);
            $styledata[] = $data;
        }
        foreach ($styledata as $data) {
            $data['styleicons'] = $styleicons;
            writetocache($data['styleid'], '', getcachevars($data, 'CONST'), 'style_');
            writetocsscache($data);
        }
    }
    if (!$cachename || $cachename == 'usergroups') {
        $query = $db->query("SELECT * FROM {$tablepre}usergroups u\r\n\t\t\t\t\tLEFT JOIN {$tablepre}admingroups a ON u.groupid=a.admingid");
        while ($data = $db->fetch_array($query)) {
            $ratearray = array();
            if ($data['raterange']) {
                foreach (explode("\n", $data['raterange']) as $rating) {
                    $rating = explode("\t", $rating);
                    $ratearray[$rating[0]] = array('min' => $rating[1], 'max' => $rating[2], 'mrpd' => $rating[3]);
                }
            }
            $data['raterange'] = $ratearray;
            $data['grouptitle'] = $data['color'] ? '<font color="' . $data['color'] . '">' . $data['grouptitle'] . '</font>' : $data['grouptitle'];
            $data['grouptype'] = $data['type'];
            $data['grouppublic'] = $data['system'] != 'private';
            $data['groupcreditshigher'] = $data['creditshigher'];
            $data['groupcreditslower'] = $data['creditslower'];
            unset($data['type'], $data['system'], $data['creditshigher'], $data['creditslower'], $data['color'], $data['groupavatar'], $data['admingid']);
            writetocache($data['groupid'], '', getcachevars($data), 'usergroup_');
        }
    }
    if (!$cachename || $cachename == 'admingroups') {
        $query = $db->query("SELECT * FROM {$tablepre}admingroups");
        while ($data = $db->fetch_array($query)) {
            writetocache($data['admingid'], '', getcachevars($data), 'admingroup_');
        }
    }
    if (!$cachename || $cachename == 'plugins') {
        $query = $db->query("SELECT pluginid, available, adminid, name, identifier, datatables, directory, copyright, modules FROM {$tablepre}plugins");
        while ($plugin = $db->fetch_array($query)) {
            $data = array_merge($plugin, array('modules' => array()), array('vars' => array()));
            $plugin['modules'] = unserialize($plugin['modules']);
            if (is_array($plugin['modules'])) {
                foreach ($plugin['modules'] as $module) {
                    $data['modules'][$module['name']] = $module;
                }
            }
            $queryvars = $db->query("SELECT variable, value FROM {$tablepre}pluginvars WHERE pluginid='{$plugin['pluginid']}'");
            while ($var = $db->fetch_array($queryvars)) {
                $data['vars'][$var['variable']] = $var['value'];
            }
            writetocache($plugin['identifier'], '', "\$_DPLUGIN['{$plugin['identifier']}'] = " . arrayeval($data), 'plugin_');
        }
    }
    if (!$cachename || $cachename == 'threadsorts') {
        $sortlist = $templatedata = array();
        $query = $db->query("SELECT t.typeid AS sortid, tt.optionid, tt.title, tt.type, tt.rules, tt.identifier, tt.description, tv.required, tv.unchangeable, tv.search\r\n\t\t\tFROM {$tablepre}threadtypes t\r\n\t\t\tLEFT JOIN {$tablepre}typevars tv ON t.typeid=tv.sortid\r\n\t\t\tLEFT JOIN {$tablepre}typeoptions tt ON tv.optionid=tt.optionid\r\n\t\t\tWHERE t.special='1' AND tv.available='1'\r\n\t\t\tORDER BY tv.displayorder");
        while ($data = $db->fetch_array($query)) {
            $data['rules'] = unserialize($data['rules']);
            $sortid = $data['sortid'];
            $optionid = $data['optionid'];
            $sortlist[$sortid][$optionid] = array('title' => dhtmlspecialchars($data['title']), 'type' => dhtmlspecialchars($data['type']), 'identifier' => dhtmlspecialchars($data['identifier']), 'description' => dhtmlspecialchars($data['description']), 'required' => intval($data['required']), 'unchangeable' => intval($data['unchangeable']), 'search' => intval($data['search']));
            if (in_array($data['type'], array('select', 'checkbox', 'radio'))) {
                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 {
                    $typelist[$sortid][$optionid]['choices'] = array();
                }
            } elseif (in_array($data['type'], array('text', 'textarea'))) {
                $sortlist[$sortid][$optionid]['maxlength'] = intval($data['rules']['maxlength']);
            } elseif ($data['type'] == 'image') {
                $sortlist[$sortid][$optionid]['maxwidth'] = intval($data['rules']['maxwidth']);
                $sortlist[$sortid][$optionid]['maxheight'] = intval($data['rules']['maxheight']);
            } elseif ($data['type'] == 'number') {
                $sortlist[$sortid][$optionid]['maxnum'] = intval($data['rules']['maxnum']);
                $sortlist[$sortid][$optionid]['minnum'] = intval($data['rules']['minnum']);
            }
        }
        $query = $db->query("SELECT typeid, description, template FROM {$tablepre}threadtypes WHERE special='1'");
        while ($data = $db->fetch_array($query)) {
            $templatedata[$data['typeid']] = $data['template'];
            $threaddesc[$data['typeid']] = dhtmlspecialchars($data['description']);
        }
        foreach ($sortlist as $sortid => $option) {
            writetocache($sortid, '', "\$_DTYPE = " . arrayeval($option) . ";\n\n\$_DTYPETEMPLATE = \"" . str_replace('"', '\\"', $templatedata[$sortid]) . "\";\n", 'threadsort_');
        }
    }
}
Ejemplo n.º 3
0
function build_cache_styles()
{
    global $_G;
    $stylevars = $styledata = array();
    $defaultstyleid = DB::result_first("SELECT svalue FROM " . DB::table('common_setting') . " WHERE skey = 'styleid'");
    $zoomstatus = DB::result_first("SELECT svalue FROM " . DB::table('common_setting') . " WHERE skey = 'zoomstatus'");
    list(, $imagemaxwidth) = explode("\t", $zoomstatus);
    $imagemaxwidth = $imagemaxwidth ? $imagemaxwidth : 600;
    $imagemaxwidthint = intval($imagemaxwidth);
    $query = DB::query("SELECT sv.* FROM " . DB::table('common_stylevar') . " sv LEFT JOIN " . DB::table('common_style') . " s ON s.styleid = sv.styleid AND (s.available=1 OR s.styleid='{$defaultstyleid}')");
    while ($var = DB::fetch($query)) {
        $stylevars[$var['styleid']][$var['variable']] = $var['substitute'];
    }
    $query = DB::query("SELECT s.*, t.directory AS tpldir FROM " . DB::table('common_style') . " s LEFT JOIN " . DB::table('common_template') . " t ON s.templateid=t.templateid");
    while ($data = DB::fetch($query)) {
        $data = array_merge($data, $stylevars[$data['styleid']]);
        $datanew = array();
        $data['imgdir'] = $data['imgdir'] ? $data['imgdir'] : STATICURL . 'image/common';
        $data['styleimgdir'] = $data['styleimgdir'] ? $data['styleimgdir'] : $data['imgdir'];
        foreach ($data as $k => $v) {
            if (substr($k, -7, 7) == 'bgcolor') {
                $newkey = substr($k, 0, -7) . 'bgcode';
                $datanew[$newkey] = setcssbackground($data, $k);
            }
        }
        $data = array_merge($data, $datanew);
        if (strstr($data['boardimg'], ',')) {
            $flash = explode(",", $data['boardimg']);
            $flash[0] = trim($flash[0]);
            $flash[0] = preg_match('/^http:\\/\\//i', $flash[0]) ? $flash[0] : $data['styleimgdir'] . '/' . $flash[0];
            $data['boardlogo'] = "<embed src=\"" . $flash[0] . "\" width=\"" . trim($flash[1]) . "\" height=\"" . trim($flash[2]) . "\" type=\"application/x-shockwave-flash\" wmode=\"transparent\"></embed>";
        } else {
            $data['boardimg'] = preg_match('/^http:\\/\\//i', $data['boardimg']) ? $data['boardimg'] : $data['styleimgdir'] . '/' . $data['boardimg'];
            $data['boardlogo'] = "<img src=\"{$data['boardimg']}\" alt=\"" . $_G['setting']['bbname'] . "\" border=\"0\" />";
        }
        $data['bold'] = $data['nobold'] ? 'normal' : 'bold';
        $contentwidthint = intval($data['contentwidth']);
        $contentwidthint = $contentwidthint ? $contentwidthint : 600;
        if (substr(trim($data['contentwidth']), -1, 1) != '%') {
            if (substr(trim($_G['setting']['imagemaxwidth']), -1, 1) != '%') {
                $data['imagemaxwidth'] = $imagemaxwidthint > $contentwidthint ? $contentwidthint : $imagemaxwidthint;
            } else {
                $data['imagemaxwidth'] = intval($contentwidthint * $imagemaxwidthint / 100);
            }
        } else {
            if (substr(trim($_G['setting']['imagemaxwidth']), -1, 1) != '%') {
                $data['imagemaxwidth'] = '%' . $imagemaxwidthint;
            } else {
                $data['imagemaxwidth'] = ($imagemaxwidthint > $contentwidthint ? $contentwidthint : $imagemaxwidthint) . '%';
            }
        }
        if ($data['extstyle']) {
            list($data['extstyle'], $data['defaultextstyle']) = explode('|', $data['extstyle']);
            $extstyle = explode("\t", $data['extstyle']);
            $data['extstyle'] = array();
            foreach ($extstyle as $dir) {
                if (file_exists($extstylefile = DISCUZ_ROOT . $data['tpldir'] . '/style/' . $dir . '/style.css')) {
                    if ($data['defaultextstyle'] == $dir) {
                        $data['defaultextstyle'] = $data['tpldir'] . '/style/' . $dir;
                    }
                    $content = file_get_contents($extstylefile);
                    if (preg_match('/\\[name\\](.+?)\\[\\/name\\]/i', $content, $r1) && preg_match('/\\[iconbgcolor](.+?)\\[\\/iconbgcolor]/i', $content, $r2)) {
                        $data['extstyle'][] = array($data['tpldir'] . '/style/' . $dir, $r1[1], $r2[1]);
                    }
                }
            }
        }
        $data['verhash'] = random(3);
        $styledata[] = $data;
    }
    foreach ($styledata as $data) {
        save_syscache('style_' . $data['styleid'], $data);
        if ($defaultstyleid == $data['styleid']) {
            save_syscache('style_default', $data);
        }
        writetocsscache($data);
    }
}