2 class index
extends tsAdminPage
{
5 public function __construct(){
8 $o = new tdoOptions($this->db
);
9 $o->option_name
= 'title';
14 $this->varArray
['menu'] = $this->menu
;
15 $this->varArray
['tit'] = $o->option_value
;
16 $this->varArray
['title'] = ' ['.$this->user
->user_name
.' @ '.$this->varArray
['tit'].']';
18 $action = tsPage
::getRequest('do');
20 // avoid making useless queries if $action = edit || delete
23 } elseif (!in_array($action, get_class_methods ($this))) {
24 $action = 'menu'.ucfirst($action);
27 if (!empty ($action) && in_array($action, get_class_methods ($this))) {
31 if (empty($this->varArray
['mainFile'])) {
32 $pt = new tdoPosts($this->db
);
33 $pt->post_active
= "Y";
35 $pt->addOrder($pt->post_id
, false);
37 $ps = $pt->getArray();
39 foreach ($ps as $post){
40 $post['eaction'] = tsPage
::setRequest(get_class($this), array('do' => 'post', 'i' => $post['post_id']));
41 $post['daction'] = tsPage
::setRequest(get_class($this), array('do' => 'delete', 'i' => $post['post_id']));
43 $post['post_title'] = stripslashes(strip_tags($post['post_title']));
44 $post['post_body'] = stripslashes(strip_tags($post['post_body']));
49 $posts[0]['post_title'] = '« empty »';
50 $posts[0]['post_body'] = 'There are no posts currently';
51 $posts[0]['eaction'] = tsPage
::setRequest(get_class($this), array('do'=>'post'));
54 $this->varArray
['posts'] = $posts;
55 $this->varArray
['mainFile'] = dirname(__FILE__
).'/pages/allposts.tpl';
59 private function mnuBuild () {
60 $menuKeys = get_class_methods (get_class());
61 $notGood = get_class_methods (get_parent_class());
63 $menuKeys = array_diff ($menuKeys, $notGood);
65 foreach ($menuKeys as $key) {
66 if (stristr ($key, 'menu')){
67 $key = strtolower (preg_replace('/menu/','', $key));
68 $this->menu
[$key] = tsPage
::setRequest (get_class($this), array('do' => $key));
73 public function menuAdd(){
77 public function delete () {
78 $id = tsPage
::getRequest('i');
80 $post = new tdoPosts($this->db
);
81 // $post->post_id = $id;
83 $post->post_active
= "N";
87 tsPage
::redirect( tsPage
::setRequest(get_class($this)) );
90 public function edit () {
91 $postId = tsPage
::getRequest('i');
93 $post = new tdoPosts ($this->db
);
94 $cp = new tdoCategoriesPosts ($this->db
);
96 if (!empty ($postId)) {
97 $post->post_id
= $postId;
101 $title = tsPage
::getRequest('t');
102 $post->clean ($title, false);
103 $post->post_title
= $title; // post title
105 $body = tsPage
::getRequest('x');
106 // this is just for fun, so I can display these values in the posts,
107 // but not have them converted at edit time
108 $body = str_replace (array('$TIME$', '$QUERIES$', '$MEMUSED$'),
109 array('%TIME%','%QUERIES%', '%MEMUSED%'), $body);
112 $post->clean ($body);
113 $post->post_body
= $body; // post body
116 $modTime = tsPage
::getRequest('d');
118 if (!empty($modTime)) {
119 $post->post_time
= date("Y-m-d G:i:s");
122 $post->post_author
= $this->user
->uid
;
124 $post->post_private
= (tsPage
::getRequest('p') ?
'Y' : 'N');
126 // getting the category id based on name
127 $incCat = tsPage
::getRequest ('c');
129 if (!empty($body) && !empty($title)) {
130 $id = $post->replace ($postId);
133 if (!is_array($incCat))
137 $cp->addWhere ($cp->post_id
, '=', $id);
140 foreach ($incCat as $catId) {
141 $cp->category_id
= $catId;
148 tsPage
::redirect( tsPage
::setRequest(get_class($this), array('do'=> 'post', 'i' => (int)$id)) );
151 public function post () {
152 $postId = tsPage
::getRequest('i');
153 // $this->initiateDisplay();
155 $this->varArray
['action'] = tsPage
::setRequest (get_class($this), array ('do'=> 'edit'));
156 $this->varArray
['mainFile'] = dirname (__FILE__
).'/pages/edit.tpl';
158 $c = new tdoCategories ($this->db
);
159 $c->category_active
= 'Y';
161 $cat = $c->getArray ();
163 $p = new tdoPosts($this->db
);
164 if (!empty($postId)) {
165 $p->post_id
= $postId;
166 $posts = $p->getArray (1);
168 // TODO: stripslashes is mandatory - also I should use htmlentities if outputting application/xhtml+xml
169 $posts[0]['post_title'] = htmlentities (stripslashes ($posts[0]['post_title']), ENT_QUOTES
, 'UTF-8');
170 $posts[0]['post_body'] = htmlentities (stripslashes ($posts[0]['post_body']), ENT_QUOTES
, 'UTF-8');
172 // this is just for fun, so I can display these values in the posts, but not have them converted at edit time
173 $posts[0]['post_body'] = str_replace(array('%TIME%','%QUERIES%', '%MEMUSED%'), array('$TIME$', '$QUERIES$', '$MEMUSED$'), $posts[0]['post_body']);
175 $this->varArray
['post'] = $posts[0];
177 $cp = new tdoCategoriesPosts ($this->db
);
178 $cp->post_id
= $postId;
180 $refs = $cp->getArray ();
182 foreach ($refs as $ref) {
183 $tref[] = $ref['category_id'];
186 foreach ($cat as $key => $catData) {
187 if (is_array ($tref) && in_array ($catData['category_id'], $tref)) {
188 $catData['category_set'] = true;
189 $cat[$key] = $catData;
194 if (!empty($postId ))
195 $this->varArray
['this_post'] = '#p'.$postId ;
197 $this->varArray
['categories'] = $cat;
198 $this->varArray
['now'] = date('Y-m-d G:i:s');
199 $this->varArray
['upload_url'] = tsPage
::setRequest ('upload', array('i' => $postId));
202 public function catedit () {
203 $c = new tdoCategories ($this->db
);
206 $i = tsPage
::getRequest('i');
208 if (tsPage
::getRequest('delete') == 'yes'){
209 $c->category_active
= 'N';
213 $n = tsPage
::getRequest('n');
215 $d = tsPage
::getRequest('d');
217 $p = tsPage
::getRequest('p');
219 $c->category_name
= $n;
220 $c->category_description
= $d;
221 $c->category_private
= $p;
225 tsPage
::redirect ( tsPage
::setRequest(get_class($this), array('do' => 'categories')));
228 public function menuCategories () {
229 // tsPage::redirect( tsPage::setRequest(get_class($this)) );
230 $c = new tdoCategories($this->db
);
232 $c->category_active
= 'Y';
233 $cs = $c->getArray();
235 $this->varArray
['categories'] = $cs;
236 $this->varArray
['action'] = tsPage
::setRequest(get_class($this), array('do'=>'catedit'));
237 $this->varArray
['mainFile'] = dirname(__FILE__
) . '/pages/categories.tpl';
241 public function optedit () {
242 $o = new tdoOptions($this->db
);
244 $i = tsPage
::getRequest('i');
247 if (tsPage
::getRequest('delete') == 'yes'){
248 $rows = $o->delete ($i);
251 $v = tsPage
::getRequest ('v');
252 $a = tsPage
::getRequest ('a') == 'Y' ?
'Y' : 'N';
253 $n = tsPage
::getRequest ('n');
256 $o->option_name
= $n;
259 $o->option_value
= $v;
260 $o->option_modif
= $a;
264 tsPage
::redirect( tsPage
::setRequest (get_class($this), array('do'=>'options' )));
267 public function menuOptions () {
268 $o = new tdoOptions($this->db
);
269 $os = $o->getArray();
271 $this->varArray
['options'] = $os;
272 $this->varArray
['action'] = tsPage
::setRequest(get_class($this), array('do'=>'optedit'));
273 $this->varArray
['mainFile'] = dirname(__FILE__
).'/pages/options.tpl';
276 public function menuMain () {
277 tsPage
::redirect( tsPage
::setRequest(get_class($this) ));
280 public function menuLogout () {
281 tsPage
::redirect( tsPage
::setRequest('login', array('do'=>'logout')) );