17 require_once SQ_INCLUDE_PATH.
'/asset_edit/asset_edit_fns.inc';
18 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
43 private $num_per_page = 100;
53 parent::__construct();
55 $this->static_screens[
'details'][
'force_unlock'] = FALSE;
56 $this->static_screens[
'details'][
'lock_type'] =
'all';
58 unset($this->static_screens[
'settings']);
59 unset($this->static_screens[
'preview']);
60 unset($this->static_screens[
'lookupValues']);
61 unset($this->static_screens[
'web_paths']);
62 unset($this->static_screens[
'metadata']);
63 unset($this->static_screens[
'metadataSchemas']);
64 unset($this->static_screens[
'workflow']);
65 unset($this->static_screens[
'tagging']);
66 unset($this->static_screens[
'dependants']);
67 unset($this->static_screens[
'linking']);
68 unset($this->static_screens[
'roles']);
69 unset($this->static_screens[
'permissions']);
94 private function _fetchRemapUrls($url_filter=
'', $remap_url_filter=
'', $page_num=1, $return_count=TRUE)
96 require_once SQ_FUDGE_PATH.
'/db_extras/db_extras.inc';
98 $offset = $this->num_per_page * ($page_num - 1);
100 $remap_urls = Array();
101 if ( (!empty($url_filter)) || (!empty($remap_url_filter))) {
103 'url' => (
string)
'%'.$url_filter.
'%',
104 'remap_url' => (
string)
'%'.$remap_url_filter.
'%',
107 $where =
' WHERE url LIKE :url AND remap_url LIKE :remap_url';
110 $bind_vars = Array();
115 $count_query =
'SELECT COUNT(url) FROM sq_ast_lookup_remap '.$where;
121 $query =
'SELECT url, remap_url, expires, never_delete, auto_remap FROM sq_ast_lookup_remap '.$where.
' ORDER BY url';
123 $query = db_extras_modify_limit_clause($query,
MatrixDAL::getDbType(), $this->num_per_page, $offset);
131 if (!empty($bind_vars)) {
132 foreach ($bind_vars as $bind_var => $bind_value) {
144 }
catch (Exception $e) {
145 throw new Exception(
'Unable to get remap urls due to the following database error: '.$e->getMessage());
150 'total_remaps' => $total_assets,
151 'remap_rows' => $remap_urls,
173 $url_filter = array_get_index($_POST, $prefix.
'_URL_FILTER',
'');
174 $remap_url_filter = array_get_index($_POST, $prefix.
'_REMAP_URL_FILTER',
'');
176 if ( (!empty($url_filter)) || (!empty($remap_url_filter))) {
177 $remap_entries_tag =
'remap_entries_filtered';
178 $no_entries_tag =
'no_url_remappings_filtered';
180 $remap_entries_tag =
'remap_entries';
181 $no_entries_tag =
'no_url_remappings';
184 $page_num = array_get_index($_POST, $prefix.
'_remap_urls_page', 1);
185 $page_num = max($page_num, 1);
187 $remap_info = $this->_fetchRemapUrls($url_filter, $remap_url_filter, $page_num, TRUE);
188 $total_assets = $remap_info[
'total_remaps'];
189 $remap_urls = $remap_info[
'remap_rows'];
191 $o->
openField(translate(
'purge_all_remaps'));
192 combo_box($prefix.
'_purge_all_remaps', Array(0 => translate(
'no'), 1 => translate(
'yes')), FALSE, 0, 0,
"onChange=\"Javascript: if (this.value == 1) { if(!confirm(js_translate('confirm_purge_all_remaps'))) { this.value = 0; } } \"". ($write_access ?
'' :
"disabled"));
193 $o->
note(translate(
'purge_all_remaps_note'));
198 text_box($prefix.
'_URL_FILTER', $url_filter, 30);
199 $o->
note(translate(
'remap_manager_url_filter_note'));
202 text_box($prefix.
'_REMAP_URL_FILTER', $remap_url_filter, 30);
203 $o->
note(translate(
'remap_manager_remap_url_filter_note'));
208 if (empty($remap_urls)) {
209 echo translate($no_entries_tag);
213 $num_pages = ceil($total_assets / $this->num_per_page);
215 if ($num_pages == 1) {
216 $page_tag = translate(
'page_number', $page_num, $num_pages);
218 $page_tag = translate(
'page_number_with_pager', $page_num, $num_pages, $prefix.
'_remap_urls_page');
220 $asset_count_tag = translate(
'item_range', ($page_num - 1) * $this->num_per_page + 1, $total_assets, $total_assets, strtolower(translate($remap_entries_tag)));
223 'first' =>
'<<',
224 'previous' =>
'<',
227 'last' =>
'>>',
231 $links[
'first'] =
'<a title="'.translate(
'pagination_go_to_first').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_remap_urls_page\', 1)">'.$links[
'first'].
'</a>';
232 $links[
'previous'] =
'<a title="'.translate(
'pagination_go_to_previous').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_remap_urls_page\', '.($page_num - 1).
')">'.$links[
'previous'].
'</a>';
234 $links[
'first'] =
'<span title="'.translate(
'pagination_cannot_go_further_back').
'." style="color: #333">'.$links[
'first'].
'</span>';
235 $links[
'previous'] =
'<span title="'.translate(
'pagination_cannot_go_further_back').
'." style="color: #333">'.$links[
'previous'].
'</span>';
238 if ($page_num < $num_pages) {
239 $links[
'last'] =
'<a title="'.translate(
'pagination_go_to_last').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_remap_urls_page\', '.$num_pages.
')">'.$links[
'last'].
'</a>';
240 $links[
'next'] =
'<a title="'.translate(
'pagination_go_to_next').
'" style="text-decoration: none; color: #fff" href="#" onClick="return sq_pager_jump(\''.$prefix.
'_remap_urls_page\', '.($page_num + 1).
')">'.$links[
'next'].
'</a>';
242 $links[
'last'] =
'<span title="'.translate(
'pagination_cannot_go_further_forward').
'." style="color: #333">'.$links[
'last'].
'</span>';
243 $links[
'next'] =
'<span title="'.translate(
'pagination_cannot_go_further_forward').
'." style="color: #333">'.$links[
'next'].
'</span>';
246 hidden_field($prefix.
'_remap_urls_page', $page_num); ?>
248 <table
class=
"sq-backend-table">
249 <tr
class=
"sq-backend-table-row">
250 <td
class=
"sq-backend-table-header-header"><?php echo implode(
' ', $links) ?></td>
251 <td
class=
"sq-backend-table-header-header" colspan=
"<?php echo ($write_access === TRUE) ? 5 : 4 ?>" style=
"text-align: right; font-weight: normal"><?php echo $asset_count_tag; ?></span></td>
254 <td
class=
"sq-backend-table-header"><?php echo translate(
'url'); ?></td>
255 <td
class=
"sq-backend-table-header"><?php echo translate(
'remap_url'); ?></td>
256 <td
class=
"sq-backend-table-header"><?php echo translate(
'expires'); ?></td>
257 <td
class=
"sq-backend-table-header"><?php echo translate(
'type'); ?></td>
261 <td
class=
"sq-backend-table-header">
263 label(translate(
'delete_question'), $prefix.
'_select_all');
264 check_box($prefix.
'_select_all',
'1', FALSE,
"check_all(document.main_form, '{$prefix}_delete_remap', this.checked);");
271 <td
class=
"sq-backend-table-header">
272 <?php echo translate(
'never_delete');
275 check_box($prefix.
'never_delete_select_all',
'1', FALSE,
"check_all(document.main_form, '{$prefix}_never_delete_remap', this.checked);");
282 foreach ($remap_urls as $url_info) {
283 if (empty($url_info[
'expires'])) {
284 $expires = translate(
'never');
286 $expires = $GLOBALS[
'SQ_SYSTEM']->datetime(iso8601_ts($url_info[
'expires']));
293 hidden_field($prefix.
'_current_page_remaps['.$url_info[
'url'].
']', $page_num);
297 if (strpos($url_info[
'url'],
'://') !== FALSE) {
298 list($protocol, $url) = explode(
'://', $url_info[
'url']);
299 $url_asset = $GLOBALS[
'SQ_SYSTEM']->am->getAssetFromURL($protocol, $url, TRUE, TRUE);
300 if (!is_null($url_asset)) {
301 $warning .= translate(
'url_currently_in_use', $GLOBALS[
'SQ_SYSTEM']->am->getTypeInfo($url_asset->type(),
'name'), translate(
'asset_format', $url_asset->name, $url_asset->id));
306 <td
class=
"sq-backend-table-cell"><?php echo $url_info[
'url']; ?><br/><span style=
"color: #FF0000;"><b><?php echo $warning; ?></b></span></td>
307 <td
class=
"sq-backend-table-cell"><?php echo $url_info[
'remap_url']; ?></td>
308 <td
class=
"sq-backend-table-cell"><?php echo $expires; ?></td>
309 <td
class=
"sq-backend-table-cell"><?php echo ((
int)$url_info[
'auto_remap'] === 1) ? translate(
'automatic') : (($url_info[
'auto_remap'] === NULL) ? translate(
'unknown') : translate(
'manual')); ?></td>
312 $never_delete_remap = (isset($_POST[$prefix.
'_never_delete_remap']) && array_key_exists($url_info[
'url'],$_POST[$prefix.
'_never_delete_remap'])) || $url_info[
'never_delete'];
314 <td
class=
"sq-backend-table-cell">
316 check_box($prefix.
'_delete_remap['.$url_info[
'url'].
']', 1, FALSE,
'', $never_delete_remap ?
'disabled' :
'');
319 <td
class=
"sq-backend-table-cell">
321 check_box($prefix.
'_never_delete_remap['.$url_info[
'url'].
']', 1, $never_delete_remap);
326 if ((isset($_POST[$prefix.
'_never_delete_remap']) && array_key_exists($url_info[
'url'],$_POST[$prefix.
'_never_delete_remap'])) || $url_info[
'never_delete']) {
328 <td
class=
"sq-backend-table-cell">
329 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/tick.gif" width=
"12" height=
"12" />
334 <td
class=
"sq-backend-table-cell">
335 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/cross.gif" width=
"12" height=
"12" />
348 return $write_access;
367 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
368 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
371 $urls_to_check = (isset($_POST[$prefix.
'_never_delete_remap'])) ? array_keys($_POST[$prefix.
'_never_delete_remap']) : array();
372 $current_page_remaps = array_get_index($_POST, $prefix.
'_current_page_remaps', Array());
373 $urls_in_current_page = array_keys($current_page_remaps);
374 $urls_to_uncheck = array_diff($urls_in_current_page, $urls_to_check);
378 'never_delete' =>
'0',
379 'urls_to_update' => $urls_to_uncheck,
381 $bind_vars_add = Array(
382 'never_delete' =>
'1',
383 'urls_to_update' => $urls_to_check,
386 if (!empty($urls_to_uncheck)) {
389 if (!empty($urls_to_check)) {
393 throw new Exception(
'Unable to delete remaps due to database error: '.$e->getMessage());
397 if (isset($_POST[$prefix.
'_purge_all_remaps']) && $_POST[$prefix.
'_purge_all_remaps']) {
399 $bind_vars = Array(
'never_delete' =>
'0');
402 throw new Exception(
'Unable to delete remaps due to database error: '.$e->getMessage());
406 if (isset($_POST[$prefix.
'_delete_remap'])) {
407 $urls = array_keys($_POST[$prefix.
'_delete_remap']);
408 if (isset($_POST[$prefix.
'_never_delete_remap'])) {
409 foreach ($_POST[$prefix.
'_never_delete_remap'] as $url => $not_deletable) {
410 foreach ($urls as $index => $url_to_delete) {
411 if ($url == $url_to_delete && !$not_deletable == 0) {
412 unset($urls[$index]);
419 $bind_vars = Array(
'urls' => $urls);
422 throw new Exception(
'Unable to delete remaps due to database error: '.$e->getMessage());
426 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
427 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
446 $o->
note(translate(
'url_remap_explanation'));
450 text_box($prefix.
'_add_remap_old_url',
'', 50);
454 text_box($prefix.
'_add_remap_new_url',
'', 50);
457 $o->
openField(translate(
'never_delete'));
458 check_box($prefix.
'_add_never_delete_option');
462 text_box($prefix.
'_add_remap_expires_days',
'', 5);
463 label(translate(
'days'), $prefix.
'_add_remap_expires_days');
467 file_upload($prefix.
'_add_remap_csv');
470 $o->
note(translate(
'csv_upload_instructions'));
471 $o->
note(translate(
'csv_upload_instructions_example_1').
'<br />'.translate(
'csv_upload_instructions_example_2').
'<br />'.translate(
'csv_upload_instructions_example_3'));
474 $o->
openField(translate(
'csv_upload_header'));
475 check_box($prefix.
'_csv_header');
476 $o->
note(translate(
'csv_upload_header_example'));
497 $file_info = get_file_upload_info($prefix.
'_add_remap_csv');
498 if (!empty($file_info)) {
499 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
500 $csv =
new CSV($file_info[
'tmp_name']);
502 if (isset($_POST[$prefix.
'_csv_header'])) {
505 $csv->import($csv_start);
507 foreach ($csv->values as $line_value) {
508 $old_url = trim($line_value[0]);
509 $new_url = trim($line_value[1]);
510 if (empty($old_url) || empty($new_url)) {
514 $expires = array_key_exists(2, $line_value) ? trim($line_value[2]) :
'';
516 if (empty($expires)) {
519 $int_expires = iso8601_ts($expires);
525 if (!isset($line_value[3]) || trim($line_value[3]) ==
'') {
526 $never_delete = $asset->
attr(
'never_delete_remap_default');
528 $never_delete = trim($line_value[3]);
531 $asset->
addRemapURL($old_url, $new_url, $int_expires, $never_delete, FALSE);
536 if (!isset($_POST[$prefix.
'_add_remap_old_url']) || !isset($_POST[$prefix.
'_add_remap_new_url'])) {
539 $old_url = trim($_POST[$prefix.
'_add_remap_old_url']);
540 $new_url = trim($_POST[$prefix.
'_add_remap_new_url']);
542 if (isset($_POST[$prefix.
'_add_never_delete_option'])) {
543 $never_delete = trim($_POST[$prefix.
'_add_never_delete_option']);
545 $never_delete =
'0' ;
548 if (empty($old_url) || empty($new_url)) {
552 if (isset($_POST[$prefix.
'_add_remap_expires_days'])) {
553 $expires_days = (int)$_POST[$prefix.
'_add_remap_expires_days'];
554 if ($expires_days > 0) {
555 $expires = strtotime(
'+ '.$expires_days.
' days');
559 $asset->
addRemapURL($old_url, $new_url, $expires, $never_delete, FALSE);
578 $link_to_404 = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'asset', FALSE,
'404');
581 if (!$write_access) {
582 if (!empty($link_to_404)) {
583 echo get_asset_tag_line($link_to_404[
'minorid']);
585 echo
'<em>'.translate(
'none').
'</em>';
588 asset_finder($prefix.
'_404asset', (!empty($link_to_404)) ? $link_to_404[
'minorid'] :
'');
591 return $write_access;
608 if (!isset($_POST[$prefix.
'_404asset'][
'assetid'])) {
611 $new_404_asset = $_POST[$prefix.
'_404asset'][
'assetid'];
614 $root_link = $GLOBALS[
'SQ_SYSTEM']->am->getLink($asset->id, SQ_LINK_NOTICE,
'', FALSE,
'404');
617 if (!empty($root_link) && $root_link[
'minorid'] == $new_404_asset) {
623 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
624 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
627 if (!empty($root_link) && !$GLOBALS[
'SQ_SYSTEM']->am->deleteAssetLink($root_link[
'linkid'])) {
629 }
else if ($new_404_asset) {
630 $root = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($new_404_asset);
631 if (!is_null($root)) {
632 if (!$asset->
createLink($root, SQ_LINK_NOTICE,
'404')) {
634 trigger_localised_error(
'CORE0027', E_USER_WARNING, $root->name, $root->id);
640 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
642 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
645 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
664 $remap_upon_webpath_change = $asset->
attr(
'remap_upon_webpath_change');
667 $o->
openField(translate(
'remap_manager_automatically_add_remaps_question'));
671 check_box($prefix.
'_remap_upon_webpath_change', TRUE, $remap_upon_webpath_change);
674 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $remap_upon_webpath_change ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
678 $o->
note(translate(
'remap_manager_auto_add_remaps_note'));
682 return $write_access;
699 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
701 $remap_upon_webpath_change = isset($_POST[$prefix.
'_remap_upon_webpath_change']);
702 $asset->
setAttrValue(
'remap_upon_webpath_change', $remap_upon_webpath_change);
722 $never_delete_remap_default = $asset->
attr(
'never_delete_remap_default');
725 $o->
openField(translate(
'remap_manager_never_delete_remap_default_question'));
729 check_box($prefix.
'_never_delete_remap_default', TRUE, $never_delete_remap_default);
732 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $never_delete_remap_default ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
736 $o->
note(translate(
'remap_manager_never_delete_remap_default_note'));
740 return $write_access;
757 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
759 $never_delete_remap_default = isset($_POST[$prefix.
'_never_delete_remap_default']);
760 $asset->
setAttrValue(
'never_delete_remap_default', $never_delete_remap_default);
780 if ($write_access === TRUE) {
783 normal_button($prefix.
'_export_to_csv', translate(
'download_file'),
'this.form.'.$prefix.
'_download_file.value = 1; this.form.submit(); SQ_FORM_SUBMITTED = false; this.form.'.$prefix.
'_download_file.value = 0; return true;');
784 hidden_field($prefix.
'_download_file', 0);
809 $download_file = (int)array_get_index($_POST, $prefix.
'_download_file', 0);
811 if ($download_file === 1) {
813 $url_filter = array_get_index($_POST, $prefix.
'_URL_FILTER',
'');
814 $remap_url_filter = array_get_index($_POST, $prefix.
'_REMAP_URL_FILTER',
'');
819 $this->num_per_page = 10000;
821 $remap_urls = $this->_fetchRemapUrls($url_filter, $remap_url_filter, $page, FALSE);
823 if (empty($remap_urls)) {
825 trigger_localised_error(
'CORE0287', E_USER_WARNING);
828 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
831 $csv->setFilename(
'remap_entries.csv');
832 $csv->setDeliminator(
',');
834 $headers = Array(
'Original URL',
'Remapped URL',
'Expiry',
'Never Delete',
'Automatic');
835 $csv->setFieldHeaders($headers);
837 $header_printed = FALSE;
838 while (!empty($remap_urls)) {
840 foreach ($remap_urls as $remap_url) {
843 $remap_url[
'remap_url'],
844 $remap_url[
'expires'],
846 if ($remap_url[
'never_delete'] !== NULL) {
847 $value_row[] = (boolean)($remap_url[
'never_delete']) ? 1 : 0;
851 if ($remap_url[
'auto_remap'] !== NULL) {
852 $value_row[] = (boolean)($remap_url[
'auto_remap']) ? 1 : 0;
856 $values[] = $value_row;
859 $csv->setValues($values);
861 if (!$header_printed) {
863 $header_printed = TRUE;
865 $csv->exportValues(FALSE);
870 $remap_urls = $this->_fetchRemapUrls($url_filter, $remap_url_filter, $page, FALSE);
897 $preserve_url_parameters = $asset->
attr(
'preserve_url_parameters');
903 check_box($prefix.
'_preserve_url_parameters', TRUE, $preserve_url_parameters);
906 <img src=
"<?php echo sq_web_path('lib'); ?>/web/images/<?php echo $preserve_url_parameters ? 'tick' : 'cross'; ?>.gif" width=
"15" height=
"15" />
911 return $write_access;
928 if (!$asset->
writeAccess(
'attributes'))
return FALSE;
930 $preserve_url_parameters = isset($_POST[$prefix.
'_preserve_url_parameters']);
931 $asset->
setAttrValue(
'preserve_url_parameters', $preserve_url_parameters);