18 require_once SQ_CORE_PACKAGE_PATH.
'/report/report_edit_fns.inc';
41 parent::__construct();
42 $this->static_screens[
'details'][
'force_unlock'] =
'0';
60 require_once SQ_FUDGE_PATH.
'/general/text.inc';
61 require_once SQ_FUDGE_PATH.
'/general/file_system.inc';
62 $owner = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($job->_running_vars[
'assetid'],
'report_links');
64 if (!isset($job->_running_vars[
'results'])) {
65 $list_content_types = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($this->
getRootAssetid($owner),
'content_type', FALSE);
66 $list_page_redirects = $GLOBALS[
'SQ_SYSTEM']->am->getChildren($this->
getRootAssetid($owner),
'page_redirect', FALSE);
67 $job->_running_vars[
'todo'] = $list_content_types + $list_page_redirects;
68 $job->_running_vars[
'done'] = Array();
69 $job->_running_vars[
'results'] = Array();
71 if (!is_dir($owner->data_path)) {
72 if (!create_directory($owner->data_path)) {
73 trigger_localised_error(
'CMS0005', E_USER_WARNING);
77 $temp_file = fopen($owner->data_path.
'/report.tmp',
'w');
78 if ($temp_file === FALSE) {
79 trigger_localised_error(
'RPRT0000', E_USER_WARNING);
82 fwrite($temp_file,
'<?xml version="1.0" encoding="'.SQ_CONF_DEFAULT_CHARACTER_SET.
'"?>'.
"\n");
83 fwrite($temp_file,
"<links>\n");
85 $temp_file = fopen($owner->data_path.
'/report.tmp',
'a');
86 if ($temp_file === FALSE) {
87 trigger_localised_error(
'RPRT0000', E_USER_WARNING);
91 if (!empty($job->_running_vars[
'todo'])) {
92 $array_keys = array_keys($job->_running_vars[
'todo']);
93 $assetid = array_shift($array_keys);
94 $asset_type = $job->_running_vars[
'todo'][$assetid][0][
'type_code'];
95 unset($job->_running_vars[
'todo'][$assetid]);
96 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
98 if ($asset_type ==
'content_type_nest_content') {
99 $step_data[
'message'] = translate(
'cms_report_links_skipping_nest_content', $assetid);
102 else if (isset($asset->status) && !in_array($asset->status,$owner->attr(
'statuses'))) {
103 $step_data[
'message'] = translate(
'cms_report_links_skipping_unwanted_status', $assetid);
106 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid, $asset_type);
108 if (!is_null($asset)) {
111 $step_data[
'message'] = translate(
'cms_report_links_generating');
114 $match = $asset->attr(
'redirect_url');
115 $confirm_internal = $asset->getRedirectAsset();
116 $validated_results = FALSE;
118 if (!is_null($confirm_internal)) {
120 if ($GLOBALS[
'SQ_SYSTEM']->am->assetExists($confirm_internal->id)) {
124 $link_type =
'internal';
125 $validated_results = Array(
'valid' =>
'1',
'description' =>
'');
126 $match =
'./?a='.$confirm_internal->id;
128 $link_type =
'internal';
129 $validated_results = Array(
'valid' =>
'1',
'description' => translate(
'cms_report_links_asset_not_exist', $confirm_internal->id));
130 $match =
'./?a='.$confirm_internal->id;
134 preg_match(
'|^\./\?a=([0-9]+)#?([^$]*)?|',$match, $results);
136 if (!empty($results)) {
137 $link_type =
'internal';
140 if (strpos(strtolower($match),
'mailto') === 0) {
141 $link_type =
'mailto';
142 $match = preg_replace(
'/mailto:/i',
'',$match);
143 list($match) = explode(
'?',$match);
144 $match = trim($match);
145 $match = ltrim($match,
'/');
148 $link_type =
'external';
155 if ($validated_results !== FALSE) {
158 'type' => $link_type,
163 if (!empty($content)) {
164 $content =
"\t".
'<asset assetid="'.$asset->id.
'" name="'.htmlSpecialChars($asset->name).
'" short_name="'.htmlSpecialChars($asset->short_name).
'" type_code="'.$asset->type().
'" status="'.$asset->status.
'">'.
"\n".$content.
"\t".
'</asset>'.
"\n";
165 fwrite($temp_file, $content);
169 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
173 $step_data[
'message'] = translate(
'cms_report_links_generating');
176 $wysiwyg_html = $asset->attr(
'html');
178 $master_matches = Array();
179 preg_match_all(
'%(href|src)=[\'"]([^\'\s"]*)%', $wysiwyg_html, $master_matches);
180 $matches = $master_matches[2];
181 foreach ($matches as $match) {
183 $keywords = retrieve_keywords_replacements($match);
184 if (count($keywords) == 1 && $match ==
'%'.$keywords[0].
'%') {
188 if (!$match)
continue;
190 $link_description =
'';
193 preg_match(
'|^\./\?a=([0-9]+)#?([^$]*)?|',$match, $results);
196 $validated_results = FALSE;
197 if (!empty($results)) {
198 $link_type =
'internal';
201 if (strpos(strtolower($match),
'mailto') === 0) {
202 $link_type =
'mailto';
203 $match = preg_replace(
'/mailto:/i',
'',$match);
204 list($match) = explode(
'?',$match);
205 $match = trim($match);
208 $link_type =
'external';
213 if ($validated_results === FALSE)
continue;
216 'type' => $link_type,
222 if (!empty($content)) {
223 $content =
"\t".
'<asset assetid="'.$asset->id.
'" name="'.htmlSpecialChars($asset->name).
'" short_name="'.htmlSpecialChars($asset->short_name).
'" type_code="'.$asset->type().
'" status="'.$asset->status.
'">'.
"\n".$content.
"\t".
'</asset>'.
"\n";
224 fwrite($temp_file, $content);
227 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
231 $step_data[
'message'] = translate(
'cms_report_links_skipping_asset', $assetid);
232 $job->_addError(translate(
'cms_report_links_asset_not_exist', $assetid));
238 $job->_running_vars[
'done'][] = $assetid;
241 if (empty($job->_running_vars[
'todo'])) {
242 $step_data[
'percent_done'] = 100;
243 $step_data[
'complete'] = TRUE;
244 $job->_running_vars[
'complete'] = TRUE;
246 $GLOBALS[
'SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
247 $user = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($job->_running_vars[
'userid']);
249 $owner->setAttrValue(
'generated_date', $job->_running_vars[
'generated_date']);
250 $owner->setAttrValue(
'generated_user', $user->name.
' (#'.$user->id.
')');
252 $owner->setAttrValue(
'report_info',
'');
253 $owner->saveAttributes();
254 $GLOBALS[
'SQ_SYSTEM']->restoreRunLevel();
257 fwrite($temp_file,
'</links>');
258 if (!copy($owner->data_path.
'/report.tmp', $owner->data_path.
'/report.xml')) {
259 trigger_localised_error(
'RPRT0001', E_USER_WARNING);
262 if (!unlink($owner->data_path.
'/report.tmp')) {
263 trigger_localised_error(
'RPRT0002', E_USER_WARNING);
266 if ($owner->attr(
'report_broken_links')) {
267 $owner->reportBrokenLink();
271 $total = count($job->_running_vars[
'todo']) + count($job->_running_vars[
'done']);
272 $step_data[
'percent_done'] = (count($job->_running_vars[
'done']) / $total) * 100;
273 $step_data[
'complete'] = FALSE;
294 $content .=
"\t\t".
'<link type="'.$link_info[
'type'].
'" valid="'.$results[
'valid'].
'">'.
"\n";
295 $content .=
"\t\t\t".
'<html><![CDATA['.$link_info[
'url'].
']]></html>'.
"\n";
296 $content .=
"\t\t\t".
'<description><![CDATA['.$results[
'description'].
']]></description>'.
"\n";
297 $content .=
"\t\t".
'</link>'.
"\n";
323 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
326 if (is_null($asset)) {
328 $description = translate(
'cms_report_links_point_invalid_assetid');
330 }
else if ($GLOBALS[
'SQ_SYSTEM']->am->assetInTrash($assetid, TRUE)) {
332 $description = translate(
'cms_report_links_point_to_trash');
334 }
else if (!empty($link[2])) {
336 $editable_contents = $GLOBALS[
'SQ_SYSTEM']->am->getEditableContents($assetid);
337 if (is_array($editable_contents)) {
338 $contents = $editable_contents;
341 $anchorExists = FALSE;
344 if (preg_match(
'/\/_admin|\/_edit/', $link[2], $matches)) {
345 $anchorExists = TRUE;
346 }
else if (preg_match(
'/^\?(.+=.*)*/', $link[2], $matches)) {
347 $anchorExists = TRUE;
351 foreach ($contents as $content) {
352 if (preg_match(
'/<a\s+(name|id)="#?'.$link[2].
'"(\s+(name|id)="#?'.$link[2].
'")?(\s+href="[^"]+")?>/', $content, $matches)) {
353 $anchorExists = TRUE;
359 if (!$anchorExists) {
361 $description = translate(
'cms_report_links_anchor_not_exist', $link[2]);
370 if (!is_null($asset)) {
371 $GLOBALS[
'SQ_SYSTEM']->am->forgetAsset($asset);
374 return Array(
'valid' => $valid,
'description' => $description);
390 if (substr($url, 0, 1) ==
'#')
return FALSE;
394 if (strcmp(substr($url, 0, 3),
'./?') == 0 || substr($url, 0, 1) ==
'?') {
395 return Array(
'valid' => 1,
'description' =>
'');
398 $validated_results = Array(
403 $url_parts = @parse_url($url);
405 if (empty($url_parts[
'scheme'])) {
406 $validated_results[
'description'] = translate(
'cms_report_links_missing_protocol');
407 $validated_results[
'valid'] =
'0';
408 }
else if (empty($url_parts[
'host'])) {
409 $validated_results[
'description'] = translate(
'cms_report_links_missing_hostname');
410 $validated_results[
'valid'] =
'0';
411 }
else if ($url_parts[
'scheme'] !=
'http') {
412 $validated_results[
'description'] = translate(
'cms_report_links_cannot_test_protocol');
413 $validated_results[
'valid'] =
'1';
415 if (empty($url_parts[
'path'])) {
416 $url_parts[
'path'] =
'/';
418 if (empty($url_parts[
'port'])) {
419 $url_parts[
'port'] =
'80';
422 $url_path = $url_parts[
'path'];
423 if (!empty($url_parts[
'query'])) {
424 $url_path .=
'?'.$url_parts[
'query'];
427 require_once(SQ_INCLUDE_PATH.
'/general_occasional.inc');
428 $socket = openSocketConnection($url_parts, $errno, $errstr, TRUE, 15);
429 if (!SQ_PA_ENABLED || !$socket) {
431 $socket = @fsockopen($url_parts[
'host'], $url_parts[
'port'], $errno, $errstr, 15);
433 fwrite ($socket,
'HEAD '.$url_path.
" HTTP/1.0\r\nHost: ".$url_parts[
'host'].
"\r\n\r\n");
438 $validated_results[
'description'] = translate(
'cms_report_links_invalid_url');
439 $validated_results[
'valid'] =
'0';
441 stream_set_timeout($socket, 5);
442 $response = fgets($socket);
443 $headers = fgets($socket);
444 $response = trim($response);
445 $headers = trim($headers);
446 $finished = (empty($headers)) ? TRUE : FALSE;
448 $next_header = fgets($socket);
449 $next_header = trim($next_header);
450 if (empty($next_header)) {
453 $headers .= $next_header.
"\r\n";
456 $info = stream_get_meta_data($socket);
458 if (preg_match(
'|405 method not allowed|i', $response) || preg_match(
'|404 not found|i', $response)) {
460 $newsocket = fsockopen($url_parts[
'host'], $url_parts[
'port'], $errno, $errstr, 15);
462 fwrite($newsocket,
'GET '.$url_path.
" HTTP/1.0\r\nHost: ".$url_parts[
'host'].
"\r\n\r\n");
465 stream_set_timeout($newsocket, 5);
466 $newresponse = fgets($newsocket);
467 $newheaders = fgets($newsocket);
468 $newresponse = trim($newresponse);
469 $newheaders = trim($newheaders);
470 $finished = (empty($newheaders)) ? TRUE : FALSE;
472 $next_header = fgets($newsocket);
473 $next_header = trim($next_header);
474 if (empty($next_header)) {
477 $newheaders .= $next_header.
"\r\n";
480 $newinfo = stream_get_meta_data($newsocket);
482 $validated_results = $this->
_checkResponse($newheaders, $newresponse, $newinfo);
486 $validated_results = $this->
_checkResponse($headers, $response, $info);
494 return $validated_results;
511 if (preg_match(
'|200 ok|i', $response)) {
514 }
else if (preg_match(
'|302 found|i', $response)) {
517 }
else if (preg_match(
'|304 not modified|i', $response)) {
520 }
else if (preg_match(
'|404 not found|i', $response)) {
521 $description = translate(
'cms_report_links_404');
523 }
else if (preg_match(
'|407 proxy authentication required|i', $response)) {
524 $description = translate(
'cms_report_links_407');
526 }
else if (preg_match(
'|301 moved|i', $response)) {
528 preg_match(
'|Location:\s*(.+)\r|i', $headers, $matches);
529 if (isset($matches[1])) {
530 $description = translate(
'cms_report_links_301_with_new_link', $matches[1]);
532 $description = translate(
'cms_report_links_301');
534 }
else if (preg_match(
'|302 moved|i', $response)) {
537 preg_match(
'|Location:\s*(.+)\r|i', $headers, $matches);
538 if (isset($matches[1])) {
539 $description = translate(
'cms_report_links_302_with_new_link', $matches[1]);
541 $description = translate(
'cms_report_links_302');
544 }
else if (preg_match(
'|202 accepted|i', $response)) {
547 }
else if (preg_match(
'|301 moved permanently|i', $response)) {
549 preg_match(
'|Location:\s*(.+)\r|i', $headers, $matches);
550 if (isset($matches[1])) {
551 $description = translate(
'cms_report_links_301_with_new_link', $matches[1]);
553 $description = translate(
'cms_report_links_301');
555 }
else if (preg_match(
'|301 permanent redirect|i', $response)) {
557 preg_match(
'|Location:\s*(.+)\r|i', $headers, $matches);
558 if (isset($matches[1])) {
559 $description = translate(
'cms_report_links_301_with_new_link', $matches[1]);
561 $description = translate(
'cms_report_links_301');
563 }
else if (preg_match(
'|302 object moved|i', $response)) {
566 preg_match(
'|Location:\s*(.+)\r|i', $headers, $matches);
567 if (isset($matches[1])) {
568 $description = translate(
'cms_report_links_302_with_new_link', $matches[1]);
570 $description = translate(
'cms_report_links_302');
572 }
else if (preg_match(
'|307 temporary redirect|i', $response)) {
574 preg_match(
'|Location:\s*(.+)\r|i', $headers, $matches);
575 if (isset($matches[1])) {
576 $description = translate(
'cms_report_links_307_with_new_link', $matches[1]);
578 $description = translate(
'cms_report_links_307');
580 }
else if (preg_match(
'|400 bad request|i', $response)) {
581 $description = translate(
'cms_report_links_400');
583 }
else if (preg_match(
'|401 access denied|i', $response)) {
584 $description = translate(
'cms_report_links_401');
586 }
else if (preg_match(
'|401 unauthorized|i', $response)) {
587 $description = translate(
'cms_report_links_401');
589 }
else if (preg_match(
'|403 forbidden|i', $response)) {
590 $description = translate(
'cms_report_links_403');
592 }
else if (preg_match(
'|403 forbidden|i', $response)) {
593 $description = translate(
'cms_report_links_403');
595 }
else if (preg_match(
'|404 page not available|i', $response)) {
596 $description = translate(
'cms_report_links_404');
598 }
else if (preg_match(
'|406 client browser does not|i', $response)) {
599 $description = translate(
'cms_report_links_406');
601 }
else if (preg_match(
'|408 request timed out|i', $response)) {
602 $description = translate(
'cms_report_links_408');
604 }
else if (preg_match(
'|412 precondition failed|i', $response)) {
605 $description = translate(
'cms_report_links_412');
607 }
else if ($info[
'timed_out']) {
608 $description = translate(
'cms_report_links_server_timeout');
612 $response = preg_replace(
'/[^(\x20-\x7F)]*/',
'',$response);
613 $description = translate(
'cms_report_links_unknown_response', $response);
618 $validated_results[
'valid'] = $valid;
619 $validated_results[
'description'] = $description;
622 return $validated_results;
637 require_once SQ_FUDGE_PATH.
'/general/www.inc';
638 if (!valid_email($mailto)) {
639 $description = translate(
'cms_report_links_invalid_email');
646 return Array(
'valid' => $valid,
'description' => $description);
663 $reported_links = $asset->parseReport();
664 $display_options = $asset->attr(
'display_options');
668 if (SQ_IN_BACKEND || SQ_IN_LIMBO) {
669 echo translate(
'cms_report_links_current');
673 if ($display_options[
'internal_section'] == TRUE) {
674 $o->openSection(
'Internal Links');
676 if (empty($reported_links[
'internal'])) {
677 echo
'No internal links were found';
680 <table
class=
"sq-backend-table" style=
"border: 1px solid #DDDDDD;" border=
"0">
682 <th colspan=
"3" class=
"sq-backend-table-header" style=
"width: 226px;"><?php echo translate(
'found_in') ?></th>
683 <th colspan=
"3" class=
"sq-backend-table-header" style=
"width: 226px;"><?php echo translate(
'linking_to') ?></th>
684 <th
class=
"sq-backend-table-header"><?php echo translate(
'comments'); ?></th>
687 foreach ($reported_links[
'internal'] as $assetid => $links) {
688 foreach ($links as $link) {
690 $from_name = (strlen($from_info[
'name']) < 40) ? $from_info[
'name'] : ellipsisize($from_info[
'name'], 40);
694 $to = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($link[
'data'],
'', TRUE);
698 $to_string = translate(
'unknown_asset_id', $link[
'data']);
703 $to_type = $to->type();
704 $to_name = (strlen($to->name) < 40) ? $to->name : ellipsisize($to->name, 40);
705 $to_string =
'<span title="'.$to->name.
'"> [#'.$to->id.
'] '.$to_name.
'</span>';
706 $to_bg = get_asset_status_icon($to->status);
707 $to_status = get_status_description($to->status);
712 <!-- ASSET STATUS -->
713 <td
class=
"sq-backend-table-cell" style=
"width: 120px; padding-top: 7px; padding-right: 0px;">
714 <?php echo $from_info[
'bg']; ?> <?php echo $from_info[
'status']; ?>
718 <td
class=
"sq-backend-table-cell" style=
"width: 16px; padding-right: 0px; padding-left: 0px;">
720 if (!empty($from_info[
'type'])) {
722 <span title=
"<?php echo ucwords(str_replace('_', ' ', $from_info['type'])); ?>">
723 <?php echo get_asset_type_icon($from_info[
'type']); ?>
731 <td
class=
"sq-backend-table-cell" style=
"width: 260px; padding-right: 1px; padding-top:6px; text-align: left;">
732 <a href=
"<?php echo $from_info['backend_url']; ?>" title=
"<?php echo translate('edit_this_asset'); ?>">[#<?php echo $from_info[
'assetid']; ?>] <?php echo $from_name ?></a>
735 <!-- LINKED STATUS -->
736 <td
class=
"sq-backend-table-cell" style=
"width: 16px; padding-top: 7px; padding-right: 0px;">
737 <?php echo $to_bg; ?><?php echo $to_status; ?>
741 <td
class=
"sq-backend-table-cell" style=
"width: 16px; padding-right: 0px; padding-left: 0px;">
743 if (!empty($to_type)) {
744 echo get_asset_type_icon($to_type);
750 <td
class=
"sq-backend-table-cell" style=
"width: 190px; padding-right: 1px; padding-top:6px; text-align: left;">
751 <?php echo $to_string; ?>
755 <td
class=
"sq-backend-table-cell">
757 if (!$link[
'valid']) {
758 echo
'<span style="color: #007EFA;"><b>';
760 echo $link[
'description'];
761 if (!$link[
'valid']) echo
'</b></span>';
776 if ($display_options[
'external_section'] == TRUE) {
777 $o->openSection(translate(
'external_links'));
779 if (empty($reported_links[
'external'])) {
780 echo translate(
'cms_report_links_no_external_links');
782 $ast_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo(array_keys($reported_links[
'external']));
784 <table
class=
"sq-backend-table">
786 <th colspan=
"3" class=
"sq-backend-table-header" style=
"width: 226px;"><?php echo translate(
'found_in'); ?></th>
787 <th
class=
"sq-backend-table-header" style=
"width: 274px;"><?php echo translate(
'url'); ?></th>
788 <th
class=
"sq-backend-table-header"><?php echo translate(
'comments'); ?></th>
791 foreach ($reported_links[
'external'] as $assetid => $links) {
792 foreach ($links as $link) {
794 $from_name = (strlen($from_info[
'name']) < 40) ? $from_info[
'name'] : ellipsisize($from_info[
'name'], 40);
796 $name = (strlen($link[
'data']) < 50) ? $link[
'data'] : ellipsisize($link[
'data'], 50);
797 $to_string =
'<a href="'.$link[
'data'].
'" target="_blank" title="'.$link[
'data'].
'">'.$name.
'</a>';
800 <!-- ASSET STATUS -->
801 <td
class=
"sq-backend-table-cell" style=
"width: 120px; padding-top: 7px; padding-right: 0px;">
802 <?php echo $from_info[
'bg']; ?> <?php echo $from_info[
'status']; ?>
806 <td
class=
"sq-backend-table-cell" style=
"width: 16px; padding-right: 0px; padding-left: 0px;">
808 if (!empty($from_info[
'type'])) {
810 <span title=
"<?php echo ucwords(str_replace('_', ' ', $from_info['type'])); ?>">
811 <?php echo get_asset_type_icon($from_info[
'type']); ?>
819 <td
class=
"sq-backend-table-cell" style=
"width: 190px; padding-right: 1px; padding-top:6px; text-align: left;">
820 <a href=
"<?php echo $from_info['backend_url']; ?>" title=
"<?php echo translate('edit_this_asset') ?>">[#<?php echo (
int) $from_info[
'assetid']; ?>] <?php echo $from_name; ?></a>
824 <td
class=
"sq-backend-table-cell" style=
"width: 226px; padding-right: 1px; padding-top:6px; text-align:left;">
825 <?php echo $to_string; ?>
829 <td
class=
"sq-backend-table-cell">
831 if (!$link[
'valid']) {
832 echo
'<span style="color: #007EFA;"><b>';
834 echo $link[
'description'];
835 if (!$link[
'valid']) echo
'</b></span>';
850 if ($display_options[
'email_section'] == TRUE) {
851 $o->openSection(translate(
'cms_report_links_email_links'));
853 if (empty($reported_links[
'mailto'])) {
854 echo translate(
'cms_report_links_no_email_links');
857 <table
class=
"sq-backend-table">
859 <th colspan=
"3" class=
"sq-backend-table-header" style=
"width: 226px;"><?php echo translate(
'found_in'); ?></th>
860 <th
class=
"sq-backend-table-header" style=
"width: 274px;"><?php echo translate(
'email'); ?></th>
861 <th
class=
"sq-backend-table-header"><?php echo translate(
'comments'); ?></th>
864 foreach ($reported_links[
'mailto'] as $assetid => $links) {
865 foreach ($links as $link) {
867 $to_string = $link[
'data'];
868 $name = (strlen($from_info[
'name']) < 40) ? $from_info[
'name'] : ellipsisize($from_info[
'name'], 40);
872 <!-- ASSET STATUS -->
873 <td
class=
"sq-backend-table-cell" style=
"width: 120px; padding-top: 7px; padding-right: 0px;">
874 <?php echo $from_info[
'bg']; ?> <?php echo $from_info[
'status']; ?>
878 <td
class=
"sq-backend-table-cell" style=
"width: 16px; padding-right: 0px; padding-left: 0px;">
880 if (!empty($from_info[
'type'])) {
882 <span title=
"<?php echo ucwords(str_replace('_', ' ', $from_info['type'])); ?>">
883 <?php echo get_asset_type_icon($from_info[
'type']); ?>
891 <td
class=
"sq-backend-table-cell" style=
"width: 190px; padding-right: 1px; padding-top:6px; text-align: left;">
892 <a href=
"<?php echo $from_info['backend_url']; ?>" title=
"<?php echo translate('edit_this_asset'); ?>">[#<?php echo (
int) $from_info[
'assetid']; ?>] <?php echo $name; ?></a>
896 <td
class=
"sq-backend-table-cell" style=
"width: 226px; padding-right: 1px; padding-top:6px;">
897 <?php echo $to_string; ?>
901 <td
class=
"sq-backend-table-cell">
903 if (!$link[
'valid']) {
904 echo
'<span style="color: #007EFA;"><b>';
906 echo $link[
'description'];
907 if (!$link[
'valid']) echo
'</b></span>';
938 $asset = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($assetid,
'', TRUE);
940 if (is_null($asset)) {
942 $asset_name =
'Unknown asset #'.$assetid;
943 $asset_short_name =
'Unknown asset #'.$assetid;
944 $asset_string =
'Unknown asset #'.$assetid;
945 $asset_bg =
'FFFFFF';
947 $asset_status_code = 0;
949 $asset_preview_url =
'';
951 $dependants = $GLOBALS[
'SQ_SYSTEM']->am->getDependantParents($asset->id);
953 $first_dep = array_pop($dependants);
954 if (!empty($first_dep)) {
955 $parent = $GLOBALS[
'SQ_SYSTEM']->am->getAsset($first_dep);
959 if (!is_null($parent)) {
960 $asset_type = $parent->type();
961 $asset_name = $parent->name;
962 $asset_short_name = $parent->short_name;
963 $asset_bg = get_asset_status_icon($parent->status);
964 $asset_status = get_status_description($parent->status);
965 $asset_status_code = $parent->status;
966 $assetid = $parent->id;
967 $asset_url = $parent->getBackendHref();
968 $asset_preview_url = $parent->getURL();
970 $asset_type = $asset->type();
971 $asset_name = $asset->name;
972 $asset_short_name = $asset->short_name;
973 $asset_bg = get_asset_status_icon($asset->status);
974 $asset_status = get_status_description($asset->status);
975 $asset_status_code = $asset->status;
976 $asset_url = $asset->getBackendHref();
977 $asset_preview_url = $asset->getURL();
980 include_once SQ_FUDGE_PATH.
'/general/general.inc';
981 $asset_string = ellipsisize($asset_name, 40);
984 <a href="'.$asset_preview_url.
'" target="_blank" title="'.$asset_name.
'">'.$asset_string.
'</a>';
988 'assetid' => $assetid,
989 'name' => $asset_name,
990 'short_name' => $asset_short_name,
991 'type' => $asset_type,
992 'type_code' => $asset_type,
993 'string' => $asset_string,
995 'status' => $asset_status,
996 'status_code' => $asset_status_code,
997 'backend_url' => $asset_url,
1015 $write_access = $asset->writeAccess(
'attributes');
1016 $tick = sq_web_path(
'lib').
'/web/images/tick.gif';
1017 $cross = sq_web_path(
'lib').
'/web/images/cross.gif';
1018 $current_settings = $asset->attr(
'display_options');
1021 <script type=
"text/javascript">
1022 var prefix =
'<?php echo $prefix; ?>';
1025 function change_section(section, obj) {
1026 var start = prefix +
'_' + section +
'_';
1027 document.getElementById(start +
'working').disabled = obj.checked ?
false :
true;
1028 document.getElementById(start +
'broken').disabled = obj.checked ?
false :
true;
1032 <table
class=
"sq-backend-table" style=
"width: 300px;">
1034 <th
class=
"sq-backend-table-header" colspan=
"2"><?php echo translate(
'cms_report_links_internal_links'); ?></th>
1037 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_section',
'Internal'); ?></td>
1038 <td
class=
"sq-backend-table-cell">
1040 $value = $current_settings[
'internal_section'];
1041 if ($write_access) {
1042 check_box($prefix.
'_internal_section',
'1', $value,
'change_section("internal", this)');
1045 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1052 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_broken'); ?></td>
1053 <td
class=
"sq-backend-table-cell">
1055 $value = $current_settings[
'internal_broken'];
1056 if ($write_access) {
1057 check_box($prefix.
'_internal_broken',
'1', $value,
'', $current_settings[
'internal_section'] == FALSE ?
'disabled' :
'');
1060 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1067 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_working'); ?></td>
1068 <td
class=
"sq-backend-table-cell">
1070 $value = $current_settings[
'internal_working'];
1071 if ($write_access) {
1072 check_box($prefix.
'_internal_working',
'1', $value,
'', $current_settings[
'internal_section'] == FALSE ?
'disabled' :
'');
1075 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1082 <th
class=
"sq-backend-table-header" colspan=
"2"><?php echo translate(
'cms_report_links_external_links'); ?></th>
1085 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_section',
'External'); ?></td>
1086 <td
class=
"sq-backend-table-cell">
1088 $value = $current_settings[
'external_section'];
1089 if ($write_access) {
1090 check_box($prefix.
'_external_section',
'1', $value,
'change_section("external", this)');
1093 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1100 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_broken'); ?></td>
1101 <td
class=
"sq-backend-table-cell">
1103 $value = $current_settings[
'external_broken'];
1104 if ($write_access) {
1105 check_box($prefix.
'_external_broken',
'1', $value,
'', $current_settings[
'external_section'] == FALSE ?
'disabled' :
'');
1108 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1115 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_working'); ?></td>
1116 <td
class=
"sq-backend-table-cell">
1118 $value = $current_settings[
'external_working'];
1119 if ($write_access) {
1120 check_box($prefix.
'_external_working',
'1', $value,
'', $current_settings[
'external_section'] == FALSE ?
'disabled' :
'');
1123 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1130 <th
class=
"sq-backend-table-header" colspan=
"2"><?php echo translate(
'cms_report_links_email_links'); ?></th>
1133 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_section',
'Email'); ?></td>
1134 <td
class=
"sq-backend-table-cell">
1136 $value = $current_settings[
'email_section'];
1137 if ($write_access) {
1138 check_box($prefix.
'_email_section',
'1', $value,
'change_section("email", this)');
1141 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1148 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_broken'); ?></td>
1149 <td
class=
"sq-backend-table-cell">
1151 $value = $current_settings[
'email_broken'];
1152 if ($write_access) {
1153 check_box($prefix.
'_email_broken',
'1', $value,
'', $current_settings[
'email_section'] == FALSE ?
'disabled' :
'');
1156 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1163 <td
class=
"sq-backend-table-cell" style=
"padding-left: 30px;"><?php echo translate(
'cms_report_links_display_working'); ?></td>
1164 <td
class=
"sq-backend-table-cell">
1166 $value = $current_settings[
'email_working'];
1167 if ($write_access) {
1168 check_box($prefix.
'_email_working',
'1', $value,
'', $current_settings[
'email_section'] == FALSE ?
'disabled' :
'');
1171 <img src=
"<?php echo $value ? $tick : $cross; ?>" />
1181 return $write_access;
1198 $write_access = $asset->writeAccess(
'attributes');
1199 if (!$write_access)
return $write_access;
1200 $display_options = $asset->attr(
'display_options');
1203 $display_options[
'internal_section'] = isset($_POST[$prefix.
'_internal_section']);
1204 if ($display_options[
'internal_section']) {
1205 $display_options[
'internal_broken'] = isset($_POST[$prefix.
'_internal_broken']);
1206 $display_options[
'internal_working'] = isset($_POST[$prefix.
'_internal_working']);
1209 $display_options[
'external_section'] = isset($_POST[$prefix.
'_external_section']);
1210 if ($display_options[
'external_section']) {
1211 $display_options[
'external_broken'] = isset($_POST[$prefix.
'_external_broken']);
1212 $display_options[
'external_working'] = isset($_POST[$prefix.
'_external_working']);
1215 $display_options[
'email_section'] = isset($_POST[$prefix.
'_email_section']);
1216 if ($display_options[
'email_section']) {
1217 $display_options[
'email_broken'] = isset($_POST[$prefix.
'_email_broken']);
1218 $display_options[
'email_working'] = isset($_POST[$prefix.
'_email_working']);
1221 $asset->setAttrValue(
'display_options', $display_options);
1238 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
1239 $write_access = $asset->writeAccess(
'attributes');
1241 $current = $asset->attr(
'statuses');
1243 if ($write_access) {
1244 require_once SQ_LIB_PATH.
'/html_form/html_form.inc';
1245 $statuses = get_constant_values(
'SQ_STATUS');
1248 foreach ($statuses as $constant => $value) {
1249 $options[$value] = get_status_description($value);
1252 combo_box($prefix.
'_statuses', $options, TRUE, $current);
1254 if (empty($current)) {
1255 echo translate(
'cms_report_links_no_status_selected');
1257 ?><ul style=
"margin: 1px 15px;"><?php
1258 foreach ($current as $status) {
1260 echo get_asset_status_icon($status);
1261 echo get_status_description($status);
1267 return $write_access;
1284 if (!$asset->writeAccess(
'attributes'))
return FALSE;
1286 $statuses = Array();
1287 if (isset($_POST[$prefix.
'_statuses'])) {
1288 foreach ($_POST[$prefix.
'_statuses'] as $status) {
1289 $statuses[] = $status;
1291 $statuses = array_unique($statuses);
1294 return $asset->setAttrValue(
'statuses', $statuses);
1309 if (!$asset->writeAccess(
'attributes'))
return FALSE;
1311 echo hidden_field($prefix.
'_export_switch',
'0');
1314 $report_path = $asset->data_path.
'/report.xml';
1315 if (file_exists($report_path)) $enabled = TRUE;
1319 if (!$enabled) $extras =
'disabled="disabled"';
1321 echo normal_button($prefix.
'_export', translate(
'download_file'),
'this.form.'.$prefix.
'_export_switch.value = 1; this.form.submit(); SQ_FORM_SUBMITTED = false; this.form.'.$prefix.
'_export_switch.value = 0; return true;', $extras);
1342 if (!$_POST[$prefix.
'_export_switch'])
return TRUE;
1343 if (headers_sent()) {
1344 trigger_localised_error(
'CORE0273', E_USER_WARNING);
1346 require_once SQ_FUDGE_PATH.
'/csv/csv.inc';
1348 $csv->setFilename(str_replace(
' ',
'_', $asset->name).
'_report.csv');
1349 $csv->setDeliminator(
',');
1351 $am = $GLOBALS[
'SQ_SYSTEM']->am;
1355 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
1356 $report_path = $asset->data_path.
'/report.xml';
1358 if (!is_file($report_path)) {
1359 echo
'This report has not been generated';
1364 $root =
new SimpleXMLElement($report_path, LIBXML_NOCDATA, TRUE);
1365 }
catch (Exception $e) {
1366 throw new Exception(
'Unable to parse report file "'.$report_path.
'": '.$e->getMessage());
1371 $empty_headers = TRUE;
1372 $top_headers = TRUE;
1373 $display_options = $asset->attr(
'display_options');
1375 foreach ($root->asset as $asset_node) {
1376 $persistent_values = Array();
1379 $attribute_list = Array(
'assetid',
'name',
'short_name',
'type_code',
'status');
1381 $headers = $attribute_list;
1384 foreach ($attribute_list as $attr) {
1386 if (isset($parent_ast_info[$attr])) {
1387 $value = array_get_index($parent_ast_info, $attr);
1388 if ($attr ==
'status') {
1390 $value = array_get_index($parent_ast_info,
'status_code');
1394 $persistent_values[] = $value;
1396 $top_headers = FALSE;
1398 foreach ($asset_node->link as $link) {
1399 $valid = (int) $link->attributes()->valid;
1400 $type = (string) $link->attributes()->type;
1401 $html = (string) $link->html;
1402 $description = (
string) $link->description;
1404 $display_link = TRUE;
1407 if (!$display_options[
'internal_section']) {
1408 $display_link = FALSE;
1411 if (!$display_options[
'internal_working']) {
1412 $display_link = FALSE;
1415 if (!$display_options[
'internal_broken']) {
1416 $display_link = FALSE;
1422 if (!$display_options[
'external_section']) {
1423 $display_link = FALSE;
1426 if (!$display_options[
'external_working']) {
1427 $display_link = FALSE;
1430 if (!$display_options[
'external_broken']) {
1431 $display_link = FALSE;
1437 if (!$display_options[
'email_section']) {
1438 $display_link = FALSE;
1441 if (!$display_options[
'email_working']) {
1442 $display_link = FALSE;
1445 if (!$display_options[
'email_broken']) {
1446 $display_link = FALSE;
1455 if ($display_link) {
1456 $row = $persistent_values;
1457 if ($empty_headers) $headers[] =
'type';
1459 if ($empty_headers) $headers[] =
'valid';
1462 if ($empty_headers) $headers[] =
'html';
1464 if ($empty_headers) $headers[] =
'description';
1465 $row[] = $description;
1468 $empty_headers = FALSE;
1473 foreach ($headers as $id => $value) {
1474 $headers[$id] = ucwords(str_replace(
'_',
' ', $value));
1477 if (!empty($logs)) $csv->setFieldHeaders($headers);
1479 $csv->setValues($logs);
1503 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
1504 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_regenerate_report');
1505 $rl_jobs = $cron_mgr->getJobs(
'cron_job_regenerate_report');
1506 $job_count = count($rl_jobs);
1507 for ($k = 0; $k < $job_count; $k++) {
1509 if ($rl_jobs[$k]->attr(
'asset') != $asset->id) {
1510 unset($rl_jobs[$k]);
1513 if (!empty($rl_jobs)) {
1515 $o->openField(translate(
'cms_report_links_future_regen_section'),
'new_line');
1518 <table
class=
"sq-backend-table">
1520 <td
class=
"sq-backend-table-header"><?php echo translate(
'when'); ?></td>
1521 <td
class=
"sq-backend-table-header"><?php echo translate(
'status'); ?></td>
1522 <td
class=
"sq-backend-table-header"><?php echo translate(
'run_as'); ?></td>
1523 <td align=
"center" class=
"sq-backend-table-header" style=
"text-align: center;"><?php
1524 if ($asset->writeAccess(
'attributes')) {
1525 echo translate(
'delete_question');
1530 foreach ($rl_jobs as $rl_job) {
1533 <td
class=
"sq-backend-table-cell">
1534 <?php echo translate(
'cms_report_links_future_regen_cron_info', $rl_job->id, $rl_job->readableWhen()); ?>
1536 <td
class=
"sq-backend-table-cell">
1538 if ($rl_job->attr(
'long') && $rl_job->attr(
'running')) {
1539 echo translate(
'cms_report_links_future_regen_running');
1543 <td
class=
"sq-backend-table-cell">
1545 $user = $rl_job->getRunningUser();
1546 echo get_asset_tag_line($user->id);
1550 <td align=
"center" class=
"sq-backend-table-cell">
1552 if ($rl_job->canDelete() && $asset->writeAccess(
'attributes')) {
1553 check_box($prefix.
'_remove_rl[]', $rl_job->id);
1568 require_once SQ_FUDGE_PATH.
'/general/datetime.inc';
1570 $edit_fns = $cron_job->getEditFns();
1573 $o->openField(translate(
'cms_report_links_future_regen_field'),
'new_line');
1574 if ($asset->writeAccess(
'attributes')) {
1575 $cron_epoc = (int)$cron_mgr->attr(
'epoch');
1576 $cron_refresh = (int)$cron_mgr->attr(
'refresh_time');
1577 if ($cron_epoc > 0 && $cron_refresh > 0) {
1578 $edit_fns->paintInLineBackend($cron_job, $o, $prefix.
'_new_rl');
1579 $o->note(translate(
'cron_manager_next_run', $cron_mgr->readableRefreshTime(), readable_datetime($cron_mgr->timeOfNextRun())));
1581 echo translate(
'cron_manager_not_configured_regen');
1584 echo translate(
'cms_report_links_future_regen_lock');
1605 $cron_mgr = $GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'cron_manager');
1606 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset(
'cron_job_regenerate_report');
1608 if (!is_null($cron_mgr)) {
1609 $rl_jobs = $cron_mgr->getJobs(
'cron_job_regenerate_report');
1610 $job_count = count($rl_jobs);
1611 for ($k = 0; $k < $job_count; $k++) {
1613 if ($rl_jobs[$k]->attr(
'asset') != $asset->id) {
1614 unset($rl_jobs[$k]);
1617 if (!empty($_POST[$prefix.
'_remove_rl'])) {
1618 if ($GLOBALS[
'SQ_SYSTEM']->am->acquireLock($cron_mgr->id,
'links')) {
1619 foreach ($rl_jobs as $rl_job) {
1620 if (in_array($rl_job->id, $_POST[$prefix.
'_remove_rl'])) {
1621 if ($cron_mgr->removeJob($rl_job)) {
1627 $GLOBALS[
'SQ_SYSTEM']->am->releaseLock($cron_mgr->id,
'links');
1630 trigger_localised_error(
'SYS0232', E_USER_NOTICE);
1634 $cron_epoc = (int)$cron_mgr->attr(
'epoch');
1635 $cron_refresh = (int)$cron_mgr->attr(
'refresh_time');
1636 if ($cron_epoc > 0 && $cron_refresh > 0) {
1637 if ($asset->writeAccess(
'attributes')) {
1639 $edit_fns = $rl->getEditFns();
1641 $new_rl = $prefix.
'_new_rl';
1642 if (isset($new_rl)) {
1643 if ($edit_fns->processInLineBackend($rl, $o, $new_rl)) {
1644 $rl->setAttrValue(
'long', TRUE);
1645 $rl->setAttrValue(
'asset', $asset->id);
1646 $rl->saveAttributes();
1654 $GLOBALS[
'SQ_SYSTEM']->changeDatabaseConnection(
'db2');
1655 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
1656 if ($cron_mgr->addJob($rl, $GLOBALS[
'SQ_SYSTEM']->user)) {
1657 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
1660 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'ROLLBACK');
1662 $GLOBALS[
'SQ_SYSTEM']->restoreDatabaseConnection();
1684 if (!$asset->writeAccess(
'attributes'))
return FALSE;
1685 echo hidden_field($prefix.
'_report_broken',
'0');
1688 $report_path = $asset->data_path.
'/report.xml';
1689 $report_info = $asset->attr(
'report_info');
1691 if (file_exists($report_path) && empty($report_info)) {
1696 if (!$enabled) $extras =
'disabled="disabled"';
1698 echo normal_button($prefix.
'_report_broken_button', translate(
'cms_report_links_broken_button'),
'this.form.'.$prefix.
'_report_broken.value = 1; this.form.submit();', $extras);
1699 if (!$report_info) {
1700 $o->note(translate(
'cms_report_links_broken_note'));
1702 $o->note($asset->attr(
'report_info'));
1724 if (!$_POST[$prefix.
'_report_broken'])
return TRUE;
1726 return $asset->reportBrokenLink();