18 require_once SQ_LIB_PATH.
'/MatrixDAL/MatrixDAL.inc';
20 require_once SQ_INCLUDE_PATH.
'/mysource_object.inc';
21 require_once SQ_INCLUDE_PATH.
'/asset_manager.inc';
22 require_once SQ_INCLUDE_PATH.
'/locale_manager.inc';
23 require_once SQ_INCLUDE_PATH.
'/performance_manager.inc';
26 require_once SQ_INCLUDE_PATH.
'/version.inc';
53 protected $_db_conns = Array();
61 protected $_db_stack = Array();
70 protected $_run_level_stack = Array();
79 protected $_context_stack = Array();
136 protected $tag_manager;
146 protected $trigger_manager;
165 public $frontend_asset;
172 protected $_user_is_root = FALSE;
179 protected $_user_is_sys_admin = FALSE;
186 protected $_user_is_public = TRUE;
202 protected $_global_defines;
233 if (!empty($this->lm) && array_get_index($this->lm->_tmp,
'strings_modified', FALSE)) {
234 $this->lm->locale_stack = Array();
238 $deja_vu->remember(SQ_DEJA_VU_LOCALE, NULL, $this->lm);
243 if(SQ_CONF_SESSION_HANDLER ===
'memcache')
244 session_write_close();
260 $this->_processUserIP();
274 $deja_vu = $GLOBALS[
'SQ_SYSTEM']->getDejaVu();
276 $this->lm = $deja_vu->recall(SQ_DEJA_VU_LOCALE);
280 if (empty($this->lm)) {
284 $this->lm->setCurrentLocale(SQ_CONF_DEFAULT_BACKEND_LOCALE);
286 if (!SQ_PHP_CLI && $GLOBALS[
'SQ_SYSTEM']->
runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
290 $proxy_conf_file = SQ_DATA_PATH.
'/private/conf/proxy_authentication.inc';
291 if (file_exists($proxy_conf_file)) {
293 require_once($proxy_conf_file);
295 if (SQ_PROXY_URL_PORT_STRIP) {
296 $url_parts = parse_url($_SERVER[
'HTTP_HOST']);
299 if (isset($url_parts[
'port'])) {
300 unset($url_parts[
'port']);
302 $_SERVER[
'HTTP_HOST'] = implode(
'', $url_parts);
307 $session_handler = $this->getSessionHandlerClassName();
308 eval($session_handler.
'::init();');
310 if(SQ_CONF_SESSION_HANDLER ===
'memcache') {
312 ini_set(
'session.gc_maxlifetime', SQ_CONF_SESSION_GC_MAXLIFETIME > 2592000 ? 2592000 : SQ_CONF_SESSION_GC_MAXLIFETIME);
315 ini_set(
'session.gc_maxlifetime', SQ_CONF_SESSION_GC_MAXLIFETIME);
318 $session_set = FALSE;
319 if (isset($_GET[
'SESSION_ID']) && (isset($_GET[
'SESSION_KEY']) || isset($_GET[
'SOAP_SESSION_KEY']))) {
321 session_id($_GET[
'SESSION_ID']);
325 if (SQ_CONF_SESSION_HANDLER ===
'memcache') {
326 $old_level = error_reporting(E_ERROR);
328 error_reporting($old_level);
333 $restore_session = FALSE;
334 if (isset($_SESSION[
'activated']) === TRUE && $_SESSION[
'activated'] === 1) {
337 session_regenerate_id(FALSE);
338 $new_session_id = session_id();
339 if (isset($_COOKIE[
'SQ_SYSTEM_SESSION'])) {
340 $new_session_id = $_COOKIE[
'SQ_SYSTEM_SESSION'];
344 session_id($new_session_id);
345 if (SQ_CONF_SESSION_HANDLER ===
'memcache') {
346 $old_level = error_reporting(E_ERROR);
348 error_reporting($old_level);
352 $restore_session = TRUE;
356 if ($restore_session === FALSE) {
357 if (isset($_GET[
'SOAP_SESSION_KEY']) === TRUE) {
359 if ($invalid_key === FALSE) {
360 $_SESSION[
'activated'] = 1;
361 define(
'SQ_SOAP_AUTH',
'1');
363 }
else if (isset($_GET[
'SESSION_KEY']) === TRUE) {
368 if (!defined(
'SQ_SOAP_AUTH')) {
369 define(
'SQ_SOAP_AUTH',
'0');
373 if ($session_set && $invalid_key && !$restore_session) {
374 define(
'SQ_ROLLBACK_VIEW',
'0');
375 define(
'SQ_TABLE_RUNNING_PREFIX',
'sq_');
377 $log = $ms->newMessage(Array(),
'system.security.alert', Array());
378 $log->parameters[
'remote_addr'] = $_SERVER[
'REMOTE_ADDR'];
379 $log->parameters[
'sessionid'] = session_id();
380 $log->parameters[
'userid'] = $_SESSION[
'userid'];
386 if (!empty($_REQUEST[
'SQ_ACTION']) && strpos($_REQUEST[
'SQ_ACTION'],
'rollback_view') === 0) {
391 if (!empty($_SESSION[
'sq_rollback_view']) && (!isset($_REQUEST[
'SQ_ACTION']) || $_REQUEST[
'SQ_ACTION'] !=
'logout')) {
393 define(
'SQ_ROLLBACK_VIEW',
'1');
394 define(
'SQ_TABLE_RUNNING_PREFIX',
'sq_rb_');
399 $then = $_SESSION[
'sq_rollback_view'][
'rollback_time'];
404 $sql =
'SELECT sq_set_rollback_timestamp(:then)';
406 $sql =
'DECLARE BEGIN sq_common_pkg.sq_set_rollback_timestamp(:then); END;';
414 throw new Exception(
'Unable to set rollback timestamp due to database error: '.$e->getMessage());
418 define(
'SQ_ROLLBACK_VIEW',
'0');
419 define(
'SQ_TABLE_RUNNING_PREFIX',
'sq_');
424 $_SESSION[
'user_last_access'] =
time();
428 if (isset($_REQUEST[
'a'])) {
429 $_REQUEST[
'a'] = rtrim($_REQUEST[
'a'],
'$');
435 define(
'SQ_ROLLBACK_VIEW',
'0');
436 define(
'SQ_TABLE_RUNNING_PREFIX',
'sq_');
441 if(defined(
'SQ_IN_PERFORMANCE_TIMING') && SQ_IN_PERFORMANCE_TIMING) {
442 if(isset($_REQUEST[
'performance_setting_user'])) {
445 if($_REQUEST[
'performance_setting_user'] ===
'Default' && ($GLOBALS[
'SQ_SYSTEM']->user instanceof
Public_User) && isset($_SESSION[
'SQ_PERFORMANCE_SETTING'][
'default_user'])) {
446 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($_SESSION[
'SQ_PERFORMANCE_SETTING'][
'default_user']);
449 else if ($_REQUEST[
'performance_setting_user'] ===
'Public' && !($GLOBALS[
'SQ_SYSTEM']->user instanceof Public_User)) {
450 $user = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'public_user');
456 else if(defined(
'SQ_IN_PERFORMANCE_RESULT') && SQ_IN_PERFORMANCE_RESULT) {
458 if(isset($_REQUEST[
'performance_setting_user']) ) {
459 if($GLOBALS[
'SQ_SYSTEM']->user instanceof
Public_User && isset($_SESSION[
'SQ_PERFORMANCE_SETTING'][
'default_user'])) {
460 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($_SESSION[
'SQ_PERFORMANCE_SETTING'][
'default_user']);
465 if(empty($GLOBALS[
'SQ_SYSTEM']->user) || !$GLOBALS[
'SQ_SYSTEM']->user->canAccessBackend()) exit(1);
466 $this->pm->printResults();
472 if (!empty($_REQUEST[
'SQ_ACTION'])) {
478 if (isset($_SESSION) === TRUE) {
479 $sandbox = array_get_index($_SESSION, SQ_SESSION_SANDBOX_INDEX, Array());
483 $alternate_context_id = NULL;
485 if ((SQ_IN_BACKEND === TRUE) || (SQ_IN_LIMBO === TRUE)) {
487 $alternate_context_id = array_get_index($sandbox,
'SQ_BACKEND_ALTERNATE_CONTEXT_ID');
491 if ($alternate_context_id === NULL) {
492 $alternate_context_id = array_get_index($sandbox,
'SQ_ALTERNATE_CONTEXT_ID');
495 if ($alternate_context_id !== NULL) {
500 $context_exists =
MatrixDAL::executeAll(
'core',
'getContexts', Array(
'contextids' => Array($alternate_context_id)));
501 if (empty($context_exists) === TRUE) {
502 $alternate_context_id = NULL;
508 $alternate_context_id = 0;
511 }
else if (SQ_PHP_CLI) {
512 $alternate_context_id = 0;
515 if ((isset($alternate_context_id) === FALSE) || ($alternate_context_id === NULL)) {
536 $require_password_change = ($this->user && !($this->user instanceof
Public_User) && $this->user->status == SQ_STATUS_LIVE_APPROVAL);
538 if (SQ_IN_BACKEND || SQ_IN_LIMBO) {
540 if ($require_password_change) {
541 $this->
paintPasswordChange(translate(
'change_password'), translate(
'must_change_password_to_access_backend'));
545 if ($this->user && !($this->user instanceof
Public_User)) {
546 require_once SQ_INCLUDE_PATH.
'/backend.inc';
548 $this->backend = &$backend;
550 $current_url = current_url(FALSE, TRUE);
551 $designid = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromUrl($current_url);
552 $design_no_frame = NULL;
553 if (!empty($designid)) {
554 $design = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($designid[
'designid']);
555 if ($design->type() ===
'design_customisation') {
557 $parent_designs = $GLOBALS[
'SQ_SYSTEM']->am->getParents($designid[
'designid'],
'design', TRUE);
558 $effective_designid = NULL;
559 if (count($parent_designs) > 0) {
560 $effective_designid = array_keys($parent_designs);
561 $effective_designid = $effective_designid[0];
564 $effective_designid = $designid[
'designid'];
566 $design_no_frame = $GLOBALS[
'SQ_SYSTEM']->am->getDesignHideFrameValues($effective_designid);
569 if ($design_no_frame) {
570 define(
'SQ_DESIGN_NO_FRAME', 1);
572 define(
'SQ_DESIGN_NO_FRAME', 0);
579 $this->
paintLogin(translate(
'login'), translate(
'must_login_to_access_backend'));
582 }
else if (SQ_IN_LOGIN) {
583 $this->
paintLogin(translate(
'login'), translate(
'must_login_to_access_backend'));
587 if (!(SQ_IN_CRON || SQ_PHP_CLI) && defined(
'SQ_CONF_REDIRECT_URL_WITH_TRAILING_SLASH') && SQ_CONF_REDIRECT_URL_WITH_TRAILING_SLASH){
588 $host = (isset($_SERVER[
'HTTP_HOST'])) ? $_SERVER[
'HTTP_HOST'] : FALSE;
589 $uri = (isset($_SERVER[
'REQUEST_URI'])) ? $_SERVER[
'REQUEST_URI'] : FALSE;
590 if ($host && $uri && substr($uri, -1) ==
'/') {
591 $uri = rtrim($uri,
'/');
594 $protocol = current_protocol().
'://';
595 header(
'HTTP/1.1 301 Moved Permanently');
596 header(
'Location: '.$protocol.$host.$uri);
603 if (isset($_REQUEST[
'a'])) {
605 if ($this->am->assetInTrash($_REQUEST[
'a'], TRUE)) {
608 $asset = $this->am->getAsset($_REQUEST[
'a'],
'', TRUE);
612 if (is_null($asset)){
613 $rm = $this->am->getSystemAsset(
'remap_manager');
614 $protocol = current_protocol();
615 if ($rm->loadRemapFromURL($protocol,
'?a='.$_REQUEST[
'a'])) exit();
617 $substr = substr($_REQUEST[
'a'], 0, strpos($_REQUEST[
'a'],
'?'));
618 if ($substr && $rm->loadRemapFromURL($protocol,
'?a='.$substr)) exit();
621 $asset = $this->am->getAssetFromURL(NULL, NULL, TRUE, TRUE);
622 if ($asset != NULL) {
623 $valid_protocols = $asset->getValidProtocols();
624 if (empty($valid_protocols)) {
633 if (!is_null($asset) && !$asset->effectiveUnrestricted() && $require_password_change) {
634 $page_name =
'"'.$asset->name.
'"';
635 $this->
paintPasswordChange(translate(
'change_password'), translate(
'must_change_password_to_access_asset', $page_name));
640 if (is_null($asset)) {
642 $rm = $this->am->getSystemAsset(
'remap_manager');
643 if(!($rm->loadRemapFromCurrentURL())) {
644 $url = strip_url(current_url(FALSE, TRUE));
645 $protocol = current_protocol();
649 $root_url = $this->am->getRootURL($url);
653 if (!empty($root_url)) {
654 $site = $this->am->getAsset($root_url[
'assetid']);
655 if (!is_null($site)) {
656 $page = $site->getSpecialPage(
'not_found');
657 if (!is_null($page)) {
667 if (!$rm->paintPageNotFoundRemap()) {
668 header(
'HTTP/1.0 404 Not Found');
670 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
672 if (SQ_CONF_SEND_CACHEABLE_HEADER && SQ_CONF_SEND_404_CACHEABLE_HEADER && $cm->cacheableHeadersEnabledForCurrentProtocol()) {
673 header(
'Pragma: cache');
675 $browser_cache_expiry = $cm->attr(
'browser_cache_expiry');
676 if (empty($browser_cache_expiry)) {
677 $browser_cache_expiry = $cm->attr(
'expiry');
680 header(
'Cache-Control: max-age='.$browser_cache_expiry.
', '.$cm->cacheControlLevel());
681 header(
'Expires: '.gmdate(
'D, d M Y H:i:s',
time() + $browser_cache_expiry).
' GMT');
685 trigger_localised_error(
'SYS0218', E_USER_NOTICE, $protocol.
'://'.$url);
696 if (isset($_SERVER[
'HTTP_USER_AGENT']) && strpos($_SERVER[
'HTTP_USER_AGENT'],
'Funnelback') !== FALSE) {
697 $fbm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'funnelback_manager', TRUE);
698 if (!is_null($fbm)) {
699 $fb_user = $fbm->attr(
'user');
701 $security_keys = $fbm->getAccessLocks($asset);
702 header(
'X-Funnelback-Locks: '.$security_keys);
704 header(
'X-Funnelback-SQUIZASSETYPE: '.$asset->type());
705 header(
'X-Funnelback-last_modified: '.
date(
'Y-m-d', $asset->updated).
'T'.
date(
'H:i:s', $asset->updated));
706 if ($asset instanceof
File) {
707 header(
'X-Funnelback-file-title: '.$asset->attr(
'title'));
708 header(
'X-Funnelback-file-name: '.$asset->name);
710 if ($asset->created_userid != 0) {
711 $created_by = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($asset->created_userid);
712 header(
'X-Funnelback-author-name: '.$created_by->name);
713 header(
'X-Funnelback-author-id: '.$created_by->id);
715 header(
'X-Funnelback-created: '.
date(
'Y-m-d', $asset->created).
'T'.
date(
'H:i:s', $asset->created));
716 header(
'X-Funnelback-ancestors: '.implode(
' ', array_keys($GLOBALS[
'SQ_SYSTEM']->am->getParents($asset->id))));
719 $mm = $GLOBALS[
'SQ_SYSTEM']->getMetadataManager();
720 require_once SQ_FUDGE_PATH.
'/general/text.inc';
722 $metadata = $mm->getMetadata($asset->id);
723 foreach ($metadata as $info) {
724 $name = $info[0][
'name'];
726 $value = $info[0][
'value'];
727 $keywords = retrieve_keywords_replacements($value);
728 $replacements = Array();
729 foreach ($keywords as $keyword) {
730 $replacements[$keyword] = $asset->getKeywordReplacement($keyword);
732 replace_keywords($value, $replacements);
733 $name = $fbm->encodeText(htmlspecialchars($name, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
734 $value = $fbm->encodeText(htmlspecialchars($value, ENT_COMPAT, SQ_CONF_DEFAULT_CHARACTER_SET));
735 header(
'X-Funnelback-metadata-'.$name.
': '.$value);
742 if (SQ_IN_PERFORMANCE) {
743 if(empty($GLOBALS[
'SQ_SYSTEM']->user) || !$GLOBALS[
'SQ_SYSTEM']->user->canAccessBackend() || !$asset->writeAccess()) {
744 $this->
paintLogin(translate(
'login'), translate(
'must_login_to_access_backend'));
746 $this->pm->printFrames($asset);
755 if (!is_null($asset)) {
756 $asset_type = $asset->type();
757 if ($asset_type ==
'site' || $GLOBALS[
'SQ_SYSTEM']->am->isTypeDecendant($asset_type,
'site')) {
763 if ($site === NULL) {
764 $asset_url = current_url(FALSE, TRUE);
766 $asset_lineage = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromURL(NULL, $asset_url, TRUE);
767 foreach ($asset_lineage as $asset_link) {
768 $asset_type = $asset_link[
'type_code'];
769 if ($asset_type ==
'site' || $GLOBALS[
'SQ_SYSTEM']->am->isTypeDecendant($asset_type,
'site')) {
770 $site_assetid = $asset_link[
'assetid'];
771 if (!empty($site_assetid)) {
772 $site = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($site_assetid);
779 if (!is_null($site)) {
780 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'CURRENT_SITE', $site);
786 if (($asset->status == SQ_STATUS_ARCHIVED) && !$asset->readAccess()) {
788 if (!(SQ_IN_BACKEND || SQ_IN_LIMBO)) {
790 $site = $GLOBALS[
'SQ_SYSTEM']->getGlobalDefine(
'CURRENT_SITE');
792 $url = strip_url(current_url(FALSE, TRUE));
793 $root_url = $this->am->getRootURL($url);
794 if (!empty($root_url)) {
795 $site = $this->am->getAsset($root_url[
'assetid']);
799 if (!is_null($site)) {
800 $page = $site->getSpecialPage(
'archive');
801 if (!is_null($page)) {
809 $this->frontend_asset = &$asset;
813 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
818 if (basename($_SERVER[
'PHP_SELF']) == SQ_CONF_RECACHE_SUFFIX) {
821 $url = strip_url(current_url(TRUE, TRUE));
822 $cm->clearCachedAssetsByUrl($url);
823 $GLOBALS[
'SQ_SYSTEM']->broadcastTriggerEvent(
'trigger_event_asset_recached', $asset);
826 if (SQ_CONF_SEND_CACHEABLE_HEADER && $cm->cacheableHeadersEnabledForCurrentProtocol() && $cm->sendCacheableHeaders($asset->type(), $asset->id)) {
829 $asset->printFrontend();
834 else if (basename($_SERVER[
'PHP_SELF']) != SQ_CONF_NOCACHE_SUFFIX &&
835 SQ_CONF_SEND_CACHEABLE_HEADER &&
836 empty($_POST) && $asset->status >= SQ_STATUS_LIVE &&
837 $asset->readAccess() &&
838 !(isset($_REQUEST[
'just_logged_out']) && $_REQUEST[
'just_logged_out']) &&
839 $cm->cacheableHeadersEnabledForCurrentProtocol() &&
840 $cm->sendCacheableHeaders($asset->type(), $asset->id)
845 $asset->printFrontend();
847 $content = ob_get_contents();
849 if (ob_get_length() !== FALSE) ob_end_clean();
854 if (SQ_CONF_NO_ASSET_SELF_LINKS) {
855 $content = parse_self_links($content);
867 $content = preg_replace(
'|<sq_wysiwyg_([^ >]*)([^>]*)>(.*)</sq_wysiwyg_\1>|si',
'$3', $content);
873 if (SQ_CONF_DEBUG & 4) {
875 log_write($this->am->getForgottenItemsReport(),
'asset_cache', E_USER_NOTICE, FALSE);
878 if (!defined(
'SQ_DESIGN_NO_FRAME')) {
879 define(
'SQ_DESIGN_NO_FRAME', 0);
883 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cm);
898 include SQ_DATA_PATH.
'/private/conf/apache.inc';
899 foreach ($request_notes as $note_name => $note_info) {
902 switch ($note_info[
'type']) {
904 $note_value = $GLOBALS[
'SQ_SYSTEM']->user->getKeywordReplacement($note_info[
'keyword']);
907 if (isset($this->frontend_asset) && $this->frontend_asset->id) {
908 $note_value = $this->frontend_asset->getKeywordReplacement($note_info[
'keyword']);
912 if ((trim($note_value) !==
'') && ($note_value !==
'%'.$note_info[
'keyword'].
'%')) {
913 apache_note($note_name, $note_value);
930 $recache = basename($_SERVER[
'PHP_SELF']) == SQ_CONF_RECACHE_SUFFIX;
933 header(
'Pragma: cache');
937 $cache_key =
'cache_info';
938 if ($contextid !== 0) {
939 $cache_key .=
'.'.$contextid;
943 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
944 $cache_info = $cm->loadFromCache($asset->id, $asset->type(), $cache_key);
946 $cache_expiry = $cm->getExpiry($asset->type(), $asset->id);
947 $browser_cache_expiry = $cm->getBrowserCacheExpiry($asset->type(), $asset->id);
948 if (empty($browser_cache_expiry)) {
949 $browser_cache_expiry = $cache_expiry;
952 header(
'Cache-Control: max-age='.$browser_cache_expiry.
', '.$cm->cacheControlLevel());
956 if ($cache_info === FALSE) {
958 $loaded_assetids = $GLOBALS[
'SQ_SYSTEM']->am->_asset_cache->getAssetKeys();
959 $asset->printFrontend();
960 $all_assetids = $GLOBALS[
'SQ_SYSTEM']->am->_asset_cache->getAssetKeys();
961 $content = ob_get_contents();
965 $assetids = array_diff($all_assetids, $loaded_assetids);
968 foreach ($assetids as &$assetid) {
969 $assetid_bits = explode(
'\\', $assetid, 2);
970 if ($assetid_bits > 1) {
971 $assetid = $assetid_bits[1];
975 $last_updated = $asset->getEffectiveLastUpdatedTime($assetids);
979 'last_modified' => $last_updated,
980 'expires' => (
time() + $cache_expiry),
982 $cm->saveToCache($asset->id, $asset->type(), $cache_key, serialize($info));
986 $expiry_time =
time() + $browser_cache_expiry;
989 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', $expiry_time).
' GMT');
990 if (SQ_CONF_SEND_LAST_MODIFIED_HEADER ) {
991 header(
'Last-Modified: '.gmdate(
'D, d M Y H:i:s', $info[
'last_modified']).
' GMT');
998 $info = unserialize($cache_info);
999 $last_modified = gmdate(
'D, d M Y H:i:s', $info[
'last_modified']).
' GMT';
1001 $not_modified = FALSE;
1003 if (isset($headers[
'If-Modified-Since']) && ($last_modified == $headers[
'If-Modified-Since'])) {
1004 $not_modified =TRUE;
1009 $browser_cache_expiry = $cm->getBrowserCacheExpiry($asset->type(), $asset->id);
1010 if (empty($browser_cache_expiry)) {
1011 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', $info[
'expires']).
' GMT');
1013 header(
'Expires: '.gmdate(
'D, d M Y H:i:s',
time() + $browser_cache_expiry).
' GMT');
1016 if (SQ_CONF_SEND_LAST_MODIFIED_HEADER) {
1017 header(
'Last-Modified: '.$last_modified);
1019 if (SQ_CONF_SEND_NOT_MODIFIED_HEADER && $not_modified) {
1020 header(
'HTTP/1.1 304 Not Modified');
1024 $asset->printFrontend();
1028 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($cm);
1045 replace_global_keywords($content);
1047 if ($this->
getGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', TRUE)) {
1049 $keywords = retrieve_keywords_replacements($content);
1050 foreach ($keywords as $word) {
1051 if (!isset($additional_replacements[$word])) {
1052 $replacement = $this->frontend_asset->getKeywordReplacement($word);
1054 if (($replacement ==
"%$word%") && (strpos(
'0123456789', $word[0]) === FALSE)) {
1055 $additional_replacements[$word] =
'';
1057 $additional_replacements[$word] = $replacement;
1061 replace_keywords($content, $additional_replacements);
1081 if (!empty($index)) {
1082 $this->_global_defines[$index] = $value;
1098 unset($this->_global_defines[$index]);
1114 if (!is_array($this->_global_defines))
return $default;
1115 return $this->
isGlobalDefineSet($index) ? $this->_global_defines[$index] : $default;
1130 return (isset($this->_global_defines[$index])) ? TRUE : FALSE;
1156 header(
'HTTP/1.0 403 Forbidden');
1158 if (array_get_index($_REQUEST,
'SQ_BACKEND_PAGE') ==
'header') {
1160 $redirect_location = replace_query_string_vars(Array(
'SQ_BACKEND_PAGE' => NULL));
1161 $redirect_location = strip_tags(addslashes($redirect_location));
1163 <script type=
"text/javascript">
1164 window.parent.document.location =
'<?php echo $redirect_location; ?>';
1169 if ((current_protocol() ==
'http') && (SQ_CONF_FORCE_SECURE_LOGIN_URLS !=
'')) {
1171 $current_url = current_url(FALSE, TRUE);
1172 $root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
1173 $current_root_url =
'';
1174 foreach ($root_urls as $url) {
1175 if (0 === strpos($current_url, $url)) {
1176 if (strlen($url) > strlen($current_root_url)) {
1177 $current_root_url = $url;
1182 if (in_array($current_root_url, explode(
"\n", SQ_CONF_FORCE_SECURE_LOGIN_URLS))) {
1184 $_SESSION[
'SQ_RETURN_TO_HTTP'] = 1;
1185 do_redirect(
'https://'.current_url(FALSE));
1188 $GLOBALS[
'SQ_LOGIN_FORM'] = Array(
'paint' =>
'login',
'heading' => $heading,
'msg' => $msg);
1191 if (SQ_CONF_ENABLE_HTTP_LOGIN && !empty($_GET[
'USE_HTTP_LOGIN']) && !isset($_SERVER[
'PHP_AUTH_USER'])) {
1194 $_SESSION[
'user'] = NULL;
1195 $_SESSION[
'userid'] = NULL;
1196 $_SESSION[
'user_type_code'] = NULL;
1199 header(
'WWW-Authenticate: Basic realm="MySource Matrix"');
1200 header(
'HTTP/1.0 401 Unauthorized');
1203 if (empty($_GET[
'FORCE_BACKUP_LOGIN'])) {
1205 $current_asset = $this->am->getAssetFromURL(NULL, NULL, TRUE, TRUE);
1207 if (is_null($current_asset)) {
1208 $current_asset = $this->am->getSystemAsset(
'root_folder');
1209 if (is_null($current_asset)) {
1210 trigger_localised_error(
'SYS0248', E_USER_ERROR);
1214 $design_info = $this->am->getDesignFromURL(strip_url(current_url(FALSE, TRUE)),
'design::system::login');
1218 $design = $this->am->getAsset($design_info[
'designid'], $design_info[
'type_code']);
1221 $design = $this->am->getSystemAsset(
'login_design');
1224 if (!is_null($design)) {
1225 $design->paint($current_asset);
1232 if ($this->_msgs) echo implode(
'<br />', $this->_msgs);
1233 require_once SQ_INCLUDE_PATH.
'/login.inc';
1251 $GLOBALS[
'SQ_PASSWORD_CHANGE_FORM'] = Array(
'paint' =>
'password_change',
'heading' => $heading,
'msg' => $msg);
1253 if ((current_protocol() ==
'http') && (SQ_CONF_FORCE_SECURE_LOGIN_URLS !=
'')) {
1256 $current_url = current_url(FALSE, TRUE);
1257 $root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
1258 $current_root_url =
'';
1259 foreach ($root_urls as $url) {
1260 if (0 === strpos($current_url, $url)) {
1261 if (strlen($url) > strlen($current_root_url)) {
1262 $current_root_url = $url;
1267 if (in_array($current_root_url, explode(
"\n", SQ_CONF_FORCE_SECURE_LOGIN_URLS))) {
1269 $_SESSION[
'SQ_RETURN_TO_HTTP'] = 1;
1270 do_redirect(
'https://'.current_url(FALSE));
1274 if (empty($_GET[
'FORCE_BACKUP_PASSWORD_CHANGE'])) {
1276 $current_asset = $this->am->getAssetFromURL(NULL, NULL, TRUE, TRUE);
1278 if (is_null($current_asset)) {
1279 $current_asset = $this->am->getSystemAsset(
'root_folder');
1280 if (is_null($current_asset)) {
1281 trigger_localised_error(
'SYS0248', E_USER_ERROR);
1285 $design_info = $this->am->getDesignFromURL(strip_url(current_url(FALSE, TRUE)),
'design::system::password_change');
1289 $design = $this->am->getAsset($design_info[
'designid'], $design_info[
'type_code']);
1292 $design = $this->am->getSystemAsset(
'password_change_design');
1295 if (!is_null($design)) {
1296 $design->paint($current_asset);
1303 if ($this->_msgs) echo implode(
'<br />', $this->_msgs);
1304 require_once SQ_INCLUDE_PATH.
'/password_change.inc';
1317 if (!SQ_CONF_ALLOW_IP_CHANGE && isset($_SESSION[
'remote_addr']) && ($_SESSION[
'remote_addr'] != $_SERVER[
'REMOTE_ADDR'])) {
1319 if (!SQ_SOAP_AUTH) {
1320 if (isset($_SESSION[
'activated']) === FALSE || $_SESSION[
'activated'] != 1) {
1322 $this->
_logSecurityMsg(
'system.security.logout.ip_change', Array(
'old_ip' => $_SESSION[
'remote_addr'],
'new_ip' => $_SERVER[
'REMOTE_ADDR']));
1333 if (!empty($_SESSION[
'userid']) && !empty($_SESSION[
'user']) && !empty($_SESSION[
'user_serialised_ts'])) {
1334 $userid = $_SESSION[
'userid'];
1336 $user_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(Array($userid), $_SESSION[
'user_type_code'], TRUE,
'updated');
1337 $user_updated_date = array_get_index($user_info, $userid, FALSE);
1338 if ($user_updated_date && $_SESSION[
'user_serialised_ts'] > iso8601_ts($user_updated_date) || (!$user_updated_date && SQ_ROLLBACK_VIEW)) {
1339 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($_SESSION[
'user_type_code']);
1340 $this->user = unserialize($_SESSION[
'user']);
1341 $GLOBALS[
'SQ_SYSTEM']->am->rememberAsset($this->user);
1345 if (is_null($this->user) && !empty($_SESSION[
'userid'])) {
1349 $this->user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($_SESSION[
'userid'], $_SESSION[
'user_type_code']);
1350 if (!is_null($this->user)) {
1351 $_SESSION[
'user'] = serialize($this->user);
1352 $_SESSION[
'user_serialised_ts'] =
time();
1356 if (is_null($this->user) || $this->user instanceof
Public_User) {
1358 if (defined(
'SQ_CONF_ALLOW_HTTP_LOGIN') && SQ_CONF_ALLOW_HTTP_LOGIN) {
1363 if (is_null($this->user)) {
1365 if (defined(
'SQ_CONF_ACCEPT_HTTP_CREDS') && SQ_CONF_ACCEPT_HTTP_CREDS) {
1370 if (is_null($this->user)) {
1376 $security_actions = Array(
'login',
'logout',
'password_change',
'hipo',
'asset_map_request');
1377 $has_security_action = in_array(array_get_index($_REQUEST,
'SQ_ACTION'), $security_actions);
1378 if (array_get_index($_SESSION,
'user_last_access') && !$has_security_action) {
1380 $session_prefs = $this->
getUserPrefs(
'user',
'SQ_USER_SESSION_PREFS', TRUE);
1384 if (!empty($user_prefs[
'timeout'])) {
1385 if (
time() - $_SESSION[
'user_last_access'] > $user_prefs[
'timeout']) {
1386 $this->
_logSecurityMsg(
'system.security.logout.idle', Array(
'timeout' => $user_prefs[
'timeout']));
1399 if (array_get_index($_SESSION,
'user_last_authentication')) {
1400 if (!empty($user_prefs[
'max_length'])) {
1401 $session_expiry_ts = $_SESSION[
'user_last_authentication'] + $user_prefs[
'max_length'];
1402 $today_start_ts = strtotime(
'00:00:01 today');
1403 $tomorrow_start_ts = strtotime(
'00:00:01 tomorrow');
1404 if ($session_expiry_ts < $today_start_ts) {
1406 $this->
_logSecurityMsg(
'system.security.logout.staleauth', Array(
'timeout' => $user_prefs[
'max_length']));
1410 }
else if ($session_expiry_ts < $tomorrow_start_ts) {
1412 if (
time() - $_SESSION[
'user_last_access'] > SQ_CONF_EDITING_TIME) {
1415 $this->
_logSecurityMsg(
'system.security.logout.staleauth', Array(
'timeout' => $user_prefs[
'max_length']));
1426 $this->_user_is_root = $_SESSION[
'user_is_root'];
1427 $this->_user_is_sys_admin = $_SESSION[
'user_is_sys_admin'];
1428 $this->_user_is_public = $_SESSION[
'user_is_public'];
1443 switch ($_REQUEST[
'SQ_ACTION']) {
1444 case 'password_change' :
1445 $password_old = array_get_index($_POST,
'SQ_PASSWORD_CHANGE_OLD');
1446 $password_new = array_get_index($_POST,
'SQ_PASSWORD_CHANGE_NEW');
1447 $password_confirm = array_get_index($_POST,
'SQ_PASSWORD_CHANGE_CONFIRM');
1449 if (is_null($password_old))
return;
1450 if (is_null($password_new))
return;
1451 if (is_null($password_confirm))
return;
1453 if (!$this->user->comparePassword($password_old)) {
1454 $this->
addMessage(
'Your old password is incorrect');
1458 if ($password_old == $password_new) {
1459 $this->
addMessage(
'The new password must be different from your old one');
1463 if ($password_new != $password_confirm) {
1464 $this->
addMessage(
'The new and confirmed passwords do not match');
1468 include_once SQ_ATTRIBUTES_PATH.
'/password/password.inc';
1470 if (!$pass_attr->validateValue($password_new)) {
1475 if ($this->user && !($this->user instanceof
Public_User)) {
1477 if ($GLOBALS[
'SQ_SYSTEM']->
runLevelEnables(SQ_SECURITY_PERMISSIONS)) {
1478 $run_level_changed = TRUE;
1479 $GLOBALS[
'SQ_SYSTEM']->setRunLevel($GLOBALS[
'SQ_SYSTEM']->
getRunLevel() - SQ_SECURITY_PERMISSIONS);
1481 $run_level_changed = FALSE;
1485 if ($this->user->validatePassword($password_new, TRUE)) {
1486 $result = $this->user->setAttrValue(
'password', $password_new);
1487 $result = $result && $this->user->saveAttributes();
1490 if ($run_level_changed) {
1491 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
1494 if ($result && $this->user->status != SQ_STATUS_LIVE) {
1495 $available_statuses = $this->user->getAvailableStatii();
1496 if (!isset($available_statuses[SQ_STATUS_LIVE]) || !$this->user->processStatusChange(SQ_STATUS_LIVE)) {
1497 trigger_localised_error(
'SYS0304', E_USER_ERROR);
1506 $login_username = array_get_index($_POST,
'SQ_LOGIN_USERNAME');
1507 $login_password = array_get_index($_POST,
'SQ_LOGIN_PASSWORD');
1508 $login_key = array_get_index($_POST,
'SQ_LOGIN_KEY');
1509 if (is_null($login_username) || is_null($login_password)) {
1515 if (!is_null($this->user) && $login_username == $this->user->attr(
'username')) {
1517 $current_url = current_url(TRUE,TRUE);
1518 do_redirect($current_url);
1522 if (!is_null($login_key) && $this->
loginKey() == $login_key) {
1525 $auth_folder = $this->am->getSystemAsset(
'authentication_folder');
1526 if (is_null($auth_folder)) {
1527 trigger_localised_error(
'SYS0249', E_USER_ERROR);
1530 $auth_systems = $auth_folder->getAuthSystems();
1533 $user_status = NULL;
1534 foreach ($auth_systems as $systemid) {
1535 $system = $this->am->getAsset($systemid);
1536 if (is_null($system))
continue;
1540 if ($login_username ===
'root' && $system->name !=
'Default Authentication')
continue;
1542 $user = $system->authenticateUser($login_username, $login_password);
1543 if (!is_null($user)) $user_status = $user->status;
1546 if (!is_null($user) && $user->canLogin()) {
1551 $failure_reason = translate(
'user_not_found');
1552 if (!is_null($user_status)) {
1553 if ($user_status & SQ_SC_STATUS_NOT_LIVE) {
1554 $failure_reason = translate(
'user_status_not_live');
1556 $failure_reason = translate(
'user_asset_in_trash');
1560 $this->
addMessage(translate(
'user_not_found'));
1562 $this->
_logSecurityMsg(
'system.security.login.failed', Array(
'login_name' => $login_username,
'failure_reason' => $failure_reason), TRUE);
1567 $this->
addMessage(translate(
'login_key_incorrect'));
1573 $for_real = ($this->user && !($this->user instanceof Public_User));
1574 $old_user = &$this->user;
1577 if (isset($_SESSION[
'login_as_invoker_user_full_name'])) {
1578 $this->
_logSecurityMsg(
'system.security.logout.secondary.manual', Array(
'secondary_user_name' => $_SESSION[
'login_as_invoker_user_full_name']));
1586 if (!isset($_SESSION[
'login_as_invoker_id']) && !isset($_SESSION[
'login_as_invoker_username'])) {
1587 $stalled_hipo_array = Array();
1588 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
1589 $current_userid = $GLOBALS[
'SQ_SYSTEM']->currentUserId();
1592 $stalled_hipo_array = $hh->getJobsForUser($current_userid);
1594 if (SQ_IN_BACKEND && !empty($stalled_hipo_array)) {
1595 $return_url = current_protocol().
'://'.current_url(FALSE);
1598 if (!$_SESSION[
'user_is_public'] && array_get_index($_SESSION,
'SQ_RETURN_TO_HTTP')) {
1599 unset($_SESSION[
'SQ_RETURN_TO_HTTP']);
1600 $return_url =
'http://'.current_url(FALSE);
1602 $return_url = replace_query_string_vars(Array(
'SQ_ACTION' => NULL), $return_url);
1603 require_once dirname(__FILE__).
'/hipo_reminder.inc';
1613 if (isset($_SERVER[
'PHP_AUTH_USER'])) { unset($_SERVER[
'PHP_AUTH_USER']); }
1614 if (isset($_SERVER[
'PHP_AUTH_PW'])) { unset ($_SERVER[
'PHP_AUTH_PW']); }
1617 $invoker_user_id = NULL;
1618 if (isset($_SESSION[
'login_as_invoker_id']) && isset($_SESSION[
'login_as_invoker_username'])) {
1619 $invoker_user_id = $_SESSION[
'login_as_invoker_id'];
1620 $invoker_username = $_SESSION[
'login_as_invoker_username'];
1621 $this->_loginAsUser($invoker_username, $invoker_user_id, TRUE);
1632 $_REQUEST[
'just_logged_out'] = 1;
1635 case 'real_logout' :
1636 $for_real = ($this->user && !($this->user instanceof Public_User));
1637 $old_user = &$this->user;
1652 if (isset($_GET[
'user'])) {
1653 $username = trim($_GET[
'user']);
1661 if (($username !=
'root') && (($username != $this->user->attr(
'username')) && (strlen($username) > 0))) {
1662 $this->_loginAsUser($username);
1666 case 'send_security_key' :
1667 require_once SQ_FUDGE_PATH.
'/general/general.inc';
1668 $vars = &$_SESSION[
'SQ_SYSTEM_SECURITY_KEY'];
1671 $vars[
'key'] = generate_security_key(strlen($vars[
'key']), $vars[
'include_uppercase'], $vars[
'include_numbers']);
1679 $vars[
'text_colour'],
1680 $vars[
'border_colour'],
1682 $vars[
'use_colours'],
1692 $vars[
'ttf_height'],
1694 $vars[
'arc_colour'],
1695 $vars[
'include_uppercase'],
1696 $vars[
'include_numbers']
1700 case 'attribute_image' :
1702 $allowed_attributes = Array(
'email');
1703 if (isset($_GET[
'attribute']) && !empty($_GET[
'attribute'])) {
1704 $attribute = $_GET[
'attribute'];
1705 if (!in_array($attribute, $allowed_attributes)) {
1709 if (isset($_GET[
'id']) && !empty($_GET[
'id'])) {
1710 $assetid = $_GET[
'id'];
1711 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
1712 if (is_null($asset) || !empty($attribute)) {
1713 $text = $asset->attr($attribute);
1718 $text = $asset->attr($attribute);
1725 case 'rollback_view_start' :
1726 $_SESSION[
'sq_rollback_view'] = Array();
1728 if (isset($_GET[
'assetid']) && isset($_GET[
'version'])) {
1730 $assetid = $_GET[
'assetid'];
1731 $version = $_GET[
'version'];
1737 'assetid' => $assetid,
1738 'version' => $version,
1741 }
catch (Exception $e) {
1742 throw new Exception(
'Could not find version '.$version.
' of asset ID #'.$assetid.
' in rollback system due to database error: '.$e->getMessage());
1744 $_SESSION[
'sq_rollback_view'] = Array(
'rollback_time' => $then);
1747 unset($_GET[
'assetid']);
1748 unset($_GET[
'version']);
1751 case 'rollback_view_stop' :
1752 if (isset($_SESSION[
'sq_rollback_view'])) {
1753 unset($_SESSION[
'sq_rollback_view']);
1759 if ($hh->processWeb()) $hh->paintWeb();
1763 case 'set_design_name' :
1764 $_SESSION[
'SQ_DESIGN_NAME'] = (isset($_GET[
'SQ_DESIGN_NAME'])) ? $_GET[
'SQ_DESIGN_NAME'] :
'';
1765 unset($_GET[
'SQ_DESIGN_NAME']);
1768 case 'clear_design_name' :
1769 if (isset($_SESSION[
'SQ_DESIGN_NAME'])) {
1770 unset($_SESSION[
'SQ_DESIGN_NAME']);
1774 case 'set_context' :
1777 $context_name = (isset($_GET[
'SQ_CONTEXT_NAME'])) ? $_GET[
'SQ_CONTEXT_NAME'] :
'';
1778 unset($_GET[
'SQ_CONTEXT_NAME']);
1779 $context_data =
MatrixDAL::executeAll(
'core',
'getContextByName', Array(
'name' => Array($context_name)));
1780 if (empty($context_data) === FALSE) {
1781 $contextid = $context_data[0][
'contextid'];
1782 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $contextid;
1786 case 'set_backend_context' :
1789 if ((SQ_IN_BACKEND === TRUE) || (SQ_IN_LIMBO === TRUE)) {
1791 $context_name = (isset($_GET[
'SQ_CONTEXT_NAME'])) ? $_GET[
'SQ_CONTEXT_NAME'] :
'';
1792 unset($_GET[
'SQ_CONTEXT_NAME']);
1793 $context_data =
MatrixDAL::executeAll(
'core',
'getContextByName', Array(
'name' => Array($context_name)));
1794 if (empty($context_data) === FALSE) {
1795 $contextid = $context_data[0][
'contextid'];
1796 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_BACKEND_ALTERNATE_CONTEXT_ID'] = $contextid;
1802 case 'clear_context' :
1803 if ((isset($_SESSION[SQ_SESSION_SANDBOX_INDEX]) === TRUE) && (isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID']) === TRUE)) {
1804 unset($_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID']);
1808 case 'asset_map_request' :
1809 require_once SQ_LIB_PATH.
'/asset_map/asset_map.inc';
1811 $asset_map->process($this->backend);
1815 case 'get_soap_downloaded_file' :
1816 $filename = array_get_index($_GET,
'soap_filename',
'');
1817 $sessionid = session_id();
1818 $full_file_path = SQ_DATA_PATH.
'/private/soap_action_file_responses/'.$sessionid.
'/'.$filename;
1820 if (!file_exists($full_file_path)) {
1821 trigger_localised_error(
'FVER0007', E_USER_WARNING, $filename);
1825 if (version_compare(PHP_VERSION,
'5.3.0') >= 0) {
1826 $finfo = finfo_open(FILEINFO_MIME_TYPE);
1827 $mime_type = finfo_file($finfo, $full_file_path);
1829 $mime_type = mime_content_type($full_file_path);
1831 header(
'Content-type: '.$mime_type);
1832 readfile($full_file_path);
1838 echo (get_unique_token());
1844 $_REQUEST[
'SQ_ACTION'] =
'';
1857 if (empty($this->user) || !($this->user instanceof
Public_User)) {
1859 $_SESSION[
'user_is_root'] = $this->_user_is_root = FALSE;
1860 $_SESSION[
'user_is_sys_admin'] = $this->_user_is_sys_admin = FALSE;
1861 $_SESSION[
'user_is_public'] = $this->_user_is_public = TRUE;
1862 $_SESSION[
'userid'] = $this->user->id;
1863 $_SESSION[
'user_type_code'] = $this->user->type();
1864 $_SESSION[
'remote_addr'] = (isset($_SERVER[
'REMOTE_ADDR'])) ? $_SERVER[
'REMOTE_ADDR'] :
'';
1865 $_SESSION[
'user'] = serialize($this->user);
1866 $_SESSION[
'user_serialised_ts'] =
time();
1885 private function _loginAsUser($username, $resuming_user_id_match=
'', $resuming_session=FALSE)
1887 $logged_in = ($this->user && !($this->user instanceof
Public_User));
1889 if ($logged_in && ($GLOBALS[
'SQ_SYSTEM']->
userRoot() || $GLOBALS[
'SQ_SYSTEM']->userSystemAdmin() || $resuming_session)) {
1890 $old_user = $this->user;
1891 $invoking_user_id = $this->user->id;
1892 $invoking_username = $this->user->attr(
'username');
1893 $invoking_user_full_name = $this->user->name;
1896 $invoking_user_nav_history = NULL;
1897 if ($resuming_session) {
1898 if (isset($_SESSION[
'login_as_invoker_sq_nav_history'])) {
1899 $invoking_user_nav_history = $_SESSION[
'login_as_invoker_sq_nav_history'];
1902 if (isset($_SESSION[
'sq_nav_history'])) {
1903 $invoking_user_nav_history = $_SESSION[
'sq_nav_history'];
1922 $auth_folder = $this->am->getSystemAsset(
'authentication_folder');
1923 if (is_null($auth_folder)) {
1924 trigger_localised_error(
'SYS0249', E_USER_ERROR);
1927 $auth_systems = $auth_folder->getAuthSystems();
1930 $secondary_user = NULL;
1931 $user_status = NULL;
1932 $failure_reason = translate(
'user_not_found');
1934 foreach ($auth_systems as $systemid) {
1935 $system = $this->am->getAsset($systemid);
1936 if (is_null($system))
continue;
1939 $secondary_user = $system->locateUser($username);
1940 if (!is_null($secondary_user)) {
1943 if ($resuming_session && ($secondary_user->id != $resuming_user_id_match)) {
1945 $this->
_logSecurityMsg(
'system.security.login.secondary.failed', Array(
'login_name' => $old_user->attr(
'username'),
'secondary_login_name' => $username,
'failure_reason' => translate(
'user_switching_access_denied')), TRUE);
1950 unset($_SESSION[
'user_login_attempts']);
1952 $user_status = $secondary_user->status;
1956 if ($secondary_user->canLogin()) {
1958 if ($resuming_session) {
1960 if (isset($invoking_user_nav_history)) {
1961 $_SESSION[
'sq_nav_history'] = $invoking_user_nav_history;
1963 return $this->
loginUser($secondary_user);
1972 $old_user_system_admin = (($old_user instanceof
System_User) && !($old_user instanceof
Root_User));
1973 $secondary_user_system_admin = (($secondary_user instanceof
System_User) && !($secondary_user instanceof Root_User));
1975 $allowed_login = !(($secondary_user instanceof Root_User) || ($old_user_system_admin && $secondary_user_system_admin));
1977 if ($allowed_login) {
1978 $_SESSION[
'login_as_invoker_username'] = $invoking_username;
1979 $_SESSION[
'login_as_invoker_user_full_name'] = $invoking_user_full_name;
1980 $_SESSION[
'login_as_invoker_id'] = $invoking_user_id;
1981 if (isset($invoking_user_nav_history)) {
1982 $_SESSION[
'login_as_invoker_sq_nav_history'] = $invoking_user_nav_history;
1986 return $this->
loginUser($secondary_user, $old_user->name);
1988 $failure_reason = translate(
'user_switching_access_denied');
1989 $user_status = NULL;
1999 if (!is_null($user_status)) {
2000 if ($user_status & SQ_SC_STATUS_NOT_LIVE) {
2001 $failure_reason = translate(
'user_status_not_live');
2003 $failure_reason = translate(
'user_asset_in_trash');
2007 $this->
addMessage(translate(
'user_not_found'));
2010 $this->
_logSecurityMsg(
'system.security.login.secondary.failed', Array(
'login_name' => $old_user->attr(
'username'),
'secondary_login_name' => $username,
'failure_reason' => $failure_reason), TRUE);
2026 if (array_get_index($_REQUEST,
'SQ_ACTION'))
return;
2027 $http_username = array_get_index($_SERVER, SQ_CONF_HTTP_LOGIN_VAR);
2028 if (is_null($http_username) || ($http_username ===
'')) {
2033 $auth_folder = $this->am->getSystemAsset(
'authentication_folder');
2034 if (is_null($auth_folder)) {
2035 trigger_localised_error(
'SYS0249', E_USER_ERROR);
2038 $auth_systems = $auth_folder->getAuthSystems();
2042 foreach ($auth_systems as $systemid) {
2043 $system = $this->am->getAsset($systemid);
2044 if (is_null($system))
continue;
2045 $user = $system->authenticateHttpUser($http_username);
2046 if (!is_null($user))
return $this->
loginUser($user);
2060 if (array_get_index($_REQUEST,
'SQ_ACTION'))
return;
2062 if (!(array_get_index($_SERVER,
'PHP_AUTH_USER') && array_get_index($_SERVER,
'PHP_AUTH_PW'))) {
2066 $auth_folder = $this->am->getSystemAsset(
'authentication_folder');
2067 if (is_null($auth_folder)) {
2068 trigger_localised_error(
'SYS0249', E_USER_ERROR);
2071 $auth_systems = $auth_folder->getAuthSystems();
2074 foreach ($auth_systems as $systemid) {
2075 $system = $this->am->getAsset($systemid);
2076 if (is_null($system))
continue;
2077 $user = $system->authenticateUser($_SERVER[
'PHP_AUTH_USER'], $_SERVER[
'PHP_AUTH_PW']);
2078 if (!is_null($user))
return $this->
loginUser($user);
2082 unset($_SERVER[
'PHP_AUTH_USER']);
2083 unset($_SERVER[
'PHP_AUTH_PW']);
2103 if (is_null($user))
return FALSE;
2107 $old_session_id = session_id();
2110 session_regenerate_id();
2112 $sess_filename = session_save_path().
'/sess_'.$old_session_id;
2113 @unlink($sess_filename);
2116 $_SESSION[
'userid'] = $user->id;
2117 $_SESSION[
'user_type_code'] = $user->
type();
2118 $_SESSION[
'user'] = serialize($user);
2119 $_SESSION[
'user_serialised_ts'] =
time();
2120 if (!$this->_user_is_public) {
2121 $_SESSION[
'remote_addr'] = $_SERVER[
'REMOTE_ADDR'];
2125 if (empty($invoking_user_full_name)) {
2128 $this->
_logSecurityMsg(
'system.security.login.secondary', Array(
'secondary_user_name' => $invoking_user_full_name));
2134 $login_contextid = $this->
getUserPrefs(
'user',
'SQ_USER_SET_CONTEXT_ON_LOGIN', TRUE);
2136 if (is_numeric($login_contextid) === TRUE) {
2137 $_SESSION[SQ_SESSION_SANDBOX_INDEX][
'SQ_ALTERNATE_CONTEXT_ID'] = $login_contextid;
2145 $_SESSION[
'user_is_root'] = $this->_user_is_root;
2146 $_SESSION[
'user_is_sys_admin'] = $this->_user_is_sys_admin;
2147 $_SESSION[
'user_is_public'] = $this->_user_is_public;
2148 $_SESSION[
'user_last_access'] =
time();
2149 $_SESSION[
'user_last_authentication'] =
time();
2152 $event_data = Array(
'password' => array_get_index($_POST,
'SQ_LOGIN_PASSWORD'));
2156 $decoded_wkey = base64_decode(SQ_LICENCE_WARRANTY_KEY);
2157 if (SQ_IN_BACKEND && defined(
'SQ_LICENCE_WARRANTY_KEY') && ($decoded_wkey !==
'') && (substr_replace($decoded_wkey,
'', 6, 8) !==
'abcdef00000000')) {
2158 $wkey_snippet = substr($decoded_wkey, 0, 6);
2159 $ikey_snippet = substr(SQ_LICENCE_INSTALL_KEY, 0, 6);
2161 $expiry_date = substr($decoded_wkey, 14);
2162 $current_date =
date(
'Ymd');
2164 $warranty_expired = ($current_date > $expiry_date) || ($wkey_snippet !== $ikey_snippet);
2167 $warranty_expired = FALSE;
2171 $return_url = current_protocol().
'://'.current_url(FALSE);
2174 if (!$_SESSION[
'user_is_public'] && array_get_index($_SESSION,
'SQ_RETURN_TO_HTTP')) {
2175 unset($_SESSION[
'SQ_RETURN_TO_HTTP']);
2176 $return_url =
'http://'.current_url(FALSE);
2178 $return_url = replace_query_string_vars(Array(
'SQ_ACTION' => NULL), $return_url);
2179 require_once dirname(__FILE__).
'/key_reminder.inc';
2183 if (!$_SESSION[
'user_is_public'] && array_get_index($_SESSION,
'SQ_RETURN_TO_HTTP')) {
2184 unset($_SESSION[
'SQ_RETURN_TO_HTTP']);
2187 do_redirect(
'http://'.current_url(FALSE, SQ_IN_LOGIN));
2191 $current_url = current_url(TRUE, TRUE);
2192 do_redirect($current_url);
2213 if (!($user instanceof
User)) {
2214 trigger_localised_error(
'SYS0171', E_USER_WARNING);
2221 if (!is_null($this->user)) {
2222 if (!isset($this->_tmp[
'current_user_cache'])) {
2223 $this->_tmp[
'current_user_cache'] = Array();
2225 array_push($this->_tmp[
'current_user_cache'], Array($this->user->id, $this->user->type()));
2228 $this->user = &$user;
2229 $this->_user_is_root = $this->
userRoot($user);
2231 $this->_user_is_public = $this->
userPublic($user);
2248 if (empty($this->_tmp[
'current_user_cache'])) {
2251 list($userid, $type_code) = array_pop($this->_tmp[
'current_user_cache']);
2252 $user = $this->am->getAsset($userid, $type_code);
2256 if (is_null($user) || !$user->canSetAsCurrentUser()) {
2258 $this->_user_is_root = FALSE;
2259 $this->_user_is_sys_admin = FALSE;
2260 $this->_user_is_public = TRUE;
2263 $this->user = &$user;
2264 $this->_user_is_root = $this->
userRoot($user);
2266 $this->_user_is_public = $this->
userPublic($user);
2285 $key = $_SESSION[
'userid'].
2286 $_SESSION[
'user_type_code'];
2288 if (isset($_SESSION[
'SQ_LOGIN_KEY'])) {
2289 $key .= $_SESSION[
'SQ_LOGIN_KEY'];
2292 if (!SQ_CONF_ALLOW_IP_CHANGE) {
2293 $key .= $_SESSION[
'remote_addr'];
2312 $key = $_SESSION[
'userid'].
2313 $_SESSION[
'user_type_code'];
2315 if (isset($_SESSION[
'SQ_LOGIN_KEY'])) {
2316 $key .= $_SESSION[
'SQ_LOGIN_KEY'];
2336 require_once SQ_FUDGE_PATH.
'/general/general.inc';
2338 if ($force_new_key || empty($_SESSION[
'SQ_LOGIN_KEY'])) {
2339 $_SESSION[
'SQ_LOGIN_KEY'] = random_password(20);
2342 return $_SESSION[
'SQ_LOGIN_KEY'];
2355 return (isset($_SESSION[
'SQ_LOGIN_KEY'])) ? $_SESSION[
'SQ_LOGIN_KEY'] :
'';
2360 public function getSessionHandlerClassName()
2362 if (SQ_CONF_SESSION_HANDLER ===
'') {
2363 $session_handler =
'Session_Handler_Default';
2365 $session_handler =
'Session_Handler_'.ucwords(SQ_CONF_SESSION_HANDLER);
2369 $this->am->includeAsset(strtolower($session_handler));
2370 }
catch (Exception $e) {
2374 trigger_error(
'Cannot start MySource user session; session handler \''.SQ_CONF_SESSION_HANDLER.
'\' does not exist
', E_USER_ERROR);
2377 return $session_handler;
2379 }//end getSessionHandlerClassName()
2390 protected function _updateSessionCookie()
2392 $session_id = session_id();
2393 if (empty($session_id)) return FALSE;
2395 $session_prefs = $this->getUserPrefs('user
', 'SQ_USER_SESSION_PREFS
', TRUE);
2396 $user_prefs = $this->_findValidSessionExpiry($session_prefs);
2398 $time_to_live = $user_prefs['persist
']; // 1 or 0
2399 if (!empty($time_to_live)) {
2400 $time_to_live = !empty($user_prefs['timeout
']) ? ($user_prefs['timeout
'] + 3600) : 0; // cookie should last 1 extra hour
2401 if (empty($time_to_live)) {
2402 // there is no max inactive time but we do want to persist across browser sessions...
2403 $time_to_live = 60 * 60 * 24 * 365; // give them a a year
2406 $session_params = session_get_cookie_params();
2407 $session_name = session_name();
2408 $header = "Set-Cookie: $session_name=$session_id; ";
2409 if (!empty($time_to_live)) {
2410 $header .= 'expires=
'.substr(date('r
', time()+$time_to_live-((int)substr(date('O
'), 0, 3)*60*60)), 0, -6).' GMT;
';
2412 if (!empty($session_params['domain
'])) {
2413 $domain = $session_params['domain
'];
2414 if (defined('SQ_CONF_SYSTEM_PARENT_DOMAINS
')) {
2415 $parent_domains = explode("\n", SQ_CONF_SYSTEM_PARENT_DOMAINS);
2416 if (is_array($parent_domains)) {
2417 foreach ($parent_domains as $parent_domain) {
2418 $parent_length = strlen($parent_domain);
2419 if ((strlen($domain) >= $parent_length) && (substr($domain, -$parent_length) == $parent_domain)) {
2420 // our current domain is a subdomain of this parent domain, so we will
2421 // actually set the cookie for the parent domain and its children
2422 $domain = '.
'.$parent_domain;
2423 $session_params['path
'] = '/
';
2429 $header .= "domain=$domain; ";
2431 if (!empty($session_params['path
'])) {
2432 $header .= "path=$session_params[path]; ";
2435 if (isset($session_params['httponly
']) && $session_params['httponly
']) {
2436 $header .= "HttpOnly; ";
2439 if (isset($session_params['secure
']) && $session_params['secure
']) {
2440 $header .= "secure; ";
2445 }//end _updateSessionCookie()
2456 public function _findValidSessionExpiry($session_prefs)
2461 'max_length
' => '0
',
2463 $current_ip = (isset($_SERVER['REMOTE_ADDR
'])) ? $_SERVER['REMOTE_ADDR
'] : '';
2464 $patt = '/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/
';
2465 if (is_array($session_prefs)) {
2466 foreach ($session_prefs as $id => $sess_pref) {
2470 'max_length
' => '0
',
2472 // Check that the current IP falls between the 'to
' and 'from
' field (also check an IP was passed)
2473 if (isset($sess_pref['ip_from
']) && !empty($sess_pref['ip_from
']) && preg_match($patt, $sess_pref['ip_from
'])) {
2474 $current_ip_value = ip2long($current_ip);
2475 $ip_from_value = ip2long($sess_pref['ip_from
']);
2476 if (($current_ip_value > -1) && ($current_ip_value != FALSE) && ($ip_from_value > -1) && ($ip_from_value != FALSE)) {
2477 if (!empty($current_ip) && ($current_ip == $sess_pref['ip_from
'])) {
2479 $prefs['persist
'] = $sess_pref['persist
'];
2480 $prefs['timeout
'] = $sess_pref['timeout
'];
2481 $prefs['max_length
'] = $sess_pref['max_length
'];
2483 } else if (!empty($current_ip) && ($current_ip_value > $ip_from_value)) {
2484 if (isset($sess_pref['ip_to
']) && !empty($sess_pref['ip_to
']) && preg_match($patt, $sess_pref['ip_to
'])) {
2485 if ((ip2long($sess_pref['ip_to
']) > -1) && (ip2long($sess_pref['ip_to
']) != FALSE)) {
2486 if ($current_ip_value < ip2long($sess_pref['ip_to
'])) {
2488 $prefs['persist
'] = $sess_pref['persist
'];
2489 $prefs['timeout
'] = $sess_pref['timeout
'];
2490 $prefs['max_length
'] = $sess_pref['max_length
'];
2508 // No IP Restriction found, so continue
2509 $temp['persist
'] = $sess_pref['persist
'];
2510 $temp['timeout
'] = $sess_pref['timeout
'];
2511 $temp['max_length
'] = $sess_pref['max_length
'];
2513 // Look for the largest general result
2514 foreach ($temp as $key => $value) {
2515 if ($value > $prefs[$key]) $prefs[$key] = $value;
2520 // Return the results
2523 }//end _findValidSessionExpiry()
2532 protected function _clearSession()
2534 foreach (array_keys($_SESSION) as $key) {
2535 if ($key == 'SQ_RETURN_TO_HTTP
') continue;
2536 // do not reset the unsuccessful attempt, unset in &authenticateUser
2537 if ($key != 'user_login_attempts
') {
2538 unset($_SESSION[$key]);
2542 }//end _clearSession()
2555 protected function _logSecurityMsg($code, $extra_replacements=Array(), $failed_login=FALSE)
2557 if ($this->userPublic($this->user) && !$failed_login) {
2560 $ms = $this->getMessagingService();
2561 $msg_reps = Array('user_name
' => $this->user->name) + $extra_replacements;
2562 $log = $ms->newMessage(Array(), $code, $msg_reps);
2563 $log->parameters['remote_addr
'] = $_SERVER['REMOTE_ADDR
'];
2564 $log->parameters['sessionid
'] = session_id();
2567 }//end _logSecurityMsg()
2570 //-- INFO ABOUT CURRENT USER --//
2581 public function currentUser($user)
2583 return ($this->user && $this->user->id == $user->id);
2585 }//end currentUser()
2594 public function currentUserId()
2597 return $this->user->id;
2598 } else if (isset($_SESSION['userid
'])) {
2599 return $_SESSION['userid
'];
2604 }//end currentUserId()
2613 public function &getPublicUser()
2615 $public_user = $this->am->getSystemAsset('public_user
');
2616 return $public_user;
2618 }//end getPublicUser()
2629 public function userRoot($user=NULL)
2631 if (is_null($user)) return $this->_user_is_root;
2632 if (!$user->id) return FALSE;
2633 if (get_class($user) == 'Root_User
') return TRUE;
2651 public function userSystemAdmin($user=NULL)
2653 if (is_null($user)) return $this->_user_is_sys_admin;
2654 if (!$user->id) return FALSE;
2655 if (!$user->canAccessBackend()) return FALSE;
2657 // now make sure that the user is in the system administrators group
2658 $sys_admin_group = $this->am->getSystemAsset('system_user_group
');
2659 $sys_admins = $this->am->getLinks($sys_admin_group->id, SQ_LINK_TYPE_1);
2660 foreach ($sys_admins as $data) {
2661 if ($data['minorid
'] == $user->id) return TRUE;
2665 }//end userSystemAdmin()
2676 public function userPublic($user=NULL)
2678 if (is_null($user)) return $this->_user_is_public;
2679 if (!$user->id) return FALSE;
2680 if (get_class($user) == 'Public_User') return TRUE;
2696 public function getUserPrefs($asset_type=NULL, $pref=NULL, $value_only=TRUE)
2698 if (!is_file(SQ_DATA_PATH.'/
private/conf/preferences.inc
')) {
2702 static $user_prefs = Array(); // per-script-execution cache
2703 if (empty($this->user->id)) {
2704 include SQ_DATA_PATH.'/
private/conf/preferences.inc
';
2705 if (is_null($pref)) {
2706 return $preferences;
2708 if (!isset($preferences[$asset_type]) || !isset($preferences[$asset_type][$pref])) {
2709 return $preferences;
2711 $pref_value = $preferences[$asset_type][$pref];
2713 return $pref_value['default'];
2720 if (!isset($user_prefs[$this->user->id])) {
2721 $groups = $this->user->getGroups();
2722 include SQ_DATA_PATH.'/
private/conf/preferences.inc
';
2723 $global_prefs = $preferences;
2724 $final_prefs = Array();
2725 foreach ($groups as $groupid => $group_type_code) {
2726 $file_path = SQ_DATA_PATH.'/
private/
'.asset_data_path_suffix($group_type_code, $groupid).'/.preferences.inc
';
2727 if (!is_file($file_path)) continue;
2729 foreach ($preferences as $type => $type_prefs) {
2730 if (!isset($final_prefs[$type])) {
2731 $final_prefs[$type] = $type_prefs;
2733 $conflicting_prefs = array_intersect(array_keys($type_prefs), array_keys($final_prefs[$type]));
2734 if (empty($conflicting_prefs)) {
2735 $final_prefs[$type] += $type_prefs;
2737 // a particular preference within this type has been defined twice, so we need the prefs
2738 // class to decide which value applies
2739 require_once SQ_SYSTEM_ROOT.'/
'.$GLOBALS['SQ_SYSTEM
']->am->getTypeInfo($type, 'dir
').'/
'.$type.'_prefs.inc
'; // can this be more efficient?
2740 eval('$final_prefs[$type] =
'.$type.'_Prefs::mergePrefs($type_prefs, $final_prefs[$type]);
');
2744 foreach ($final_prefs[$type] as $pref_name => $pref_details) {
2745 if (is_array($pref_details) && isset($pref_details['default'])) {
2746 $final_prefs[$type][$pref_name] = $pref_details['default'];
2748 $final_prefs[$type][$pref_name] = $pref_details;
2755 // now final_prefs contains all the group prefs; pad it out with remaining global prefs
2756 foreach ($global_prefs as $type => $type_prefs) {
2757 foreach ($type_prefs as $pref_name => $pref_details) {
2758 if (!isset($final_prefs[$type][$pref_name])) {
2759 $final_prefs[$type][$pref_name] = $value_only ? $pref_details['default'] : $pref_details;
2764 $user_prefs[$this->user->id] = $final_prefs;
2766 if (is_null($asset_type)) {
2767 return $user_prefs[$this->user->id];
2769 if (is_null($pref) && isset($user_prefs[$this->user->id][$asset_type])) {
2770 return $user_prefs[$this->user->id][$asset_type];
2771 } else if (isset($user_prefs[$this->user->id][$asset_type][$pref])) {
2772 return $user_prefs[$this->user->id][$asset_type][$pref];
2778 }//end getUserPrefs()
2781 //-- CONTEXT SET/GET --//
2790 public function getContextId()
2792 $current_contextid = NULL;
2793 $stack_height = count($this->_context_stack);
2794 if ($stack_height > 0) {
2795 $current_contextid = $this->_context_stack[$stack_height - 1];
2797 if (is_null($current_contextid) === FALSE) {
2798 $current_contextid = (int)$current_contextid;
2800 return $current_contextid;
2802 }//end getContextId()
2812 public function changeContext($contextid)
2814 array_push($this->_context_stack, $contextid);
2816 }//end changeContextId()
2824 public function restoreContext()
2826 if (count($this->_context_stack) <= 0) {
2827 // Cannot restore the context as the context stack is empty
2828 trigger_localised_error('SYS0332
', E_USER_ERROR);
2830 array_pop($this->_context_stack);
2833 }//end restoreContext()
2853 public function getAllContexts($force_reload=FALSE)
2855 if (((boolean)$force_reload === TRUE) || (is_array($this->_tmp) === FALSE) || (array_key_exists('context_cache
', $this->_tmp) === FALSE)) {
2856 $context_data = MatrixDAL::executeGroupedAssoc('core
', 'getContexts
', Array('contextids
' => NULL));
2857 foreach ($context_data as $contextid => &$context_item) {
2858 $context_item = $context_item[0];
2859 if (empty($context_item["conditions"]) === FALSE) {
2860 $context_item['conditions
'] = unserialize($context_item['conditions
']);
2863 unset($context_item);
2864 $this->_tmp['context_cache
'] = $context_data;
2867 return $this->_tmp['context_cache
'];
2869 }//end getContextInfo()
2881 public function insertContextData($contextid)
2884 $GLOBALS['SQ_SYSTEM
']->changeDatabaseConnection('db2
');
2885 $GLOBALS['SQ_SYSTEM
']->doTransaction('BEGIN
');
2886 MatrixDAL::executeQuery('core
', 'copyContextAttributeData
', Array('contextid
' => $contextid));
2887 MatrixDAL::executeQuery('core
', 'copyContextUniqueAttributeData
', Array('contextid
' => $contextid));
2888 MatrixDAL::executeQuery('core
', 'copyContextMetadataDefaults
', Array('contextid
' => $contextid));
2889 $GLOBALS['SQ_SYSTEM
']->doTransaction('COMMIT
');
2890 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
2891 } catch (DALException $e) {
2892 $GLOBALS['SQ_SYSTEM
']->doTransaction('ROLLBACK
');
2893 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
2894 throw new Exception('Cannot insert
default attribute data
for context #
'.$contextid.'; DB returned error
"'.$e->getMessage().'"');
2897 // Broadcast a 'context created
' event so that assets can do something
2898 // with it if they want (such as create a new content file to go with it)
2899 // The broadcaster makes no difference since this will be called from a
2900 // config screen - so the currently logged in user will suffice
2901 $em = $this->getEventManager();
2902 $em->broadcastEvent($this->user, 'contextCreate
', Array('contextid
' => $contextid));
2906 }//end insertContextData()
2918 public function deleteContextData($contextid)
2921 $GLOBALS['SQ_SYSTEM
']->changeDatabaseConnection('db2
');
2922 $GLOBALS['SQ_SYSTEM
']->doTransaction('BEGIN
');
2923 MatrixDAL::executeQuery('core
', 'deleteContextAttributeData
', Array('contextids
' => Array($contextid)));
2924 MatrixDAL::executeQuery('core
', 'deleteContextUniqueAttributeData
', Array('contextids
' => Array($contextid)));
2925 MatrixDAL::executeQuery('core
', 'deleteContextMetadataDefaults
', Array('contextids
' => Array($contextid)));
2926 MatrixDAL::executeQuery('core
', 'deleteContextMetadataValue
', Array('contextids
' => Array($contextid)));
2927 $GLOBALS['SQ_SYSTEM
']->doTransaction('COMMIT
');
2928 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
2929 } catch (DALException $e) {
2930 $GLOBALS['SQ_SYSTEM
']->doTransaction('ROLLBACK
');
2931 $GLOBALS['SQ_SYSTEM
']->restoreDatabaseConnection();
2932 throw new Exception('Cannot
delete attribute data
for context #
'.$contextid.'; DB returned error
"'.$e->getMessage().'"');
2935 // Broadcast a 'context deleted
' event so that assets can do something
2936 // with it if they want (such as cleaning up content files)
2937 // The broadcaster makes no difference since this will be called from a
2938 // config screen - so the currently logged in user will suffice
2939 $em = $this->getEventManager();
2940 $em->broadcastEvent($this->user, 'contextDelete
', Array('contextid
' => $contextid));
2943 }//end deleteContextData()
2956 public function getAlternateContext()
2958 // Check first to see whether we have an overriding context name set,
2959 // that hasn't already been swallowed by either set_context or
2961 $override_context_name = array_get_index($_GET,
'SQ_CONTEXT_NAME', NULL);
2962 if ($override_context_name !== NULL) {
2963 $context_name = (isset($_GET[
'SQ_CONTEXT_NAME'])) ? $_GET[
'SQ_CONTEXT_NAME'] :
'';
2964 unset($_GET[
'SQ_CONTEXT_NAME']);
2965 $context_data =
MatrixDAL::executeAll(
'core',
'getContextByName', Array(
'name' => Array($context_name)));
2966 if (empty($context_data) === FALSE) {
2967 $contextid = $context_data[0][
'contextid'];
2974 unset($contexts[0]);
2977 if (empty($contexts)) {
2982 uasort($contexts, create_function(
'$a,$b',
'return $a["sort_order"] - $b["sort_order"];'));
2987 $root_url_info = $GLOBALS[
'SQ_SYSTEM']->am->getRootURL();
2988 if (array_key_exists($root_url_info[
'base_contextid'], $contexts) === TRUE) {
2989 $use_contextid = $root_url_info[
'base_contextid'];
2994 foreach ($contexts as $contextid => $context) {
2997 if ($context[
'at_least'] === NULL) {
2998 $context[
'at_least'] = max(1, count($context[
'conditions']));
3000 $maximum_failures = count($context[
'conditions']) - $context[
'at_least'];
3002 if ($maximum_failures < 0) {
3006 $total_failures = 0;
3008 foreach ($context[
'conditions'] as $condition) {
3009 $condition_type = $condition[
'type'];
3010 $condition_options = $condition[
'options'];
3014 switch ($condition_type) {
3015 case 'accept-language':
3016 $language = $condition_options[
'language'];
3017 $language = str_replace(
'_',
'-', strtolower($language));
3018 $min_q = $condition_options[
'min_q'];
3019 $header = array_get_index($_SERVER,
'HTTP_ACCEPT_LANGUAGE');
3021 if ($header !== NULL) {
3022 $header_items = explode(
',', $header);
3023 foreach ($header_items as $header_item) {
3024 $item_bits = explode(
';', trim($header_item));
3025 if (count($item_bits) === 1) {
3026 $item_bits[1] =
'q=1.0';
3028 list($header_language, $header_q_value) = $item_bits;
3029 $header_language = trim($header_language);
3030 $header_q_value = (float)str_replace(
'q=',
'', trim($header_q_value));
3034 if (strpos($header_language, $language) === 0) {
3035 if ($header_q_value >= $min_q) {
3046 if ($condition_type ==
'get') {
3047 $var_value = array_get_index($_GET, $condition_options[
'var_name']);
3049 $var_value = array_get_index($_POST, $condition_options[
'var_name']);
3053 $match_type = $condition_options[
'match_type'];
3054 $match_value = $condition_options[
'match_value'];
3055 $case_sensitive = array_get_index($condition_options,
'case_sensitive', 1);
3057 if ($match_type ===
'exists') {
3058 $matched = ($var_value === NULL) ? FALSE : TRUE;
3060 if ($var_value !== NULL) {
3061 if ($case_sensitive === 0) {
3062 $var_value = strtolower($var_value);
3063 $match_value = strtolower($match_value);
3066 switch ($match_type) {
3068 if ($var_value === $match_value) {
3074 if (strpos($var_value, $match_value) === 0) {
3080 if (strpos($var_value, $match_value) === strlen($var_value) - strlen($match_value)) {
3086 if (strpos($var_value, $match_value) !== FALSE) {
3096 if ($condition_options[
'match_logic'] === 0) {
3105 $server_index =
'HTTP_'.str_replace(
'-',
'_', strtoupper($condition_options[
'header_name']));
3106 $header_value = array_get_index($_SERVER, $server_index);
3109 $match_type = $condition_options[
'match_type'];
3110 $match_value = $condition_options[
'match_value'];
3111 $case_sensitive = array_get_index($condition_options,
'case_sensitive', 1);
3113 if ($match_type ===
'exists') {
3114 $matched = ($header_value === NULL) ? FALSE : TRUE;
3116 if ($header_value !== NULL) {
3117 if ($case_sensitive === 0) {
3118 $header_value = strtolower($header_value);
3119 $match_value = strtolower($match_value);
3122 switch ($match_type) {
3124 if ($header_value === $match_value) {
3130 if (strpos($header_value, $match_value) === 0) {
3136 if (strpos($header_value, $match_value) === strlen($header_value) - strlen($match_value)) {
3142 if (strpos($header_value, $match_value) !== FALSE) {
3152 if ($condition_options[
'match_logic'] === 0) {
3161 $current_url = current_url(FALSE, TRUE);
3164 $match_type = $condition_options[
'match_type'];
3165 $match_value = $condition_options[
'match_value'];
3167 switch ($match_type) {
3169 if ($current_url === $match_value) {
3175 if (strpos($current_url, $match_value) === 0) {
3181 if (strpos($current_url, $match_value) === strlen($current_url) - strlen($match_value)) {
3187 if (strpos($current_url, $match_value) !== FALSE) {
3193 if ($condition_options[
'match_logic'] === 0) {
3203 $current_port = (int)array_get_index($_SERVER,
'SERVER_PORT', 80);
3204 $match_type = $condition_options[
'match_type'];
3205 $match_value = (int)$condition_options[
'match_value'];
3207 if ($match_type ===
'is') {
3209 $pass = ($current_port === $match_value) ? TRUE : FALSE;
3212 $pass = ($current_port !== $match_value) ? TRUE : FALSE;
3218 $current_protocol = current_protocol();
3219 $match_value = (int)$condition_options[
'match_value'];
3221 if ($match_value === 1) {
3223 $pass = ($current_protocol ===
'https') ? TRUE : FALSE;
3226 $pass = ($current_protocol ===
'http') ? TRUE : FALSE;
3233 if ($pass === FALSE) {
3238 if ($total_failures > $maximum_failures) {
3247 if ($total_failures <= $maximum_failures) {
3248 $use_contextid = $contextid;
3254 return $use_contextid;
3272 if (!isset($this->ms) || (get_class($this->ms) !=
'Messaging_Service')) {
3273 require_once SQ_INCLUDE_PATH.
'/messaging_service.inc';
3291 if (!isset($this->fv) || (get_class($this->fv) !=
'File_Versioning')) {
3292 require_once SQ_LIB_PATH.
'/file_versioning/file_versioning.inc';
3310 if (!isset($this->hh) || (get_class($this->hh) !=
'HIPO_Herder')) {
3311 require_once SQ_SYSTEM_ROOT.
'/core/hipo/hipo_herder.inc';
3329 if (!isset($this->mm) || (get_class($this->mm) !=
'Metadata_Manager')) {
3330 require_once SQ_INCLUDE_PATH.
'/metadata_manager.inc';
3348 if (!isset($this->wm) || (get_class($this->wm) !=
'Workflow_Manager')) {
3349 require_once SQ_INCLUDE_PATH.
'/workflow_manager.inc';
3367 if (!isset($this->em) || (get_class($this->em) !=
'Event_Manager')) {
3368 require_once SQ_INCLUDE_PATH.
'/event_manager.inc';
3387 if ((!isset($this->tag_manager) || (get_class($this->tag_manager) !=
'Tag_Manager')) && $am->isSystemAssetType(
'tag_manager')) {
3388 $this->tag_manager = $am->getSystemAsset(
'tag_manager');
3390 return $this->tag_manager;
3406 if ((!isset($this->trigger_manager) || ($am->installed(
'trigger_manager') && !($this->trigger_manager instanceof
Trigger_Manager))) && $am->isSystemAssetType(
'trigger_manager')) {
3407 $this->trigger_manager = $am->getSystemAsset(
'trigger_manager');
3410 return $this->trigger_manager;
3424 if ((!isset($this->log_manager) || (get_class($this->log_manager) !=
'Log_Manager')) && $am->isSystemAssetType(
'log_manager')) {
3425 $this->log_manager = $am->getSystemAsset(
'log_manager');
3431 if (is_null($this->log_manager)) {
3435 return $this->log_manager;
3450 if (!isset($this->_deja_vu) || (get_class($this->_deja_vu) !=
'Deja_Vu')) {
3451 require_once SQ_INCLUDE_PATH.
'/deja_vu.inc';
3452 $this->_deja_vu =
new Deja_Vu();
3455 if ($this->_deja_vu->enabled()) {
3456 return $this->_deja_vu;
3479 $this->_run_level_stack[] = $run_level;
3492 if (empty($this->_run_level_stack)) {
3494 trigger_localised_error(
'SYS0110', E_USER_ERROR);
3497 array_pop($this->_run_level_stack);
3512 if (empty($this->_run_level_stack))
return NULL;
3514 end($this->_run_level_stack);
3515 $current_run_level = current($this->_run_level_stack);
3516 reset($this->_run_level_stack);
3518 return $current_run_level;
3535 if (is_null($current_run_level)) {
3537 trigger_localised_error(
'SYS0102', E_USER_ERROR);
3540 return ($security_system & $current_run_level);
3560 $db_conf = require(SQ_DATA_PATH.
'/private/conf/db.inc');
3563 if ($conn ===
'dbcache') {
3564 if (empty($db_conf[$conn]) && empty($db_conf[
'db2'])) {
3565 throw new Exception (
'Unable to connect to connection "'.$conn.
'". No connection with that name is defined in the database config, and unable to fall back to "db2" connection.');
3566 }
else if (empty($db_conf[$conn])) {
3568 $dsn_array = $db_conf[
'db2'];
3571 $dsn_array = $db_conf[$conn];
3573 }
else if ($conn ===
'dbsearch') {
3574 if (empty($db_conf[$conn]) && empty($db_conf[
'db'])) {
3575 throw new Exception (
'Unable to connect to connection "'.$conn.
'". No connection with that name is defined in the database config, and unable to fall back to "db" connection.');
3576 }
else if (empty($db_conf[$conn])) {
3578 $dsn_array = $db_conf[
'db'];
3581 $dsn_array = $db_conf[$conn];
3585 if (empty($db_conf[$conn])) {
3586 throw new Exception (
'Unable to connect to connection "'.$conn.
'". No connection with that name is defined in the database config.');
3590 if ($conn ===
'db' && (SQ_IN_BACKEND || SQ_IN_LIMBO || SQ_PHP_CLI)) {
3591 $dsn_array = $db_conf[
'db2'];
3593 $dsn_array = $db_conf[$conn];
3598 if (empty($this->_db_conns[$conn])) {
3604 if ($dsn_array[
'type'] ===
'oci') {
3612 if ($dsn_array[
'type'] ===
'oci') {
3613 $db->setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE);
3617 $db->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
3620 $db->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
3623 $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, TRUE);
3626 }
catch (Exception $e) {
3627 header(
'HTTP/1.0 500 Internal Server Error');
3628 throw new Exception(
'Could not create database connection: '.$e->getMessage());
3648 if ($force_reconnect) {
3651 array_pop($this->_db_conns);
3670 if (!isset($this->tm) || get_class($this->tm) !=
'Transaction_Manager') {
3671 require_once SQ_INCLUDE_PATH.
'/transaction_manager.inc';
3687 switch (strtolower($type)) {
3689 return $this->tm->begin($current_db);
3691 return $this->tm->commit($current_db);
3693 return $this->tm->rollback($current_db);
3711 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
3712 $then = strtotime($_SESSION[
'sq_rollback_view'][
'rollback_time']);
3713 $time_string = readable_datetime($then).
' ('.easy_time_total(
time() - $then, TRUE).
' ago)';
3714 $warning_message = translate(
'rollback_mode_warning_message', $time_string);
3715 $exit_url = $_SERVER[
'PHP_SELF'].
'?SQ_ACTION=rollback_view_stop';
3718 <div align=
"center">
3720 .sq-rollback-warning {
3722 font-family: Verdana, Arial, Helvetica, sans-serif;
3724 text-decoration: none;
3729 <table border=
"0" cellspacing=
"3" cellpadding=
"2" width=
"95%" bgcolor=
"#FF0000">
3731 <td bgcolor=
"#FFE5E8">
3732 <table border=
"0" cellspacing=
"2" cellpadding=
"2" width=
"100%">
3734 <td
class=
"sq-rollback-warning" align=
"right"><?php echo translate(
'exit_rollback_view'); ?><?php sq_print_icon(sq_web_path(
'lib').
'/web/images/icons/delete.png',
'16',
'16', translate(
'exit_rollback_view'), NULL,
'onclick="window.top.location=\''.$exit_url.
'\';
return false;
" style="cursor: pointer;
"'); ?>
3738 <td class="sq-rollback-warning
" align="center
"><u><?php echo translate('in_rollback_mode'); ?></u>
3742 <td class="sq-rollback-warning
"><?php echo $warning_message; ?>
3753 }//end printRollbackWarning()
3774 function constructRollbackWhereClause($where='', $table_alias=NULL, $prefix='WHERE', $is_table_alias=TRUE)
3776 // trim off a current prefix keyword if it exists
3777 $where = trim($where);
3778 if (strtoupper(substr($where, 0, strlen($prefix))) == strtoupper($prefix)) {
3779 $where = substr($where, strlen($prefix));
3782 if (!SQ_ROLLBACK_VIEW) {
3783 // we are not in rollback view so we dont need anything special in the where clause
3784 if (empty($where)) {
3787 return ' '.$prefix.' '.$where;
3791 if (!is_null($table_alias)) {
3792 if ($is_table_alias) $table_alias .= '.';
3797 $then = $_SESSION['sq_rollback_view']['rollback_time'];
3799 if (!empty($where)) $where .= ' AND ';
3800 $where .= $table_alias.'sq_eff_from <= \''.$then.'\'
3801 AND ('.$table_alias.'sq_eff_to IS NULL
3802 OR '.$table_alias.'sq_eff_to > \''.$then.'\')';
3804 return ' '.$prefix.' '.$where;
3806 }//end constructRollbackWhereClause()
3826 function acquireLock($lockid, $source_lockid='', $expires=0)
3828 $class_name = 'locking_method_'.SQ_CONF_LOCKING_METHOD;
3829 $this->am->includeAsset($class_name);
3832 $ok = eval('return '.$class_name.'::acquireLock($lockid, $source_lockid, $expires);');
3833 } catch (Exception $e) {
3834 return $e->getMessage();
3839 }//end acquireLock()
3850 function releaseLock($lockid)
3852 $class_name = 'locking_method_'.SQ_CONF_LOCKING_METHOD;
3853 $this->am->includeAsset($class_name);
3856 $ok = eval('return '.$class_name.'::releaseLock($lockid);');
3857 } catch (Exception $e) {
3858 return $e->getMessage();
3863 }//end releaseLock()
3880 function updateLock($lockid, $expires=0)
3882 $class_name = 'locking_method_'.SQ_CONF_LOCKING_METHOD;
3883 $this->am->includeAsset($class_name);
3886 $ok = eval('return '.$class_name.'::updateLock($lockid, $expires);');
3887 } catch (Exception $e) {
3888 return $e->getMessage();
3907 function getLockInfo($lockid, $full_chain=FALSE, $check_expires=TRUE, $allow_only_one=TRUE)
3909 $class_name = 'locking_method_'.SQ_CONF_LOCKING_METHOD;
3910 $this->am->includeAsset($class_name);
3913 $lock_info = eval('return '.$class_name.'::getLockInfo($lockid, $full_chain, $check_expires, $allow_only_one);');
3914 } catch (Exception $e) {
3915 return $e->getMessage();
3920 }//end getLockInfo()
3923 //-- SYSTEM MESSAGES --//
3934 function addMessage($msg)
3936 $this->_msgs[] = $msg;
3949 return (empty($this->_msgs)) ? Array() : $this->_msgs;
3965 function datetime($timestamp=NULL)
3967 return (is_null($timestamp)) ? date('d/m/Y H:i:s') : date('d/m/Y H:i:s', $timestamp);
3980 function date($timestamp=NULL)
3982 return (is_null($timestamp)) ? date('d/m/Y') : date('d/m/Y', $timestamp);
3995 function time($timestamp=NULL)
3997 return (is_null($timestamp)) ? date('H:i:s') : date('H:i:s', $timestamp);
4015 function getInstalledPackages()
4018 $sql = 'SELECT code_name, version, name, description FROM sq_pkg';
4019 $packages = MatrixDAL::executeSqlAssoc($sql);
4020 } catch (DALException $e) {
4021 throw new Exception ('Could not get installed packages list due to database error: '.$e->getMessage());
4026 }//end getInstalledPackages()
4042 function broadcastTriggerEvent($event_name, &$broadcaster, $parameters=NULL)
4044 if (!$GLOBALS['SQ_SYSTEM']->runLevelEnables(SQ_SECURITY_TRIGGERS)) {
4047 $tm = $this->getTriggerManager();
4048 if (!is_null($tm)) {
4049 return $tm->broadcastEvent($event_name, $broadcaster, $parameters);
4054 }//end broadcastTriggerEvent()
4063 function _getHeaders()
4065 if (function_exists('apache_request_headers')) {
4066 // If the apache_request_headers function exists, we are
4067 // in an Apache module
4068 return apache_request_headers();
4069 } else if (isset($_ENV)) {
4070 // Otherwise, we are probably in CGI, where request headers are
4071 // dumped into $_ENV, so return that instead
4075 }//end _getHeaders()
4091 protected function _paintNotFoundAsset(Asset $asset, Site $site)
4093 header('HTTP/1.0 404 Not Found');
4095 // Send Cacheable Header based on Not Found page asset type
4096 if (SQ_CONF_SEND_CACHEABLE_HEADER && SQ_CONF_SEND_404_CACHEABLE_HEADER) {
4097 $cm = $GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cache_manager');
4098 header('Pragma: cache');
4100 $browser_cache_expiry = $cm->getBrowserCacheExpiry($asset->type(), $asset->id);
4101 if (empty($browser_cache_expiry)) {
4102 $browser_cache_expiry = $cm->getExpiry($asset->type(), $asset->id);
4105 header('Cache-Control: max-age='.$browser_cache_expiry.', '.$cm->cacheControlLevel());
4106 header('Expires: '.gmdate('D, d M Y H:i:s', time() + $browser_cache_expiry).' GMT');
4109 $old_current_asset = $GLOBALS['SQ_SYSTEM']->getGlobalDefine('CURRENT_ASSET', NULL);
4110 $GLOBALS['SQ_SYSTEM']->setGlobalDefine('CURRENT_ASSET', $asset);
4112 // If "Not found
" page has overriding design and/or paint layout
4113 $override_design = $site->getSpecialPage('not_found_design');
4114 $override_layout = $site->getSpecialPage('not_found_layout');
4116 $site->paintAsset($asset, $override_design, $override_layout);
4117 $content = ob_get_clean();
4119 $this->replaceKeyword($content);
4121 if (is_null($old_current_asset)) {
4122 $GLOBALS['SQ_SYSTEM']->unsetGlobalDefine('CURRENT_ASSET');
4124 $GLOBALS['SQ_SYSTEM']->setGlobalDefine('CURRENT_ASSET', $old_current_asset);
4129 }//end _paintNotFoundAsset()
4144 function authRedirect()
4146 $db = $GLOBALS['SQ_SYSTEM']->db;
4148 $current_url = current_url(FALSE, FALSE);
4149 $current_protocol = current_protocol();
4150 $root_url = $GLOBALS['SQ_SYSTEM']->am->getRootURL();
4153 'urlid' => $root_url['urlid'],
4155 $result = MatrixDAL::executeAll('core', 'getAuthRedirect', $bind_vars);
4157 if (empty($result)) return FALSE;
4158 $new_root_url = $result[0];
4161 // If the protocol is valid, then use the same protocol, otherwise
4162 // use the one that is available
4163 if ($new_root_url[$current_protocol]) {
4164 $protocol = $current_protocol;
4166 // If current protocol not valid, then only one must be selected...
4167 // and it's the wrong one
4168 $protocol = $new_root_url['https' ] ? 'https' : 'http';
4171 // build the new URL, and redirect - this exits the script
4172 $url = $protocol.'://'.preg_replace('|^'.addslashes($root_url['url']).'|', $new_root_url['url'], $current_url);
4174 // Before redirecting, blanking out the public user, see ya on the flip side!
4175 if ($this->userPublic($this->user)) {
4176 $_SESSION['user'] = NULL;
4177 $_SESSION['userid'] = NULL;
4178 $_SESSION['user_type_code'] = NULL;
4183 // Fall-through that should never be executed
4186 }//end authRedirect()
4197 public function _generateAttributeImage($text)
4200 putenv('GDFONTPATH=' . realpath(SQ_LIB_PATH.'/fonts'));
4201 $default_fonts = Array( 1,2,3,4,5 );
4204 // Load the user prefs
4205 $image_prefs = $this->getUserPrefs('user', 'SQ_USER_ATTRIBUTE_IMAGE', TRUE);
4206 $font = $image_prefs['face'];
4207 $size = $image_prefs['size'];
4208 $hpad = $image_prefs['hpad'];
4209 $vpad = $image_prefs['vpad'];
4210 $colour1 = ltrim($image_prefs['bgcol'], '#');
4211 $colour2 = ltrim($image_prefs['fgcol'], '#');
4213 // Calculate the sizes etc.
4214 $width = ((in_array($font, $default_fonts)) ? (imagefontwidth($font) * strlen($text)) : ($size * strlen($text))) + ($hpad * 2);
4215 $height = ((in_array($font, $default_fonts)) ? imagefontheight($font) : ($size + $size/2)) + ($vpad * 2);
4218 $y = (in_array($font, $default_fonts)) ? (0 + $vpad) : (round($height - ($size / 2), 0) - $vpad);
4221 if (!$image = imagecreatetruecolor($width, $height)) {
4222 trigger_error('Cannot Initialize new GD image stream', E_USER_WARNING);
4226 // Work out the colours
4227 list($r1,$g1,$b1) = str_split($colour1, 2);
4228 list($r2,$g2,$b2) = str_split($colour2, 2);
4229 $bg_colour = imagecolorallocate($image, hexdec($r1), hexdec($g1), hexdec($b1));
4230 $fg_colour = imagecolorallocate($image, hexdec($r2), hexdec($g2), hexdec($b2));
4232 // Colour the background
4233 imagefill($image, 0,0, $bg_colour);
4235 // Write the text on the image
4236 if (in_array($font, $default_fonts)) {
4237 $text_created = imagestring($image, $font, $x, $y, $text, $fg_colour);
4239 $text_created = @imagettftext($image, $size, 0, $x, $y, $fg_colour, $font, $text);
4242 // Getting image sizes correct the first time, is kind of tricky
4243 // So creating the image putting the text on it, then resizing the image, seems to work
4244 if ($text_created === FALSE) {
4245 // An error occured with drawing the text, try using the default font
4246 $width = (imagefontwidth * strlen($text)) + ($hpad * 2);
4247 $height = imagefontheight + ($vpad * 2);
4248 if (!$image = imagecreatetruecolor($width, $height)) {
4249 trigger_error('Cannot Initialize new GD image stream', E_USER_WARNING);
4252 imagefill($image, 0,0, $bg_colour);
4253 $text_created = imagestring($image, $backup_font, $x, $y, $text, $fg_colour);
4254 } else if (isset($text_created[2]) && !empty($text_created[2]) && $text_created[2] != $width) {
4255 $width = $text_created[2]+1;
4256 $height = $text_created[3];
4257 if (!$image = imagecreatetruecolor($width, $height)) {
4258 trigger_error('Cannot Initialize new GD image stream', E_USER_WARNING);
4261 $bg_colour = imagecolorallocate($image, hexdec($r1), hexdec($g1), hexdec($b1));
4262 $fg_colour = imagecolorallocate($image, hexdec($r2), hexdec($g2), hexdec($b2));
4263 imagefill($image, 0,0, $bg_colour);
4264 $text_created = @imagettftext($image, $size, 0, $x, $y, $fg_colour, $font, $text);
4266 header('Content-type: image/png');
4269 }//end _generateAttributeImage()
4280 function _translateMatrixURL(&$content)
4282 // Get all the matrix ./a=xx links in the content
4283 preg_match_all('!<[^>]*'.'(?:(?:href)|(?:src))\s*=\s*'.'(?:"|\
')'.
'\./\?a=([0-9]+(?:\:[0-9a-z]+\$?)?)'.
'[^:"\']*?'.
'(?:"|\')'.
'[^>]*>!msi', $content, $matches);
4284 if (empty($matches[1]))
return;
4286 foreach($matches[1] as $key => $assetid) {
4287 $matches[1][$key] = rtrim($assetid,
'$');
4289 $assets_url = $GLOBALS[
'SQ_SYSTEM']->am->getAssetURL($matches[1]);
4292 foreach($matches[1] as $index => $assetid) {
4293 if (isset($assets_url[$assetid]) && !empty($assets_url[$assetid])) {
4294 $replacement = preg_replace(
'!\./\?a=[0-9]+(?:\:[0-9a-z]+\$?)?!i', str_replace(
'$',
'\$', $assets_url[$assetid]), $matches[0][$index]);
4295 $content = str_replace($matches[0][$index], $replacement, $content);
4311 if(!defined(
'SQ_IN_PERFORMANCE_TIMING'))
return;
4314 preg_match_all(
'/<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU', $content, $matches);
4317 foreach($matches[0] as $index => $url) {
4318 $src = $matches[2][$index];
4319 if(empty($src))
continue;
4322 if(substr($src, -1) ==
'/') {
4323 $src = rtrim($src,
'/');
4326 if(strpos($src,
'?') !== FALSE) {
4327 $src = preg_replace(
'/\?/',
'/'.SQ_CONF_PERFORMANCE_SUFFIX.
'/?', $src);
4330 $src = $src.
'/'.SQ_CONF_PERFORMANCE_SUFFIX;
4334 $pos = strpos($url, $matches[2][$index]);
4336 $new_url = substr_replace($url, $src, $pos, strlen($matches[2][$index]));
4339 $new_url = preg_replace(
'/target[ ]*=[ ]*[^a-zA-Z_"\']*/i',
'', $new_url);
4342 $new_url = preg_replace(
'/^<a/i',
'<a target="_top"', $new_url);
4344 $content = str_replace($url, $new_url, $content);
4349 preg_match_all(
'/<form\s[^>]*action=(\"??)([^\" >]*?)\\1[^>]*>/siU', $content, $matches);
4352 foreach($matches[0] as $index => $url) {
4354 if(preg_match(
'/onsubmit/i', $new_url)) {
4356 $new_url = preg_replace(
'/onsubmit[ ]*=[ ]*["\']+([^"\']*)["\']+/i',
'onsubmit="parent.result_frame.document.location.reload(); \\1"', $new_url);
4360 $new_url = preg_replace(
'/^<form/i',
'<form onsubmit="parent.result_frame.document.location.reload();"', $new_url);
4364 $content = str_replace($url, $new_url, $content);
4379 private function _processUserIP()
4381 if(!defined(
'SQ_CONF_USE_HTTP_X_FORWARDED_FOR') || !defined(
'SQ_CONF_FORWARDED_IP_PROXY_LIST'))
return;
4382 if (SQ_CONF_USE_HTTP_X_FORWARDED_FOR && SQ_CONF_FORWARDED_IP_PROXY_LIST !=
''){
4383 $safe_list = explode(
"\n", SQ_CONF_FORWARDED_IP_PROXY_LIST);
4384 if (array_key_exists(
'REMOTE_ADDR', $_SERVER) && in_array($_SERVER[
'REMOTE_ADDR'], $safe_list)) {
4386 if (!empty($_SERVER[
'HTTP_X_FORWARDED_FOR'])) {
4387 $forwards = explode(
', ', $_SERVER[
'HTTP_X_FORWARDED_FOR']);
4390 for ($n=count($forwards)-1; $n > 0; $n--) {
4391 if (!in_array($forwards[$n], $safe_list)) {
4395 $last_forward = trim($forwards[$n]);
4397 $_SERVER[
'REMOTE_ADDR'] = $last_forward;