1: <?php
2:
3:
4: if(!isset($config)) {
5: require_once '../util/AlphaConfig.inc';
6: $config = AlphaConfig::getInstance();
7:
8: require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
9: }
10:
11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: class ViewArticle extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: protected $BO;
64:
65: 66: 67: 68: 69: 70:
71: private static $logger = null;
72:
73: 74: 75: 76: 77:
78: public function __construct() {
79: self::$logger = new Logger('ViewArticle');
80: self::$logger->debug('>>__construct()');
81:
82: global $config;
83:
84:
85: parent::__construct('Public');
86:
87: $this->BO = new ArticleObject();
88:
89: self::$logger->debug('<<__construct');
90: }
91:
92: 93: 94: 95: 96: 97: 98:
99: public function doGET($params) {
100: global $config;
101:
102: try{
103:
104: if($config->get('app.force.mod.rewrite.uls') && basename($_SERVER['PHP_SELF']) == 'ViewArticle.php') {
105:
106: header('HTTP/1.1 301 Moved Permanently');
107:
108: header('Location: '.$this->BO->get('URL'));
109:
110:
111: exit;
112: }
113:
114:
115: if (isset($params['oid']) && AlphaValidator::isInteger($params['oid'])) {
116: $this->BO->load($params['oid']);
117:
118: $BOView = AlphaView::getInstance($this->BO);
119:
120:
121: $this->setTitle($this->BO->get('title'));
122: $this->setDescription($this->BO->get('description'));
123:
124: echo AlphaView::displayPageHead($this);
125:
126: echo $BOView->markdownView();
127: }else{
128: throw new IllegalArguementException('No article available to view!');
129: }
130: }catch(IllegalArguementException $e) {
131: self::$logger->error($e->getMessage());
132: throw new ResourceNotFoundException($e->getMessage());
133: }catch(BONotFoundException $e) {
134: self::$logger->warn($e->getMessage());
135: throw new ResourceNotFoundException('The article that you have requested cannot be found!');
136: }
137:
138: echo AlphaView::displayPageFoot($this);
139: }
140:
141: 142: 143: 144: 145: 146:
147: public function during_displayPageHead_callback() {
148: return $this->BO->get('headerContent');
149: }
150:
151: 152: 153: 154: 155: 156:
157: public function insert_CMSDisplayStandardHeader_callback() {
158: global $config;
159:
160: $html = '';
161:
162: if($config->get('cms.display.standard.header')) {
163: $html.= '<p><a href="'.$config->get('app.url').'">'.$config->get('app.title').'</a> ';
164: $html.= 'Date Added: <em>'.$this->BO->getCreateTS()->getDate().'</em> ';
165: $html.= 'Last Updated: <em>'.$this->BO->getUpdateTS()->getDate().'</em> ';
166: $html.= 'Revision: <em>'.$this->BO->getVersion().'</em></p>';
167: }
168:
169: $html.= $config->get('cms.header');
170:
171: return $html;
172: }
173:
174: 175: 176: 177: 178: 179: 180:
181: public function () {
182: global $config;
183:
184: $html = '';
185:
186: if($config->get('cms.display.comments'))
187: $html .= $this->renderComments();
188:
189: if($config->get('cms.display.tags')) {
190: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
191:
192: if(count($tags) > 0) {
193: $html .= '<p>Tags:';
194:
195: foreach($tags as $tag)
196: $html .= ' <a href="'.$config->get('app.url').'search/q/'.$tag->get('content').'">'.$tag->get('content').'</a>';
197: $html .= '</p>';
198: }
199: }
200:
201: if($config->get('cms.display.votes')) {
202: $rating = $this->BO->getArticleScore();
203: $votes = $this->BO->getArticleVotes();
204: $html .= '<p>Average Article User Rating: <strong>'.$rating.'</strong> out of 10 (based on <strong>'.count($votes).'</strong> votes)</p>';
205: }
206:
207: if(!$this->BO->checkUserVoted() && $config->get('cms.voting.allowed')) {
208: $html .= '<form action="'.$_SERVER['REQUEST_URI'].'" method="post">';
209: $html .= '<p>Please rate this article from 1-10 (10 being the best):' .
210: '<select name="user_vote">' .
211: '<option value="1">1' .
212: '<option value="2">2' .
213: '<option value="3">3' .
214: '<option value="4">4' .
215: '<option value="5">5' .
216: '<option value="6">6' .
217: '<option value="7">7' .
218: '<option value="8">8' .
219: '<option value="9">9' .
220: '<option value="10">10' .
221: '</select></p> ';
222: $temp = new Button('submit','Vote!','voteBut');
223: $html .= $temp->render();
224:
225: $html .= AlphaView::renderSecurityFields();
226: $html .= '<form>';
227: }
228:
229: AlphaDAO::disconnect();
230:
231: if($config->get('cms.allow.print.versions')) {
232: $html .= ' ';
233: $temp = new Button("window.open('".$this->BO->get('printURL')."')",'Open Printer Version','printBut');
234: $html .= $temp->render();
235: }
236:
237: $html .= ' ';
238: if($config->get('cms.allow.pdf.versions')) {
239: $html .= ' ';
240: $temp = new Button("document.location = '".FrontController::generateSecureURL("act=ViewArticlePDF&title=".$this->BO->get("title"))."';",'Open PDF Version','pdfBut');
241: $html .= $temp->render();
242: }
243:
244:
245: if (isset($_SESSION['currentUser']) && $_SESSION['currentUser']->inGroup('Admin')) {
246: $html .= ' ';
247: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Edit&bo='.get_class($this->BO).'&oid='.$this->BO->getID())."'",'Edit','editBut');
248: $html .= $button->render();
249: }
250:
251: if($config->get('cms.display.standard.footer')) {
252: $html .= '<p>Article URL: <a href="http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"].'">http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"].'</a><br>';
253: $html .= 'Title: '.$this->BO->get('title').'<br>';
254: $html .= 'Author: '.$this->BO->get('author').'</p>';
255: }
256:
257: $html .= $config->get('cms.footer');
258:
259: return $html;
260: }
261:
262: 263: 264: 265: 266: 267:
268: public function doPOST($params) {
269: global $config;
270:
271: try {
272:
273: if(!$this->checkSecurityFields())
274: throw new SecurityException('This page cannot accept post data from remote servers!');
275:
276:
277: if(isset($params['voteBut']) && !$this->BO->checkUserVoted()) {
278: $vote = new ArticleVoteObject();
279:
280: if(isset($params['oid'])) {
281: $vote->set('articleOID', $params['oid']);
282: }else{
283:
284: if (isset($params['title'])) {
285: $title = str_replace('_', ' ', $params['title']);
286: }else{
287: throw new IllegalArguementException('Could not load the article as a title or OID was not supplied!');
288: }
289:
290: $this->BO = new ArticleObject();
291: $this->BO->loadByAttribute('title', $title);
292: $vote->set('articleOID', $this->BO->getOID());
293: }
294:
295: $vote->set('personOID', $_SESSION['currentUser']->getID());
296: $vote->set('score', $params['user_vote']);
297:
298: try {
299: $vote->save();
300:
301: AlphaDAO::disconnect();
302:
303: $this->setStatusMessage(AlphaView::displayUpdateMessage('Thank you for rating this article!'));
304:
305: $this->doGET($params);
306: }catch (FailedSaveException $e) {
307: self::$logger->error($e->getMessage());
308: }
309: }
310:
311: if(isset($params['createBut'])) {
312: $comment = new ArticleCommentObject();
313:
314:
315: $comment->populateFromPost();
316:
317:
318: $comment->set('content', InputFilter::encode($comment->get('content')));
319:
320: try {
321: $success = $comment->save();
322:
323: AlphaDAO::disconnect();
324:
325: $this->setStatusMessage(AlphaView::displayUpdateMessage('Thank you for your comment!'));
326:
327: $this->doGET($params);
328: }catch (FailedSaveException $e) {
329: self::$logger->error($e->getMessage());
330: }
331: }
332:
333: if(isset($params['saveBut'])) {
334: $comment = new ArticleCommentObject();
335:
336: try {
337: $comment->load($params['article_comment_id']);
338:
339:
340: $comment->populateFromPost();
341:
342: $success = $comment->save();
343:
344: AlphaDAO::disconnect();
345:
346: $this->setStatusMessage(AlphaView::displayUpdateMessage('Your comment has been updated.'));
347:
348: $this->doGET($params);
349: }catch (AlphaException $e) {
350: self::$logger->error($e->getMessage());
351: }
352: }
353: }catch(SecurityException $e) {
354: self::$logger->warn($e->getMessage());
355: throw new ResourceNotAllowedException($e->getMessage());
356: }
357: }
358:
359: 360: 361: 362: 363: 364:
365: private function () {
366: global $config;
367:
368: $html = '';
369:
370: $comments = $this->BO->getArticleComments();
371: $comment_count = count($comments);
372:
373: if($config->get('cms.display.comments') && $comment_count > 0) {
374: $html .= '<h2>There are ['.$comment_count.'] user comments for this article</h2>';
375:
376: ob_start();
377: for($i = 0; $i < $comment_count; $i++) {
378: $view = AlphaView::getInstance($comments[$i]);
379: $view->markdownView();
380: }
381: $html.= ob_get_clean();
382: }
383:
384: if(isset($_SESSION['currentUser']) && $config->get('cms.comments.allowed')) {
385: $comment = new ArticleCommentObject();
386: $comment->set('articleOID', $this->BO->getID());
387:
388: ob_start();
389: $view = AlphaView::getInstance($comment);
390: $view->createView();
391: $html.= ob_get_clean();
392: }
393:
394: return $html;
395: }
396: }
397:
398:
399: if(basename($_SERVER['PHP_SELF']) == 'ViewArticle.php') {
400: $controller = new ViewArticle();
401:
402: if(!empty($_POST)) {
403: $controller->doPOST($_REQUEST);
404: }else{
405: $controller->doGET($_GET);
406: }
407: }
408:
409: ?>