| 1 |
<?php
|
| 2 |
|
| 3 |
/* This file is part of "Broken Anchor for Node comments Module".
|
| 4 |
* Copyright 2009, arNuméral
|
| 5 |
* Author : Yoran Brault
|
| 6 |
* eMail : yoran.brault@bad_arnumeral.fr (remove bad_ before sending an email)
|
| 7 |
* Site : http://www.arnumeral.fr/node/2
|
| 8 |
*
|
| 9 |
* "Broken Anchor for Node comments Module" is free software; you can redistribute it and/or
|
| 10 |
* modify it under the terms of the GNU General Public License as
|
| 11 |
* published by the Free Software Foundation; either version 2.1 of
|
| 12 |
* the License, or (at your option) any later version.
|
| 13 |
*
|
| 14 |
* "Broken Anchor for Node comments Module" is distributed in the hope that it will be useful,
|
| 15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 17 |
* General Public License for more details.
|
| 18 |
*
|
| 19 |
* You should have received a copy of the GNU General Public
|
| 20 |
* License along with "Broken Anchor for Node comments Module"; if not, write to the Free
|
| 21 |
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
| 22 |
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
|
| 23 |
*/
|
| 24 |
|
| 25 |
|
| 26 |
function broken_anchor_report() {
|
| 27 |
$date=variable_get("broken_anchor_statistics_last_cron",null);
|
| 28 |
$output.=t("Last check : @date", array("@date"=>$date==0?t("never"):format_date($date)))."<br>";
|
| 29 |
foreach (module_implements('broken_anchor_info') as $module) {
|
| 30 |
$type[$module]=module_invoke($module, 'broken_anchor_info');
|
| 31 |
$progress=module_invoke($module, 'broken_anchor_get_progress',broken_anchor_last_check_id($module));
|
| 32 |
$output.=t("@type checked : @percent %",
|
| 33 |
array(
|
| 34 |
"@type"=>$type[$module]['description'],
|
| 35 |
"@percent"=>$progress['total']==0?0:number_format($progress['passed']/$progress['total'],3)
|
| 36 |
))." (".$progress['passed']."/".$progress['total'].")<br>";
|
| 37 |
}
|
| 38 |
$header = array(t('checked'), t('ID'), t('url'), t('count'), t('status'), t('operation'));
|
| 39 |
$cursor=pager_query("
|
| 40 |
select *
|
| 41 |
from broken_anchor_errors b
|
| 42 |
where ignored is null
|
| 43 |
order by b.cid,checked",
|
| 44 |
broken_anchor_report_page_size(), 0, "
|
| 45 |
select count(*)
|
| 46 |
from {broken_anchor_errors}
|
| 47 |
where ignored is null");
|
| 48 |
|
| 49 |
|
| 50 |
$rows=array();
|
| 51 |
while ($error = db_fetch_object($cursor)) {
|
| 52 |
if ($error->match_type==0) {
|
| 53 |
$url=parse_url($error->match);
|
| 54 |
$match=$url['scheme']==''?$error->match:l($url['host'], $error->match,array('attributes'=>array('target'=>'_blank')));
|
| 55 |
} else {
|
| 56 |
$match=$error->match;
|
| 57 |
}
|
| 58 |
|
| 59 |
$rows[]=array(
|
| 60 |
format_date($error->checked,"small"),
|
| 61 |
module_invoke($error->module, 'broken_anchor_link', $error->cid),
|
| 62 |
$match,
|
| 63 |
$error->count,
|
| 64 |
$error->status,
|
| 65 |
l(t('Check'), 'admin/reports/broken_anchor/check/'. $error->module."/".$error->cid)." - ".
|
| 66 |
l(t('Ignore'), 'admin/reports/broken_anchor/ignore/'. $error->eid)
|
| 67 |
);
|
| 68 |
}
|
| 69 |
if (count($rows)==0) {
|
| 70 |
$output.= t("No error found");
|
| 71 |
} else {
|
| 72 |
$output.=theme('table', $header, $rows);
|
| 73 |
$output.=theme('pager', NULL, variable_get('default_nodes_main', 10));
|
| 74 |
}
|
| 75 |
return $output;
|
| 76 |
}
|
| 77 |
|
| 78 |
function broken_anchor_update_node($module, $cid) {
|
| 79 |
$contents=module_invoke($module, 'broken_anchor_get_contents', $cid, 1);
|
| 80 |
if (count($contents)!=1) {
|
| 81 |
$message=t("Unable to get content from @module with id = @id", array("@module"=>$module, "@id"=>$cid));
|
| 82 |
} else {
|
| 83 |
$errors=broken_anchor_check_content($module, $contents[0]);
|
| 84 |
$message = t("Content checked again. Report is updated");
|
| 85 |
}
|
| 86 |
drupal_set_message($message);
|
| 87 |
drupal_goto('admin/reports/broken_anchor');
|
| 88 |
}
|
| 89 |
|
| 90 |
function broken_anchor_ignore_error($eid) {
|
| 91 |
db_query("update {broken_anchor_errors} set ignored=1 where eid=%d",$eid);
|
| 92 |
$message = t('This error is now ignored.');
|
| 93 |
drupal_set_message($message);
|
| 94 |
drupal_goto('admin/reports/broken_anchor');
|
| 95 |
}
|