1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alpha\Controller; |
4
|
|
|
|
5
|
|
|
use Alpha\Util\Logging\Logger; |
6
|
|
|
use Alpha\Util\Logging\KPI; |
7
|
|
|
use Alpha\Util\Config\ConfigProvider; |
8
|
|
|
use Alpha\Util\Security\SecurityUtils; |
9
|
|
|
use Alpha\Util\Extension\TCPDFFacade; |
10
|
|
|
use Alpha\Util\Http\Request; |
11
|
|
|
use Alpha\Util\Http\Response; |
12
|
|
|
use Alpha\Util\Service\ServiceFactory; |
13
|
|
|
use Alpha\Util\File\FileUtils; |
14
|
|
|
use Alpha\Model\Article; |
15
|
|
|
use Alpha\Model\ArticleComment; |
16
|
|
|
use Alpha\Model\Type\Relation; |
17
|
|
|
use Alpha\View\View; |
18
|
|
|
use Alpha\View\ViewState; |
19
|
|
|
use Alpha\View\Widget\Button; |
20
|
|
|
use Alpha\Exception\SecurityException; |
21
|
|
|
use Alpha\Exception\AlphaException; |
22
|
|
|
use Alpha\Exception\RecordNotFoundException; |
23
|
|
|
use Alpha\Exception\IllegalArguementException; |
24
|
|
|
use Alpha\Exception\ResourceNotFoundException; |
25
|
|
|
use Alpha\Exception\FileNotFoundException; |
26
|
|
|
use Alpha\Model\ActiveRecord; |
27
|
|
|
use Alpha\Controller\Front\FrontController; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Controller used handle Article objects. |
31
|
|
|
* |
32
|
|
|
* @since 1.0 |
33
|
|
|
* |
34
|
|
|
* @author John Collins <[email protected]> |
35
|
|
|
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License |
36
|
|
|
* @copyright Copyright (c) 2018, John Collins (founder of Alpha Framework). |
37
|
|
|
* All rights reserved. |
38
|
|
|
* |
39
|
|
|
* <pre> |
40
|
|
|
* Redistribution and use in source and binary forms, with or |
41
|
|
|
* without modification, are permitted provided that the |
42
|
|
|
* following conditions are met: |
43
|
|
|
* |
44
|
|
|
* * Redistributions of source code must retain the above |
45
|
|
|
* copyright notice, this list of conditions and the |
46
|
|
|
* following disclaimer. |
47
|
|
|
* * Redistributions in binary form must reproduce the above |
48
|
|
|
* copyright notice, this list of conditions and the |
49
|
|
|
* following disclaimer in the documentation and/or other |
50
|
|
|
* materials provided with the distribution. |
51
|
|
|
* * Neither the name of the Alpha Framework nor the names |
52
|
|
|
* of its contributors may be used to endorse or promote |
53
|
|
|
* products derived from this software without specific |
54
|
|
|
* prior written permission. |
55
|
|
|
* |
56
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
57
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
58
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
59
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
60
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
61
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
62
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
63
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
64
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
65
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
66
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
67
|
|
|
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
68
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
69
|
|
|
* </pre> |
70
|
|
|
*/ |
71
|
|
|
class ArticleController extends ActiveRecordController implements ControllerInterface |
72
|
|
|
{ |
73
|
|
|
/** |
74
|
|
|
* The Article record object that this controller is currently working with. |
75
|
|
|
* |
76
|
|
|
* @var \Alpha\Model\Article |
77
|
|
|
* |
78
|
|
|
* @since 3.0 |
79
|
|
|
*/ |
80
|
|
|
protected $record = null; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Trace logger. |
84
|
|
|
* |
85
|
|
|
* @var \Alpha\Util\Logging\Logger |
86
|
|
|
* |
87
|
|
|
* @since 1.0 |
88
|
|
|
*/ |
89
|
|
|
private static $logger = null; |
|
|
|
|
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* constructor to set up the object. |
93
|
|
|
* |
94
|
|
|
* @since 1.0 |
95
|
|
|
*/ |
96
|
|
|
public function __construct() |
97
|
|
|
{ |
98
|
|
|
self::$logger = new Logger('ArticleController'); |
99
|
|
|
self::$logger->debug('>>__construct()'); |
100
|
|
|
|
101
|
|
|
// ensure that the super class constructor is called, indicating the rights group |
102
|
|
|
parent::__construct('Public'); |
103
|
|
|
|
104
|
|
|
self::$logger->debug('<<__construct'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Handle GET requests. |
109
|
|
|
* |
110
|
|
|
* @param \Alpha\Util\Http\Request |
111
|
|
|
* |
112
|
|
|
* @return \Alpha\Util\Http\Response |
113
|
|
|
* |
114
|
|
|
* @throws \Alpha\Exception\ResourceNotFoundException |
115
|
|
|
* |
116
|
|
|
* @since 1.0 |
117
|
|
|
*/ |
118
|
|
|
public function doGET($request) |
119
|
|
|
{ |
120
|
|
|
self::$logger->debug('>>doGET($request=['.var_export($request, true).'])'); |
121
|
|
|
|
122
|
|
|
$config = ConfigProvider::getInstance(); |
123
|
|
|
|
124
|
|
|
$params = $request->getParams(); |
125
|
|
|
|
126
|
|
|
$body = ''; |
127
|
|
|
|
128
|
|
|
// handle requests for PDFs |
129
|
|
|
if (isset($params['title']) && (isset($params['pdf']) || $request->getHeader('Accept') == 'application/pdf')) { |
130
|
|
|
try { |
131
|
|
|
$title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
132
|
|
|
|
133
|
|
|
if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { |
134
|
|
|
$record = new $params['ActiveRecordType']; |
135
|
|
|
} else { |
136
|
|
|
$record = new Article(); |
137
|
|
|
} |
138
|
|
|
$record->loadByAttribute('title', $title); |
139
|
|
|
$this->record = $record; |
140
|
|
|
|
141
|
|
|
ActiveRecord::disconnect(); |
142
|
|
|
|
143
|
|
|
$pdf = new TCPDFFacade($record); |
144
|
|
|
$pdfData = $pdf->getPDFData(); |
145
|
|
|
$pdfDownloadName = str_replace(' ', '-', $record->get('title').'.pdf'); |
146
|
|
|
|
147
|
|
|
$headers = array( |
148
|
|
|
'Pragma' => 'public', |
149
|
|
|
'Expires' => 0, |
150
|
|
|
'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', |
151
|
|
|
'Content-Transfer-Encoding' => 'binary', |
152
|
|
|
'Content-Type' => 'application/pdf', |
153
|
|
|
'Content-Length' => strlen($pdfData), |
154
|
|
|
'Content-Disposition' => 'attachment; filename="'.$pdfDownloadName.'";', |
155
|
|
|
); |
156
|
|
|
|
157
|
|
|
return new Response(200, $pdfData, $headers); |
158
|
|
|
} catch (IllegalArguementException $e) { |
159
|
|
|
self::$logger->error($e->getMessage()); |
160
|
|
|
throw new ResourceNotFoundException($e->getMessage()); |
161
|
|
|
} catch (RecordNotFoundException $e) { |
162
|
|
|
self::$logger->error($e->getMessage()); |
163
|
|
|
throw new ResourceNotFoundException($e->getMessage()); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
// view edit article requests |
168
|
|
|
if ((isset($params['view']) && $params['view'] == 'edit') && (isset($params['title']) || isset($params['ActiveRecordID']))) { |
169
|
|
|
if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { |
170
|
|
|
$record = new $params['ActiveRecordType']; |
171
|
|
|
} else { |
172
|
|
|
$record = new Article(); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
try { |
176
|
|
|
if (isset($params['title'])) { |
177
|
|
|
$title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
178
|
|
|
$record->loadByAttribute('title', $title); |
179
|
|
|
} else { |
180
|
|
|
$record->load($params['ActiveRecordID']); |
181
|
|
|
} |
182
|
|
|
} catch (RecordNotFoundException $e) { |
183
|
|
|
self::$logger->warn($e->getMessage()); |
184
|
|
|
$body .= View::renderErrorPage(404, 'Failed to find the requested article!'); |
185
|
|
|
|
186
|
|
|
return new Response(404, $body, array('Content-Type' => 'text/html')); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
ActiveRecord::disconnect(); |
190
|
|
|
|
191
|
|
|
$this->record = $record; |
192
|
|
|
$view = View::getInstance($record); |
193
|
|
|
|
194
|
|
|
// set up the title and meta details |
195
|
|
|
$this->setTitle($record->get('title').' (editing)'); |
196
|
|
|
$this->setDescription('Page to edit '.$record->get('title').'.'); |
197
|
|
|
$this->setKeywords('edit,article'); |
198
|
|
|
|
199
|
|
|
$body .= View::displayPageHead($this); |
200
|
|
|
|
201
|
|
|
$message = $this->getStatusMessage(); |
202
|
|
|
if (!empty($message)) { |
203
|
|
|
$body .= $message; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
$body .= $view->editView(array('URI' => $request->getURI())); |
207
|
|
|
$body .= View::renderDeleteForm($request->getURI()); |
208
|
|
|
|
209
|
|
|
$body .= View::displayPageFoot($this); |
210
|
|
|
self::$logger->debug('<<doGET'); |
211
|
|
|
|
212
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
// handle requests for viewing articles |
216
|
|
|
if (isset($params['title']) || isset($params['ActiveRecordID'])) { |
217
|
|
|
$KDP = new KPI('viewarticle'); |
218
|
|
|
if (isset($params['ActiveRecordType']) && class_exists($params['ActiveRecordType'])) { |
219
|
|
|
$record = new $params['ActiveRecordType']; |
220
|
|
|
} else { |
221
|
|
|
$record = new Article(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
try { |
225
|
|
|
if (isset($params['title'])) { |
226
|
|
|
$title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
227
|
|
|
|
228
|
|
|
$record->loadByAttribute('title', $title, false, array('ID', 'version_num', 'created_ts', 'updated_ts', 'title', 'author', 'published', 'content', 'headerContent')); |
229
|
|
|
} else { |
230
|
|
|
$record->load($params['ActiveRecordID']); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
if (!$record->get('published')) { |
234
|
|
|
throw new RecordNotFoundException('Attempted to load an article which is not published yet'); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
$record->set('tags', $record->getID()); |
238
|
|
|
} catch (IllegalArguementException $e) { |
239
|
|
|
self::$logger->warn($e->getMessage()); |
240
|
|
|
throw new ResourceNotFoundException('The file that you have requested cannot be found!'); |
241
|
|
|
} catch (RecordNotFoundException $e) { |
242
|
|
|
self::$logger->warn($e->getMessage()); |
243
|
|
|
throw new ResourceNotFoundException('The article that you have requested cannot be found!'); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
$this->record = $record; |
247
|
|
|
$this->setTitle($record->get('title')); |
248
|
|
|
$this->setDescription($record->get('description')); |
249
|
|
|
|
250
|
|
|
$recordView = View::getInstance($record); |
251
|
|
|
|
252
|
|
|
$body .= View::displayPageHead($this); |
253
|
|
|
|
254
|
|
|
$message = $this->getStatusMessage(); |
255
|
|
|
if (!empty($message)) { |
256
|
|
|
$body .= $message; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
$body .= $recordView->markdownView(); |
260
|
|
|
|
261
|
|
|
$body .= View::displayPageFoot($this); |
262
|
|
|
|
263
|
|
|
$KDP->log(); |
264
|
|
|
|
265
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
// handle requests to view an article stored in a file |
269
|
|
|
if (isset($params['file'])) { |
270
|
|
|
try { |
271
|
|
|
$record = new Article(); |
272
|
|
|
|
273
|
|
|
// just checking to see if the file path is absolute or not |
274
|
|
|
if (mb_substr($params['file'], 0, 1) == '/') { |
275
|
|
|
$record->loadContentFromFile($params['file']); |
276
|
|
|
} else { |
277
|
|
|
$record->loadContentFromFile($config->get('app.root').'docs/'.$params['file']); |
278
|
|
|
} |
279
|
|
|
} catch (IllegalArguementException $e) { |
280
|
|
|
self::$logger->error($e->getMessage()); |
281
|
|
|
throw new ResourceNotFoundException($e->getMessage()); |
282
|
|
|
} catch (FileNotFoundException $e) { |
283
|
|
|
self::$logger->warn($e->getMessage().' File path is ['.$params['file'].']'); |
284
|
|
|
throw new ResourceNotFoundException('Failed to load the requested article from the file system!'); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
$this->record = $record; |
288
|
|
|
$this->setTitle($record->get('title')); |
289
|
|
|
|
290
|
|
|
$recordView = View::getInstance($record); |
291
|
|
|
|
292
|
|
|
$body .= View::displayPageHead($this, false); |
|
|
|
|
293
|
|
|
|
294
|
|
|
$body .= $recordView->markdownView(); |
295
|
|
|
|
296
|
|
|
$body .= View::displayPageFoot($this); |
297
|
|
|
|
298
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
// handle requests to view a list of articles |
302
|
|
|
if (isset($params['start'])) { |
303
|
|
|
return parent::doGET($request); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
// create a new article requests |
307
|
|
|
$record = new Article(); |
308
|
|
|
$view = View::getInstance($record); |
309
|
|
|
|
310
|
|
|
// set up the title and meta details |
311
|
|
|
$this->setTitle('Creating article'); |
312
|
|
|
$this->setDescription('Page to create a new article.'); |
313
|
|
|
$this->setKeywords('create,article'); |
314
|
|
|
|
315
|
|
|
$body .= View::displayPageHead($this); |
316
|
|
|
|
317
|
|
|
$message = $this->getStatusMessage(); |
318
|
|
|
if (!empty($message)) { |
319
|
|
|
$body .= $message; |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
$fields = array('formAction' => $this->request->getURI()); |
323
|
|
|
$body .= $view->createView($fields); |
324
|
|
|
|
325
|
|
|
$body .= View::displayPageFoot($this); |
326
|
|
|
self::$logger->debug('<<doGET'); |
327
|
|
|
|
328
|
|
|
return new Response(200, $body, array('Content-Type' => 'text/html')); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
/** |
332
|
|
|
* Method to handle PUT requests. |
333
|
|
|
* |
334
|
|
|
* @param \Alpha\Util\Http\Request |
335
|
|
|
* |
336
|
|
|
* @return \Alpha\Util\Http\Response |
337
|
|
|
* |
338
|
|
|
* @since 1.0 |
339
|
|
|
*/ |
340
|
|
|
public function doPUT($request) |
341
|
|
|
{ |
342
|
|
|
self::$logger->debug('>>doPUT($request=['.var_export($request, true).'])'); |
343
|
|
|
|
344
|
|
|
$config = ConfigProvider::getInstance(); |
345
|
|
|
|
346
|
|
|
$params = $request->getParams(); |
347
|
|
|
|
348
|
|
|
if (!isset($params['ActiveRecordID']) && isset($params['title'])) { |
349
|
|
|
$title = str_replace($config->get('cms.url.title.separator'), ' ', $params['title']); |
350
|
|
|
$record = new Article(); |
351
|
|
|
$record->loadByAttribute('title', $title); |
352
|
|
|
$params['ActiveRecordID'] = $record->getID(); |
353
|
|
|
} |
354
|
|
|
$request->addParams(array('ActiveRecordType' => 'Alpha\Model\Article', 'ActiveRecordID' => $params['ActiveRecordID'])); |
355
|
|
|
$response = parent::doPUT($request); |
356
|
|
|
|
357
|
|
|
if ($this->getNextJob() != '') { |
358
|
|
|
$response->redirect($this->getNextJob()); |
359
|
|
|
} else { |
360
|
|
|
if ($this->request->isSecureURI()) { |
361
|
|
|
$response->redirect(FrontController::generateSecureURL('act=Alpha\\Controller\\ActiveRecordController&ActiveRecordType=Alpha\Model\Article&ActiveRecordID='.$this->record->getID().'&view=edit')); |
362
|
|
|
} else { |
363
|
|
|
$title = str_replace(' ', $config->get('cms.url.title.separator'), $this->record->get('title')); |
364
|
|
|
$response->redirect($config->get('app.url').'/a/'.$title.'/edit'); |
365
|
|
|
} |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
self::$logger->debug('<<doPUT'); |
369
|
|
|
|
370
|
|
|
return $response; |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* Method to handle DELETE requests. |
375
|
|
|
* |
376
|
|
|
* @param \Alpha\Util\Http\Request |
377
|
|
|
* |
378
|
|
|
* @return \Alpha\Util\Http\Response |
379
|
|
|
* |
380
|
|
|
* @since 2.0 |
381
|
|
|
*/ |
382
|
|
|
public function doDELETE($request) |
383
|
|
|
{ |
384
|
|
|
self::$logger->debug('>>doDELETE($request=['.var_export($request, true).'])'); |
385
|
|
|
|
386
|
|
|
$this->setUnitOfWork(array()); |
387
|
|
|
|
388
|
|
|
self::$logger->debug('<<doDELETE'); |
389
|
|
|
|
390
|
|
|
return parent::doDELETE($request); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Renders custom HTML header content. |
395
|
|
|
* |
396
|
|
|
* @return string |
397
|
|
|
* |
398
|
|
|
* @since 1.0 |
399
|
|
|
*/ |
400
|
|
|
public function during_displayPageHead_callback() |
401
|
|
|
{ |
402
|
|
|
$config = ConfigProvider::getInstance(); |
403
|
|
|
|
404
|
|
|
$params = $this->request->getParams(); |
405
|
|
|
|
406
|
|
|
$html = ''; |
407
|
|
|
|
408
|
|
|
if ((isset($params['view']) && ($params['view'] == 'edit' || $params['view'] == 'create')) || (isset($params['ActiveRecordType']) && !isset($params['ActiveRecordID']))) { |
409
|
|
|
$fieldid = ($config->get('security.encrypt.http.fieldnames') ? 'text_field_'.base64_encode(SecurityUtils::encrypt('content')).'_0' : 'text_field_content_0'); |
410
|
|
|
|
411
|
|
|
$html .= ' |
412
|
|
|
<script type="text/javascript"> |
413
|
|
|
$(document).ready(function() { |
414
|
|
|
$(\'[id="'.$fieldid.'"]\').pagedownBootstrap({ |
415
|
|
|
\'sanatize\': false |
416
|
|
|
}); |
417
|
|
|
}); |
418
|
|
|
</script>'; |
419
|
|
|
} elseif (isset($params['view']) && $params['view'] == 'print') { |
420
|
|
|
$html .= '<link rel="StyleSheet" type="text/css" href="'.$config->get('app.url').'/css/print.css">'; |
421
|
|
|
} |
422
|
|
|
|
423
|
|
|
if ($this->record instanceof Article) { |
424
|
|
|
$headerContent = $this->record->get('headerContent'); |
425
|
|
|
if ($headerContent != '') { |
426
|
|
|
$html .= $headerContent; |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
return $html; |
431
|
|
|
} |
432
|
|
|
|
433
|
|
|
/** |
434
|
|
|
* Callback that inserts the CMS level header. |
435
|
|
|
* |
436
|
|
|
* @return string |
437
|
|
|
* |
438
|
|
|
* @since 1.0 |
439
|
|
|
*/ |
440
|
|
|
public function insert_CMSDisplayStandardHeader_callback() |
441
|
|
|
{ |
442
|
|
|
if ($this->request->getParam('token') != null) { |
443
|
|
|
return ''; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
if (!$this->record instanceof Article) { |
447
|
|
|
return ''; |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
$config = ConfigProvider::getInstance(); |
451
|
|
|
|
452
|
|
|
$html = ''; |
453
|
|
|
|
454
|
|
|
if ($config->get('cms.display.standard.header')) { |
455
|
|
|
$html .= '<p><a href="'.$config->get('app.url').'">'.$config->get('app.title').'</a> '; |
456
|
|
|
$html .= 'Date Added: <em>'.$this->record->getCreateTS()->getDate().'</em> '; |
457
|
|
|
$html .= 'Last Updated: <em>'.$this->record->getUpdateTS()->getDate().'</em> '; |
458
|
|
|
$html .= 'Revision: <em>'.$this->record->getVersion().'</em></p>'; |
459
|
|
|
} |
460
|
|
|
|
461
|
|
|
$html .= $config->get('cms.header'); |
462
|
|
|
|
463
|
|
|
return $html; |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
/** |
467
|
|
|
* Callback used to render footer content, including comments, votes and print/PDF buttons when |
468
|
|
|
* enabled to do so. |
469
|
|
|
* |
470
|
|
|
* @return string |
471
|
|
|
* |
472
|
|
|
* @since 1.0 |
473
|
|
|
*/ |
474
|
|
|
public function before_displayPageFoot_callback() |
475
|
|
|
{ |
476
|
|
|
$config = ConfigProvider::getInstance(); |
477
|
|
|
$sessionProvider = $config->get('session.provider.name'); |
478
|
|
|
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
479
|
|
|
|
480
|
|
|
$html = ''; |
481
|
|
|
$params = $this->request->getParams(); |
482
|
|
|
|
483
|
|
|
// this will ensure that direct requests to ActiveRecordController will be re-directed here. |
484
|
|
|
if (isset($this->record) && !$this->record->isTransient()) { |
485
|
|
|
$this->setName($config->get('app.url').$this->request->getURI()); |
486
|
|
|
$this->setUnitOfWork(array($config->get('app.url').$this->request->getURI(), $config->get('app.url').$this->request->getURI())); |
487
|
|
|
} else { |
488
|
|
|
$this->setUnitOfWork(array()); |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
if ($this->record != null) { |
492
|
|
|
if (isset($params['view']) && $params['view'] == 'detailed') { |
493
|
|
|
if ($config->get('cms.display.comments')) { |
494
|
|
|
$html .= $this->renderComments(); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
if ($config->get('cms.display.tags')) { |
498
|
|
|
$html .= $this->renderTags(); |
499
|
|
|
} |
500
|
|
|
|
501
|
|
|
if ($config->get('cms.display.votes')) { |
502
|
|
|
$rating = $this->record->getArticleScore(); |
503
|
|
|
$votes = $this->record->getArticleVotes(); |
504
|
|
|
$html .= '<p>Average Article User Rating: <strong>'.$rating.'</strong> out of 10 (based on <strong>'.count($votes).'</strong> votes)</p>'; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
if (!$this->record->checkUserVoted() && $config->get('cms.voting.allowed')) { |
508
|
|
|
$html .= $this->renderVotes(); |
509
|
|
|
} |
510
|
|
|
|
511
|
|
|
ActiveRecord::disconnect(); |
512
|
|
|
|
513
|
|
|
if ($config->get('cms.allow.print.versions')) { |
514
|
|
|
$html .= ' '; |
515
|
|
|
$temp = new Button("window.open('".$this->record->get('printURL')."')", 'Open Printer Version', 'printBut'); |
516
|
|
|
$html .= $temp->render(); |
517
|
|
|
} |
518
|
|
|
|
519
|
|
|
$html .= ' '; |
520
|
|
|
if ($config->get('cms.allow.pdf.versions')) { |
521
|
|
|
$html .= ' '; |
522
|
|
|
$temp = new Button("document.location = '".FrontController::generateSecureURL("act=Alpha\Controller\ArticleController&mode=pdf&title=".$this->record->get('title'))."';", 'Open PDF Version', 'pdfBut'); |
523
|
|
|
$html .= $temp->render(); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
// render edit button for admins only |
527
|
|
|
if ($session->get('currentUser') instanceof \Alpha\Model\Person && $session->get('currentUser')->inGroup('Admin')) { |
528
|
|
|
$html .= ' '; |
529
|
|
|
$button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ArticleController&mode=edit&ActiveRecordID='.$this->record->getID())."'", 'Edit', 'editBut'); |
530
|
|
|
$html .= $button->render(); |
531
|
|
|
} |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
if ($config->get('cms.display.standard.footer')) { |
535
|
|
|
$html .= $this->renderStandardFooter(); |
536
|
|
|
} |
537
|
|
|
} |
538
|
|
|
|
539
|
|
|
$html .= $config->get('cms.footer'); |
540
|
|
|
|
541
|
|
|
return $html; |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* Method for displaying the user comments for the article. |
546
|
|
|
* |
547
|
|
|
* @return string |
548
|
|
|
* |
549
|
|
|
* @since 1.0 |
550
|
|
|
*/ |
551
|
|
|
private function renderComments() |
552
|
|
|
{ |
553
|
|
|
$config = ConfigProvider::getInstance(); |
554
|
|
|
$sessionProvider = $config->get('session.provider.name'); |
555
|
|
|
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
556
|
|
|
|
557
|
|
|
$html = ''; |
558
|
|
|
|
559
|
|
|
$comments = $this->record->getArticleComments(); |
560
|
|
|
$commentsCount = count($comments); |
561
|
|
|
|
562
|
|
|
$URL = FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType=Alpha\Model\ArticleComment'); |
563
|
|
|
|
564
|
|
|
$fields = array('formAction' => $URL); |
565
|
|
|
|
566
|
|
|
if ($config->get('cms.display.comments') && $commentsCount > 0) { |
567
|
|
|
$html .= '<h2>There are ['.$commentsCount.'] user comments for this article</h2>'; |
568
|
|
|
|
569
|
|
|
for ($i = 0; $i < $commentsCount; ++$i) { |
570
|
|
|
$view = View::getInstance($comments[$i]); |
571
|
|
|
$html .= $view->markdownView($fields); |
572
|
|
|
} |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
if ($session->get('currentUser') != null && $config->get('cms.comments.allowed')) { |
576
|
|
|
$comment = new ArticleComment(); |
577
|
|
|
$comment->set('articleID', $this->record->getID()); |
578
|
|
|
|
579
|
|
|
$view = View::getInstance($comment); |
580
|
|
|
$html .= $view->createView($fields); |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
return $html; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
/** |
587
|
|
|
* Method for displaying the tags for the article. |
588
|
|
|
* |
589
|
|
|
* @return string |
590
|
|
|
* |
591
|
|
|
* @since 3.0 |
592
|
|
|
*/ |
593
|
|
|
private function renderTags() |
594
|
|
|
{ |
595
|
|
|
$config = ConfigProvider::getInstance(); |
596
|
|
|
$relation = $this->record->getPropObject('tags'); |
597
|
|
|
|
598
|
|
|
$html = ''; |
599
|
|
|
|
600
|
|
|
if ($relation instanceof Relation) { |
601
|
|
|
$tags = $relation->getRelated(); |
602
|
|
|
|
603
|
|
|
if (count($tags) > 0) { |
604
|
|
|
$html .= '<p>Tags:'; |
605
|
|
|
|
606
|
|
|
foreach ($tags as $tag) { |
607
|
|
|
$html .= ' <a href="'.$config->get('app.url').'/search/'.$tag->get('content').'">'.$tag->get('content').'</a>'; |
608
|
|
|
} |
609
|
|
|
$html .= '</p>'; |
610
|
|
|
} |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
return $html; |
614
|
|
|
} |
615
|
|
|
|
616
|
|
|
/** |
617
|
|
|
* Method for displaying the votes for the article. |
618
|
|
|
* |
619
|
|
|
* @return string |
620
|
|
|
* |
621
|
|
|
* @since 3.0 |
622
|
|
|
*/ |
623
|
|
|
private function renderVotes() |
624
|
|
|
{ |
625
|
|
|
$config = ConfigProvider::getInstance(); |
626
|
|
|
$sessionProvider = $config->get('session.provider.name'); |
627
|
|
|
$session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); |
628
|
|
|
|
629
|
|
|
$URL = FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType=Alpha\Model\ArticleVote'); |
630
|
|
|
$html = '<form action="'.$URL.'" method="post" accept-charset="UTF-8">'; |
631
|
|
|
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('score')) : 'score'); |
632
|
|
|
$html .= '<p>Please rate this article from 1-10 (10 being the best):'. |
633
|
|
|
'<select name="'.$fieldname.'">'. |
634
|
|
|
'<option value="1">1'. |
635
|
|
|
'<option value="2">2'. |
636
|
|
|
'<option value="3">3'. |
637
|
|
|
'<option value="4">4'. |
638
|
|
|
'<option value="5">5'. |
639
|
|
|
'<option value="6">6'. |
640
|
|
|
'<option value="7">7'. |
641
|
|
|
'<option value="8">8'. |
642
|
|
|
'<option value="9">9'. |
643
|
|
|
'<option value="10">10'. |
644
|
|
|
'</select></p> '; |
645
|
|
|
|
646
|
|
|
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('articleID')) : 'articleID'); |
647
|
|
|
$html .= '<input type="hidden" name="'.$fieldname.'" value="'.$this->record->getID().'"/>'; |
648
|
|
|
|
649
|
|
|
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('personID')) : 'personID'); |
650
|
|
|
$html .= '<input type="hidden" name="'.$fieldname.'" value="'.$session->get('currentUser')->getID().'"/>'; |
651
|
|
|
|
652
|
|
|
$fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('statusMessage')) : 'statusMessage'); |
653
|
|
|
$html .= '<input type="hidden" name="'.$fieldname.'" value="Thank you for rating this article!"/>'; |
654
|
|
|
|
655
|
|
|
$temp = new Button('submit', 'Vote!', 'voteBut'); |
656
|
|
|
$html .= $temp->render(); |
657
|
|
|
|
658
|
|
|
$html .= View::renderSecurityFields(); |
659
|
|
|
$html .= '<form>'; |
660
|
|
|
|
661
|
|
|
return $html; |
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
/** |
665
|
|
|
* Method for displaying the standard CMS footer for the article. |
666
|
|
|
* |
667
|
|
|
* @return string |
668
|
|
|
* |
669
|
|
|
* @since 3.0 |
670
|
|
|
*/ |
671
|
|
|
private function renderStandardFooter() |
672
|
|
|
{ |
673
|
|
|
$html = '<p>Article URL: <a href="'.$this->record->get('URL').'">'.$this->record->get('URL').'</a><br>'; |
674
|
|
|
$html .= 'Title: '.$this->record->get('title').'<br>'; |
675
|
|
|
$html .= 'Author: '.$this->record->get('author').'</p>'; |
676
|
|
|
|
677
|
|
|
return $html; |
678
|
|
|
} |
679
|
|
|
} |
680
|
|
|
|