/** * Put a result into the cache. * * @param ID_TEXT The codename to check for cacheing * @param integer The TTL of what is being cached in minutes * @param LONG_TEXT The requisite situational information (a serialized map) [-> further restraints when reading] * @param mixed The result we are cacheing * @param ?array A list of the language files that need loading to use tempcode embedded in the cache (NULL: none required) * @param ?array A list of the javascript files that need loading to use tempcode embedded in the cache (NULL: none required) * @param ?array A list of the css files that need loading to use tempcode embedded in the cache (NULL: none required) * @param boolean Whether we are cacheing Tempcode (needs special care) * @param ?ID_TEXT The theme this is being cached for (NULL: current theme) * @param ?LANGUAGE_NAME The language this is being cached for (NULL: current language) */ function put_into_cache($codename, $ttl, $cache_identifier, $cache, $_langs_required = NULL, $_javascripts_required = NULL, $_csss_required = NULL, $tempcode = false, $theme = NULL, $lang = NULL) { if ($theme === NULL) { $theme = $GLOBALS['FORUM_DRIVER']->get_theme(); } if ($lang === NULL) { $lang = user_lang(); } global $KEEP_MARKERS, $SHOW_EDIT_LINKS; if ($KEEP_MARKERS || $SHOW_EDIT_LINKS) { return; } $langs_required = is_null($_langs_required) ? '' : implode(':', $_langs_required); $langs_required .= '!'; $langs_required .= is_null($_javascripts_required) ? '' : implode(':', $_javascripts_required); $langs_required .= '!'; $langs_required .= is_null($_csss_required) ? '' : implode(':', $_csss_required); if (!is_null($GLOBALS['MEM_CACHE'])) { $pcache = persistant_cache_get(array('CACHE', $codename)); if (is_null($pcache)) { $pcache = array(); } $pcache[$cache_identifier][$lang][$theme] = array('langs_required' => $langs_required, 'date_and_time' => time(), 'the_value' => $cache); persistant_cache_set(array('CACHE', $codename), $pcache, false, $ttl * 60); } else { $GLOBALS['SITE_DB']->query_delete('cache', array('lang' => $lang, 'the_theme' => $theme, 'cached_for' => $codename, 'identifier' => md5($cache_identifier)), '', 1); $GLOBALS['SITE_DB']->query_insert('cache', array('langs_required' => $langs_required, 'lang' => $lang, 'cached_for' => $codename, 'the_value' => $tempcode ? $cache->to_assembly($lang) : serialize($cache), 'date_and_time' => time(), 'the_theme' => $theme, 'identifier' => md5($cache_identifier)), false, true); } }
/** * Called once our DB connection becomes active. */ function _general_db_init() { global $TABLE_LANG_FIELDS; if (count($TABLE_LANG_FIELDS) > 0) { return; } $TABLE_LANG_FIELDS = function_exists('persistant_cache_get') ? persistant_cache_get('TABLE_LANG_FIELDS') : NULL; if ($TABLE_LANG_FIELDS === NULL) { $TABLE_LANG_FIELDS = array(); $_table_lang_fields = $GLOBALS['SITE_DB']->query('SELECT m_name,m_table FROM ' . get_table_prefix() . 'db_meta WHERE ' . db_string_equal_to('m_type', 'SHORT_TRANS') . ' OR ' . db_string_equal_to('m_type', 'LONG_TRANS') . ' OR ' . db_string_equal_to('m_type', '*SHORT_TRANS') . ' OR ' . db_string_equal_to('m_type', '*LONG_TRANS') . ' OR ' . db_string_equal_to('m_type', '?SHORT_TRANS') . ' OR ' . db_string_equal_to('m_type', '?LONG_TRANS'), NULL, NULL, true); if ($_table_lang_fields !== NULL) { foreach ($_table_lang_fields as $lang_field) { if ($lang_field['m_table'] == 'f_member_custom_fields') { continue; } if (!isset($TABLE_LANG_FIELDS[$lang_field['m_table']])) { $TABLE_LANG_FIELDS[$lang_field['m_table']] = array(); } $TABLE_LANG_FIELDS[$lang_field['m_table']][] = $lang_field['m_name']; } } if (function_exists('persistant_cache_set')) { persistant_cache_set('TABLE_LANG_FIELDS', $TABLE_LANG_FIELDS); } } }
/** * A template has not been structurally cached, so compile it and store in the cache. * * @param ID_TEXT The theme the template is in the context of * @param PATH The path to the template file * @param ID_TEXT The codename of the template (e.g. foo) * @param ID_TEXT The actual codename to use for the template (e.g. thin_foo) * @param LANGUAGE_NAME The language the template is in the context of * @param string File type suffix of template file * @param ?ID_TEXT The theme to cache in (NULL: main theme) * @return tempcode The compiled tempcode */ function _do_template($theme, $path, $codename, $_codename, $lang, $suffix, $theme_orig = NULL) { if (is_null($theme_orig)) { $theme_orig = $theme; } $base_dir = ($theme == 'default' && ($suffix != '.css' || strpos($path, '/css_custom') === false) ? get_file_base() : get_custom_file_base()) . '/themes/'; global $CACHE_TEMPLATES, $FILE_ARRAY, $TEMPLATE_PREVIEW_OP, $MEM_CACHE; if (isset($FILE_ARRAY)) { $html = unixify_line_format(file_array_get('themes/' . $theme . $path . $codename . $suffix)); } else { $html = unixify_line_format(file_get_contents($base_dir . filter_naughty($theme . $path . $codename) . $suffix, FILE_TEXT)); } if (strpos($html, '{$,Parser hint: pure}') !== false) { return make_string_tempcode(preg_replace('#\\{\\$,.*\\}#U', '/*no minify*/', $html)); } if ($GLOBALS['SEMI_DEBUG_MODE'] && strpos($html, '.innerHTML') !== false && strpos($html, 'Parser hint: .innerHTML okay') === false) { require_code('site'); attach_message('Do not use the .innerHTML property in your Javascript because it will not work in true XHTML (when the browsers real XML parser is in action). Use ocPortal\'s global setInnerHTML/getInnerHTML functions.', 'warn'); } // Strip off trailing final lines from single lines templates. Editors often put these in, and it causes annoying "visible space" issues if (substr($html, -1, 1) == chr(10) && substr_count($html, chr(10)) == 1) { $html = substr($html, 0, strlen($html) - 1); } if ($TEMPLATE_PREVIEW_OP) { $test = post_param($codename, NULL); if (!is_null($test)) { $html = post_param($test . '_new'); } } $result = template_to_tempcode($html, 0, false, $codename, $theme, $lang); if ($CACHE_TEMPLATES && ($suffix == '.tpl' || $codename == 'no_cache')) { if (!is_null($MEM_CACHE)) { persistant_cache_set(array('TEMPLATE', $theme, $lang, $_codename), $result->to_assembly(), strpos($path, 'default/templates/') !== false); } else { $path2 = get_custom_file_base() . '/themes/' . $theme_orig . '/templates_cached/' . filter_naughty($lang) . '/'; $myfile = @fopen($path2 . filter_naughty($_codename) . $suffix . '.tcd', 'wb'); if ($myfile === false) { if (@mkdir($path2, 0777)) { require_code('files'); fix_permissions($path2, 0777); } else { if (file_exists($path2 . filter_naughty($_codename) . $suffix . '.tcd')) { warn_exit(do_lang_tempcode('WRITE_ERROR', $path2 . filter_naughty($_codename) . $suffix . '.tcd')); } else { warn_exit(do_lang_tempcode('WRITE_ERROR_CREATE', $path2 . filter_naughty($_codename) . $suffix . '.tcd')); } } } else { fwrite($myfile, $result->to_assembly($lang)); fclose($myfile); fix_permissions($path2 . filter_naughty($_codename) . $suffix . '.tcd'); } } } return $result; }
/** * Load up hooks needed to detect how to use monikers. */ function load_moniker_hooks() { global $CONTENT_OBS; if ($CONTENT_OBS === NULL) { $CONTENT_OBS = function_exists('persistant_cache_get') ? persistant_cache_get('CONTENT_OBS') : NULL; if ($CONTENT_OBS !== NULL) { foreach ($CONTENT_OBS as $ob_info) { if ($ob_info['title_field'] !== NULL && strpos($ob_info['title_field'], 'CALL:') !== false) { require_code('hooks/systems/content_meta_aware/' . $ob_info['_hook']); } } return; } $CONTENT_OBS = array(); $hooks = find_all_hooks('systems', 'content_meta_aware'); foreach ($hooks as $hook => $sources_dir) { $info_function = extract_module_functions(get_file_base() . '/' . $sources_dir . '/hooks/systems/content_meta_aware/' . $hook . '.php', array('info')); if ($info_function[0] !== NULL) { $ob_info = is_array($info_function[0]) ? call_user_func_array($info_function[0][0], $info_function[0][1]) : eval($info_function[0]); if ($ob_info === NULL) { continue; } $ob_info['_hook'] = $hook; $CONTENT_OBS[$ob_info['view_pagelink_pattern']] = $ob_info; if ($ob_info['title_field'] !== NULL && strpos($ob_info['title_field'], 'CALL:') !== false) { require_code('hooks/systems/content_meta_aware/' . $hook); } } } if (function_exists('persistant_cache_set')) { persistant_cache_set('CONTENT_OBS', $CONTENT_OBS); } } }
/** * Find the URL to a certain external handler script (ocPortal allows these to be moved around between zones, to suit site .htaccess requirements). * * @param string The codename of the needed script * @param boolean Whether to append keep variables * @param integer Code representing what base URL type to use (0=guess, 1=http, 2=https) * @set 0 1 2 * @return URLPATH The URL to the script */ function find_script($name, $append_keep = false, $base_url_code = 0) { $append = ''; if ($append_keep) { $keep = symbol_tempcode('KEEP', array('1')); $append .= $keep->evaluate(); } global $CACHE_FIND_SCRIPT; if ($CACHE_FIND_SCRIPT === array()) { if (function_exists('persistant_cache_get')) { $CACHE_FIND_SCRIPT = persistant_cache_get('SCRIPT_PLACES'); } if ($CACHE_FIND_SCRIPT === NULL) { $CACHE_FIND_SCRIPT = array(); } } if (isset($CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code])) { return $CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code] . $append; } $zones = array(get_zone_name()); if (!in_safe_mode()) { $zones[] = 'data_custom'; } $zones[] = 'data'; $zones = array_merge($zones, find_all_zones()); foreach ($zones as $zone) { if (is_file(get_file_base() . '/' . $zone . '/' . $name . '.php')) { $ret = get_base_url() . '/' . $zone . ($zone != '' ? '/' : '') . $name . '.php'; $CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code] = $ret; if (function_exists('persistant_cache_set')) { persistant_cache_set('SCRIPT_PLACES', $CACHE_FIND_SCRIPT, true); } return $ret . $append; } } $ret = get_base_url($base_url_code == 0 ? NULL : $base_url_code == 2) . '/site/' . $name . '.php'; $CACHE_FIND_SCRIPT[$name][$append_keep][$base_url_code] = $ret; if (function_exists('persistant_cache_set')) { persistant_cache_set('SCRIPT_PLACES', $CACHE_FIND_SCRIPT, true); } return $ret . $append; }
/** * Find the value of the specified configuration option. * * @param ID_TEXT The name of the option * @param boolean Where to accept a missing option (and return NULL) * @return ?SHORT_TEXT The value (NULL: either null value, or no option found whilst $missing_ok set) */ function get_option($name, $missing_ok = false) { global $OPTIONS; if (!isset($OPTIONS[$name])) { if ($missing_ok) { return NULL; } require_code('config2'); find_lost_option($name); } $option =& $OPTIONS[$name]; // The master of redundant quick exit points. Has to be after the above IF due to weird PHP isset/NULL bug on some 5.1.4 (and possibly others) if (isset($option['config_value_translated'])) { if ($option['config_value_translated'] == '<null>') { return NULL; } return $option['config_value_translated']; } // Redundant, quick exit points $type = $option['the_type']; if (!isset($option['c_set'])) { $option['c_set'] = $option['config_value'] === NULL ? 0 : 1; } // for compatibility during upgrades if ($option['c_set'] == 1 && $type != 'transline' && $type != 'transtext') { //@print_r($OPTIONS); exit($name.'='.gettype($option['config_value_translated'])); $option['config_value_translated'] = $option['config_value']; // Allows slightly better code path next time if ($option['config_value_translated'] === NULL) { $option['config_value_translated'] = '<null>'; } $OPTIONS[$name] = $option; if (function_exists('persistant_cache_set')) { persistant_cache_set('OPTIONS', $OPTIONS); } if ($option['config_value'] == '<null>') { return NULL; } return $option['config_value']; } global $GET_OPTION_LOOP; $GET_OPTION_LOOP = 1; // Find default if not set if ($option['c_set'] == 0) { if ($type == 'transline' || $type == 'transtext') { if (defined('HIPHOP_PHP')) { require_code('hooks/systems/config_default/' . $name); $hook = object_factory('Hook_config_default_' . $name); $option['config_value_translated'] = $hook->get_default(); } else { if (!isset($option['eval'])) { global $SITE_INFO; $OPTIONS = $GLOBALS['SITE_DB']->query_select('config c LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON (c.config_value=t.id AND ' . db_string_equal_to('t.language', array_key_exists('default_lang', $SITE_INFO) ? $SITE_INFO['default_lang'] : 'EN') . ' AND (' . db_string_equal_to('c.the_type', 'transtext') . ' OR ' . db_string_equal_to('c.the_type', 'transline') . '))', array('c.the_name', 'c.config_value', 'c.eval', 'c.the_type', 'c.c_set', 't.text_original AS config_value_translated'), array(), ''); $OPTIONS = list_to_map('the_name', $OPTIONS); $option =& $OPTIONS[$name]; } $GLOBALS['REQUIRE_LANG_LOOP'] = 10; // LEGACY Workaround for corrupt webhost installers $option['config_value_translated'] = eval($option['eval'] . ';'); $GLOBALS['REQUIRE_LANG_LOOP'] = 0; // LEGACY if (is_object($option['config_value_translated'])) { $option['config_value_translated'] = $option['config_value_translated']->evaluate(); } if (get_value('setup_wizard_completed') === '1' && $option['config_value_translated'] !== NULL) { require_code('config2'); set_option($name, $option['config_value_translated']); } } if (is_object($option['config_value_translated'])) { $option['config_value_translated'] = $option['config_value_translated']->evaluate(); } $GET_OPTION_LOOP = 0; return $option['config_value_translated']; } // if ((!function_exists('do_lang')) && (strpos($option['eval'],'do_lang')!==false)) @debug_print_backtrace(); if (defined('HIPHOP_PHP')) { require_code('hooks/systems/config_default/' . $name); $hook = object_factory('Hook_config_default_' . $name); $option['config_value'] = $hook->get_default(); } else { if (!isset($option['eval'])) { global $SITE_INFO; $OPTIONS = $GLOBALS['SITE_DB']->query_select('config c LEFT JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'translate t ON (c.config_value=t.id AND ' . db_string_equal_to('t.language', array_key_exists('default_lang', $SITE_INFO) ? $SITE_INFO['default_lang'] : 'EN') . ' AND (' . db_string_equal_to('c.the_type', 'transtext') . ' OR ' . db_string_equal_to('c.the_type', 'transline') . '))', array('c.the_name', 'c.config_value', 'c.eval', 'c.the_type', 'c.c_set', 't.text_original AS config_value_translated'), array(), ''); $OPTIONS = list_to_map('the_name', $OPTIONS); $option =& $OPTIONS[$name]; } require_code('lang'); $GLOBALS['REQUIRE_LANG_LOOP'] = 10; // LEGACY Workaround for corrupt webhost installers $option['config_value'] = eval($option['eval'] . ';'); $GLOBALS['REQUIRE_LANG_LOOP'] = 0; // LEGACY if (get_value('setup_wizard_completed') === '1' && isset($option['config_value_translated'])) { require_code('config2'); set_option($name, $option['config_value']); } } if (is_object($option['config_value'])) { $option['config_value'] = $option['config_value']->evaluate(); } elseif (is_integer($option['config_value'])) { $option['config_value'] = strval($option['config_value']); } $GET_OPTION_LOOP = 0; $option['c_set'] = 1; return $option['config_value']; } // Translations if needed if ($type == 'transline' || $type == 'transtext') { if (!isset($option['config_value_translated'])) { $option['config_value_translated'] = get_translated_text(intval($option['config_value'])); $OPTIONS[$name] = $option; persistant_cache_set('OPTIONS', $OPTIONS); } // Answer $GET_OPTION_LOOP = 0; return $option['config_value_translated']; } // Answer $GET_OPTION_LOOP = 0; return $option['config_value']; }
/** * Get meta information for specified resource * * @param ID_TEXT The type of resource (e.g. download) * @param ID_TEXT The ID of the resource * @return array The first element is the meta keyword string for the specified resource, and the other is the meta description string. */ function seo_meta_get_for($type, $id) { $cache = persistant_cache_get(array('seo', $type, $id)); if ($cache !== NULL) { return $cache; } $rows = $GLOBALS['SITE_DB']->query_select('seo_meta', array('*'), array('meta_for_type' => $type, 'meta_for_id' => $id), '', 1); if (!array_key_exists(0, $rows)) { $cache = array('', ''); } else { $cache = array(get_translated_text($rows[0]['meta_keywords']), get_translated_text($rows[0]['meta_description'])); } persistant_cache_set(array('seo', $type, $id), $cache); return $cache; }
/** * The actualiser for toggling invisible mode. * * @return tempcode The UI. */ function invisible() { if (get_option('is_on_invisibility') == '1') { $visible = array_key_exists(get_session_id(), $GLOBALS['SESSION_CACHE']) && $GLOBALS['SESSION_CACHE'][get_session_id()]['session_invisible'] == 0; } else { $visible = false; // Small fudge: always say thay are not visible now, so this will make them visible -- because they don't have permission to be invisible } $title = get_page_title($visible ? 'INVISIBLE' : 'BE_VISIBLE'); $GLOBALS['SITE_DB']->query_update('sessions', array('session_invisible' => $visible ? 1 : 0), array('the_user' => get_member(), 'the_session' => get_session_id()), '', 1); global $SESSION_CACHE; if ($SESSION_CACHE[get_session_id()]['the_user'] == get_member()) { $SESSION_CACHE[get_session_id()]['session_invisible'] = $visible ? 1 : 0; if (get_value('session_prudence') !== '1') { persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } decache('side_users_online'); // Store in cookie, if we have login cookies around if (array_key_exists(get_member_cookie(), $_COOKIE)) { require_code('users_active_actions'); ocp_setcookie(get_member_cookie() . '_invisible', strval($visible ? 1 : 0)); $_COOKIE[get_member_cookie() . '_invisible'] = strval($visible ? 1 : 0); } $url = get_param('redirect', NULL); if (is_null($url)) { $_url = build_url(array('page' => ''), ''); $url = $_url->evaluate(); } return redirect_screen($title, $url, do_lang_tempcode('SUCCESS')); }
/** * Show poll block. * * @param boolean Whether to get the output instead of outputting it directly * @param ?AUTO_LINK Poll ID (NULL: read from environment) * @return ?object Output (NULL: outputted it already) */ function poll_script($ret = false, $param = NULL) { require_lang('polls'); require_css('polls'); if (is_null($param)) { $param = get_param_integer('param'); } $zone = get_param('zone', get_module_zone('polls')); if ($param == -1) { $rows = persistant_cache_get('POLL'); if (is_null($rows)) { $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('is_current' => 1), 'ORDER BY id DESC', 1); persistant_cache_set('POLL', $rows); } } else { $rows = $GLOBALS['SITE_DB']->query_select('poll', array('*'), array('id' => $param), '', 1); } if (has_actual_page_access(NULL, 'cms_polls', NULL, NULL) && has_submit_permission('mid', get_member(), get_ip_address(), 'cms_polls')) { $submit_url = build_url(array('page' => 'cms_polls', 'type' => 'ad', 'redirect' => get_self_url(true, false)), get_module_zone('cms_polls')); } else { $submit_url = new ocp_tempcode(); } if (!array_key_exists(0, $rows)) { $content = do_template('BLOCK_NO_ENTRIES', array('_GUID' => 'fdc85bb2e14bdf00830347e52f25cdac', 'HIGH' => true, 'TITLE' => do_lang_tempcode('POLL'), 'MESSAGE' => do_lang_tempcode('NO_ENTRIES'), 'ADD_NAME' => do_lang_tempcode('ADD_POLL'), 'SUBMIT_URL' => $submit_url)); } else { $myrow = $rows[0]; $ip = get_ip_address(); // Show the poll normally $show_poll_results = get_param_integer('show_poll_results_' . strval($myrow['id']), 0); if ($show_poll_results == 0) { $content = show_poll(false, $myrow, $zone); } else { // Voting $cast = post_param_integer('cast_' . strval($myrow['id']), -1); if ($cast != -1) { if (may_vote_in_poll($myrow)) { if (addon_installed('points')) { require_code('points'); $_before = point_info(get_member()); $before = array_key_exists('points_gained_voting', $_before) ? $_before['points_gained_voting'] : 0; $GLOBALS['FORUM_DRIVER']->set_custom_field(get_member(), 'points_gained_voting', $before + 1); } $GLOBALS['SITE_DB']->query_update('poll', array('votes' . strval($cast) => $myrow['votes' . strval($cast)] + 1), array('id' => $myrow['id']), '', 1); $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $myrow['id'], 'v_voter_id' => get_member(), 'v_voter_ip' => $ip, 'v_vote_for' => $cast)); $myrow['votes' . strval($cast)]++; } } else { // Viewing the results if (may_vote_in_poll($myrow)) { $GLOBALS['SITE_DB']->query_insert('poll_votes', array('v_poll_id' => $myrow['id'], 'v_voter_id' => is_guest() ? NULL : get_member(), 'v_voter_ip' => $ip, 'v_vote_for' => NULL)); } } // Show poll, with results $content = show_poll(true, $myrow, $zone); } } if ($ret) { return $content; } // Display $echo = do_template('STYLED_HTML_WRAP', array('TITLE' => do_lang_tempcode('POLL'), 'FRAME' => true, 'CONTENT' => $content)); $echo->handle_symbol_preprocessing(); $echo->evaluate_echo(); return NULL; }
/** * Get the human-readable form of a language id, or a language entry from a language INI file. * * @param ID_TEXT The language id * @param ?mixed The first token [string or tempcode] (replaces {1}) (NULL: none) * @param ?mixed The second token [string or tempcode] (replaces {2}) (NULL: none) * @param ?mixed The third token (replaces {3}). May be an array of [of string], to allow any number of additional args (NULL: none) * @param ?LANGUAGE_NAME The language to use (NULL: users language) * @param boolean Whether to cause ocPortal to exit if the lookup does not succeed * @return ?mixed The human-readable content (NULL: not found). String normally. Tempcode if tempcode parameters. */ function _do_lang($codename, $token1 = NULL, $token2 = NULL, $token3 = NULL, $lang = NULL, $require_result = true) { global $LANGUAGE, $USER_LANG_CACHED, $RECORD_LANG_STRINGS, $XSS_DETECT, $PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED; if ($lang === NULL) { $lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED; } if ($GLOBALS['SEMI_DEBUG_MODE']) { $pos = strpos($codename, '='); if ($pos !== false) { // Find loaded file with smallest levenstein distance to current page $best = mixed(); $best_for = NULL; global $LANGS_REQUESTED; foreach (array_keys($LANGS_REQUESTED) as $possible) { $dist = levenshtein(get_page_name(), $possible); if (is_null($best) || $best > $dist) { $best = $dist; $best_for = $possible; } } $save_path = get_file_base() . '/lang/' . fallback_lang() . '/' . $best_for . '.ini'; if (!is_file($save_path)) { $save_path = get_file_base() . '/lang_custom/' . fallback_lang() . '/' . $best_for . '.ini'; } // Tack language strings onto this file list($codename, $value) = explode('=', $codename, 2); $myfile = fopen($save_path, 'at'); fwrite($myfile, "\n" . $codename . '=' . $value); fclose($myfile); // Fake-load the string $LANGUAGE[$lang][$codename] = $value; // Go through all required files, doing a string replace if needed $included_files = get_included_files(); foreach ($included_files as $inc) { $orig_contents = file_get_contents($inc); $contents = str_replace("'" . $codename . '=' . $value . "'", "'" . $codename . "'", $orig_contents); if ($orig_contents != $contents) { $myfile = fopen($inc, 'wt'); fwrite($myfile, $contents); fclose($myfile); } } } } $there = isset($LANGUAGE[$lang][$codename]); if (!$there) { $pos = strpos($codename, ':'); if ($pos !== false) { require_lang(substr($codename, 0, $pos), NULL, NULL, !$require_result); $codename = substr($codename, $pos + 1); } $there = isset($LANGUAGE[$lang][$codename]); } if ($RECORD_LANG_STRINGS) { global $RECORDED_LANG_STRINGS; $RECORDED_LANG_STRINGS[$codename] = 1; } if (!$there && (!isset($LANGUAGE[$lang]) || !array_key_exists($codename, $LANGUAGE[$lang]))) { global $PAGE_CACHE_LAZY_LOAD, $PAGE_CACHE_LANGS_REQUESTED, $LANG_REQUESTED_LANG; if ($PAGE_CACHE_LAZY_LOAD) { $PAGE_CACHE_LAZY_LOAD = false; // We can't be lazy any more, but we will keep growing our pool so hopefully CAN be lazy the next time foreach ($PAGE_CACHE_LANGS_REQUESTED as $request) { list($that_codename, $that_lang) = $request; unset($LANG_REQUESTED_LANG[$that_lang][$that_codename]); require_lang($that_codename, $that_lang, NULL, true); } $ret = _do_lang($codename, $token1, $token2, $token3, $lang, $require_result); if ($ret === NULL) { $PAGE_CACHE_LANG_LOADED[$lang][$codename] = NULL; if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED); } else { open_page_cache_file(); @rewind($PAGE_CACHE_FILE); @flock($PAGE_CACHE_FILE, LOCK_EX); @ftruncate($PAGE_CACHE_FILE, 0); @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED)); @flock($PAGE_CACHE_FILE, LOCK_UN); } } return $ret; } require_all_open_lang_files($lang); } if ($lang == 'xxx') { return 'xxx'; } // Helpful for testing language compliancy. We don't expect to see non x's if we're running this language if (!isset($LANGUAGE[$lang][$codename]) && ($require_result || !isset($LANGUAGE[$lang]) || !array_key_exists($codename, $LANGUAGE[$lang]))) { if ($lang != fallback_lang()) { $ret = do_lang($codename, $token1, $token2, $token3, fallback_lang(), $require_result); if ($PAGE_CACHE_FILE !== NULL) { if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename]) && isset($PAGE_CACHE_LANG_LOADED[fallback_lang()][$codename])) { $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $PAGE_CACHE_LANG_LOADED[fallback_lang()][$codename]; // Will have been cached into fallback_lang() from the nested do_lang call, we need to copy it into our cache bucket for this language if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED); } else { open_page_cache_file(); @rewind($PAGE_CACHE_FILE); @flock($PAGE_CACHE_FILE, LOCK_EX); @ftruncate($PAGE_CACHE_FILE, 0); @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED)); @flock($PAGE_CACHE_FILE, LOCK_UN); } } } return $ret; } else { if ($require_result) { global $USER_LANG_LOOP, $REQUIRE_LANG_LOOP; //print_r(debug_backtrace()); if ($USER_LANG_LOOP == 1) { critical_error('RELAY', 'Missing language code: ' . escape_html($codename) . '. This language code is required to produce error messages, and thus a critical error was prompted by the non-ability to show less-critical error messages. It is likely the source language files (lang/' . fallback_lang() . '/*.ini) for ocPortal on this website have been corrupted.'); } if ($REQUIRE_LANG_LOOP >= 2) { return ''; } // Probably failing to load global.ini, so just output with some text missing require_code('view_modes'); erase_cached_language(); require_code('site'); attach_message(do_lang_tempcode('MISSING_LANG_ENTRY', escape_html($codename)), 'warn'); return ''; } else { return NULL; } } } if ($PAGE_CACHE_FILE !== NULL) { if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename]) && (!isset($PAGE_CACHE_LANG_LOADED[$lang]) || !array_key_exists($codename, $PAGE_CACHE_LANG_LOADED[$lang]))) { $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $LANGUAGE[$lang][$codename]; if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED); } else { open_page_cache_file(); @rewind($PAGE_CACHE_FILE); @flock($PAGE_CACHE_FILE, LOCK_EX); @ftruncate($PAGE_CACHE_FILE, 0); @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED)); @flock($PAGE_CACHE_FILE, LOCK_UN); } } } // Put in parameters static $non_plural_non_vowel = array('1', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z', '{'); $looked_up = $LANGUAGE[$lang][$codename]; if ($looked_up === NULL) { return NULL; // Learning cache pool has told us this string definitely does not exist } $out = str_replace('\\n', "\n", $looked_up); $plural_or_vowel_check = strpos($out, '|') !== false; if ($XSS_DETECT) { ocp_mark_as_escaped($out); } if ($token1 !== NULL) { if (is_object($token1) && $token2 === NULL || $token2 !== NULL && is_object($token2)) { $bits = preg_split('#\\{\\d[^\\}]*\\}#', $out, 2, PREG_SPLIT_OFFSET_CAPTURE); $ret = new ocp_tempcode(); foreach ($bits as $bit) { if ($XSS_DETECT) { ocp_mark_as_escaped($bit[0]); } $at = $bit[1]; if ($at != 0) { if ($out[$at - 2] == '1') { $ret->attach($token1); } elseif ($out[$at - 2] == '2') { $ret->attach($token2); } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '1|') { $exploded = explode('|', $out[$at - 2]); $_token = $token1->evaluate(); $_token_denum = str_replace(',', '', $_token); $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]); } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '2|') { $exploded = explode('|', $out[$at - 2]); $_token = $token2->evaluate(); $_token_denum = str_replace(',', '', $_token); $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]); } } $ret->attach($bit[0]); } return $ret; } elseif ($token1 !== NULL) { $out = str_replace('{1}', $token1, $out); if ($plural_or_vowel_check) { $_token_denum = str_replace(',', '', $token1); $out = preg_replace('#\\{1\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($token1, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out); } if ($XSS_DETECT && ocp_is_escaped($token1)) { ocp_mark_as_escaped($out); } } if ($token2 !== NULL) { if ($XSS_DETECT) { $escaped = ocp_is_escaped($out); } $out = str_replace('{2}', $token2, $out); if ($plural_or_vowel_check) { $_token_denum = str_replace(',', '', $token1); $out = preg_replace('#\\{2\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($token2, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out); } if ($XSS_DETECT && ocp_is_escaped($token2) && $escaped) { ocp_mark_as_escaped($out); } if ($token3 !== NULL) { $i = 3; if (!is_array($token3)) { $token3 = array($token3); } foreach ($token3 as $token) { if ($XSS_DETECT) { $escaped = ocp_is_escaped($out); } $out = str_replace('{' . strval($i) . '}', $token, $out); if ($plural_or_vowel_check) { $_token_denum = str_replace(',', '', $token); $out = preg_replace('#\\{' . strval($i) . '\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : ocp_mb_strtolower(ocp_mb_substr($token, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out); } if ($XSS_DETECT && ocp_is_escaped($token) && $escaped) { ocp_mark_as_escaped($out); } $i++; } } } } return $out; }
/** * Find the URL to the theme image of the specified ID. It searches various priorities, including language and theme overrides. * * @param ID_TEXT The theme image ID * @param boolean Whether to silently fail (i.e. not give out an error message when a theme image cannot be found) * @param boolean Whether to leave URLs as relative local URLs * @param ?ID_TEXT The theme to search in (NULL: users current theme) * @param ?LANGUAGE_NAME The language to search for (NULL: users current language) * @param ?object The database to use (NULL: site database) * @param boolean Whether to only search the default 'images' filesystem * @return URLPATH The URL found (blank: not found) */ function find_theme_image($id, $silent_fail = false, $leave_local = false, $theme = NULL, $lang = NULL, $db = NULL, $pure_only = false) { if (substr($id, 0, 4) == 'ocf_' && is_file(get_file_base() . '/themes/default/images/avatars/index.html')) { $id = substr($id, 4); } if (isset($_GET['keep_theme_seed']) && get_param('keep_theme_seed', NULL) !== NULL && function_exists('has_specific_permission') && has_specific_permission(get_member(), 'view_profiling_modes')) { require_code('themewizard'); $test = find_theme_image_themewizard_preview($id); if ($test !== NULL) { return $test; } } if ($db === NULL) { $db = $GLOBALS['SITE_DB']; } global $RECORD_IMG_CODES; if ($RECORD_IMG_CODES) { global $RECORDED_IMG_CODES; if (isset($GLOBALS['FORUM_DB']) && $db->connection_write !== $GLOBALS['FORUM_DB']->connection_write) { $RECORDED_IMG_CODES[serialize(array($id, $theme, $lang))] = 1; } } $true_theme = $GLOBALS['FORUM_DRIVER']->get_theme(); if ($theme === NULL) { $theme = $true_theme; } global $USER_LANG_CACHED; $true_lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED; if ($lang === NULL) { $lang = $true_lang; } $truism = $theme == $true_theme && $lang == $true_lang; $site = $GLOBALS['SITE_DB'] == $db ? 'site' : 'forums'; global $IMG_CODES; if (!isset($IMG_CODES[$site])) { static $cache = NULL; if ($site == 'site') { $cache = persistant_cache_get('THEME_IMAGES'); } if (!isset($cache[$true_theme][$true_lang])) { $IMG_CODES[$site] = $db->query_select('theme_images', array('id', 'path'), array('theme' => $true_theme, 'lang' => $true_lang)); $IMG_CODES[$site] = collapse_2d_complexity('id', 'path', $IMG_CODES[$site]); if ($site == 'site') { if ($cache === NULL) { $cache = array(); } $cache[$theme][$true_lang] = $IMG_CODES[$site]; persistant_cache_set('THEME_IMAGES', $cache); } } else { $IMG_CODES[$site] = $cache[$true_theme][$true_lang]; } } if (!$truism && !$pure_only) { $path = $db->query_value_null_ok('theme_images', 'path', array('theme' => $theme, 'lang' => $lang, 'id' => $id)); if ($path !== NULL) { if (url_is_local($path) && !$leave_local) { $path = ($db->connection_write != $GLOBALS['SITE_DB']->connection_write ? get_forum_base_url() : (substr($path, 0, 22) == 'themes/default/images/' ? get_base_url() : get_custom_base_url())) . '/' . $path; } return cdn_filter($path); } } if ($pure_only || !isset($IMG_CODES[$site][$id]) || !$truism) { $path = NULL; $priorities = array(); if (!$pure_only) { $priorities = array_merge($priorities, array(array($theme, $lang, 'images_custom'), array($theme, '', 'images_custom'), $lang == fallback_lang() ? NULL : array($theme, fallback_lang(), 'images_custom'))); } // This will not do a DB search, just a filesystem search. The Theme Wizard makes these though $priorities = array_merge($priorities, array(array($theme, $lang, 'images'), array($theme, '', 'images'), $lang == fallback_lang() ? NULL : array($theme, fallback_lang(), 'images'))); if ($theme != 'default') { if (!$pure_only) { $priorities = array_merge($priorities, array(array('default', $lang, 'images_custom'), array('default', '', 'images_custom'), $lang == fallback_lang() ? NULL : array('default', fallback_lang(), 'images_custom'))); } $priorities = array_merge($priorities, array(array('default', $lang, 'images'), array('default', '', 'images'), $lang == fallback_lang() ? NULL : array('default', fallback_lang(), 'images'))); } foreach ($priorities as $i => $priority) { if ($priority === NULL) { continue; } if ($priority[2] == 'images_custom' && $priority[1] != '') { $smap = array('id' => $id, 'theme' => $priority[0], 'lang' => $priority[1]); $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $truism_b = $priority[0] == $true_theme && (!multi_lang() || $priority[1] == '' || $priority[1] === $true_lang); $path = $truism_b ? NULL : $db->query_value_null_ok('theme_images', 'path', $smap); $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; if ($path !== NULL) { if (strpos($path, '/images/' . $id . '.') !== false) { continue; } if (array_key_exists('lang', $smap) && strpos($path, '/images/' . $smap['lang'] . '/' . $id . '.') !== false) { continue; } break; } } $test = _search_img_file($priority[0], $priority[1], $id, $priority[2]); if ($test !== NULL) { $path_bits = explode('/', $test); $path = ''; foreach ($path_bits as $bit) { if ($path != '') { $path .= '/'; } $path .= rawurlencode($bit); } break; } } if ($db->connection_write == $GLOBALS['SITE_DB']->connection_write) { if ($path !== NULL && $path != '' || $silent_fail && !$GLOBALS['SEMI_DEBUG_MODE']) { $nql_backup = $GLOBALS['NO_QUERY_LIMIT']; $GLOBALS['NO_QUERY_LIMIT'] = true; $db->query_delete('theme_images', array('id' => $id, 'theme' => $theme, 'lang' => $lang)); // Allow for race conditions $db->query_insert('theme_images', array('id' => $id, 'theme' => $theme, 'path' => $path === NULL ? '' : $path, 'lang' => $lang), false, true); // Allow for race conditions $GLOBALS['NO_QUERY_LIMIT'] = $nql_backup; persistant_cache_delete('THEME_IMAGES'); } } if ($path === NULL) { if (!$silent_fail) { require_code('site'); attach_message(do_lang_tempcode('NO_SUCH_IMAGE', escape_html($id)), 'warn'); } return ''; } if ($truism) { $IMG_CODES[$site][$id] = $path; } // only cache if we are looking up for our own theme/lang } else { $path = $IMG_CODES[$site][$id]; global $SITE_INFO; if ($path != '' && (!isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0') && (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') && url_is_local($path) && !is_file(get_custom_file_base() . '/' . rawurldecode($path))) { unset($IMG_CODES[$site][$id]); return find_theme_image($id, $silent_fail, $leave_local, $theme, $lang, $db, $pure_only); } } if (url_is_local($path) && !$leave_local && $path != '') { if ($db->connection_write != $GLOBALS['SITE_DB']->connection_write) { $base_url = get_forum_base_url(); } else { global $SITE_INFO; $missing = !$pure_only && ((!isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0') && (!isset($SITE_INFO['no_disk_sanity_checks']) || $SITE_INFO['no_disk_sanity_checks'] == '0') && (!is_file(get_file_base() . '/' . rawurldecode($path)) && !is_file(get_custom_file_base() . '/' . rawurldecode($path)))); if (substr($path, 0, 22) == 'themes/default/images/' || $missing) { if ($missing) { return find_theme_image($id, $silent_fail, $leave_local, $theme, $lang, $db, true); } $base_url = get_base_url(); } else { $base_url = get_custom_base_url(); } } $path = $base_url . '/' . $path; } return cdn_filter($path); }
/** * Delete a session. * * @param integer The new session */ function delete_session($session) { require_code('users_inactive_occasionals'); set_session_id(-1); $GLOBALS['SITE_DB']->query_delete('sessions', array('the_session' => $session), '', 1); global $SESSION_CACHE; unset($SESSION_CACHE[$session]); if (get_value('session_prudence') !== '1') { persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } }
/** * Evaluate a conventional tempcode variable, handling escaping * * @param LANGUAGE_NAME The language to evaluate this symbol in (some symbols refer to language elements) * @param array Array of escaping operations * @param integer The type of symbol this is (TC_SYMBOL, TC_LANGUAGE_REFERENCE) * @set 0 2 * @param ID_TEXT The name of the symbol * @param array Parameters to the symbol. For all but directive it is an array of strings. For directives it is an array of Tempcode objects. Actually there may be template-style parameters in here, as an influence of singular_bind and these may be Tempcode, but we ignore them. * @return mixed The result. Either tempcode, or a string. */ function ecv($lang, $escaped, $type, $name, $param) { global $TEMPCODE_SETGET, $CYCLES, $PREPROCESSABLE_SYMBOLS, $DISPLAYED_TITLE; //echo '<!--'.$name.'-->'."\n"; if ($type == TC_SYMBOL) { $escaped_codes = $name . ($escaped == array() ? '' : serialize($escaped)); $cacheable = $param == array() && !isset($GLOBALS['NON_CACHEABLE_SYMBOLS'][$name]); if ($cacheable) { global $SYMBOL_CACHE; if (isset($SYMBOL_CACHE[$escaped_codes])) { return $SYMBOL_CACHE[$escaped_codes]; } } $value = ''; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } $temp_array = array(); if (isset($PREPROCESSABLE_SYMBOLS[$name]) && $name != 'PAGE_LINK') { handle_symbol_preprocessing(array($escaped, $type, $name, $param), $temp_array); } // Late preprocessing. Should not be needed in case of full screen output (as this was properly preprocessed), but is in other cases switch ($name) { case 'PAGE_LINK': if (isset($param[0])) { list($zone, $map, $hash) = page_link_decode(is_object($param[0]) ? $param[0]->evaluate() : $param[0]); $skip = NULL; if (isset($param[4])) { $skip = array_flip(explode('|', $param[4])); } $avoid_remap = isset($param[1]) && $param[1] == '1'; $skip_keep = isset($param[2]) && $param[2] == '1'; $keep_all = isset($param[3]) && $param[3] == '1'; foreach ($map as $key => $val) { if (is_object($val)) { $map[$key] = $val->evaluate(); } } $value = _build_url($map, $zone, $skip, $keep_all, $avoid_remap, $skip_keep, $hash); } else { $value = get_zone_name() . ':' . get_page_name(); foreach ($_GET as $key => $val) { if ($key == 'page') { continue; } if (is_array($val)) { continue; } if (substr($key, 0, 5) == 'keep_' && !skippable_keep($key, $val)) { continue; } $value .= ':' . $key . '=' . $val; } } break; case 'SET': if (isset($param[1])) { if (isset($param[1]) && is_object($param[1])) { $TEMPCODE_SETGET[$param[0]] = $param[1]; } else { $param_copy = $param; unset($param_copy[0]); $TEMPCODE_SETGET[$param[0]] = implode(',', $param_copy); } } break; case 'GET': if (isset($param[0])) { if (isset($TEMPCODE_SETGET[$param[0]])) { if (is_object($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = $TEMPCODE_SETGET[$param[0]]->evaluate(); } $value = $TEMPCODE_SETGET[$param[0]]; } } break; case 'EQ': if (isset($param[1])) { $first = array_shift($param); $count = 0; foreach ($param as $test) { if ($first == $test) { $count++; break; } } $value = $count != 0 ? '1' : '0'; } break; case 'NEQ': if (isset($param[1])) { $first = array_shift($param); $count = 0; foreach ($param as $test) { if ($first == $test) { $count++; } } $value = $count == 0 ? '1' : '0'; } break; case 'NOT': if (isset($param[0])) { $value = $param[0] == '1' || $param[0] == '1' ? '0' : '1'; } break; case 'OR': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count > 0 ? '1' : '0'; break; case 'AND': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count == count($param) ? '1' : '0'; break; case 'HAS_ACTUAL_PAGE_ACCESS': if (isset($param[0])) { $value = has_actual_page_access($param !== NULL && isset($param[2]) ? intval($param[2]) : get_member(), $param[0], isset($param[1]) ? $param[1] : NULL) ? '1' : '0'; } break; case '?': if (isset($param[1])) { $value = $param[0] == '1' || $param[0] == '1' ? $param[1] : (isset($param[2]) ? $param[2] : $value); } break; case 'IMG': if (isset($param[0]) && isset($GLOBALS['SITE_DB']) && function_exists('find_theme_image') && $GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { $value = find_theme_image($param[0], isset($param[3]) && $param[3] == '1', false, array_key_exists(2, $param) && $param[2] != '' ? $param[2] : NULL, NULL, isset($param[1]) && $param[1] == '1' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']); } break; case '': break; case 'META_DATA': if (isset($param[0])) { global $META_DATA; if (isset($param[1])) { $matches = array(); if ($param[0] == 'image' && preg_match('#^' . preg_quote(find_script('attachment'), '#') . '\\?id=(\\d+)#', $param[1], $matches) != 0) { require_code('attachments'); if (!has_attachment_access($GLOBALS['FORUM_DRIVER']->get_guest_id(), intval($matches[1]))) { break; } } $META_DATA[$param[0]] = $param[1]; } else { $value = isset($META_DATA[$param[0]]) ? strip_comcode($META_DATA[$param[0]]) : ''; if ($value === NULL) { $value = ''; } } } break; case 'SPECIAL_CLICK_TO_EDIT': $_value = do_lang_tempcode('SPECIAL_CLICK_TO_EDIT'); $value = $_value->evaluate(); break; case 'KEEP': // What needs preserving in the URL $value = keep_symbol($param); break; case 'BROWSER': if (isset($param[1])) { $q = false; foreach (explode('|', $param[0]) as $browser) { $q = browser_matches($browser); if ($q) { break; } } $value = $q ? $param[1] : (isset($param[2]) ? $param[2] : ''); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } } break; case 'JAVASCRIPT_INCLUDE': if (isset($param[0])) { require_javascript($param[0]); /*// Has to do this inline, as you're not allowed to reference scripts outside head if (!array_key_exists($param[0],$GLOBALS['JAVASCRIPTS'])) { $GLOBALS['JAVASCRIPTS'][$param[0]]=1; $file=javascript_enforce($param[0]); $_value=do_template('JAVASCRIPT_NEED_INLINE',array('_GUID'=>'d6c907e26c5a8dd8c65f1d36a1a674a9','CODE'=>file_get_contents($file,FILE_TEXT))); $value=$_value->evaluate(); }*/ } break; case 'FACILITATE_AJAX_BLOCK_CALL': if (isset($param[0])) { require_javascript('javascript_ajax'); require_code('blocks'); $_block_constraints = block_params_to_block_signature(block_params_str_to_arr($param[0])); if (array_key_exists(1, $param)) { $_block_constraints = array_merge($_block_constraints, block_params_str_to_arr($param[1])); ksort($_block_constraints); } $block_constraints = block_params_arr_to_str($_block_constraints); // Store permissions $_auth_key = $GLOBALS['SITE_DB']->query_select('temp_block_permissions', array('id', 'p_time'), array('p_session_id' => get_session_id(), 'p_block_constraints' => $block_constraints), '', 1); if (!array_key_exists(0, $_auth_key)) { $auth_key = $GLOBALS['SITE_DB']->query_insert('temp_block_permissions', array('p_session_id' => get_session_id(), 'p_block_constraints' => $block_constraints, 'p_time' => time()), true); } else { $auth_key = $_auth_key[0]['id']; if (time() - $_auth_key[0]['p_time'] > 100) { $GLOBALS['SITE_DB']->query_update('temp_block_permissions', array('p_time' => time()), array('p_session_id' => get_session_id(), 'p_block_constraints' => $block_constraints), '', 1); } } $keep = symbol_tempcode('KEEP'); $value = find_script('snippet') . '?snippet=block&auth_key=' . urlencode(strval($auth_key)) . '&block_map=' . urlencode($param[0]) . $keep->evaluate(); } break; case 'LANG': $value = user_lang(); break; case '_GET': if (isset($param[0])) { $value = get_param($param[0], isset($param[1]) ? $param[1] : '', true); } break; case 'QUERY_STRING': $value = ocp_srv('QUERY_STRING'); break; case 'USER_AGENT': $value = ocp_srv('HTTP_USER_AGENT'); break; case 'STRIP_TAGS': if (isset($param[0])) { if (isset($param[1]) && $param[1] == '1') { $value = strip_tags(str_replace('))', ')', str_replace('((', '(', str_replace('<em>', '(', str_replace('</em>', ')', $param[0]))))); } else { $value = strip_tags($param[0], array_key_exists(2, $param) ? $param[2] : ''); } if (isset($param[1]) && $param[1] == '1') { $value = @html_entity_decode($value, ENT_QUOTES, get_charset()); } } break; case 'CONFIG_OPTION': if (isset($param[0])) { if (!isset($GLOBALS['OPTIONS'])) { $value = '0'; } else { $value = get_option($param[0], true); if ($value === NULL) { $value = ''; } } } break; case 'TRUNCATE_LEFT': // Truncate the left length of a string. 0: text to truncate, 1: the truncate length, 2: whether to use a tooltip mouse-over if it is truncated, 3: whether it is encoded as HTML (0=no [default, plain-text], 1=yes) $value = symbol_truncator($param, 'left'); break; case 'TRUNCATE_RIGHT': $value = symbol_truncator($param, 'right'); break; case 'TRUNCATE_SPREAD': $value = symbol_truncator($param, 'spread'); break; case 'TRUNCATE_EXPAND': $value = symbol_truncator($param, 'expand'); break; case 'THEME': if (isset($GLOBALS['FORUM_DRIVER'])) { $value = $GLOBALS['FORUM_DRIVER']->get_theme(); } else { $value = 'default'; } break; case 'REVERSE': if (isset($param[0])) { $value = implode(',', array_reverse(explode(',', $param[0]))); } break; case 'COMMA_LIST_GET': if (isset($param[1])) { require_code('blocks'); $values = block_params_str_to_arr($param[0]); $value = isset($values[$param[1]]) ? $values[$param[1]] : ''; } break; case 'COMMA_LIST_SET': if (isset($param[2])) { require_code('blocks'); $values = block_params_str_to_arr($param[0]); $values[$param[1]] = $param[2]; $value = block_params_arr_to_str($values); } break; case 'IS_EMPTY': if (isset($param[0])) { $value = $param[0] == '' ? '1' : '0'; } break; case 'IS_NON_EMPTY': if (isset($param[0])) { $value = $param[0] != '' ? '1' : '0'; } break; case 'CUSTOM_BASE_URL': $value = get_custom_base_url(isset($param[0]) && $param[0] != '' ? $param[0] == '1' : NULL); if (isset($param[1]) && $param[1] == '1') { $value = cdn_filter($value); } break; case 'LOAD_PANEL': foreach ($param as $i => $p) { if (is_object($p)) { $param[$i] = $p->evaluate(); } } global $LOADED_PANELS; if (strpos($param[0], ':') !== false) { $param = array_reverse(explode(':', $param[0], 2)); } if (substr($param[0], 0, 6) == 'panel_') { $param[0] = substr($param[0], 6); } $sr = serialize($param); $value = array_key_exists($sr, $LOADED_PANELS) ? $LOADED_PANELS[$sr] : ''; break; case 'HAS_JS': case 'JS_ON': if (isset($param[1])) { $value = has_js() ? $param[0] : $param[1]; } else { $value = has_js() ? '1' : '0'; } break; case 'BASE_URL_NOHTTP': $value = preg_replace('#^https?://[^/]+#', '', get_base_url()); if (substr($value, 0, 2) == '//') { $value = substr($value, 1); } if (!$GLOBALS['DEBUG_MODE']) { break; } // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... case 'CUSTOM_BASE_URL_NOHTTP': $value = preg_replace('#^https?://[^/]+/#', '/', get_custom_base_url()); if (substr($value, 0, 2) == '//') { $value = substr($value, 1); } if (!$GLOBALS['DEBUG_MODE']) { break; } // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... case 'BASE_URL': $value = get_base_url(isset($param[0]) ? $param[0] == '1' : NULL); break; case 'ZONE': $value = get_zone_name(); break; case 'PAGE': $value = get_page_name(); break; case 'SITE_NAME': $value = get_site_name(); break; case 'HEADER_TEXT': global $ZONE; $value = $ZONE['zone_header_text_trans']; break; case 'PANEL_WIDTH': if (isset($TEMPCODE_SETGET['PANEL_WIDTH']) && $TEMPCODE_SETGET['PANEL_WIDTH'] != '') { $value = $TEMPCODE_SETGET['PANEL_WIDTH']; } else { $value = get_option('panel_width', true); if ($value === NULL) { $value = '13.3em'; } } break; case 'PANEL_WIDTH_SPACED': if (isset($TEMPCODE_SETGET['PANEL_WIDTH_SPACED']) && $TEMPCODE_SETGET['PANEL_WIDTH_SPACED'] != '') { $value = $TEMPCODE_SETGET['PANEL_WIDTH_SPACED']; } else { $value = get_option('panel_width_spaced', true); if (is_null($value)) { $value = '14.3em'; } } break; case 'TRIM': if (isset($param[0])) { $value = preg_replace(array('#^\\s+#', '#^(<br\\s*/?' . '>\\s*)+#', '#^( )+#', '#\\s+$#', '#(<br\\s*/?' . '>\\s*)+$#', '#( )+$#'), array('', '', '', '', '', ''), $param[0]); } break; case 'CPF_VALUE': if (isset($param[0])) { if (is_numeric($param[0])) { require_code('ocf_members'); $fields = ocf_get_custom_fields_member(isset($param[1]) ? intval($param[1]) : get_member()); if (array_key_exists(intval($param[0]), $fields)) { $_value = $fields[intval($param[0])]; } } elseif (substr($param[0], 0, 2) == 'm_' && strpos(strtolower($param[0]), 'hash') === false && strpos(strtolower($param[0]), 'salt') === false) { $_value = $GLOBALS['FORUM_DRIVER']->get_member_row_field(isset($param[1]) ? intval($param[1]) : get_member(), $param[0]); } else { $_value = get_ocp_cpf($param[0], isset($param[1]) ? intval($param[1]) : NULL); } if (!is_string($_value)) { $value = is_null($_value) ? '' : strval($_value); } else { $value = $_value; } } break; case 'BANNER': if (addon_installed('banners')) { global $SITE_INFO; $is_on_banners = get_option('is_on_banners') == '1' && (!has_specific_permission(get_member(), 'banner_free') || $GLOBALS['FORUM_DRIVER']->is_super_admin(get_member()) && get_option('admin_banners') == '1' || !is_null($GLOBALS['CURRENT_SHARE_USER'])); if (array_key_exists('throttle_bandwidth_registered', $SITE_INFO)) { $views_till_now = intval(get_value('page_views')); $bandwidth_allowed = $SITE_INFO['throttle_bandwidth_registered']; $total_bandwidth = intval(get_value('download_bandwidth')); if ($bandwidth_allowed * 1024 * 1024 >= $total_bandwidth) { $is_on_banners = false; } } if ($is_on_banners && !is_page_https(get_zone_name(), get_page_name())) { require_code('banners'); $b_type = isset($param[0]) ? $param[0] : ''; $internal_only = isset($param[1]) ? intval($param[1]) : ($b_type == '' ? 0 : 1); if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['SET_RAND'])) { $_value = banners_script(true, '', '', $b_type, $internal_only, ''); $value = $_value->evaluate(); } else { $value = 'Banner goes here'; } } } break; case 'AVATAR': $value = $GLOBALS['FORUM_DRIVER']->get_member_avatar_url(isset($param[0]) ? intval($param[0]) : get_member()); if (url_is_local($value) && $value != '') { $value = get_custom_base_url() . '/' . $value; } break; case 'IS_GUEST': if (isset($param[0])) { $value = is_guest(intval($param[0])) ? '1' : '0'; } else { $value = is_guest() ? '1' : '0'; } break; case 'MEMBER': $value = strval(get_member()); break; case 'USER': if (!isset($param[0])) { $value = strval(get_member()); } else { $member_id = $GLOBALS['FORUM_DRIVER']->get_member_from_username($param[0]); $value = is_null($member_id) ? '' : strval($member_id); } break; case 'CSS_INCLUDE': if (isset($param[0])) { require_css($param[0]); /*// Has to do this inline, as you're not allowed to reference sheets outside head if (!array_key_exists($param[0],$GLOBALS['CSSS'])) { $GLOBALS['CSSS'][$param[0]]=1; $file=css_enforce($param[0]); $_value=do_template('CSS_NEED_INLINE',array('_GUID'=>'9de994d2f6d47a622d49347feb7ebe96','CSS'=>str_replace('../../../../',get_base_url().'/',file_get_contents($file,FILE_TEXT)))); $value=$_value->evaluate(); }*/ } break; case 'USER_OVERIDE': $value = get_param('id', ''); if (!is_numeric($value) || $value == '') { $value = strval(get_member()); } break; case 'IS_HTTPAUTH_LOGIN': $value = is_httpauth_login() ? '1' : '0'; break; case 'MEMBER_PROFILE_LINK': $value = $GLOBALS['FORUM_DRIVER']->member_profile_url(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member(), false, true); if (is_null($value)) { $value = ''; } break; case 'USERNAME': $value = $GLOBALS['FORUM_DRIVER']->get_username(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member()); if (is_null($value)) { $value = do_lang('UNKNOWN'); } break; case 'CYCLE': if (isset($param[0])) { if (!isset($CYCLES[$param[0]])) { $CYCLES[$param[0]] = 0; } if (!isset($param[1])) { $value = strval($CYCLES[$param[0]]); } else { if (count($param) == 2) { $param = array_merge(array($param[0]), explode(',', $param[1])); } ++$CYCLES[$param[0]]; if (!array_key_exists($CYCLES[$param[0]], $param)) { $CYCLES[$param[0]] = 1; } $value = $param[$CYCLES[$param[0]]]; } } break; case 'THUMBNAIL': require_code('images'); $value = _symbol_thumbnail($param); break; case 'IMAGE_WIDTH': require_code('images'); list($value, ) = _symbol_image_dims($param); break; case 'IMAGE_HEIGHT': require_code('images'); list(, $value) = _symbol_image_dims($param); break; case 'IS_IN_GROUP': if (isset($param[0])) { if (in_array($param[count($param) - 1], array('', 'primary', 'secondary'))) { $last_param = $param[count($param) - 1]; unset($param[count($param) - 1]); } else { $last_param = ''; } $member_id = get_member(); $new_param = ''; $param_2 = array(); foreach ($param as $group) { if (substr($group, 0, 1) == '!' && is_numeric(substr($group, 1))) { $member_id = intval(substr($group, 1)); } else { $param_2 = array_merge($param_2, explode(',', $group)); } } foreach ($param_2 as $group) { if ($new_param != '') { $new_param .= ','; } $new_param .= $group; } if ($last_param == 'primary') { $member_row = $GLOBALS['FORUM_DRIVER']->get_member_row($member_id); $real_group_list = array($GLOBALS['FORUM_DRIVER']->pname_group($member_row)); } elseif ($last_param == 'secondary') { $real_group_list = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id); $member_row = $GLOBALS['FORUM_DRIVER']->get_member_row($member_id); $real_group_list = array_diff($real_group_list, array($GLOBALS['FORUM_DRIVER']->pname_group($member_row))); } else { $real_group_list = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id); } require_code('ocfiltering'); $value = count(array_intersect(ocfilter_to_idlist_using_memory($new_param, $GLOBALS['FORUM_DRIVER']->get_usergroup_list()), $real_group_list)) != 0 ? '1' : '0'; } break; case 'IS_STAFF': if (isset($GLOBALS['FORUM_DRIVER'])) { $value = $GLOBALS['FORUM_DRIVER']->is_staff(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member()) ? '1' : '0'; } else { $value = '0'; } break; case 'IS_SUPER_ADMIN': if (isset($GLOBALS['FORUM_DRIVER'])) { $value = $GLOBALS['FORUM_DRIVER']->is_super_admin(!is_null($param) && isset($param[0]) ? intval($param[0]) : get_member()) ? '1' : '0'; } else { $value = '0'; } break; case 'PHOTO': if (isset($param[0])) { $value = $GLOBALS['FORUM_DRIVER']->get_member_photo_url(intval($param[0])); if (url_is_local($value) && $value != '') { $value = get_custom_base_url() . '/' . $value; } } break; case 'OCF_RANK_IMAGE': if (addon_installed('ocf_forum')) { require_code('ocf_groups'); $rank_images = new ocp_tempcode(); $member_id = isset($param[0]) ? intval($param[0]) : get_member(); $posters_groups = $GLOBALS['FORUM_DRIVER']->get_members_groups($member_id, true); foreach ($posters_groups as $group) { $rank_image = ocf_get_group_property($group, 'rank_image'); $group_leader = ocf_get_group_property($group, 'group_leader'); $group_name = ocf_get_group_name($group); $rank_image_pri_only = ocf_get_group_property($group, 'rank_image_pri_only'); if ($rank_image != '' && ($rank_image_pri_only == 0 || $group == $GLOBALS['FORUM_DRIVER']->get_member_row_field($member_id, 'm_primary_group'))) { $rank_images->attach(do_template('OCF_RANK_IMAGE', array('USERNAME' => $GLOBALS['FORUM_DRIVER']->get_username($member_id), 'GROUP_NAME' => $group_name, 'IMG' => $rank_image, 'IS_LEADER' => $group_leader == $member_id))); } } $value = $rank_images->evaluate(); } break; case 'TOTAL_POINTS': if (addon_installed('points')) { require_code('points'); $value = strval(total_points(isset($param[0]) ? intval($param[0]) : get_member())); } break; case 'POINTS_USED': if (addon_installed('points')) { require_code('points'); $value = strval(points_used(isset($param[0]) ? intval($param[0]) : get_member())); } break; case 'AVAILABLE_POINTS': if (addon_installed('points')) { require_code('points'); $value = strval(available_points(isset($param[0]) ? intval($param[0]) : get_member())); } break; case 'URL_FOR_GET_FORM': if (isset($param[0])) { $url_bits = parse_url($param[0]); if (array_key_exists('scheme', $url_bits)) { $value = $url_bits['scheme'] . '://' . (array_key_exists('host', $url_bits) ? $url_bits['host'] : 'localhost'); if (array_key_exists('port', $url_bits) && $url_bits['port'] != 80) { $value .= ':' . strval($url_bits['port']); } } if (array_key_exists('path', $url_bits)) { $value .= $url_bits['path']; } } break; case 'HIDDENS_FOR_GET_FORM': $_value = new ocp_tempcode(); $url_bits = parse_url($param[0]); if (array_key_exists('query', $url_bits) && $url_bits['query'] != '') { foreach (explode('&', $url_bits['query']) as $exp) { $parts = explode('=', $exp, 2); if (count($parts) == 2) { if (!in_array($parts[0], $param)) { $_value->attach(form_input_hidden($parts[0], urldecode($parts[1]))); } } } } $value = $_value->evaluate(); break; case 'NOTIFICATIONS_ENABLED': $value = ''; if (array_key_exists(0, $param)) { require_code('notifications'); $value = notifications_enabled(array_key_exists(1, $param) ? $param[1] : get_page_name(), $param[0]) ? '1' : '0'; } break; case 'DOCUMENT_HELP': global $DOCUMENT_HELP, $HELPER_PANEL_TUTORIAL; $value = $DOCUMENT_HELP; if ($value == '' && $HELPER_PANEL_TUTORIAL != '') { $value = brand_base_url() . '/docs' . strval(ocp_version()) . '/pg/' . $HELPER_PANEL_TUTORIAL; } break; case 'HTTP_STATUS_CODE': global $HTTP_STATUS_CODE; $value = $HTTP_STATUS_CODE; break; case 'TEMPCODE': if (isset($param[0])) { require_code('tempcode_compiler'); $_value = template_to_tempcode($param[0]); $value = $_value->evaluate(); } break; case 'COMCODE': if (isset($param[0])) { $_value = comcode_to_tempcode($param[0], NULL, true); $value = $_value->evaluate(); } break; case 'FLAGRANT': $_value = get_flagrant(); $value = $_value->evaluate(); break; case 'IMG_WIDTH': case 'IMG_HEIGHT': if (isset($param[0]) && isset($GLOBALS['SITE_DB']) && function_exists('find_theme_image') && $GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { global $THEME_IMG_DIMS_CACHE; if (!isset($THEME_IMG_DIMS_CACHE)) { $THEME_IMG_DIMS_CACHE = function_exists('persistant_cache_get') ? persistant_cache_get('THEME_IMG_DIMS') : array(); } if (isset($THEME_IMG_DIMS_CACHE[$param[0]])) { list($width, $height) = $THEME_IMG_DIMS_CACHE[$param[0]]; $value = $name == 'IMG_WIDTH' ? $width : $height; } else { if (strpos($param[0], '://') === false) { $img_url = find_theme_image($param[0], false, false, array_key_exists(2, $param) ? $param[2] : NULL, NULL, isset($param[1]) && $param[1] == '1' ? $GLOBALS['FORUM_DB'] : $GLOBALS['SITE_DB']); } else { $img_url = $param[0]; } require_code('images'); list($width, $height) = _symbol_image_dims(array($img_url)); $value = $name == 'IMG_WIDTH' ? $width : $height; $THEME_IMG_DIMS_CACHE[$param[0]] = array($width, $height); if (function_exists('persistant_cache_set')) { persistant_cache_set('THEME_IMG_DIMS', $THEME_IMG_DIMS_CACHE); } } } break; case 'CLEAN_FILE_SIZE': if (isset($param[0])) { $bytes = is_numeric($param[0]) ? intval($param[0]) : NULL; require_code('files'); $value = clean_file_size($bytes); } break; case 'TIME_PERIOD': if (isset($param[0])) { $value = display_time_period(intval($param[0])); } break; case 'MAKE_RELATIVE_DATE': if (isset($param[0])) { if (get_option('use_contextual_dates') == '0' && (!array_key_exists(1, $param) || $param[1] != '1')) { $value = get_timezoned_date(intval($param[0])); } else { $value = display_time_period(time() - intval($param[0])); } } break; case 'TIMEZONE': $value = make_nice_timezone_name(get_site_timezone()); break; case 'LOAD_PAGE': foreach ($param as $i => $p) { if (is_object($p)) { $param[$i] = $p->evaluate(); } } global $LOADED_PAGES; if (strpos($param[0], ':') !== false) { $param = array_reverse(explode(':', $param[0], 2)); } $_value = $LOADED_PAGES[serialize($param)]; $value = $_value->evaluate(); break; case 'RUNNING_SCRIPT': if (isset($param[0])) { $value = running_script($param[0]) ? '1' : '0'; } break; case 'MATCH_KEY_MATCH': $value = '0'; foreach ($param as $match_key) { if ($match_key == '1' || $match_key == '0' || $match_key == '') { continue; } if (match_key_match($match_key, isset($param[1]) && $match_key == '1')) { $value = '1'; } } break; case 'VERSION': $value = strval(ocp_version()); break; case 'PREVIEW_VALIDATION': $value = get_option('is_on_preview_validation') == '1' ? '1' : '0'; break; case 'BLOCK': if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['SET_RAND'])) { foreach ($param as $i => $p) { if (is_object($p)) { $param[$i] = $p->evaluate(); } } if (count($param) == 1 && strpos($param[0], ',') !== false) { $param = preg_split('#((?<!\\\\)|(?<=\\\\\\\\)|(?<=^)),#', $param[0]); foreach ($param as $key => $val) { $param[$key] = str_replace('\\,', ',', $val); } } global $LOADED_BLOCKS; if (isset($LOADED_BLOCKS[serialize($param)])) { // Will always be set $value = $LOADED_BLOCKS[serialize($param)]->evaluate(); } } break; case 'CURRENCY': if (addon_installed('ecommerce')) { if (isset($param[0])) { require_code('currency'); $value = currency_convert(floatval(str_replace(',', '', $param[0])), isset($param[1]) && $param[1] != '' ? $param[1] : get_option('currency'), isset($param[2]) && $param[2] != '' ? $param[2] : NULL, isset($param[3]) && $param[3] == '1'); if (is_null($value)) { $value = do_lang('INTERNAL_ERROR'); } } else { $value = get_option('currency'); } } break; case 'CURRENCY_SYMBOL': if (addon_installed('ecommerce')) { require_code('ecommerce'); $value = ecommerce_get_currency_symbol(); } break; case 'GEOLOCATE': $value = geolocate_ip(isset($param[0]) ? $param[0] : NULL); break; case 'NO_SAFE_MODE': $value = str_replace(array('on', 'true', 'yes'), array('1', '1', '1'), strtolower(ini_get('safe_mode'))) == '1' ? '0' : '1'; break; case 'FORCE_PREVIEWS': if (get_option('forced_preview_option') == '1') { if (get_forum_type() == 'ocf') { if (is_guest() && get_option('default_preview_guests') == '0') { $value = '0'; } else { $value = $GLOBALS['FORUM_DRIVER']->get_member_row_field(get_member(), 'm_preview_posts') == 1 ? '1' : '0'; } } else { $value = get_option('default_preview_guests') == '0' ? '0' : '1'; } } else { $value = '0'; } break; case 'PREVIEW_URL': $value = find_script('preview'); $value .= '?page=' . get_page_name(); $value .= '&type=' . get_param('type', '', true); break; case 'ADDON_INSTALLED': if (isset($param[0]) && !running_script('install')) { $value = addon_installed($param[0]) ? '1' : '0'; } break; case 'VALUE_OPTION': if (isset($param[0])) { $value = function_exists('get_value') ? get_value($param[0]) : ''; if (is_null($value)) { $value = function_exists('get_long_value') ? get_long_value($param[0]) : ''; if (is_null($value)) { $value = isset($param[1]) ? $param[1] : ''; if ($param[0] == 'textmate' && (ocp_srv('HTTP_HOST') == 'localhost' && strpos(ocp_srv('HTTP_USER_AGENT'), 'Macintosh') !== false)) { $value = '1'; } } } } break; case 'KEEP_INDEX': // What needs preserving in the URL $value = 'index.php'; if (count($_GET) > 0) { foreach ($_GET as $key => $val) { if (is_array($val)) { continue; } if (get_magic_quotes_gpc()) { $val = stripslashes($val); } if (substr($key, 0, 5) == 'keep_' && !skippable_keep($key, $val) && strpos($key, '_expand_') === false) { $value .= ($value == 'index.php' ? '?' : '&') . urlencode($key) . '=' . ocp_url_encode($val); } } } break; case 'HIDE_HELP_PANEL': $value = array_key_exists('hide_help_panel', $_COOKIE) && $_COOKIE['hide_help_panel'] == '1' ? '1' : '0'; break; case 'URLISE_LANG': if (isset($param[1])) { $_value = urlise_lang($param[0], $param[1], isset($param[2]) ? $param[2] : '', isset($param[3]) ? $param[3] == '1' : false); $value = $_value->evaluate(); } break; case 'FIND_SCRIPT_NOHTTP': if (isset($param[0]) && function_exists('find_script')) { $value = preg_replace('#^https?://[^/]+#', '', find_script($param[0], false, isset($param[1]) ? intval($param[1]) : 0)); } if (!$GLOBALS['DEBUG_MODE']) { break; } // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... // Debug mode changes base domain so we need to actually use it in full (fine, we don't have HTTPS in debug mode). Bubble on... case 'FIND_SCRIPT': if (isset($param[0]) && function_exists('find_script')) { $value = find_script($param[0], false, isset($param[1]) ? intval($param[1]) : 0); } break; case 'MOBILE': $value = is_mobile(NULL, array_key_exists(0, $param) ? $param[0] == '1' : false) ? '1' : '0'; break; case 'VALID_FILE_TYPES': $value = get_option('valid_types'); $types = array_flip(explode(',', $value)); $value = ''; ksort($types); foreach (array_flip($types) as $val) { $value .= $val . ','; } $value = substr($value, 0, strlen($value) - 1); break; case 'BROWSER_UA': $browser = get_browser_string(); $value = $browser; break; case 'OS': $os = get_os_string(); if (is_null($os)) { $os = ''; } $value = $os; break; case 'ANCHOR': if (isset($param[0])) { $_value = do_template('ANCHOR', array('_GUID' => '8795c70c9dd7c6217bb765264ac24092', 'NAME' => $param[0])); $value = $_value->evaluate(); } break; case 'CSS_TEMPCODE': $_value = css_tempcode(); $value = $_value->evaluate(); break; case 'JS_TEMPCODE': $_value = javascript_tempcode(isset($param[0]) ? $param[0] : NULL); $value = $_value->evaluate(); break; case 'PAD_LEFT': if (array_key_exists(1, $param)) { $value = str_pad($param[0], intval($param[1]), array_key_exists(2, $param) ? $param[2] : '', STR_PAD_LEFT); } break; case 'PAD_RIGHT': if (array_key_exists(1, $param)) { $value = str_pad($param[0], intval($param[1]), array_key_exists(2, $param) ? $param[2] : '', STR_PAD_RIGHT); } break; case 'PAGE_TITLE': $value = is_null($DISPLAYED_TITLE) ? '' : $DISPLAYED_TITLE->evaluate(); break; case 'SET_TITLE': if (array_key_exists(0, $param)) { get_page_title($param[0], false); } break; case 'EXTRA_HEAD': $_value = $GLOBALS['EXTRA_HEAD']; if ($_value === NULL) { $_value = new ocp_tempcode(); } $value = $_value->evaluate(); break; case 'EXTRA_FOOT': if ($GLOBALS['EXTRA_FOOT'] === NULL) { $GLOBALS['EXTRA_FOOT'] = new ocp_tempcode(); } $_value = $GLOBALS['EXTRA_FOOT']; if (array_key_exists(0, $param)) { $GLOBALS['EXTRA_FOOT']->attach($param[0]); } else { $value = $_value->evaluate(); } break; case 'RAND': if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['RAND'])) { $GLOBALS['NO_EVAL_CACHE'] = true; $value = strval(mt_rand(0, 32000)); } else { $value = '4'; } break; case 'SET_RAND': if (isset($param[0])) { if (isset($GLOBALS['NON_CACHEABLE_SYMBOLS']['SET_RAND'])) { $GLOBALS['NO_EVAL_CACHE'] = true; $value = $param[mt_rand(0, count($param) - 1)]; } else { $value = $param[0]; } } break; case 'COPYRIGHT': $value = str_replace('$CURRENT_YEAR', date('Y'), get_option('copyright')); break; case 'KEYWORDS_SPACED': $value = str_replace(',', ' ', get_option('keywords')); break; case 'STAFF_ADDRESS_PURE': $value = get_option('staff_address'); break; case 'STAFF_ADDRESS': require_code('obfuscate'); $value = obfuscate_email_address(get_option('staff_address')); break; case 'DOMAIN': $value = get_domain(); break; case 'BRAND_NAME': $value = function_exists('get_value') ? get_value('rebrand_name') : NULL; if (is_null($value)) { $value = 'ocPortal'; } break; case 'BRAND_BASE_URL': $value = brand_base_url(); break; case 'SHOW_DOCS': $value = get_option('show_docs') === '0' ? '0' : '1'; break; case 'MEMBER_EMAIL': $value = $GLOBALS['FORUM_DRIVER']->get_member_email_address(isset($param[0]) ? intval($param[0]) : get_member()); break; case 'OCF_MEMBER_HTML': if (get_forum_type() == 'ocf') { require_code('ocf_members'); require_code('ocf_members2'); $_value = ocf_show_member_box(isset($param[0]) ? intval($param[0]) : get_member()); $value = $_value->evaluate(); } break; case 'HAS_SPECIFIC_PERMISSION': if (isset($param[0])) { $value = has_specific_permission(!is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), $param[0]) ? '1' : '0'; } break; case 'HAS_ZONE_ACCESS': if (isset($param[0])) { $value = has_zone_access(!is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), $param[0]) ? '1' : '0'; } break; case 'HAS_PAGE_ACCESS': if (isset($param[0]) && isset($param[1])) { $value = has_page_access(!is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), $param[0], $param[1], !is_null($param) && isset($param[3]) ? $param[3] == '1' : false) ? '1' : '0'; } break; case 'HAS_CATEGORY_ACCESS': if (isset($param[0])) { $value = has_category_access(!is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), $param[0], $param[1]) ? '1' : '0'; } break; case 'HAS_ATTACHMENT_ACCESS': if (isset($param[0])) { require_code('attachments'); $value = has_attachment_access(!is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), $param[0]) ? '1' : '0'; } break; case 'HAS_SUBMIT_PERMISSION': if (isset($param[0]) && (strtolower($param[0]) == 'low' || strtolower($param[0]) == 'mid' || strtolower($param[0]) == 'high')) { $value = has_submit_permission(strtolower($param[0]), !is_null($param) && isset($param[1]) ? intval($param[1]) : get_member(), !is_null($param) && isset($param[2]) ? $param[2] : get_ip_address(), !is_null($param) && isset($param[3]) ? $param[3] : get_page_name()) ? '1' : '0'; } break; case 'HAS_DELETE_PERMISSION': if (isset($param[0]) && (strtolower($param[0]) == 'low' || strtolower($param[0]) == 'mid' || strtolower($param[0]) == 'high') && isset($param[1])) { $value = has_delete_permission(strtolower($param[0]), !is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), intval($param[1]), !is_null($param) && isset($param[3]) ? $param[3] : get_page_name()) ? '1' : '0'; } break; case 'HAS_EDIT_PERMISSION': if (isset($param[0]) && (strtolower($param[0]) == 'low' || strtolower($param[0]) == 'mid' || strtolower($param[0]) == 'high') && isset($param[1])) { $value = has_edit_permission(strtolower($param[0]), !is_null($param) && isset($param[2]) ? intval($param[2]) : get_member(), intval($param[1]), !is_null($param) && isset($param[3]) ? $param[3] : get_page_name()) ? '1' : '0'; } break; case 'ENTITY_DECODE': if (isset($param[0])) { $value = @html_entity_decode($param[0], ENT_QUOTES, get_charset()); } break; case 'RESET_CYCLE': if (isset($param[0])) { $CYCLES[$param[0]] = 0; } break; case 'SITE_SCOPE': $value = get_option('site_scope'); break; case 'LAST_VISIT_TIME': if (get_forum_type() == 'ocf') { $member_info = ocf_read_in_member_profile(get_member(), true); $value = strval($member_info['last_visit_time']); } break; case 'NUM_NEW_TOPICS': if (get_forum_type() == 'ocf') { $member_info = ocf_read_in_member_profile(get_member(), true); $_new_topics = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_topics WHERE NOT t_forum_id IS NULL AND t_cache_first_time>' . strval((int) $member_info['last_visit_time'])); $new_topics = $_new_topics[0]['mycnt']; $value = strval($new_topics); } break; case 'NUM_NEW_POSTS': if (get_forum_type() == 'ocf') { $member_info = ocf_read_in_member_profile(get_member(), true); $_new_posts = $GLOBALS['FORUM_DB']->query('SELECT COUNT(*) AS mycnt FROM ' . $GLOBALS['FORUM_DB']->get_table_prefix() . 'f_posts WHERE NOT p_cache_forum_id IS NULL AND p_time>' . strval((int) $member_info['last_visit_time'])); $new_posts = $_new_posts[0]['mycnt']; $value = strval($new_posts); } break; case 'HAS_FORUM': $value = has_no_forum() ? '0' : '1'; break; case 'OCF': $value = get_forum_type() == 'ocf' ? '1' : '0'; break; case 'BOARD_PREFIX': $value = get_forum_base_url(); break; case 'DATE_AND_TIME': $use_contextual_dates = isset($param[0]) && $param[0] == '1'; $verbose = isset($param[1]) && $param[1] == '1'; $server_time = isset($param[2]) && $param[2] == '1'; $time = isset($param[3]) ? intval($param[3]) : time(); $value = get_timezoned_date($time, true, $verbose, $server_time, !$use_contextual_dates); break; case 'DATE': $use_contextual_dates = isset($param[0]) && $param[0] == '1'; $verbose = isset($param[1]) && $param[1] == '1'; $server_time = isset($param[2]) && $param[2] == '1'; $time = isset($param[3]) ? intval($param[3]) : time(); $value = get_timezoned_date($time, false, $verbose, $server_time, !$use_contextual_dates); break; case 'TIME': $time = isset($param[0]) ? intval($param[0]) : time(); $value = get_timezoned_time($time); break; case 'SECONDS_PERIOD': if (array_key_exists(0, $param)) { $value = display_seconds_period(intval($param[0])); } break; case 'FROM_TIMESTAMP': if (isset($param[0])) { $timestamp = isset($param[1]) ? intval($param[1]) : time(); if (!array_key_exists(2, $param) || $param[2] == '1') { $timestamp = utctime_to_usertime($timestamp); } $value = locale_filter(my_strftime($param[0], $timestamp)); if ($value == $param[0]) { // If no conversion happened then the syntax must have been for 'date' not 'strftime' $value = date($param[0], $timestamp); } } else { $timestamp = time(); $value = strval($timestamp); } break; case 'TO_TIMESTAMP': if (isset($param[0])) { $value = strval(strtotime($param[0])); if (array_key_exists(1, $param) && $param[1] == '1') { $value = strval(usertime_to_utctime(intval($value))); } // '1' means date was in user-time so needs converting to a UTC timestamp } else { $value = strval(time()); } break; case 'SESSION_HASHED': $value = md5(strval(get_session_id())); break; case 'SESSION': $value = strval(get_session_id()); break; case 'IN_ARRAY': if (isset($param[1])) { $array = array_slice($param, 1); $value = in_array($param[0], $array) ? '1' : '0'; } break; case 'MULT': if (isset($param[1])) { $value = float_to_raw_string(floatval($param[0]) * floatval($param[1]), 2, true); } break; case 'ROUND': if (isset($param[0])) { $amount = isset($param[1]) ? intval($param[1]) : 0; if ($amount > 0) { $value = float_format(floatval($param[0]), $amount); } else { $value = strval(intval(round(floatval($param[0]), $amount))); } } break; case 'DEV_MODE': $value = $GLOBALS['DEBUG_MODE'] ? '1' : '0'; break; case 'BROWSER_MATCHES': if (isset($param[0])) { $q = false; foreach (explode('|', $param[0]) as $browser) { $q = browser_matches($browser); if ($q) { break; } } $value = $q ? '1' : '0'; } break; case 'ISSET': if (isset($param[0])) { $value = isset($TEMPCODE_SETGET[$param[0]]) ? '1' : '0'; } break; case 'INIT': if (isset($param[1])) { if (!isset($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = $param[1]; } } break; case 'INC': if (isset($param[0])) { if (!isset($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = '0'; } $TEMPCODE_SETGET[$param[0]] = strval(intval($TEMPCODE_SETGET[$param[0]]) + 1); } break; case 'DEC': if (isset($param[0])) { if (!isset($TEMPCODE_SETGET[$param[0]])) { $TEMPCODE_SETGET[$param[0]] = '0'; } $TEMPCODE_SETGET[$param[0]] = strval(intval($TEMPCODE_SETGET[$param[0]]) - 1); } break; case 'PREG_MATCH': if (isset($param[1])) { $value = preg_match('#' . str_replace('#', '\\#', $param[0]) . '#' . (isset($param[2]) ? str_replace('e', '', $param[2]) : ''), $param[1]) != 0 ? '1' : '0'; } break; case 'PREG_REPLACE': if (isset($param[2])) { $value = preg_replace('#' . str_replace('#', '\\#', $param[0]) . '#' . (isset($param[3]) ? str_replace('e', '', $param[3]) : ''), $param[1], $param[2]); } break; case 'MAX': if (isset($param[0])) { $value = strval(max(intval($param[0]), intval($param[1]))); } break; case 'MIN': if (isset($param[0])) { $value = strval(min(intval($param[0]), intval($param[1]))); } break; case 'MOD': if (isset($param[0])) { $value = strval(max(intval($param[0]), -intval($param[0]))); } break; case 'REM': if (isset($param[1])) { $value = strval(intval($param[0]) % intval($param[1])); } break; case 'DIV_FLOAT': if (isset($param[1])) { $value = float_to_raw_string(floatval($param[0]) / floatval($param[1]), 2, true); } break; case 'DIV': if (isset($param[1])) { $value = strval(intval(floor(floatval($param[0]) / floatval($param[1])))); } break; case 'SUBTRACT': if (isset($param[1])) { $value = float_to_raw_string(floatval(str_replace(',', '', $param[0])) - floatval(str_replace(',', '', $param[1])), 2, true); } break; case 'ADD': if (isset($param[1])) { $value = float_to_raw_string(floatval(str_replace(',', '', $param[0])) + floatval(str_replace(',', '', $param[1])), 2, true); } break; case 'WCASE': if (isset($param[0])) { $value = ucwords($param[0]); } break; case 'LCASE': if (isset($param[0])) { $value = ocp_mb_strtolower($param[0]); } break; case 'UCASE': if (isset($param[0])) { $value = ocp_mb_strtoupper($param[0]); } break; case '_POST': if (isset($param[0])) { $value = post_param($param[0], isset($param[1]) ? $param[1] : ''); } break; case 'REPLACE': if (isset($param[2])) { $value = str_replace($param[0], $param[1], $param[2]); if ($GLOBALS['XSS_DETECT'] && ocp_is_escaped($param[0])) { ocp_mark_as_escaped($value); } } break; case 'AT': if (isset($param[1])) { $value = ocp_mb_substr($param[0], intval($param[1]), 1); } break; case 'STRPOS': if (isset($param[1])) { $t_value = strpos($param[0], $param[1]); $value = $t_value === false ? '0' : strval($t_value); } break; case 'IN_STR': if (isset($param[1])) { if ($param[1] == '') { $value = '0'; } else { $value = '0'; foreach ($param as $i => $check) { if (is_integer($i) && $i != 0 && $check != '') { if (strpos($param[0], $check) !== false) { $value = '1'; break; } } } } } break; case 'SUBSTR_COUNT': if (isset($param[1])) { $value = strval(substr_count($param[0], $param[1])); } break; case 'SUBSTR': if (isset($param[1])) { $value = ocp_mb_substr($param[0], intval($param[1]), isset($param[2]) ? intval($param[2]) : strlen($param[0])); } break; case 'LENGTH': if (isset($param[0])) { $value = strval(ocp_mb_strlen($param[0])); } break; case 'WORDWRAP': if (isset($param[1])) { $cut = isset($param[3]) && $param[3] == '1'; $value = wordwrap($param[0], intval($param[1]), isset($param[2]) ? $param[2] : '<br />', $cut); if ($GLOBALS['XSS_DETECT'] && ocp_is_escaped($param[0])) { ocp_mark_as_escaped($value); } } break; case 'ALTERNATOR_TRUNCATED': // Alternate values according to whether some given text WOULD have been truncated. 0: text to check against, 1: the truncate length, 2:IF would not be do this, 3: if it would be do this, 4: whether given text is encoded as HTML (0=no [default, plain-text], 1=yes) if (isset($param[3])) { $amount = intval($param[1]); $is_html = isset($param[4]) && $param[4] == '1'; if (strlen($is_html ? strip_tags($param[0]) : $param[0]) > $amount) { $value = $param[3]; } else { $value = $param[2]; } } break; case 'ESCAPE': if (isset($param[0])) { $d_escaping = array(isset($param[1]) ? constant($param[1]) : ENTITY_ESCAPED); if (is_string($param[0])) { apply_tempcode_escaping($d_escaping, $param[0]); } $value = $param[0]; } break; case 'COOKIE_PATH': $value = function_exists('get_cookie_path') ? get_cookie_path() : '/'; break; case 'COOKIE_DOMAIN': $s_value = function_exists('get_cookie_domain') ? get_cookie_domain() : ''; $value = is_null($s_value) ? '' : $s_value; break; case 'IS_A_COOKIE_LOGIN': global $IS_A_COOKIE_LOGIN; $value = $IS_A_COOKIE_LOGIN && ini_get('suhosin.cookie.max_name_length') !== '64' ? '1' : '0'; break; case 'GROUP_ID': if (isset($param[0])) { $groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(isset($param[1]) ? intval($param[1]) : get_member()); $value = array_key_exists(intval($param[0]), $groups) ? strval($groups[intval($param[0])]) : ''; } break; case 'GROUP_NAME': if (isset($param[0])) { $groups = $GLOBALS['FORUM_DRIVER']->get_members_groups(isset($param[1]) ? intval($param[1]) : get_member()); if (array_key_exists(intval($param[0]), $groups)) { $all_usergroups = $GLOBALS['FORUM_DRIVER']->get_usergroup_list(); $value = $all_usergroups[$groups[intval($param[0])]]; } if ($GLOBALS['XSS_DETECT'] && ocp_is_escaped($param[0])) { ocp_mark_as_escaped($value); } } break; case 'NEGATE': if (isset($param[0])) { $value = strval(-intval($param[0])); } break; case 'XOR': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count == 1 ? '1' : '0'; break; case 'NOR': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count > 0 ? '0' : '1'; break; case 'NAND': $count = 0; foreach ($param as $test) { if ($test == '1' || $test == '1') { $count++; } } $value = $count == count($param) ? '0' : '1'; break; case 'LT': if (isset($param[1])) { $value = intval($param[0]) < intval($param[1]) ? '1' : '0'; } break; case 'GT': if (isset($param[1])) { $value = intval($param[0]) > intval($param[1]) ? '1' : '0'; } break; case 'COPPA_ON': $value = get_option('is_on_coppa') == '1' ? '1' : '0'; break; case 'OBFUSCATE': if (isset($param[0])) { require_code('obfuscate'); $value = obfuscate_entities($param[0]); } break; case 'FIX_ID': if (isset($param[0])) { $value = fix_id($param[0]); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } } break; case 'MAILTO': require_code('obfuscate'); $value = mailto_obfuscated(); break; case 'INLINE_STATS': $value = get_option('show_inline_stats') == '1' ? '1' : '0'; break; case 'ATTACHMENT_DOWNLOADS': if (isset($param[0])) { $db = $GLOBALS['SITE_DB']; if (isset($param[1]) && $param[1] == '1') { $db = $GLOBALS['FORUM_DB']; } $_value = $db->query_value_null_ok('attachments', 'a_num_downloads', array('id' => intval($param[0]))); $value = is_null($_value) ? '?' : strval($_value); } break; case 'CSS_DIMENSION_REDUCE': if (isset($param[1])) { $value = $param[0]; if (substr($value, -2) == 'px') { $b = $param[1]; $value = strval(intval(substr($value, 0, -2)) - intval($b)) . 'px'; } if ($value == '') { $value = '0px'; } } break; case 'COMMENT_COUNT': if (isset($param[1])) { if (get_option('is_on_comments') == '1') { $count = 0; $_comments = $GLOBALS['FORUM_DRIVER']->get_forum_topic_posts($GLOBALS['FORUM_DRIVER']->find_topic_id_for_topic_identifier(get_option('comments_forum_name'), $param[0] . '_' . $param[1]), $count, 0, 0, false); $_value = do_lang_tempcode('_COMMENTS', integer_format(0)); if (is_array($_comments)) { $_value = do_lang_tempcode('_COMMENTS', escape_html(integer_format($count))); } $value = $_value->evaluate(); } else { $value = do_lang('VIEW'); } } break; case 'CAN_SPELLCHECK': $value = function_exists('pspell_check') ? '1' : '0'; break; case 'AWARD_ID': if (array_key_exists(0, $param)) { $value = $GLOBALS['SITE_DB']->query_value_null_ok('award_archive', 'content_id', array('a_type_id' => intval($param[0])), 'ORDER BY date_and_time DESC'); if (is_null($value)) { $value = ''; } } break; case 'SELF_PAGE_LINK': $value = ''; if (running_script('index') || running_script('iframe')) { $value = get_zone_name() . ':' . get_page_name(); foreach ($_GET as $key => $val) { if ($key == 'page') { continue; } if (is_array($val)) { continue; } if (substr($key, 0, 5) == 'keep_') { continue; } $value .= ':' . $key . '=' . $val; } } break; case 'SET_TUTORIAL_LINK': $value = ''; if (array_key_exists(1, $param) && $param[1] != '' && $param[1][0] != '#') { set_tutorial_link($param[0], $param[1]); } break; case 'DISPLAY_CONCEPT': $value = ''; if (array_key_exists(0, $param)) { $key = $param[0]; $page_link = get_tutorial_link('concept___' . preg_replace('#[^\\w_]#', '_', $key)); if (is_null($page_link)) { $temp_tpl = make_string_tempcode($key); } else { list($zone, $attributes, $hash) = page_link_decode($page_link); $_url = build_url($attributes, $zone, NULL, false, false, false, $hash); $temp_tpl = do_template('COMCODE_CONCEPT', array('_GUID' => 'ee0cd05f87329923f05145180004d8a8', 'TEXT' => $key, 'URL' => $_url)); } $value = $temp_tpl->evaluate(); } break; case 'SELF_URL': $extra_params = NULL; if (isset($param[3])) { $extra_params = array(); $i = 3; while (isset($param[$i])) { $bits = explode('=', $param[$i], 2); if ($bits[1] == '<null>') { $bits[1] = NULL; } $extra_params[$bits[0]] = $bits[1]; $i++; } } $value = get_self_url(true, isset($param[0]) && $param[0] == '1', $extra_params, isset($param[1]) && $param[1] == '1', isset($param[2]) && $param[2] == '1'); break; case 'SHIFT_DECODE': if (isset($param[0])) { global $SHIFT_VARIABLES; $key = $param[0]; $value = isset($SHIFT_VARIABLES[$key]) ? $SHIFT_VARIABLES[$key]->evaluate() : ''; } break; case 'NUMBER_FORMAT': if (isset($param[0])) { $value = integer_format(intval($param[0])); } break; case 'FLOAT_FORMAT': if (isset($param[0])) { $value = float_format(floatval($param[0])); } break; case 'CURRENTLY_INVISIBLE': $value = is_invisible() ? '1' : '0'; break; case 'IS_FRIEND': if (isset($param[0])) { $test = $GLOBALS['SITE_DB']->query_value_null_ok('chat_buddies', 'member_likes', array('member_likes' => isset($param[1]) ? intval($param[1]) : get_member(), 'member_liked' => intval($param[0]))); $value = is_null($test) ? '0' : '1'; } break; case 'SSW': $value = get_option('ssw') == '1' ? '1' : '0'; break; case 'RATING': if (isset($param[1])) { require_code('feedback'); $rating = get_rating_simple_array(array_key_exists(3, $param) ? $param[3] : get_self_url(true), array_key_exists(4, $param) ? $param[4] : (is_null($DISPLAYED_TITLE) ? '' : $DISPLAYED_TITLE->evaluate()), $param[0], $param[1], array_key_exists(5, $param) ? $param[5] : 'RATING_FORM', array_key_exists(2, $param) ? $param[2] : NULL); if ($rating !== NULL) { if (!array_key_exists(2, $param) || $param[2] == '0') { $value = isset($rating['ALL_RATING_CRITERIA'][0]['RATING']) ? $rating['ALL_RATING_CRITERIA'][0]['RATING'] : ''; } else { $value = do_template('RATING_INLINE_STATIC', $rating); } if (is_object($value)) { $value = $value->evaluate(); } } } break; case 'VIEWS': if (isset($param[2])) { $id_field = 'id'; // Not allowed for security reasons if (preg_match('#^\\w*views\\w*$#', $param[1]) != 0) { $test = $GLOBALS['SITE_DB']->query_value_null_ok($param[0], $param[1], array($id_field => $param[2])); if (!is_null($test)) { $value = integer_format($test); } } } break; default: global $EXTRA_SYMBOLS; if (is_null($EXTRA_SYMBOLS)) { $EXTRA_SYMBOLS = array(); $hooks = find_all_hooks('systems', 'symbols'); foreach (array_keys($hooks) as $hook) { $EXTRA_SYMBOLS[$hook] = array(); } } if (array_key_exists($name, $EXTRA_SYMBOLS)) { if (!array_key_exists('ob', $EXTRA_SYMBOLS[$name])) { require_code('hooks/systems/symbols/' . filter_naughty_harsh($name)); $EXTRA_SYMBOLS[$name]['ob'] = object_factory('Hook_symbol_' . filter_naughty_harsh($name)); } $value = $EXTRA_SYMBOLS[$name]['ob']->run($param); break; } if (defined($name)) { $value = @strval(constant($name)); break; } $value = ''; require_code('site'); attach_message(do_lang_tempcode('MISSING_SYMBOL', escape_html($name)), 'warn'); } if ($escaped != array()) { if (is_object($value)) { $value = $value->evaluate(); } apply_tempcode_escaping($escaped, $value); } if ($cacheable) { $SYMBOL_CACHE[$escaped_codes] = $value; } return $value; } // Is it a directive? if ($type == TC_DIRECTIVE) { $value = ''; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } // In our param we should have a map of bubbled template parameters (under 'vars') and our numbered directive parameters if ($param === NULL) { $param = array(); } // Closure-based Tempcode parser may send in strings, so we need to adapt... foreach ($param as $key => $val) { if (is_string($val)) { $param[$key] = make_string_tempcode($val); } } if (!isset($param['vars'])) { $param['vars'] = array(); } switch ($name) { case 'SHIFT_ENCODE': break; case 'PARAM_INFO': $_value = do_template('PARAM_INFO', array('MAP' => $param['vars'])); $value = $_value->evaluate(); break; case 'CSS_INHERIT': // e.g. {+START,CSS_INHERIT,global,default,#886aa9}{+END} if (isset($param[0])) { require_code('css_and_js'); $css_file = $param[0]->evaluate(); $theme = isset($param[1]) ? $param[1]->evaluate() : 'default'; $seed = isset($param[2]) ? $param[2]->evaluate() : NULL; if ($seed == '') { $seed = NULL; } $dark = isset($param[3]) ? $param[3]->evaluate() == '1' : false; $algorithm = isset($param[4]) ? $param[4]->evaluate() : 'equations'; $value = css_inherit($css_file, $theme, $GLOBALS['FORUM_DRIVER']->get_theme(), $seed, $dark, $algorithm); } break; case 'FRACTIONAL_EDITABLE': foreach (array_keys($param) as $key) { if (!is_numeric($key)) { unset($param[$key]); } } if (isset($param[3])) { $edit_text = $param[0]->evaluate(); $edit_param_name = $param[1]->evaluate(); $edit_pagelink = $param[2]->evaluate(); $supports_comcode = (isset($param[4]) ? $param[3]->evaluate() : '0') == '1'; list($zone, $attributes, ) = page_link_decode($edit_pagelink); if ($zone == '_SEARCH') { $zone = get_module_zone($attributes['page']); } if (has_actual_page_access(get_member(), $attributes['page'], $zone) && has_zone_access(get_member(), 'adminzone')) { $keep = symbol_tempcode('KEEP'); $url = find_script('fractional_edit') . '?edit_param_name=' . urlencode($edit_param_name) . '&supports_comcode=' . ($supports_comcode ? '1' : '0') . '&zone=' . urlencode($zone) . $keep->evaluate(); foreach ($attributes as $key => $val) { $url .= '&' . $key . '=' . urlencode($val); } $_value = $param[count($param) - 1]; $_value = do_template('FRACTIONAL_EDIT', array('_GUID' => '075ac126c427d28b309004bc67b32b08', 'VALUE' => $_value, 'URL' => $url, 'EDIT_TEXT' => $edit_text, 'EDIT_PARAM_NAME' => $edit_param_name)); $value = $_value->evaluate(); } else { $value = $param[count($param) - 1]->evaluate(); } } break; case 'SET': if (isset($param[1])) { $var = $param[0]->evaluate(); $set_val = ''; $i = 1; while (isset($param[$i])) { if ($i != 1) { $set_val .= ','; } $set_val .= $param[1]->evaluate(); $i++; } $TEMPCODE_SETGET[$var] = $set_val; } break; case 'IN_ARRAY': if (isset($param[1])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? '1' : '0'; } break; case 'NOT_IN_ARRAY': if (isset($param[1])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? '0' : '1'; } break; case 'IF_IN_ARRAY': if (isset($param[2])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? $param[2]->evaluate() : ''; } break; case 'IF_NOT_IN_ARRAY': if (isset($param[2])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = in_array($param[0]->evaluate(), $array) ? '' : $param[2]->evaluate(); } break; case 'IMPLODE': if (isset($param[1])) { $key = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); if (isset($param[2]) && $param[2]->evaluate() == '1') { $delim = $param[0]->evaluate(); foreach ($array as $key => $val) { if ($value != '') { $value .= $delim; } $value .= (is_integer($key) ? integer_format($key) : $key) . ' = ' . $val; } } else { $value = implode($param[0]->evaluate(), $array); } } break; case 'COUNT': if (isset($param[0])) { $key = $param[0]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $value = strval(count($array)); } break; case 'BOX': unset($param['vars']); $title = isset($param[1]) ? $param[0]->evaluate() : ''; $dimensions = isset($param[2]) ? $param[1]->evaluate() : '100%'; if ($dimensions == '') { $dimensions = '100%'; } $box_type = isset($param[3]) ? $param[2]->evaluate() : 'classic'; $options = isset($param[4]) ? $param[3]->evaluate() : ''; $meta = isset($param[5]) ? $param[4]->evaluate() : ''; $links = isset($param[6]) ? $param[5]->evaluate() : ''; $expand = isset($param[7]) ? $param[6]->evaluate() == '1' : false; $toplink = isset($param[8]) ? $param[7]->evaluate() : ''; $tmp = put_in_standard_box(array_pop($param), $title, $dimensions, $box_type, $options, $meta, $links, $expand, $toplink); $value = $tmp->evaluate(); break; case 'IF_NON_EMPTY': if (isset($param[1])) { if (!$param[0]->is_really_empty()) { $value = $param[1]->evaluate(); } } break; case 'IF_PASSED': if (isset($param[1])) { $t = $param[0]->evaluate(); if (isset($param['vars'][$t])) { $value = $param[1]->evaluate(); } } break; case 'IF_NON_PASSED': if (isset($param[1])) { $t = $param[0]->evaluate(); if (!isset($param['vars'][$t])) { $value = $param[1]->evaluate(); } } break; case 'IF_EMPTY': if (isset($param[1])) { if ($param[0]->is_really_empty()) { $value = $param[1]->evaluate(); } } break; case 'IF_ARRAY_EMPTY': if (isset($param[0])) { $looking_at = $param[0]->evaluate(); if (array_key_exists($looking_at, $param['vars'])) { if (count($param['vars'][$looking_at]) == 0) { $value = $param[1]->evaluate(); } } } break; case 'IF_ARRAY_NON_EMPTY': if (isset($param[0])) { $looking_at = $param[0]->evaluate(); if (array_key_exists($looking_at, $param['vars'])) { if (count($param['vars'][$looking_at]) != 0) { $value = $param[1]->evaluate(); } } } break; case 'OF': if (isset($param[1])) { $key = $param[0]->evaluate(); $x = $param[1]->evaluate(); $array = array_key_exists($key, $param['vars']) ? $param['vars'][$key] : array(); $x2 = is_numeric($x) ? intval($x) : $x; if (is_integer($x2)) { if ($x2 < 0) { $x2 = count($array) - 1; } elseif ($x2 >= count($array)) { $x2 -= count($array); } } $value = array_key_exists($x2, $array) ? $array[$x2] : ''; if (is_object($value)) { $value = $value->evaluate(); } } break; case 'INCLUDE': if (isset($param[1])) { $tpl_params = $param['vars']; $explode = explode(chr(10), $param[1]->evaluate()); foreach ($explode as $val) { $bits = explode('=', $val, 2); if (count($bits) == 2) { $tpl_params[ltrim($bits[0])] = $bits[1]; } } $td = isset($param[3]) ? $param[2]->evaluate() : ''; if ($td == '') { $td = 'templates'; } $ex = isset($param[2]) ? $param[1]->evaluate() : ''; if ($ex == '') { $ex = '.tpl'; } $_value = do_template($param[0]->evaluate(), $tpl_params, NULL, false, NULL, $ex, $td); $value = $_value->evaluate(); } break; case 'WHILE': if (isset($param[1])) { $_p = $param[0]->evaluate(); if ($_p == '1' || $_p == '1') { $value = ''; $value .= $param[1]->evaluate(); $value .= ecv($lang, $escaped, $type, $name, $param); } } break; case 'IF': if (isset($param[1])) { $_p = $param[0]->evaluate(); if ($_p == '1' || $_p == '1') { $value = $param[1]->evaluate(); } } break; case 'LOOP': if (isset($param[0])) { if (!array_key_exists($param[0]->evaluate(), $param['vars'])) { require_code('site'); attach_message(do_lang_tempcode('MISSING_TEMPLATE_PARAMETER', $param[0]->evaluate(), '???'), 'warn'); return ''; } $array_key = $param[0]->evaluate(); if (is_numeric($array_key) || strpos($array_key, ',') !== false) { $array = explode(',', $array_key); } else { $array = array_key_exists($array_key, $param['vars']) ? $param['vars'][$array_key] : array(); if (!is_array($array)) { $array = array(); } } $value = ''; if (array_key_exists(1 + 1, $param)) { $columns = $param[1]->evaluate(); $row_starter = array_key_exists(2 + 1, $param) ? $param[2]->evaluate() : '<tr>'; $row_terminator = array_key_exists(3 + 1, $param) ? $param[3]->evaluate() : '</tr>'; $value .= $row_starter; // Sorting if (array_key_exists(4 + 1, $param)) { $sort_key = $param[4]->evaluate(); $rev = array_key_exists(5 + 1, $param) && $param[5]->evaluate() == 'DESC'; if ($sort_key != '') { global $M_SORT_KEY; $M_SORT_KEY = $sort_key; uasort($array, 'multi_sort'); } if ($rev) { $array = array_reverse($array); } } } $last = count($param) - 2; $col = 0; $first = true; foreach ($array as $go_key => $go) { if (!is_array($go)) { $go = array('_loop_key' => make_string_tempcode(is_integer($go_key) ? strval($go_key) : $go_key), '_loop_var' => make_string_tempcode($go)); } // In case it's not a list of maps, but just a list if (isset($param[2]) && $col % $columns == 0 && $col != 0) { $value .= $row_starter; } $ps = $go + $param['vars'] + array('_loop_key' => make_string_tempcode(is_integer($go_key) ? strval($go_key) : $go_key), '_i' => strval($col), '_first' => $first, '_last' => $col == count($array) - 1); $bound = $param[$last]->bind($ps, ''); $value .= $bound->evaluate(); ++$col; if (isset($param[3]) && $col % $columns == 0) { $value .= $row_terminator; } $first = false; } if (isset($param[2]) && $col % $columns != 0) { $value .= $row_terminator; } } break; default: require_code('site'); attach_message(do_lang_tempcode('UNKNOWN_DIRECTIVE', escape_html($name)), 'warn'); } if ($escaped != array()) { apply_tempcode_escaping($escaped, $value); } return $value; } // By elimination, it's language $a = isset($param[0]) ? is_object($param[0]) ? $param[0]->evaluate() : $param[0] : NULL; $b = isset($param[1]) ? is_object($param[1]) ? $param[1]->evaluate() : $param[1] : NULL; $c = isset($param[2]) ? array_splice($param, 2) : NULL; if ($c !== NULL) { foreach ($c as $i => $cc) { if (is_object($cc)) { $c[$i] = $cc->evaluate(); } } } static $dle = false; if (!$dle) { $dle = function_exists('do_lang'); } $ret = $dle ? do_lang($name, $a, $b, $c, $lang, false) : escape_html($name . ':' . (!is_null($a) ? $a : '') . ',' . (!is_null($b) ? $b : '')); if ($ret === NULL) { if ($type != TC_PARAMETER) { require_code('site'); attach_message(do_lang_tempcode('MISSING_LANG_ENTRY', escape_html($name)), 'warn'); } $value = ''; if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($value); } return $value; } if ($escaped != array() && $escaped != array(ENTITY_ESCAPED)) { apply_tempcode_escaping(array_diff($escaped, array(ENTITY_ESCAPED)), $ret); } // Escape but without ENTITY_ESCAPED because we don't do that on lang strings return $ret; }
/** * This function is a very important one when coding. It allows you to include a source code file (from root/sources/ or root/sources_custom/) through the proper channels. * You should remember this function, and not substitute anything else for it, as that will likely make your code unstable. * It is key to source code modularity in ocPortal. * * @param string The codename for the source module to load (or a full relative path, ending with .php; if custom checking is needed, this must be the custom version) * @param boolean Whether to cleanly fail when a source file is missing */ function require_code($codename, $light_exit = false) { $hphp = defined('HIPHOP_PHP'); if ($hphp) { if ($codename == 'tempcode') { $codename = 'tempcode__runtime'; } if ($codename == 'tempcode_compiler') { $codename = 'tempcode_compiler__runtime'; } } global $_REQUIRED_CODE, $FILE_BASE, $SITE_INFO; if (isset($_REQUIRED_CODE[$codename])) { return; } $_REQUIRED_CODE[$codename] = 1; $shorthand = strpos($codename, '.php') === false; if (!$shorthand) { $non_custom_codename = str_replace('_custom/', '/', $codename); $_REQUIRED_CODE[$non_custom_codename] = 1; } $codename = filter_naughty($codename); static $mue = NULL; if ($mue === NULL) { $mue = function_exists('memory_get_usage'); } if ($mue && isset($_GET['keep_show_loading']) && $_GET['keep_show_loading'] == '1') { if (function_exists('memory_get_usage')) { $before = memory_get_usage(); } } $worked = false; $path_a = $FILE_BASE . '/' . ($shorthand ? 'sources_custom/' . $codename . '.php' : $codename); $path_b = $FILE_BASE . '/' . ($shorthand ? 'sources/' . $codename . '.php' : $non_custom_codename); $has_original = NULL; if (isset($GLOBALS['MEM_CACHE'])) { global $CODE_OVERRIDES; if (!isset($CODE_OVERRIDES)) { $CODE_OVERRIDES = persistant_cache_get('CODE_OVERRIDES'); if ($CODE_OVERRIDES === NULL) { $CODE_OVERRIDES = array(); } } if (isset($CODE_OVERRIDES[$codename])) { $has_override = $CODE_OVERRIDES[$codename]; $has_original = $CODE_OVERRIDES['!' . $codename]; } else { $has_override = is_file($path_a); $has_original = is_file($path_b); $CODE_OVERRIDES[$codename] = $has_override; $CODE_OVERRIDES['!' . $codename] = $has_original; persistant_cache_set('CODE_OVERRIDES', $CODE_OVERRIDES, true); } } else { $has_override = is_file($path_a); } if (isset($SITE_INFO['safe_mode']) && $SITE_INFO['safe_mode'] == '1') { $has_override = false; } if ($has_override && (!function_exists('in_safe_mode') || !in_safe_mode() || !is_file($path_b))) { $done_init = false; $init_func = 'init__' . str_replace('/', '__', str_replace('.php', '', $codename)); if (!isset($has_original)) { $has_original = is_file($path_b); } if ($path_a != $path_b && $has_original) { $orig = str_replace(array('?' . '>', '<?php'), array('', ''), file_get_contents($path_b)); $a = file_get_contents($path_a); if ((strpos($codename, '.php') === false || strpos($a, 'class Mx_') === false) && (function_exists('quercus_version') || !$hphp)) { $functions_before = get_defined_functions(); $classes_before = get_declared_classes(); include $path_a; // Include our overrride $functions_after = get_defined_functions(); $classes_after = get_declared_classes(); $functions_diff = array_diff($functions_after['user'], $functions_before['user']); // Our override defined these functions $classes_diff = array_diff($classes_after, $classes_before); $pure = true; // We will set this to false if it does not have all functions the main one has. If it does have all functions we know we should not run the original init, as it will almost certainly just have been the same code copy&pasted through. $overlaps = false; foreach ($functions_diff as $function) { if (strpos($orig, 'function ' . $function . '(') !== false) { $orig = str_replace('function ' . $function . '(', 'function non_overrided__' . $function . '(', $orig); $overlaps = true; } else { $pure = false; } } foreach ($classes_diff as $class) { if (substr(strtolower($class), 0, 6) == 'module') { $class = ucfirst($class); } if (substr(strtolower($class), 0, 4) == 'hook') { $class = ucfirst($class); } if (strpos($orig, 'class ' . $class) !== false) { $orig = str_replace('class ' . $class, 'class non_overrided__' . $class, $orig); $overlaps = true; } else { $pure = false; } } // See if we can get away with loading init function early. If we can we do a special version of it that supports fancy code modification. Our override isn't allowed to call the non-overridden init function as it won't have been loaded up by PHP in time. Instead though we will call it ourselves if it still exists (hasn't been removed by our own init function) because it likely serves a different purpose to our code-modification init function and copy&paste coding is bad. $doing_code_modifier_init = function_exists($init_func); if ($doing_code_modifier_init) { $test = call_user_func_array($init_func, array($orig)); if (is_string($test)) { $orig = $test; } $done_init = true; } if (!$doing_code_modifier_init && !$overlaps) { include $path_b; } else { eval($orig); // Load up modified original } if (!$pure && $doing_code_modifier_init && function_exists('non_overrided__init__' . str_replace('/', '__', str_replace('.php', '', $codename)))) { call_user_func('non_overrided__init__' . str_replace('/', '__', str_replace('.php', '', $codename))); } } else { // Note we load the original and then the override. This is so function_exists can be used in the overrides (as we can't support the re-definition) OR in the case of Mx_ class derivation, so that the base class is loaded first. if (isset($_GET['keep_show_parse_errors']) && (function_exists('quercus_version') || !$hphp)) { @ini_set('display_errors', '0'); $orig = str_replace('?' . '>', '', str_replace('<?php', '', file_get_contents($path_b))); if (eval($orig) === false) { if (!function_exists('fatal_exit') || $codename == 'failure') { critical_error('PASSON', @strval($php_errormsg) . ' [sources/' . $codename . '.php]'); } fatal_exit(@strval($php_errormsg) . ' [sources/' . $codename . '.php]'); } } else { include $path_b; } if (isset($_GET['keep_show_parse_errors']) && (function_exists('quercus_version') || !$hphp)) { @ini_set('display_errors', '0'); $orig = str_replace('?' . '>', '', str_replace('<?php', '', file_get_contents($path_a))); if (eval($orig) === false) { if (!function_exists('fatal_exit') || $codename == 'failure') { critical_error('PASSON', @strval($php_errormsg) . ' [sources_custom/' . $codename . '.php]'); } fatal_exit(@strval($php_errormsg) . ' [sources_custom/' . $codename . '.php]'); } } else { include $path_a; } } } else { if (isset($_GET['keep_show_parse_errors']) && (function_exists('quercus_version') || !$hphp)) { @ini_set('display_errors', '0'); $orig = str_replace('?' . '>', '', str_replace('<?php', '', file_get_contents($path_a))); if (eval($orig) === false) { if (!function_exists('fatal_exit') || $codename == 'failure') { critical_error('PASSON', @strval($php_errormsg) . ' [sources_custom/' . $codename . '.php]'); } fatal_exit(@strval($php_errormsg) . ' [sources_custom/' . $codename . '.php]'); } } else { include $path_a; } } if ($mue && isset($_GET['keep_show_loading']) && $_GET['keep_show_loading'] == '1') { if (function_exists('memory_get_usage')) { print '<!-- require_code: ' . htmlentities($codename) . ' (' . number_format(memory_get_usage() - $before) . ' bytes used, now at ' . number_format(memory_get_usage()) . ') -->' . "\n"; flush(); } } if (!$done_init) { if (function_exists($init_func)) { call_user_func($init_func); } } $worked = true; } else { if (isset($_GET['keep_show_parse_errors']) && (function_exists('quercus_version') || !$hphp)) { $contents = @file_get_contents($path_b); if ($contents !== false) { @ini_set('display_errors', '0'); $orig = str_replace(array('?' . '>', '<' . '?php'), array('', ''), $contents); if (eval($orig) === false) { if (!function_exists('fatal_exit') || $codename == 'failure') { critical_error('PASSON', @strval($php_errormsg) . ' [sources/' . $codename . '.php]'); } fatal_exit(@strval($php_errormsg) . ' [sources/' . $codename . '.php]'); } $worked = true; } } else { $php_errormsg = ''; @(include $path_b); if ($php_errormsg == '') { $worked = true; } } if ($worked) { if ($mue && isset($_GET['keep_show_loading']) && $_GET['keep_show_loading'] == '1') { if (function_exists('memory_get_usage')) { print '<!-- require_code: ' . htmlentities($codename) . ' (' . number_format(memory_get_usage() - $before) . ' bytes used, now at ' . number_format(memory_get_usage()) . ') -->' . "\n"; flush(); } } $init_func = 'init__' . str_replace(array('/', '.php'), array('__', ''), $codename); if (function_exists($init_func)) { call_user_func($init_func); } } } if ($worked) { return; } if ($light_exit) { warn_exit(do_lang_tempcode('MISSING_SOURCE_FILE', escape_html($codename), escape_html($path_b))); } if (!function_exists('do_lang')) { if ($codename == 'critical_errors') { exit('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . chr(10) . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN"><head><title>Critical startup error</title></head><body><h1>ocPortal startup error</h1><p>The ocPortal critical error message file, sources/critical_errors.php, could not be located. This is almost always due to an incomplete upload of the ocPortal system, so please check all files are uploaded correctly.</p><p>Once all ocPortal files are in place, ocPortal must actually be installed by running the installer. You must be seeing this message either because your system has become corrupt since installation, or because you have uploaded some but not all files from our manual installer package: the quick installer is easier, so you might consider using that instead.</p><p>ocProducts maintains full documentation for all procedures and tools, especially those for installation. These may be found on the <a href="http://ocportal.com">ocPortal website</a>. If you are unable to easily solve this problem, we may be contacted from our website and can help resolve it for you.</p><hr /><p style="font-size: 0.8em">ocPortal is a website engine created by ocProducts.</p></body></html>'); require $GLOBALS['FILE_BASE'] . '/sources/global.php'; } critical_error('MISSING_SOURCE', $codename); } fatal_exit(do_lang_tempcode('MISSING_SOURCE_FILE', escape_html($codename), escape_html($path_b))); }
/** * Get the parsed contents of a comcode page. * * @param PATH The relative (to ocPortal's base directory) path to the page (e.g. pages/comcode/EN/start.txt) * @param ID_TEXT The zone the page is being loaded from * @param ID_TEXT The codename of the page * @param ?PATH The file base to load from (NULL: standard) * @param boolean Whether the page is being included from another * @return tempcode The page */ function load_comcode_page($string, $zone, $codename, $file_base = NULL, $being_included = false) { if ($file_base === NULL) { $file_base = get_file_base(); } if (!$being_included) { $GLOBALS['TITLE_CALLED'] = true; } $is_panel = substr($codename, 0, 6) == 'panel_' || strpos($codename, 'panel_') !== false && get_param_integer('keep_theme_test', 0) == 1; if ($zone == '' && $codename == '404') { global $EXTRA_HEAD; $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML $GLOBALS['HTTP_STATUS_CODE'] = '404'; if (!headers_sent()) { if (!browser_matches('ie') && strpos(ocp_srv('SERVER_SOFTWARE'), 'IIS') === false) { header('HTTP/1.0 404 Not Found'); } } } if (($is_panel || $codename[0] == '_') && get_page_name() == $codename) { global $EXTRA_HEAD; $EXTRA_HEAD->attach('<meta name="robots" content="noindex" />'); // XHTMLXHTML } if ($zone == 'adminzone') { require_code('site_adminzone'); adminzone_special_cases($codename); } if ($codename == 'sitemap') { $GLOBALS['FEED_URL'] = find_script('backend') . '?mode=comcode_pages&filter=' . $zone; } global $PAGE_STRING, $COMCODE_PARSE_TITLE, $LAST_COMCODE_PARSED_TITLE; $COMCODE_PARSE_TITLE = NULL; if ($PAGE_STRING === NULL && !$being_included && !$is_panel) { $PAGE_STRING = $string; } $new_comcode_page_row = array('the_zone' => $zone, 'the_page' => $codename, 'p_parent_page' => '', 'p_validated' => 1, 'p_edit_date' => NULL, 'p_add_date' => NULL, 'p_submitter' => NULL, 'p_show_as_edit' => 0); if ((get_option('is_on_comcode_page_cache') == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1 || get_param_integer('cache_blocks', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache_blocks', NULL) !== 0 && get_param_integer('cache', NULL) !== 0 && get_param_integer('keep_print', 0) == 0) { global $SITE_INFO; $support_smart_decaching = !isset($SITE_INFO['disable_smart_decaching']) || $SITE_INFO['disable_smart_decaching'] == '0'; if (is_browser_decacheing()) { $comcode_page = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index', 'cc_page_title'), array('the_page' => $codename, 'the_zone' => $zone, 'the_theme' => $GLOBALS['FORUM_DRIVER']->get_theme()), '', 1, 0, false, array()); if (array_key_exists(0, $comcode_page)) { if ($comcode_page[0]['string_index'] !== NULL) { delete_lang($comcode_page[0]['string_index']); } $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_page' => $codename, 'the_zone' => $zone)); } } $theme = $GLOBALS['FORUM_DRIVER']->get_theme(); if ($GLOBALS['MEM_CACHE'] !== NULL) { if ($support_smart_decaching) { $mtime = filemtime($file_base . '/' . $string); if ($mtime > time()) { $mtime = time(); } // Timezone error, we have to assume that cache is ok rather than letting us get in a loop decacheing the file. It'll get fixed automatically in a few hours when the hours of the timezone difference passes. $pcache = persistant_cache_get(array('COMCODE_PAGE', $codename, $zone, $theme, user_lang()), $mtime); } else { $pcache = persistant_cache_get(array('COMCODE_PAGE', $codename, $zone, $theme, user_lang())); } } else { $pcache = NULL; } if ($pcache === NULL) { $comcode_page = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages a JOIN ' . $GLOBALS['SITE_DB']->get_table_prefix() . 'comcode_pages b ON (a.the_page=b.the_page AND a.the_zone=b.the_zone)', array('*'), array('a.the_page' => $codename, 'a.the_zone' => $zone, 'the_theme' => $theme), '', 1, NULL, false, array('string_index', 'cc_page_title')); if (array_key_exists(0, $comcode_page)) { if ($support_smart_decaching) { $mtime = filemtime($file_base . '/' . $string); if ($mtime > time()) { $mtime = time(); } // Timezone error, we have to assume that cache is ok rather than letting us get in a loop decacheing the file. It'll get fixed automatically in a few hours when the hours of the timezone difference passes. } if (!$support_smart_decaching || ($comcode_page[0]['p_edit_date'] !== NULL && $comcode_page[0]['p_edit_date'] >= $mtime || $comcode_page[0]['p_edit_date'] === NULL && $comcode_page[0]['p_add_date'] !== NULL && $comcode_page[0]['p_add_date'] >= $mtime)) { $comcode_page_row = $comcode_page[0]; $db_set = get_translated_tempcode($comcode_page[0]['string_index'], NULL, user_lang(), true, true, true); unset($GLOBALS['RECORDED_LANG_STRINGS_CONTENT'][$comcode_page[0]['string_index']]); } else { $mtime = filemtime($file_base . '/' . $string); if ($mtime > time()) { $mtime = time(); } // Timezone error, we have to assume that cache is ok rather than letting us get in a loop decacheing the file. It'll get fixed automatically in a few hours when the hours of the timezone difference passes. $GLOBALS['SITE_DB']->query_update('comcode_pages', array('p_edit_date' => $mtime), array('the_page' => $codename, 'the_zone' => $zone), '', 1); $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => $zone, 'the_page' => $codename)); delete_lang($comcode_page[0]['string_index']); $db_set = NULL; $comcode_page_row = NULL; } } else { $db_set = NULL; $comcode_page_row = NULL; } if ($db_set !== NULL) { $index = $comcode_page[0]['string_index']; $title_to_use = $comcode_page[0]['cc_page_title']; if ($title_to_use !== NULL) { $title_to_use = get_translated_text($title_to_use, NULL, NULL, true); if ($title_to_use === NULL) { $title_to_use = $codename; } } $html = $db_set; } else { $comcode_page = $GLOBALS['SITE_DB']->query_select('comcode_pages', array('*'), array('the_page' => $codename, 'the_zone' => $zone), '', 1); if (array_key_exists(0, $comcode_page)) { $comcode_page_row = $comcode_page[0]; } require_code('site2'); $new_comcode_page_row['p_add_date'] = filectime($file_base . '/' . $string); list($html, $title_to_use, $comcode_page_row) = _load_comcode_page_not_cached($string, $zone, $codename, $file_base, $comcode_page_row, $new_comcode_page_row, $being_included); } persistant_cache_set(array('COMCODE_PAGE', $codename, $zone, $theme, user_lang()), array($html, $title_to_use, $comcode_page_row)); } else { list($html, $title_to_use, $comcode_page_row) = $pcache; } } else { require_code('site2'); $new_comcode_page_row['p_add_date'] = filectime($file_base . '/' . $string); list($html, $comcode_page_row, $title_to_use) = _load_comcode_page_cache_off($string, $zone, $codename, $file_base, $new_comcode_page_row, $being_included); } $filtered_title_to_use = mixed(); if (!$is_panel && !$being_included) { if ($title_to_use !== NULL && $title_to_use != '') { get_page_title($title_to_use, false); // Little hack - this gets shift encoded, but shift encoding can't survive a tempcode cache. This will force it to reshift. It'll also make sure DISPLAYED_TITLE gets set. $filtered_title_to_use = @html_entity_decode(strip_tags($title_to_use), ENT_QUOTES, get_charset()); } seo_meta_load_for('comcode_page', $zone . ':' . $codename, $filtered_title_to_use); } $LAST_COMCODE_PARSED_TITLE = $title_to_use; if ($html->is_definitely_empty() && $being_included) { return $html; } if (has_actual_page_access(get_member(), 'cms_comcode_pages', NULL, NULL, $comcode_page_row['p_submitter'] == get_member() && !is_guest() ? 'edit_own_highrange_content' : 'edit_highrange_content')) { $redirect = get_self_url(true, false, array('redirect' => NULL, 'redirected' => NULL)); if (($codename == 'panel_left' || $codename == 'panel_right') && has_js() && has_actual_page_access(get_member(), 'admin_zones')) { $edit_url = build_url(array('page' => 'admin_zones', 'type' => '_editor', 'id' => get_zone_name(), 'redirect' => $redirect, 'wide' => 1), get_module_zone('admin_zones')); } else { $edit_url = build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'page_link' => $zone . ':' . $codename, 'redirect' => $redirect), get_module_zone('cms_comcode_pages')); } $add_child_url = get_option('is_on_comcode_page_children') == '1' ? build_url(array('page' => 'cms_comcode_pages', 'type' => '_ed', 'parent_page' => $codename, 'page_link' => $zone . ':'), get_module_zone('cms_comcode_pages')) : new ocp_tempcode(); } else { $edit_url = new ocp_tempcode(); $add_child_url = new ocp_tempcode(); } $warning_details = new ocp_tempcode(); if ($comcode_page_row['p_validated'] !== NULL && $comcode_page_row['p_validated'] == 0) { require_code('site2'); $warning_details = get_page_warning_details($zone, $codename, $edit_url); } if (!$is_panel && $title_to_use !== NULL && !$being_included) { global $PT_PAIR_CACHE_CP; $PT_PAIR_CACHE_CP[$codename]['cc_page_title'] = $title_to_use === NULL ? do_lang_tempcode('NA_EM') : make_string_tempcode($title_to_use); $PT_PAIR_CACHE_CP[$codename]['p_parent_page'] = $comcode_page_row['p_parent_page']; $comcode_breadcrumbs = comcode_breadcrumbs($codename, $zone, get_param('root', ''), $comcode_page_row['p_parent_page'] == '' || !has_specific_permission(get_member(), 'open_virtual_roots')); breadcrumb_add_segment($comcode_breadcrumbs); $GLOBALS['META_DATA'] += array('created' => date('Y-m-d', $comcode_page_row['p_add_date']), 'creator' => is_guest($comcode_page_row['p_submitter']) ? '' : $GLOBALS['FORUM_DRIVER']->get_username($comcode_page_row['p_submitter']), 'publisher' => '', 'modified' => $comcode_page_row['p_edit_date'] === NULL ? '' : date('Y-m-d', $comcode_page_row['p_edit_date']), 'type' => 'Comcode page', 'title' => $title_to_use, 'identifier' => $zone . ':' . $codename, 'description' => ''); } if ($html->is_definitely_empty() && $is_panel) { return $html; } global $SCREEN_TEMPLATE_CALLED; $st = $SCREEN_TEMPLATE_CALLED; $ret = do_template('COMCODE_PAGE_SCREEN', array('_GUID' => '0fc4fe4f27e54aaaa2b7e4848c02bacb', 'IS_PANEL' => $is_panel, 'BEING_INCLUDED' => $being_included, 'SUBMITTER' => strval($comcode_page_row['p_submitter']), 'TAGS' => get_loaded_tags('comcode_pages'), 'WARNING_DETAILS' => $warning_details, 'EDIT_DATE_RAW' => $comcode_page_row['p_edit_date'] === NULL ? '' : strval($comcode_page_row['p_edit_date']), 'SHOW_AS_EDIT' => $comcode_page_row['p_show_as_edit'] == 1, 'CONTENT' => $html, 'EDIT_URL' => $edit_url, 'ADD_CHILD_URL' => $add_child_url, 'NAME' => $codename)); if ($is_panel || $being_included) { $SCREEN_TEMPLATE_CALLED = $st; } return $ret; }
/** * Find what sessions are expired and delete them, and recover an existing one for $member if there is one. * * @param ?MEMBER User to get a current session for (NULL: do not try, which guarantees a return result of NULL also) * @return ?AUTO_LINK The session id we rebound to (NULL: did not rebind) */ function delete_expired_sessions_or_recover($member = NULL) { $new_session = NULL; $ip = get_ip_address(3); // Delete expired sessions $GLOBALS['SITE_DB']->query('DELETE FROM ' . get_table_prefix() . 'sessions WHERE last_activity<' . strval(time() - 60 * 60 * max(1, intval(get_option('session_expiry_time'))))); $new_session = NULL; $dirty_session_cache = false; global $SESSION_CACHE; foreach ($SESSION_CACHE as $_session => $row) { if (!array_key_exists('the_user', $row)) { continue; } // Workaround to HipHop PHP weird bug // Delete expiry from cache if ($row['last_activity'] < time() - 60 * 60 * max(1, intval(get_option('session_expiry_time')))) { $dirty_session_cache = true; unset($SESSION_CACHE[$_session]); continue; } // Get back to prior session if there was one if ($member !== NULL) { if ($row['the_user'] == $member && (get_option('ip_strict_for_sessions') == '0' && $member != $GLOBALS['FORUM_DRIVER']->get_guest_id() || $row['ip'] == $ip) && $row['last_activity'] > time() - 60 * 60 * max(1, intval(get_option('session_expiry_time')))) { $new_session = $_session; } } } if ($dirty_session_cache) { if (get_value('session_prudence') !== '1') { persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } return $new_session; }
/** * Get the block object for a given block codename. * * @param ID_TEXT The block name * @param ?array The block parameter map (NULL: no parameters) * @return mixed Either the block object, or the string output of a miniblock */ function do_block_hunt_file($codename, $map = NULL) { global $BLOCKS_AT_CACHE; $codename = filter_naughty_harsh($codename); $file_base = get_file_base(); global $_REQUIRED_CODE; if (isset($BLOCKS_AT_CACHE[$codename]) && !in_safe_mode() && $BLOCKS_AT_CACHE[$codename] == 'sources_custom/blocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources_custom/blocks/' . $codename . '.php')) { if (!isset($_REQUIRED_CODE['blocks/' . $codename])) { require_once $file_base . '/sources_custom/blocks/' . $codename . '.php'; } $_REQUIRED_CODE['blocks/' . $codename] = 1; if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources_custom/blocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } elseif (isset($BLOCKS_AT_CACHE[$codename]) && $BLOCKS_AT_CACHE[$codename] == 'sources/blocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources/blocks/' . $codename . '.php')) { if (!isset($_REQUIRED_CODE['blocks/' . $codename])) { require_once $file_base . '/sources/blocks/' . $codename . '.php'; } $_REQUIRED_CODE['blocks/' . $codename] = 1; if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources/blocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } else { if (isset($BLOCKS_AT_CACHE[$codename]) && !in_safe_mode() && $BLOCKS_AT_CACHE[$codename] == 'sources_custom/miniblocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources_custom/miniblocks/' . $codename . '.php')) { require_code('developer_tools'); destrictify(); ob_start(); if (defined('HIPHOP_PHP')) { require 'sources_custom/miniblocks/' . $codename . '.php'; } else { require $file_base . '/sources_custom/miniblocks/' . $codename . '.php'; } $object = ob_get_contents(); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($object); } ob_end_clean(); restrictify(); if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources_custom/miniblocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } elseif (isset($BLOCKS_AT_CACHE[$codename]) && $BLOCKS_AT_CACHE[$codename] == 'sources/miniblocks' || !isset($BLOCKS_AT_CACHE[$codename]) && is_file($file_base . '/sources/miniblocks/' . $codename . '.php')) { require_code('developer_tools'); destrictify(); ob_start(); if (defined('HIPHOP_PHP')) { require 'sources/miniblocks/' . $codename . '.php'; } else { require $file_base . '/sources/miniblocks/' . $codename . '.php'; } $object = ob_get_contents(); if ($GLOBALS['XSS_DETECT']) { ocp_mark_as_escaped($object); } ob_end_clean(); restrictify(); if (!isset($BLOCKS_AT_CACHE[$codename])) { $BLOCKS_AT_CACHE[$codename] = 'sources/miniblocks'; if (function_exists('persistant_cache_set')) { persistant_cache_set('BLOCKS_AT', $BLOCKS_AT_CACHE, true); } } } elseif (is_null($map) || !array_key_exists('failsafe', $map) || $map['failsafe'] != '1') { $temp = paragraph(do_lang_tempcode('MISSING_BLOCK_FILE', escape_html($codename)), '90dfdlksds8d7dyddssdds', 'error_marker'); return $temp->evaluate(); } else { $object = ''; } return $object; } $_object = object_factory('Block_' . $codename); return $_object; }
/** * Build a menu branch map from a database row. * * @param array The database row * @param array List of all the database rows for this menu * @return array The menu branch map */ function build_stored_menu_branch($thisitem, $items) { $i = 0; $branch = array('type' => 'link', 'caption' => $thisitem['cap'], 'special' => NULL, 'children' => array(), 'only_on_page' => NULL, 'modifiers' => array(), 'caption_long' => array_key_exists('i_caption_long', $thisitem) ? $thisitem['i_caption_long'] : '', 'img' => array_key_exists('i_theme_img_code', $thisitem) ? $thisitem['i_theme_img_code'] : ''); // HACKHACK: Cleaner way preferable, but needs new DB field! if (array_key_exists('i_caption_long', $thisitem) && substr($thisitem['i_caption_long'], 0, 3) == '!!!') { require_code('menus_sitemap'); $extra = build_sitetree_menu(explode(':', substr($thisitem['i_caption_long'], 3))); foreach ($extra as $e) { if (strpos($thisitem['i_url'], ':root') !== false) { $e['i_url'] .= substr($thisitem['i_url'], strpos($thisitem['i_url'], ':root')); } elseif (strpos($thisitem['i_url'], ':keep_') !== false) { $e['i_url'] .= substr($thisitem['i_url'], strpos($thisitem['i_url'], ':keep_')); } if (is_null($e['i_parent'])) { $e['i_parent'] = $thisitem['id']; } $items[] = $e; } } // HACKHACK: Cleaner way preferable, but needs new DB field! if (array_key_exists('i_caption_long', $thisitem) && substr($thisitem['i_caption_long'], 0, 2) == '@@') { $bits = explode('@@', $thisitem['i_caption_long']); $extra = array(); foreach ($bits as $bit) { if ($bit == '') { continue; } $_extra = persistant_cache_get(array('MENU', $bit)); if (is_null($_extra)) { $_extra = $GLOBALS['SITE_DB']->query_select('menu_items', array('id', 'i_caption_long AS _i_caption_long', 'i_new_window', 'i_expanded', 'i_parent', 'i_caption AS _cap', 'i_url', 'i_check_permissions', 'i_page_only', 'i_theme_img_code'), array('i_menu' => $bit), 'ORDER BY i_order'); foreach ($_extra as $i => $_e) { $_extra[$i]['cap'] = get_translated_text($_e['_cap']); $_extra[$i]['i_caption_long'] = get_translated_text($_e['_i_caption_long']); } persistant_cache_set(array('MENU', $bit), $_extra); } $extra = array_merge($extra, $_extra); } foreach ($extra as $e) { if (strpos($thisitem['i_url'], ':root') !== false) { $e['i_url'] .= substr($thisitem['i_url'], strpos($thisitem['i_url'], ':root')); } elseif (strpos($thisitem['i_url'], ':keep_') !== false) { $e['i_url'] .= substr($thisitem['i_url'], strpos($thisitem['i_url'], ':keep_')); } if (is_null($e['i_parent'])) { $e['i_parent'] = $thisitem['id']; } $items[] = $e; } } foreach ($items as $item) { if ($item['i_parent'] == $thisitem['id']) { $branch['type'] = 'drawer'; break; } } if ($branch['caption'] == '') { $branch['type'] = 'blank'; } else { if ($branch['type'] == 'drawer') { if ($thisitem['i_expanded'] == 1) { $branch['modifiers']['expanded'] = 1; } for ($i = 0; $i < count($items); $i++) { if (array_key_exists($i, $items)) { $item = $items[$i]; // Search for children if ($item['i_parent'] == $thisitem['id'] && $item['id'] != $thisitem['id']) { $new_kids_on_the_block = build_stored_menu_branch($item, $items); $branch['children'][] = $new_kids_on_the_block; } } } } $branch['only_on_page'] = $thisitem['i_page_only']; if ($thisitem['i_new_window'] == 1) { $branch['modifiers']['new_window'] = 1; } if ($thisitem['i_check_permissions'] == 1) { $branch['modifiers']['check_perms'] = 1; } if (array_key_exists('i_popup', $thisitem) && $thisitem['i_popup'] == 1) { $branch['modifiers']['popup'] = 1; $branch['width'] = $thisitem['i_width']; $branch['height'] = $thisitem['i_height']; } $branch['special'] = $thisitem['i_url']; } return $branch; }
/** * Find if a member's has access to a specified page, in a specific zone. Note that page access does not imply zone access; you have access a page, but not the zone, so still couldn't see it. * * @param MEMBER The member being checked whether to have the access * @param ID_TEXT The ID code for the page being checked * @param ID_TEXT The ID code for the zone being checked * @param boolean Whether we want to check we have access to the CURRENT page, using any match tag permissions * @return boolean Whether the member has page access */ function has_page_access($member, $page, $zone, $at_now = false) { if (running_script('upgrader')) { return true; } global $PAGE_ACCESS_CACHE; if (!isset($PAGE_ACCESS_CACHE[$member]) && function_exists('persistant_cache_get') && is_guest($member)) { $PAGE_ACCESS_CACHE = persistant_cache_get('GUEST_PAGE_ACCESS'); } if (isset($PAGE_ACCESS_CACHE[$member]) && isset($PAGE_ACCESS_CACHE[$member][$zone . ':' . $page]) && (!$at_now || $PAGE_ACCESS_CACHE[$member][$zone . ':' . $page])) { handle_permission_check_logging($member, 'has_page_access', array($page, $zone), $PAGE_ACCESS_CACHE[$member][$zone . ':' . $page]); return $PAGE_ACCESS_CACHE[$member][$zone . ':' . $page]; } $groups = _get_where_clause_groups($member, false); if ($groups === NULL) { return true; } $pg_where = '(' . db_string_equal_to('zone_name', $zone) . ' AND ' . db_string_equal_to('page_name', $page) . ')'; $select = 'page_name,zone_name'; if ($at_now) { $pg_where .= ' OR page_name LIKE \'' . db_encode_like('\\_WILD:' . $page . ':%') . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like($zone . ':' . $page . ':%') . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like('\\_WILD:\\_WILD:%') . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like($zone . ':\\_WILD:%') . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like('\\_WILD:' . $page) . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like($zone . ':' . $page) . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like('\\_WILD:\\_WILD') . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like($zone . ':\\_WILD') . '\''; $pg_where .= ' OR page_name LIKE \'' . db_encode_like($zone) . '\''; } $select .= ',group_id'; $perhaps = array_key_exists($groups, $GLOBALS['TOTAL_PP_CACHE']) && !$at_now ? $GLOBALS['TOTAL_PP_CACHE'][$groups] : $GLOBALS['SITE_DB']->query('SELECT ' . $select . ' FROM ' . get_table_prefix() . 'group_page_access WHERE (' . $pg_where . ') AND (' . $groups . ')'); $groups2 = filter_group_permissivity($GLOBALS['FORUM_DRIVER']->get_members_groups($member, false)); $found_match_key_one = false; $denied_groups = array(); foreach ($groups2 as $group) { foreach ($perhaps as $praps) { if (strpos($praps['page_name'], ':') !== false) { $found_match_key_one = true; } if ($praps['group_id'] == $group && ($praps['zone_name'] == $zone || $praps['zone_name'] == '/')) { if ($praps['page_name'] == $page || $at_now && $praps['zone_name'] == '/' && match_key_match($praps['page_name'], true)) { $denied_groups[$group] = 1; } } } } if (!$found_match_key_one) { $at_now = false; } // We found it makes no difference. Let our caching work better. if (count($denied_groups) == count($groups2)) { $test = $GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT member_id FROM ' . get_table_prefix() . 'member_page_access WHERE (' . $pg_where . ') AND (member_id=' . strval((int) $member) . ' AND active_until>' . strval(time()) . ')'); if (!is_null($test)) { $result = true; handle_permission_check_logging($member, 'has_page_access', array($page, $zone), $result); if (!$at_now) { $PAGE_ACCESS_CACHE[$member][$zone . ':' . $page] = $result; } if (function_exists('persistant_cache_set') && is_guest($member)) { persistant_cache_set('GUEST_PAGE_ACCESS', $PAGE_ACCESS_CACHE); } return $result; } } $result = count($denied_groups) != count($groups2); // Has to be explicitly denied to all the usergroups they're in handle_permission_check_logging($member, 'has_page_access', array($page, $zone), $result); if (!$at_now) { $PAGE_ACCESS_CACHE[$member][$zone . ':' . $page] = $result; } if (function_exists('persistant_cache_set') && is_guest($member)) { persistant_cache_set('GUEST_PAGE_ACCESS', $PAGE_ACCESS_CACHE); } return $result; }
/** * Check to see if an IP address is banned. * * @param string The IP address to check for banning (potentially encoded with *'s) * @return boolean Whether the IP address is banned */ function ip_banned($ip) { if (!addon_installed('securitylogging')) { return false; } $ip4 = strpos($ip, '.') !== false; if ($ip4) { $ip_parts = explode('.', $ip); } else { $ip_parts = explode(':', $ip); } global $SITE_INFO; if (isset($SITE_INFO['known_suexec']) && $SITE_INFO['known_suexec'] == '1' || is_writable_wrap(get_file_base() . '/.htaccess')) { $bans = array(); $ban_count = preg_match_all('#\\ndeny from (.*)#', file_get_contents(get_file_base() . '/.htaccess'), $bans); $ip_bans = array(); for ($i = 0; $i < $ban_count; $i++) { $ip_bans[] = array('ip' => $bans[1][$i]); } } else { $ip_bans = persistant_cache_get('IP_BANS'); if (!is_array($ip_bans)) { $ip_bans = $GLOBALS['SITE_DB']->query('SELECT ip FROM ' . get_table_prefix() . 'usersubmitban_ip', NULL, NULL, true); if (!is_null($ip_bans)) { persistant_cache_set('IP_BANS', $ip_bans); } } if (is_null($ip_bans)) { critical_error('DATABASE_FAIL'); } } $self_ip = NULL; foreach ($ip_bans as $ban) { if ($ip4 && compare_ip_address_ip4($ban['ip'], $ip_parts) || !$ip4 && compare_ip_address_ip6($ban['ip'], $ip_parts)) { if (is_null($self_ip)) { $self_host = ocp_srv('HTTP_HOST'); if ($self_host == '' || preg_match('#^localhost[\\.\\:$]#', $self_host) != 0) { $self_ip = ''; } else { if (preg_match('#(\\s|,|^)gethostbyname(\\s|$|,)#i', @ini_get('disable_functions')) == 0) { $self_ip = gethostbyname($self_host); } else { $self_ip = ''; } if ($self_ip == '') { $self_ip = ocp_srv('SERVER_ADDR'); } } } if ($self_ip != '' && compare_ip_address($ban['ip'], $self_ip)) { continue; } if (compare_ip_address($ban['ip'], '127.0.0.1')) { continue; } if (compare_ip_address($ban['ip'], 'fe00:0000:0000:0000:0000:0000:0000:0000')) { continue; } return true; } } return false; }
/** * Set up a new session / Restore an existing one that was lost. * * @param MEMBER Logged in member * @param BINARY Whether the session should be considered confirmed * @param boolean Whether the session should be invisible * @return AUTO_LINK New session ID */ function create_session($member, $session_confirmed = 0, $invisible = false) { global $SESSION_CACHE; global $MEMBER_CACHED; $MEMBER_CACHED = $member; if ($invisible && get_option('is_on_invisibility') == '0') { $invisible = false; } $new_session = mixed(); $restored_session = delete_expired_sessions_or_recover($member); if (is_null($restored_session)) { // Generate random session $new_session = mt_rand(0, mt_getrandmax() - 1); // Store session $username = $GLOBALS['FORUM_DRIVER']->get_username($member); $new_session_row = array('the_session' => $new_session, 'last_activity' => time(), 'the_user' => $member, 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed, 'session_invisible' => $invisible ? 1 : 0, 'cache_username' => $username, 'the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => substr(get_page_name(), 0, 80), 'the_type' => substr(get_param('type', '', true), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80)); $GLOBALS['SITE_DB']->query_insert('sessions', $new_session_row, false, true); $SESSION_CACHE[$new_session] = $new_session_row; $big_change = true; } else { $new_session = $restored_session; $prior_session_row = $SESSION_CACHE[$new_session]; $new_session_row = array('the_title' => '', 'the_zone' => get_zone_name(), 'the_page' => get_page_name(), 'the_type' => substr(either_param('type', ''), 0, 80), 'the_id' => substr(either_param('id', ''), 0, 80), 'last_activity' => time(), 'ip' => get_ip_address(3), 'session_confirmed' => $session_confirmed); $big_change = $prior_session_row['last_activity'] < time() - 10 || $prior_session_row['session_confirmed'] != $session_confirmed || $prior_session_row['ip'] != $new_session_row['ip']; if ($big_change) { $GLOBALS['SITE_DB']->query_update('sessions', $new_session_row, array('the_session' => $new_session), '', 1, NULL, false, true); } $SESSION_CACHE[$new_session] = array_merge($SESSION_CACHE[$new_session], $new_session_row); } if ($big_change) { if (get_value('session_prudence') !== '1') { // With session prudence we don't store all these in persistant cache due to the size of it all. So only re-save if that's not on. persistant_cache_set('SESSION_CACHE', $SESSION_CACHE); } } set_session_id($new_session); // We won't set it true here, but something that really needs it to persist might come back and re-set it // New sessions = Login points if (!is_null($member) && addon_installed('points') && addon_installed('stats') && !is_guest($member)) { $points_per_daily_visit = intval(get_option('points_per_daily_visit', true)); if ($points_per_daily_visit != 0) { // See if this is the first visit today $test = $GLOBALS['SITE_DB']->query_value('stats', 'MAX(date_and_time)', array('the_user' => $member)); if (!is_null($test)) { require_code('temporal'); require_code('tempcode'); if (date('d/m/Y', tz_time($test, get_site_timezone())) != date('d/m/Y', tz_time(time(), get_site_timezone()))) { require_code('points'); $_before = point_info($member); if (array_key_exists('points_gained_given', $_before)) { $GLOBALS['FORUM_DRIVER']->set_custom_field($member, 'points_gained_given', strval(intval($_before['points_gained_given']) + $points_per_daily_visit)); } } } } } $GLOBALS['SESSION_CONFIRMED'] = $session_confirmed; return $new_session; }
/** * Load up a language file, compiling it (it's not cached yet). * * @param ID_TEXT The language file name * @param ?LANGUAGE_NAME The language (NULL: uses the current language) * @param ?string The language type (lang_custom, or custom) (NULL: normal priorities are used) * @set lang_custom custom * @param PATH Where we are cacheing too * @param boolean Whether to just return if there was a loading error * @return boolean Whether we FAILED to load */ function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false) { global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG; $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0; if ($desire_cache) { if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { global $DECACHED_COMCODE_LANG_STRINGS; // Cleanup language strings if (!$DECACHED_COMCODE_LANG_STRINGS) { $DECACHED_COMCODE_LANG_STRINGS = true; $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true); if (!is_null($comcode_lang_strings)) { $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!')); foreach ($comcode_lang_strings as $comcode_lang_string) { delete_lang($comcode_lang_string['string_index']); } } } } $load_target = array(); } else { $load_target =& $LANGUAGE[$lang]; } global $FILE_ARRAY; if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) { $lang_file = 'lang/' . $lang . '/' . $codename . '.ini'; $file = file_array_get($lang_file); _get_lang_file_map($file, $load_target, NULL, true); $bad = true; } else { $bad = true; $dirty = false; // Load originals $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini'; if (file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; } // Load overrides now if they are there if ($type != 'lang') { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; } if (!file_exists($lang_file)) { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po'; if (!file_exists($lang_file)) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po'; } } } if ($type != 'lang' && file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; $dirty = true; // Tainted from the official pack, so can't store server wide } // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded if ($bad && $lang != fallback_lang()) { require_lang($codename, fallback_lang(), $type, $ignore_errors); $REQUIRE_LANG_LOOP--; $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd'; if (file_exists($fallback_cache_path)) { require_code('files'); @copy($fallback_cache_path, $cache_path); fix_permissions($cache_path); } if (!array_key_exists($lang, $LANG_LOADED_LANG)) { $LANG_LOADED_LANG[$lang] = array(); } $LANG_LOADED_LANG[$lang][$codename] = 1; return $bad; } if ($bad) { if ($ignore_errors) { return true; } if ($codename != 'critical_error' || $lang != get_site_default_lang()) { fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang))); } else { critical_error('CRIT_LANG'); } } } if (is_null($GLOBALS['MEM_CACHE'])) { // Cache if ($desire_cache) { $file = @fopen($cache_path, 'wt'); // Will fail if cache dir missing .. e.g. in quick installer if ($file) { if (fwrite($file, serialize($load_target)) > 0) { // Success fclose($file); require_code('files'); fix_permissions($cache_path); } else { // Failure fclose($file); @unlink($cache_path); } } } } else { persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty); } if ($desire_cache) { $LANGUAGE[$lang] += $load_target; } return $bad; }
/** * Find the cache-on parameters for 'codename's cacheing style (prevents us needing to load up extra code to find it). * * @param ID_TEXT The codename of what will be checked for cacheing * @return ?array The cached result (NULL: no cached result) */ function find_cache_on($codename) { if (defined('HIPHOP_PHP')) { return NULL; } // See if we have it cached global $CACHE_ON; if ($CACHE_ON === NULL) { $CACHE_ON = persistant_cache_get('CACHE_ON'); if ($CACHE_ON === NULL) { $CACHE_ON = $GLOBALS['SITE_DB']->query_select('cache_on', array('*')); persistant_cache_set('CACHE_ON', $CACHE_ON); } } foreach ($CACHE_ON as $row) { if ($row['cached_for'] == $codename) { return $row; } } return NULL; }
/** * Get the human-readable form of a language id, or a language entry from a language INI file. * * @param ID_TEXT The language id * @param ?mixed The first token [string or tempcode] (replaces {1}) (NULL: none) * @param ?mixed The second token [string or tempcode] (replaces {2}) (NULL: none) * @param ?mixed The third token (replaces {3}). May be an array of [of string], to allow any number of additional args (NULL: none) * @param ?LANGUAGE_NAME The language to use (NULL: users language) * @param boolean Whether to cause ocPortal to exit if the lookup does not succeed * @return ?mixed The human-readable content (NULL: not found). String normally. Tempcode if tempcode parameters. */ function _do_lang($codename, $token1 = NULL, $token2 = NULL, $token3 = NULL, $lang = NULL, $require_result = true) { $pos = strpos($codename, ':'); if ($pos !== false) { require_lang(substr($codename, 0, $pos)); $codename = substr($codename, $pos + 1); } global $LANGUAGE, $USER_LANG_CACHED, $RECORD_LANG_STRINGS, $XSS_DETECT, $PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED; if ($RECORD_LANG_STRINGS) { global $RECORDED_LANG_STRINGS; $RECORDED_LANG_STRINGS[$codename] = 1; } if ($lang === NULL) { $lang = $USER_LANG_CACHED === NULL ? user_lang() : $USER_LANG_CACHED; } if (!isset($LANGUAGE[$lang][$codename]) && (!array_key_exists($lang, $LANGUAGE) || !array_key_exists($codename, $LANGUAGE[$lang]))) { global $PAGE_CACHE_LAZY_LOAD, $PAGE_CACHE_LANGS_REQUESTED, $LANG_REQUESTED_LANG; if ($PAGE_CACHE_LAZY_LOAD) { $PAGE_CACHE_LAZY_LOAD = false; // We can't be lazy any more, but we will keep growing our pool so hopefully CAN be lazy the next time foreach ($PAGE_CACHE_LANGS_REQUESTED as $request) { list($that_codename, $that_lang) = $request; unset($LANG_REQUESTED_LANG[$that_lang][$that_codename]); require_lang($that_codename, $that_lang, NULL, true); } $ret = _do_lang($codename, $token1, $token2, $token3, $lang, $require_result); if ($ret === NULL) { $PAGE_CACHE_LANG_LOADED[$lang][$codename] = NULL; if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED); } else { @rewind($PAGE_CACHE_FILE); @ftruncate($PAGE_CACHE_FILE, 0); @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED)); } } return $ret; } require_all_open_lang_files($lang); } if ($lang == 'xxx') { return 'xxx'; } // Helpful for testing language compliancy. We don't expect to see non x's if we're running this language if (!isset($LANGUAGE[$lang][$codename]) && (!array_key_exists($lang, $LANGUAGE) || !array_key_exists($codename, $LANGUAGE[$lang]))) { if ($lang != fallback_lang()) { $ret = do_lang($codename, $token1, $token2, $token3, fallback_lang(), $require_result); if ($codename == 'charset') { switch (strtolower($lang)) { case 'ar': case 'bg': case 'zh-CN': case 'zh-TW': case 'hr': case 'cs': case 'da': case 'nl': case 'fi': case 'fr': case 'de': case 'el': case 'hi': case 'it': case 'ja': case 'ko': case 'pl': case 'pt': case 'ro': case 'ru': case 'es': case 'sv': $ret = 'utf-8'; break; } } elseif (substr($codename, 0, 3) == 'FC_') { $ret = ocp_mb_substr(trim(do_lang(substr($codename, 3), $token1, $token2, $token3, $lang)), 0, 1); } elseif ($codename == 'locale') { $ret = strtolower($lang) . '_' . strtoupper($lang); } else { $ret2 = strtolower($codename) != $codename ? google_translate($ret, $lang) : $ret; if ($ret2 != $ret) { $ret = $ret2; } } if ($PAGE_CACHE_FILE !== NULL) { if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename]) && isset($PAGE_CACHE_LANG_LOADED[fallback_lang()][$codename])) { $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $ret; // Will have been cached into fallback_lang() from the nested do_lang call, we need to copy it into our cache bucket for this language if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED); } else { @rewind($PAGE_CACHE_FILE); @ftruncate($PAGE_CACHE_FILE, 0); @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED)); } } } return $ret; } else { if ($require_result) { global $USER_LANG_LOOP, $REQUIRE_LANG_LOOP; //print_r(debug_backtrace()); if ($USER_LANG_LOOP == 1) { critical_error('RELAY', 'Missing language code: ' . escape_html($codename) . '. This language code is required to produce error messages, and thus a critical error was prompted by the non-ability to show less-critical error messages. It is likely the source language files (lang/' . fallback_lang() . '/*.ini) for ocPortal on this website have been corrupted.'); } if ($REQUIRE_LANG_LOOP >= 2) { return ''; } // Probably failing to load global.ini, so just output with some text missing require_code('view_modes'); erase_cached_language(); fatal_exit(do_lang_tempcode('MISSING_LANG_ENTRY', escape_html($codename))); } else { return NULL; } } } if ($PAGE_CACHE_FILE !== NULL) { if (!isset($PAGE_CACHE_LANG_LOADED[$lang][$codename])) { $PAGE_CACHE_LANG_LOADED[$lang][$codename] = $LANGUAGE[$lang][$codename]; if ($GLOBALS['MEM_CACHE'] !== NULL) { persistant_cache_set($PAGE_CACHE_FILE, $PAGE_CACHE_LANG_LOADED); } else { @rewind($PAGE_CACHE_FILE); @ftruncate($PAGE_CACHE_FILE, 0); @fwrite($PAGE_CACHE_FILE, serialize($PAGE_CACHE_LANG_LOADED)); } } } // Put in parameters static $non_plural_non_vowel = array('1', 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'); $looked_up = $LANGUAGE[$lang][$codename]; if ($looked_up === NULL) { return NULL; } // Learning cache pool has told us this string definitely does not exist $out = str_replace('\\n', "\n", $looked_up); $plural_or_vowel_check = strpos($out, '|') !== false; if ($XSS_DETECT) { ocp_mark_as_escaped($out); } if ($token1 !== NULL) { if (is_object($token1) && $token2 === NULL || $token2 !== NULL && is_object($token2)) { $bits = preg_split('#\\{\\d[^\\}]*\\}#', $out, 2, PREG_SPLIT_OFFSET_CAPTURE); $ret = new ocp_tempcode(); foreach ($bits as $bit) { if ($XSS_DETECT) { ocp_mark_as_escaped($bit[0]); } $at = $bit[1]; if ($at != 0) { if ($out[$at - 2] == '1') { $ret->attach($token1); } elseif ($out[$at - 2] == '2') { $ret->attach($token2); } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '1|') { $exploded = explode('|', $out[$at - 2]); $_token = $token1->evaluate(); $_token_denum = str_replace(',', '', $_token); $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]); } elseif ($plural_or_vowel_check && substr($out[$at - 2], 0, 2) == '2|') { $exploded = explode('|', $out[$at - 2]); $_token = $token2->evaluate(); $_token_denum = str_replace(',', '', $_token); $ret->attach(in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($_token, 0, 1)), $non_plural_non_vowel) ? $exploded[1] : $exploded[2]); } } $ret->attach($bit[0]); } return $ret; } elseif ($token1 !== NULL) { $out = str_replace('{1}', $token1, $out); if ($plural_or_vowel_check) { $_token_denum = str_replace(',', '', $token1); $out = preg_replace('#\\{1\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($token1, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out); } if ($XSS_DETECT && ocp_is_escaped($token1)) { ocp_mark_as_escaped($out); } } if ($token2 !== NULL) { if ($XSS_DETECT) { $escaped = ocp_is_escaped($out); } $out = str_replace('{2}', $token2, $out); if ($plural_or_vowel_check) { $_token_denum = str_replace(',', '', $token1); $out = preg_replace('#\\{2\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($token2, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out); } if ($XSS_DETECT && ocp_is_escaped($token2) && $escaped) { ocp_mark_as_escaped($out); } if ($token3 !== NULL) { $i = 3; if (!is_array($token3)) { $token3 = array($token3); } foreach ($token3 as $token) { if ($XSS_DETECT) { $escaped = ocp_is_escaped($out); } $out = str_replace('{' . strval($i) . '}', $token, $out); if ($plural_or_vowel_check) { $_token_denum = str_replace(',', '', $token); $out = preg_replace('#\\{' . strval($i) . '\\|(.*)\\|(.*)\\}#U', in_array(is_numeric($_token_denum) ? $_token_denum : strtolower(substr($token, 0, 1)), $non_plural_non_vowel) ? '\\1' : '\\2', $out); } if ($XSS_DETECT && ocp_is_escaped($token) && $escaped) { ocp_mark_as_escaped($out); } $i++; } } } } return $out; }
/** * Load up a language file, compiling it (it's not cached yet). * * @param ID_TEXT The language file name * @param ?LANGUAGE_NAME The language (NULL: uses the current language) * @param ?string The language type (lang_custom, or custom) (NULL: normal priorities are used) * @set lang_custom custom * @param PATH Where we are cacheing too * @param boolean Whether to just return if there was a loading error * @return boolean Whether we FAILED to load */ function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_errors = false) { global $LANGUAGE, $REQUIRE_LANG_LOOP, $LANG_LOADED_LANG; $desire_cache = function_exists('get_option') && (get_option('is_on_lang_cache', true) == '1' || get_param_integer('keep_cache', 0) == 1 || get_param_integer('cache', 0) == 1) && get_param_integer('keep_cache', NULL) !== 0 && get_param_integer('cache', NULL) !== 0; if ($desire_cache) { if ($GLOBALS['IN_MINIKERNEL_VERSION'] == 0) { global $DECACHED_COMCODE_LANG_STRINGS; // Cleanup language strings if (!$DECACHED_COMCODE_LANG_STRINGS) { $DECACHED_COMCODE_LANG_STRINGS = true; $comcode_lang_strings = $GLOBALS['SITE_DB']->query_select('cached_comcode_pages', array('string_index'), array('the_zone' => '!'), '', NULL, NULL, true); if (!is_null($comcode_lang_strings)) { $GLOBALS['SITE_DB']->query_delete('cached_comcode_pages', array('the_zone' => '!')); foreach ($comcode_lang_strings as $comcode_lang_string) { delete_lang($comcode_lang_string['string_index']); } } } } $load_target = array(); } else { $load_target =& $LANGUAGE[$lang]; } global $FILE_ARRAY; if (@is_array($FILE_ARRAY) && file_array_exists('lang/' . $lang . '/' . $codename . '.ini')) { $lang_file = 'lang/' . $lang . '/' . $codename . '.ini'; $file = file_array_get($lang_file); _get_lang_file_map($file, $load_target, NULL, true); $bad = true; } else { $bad = true; $dirty = false; // Load originals $lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini'; if (file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; } // Load overrides now if they are there if ($type != 'lang') { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; if (!file_exists($lang_file) && get_file_base() != get_custom_file_base()) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; } if (!file_exists($lang_file)) { $lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.po'; if (!file_exists($lang_file)) { $lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '-' . strtolower($lang) . '.po'; } } } if ($type != 'lang' && file_exists($lang_file)) { _get_lang_file_map($lang_file, $load_target, NULL, false); $bad = false; $dirty = true; // Tainted from the official pack, so can't store server wide } // NB: Merge op doesn't happen in require_lang. It happens when do_lang fails and then decides it has to force a recursion to do_lang(xx,fallback_lang()) which triggers require_lang(xx,fallback_lang()) when it sees it's not loaded if ($bad && $lang != fallback_lang()) { require_lang($codename, fallback_lang(), $type, $ignore_errors); $REQUIRE_LANG_LOOP--; $fallback_cache_path = get_custom_file_base() . '/lang_cached/' . fallback_lang() . '/' . $codename . '.lcd'; if (file_exists($fallback_cache_path)) { require_code('files'); $fallback_map = unserialize(file_get_contents($fallback_cache_path)); $sep = '<span class="notranslate">----</span>'; $to_translate = ''; $i = 0; $from = 0; $lang_codes = array_keys($fallback_map); foreach ($fallback_map as $value) { if (strlen($to_translate . $sep . $to_translate) >= 3000) { $translated = preg_split('#<span class="notranslate">[^<>]*----[^<>]*</span>#', google_translate($to_translate, $lang)); foreach ($translated as $j => $t_value) { if (strtolower($lang_codes[$from + $j]) == $lang_codes[$from + $j]) { $t_value = $fallback_map[$lang_codes[$from + $j]]; } if ($lang_codes[$from + $j] == 'locale') { $t_value = strtolower($lang) . '_' . strtoupper($lang); } $fallback_map[$lang_codes[$from + $j]] = $t_value; $load_target[$lang_codes[$from + $j]] = $t_value; } $from = $i; $to_translate = ''; } if ($to_translate != '') { $to_translate .= $sep; } $to_translate .= $value; $i++; } $translated = preg_split('#<span class="notranslate">[^<>]*----[^<>]*</span>#', google_translate($to_translate, $lang)); foreach ($translated as $j => $t_value) { if (strtolower($lang_codes[$from + $j]) == $lang_codes[$from + $j]) { $t_value = $fallback_map[$lang_codes[$from + $j]]; } if ($lang_codes[$from + $j] == 'locale') { $t_value = strtolower($lang) . '_' . strtoupper($lang); } $fallback_map[$lang_codes[$from + $j]] = $t_value; $load_target[$lang_codes[$from + $j]] = $t_value; } if (function_exists('ocp_mb_substr') && $codename == 'dates') { foreach (array_keys($fallback_map) as $key) { if (substr($key, 0, 3) == 'FC_') { $test = ocp_mb_substr(trim($fallback_map[substr($key, 3)]), 0, 1, true); if ($test !== false) { $fallback_map[$key] = $test; } } } } $myfile = fopen($cache_path, 'wb'); fwrite($myfile, serialize($fallback_map)); fclose($myfile); fix_permissions($cache_path); } if (!array_key_exists($lang, $LANG_LOADED_LANG)) { $LANG_LOADED_LANG[$lang] = array(); } $LANG_LOADED_LANG[$lang][$codename] = 1; if (!$bad) { $LANGUAGE[$lang] += $fallback_map; } return $bad; } if ($bad) { if ($ignore_errors) { return true; } if ($codename != 'critical_error' || $lang != get_site_default_lang()) { fatal_exit(do_lang_tempcode('MISSING_LANG_FILE', escape_html($codename), escape_html($lang))); } else { critical_error('CRIT_LANG'); } } } if (is_null($GLOBALS['MEM_CACHE'])) { // Cache if ($desire_cache) { $file = @fopen($cache_path, 'wt'); // Will fail if cache dir missing .. e.g. in quick installer if ($file) { if (fwrite($file, serialize($load_target)) > 0) { // Success fclose($file); require_code('files'); fix_permissions($cache_path); } else { // Failure fclose($file); @unlink($cache_path); } } } } else { persistant_cache_set(array('LANG', $lang, $codename), $load_target, !$dirty); } if ($desire_cache) { $LANGUAGE[$lang] += $load_target; } return $bad; }