18 require_once SQ_CORE_PACKAGE_PATH.
'/folder/folder.inc';
43 parent::__construct($assetid);
56 $lock_types = parent::lockTypes();
57 $lock_types[
'attr_links'] = ($lock_types[
'attributes'] | $lock_types[
'links']);
122 public function delete($release_lock=TRUE)
124 $this->_tmp[
'deleting_site'] = TRUE;
125 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
126 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
129 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
130 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
134 if (!parent::delete($release_lock)) {
135 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
136 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
140 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
141 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
142 $this->_tmp[
'deleting_site'] = FALSE;
159 if (!isset($this->_tmp[
'urls_info'])) {
160 $sql =
'SELECT urlid, url, http, https, base_contextid
161 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_url
163 $where =
'assetid = :assetid';
164 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
165 $sql .= $where.
' ORDER BY urlid';
175 foreach ($result_x as $key => $row) {
176 $result[$key] = $row[0];
179 }
catch (Exception $e) {
180 throw new Exception(
'Unable to get applied schemas for asset ID #'.$this->
id.
' due to database error: '.$e->getMessage());
183 $this->_tmp[
'urls_info'] = $result;
187 return $this->_tmp[
'urls_info'];
204 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
205 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
207 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
210 $processed_urlids = Array();
212 $system_root_urls = explode(
"\n", SQ_CONF_SYSTEM_ROOT_URLS);
214 for (reset($save_urls); NULL !== ($save_urlid = key($save_urls)); next($save_urls)) {
216 $save_urls[$save_urlid][
'base_contextid'] = array_get_index($save_urls[$save_urlid],
'base_contextid', 0);
218 $curr_urlid = $save_urlid;
221 $save_urls[$save_urlid][
'url'] = strip_url($save_urls[$save_urlid][
'url'], TRUE);
224 $paths = explode(
'/', $save_urls[$save_urlid][
'url']);
228 foreach ($paths as $path) {
229 $clean_paths = make_valid_web_paths(Array($path));
230 $clean_path = (empty($clean_paths)) ?
'' : $clean_paths[0];
231 if ($path != $clean_path) {
232 if ($clean_path !=
'') {
233 trigger_localised_error(
'CORE0080', $save_urls[$save_urlid][
'url'], $path, $clean_path, E_USER_WARNING);
235 trigger_localised_error(
'CORE0124', $save_urls[$save_urlid][
'url'], $path, E_USER_WARNING);
238 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
239 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
246 $found_root_url = FALSE;
247 foreach ($system_root_urls as $root_url) {
248 if (substr($save_urls[$save_urlid][
'url'], 0, strlen($root_url)) == $root_url) {
249 $found_root_url = TRUE;
254 if (!$found_root_url) {
255 trigger_localised_error(
'CORE0082', E_USER_WARNING, $save_urls[$save_urlid][
'url']);
256 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
257 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
264 for (reset($current_urls); NULL !== ($i = key($current_urls)); next($current_urls)) {
265 if ($save_urls[$save_urlid][
'url'] == $current_urls[$i][
'url']) {
273 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(NULL, $save_urls[$save_urlid][
'url'], TRUE, TRUE);
274 if (!is_null($asset)) {
275 trigger_localised_error(
'CORE0081', E_USER_WARNING, $save_urls[$save_urlid][
'url'], $asset->name, $asset->id);
277 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
278 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
284 if (isset($current_urls[$save_urlid])) {
286 if ($current_urls[$save_urlid][
'url'] != $save_urls[$save_urlid][
'url'] ||
287 $current_urls[$save_urlid][
'http'] != $save_urls[$save_urlid][
'http'] ||
288 $current_urls[$save_urlid][
'https'] != $save_urls[$save_urlid][
'https'] ||
289 $current_urls[$save_urlid][
'base_contextid'] != $save_urls[$save_urlid][
'base_contextid']) {
297 base_contextid = :base_contextid
300 AND assetid = :assetid';
312 }
catch (Exception $e) {
313 throw new Exception(
'Unable to update URLs for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
319 foreach ($current_urls as $url) {
320 if($save_urls[$save_urlid][
'url'] === $url[
'url']) {
321 trigger_localised_error(
'CORE0081', E_USER_WARNING, $save_urls[$save_urlid][
'url'], $this->name, $this->
id);
322 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
323 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
361 }
catch (Exception $e) {
362 throw new Exception(
'Unable to insert URLs for asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
367 $current_urls[$curr_urlid] = $save_urls[$save_urlid];
368 $processed_urlids[] = $curr_urlid;
372 $delete_urlids = array_diff(array_keys($current_urls), $processed_urlids);
374 foreach ($delete_urlids as $urlid) {
385 }
catch (Exception $e) {
386 throw new Exception(
'Unable to delete URLs from asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
391 $bind_vars = Array(
'old_auth_urlid' => $urlid,
'new_auth_urlid' => NULL);
393 }
catch (Exception $e) {
394 throw new Exception(
'Unable to remove authentication redirect for auth_urlid: '.$urlid.
' due to database error: '.$e->getMessage());
399 unset($this->_tmp[
'urls_info']);
401 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
402 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
403 if ($updated)
return 2;
421 if (!empty($current_urls)) {
438 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
440 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
442 unset($this->_tmp[
'lookups']);
443 unset($this->_tmp[
'url']);
444 unset($this->_tmp[
'href']);
446 if (!isset($this->_tmp[
'deleting_site'])) {
447 $this->_tmp[
'deleting_site'] = FALSE;
451 $lookup_values = $this->
getLookupValues(FALSE, $prefix=
'design::', FALSE);
465 assetid = :assetid_1)
472 assetid = :assetid_2)
480 }
catch (Exception $e) {
481 throw new Exception(
'Unable to remove existing lookups for Site asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
494 }
catch (Exception $e) {
495 throw new Exception(
'Unable to remove existing lookups for Site asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
498 $our_design_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'design', FALSE);
499 $design_lookups = Array();
500 foreach ($our_design_links as $link) {
501 if (preg_match(
'/^design::(system|user)::(.*)$/', $link[
'value'])) {
502 $design_lookups[$link[
'value']] = $link[
'minorid'];
505 $override_design_lookups = Array();
507 foreach ($our_design_links as $link) {
508 if (preg_match(
'/^override::design::(system|user)::(.*)$/', $link[
'value'])) {
509 $name = preg_replace(
'/^override::(.*)$/',
'$1', $link[
'value']);
510 $override_design_lookups[$name] = $link[
'minorid'];
513 unset($our_design_links);
515 $our_layout_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_LINK_NOTICE,
'paint_layout_page', FALSE);
516 $paint_layouts = Array();
517 foreach ($our_layout_links as $link) {
518 if (preg_match(
'/^paint_layout::(system|user)::.*$/', $link[
'value'])) {
519 $paint_layouts[$link[
'value']] = Array(
520 'value' => $link[
'minorid'],
525 $override_paint_layouts = Array();
526 foreach ($our_layout_links as $link) {
527 if (preg_match(
'/^override::paint_layout::system::.*$/', $link[
'value'])) {
528 $name = preg_replace(
'/^override::(.*)$/',
'$1', $link[
'value']);
529 $override_paint_layouts[$name] = Array(
530 'value' => $link[
'minorid'],
535 unset($our_layout_links);
538 $edit_layouts = Array();
539 foreach($our_edit_layouts as $layout_url => $layouts) {
540 foreach($layouts as $name => $layout_data) {
541 if (!isset($edit_layouts[$name])) {
542 $edit_layouts[$name] = $layout_data[
'value'];
546 unset($our_edit_layouts);
549 $current_urls = Array();
551 for (reset($urls); NULL !== ($urlid = key($urls)); next($urls)) {
552 $current_urls[] = $urls[$urlid][
'url'];
555 foreach ($design_lookups as $design_name => $value) {
556 $lookup_values[$urls[$urlid][
'url']][$design_name][
'value'] = $value;
558 foreach ($override_design_lookups as $override_design_name => $value) {
559 $lookup_values[$urls[$urlid][
'url'].
'/'][$override_design_name][
'value'] = $value;
562 if (!isset($lookup_values[$urls[$urlid][
'url']])) {
564 $lookup_values[$urls[$urlid][
'url']] =
'';
566 if (!isset($lookup_values[$urls[$urlid][
'url'].
'/'])) {
568 $lookup_values[$urls[$urlid][
'url'].
'/'] =
'';
572 foreach($edit_layouts as $layout_name => $value) {
573 if (!isset($lookup_values[$urls[$urlid][
'url']][$layout_name])) {
574 $lookup_values[$urls[$urlid][
'url']][$layout_name][
'value'] = $value;
604 }
catch (Exception $e) {
605 throw new Exception(
'Unable to insert lookups for Site asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
613 foreach ($lookup_values as $url => $data) {
616 if (!in_array(rtrim($url,
'/'), $current_urls)) {
617 unset($lookup_values[$url]);
621 if (preg_match(
'/.+\/$/', $url)) {
623 foreach ($override_paint_layouts as $name => $value) {
625 $lookup_values[$url][$name] = $value;
626 }
else if (!in_array($name, array_keys($data))) {
627 $lookup_values[$url][$name] = $value;
632 foreach ($paint_layouts as $name => $value) {
634 $lookup_values[$url][$name] = $value;
635 }
else if (!in_array($name, array_keys($data))) {
636 $lookup_values[$url][$name] = $value;
643 foreach ($lookup_values as $url => $data) {
645 $exploded_url = explode(
'/', $url);
646 $depth = count($exploded_url)-1;
649 foreach ($data as $layout_name => $value) {
673 }
catch (Exception $e) {
674 throw new Exception(
'Unable to insert lookup values for Site asset "'.$this->name.
'" (#'.$this->id.
') due to database error: '.$e->getMessage());
681 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
682 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
698 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
699 switch (strtolower($link[
'value'])) {
701 return translate(
'core_site_index_page');
704 return translate(
'core_site_not_found_page');
707 return translate(
'core_site_archive_page');
710 return parent::describeLink($linkid);
728 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
733 if (is_null($index_page)) {
736 $asset_url = strip_url($this->
getURL(NULL, TRUE), TRUE);
738 $result = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromURL($asset_url, $design_name);
739 if (!empty($result)) {
745 trigger_localised_error(
'CORE0065', E_USER_NOTICE, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'), $this->name, $this->
id);
763 if (!is_null($index_page)) $index_page->printBody();
786 if (is_null($asset))
return;
790 $GLOBALS[
'SQ_SYSTEM']->paintLogin(translate(
'login'), translate(
'cannot_access_asset', $this->name));
794 if ($asset->charset) {
795 header(
"Content-type: text/html; charset=$this->charset");
797 header(
'Content-type: text/html; charset='.SQ_CONF_DEFAULT_CHARACTER_SET);
800 if ($asset->languages) {
801 header(
"Content-language: $this->languages");
805 if (!is_null($design)) {
806 $design_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($design->id, Array(
'design'), FALSE);
807 if (empty($design_info)) {
808 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($design);
814 $asset_url = strip_url($asset->
getURL(NULL, TRUE), TRUE);
815 if (is_null($design)) {
816 $url = strip_url($this->
getURL(), TRUE);
818 $result = $GLOBALS[
'SQ_SYSTEM']->am->getDesignFromURL($asset_url, $design_name);
820 if (empty($result)) {
823 $sql =
'SELECT lv.value as designid, a.type_code
824 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup l
825 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_value lv ON l.url = lv.url
826 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast a ON lv.value = a.assetid
828 $where =
'l.assetid = :assetid
830 AND lv.name = :lookup_name';
831 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lv');
832 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
833 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'a');
844 if (!empty($result)) $result = $result[0];
845 }
catch (Exception $e) {
846 throw new Exception(
'Unable to get default design for asset: '.$asset->id.
' due to database error: '.$e->getMessage());
852 $design = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($result[
'designid'], $result[
'type_code']);
856 global $ASSET_LINEAGE;
857 if (!empty($asset_url)) {
858 $ASSET_LINEAGE = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromUrl(NULL, $asset_url);
862 if($this->
attr(
'not_found_page_cache_globally') == TRUE) {
863 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
864 $cm->global_cache = TRUE;
867 if (!is_null($design)) {
872 if (!is_null($layout)) {
874 $layout_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($layout->id, Array(
'paint_layout_page'));
875 if (!empty($layout_info)) {
876 $layout_id = $layout->id;
879 if (empty($layout_id)) {
881 $layout_id = $GLOBALS[
'SQ_SYSTEM']->am->getValueFromURL($asset_url, $layout_name);
884 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_PAINT_LAYOUT_ID', $layout_id);
893 if($this->
attr(
'not_found_page_cache_globally') === TRUE) {
894 $cm->global_cache = FALSE;
910 if (isset($_GET[
'limbo_assetid']) && $_GET[
'limbo_assetid'] == $this->
id) {
915 if (is_null($index_page)) {
920 $GLOBALS[
'SQ_SYSTEM']->backend->out->addFormActionGetVar(
'limbo_assetid', $index_page->id, TRUE);
921 $GLOBALS[
'SQ_SYSTEM']->backend->out->addFormActionGetVar(
'assetid', $index_page->id);
922 $GLOBALS[
'SQ_SYSTEM']->backend->out->addHiddenField(
'backend_assetid', $index_page->id);
923 $index_page->initLimbo();
942 case 'not_found_design':
943 case 'not_found_layout':
945 return $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'', TRUE, $page);
949 trigger_localised_error(
'CORE0075', E_USER_WARNING, $page);
972 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
990 $network_links = $GLOBALS[
'SQ_SYSTEM']->am->getLinks($this->
id, SQ_SC_LINK_SIGNIFICANT,
'site_network', FALSE,
'minor');
991 if (empty($network_links))
return $null;
993 $site_network = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($network_links[0][
'majorid'], $network_links[0][
'major_type_code']);
994 return $site_network;
1011 if (is_null($site_network))
return '';
1012 return $site_network->getPrimaryURL();
1033 $replacement = NULL;
1038 $full_keyword = $keyword;
1039 $keyword = parse_keyword($keyword, $modifiers);
1041 $keyword_name = substr($keyword, 6);
1042 if (0 === strpos($keyword_name,
'index_id') || 0 === strpos($keyword_name,
'not_found_id') || 0 === strpos($keyword_name,
'archive_id') ) {
1043 $keyword_name = substr($keyword_name, 0, -3);
1045 if (!is_null($asset)) $replacement = $asset->id;
1048 if ($replacement !== NULL) {
1049 if (count($modifiers) > 0) {
1050 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
1054 $replacement = parent::getKeywordReplacement($full_keyword);
1057 return $replacement;
1080 if (empty($index_link) === FALSE) {
1081 $assetids[] = $index_link[
'minorid'];
1084 return parent::getEffectiveLastUpdatedTime($assetids);