ocPortal Developer's Guide: Core support functions (2)
» Return to Contents
support.php contains further support functions, which are shared between the installer and the main installation (i.e. global.php and global2.php are not used by the installer, and the installer emulates these functions functionality via minikernel.php).
sources/support.php
Global_functions_support.php
Function summary
|
void
|
init__support ()
|
|
?array
|
find_template_place (ID_TEXT codename, ?LANGUAGE_NAME lang, ID_TEXT theme, string suffix, string type)
|
|
BINARY
|
is_wide_high ()
|
|
BINARY
|
is_wide ()
|
|
integer
|
ocp_mb_strlen (string in)
|
|
~string
|
ocp_mb_substr (string in, integer from, ?integer amount, boolean force)
|
|
string
|
ocp_mb_strtolower (string in)
|
|
string
|
ocp_mb_strtoupper (string in)
|
|
boolean
|
is_writable_wrap (PATH path)
|
|
void
|
intelligent_write_error (PATH path)
|
|
tempcode
|
intelligent_write_error_inline (PATH path)
|
|
boolean
|
fractional_edit ()
|
|
integer
|
strlen_sort (string a, string b)
|
|
boolean
|
has_no_forum ()
|
|
boolean
|
addon_installed (ID_TEXT addon)
|
|
string
|
float_to_raw_string (float num, integer decs_wanted, boolean only_needed_decs)
|
|
string
|
float_format (float val, integer frac_digits)
|
|
string
|
integer_format (integer val)
|
|
integer
|
multi_sort (array a, array b)
|
|
void
|
ocf_require_all_forum_stuff ()
|
|
tempcode
|
globalise (tempcode middle, ?mixed message, string type, boolean include_header_and_footer)
|
|
~string
|
ocp_tempnam (string prefix)
|
|
object
|
make_xhtml_strict (object global)
|
|
mixed
|
array_peek (array array, integer depth_down)
|
|
string
|
fix_id (string param)
|
|
boolean
|
match_key_match (string match_tag, boolean support_post)
|
|
ID_TEXT
|
get_page_name ()
|
|
array
|
list_to_map (string map_value, array list)
|
|
array
|
collapse_2d_complexity (string key, string value, array list)
|
|
array
|
collapse_1d_complexity (string key, array list)
|
|
string
|
ocp_srv (string key)
|
|
boolean
|
is_valid_ip (IP ip)
|
|
IP
|
get_ip_address (integer amount)
|
|
string
|
get_browser_string ()
|
|
string
|
get_os_string ()
|
|
boolean
|
cron_installed ()
|
|
?string
|
geolocate_ip (?IP ip)
|
|
boolean
|
compare_ip_address (string wild, IP full)
|
|
boolean
|
compare_ip_address_ip4 (string wild, array full_parts)
|
|
boolean
|
compare_ip_address_ip6 (string wild, array full_parts)
|
|
tempcode
|
get_flagrant ()
|
|
void
|
log_it (ID_TEXT type, ?SHORT_TEXT a, ?SHORT_TEXT b)
|
|
void
|
syndicate_described_activity (string a_language_string_code, string a_label_1, string a_label_2, string a_label_3, string a_pagelink_1, string a_pagelink_2, string a_pagelink_3, string a_addon, BINARY a_is_public, ?MEMBER a_member_id, boolean sitewide_too, ?MEMBER also_involving)
|
|
boolean
|
has_external_site_wide_syndication ()
|
|
tempcode
|
get_syndication_option_fields ()
|
|
string
|
php_addslashes (string in)
|
|
array
|
remove_duplicate_rows (array rows, string id_field)
|
|
void
|
member_tracking_update ()
|
|
?array
|
get_members_viewing (?ID_TEXT page, ?ID_TEXT type, ?SHORT_TEXT id, boolean forum_layer)
|
|
boolean
|
is_invisible ()
|
|
integer
|
get_num_users_site ()
|
|
integer
|
get_num_users_peak ()
|
|
string
|
escape_html (mixed string)
|
|
URLPATH
|
brand_base_url ()
|
|
boolean
|
browser_matches (string code)
|
|
boolean
|
is_mobile (?string user_agent, boolean truth)
|
|
?string
|
get_bot_type ()
|
|
SHORT_TEXT
|
read_multi_code (ID_TEXT param)
|
|
string
|
flatten_slashed_array (array array)
|
|
string
|
wordfilter_text (string text)
|
|
string
|
xmlentities (string string, integer quote_style)
|
|
boolean
|
has_cookies ()
|
|
boolean
|
has_js ()
|
|
string
|
get_rand_password ()
|
|
?mixed
|
mixed ()
|
|
array
|
seo_meta_get_for (ID_TEXT type, ID_TEXT id)
|
|
void
|
seo_meta_load_for (ID_TEXT type, ID_TEXT id, ?string title)
|
|
tempcode
|
get_loaded_tags (?ID_TEXT limit_to, ?array the_tags)
|
|
ID_TEXT
|
get_zone_default_page (ID_TEXT zone_name)
|
|
SHORT_TEXT
|
best_hash (SHORT_TEXT to_hash, SHORT_TEXT salt)
|
|
boolean
|
check_master_password (SHORT_TEXT password_given)
|
|
ID_TEXT
|
produce_salt ()
|
|
ID_TEXT
|
get_site_salt ()
|
|
string
|
titleify (ID_TEXT boring)
|
void init__support()
Standard code module initialisation function.
Parameters…
(No return value)
function init__support()
{
global $PAGE_NAME_CACHE,$GETTING_PAGE_NAME;
$PAGE_NAME_CACHE=NULL;
$GETTING_PAGE_NAME=false;
global $IS_MOBILE,$IS_MOBILE_TRUTH;
$IS_MOBILE=NULL;
$IS_MOBILE_TRUTH=NULL;
// Heavily optimised! Ended up with preg_replace after trying lots of things
global $HTML_ESCAPE_1,$HTML_ESCAPE_1_STRREP,$HTML_ESCAPE_2;
$HTML_ESCAPE_1=array('/&/'/*,'/ì/','/î/'*/,'/"/','/\'/','/</','/>/'/*,'/£/'*/);
$HTML_ESCAPE_1_STRREP=array('&'/*,'ì','î'*/,'"','\'','<','>'/*,'£'*/);
$HTML_ESCAPE_2=array('&'/*,'"','"'*/,'"',''','<','>'/*,'£'*/);
global $BOT_MAP,$CACHE_BOT_TYPE;
$BOT_MAP=NULL;
$CACHE_BOT_TYPE=false;
global $LOCALE_FILTER;
$LOCALE_FILTER=NULL;
global $HAS_COOKIES;
$HAS_COOKIES=NULL;
global $BROWSER_MATCHES_CACHE;
$BROWSER_MATCHES_CACHE=array();
$GLOBALS['MSN_DB']=NULL;
// This is like NULL, but is a higher-precedence NULL that can also survive string layers (such as HTML forms). It should only be used when:
// - 'NULL' or '' or '-1' aren't appropriate (although '-1' is only appropriate when dealing with numbers held in strings, really).
// - OR, as the standard "ignore this field" indicator for query_update (so that "fractional edits" can happen without requiring a secondary API set or a messed up primary API)
if (!defined('STRING_MAGIC_NULL')) define('STRING_MAGIC_NULL','!--:)abcUNLIKELY');
// This is similar, but for integers. As before, it should only be used when NULL and -1 aren't appropiate OR as the "ignore this field" indicator.
if (!defined('INTEGER_MAGIC_NULL')) define('INTEGER_MAGIC_NULL',1634817353); // VERY unlikely to occur, but is both a 32bit unsigned and a 32 bit signed number
global $ZONE_DEFAULT_PAGES;
$ZONE_DEFAULT_PAGES=array();
global $PHP_REP_FROM,$PHP_REP_TO,$PHP_REP_TO_TWICE;
$PHP_REP_FROM=array('\\',"\n",'$','"');
$PHP_REP_TO=array('\\\\','\n','\$','\\"');
$PHP_REP_TO_TWICE=array('\\\\\\\\','\\n','\\\\$','\\\\\"');
global $IS_WIDE,$IS_WIDE_HIGH;
$IS_WIDE=NULL;
$IS_WIDE_HIGH=NULL;
global $ADDON_INSTALLED_CACHE;
$ADDON_INSTALLED_CACHE=array();
}
?array find_template_place(ID_TEXT codename, ?LANGUAGE_NAME lang, ID_TEXT theme, string suffix, string type)
Search for a template.
Parameters…
| Name |
codename |
| Description |
The codename of the template being loaded |
| Type |
ID_TEXT |
| Name |
lang |
| Description |
The language to load the template in (templates can embed language references) (NULL: users own language) |
| Type |
?LANGUAGE_NAME |
| Name |
theme |
| Description |
The theme to use |
| Type |
ID_TEXT |
| Name |
suffix |
| Description |
File type suffix of template file (e.g. .tpl) |
| Type |
string |
| Name |
type |
| Description |
Subdirectory type to look in |
| Type |
string |
| Values restricted to |
templates css |
Returns…
| Description |
List of parameters needed for the _do_template function to be able to load the template (NULL: could not find the template) |
| Type |
?array |
function find_template_place($codename,$lang,$theme,$suffix,$type)
{
global $FILE_ARRAY,$CURRENT_SHARE_USER;
static $tp_cache=array();
$sz=serialize(array($codename,$lang,$theme,$suffix,$type));
if (isset($tp_cache[$sz])) return $tp_cache[$sz];
$prefix_default=get_file_base().'/themes/';
$prefix=($theme=='default')?$prefix_default:(get_custom_file_base().'/themes/');
if (!isset($FILE_ARRAY))
{
if ((is_file($prefix.$theme.'/'.$type.'_custom/'.$codename.$suffix)) && (!in_safe_mode()))
$place=array($theme,'/'.$type.'_custom/');
elseif (is_file($prefix.$theme.'/'.$type.'/'.$codename.$suffix))
$place=array($theme,'/'.$type.'/');
elseif (($CURRENT_SHARE_USER!==NULL) && ($theme!='default') && (is_file(get_file_base().'/themes/'.$theme.'/'.$type.'_custom/'.$codename.$suffix)))
$place=array($theme,'/'.$type.'_custom/');
elseif (($CURRENT_SHARE_USER!==NULL) && ($theme!='default') && (is_file(get_file_base().'/themes/'.$theme.'/'.$type.'/'.$codename.$suffix)))
$place=array($theme,'/'.$type.'/');
elseif (($CURRENT_SHARE_USER!==NULL) && (is_file(get_custom_file_base().'/themes/default/'.$type.'_custom/'.$codename.$suffix)))
$place=array('default','/'.$type.'_custom/');
elseif (($CURRENT_SHARE_USER!==NULL) && (is_file(get_custom_file_base().'/themes/default/'.$type.'/'.$codename.$suffix)))
$place=array('default','/'.$type.'/');
elseif ((is_file($prefix_default.'default'.'/'.$type.'_custom/'.$codename.$suffix)) && (!in_safe_mode()))
$place=array('default','/'.$type.'_custom/');
elseif (is_file($prefix_default.'default'.'/'.$type.'/'.$codename.$suffix))
$place=array('default','/'.$type.'/');
else $place=NULL;
if ($place===NULL) // Get desparate, search in themes other than current and default
{
$dh=opendir(get_file_base().'/themes');
while (($possible_theme=readdir($dh)))
{
if ((substr($possible_theme,0,1)!='.') && ($possible_theme!='default') && ($possible_theme!=$theme) && ($possible_theme!='map.ini') && ($possible_theme!='index.html'))
{
$fullpath=get_custom_file_base().'/themes/'.$possible_theme.'/'.$type.'_custom/'.$codename.$suffix;
if (is_file($fullpath))
{
$place=array($possible_theme,'/'.$type.'_custom/');
break;
}
}
}
closedir($dh);
}
} else
{
$place=array('default','/'.$type.'/');
}
$tp_cache[$sz]=$place;
return $place;
}
BINARY is_wide_high()
Find whether panels and the header/footer areas won't be shown.
Parameters…
Returns…
| Description |
Result. |
| Type |
BINARY |
function is_wide_high()
{
global $IS_WIDE_HIGH;
if ($IS_WIDE_HIGH!==NULL) return $IS_WIDE_HIGH;
$IS_WIDE_HIGH=get_param_integer('wide_high',get_param_integer('keep_wide_high',get_param_integer('wide_print',0)));
return $IS_WIDE_HIGH;
}
BINARY is_wide()
Find whether panels will be shown.
Parameters…
Returns…
| Description |
Result. |
| Type |
BINARY |
function is_wide()
{
global $IS_WIDE;
if ($IS_WIDE!==NULL) return $IS_WIDE;
global $ZONE;
$IS_WIDE=get_param_integer('wide',get_param_integer('keep_wide',(is_wide_high()==1)?1:$ZONE['zone_wide']));
if ($IS_WIDE==0) return 0;
// Need to check it is allowed
$theme=$GLOBALS['FORUM_DRIVER']->get_theme();
$ini_path=(($theme=='default')?get_file_base():get_custom_file_base()).'/themes/'.$theme.'/theme.ini';
if (is_file($ini_path))
{
require_code('files');
$details=better_parse_ini_file($ini_path);
if ((isset($details['supports_wide'])) && ($details['supports_wide']=='0'))
{
$IS_WIDE=0;
return $IS_WIDE;
}
}
return $IS_WIDE;
}
integer ocp_mb_strlen(string in)
Get string length, with utf-8 awareness where possible/required.
Parameters…
| Name |
in |
| Description |
The string to get the length of. |
| Type |
string |
Returns…
| Description |
The string length. |
| Type |
integer |
function ocp_mb_strlen($in)
{
if (strtolower(get_charset())!='utf-8') return strlen($in);
if (function_exists('mb_strlen')) return @mb_strlen($in); // @ is because there could be invalid unicode involved
if (function_exists('iconv_strlen')) return @iconv_strlen($in);
return strlen($in);
}
~string ocp_mb_substr(string in, integer from, ?integer amount, boolean force)
Return part of a string, with utf-8 awareness where possible/required.
Parameters…
| Name |
in |
| Description |
The subject. |
| Type |
string |
| Name |
from |
| Description |
The start position. |
| Type |
integer |
| Name |
amount |
| Description |
The length to extract (NULL: all remaining). |
| Default value |
|
| Type |
?integer |
| Name |
force |
| Description |
Whether to force unicode as on. |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
String part (false: $start was over the end of the string). |
| Type |
~string |
function ocp_mb_substr($in,$from,$amount=NULL,$force=false)
{
if (is_null($amount)) $amount=ocp_mb_strlen($in)-$from;
if ((!$force) && (strtolower(get_charset())!='utf-8')) return substr($in,$from,$amount);
if (function_exists('iconv_substr')) return @iconv_substr($in,$from,$amount);
if (function_exists('mb_substr')) return @mb_substr($in,$from,$amount);
$ret=substr($in,$from,$amount);
$end=ord(substr($ret,-1));
if (($end>=192) && ($end<=223)) $ret.=substr($in,$from+$amount,1);
if ($from!=0)
{
$start=ord(substr($ret,0,1));
if (($start>=192) && ($start<=223)) $ret=substr($in,$from-1,1).$ret;
}
return $ret;
}
string ocp_mb_strtolower(string in)
Make a string lowercase, with utf-8 awareness where possible/required.
Parameters…
| Name |
in |
| Description |
Subject. |
| Type |
string |
Returns…
| Description |
Result. |
| Type |
string |
function ocp_mb_strtolower($in)
{
if (strtolower(get_charset())!='utf-8') return strtolower($in);
if (function_exists('mb_strtolower')) return mb_strtolower($in);
return strtolower($in);
}
string ocp_mb_strtoupper(string in)
Make a string uppercase, with utf-8 awareness where possible/required.
Parameters…
| Name |
in |
| Description |
Subject. |
| Type |
string |
Returns…
| Description |
Result. |
| Type |
string |
function ocp_mb_strtoupper($in)
{
if (strtoupper(get_charset())!='utf-8') return strtoupper($in);
if (function_exists('mb_strtoupper')) return mb_strtoupper($in);
return strtoupper($in);
}
boolean is_writable_wrap(PATH path)
Find whether a file/directory is writeable. This function is designed to get past that the PHP is_writable function does not work properly on Windows.
Parameters…
| Name |
path |
| Description |
The file path |
| Type |
PATH |
Returns…
| Description |
Whether the file is writeable |
| Type |
boolean |
function is_writable_wrap($path)
{
if (strtoupper(substr(PHP_OS,0,3))!='WIN') return is_writable($path);
if (!file_exists($path)) return false;
if (is_dir($path))
{
/*if (false) // ideal, but too dangerous as sometimes you can write files but not delete again
{
$test=@fopen($path.'/ocp.delete.me','wt');
if ($test!==false)
{
fclose($test);
unlink($path.'/ocp.delete.me');
return true;
}
return false;
}*/
return is_writable($path); // imperfect unfortunately; but unlikely to cause a problem
} else
{
$test=@fopen($path,'ab');
if ($test!==false)
{
fclose($test);
return true;
}
return false;
}
}
void intelligent_write_error(PATH path)
Discern the cause of a file-write error, and show an appropriate error message.
Parameters…
| Name |
path |
| Description |
File path that could not be written |
| Type |
PATH |
(No return value)
function intelligent_write_error($path)
{
if (file_exists($path))
{
warn_exit(do_lang_tempcode('WRITE_ERROR',escape_html($path)));
}
elseif (file_exists(dirname($path)))
{
if (strpos($path,'/templates_cached/')!==false) critical_error('PASSON',do_lang('WRITE_ERROR_CREATE',escape_html($path),escape_html(dirname($path))));
warn_exit(do_lang_tempcode('WRITE_ERROR_CREATE',escape_html($path),escape_html(dirname($path))));
} else
{
warn_exit(do_lang_tempcode('WRITE_ERROR_MISSING_DIRECTORY',escape_html(dirname($path)),escape_html(dirname(dirname($path)))));
}
}
tempcode intelligent_write_error_inline(PATH path)
Discern the cause of a file-write error, and return an appropriate error message.
Parameters…
| Name |
path |
| Description |
File path that could not be written |
| Type |
PATH |
Returns…
| Description |
Message |
| Type |
tempcode |
function intelligent_write_error_inline($path)
{
if (file_exists($path))
return do_lang_tempcode('WRITE_ERROR',escape_html($path));
elseif (file_exists(dirname($path)))
return do_lang_tempcode('WRITE_ERROR_CREATE',escape_html($path),escape_html(dirname($path)));
else
return do_lang_tempcode('WRITE_ERROR_MISSING_DIRECTORY',escape_html(dirname($path)),escape_html(dirname(dirname($path))));
return new ocp_tempcode();
}
boolean fractional_edit()
Find whether a fractional edit is underway.
Parameters…
Returns…
| Description |
Whether a fractional edit is underway |
| Type |
boolean |
function fractional_edit()
{
return post_param_integer('fractional_edit',0)==1;
}
integer strlen_sort(string a, string b)
Helper function for usort to sort a list by string length.
Parameters…
| Name |
a |
| Description |
The first string to compare |
| Type |
string |
| Name |
b |
| Description |
The second string to compare |
| Type |
string |
Returns…
| Description |
The comparison result (0 for equal, -1 for less, 1 for more) |
| Type |
integer |
function strlen_sort($a,$b)
{
if (!isset($a)) $a='';
if (!isset($b)) $b='';
if ($a==$b) return 0;
if (!is_string($a))
{
global $M_SORT_KEY;
return (strlen($a[$M_SORT_KEY])<strlen($b[$M_SORT_KEY]))?-1:1;
}
return (strlen($a)<strlen($b))?-1:1;
}
boolean has_no_forum()
Find whether we have no forum on this website.
Parameters…
Returns…
| Description |
Whether we have no forum on this website |
| Type |
boolean |
function has_no_forum()
{
if (get_forum_type()=='none') return true;
if ((get_forum_type()=='ocf') && (!addon_installed('ocf_forum'))) return true;
return false;
}
boolean addon_installed(ID_TEXT addon)
Check to see if an addon is installed. This only works with addons written with addon_registry hooks, which is all the bundled ocPortal addons; it is unlikely to work with third-party addons.
Parameters…
| Name |
addon |
| Description |
The module name |
| Type |
ID_TEXT |
Returns…
| Description |
Whether it is |
| Type |
boolean |
function addon_installed($addon)
{
global $ADDON_INSTALLED_CACHE;
if ($ADDON_INSTALLED_CACHE==array())
{
if (function_exists('persistant_cache_get')) $ADDON_INSTALLED_CACHE=persistant_cache_get('ADDONS_INSTALLED');
}
if (isset($ADDON_INSTALLED_CACHE[$addon])) return $ADDON_INSTALLED_CACHE[$addon];
$answer=is_file(get_file_base().'/sources/hooks/systems/addon_registry/'.filter_naughty($addon).'.php') || is_file(get_file_base().'/sources_custom/hooks/addon_registry/'.filter_naughty($addon).'.php');
$ADDON_INSTALLED_CACHE[$addon]=$answer;
if (function_exists('persistant_cache_set')) persistant_cache_set('ADDONS_INSTALLED',$ADDON_INSTALLED_CACHE,true);
return $answer;
}
string float_to_raw_string(float num, integer decs_wanted, boolean only_needed_decs)
Convert a float to a "technical string representation of a float".
Parameters…
| Name |
num |
| Description |
The number |
| Type |
float |
| Name |
decs_wanted |
| Description |
The number of decimals to keep |
| Default value |
2 |
| Type |
integer |
| Name |
only_needed_decs |
| Description |
Whether to trim trailing zeros |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
The string converted |
| Type |
string |
function float_to_raw_string($num,$decs_wanted=2,$only_needed_decs=false)
{
$str=number_format($num,5,'.','');
$decs_here=strlen($str)-strpos($str,'.')-1;
if ($decs_here<$decs_wanted)
{
for ($i=0;$i<$decs_wanted-$decs_here;$i++)
{
$str.='0';
}
} else
{
$str=substr($str,0,strlen($str)-$decs_here+$decs_wanted);
if ($decs_wanted==0) $str=rtrim($str,'.');
}
if ($only_needed_decs) $str=preg_replace('#\.$#','',preg_replace('#0+$#','',$str));
return $str;
}
string float_format(float val, integer frac_digits)
Format the given float number as a nicely formatted string.
Parameters…
| Name |
val |
| Description |
The value to format |
| Type |
float |
| Name |
frac_digits |
| Description |
The number of fractional digits |
| Default value |
2 |
| Type |
integer |
Returns…
| Description |
Nicely formatted string |
| Type |
string |
function float_format($val,$frac_digits=2)
{
$locale=function_exists('localeconv')?localeconv():array('decimal_point'=>'.','thousands_sep'=>',');
//$frac_digits=$locale['frac_digits']; // This seems to not work on all PHP configurations
if ($locale['thousands_sep']=='') $locale['thousands_sep']=',';
return number_format($val,$frac_digits,$locale['decimal_point'],$locale['thousands_sep']);
}
string integer_format(integer val)
Format the given integer number as a nicely formatted string.
Parameters…
| Name |
val |
| Description |
The value to format |
| Type |
integer |
Returns…
| Description |
Nicely formatted string |
| Type |
string |
function integer_format($val)
{
$locale=function_exists('localeconv')?localeconv():array('decimal_point'=>'.','thousands_sep'=>',');
if ($locale['thousands_sep']=='') $locale['thousands_sep']=',';
return number_format($val,0,$locale['decimal_point'],$locale['thousands_sep']);
}
integer multi_sort(array a, array b)
Helper function to sort a list of maps by the value at $key in each of those maps.
Parameters…
| Name |
a |
| Description |
The first to compare |
| Type |
array |
| Name |
b |
| Description |
The second to compare |
| Type |
array |
Returns…
| Description |
The comparison result (0 for equal, -1 for less, 1 for more) |
| Type |
integer |
function multi_sort($a,$b)
{
global $M_SORT_KEY;
$keys=explode(',',is_string($M_SORT_KEY)?$M_SORT_KEY:strval($M_SORT_KEY));
$first_key=$keys[0];
if ($first_key[0]=='!') $first_key=substr($first_key,1);
if ((is_string($a[$first_key])) || (is_object($a[$first_key])))
{
$ret=0;
do
{
$key=array_shift($keys);
$av=$a[$key];
$bv=$b[$key];
// If calling, must put an "@" around the uasort call because of a PHP bug
if (is_object($av)) $av=$av->evaluate();
if (is_object($bv)) $bv=$bv->evaluate();
if ($key[0]=='!') // Flip around
{
$key=substr($key,1);
$ret=-strnatcasecmp($av,$bv);
} else
{
$ret=strnatcasecmp($av,$bv);
}
}
while ((count($keys)!=0) && ($ret==0));
return $ret;
}
do
{
$key=array_shift($keys);
if ($key[0]=='!') // Flip around
{
$key=substr($key,1);
$ret=($a[$key]>$b[$key])?-1:(($a[$key]==$b[$key])?0:1);
} else
{
$ret=($a[$key]>$b[$key])?1:(($a[$key]==$b[$key])?0:-1);
}
}
while ((count($keys)!=0) && ($ret==0));
return $ret;
}
void ocf_require_all_forum_stuff()
Require all code relating to the OCF forum
Parameters…
(No return value)
function ocf_require_all_forum_stuff()
{
require_lang('ocf');
require_code('ocf_members');
require_code('ocf_topics');
require_code('ocf_posts');
require_code('ocf_moderation');
require_code('ocf_groups');
require_code('ocf_forums');
require_code('ocf_general');
}
tempcode globalise(tempcode middle, ?mixed message, string type, boolean include_header_and_footer)
Turn the tempcode lump into a standalone page (except for header/footer which is assumed already handled elsewhere).
Parameters…
| Name |
middle |
| Description |
The tempcode to put into a nice frame |
| Type |
tempcode |
| Name |
message |
| Description |
'Additional' message (NULL: none) |
| Default value |
|
| Type |
?mixed |
| Name |
type |
| Description |
The type of special message |
| Default value |
|
| Type |
string |
| Values restricted to |
inform warn "" |
| Name |
include_header_and_footer |
| Description |
Whether to automatically include the header and footer templates |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Standalone page |
| Type |
tempcode |
function globalise($middle,$message=NULL,$type='',$include_header_and_footer=false)
{
require_code('site');
global $DONE_HEADER;
global $CYCLES; $CYCLES=array(); // Here we reset some Tempcode environmental stuff, because template compilation or preprocessing may have dirtied things
if ($GLOBALS['HELPER_PANEL_TUTORIAL']===NULL) $GLOBALS['HELPER_PANEL_TUTORIAL']='';
if ($GLOBALS['HELPER_PANEL_HTML']===NULL) $GLOBALS['HELPER_PANEL_HTML']='';
if ($GLOBALS['HELPER_PANEL_TEXT']===NULL) $GLOBALS['HELPER_PANEL_TEXT']='';
if ($GLOBALS['HELPER_PANEL_PIC']===NULL) $GLOBALS['HELPER_PANEL_PIC']='';
$_message=($message!==NULL)?do_template('ADDITIONAL',array('_GUID'=>'b4c9f0a0bbfb9344d00c29db8ff5715d','TYPE'=>$type,'MESSAGE'=>$message)):new ocp_tempcode();
if (get_option('show_docs')=='0') $GLOBALS['HELPER_PANEL_TUTORIAL']='';
$global=new ocp_tempcode();
$bail_out=(isset($DONE_HEADER) && $DONE_HEADER);
if (($include_header_and_footer) && (!$bail_out)) $global->attach(do_header());
$global->attach(do_template('GLOBAL',array('_GUID'=>'592faa2c0e8bf2dc3492de2c11ca7131','HELPER_PANEL_TUTORIAL'=>$GLOBALS['HELPER_PANEL_TUTORIAL'],'HELPER_PANEL_HTML'=>$GLOBALS['HELPER_PANEL_HTML'],'HELPER_PANEL_TEXT'=>$GLOBALS['HELPER_PANEL_TEXT'],'HELPER_PANEL_PIC'=>$GLOBALS['HELPER_PANEL_PIC'],'MESSAGE_TOP'=>$GLOBALS['ATTACHED_MESSAGES'],'MESSAGE'=>$_message,'MIDDLE'=>$middle,'BREADCRUMBS'=>breadcrumbs())));
if ($include_header_and_footer) $global->attach(do_footer($bail_out));
$global->handle_symbol_preprocessing();
if (get_value('xhtml_strict')==='1')
{
$global=make_xhtml_strict($global);
}
return $global;
}
~string ocp_tempnam(string prefix)
Create file with unique file name, but works around compatibility issues between servers.
Parameters…
| Name |
prefix |
| Description |
The prefix of the temporary file name. |
| Type |
string |
Returns…
| Description |
The name of the temporary file (false: error). |
| Type |
~string |
function ocp_tempnam($prefix)
{
$problem_saving=((ini_get('safe_mode')=='1') || ((@strval(ini_get('open_basedir'))!='') && (preg_match('#(^|:|;)/tmp($|:|;|/)#',ini_get('open_basedir'))==0)));
$local_path=get_custom_file_base().'/safe_mode_temp/';
$server_path='/tmp/';
$tmp_path=$problem_saving?$local_path:$server_path;
$tempnam=tempnam($tmp_path,$prefix);
if (($tempnam===false) && (!$problem_saving))
{
$problem_saving=true;
$tempnam=tempnam($local_path,$prefix);
}
return $tempnam;
}
object make_xhtml_strict(object global)
Take a Tempcode object and run some hackerish code to make it XHTML-strict.
Parameters…
| Name |
global |
| Description |
Tempcode object |
| Type |
object |
Returns…
| Description |
Tempcode object (no longer cache safe) |
| Type |
object |
function make_xhtml_strict($global)
{
$_global=$global->evaluate();
$_global=str_replace(
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
$_global);
$_global=preg_replace('#(<a\s[^>]*)onclick="([^"]*)"(\s[^>]*)target="_blank"#','${1}onclick="this.target=\'_blank\'; ${2}"${3}',$_global);
$_global=preg_replace('#(<a\s[^>]*)target="_blank"(\s[^>]*)onclick="([^"]*)"#','${1}onclick="this.target=\'_blank\'; ${3}"${2}',$_global);
$_global=preg_replace('#(<a\s[^>]*)target="_blank"#','${1}onclick="this.target=\'_blank\';"',$_global);
$_global=preg_replace('#(<form\s[^>]*)onsubmit="([^"]*)"(\s[^>]*)target="_blank"#','${1}onsubmit="this.target=\'_blank\'; ${2}"${3}',$_global);
$_global=preg_replace('#(<form\s[^>]*)target="_blank"(\s[^>]*)onsubmit="([^"]*)"#','${1}onsubmit="this.target=\'_blank\'; ${3}"${2}',$_global);
$_global=preg_replace('#(<form\s[^>]*)target="_blank"#','${1}onsubmit="this.target=\'_blank\';"',$_global);
$_global=preg_replace('#(<(a|form)\s[^>]*)target="[^"]*"#','${1}',$_global);
return make_string_tempcode($_global);
}
mixed array_peek(array array, integer depth_down)
Peek at a stack element.
Parameters…
| Name |
array |
| Description |
The stack to peek in |
| Type |
array |
| Name |
depth_down |
| Description |
The depth into the stack we are peaking |
| Default value |
1 |
| Type |
integer |
Returns…
| Description |
The result of the peeking |
| Type |
mixed |
function array_peek($array,$depth_down=1)
{
$count=count($array);
if ($count-$depth_down<0) return NULL;
return $array[$count-$depth_down];
}
string fix_id(string param)
Make a value suitable for use in an XML ID.
Parameters…
| Name |
param |
| Description |
The value to escape |
| Type |
string |
Returns…
| Description |
The escaped value |
| Type |
string |
function fix_id($param)
{
return str_replace('[','_opensquare_',str_replace(']','_closesquare_',str_replace(''','_apostophe_',str_replace('\'','_apostophe_',str_replace('-','_minus_',str_replace(' ','_space_',str_replace('+','_plus_',str_replace('*','_star_',str_replace('/','__',$param)))))))));
}
boolean match_key_match(string match_tag, boolean support_post)
See if the current URL matches the given ocPortal match tags.
Parameters…
| Name |
match_tag |
| Description |
Match tags |
| Type |
string |
| Name |
support_post |
| Description |
Check against POSTed data too |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Whether there is a match |
| Type |
boolean |
function match_key_match($match_tag,$support_post=false)
{
$req_func=$support_post?'either_param':'get_param';
$potentials=explode(',',$match_tag);
foreach ($potentials as $potential)
{
$parts=explode(':',$potential);
if (($parts[0]=='_WILD') || ($parts[0]=='_SEARCH')) $parts[0]=get_zone_name();
if ((!array_key_exists(1,$parts)) || ($parts[1]=='_WILD')) $parts[1]=get_page_name();
if (($parts[0]=='site') && (get_option('collapse_user_zones')=='1')) $parts[0]='';
$zone_matches=(($parts[0]==get_zone_name()) || ((strpos($parts[0],'*')!==false) && (simulated_wildcard_match(get_zone_name(),$parts[0],true))));
$page_matches=(($parts[1]==get_page_name()) || ((strpos($parts[1],'*')!==false) && (simulated_wildcard_match(get_page_name(),$parts[1],true))));
if (($zone_matches) && ($page_matches))
{
$bad=false;
for ($i=2;$i<count($parts);$i++)
{
if ($parts[$i]!='')
{
if (($i==2) && (strpos($parts[$i],'=')===false))
{
$parts[$i]='type='.$parts[$i];
}
elseif (($i==3) && (strpos($parts[$i],'=')===false))
{
$parts[$i]='id='.$parts[$i];
}
}
$subparts=explode('=',$parts[$i]);
if ((count($subparts)!=2) || (call_user_func_array($req_func,array($subparts[0],'misc'))!=$subparts[1]))
{
$bad=true;
continue;
}
}
if (!$bad) return true;
}
}
return false;
}
ID_TEXT get_page_name()
Get the name of the current page
Parameters…
Returns…
| Description |
The current page name |
| Type |
ID_TEXT |
function get_page_name()
{
global $PAGE_NAME_CACHE;
if (isset($PAGE_NAME_CACHE)) return $PAGE_NAME_CACHE;
global $ZONE,$GETTING_PAGE_NAME;
if ($GETTING_PAGE_NAME) return 'unknown';
$GETTING_PAGE_NAME=true;
$page=get_param('page','');
if (strlen($page)>80)
{
warn_exit(do_lang_tempcode('INTERNAL_ERROR'));
}
if (($page=='') && ($ZONE!==NULL))
{
$page=ocp_srv('QUERY_STRING');
if ((strpos($page,'=')!==false) || ($page==''))
{
$page=$ZONE['zone_default_page'];
if ($page===NULL) $page='';
}
}
$page=filter_naughty($page);
if ($ZONE!==NULL) $PAGE_NAME_CACHE=$page;
$GETTING_PAGE_NAME=false;
return $page;
}
array list_to_map(string map_value, array list)
Take a list of maps, and make one of the values of each array the index of a map to the map
Parameters…
| Name |
map_value |
| Description |
The key key of our maps that reside in our map |
| Type |
string |
| Name |
list |
| Description |
The list of maps |
| Type |
array |
Returns…
| Description |
The collapsed map |
| Type |
array |
function list_to_map($map_value,$list)
{
$i=0;
$new_map=array();
foreach ($list as $map)
{
$key=$map[$map_value];
$new_map[$key]=$map;
$i++;
}
if ($i>0) return $new_map;
return array();
}
array collapse_2d_complexity(string key, string value, array list)
Take a list of maps of just two elements, and make it into a single map
Parameters…
| Name |
key |
| Description |
The key key of our maps that reside in our map |
| Type |
string |
| Name |
value |
| Description |
The value key of our maps that reside in our map |
| Type |
string |
| Name |
list |
| Description |
The map of maps |
| Type |
array |
Returns…
| Description |
The collapsed map |
| Type |
array |
function collapse_2d_complexity($key,$value,$list)
{
$new_map=array();
foreach ($list as $map)
{
$new_map[$map[$key]]=$map[$value];
}
return $new_map;
}
array collapse_1d_complexity(string key, array list)
Take a list of maps of just one element, and make it into a single map
Parameters…
| Name |
key |
| Description |
The key of our maps that reside in our map |
| Type |
string |
| Name |
list |
| Description |
The map of maps |
| Type |
array |
Returns…
| Description |
The collapsed map |
| Type |
array |
function collapse_1d_complexity($key,$list)
{
$new_map=array();
foreach ($list as $map)
{
$new_map[]=$map[$key];
}
return $new_map;
}
string ocp_srv(string key)
Get server environment variables.
Parameters…
| Name |
key |
| Description |
The variable name |
| Type |
string |
Returns…
| Description |
The variable value ('' means unknown) |
| Type |
string |
function ocp_srv($key)
{
if (isset($_SERVER[$key])) return /*stripslashes*/($_SERVER[$key]);
if ((isset($_ENV)) && (isset($_ENV[$key]))) return /*stripslashes*/($_ENV[$key]);
if ($key=='HTTP_HOST')
{
return 'localhost';
}
if ($key=='SERVER_ADDR')
{
return ocp_srv('LOCAL_ADDR');
}
return '';
}
boolean is_valid_ip(IP ip)
Find whether an IP address is valid
Parameters…
| Name |
ip |
| Description |
IP address to check. |
| Type |
IP |
Returns…
| Description |
Whether the IP address is valid. |
| Type |
boolean |
function is_valid_ip($ip)
{
if ($ip=='') return false;
$parts=array();
if (preg_match('#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#',$ip,$parts)!=0)
{
if (intval($parts[1])>255) return false;
if (intval($parts[2])>255) return false;
if (intval($parts[3])>255) return false;
if (intval($parts[4])>255) return false;
return true;
}
if (preg_match('#^[\d:a-fA-F]*$#',$ip)!=0)
{
return true;
}
return false;
}
IP get_ip_address(integer amount)
Attempt to get the IP address of the current user
Parameters…
| Name |
amount |
| Description |
The number of groups to include in the IP address (rest will be replaced with *'s). For IP6, this is doubled. |
| Default value |
4 |
| Type |
integer |
| Values restricted to |
1 2 3 4 |
Returns…
| Description |
The users IP address (blank: could not find a valid one) |
| Type |
IP |
function get_ip_address($amount=4)
{
// return strval(mt_rand(0,255)).'.'.strval(mt_rand(0,255)).'.'.strval(mt_rand(0,255)).'.'.strval(mt_rand(0,255)); // Nice little test for if sessions break
$fw=ocp_srv('HTTP_X_FORWARDED_FOR');
if (ocp_srv('HTTP_CLIENT_IP')!='') $fw=ocp_srv('HTTP_CLIENT_IP');
if (($fw!='') && ($fw!='127.0.0.1') && (substr($fw,0,8)!='192.168.') && (substr($fw,0,3)!='10.') && (is_valid_ip($fw)) && ($fw!=ocp_srv('SERVER_ADDR'))) $ip=$fw;
else $ip=ocp_srv('REMOTE_ADDR');
if (!is_valid_ip($ip)) return '';
// Bizarro-filter (found "in the wild")
$pos=strpos($ip,',');
if ($pos!==false) $ip=substr($ip,0,$pos);
$ip=preg_replace('#%14$#','',$ip);
if (strpos($ip,':')!==false)
{
if (substr_count($ip,':')<7)
{
$ip=str_replace('::',str_repeat(':',(7-substr_count($ip,':'))+2),$ip);
}
$parts=explode(':',$ip);
for ($i=0;$i<$amount*2;$i++)
{
$parts[$i]=isset($parts[$i])?str_pad($parts[$i],4,'0',STR_PAD_LEFT):'0000';
}
for ($i=$amount*2;$i<8;$i++)
{
$parts[$i]='*';
}
return implode(':',$parts);
} else
{
$parts=explode('.',$ip);
for ($i=0;$i<$amount;$i++)
{
if (!array_key_exists($i,$parts)) $parts[$i]='0';
}
for ($i=$amount;$i<4;$i++)
{
$parts[$i]='*';
}
return implode('.',$parts);
}
}
string get_browser_string()
Get a string of the users web browser
Parameters…
Returns…
| Description |
The web browser string |
| Type |
string |
function get_browser_string()
{
return ocp_srv('HTTP_USER_AGENT');
}
string get_os_string()
Get the user's operating system
Parameters…
Returns…
| Description |
The operating system string |
| Type |
string |
function get_os_string()
{
if (ocp_srv('HTTP_UA_OS')!='') return ocp_srv('HTTP_UA_OS');
elseif (ocp_srv('HTTP_USER_AGENT')!='')
{
// Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586)
// We need to get the stuff in the brackets
$matches=array();
if (preg_match('#\(([^\)]*)\)#',ocp_srv('HTTP_USER_AGENT'),$matches)!=0)
{
$ret=$matches[1];
$ret=preg_replace('#^compatible; (MSIE[^;]*; )?#','',$ret);
return $ret;
}
}
return '';
}
boolean cron_installed()
Find if Cron is installed
Parameters…
Returns…
| Description |
Whether Cron is installed |
| Type |
boolean |
function cron_installed()
{
$last_cron=get_value('last_cron');
if (is_null($last_cron)) return false;
return intval($last_cron)>(time()-60*60*5);
}
?string geolocate_ip(?IP ip)
Find the country an IP address long is located in
Parameters…
| Name |
ip |
| Description |
The IP to geolocate (NULL: current user's IP) |
| Default value |
|
| Type |
?IP |
Returns…
| Description |
The country initials (NULL: unknown) |
| Type |
?string |
function geolocate_ip($ip=NULL)
{
if (is_null($ip)) $ip=get_ip_address();
if (!addon_installed('stats')) return NULL;
$long_ip=ip2long($ip);
if ($long_ip===false) return NULL; // No IP6 support
$query='SELECT * FROM '.get_table_prefix().'ip_country WHERE begin_num<='.sprintf('%u',$long_ip).' AND end_num>='.sprintf('%u',$long_ip);
$results=$GLOBALS['SITE_DB']->query($query);
if (!array_key_exists(0,$results)) return NULL;
elseif (!is_null($results[0]['country'])) return $results[0]['country'];
else return NULL;
}
boolean compare_ip_address(string wild, IP full)
Compare two IP addresses for potential correlation. Not as simple as equality due to '*' syntax.
Parameters…
| Name |
wild |
| Description |
The general IP address that is potentially wildcarded |
| Type |
string |
| Name |
full |
| Description |
The specific IP address we are checking |
| Type |
IP |
Returns…
| Description |
Whether the IP addresses correlate |
| Type |
boolean |
function compare_ip_address($wild,$full)
{
$wild_parts=explode((strpos($full,'.')!==false)?'.':':',$wild);
$full_parts=explode((strpos($full,'.')!==false)?'.':':',$full);
foreach ($wild_parts as $i=>$wild_part)
{
if (($wild_part!='*') && ($wild_part!=$full_parts[$i])) return false;
}
return true;
}
boolean compare_ip_address_ip4(string wild, array full_parts)
Compare two IP addresses for potential correlation. Not as simple as equality due to '*' syntax. IP4-only variant
Parameters…
| Name |
wild |
| Description |
The general IP address that is potentially wildcarded |
| Type |
string |
| Name |
full_parts |
| Description |
The exploded parts of the specific IP address we are checking |
| Type |
array |
Returns…
| Description |
Whether the IP addresses correlate |
| Type |
boolean |
function compare_ip_address_ip4($wild,$full_parts)
{
$wild_parts=explode('.',$wild);
foreach ($wild_parts as $i=>$wild_part)
{
if (($wild_part!='*') && ($wild_part!=$full_parts[$i])) return false;
}
return true;
}
boolean compare_ip_address_ip6(string wild, array full_parts)
Compare two IP addresses for potential correlation. Not as simple as equality due to '*' syntax. IP6-only variant
Parameters…
| Name |
wild |
| Description |
The general IP address that is potentially wildcarded |
| Type |
string |
| Name |
full_parts |
| Description |
The exploded parts of the specific IP address we are checking |
| Type |
array |
Returns…
| Description |
Whether the IP addresses correlate |
| Type |
boolean |
function compare_ip_address_ip6($wild,$full_parts)
{
$wild_parts=explode(':',$wild);
foreach ($wild_parts as $i=>$wild_part)
{
if (($wild_part!='*') && ($wild_part!=$full_parts[$i])) return false;
}
return true;
}
tempcode get_flagrant()
Get the XHTML for the flagrant text message.
Parameters…
Returns…
| Description |
The flagrant text message |
| Type |
tempcode |
function get_flagrant()
{
if (!addon_installed('flagrant')) return new ocp_tempcode();
$system=(mt_rand(0,1)==0);
$_flagrant=NULL;
if (!$system)
{
$_flagrant=persistant_cache_get('FLAGRANT');
if ($_flagrant===NULL)
{
$flagrant=$GLOBALS['SITE_DB']->query_value_null_ok_full('SELECT the_message FROM '.get_table_prefix().'text WHERE active_now=1 AND activation_time+days*60*60*24<'.strval(time()),true/*in case tablemissing*/);
if ($flagrant===NULL)
{
persistant_cache_set('FLAGRANT',false);
} else
{
$_flagrant=get_translated_tempcode($flagrant);
persistant_cache_set('FLAGRANT',$_flagrant);
}
}
if ($_flagrant===false) $_flagrant=NULL;
}
if ($_flagrant===NULL)
{
return make_string_tempcode(get_option('system_flagrant'));
} else
{
return do_lang_tempcode('_COMMUNITY_MESSAGE',$_flagrant);
}
}
void log_it(ID_TEXT type, ?SHORT_TEXT a, ?SHORT_TEXT b)
Log an action
Parameters…
| Name |
type |
| Description |
The type of activity just carried out (a lang string) |
| Type |
ID_TEXT |
| Name |
a |
| Description |
The most important parameter of the activity (e.g. id) (NULL: none) |
| Default value |
|
| Type |
?SHORT_TEXT |
| Name |
b |
| Description |
A secondary (perhaps, human readable) parameter of the activity (e.g. caption) (NULL: none) |
| Default value |
|
| Type |
?SHORT_TEXT |
(No return value)
function log_it($type,$a=NULL,$b=NULL)
{
require_code('support2');
_log_it($type,$a,$b);
}
void syndicate_described_activity(string a_language_string_code, string a_label_1, string a_label_2, string a_label_3, string a_pagelink_1, string a_pagelink_2, string a_pagelink_3, string a_addon, BINARY a_is_public, ?MEMBER a_member_id, boolean sitewide_too, ?MEMBER also_involving)
Syndicate human-intended descriptions of activities performed to the internal wall, and external listeners.
Parameters…
| Name |
a_language_string_code |
| Description |
Language string code |
| Default value |
|
| Type |
string |
| Name |
a_label_1 |
| Description |
Label 1 (given as a parameter to the language string code) |
| Default value |
|
| Type |
string |
| Name |
a_label_2 |
| Description |
Label 2 (given as a parameter to the language string code) |
| Default value |
|
| Type |
string |
| Name |
a_label_3 |
| Description |
Label 3 (given as a parameter to the language string code) |
| Default value |
|
| Type |
string |
| Name |
a_pagelink_1 |
| Description |
Page link 1 |
| Default value |
|
| Type |
string |
| Name |
a_pagelink_2 |
| Description |
Page link 2 |
| Default value |
|
| Type |
string |
| Name |
a_pagelink_3 |
| Description |
Page link 3 |
| Default value |
|
| Type |
string |
| Name |
a_addon |
| Description |
Addon that caused the event |
| Default value |
|
| Type |
string |
| Name |
a_is_public |
| Description |
Whether this post should be public or friends-only |
| Default value |
1 |
| Type |
BINARY |
| Name |
a_member_id |
| Description |
Member being written for (NULL: current member) |
| Default value |
|
| Type |
?MEMBER |
| Name |
sitewide_too |
| Description |
Whether to push this out as a site event if user requested |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
also_involving |
| Description |
Member also 'intimately' involved, such as a content submitter who is a friend (NULL: none) |
| Default value |
|
| Type |
?MEMBER |
(No return value)
function syndicate_described_activity($a_language_string_code='',$a_label_1='',$a_label_2='',$a_label_3='',$a_pagelink_1='',$a_pagelink_2='',$a_pagelink_3='',$a_addon='',$a_is_public=1,$a_member_id=NULL,$sitewide_too=false,$also_involving=NULL)
{
if (running_script('install')) return;
$hooks=find_all_hooks('systems','activities');
foreach (array_keys($hooks) as $hook) // We only expect one actually
{
require_code('hooks/systems/activities/'.$hook);
$ob=object_factory('Activity_'.$hook);
register_shutdown_function(array($ob,'syndicate_described_activity'),$a_language_string_code,$a_label_1,$a_label_2,$a_label_3,$a_pagelink_1,$a_pagelink_2,$a_pagelink_3,$a_addon,$a_is_public,$a_member_id,$sitewide_too,$also_involving);
}
}
boolean has_external_site_wide_syndication()
Detect whether we have external site-wide syndication support somewhere.
Parameters…
Returns…
| Description |
Whether we do |
| Type |
boolean |
function has_external_site_wide_syndication()
{
$hooks=find_all_hooks('systems','activities');
$ret=false;
foreach (array_keys($hooks) as $hook) // We only expect one actually
{
require_code('hooks/systems/activities/'.$hook);
$ob=object_factory('Activity_'.$hook);
$ret=$ret || $ob->has_external_site_wide_syndication();
}
return $ret;
}
tempcode get_syndication_option_fields()
Get syndication field UI.
Parameters…
Returns…
| Description |
Syndication fields (or empty) |
| Type |
tempcode |
function get_syndication_option_fields()
{
$hooks=find_all_hooks('systems','activities');
$ret=new ocp_tempcode();
foreach (array_keys($hooks) as $hook) // We only expect one actually
{
require_code('hooks/systems/activities/'.$hook);
$ob=object_factory('Activity_'.$hook);
$ret->attach($ob->get_syndication_option_fields());
}
return $ret;
}
string php_addslashes(string in)
Escape a string to fit within PHP double quotes.
Parameters…
| Name |
in |
| Description |
String in |
| Type |
string |
Returns…
| Description |
Resultant string |
| Type |
string |
function php_addslashes($in)
{
global $PHP_REP_FROM,$PHP_REP_TO;
return str_replace($PHP_REP_FROM,$PHP_REP_TO,$in);
//return str_replace("\n",'\n',str_replace('$','\$',str_replace('\\\'','\'',addslashes($in))));
}
array remove_duplicate_rows(array rows, string id_field)
Remove any duplication inside the list of rows (each row being a map). Duplication is defined by rows with correspinding IDs.
Parameters…
| Name |
rows |
| Description |
The rows to remove duplication of |
| Type |
array |
| Name |
id_field |
| Description |
The ID field |
| Default value |
id |
| Type |
string |
Returns…
| Description |
The filtered rows |
| Type |
array |
function remove_duplicate_rows($rows,$id_field='id')
{
$ids_seen=array();
$rows2=array();
foreach ($rows as $row)
{
if (!array_key_exists($row[$id_field],$ids_seen))
$rows2[]=$row;
$ids_seen[$row[$id_field]]=1;
}
return $rows2;
}
void member_tracking_update()
Update the member tracker for the currently viewing user.
Parameters…
(No return value)
function member_tracking_update()
{
global $ZONE;
$page=get_param('page',$ZONE['zone_default_page']);
$type=get_param('type','/');
$id=get_param('id','/',true);
if ($type=='/') $type='';
if ($id=='/') $id='';
$GLOBALS['SITE_DB']->query('DELETE FROM '.get_table_prefix().'member_tracking WHERE mt_time<'.strval(time()-60*intval(get_option('users_online_time'))).' OR (mt_member_id='.strval((integer)get_member()).' AND '.db_string_equal_to('mt_type',$type).' AND '.db_string_equal_to('mt_id',$id).' AND '.db_string_equal_to('mt_page',$page).')');
$GLOBALS['SITE_DB']->query_insert('member_tracking',array(
'mt_member_id'=>get_member(),
'mt_cache_username'=>$GLOBALS['FORUM_DRIVER']->get_username(get_member()),
'mt_time'=>time(),
'mt_page'=>$page,
'mt_type'=>$type,
'mt_id'=>$id
),false,true); // Ignore errors for race conditions
}
?array get_members_viewing(?ID_TEXT page, ?ID_TEXT type, ?SHORT_TEXT id, boolean forum_layer)
Get a map of members viewing the specified ocPortal location.
Parameters…
| Name |
page |
| Description |
The page they need to be viewing (NULL: don't care) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
type |
| Description |
The page-type they need to be viewing (NULL: don't care) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
id |
| Description |
The type-id they need to be viewing (NULL: don't care) |
| Default value |
|
| Type |
?SHORT_TEXT |
| Name |
forum_layer |
| Description |
Whether this has to be done over the forum driver (multi site network) |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
A map of member-ids to rows about them (NULL: Too many) |
| Type |
?array |
function get_members_viewing($page=NULL,$type=NULL,$id=NULL,$forum_layer=false)
{
// Update the member tracking
member_tracking_update();
global $ZONE;
if ($page===NULL) $page=get_param('page',$ZONE['zone_default_page']);
if ($type===NULL) $type=get_param('type','/');
if ($id===NULL) $id=get_param('id','/',true);
if ($type=='/') $type='';
if ($id=='/') $id='';
$map=array();
if (($page!==NULL) && ($page!='')) $map['mt_page']=$page;
if (($type!==NULL) && ($type!='')) $map['mt_type']=$type;
if (($id!==NULL) && ($id!='')) $map['mt_id']=$id;
$map['session_invisible']=0;
$db=($forum_layer?$GLOBALS['FORUM_DB']:$GLOBALS['SITE_DB']);
$results=$db->query_select('member_tracking t LEFT JOIN '.$db->get_table_prefix().'sessions s ON t.mt_member_id=s.the_user',array('*'),$map,'ORDER BY mt_member_id',200);
if (count($results)==200) return NULL;
$results=remove_duplicate_rows($results,'mt_member_id');
$out=array();
foreach ($results as $row)
{
if (!member_blocked(get_member(),$row['mt_member_id'])) $out[$row['mt_member_id']]=$row;
}
return $out;
}
boolean is_invisible()
Find whether the current user is invisible.
Parameters…
Returns…
| Description |
Whether the current user is invisible |
| Type |
boolean |
function is_invisible()
{
global $SESSION_CACHE;
$s=get_session_id();
foreach ($SESSION_CACHE as $row)
{
if (!array_key_exists('the_user',$row)) continue; // Workaround to HipHop PHP weird bug
if (($row['the_session']==$s) && ($row['session_invisible']==1))
{
return true;
}
}
return false;
}
integer get_num_users_site()
Get the number of users on the site in the last 5 minutes. The function also maintains the statistic via the sessions table.
Parameters…
Returns…
| Description |
The number of users on the site |
| Type |
integer |
function get_num_users_site()
{
global $NUM_USERS_SITE,$PEAK_USERS_EVER;
$users_online_time_seconds=60*intval(get_option('users_online_time'));
$NUM_USERS_SITE=get_value_newer_than('users_online',time()-$users_online_time_seconds/2);
if ($NUM_USERS_SITE===NULL)
{
$NUM_USERS_SITE=get_value('users_online');
$count=0;
get_online_members(false,NULL,$count);
if (strval($count)!=$NUM_USERS_SITE)
{
$NUM_USERS_SITE=strval($count);
set_value('users_online',$NUM_USERS_SITE);
}
}
if ((intval($NUM_USERS_SITE)>intval(get_option('maximum_users'))) && (intval(get_option('maximum_users'))>1) && (get_page_name()!='login') && (!has_specific_permission(get_member(),'access_overrun_site')))
{
$GLOBALS['HTTP_STATUS_CODE']='503';
header('HTTP/1.0 503 Service Unavailable');
critical_error('BUSY',do_lang('TOO_MANY_USERS'));
}
if (addon_installed('stats'))
{
$PEAK_USERS_EVER=get_value_newer_than('user_peak',time()-$users_online_time_seconds*10);
if (($PEAK_USERS_EVER===NULL) || ($PEAK_USERS_EVER==''))
{
$_peak_users_user=$GLOBALS['SITE_DB']->query_value_null_ok('usersonline_track','MAX(peak)',NULL,'',true);
$PEAK_USERS_EVER=($_peak_users_user===NULL)?$NUM_USERS_SITE:strval($_peak_users_user);
set_value('user_peak',$PEAK_USERS_EVER);
}
if ($NUM_USERS_SITE>$PEAK_USERS_EVER)
{
// In case the record is beaten more than once within the same second
$time=time();
$GLOBALS['SITE_DB']->query_delete('usersonline_track',array('date_and_time'=>$time),'',1,NULL,true);
// New record
$GLOBALS['SITE_DB']->query_insert('usersonline_track',array('date_and_time'=>$time,'peak'=>intval($NUM_USERS_SITE)),false,true);
}
}
return intval($NUM_USERS_SITE);
}
integer get_num_users_peak()
Get the largest amount of users ever to be on the site at the same time.
Parameters…
Returns…
| Description |
The number of peak users |
| Type |
integer |
function get_num_users_peak()
{
global $PEAK_USERS_EVER;
return intval($PEAK_USERS_EVER);
}
string escape_html(mixed string)
Get the specified string, but with all characters escaped.
Parameters…
| Name |
string |
| Description |
The input string |
| Type |
mixed |
Returns…
| Description |
The escaped string |
| Type |
string |
function escape_html($string)
{
// if ($string==='') return $string; // Optimisation
if (is_object($string)) return $string;
/*if ($GLOBALS['XSS_DETECT'])
{
if (ocp_is_escaped($string))
{
@var_dump(debug_backtrace());
@exit('String double-escaped');
}
}*/
global $HTML_ESCAPE_1_STRREP,$HTML_ESCAPE_2,$XSS_DETECT;
$ret=str_replace($HTML_ESCAPE_1_STRREP,$HTML_ESCAPE_2,$string);
if ($XSS_DETECT)
{
ocp_mark_as_escaped($ret);
}
return $ret;
}
URLPATH brand_base_url()
Find the base URL for documentation.
Parameters…
Returns…
| Description |
The base URL for documentation |
| Type |
URLPATH |
function brand_base_url()
{
$value=get_value('rebrand_base_url');
if (($value===NULL) || ($value=='')) $value='http://ocportal.com';
return $value;
}
boolean browser_matches(string code)
See's if the current browser matches some special property code. Assumes users are keeping up on newish browsers (except for IE users, who are 6+)
Parameters…
| Name |
code |
| Description |
The property code |
| Type |
string |
| Values restricted to |
android ios wysiwyg windows mac linux odd_os mobile opera ie_decent ie_new ie ie_old gecko konqueror safari odd_browser has_artificial_monopoly has_fanboys quirk__internalised_list_indent quirk__quirk__list_indent_in_ul_instead_of_li chrome ie5 ie6 ie7+ ie8+ ie9+ |
Returns…
| Description |
Whether there is a match |
| Type |
boolean |
function browser_matches($code)
{
global $BROWSER_MATCHES_CACHE;
if (isset($BROWSER_MATCHES_CACHE[$code])) return $BROWSER_MATCHES_CACHE[$code];
$browser=strtolower(ocp_srv('HTTP_USER_AGENT'));
$os=strtolower(ocp_srv('HTTP_UA_OS')).' '.$browser;
$is_opera=strpos($browser,'opera')!==false;
$is_konqueror=strpos($browser,'konqueror')!==false;
$is_safari=strpos($browser,'applewebkit')!==false;
$is_chrome=strpos($browser,'chrome/')!==false;
$is_gecko=(strpos($browser,'gecko')!==false) && !$is_opera && !$is_konqueror && !$is_safari;
$is_ie=(strpos($browser,'msie')!==false) && !$is_opera;
$is_ie_old=((strpos($browser,'msie 6')!==false) || (strpos($browser,'msie 5')!==false)) && ($is_ie);
$is_ie_decent=(!$is_ie_old) && (strpos($browser,'msie 7')===false) && $is_ie;
$is_ie5=(strpos($browser,'msie 5')!==false) && ($is_ie);
$is_ie6=(strpos($browser,'msie 6')!==false) && ($is_ie);
$is_ie7=(strpos($browser,'msie 7')!==false) && ($is_ie);
$is_ie8=(strpos($browser,'msie 8')!==false) && ($is_ie);
$is_ie9=(strpos($browser,'msie 8')===false) && ($is_ie_decent);
$is_ie_new=(!$is_ie_old) && ($is_ie);
$is_iceweasel=(strpos($browser,'iceweasel')!==false);
switch ($code)
{
case 'android':
$BROWSER_MATCHES_CACHE[$code]=strpos($browser,'android')!==false;
return $BROWSER_MATCHES_CACHE[$code];
case 'ios':
$BROWSER_MATCHES_CACHE[$code]=strpos($browser,'iphone')!==false;
return $BROWSER_MATCHES_CACHE[$code];
case 'true_xhtml':
$BROWSER_MATCHES_CACHE[$code]=$is_opera || $is_konqueror || $is_safari || $is_gecko;
return $BROWSER_MATCHES_CACHE[$code];
case 'wysiwyg':
if ((get_value('no_wysiwyg')==='1') || (is_mobile()) || (strpos($os,'ipad')!==false))
{
$BROWSER_MATCHES_CACHE[$code]=false;
return false;
}
$BROWSER_MATCHES_CACHE[$code]=true; // As of ocPortal 5.1, using CKEditor
return $BROWSER_MATCHES_CACHE[$code];
case 'windows':
$BROWSER_MATCHES_CACHE[$code]=(strpos($os,'windows')!==false) || (strpos($os,'win32')!==false);
return $BROWSER_MATCHES_CACHE[$code];
case 'mac':
$BROWSER_MATCHES_CACHE[$code]=strpos($os,'mac')!==false;
return $BROWSER_MATCHES_CACHE[$code];
case 'linux':
$BROWSER_MATCHES_CACHE[$code]=strpos($os,'linux')!==false;
return $BROWSER_MATCHES_CACHE[$code];
case 'odd_os':
$BROWSER_MATCHES_CACHE[$code]=(strpos($os,'windows')===false) && (strpos($os,'mac')===false) && (strpos($os,'linux')===false);
return $BROWSER_MATCHES_CACHE[$code];
case 'mobile':
$BROWSER_MATCHES_CACHE[$code]=is_mobile();
return $BROWSER_MATCHES_CACHE[$code];
case 'opera':
$BROWSER_MATCHES_CACHE[$code]=$is_opera;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie':
$BROWSER_MATCHES_CACHE[$code]=$is_ie;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie5':
$BROWSER_MATCHES_CACHE[$code]=$is_ie5;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie6':
case 'ie_old':
$BROWSER_MATCHES_CACHE[$code]=$is_ie_old;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie7':
$BROWSER_MATCHES_CACHE[$code]=$is_ie7;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie8':
$BROWSER_MATCHES_CACHE[$code]=$is_ie8;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie7+':
case 'ie_new':
$BROWSER_MATCHES_CACHE[$code]=$is_ie_new;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie8+':
case 'ie_decent':
$BROWSER_MATCHES_CACHE[$code]=$is_ie_decent;
return $BROWSER_MATCHES_CACHE[$code];
case 'ie9+':
$BROWSER_MATCHES_CACHE[$code]=$is_ie9;
return $BROWSER_MATCHES_CACHE[$code];
case 'has_artificial_monopoly':
$BROWSER_MATCHES_CACHE[$code]=$is_ie;
return $BROWSER_MATCHES_CACHE[$code];
case 'has_fanboys':
$BROWSER_MATCHES_CACHE[$code]=$is_gecko; // change to Chrome?
return $BROWSER_MATCHES_CACHE[$code];
case 'no_multi_wysiwyg':
$BROWSER_MATCHES_CACHE[$code]=false;//$is_gecko; once once needed, but Firefox is much more stable now
return $BROWSER_MATCHES_CACHE[$code];
case 'chrome':
$BROWSER_MATCHES_CACHE[$code]=$is_chrome;
return $BROWSER_MATCHES_CACHE[$code];
case 'gecko':
$BROWSER_MATCHES_CACHE[$code]=$is_gecko;
return $BROWSER_MATCHES_CACHE[$code];
case 'konqueror':
$BROWSER_MATCHES_CACHE[$code]=$is_konqueror;
return $BROWSER_MATCHES_CACHE[$code];
case 'safari':
$BROWSER_MATCHES_CACHE[$code]=$is_safari;
return $BROWSER_MATCHES_CACHE[$code];
case 'odd_browser':
$BROWSER_MATCHES_CACHE[$code]=!$is_opera && !$is_konqueror && !$is_safari && !$is_gecko && !$is_ie;
return $BROWSER_MATCHES_CACHE[$code];
case 'quirk__internalised_list_indent':
$BROWSER_MATCHES_CACHE[$code]=$is_gecko;
return $BROWSER_MATCHES_CACHE[$code];
case 'quirk__list_indent_in_ul_instead_of_li':
$BROWSER_MATCHES_CACHE[$code]=$is_opera;
return $BROWSER_MATCHES_CACHE[$code];
case 'itunes':
$BROWSER_MATCHES_CACHE[$code]=(strpos($browser,'itunes')!==false);
return $BROWSER_MATCHES_CACHE[$code];
}
// Should never get here
return false;
}
boolean is_mobile(?string user_agent, boolean truth)
Look at the user's browser, and decide if they are viewing on a mobile device or not.
Parameters…
| Name |
user_agent |
| Description |
The user agent (NULL: get from environment, current user's browser) |
| Default value |
|
| Type |
?string |
| Name |
truth |
| Description |
Whether to always tell the truth (even if the current page does not have mobile support) |
| Default value |
boolean-false |
| Type |
boolean |
Returns…
| Description |
Whether the user is using a mobile device |
| Type |
boolean |
function is_mobile($user_agent=NULL,$truth=false)
{
$user_agent_given=($user_agent!==NULL);
if ($user_agent===NULL) $user_agent=ocp_srv('HTTP_USER_AGENT');
global $IS_MOBILE,$IS_MOBILE_TRUTH;
if (!$user_agent_given)
{
if (($truth?$IS_MOBILE_TRUTH:$IS_MOBILE)!==NULL) return $truth?$IS_MOBILE_TRUTH:$IS_MOBILE;
}
if ((!function_exists('get_option')) || (get_option('mobile_support')=='0'))
{
$IS_MOBILE=false;
$IS_MOBILE_TRUTH=false;
return false;
}
global $SITE_INFO;
if (((!isset($SITE_INFO['assume_full_mobile_support'])) || ($SITE_INFO['assume_full_mobile_support']=='0')) && (isset($GLOBALS['FORUM_DRIVER'])) && (!$truth) && (($theme=$GLOBALS['FORUM_DRIVER']->get_theme())!='default'))
{
$ini_path=(($theme=='default')?get_file_base():get_custom_file_base()).'/themes/'.$theme.'/theme.ini';
if (is_file($ini_path))
{
require_code('files');
$details=better_parse_ini_file($ini_path);
if ((isset($details['mobile_pages'])) && ($details['mobile_pages']!='') && (preg_match('#(^|,)\s*'.str_replace('#','\#',preg_quote(get_page_name())).'\s*(,|$)#',$details['mobile_pages'])==0))
{
$IS_MOBILE=false;
return false;
}
}
}
if (!$user_agent_given)
{
$val=get_param_integer('keep_mobile',NULL);
if ($val!==NULL)
{
if (isset($GLOBALS['FORUM_DRIVER']))
$IS_MOBILE=($val==1);
$IS_MOBILE_TRUTH=$IS_MOBILE;
return $IS_MOBILE;
}
}
// The set of browsers
$browsers=array(
// Implication by technology claims
'WML',
'WAP',
'Wap',
'MIDP', // Mobile Information Device Profile
// Generics
'Mobile',
'Smartphone',
'WebTV',
// Well known/important browsers/brands
'Minimo', // By Mozilla
'Fennec', // By Mozilla (being outmoded by minimo)
'Mobile Safari', // Usually Android
'lynx',
'Links',
'iPhone',
'iPod',
'Opera Mobi',
'Opera Mini',
'BlackBerry',
'Windows Phone',
'Windows CE',
'Symbian',
'nook browser', // Barnes and Noble
'Blazer', // Palm
'PalmOS',
'webOS', // Palm
'SonyEricsson',
// Games consoles
'Nintendo',
'PlayStation Portable',
// Less well known but common browsers
'UP.Browser', // OpenWave
'UP.Link', // OpenWave again?
'NetFront',
'Teleca',
'UCWEB',
// Specific lamely-identified devices/brands
'DDIPOCKET',
'SEMC-Browser',
'DoCoMo',
'Xda',
'ReqwirelessWeb', // Siemens/Samsung
// Specific services
'AvantGo',
);
$exceptions=array(
'iPad',
);
if (((!isset($SITE_INFO['no_extra_mobiles'])) || ($SITE_INFO['no_extra_mobiles']=='0')) && (is_file(get_file_base().'/text_custom/pdas.txt')))
{
require_code('files');
$pdas=better_parse_ini_file((get_file_base().'/text_custom/pdas.txt'));
foreach ($pdas as $key=>$val)
{
if ($val==1)
{
$browsers[]=$key;
} else
{
$exceptions[]=$key;
}
}
}
// The test
$result=(preg_match('/('.implode('|',$browsers).')/i',$user_agent)!=0) && (preg_match('/('.implode('|',$exceptions).')/i',$user_agent)==0);
if (!$user_agent_given)
{
if (isset($GLOBALS['FORUM_DRIVER']))
{
$IS_MOBILE=$result;
$IS_MOBILE_TRUTH=$IS_MOBILE;
}
}
return $result;
}
?string get_bot_type()
Get the name of a webcrawler bot, or NULL if no bot detected
Parameters…
Returns…
| Description |
Webcrawling bot name (NULL: not a bot) |
| Type |
?string |
function get_bot_type()
{
//if ($_SERVER['REMOTE_ADDR']=='188.64.38.59') $_SERVER['HTTP_USER_AGENT']='Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)';
global $CACHE_BOT_TYPE;
if ($CACHE_BOT_TYPE!==false) return $CACHE_BOT_TYPE;
$agent=strtolower(ocp_srv('HTTP_USER_AGENT'));
global $BOT_MAP,$SITE_INFO;
if ($BOT_MAP===NULL)
{
if (((!isset($SITE_INFO['no_extra_bots'])) || ($SITE_INFO['no_extra_bots']=='0')) && (is_file(get_file_base().'/text_custom/bots.txt')))
{
require_code('files');
$BOT_MAP=better_parse_ini_file(get_file_base().'/text_custom/bots.txt');
} else
{
$BOT_MAP=array(
'zyborg'=>'Looksmart',
'googlebot'=>'Google',
'teoma'=>'Teoma',
'scooter'=>'Altavista',
'jeeves'=>'Ask Jeeves',
'infoseek'=>'Infoseek',
'ultraseek'=>'Infoseek',
'ia_archiver'=>'Alexa/Archive.org',
'slurp'=>'Inktomi/Yahoo/Hot Bot',
'yahoo'=>'Yahoo/Overture',
'msnbot'=>'MSN',
'architextspider'=>'Excite',
'lycos'=>'Lycos',
'mercator'=>'Altavista',
'mantraagent'=>'LookSmart',
'wisenutbot'=>'Looksmart',
'paros'=>'Paros',
'sqworm'=>'Aol.com',
'baidu'=>'Baidu',
);
}
}
foreach ($BOT_MAP as $id=>$name)
{
if ($name=='') continue;
if (strpos($agent,$id)!==false)
{
$CACHE_BOT_TYPE=$name;
return $name;
}
}
if ((strpos($agent,'bot')!==false) || (strpos($agent,'spider')!==false))
{
$to_a=strpos($agent,' ');
if ($to_a===false) $to_a=strlen($agent);
$to_b=strpos($agent,'/');
if ($to_b===false) $to_b=strlen($agent);
$CACHE_BOT_TYPE=substr($agent,0,min($to_a,$to_b));
return $agent;
}
$CACHE_BOT_TYPE=NULL;
return NULL;
}
SHORT_TEXT read_multi_code(ID_TEXT param)
Read a multi code from a named parameter stub.
Parameters…
| Name |
param |
| Description |
The parameter stub (stub of a series of POST parameters, made by ocf_get_forum_multi_code_field's field or similar). |
| Type |
ID_TEXT |
Returns…
| Description |
The multi code. |
| Type |
SHORT_TEXT |
function read_multi_code($param)
{
$type=post_param($param);
if ($type=='*') return $type;
if (!array_key_exists($param.'_list',$_POST)) return '';
$in=implode(',',$_POST[$param.'_list']);
return $type.$in;
}
string flatten_slashed_array(array array)
Turn an array into a humanely readable string.
Parameters…
| Name |
array |
| Description |
Array to convert |
| Type |
array |
Returns…
| Description |
A humanely readable version of the array. |
| Type |
string |
function flatten_slashed_array($array)
{
$ret='';
foreach ($array as $key=>$val)
{
if (is_array($val)) $val=flatten_slashed_array($val);
if (get_magic_quotes_gpc()) $val=stripslashes($val);
$ret.='<param>'.(is_integer($key)?strval($key):$key).'='.$val.'</param>'."\n"; // $key may be integer, due to recursion line for list fields, above
}
return $ret;
}
string wordfilter_text(string text)
Get a word-filtered version of the specified text.
Parameters…
| Name |
text |
| Description |
Text to filter |
| Type |
string |
Returns…
| Description |
Filtered version of the input text |
| Type |
string |
function wordfilter_text($text)
{
if (!addon_installed('wordfilter')) return $text;
require_code('word_filter');
return check_word_filter($text,NULL,true);
}
string xmlentities(string string, integer quote_style)
XML escape the input string.
Parameters…
| Name |
string |
| Description |
Input string |
| Type |
string |
| Name |
quote_style |
| Description |
Quote style |
| Default value |
2 |
| Type |
integer |
Returns…
| Description |
Escaped version of input string |
| Type |
string |
function xmlentities($string,$quote_style=ENT_COMPAT)
{
$ret=str_replace('>','>',str_replace('<','<',str_replace('"','"',str_replace('&','&',$string))));
if (function_exists('ocp_mark_as_escaped')) ocp_mark_as_escaped($ret);
return $ret;
}
boolean has_cookies()
Determine whether the user's browser supports cookies or not.Unfortunately this function will only return true once a user has been to the site more than once… ocPortal will set a cookie, and if it perseveres, that indicates cookies work.
Parameters…
Returns…
| Description |
Whether the user has definitely got cookies |
| Type |
boolean |
function has_cookies() // Will fail on users first visit, but then will catch on
{
global $HAS_COOKIES;
if ($HAS_COOKIES!==NULL) return $HAS_COOKIES;
/*if (($GLOBALS['DEBUG_MODE']) && (get_param_integer('keep_debug_has_cookies',0)==0) && (!running_script('occle'))) We know this works by now, was tested for years. Causes annoyance when developing
{
$_COOKIE=array();
return false;
}*/
if (count($_COOKIE)>0)
{
$HAS_COOKIES=true;
return true;
}
require_code('users_active_actions');
ocp_setcookie('has_cookies','1');
$HAS_COOKIES=false;
return false;
}
boolean has_js()
Determine whether the user's browser supports JavaScript or not.Unfortunately this function will only return true once a user has been to the site more than once… Javascript will set a cookie, indicating it works.
Parameters…
Returns…
| Description |
Whether the user has definitely got Javascript |
| Type |
boolean |
function has_js()
{
if (get_param_integer('keep_has_js',0)==1) return true;
if (get_param_integer('keep_has_js',NULL)===0) return false;
//if (browser_matches('ie5')) return true; // Dual running masks cookies
if (!function_exists('get_option')) return true;
if (get_option('detect_javascript',true)==='0') return true;
return ((array_key_exists('js_on',$_COOKIE)) && ($_COOKIE['js_on']=='1'));
}
string get_rand_password()
Get a randomised password.
Parameters…
Returns…
| Description |
The randomised password |
| Type |
string |
function get_rand_password()
{
return substr(uniqid(strval(mt_rand(0,32767)),true),0,10);
}
?mixed mixed()
Assign this to explicitly declare that a variable may be of mixed type, and initialise to NULL.
Parameters…
Returns…
| Description |
Of mixed type (NULL: default) |
| Type |
?mixed |
function mixed()
{
return NULL;
}
array seo_meta_get_for(ID_TEXT type, ID_TEXT id)
Get meta information for specified resource
Parameters…
| Name |
type |
| Description |
The type of resource (e.g. download) |
| Type |
ID_TEXT |
| Name |
id |
| Description |
The ID of the resource |
| Type |
ID_TEXT |
Returns…
| Description |
The first element is the meta keyword string for the specified resource, and the other is the meta description string. |
| Type |
array |
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;
}
void seo_meta_load_for(ID_TEXT type, ID_TEXT id, ?string title)
Load the specified resource's meta information into the system for use on this page.Also, if the title is specified then this is used for the page title.
Parameters…
| Name |
type |
| Description |
The type of resource (e.g. download) |
| Type |
ID_TEXT |
| Name |
id |
| Description |
The ID of the resource |
| Type |
ID_TEXT |
| Name |
title |
| Description |
The page-specific title to use, in Comcode or plain-text format with possible HTML entities included [Comcode will later be stripped] (NULL: none) |
| Default value |
|
| Type |
?string |
(No return value)
function seo_meta_load_for($type,$id,$title=NULL)
{
$result=seo_meta_get_for($type,$id);
global $SEO_KEYWORDS,$SEO_DESCRIPTION,$SEO_TITLE;
if ($SEO_TITLE=='DO_NOT_REPLACE') return; // main_include_module block set this
if ($result[0]!='') $SEO_KEYWORDS=array_map('trim',explode(',',$result[0]));
if ($result[1]!='') $SEO_DESCRIPTION=$result[1];
if ($title!==NULL) $SEO_TITLE=str_replace('–','-',str_replace('©','(c)',str_replace(''','\'',$title)));
}
tempcode get_loaded_tags(?ID_TEXT limit_to, ?array the_tags)
Get Tempcode for tags, based on loaded up from SEO keywords (seo_meta_load_for).
Parameters…
| Name |
limit_to |
| Description |
The search code for this tag content (e.g. downloads) (NULL: there is none) |
| Default value |
|
| Type |
?ID_TEXT |
| Name |
the_tags |
| Description |
Explicitly pass a list of tags instead (NULL: use loaded ones) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
Loaded tag output (or blank if there are none) |
| Type |
tempcode |
function get_loaded_tags($limit_to=NULL,$the_tags=NULL)
{
if (!addon_installed('search')) return new ocp_tempcode();
if ($the_tags===NULL)
{
global $SEO_KEYWORDS;
$the_tags=$SEO_KEYWORDS;
}
$tags=array();
if ($the_tags!==NULL)
{
$search_limiter_no=array('all_defaults'=>'1');
if ($limit_to!==NULL) $search_limiter_no['search_'.$limit_to]='1';
if ($limit_to!==NULL)
{
$search_limiter_yes=array();
$search_limiter_yes['search_'.$limit_to]='1';
} else
{
$search_limiter_yes=$search_limiter_no;
}
foreach ($the_tags as $tag)
{
$tag=trim($tag);
if ($tag=='') continue;
$tags[]=array(
'TAG'=>$tag,
'LINK_LIMITEDSCOPE'=>build_url(array('page'=>'search','type'=>'results','content'=>$tag,'only_search_meta'=>'1')+$search_limiter_yes,get_module_zone('search')),
'LINK_FULLSCOPE'=>build_url(array('page'=>'search','type'=>'results','content'=>$tag,'only_search_meta'=>'1')+$search_limiter_no,get_module_zone('search')),
);
}
}
return do_template('TAGS',array('TAGS'=>$tags,'TYPE'=>($limit_to===NULL)?'':$limit_to));
}
ID_TEXT get_zone_default_page(ID_TEXT zone_name)
Get the default page for a zone.
Parameters…
| Name |
zone_name |
| Description |
Zone name |
| Type |
ID_TEXT |
Returns…
| Description |
Default page |
| Type |
ID_TEXT |
function get_zone_default_page($zone_name)
{
if ($zone_name=='_SELF') $zone_name=get_zone_name();
$p_test=persistant_cache_get(array('ZONE',$zone_name));
if ($p_test!==NULL)
return $p_test['zone_default_page'];
global $ZONE;
if (($ZONE['zone_name']==$zone_name) && ($ZONE['zone_default_page']!==NULL))
{
return $ZONE['zone_default_page'];
} else
{
global $ZONE_DEFAULT_PAGES;
if (!isset($ZONE_DEFAULT_PAGES[$zone_name]))
{
$_zone_default_page=NULL;
if (function_exists('persistant_cache_set'))
{
$temp=persistant_cache_get('ALL_ZONES_TITLED');
if ($temp!==NULL)
{
$_zone_default_page=array();
foreach ($temp as $_temp)
{
list($_zone_name,,,$zone_default_page)=$_temp;
$_zone_default_page[]=array('zone_name'=>$_zone_name,'zone_default_page'=>$zone_default_page);
}
}
}
if ($_zone_default_page===NULL)
$_zone_default_page=$GLOBALS['SITE_DB']->query_select('zones',array('zone_name','zone_default_page'),NULL/*array('zone_name'=>$zone_name)*/,'ORDER BY zone_title',50/*reasonable limit; zone_title is sequential for default zones*/);
$ZONE_DEFAULT_PAGES[$zone_name]='start';
$ZONE_DEFAULT_PAGES['collaboration']='start'; // Set this in case collaboration zone removed but still referenced. Performance tweak!
foreach ($_zone_default_page as $zone_row)
$ZONE_DEFAULT_PAGES[$zone_row['zone_name']]=$zone_row['zone_default_page'];
}
return $ZONE_DEFAULT_PAGES[$zone_name];
}
}
SHORT_TEXT best_hash(SHORT_TEXT to_hash, SHORT_TEXT salt)
Hash something as well as possible. Only use this function if the hash is for short-term use, because long-term we don't know if the best hash function will change or not.
Parameters…
| Name |
to_hash |
| Description |
What to hash |
| Type |
SHORT_TEXT |
| Name |
salt |
| Description |
Salt |
| Type |
SHORT_TEXT |
Returns…
| Description |
Hashed result |
| Type |
SHORT_TEXT |
function best_hash($to_hash,$salt)
{
// The crypt implementation is quite complex.
// It md5's $to_hash first because crypt is not binary safe and we need to feed in arbitrary data.
// It substr's the salt to comply with salt length requirements.
if ((defined('CRYPT_BLOWFISH')) && (CRYPT_BLOWFISH==1))
{
$_salt=substr(md5($salt),0,22).'$';
return substr(crypt(md5($to_hash),'$2a$07$'.$_salt),strlen($_salt));
}
if ((defined('CRYPT_SHA512')) && (CRYPT_SHA512==1))
{
$_salt='$6$rounds=5000$'.substr(md5($salt),0,17).'$';
return substr(crypt(md5($to_hash),$_salt),strlen($_salt));
}
if (function_exists('sha1')) return sha1($to_hash.$salt);
return md5($to_hash.$salt);
}
boolean check_master_password(SHORT_TEXT password_given)
Check the given master password is valid.
Parameters…
| Name |
password_given |
| Description |
Given master password |
| Type |
SHORT_TEXT |
Returns…
| Description |
Whether it is valid |
| Type |
boolean |
function check_master_password($password_given)
{
global $SITE_INFO;
if (!array_key_exists('admin_password',$SITE_INFO)) exit('No master password defined in info.php currently so cannot authenticate');
$actual_password_hashed=$SITE_INFO['admin_password'];
$salt='';
if ((substr($actual_password_hashed,0,1)=='!') && (strlen($actual_password_hashed)==33))
{
$actual_password_hashed=substr($actual_password_hashed,1);
$salt='ocp';
}
return (((strlen($password_given)!=32) && ($actual_password_hashed==$password_given)) || ($actual_password_hashed==md5($password_given.$salt)));
}
ID_TEXT produce_salt()
Get a decent randomised salt.
Parameters…
Returns…
| Description |
The salt |
| Type |
ID_TEXT |
function produce_salt()
{
return uniqid('',true);
}
ID_TEXT get_site_salt()
Get the site-wide salt. It should be something hard for a hacker to get, so we depend on data gathered both from the database and file-system.
Parameters…
Returns…
| Description |
The salt |
| Type |
ID_TEXT |
function get_site_salt()
{
$site_salt=get_value('site_salt');
if ($site_salt===NULL)
{
$site_salt=produce_salt();
set_value('site_salt',$site_salt);
}
//global $SITE_INFO; This is unstable on some sites, as the array can be prepopulated on the fly
//$site_salt.=serialize($SITE_INFO);
return md5($site_salt);
}
string titleify(ID_TEXT boring)
Turn a boring codename, into a "pretty" title.
Parameters…
| Name |
boring |
| Description |
The codename |
| Type |
ID_TEXT |
Returns…
| Description |
The title |
| Type |
string |
function titleify($boring)
{
$ret=ucwords(str_replace('_',' ',$boring));
$ret=str_replace('Ocportal','ocPortal',$ret);
if (substr($ret,0,3)=='Oc ') $ret='oc'.str_replace(' ','',substr($ret,3));
return $ret;
}
sources/files.php
Global_functions_files.php
Function summary
|
void
|
init__files ()
|
|
boolean
|
is_suexec_like ()
|
|
integer
|
php_return_bytes (string val)
|
|
string
|
get_file_size (URLPATH url)
|
|
string
|
clean_file_size (integer bytes)
|
|
string
|
get_file_extension (string name)
|
|
array
|
better_parse_ini_file (?PATH filename, ?string file)
|
|
boolean
|
should_ignore_file (string filepath, integer bitmask)
|
|
void
|
deldir_contents (PATH dir, boolean default_preserve, boolean just_files)
|
|
void
|
fix_permissions (PATH path, integer perms)
|
|
?string
|
http_download_file (URLPATH url, ?integer byte_limit, boolean trigger_error, boolean no_redirect, string ua, ?array post_params, ?array cookies, ?string accept, ?string accept_charset, ?string accept_language, ?resource write_to_file, ?string referer, ?array auth, float timeout, boolean is_xml, ?array files)
|
void init__files()
Standard code module initialisation function.
Parameters…
(No return value)
function init__files()
{
global $DOWNLOAD_LEVEL;
$DOWNLOAD_LEVEL=0;
define('IGNORE_DEFAULTS',0);
// -
define('IGNORE_ACCESS_CONTROLLERS',1);
define('IGNORE_CUSTOM_DIR_CONTENTS',2);
define('IGNORE_HIDDEN_FILES',4);
define('IGNORE_EDITFROM_FILES',8);
define('IGNORE_REVISION_FILES',16);
define('IGNORE_CUSTOM_ZONES',32);
define('IGNORE_THEMES',64);
define('IGNORE_CUSTOM_DIR_CONTENTS_CASUAL_OVERRIDE',128);
}
boolean is_suexec_like()
Find whether we can get away with natural file access, not messing with AFMs, world-writability, etc.
Parameters…
Returns…
| Description |
Whether we have this |
| Type |
boolean |
function is_suexec_like()
{
return (((function_exists('posix_getuid')) && (strpos(@ini_get('disable_functions'),'posix_getuid')===false) && (!isset($_SERVER['HTTP_X_MOSSO_DT'])) && (is_integer(@posix_getuid())) && (@posix_getuid()==@fileowner(get_file_base().'/'.(running_script('install')?'install.php':'index.php'))))
|| (is_writable_wrap(get_file_base().'/'.(running_script('index')?'index.php':'install.php'))));
}
integer php_return_bytes(string val)
Get the number of bytes for a PHP config option. Code taken from the PHP manual.
Parameters…
| Name |
val |
| Description |
PHP config option value. |
| Type |
string |
Returns…
| Description |
Number of bytes. |
| Type |
integer |
function php_return_bytes($val)
{
$val=trim($val);
if ($val=='') return 0;
$last=strtolower($val[strlen($val)-1]);
$_val=intval($val);
switch($last)
{
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$_val*=1024;
case 'm':
$_val*=1024;
case 'k':
$_val*=1024;
}
return $_val;
}
string get_file_size(URLPATH url)
Get a formatted-string filesize for the specified file. It is formatted as such: x Mb/Kb/Bytes (or unknown). It is assumed that the file exists.
Parameters…
| Name |
url |
| Description |
The URL that the file size of is being worked out for. Should be local. |
| Type |
URLPATH |
Returns…
| Description |
The formatted-string file size |
| Type |
string |
function get_file_size($url)
{
if (substr($url,0,strlen(get_base_url()))==get_base_url())
$url=substr($url,strlen(get_base_url()));
if (!url_is_local($url)) return do_lang('UNKNOWN');
$_full=rawurldecode($url);
$_full=get_file_base().'/'.$_full;
$file_size_bytes=filesize($_full);
return clean_file_size($file_size_bytes);
}
string clean_file_size(integer bytes)
Format the specified filesize.
Parameters…
| Name |
bytes |
| Description |
The number of bytes the file has |
| Type |
integer |
Returns…
| Description |
The formatted-string file size |
| Type |
string |
function clean_file_size($bytes)
{
if ($bytes<0) return '-'.clean_file_size(-$bytes);
if (is_null($bytes)) return do_lang('UNKNOWN').' bytes';
if (floatval($bytes)>2.0*1024.0*1024.0*1024.0) return strval(intval(round(floatval($bytes)/1024.0/1024.0/1024.0))).' Gb';
if (floatval($bytes)>1024.0*1024.0*1024.0) return float_format(round(floatval($bytes)/1024.0/1024.0/1024.0,2)).' Gb';
if (floatval($bytes)>2.0*1024.0*1024.0) return strval(intval(round(floatval($bytes)/1024.0/1024.0))).' Mb';
if (floatval($bytes)>1024.0*1024.0) return float_format(round(floatval($bytes)/1024.0/1024.0,2)).' Mb';
if (floatval($bytes)>2.0*1024.0) return strval(intval(round(floatval($bytes)/1024.0))).' Kb';
if (floatval($bytes)>1024.0) return float_format(round(floatval($bytes)/1024.0,2)).' Kb';
return strval($bytes).' Bytes';
}
string get_file_extension(string name)
Get the file extension of the specified file. It returns without a dot.
Parameters…
| Name |
name |
| Description |
The filename |
| Type |
string |
Returns…
| Description |
The filename extension (no dot) |
| Type |
string |
function get_file_extension($name)
{
$dot_pos=strrpos($name,'.');
if ($dot_pos===false) return '';
return strtolower(substr($name,$dot_pos+1));
}
array better_parse_ini_file(?PATH filename, ?string file)
Parse the specified INI file, and get an array of what it found.
Parameters…
| Name |
filename |
| Description |
The path to the ini file to open (NULL: given contents in $file instead) |
| Type |
?PATH |
| Name |
file |
| Description |
The contents of the file (NULL: the file needs opening) |
| Default value |
|
| Type |
?string |
Returns…
| Description |
A map of the contents of the ini files |
| Type |
array |
function better_parse_ini_file($filename,$file=NULL)
{
// NB: 'file()' function not used due to slowness compared to file_get_contents then explode
if (is_null($file))
{
global $FILE_ARRAY;
if (@is_array($FILE_ARRAY)) $file=file_array_get($filename);
else $file=file_get_contents($filename,FILE_TEXT);
}
$ini_array=array();
$lines=explode(chr(10),$file);
foreach ($lines as $line)
{
$line=rtrim($line);
if ($line=='') continue;
if ($line[0]=='#') continue;
$bits=explode('=',$line,2);
if (isset($bits[1]))
{
list($property,$value)=$bits;
$value=trim($value,'"');
$ini_array[$property]=$value;
}
}
return $ini_array;
}
boolean should_ignore_file(string filepath, integer bitmask)
Find whether a file is known to be something that should/could be there but isn't an ocPortal distribution file, or for some other reason should be ignored.
Parameters…
| Name |
filepath |
| Description |
File path |
| Type |
string |
| Name |
bitmask |
| Description |
Bitmask of extra stuff to ignore (see IGNORE_* constants) |
| Default value |
0 |
| Type |
integer |
Returns…
| Description |
Whether it should be ignored |
| Type |
boolean |
function should_ignore_file($filepath,$bitmask=0)
{
// Normalise
$filepath=strtolower($filepath);
if (strpos($filepath,'/')!==false)
{
$dir=dirname($filepath);
$filename=basename($filepath);
} else
{
$dir='';
$filename=$filepath;
}
$ignore_filenames=array(
'.'=>'.*',
'..'=>'.*',
'__macosx'=>'.*',
'.bash_history'=>'.*',
'thumbs.db:encryptable'=>'.*',
'thumbs.db'=>'.*',
'.ds_store'=>'.*',
'.svn'=>'.*',
'.git'=>'.*',
'cvs'=>'.*',
'web-inf'=>'.*',
'bingsiteauth.xml'=>'',
'parameters.xml'=>'',
'manifest.xml'=>'',
'web.config'=>'',
'nbproject'=>'',
'no_mem_cache'=>'',
'php.ini'=>'.*',
'.htpasswd'=>'.*',
'closed.html'=>'',
'iirf.ini'=>'',
'robots.txt'=>'',
'data.ocp'=>'',
'install_ok'=>'',
'install_locked'=>'',
'install.php'=>'',
'install.sql'=>'',
'install1.sql'=>'',
'install2.sql'=>'',
'install3.sql'=>'',
'install4.sql'=>'',
'user.sql'=>'',
'postinstall.sql'=>'',
'restore.php'=>'',
'info.php.template'=>'',
'make_files-output-log.html'=>'',
'400.shtml'=>'',
'500.shtml'=>'',
'404.shtml'=>'',
'403.shtml'=>'',
'theme.ini'=>'themes/[^/]*',
'old'=>'.*',
'uploads'=>'',
'gibb'=>'.*',
'gibberish'=>'.*',
'.gitignore'=>'',
'.project'=>'',
'if_hosted_service.txt'=>'',
'subs.inc'=>'',
'docs'=>'data/images',
// Non-bundled addon stuff that we can't detect automatically
'_tests'=>'',
'killjunk.sh'=>'',
'transcoder'=>'',
'facebook_connect.php'=>'',
// Bundled stuff that is not in *_custom dir yet is volatile
'map.ini'=>'themes',
'info.php'=>'',
'ocp_sitemap.xml'=>'',
);
if (($bitmask & IGNORE_ACCESS_CONTROLLERS)!=0)
{
$ignore_filenames+=array(
'.htaccess'=>'.*',
'index.html'=>'.*',
);
}
$ignore_extensions=array(
'tar'=>'(imports|exports)/.*',
'gz'=>'(imports|exports)/.*',
'lcd'=>'lang_cached/.*',
'gcd'=>'persistant_cache',
'tcp'=>'themes/[^/]*/templates_cached/.*',
'tcd'=>'themes/[^/]*/templates_cached/.*',
'css'=>'themes/[^/]*/templates_cached/.*',
'js'=>'themes/[^/]*/templates_cached/.*',
'log'=>'.*',
'clpprj'=>'',
'tmproj'=>'',
'zpj'=>'',
'o'=>'',
'scm'=>'',
'heap'=>'',
'sch'=>'',
'dll'=>'',
'fcgi'=>'',
);
if (($bitmask & IGNORE_EDITFROM_FILES)!=0)
{
$ignore_extensions+=array(
'editfrom'=>'.*',
);
}
$ignore_filename_patterns=array(
'\..*\.(png|gif|jpeg|jpg)'=>'.*', // Image meta data file, e.g. ".example.png"
'\_vti\_.*'=>'.*', // Frontpage
);
if (($bitmask & IGNORE_CUSTOM_DIR_CONTENTS)!=0)
{
$ignore_filename_patterns+=array(
'.*\_custom'=>'.*',
'.*'=>'.*\_custom(/.*)?',
);
}
elseif (($bitmask & IGNORE_CUSTOM_DIR_CONTENTS_CASUAL_OVERRIDE)!=0)
{
$ignore_filename_patterns+=array(
'(comcode|html|lang|templates|images)\_custom'=>'.*',
'.*'=>'(^|/)(lang|templates|images)\_custom(/.*)?',
);
}
if (($bitmask & IGNORE_HIDDEN_FILES)!=0)
{
$ignore_filename_patterns+=array(
'\..*'=>'.*',
);
}
if (($bitmask & IGNORE_REVISION_FILES)!=0)
{
$ignore_filename_patterns+=array(
'.*\.\d+'=>'.*',
);
}
if (isset($ignore_filenames[$filename]))
{
if (preg_match('#^'.$ignore_filenames[$filename].'$#',$dir)!=0) return true; // Check dir context
}
$extension=get_file_extension($filename);
if (isset($ignore_extensions[$extension]))
{
if (preg_match('#^'.$ignore_extensions[$extension].'$#',$dir)!=0) return true; // Check dir context
}
foreach ($ignore_filename_patterns as $filename_pattern=>$dir_pattern)
{
if (preg_match('#^'.$filename_pattern.'$#',$filename)!=0)
{
if (preg_match('#^'.$dir_pattern.'$#',$dir)!=0) return true; // Check dir context
}
}
if (($dir!='') && (file_exists(get_file_base().'/'.$filepath.'/sources_custom'))) // ocPortal dupe (e.g. backup) install
{
return true;
}
if (($bitmask & IGNORE_THEMES)!=0)
{
if ((preg_match('#^themes($|/)#',$dir)!=0) && (!in_array($filename,array('default','index.html','map.ini')))) return true;
}
if (($bitmask & IGNORE_CUSTOM_ZONES)!=0)
{
if ((file_exists(get_file_base().$filepath.'/index.php')) && (file_exists(get_file_base().$filepath.'/pages')) && (!in_array($filename,array('adminzone','collaboration','cms','forum','site'))))
return true;
}
return false;
}
void deldir_contents(PATH dir, boolean default_preserve, boolean just_files)
Delete all the contents of a directory, and any subdirectories of that specified directory (recursively).
Parameters…
| Name |
dir |
| Description |
The pathname to the directory to delete |
| Type |
PATH |
| Name |
default_preserve |
| Description |
Whether to preserve files there by default |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
just_files |
| Description |
Whether to just delete files |
| Default value |
boolean-false |
| Type |
boolean |
(No return value)
function deldir_contents($dir,$default_preserve=false,$just_files=false)
{
require_code('files2');
_deldir_contents($dir,$default_preserve,$just_files);
}
void fix_permissions(PATH path, integer perms)
Ensure that the specified file/folder is writeable for the FTP user (so that it can be deleted by the system), and should be called whenever a file is uploaded/created, or a folder is made. We call this function assuming we are giving world permissions
Parameters…
| Name |
path |
| Description |
The full pathname to the file/directory |
| Type |
PATH |
| Name |
perms |
| Description |
The permissions to make (not the permissions are reduced if the function finds that the file is owned by the web user [doesn't need world permissions then]) |
| Default value |
438 |
| Type |
integer |
(No return value)
function fix_permissions($path,$perms=0666) // We call this function assuming we are giving world permissions
{
// If the file user is different to the FTP user, we need to make it world writeable
if ((!is_suexec_like()) || (ocp_srv('REQUEST_METHOD')==''))
{
@chmod($path,$perms);
} else // Otherwise we do not
{
if ($perms==0666) @chmod($path,0644);
elseif ($perms==0777) @chmod($path,0755);
else @chmod($path,$perms);
}
global $_CREATED_FILES; // From ocProducts PHP version, for development testing
if (isset($_CREATED_FILES))
foreach ($_CREATED_FILES as $i=>$x)
if ($x==$path) unset($_CREATED_FILES[$i]);
}
?string http_download_file(URLPATH url, ?integer byte_limit, boolean trigger_error, boolean no_redirect, string ua, ?array post_params, ?array cookies, ?string accept, ?string accept_charset, ?string accept_language, ?resource write_to_file, ?string referer, ?array auth, float timeout, boolean is_xml, ?array files)
Return the file in the URL by downloading it over HTTP. If a byte limit is given, it will only download that many bytes. It outputs warnings, returning NULL, on error.
Parameters…
| Name |
url |
| Description |
The URL to download |
| Type |
URLPATH |
| Name |
byte_limit |
| Description |
The number of bytes to download. This is not a guarantee, it is a minimum (NULL: all bytes) |
| Default value |
|
| Type |
?integer |
| Value range |
1 max |
| Name |
trigger_error |
| Description |
Whether to throw an ocPortal error, on error |
| Default value |
boolean-true |
| Type |
boolean |
| Name |
no_redirect |
| Description |
Whether to block redirects (returns NULL when found) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
ua |
| Description |
The user-agent to identify as |
| Default value |
ocPortal |
| Type |
string |
| Name |
post_params |
| Description |
An optional array of POST parameters to send; if this is NULL, a GET request is used (NULL: none) |
| Default value |
|
| Type |
?array |
| Name |
cookies |
| Description |
An optional array of cookies to send (NULL: none) |
| Default value |
|
| Type |
?array |
| Name |
accept |
| Description |
'accept' header value (NULL: don't pass one) |
| Default value |
|
| Type |
?string |
| Name |
accept_charset |
| Description |
'accept-charset' header value (NULL: don't pass one) |
| Default value |
|
| Type |
?string |
| Name |
accept_language |
| Description |
'accept-language' header value (NULL: don't pass one) |
| Default value |
|
| Type |
?string |
| Name |
write_to_file |
| Description |
File handle to write to (NULL: do not do that) |
| Default value |
|
| Type |
?resource |
| Name |
referer |
| Description |
The HTTP referer (NULL: none) |
| Default value |
|
| Type |
?string |
| Name |
auth |
| Description |
A pair: authentication username and password (NULL: none) |
| Default value |
|
| Type |
?array |
| Name |
timeout |
| Description |
The timeout |
| Default value |
6 |
| Type |
float |
| Name |
is_xml |
| Description |
Whether to treat the POST parameters as a raw POST (rather than using MIME) |
| Default value |
boolean-false |
| Type |
boolean |
| Name |
files |
| Description |
Files to send. Map between field to file path (NULL: none) |
| Default value |
|
| Type |
?array |
Returns…
| Description |
The data downloaded (NULL: error) |
| Type |
?string |
function http_download_file($url,$byte_limit=NULL,$trigger_error=true,$no_redirect=false,$ua='ocPortal',$post_params=NULL,$cookies=NULL,$accept=NULL,$accept_charset=NULL,$accept_language=NULL,$write_to_file=NULL,$referer=NULL,$auth=NULL,$timeout=6.0,$is_xml=false,$files=NULL)
{
require_code('files2');
return _http_download_file($url,$byte_limit,$trigger_error,$no_redirect,$ua,$post_params,$cookies,$accept,$accept_charset,$accept_language,$write_to_file,$referer,$auth,$timeout,$is_xml,$files);
}
0 reviews: Unrated (average)
There have been no comments yet