17 require_once SQ_INCLUDE_PATH.
'/asset.inc';
42 $this->
Asset($assetid);
60 require_once SQ_CORE_PACKAGE_PATH.
'/system/system_asset_fns.inc';
61 if (!system_asset_fns_create_pre_check($this)) {
64 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
65 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
67 if ($linkid = parent::create($link)) {
68 if (!system_asset_fns_create_cleanup($this)) {
74 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
76 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
79 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
96 return $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->
type(),
'name');
110 $page_links = parent::_getAllowedLinks();
112 $page_links[SQ_LINK_NOTICE][
'asset'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
154 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLinkById($linkid);
155 switch (strtolower($link[
'value'])) {
157 return translate(
'404_remap_description');
160 return parent::describeLink($linkid);
179 public function addRemapURL($old_url, $new_url, $expires=NULL, $never_delete=NULL, $auto=TRUE)
182 if (!is_string($old_url) || !is_string($new_url)) {
183 trigger_localised_error(
'CORE0093', E_USER_WARNING);
187 $old_url = strip_url($old_url);
188 $new_url = strip_url($new_url);
191 if (strcmp($old_url, $new_url) == 0)
return 1;
194 if ($new_url ===
'') {
195 trigger_localised_error(
'CORE0271', E_USER_WARNING);
201 $sql =
'SELECT remap_url
202 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_remap';
203 $where =
'url = :url';
204 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
210 }
catch (Exception $e) {
211 throw new Exception(
'Unable to get remap URLs for URL: '.$old_url.
' due to database error: '.$e->getMessage());
214 if (in_array($new_url, $remap_urls))
return 1;
216 if (count($remap_urls) > 0) {
217 trigger_localised_error(
'CORE0024', E_USER_WARNING, $old_url);
221 if ($never_delete === NULL){
222 $never_delete = ($this->
attr(
'never_delete_remap_default') == FALSE) ? 0 : 1;
225 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
227 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
230 $sql =
'DELETE FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_remap';
231 $where =
' WHERE url = :url';
237 }
catch (Exception $e) {
238 throw new Exception(
'Unable to delete old remap URLs for URL: '.$new_url.
' due to database error: '.$e->getMessage());
244 'remap_url' => $new_url,
245 'expires' => (is_null($expires)) ? $expires : ts_iso8601($expires),
246 'never_delete' => $never_delete,
247 'auto_remap' => ($auto === TRUE) ?
'1' : (($auto === FALSE) ?
'0' : NULL),
250 }
catch (Exception $e) {
251 throw new Exception(
'Unable to insert new remap from: '.$old_url.
' to: '.$new_url.
' due to database error: '. $e->getMessage());
254 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
255 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
273 if (is_null($asset))
return $null;
280 $bind_vars = Array();
285 $sql =
'SELECT url, remap_url, expires, never_delete, auto_remap
286 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_remap';
287 $union_select =
'(SELECT
290 '.$GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause(
'http = \'1\'
291 AND assetid = :assetid').
')
294 (\'https://\' || url)
296 '.$GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause(
'https = \'1\'
297 AND assetid = :assetid_1').
')';
299 $bind_vars[
'assetid'] = $asset->id;
300 $bind_vars[
'assetid_1'] = $asset->id;
301 $where =
'remap_url IN ('.$union_select.
')';
302 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where);
306 foreach ($bind_vars as $bind_var => $bind_value) {
310 }
catch (Exception $e) {
311 throw new Exception(
'Unable to get remap URLs for this asset: '.$asset->id.
' due to database error: '.$e->getMessage());
334 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
337 $bind_vars = Array(
'assetid' => $assetid);
340 throw new Exception(
'Unable to remap all URLs; could not get existing lookups for asset ID #'.$assetid.
' due to database error: '.$e->getMessage);
343 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
345 $protocols = Array (
'https' => FALSE,
'http' => FALSE );
346 $never_delete = ($this->
attr(
'never_delete_remap_default') == FALSE) ? 0 : 1;
348 foreach ($urls as $url_data) {
349 if ($url_data[
'http']) {
350 $retval = @$this->
addRemapURL(
'http://'.$url_data[
'url'], $new_url, $expires, $never_delete, FALSE);
352 trigger_localised_error(
'CORE0039', E_USER_WARNING, $assetid, $new_url);
353 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
354 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
357 $protocols[
'http'] = TRUE;
359 if ($url_data[
'https']) {
360 $retval = @$this->
addRemapURL(
'https://'.$url_data[
'url'], $new_url, $expires, $never_delete, FALSE);
362 trigger_localised_error(
'CORE0039', E_USER_WARNING, $assetid, $new_url);
363 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
364 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
367 $protocols[
'https'] = TRUE;
372 foreach ($protocols as $protocol => $enabled){
376 $bind_vars = Array(
'urls' => Array($protocol.
'://?a='.$assetid));
379 throw new Exception(
'Unable to delete assetid remaps due to database error: '.$e->getMessage());
381 $retval = @$this->
addRemapURL($protocol.
'://?a='.$assetid, $new_url, $expires, $never_delete, FALSE);
383 trigger_localised_error(
'CORE0040', E_USER_WARNING, $assetid, $new_url);
384 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
385 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
391 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
392 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
407 $protocol = current_protocol();
410 $url = strip_url(current_url(FALSE, TRUE));
413 $url_with_params = strip_url($_SERVER[
'HTTP_HOST'].$_SERVER[
'REQUEST_URI']);
419 if(!$this->
attr(
"preserve_url_parameters")) {
422 if ($url === $url_with_params) {
432 $pos = strpos($url_with_params,
'?');
434 $parameters = substr($url_with_params, $pos + 1);
438 if (!empty($parameters)) {
460 if (is_null($protocol)) $protocol = current_protocol();
462 $url = strip_url(current_url(FALSE, TRUE));
465 $url = $protocol.
'://'.$url;
466 $time = ts_iso8601(time());
469 if(!empty($parameters)) {
475 'url_with_trailing_question_mark' => $url.
'?',
480 throw new Exception(
'Unable to get current remap URL for "'.$url.
'" due to database error: '.$e->getMessage());
483 if(empty($results))
return FALSE;
485 $remap_url = $results[0][
'remap_url'];
488 if($results[0][
'url'] === $url) {
490 if(strpos($remap_url,
'?') !== FALSE) {
491 $remap_url = $remap_url.
'&'.$parameters;
494 $remap_url = $remap_url.
'?'.$parameters;
508 throw new Exception(
'Unable to get current remap URL for "'.$url.
'" due to database error: '.$e->getMessage());
513 if (!empty($remap_url)) {
515 header(
'HTTP/1.1 301 Moved Permanently');
516 $cm = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cache_manager');
518 if (SQ_CONF_SEND_CACHEABLE_HEADER && $cm->cacheableHeadersEnabledForCurrentProtocol()) {
519 header(
'Pragma: cache');
521 $browser_cache_expiry = $cm->attr(
'browser_cache_expiry');
522 if (empty($browser_cache_expiry)) {
523 $browser_cache_expiry = $cm->attr(
'expiry');
526 header(
'Cache-Control: max-age='.$browser_cache_expiry.
', '.$cm->cacheControlLevel());
527 header(
'Expires: '.gmdate(
'D, d M Y H:i:s', time() + $browser_cache_expiry).
' GMT');
529 header(
'Location: '.$remap_url);
549 if (is_null($protocol)) $protocol = current_protocol();
551 $url = strip_url(current_url(FALSE, TRUE));
554 $url = $protocol.
'://'.$url;
557 $time = ts_iso8601(time());
564 throw new Exception(
'Unable to get current remap URL for "'.$url.
'" due to database error: '.$e->getMessage());
568 if (!empty($remap_url)) {
569 $protocol = parse_url($remap_url, PHP_URL_SCHEME);
570 $search =
'#'.$protocol.
'\\://#';
571 $url = preg_replace($search,
'', $remap_url);
575 if ($final_url !== FALSE) $remap_url = $final_url;
592 $link_to_404 = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'', FALSE,
'404');
594 if (empty($link_to_404)) {
597 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link_to_404[
'minorid']);
618 if (is_null($asset))
return FALSE;
621 header(
'HTTP/1.0 404 Not Found');
623 $url = strip_url($this->
getURL(), TRUE);
624 $asset_url = strip_url($asset->getURL(NULL, TRUE), TRUE);
626 global $ASSET_LINEAGE;
627 $ASSET_LINEAGE = $GLOBALS[
'SQ_SYSTEM']->am->getLineageFromUrl(NULL, $asset_url);
629 $design = $this->
getDesign($asset, $url);
630 if (!is_null($design)) {
631 $design->paint($asset);
636 if (!is_null($design)) {
637 $design->paint($asset);
642 $asset->printFrontend();
664 if (is_null($asset))
return $null;
666 $bind_vars = Array();
669 $sql =
'SELECT lv.value as designid, a.type_code
670 FROM '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup l
671 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast_lookup_value lv ON ((l.url = lv.url) OR (l.url || \'/\' = lv.url))
672 INNER JOIN '.SQ_TABLE_RUNNING_PREFIX.
'ast a ON lv.value = a.assetid
674 $where =
'l.assetid = :assetid AND lv.name = :lookup_name';
676 $bind_vars[
'assetid'] = $asset->id;
677 $bind_vars[
'lookup_name'] =
'design::system::frontend';
679 if (!is_null($url)) {
680 $where .=
' AND lv.url LIKE :url';
681 $bind_vars[
'url'] = $url.
'%';
684 $order_by =
' ORDER BY depth DESC';
685 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'lv');
686 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'l');
687 $where = $GLOBALS[
'SQ_SYSTEM']->constructRollbackWhereClause($where,
'a');
688 $sql .= $where.$order_by;
693 foreach ($bind_vars as $bind_var => $bind_value) {
698 throw new Exception(
'Unable to select design of remapped asset "'.$asset->name.
'" (#'.$asset->id.
') due to database error: '.$e->getMessage());
702 return $GLOBALS[
'SQ_SYSTEM']->am->getAsset($result[0][
'designid'], $result[0][
'type_code']);