19 require_once SQ_CORE_PACKAGE_PATH.
'/folder/folder_edit_fns.inc';
38 protected $protos = Array(
'http',
'https');
47 parent::__construct();
48 $this->static_screens[
'details'][
'lock_type'] =
'attr_links';
49 unset($this->static_screens[
'dependants']);
67 <table border=
"0" cellspacing=
"0" cellpadding=
"3" id=
"urls_<?php echo $prefix; ?>-table" class=
"sq-backend-table" style=
"width: auto">
72 foreach ($this->protos as $protocol) {
73 ?><th><?php echo strtoupper($protocol) ?></th><?php
76 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
77 if (count($all_contexts) > 1) {
78 ?><th>Base Context</th><?php
83 <tbody
id=
"urls_<?php echo $prefix; ?>">
91 for (reset($urls); NULL !== ($urlid = key($urls)); next($urls)) {
92 $this->
_paintURL($o, $prefix, $urlid, $urls[$urlid], $wa);
97 if (count($urlids) > 0) {
98 $last_id = $urlids[count($urlids)-1];
103 $this->
_paintURL($o, $prefix, ++$last_id, Array(
'url' =>
'',
'protocols' => Array()), TRUE);
104 $urlids[] = $last_id;
107 $o->
addOnSubmit(
'if (!site_url_check()) return false;');
115 <script language=
"JavaScript" type=
"text/javascript">
117 var site_url_protos =
new Array(
"<?php echo implode('",
"', $this->protos); ?>");
118 var site_url_urlids =
new Array(
"<?php echo implode('",
"', $urlids); ?>");
120 var optionList = document.getElementById(
'urls_<?php echo $prefix; ?>');
121 var inputs = optionList.getElementsByTagName(
'TR');
123 function expandList(el) {
124 var lastId = site_url_urlids[site_url_urlids.length-1];
126 var lastInput = inputs[inputs.length-1];
127 var newInput = lastInput.cloneNode(
true);
132 var parentTr = el.parentNode.parentNode;
133 if (lastInput != parentTr || (inputs.length > 1 && inputs[inputs.length-2].getElementsByTagName(
'INPUT')[0].value ==
'')) {
137 newInput.getElementsByTagName(
'INPUT')[0].value =
'';
138 newInput.getElementsByTagName(
'INPUT')[0].id =
'<?php echo $prefix; ?>' +
'_urls['+lastId+
'][url]';
139 newInput.getElementsByTagName(
'INPUT')[0].name =
'<?php echo $prefix; ?>' +
'_urls['+lastId+
'][url]';
143 for (var i = 1; i < newInput.getElementsByTagName(
'INPUT').length; i++) {
144 newInput.getElementsByTagName(
'INPUT')[i].id =
'<?php echo $prefix; ?>' +
'_urls['+lastId+
'][protocols]['+prot+
']';
145 newInput.getElementsByTagName(
'INPUT')[i].name =
'<?php echo $prefix; ?>' +
'_urls['+lastId+
'][protocols]['+prot+
']';
150 if (newInput.getElementsByTagName(
'SELECT').length > 0) {
151 newInput.getElementsByTagName(
'SELECT')[0].value = 0;
152 newInput.getElementsByTagName(
'SELECT')[0].id =
'<?php echo $prefix; ?>' +
'_urls['+lastId+
'][base_contextid]';
153 newInput.getElementsByTagName(
'SELECT')[0].name =
'<?php echo $prefix; ?>' +
'_urls['+lastId+
'][base_contextid]';
156 site_url_urlids.push(lastId);
157 optionList.appendChild(newInput);
161 function site_url_check() {
163 for (var j = 0; j < site_url_urlids.length; j++) {
164 var urlid = site_url_urlids[j];
167 var url = get_form_element_value(
"<?php echo $prefix; ?>_urls[" + urlid +
"][url]");
170 for (var i = 0; i < site_url_protos.length; i++) {
171 if (document.getElementById(
"<?php echo $prefix; ?>_urls[" + urlid +
"][protocols][" + i +
"]").checked) {
180 if (!confirm(js_translate(
'must_select_at_least_one_protocol', url))) {
187 for (var i = 0; i < site_url_protos.length; i++) {
188 var proto = get_form_element(
"<?php echo $prefix; ?>_urls[" + urlid +
"][protocols][" + i +
"]");
189 proto.checked =
false;
222 $all_contexts = $GLOBALS[
'SQ_SYSTEM']->getAllContexts();
225 <td
class=
"sq-backend-table-cell">
228 text_box($prefix.
'_urls['.$i.
'][url]', $url_info[
'url'], 40,
'', FALSE,
'onFocus="expandList(this);"');
230 echo
'<strong>'.$url_info[
'url'].
'</strong>';
235 for ($k = 0; $k < count($this->protos); $k++) {
237 <td
class=
"sq-backend-table-cell" style=
"text-align: center">
240 check_box($prefix.
'_urls['.$i.
'][protocols]['.$k.
']', $this->protos[$k], !empty($url_info[$this->protos[$k]]));
243 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo empty($url_info[$this->protos[$k]]) ? 'cross' : 'tick'; ?>.gif" width=
"15" height=
"15" />
251 if (count($all_contexts) > 1) {
252 ?><td
class=
"sq-backend-table-cell"><?php
254 if (array_key_exists(
'base_contextid', $url_info) === FALSE) {
255 $url_info[
'base_contextid'] = 0;
259 if (array_key_exists($url_info[
'base_contextid'], $all_contexts) === FALSE) {
260 $url_info[
'base_contextid'] = 0;
263 if ($write_access === TRUE) {
265 foreach ($all_contexts as $contextid => $context_data) {
266 $options[$contextid] = $context_data[
'name'];
268 combo_box($prefix.
'_urls['.$i.
'][base_contextid]', $options, FALSE, $url_info[
'base_contextid']);
270 echo $all_contexts[$url_info[
'base_contextid']][
'name'];
294 if (empty($_POST[$prefix.
'_urls']))
return FALSE;
296 $post = $_POST[$prefix.
'_urls'];
299 for (reset($post); NULL !== ($urlid = key($post)); next($post)) {
301 $url = trim($post[$urlid][
'url']);
305 if(preg_match(
'/^http(s)?:/', $url)) {
306 trigger_localised_error(
'CORE0303', E_USER_WARNING, $url);
311 if ($url && !empty($post[$urlid][
'protocols'])) {
312 $urls[$urlid] = Array(
313 'url' => $post[$urlid][
'url'],
314 'base_contextid' => array_get_index($post[$urlid],
'base_contextid', 0),
316 for ($k = 0; $k < count($this->protos); $k++) {
317 $urls[$urlid][$this->protos[$k]] = (int) in_array($this->protos[$k], $post[$urlid][
'protocols']);
333 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
334 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
337 foreach ($urls as $urlid => $url_data) {
339 if (!isset($old_urls[$urlid]) || $old_urls[$urlid]==$url_data) {
348 'url' => strip_url($urls[$urlid][
'url']),
352 }
catch (Exception $e) {
353 throw new Exception(
'Unable to update URL: '.strip_url($urls[$urlid][
'url']).
' for urlid: '.$urlid.
' due to database error: '.$e->getMessage());
357 foreach (Array(
'sq_ast_lookup_value',
'sq_ast_lookup') as $tablename) {
359 if ($urls[$urlid][
'url'] == $old_urls[$urlid][
'url']) {
365 url = :url || SUBSTR(url, :substr_arg)
367 (url LIKE :old_url_like OR url LIKE :old_url_like_slash)';
370 if ($tablename ==
'sq_ast_lookup') {
371 $sql .=
' AND root_urlid = :urlid';
372 }
else if ($tablename ==
'sq_ast_lookup_value') {
373 $sql .=
' AND url IN (
379 sq_ast_lookup_value v ON ((l.url = v.url) OR (l.url || \'/\' = v.url))
381 l.root_urlid = :urlid
392 }
catch (Exception $e) {
393 throw new Exception(
'Unable to update this old URL: '.$old_urls[$urlid][
'url'].
' with this new URL: '.$urls[$urlid][
'url'].
' due to database error: '.$e->getMessage());
398 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
399 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
404 if ($run_hipo && $updatelookups) {
405 $hh = $GLOBALS[
'SQ_SYSTEM']->getHipoHerder();
406 $vars = Array(
'assetids' => Array($asset->id));
407 $hh->queueHipo(
'hipo_job_update_lookups', $vars);
636 $bind_vars = Array(
'assetid' => $asset->id);
638 }
catch (Exception $e) {
639 throw new Exception(
'Unable to get URLs for asset: '.$asset->id.
' due to database error: '.$e->getMessage());
642 $combo_box_urls = Array();
644 foreach ($urls as $urlid => $url) {
645 $combo_box_urls[$url[
'urlid']] = $url[
'url'];
648 $combo_box_from = $combo_box_urls;
652 $paint_table = FALSE;
656 foreach ($urls as $urlid => $url) {
657 if (!empty($url[
'auth_urlid'])) {
659 $auth_urlid = $url[
'auth_urlid'];
660 unset($combo_box_from[$urlid]);
663 <td><?php echo $url[
'url'] ?></td>
666 combo_box($prefix.
'auth_url[change]['.$url[
'urlid'].
']', $combo_box_urls, FALSE, $url[
'auth_urlid']);
668 for ($i=0; $i<count($urls); $i++) {
669 if ($urls[$i][
'urlid'] === $auth_urlid)
670 echo $urls[$i][
'url'];
674 <?php
if ($write_access) {
676 <td><?php echo check_box($prefix.
'auth_url[delete]['.$url[
'urlid'].
']') ?></td>
686 $body = ob_get_clean();
688 $o->
openSection(translate(
'core_site_current_redirects'));
693 <table
class=
"sq-backend-table">
695 <th><?php echo translate(
'old_url') ?></th>
696 <th><?php echo translate(
'new_url') ?></th>
697 <?php
if ($write_access) {
698 ?><th>Delete?</th><?php
708 ?><em>No redirects currently exist</em><?php
717 $combo_box_from = Array(
'' =>
'-- Select URL --') + $combo_box_from;
718 $combo_box_urls = Array(
'' =>
'-- Select URL --') + $combo_box_urls;
720 $o->
openSection(translate(
'core_site_add_redirect'));
723 combo_box($prefix.
'auth_url[from]', $combo_box_from);
727 combo_box($prefix.
'auth_url[to]', $combo_box_urls);
734 return $write_access;
756 $bind_vars = Array(
'assetid' => $asset->id);
759 $transformed_urls = Array();
760 foreach ($urls as $key => $value) {
761 if (isset($value[
'urlid'])) {
762 $transformed_urls[$value[
'urlid']] = $value[
'auth_urlid'];
765 $urls = $transformed_urls;
767 }
catch (Exception $e) {
768 throw new Exception(
'Unable to get authentication redirect URLs for asset: '.$asset->id.
' due to database error: '.$e->getMessage());
770 $changed_urlids = Array();
772 $auth_urls = $_REQUEST[$prefix.
'auth_url'];
776 if (!is_array($auth_urls))
return FALSE;
778 if (isset($auth_urls[
'change'])) {
779 if (!is_array($auth_urls[
'change']))
return FALSE;
781 foreach ($auth_urls[
'change'] as $from => $to) {
782 if (!is_numeric($to))
return FALSE;
783 $urls[$from] = (int)$to;
784 $changed_urlids[$from] = TRUE;
788 if (isset($auth_urls[
'delete'])) {
789 if (!is_array($auth_urls[
'delete']))
return FALSE;
791 foreach ($auth_urls[
'delete'] as $from => $value) {
793 $changed_urlids[$from] = TRUE;
797 if (!empty($auth_urls[
'from']) && !empty($auth_urls[
'to'])) {
798 if (!is_numeric($auth_urls[
'from']))
return FALSE;
799 if (!is_numeric($auth_urls[
'to']))
return FALSE;
801 $urls[(int)$auth_urls[
'from']] = (
int)$auth_urls[
'to'];
802 $changed_urlids[(int)$auth_urls[
'from']] = TRUE;
808 trigger_localised_error(
'CORE0269', E_USER_WARNING);
812 if (isset($_POST[$prefix.
'_urls'])) {
813 $processed_urls = $_POST[$prefix.
'_urls'];
815 $diff_urls = array_values(array_diff(array_keys($processed_urls), array_keys($current_urls)));
818 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
820 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
823 foreach (array_keys($changed_urlids) as $urlid) {
824 if (isset($diff_urls) && !in_array($urls[$urlid], $diff_urls)) {
827 'auth_urlid' => $urls[$urlid],
831 }
catch (Exception $e) {
832 throw new Exception(
'Unable to update auth_urlid for urlid: '.$urlid.
' due to database error: '.$e->getMessage());
837 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
838 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
872 foreach (array_keys($urls) as $from) {
873 $current_from = $from;
878 while (!$complete && !$circular) {
879 $seen[] = $current_from;
882 $current_from = array_get_index($urls, $current_from, NULL);
884 if (empty($current_from)) $complete = TRUE;
887 if (array_search($current_from, $seen) !== FALSE) {
894 if ($circular)
return TRUE;