From: <al...@us...> - 2008-01-15 14:52:44
|
Revision: 593 http://sciret.svn.sourceforge.net/sciret/?rev=593&view=rev Author: alpeb Date: 2008-01-15 06:52:43 -0800 (Tue, 15 Jan 2008) Log Message: ----------- if article doesn't exist, redirect to home and show error message Modified Paths: -------------- branches/release-candidates/sciret-1.2/views/ViewArticle.php Modified: branches/release-candidates/sciret-1.2/views/ViewArticle.php =================================================================== --- branches/release-candidates/sciret-1.2/views/ViewArticle.php 2008-01-15 14:51:50 UTC (rev 592) +++ branches/release-candidates/sciret-1.2/views/ViewArticle.php 2008-01-15 14:52:43 UTC (rev 593) @@ -18,8 +18,17 @@ class ViewArticle extends View { + var $article; + + function preDispatch() { + $this->article = new Article($_GET['id']); + if (!$this->article->getId()) { + $_SESSION['message'] = $this->user->lang('Article does not exist'); + Library::redirect(Library::getLink(array())); + } + } + function dispatch() { - $article = new Article($_GET['id']); $this->tpl->set_file('search', 'BasicSearch.tpl'); $this->tpl->set_block('search', 'searchInKB_block', 'searchInKB'); @@ -52,7 +61,7 @@ if ($this->configuration->getConfigValue('allowCommentsRatings')) { $viewComments = new ViewComments($this->user, $this->configuration); - $viewComments->setArticle($article); + $viewComments->setArticle($this->article); $viewComments->setTemplate($this->tpl); $this->tpl->set_var('commentsTable', $viewComments->dispatch(true)); } else { @@ -60,12 +69,12 @@ } // *** ATTACHED FILES **** - $files = $article->getFiles(); + $files = $this->article->getFiles(); $notFirstPass = false; foreach ($files as $file) { if (!$this->user->isAnonymous()) { $this->tpl->set_var(array( - 'href_del' => Library::getLink(array('action' => 'DeleteFile', 'artId' => $article->getId(), 'id' => $file->getId())), + 'href_del' => Library::getLink(array('action' => 'DeleteFile', 'artId' => $this->article->getId(), 'id' => $file->getId())), )); $this->tpl->parse('img_delete', 'img_delete_block'); } else { @@ -85,7 +94,7 @@ if (!$this->user->isAnonymous()) { $this->tpl->set_var(array( - 'uploadAction' => Library::getLink(array('action' => 'UploadFile', 'artId' => $article->getId())), + 'uploadAction' => Library::getLink(array('action' => 'UploadFile', 'artId' => $this->article->getId())), 'maxFileSize' => ini_get('upload_max_filesize'), )); $this->tpl->parse('file_upload', 'file_upload_block'); @@ -95,7 +104,7 @@ // *** RELATED ARTICLES **** $relatedArticles = new ViewRelatedArticles($this->user, $this->configuration); - $relatedArticles->setParent($article); + $relatedArticles->setParent($this->article); $relatedArticles->setTemplate($this->tpl); $this->tpl->set_var('relatedArticlesTable', $relatedArticles->dispatch(true)); @@ -103,7 +112,7 @@ $historyGateway = new HistoryGateway; $firstIteration = true; $trClass = 'row_off'; - foreach ($historyGateway->getEvents($article->getId()) as $history) { + foreach ($historyGateway->getEvents($this->article->getId()) as $history) { $this->tpl->set_var(array( 'historyTrClass' => $trClass, 'historyDate' => $this->user->formatDate($history->getDate()), @@ -129,69 +138,69 @@ $categoryGateway = new CategoryGateway; $this->categories = $categoryGateway->getCategories(); - if ($article->isDraft()) { + if ($this->article->isDraft()) { $status = $this->user->lang('Article marked as draft') . ' ' . '(<a href="javascript:void(0)" class="headerLinks" onclick="markAsFinal(\'markFinalProgressImg\');" >' . $this->user->lang('mark as final') . '</a>)'; - } elseif (!$article->isPublished()) { + } elseif (!$this->article->isPublished()) { $status = $this->user->lang("This article hasn't yet been published in the Knowledge Base"); } else { $status = ''; } $this->tpl->set_var(array( - 'printerViewLink' => Library::getLink(array('view' => 'PrinterView', 'artId' => $article->getId())), - 'pdfLink' => Library::getLink(array('action' => 'ArticleToPdf', 'artId' => $article->getId())), - 'mailArticleLink' => Library::getLink(array('view' => 'MailArticle', 'artId' => $article->getId())), - 'editArticleLink' => Library::getLink(array('view' => 'EditArticle', 'id' => $article->getId())), - 'addCommentsAction' => Library::getLink(array('action' => 'AddCommentAndRating', 'artId' => $article->getId())), - 'addRelatedAction' => Library::getLink(array('action' => 'AddRelatedArticles', 'artId' => $article->getId())), - 'art_id' => $article->getId(), - 'category' => $this->_getCategoryPath($article->getCategoryId(), 'MainView', true), + 'printerViewLink' => Library::getLink(array('view' => 'PrinterView', 'artId' => $this->article->getId())), + 'pdfLink' => Library::getLink(array('action' => 'ArticleToPdf', 'artId' => $this->article->getId())), + 'mailArticleLink' => Library::getLink(array('view' => 'MailArticle', 'artId' => $this->article->getId())), + 'editArticleLink' => Library::getLink(array('view' => 'EditArticle', 'id' => $this->article->getId())), + 'addCommentsAction' => Library::getLink(array('action' => 'AddCommentAndRating', 'artId' => $this->article->getId())), + 'addRelatedAction' => Library::getLink(array('action' => 'AddRelatedArticles', 'artId' => $this->article->getId())), + 'art_id' => $this->article->getId(), + 'category' => $this->_getCategoryPath($this->article->getCategoryId(), 'MainView', true), 'lang_status' => $status, - 'title' => $article->getTitle(), - 'deleteTitle' => addslashes($article->getTitle()), - 'img_stars' => $article->getTotalVotes()? '<img src="images/'.round($article->getAverageRating()).'stars.png" width="50" height="10" />' : '', - 'createdby' => $this->user->lang('Created by %s on %s', $article->getCreatedBy(), $this->user->formatDate($article->getCreationDate())), - 'content' => $article->getContent(), + 'title' => $this->article->getTitle(), + 'deleteTitle' => addslashes($this->article->getTitle()), + 'img_stars' => $this->article->getTotalVotes()? '<img src="images/'.round($this->article->getAverageRating()).'stars.png" width="50" height="10" />' : '', + 'createdby' => $this->user->lang('Created by %s on %s', $this->article->getCreatedBy(), $this->user->formatDate($this->article->getCreationDate())), + 'content' => $this->article->getContent(), 'img_delete' => '', - 'usage' => $article->isInternal() ? '<span style="color: red">'.$this->user->lang('Internal use only').'</span>' : $this->user->lang('Publicly available'), + 'usage' => $this->article->isInternal() ? '<span style="color: red">'.$this->user->lang('Internal use only').'</span>' : $this->user->lang('Publicly available'), )); - if ($article->getQuestion()) { - $this->tpl->set_var('question', $article->getQuestion()); + if ($this->article->getQuestion()) { + $this->tpl->set_var('question', $this->article->getQuestion()); $this->tpl->parse('question', 'question_block'); } else { $this->tpl->set_var('question', ''); } - if (!$article->isInternal()) { + if (!$this->article->isInternal()) { $this->tpl->parse('mailArticle', 'mailArticle_block'); } else { $this->tpl->set_var('mailArticle', ''); } - if ($article->getModifiedByUserId() != 0) { + if ($this->article->getModifiedByUserId() != 0) { $this->tpl->set_var(array( - 'modificationDate' => $this->user->formatDate($article->getModificationDate()), - 'modifiedByUserName' => $article->getModifiedBy(), + 'modificationDate' => $this->user->formatDate($this->article->getModificationDate()), + 'modifiedByUserName' => $this->article->getModifiedBy(), )); $this->tpl->parse('lastModif', 'lastModif_block'); } else { $this->tpl->set_var('lastModif', ''); } - if ($article->getExpDate() == '0000-00-00') { + if ($this->article->getExpDate() == '0000-00-00') { $this->tpl->set_var('expDate', $this->user->lang('Never expires')); } else { - $this->tpl->set_var('expDate', $this->user->formatDate($article->getExpDate())); + $this->tpl->set_var('expDate', $this->user->formatDate($this->article->getExpDate())); } $showEditDelete = false; if ($this->configuration->getConfigValue('restrictEditDelete')) { - if ($article->getUserId() == $this->user->getId() || ($this->user->getRole() & ROLE_ADMIN) == ROLE_ADMIN) { + if ($this->article->getUserId() == $this->user->getId() || ($this->user->getRole() & ROLE_ADMIN) == ROLE_ADMIN) { $showEditDelete = true; } } else { @@ -203,14 +212,14 @@ if ($showEditDelete) { $this->tpl->parse('edit_del', 'edit_del_block'); - if (!$article->isPublished()) { - $this->tpl->set_var('publishBtnDisplay', $article->isDraft()? 'none' : ''); + if (!$this->article->isPublished()) { + $this->tpl->set_var('publishBtnDisplay', $this->article->isDraft()? 'none' : ''); $this->tpl->parse('publish_btn', 'publish_btn_block'); } else { $this->tpl->set_var('publish_btn', ''); } - if ($article->isFavorite($this->user->getId())) { + if ($this->article->isFavorite($this->user->getId())) { $this->tpl->set_var(array( 'favoriteArticleStarImgDisplay' => 'none', 'unFavoriteArticleStarImgDisplay' => 'inline', @@ -234,10 +243,10 @@ $this->tpl->pparse('out', 'view_article'); // only record one view per session - if (!isset($_SESSION['seen_article_'.$article->getId()])) { - $article->setViews($article->getViews() + 1); - $article->save(); - $_SESSION['seen_article_'.$article->getId()] = true; + if (!isset($_SESSION['seen_article_'.$this->article->getId()])) { + $this->article->setViews($this->article->getViews() + 1); + $this->article->save(); + $_SESSION['seen_article_'.$this->article->getId()] = true; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |