本文整理汇总了PHP中cache_get_data函数的典型用法代码示例。如果您正苦于以下问题:PHP cache_get_data函数的具体用法?PHP cache_get_data怎么用?PHP cache_get_data使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cache_get_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getLegacyKarmaByMemberID
/**
* Get legacy karma value for member id
* @param int $member_id
* @return array|bool
*/
function getLegacyKarmaByMemberID($member_id = 0)
{
global $smcFunc;
if (!$member_id) {
return false;
}
// Check cache
$legacyKarma = cache_get_data('legacyKarma_' . $member_id);
if (empty($legacyKarma)) {
$request = $smcFunc['db_query']('', '
SELECT karma_good, karma_bad
FROM {db_prefix}members
WHERE id_member = {int:member_id}
LIMIT 1', array('member_id' => $member_id));
$legacyKarma = array();
list($legacyKarma['good'], $legacyKarma['bad']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
cache_put_data('legacyKarma_' . $member_id, $legacyKarma);
}
if (!empty($legacyKarma['good']) || !empty($legacyKarma['bad'])) {
return (!empty($legacyKarma['good']) ? '+' . $legacyKarma['good'] : '') . (!empty($legacyKarma['good']) && !empty($legacyKarma['bad']) ? '/' : '') . (!empty($legacyKarma['bad']) ? '-' . $legacyKarma['bad'] : '');
} else {
return false;
}
}
示例2: load_theme
public static function load_theme()
{
global $context, $modSettings, $txt, $settings, $user_info;
if (($themes = cache_get_data('TS_themes_list', 3600)) === null) {
loadLanguage('ManageThemes');
require_once SUBSDIR . '/Themes.subs.php';
$themes = availableThemes($user_info['theme'], $user_info['id']);
cache_put_data('TS_themes_list', $themes, 3600);
}
foreach ($themes[0] as $theme_id => $theme) {
$name = $theme['name'];
$selected = !empty($user_info['theme']) && $user_info['theme'] == $theme_id;
$context['ThemeSelector'][$theme_id] = array('name' => $name, 'selected' => $selected, 'variants' => array());
if (isset($theme['variants'])) {
foreach ($theme['variants'] as $key => $variant) {
$context['ThemeSelector'][$theme_id]['variants'][$key] = array('name' => $variant['label'], 'selected' => $context['theme_variant'] == '_' . $key);
}
}
}
if (!isset($context['theme_header_callbacks'])) {
$context['theme_header_callbacks'] = array();
}
$context['theme_header_callbacks'][] = 'themeselector';
loadTemplate('ThemeSelector');
loadJavascriptFile('ThemeSelector.js');
loadCSSFile('ThemeSelector.css');
}
示例3: cache_quick_get
/**
* Try to retrieve a cache entry. On failure, call the appropriate function.
* This callback is sent as $file to include, and $function to call, with
* $params parameters.
*
* @param string $key cache entry key
* @param string $file file to include
* @param string $function function to call
* @param mixed[] $params parameters sent to the function
* @param int $level = 1
* @return string
*/
function cache_quick_get($key, $file, $function, $params, $level = 1)
{
global $modSettings;
// @todo Why are we doing this if caching is disabled?
if (function_exists('call_integration_hook')) {
call_integration_hook('pre_cache_quick_get', array(&$key, &$file, &$function, &$params, &$level));
}
/* Refresh the cache if either:
1. Caching is disabled.
2. The cache level isn't high enough.
3. The item has not been cached or the cached item expired.
4. The cached item has a custom expiration condition evaluating to true.
5. The expire time set in the cache item has passed (needed for Zend).
*/
if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < $level || !is_array($cache_block = cache_get_data($key, 3600)) || !empty($cache_block['refresh_eval']) && eval($cache_block['refresh_eval']) || !empty($cache_block['expires']) && $cache_block['expires'] < time()) {
require_once SOURCEDIR . '/' . $file;
$cache_block = call_user_func_array($function, $params);
if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
cache_put_data($key, $cache_block, $cache_block['expires'] - time());
}
}
// Some cached data may need a freshening up after retrieval.
if (!empty($cache_block['post_retri_eval'])) {
eval($cache_block['post_retri_eval']);
}
if (function_exists('call_integration_hook')) {
call_integration_hook('post_cache_quick_get', array($cache_block));
}
return $cache_block['data'];
}
示例4: template_init
function template_init()
{
global $context, $settings, $options, $txt, $modSettings;
$settings['use_default_images'] = 'never';
$settings['doctype'] = 'html';
$settings['theme_version'] = '2.0';
$settings['use_tabs'] = true;
$settings['use_buttons'] = true;
$settings['separate_sticky_lock'] = true;
$settings['strict_doctype'] = false;
$settings['message_index_preview'] = true;
$settings['require_theme_strings'] = true;
$settings['alphathemes'] = true;
if (($settings['tp_boardicons'] = cache_get_data('alpha_boardicons', 2)) == null) {
$settings['tp_boardicons'] = my_readfolder($settings['theme_dir'] . '/images/boardicons', $settings['theme_url'] . '/images/boardicons', '.png');
cache_put_data('alpha_boardicons', $settings['tp_boardicons'], 2);
}
$settings['extra_copyrights'] = array('<b>ShelfLife</b> theme © 2015, BK');
$settings['catch_action'] = array('layers' => array('wrapinit', 'html', 'body', 'wrap'));
/* all modules possible
$settings['module_display'] = '';
$settings['module_boardindex'] = '';
$settings['module_messageindex'] = '';
$settings['module_profile'] = '';
$settings['module_pm'] = '';
*/
// can be board-based.
}
示例5: sportal_get_shouts
/**
* Loads all the shouts for a given shoutbox
*
* @param int $shoutbox id of the shoutbox to get data from
* @param mixed[] $parameters
*
* @return type
*/
function sportal_get_shouts($shoutbox, $parameters)
{
global $scripturl, $context, $user_info, $modSettings, $txt;
$db = database();
// Set defaults or used what was passed
$shoutbox = !empty($shoutbox) ? (int) $shoutbox : 0;
$start = !empty($parameters['start']) ? (int) $parameters['start'] : 0;
$limit = !empty($parameters['limit']) ? (int) $parameters['limit'] : 20;
$bbc = !empty($parameters['bbc']) ? $parameters['bbc'] : array();
$reverse = !empty($parameters['reverse']);
$cache = !empty($parameters['cache']);
$can_delete = !empty($parameters['can_moderate']);
// Cached, use it first
if (!empty($start) || !$cache || ($shouts = cache_get_data('shoutbox_shouts-' . $shoutbox, 240)) === null) {
$request = $db->query('', '
SELECT
sh.id_shout, sh.body, IFNULL(mem.id_member, 0) AS id_member,
IFNULL(mem.real_name, sh.member_name) AS member_name, sh.log_time,
mg.online_color AS member_group_color, pg.online_color AS post_group_color
FROM {db_prefix}sp_shouts AS sh
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = sh.id_member)
LEFT JOIN {db_prefix}membergroups AS pg ON (pg.id_group = mem.id_post_group)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = mem.id_group)
WHERE sh.id_shoutbox = {int:id_shoutbox}
ORDER BY sh.id_shout DESC
LIMIT {int:start}, {int:limit}', array('id_shoutbox' => $shoutbox, 'start' => $start, 'limit' => $limit));
$shouts = array();
while ($row = $db->fetch_assoc($request)) {
// Disable the aeva mod for the shoutbox.
$context['aeva_disable'] = true;
$online_color = !empty($row['member_group_color']) ? $row['member_group_color'] : $row['post_group_color'];
$shouts[$row['id_shout']] = array('id' => $row['id_shout'], 'author' => array('id' => $row['id_member'], 'name' => $row['member_name'], 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" title="' . $txt['on'] . ' ' . strip_tags(standardTime($row['log_time'])) . '"' . (!empty($online_color) ? ' style="color: ' . $online_color . ';"' : '') . '>' . $row['member_name'] . '</a>' : $row['member_name'], 'color' => $online_color), 'time' => $row['log_time'], 'text' => parse_bbc($row['body'], true, '', $bbc));
}
$db->free_result($request);
if (empty($start) && $cache) {
cache_put_data('shoutbox_shouts-' . $shoutbox, $shouts, 240);
}
}
foreach ($shouts as $shout) {
// Private shouts @username: only get shown to the shouter and shoutee, and the admin
if (preg_match('~^@(.+?): ~u', $shout['text'], $target) && Util::strtolower($target[1]) !== Util::strtolower($user_info['name']) && $shout['author']['id'] != $user_info['id'] && !$user_info['is_admin']) {
unset($shouts[$shout['id']]);
continue;
}
$shouts[$shout['id']] += array('is_me' => preg_match('~^<div\\sclass="meaction">\\* ' . preg_quote($shout['author']['name'], '~') . '.+</div>$~', $shout['text']) != 0, 'delete_link' => $can_delete ? '<a class="dot dotdelete" href="' . $scripturl . '?action=shoutbox;shoutbox_id=' . $shoutbox . ';delete=' . $shout['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '"></a> ' : '', 'delete_link_js' => $can_delete ? '<a class="dot dotdelete" href="' . $scripturl . '?action=shoutbox;shoutbox_id=' . $shoutbox . ';delete=' . $shout['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="sp_delete_shout(' . $shoutbox . ', ' . $shout['id'] . ', \'' . $context['session_var'] . '\', \'' . $context['session_id'] . '\'); return false;"></a> ' : '');
// Prepare for display in the box
$shouts[$shout['id']]['time'] = standardTime($shouts[$shout['id']]['time']);
$shouts[$shout['id']]['text'] = preg_replace('~(</?)div([^<]*>)~', '$1span$2', $shouts[$shout['id']]['text']);
$shouts[$shout['id']]['text'] = preg_replace('~<a([^>]+>)([^<]+)</a>~', '<a$1' . $txt['sp_link'] . '</a>', $shouts[$shout['id']]['text']);
$shouts[$shout['id']]['text'] = censorText($shouts[$shout['id']]['text']);
// Ignored user, hide the shout with option to show it
if (!empty($modSettings['enable_buddylist']) && in_array($shout['author']['id'], $context['user']['ignoreusers'])) {
$shouts[$shout['id']]['text'] = '<a href="#toggle" id="ignored_shout_link_' . $shout['id'] . '" onclick="sp_show_ignored_shout(' . $shout['id'] . '); return false;">[' . $txt['sp_shoutbox_show_ignored'] . ']</a><span id="ignored_shout_' . $shout['id'] . '" style="display: none;">' . $shouts[$shout['id']]['text'] . '</span>';
}
}
if ($reverse) {
$shouts = array_reverse($shouts);
}
return $shouts;
}
示例6: akismet_load_theme
function akismet_load_theme()
{
global $context, $topic;
// Is this a topic being displayed?
if (empty($_REQUEST['action']) && !empty($board) && !empty($topic)) {
// Looking through the topic table can be slow, so try using the cache first.
if (($spam = cache_get_data('akismet-spam-topic-' . $topic, 3600)) === NULL) {
$request = $smcFunc['db_query']('', '
SELECT id_topic
FROM {db_prefix}topics
WHERE id_topic = {int:id_topic}', array('id_topic' => $topic));
// So did it find anything?
if ($smcFunc['db_num_rows']($request)) {
list($spam) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
// Save save save.
cache_put_data('akismet-spam-topic-' . $topic, $spam, 120);
}
}
if (!empty($span)) {
// So we now know this is a spam topic. Show a warning.
loadLanguage('Akismet');
loadTemplate('Akismet');
$context['template_layers'][] = 'akismet_warn_topic';
}
}
}
示例7: parsesmileys
/**
* Parse smileys in the passed message.
*
* What it does:
* - The smiley parsing function which makes pretty faces appear :).
* - If custom smiley sets are turned off by smiley_enable, the default set of smileys will be used.
* - These are specifically not parsed in code tags [url=mailto:Dad@blah.com]
* - Caches the smileys from the database or array in memory.
* - Doesn't return anything, but rather modifies message directly.
*
* @param string $message
*/
function parsesmileys(&$message)
{
global $modSettings, $txt, $user_info;
static $smileyPregSearch = null, $smileyPregReplacements = array();
// No smiley set at all?!
if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
return;
}
// If smileyPregSearch hasn't been set, do it now.
if (empty($smileyPregSearch)) {
// Use the default smileys if it is disabled. (better for "portability" of smileys.)
if (empty($modSettings['smiley_enable'])) {
$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', 'O:)');
$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], $txt['icon_laugh'], $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', $txt['icon_angel']);
} else {
// Load the smileys in reverse order by length so they don't get parsed wrong.
if (($temp = cache_get_data('parsing_smileys', 480)) == null) {
$smileysfrom = array();
$smileysto = array();
$smileysdescs = array();
// @todo there is no reason $db should be used before this
$db = database();
$db->fetchQueryCallback('
SELECT code, filename, description
FROM {db_prefix}smileys
ORDER BY LENGTH(code) DESC', array(), function ($row) use(&$smileysfrom, &$smileysto, &$smileysdescs) {
$smileysfrom[] = $row['code'];
$smileysto[] = htmlspecialchars($row['filename']);
$smileysdescs[] = $row['description'];
});
cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
} else {
list($smileysfrom, $smileysto, $smileysdescs) = $temp;
}
}
// The non-breaking-space is a complex thing...
$non_breaking_space = '\\x{A0}';
// This smiley regex makes sure it doesn't parse smileys within code tags (so [url=mailto:David@bla.com] doesn't parse the :D smiley)
$smileyPregReplacements = array();
$searchParts = array();
$smileys_path = htmlspecialchars($modSettings['smileys_url'] . '/' . $user_info['smiley_set'] . '/');
for ($i = 0, $n = count($smileysfrom); $i < $n; $i++) {
$specialChars = htmlspecialchars($smileysfrom[$i], ENT_QUOTES);
$smileyCode = '<img src="' . $smileys_path . $smileysto[$i] . '" alt="' . strtr($specialChars, array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" title="' . strtr(htmlspecialchars($smileysdescs[$i]), array(':' => ':', '(' => '(', ')' => ')', '$' => '$', '[' => '[')) . '" class="smiley" />';
$smileyPregReplacements[$smileysfrom[$i]] = $smileyCode;
$searchParts[] = preg_quote($smileysfrom[$i], '~');
if ($smileysfrom[$i] != $specialChars) {
$smileyPregReplacements[$specialChars] = $smileyCode;
$searchParts[] = preg_quote($specialChars, '~');
}
}
$smileyPregSearch = '~(?<=[>:\\?\\.\\s' . $non_breaking_space . '[\\]()*\\\\;]|^)(' . implode('|', $searchParts) . ')(?=[^[:alpha:]0-9]|$)~';
}
// Replace away!
$message = preg_replace_callback($smileyPregSearch, function ($matches) use($smileyPregReplacements) {
return $smileyPregReplacements[$matches[0]];
}, $message);
}
示例8: parse_smileys
function parse_smileys(&$message)
{
global $modSettings, $txt, $user_info, $context, $smcFunc;
static $smileyarray = array();
// No smiley set at all?!
if ($user_info['smiley_set'] == 'none' || trim($message) == '') {
return;
}
// If the smiley array hasn't been set, do it now.
if (empty($smileyarray)) {
// Small fix because entities are getting messed up
$smileyarray = array('"' => '"', ''' => ''', ''' => ''', '<' => '<', '>' => '>', '&' => '&');
// Use the default smileys if it is disabled. (better for "portability" of smileys.)
if (empty($modSettings['smiley_enable'])) {
$smileysfrom = array('>:D', ':D', '::)', '>:(', ':))', ':)', ';)', ';D', ':(', ':o', '8)', ':P', '???', ':-[', ':-X', ':-*', ':\'(', ':-\\', '^-^', 'O0', 'C:-)', '0:)');
$smileysto = array('evil.gif', 'cheesy.gif', 'rolleyes.gif', 'angry.gif', 'laugh.gif', 'smiley.gif', 'wink.gif', 'grin.gif', 'sad.gif', 'shocked.gif', 'cool.gif', 'tongue.gif', 'huh.gif', 'embarrassed.gif', 'lipsrsealed.gif', 'kiss.gif', 'cry.gif', 'undecided.gif', 'azn.gif', 'afro.gif', 'police.gif', 'angel.gif');
$smileysdescs = array('', $txt['icon_cheesy'], $txt['icon_rolleyes'], $txt['icon_angry'], '', $txt['icon_smiley'], $txt['icon_wink'], $txt['icon_grin'], $txt['icon_sad'], $txt['icon_shocked'], $txt['icon_cool'], $txt['icon_tongue'], $txt['icon_huh'], $txt['icon_embarrassed'], $txt['icon_lips'], $txt['icon_kiss'], $txt['icon_cry'], $txt['icon_undecided'], '', '', '', '');
} else {
// Load the smileys in reverse order by length so they don't get parsed wrong.
if (($temp = cache_get_data('parsing_smileys', 480)) == null) {
$result = $smcFunc['db_query']('', '
SELECT code, filename, description
FROM {db_prefix}smileys', array());
$smileysfrom = array();
$smileysto = array();
$smileysdescs = array();
while ($row = $smcFunc['db_fetch_assoc']($result)) {
$smileysfrom[] = $row['code'];
$smileysto[] = $row['filename'];
$smileysdescs[] = $row['description'];
}
$smcFunc['db_free_result']($result);
cache_put_data('parsing_smileys', array($smileysfrom, $smileysto, $smileysdescs), 480);
} else {
list($smileysfrom, $smileysto, $smileysdescs) = $temp;
}
}
foreach ($smileysfrom as $i => $from) {
$smileyCode = '<img src="' . $modSettings['smileys_url'] . '/' . $user_info['smiley_set'] . '/' . $smileysto[$i] . '" alt="' . htmlentities($from) . '" title="' . htmlentities($smileysdescs[$i]) . '" class="smiley" />';
$smileyarray[$from] = $smileyCode;
if ($from != ($specialChars = htmlspecialchars($from, ENT_QUOTES))) {
$smileyarray[$specialChars] = $smileyCode;
}
}
}
// Replace away!
$message = strtr($message, $smileyarray);
}
示例9: loadMessageLimit
/**
* Loads information about the users personal message limit.
*
* @package PersonalMessage
*/
function loadMessageLimit()
{
global $user_info, $context;
$db = database();
if ($user_info['is_admin']) {
$context['message_limit'] = 0;
} elseif (($context['message_limit'] = cache_get_data('msgLimit:' . $user_info['id'], 360)) === null) {
$request = $db->query('', '
SELECT
MAX(max_messages) AS top_limit, MIN(max_messages) AS bottom_limit
FROM {db_prefix}membergroups
WHERE id_group IN ({array_int:users_groups})', array('users_groups' => $user_info['groups']));
list($maxMessage, $minMessage) = $db->fetch_row($request);
$db->free_result($request);
$context['message_limit'] = $minMessage == 0 ? 0 : $maxMessage;
// Save us doing it again!
cache_put_data('msgLimit:' . $user_info['id'], $context['message_limit'], 360);
}
}
示例10: loadArcadeSettings
function loadArcadeSettings()
{
global $arcSettings, $modSettings, $smcFunc;
if (($arcSettings = cache_get_data('arcSettings', 90)) == null) {
$request = $smcFunc['db_query']('', '
SELECT variable, value
FROM {db_prefix}arcade_settings', array());
$arcSettings = array();
if (!$request) {
db_fatal_error();
}
while ($row = $smcFunc['db_fetch_row']($request)) {
$arcSettings[$row[0]] = $row[1];
}
$smcFunc['db_free_result']($request);
if (!empty($modSettings['cache_enable'])) {
cache_put_data('arcSettings', $arcSettings, 90);
}
}
}
示例11: setupMenuContext
function setupMenuContext()
{
global $context, $modSettings, $user_info, $txt, $scripturl;
// Set up the menu privileges.
$context['allow_search'] = allowedTo('search_posts');
$context['allow_admin'] = allowedTo(array('admin_forum', 'manage_boards', 'manage_permissions', 'moderate_forum', 'manage_membergroups', 'manage_bans', 'send_mail', 'edit_news', 'manage_attachments', 'manage_smileys'));
$context['allow_edit_profile'] = !$user_info['is_guest'] && allowedTo(array('profile_view_own', 'profile_view_any', 'profile_identity_own', 'profile_identity_any', 'profile_extra_own', 'profile_extra_any', 'profile_remove_own', 'profile_remove_any', 'moderate_forum', 'manage_membergroups', 'profile_title_own', 'profile_title_any'));
$context['allow_memberlist'] = allowedTo('view_mlist');
$context['allow_calendar'] = allowedTo('calendar_view') && !empty($modSettings['cal_enabled']);
$context['allow_moderation_center'] = $context['user']['can_mod'];
$context['allow_pm'] = allowedTo('pm_read');
$cacheTime = $modSettings['lastActive'] * 60;
// All the buttons we can possible want and then some, try pulling the final list of buttons from cache first.
if (($menu_buttons = cache_get_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $cacheTime)) === null || time() - $cacheTime <= $modSettings['settings_updated']) {
$buttons = array('home' => array('title' => $txt['home'], 'href' => $scripturl, 'show' => true, 'sub_buttons' => array(), 'is_last' => $context['right_to_left']), 'help' => array('title' => $txt['help'], 'href' => $scripturl . '?action=help', 'show' => true, 'sub_buttons' => array()), 'search' => array('title' => $txt['search'], 'href' => $scripturl . '?action=search', 'show' => $context['allow_search'], 'sub_buttons' => array()), 'admin' => array('title' => $txt['admin'], 'href' => $scripturl . '?action=admin', 'show' => $context['allow_admin'], 'sub_buttons' => array('featuresettings' => array('title' => $txt['modSettings_title'], 'href' => $scripturl . '?action=admin;area=featuresettings', 'show' => allowedTo('admin_forum')), 'packages' => array('title' => $txt['package'], 'href' => $scripturl . '?action=admin;area=packages', 'show' => allowedTo('admin_forum')), 'errorlog' => array('title' => $txt['errlog'], 'href' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc', 'show' => allowedTo('admin_forum') && !empty($modSettings['enableErrorLogging'])), 'permissions' => array('title' => $txt['edit_permissions'], 'href' => $scripturl . '?action=admin;area=permissions', 'show' => allowedTo('manage_permissions'), 'is_last' => true))), 'moderate' => array('title' => $txt['moderate'], 'href' => $scripturl . '?action=moderate', 'show' => $context['allow_moderation_center'], 'sub_buttons' => array('modlog' => array('title' => $txt['modlog_view'], 'href' => $scripturl . '?action=moderate;area=modlog', 'show' => !empty($modSettings['modlog_enabled']) && !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1'), 'poststopics' => array('title' => $txt['mc_unapproved_poststopics'], 'href' => $scripturl . '?action=moderate;area=postmod;sa=posts', 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'attachments' => array('title' => $txt['mc_unapproved_attachments'], 'href' => $scripturl . '?action=moderate;area=attachmod;sa=attachments', 'show' => $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap'])), 'reports' => array('title' => $txt['mc_reported_posts'], 'href' => $scripturl . '?action=moderate;area=reports', 'show' => !empty($user_info['mod_cache']) && $user_info['mod_cache']['bq'] != '0=1', 'is_last' => true))), 'profile' => array('title' => $txt['profile'], 'href' => $scripturl . '?action=profile', 'show' => $context['allow_edit_profile'], 'sub_buttons' => array('summary' => array('title' => $txt['summary'], 'href' => $scripturl . '?action=profile', 'show' => true), 'account' => array('title' => $txt['account'], 'href' => $scripturl . '?action=profile;area=account', 'show' => allowedTo(array('profile_identity_any', 'profile_identity_own', 'manage_membergroups'))), 'profile' => array('title' => $txt['forumprofile'], 'href' => $scripturl . '?action=profile;area=forumprofile', 'show' => allowedTo(array('profile_extra_any', 'profile_extra_own')), 'is_last' => true))), 'pm' => array('title' => $txt['pm_short'], 'href' => $scripturl . '?action=pm', 'show' => $context['allow_pm'], 'sub_buttons' => array('pm_read' => array('title' => $txt['pm_menu_read'], 'href' => $scripturl . '?action=pm', 'show' => allowedTo('pm_read')), 'pm_send' => array('title' => $txt['pm_menu_send'], 'href' => $scripturl . '?action=pm;sa=send', 'show' => allowedTo('pm_send'), 'is_last' => true))), 'calendar' => array('title' => $txt['calendar'], 'href' => $scripturl . '?action=calendar', 'show' => $context['allow_calendar'], 'sub_buttons' => array('view' => array('title' => $txt['calendar_menu'], 'href' => $scripturl . '?action=calendar', 'show' => allowedTo('calendar_post')), 'post' => array('title' => $txt['calendar_post_event'], 'href' => $scripturl . '?action=calendar;sa=post', 'show' => allowedTo('calendar_post'), 'is_last' => true))), 'mlist' => array('title' => $txt['members_title'], 'href' => $scripturl . '?action=mlist', 'show' => $context['allow_memberlist'], 'sub_buttons' => array('mlist_view' => array('title' => $txt['mlist_menu_view'], 'href' => $scripturl . '?action=mlist', 'show' => true), 'mlist_search' => array('title' => $txt['mlist_search'], 'href' => $scripturl . '?action=mlist;sa=search', 'show' => true, 'is_last' => true))), 'login' => array('title' => $txt['login'], 'href' => $scripturl . '?action=login', 'show' => $user_info['is_guest'], 'sub_buttons' => array()), 'register' => array('title' => $txt['register'], 'href' => $scripturl . '?action=register', 'show' => $user_info['is_guest'], 'sub_buttons' => array(), 'is_last' => !$context['right_to_left']), 'logout' => array('title' => $txt['logout'], 'href' => $scripturl . '?action=logout;%1$s=%2$s', 'show' => !$user_info['is_guest'], 'sub_buttons' => array(), 'is_last' => !$context['right_to_left']));
// Allow editing menu buttons easily.
call_integration_hook('integrate_menu_buttons', array(&$buttons));
// Now we put the buttons in the context so the theme can use them.
$menu_buttons = array();
foreach ($buttons as $act => $button) {
if (!empty($button['show'])) {
$button['active_button'] = false;
// Make sure the last button truely is the last button.
if (!empty($button['is_last'])) {
if (isset($last_button)) {
unset($menu_buttons[$last_button]['is_last']);
}
$last_button = $act;
}
// Go through the sub buttons if there are any.
if (!empty($button['sub_buttons'])) {
foreach ($button['sub_buttons'] as $key => $subbutton) {
if (empty($subbutton['show'])) {
unset($button['sub_buttons'][$key]);
}
// 2nd level sub buttons next...
if (!empty($subbutton['sub_buttons'])) {
foreach ($subbutton['sub_buttons'] as $key2 => $sub_button2) {
if (empty($sub_button2['show'])) {
unset($button['sub_buttons'][$key]['sub_buttons'][$key2]);
}
}
}
}
}
$menu_buttons[$act] = $button;
}
}
if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= 2) {
cache_put_data('menu_buttons-' . implode('_', $user_info['groups']) . '-' . $user_info['language'], $menu_buttons, $cacheTime);
}
}
$context['menu_buttons'] = $menu_buttons;
// Logging out requires the session id in the url.
if (isset($context['menu_buttons']['logout'])) {
$context['menu_buttons']['logout']['href'] = sprintf($context['menu_buttons']['logout']['href'], $context['session_var'], $context['session_id']);
}
// Figure out which action we are doing so we can set the active tab.
// Default to home.
$current_action = 'home';
if (isset($context['menu_buttons'][$context['current_action']])) {
$current_action = $context['current_action'];
} elseif ($context['current_action'] == 'search2') {
$current_action = 'search';
} elseif ($context['current_action'] == 'theme') {
$current_action = isset($_REQUEST['sa']) && $_REQUEST['sa'] == 'pick' ? 'profile' : 'admin';
} elseif ($context['current_action'] == 'register2') {
$current_action = 'register';
} elseif ($context['current_action'] == 'login2' || $user_info['is_guest'] && $context['current_action'] == 'reminder') {
$current_action = 'login';
} elseif ($context['current_action'] == 'groups' && $context['allow_moderation_center']) {
$current_action = 'moderate';
}
$context['menu_buttons'][$current_action]['active_button'] = true;
if (!$user_info['is_guest'] && $context['user']['unread_messages'] > 0 && isset($context['menu_buttons']['pm'])) {
$context['menu_buttons']['pm']['alttitle'] = $context['menu_buttons']['pm']['title'] . ' [' . $context['user']['unread_messages'] . ']';
$context['menu_buttons']['pm']['title'] .= ' [<strong>' . $context['user']['unread_messages'] . '</strong>]';
}
}
示例12: get_main_menu_groups
function get_main_menu_groups()
{
global $smcFunc;
if (($groups = cache_get_data('char_main_menu_groups', 300)) === null) {
$groups = [];
$request = $smcFunc['db_query']('', '
SELECT mg.id_group, mg.group_name
FROM {db_prefix}membergroups AS mg
INNER JOIN {db_prefix}characters AS chars ON (chars.main_char_group = mg.id_group)
WHERE chars.char_sheet != 0
GROUP BY mg.id_group
ORDER BY mg.badge_order, mg.group_name');
while ($row = $smcFunc['db_fetch_assoc']($request)) {
$groups[$row['id_group']] = $row['group_name'];
}
$smcFunc['db_free_result']($request);
cache_put_data('char_main_menu_groups', $groups, 300);
}
return $groups;
}
示例13: shd_load_user_perms
/**
* Defines user permissions, most importantly concerning ticket visibility
*
* Populates specific parameters in $user_info, mostly to add {} abstract variables in $smcFunc['db_query'] data calls.
* The foremost one of these is {query_see_ticket}, an SQL clause constructed to ensure ticket visibility is maintained given the
* active user's permission set.
*
* Prior to 1.1 this was in Subs-SimpleDesk.php
*
* @see shd_db_query()
* @since 1.0
*/
function shd_load_user_perms()
{
global $user_info, $context, $smcFunc, $modSettings;
// OK, have we been here before? If we have, we're done.
if (!empty($user_info['query_see_ticket'])) {
return;
}
// Right, we're loading the current user.
shd_load_role_templates();
// If they're a guest, bail; if they're not a forum admin (who can do anything), figure out what permissions they have
if (!empty($user_info['is_guest'])) {
$user_info['shd_permissions'] = array();
$user_info['query_see_ticket'] = '1=0';
return;
} elseif (empty($user_info['is_admin'])) {
$permissions_cache = 'shd_permissions_' . implode('-', $user_info['groups']);
$perm_cache_time = 300;
$temp = cache_get_data($permissions_cache, $perm_cache_time);
if ($temp === null || time() - $perm_cache_time > $modSettings['settings_updated']) {
$role_permissions = array();
// 1. Get all the roles that conceivably apply to this user.
$query = $smcFunc['db_query']('', '
SELECT hdrg.id_role, hdr.template
FROM {db_prefix}helpdesk_role_groups AS hdrg
INNER JOIN {db_prefix}helpdesk_roles AS hdr ON (hdrg.id_role = hdr.id_role)
WHERE hdrg.id_group IN ({array_int:groups})', array('groups' => $user_info['groups']));
$roles = array();
while ($row = $smcFunc['db_fetch_assoc']($query)) {
$role_permissions[$row['id_role']] = $context['shd_permissions']['roles'][$row['template']]['permissions'];
$roles[$row['id_role']] = true;
}
$smcFunc['db_free_result']($query);
// 1a. Get all the departments these roles are in.
$depts = array();
if (!empty($roles)) {
$query = $smcFunc['db_query']('', '
SELECT id_role, id_dept
FROM {db_prefix}helpdesk_dept_roles
WHERE id_role IN ({array_int:roles})', array('roles' => array_keys($roles)));
while ($row = $smcFunc['db_fetch_assoc']($query)) {
$depts[$row['id_role']][] = $row['id_dept'];
}
$smcFunc['db_free_result']($query);
}
$denied = array();
// 2.1. Apply role specific rules against their parent templates
if (!empty($depts)) {
$query = $smcFunc['db_query']('', '
SELECT id_role, permission, add_type
FROM {db_prefix}helpdesk_role_permissions
WHERE id_role IN ({array_int:roles})', array('roles' => array_keys($roles)));
while ($row = $smcFunc['db_fetch_assoc']($query)) {
if ($row['add_type'] == ROLEPERM_DENY) {
$denied[$row['permission']] = true;
} else {
$role_permissions[$row['id_role']][$row['permission']] = $row['add_type'];
}
}
$smcFunc['db_free_result']($query);
}
// 2.2 Having loaded all the roles, and applied role specific changes, fuse them all together
$user_info['shd_permissions'] = array();
if (!empty($depts) && !empty($role_permissions)) {
foreach ($role_permissions as $role => $perm_list) {
if (empty($depts[$role])) {
continue;
}
foreach ($perm_list as $perm => $value) {
if ($value == ROLEPERM_ALLOW) {
$user_info['shd_permissions'][$perm] = isset($user_info['shd_permissions'][$perm]) ? array_merge($user_info['shd_permissions'][$perm], $depts[$role]) : $depts[$role];
}
}
}
}
// 2.3 Apply any deny restrictions
if (!empty($denied)) {
foreach ($denied as $perm => $value) {
if (isset($user_info['shd_permissions'][$perm])) {
unset($user_info['shd_permissions'][$perm]);
}
}
}
cache_put_data($permissions_cache, $user_info['shd_permissions'], $perm_cache_time);
} else {
$user_info['shd_permissions'] = $temp;
}
} elseif ($user_info['is_admin']) {
// Figure out what departments there are, because these are the departments in which they have any given permission.
//.........这里部分代码省略.........
示例14: cache_quick_get
function cache_quick_get($key, $file, $function, $params, $level = 1)
{
global $modSettings, $sourcedir;
// Refresh the cache if either:
// 1. Caching is disabled.
// 2. The cache level isn't high enough.
// 3. The item has not been cached or the cached item expired.
// 4. The cached item has a custom expiration condition evaluating to true.
// 5. The expire time set in the cache item has passed (needed for Zend).
if (empty($modSettings['cache_enable']) || $modSettings['cache_enable'] < $level || !is_array($cache_block = cache_get_data($key, 3600)) || !empty($cache_block['refresh_eval']) && eval($cache_block['refresh_eval']) || !empty($cache_block['expires']) && $cache_block['expires'] < time()) {
require_once $sourcedir . '/' . $file;
$cache_block = call_user_func_array($function, $params);
if (!empty($modSettings['cache_enable']) && $modSettings['cache_enable'] >= $level) {
cache_put_data($key, $cache_block, $cache_block['expires'] - time());
}
}
// Some cached data may need a freshening up after retrieval.
if (!empty($cache_block['post_retri_eval'])) {
eval($cache_block['post_retri_eval']);
}
return $cache_block['data'];
}
示例15: searchQuery
/**
* This has it's own custom search.
*
* @param mixed[] $search_params
* @param mixed[] $search_words
* @param string[] $excluded_words
* @param int[] $participants
* @param string[] $search_results
*/
public function searchQuery($search_params, $search_words, $excluded_words, &$participants, &$search_results)
{
global $user_info, $context, $modSettings;
// Only request the results if they haven't been cached yet.
if (($cached_results = cache_get_data('searchql_results_' . md5($user_info['query_see_board'] . '_' . $context['params']))) === null) {
// Create an instance of the sphinx client and set a few options.
$mySphinx = @mysql_connect(($modSettings['sphinx_searchd_server'] === 'localhost' ? '127.0.0.1' : $modSettings['sphinx_searchd_server']) . ':' . (int) $modSettings['sphinxql_searchd_port']);
// No connection, daemon not running? log the error
if ($mySphinx === false) {
fatal_lang_error('error_no_search_daemon');
}
// Compile different options for our query
$query = 'SELECT *' . (empty($search_params['topic']) ? ', COUNT(*) num' : '') . ', (weight() + (relevance/1000)) rank FROM elkarte_index';
// Construct the (binary mode & |) query.
$where_match = $this->_constructQuery($search_params['search']);
// Nothing to search, return zero results
if (trim($where_match) === '') {
return 0;
}
if ($search_params['subject_only']) {
$where_match = '@subject ' . $where_match;
}
$query .= ' WHERE MATCH(\'' . $where_match . '\')';
// Set the limits based on the search parameters.
$extra_where = array();
if (!empty($search_params['min_msg_id']) || !empty($search_params['max_msg_id'])) {
$extra_where[] = 'id >= ' . $search_params['min_msg_id'] . ' AND id <= ' . (empty($search_params['max_msg_id']) ? (int) $modSettings['maxMsgID'] : $search_params['max_msg_id']);
}
if (!empty($search_params['topic'])) {
$extra_where[] = 'id_topic = ' . (int) $search_params['topic'];
}
if (!empty($search_params['brd'])) {
$extra_where[] = 'id_board IN (' . implode(',', $search_params['brd']) . ')';
}
if (!empty($search_params['memberlist'])) {
$extra_where[] = 'id_member IN (' . implode(',', $search_params['memberlist']) . ')';
}
if (!empty($extra_where)) {
$query .= ' AND ' . implode(' AND ', $extra_where);
}
// Put together a sort string; besides the main column sort (relevance, id_topic, or num_replies)
$search_params['sort_dir'] = strtoupper($search_params['sort_dir']);
$sphinx_sort = $search_params['sort'] === 'id_msg' ? 'id_topic' : $search_params['sort'];
// Add secondary sorting based on relevance value (if not the main sort method) and age
$sphinx_sort .= ' ' . $search_params['sort_dir'] . ($search_params['sort'] === 'relevance' ? '' : ', relevance DESC') . ', poster_time DESC';
// Replace relevance with the returned rank value, rank uses sphinx weight + our own computed field weight relevance
$sphinx_sort = str_replace('relevance ', 'rank ', $sphinx_sort);
// Grouping by topic id makes it return only one result per topic, so don't set that for in-topic searches
if (empty($search_params['topic'])) {
$query .= ' GROUP BY id_topic WITHIN GROUP ORDER BY ' . $sphinx_sort;
}
$query .= ' ORDER BY ' . $sphinx_sort;
$query .= ' LIMIT 0,' . (int) $modSettings['sphinx_max_results'];
// Set any options needed, like field weights
$query .= ' OPTION field_weights=(subject=' . (!empty($modSettings['search_weight_subject']) ? $modSettings['search_weight_subject'] * 200 : 1000) . ',body=1000)';
// Execute the search query.
$request = mysql_query($query, $mySphinx);
// Can a connection to the daemon be made?
if ($request === false) {
// Just log the error.
if (mysql_error($mySphinx)) {
log_error(mysql_error($mySphinx));
}
fatal_lang_error('error_no_search_daemon');
}
// Get the relevant information from the search results.
$cached_results = array('num_results' => 0, 'matches' => array());
if (mysql_num_rows($request) != 0) {
while ($match = mysql_fetch_assoc($request)) {
if (empty($search_params['topic'])) {
$num = isset($match['num']) ? $match['num'] : (isset($match['@count']) ? $match['@count'] : 0);
} else {
$num = 0;
}
$cached_results['matches'][$match['id']] = array('id' => $match['id_topic'], 'relevance' => round($match['relevance'] / 10000, 1) . '%', 'num_matches' => $num, 'matches' => array());
}
}
mysql_free_result($request);
mysql_close($mySphinx);
$cached_results['num_results'] = count($cached_results['matches']);
// Store the search results in the cache.
cache_put_data('searchql_results_' . md5($user_info['query_see_board'] . '_' . $context['params']), $cached_results, 600);
}
$participants = array();
foreach (array_slice(array_keys($cached_results['matches']), $_REQUEST['start'], $modSettings['search_results_per_page']) as $msgID) {
$context['topics'][$msgID] = $cached_results['matches'][$msgID];
$participants[$cached_results['matches'][$msgID]['id']] = false;
}
// Sentences need to be broken up in words for proper highlighting.
$search_results = array();
foreach ($search_words as $orIndex => $words) {
//.........这里部分代码省略.........