Example #1
0
function build_cache_setting()
{
    global $_G;
    $table = 'common_setting';
    $skipkeys = array('posttableids', 'siteuniqueid', 'mastermobile', 'closedreason', 'creditsnotify', 'backupdir', 'custombackup', 'jswizard', 'maxonlines', 'modreasons', 'newsletter', 'postno', 'postnocustom', 'customauthorinfo', 'domainwhitelist', 'ipregctrl', 'ipverifywhite', 'fastsmiley', 'defaultdoing', 'profilegroup');
    $serialized = array('reginput', 'memory', 'search', 'creditspolicy', 'ftp', 'secqaa', 'ec_credit', 'qihoo', 'spacedata', 'infosidestatus', 'uc', 'indexhot', 'relatedtag', 'sitemessage', 'uchome', 'heatthread', 'recommendthread', 'disallowfloat', 'allowviewuserthread', 'advtype', 'click', 'card', 'rewritestatus', 'rewriterule', 'privacy', 'focus', 'forumkeys', 'article_tags', 'verify', 'seotitle', 'seodescription', 'seokeywords', 'domain', 'ranklist', 'seccodedata', 'inviteconfig', 'advexpiration', 'allowpostcomment', 'mobile', 'connect');
    $data = array();
    $query = DB::query("SELECT * FROM " . DB::table($table) . " WHERE skey NOT IN(" . dimplode($skipkeys) . ')');
    while ($setting = DB::fetch($query)) {
        if ($setting['skey'] == 'extcredits') {
            if (is_array($setting['svalue'] = unserialize($setting['svalue']))) {
                foreach ($setting['svalue'] as $key => $value) {
                    if ($value['available']) {
                        unset($setting['svalue'][$key]['available']);
                    } else {
                        unset($setting['svalue'][$key]);
                    }
                }
            }
        } elseif ($setting['skey'] == 'creditsformula') {
            if (!checkformulacredits($setting['svalue'])) {
                $setting['svalue'] = '$member[\'extcredits1\']';
            } else {
                $setting['svalue'] = preg_replace("/(friends|doings|blogs|albums|polls|sharings|digestposts|posts|threads|oltime|extcredits[1-8])/", "\$member['\\1']", $setting['svalue']);
            }
        } elseif ($setting['skey'] == 'maxsmilies') {
            $setting['svalue'] = $setting['svalue'] <= 0 ? -1 : $setting['svalue'];
        } elseif ($setting['skey'] == 'threadsticky') {
            $setting['svalue'] = explode(',', $setting['svalue']);
        } elseif ($setting['skey'] == 'attachdir') {
            $setting['svalue'] = preg_replace("/\\.asp|\\0/i", '0', $setting['svalue']);
            $setting['svalue'] = str_replace('\\', '/', substr($setting['svalue'], 0, 2) == './' ? DISCUZ_ROOT . $setting['svalue'] : $setting['svalue']);
            $setting['svalue'] .= substr($setting['svalue'], -1, 1) != '/' ? '/' : '';
        } elseif ($setting['skey'] == 'attachurl') {
            $setting['svalue'] .= substr($setting['svalue'], -1, 1) != '/' ? '/' : '';
        } elseif ($setting['skey'] == 'onlinehold') {
            $setting['svalue'] = $setting['svalue'] * 60;
        } elseif (in_array($setting['skey'], $serialized)) {
            $setting['svalue'] = @unserialize($setting['svalue']);
            if ($setting['skey'] == 'search') {
                foreach ($setting['svalue'] as $key => $val) {
                    foreach ($val as $k => $v) {
                        $setting['svalue'][$key][$k] = max(0, intval($v));
                    }
                }
            }
            if ($setting['skey'] == 'ftp') {
                $setting['svalue']['attachurl'] .= substr($setting['svalue']['attachurl'], -1, 1) != '/' ? '/' : '';
            }
        }
        $_G['setting'][$setting['skey']] = $data[$setting['skey']] = $setting['svalue'];
    }
    DB::free_result($query);
    $data['newusergroupid'] = DB::result_first("SELECT groupid FROM " . DB::table('common_usergroup') . " WHERE creditshigher<=" . intval($data['initcredits']) . " AND " . intval($data['initcredits']) . "<creditslower LIMIT 1");
    if ($data['srchhotkeywords']) {
        $data['srchhotkeywords'] = explode("\n", $data['srchhotkeywords']);
    }
    if ($data['search']) {
        $searchstatus = 0;
        foreach ($data['search'] as $item) {
            if ($item['status']) {
                $searchstatus = 1;
                break;
            }
        }
        if (!$searchstatus) {
            $data['search'] = array();
        }
    }
    $data['creditspolicy'] = array_merge($data['creditspolicy'], get_cachedata_setting_creditspolicy());
    if ($data['heatthread']['iconlevels']) {
        $data['heatthread']['iconlevels'] = explode(',', $data['heatthread']['iconlevels']);
        arsort($data['heatthread']['iconlevels']);
    } else {
        $data['heatthread']['iconlevels'] = array();
    }
    if ($data['verify']) {
        foreach ($data['verify'] as $key => $value) {
            if ($value['available'] && !empty($value['icon'])) {
                $icourl = parse_url($value['icon']);
                if (!$icourl['host'] && !file_exists($value['icon'])) {
                    $data['verify'][$key]['icon'] = $data['attachurl'] . 'common/' . $value['icon'];
                }
            }
        }
    }
    if ($data['recommendthread']['status']) {
        if ($data['recommendthread']['iconlevels']) {
            $data['recommendthread']['iconlevels'] = explode(',', $data['recommendthread']['iconlevels']);
            arsort($data['recommendthread']['iconlevels']);
        } else {
            $data['recommendthread']['iconlevels'] = array();
        }
    } else {
        $data['recommendthread'] = array('allow' => 0);
    }
    if ($data['commentnumber'] && !$data['allowpostcomment']) {
        $data['commentnumber'] = 0;
    }
    if (!empty($data['ftp'])) {
        if (!empty($data['ftp']['allowedexts'])) {
            $data['ftp']['allowedexts'] = str_replace(array("\r\n", "\r"), array("\n", "\n"), $data['ftp']['allowedexts']);
            $data['ftp']['allowedexts'] = explode("\n", strtolower($data['ftp']['allowedexts']));
            array_walk($data['ftp']['allowedexts'], 'trim');
        }
        if (!empty($data['ftp']['disallowedexts'])) {
            $data['ftp']['disallowedexts'] = str_replace(array("\r\n", "\r"), array("\n", "\n"), $data['ftp']['disallowedexts']);
            $data['ftp']['disallowedexts'] = explode("\n", strtolower($data['ftp']['disallowedexts']));
            array_walk($data['ftp']['disallowedexts'], 'trim');
        }
        $data['ftp']['connid'] = 0;
    }
    if (!empty($data['forumkeys'])) {
        $data['forumfids'] = array_flip($data['forumkeys']);
    } else {
        $data['forumfids'] = array();
    }
    $data['commentitem'] = explode("\t", $data['commentitem']);
    $commentitem = array();
    foreach ($data['commentitem'] as $k => $v) {
        $tmp = explode(chr(0) . chr(0) . chr(0), $v);
        if (count($tmp) > 1) {
            $commentitem[$tmp[0]] = $tmp[1];
        } else {
            $commentitem[$k] = $v;
        }
    }
    $data['commentitem'] = $commentitem;
    if ($data['allowviewuserthread']['allow']) {
        $data['allowviewuserthread'] = is_array($data['allowviewuserthread']['fids']) && $data['allowviewuserthread']['fids'] && !in_array('', $data['allowviewuserthread']['fids']) ? dimplode($data['allowviewuserthread']['fids']) : '';
    } else {
        $data['allowviewuserthread'] = false;
    }
    include_once DISCUZ_ROOT . './source/discuz_version.php';
    $_G['setting']['version'] = $data['version'] = DISCUZ_VERSION;
    $data['sitemessage']['time'] = !empty($data['sitemessage']['time']) ? $data['sitemessage']['time'] * 1000 : 0;
    foreach (array('register', 'login', 'newthread', 'reply') as $type) {
        $data['sitemessage'][$type] = !empty($data['sitemessage'][$type]) ? explode("\n", $data['sitemessage'][$type]) : array();
    }
    $data['cachethreadon'] = DB::result_first("SELECT COUNT(*) FROM " . DB::table('forum_forum') . " WHERE status='1' AND threadcaches>0") ? 1 : 0;
    $data['disallowfloat'] = is_array($data['disallowfloat']) ? implode('|', $data['disallowfloat']) : '';
    if (!$data['imagelib']) {
        unset($data['imageimpath']);
    }
    if (is_array($data['relatedtag']['order'])) {
        asort($data['relatedtag']['order']);
        $relatedtag = array();
        foreach ($data['relatedtag']['order'] as $k => $v) {
            $relatedtag['status'][$k] = $data['relatedtag']['status'][$k];
            $relatedtag['name'][$k] = $data['relatedtag']['name'][$k];
            $relatedtag['limit'][$k] = $data['relatedtag']['limit'][$k];
            $relatedtag['template'][$k] = $data['relatedtag']['template'][$k];
        }
        $data['relatedtag'] = $relatedtag;
        foreach ((array) $data['relatedtag']['status'] as $appid => $status) {
            if (!$status) {
                unset($data['relatedtag']['limit'][$appid]);
            }
        }
        unset($data['relatedtag']['status'], $data['relatedtag']['order'], $relatedtag);
    }
    $data['domain']['defaultindex'] = isset($data['defaultindex']) && $data['defaultindex'] != '#' ? $data['defaultindex'] : '';
    $data['domain']['holddomain'] = isset($data['holddomain']) ? $data['holddomain'] : '';
    $data['domain']['list'] = array();
    $query = DB::query("SELECT * FROM " . DB::table('common_domain') . " WHERE idtype IN('subarea', 'forum', 'topic', 'channel')");
    while ($value = DB::fetch($query)) {
        $data['domain']['list'][$value['domain'] . '.' . $value['domainroot']] = array('id' => $value['id'], 'idtype' => $value['idtype']);
    }
    writetocache('domain', getcachevars(array('domain' => $data['domain'])));
    $data['seccodedata'] = is_array($data['seccodedata']) ? $data['seccodedata'] : array();
    if ($data['seccodedata']['type'] == 2) {
        if (extension_loaded('ming')) {
            unset($data['seccodedata']['background'], $data['seccodedata']['adulterate'], $data['seccodedata']['ttf'], $data['seccodedata']['angle'], $data['seccodedata']['color'], $data['seccodedata']['size'], $data['seccodedata']['animator']);
        } else {
            $data['seccodedata']['animator'] = 0;
        }
    } elseif ($data['seccodedata']['type'] == 99) {
        $data['seccodedata']['width'] = 32;
        $data['seccodedata']['height'] = 24;
    }
    $data['watermarktype'] = !empty($data['watermarktype']) ? unserialize($data['watermarktype']) : array();
    $data['watermarktext'] = !empty($data['watermarktext']) ? unserialize($data['watermarktext']) : array();
    foreach ($data['watermarktype'] as $k => $v) {
        if ($data['watermarktype'][$k] == 'text' && $data['watermarktext']['text'][$k]) {
            if ($data['watermarktext']['text'][$k] && strtoupper(CHARSET) != 'UTF-8') {
                $data['watermarktext']['text'][$k] = diconv($data['watermarktext']['text'][$k], CHARSET, 'UTF-8', true);
            }
            $data['watermarktext']['text'][$k] = bin2hex($data['watermarktext']['text'][$k]);
            if (file_exists('static/image/seccode/font/en/' . $data['watermarktext']['fontpath'][$k])) {
                $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/en/' . $data['watermarktext']['fontpath'][$k];
            } elseif (file_exists('static/image/seccode/font/ch/' . $data['watermarktext']['fontpath'][$k])) {
                $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/ch/' . $data['watermarktext']['fontpath'][$k];
            } else {
                $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/' . $data['watermarktext']['fontpath'][$k];
            }
            $data['watermarktext']['color'][$k] = preg_replace('/#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/e', "hexdec('\\1').','.hexdec('\\2').','.hexdec('\\3')", $data['watermarktext']['color'][$k]);
            $data['watermarktext']['shadowcolor'][$k] = preg_replace('/#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/e', "hexdec('\\1').','.hexdec('\\2').','.hexdec('\\3')", $data['watermarktext']['shadowcolor'][$k]);
        } else {
            $data['watermarktext']['text'][$k] = '';
            $data['watermarktext']['fontpath'][$k] = '';
            $data['watermarktext']['color'][$k] = '';
            $data['watermarktext']['shadowcolor'][$k] = '';
        }
    }
    $data['styles'] = array();
    $query = DB::query("SELECT s.styleid, s.name, s.extstyle, t.directory FROM " . DB::table('common_style') . " s\n\t\t\t\tLEFT JOIN " . DB::table('common_template') . " t ON s.templateid=t.templateid\n\t\t\t\tWHERE s.available='1'");
    while ($style = DB::fetch($query)) {
        $data['styles'][$style['styleid']] = dhtmlspecialchars($style['name']);
    }
    $exchcredits = array();
    $allowexchangein = $allowexchangeout = FALSE;
    foreach ((array) $data['extcredits'] as $id => $credit) {
        $data['extcredits'][$id]['img'] = $credit['img'] ? '<img style="vertical-align:middle" src="' . $credit['img'] . '" />' : '';
        if (!empty($credit['ratio'])) {
            $exchcredits[$id] = $credit;
            $credit['allowexchangein'] && ($allowexchangein = TRUE);
            $credit['allowexchangeout'] && ($allowexchangeout = TRUE);
        }
        $data['creditnotice'] && ($data['creditnames'][] = str_replace("'", "\\'", htmlspecialchars($id . '|' . $credit['title'] . '|' . $credit['unit'])));
    }
    $data['creditnames'] = $data['creditnotice'] ? @implode(',', $data['creditnames']) : '';
    $creditstranssi = explode(',', $data['creditstrans']);
    $data['creditstrans'] = $creditstranssi[0];
    unset($creditstranssi[0]);
    $data['creditstransextra'] = $creditstranssi;
    for ($i = 1; $i < 11; $i++) {
        $data['creditstransextra'][$i] = $data['creditstrans'] ? !$data['creditstransextra'][$i] ? $data['creditstrans'] : $data['creditstransextra'][$i] : 0;
    }
    $data['exchangestatus'] = $allowexchangein && $allowexchangeout;
    $data['transferstatus'] = isset($data['extcredits'][$data['creditstrans']]);
    list($data['zoomstatus'], $data['imagemaxwidth']) = explode("\t", $data['zoomstatus']);
    $data['imagemaxwidth'] = intval($data['imagemaxwidth']);
    require_once DISCUZ_ROOT . './config/config_ucenter.php';
    $data['ucenterurl'] = UC_API;
    $query = DB::query("SELECT identifier, name FROM " . DB::table('common_magic') . " WHERE available='1'");
    while ($magic = DB::fetch($query)) {
        $data['magics'][$magic['identifier']] = $magic['name'];
    }
    $data['tradeopen'] = DB::result_first("SELECT count(*) FROM " . DB::table('common_usergroup_field') . " WHERE allowposttrade='1'") ? 1 : 0;
    $data['medalstatus'] = intval(DB::result_first("SELECT count(*) FROM " . DB::table('forum_medal') . " WHERE available='1'"));
    $focus = array();
    if ($data['focus']['data']) {
        foreach ($data['focus']['data'] as $k => $v) {
            if ($v['available'] && $v['position']) {
                foreach ($v['position'] as $position) {
                    $focus[$position][$k] = $k;
                }
            }
        }
    }
    $data['focus'] = $focus;
    list($data['plugins'], $data['pluginlinks'], $data['hookscript'], $data['hookscriptmobile'], $data['threadplugins'], $data['specialicon']) = get_cachedata_setting_plugin();
    if (empty($data['defaultindex'])) {
        $data['defaultindex'] = array();
    }
    list($data['navs'], $data['subnavs'], $data['menunavs'], $data['navmns'], $data['navmn'], $data['navdms'], $data['navlogos']) = get_cachedata_mainnav();
    $data['footernavs'] = get_cachedata_footernav();
    $data['spacenavs'] = get_cachedata_spacenavs();
    $data['mynavs'] = get_cachedata_mynavs();
    $data['topnavs'] = get_cachedata_topnav();
    require_once DISCUZ_ROOT . './uc_client/client.php';
    $ucapparray = uc_app_ls();
    $data['allowsynlogin'] = isset($ucapparray[UC_APPID]['synlogin']) ? $ucapparray[UC_APPID]['synlogin'] : 1;
    $appnamearray = array('UCHOME', 'XSPACE', 'DISCUZ', 'SUPESITE', 'SUPEV', 'ECSHOP', 'ECMALL', 'OTHER');
    $data['ucapp'] = $data['ucappopen'] = array();
    $data['uchomeurl'] = '';
    $data['discuzurl'] = $_G['siteurl'];
    $appsynlogins = 0;
    foreach ($ucapparray as $apparray) {
        if ($apparray['appid'] != UC_APPID) {
            if (!empty($apparray['synlogin'])) {
                $appsynlogins = 1;
            }
            if ($data['uc']['navlist'][$apparray['appid']] && $data['uc']['navopen']) {
                $data['ucapp'][$apparray['appid']]['name'] = $apparray['name'];
                $data['ucapp'][$apparray['appid']]['url'] = $apparray['url'];
            }
        } else {
            $data['discuzurl'] = $apparray['url'];
        }
        if (!empty($apparray['viewprourl'])) {
            $data['ucapp'][$apparray['appid']]['viewprourl'] = $apparray['url'] . $apparray['viewprourl'];
        }
        foreach ($appnamearray as $name) {
            if ($apparray['type'] == $name && $apparray['appid'] != UC_APPID) {
                $data['ucappopen'][$name] = 1;
                if ($name == 'UCHOME') {
                    $data['uchomeurl'] = $apparray['url'];
                } elseif ($name == 'XSPACE') {
                    $data['xspaceurl'] = $apparray['url'];
                }
            }
        }
    }
    $data['allowsynlogin'] = $data['allowsynlogin'] && $appsynlogins ? 1 : 0;
    $data['homeshow'] = $data['uchomeurl'] && $data['uchome']['homeshow'] ? $data['uchome']['homeshow'] : '0';
    unset($data['allowthreadplugin']);
    if ($data['jspath'] == 'data/cache/') {
        writetojscache();
    } elseif (!$data['jspath']) {
        $data['jspath'] = 'static/js/';
    }
    if ($data['cacheindexlife']) {
        $cachedir = DISCUZ_ROOT . './' . $data['cachethreaddir'];
        $tidmd5 = substr(md5(0), 3);
        @unlink($cachedir . '/' . $tidmd5[0] . '/' . $tidmd5[1] . '/' . $tidmd5[2] . '/0.htm');
    }
    $reginputbwords = array('username', 'password', 'password2', 'email');
    if (in_array($data['reginput']['username'], $reginputbwords) || !preg_match('/^[A-z]\\w+?$/', $data['reginput']['username'])) {
        $data['reginput']['username'] = random(6);
    }
    if (in_array($data['reginput']['password'], $reginputbwords) || !preg_match('/^[A-z]\\w+?$/', $data['reginput']['password'])) {
        $data['reginput']['password'] = random(6);
    }
    if (in_array($data['reginput']['password2'], $reginputbwords) || !preg_match('/^[A-z]\\w+?$/', $data['reginput']['password2'])) {
        $data['reginput']['password2'] = random(6);
    }
    if (in_array($data['reginput']['email'], $reginputbwords) || !preg_match('/^[A-z]\\w+?$/', $data['reginput']['email'])) {
        $data['reginput']['email'] = random(6);
    }
    $defaultcurhost = empty($_G['setting']['domain']['app']['default']) ? '{CURHOST}' : $_G['setting']['domain']['app']['default'];
    $output = array('str' => array(), 'preg' => array());
    //str為二級域名的查找和替換,preg為rewrite和默認域名的查找和替換
    $_G['domain'] = array();
    if (is_array($_G['setting']['domain']['app'])) {
        $apps = $_G['setting']['domain']['app'];
        $repflag = $apps['portal'] || $apps['forum'] || $apps['group'] || $apps['home'] || $apps['default'];
        foreach ($apps as $app => $domain) {
            if (in_array($app, array('default', 'mobile'))) {
                continue;
            }
            $appphp = "{$app}.php";
            if (!$domain) {
                $domain = $defaultcurhost;
            }
            if ($domain != '{CURHOST}') {
                $domain = 'http://' . $domain . $_G['siteport'] . '/';
            }
            if ($repflag) {
                $output['str']['search'][$app] = "<a href=\"{$app}.php";
                $output['str']['replace'][$app] = '<a href="' . $domain . $appphp;
                $_G['domain']['pregxprw'][$app] = '<a href\\="(' . preg_quote($domain, '/') . ')' . $appphp;
            } else {
                $_G['domain']['pregxprw'][$app] = '<a href\\="()' . $appphp;
            }
        }
    }
    if ($_G['setting']['rewritestatus'] || $output['str']['search']) {
        if ($_G['setting']['rewritestatus']) {
            require_once libfile('function/admincp');
            $output['preg'] = rewritedata(0);
        }
        if ($repflag) {
            if ($defaultcurhost != '{CURHOST}') {
                $defaultcurhost = 'http://' . $defaultcurhost . $_G['siteport'] . '/';
            }
            $output['preg']['search'][] = "/<a href=\"(\\w+\\.php)/";
            $output['preg']['replace'][] = '<a href="' . $defaultcurhost . "\$1";
        }
    }
    $data['output'] = $output;
    save_syscache('setting', $data);
    $_G['setting'] = $data;
}
Example #2
0
            }
        }
        if ($searchindex['id']) {
            $searchid = $searchindex['id'];
        } else {
            if (!$srchtxt) {
                dheader('Location: search.php?mod=portal');
            }
            if ($_G['adminid'] != '1' && $_G['setting']['search']['portal']['maxspm']) {
                if (DB::result_first("SELECT COUNT(*) FROM " . DB::table('common_searchindex') . " WHERE srchmod='{$srchmod}' AND dateline>'{$_G['timestamp']}'-60") >= $_G['setting']['search']['portal']['maxspm']) {
                    showmessage('search_toomany', 'search.php?mod=portal', array('maxspm' => $_G['setting']['search']['portal']['maxspm']));
                }
            }
            $num = $ids = 0;
            $_G['setting']['search']['portal']['maxsearchresults'] = $_G['setting']['search']['portal']['maxsearchresults'] ? intval($_G['setting']['search']['portal']['maxsearchresults']) : 500;
            $srchtxtsql = addcslashes($srchtxt, '%_');
            $query = DB::query("SELECT aid FROM " . DB::table('portal_article_title') . " WHERE title LIKE '%{$srchtxtsql}%' ORDER BY aid DESC LIMIT " . $_G['setting']['search']['portal']['maxsearchresults']);
            while ($article = DB::fetch($query)) {
                $ids .= ',' . $article['aid'];
                $num++;
            }
            DB::free_result($query);
            $keywords = str_replace('%', '+', $srchtxt);
            $expiration = TIMESTAMP + $cachelife_text;
            DB::query("INSERT INTO " . DB::table('common_searchindex') . " (srchmod, keywords, searchstring, useip, uid, dateline, expiration, num, ids)\r\n\t\t\t\t\tVALUES ('{$srchmod}', '{$keywords}', '{$searchstring}', '{$_G['clientip']}', '{$_G['uid']}', '{$_G['timestamp']}', '{$expiration}', '{$num}', '{$ids}')");
            $searchid = DB::insert_id();
            !($_G['portal']['exempt'] & 2) && updatecreditbyaction('search');
        }
        dheader("location: search.php?mod=portal&searchid={$searchid}&searchsubmit=yes");
    }
}
Example #3
0
 }
 $data = ['penalty' => $penalty, 'reason' => $reason, 'seed_id' => $seed['seed_id']];
 $res = PTHelper::getApiCurl("seed/delete", $data);
 if ($res['result'] != 'success') {
     if ($res['reason'] == 'not exists') {
         deleteThreadAndSeed($tid);
         $seed_not_exists++;
         continue;
     } else {
         throw new Exception("删除seed_id : {$seed['seed_id']} 失败" . $res['extra']);
     }
 } else {
     $seed_info = $res['extra'];
     $threadinfo = DB::query("SELECT tid FROM " . DB::table('forum_thread') . " WHERE tid='{$tid}' LIMIT 1;");
     $threadnum = DB::num_rows($threadinfo);
     DB::free_result($threadinfo);
     // 如果帖子未删除
     if ($threadnum <= 0) {
         $thread_not_exists++;
     }
     // 查询发种者
     $publisheruid = $seed_info['discuz_pub_uid'];
     $threadsubject = DB::fetch_first("SELECT subject FROM " . DB::table('forum_thread') . " WHERE tid='{$tid}';")['subject'];
     $name = DB::fetch_first("SELECT username FROM " . DB::table('ucenter_members') . " WHERE uid='{$uid}';")['username'];
     // 关于用户名:
     //"alter table pre_ucenter_members change username username char(32) default '' not null;";
     //http://www.discuz.net/thread-1634979-1-1.html
     //http://www.51php.com/discuz/17191.html
     // 在发送短消息之前要对即将加入的信息进行转义
     $threadsubject = htmlentities($threadsubject, ENT_QUOTES);
     $reason = htmlentities($reason, ENT_QUOTES);
function friend_cache($touid)
{
    global $_G;
    $tospace = array('uid' => $touid);
    space_merge($tospace, 'field_home');
    $filtergids = empty($tospace['privacy']['filter_gid']) ? array() : $tospace['privacy']['filter_gid'];
    $uids = array();
    $count = 0;
    $fcount = 0;
    $query = DB::query("SELECT * FROM " . DB::table('home_friend') . " WHERE uid='{$touid}' ORDER BY num DESC, dateline DESC");
    while ($value = DB::fetch($query)) {
        if ($value['fuid'] == $touid) {
            continue;
        }
        if ($fcount > 200) {
            $count = DB::num_rows($query);
            DB::free_result($query);
            break;
        } elseif (empty($filtergids) || !in_array($value['gid'], $filtergids)) {
            $uids[] = $value['fuid'];
            $fcount++;
        }
        $count++;
    }
    DB::update('common_member_field_home', array('feedfriend' => implode(',', $uids)), array('uid' => $touid));
    DB::update('common_member_count', array('friends' => $count), array('uid' => $touid));
}
Example #5
0
 public function uloginLoginUser($user_id)
 {
     $result = DB::query("SELECT * FROM {users} WHERE trash='0' AND act='1' AND id='%s'", $user_id);
     $user = DB::fetch_object($result);
     DB::free_result($result);
     $this->diafan->_users->set($user);
     $this->diafan->redirect($this->diafan->_route->current_link());
 }
Example #6
0
            $userUpdate["LOG_IP"] = $userInfo["LOG_IP"] . ';' . $ip;
        } else {
            $userUpdate["LOG_IP"] = $ip;
        }
        if (!$userInfo["LOG_TIMES"]) {
            $userUpdate["LOG_TIMES"] = 1;
        } else {
            $userUpdate["LOG_TIMES"] = $userInfo["LOG_TIMES"] + 1;
        }
        $db->update("admin", $userUpdate, "ID='{$userInfo['ID']}'");
        header("Location: user.php?action=1 ");
    } else {
        $message = "用户名或密码错误";
        header("Location: index.php ");
    }
    $db->free_result();
} else {
    $message = "请输入用户名和密码";
    header("Location: index.php ");
}
setcookie("message", $message);
function dowith_sql($str)
{
    $str = str_replace("and", "", $str);
    $str = str_replace("execute", "", $str);
    $str = str_replace("update", "", $str);
    $str = str_replace("count", "", $str);
    $str = str_replace("chr", "", $str);
    $str = str_replace("mid", "", $str);
    $str = str_replace("master", "", $str);
    $str = str_replace("truncate", "", $str);
Example #7
0
 function Get($ids, $fields = '*', $process = 'Make', $table = "", $prikey = 'tid', $cache = 0)
 {
     $table = $table ? $table : TABLE_PREFIX . "topic";
     if ($cache) {
         $cache_key = md5($fields . $process . $table . $prikey);
     }
     $condition = "";
     $ids_count = 0;
     $is_num = is_numeric($ids);
     if ($is_num) {
         if ($cache && isset($this->_cache[$cache_key][$ids])) {
             return $this->_cache[$cache_key][$ids];
         }
         $condition = "WHERE `{$prikey}`='{$ids}'";
     } elseif (is_array($ids)) {
         $ids_count = count($ids);
         $condition = "WHERE `{$prikey}` IN ('" . implode("','", $ids) . "')";
     } elseif (is_string($ids) && false !== strpos(strtolower($ids), ' limit ')) {
         $condition = $ids;
     } else {
         return false;
     }
     $sql = "SELECT {$fields} FROM {$table} {$condition} ";
     $query = DB::query($sql);
     $list = array();
     if (!$query || ($num_rows = DB::num_rows($query)) < 1 || $ids_count > 0 && $num_rows != $ids_count) {
         if (TABLE_PREFIX . 'topic' == $table) {
             if ($is_num) {
                 $is_one = 1;
                 $list = jtable('topic')->row($ids);
                 if ($list && $process) {
                     $list = $this->{$process}($list);
                 }
             } elseif ($ids_count > 0) {
                 $list = jtable('topic')->get_list($ids);
             }
         }
         if (!$list) {
             return false;
         }
     } else {
         $is_one = $is_num && $num_rows < 2 ? 1 : 0;
         $pri_key_is_set = 1;
         while (false != ($row = DB::fetch($query))) {
             if ($process && ('Make' != $process || $is_one)) {
                 $row = $cache && isset($this->_cache[$cache_key][$row[$prikey]]) ? $this->_cache[$cache_key][$row[$prikey]] : $this->{$process}($row);
             }
             if ($cache && isset($row[$prikey]) && !isset($this->_cache[$cache_key][$row[$prikey]])) {
                 $this->_cache[$cache_key][$row[$prikey]] = $row;
             }
             if ($is_one) {
                 $list = $row;
                 break;
             } else {
                 if (isset($row[$prikey])) {
                     $pri_key_is_set = 1;
                     $list[$row[$prikey]] = $row;
                 } else {
                     $list[] = $row;
                 }
             }
         }
         DB::free_result($query);
         if ($ids_count > 0 && $list && $pri_key_is_set) {
             $_list = array();
             foreach ($ids as $_id) {
                 $_list[$_id] = $list[$_id];
             }
             $list = $_list;
             unset($_list);
         }
     }
     if ('Make' == $process && !$is_one) {
         $verify = $table == TABLE_PREFIX . 'topic_verify' ? 1 : 0;
         $list = $this->MakeAll($list, 1, $verify);
     }
     return $list;
 }
 private function _searchData($kw, $page, $pagesize, $res, $searchid)
 {
     global $_G;
     $srchtype = 'title';
     $orderby = 'lastpost';
     $ascdesc = 'desc';
     $srchtxt = $kw;
     $keyword = WebUtils::t(dhtmlspecialchars(trim($kw)));
     $_G['setting']['search']['forum']['searchctrl'] = intval($_G['setting']['search']['forum']['searchctrl']);
     require_once libfile('function/forumlist');
     require_once libfile('function/forum');
     require_once libfile('function/search');
     require_once libfile('function/misc');
     require_once libfile('function/post');
     loadcache(array('forums', 'posttable_info'));
     $srchmod = 2;
     $cachelife_time = 300;
     $cachelife_text = 3600;
     $seltableid = 0;
     if (empty($searchid)) {
         //searchid 为空的时候就要通过拼接一个字符串来进行查找搜索缓存表了
         if ($_G['group']['allowsearch'] & 32 && $srchtype == 'fulltext') {
             //全文搜索
             //时间段设置检测
             periodscheck('searchban0periods');
         } elseif ($srchtype != 'title') {
             $srchtype = 'title';
         }
         $forumsarray = array();
         if (!empty($srchfid)) {
             foreach (is_array($srchfid) ? $srchfid : explode('_', $srchfid) as $forum) {
                 if ($forum = intval(trim($forum))) {
                     $forumsarray[] = $forum;
                 }
             }
         }
         //取出板块的fid
         $fids = $comma = '';
         foreach ($_G['cache']['forums'] as $fid => $forum) {
             if ($forum['type'] != 'group' && (!$forum['viewperm'] && $_G['group']['readaccess']) || $forum['viewperm'] && forumperm($forum['viewperm'])) {
                 if (!$forumsarray || in_array($fid, $forumsarray)) {
                     $fids .= "{$comma}'{$fid}'";
                     $comma = ',';
                 }
             }
         }
         if ($_G['setting']['threadplugins'] && $specialplugin) {
             $specialpluginstr = implode("','", $specialplugin);
             $special[] = 127;
         } else {
             $specialpluginstr = '';
         }
         $special = '';
         $specials = $special ? implode(',', $special) : '';
         $srchfilter = 'all';
         //所有板块
         //搜索缓存表 查找字符串
         $srchuid = $srchuname = $srchfrom = $before = '';
         $searchstring = 'forum|' . $srchtype . '|' . base64_encode($srchtxt) . '|' . intval($srchuid) . '|' . $srchuname . '|' . addslashes($fids) . '|' . intval($srchfrom) . '|' . intval($before) . '|' . $srchfilter . '|' . $specials . '|' . $specialpluginstr . '|' . $se0;
         $searchindex = array('id' => 0, 'dateline' => '0');
         foreach (C::t('common_searchindex')->fetch_all_search($_G['setting']['search']['forum']['searchctrl'], $_G['clientip'], $_G['uid'], $_G['timestamp'], $searchstring, $srchmod) as $index) {
             if ($index['indexvalid'] && $index['dateline'] > $searchindex['dateline']) {
                 $searchindex = array('id' => $index['searchid'], 'dateline' => $index['dateline']);
                 break;
             } elseif ($_G['adminid'] != '1' && $index['flood']) {
                 //抱歉,您在 秒内只能进行一次搜索
                 return WebUtils::makeErrorInfo_oldVersion($res, 'search_ctrl', array('searchctrl' => $_G['setting']['search']['forum']['searchctrl']));
             }
         }
         if ($searchindex['id']) {
             $searchid = $searchindex['id'];
         } else {
             if ($_G['adminid'] != '1' && $_G['setting']['search']['forum']['maxspm']) {
                 if (C::t('common_searchindex')->count_by_dateline($_G['timestamp'], $srchmod) >= $_G['setting']['search']['forum']['maxspm']) {
                     //抱歉,站点设置每分钟系统最多响应搜索请求 {maxspm} 次,请稍候再试
                     return WebUtils::makeErrorInfo_oldVersion($res, 'search_toomany', array('maxspm' => $_G['setting']['search']['forum']['maxspm']));
                 }
             }
             $digestltd = $srchfilter == 'digest' ? "t.digest>'0' AND" : '';
             $topltd = $srchfilter == 'top' ? "AND t.displayorder>'0'" : "AND t.displayorder>='0'";
             $sqlsrch = $srchtype == 'fulltext' ? "FROM " . DB::table(getposttable($seltableid)) . " p, " . DB::table('forum_thread') . " t WHERE {$digestltd} t.fid IN ({$fids}) {$topltd} AND p.tid=t.tid AND p.invisible='0'" : "FROM " . DB::table('forum_thread') . " t WHERE {$digestltd} t.fid IN ({$fids}) {$topltd}";
             if ($srchtxt) {
                 $srcharr = $srchtype == 'fulltext' ? searchkey($keyword, "(p.message LIKE '%{text}%' OR p.subject LIKE '%{text}%')", true) : searchkey($keyword, "t.subject LIKE '%{text}%'", true);
                 $srchtxt = $srcharr[0];
                 $sqlsrch .= $srcharr[1];
             }
             $keywords = str_replace('%', '+', $srchtxt);
             $expiration = TIMESTAMP + $cachelife_text;
             $num = $ids = 0;
             $_G['setting']['search']['forum']['maxsearchresults'] = $_G['setting']['search']['forum']['maxsearchresults'] ? intval($_G['setting']['search']['forum']['maxsearchresults']) : 500;
             $query = DB::query("SELECT " . ($srchtype == 'fulltext' ? 'DISTINCT' : '') . " t.tid, t.closed, t.author, t.authorid {$sqlsrch} ORDER BY tid DESC LIMIT " . $_G['setting']['search']['forum']['maxsearchresults']);
             while ($thread = DB::fetch($query)) {
                 $ids .= ',' . $thread['tid'];
                 $num++;
             }
             DB::free_result($query);
             $idsArr = explode(',', $ids);
             $idCount = count($idsArr);
             if ($idCount == 1) {
                 return WebUtils::makeErrorInfo_oldVersion($res, 'search_no_results');
             }
             $searchid = C::t('common_searchindex')->insert(array('srchmod' => $srchmod, 'keywords' => $keywords, 'searchstring' => $searchstring, 'useip' => $_G['clientip'], 'uid' => $_G['uid'], 'dateline' => $_G['timestamp'], 'expiration' => $expiration, 'num' => $num, 'ids' => $ids), true);
             !($_G['group']['exempt'] & 2) && updatecreditbyaction('search');
         }
     }
     //这个分支要把数据取出来,并且返回正确的数据结构
     $start_limit = ($page - 1) * $pagesize;
     $index = C::t('common_searchindex')->fetch_by_searchid_srchmod($searchid, $srchmod);
     if (!$index) {
         //showmessage('search_id_invalid');//指定的搜索不存在或已过期
         return WebUtils::makeErrorInfo_oldVersion($res, 'search_id_invalid');
     }
     $keyword = dhtmlspecialchars($index['keywords']);
     $keyword = $keyword != '' ? str_replace('+', ' ', $keyword) : '';
     $index['keywords'] = rawurlencode($index['keywords']);
     $searchstring = explode('|', $index['searchstring']);
     $index['searchtype'] = $searchstring[0];
     $searchstring[2] = base64_decode($searchstring[2]);
     $srchuname = $searchstring[3];
     $modfid = 0;
     if ($keyword) {
         $modkeyword = str_replace(' ', ',', $keyword);
         $fids = explode(',', str_replace('\'', '', $searchstring[5]));
         if (count($fids) == 1 && in_array($_G['adminid'], array(1, 2, 3))) {
             $modfid = $fids[0];
             if ($_G['adminid'] == 3 && !C::t('forum_moderator')->fetch_uid_by_fid_uid($modfid, $_G['uid'])) {
                 $modfid = 0;
             }
         }
     }
     $threadlist = $posttables = array();
     foreach (C::t('forum_thread')->fetch_all_by_tid_fid_displayorder(explode(',', $index['ids']), null, 0, $orderby, $start_limit, $pagesize, '>=', $ascdesc, 0) as $thread) {
         $thread['subject'] = bat_highlight($thread['subject'], $keyword);
         $thread['realtid'] = $thread['isgroup'] == 1 ? $thread['closed'] : $thread['tid'];
         $tempLastPost = $thread['lastpost'];
         $tempDateLine = $thread['dateline'];
         $threadlist[$thread['tid']] = procthread($thread, 'dt');
         $threadlist[$thread['tid']]['lastpost'] = $tempLastPost;
         $threadlist[$thread['tid']]['dateline'] = $tempDateLine;
         $posttables[$thread['posttableid']][] = $thread['tid'];
     }
     if ($threadlist) {
         foreach ($posttables as $tableid => $tids) {
             foreach (C::t('forum_post')->fetch_all_by_tid($tableid, $tids, true, '', 0, 0, 1) as $post) {
                 $threadlist[$post['tid']]['message'] = bat_highlight(messagecutstr($post['message'], 200), $keyword);
             }
         }
     }
     $pageInfo = $row = $rows = array();
     $rows = $this->_fieldInfo($threadlist);
     $pageInfo = WebUtils::getWebApiArrayWithPage_oldVersion($page, $pagesize, $index['num']);
     $res = array_merge($res, $pageInfo);
     $res['searchid'] = (int) $searchid;
     $res['list'] = $rows;
     return $res;
 }
Example #9
0
function jsg_member_get($p, $mark = 1, $cache = 1)
{
    if ($cache && $p['uid'] && $p['uid'] == MEMBER_ID && $GLOBALS['_J']['member']) {
        return array('list' => array($GLOBALS['_J']['member']));
    }
    static $S_members = array();
    if ($cache) {
        $cache_id = md5(serialize($p) . $mark);
        if (isset($S_members[$cache_id])) {
            return $S_members[$cache_id];
        }
    }
    $wheres = array();
    $ws = array('uid' => 1, 'username' => 1, 'nickname' => 1, 'email' => 1, 'phone' => 1, 'province' => 1, 'city' => 1, 'role_id' => 1, 'ucuid' => 1, 'invite_uid' => 1);
    foreach ($p as $k => $v) {
        if (isset($ws[$k])) {
            $vs = (array) $v;
            $wheres[$k] = " `{$k}` IN ('" . implode("','", $vs) . "') ";
        }
    }
    $sql_where = $wheres ? " WHERE " . implode(" AND ", $wheres) : "";
    $count = max(0, (int) $p['count']);
    if ($count < 1) {
        $count = DB::result_first("SELECT COUNT(*) AS `count` FROM " . DB::table('members') . " {$sql_where} ");
    }
    $rets = array();
    if ($count > 0) {
        $page = array();
        $sql_limit = '';
        if ($p['per_page_num']) {
            $page = page($count, $p['per_page_num'], $p['page_url'], array('return' => 'Array', 'extra' => $p['page_extra']));
            $sql_limit = " {$page['limit']} ";
        } elseif ($p['limit']) {
            if (false !== strpos(strtolower($p['limit']), 'limit ')) {
                $sql_limit = " {$p['limit']} ";
            } else {
                $sql_limit = " LIMIT {$p['limit']} ";
            }
        } elseif ($p['count']) {
            $sql_limit = " LIMIT {$p['count']} ";
        }
        $sql_order = '';
        if ($p['order']) {
            if (false !== strpos(strtolower($p['order']), 'order by ')) {
                $sql_order = " {$p['order']} ";
            } else {
                $sql_order = " ORDER BY {$p['order']} ";
            }
        }
        $sql_fields = $p['fields'] ? $p['fields'] : "*";
        $query = DB::query("SELECT {$sql_fields} FROM " . DB::table('members') . " {$sql_where} {$sql_order} {$sql_limit} ");
        $list = array();
        while (false != ($r = DB::fetch($query))) {
            if ($mark) {
                $r = jsg_member_make($r);
            }
            $list[] = $r;
        }
        DB::free_result($query);
        if ($list) {
            if ($mark) {
                $list = buddy_follow_html($list, 'uid', true === IN_JISHIGOU_WAP ? 'wap_follow_html' : 'follow_html');
            }
            $rets = array('count' => $count, 'list' => $list, 'page' => $page);
        }
    }
    if ($cache && $cache_id) {
        $S_members[$cache_id] = $rets;
    }
    return $rets;
}