2010-05-28 04:28:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Content side-report listing pages with broken links
|
|
|
|
* @package cms
|
|
|
|
* @subpackage content
|
|
|
|
*/
|
|
|
|
|
|
|
|
class BrokenLinksReport extends SS_Report {
|
2010-10-04 07:32:22 +02:00
|
|
|
|
2010-05-28 04:28:38 +02:00
|
|
|
function title() {
|
2010-05-28 04:30:17 +02:00
|
|
|
return _t('BrokenLinksReport.BROKENLINKS',"Broken links report");
|
2010-05-28 04:28:38 +02:00
|
|
|
}
|
2010-10-04 07:32:22 +02:00
|
|
|
|
2010-05-28 04:30:34 +02:00
|
|
|
function sourceRecords($params, $sort, $limit) {
|
2010-05-28 04:30:59 +02:00
|
|
|
$join = '';
|
2010-05-28 04:32:13 +02:00
|
|
|
$sortBrokenReason = false;
|
2010-05-28 04:30:59 +02:00
|
|
|
if($sort) {
|
|
|
|
$parts = explode(' ', $sort);
|
|
|
|
$field = $parts[0];
|
|
|
|
$direction = $parts[1];
|
|
|
|
|
|
|
|
if($field == 'AbsoluteLink') {
|
|
|
|
$sort = 'URLSegment ' . $direction;
|
2010-05-28 04:31:07 +02:00
|
|
|
} elseif($field == 'Subsite.Title') {
|
2010-05-28 04:30:59 +02:00
|
|
|
$join = 'LEFT JOIN "Subsite" ON "Subsite"."ID" = "SiteTree"."SubsiteID"';
|
2010-05-28 04:31:07 +02:00
|
|
|
} elseif($field == 'BrokenReason') {
|
2010-05-28 04:32:13 +02:00
|
|
|
$sortBrokenReason = true;
|
|
|
|
$sort = '';
|
2010-05-28 04:30:59 +02:00
|
|
|
}
|
|
|
|
}
|
2010-10-13 06:19:22 +02:00
|
|
|
$q = DB::USE_ANSI_SQL ? '"' : '`';
|
|
|
|
if (!isset($_REQUEST['CheckSite']) || $params['CheckSite'] == 'Published') $ret = Versioned::get_by_stage('SiteTree', 'Live', "({$q}SiteTree{$q}.{$q}HasBrokenLink{$q} = 1 OR {$q}SiteTree{$q}.{$q}HasBrokenFile{$q} = 1)", $sort, $join, $limit);
|
|
|
|
else $ret = DataObject::get('SiteTree', "({$q}SiteTree{$q}.{$q}HasBrokenFile{$q} = 1 OR {$q}HasBrokenLink{$q} = 1)", $sort, $join, $limit);
|
2010-05-28 04:28:38 +02:00
|
|
|
|
|
|
|
$returnSet = new DataObjectSet();
|
|
|
|
if ($ret) foreach($ret as $record) {
|
|
|
|
$reason = false;
|
|
|
|
$isRedirectorPage = in_array($record->ClassName, ClassInfo::subclassesFor('RedirectorPage'));
|
|
|
|
$isVirtualPage = in_array($record->ClassName, ClassInfo::subclassesFor('VirtualPage'));
|
|
|
|
|
|
|
|
if ($isVirtualPage) {
|
|
|
|
if ($record->HasBrokenLink) {
|
2010-10-04 07:32:22 +02:00
|
|
|
$reason = _t('BrokenLinksReport.VirtualPageNonExistent', "virtual page pointing to non-existent page");
|
2010-05-28 04:28:38 +02:00
|
|
|
$reasonCodes = array("VPBROKENLINK");
|
|
|
|
}
|
|
|
|
} else if ($isRedirectorPage) {
|
|
|
|
if ($record->HasBrokenLink) {
|
2010-10-04 07:32:22 +02:00
|
|
|
$reason = _t('BrokenLinksReport.RedirectorNonExistent', "redirector page pointing to non-existent page");
|
2010-05-28 04:28:38 +02:00
|
|
|
$reasonCodes = array("RPBROKENLINK");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($record->HasBrokenLink && $record->HasBrokenFile) {
|
2010-10-04 07:32:22 +02:00
|
|
|
$reason = _t('BrokenLinksReport.HasBrokenLinkAndFile', "has broken link and file");
|
2010-05-28 04:28:38 +02:00
|
|
|
$reasonCodes = array("BROKENFILE", "BROKENLINK");
|
|
|
|
} else if ($record->HasBrokenLink && !$record->HasBrokenFile) {
|
2010-10-04 07:32:22 +02:00
|
|
|
$reason = _t('BrokenLinksReport.HasBrokenLink', "has broken link");
|
2010-05-28 04:28:38 +02:00
|
|
|
$reasonCodes = array("BROKENLINK");
|
|
|
|
} else if (!$record->HasBrokenLink && $record->HasBrokenFile) {
|
2010-10-04 07:32:22 +02:00
|
|
|
$reason = _t('BrokenLinksReport.HasBrokenFile', "has broken file");
|
2010-05-28 04:28:38 +02:00
|
|
|
$reasonCodes = array("BROKENFILE");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($reason) {
|
2010-05-28 04:30:17 +02:00
|
|
|
if (isset($params['Reason']) && $params['Reason'] && !in_array($params['Reason'], $reasonCodes)) continue;
|
2010-05-28 04:28:38 +02:00
|
|
|
$record->BrokenReason = $reason;
|
|
|
|
$returnSet->push($record);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-28 04:32:13 +02:00
|
|
|
if($sortBrokenReason) $returnSet->sort('BrokenReason', $direction);
|
2010-05-28 04:30:40 +02:00
|
|
|
|
2010-05-28 04:28:38 +02:00
|
|
|
return $returnSet;
|
|
|
|
}
|
|
|
|
function columns() {
|
2010-10-04 07:32:22 +02:00
|
|
|
if(isset($_REQUEST['CheckSite']) && $_REQUEST['CheckSite'] == 'Draft') {
|
|
|
|
$dateTitle = _t('BrokenLinksReport.ColumnDateLastModified', 'Date last modified');
|
|
|
|
} else {
|
|
|
|
$dateTitle = _t('BrokenLinksReport.ColumnDateLastPublished', 'Date last published');
|
|
|
|
}
|
|
|
|
|
2010-05-28 04:28:38 +02:00
|
|
|
$fields = array(
|
|
|
|
"Title" => array(
|
2010-10-15 03:46:53 +02:00
|
|
|
"title" => _t('BrokenLinksReport.PageName', 'Page name'),
|
2010-10-04 07:32:22 +02:00
|
|
|
'formatting' => sprintf(
|
|
|
|
'<a href=\"admin/show/$ID\" title=\"%s\">$value</a>',
|
|
|
|
_t('BrokenLinksReport.HoverTitleEditPage', 'Edit page')
|
|
|
|
)
|
2010-05-28 04:28:38 +02:00
|
|
|
),
|
2010-05-28 04:30:17 +02:00
|
|
|
"LastEdited" => array(
|
2010-10-04 07:32:22 +02:00
|
|
|
"title" => $dateTitle,
|
2010-10-19 03:04:05 +02:00
|
|
|
'casting' => 'SS_Datetime->Full'
|
2010-05-28 04:30:17 +02:00
|
|
|
),
|
2010-05-28 04:28:38 +02:00
|
|
|
"BrokenReason" => array(
|
2010-10-04 07:32:22 +02:00
|
|
|
"title" => _t('BrokenLinksReport.ColumnProblemType', "Problem type")
|
2010-05-28 04:28:38 +02:00
|
|
|
),
|
|
|
|
'AbsoluteLink' => array(
|
2010-10-04 07:32:22 +02:00
|
|
|
'title' => _t('BrokenLinksReport.ColumnURL', 'URL'),
|
2010-05-28 04:28:38 +02:00
|
|
|
'formatting' => '$value " . ($AbsoluteLiveLink ? "<a href=\"$AbsoluteLiveLink\">(live)</a>" : "") . " <a href=\"$value?stage=Stage\">(draft)</a>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
function parameterFields() {
|
|
|
|
return new FieldSet(
|
2010-10-15 03:46:53 +02:00
|
|
|
new DropdownField('CheckSite', _t('BrokenLinksReport.CheckSite','Check site'), array(
|
2010-10-04 07:32:22 +02:00
|
|
|
'Published' => _t('BrokenLinksReport.CheckSiteDropdownPublished', 'Published Site'),
|
|
|
|
'Draft' => _t('BrokenLinksReport.CheckSiteDropdownDraft', 'Draft Site')
|
2010-05-28 04:30:27 +02:00
|
|
|
)),
|
2010-10-04 07:32:22 +02:00
|
|
|
new DropdownField(
|
|
|
|
'Reason',
|
|
|
|
_t('BrokenLinksReport.ReasonDropdown', 'Problem to check'),
|
|
|
|
array(
|
2010-10-15 03:46:53 +02:00
|
|
|
'' => _t('BrokenLinksReport.Any', 'Any'),
|
2010-10-04 07:32:22 +02:00
|
|
|
'BROKENFILE' => _t('BrokenLinksReport.ReasonDropdownBROKENFILE', 'Broken file'),
|
|
|
|
'BROKENLINK' => _t('BrokenLinksReport.ReasonDropdownBROKENLINK', 'Broken link'),
|
|
|
|
'VPBROKENLINK' => _t('BrokenLinksReport.ReasonDropdownVPBROKENLINK', 'Virtual page pointing to non-existent page'),
|
|
|
|
'RPBROKENLINK' => _t('BrokenLinksReport.ReasonDropdownRPBROKENLINK', 'Redirector page pointing to non-existent page'),
|
|
|
|
)
|
|
|
|
)
|
2010-05-28 04:28:38 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|