2007-07-19 12:40:05 +02:00
< ? php
2010-05-28 04:23:10 +02:00
2008-02-25 03:10:37 +01:00
/**
* Base class for the small reports that appear in the left hand site of the Site Content section of the CMS .
* Create subclasses of this class to build new reports .
2010-04-23 02:11:32 +02:00
*
2008-02-25 03:10:37 +01:00
* @ package cms
* @ subpackage content
2010-05-28 04:37:39 +02:00
*
* @ package cms
* @ subpackage content
2008-02-25 03:10:37 +01:00
*/
2010-05-28 04:23:10 +02:00
class SideReportView extends ViewableData {
protected $controller , $report ;
protected $parameters ;
2009-10-16 00:43:58 +02:00
2010-05-28 04:23:10 +02:00
function __construct ( $controller , $report ) {
$this -> controller = $controller ;
$this -> report = $report ;
parent :: __construct ();
}
2007-07-19 12:40:05 +02:00
2009-10-29 03:50:47 +01:00
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.OtherGroupTitle' , " Other " );
2009-10-29 03:50:47 +01:00
}
function sort () {
return 0 ;
}
2010-05-28 04:23:10 +02:00
function setParameters ( $parameters ) {
$this -> parameters = $parameters ;
}
function forTemplate () {
$records = $this -> report -> records ( $this -> parameters );
$columns = $this -> report -> columns ();
2007-07-19 12:40:05 +02:00
2010-05-28 04:23:10 +02:00
if ( $records && $records -> Count ()) {
2007-07-19 12:40:05 +02:00
$result = " <ul class= \" $this->class\ " > \n " ;
foreach ( $records as $record ) {
$result .= " <li> \n " ;
2010-05-28 04:23:10 +02:00
foreach ( $columns as $source => $info ) {
if ( is_string ( $info )) $info = array ( 'title' => $info );
$result .= $this -> formatValue ( $record , $source , $info );
2007-07-19 12:40:05 +02:00
}
$result .= " \n </li> \n " ;
}
$result .= " </ul> \n " ;
} else {
2009-01-05 07:17:59 +01:00
$result = " <p class= \" message notice \" > " .
sprintf (
_t ( 'SideReport.REPEMPTY' , 'The %s report is empty.' , PR_MEDIUM , '%s is a report title' ),
2010-05-28 04:23:10 +02:00
$this -> report -> title ()
2009-01-05 07:17:59 +01:00
)
. " </p> " ;
2007-07-19 12:40:05 +02:00
}
return $result ;
}
2009-10-16 00:43:58 +02:00
2010-05-28 04:23:10 +02:00
protected function formatValue ( $record , $source , $info ) {
// Field sources
//if(is_string($source)) {
$val = Convert :: raw2xml ( $record -> $source );
//} else {
// $val = $record->val($source[0], $source[1]);
//}
2010-05-28 04:29:58 +02:00
// Casting, a la TableListField. We're deep-calling a helper method on TableListField that
// should probably be pushed elsewhere...
if ( ! empty ( $info [ 'casting' ])) {
$val = TableListField :: getCastedValue ( $val , $info [ 'casting' ]);
}
2010-05-28 04:23:10 +02:00
// Formatting, a la TableListField
if ( ! empty ( $info [ 'formatting' ])) {
$format = str_replace ( '$value' , " __VAL__ " , $info [ 'formatting' ]);
$format = preg_replace ( '/\$([A-Za-z0-9-_]+)/' , '$record->$1' , $format );
$format = str_replace ( '__VAL__' , '$val' , $format );
$val = eval ( 'return "' . $format . '";' );
}
$prefix = empty ( $info [ 'newline' ]) ? " " : " <br> " ;
2010-05-28 04:29:58 +02:00
$classClause = " " ;
if ( isset ( $info [ 'title' ])) {
$cssClass = ereg_replace ( '[^A-Za-z0-9]+' , '' , $info [ 'title' ]);
$classClause = " class= \" $cssClass\ " " ;
}
2010-05-28 04:23:10 +02:00
if ( isset ( $info [ 'link' ]) && $info [ 'link' ]) {
$link = ( $info [ 'link' ] === true ) ? " admin/show/ $record->ID " : $info [ 'link' ];
2010-05-28 04:29:58 +02:00
return $prefix . " <a $classClause href= \" $link\ " > $val </ a > " ;
2010-05-28 04:23:10 +02:00
} else {
2010-05-28 04:29:58 +02:00
return $prefix . " <span $classClause > $val </span> " ;
2010-05-28 04:23:10 +02:00
}
2009-10-28 03:21:01 +01:00
}
2007-07-19 12:40:05 +02:00
}
2010-05-28 04:29:58 +02:00
/**
* A report wrapper that makes it easier to define slightly different behaviour for side - reports .
*
* This report wrapper will use sideReportColumns () for the report columns , instead of columns () .
2010-05-28 04:37:39 +02:00
*
* @ package cms
* @ subpackage content
2010-05-28 04:29:58 +02:00
*/
2010-05-28 04:35:56 +02:00
class SideReportWrapper extends SS_ReportWrapper {
2010-05-28 04:29:58 +02:00
function columns () {
if ( $this -> baseReport -> hasMethod ( 'sideReportColumns' )) {
return $this -> baseReport -> sideReportColumns ();
} else {
return parent :: columns ();
}
}
}
2010-05-28 04:23:10 +02:00
////////////////////////////////////////////////////////////////////////////////////////////////
2008-02-25 03:10:37 +01:00
/**
* Content side - report listing empty pages
2010-04-23 02:11:32 +02:00
*
2008-02-25 03:10:37 +01:00
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_EmptyPages extends SS_Report {
2007-07-19 12:40:05 +02:00
function title () {
2009-10-29 03:50:47 +01:00
return _t ( 'SideReport.EMPTYPAGES' , " Pages with no content " );
}
2010-05-28 04:23:10 +02:00
2009-10-29 03:50:47 +01:00
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.ContentGroupTitle' , " Content reports " );
2009-10-29 03:50:47 +01:00
}
function sort () {
return 100 ;
2007-07-19 12:40:05 +02:00
}
2010-05-28 04:23:10 +02:00
function sourceRecords ( $params = null ) {
2010-10-04 08:09:26 +02:00
return DataObject :: get ( " SiteTree " , " \" ClassName \" != 'RedirectorPage' AND ( \" Content \" = '' OR \" Content \" IS NULL OR \" Content \" LIKE '<p></p>' OR \" Content \" LIKE '<p> </p>') " , '"Title"' );
2007-07-19 12:40:05 +02:00
}
2010-05-28 04:23:10 +02:00
function columns () {
2007-07-19 12:40:05 +02:00
return array (
2010-05-28 04:23:10 +02:00
" Title " => array (
" title " => " Title " , // todo: use NestedTitle(2)
" link " => true ,
),
2007-07-19 12:40:05 +02:00
);
}
}
2008-02-25 03:10:37 +01:00
/**
* Content side - report listing recently editing pages .
2010-04-23 02:11:32 +02:00
*
2008-02-25 03:10:37 +01:00
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_RecentlyEdited extends SS_Report {
2007-07-19 12:40:05 +02:00
function title () {
2007-09-16 18:33:05 +02:00
return _t ( 'SideReport.LAST2WEEKS' , " Pages edited in the last 2 weeks " );
2007-07-19 12:40:05 +02:00
}
2009-10-29 03:50:47 +01:00
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.ContentGroupTitle' , " Content reports " );
2009-10-29 03:50:47 +01:00
}
function sort () {
return 200 ;
}
2010-05-28 04:23:10 +02:00
function sourceRecords ( $params = null ) {
API CHANGE: Renamed conflicting classes to have an "SS_" namespace, and renamed existing "SS" namespace to "SS_". The affected classes are: HTTPRequest, HTTPResponse, Query, Database, SSBacktrace, SSCli, SSDatetime, SSDatetimeTest, SSLog, SSLogTest, SSLogEmailWriter, SSLogErrorEmailFormatter, SSLogErrorFileFormatter, SSLogFileWriter and SSZendLog.
MINOR: Replaced usage of renamed classes with the new namespaced name.
From: Sam Minnee <sam@silverstripe.com>
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@90076 467b73ca-7a2a-4603-9d3b-597d59a354a9
2009-10-26 04:06:42 +01:00
$threshold = strtotime ( '-14 days' , SS_Datetime :: now () -> Format ( 'U' ));
2009-08-06 23:41:49 +02:00
return DataObject :: get ( " SiteTree " , " \" SiteTree \" . \" LastEdited \" > ' " . date ( " Y-m-d H:i:s " , $threshold ) . " ' " , " \" SiteTree \" . \" LastEdited \" DESC " );
2007-07-19 12:40:05 +02:00
}
2010-05-28 04:23:10 +02:00
function columns () {
2007-07-19 12:40:05 +02:00
return array (
2010-05-28 04:23:10 +02:00
" Title " => array (
" title " => " Title " , // todo: use NestedTitle(2)
" link " => true ,
),
2007-07-19 12:40:05 +02:00
);
}
}
2008-02-25 03:10:37 +01:00
2010-05-28 04:37:39 +02:00
/**
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_ToDo extends SS_Report {
2008-02-25 03:10:37 +01:00
function title () {
2009-10-29 03:50:47 +01:00
return _t ( 'SideReport.TODO' , " Pages with To Do items " );
}
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.ContentGroupTitle' , " Content reports " );
2009-10-29 03:50:47 +01:00
}
function sort () {
return 0 ;
2008-02-25 03:10:37 +01:00
}
2010-05-28 04:35:56 +02:00
function sourceRecords ( $params = null ) {
2008-11-24 10:30:41 +01:00
return DataObject :: get ( " SiteTree " , " \" SiteTree \" . \" ToDo \" IS NOT NULL AND \" SiteTree \" . \" ToDo \" <> '' " , " \" SiteTree \" . \" LastEdited \" DESC " );
2008-02-25 03:10:37 +01:00
}
2010-05-28 04:35:56 +02:00
function columns () {
2008-02-25 03:10:37 +01:00
return array (
" Title " => array (
2010-05-28 04:35:56 +02:00
" title " => " Title " , // todo: use NestedTitle(2)
2008-02-25 03:10:37 +01:00
" link " => true ,
),
" ToDo " => array (
2010-05-28 04:35:56 +02:00
" title " => " ToDo " ,
2008-02-25 03:10:37 +01:00
" newline " => true ,
),
);
}
}
2009-10-11 02:08:06 +02:00
/**
2009-10-29 22:59:47 +01:00
* Content side - report listing pages with broken links
2010-04-23 02:11:32 +02:00
*
2009-10-11 02:08:06 +02:00
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_BrokenLinks extends SS_Report {
2009-10-29 22:59:47 +01:00
function title () {
return _t ( 'SideReport.BROKENLINKS' , " Pages with broken links " );
2009-10-11 02:08:06 +02:00
}
2009-10-29 03:50:47 +01:00
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.BrokenLinksGroupTitle' , " Broken links reports " );
2009-10-29 03:50:47 +01:00
}
2010-05-28 04:23:10 +02:00
function sourceRecords ( $params = null ) {
2009-10-29 22:59:47 +01:00
// Get class names for page types that are not virtual pages or redirector pages
$classes = array_diff ( ClassInfo :: subclassesFor ( 'SiteTree' ), ClassInfo :: subclassesFor ( 'VirtualPage' ), ClassInfo :: subclassesFor ( 'RedirectorPage' ));
$classNames = " ' " . join ( " ',' " , $classes ) . " ' " ;
if ( isset ( $_REQUEST [ 'OnLive' ])) $ret = Versioned :: get_by_stage ( 'SiteTree' , 'Live' , " ClassName IN ( $classNames ) AND HasBrokenLink = 1 " );
else $ret = DataObject :: get ( 'SiteTree' , " ClassName IN ( $classNames ) AND HasBrokenLink = 1 " );
return $ret ;
}
2010-05-28 04:23:10 +02:00
function columns () {
2009-10-29 22:59:47 +01:00
return array (
2010-05-28 04:23:10 +02:00
" Title " => array (
" title " => " Title " , // todo: use NestedTitle(2)
" link " => true ,
),
2009-10-29 22:59:47 +01:00
);
}
2010-05-28 04:23:10 +02:00
function parameterFields () {
2009-10-29 22:59:47 +01:00
return new FieldSet (
2010-10-04 07:32:22 +02:00
new CheckboxField ( 'OnLive' , _t ( 'SideReport.ParameterLiveCheckbox' , 'Check live site' ))
2009-10-29 22:59:47 +01:00
);
}
}
/**
* Content side - report listing pages with broken files
* or asset links
2010-04-23 02:11:32 +02:00
*
2009-10-29 22:59:47 +01:00
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_BrokenFiles extends SS_Report {
2009-10-29 22:59:47 +01:00
function title () {
return _t ( 'SideReport.BROKENFILES' , " Pages with broken files " );
}
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.BrokenLinksGroupTitle' , " Broken links reports " );
2009-10-29 22:59:47 +01:00
}
2010-05-28 04:23:10 +02:00
function sourceRecords ( $params = null ) {
2009-10-29 22:59:47 +01:00
// Get class names for page types that are not virtual pages or redirector pages
$classes = array_diff ( ClassInfo :: subclassesFor ( 'SiteTree' ), ClassInfo :: subclassesFor ( 'VirtualPage' ), ClassInfo :: subclassesFor ( 'RedirectorPage' ));
$classNames = " ' " . join ( " ',' " , $classes ) . " ' " ;
if ( isset ( $_REQUEST [ 'OnLive' ])) $ret = Versioned :: get_by_stage ( 'SiteTree' , 'Live' , " ClassName IN ( $classNames ) AND HasBrokenFile = 1 " );
else $ret = DataObject :: get ( 'SiteTree' , " ClassName IN ( $classNames ) AND HasBrokenFile = 1 " );
return $ret ;
}
2010-05-28 04:23:10 +02:00
function columns () {
2009-10-29 22:59:47 +01:00
return array (
2010-05-28 04:23:10 +02:00
" Title " => array (
" title " => " Title " , // todo: use NestedTitle(2)
" link " => true ,
),
2009-10-29 22:59:47 +01:00
);
}
2010-05-28 04:23:10 +02:00
function parameterFields () {
2009-10-29 22:59:47 +01:00
return new FieldSet (
2010-10-04 07:32:22 +02:00
new CheckboxField ( 'OnLive' , _t ( 'SideReport.ParameterLiveCheckbox' , 'Check live site' ))
2009-10-29 22:59:47 +01:00
);
}
}
2010-04-23 02:11:32 +02:00
/**
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_BrokenVirtualPages extends SS_Report {
2009-10-29 22:59:47 +01:00
function title () {
return _t ( 'SideReport.BROKENVIRTUALPAGES' , 'VirtualPages pointing to deleted pages' );
}
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.BrokenLinksGroupTitle' , " Broken links reports " );
2009-10-29 22:59:47 +01:00
}
2010-05-28 04:23:10 +02:00
function sourceRecords ( $params = null ) {
2009-10-29 22:59:47 +01:00
$classNames = " ' " . join ( " ',' " , ClassInfo :: subclassesFor ( 'VirtualPage' )) . " ' " ;
if ( isset ( $_REQUEST [ 'OnLive' ])) $ret = Versioned :: get_by_stage ( 'SiteTree' , 'Live' , " ClassName IN ( $classNames ) AND HasBrokenLink = 1 " );
else $ret = DataObject :: get ( 'SiteTree' , " ClassName IN ( $classNames ) AND HasBrokenLink = 1 " );
return $ret ;
2009-10-11 02:08:06 +02:00
}
2010-05-28 04:23:10 +02:00
function columns () {
2009-10-11 02:08:06 +02:00
return array (
2010-05-28 04:23:10 +02:00
" Title " => array (
" title " => " Title " , // todo: use NestedTitle(2)
" link " => true ,
),
2009-10-11 02:08:06 +02:00
);
}
2010-05-28 04:23:10 +02:00
function parameterFields () {
2009-10-29 22:59:47 +01:00
return new FieldSet (
2010-10-04 07:32:22 +02:00
new CheckboxField ( 'OnLive' , _t ( 'SideReport.ParameterLiveCheckbox' , 'Check live site' ))
2009-10-29 22:59:47 +01:00
);
}
}
2010-04-23 02:11:32 +02:00
/**
* @ package cms
* @ subpackage content
*/
2010-05-28 04:23:10 +02:00
class SideReport_BrokenRedirectorPages extends SS_Report {
2009-10-29 22:59:47 +01:00
function title () {
return _t ( 'SideReport.BROKENREDIRECTORPAGES' , 'RedirectorPages pointing to deleted pages' );
}
function group () {
2010-10-04 07:32:22 +02:00
return _t ( 'SideReport.BrokenLinksGroupTitle' , " Broken links reports " );
2009-10-29 22:59:47 +01:00
}
2010-05-28 04:23:10 +02:00
function sourceRecords ( $params = null ) {
2009-10-29 22:59:47 +01:00
$classNames = " ' " . join ( " ',' " , ClassInfo :: subclassesFor ( 'RedirectorPage' )) . " ' " ;
if ( isset ( $_REQUEST [ 'OnLive' ])) $ret = Versioned :: get_by_stage ( 'SiteTree' , 'Live' , " ClassName IN ( $classNames ) AND HasBrokenLink = 1 " );
else $ret = DataObject :: get ( 'SiteTree' , " ClassName IN ( $classNames ) AND HasBrokenLink = 1 " );
return $ret ;
}
2009-10-11 02:08:06 +02:00
2010-05-28 04:23:10 +02:00
function columns () {
2009-10-29 22:59:47 +01:00
return array (
2010-05-28 04:23:10 +02:00
" Title " => array (
" title " => " Title " , // todo: use NestedTitle(2)
" link " => true ,
),
2009-10-29 22:59:47 +01:00
);
}
2010-05-28 04:23:10 +02:00
function parameterFields () {
2009-10-29 22:59:47 +01:00
return new FieldSet (
2010-10-04 07:32:22 +02:00
new CheckboxField ( 'OnLive' , _t ( 'SideReport.ParameterLiveCheckbox' , 'Check live site' ))
2009-10-29 22:59:47 +01:00
);
}
2009-10-11 02:08:06 +02:00
}