18 require_once SQ_CORE_PACKAGE_PATH.
'/report/report.inc';
31 register_implementation(
'report_links',
'bridge');
44 $this->_ser_attrs = TRUE;
45 parent::__construct($assetid);
71 function getLinks($assetid, $link_types, $type_code=
'', $strict_type_code=TRUE, $side_of_link=
'major', $sort_by=NULL)
73 assert_equals($assetid, $this->
id,
'The Links Report can only get its own links');
75 if (!isset($this->_tmp[
'getLinks'])) {
77 $am = $GLOBALS[
'SQ_SYSTEM']->am;
78 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
79 $report_path = $this->data_path.
'/report.xml';
80 if (!is_file($report_path))
return Array();
83 $root = @
new SimpleXMLElement($report_path, LIBXML_NOCDATA, TRUE);
84 }
catch (Exception $e) {
85 trigger_error(
'Unable to parse report file "'.$report_path.
'": '.$e->getMessage());
91 foreach ($root->asset as $asset_element) {
94 'minorid' => (
int) $asset_element->attributes()->assetid,
96 'link_type' => SQ_LINK_TYPE_1,
97 'minor_type_code' => (string) $asset_element->attributes()->type_code,
98 'sort_order' => $sort_order,
99 'is_dependant' =>
'0',
100 'is_exclusive' =>
'0',
106 $this->_tmp[
'getLinks'] = $links;
110 return $this->_tmp[
'getLinks'];
128 function getParents($assetid, $type_code=
'', $strict_type_code=TRUE)
130 assert_equals($assetid, $this->
id,
'The Links Report can only get its own links');
156 function getChildren($assetid, $type_code=
'', $strict_type_code=TRUE, $dependant=NULL, $sort_by=NULL)
158 assert_equals($assetid, $this->
id,
'The Links Report can only get its own links');
193 require_once SQ_INCLUDE_PATH.
'/general_occasional.inc';
194 require_once SQ_FUDGE_PATH.
'/general/general.inc';
196 $report_path = $this->data_path.
'/report.xml';
197 if (!is_file($report_path)) {
198 echo translate(
'report_not_generated');
203 $root = @
new SimpleXMLElement($report_path, LIBXML_NOCDATA, TRUE);
204 }
catch (Exception $e) {
205 trigger_error(
'Unable to parse report file "'.$report_path.
'": '.$e->getMessage());
209 $reported_links = Array(
210 'internal' => Array(),
211 'external' => Array(),
215 $display_options = $this->
attr(
'display_options');
216 $status_options = $this->
attr(
'statuses');
218 foreach ($root->asset as $asset_element) {
220 if (!in_array($asset_element->attributes()->status,$status_options))
continue;
221 foreach ($asset_element->link as $link) {
222 $type = (string) $link->attributes()->type;
223 assert_isset_array_index($reported_links, $type,
'Unknown link type "'.$type.
'"');
226 $new_link[
'html'] = (string) $link->html;
229 if ($type ==
'internal') {
230 $to_assetid = preg_replace(
'|\./\?a=([0-9]+).*|',
'\\1', (
string) $link->html);
231 $new_link[
'data'] = $to_assetid;
233 $new_link[
'data'] = (string) $link->html;
235 $new_link[
'description'] = htmlentities((
string) $link->description);
237 $valid = (int) $link->attributes()->valid;
238 $new_link[
'valid'] = $valid;
240 $display_link = TRUE;
244 if (!$display_options[
'internal_working']) {
245 $display_link = FALSE;
248 if (!$display_options[
'internal_broken']) {
249 $display_link = FALSE;
255 if (!$display_options[
'external_working']) {
256 $display_link = FALSE;
259 if (!$display_options[
'external_broken']) {
260 $display_link = FALSE;
266 if (!$display_options[
'email_working']) {
267 $display_link = FALSE;
270 if (!$display_options[
'email_broken']) {
271 $display_link = FALSE;
278 if ($display_link || $show_all) {
279 $reported_links[$type][(int) $asset_element->attributes()->assetid][] = $new_link;
284 return $reported_links;
298 if (empty($reported_links))
return FALSE;
300 $asset_admins = Array();
302 'link_report_name' => $this->name,
303 'link_report_id' => $this->
id,
306 $ms = $GLOBALS[
'SQ_SYSTEM']->getMessagingService();
308 foreach ($reported_links as $link_type => $info) {
309 $msg_reps[
'type'] = $link_type;
311 foreach ($info as $assetid => $link_info) {
312 $msg_reps[
'assetid'] = $assetid;
314 foreach ($link_info as $link_details) {
315 if (!$link_details[
'valid']) {
316 if (!isset($asset_admins[$assetid])) {
318 $asset_admins[$assetid] = $GLOBALS[
'SQ_SYSTEM']->am->getPermission($assetid, SQ_PERMISSION_ADMIN, TRUE, FALSE, TRUE, FALSE, FALSE);
320 $msg_reps[
'link'] = $link_details[
'html'];
321 $msg_reps[
'description'] = $link_details[
'description'];
323 if (!empty($asset_admins[$assetid])) {
324 $msg = $ms->newMessage();
325 $msg->to = $asset_admins[$assetid];
327 $msg->type =
'asset.report.brokenlink';
328 $msg->replacements = $msg_reps;
329 $ms->enqueueMessage($msg);
340 $this->
setAttrValue(
'report_info', translate(
'cms_report_links_broken_info', $this->
attr(
'generated_date')));