18 require_once SQ_CORE_PACKAGE_PATH.
'/page/page.inc';
43 parent::__construct($assetid);
56 $lock_types = parent::lockTypes();
57 $lock_types[
'redirect'] = ($lock_types[
'attributes'] | $lock_types[
'links']);
72 $page_links = parent::_getAllowedLinks();
73 $page_links[SQ_LINK_NOTICE][
'asset'] = Array(
'card' =>
'M',
'exclusive' => FALSE);
89 $notice_links = unserialize(file_to_string($this->data_path.
'/.sq_notice_links'));
90 foreach ($notice_links as $link) {
91 if ($link[
'value'] ==
'redirect_asset') {
92 $redirect_link = $link;
97 if (!empty($this->
id)) {
98 $link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'', TRUE,
'redirect_asset');
102 $res = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'minorid'], $link[
'minor_type_code']);
120 $old_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($this->
id, SQ_LINK_NOTICE,
'', TRUE,
'redirect_asset');
121 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
122 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
123 if (empty($old_link)) {
125 if (is_null($asset)) {
126 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
127 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
132 }
else if (!is_null($asset) && $old_link[
'minorid'] == $asset->id) {
133 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
134 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
139 if (!$this->
deleteLink($old_link[
'linkid'])) {
140 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
141 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
146 if (!is_null($asset)) {
147 if (!$this->
createLink($asset, SQ_LINK_NOTICE,
'redirect_asset')) {
148 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
149 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
154 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
155 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
172 $GLOBALS[
'SQ_SYSTEM']->setGlobalDefine(
'SQ_REPLACE_MYSOURCE_LEVEL_KEYWORDS', FALSE);
176 $GLOBALS[
'SQ_SYSTEM']->paintLogin(
'Login', translate(
'cannot_access_asset', $this->name));
187 if (empty($url))
return;
191 $pmap_value = $pmap->getParameters();
193 foreach ($pmap_value as $index => $value) {
194 if (isset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$value])) {
195 unset($_SESSION[SQ_SESSION_SANDBOX_INDEX][$value]);
199 $return_value = $pmap->getParameterValue($value);
202 replace_global_keywords($return_value);
205 $_SESSION[SQ_SESSION_SANDBOX_INDEX][$value] = $return_value;
209 if($this->
attr(
'permanent_redirect') && !headers_sent()) {
210 header(
'HTTP/1.1 301 Moved Permanently');
211 header(
'Location: '.$url);
215 $timeout = $this->
attr(
'timeout');
216 if (($timeout > 0) || headers_sent()) {
217 if (!isset($this->_tmp[
'parent_already_called'])) {
218 $this->_tmp[
'parent_already_called'] = TRUE;
219 parent::printFrontend();
225 if ($this->
attr(
'new_window')) {
226 $options = $this->
attr(
'new_window_options');
227 $params =
'location='.((strpos($options,
'hide_location' ) !== FALSE) ?
'0' :
'1').
','
228 .
'menubar='.((strpos($options,
'hide_menubar' ) !== FALSE) ?
'0' :
'1').
','
229 .
'scrollbars='.((strpos($options,
'hide_scrollbars') !== FALSE) ?
'0' :
'1').
','
230 .
'statusbar='.((strpos($options,
'hide_status' ) !== FALSE) ?
'0' :
'1').
','
231 .
'toolbar='.((strpos($options,
'hide_toolbar' ) !== FALSE) ?
'0' :
'1').
','
232 .
'resizable='.((strpos($options,
'not_resizable' ) !== FALSE) ?
'0' :
'1');
233 if ($w = $this->
attr(
'new_window_width')) {
234 $params .=
',width='.$w;
236 if ($h = $this->
attr(
'new_window_height')) {
237 $params .=
',height='.$h;
241 $wrap_script = !headers_sent();
246 <script language=
"JavaScript" type=
"text/javascript">
247 var page = window.open(
'<?php echo addslashes($url); ?>',
'<?php echo time(); ?>',
'<?php echo addslashes($params);?>');
251 if ($wrap_script) ?></body></html><?php
255 if (!headers_sent()) header(
'Location: '.$url);
269 $keywords = parent::getAvailableKeywords();
271 $asset =
new Asset();
273 foreach ($asset->getAvailableKeywords() as $keyword => $desc) {
274 $keywords[
'referring_'.$keyword] =
'Referring Asset: '.$desc;
277 $keywords[
'javascript_redirect'] =
'JavaScript Redirect Code';
278 $keywords[
'redirect_url'] =
'Redirect URL';
279 $keywords[
'redirect_assetid'] =
'Redirect Asset Id';
303 $original_keyword = $keyword;
304 $keyword = parse_keyword($keyword, $modifiers);
306 if (preg_match(
'|^referring\_(.*)|', $keyword, $matches)) {
308 $replacement = empty($referring_asset) ?
'' : $referring_asset->getKeywordReplacement($matches[1]);
309 }
else if ($keyword ===
'redirect_url') {
311 }
else if ($keyword ===
'redirect_assetid') {
313 $replacement = empty($redirect_asset) ?
'' : $redirect_asset->id;
315 return parent::getKeywordReplacement($original_keyword);
318 if (!is_null($replacement)) {
319 apply_keyword_modifiers($replacement, $modifiers, Array(
'assetid' => $this->
id));
335 $url = array_get_index($_SERVER,
'HTTP_REFERER', FALSE);
338 $url = preg_replace(
'|^.*://|',
'', $url);
339 $url = preg_replace(
'|\?.*$|',
'', $url);
341 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL(NULL, $url, FALSE, TRUE);
370 $qrystr_param = $this->
attr(
'use_querystring_parameter');
371 $url = trim($this->
attr(
'redirect_url'));
372 if ($qrystr_param && isset($_GET[$qrystr_param]) && trim($_GET[$qrystr_param]) !=
'') {
373 $url = trim($_GET[$qrystr_param]);
376 }
else if ($url !=
'') {
378 replace_global_keywords($url);
383 if (!is_null($redirect_asset)) {
384 if (($url = $redirect_asset->getURL()) ==
'') {
385 $url = current_url().
'?a='.$redirect_asset->id;
391 trigger_localised_error(
'CMS0037', E_USER_WARNING, $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($this->type(),
'name'), $this->name, $this->
id);
395 $url_suffix = trim($this->
attr(
'url_suffix'));
398 if ($url_suffix !=
'') {
401 replace_global_keywords($url_suffix);
408 if ($this->
attr(
'append_querystring') && !empty($_SERVER[
'QUERY_STRING'])) {
409 $url .= ((strpos($url,
'?') === FALSE) ?
'?' :
'&').$_SERVER[
'QUERY_STRING'];
415 $stripchars = array();
416 for ($i = 0; $i < 32; $stripchars[] = chr($i), $i++);
417 $url = str_replace($stripchars,
'', $url);
432 static $fn_called = FALSE;
434 if ($fn_called)
return '';
437 $timeout = $this->
attr(
'timeout');
439 if (empty($url))
return;
442 if (headers_sent()) {
444 <script language=
"JavaScript" type=
"text/javascript">
445 setTimeout(
"self.location = '<?php echo addslashes($url); ?>'", <?php echo $timeout * 1000 ?>);
449 return ob_get_clean();