1 <?php
2
3 4 5 6 7 8 9
10 class SideReportView extends ViewableData {
11 protected $controller, $report;
12 protected $parameters;
13
14 function __construct($controller, $report) {
15 $this->controller = $controller;
16 $this->report = $report;
17 parent::__construct();
18 }
19
20 function group() {
21 return _t('SideReport.OtherGroupTitle', "Other");
22 }
23
24 function sort() {
25 return 0;
26 }
27
28 function setParameters($parameters) {
29 $this->parameters = $parameters;
30 }
31
32 function forTemplate() {
33 $records = $this->report->records($this->parameters);
34 $columns = $this->report->columns();
35
36 if($records && $records->Count()) {
37 $result = "<ul class=\"$this->class\">\n";
38
39 foreach($records as $record) {
40 $result .= "<li>\n";
41 foreach($columns as $source => $info) {
42 if(is_string($info)) $info = array('title' => $info);
43 $result .= $this->formatValue($record, $source, $info);
44 }
45 $result .= "\n</li>\n";
46 }
47 $result .= "</ul>\n";
48 } else {
49 $result = "<p class=\"message notice\">" .
50 sprintf(
51 _t('SideReport.REPEMPTY','The %s report is empty.',PR_MEDIUM,'%s is a report title'),
52 $this->report->title()
53 )
54 . "</p>";
55 }
56 return $result;
57 }
58
59 protected function formatValue($record, $source, $info) {
60
61
62 $val = Convert::raw2xml($record->$source);
63
64
65
66
67
68
69 if(!empty($info['casting'])) {
70 $val = TableListField::getCastedValue($val, $info['casting']);
71 }
72
73
74 if(!empty($info['formatting'])) {
75 $format = str_replace('$value', "__VAL__", $info['formatting']);
76 $format = preg_replace('/\$([A-Za-z0-9-_]+)/','$record->$1', $format);
77 $format = str_replace('__VAL__', '$val', $format);
78 $val = eval('return "' . $format . '";');
79 }
80
81 $prefix = empty($info['newline']) ? "" : "<br>";
82
83
84 $classClause = "";
85 if(isset($info['title'])) {
86 $cssClass = ereg_replace('[^A-Za-z0-9]+','',$info['title']);
87 $classClause = "class=\"$cssClass\"";
88 }
89
90 if(isset($info['link']) && $info['link']) {
91 $link = ($info['link'] === true) ? "admin/show/$record->ID" : $info['link'];
92 return $prefix . "<a $classClause href=\"$link\">$val</a>";
93 } else {
94 return $prefix . "<span $classClause>$val</span>";
95 }
96
97 }
98 }
99
100 101 102 103 104 105 106 107
108 class SideReportWrapper extends SS_ReportWrapper {
109 function columns() {
110 if($this->baseReport->hasMethod('sideReportColumns')) {
111 return $this->baseReport->sideReportColumns();
112 } else {
113 return parent::columns();
114 }
115 }
116 }
117
118
119
120 121 122 123 124 125
126 class SideReport_EmptyPages extends SS_Report {
127 function title() {
128 return _t('SideReport.EMPTYPAGES',"Pages with no content");
129 }
130
131 function group() {
132 return _t('SideReport.ContentGroupTitle', "Content reports");
133 }
134 function sort() {
135 return 100;
136 }
137 function sourceRecords($params = null) {
138 return DataObject::get("SiteTree", "\"ClassName\" != 'RedirectorPage' AND (\"Content\" = '' OR \"Content\" IS NULL OR \"Content\" LIKE '<p></p>' OR \"Content\" LIKE '<p> </p>')", '"Title"');
139 }
140 function columns() {
141 return array(
142 "Title" => array(
143 "title" => "Title",
144 "link" => true,
145 ),
146 );
147 }
148 }
149
150 151 152 153 154 155
156 class SideReport_RecentlyEdited extends SS_Report {
157 function title() {
158 return _t('SideReport.LAST2WEEKS',"Pages edited in the last 2 weeks");
159 }
160 function group() {
161 return _t('SideReport.ContentGroupTitle', "Content reports");
162 }
163 function sort() {
164 return 200;
165 }
166 function sourceRecords($params = null) {
167 $threshold = strtotime('-14 days', SS_Datetime::now()->Format('U'));
168 return DataObject::get("SiteTree", "\"SiteTree\".\"LastEdited\" > '".date("Y-m-d H:i:s", $threshold)."'", "\"SiteTree\".\"LastEdited\" DESC");
169 }
170 function columns() {
171 return array(
172 "Title" => array(
173 "title" => "Title",
174 "link" => true,
175 ),
176 );
177 }
178 }
179
180 181 182 183
184 class SideReport_ToDo extends SS_Report {
185 function title() {
186 return _t('SideReport.TODO',"Pages with To Do items");
187 }
188 function group() {
189 return _t('SideReport.ContentGroupTitle', "Content reports");
190 }
191 function sort() {
192 return 0;
193 }
194 function sourceRecords($params = null) {
195 return DataObject::get("SiteTree", "\"SiteTree\".\"ToDo\" IS NOT NULL AND \"SiteTree\".\"ToDo\" <> ''", "\"SiteTree\".\"LastEdited\" DESC");
196 }
197 function columns() {
198 return array(
199 "Title" => array(
200 "title" => "Title",
201 "link" => true,
202 ),
203 "ToDo" => array(
204 "title" => "ToDo",
205 "newline" => true,
206 ),
207 );
208 }
209 }
210
211 212 213 214 215 216
217 class SideReport_BrokenLinks extends SS_Report {
218 function title() {
219 return _t('SideReport.BROKENLINKS',"Pages with broken links");
220 }
221 function group() {
222 return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports");
223 }
224 function sourceRecords($params = null) {
225
226 $classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage'));
227 $classNames = "'".join("','", $classes)."'";
228
229 if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND HasBrokenLink = 1");
230 else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenLink = 1");
231 return $ret;
232 }
233 function columns() {
234 return array(
235 "Title" => array(
236 "title" => "Title",
237 "link" => true,
238 ),
239 );
240 }
241 function getParameterFields() {
242 return new FieldSet(
243 new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site'))
244 );
245 }
246 }
247
248 249 250 251 252 253 254
255 class SideReport_BrokenFiles extends SS_Report {
256 function title() {
257 return _t('SideReport.BROKENFILES',"Pages with broken files");
258 }
259 function group() {
260 return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports");
261 }
262 function sourceRecords($params = null) {
263
264 $classes = array_diff(ClassInfo::subclassesFor('SiteTree'), ClassInfo::subclassesFor('VirtualPage'), ClassInfo::subclassesFor('RedirectorPage'));
265 $classNames = "'".join("','", $classes)."'";
266
267 if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND HasBrokenFile = 1");
268 else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenFile = 1");
269 return $ret;
270 }
271 function columns() {
272 return array(
273 "Title" => array(
274 "title" => "Title",
275 "link" => true,
276 ),
277 );
278 }
279
280 function getParameterFields() {
281 return new FieldSet(
282 new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site'))
283 );
284 }
285
286 }
287
288 289 290 291
292 class SideReport_BrokenVirtualPages extends SS_Report {
293 function title() {
294 return _t('SideReport.BROKENVIRTUALPAGES', 'VirtualPages pointing to deleted pages');
295 }
296 function group() {
297 return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports");
298 }
299 function sourceRecords($params = null) {
300 $classNames = "'".join("','", ClassInfo::subclassesFor('VirtualPage'))."'";
301 if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND HasBrokenLink = 1");
302 else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenLink = 1");
303 return $ret;
304 }
305
306 function columns() {
307 return array(
308 "Title" => array(
309 "title" => "Title",
310 "link" => true,
311 ),
312 );
313 }
314
315 function getParameterFields() {
316 return new FieldSet(
317 new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site'))
318 );
319 }
320 }
321
322 323 324 325
326 class SideReport_BrokenRedirectorPages extends SS_Report {
327 function title() {
328 return _t('SideReport.BROKENREDIRECTORPAGES', 'RedirectorPages pointing to deleted pages');
329 }
330 function group() {
331 return _t('SideReport.BrokenLinksGroupTitle', "Broken links reports");
332 }
333 function sourceRecords($params = null) {
334 $classNames = "'".join("','", ClassInfo::subclassesFor('RedirectorPage'))."'";
335
336 if (isset($_REQUEST['OnLive'])) $ret = Versioned::get_by_stage('SiteTree', 'Live', "ClassName IN ($classNames) AND HasBrokenLink = 1");
337 else $ret = DataObject::get('SiteTree', "ClassName IN ($classNames) AND HasBrokenLink = 1");
338 return $ret;
339 }
340
341 function columns() {
342 return array(
343 "Title" => array(
344 "title" => "Title",
345 "link" => true,
346 ),
347 );
348 }
349
350 function getParameterFields() {
351 return new FieldSet(
352 new CheckboxField('OnLive', _t('SideReport.ParameterLiveCheckbox', 'Check live site'))
353 );
354 }
355 }
356
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-