mirror of
https://github.com/silverstripe/silverstripe-externallinks.git
synced 2024-10-22 17:05:44 +02:00
71 lines
1.7 KiB
PHP
71 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Represents a single link checked for a single run that is broken
|
|
*
|
|
* @method BrokenExternalPageTrack Track()
|
|
* @method BrokenExternalPageTrackStatus Status()
|
|
*/
|
|
class BrokenExternalLink extends DataObject {
|
|
|
|
private static $db = array(
|
|
'Link' => 'Varchar(2083)', // 2083 is the maximum length of a URL in Internet Explorer.
|
|
'HTTPCode' =>'Int'
|
|
);
|
|
|
|
private static $has_one = array(
|
|
'Track' => 'BrokenExternalPageTrack',
|
|
'Status' => 'BrokenExternalPageTrackStatus'
|
|
);
|
|
|
|
/**
|
|
* @return SiteTree
|
|
*/
|
|
public function Page() {
|
|
return $this->Track()->Page();
|
|
}
|
|
|
|
public static $summary_fields = array(
|
|
'Page.Title' => 'Page',
|
|
'HTTPCodeDescription' => 'HTTP Code',
|
|
'Created' => 'Created'
|
|
);
|
|
|
|
public static $searchable_fields = array(
|
|
'HTTPCode' => array('title' => 'HTTP Code')
|
|
);
|
|
|
|
public function canEdit($member = false) {
|
|
return false;
|
|
}
|
|
|
|
public function canView($member = false) {
|
|
$member = $member ? $member : Member::currentUser();
|
|
$codes = array('content-authors', 'administrators');
|
|
return Permission::checkMember($member, $codes);
|
|
}
|
|
|
|
/**
|
|
* Retrieve a human readable description of a response code
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getHTTPCodeDescription() {
|
|
$code = $this->HTTPCode;
|
|
if(empty($code)) {
|
|
// Assume that $code = 0 means there was no response
|
|
$description = _t(__CLASS__.'.NOTAVAILABLE', 'Server Not Available');
|
|
} elseif(
|
|
($descriptions = Config::inst()->get('SS_HTTPResponse', 'status_codes'))
|
|
&& isset($descriptions[$code])
|
|
) {
|
|
$description = $descriptions[$code];
|
|
} else {
|
|
$description = _t(__CLASS__.'.UNKNOWNRESPONSE', 'Unknown Response Code');
|
|
}
|
|
return sprintf("%d (%s)", $code, $description);
|
|
}
|
|
}
|
|
|
|
|