'<', '<' => '<', '<' => '<', '>' => '>', '>' => '>', '>' => '>' ); foreach($array as $k=>$v){ $in = preg_replace("/".preg_quote($k)."/i",$v, $in); } return $in; } // ------------------------------------------------------------- function doSlash($in) { return doArray($in,'mysql_real_escape_string'); } // ------------------------------------------------------------- function doSpecial($in) { return doArray($in,'htmlspecialchars'); } // ------------------------------------------------------------- function _null($a) { return NULL; } // ------------------------------------------------------------- function array_null($in) { return array_map('_null', $in); } // ------------------------------------------------------------- function escape_title($title) { return strtr($title, array( '<' => '<', '>' => '>', "'" => ''', '"' => '"', ) ); } // ------------------------------------------------------------- // deprecated, use htmlspecialchars instead. Remove in crockery function escape_output($str) { return htmlspecialchars($str); } // ------------------------------------------------------------- // unused function => deprecate and remove in crockery? function escape_tags($str) { return strtr($str, array( '<' => '<', '>' => '>', ) ); } // ------------------------------------------------------------- function escape_cdata($str) { return '', ']]]>', $str).']]>'; } //------------------------------------------------------------- function gTxt($var, $atts=array()) { global $textarray; if(isset($textarray[strtolower($var)])) { $out = $textarray[strtolower($var)]; return strtr($out, $atts); } if ($atts) return $var.': '.join(', ', $atts); return $var; } //------------------------------------------------------------- function gTime($timestamp) { return safe_strftime('%d %b %Y %X', $timestamp); } // ------------------------------------------------------------- function dmp() { static $f = FALSE; if(defined('txpdmpfile')) { global $prefs; if(!$f) $f = fopen($prefs['tempdir'].'/'.txpdmpfile, 'a'); fwrite($f, "\n[".safe_strftime('iso8601')."]\n"); } $a = func_get_args(); if(!$f) echo "
".n; foreach ($a as $thing) { $out = is_scalar($thing) ? strval($thing) : var_export($thing, true); if ($f) { fwrite($f, $out."\n"); } else { echo htmlspecialchars($out), n; } } if(!$f) echo "".n; } // ------------------------------------------------------------- function load_lang($lang) { global $txpcfg; foreach(array($lang, 'en-gb') as $lang_code) { $rs = (txpinterface == 'admin') ? safe_rows_start('name, data','txp_lang',"lang='".doSlash($lang_code)."'") : safe_rows_start('name, data','txp_lang',"lang='".doSlash($lang_code)."' AND ( event='public' OR event='common')"); if (mysql_num_rows($rs)) break; } $out = array(); if ($rs && mysql_num_rows($rs) > 0) { while ($a = nextRow($rs)) { $out[$a['name']] = $a['data']; } }else{ #backward compatibility stuff. Remove when necessary. $filename = is_file(txpath.'/lang/'.$lang.'.txt') ? txpath.'/lang/'.$lang.'.txt' : txpath.'/lang/en-gb.txt'; $file = @fopen($filename, "r"); if ($file) { while (!feof($file)) { $line = fgets($file, 4096); if($line[0]=='#') continue; @list($name,$val) = explode(' => ',trim($line)); $out[$name] = $val; } @fclose($filename); } } return $out; } // ------------------------------------------------------------- function load_lang_dates($lang) { global $txpcfg; $filename = is_file(txpath.'/lang/'.$lang.'_dates.txt')? txpath.'/lang/'.$lang.'_dates.txt': txpath.'/lang/en-gb_dates.txt'; $file = @file(txpath.'/lang/'.$lang.'_dates.txt','r'); if(is_array($file)) { foreach($file as $line) { if($line[0]=='#' || strlen($line) < 2) continue; list($name,$val) = explode('=>',$line,2); $out[trim($name)] = trim($val); } return $out; } return false; } // ------------------------------------------------------------- function load_lang_event($event) { global $txpcfg; $lang = LANG; $installed = safe_field('name', 'txp_lang',"lang='".doSlash($lang)."' limit 1"); $lang_code = ($installed)? $lang : 'en-gb'; $rs = safe_rows_start('name, data','txp_lang',"lang='".doSlash($lang_code)."' AND event='".doSlash($event)."'"); $out = array(); if ($rs && !empty($rs)) { while ($a = nextRow($rs)) { $out[$a['name']] = $a['data']; } } return ($out) ? $out : ''; } // ------------------------------------------------------------- function check_privs() { global $txp_user; $privs = safe_field("privs", "txp_users", "name='".doSlash($txp_user)."'"); $args = func_get_args(); if(!in_array($privs,$args)) { exit(pageTop('Restricted').'
'. gTxt('restricted_area').'
'); } } // ------------------------------------------------------------- function add_privs($res, $perm = '1') // perm = '1,2,3' { global $txp_permissions; // Don't let them override privs that exist if (!isset($txp_permissions[$res])) $txp_permissions[$res] = $perm; } // ------------------------------------------------------------- function has_privs($res, $user='') { global $txp_user, $txp_permissions; static $privs; // If no user name is supplied, assume the current login name if (empty($user)) $user = $txp_user; if (!isset($privs[$user])) { $privs[$user] = safe_field("privs", "txp_users", "name='".doSlash($user)."'"); } if (isset($txp_permissions[$res])) { return in_array($privs[$user], explode(',', $txp_permissions[$res])); } else { return false; } } // ------------------------------------------------------------- function require_privs($res, $user='') { if (!has_privs($res, $user)) exit(pageTop('Restricted').''. gTxt('restricted_area').'
'); } // ------------------------------------------------------------- function sizeImage($name) { $size = @getimagesize($name); return(is_array($size)) ? $size[3] : false; } // ------------------------------------------------------------- function gps($thing) // checks GET and POST for a named variable, or creates it blank { if (isset($_GET[$thing])) { if (MAGIC_QUOTES_GPC) { return doStrip($_GET[$thing]); } else { return $_GET[$thing]; } } elseif (isset($_POST[$thing])) { if (MAGIC_QUOTES_GPC) { return doStrip($_POST[$thing]); } else { return $_POST[$thing]; } } return ''; } // ------------------------------------------------------------- function gpsa($array) // performs gps() on an array of variable names { if(is_array($array)) { $out = array(); foreach($array as $a) { $out[$a] = gps($a); } return $out; } return false; } // ------------------------------------------------------------- function ps($thing) // checks POST for a named variable, or creates it blank { if (isset($_POST[$thing])) { if (MAGIC_QUOTES_GPC) { return doStrip($_POST[$thing]); } else { return $_POST[$thing]; } } return ''; } // ------------------------------------------------------------- function psa($array) // performs ps on an array of variable names { foreach($array as $a) { $out[$a] = ps($a); } return $out; } // ------------------------------------------------------------- function psas($array) // same as above, but does strip_tags on post values { foreach($array as $a) { $out[$a] = strip_tags(ps($a)); } return $out; } // ------------------------------------------------------------- function stripPost() { if (isset($_POST)) { if (MAGIC_QUOTES_GPC) { return doStrip($_POST); } else { return $_POST; } } return ''; } // ------------------------------------------------------------- function serverSet($thing) // Get a var from $_SERVER global array, or create it { return (isset($_SERVER[$thing])) ? $_SERVER[$thing] : ''; } // ------------------------------------------------------------- function pcs($thing) // Get a var from POST or COOKIE; if not, create it { if (isset($_COOKIE["txp_".$thing])) { if (MAGIC_QUOTES_GPC) { return doStrip($_COOKIE["txp_".$thing]); } else return $_COOKIE["txp_".$thing]; } elseif (isset($_POST[$thing])) { if (MAGIC_QUOTES_GPC) { return doStrip($_POST[$thing]); } else return $_POST[$thing]; } return ''; } // ------------------------------------------------------------- function cs($thing) // Get a var from COOKIE; if not, create it { if (isset($_COOKIE[$thing])) { if (MAGIC_QUOTES_GPC) { return doStrip($_COOKIE[$thing]); } else return $_COOKIE[$thing]; } return ''; } // ------------------------------------------------------------- function yes_no($status) { return ($status==0) ? (gTxt('no')) : (gTxt('yes')); } // ------------------------------------------------------------- function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } // ------------------------------------------------------------- function load_plugin($name) { global $plugins, $plugins_ver, $prefs, $txp_current_plugin; if (is_array($plugins) and in_array($name,$plugins)) { return true; } if (!empty($prefs['plugin_cache_dir'])) { $dir = rtrim($prefs['plugin_cache_dir'], '/') . '/'; # in case it's a relative path if (!is_dir($dir)) $dir = rtrim(realpath(txpath.'/'.$dir), '/') . '/'; if (is_file($dir . $name . '.php')) { $plugins[] = $name; set_error_handler("pluginErrorHandler"); if (isset($txp_current_plugin)) $txp_parent_plugin = $txp_current_plugin; $txp_current_plugin = $name; include($dir . $name . '.php'); $txp_current_plugin = (isset($txp_parent_plugin) ? $txp_parent_plugin : NULL); $plugins_ver[$name] = @$plugin['version']; restore_error_handler(); return true; } } $rs = safe_row("name,code,version","txp_plugin","status = 1 AND name='".doSlash($name)."'"); if ($rs) { $plugins[] = $rs['name']; $plugins_ver[$rs['name']] = $rs['version']; set_error_handler("pluginErrorHandler"); if (isset($txp_current_plugin)) $txp_parent_plugin = $txp_current_plugin; $txp_current_plugin = $rs['name']; eval($rs['code']); $txp_current_plugin = (isset($txp_parent_plugin) ? $txp_parent_plugin : NULL); restore_error_handler(); return true; } return false; } // ------------------------------------------------------------- function require_plugin($name) { if (!load_plugin($name)) trigger_error("Unable to include required plugin \"{$name}\"",E_USER_ERROR); } // ------------------------------------------------------------- function include_plugin($name) { if (!load_plugin($name)) trigger_error("Unable to include plugin \"{$name}\"",E_USER_WARNING); } // ------------------------------------------------------------- function pluginErrorHandler($errno, $errstr, $errfile, $errline) { $error = array( E_WARNING => "Warning", E_NOTICE => "Notice", E_USER_ERROR => "User_Error", E_USER_WARNING => "User_Warning", E_USER_NOTICE => "User_Notice"); if (!($errno & error_reporting())) return; global $txp_current_plugin, $production_status; printf ("".gTxt('plugin_load_error').' %s -> %s: %s on line %s', $txp_current_plugin, $error[$errno], $errstr, $errline); if ($production_status == 'debug') print "\n
".htmlspecialchars(join("\n", get_caller(10)))."
";
}
// -------------------------------------------------------------
function tagErrorHandler($errno, $errstr, $errfile, $errline)
{
global $production_status;
$error = array( E_WARNING => "Warning", E_NOTICE => "Notice", E_USER_ERROR => "Textpattern Error",
E_USER_WARNING => "Textpattern Warning", E_USER_NOTICE => "Textpattern Notice");
if (!($errno & error_reporting())) return;
if ($production_status == 'live') return;
global $txp_current_tag;
$errline = ($errstr === 'unknown_tag') ? '' : " on line $errline";
printf ("".gTxt('tag_error').' %s -> %s: %s %s', htmlspecialchars($txp_current_tag), $error[$errno], $errstr, $errline ); if ($production_status == 'debug') { print "\n
".htmlspecialchars(join("\n", get_caller(10)))."
";
$trace_msg = gTxt('tag_error').' '.$txp_current_tag.' -> '.$error[$errno].': '.$errstr.' '.$errline;
trace_add( $trace_msg );
}
}
// -------------------------------------------------------------
function feedErrorHandler($errno, $errstr, $errfile, $errline)
{
global $production_status;
if ($production_status != 'debug') return;
return tagErrorHandler($errno, $errstr, $errfile, $errline);
}
// -------------------------------------------------------------
function load_plugins($type=0)
{
global $prefs,$plugins, $plugins_ver;
if (!is_array($plugins)) $plugins = array();
if (!empty($prefs['plugin_cache_dir'])) {
$dir = rtrim($prefs['plugin_cache_dir'], '/') . '/';
# in case it's a relative path
if (!is_dir($dir))
$dir = rtrim(realpath(txpath.'/'.$dir), '/') . '/';
foreach (glob($dir.'*.php') as $f) {
load_plugin(basename($f, '.php'));
}
}
$where = 'status = 1 AND type IN ('.($type ? '1,3' : '0,1').')';
$rs = safe_rows("name, code, version", "txp_plugin", $where.' order by load_order');
if ($rs) {
$old_error_handler = set_error_handler("pluginErrorHandler");
foreach($rs as $a) {
if (!in_array($a['name'],$plugins)) {
$plugins[] = $a['name'];
$plugins_ver[$a['name']] = $a['version'];
$GLOBALS['txp_current_plugin'] = $a['name'];
$eval_ok = eval($a['code']);
if ($eval_ok === FALSE)
echo gTxt('plugin_load_error_above').strong($a['name']).n.br;
unset($GLOBALS['txp_current_plugin']);
}
}
restore_error_handler();
}
}
// -------------------------------------------------------------
function register_callback($func, $event, $step='', $pre=0)
{
global $plugin_callback;
$plugin_callback[] = array('function'=>$func, 'event'=>$event, 'step'=>$step, 'pre'=>$pre);
}
// -------------------------------------------------------------
function register_page_extension($func, $event, $step='', $top=0)
{
# For now this just does the same as register_callback
register_callback($func, $event, $step, $top);
}
// -------------------------------------------------------------
function callback_event($event, $step='', $pre=0)
{
global $plugin_callback;
if (!is_array($plugin_callback))
return;
$return_value = '';
foreach ($plugin_callback as $c) {
if ($c['event'] == $event and (empty($c['step']) or $c['step'] == $step) and $c['pre'] == $pre) {
if (is_callable($c['function'])) {
$return_value .= call_user_func($c['function'], $event, $step);
}
}
}
return $return_value;
}
// -------------------------------------------------------------
function register_tab($area, $event, $title)
{
global $plugin_areas;
$plugin_areas[$area][$title] = $event;
}
// -------------------------------------------------------------
// deprecated, use lAtts instead. Remove in crockery
function getAtt($name, $default=NULL)
{
global $theseatts;
return isset($theseatts[$name]) ? $theseatts[$name] : $default;
}
// -------------------------------------------------------------
// deprecated, use lAtts instead. Remove in crockery
function gAtt(&$atts, $name, $default=NULL)
{
return isset($atts[$name]) ? $atts[$name] : $default;
}
// -------------------------------------------------------------
function lAtts($pairs, $atts, $warn=1)
{
global $production_status;
foreach($atts as $name => $value)
{
if (array_key_exists($name, $pairs))
{
$pairs[$name] = $value;
}
elseif ($warn and $production_status != 'live')
{
trigger_error(gTxt('unknown_attribute', array('{att}' => $name)));
}
}
return ($pairs) ? $pairs : false;
}
// -------------------------------------------------------------
function select_buttons()
{
return
gTxt('select').': '.
fInput('button','selall',gTxt('all'),'smallerboxsp','select all','selectall();').
fInput('button','selnone',gTxt('none'),'smallerboxsp','select none','deselectall();').
fInput('button','selrange',gTxt('range'),'smallerboxsp','select range','selectrange();');
}
// -------------------------------------------------------------
function stripSpace($text, $force=0)
{
global $prefs;
if ($force or !empty($prefs['attach_titles_to_permalinks']))
{
$text = sanitizeForUrl($text);
if ($prefs['permalink_title_format']) {
return strtolower($text);
} else {
return str_replace('-','',$text);
}
}
}
// -------------------------------------------------------------
function sanitizeForUrl($text)
{
// Remove names entities and tags
$text = preg_replace("/(^|&\S+;)|(<[^>]*>)/U","",dumbDown($text));
// Dashify high-order chars leftover from dumbDown()
$text = preg_replace("/[\x80-\xff]/","-",$text);
// Collapse spaces, minuses, (back-)slashes and non-words
$text = preg_replace('/[\s\-\/\\\\]+/', '-', trim(preg_replace('/[^\w\s\-\/\\\\]/', '', $text)));
// Remove all non-whitelisted characters
$text = preg_replace("/[^A-Za-z0-9\-_]/","",$text);
return $text;
}
// -------------------------------------------------------------
function dumbDown($str, $lang=LANG)
{
static $array;
if (empty($array[$lang])) {
$array[$lang] = array( // nasty, huh?.
'À'=>'A','À'=>'A','Á'=>'A','Á'=>'A','Â'=>'A','Â'=>'A',
'Ã'=>'A','Ã'=>'A','Ä'=>'Ae','Ä'=>'A','Å'=>'A','Å'=>'A',
'Æ'=>'Ae','Æ'=>'AE',
'Ā'=>'A','Ą'=>'A','Ă'=>'A',
'Ç'=>'C','Ç'=>'C','Ć'=>'C','Č'=>'C','Ĉ'=>'C','Ċ'=>'C',
'Ď'=>'D','Đ'=>'D','Ð'=>'D','Ð'=>'D',
'È'=>'E','È'=>'E','É'=>'E','É'=>'E','Ê'=>'E','Ê'=>'E','Ë'=>'E','Ë'=>'E',
'Ē'=>'E','Ę'=>'E','Ě'=>'E','Ĕ'=>'E','Ė'=>'E',
'Ĝ'=>'G','Ğ'=>'G','Ġ'=>'G','Ģ'=>'G',
'Ĥ'=>'H','Ħ'=>'H',
'Ì'=>'I','Ì'=>'I','Í'=>'I','Í'=>'I','Î'=>'I','Î'=>'I','Ï'=>'I','Ï'=>'I',
'Ī'=>'I','Ĩ'=>'I','Ĭ'=>'I','Į'=>'I','İ'=>'I',
'IJ'=>'IJ',
'Ĵ'=>'J',
'Ķ'=>'K',
'Ł'=>'K','Ľ'=>'K','Ĺ'=>'K','Ļ'=>'K','Ŀ'=>'K',
'Ñ'=>'N','Ñ'=>'N','Ń'=>'N','Ň'=>'N','Ņ'=>'N','Ŋ'=>'N',
'Ò'=>'O','Ò'=>'O','Ó'=>'O','Ó'=>'O','Ô'=>'O','Ô'=>'O','Õ'=>'O','Õ'=>'O',
'Ö'=>'Oe','Ö'=>'Oe',
'Ø'=>'O','Ø'=>'O','Ō'=>'O','Ő'=>'O','Ŏ'=>'O',
'Œ'=>'OE',
'Ŕ'=>'R','Ř'=>'R','Ŗ'=>'R',
'Ś'=>'S','Š'=>'S','Ş'=>'S','Ŝ'=>'S','Ș'=>'S',
'Ť'=>'T','Ţ'=>'T','Ŧ'=>'T','Ț'=>'T',
'Ù'=>'U','Ù'=>'U','Ú'=>'U','Ú'=>'U','Û'=>'U','Û'=>'U',
'Ü'=>'Ue','Ū'=>'U','Ü'=>'Ue',
'Ů'=>'U','Ű'=>'U','Ŭ'=>'U','Ũ'=>'U','Ų'=>'U',
'Ŵ'=>'W',
'Ý'=>'Y','Ý'=>'Y','Ŷ'=>'Y','Ÿ'=>'Y',
'Ź'=>'Z','Ž'=>'Z','Ż'=>'Z',
'Þ'=>'T','Þ'=>'T',
'à'=>'a','á'=>'a','â'=>'a','ã'=>'a','ä'=>'ae',
'ä'=>'ae',
'å'=>'a','ā'=>'a','ą'=>'a','ă'=>'a','å'=>'a',
'æ'=>'ae',
'ç'=>'c','ć'=>'c','č'=>'c','ĉ'=>'c','ċ'=>'c',
'ď'=>'d','đ'=>'d','ð'=>'d',
'è'=>'e','é'=>'e','ê'=>'e','ë'=>'e','ē'=>'e',
'ę'=>'e','ě'=>'e','ĕ'=>'e','ė'=>'e',
'ƒ'=>'f',
'ĝ'=>'g','ğ'=>'g','ġ'=>'g','ģ'=>'g',
'ĥ'=>'h','ħ'=>'h',
'ì'=>'i','í'=>'i','î'=>'i','ï'=>'i','ī'=>'i',
'ĩ'=>'i','ĭ'=>'i','į'=>'i','ı'=>'i',
'ij'=>'ij',
'ĵ'=>'j',
'ķ'=>'k','ĸ'=>'k',
'ł'=>'l','ľ'=>'l','ĺ'=>'l','ļ'=>'l','ŀ'=>'l',
'ñ'=>'n','ń'=>'n','ň'=>'n','ņ'=>'n','ʼn'=>'n',
'ŋ'=>'n',
'ò'=>'o','ó'=>'o','ô'=>'o','õ'=>'o','ö'=>'oe',
'ö'=>'oe',
'ø'=>'o','ō'=>'o','ő'=>'o','ŏ'=>'o',
'œ'=>'oe',
'ŕ'=>'r','ř'=>'r','ŗ'=>'r',
'š'=>'s',
'ù'=>'u','ú'=>'u','û'=>'u','ü'=>'ue','ū'=>'u',
'ü'=>'ue',
'ů'=>'u','ű'=>'u','ŭ'=>'u','ũ'=>'u','ų'=>'u',
'ŵ'=>'w',
'ý'=>'y','ÿ'=>'y','ŷ'=>'y',
'ž'=>'z','ż'=>'z','ź'=>'z',
'þ'=>'t',
'ß'=>'ss',
'ſ'=>'ss',
'à'=>'a','á'=>'a','â'=>'a','ã'=>'a','ä'=>'ae',
'å'=>'a','æ'=>'ae','ç'=>'c','ð'=>'d',
'è'=>'e','é'=>'e','ê'=>'e','ë'=>'e',
'ì'=>'i','í'=>'i','î'=>'i','ï'=>'i',
'ñ'=>'n',
'ò'=>'o','ó'=>'o','ô'=>'o','õ'=>'o','ö'=>'oe',
'ø'=>'o',
'ù'=>'u','ú'=>'u','û'=>'u','ü'=>'ue',
'ý'=>'y','ÿ'=>'y',
'þ'=>'t',
'ß'=>'ss'
);
if (is_file(txpath.'/lib/i18n-ascii.txt')) {
$i18n = parse_ini_file(txpath.'/lib/i18n-ascii.txt', true);
# load the global map
if (@is_array($i18n['default'])) {
$array[$lang] = array_merge($array[$lang], $i18n['default']);
# base language overrides: 'de-AT' applies the 'de' section
if (preg_match('/([a-zA-Z]+)-.+/', $lang, $m)) {
if (@is_array($i18n[$m[1]]))
$array[$lang] = array_merge($array[$lang], $i18n[$m[1]]);
};
# regional language overrides: 'de-AT' applies the 'de-AT' section
if (@is_array($i18n[$lang]))
$array[$lang] = array_merge($array[$lang], $i18n[$lang]);
}
# load an old file (no sections) just in case
else
$array[$lang] = array_merge($array[$lang], $i18n);
}
}
return strtr($str, $array[$lang]);
}
// -------------------------------------------------------------
function clean_url($url)
{
return preg_replace("/\"|'|(?:\s.*$)/",'',$url);
}
// -------------------------------------------------------------
function noWidow($str)
{
// replace the last space with a nbsp
if (REGEXP_UTF8 == 1)
return preg_replace('@[ ]+([[:punct:]]?\pL+[[:punct:]]?)$@u', ' $1', rtrim($str));
return preg_replace('@[ ]+([[:punct:]]?\w+[[:punct:]]?)$@', ' $1', rtrim($str));
}
// -------------------------------------------------------------
function is_blacklisted($ip, $checks = '')
{
global $prefs;
if (!$checks)
{
$checks = do_list($prefs['spam_blacklists']);
}
$rip = join('.', array_reverse(explode('.', $ip)));
foreach ($checks as $a)
{
$parts = explode(':', $a, 2);
$rbl = $parts[0];
if (isset($parts[1]))
{
foreach (explode(':', $parts[1]) as $code)
{
$codes[] = strpos($code, '.') ? $code : '127.0.0.'.$code;
}
}
$hosts = $rbl ? @gethostbynamel($rip.'.'.trim($rbl, '. ').'.') : FALSE;
if ($hosts and (!isset($codes) or array_intersect($hosts, $codes)))
{
$listed[] = $rbl;
}
}
return (!empty($listed)) ? join(', ', $listed) : false;
}
// -------------------------------------------------------------
function is_logged_in($user = '')
{
$name = substr(cs('txp_login_public'), 10);
if (!strlen($name) or strlen($user) and $user !== $name)
{
return FALSE;
}
$rs = safe_row('nonce, name, RealName, email, privs', 'txp_users', "name = '".doSlash($name)."'");
if ($rs and substr(md5($rs['nonce']), -10) === substr(cs('txp_login_public'), 0, 10))
{
unset($rs['nonce']);
return $rs;
}
else
{
return FALSE;
}
}
// -------------------------------------------------------------
function updateSitePath($here)
{
$here = doSlash($here);
$rs = safe_field ("name",'txp_prefs',"name = 'path_to_site'");
if (!$rs) {
safe_insert("txp_prefs","prefs_id=1,name='path_to_site',val='$here'");
} else {
safe_update('txp_prefs',"val='$here'","name='path_to_site'");
}
}
// -------------------------------------------------------------
function splat($text)
{
$atts = array();
if (preg_match_all('@(\w+)\s*=\s*(?:"((?:[^"]|"")*)"|\'((?:[^\']|\'\')*)\'|([^\s\'"/>]+))@s', $text, $match, PREG_SET_ORDER))
{
foreach ($match as $m)
{
switch (count($m))
{
case 3:
$val = str_replace('""', '"', $m[2]);
break;
case 4:
$val = str_replace("''", "'", $m[3]);
if (strpos($m[3], ''.n.n."$errno: $errstr in $errfile at line $errline\n"; # Requires PHP 4.3 if (is_callable('debug_backtrace')) { echo "Backtrace:\n"; $trace = debug_backtrace(); foreach($trace as $ent) { if(isset($ent['file'])) echo $ent['file'].':'; if(isset($ent['function'])) { echo $ent['function'].'('; if(isset($ent['args'])) { $args=''; foreach($ent['args'] as $arg) { $args.=$arg.','; } echo rtrim($args,','); } echo ') '; } if(isset($ent['line'])) echo 'at line '.$ent['line'].' '; if(isset($ent['file'])) echo 'in '.$ent['file']; echo "\n"; } } echo ""; } // ------------------------------------------------------------- function find_temp_dir() { global $path_to_site, $img_dir; if (is_windows()) { $guess = array(txpath.DS.'tmp', getenv('TMP'), getenv('TEMP'), getenv('SystemRoot').DS.'Temp', 'C:'.DS.'Temp', $path_to_site.DS.$img_dir); foreach ($guess as $k=>$v) if (empty($v)) unset($guess[$k]); } else $guess = array(txpath.DS.'tmp', '', DS.'tmp', $path_to_site.DS.$img_dir); foreach ($guess as $dir) { $tf = @tempnam($dir, 'txp_'); if ($tf) $tf = realpath($tf); if ($tf and file_exists($tf)) { unlink($tf); return dirname($tf); } } return false; } // ------------------------------------------------------------- function get_uploaded_file($f, $dest='') { global $tempdir; if (!is_uploaded_file($f)) return false; if ($dest) { $newfile = $dest; } else { $newfile = tempnam($tempdir, 'txp_'); if (!$newfile) return false; } # $newfile is created by tempnam(), but move_uploaded_file # will overwrite it if (move_uploaded_file($f, $newfile)) return $newfile; } // -------------------------------------------------------------- function set_error_level($level) { if ($level == 'debug') { error_reporting(E_ALL); } elseif ($level == 'live') { // don't show errors on screen error_reporting(E_ALL ^ (E_WARNING | E_NOTICE)); @ini_set("display_errors","1"); } else { // default is 'testing': display everything except notices error_reporting(E_ALL ^ (E_NOTICE)); } } // ------------------------------------------------------------- function shift_uploaded_file($f, $dest) { // Rename might not work, but it's worth a try if (@rename($f, $dest)) return true; if (@copy($f, $dest)) { unlink($f); return true; } } // ------------------------------------------------------------- function upload_get_errormsg($err_code) { $msg = ''; switch ($err_code) { // Value: 0; There is no error, the file uploaded with success. case UPLOAD_ERR_OK : $msg = '';break; // Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini. case UPLOAD_ERR_INI_SIZE : $msg = gTxt('upload_err_ini_size');break; // Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form. case UPLOAD_ERR_FORM_SIZE : $msg = gTxt('upload_err_form_size');break; // Value: 3; The uploaded file was only partially uploaded. case UPLOAD_ERR_PARTIAL : $msg = gTxt('upload_err_partial');break; // Value: 4; No file was uploaded. case UPLOAD_ERR_NO_FILE : $msg = gTxt('upload_err_no_file');break; // Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3. case UPLOAD_ERR_NO_TMP_DIR : $msg = gTxt('upload_err_tmp_dir');break; // Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0. case UPLOAD_ERR_CANT_WRITE : $msg = gTxt('upload_err_cant_write');break; // Value: 8; File upload stopped by extension. Introduced in PHP 5.2.0. case UPLOAD_ERR_EXTENSION : $msg = gTxt('upload_err_extension');break; } return $msg; } // ------------------------------------------------------------- function is_windows() { return (PHP_OS == 'WINNT' or PHP_OS == 'WIN32' or PHP_OS == 'Windows'); } // ------------------------------------------------------------- function is_cgi() { return IS_CGI; } // ------------------------------------------------------------- function is_mod_php() { return IS_APACHE; } // ------------------------------------------------------------- function is_disabled($function) { static $disabled; if (!isset($disabled)) { $disabled = explode(',', ini_get('disable_functions')); } return in_array($function, $disabled); } // -------------------------------------------------------------- function build_file_path($base,$path) { $base = rtrim($base,'/\\'); $path = ltrim($path,'/\\'); return $base.DIRECTORY_SEPARATOR.$path; } // -------------------------------------------------------------- function get_author_name($name) { static $authors = array(); if (isset($authors[$name])) return $authors[$name]; $realname = fetch('RealName','txp_users','name',doSlash($name)); $authors[$name] = $realname; return ($realname) ? $realname : $name; } // -------------------------------------------------------------- function EvalElse($thing, $condition) { global $txp_current_tag; trace_add("[$txp_current_tag: ".($condition ? gTxt('true') : gTxt('false'))."]"); $els = strpos($thing, '
Error: '".htmlspecialchars($myvar)."' is not an integer". n.'
'.
htmlspecialchars(join(n, get_caller(5,1))).'
', E_USER_ERROR);
}
else
{
trigger_error("'".htmlspecialchars($myvar)."' is not an integer.", E_USER_ERROR);
}
return false;
}
//-------------------------------------------------------------
function replace_relative_urls($html, $permalink='') {
global $siteurl;
# urls like "/foo/bar" - relative to the domain
if (serverSet('HTTP_HOST')) {
$html = preg_replace('@(]+href=")/@','$1'.PROTOCOL.serverSet('HTTP_HOST').'/',$html);
$html = preg_replace('@(