This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
/
view_article.php
80 lines (73 loc) · 2.41 KB
/
view_article.php
1
2
3
4
5
6
7
8
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* File defines the ViewArticleController PageController class
* @package PageController
*/
/**
*/
$current_dir = dirname (__FILE__);
require_once ($current_dir . DIRECTORY_SEPARATOR . "shared" . DIRECTORY_SEPARATOR . "bootstrap.php");
require_once (joinPath (INCLUDES_DIR, "models", "Article.php"));
require_once (joinPath (INCLUDES_DIR, "models", "ArticleTag.php"));
/**
* View article page
*
* Read in the specified article from the database.
* Display article in the page
* @package PageController
*/
class ViewArticleController implements Controller {
/**
* PageTemplate object used to render page
* @access protected
* @var PageTemplate
*/
protected $template;
/**
* Constructor. Create instance of PageTemplate using default index_tpl.php file
* @access public
*/
public function __construct () {
$this->template = new PageTemplate ();
}
/**
* Run method with main page logic
*
* Read in the specified article from the database.
* Populate template and display article in the page
* @access public
*/
public function run () {
$session = Session::getInstance ();
$user = $session->getUser ();
/*
if ($user == null || !$user->validUser ()) {
header ("Location: " . BASE_URL);
return;
}
*/
$articleDAO = ArticleDAO::getInstance ();
$tagDAO = ArticleTagDAO::getInstance ();
$article = $articletags = null;
$title = "";
if (!empty ($_GET["id"]) && is_numeric ($_GET["id"])) {
$article_id = intval ($_GET["id"]);
$article = $articleDAO->load ($article_id, array ("joins" => true));
if ($article) {
$title .= "{$article->getTitle ()}";
$articletags = $tagDAO->allArticleTags ($article, array ("order" => "name"));
}
}
//print_r ($articletags);
$this->template->render (array (
"title" => "Article - " . $title,
"main_page" => "view_article_tpl.php",
"session" => $session,
"article" => $article,
"articletags" => $articletags,
));
}
}
$controller = new ViewArticleController ();
$controller->run ();
?>