36 function link_type_name($type)
44 static $_link_type_name_cache = array();
45 if (isset($_link_type_name_cache[$type])) {
46 return $_link_type_name_cache[$type];
49 $names = get_bit_names(
'SQ_LINK_', $type);
51 if (is_array($names)) {
53 for ($i = 0; $i < count($names); $i++) {
55 if ($i < count($names) - 2) {
57 }
else if ($i < count($names) - 1) {
61 $_link_type_name_cache[$type] = $str;
64 $_link_type_name_cache[$type] = $names;
77 function get_link_type_names()
79 static $_get_link_type_names_cache = array();
80 if (!empty($_get_link_type_names_cache)) {
81 return $_get_link_type_names_cache;
83 $link_types = get_constant_values(
'SQ_LINK_');
85 foreach ($link_types as $value) {
86 $type_names[$value] = link_type_name($value);
89 $_get_link_type_names_cache = $type_names;
104 function permission_type_name($type)
106 if (isset($GLOBALS[
'SQ_PERM_TYPE_NAME'][$type]) === FALSE) {
107 $name = get_bit_names(
'SQ_PERMISSION_', $type, FALSE, TRUE);
108 if (is_array($name))
return 'Unknown';
109 $GLOBALS[
'SQ_PERM_TYPE_NAME'][$type] = ucwords(strtolower($name));
112 return $GLOBALS[
'SQ_PERM_TYPE_NAME'][$type];
131 function get_bit_names($prefix, $bit_value, $force_array=FALSE, $exact_value=FALSE)
134 $bit_values = Array($bit_value);
136 $bit_values = bit_elements($bit_value);
144 static $_cache = array();
145 $hash = $prefix.
'.'.$bit_value.
'.'.(int)$force_array.
'.'.(
int)$exact_value;
146 if (isset($_cache[$hash]) === TRUE) {
147 return $_cache[$hash];
151 static $_userConstants = array();
152 if (empty($_userConstants) === TRUE) {
153 $constants = get_defined_constants(TRUE);
154 $_userConstants = $constants[
'user'];
159 foreach ($_userConstants as $name => $value) {
160 if (preg_match(
'/^'.$prefix.
'(.*)$/', $name, $matches) && in_array($value, $bit_values)) {
161 $names[] = $matches[1];
165 if ($force_array || count($names) > 1) {
166 $_cache[$hash] = $names;
168 }
else if (count($names)) {
169 $_cache[$hash] = $names[0];
186 function get_constant_values($prefix)
191 static $_cache = array();
192 if (isset($_cache[$prefix]) === TRUE) {
193 return $_cache[$prefix];
197 static $_userConstants = array();
198 if (empty($_userConstants) === TRUE) {
199 $constants = get_defined_constants(TRUE);
200 $_userConstants = $constants[
'user'];
204 foreach ($_userConstants as $name => $value) {
205 if (preg_match(
'/^'.$prefix.
'(.*)$/', $name, $matches)) {
206 $names[$name] = $value;
210 $_cache[$prefix] = $names;
225 function get_status_description($status)
227 if (isset($GLOBALS[
'SQ_STATUS_DESC_NAME'][$status]) === FALSE) {
229 $status_code = get_bit_names(
'SQ_STATUS_', $status);
230 $status_code =
'asset_status_'.strtolower($status_code);
232 require_once SQ_INCLUDE_PATH.
'/asset_status/'.$status_code.
'.inc';
234 $status_object =
new $status_code($this);
236 $status_object =
new $status_code(NULL);
239 $GLOBALS[
'SQ_STATUS_DESC_NAME'][$status] = $status_object->getDescription();
242 return $GLOBALS[
'SQ_STATUS_DESC_NAME'][$status];
255 function get_status_value($description)
257 foreach (get_constant_values(
'SQ_STATUS_') as $status_value) {
258 if (strtolower(get_status_description($status_value)) == strtolower($description)) {
259 return $status_value;
274 function get_status_colour($status)
277 case SQ_STATUS_ARCHIVED :
280 case SQ_STATUS_UNDER_CONSTRUCTION :
283 case SQ_STATUS_PENDING_APPROVAL :
286 case SQ_STATUS_APPROVED :
289 case SQ_STATUS_LIVE :
292 case SQ_STATUS_LIVE_APPROVAL :
295 case SQ_STATUS_EDITING :
298 case SQ_STATUS_EDITING_APPROVAL :
301 case SQ_STATUS_EDITING_APPROVED :
320 function get_status_names()
323 $statuses = get_constant_values(
'SQ_STATUS_');
324 foreach ($statuses as $name => $value) {
325 $res[$value] = ucwords(strtolower(str_replace(Array(
'SQ_STATUS_',
'_'), Array(
'',
' '), $name)));
345 function asset_link_treeid_convert($value, $encode)
348 static $digits = Array(
349 0 =>
'0', 1 =>
'1', 2 =>
'2', 3 =>
'3', 4 =>
'4', 5 =>
'5', 6 =>
'6', 7 =>
'7',
350 8 =>
'8', 9 =>
'9', 10 =>
'=', 11 =>
'A', 12 =>
'B', 13 =>
'C', 14 =>
'D', 15 =>
'E',
351 16 =>
'F', 17 =>
'G', 18 =>
'H', 19 =>
'I', 20 =>
'J', 21 =>
'K', 22 =>
'L', 23 =>
'M',
352 24 =>
'N', 25 =>
'O', 26 =>
'P', 27 =>
'Q', 28 =>
'R', 29 =>
'S', 30 =>
'T', 31 =>
'U',
353 32 =>
'V', 33 =>
'W', 34 =>
'X', 35 =>
'Y', 36 =>
'Z', 37 =>
'a', 38 =>
'b', 39 =>
'c',
354 40 =>
'd', 41 =>
'e', 42 =>
'f', 43 =>
'g', 44 =>
'h', 45 =>
'i', 46 =>
'j', 47 =>
'k',
355 48 =>
'l', 49 =>
'm', 50 =>
'n', 51 =>
'o', 52 =>
'p', 53 =>
'q', 54 =>
'r', 55 =>
's',
356 56 =>
't', 57 =>
'u', 58 =>
'v', 59 =>
'w', 60 =>
'x', 61 =>
'y', 62 =>
'z', 63 =>
'~',
364 $str = $digits[$i % SQ_CONF_ASSET_TREE_BASE].$str;
365 $i = floor($i / SQ_CONF_ASSET_TREE_BASE);
367 if (strlen($str) > SQ_CONF_ASSET_TREE_SIZE) {
368 trigger_localised_error(
'SYS0213', E_USER_WARNING, (
int) $value, SQ_CONF_ASSET_TREE_SIZE, (pow(SQ_CONF_ASSET_TREE_BASE, SQ_CONF_ASSET_TREE_SIZE) - 1));
371 return str_pad($str, SQ_CONF_ASSET_TREE_SIZE, $digits[0], STR_PAD_LEFT);
376 $str = (string) $value;
378 $x = pow(SQ_CONF_ASSET_TREE_BASE, $len - 1);
379 for ($i = 0; $i < $len; $i++) {
380 if (($d = array_search($str{$i}, $digits)) === FALSE) {
384 $x = $x / SQ_CONF_ASSET_TREE_BASE;
405 function make_valid_web_paths($paths, $fallback_path=
'')
407 $valid_paths = Array();
410 $lang_char_map = Array();
411 if (SQ_CONF_USE_LANG_CHAR_MAP) {
412 $lang_char_map = getLangCharMap();
415 foreach ($paths as $path) {
418 if (!empty($lang_char_map)) {
419 $path = str_replace(array_keys($lang_char_map), array_values($lang_char_map), $path);
423 if ($path == SQ_CONF_BACKEND_SUFFIX || $path == SQ_CONF_LIMBO_SUFFIX || $path == SQ_CONF_LOGIN_SUFFIX || $path == SQ_CONF_NOCACHE_SUFFIX) {
424 trigger_localised_error(
'SYS0114', E_USER_WARNING, $path);
429 if (preg_match(
'/^__/', $path)) {
430 trigger_localised_error(
'SYS0115', E_USER_WARNING);
435 $path = str_replace(
'&', SQ_CONF_WEB_PATH_SEPARATOR.translate(
'web_path_ampersand_replacement').SQ_CONF_WEB_PATH_SEPARATOR, $path);
436 $path = preg_replace(
'|&[^;]+;|',
'', $path);
437 $path = preg_replace(
'|&#[0-9]+;|',
'', $path);
438 $path = str_replace(
'&', SQ_CONF_WEB_PATH_SEPARATOR.translate(
'web_path_ampersand_replacement').SQ_CONF_WEB_PATH_SEPARATOR, $path);
441 $path = preg_replace(
'/\\s+/', SQ_CONF_WEB_PATH_SEPARATOR, $path);
444 $path = preg_replace(
'/[\(\)\[\]]/',
'', $path);
447 if (function_exists(
'mb_convert_encoding')) {
448 $path = mb_convert_encoding($path,
'HTML-ENTITIES', SQ_CONF_DEFAULT_CHARACTER_SET);
450 $path = htmlentities($path, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET);
454 $path = preg_replace(
'/&([a-zA-Z])(ring|uml|acute|grave|circ|tilde);/',
'$1', $path);
457 $path = preg_replace(
'|&[^;]+;|',
'', $path);
460 $path = preg_replace(
'/[^a-zA-Z0-9\-$_@.!*~(),]/',
'', $path);
464 if (SQ_CONF_WEB_PATH_SEPARATOR !=
'') $path = preg_replace(
'/'.SQ_CONF_WEB_PATH_SEPARATOR.
'+/', SQ_CONF_WEB_PATH_SEPARATOR, $path);
467 if ($path !==
'' && !in_array($path, $valid_paths)) {
468 $valid_paths[] = $path;
474 if (empty($valid_paths) && strlen(trim(join(
'', $paths)))) {
475 $valid_paths = make_valid_web_paths(Array($fallback_path));
503 function implode_sql($query_components)
505 $where_joiner = trim(strtoupper(array_get_index($query_components,
'where_joiner',
'')));
506 if ($where_joiner !=
'OR') $where_joiner =
'AND';
508 $select =
'SELECT '.implode(
', ', $query_components[
'select']);
509 $from =
'FROM '.implode(
', ', $query_components[
'from']);
510 if (isset($query_components[
'join'])) {
511 $from .=
' '.implode(
"\n", $query_components[
'join']);
513 $where =
'WHERE ('.implode(
")\n\t".$where_joiner.
' (', $query_components[
'where']).
')';
515 $sql =
"$select\n$from\n$where";
517 if (!empty($query_components[
'group_by'])) {
518 $sql .=
"\nGROUP BY ".implode(
', ', $query_components[
'group_by']);
520 if (!empty($query_components[
'having'])) {
521 $sql .=
"\nHAVING ".implode(
' ', $query_components[
'having']);
523 if (!empty($query_components[
'order_by'])) {
524 $sql .=
"\nORDER BY ".implode(
', ', $query_components[
'order_by']);
542 function addProxyInfo(&$request_parameters, &$default_headers, $page_url)
544 require_once(SQ_DATA_PATH.
'/private/conf/proxy_authentication.inc');
546 $proxy = get_proxy_info_for_url($page_url);
550 $request_parameters[
'proxy_host'] = ($proxy[
'host'] ===
'') ? NULL : $proxy[
'host'];
551 $request_parameters[
'proxy_port'] = ($proxy[
'host'] ===
'') ? NULL : $proxy[
'port'];
552 $default_headers[
'Proxy-Authorization'] =
'Basic '.base64_encode($proxy[
'user'].
':'.$proxy[
'password']);
572 function openSocketConnection($url_parts, &$errno, &$errstr, $force_fsockopen=FALSE, $timeout=60)
574 return open_socket_connection($url_parts, $errno, $errstr, $force_fsockopen, $timeout);
591 function open_socket_connection($url_parts, &$errno, &$errstr, $force_fsockopen=FALSE, $timeout=60)
593 include_once(SQ_DATA_PATH.
'/private/conf/proxy_authentication.inc');
595 if (is_array($url_parts)) {
596 if (!empty($url_parts[
'query']) && $url_parts[
'query'][0] !=
'?') {
597 $url_parts[
'query'] =
'?'.$url_parts[
'query'];
599 if (!empty($url_parts[
'path']) && $url_parts[
'path'][0] !=
'/') {
600 $url_parts[
'path'] =
'/'.$url_parths[
'path'];
602 $page_url = $url_parts[
'scheme'].
'://'.$url_parts[
'host'].
':'.$url_parts[
'port'].$url_parts[
'path'].array_get_index($url_parts,
'query',
'');
604 $page_url = $url_parts;
608 $proxy = get_proxy_info_for_url($page_url);
610 $con = @fsockopen($proxy[
'host'], $proxy[
'port'], $errno, $errstr);
611 if (!$con)
return FALSE;
614 preg_match(
'@^(?:http://)?([^/]+)@i', $page_url, $matches);
617 fputs($con,
"GET $page_url HTTP/1.0\r\n");
618 fputs($con,
"Host: ".$host.
"\r\n");
619 if( !empty($proxy[
'user']) && !empty($proxy[
'password']) ){
620 fputs($con,
'Proxy-Authorization: Basic '.base64_encode($proxy[
'user'].
':'.$proxy[
'password']).
"\r\n");
625 if ($force_fsockopen && is_array($url_parts)) {
626 $con = @fsockopen($url_parts[
'host'], $url_parts[
'port'], $errno, $errstr, $timeout);
628 $con = @fopen($page_url,
'r');
645 function getLangCharMap($lang_code=
'')
647 $character_map = Array();
648 if (empty($lang_code)) {
649 $lang_code = SQ_CONF_DEFAULT_FRONTEND_LANGUAGE;
652 include SQ_DATA_PATH.
'/private/conf/lang_char_map.inc';
654 if (isset($lang_char_map[$lang_code]) && is_array($lang_char_map[$lang_code])) {
655 $character_map = $lang_char_map[$lang_code];
658 return $character_map;
671 function parse_self_links($content)
674 $url = str_replace(
"/",
"\/", $GLOBALS[
'SQ_SYSTEM']->frontend_asset->getURL());
675 $web_path = substr($url, strrpos($url,
"/") + 1);
678 $href_pattern =
"/<a [^<]*href=\"(".$url.
")\/?\"[^>]*>(.*?)<\/a>/msi";
679 $web_path_pattern =
"/<a [^<]*href=\"(\.{0,2}\/{1})?".$web_path.
"\/?\"[^>]*>(.*?)<\/a>/msi";
680 $content = preg_replace(Array($href_pattern, $web_path_pattern),
'$2', $content);
695 function sizeInBytes($size)
697 $size = strtolower(str_replace(
' ',
'', $size));
698 preg_match(
'/^([0-9]+)([a-z]+)$/', $size, $matches);
700 $value = (int) array_get_index($matches, 1, $size);
701 $unit_type = array_get_index($matches, 2,
'');
706 $value = $value * 1024 * 1024 * 1024;
711 $value = $value * 1024 * 1024;
716 $value = $value * 1024;