ginf={url:'{$siteURL}',script:'{$scriptName}',target:{h:'{$targetHost}',p:'{$targetPath}',b:'{$base}',u:'{$fullURL}'},enc:{u:'{$unique}',e:'{$options['encodeURL']}',x:'{$options['encodePage']}',p:'{$CONFIG['path_info_urls']}'},b:'{$bitfield}'{$optional}}
OUT;
}
/*****************************************************************
* Compatability
******************************************************************/
# Requirements are only PHP5 but this function was introduced in PHP 5.1.3
if ( ! function_exists('curl_setopt_array') ) {
# Takes an array of options and sets all at once
function curl_setopt_array($ch, $options) {
foreach ( $options as $option => $value ) {
curl_setopt($ch, $option, $value);
}
}
}
if ( COMPATABILITY_MODE ) {
# Function renamed at 1.0, here for backwards compatability
function render_injectionJS() {
return injectionJS();
}
}
/*****************************************************************
* Miscellaneous
******************************************************************/
# Send no-cache headers.
function sendNoCache() {
header( 'Cache-Control: no-store, no-cache, must-revalidate' );
header( 'Cache-Control: post-check=0, pre-check=0', false );
header( 'Pragma: no-cache' );
}
# Trim and stripslashes
function clean($value) {
# Static $magic saves us recalling get_magic_quotes_gpc() every time
static $magic;
# Recurse if array
if ( is_array($value) ) {
return array_map($value);
}
# Trim extra spaces
$value = trim($value);
# Check magic quotes status
if ( ! isset($magic) ) {
$magic = get_magic_quotes_gpc();
}
# Stripslashes if magic
if ( $magic && is_string($value) ) {
$value = stripslashes($value);
}
# Return cleaned
return $value;
}
# Redirect
function redirect($to = 'index.php') {
# Did we have an absolute URL?
if ( strpos($to, 'http') !== 0 ) {
# If not, prefix our current URL
$to = GLYPE_URL . '/' . $to;
}
# Send redirect
header('Location: ' . $to);
exit;
}
# Error message
function error($type, $allowReload=false) {
global $CONFIG, $themeReplace, $options, $phrases, $flag;
# Get extra arguments
$args = func_get_args();
# Remove first argument (we have that as $type)
array_shift($args);
# Check error exists
# Force to the "unknown" error message
if ( ! isset($phrases[$type]) ) {
$args = array($type);
$type = 'unknown_error';
}
if ( $args ) {
# Error text must be generated by calling sprintf - we only have
# the extra args as an array so we have to use call_user_func_array
$errorText = call_user_func_array('sprintf', array_merge((array) $phrases[$type], $args));
} else {
# Error text can be fetched simply from the $phrases array
$errorText = $phrases[$type];
}
# If in frame or ajax, don't redirect back to index
if ( isset($flag) && ( $flag == 'frame' || $flag == 'ajax' ) ) {
die($errorText . ' Return to index.');
}
# Finally add it to the $themeReplace array to get it in there
$themeReplace['error'] = '' . $errorText . '
';
# And a link to try again?
$return=currentURL();
if (strlen($return)>0) {
$themeReplace['error'] .= '[Reload ' . htmlentities(deproxyURL($return)) . ']
';
}
# Start with an empty array
$toShow = array();
# Loop through the available options
foreach ( $CONFIG['options'] as $name => $details ) {
# Check we're allowed to choose
if ( ! empty($details['force']) ) {
continue;
}
# Generate the HTML 'checked' where appropriate
$checked = $options[$name] ? ' checked="checked"' : '';
# Add to the toShow array
$toShow[] = array(
'name' => $name,
'title' => $details['title'],
'desc' => $details['desc'],
'escaped_desc' => str_replace("'", "\'", $details['desc']),
'checked' => $checked
);
}
sendNoCache();
$vars2['toShow'] = $toShow;
echo loadTemplate('main', $vars2);
# And flush buffer
ob_end_flush();
exit;
}
# Return current URL (absolute URL to proxied page)
function currentURL() {
# Which method are we using
$method = empty($_SERVER['PATH_INFO']) ? 'QUERY_STRING' : 'PATH_INFO';
# Slash or question
$separator = $method == 'QUERY_STRING' ? '?' : '';
# Return full URL
return GLYPE_BROWSE . $separator . ( isset($_SERVER[$method]) ? $_SERVER[$method] : '');
}
# Check tmp directory and create it if necessary
function checkTmpDir($path, $htaccess=false) {
global $CONFIG;
# Does it already exist?
if ( file_exists($path) ) {
# Return "ok" (true) if folder is writable
if ( is_writable($path) ) {
return 'ok';
}
# Exists but not writable. Nothing else we can do.
return false;
} else {
# Does not exist, can we create it? (No if the desired dir is not
# inside the temp dir)
if ( is_writable($CONFIG['tmp_dir']) && realpath($CONFIG['tmp_dir']) == realpath(dirname($path) . '/') && mkdir($path, 0755, true) ) {
# New dir, protect it with .htaccess
if ( $htaccess ) {
file_put_contents($path . '/.htaccess', $htaccess);
}
# Return (true) "made"
return 'made';
}
}
return false;
}
# note - intended to obfustate URLs and HTML source code. Does not provide security. Use SSL for actual security.
function arcfour($w,$k,$d) {
if ($w=='decrypt') {$d=base64_decode($d);}
$o='';$s=array();$n=256;$l=strlen($k);$e=strlen($d);
for($i=0;$i<$n;++$i){$s[$i]=$i;}
for($j=$i=0;$i<$n;++$i){$j=($j+$s[$i]+ord($k[$i%$l]))%$n;$x=$s[$i];$s[$i]=$s[$j];$s[$j]=$x;}
for($i=$j=$y=0;$y<$e;++$y){$i=($i+1)%$n;$j=($j+$s[$i])%$n;$x=$s[$i];$s[$i]=$s[$j];$s[$j]=$x;$o.=$d[$y]^chr($s[($s[$i]+$s[$j])%$n]);}
if ($w=='encrypt') {$o=base64_encode($o);}
return $o;
}
# note - intended to obfustate URLs and HTML source code. Does not provide security. Use SSL for actual security.
function glype_session_id() {
$session_id = session_id();
if ($session_id=='') {
return '';
} elseif (!preg_match('/^[a-zA-Z0-9-]+$/', $session_id)) { # valid characters are a-z, A-Z, 0-9 and '-'
return md5($_SERVER['HTTP_HOST'].$_SERVER['REMOTE_ADDR']);
} else {
return $session_id;
}
}
# Proxify is a registered trademark of UpsideOut, Inc. All rights reserved.
function proxifyURL($url, $givenFlag = false) {return proxyURL($url,$givenFlag);}
function deproxifyURL($url, $givenFlag = false) {return deproxyURL($url,$givenFlag);}