* refactored the tsPage::[get|set]Request to tsUrl::[get|set]Request
[vsc.git] / _pages / index / code.php
blobb308e527b52db790a98bedff2853aef65472c01c
1 <?php
2 class index extends tsPage{
4 private $dateStart,
5 $dateEnd,
6 $user;
8 public function __construct(){
10 parent::__construct();
12 $this->user = new tsUsers ($this->db);
13 // TODO: I think it would be better to handle the GET params inside the
14 // methods that handle the display.
15 $postId = tsUrl::getRequest('p');
16 $search = tsUrl::getRequest('search');
18 $p = new tdoPosts ($this->db);
20 if ( !empty($search) ) {
21 $posts = $p->searchPosts ($search, $this->user->uid);
22 } else {
23 if (empty ($postId)) {
24 $posts = $p->getAllPosts ($this->user->uid);
25 } else {
26 $posts = $p->getPost ($postId, $this->user->uid);
27 // var_dump ($posts);
31 if ( empty($posts) ) {
32 $posts[0]['post_id'] = 0;
33 $posts[0]['post_title'] = '&laquo; empty &raquo;';
34 $posts[0]['user_name'] = 'Admin';
35 $posts[0]['post_body'] = 'There are no posts currently';
39 // unset ($p);
40 $this->display($posts);
43 private function buildSidebar ($posts) {
44 $actions = array ();
45 if ($this->user->isLogged () ) {
46 $action['url'] = str_replace (URL, URL.'/adm/', tsUrl::setRequest());
47 $action['label'] = 'Admin';
48 $actions[] = $action;
50 $red = urlencode(tsUrl::setRequest(get_class ($this)));
52 $action['url'] = str_replace (URL, URL.'/adm/', tsUrl::setRequest('login', array('do'=>'logout', 'r' => $red)));
53 $action['label'] = 'Logout';
54 $actions[] = $action;
56 $user['actions'] = $actions;
58 $this->varArray['sidebar'] = dirname(__FILE__).'/pages/sidebar.tpl';
59 $this->varArray['user'] = $user; // ?? FIXME
62 private function getAll ($start, $end) {
66 private function getOne () {
70 private function getSearch () {
74 private function display ($posts) {
75 $o = new tdoOptions($this->db);
76 $o->option_name = 'title';
77 $o->findFirst();
79 // admin edit and stuff
80 foreach ($posts as $key => $post) {
81 if ($this->user->isLogged ()) {
82 $posts[$key]['eaction'] = str_replace (URL.'/', URL.'/adm/', tsUrl::setRequest('index', array('do' => 'post', 'i' => $post['post_id'])));
84 $posts[$key]['addaction'] = tsUrl::setRequest(get_class ($this), array('p' => $post['post_id'], '#reply'));
87 if (sizeof ($posts) > 1) {
88 // display all posts
89 $this->varArray['posts'] = $posts;
90 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/main.tpl';
91 } else {
92 // display one post - this is temporary
93 $this->varArray['post'] = $posts[0];
94 $this->varArray['user'] = unserialize($_SESSION['user']); // dumb
95 // must add the comments - comments = posts with parent = posts[0].id
96 $this->varArray['comments'] = false;
97 $this->varArray['mainFile'] = dirname(__FILE__).'/pages/post.tpl';
100 $this->buildSidebar($posts);
102 $this->varArray['title'] = $o->option_value;
103 $this->varArray['main'] = tsUrl::setRequest (get_class($this));
104 $this->varArray['contact'] = tsUrl::setRequest ('contact');
105 $this->varArray['search'] = tsUrl::setRequest (get_class($this));
108 private function postComment () {
109 $parent = tsUrl::getRequest('p');
110 $name = tsUrl::getRequest('n');
111 $mail = tsUrl::getRequest('m');
112 $name = tsUrl::getRequest('e');
113 $post = tsUrl::getRequest('x');
115 $user = new tdoUsers($this->db);
116 $user->user_name = $name;
117 $user->user_email = $mail;
119 $uid = $user->insert();
121 $comment = new tdoPosts($this->db);
122 $comment->clean($post);
123 $comment->post_body = $post;
124 $comment->post_parent = $parent;
125 $comment->post_author = $uid;
127 $comment->insert();
129 tsPage::redirect(tsUrl::setRequest(get_class ($this), array ('p' => $parent)));
132 // private function display ( $postId ) {
134 // }
136 // private function edit () {
137 // $i = tsUrl::getRequest ('i');
138 // //tsPage::redirect(str_replace(array( URL.'/'),array( URL.'/adm/'), tsUrl::setRequest('index', array('do' => 'post', 'i' => $i))));
139 // }