function cache_expire_variable($vn) { cache_debug("Adding {$vn} to expire variable store"); cache_variable($vn); }
/** * Take a code as input and grab its language specific message. Also cache the resulting * message. Return the message. Same as get_message but key value in cache is string * @access public * @param string $codes Message Code to translate - > 'term' field in DB * @return string The translated language specific message for code $code * @author Jacek Materna */ function getTranslatedCodeStr($codes) { /* this is where we want to get the msgs from the database inside a static variable */ global $_cache_msgs_new; static $_msgs_new; if (!isset($_msgs_new)) { if ( !($lang_et = cache(120, 'msgs_new', $_SESSION['lang'])) ) { global $db, $_base_path; $parent = Language::getParentCode($_SESSION['lang']); /* get $_msgs_new from the DB */ $sql = 'SELECT * FROM '.TABLE_PREFIX.'language_text WHERE variable="_msgs" AND (language_code="'.$_SESSION['lang'].'" OR language_code="'.$parent.'")'; $result = @mysql_query($sql, $db); $i = 1; while ($row = @mysql_fetch_assoc($result)) { // do not cache key as a digit (no contstant(), use string) $_cache_msgs_new[$row['term']] = str_replace('SITE_URL/', $_base_path, $row['text']); if (AT_DEVEL) { $_cache_msgs_new[$row['term']] .= ' <small><small>('.$row['term'].')</small></small>'; } } cache_variable('_cache_msgs_new'); endcache(true, false); } $_msgs_new = $_cache_msgs_new; } if (is_array($codes)) { /* this is an array with terms to replace */ $code = array_shift($codes); $message = $_msgs_new[$code]; $terms = $codes; /* replace the tokens with the terms */ $message = vsprintf($message, $terms); } else { $message = $_msgs_new[$codes]; if ($message == '') { /* the language for this msg is missing: */ $sql = 'SELECT * FROM '.TABLE_PREFIX.'language_text WHERE variable="_msgs"'; $result = @mysql_query($sql, $db); $i = 1; while ($row = @mysql_fetch_assoc($result)) { if (($row['term']) === $codes) { $message = '['.$row['term'].']'; break; } } } $code = $codes; } return $message; }
/** * Converts language code to actual language message, caches them according to page url * @access public * @param args unlimited number of arguments allowed but first arg MUST be name of the language variable/term * i.e $args[0] = the term to the format string $_template[term] * $args[1..x] = optional arguments to the formatting string * @return string|array full resulting message * @see $db in include/vitals.inc.php * @see cache() in include/phpCache/phpCache.inc.php * @see cache_variable() in include/phpCache/phpCache.inc.php * @author Joel Kronenberg */ function _AT() { global $_cache_template, $lang_et, $_rel_url; static $_template; $args = func_get_args(); if ($args[0] == "") { return ""; } $languageTextDAO = new LanguageTextDAO(); // a feedback msg if (!is_array($args[0])) { /** * Added functionality for translating language code String (TR_ERROR|TR_INFOS|TR_WARNING|TR_FEEDBACK).* * to its text and returning the result. No caching needed. * @author Jacek Materna */ // Check for specific language prefix, extendible as needed // 0002767: a substring+in_array test should be faster than a preg_match test. // replaced the preg_match with a test of the substring. $sub_arg = substr($args[0], 0, 7); // 7 is the shortest type of msg (TR_INFO) if (in_array($sub_arg, array('TR_ERRO', 'TR_INFO', 'TR_WARN', 'TR_FEED', 'TR_CONF'))) { global $_base_path, $addslashes; $args[0] = $addslashes($args[0]); /* get $_msgs_new from the DB */ $rows = $languageTextDAO->getMsgByTermAndLang($args[0], $_SESSION['lang']); $msgs = ''; if (is_array($rows)) { $row = $rows[0]; // do not cache key as a digit (no contstant(), use string) $msgs = str_replace('SITE_URL/', $_base_path, $row['text']); if (defined('TR_DEVEL') && TR_DEVEL) { $msgs .= ' <small><small>(' . $args[0] . ')</small></small>'; } } return $msgs; } } // a template variable if (!isset($_template)) { $url_parts = parse_url(TR_BASE_HREF); $name = substr($_SERVER['PHP_SELF'], strlen($url_parts['path']) - 1); if (!($lang_et = cache(120, 'lang', $_SESSION['lang'] . '_' . $name))) { /* get $_template from the DB */ $rows = $languageTextDAO->getAllTemplateByLang($_SESSION['lang']); if (is_array($rows)) { foreach ($rows as $id => $row) { //Do not overwrite the variable that existed in the cache_template already. //The edited terms (_c_template) will always be at the top of the resultset //0003279 if (isset($_cache_template[$row['term']])) { continue; } // saves us from doing an ORDER BY if ($row['language_code'] == $_SESSION['lang']) { $_cache_template[$row['term']] = stripslashes($row['text']); } else { if (!isset($_cache_template[$row['term']])) { $_cache_template[$row['term']] = stripslashes($row['text']); } } } } cache_variable('_cache_template'); endcache(true, false); } $_template = $_cache_template; } $num_args = func_num_args(); if (is_array($args[0])) { $args = $args[0]; $num_args = count($args); } $format = array_shift($args); if (isset($_template[$format]) && count($args) > 0) { $outString = vsprintf($_template[$format], $args); $str = ob_get_contents(); } else { $outString = ''; } if ($outString === false) { return '[Error parsing language. Variable: <code>' . $format . '</code>. Language: <code>' . $_SESSION['lang'] . '</code> ]'; } if (empty($outString)) { $rows = $languageTextDAO->getByTermAndLang($format, $_SESSION['lang']); if (is_array($rows)) { $row = $rows[0]; $_template[$row['term']] = stripslashes($row['text']); $outString = $_template[$row['term']]; } if (empty($outString)) { return '[ ' . $format . ' ]'; } } return $outString; }