PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
3.1.7 3.1.6 3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 139 releases
← All changes | wpf-includes/class-forums.php +104 -310 1.4.1beta-4 View file →
@@ -3,73 +3,15 @@
3 3 if( !defined( 'ABSPATH' ) ) exit;
4 4
5 5
6 6 class wpForoForum{
7 +
7 8 private $wpforo;
8 - public $default;
9 - public $options;
10 - public $cans;
11 -
12 - static $cache = array( 'forums' => array(), 'forum' => array(), 'item' => array() );
9 + private static $cache = array();
13 10
14 - public function __construct( $wpForo ){
11 + function __construct( $wpForo ){
15 12 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
16 -
17 - $this->init_defaults();
18 - $this->init_options();
19 13 }
20 -
21 - private function init_defaults(){
22 - $this->default = new stdClass;
23 -
24 - $this->default->options = array(
25 - 'layout_qa_intro_topics_toggle' => 1,
26 - 'layout_extended_intro_topics_toggle' => 1,
27 - 'layout_qa_intro_topics_count' => 3,
28 - 'layout_extended_intro_topics_count' => 5,
29 - );
30 -
31 - $this->default->cans = array (
32 - 'vf' => 'Can view forum',
33 - 'ct' => 'Can create topic',
34 - 'vt' => 'Can view topic',
35 - 'et' => 'Can edit topic',
36 - 'dt' => 'Can delete topic',
37 - 'cr' => 'Can post reply',
38 - 'vr' => 'Can view replies',
39 - 'er' => 'Can edit replies',
40 - 'dr' => 'Can delete replies',
41 - 'eot' => 'Can edit own topic',
42 - 'eor' => 'Can edit own reply',
43 - 'dot' => 'Can delete own topic',
44 - 'dor' => 'Can delete own reply',
45 - 'l' => 'Can like',
46 - 'r' => 'Can report',
47 - 's' => 'Can set topic sticky',
48 - 'p' => 'Can set topic private',
49 - 'op' => 'Can set own topic private',
50 - 'vp' => 'Can view private topic',
51 - 'au' => 'Can approve/unapprove content',
52 - 'sv' => 'Can set topic solved',
53 - 'osv' => 'Can set own topic solved',
54 - 'v' => 'Can vote',
55 - 'a' => 'Can attach file',
56 - 'va' => 'Can view attached files',
57 - 'at' => 'Can set topic answered',
58 - 'oat' => 'Can set own topic answered',
59 - 'cot' => 'Can close topic',
60 - 'mt' => 'Can move topic'
61 - );
62 - }
63 -
64 - private function init_options(){
65 - $this->options = get_wpf_option('wpforo_forum_options', $this->default->options);
66 - $this->cans = apply_filters('wpforo_forum_cans', $this->default->cans);
67 - }
68 -
69 - public function get_cache( $var ){
70 - if( isset(self::$cache[$var]) ) return self::$cache[$var];
71 - }
72 14
73 15 private function unique_slug($slug, $parentid = 0, $forumid = 0){
74 16 $new_slug = wpforo_text($slug, 250, false);
75 17 $forumid = intval($forumid);
@@ -86,9 +28,9 @@
86 28 return $new_slug;
87 29 }
88 30
89 31 public function add( $args = array(), $checkperm = TRUE ){
90 - if( $checkperm && !$this->wpforo->perm->usergroup_can('cf') ){
32 + if( $checkperm && !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'cf') ){
91 33 $this->wpforo->notice->add('Permission denied for add forum', 'error');
92 34 return FALSE;
93 35 }
94 36
@@ -103,9 +45,9 @@
103 45 }
104 46
105 47 $title = sanitize_text_field($title);
106 48 $title = wpforo_text($title, 250, false);
107 - $description = (isset($description) ? wpforo_kses($description, 'post') : '');
49 + $description = (isset($description) ? wpforo_kses($description) : '');
108 50 $permission = (isset($permission) && is_array($permission)) ? serialize(array_map('sanitize_text_field', $permission)) : 'a:5:{i:1;s:4:"full";i:2;s:9:"moderator";i:3;s:8:"standard";i:4;s:9:"read_only";i:5;s:8:"standard";}';
109 51 $meta_key = (isset($meta_key)) ? sanitize_text_field($meta_key) : '';
110 52 $meta_desc = (isset($meta_desc)) ? sanitize_text_field($meta_desc) : '';
111 53 $parentid = (isset($parentid)) ? intval($parentid) : 0;
@@ -145,13 +87,10 @@
145 87 ),
146 88 array('%s','%s','%s','%d','%s','%d','%d','%s','%s','%s','%d','%d','%d','%d')
147 89 )
148 90 ){
149 - $forumid = $this->wpforo->db->insert_id;
150 - $this->delete_tree_cache();
151 - wpforo_clean_cache($forumid, 'forum', $args);
152 91 $this->wpforo->notice->add('Your forum successfully added', 'success');
153 - return $forumid;
92 + return $this->wpforo->db->insert_id;
154 93 }
155 94
156 95 $this->wpforo->notice->add('Can\'t add forum', 'error');
157 96 return FALSE;
@@ -157,9 +96,9 @@
157 96 return FALSE;
158 97 }
159 98
160 99 public function edit( $args = array() ){
161 - if( !$this->wpforo->perm->usergroup_can('ef') ){
100 + if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'ef') ){
162 101 $this->wpforo->notice->add('Permission denied for edit forum', 'error');
163 102 return FALSE;
164 103 }
165 104
@@ -181,9 +120,9 @@
181 120
182 121 $forumid = intval($forumid);
183 122 $title = sanitize_text_field($title);
184 123 $title = wpforo_text($title, 250, false);
185 - $description = wpforo_kses($description, 'post');
124 + $description = wpforo_kses($description);
186 125 $permission = (isset($permission) && is_array($permission)) ? serialize(array_map('sanitize_text_field', $permission)) : 'a:5:{i:1;s:4:"full";i:2;s:9:"moderator";i:3;s:8:"standard";i:4;s:9:"read_only";i:5;s:8:"standard";}';
187 126 $meta_key = (isset($meta_key)) ? sanitize_text_field($meta_key) : '';
188 127 $meta_desc = (isset($meta_desc)) ? sanitize_text_field($meta_desc) : '';
189 128 $parentid = (isset($parentid)) ? intval($parentid) : 0;
@@ -205,11 +144,11 @@
205 144
206 145 if( FALSE !== $this->wpforo->db->update(
207 146 $this->wpforo->db->prefix . 'wpforo_forums',
208 147 array(
209 - 'title' => stripslashes($title),
148 + 'title' => $title,
210 149 'slug' => $slug,
211 - 'description' => stripslashes($description),
150 + 'description' => $description,
212 151 'parentid' => $parentid,
213 152 'icon' => $icon,
214 153 'permissions' => $permission,
215 154 'meta_key' => $meta_key,
@@ -228,10 +167,8 @@
228 167 $this->get_childs($forumid, $childs);
229 168 $sql = "UPDATE `".$this->wpforo->db->prefix . "wpforo_forums` SET `cat_layout` = ".intval($cat_layout)." WHERE `forumid` IN(". implode(',', array_map('intval', $childs)).")";
230 169 $this->wpforo->db->query($sql);
231 170 }
232 - $this->delete_tree_cache();
233 - wpforo_clean_cache($forumid, 'forum', $args);
234 171 $this->wpforo->notice->add('Forum successfully updated', 'success');
235 172 return $forumid;
236 173 }
237 174
@@ -238,52 +175,51 @@
238 175 $this->wpforo->notice->add('Forum update error', 'error');
239 176 return FALSE;
240 177 }
241 178
242 - public function delete($forumid = 0){
243 - $forumid = intval($forumid);
244 - if(!$forumid && isset( $_REQUEST['id'] ) ) $forumid = intval($_REQUEST['id']);
245 -
246 - if( !$this->wpforo->perm->usergroup_can('df') ){
179 + function delete(){
180 + if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'df') ){
247 181 $this->wpforo->notice->add('Permission denied for delete forum', 'error');
248 182 return FALSE;
249 183 }
250 184
251 - $childs = array();
252 - $this->get_childs($forumid, $childs);
253 - $forumids = implode(',', array_map('intval', $childs));
254 -
255 - // START delete topic posts include first post
256 - if( $topicids = $this->wpforo->db->get_col( "SELECT `topicid` FROM ".$this->wpforo->db->prefix."wpforo_topics WHERE `forumid` IN(". esc_sql($forumids) .")" ) ){
257 - foreach($topicids as $topicid){
258 - $this->wpforo->topic->delete($topicid, false);
185 + if(isset($_GET['id']) && is_array($_REQUEST['forum']) && !empty($_REQUEST['forum']) && isset($_REQUEST['forum']['delete'])){
186 +
187 + $forumid = intval($_GET['id']);
188 +
189 + extract($_REQUEST['forum'], EXTR_OVERWRITE);
190 +
191 + if(intval($delete) == 1){
192 +
193 + $forumid = intval($forumid);
194 + $this->get_childs($forumid, $data);
195 + $forumids = implode(',', array_map('intval', $data));
196 + $topics = $this->wpforo->db->get_results("SELECT `topicid` FROM ".$this->wpforo->db->prefix."wpforo_topics WHERE `forumid` IN(". esc_sql($forumids) .")", ARRAY_A);
197 +
198 + if(!empty($topics)){
199 + foreach($topics as $topic){
200 + $this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_posts', array( 'topicid' => $topic['topicid'] ), array( '%d' ) );
201 + $this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_topics', array( 'topicid' => $topic['topicid'] ), array( '%d' ) );
202 + }
259 203 }
260 - }
261 - // END delete topic posts include first post
262 -
263 - if($this->wpforo->db->query( "DELETE FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `forumid` IN(". esc_sql($forumids) .")" )){
264 - $this->delete_tree_cache();
265 - wpforo_clean_cache();
266 - $this->wpforo->notice->add('Your forum successfully deleted', 'success');
267 - return TRUE;
268 - }
269 -
270 - $this->wpforo->notice->add('Forum deleting error', 'error');
271 - return FALSE;
272 - }
273 -
274 - public function merge($forumid = 0, $mergeid = 0){
275 - $forumid = intval($forumid);
276 - $mergeid = intval($mergeid);
277 -
278 - if(!$forumid && isset( $_REQUEST['id'] ) ) $forumid = intval($_REQUEST['id']);
279 - if(!$mergeid && isset( $_REQUEST['forum']['mergeid'] ) ) $mergeid = intval($_REQUEST['forum']['mergeid']);
280 -
281 - if( !$forumid || !$mergeid ) return false;
282 -
283 - if( $child_forumids = $this->get_child_forums( $forumid ) ){
284 - $forumids = trim( implode(',', array_map('intval', $child_forumids)) );
285 - if( $forumids ){
204 +
205 + if($this->wpforo->db->query( "DELETE FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `forumid` IN(". esc_sql($forumids) .")" )){
206 + $this->wpforo->notice->add('Your forum successfully deleted', 'success');
207 + return TRUE;
208 + }else{
209 + $this->wpforo->notice->add('Forum deleting error', 'error');
210 + return FALSE;
211 + }
212 +
213 + unset($data);
214 +
215 + }elseif(intval( $delete ) == 0 && isset( $mergeid ) && $mergeid != 0){
216 +
217 + $forumid = intval($forumid);
218 + $mergeid = intval($mergeid);
219 + $data = $this->get_child_forums( $forumid );
220 + $forumids = implode(',', array_map('intval', $data));
221 +
286 222 $merge_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($mergeid) );
287 223
288 224 if(!$this->wpforo->db->query( "UPDATE ".$this->wpforo->db->prefix."wpforo_forums SET `parentid` = " . intval($mergeid) . ", `cat_layout` = " . intval($merge_layout) . " WHERE `forumid` IN(". esc_sql($forumids) .")" )){
289 225 $this->wpforo->notice->add('Forum merging error', 'error');
@@ -288,38 +224,26 @@
288 224 if(!$this->wpforo->db->query( "UPDATE ".$this->wpforo->db->prefix."wpforo_forums SET `parentid` = " . intval($mergeid) . ", `cat_layout` = " . intval($merge_layout) . " WHERE `forumid` IN(". esc_sql($forumids) .")" )){
289 225 $this->wpforo->notice->add('Forum merging error', 'error');
290 226 return FALSE;
291 227 }
228 +
229 + $this->wpforo->db->update(
230 + $this->wpforo->db->prefix . 'wpforo_topics',
231 + array( 'forumid' => $mergeid ),
232 + array( 'forumid' => $forumid ),
233 + array( '%d' ),
234 + array( '%d' )
235 + );
236 +
237 + if($this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_forums', array( 'forumid' => $forumid ), array( '%d' ) )){
238 + $this->wpforo->notice->add('Forum is successfully merged', 'success');
239 + return TRUE;
240 + }else{
241 + $this->wpforo->notice->add('Forum merging error', 'error');
242 + return FALSE;
243 + }
292 244 }
293 245 }
294 -
295 - $this->wpforo->db->update(
296 - $this->wpforo->db->prefix . 'wpforo_topics',
297 - array( 'forumid' => $mergeid ),
298 - array( 'forumid' => $forumid ),
299 - array( '%d' ),
300 - array( '%d' )
301 - );
302 - $this->wpforo->db->update(
303 - $this->wpforo->db->prefix . 'wpforo_posts',
304 - array( 'forumid' => $mergeid ),
305 - array( 'forumid' => $forumid ),
306 - array( '%d' ),
307 - array( '%d' )
308 - );
309 -
310 - $this->rebuild_last_infos($mergeid);
311 - $this->rebuild_stats($mergeid);
312 -
313 - if($this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_forums', array( 'forumid' => $forumid ), array( '%d' ) )){
314 - $this->delete_tree_cache();
315 - wpforo_clean_cache(0, 'forum');
316 - $this->wpforo->notice->add('Forum is successfully merged', 'success');
317 - return TRUE;
318 - }
319 -
320 - $this->wpforo->notice->add('Forum merging error', 'error');
321 - return FALSE;
322 246 }
323 247
324 248 public function rebuild_last_infos($forumid){
325 249
@@ -349,33 +273,11 @@
349 273 $this->wpforo->db->query( "UPDATE `".$this->wpforo->db->prefix."wpforo_forums`
350 274 SET `last_topicid` = ".intval($last_topicid).", `last_postid` = ".intval($last_postid).",
351 275 `last_userid` = ".intval($last_userid).", `last_post_date` = '".esc_sql($last_post_date)."'
352 276 WHERE `forumid` = ".intval($forumid) );
353 - wpforo_clean_cache(0, 'forum');
354 277 }
355 -
356 - public function rebuild_stats($forumid){
357 - if( !$forumid = intval($forumid) ) return false;
358 - $topics = $this->wpforo->topic->get_count( array('forumid' => $forumid) );
359 - $posts = $this->wpforo->post->get_count( array('forumid' => $forumid) );
360 -
361 - if( false !== $this->wpforo->db->update(
362 - $this->wpforo->db->prefix . "wpforo_forums",
363 - array('topics' => $topics, 'posts' => $posts ),
364 - array('forumid' => $forumid),
365 - array('%d', '%d'),
366 - array('%d')
367 - ) ) {
368 - wpforo_clean_cache(0, 'forum');
369 - return true;
370 - }
371 - return false;
372 - }
373 278
374 - function get_forum( $args){
375 -
376 - $cache = $this->wpforo->cache->on('memory_cashe');
377 -
279 + function get_forum( $args, $cache = false){
378 280 if(is_array($args)){
379 281 $default = array(
380 282 'forumid' => NULL, // forumid
381 283 'slug' => '', // slug
@@ -384,10 +286,10 @@
384 286 'type' => 'all' // category, forum
385 287 );
386 288 }else{
387 289 $default = array(
388 - 'forumid' => ( is_numeric($args) ? intval($args) : NULL ), // forumid
389 - 'slug' => ( !is_numeric($args) ? $args : '' ), // slug
290 + 'forumid' => $args, // forumid
291 + 'slug' => '', // slug
390 292 'cat_layout' => 1, // forum layout
391 293 'status' => NULL, // status forum 1 OR 0
392 294 'type' => 'all' // category, forum
393 295 );
@@ -392,22 +294,16 @@
392 294 'type' => 'all' // category, forum
393 295 );
394 296 }
395 297 $args = wpforo_parse_args( $args, $default );
396 -
397 - if( $cache && !empty($args['forumid']) ){
398 - if( !empty(self::$cache['forum'][$args['forumid']]) ){
298 + if(isset($args['forumid'])){
299 + if( isset(self::$cache['forum'][$args['forumid']]) ){
399 300 return self::$cache['forum'][$args['forumid']];
400 301 }
401 302 }
402 -
403 - if( $cache && !empty($args['slug']) ){
404 - if( !empty(self::$cache['forum'][addslashes($args['slug'])]) ){
405 - return self::$cache['forum'][addslashes($args['slug'])];
406 - }
407 - }
408 303 if(!empty($args)){
409 304 extract($args, EXTR_OVERWRITE);
305 +
410 306 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_forums`";
411 307 $wheres = array();
412 308 if($forumid != NULL) $wheres[] = "`forumid` = " . intval($forumid);
413 309 if($status != NULL) $wheres[] = "`status` = " . intval($status);
@@ -415,9 +311,9 @@
415 311 $wheres[] = "`is_cat` = 1";
416 312 }elseif($type == 'forum'){
417 313 $wheres[] = "`is_cat` = 0";
418 314 }
419 - if($slug != '') $wheres[] = "`slug` = '" . esc_sql($slug) . "'";
315 + if($slug != '') $wheres[] = "`slug` = '" . sanitize_title($slug) . "'";
420 316
421 317 if(!empty($wheres)){
422 318 $sql .= " WHERE " . implode( " AND ", $wheres );
423 319 }
@@ -424,12 +320,10 @@
424 320 $forum = $this->wpforo->db->get_row($sql, ARRAY_A);
425 321 if(!empty($forum)) {
426 322 $forum['url'] = $this->get_forum_url( $forum );
427 323 }
428 - $forum = apply_filters('wpforo_get_forum', $forum);
429 324 if($cache && isset($forumid)){
430 - self::$cache['forum'][addslashes($forum['slug'])] = $forum;
431 - return self::$cache['forum'][$forum['forumid']] = $forum;
325 + return self::$cache['forum'][$forumid] = $forum;
432 326 }
433 327 else{
434 328 return $forum;
435 329 }
@@ -435,12 +329,9 @@
435 329 }
436 330 }
437 331 }
438 332
439 - function get_forums($args = array(), &$items_count = 0 ){
440 -
441 - $cache = $this->wpforo->cache->on('object_cashe');
442 -
333 + function get_forums($args = array(), &$items_count = 0){
443 334 $default = array(
444 335 'include' => array(), // array( 2, 10, 25 )
445 336 'exclude' => array(), // array( 2, 10, 25 )
446 337 'parent_include' => array(), // array( 2, 10, 25 )
@@ -456,9 +347,8 @@
456 347 );
457 348
458 349 $args = wpforo_parse_args( $args, $default );
459 350 if(is_array($args) && !empty($args)){
460 -
461 351 extract($args, EXTR_OVERWRITE);
462 352
463 353 $include = wpforo_parse_args( $include );
464 354 $exclude = wpforo_parse_args( $exclude );
@@ -480,14 +370,13 @@
480 370 }elseif($type == 'forum'){
481 371 $wheres[] = " `is_cat` = 0";
482 372 }
483 373
484 - if($parent_slug != '') $wheres[] = "`slug` = '" . esc_sql($parent_slug) . "'";
374 + if($parent_slug != '') $wheres[] = "`slug` = '" . esc_sql(sanitize_text_field($parent_slug)) . "'";
485 375
486 376 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
487 377
488 - $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
489 - if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
378 + $items_count = $this->wpforo->db->get_var(preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql));
490 379
491 380 $sql .= esc_sql(" ORDER BY `$orderby` " . $order);
492 381
493 382 if($row_count != NULL){
@@ -497,18 +386,10 @@
497 386 $sql .= esc_sql(" LIMIT $row_count");
498 387 }
499 388 }
500 389
501 - if( $cache ){ $object_key = md5( $sql . $this->wpforo->current_user_groupid ); $object_cache = $this->wpforo->cache->get( $object_key ); if(!empty($object_cache)){$items_count = $object_cache['items_count']; return $object_cache['items'];}}
390 + return $this->wpforo->db->get_results($sql, ARRAY_A);
502 391
503 - $forums = $this->wpforo->db->get_results($sql, ARRAY_A);
504 - $forums = apply_filters('wpforo_get_topics', $forums);
505 -
506 - if($cache && isset($object_key) && !empty($forums)){
507 - self::$cache['forums'][$object_key]['items'] = $forums;
508 - self::$cache['forums'][$object_key]['items_count'] = $items_count;
509 - }
510 - return $forums;
511 392 }
512 393 }
513 394
514 395 function search($needle, $fields = array()){
@@ -538,11 +419,8 @@
538 419 return array();
539 420 }
540 421
541 422 function update_hierarchy(){
542 -
543 - $this->delete_tree_cache();
544 -
545 423 if(is_array($_REQUEST['forum']) && !empty($_REQUEST['forum'])){
546 424 $i = 0;
547 425 foreach($_REQUEST['forum'] as $hierarchy){
548 426
@@ -643,9 +521,9 @@
643 521 if( isset($_GET['page']) && $_GET['page'] == 'wpforo-ads' && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id']) && $_GET['id'] ){
644 522 $ad = $wpforo->ad->get_ad($_GET['id']);
645 523 $ad_forumids = explode(',', $ad['forumids']);
646 524 }
647 - ?><option value="<?php echo intval($forumid) ?>"<?php echo( !$cats && $depth == 0 ? ' disabled ': ''); echo ( $forumid == $this->parentid($topicid) || (isset( $_GET['forumid'] ) && $forumid == $_GET['forumid']) || ( !empty($_GET['wpff']) && in_array($forumid, $_GET['wpff']) ) || ( !empty($ad_forumids) && in_array($forumid, $ad_forumids) ) || ( isset($_GET['parentid']) && $_GET['parentid'] == $forumid ) ? ' selected ' : '' ) ?> > <?php echo esc_html(str_repeat( '— ', $depth ) . trim($name)) ?></option><?php
525 + ?><option value="<?php echo intval($forumid) ?>"<?php echo( !$cats && $depth == 0 ? 'disabled': ''); echo ( $forumid == $this->parentid($topicid) || (isset( $_GET['forumid'] ) && $forumid == $_GET['forumid']) || ( !empty($_GET['wpff']) && in_array($forumid, $_GET['wpff']) ) || ( !empty($ad_forumids) && in_array($forumid, $ad_forumids) ) ? 'selected' : '' ) ?> > <?php echo esc_html(str_repeat( '— ', $depth ) . trim($name)) ?></option><?php
648 526 }elseif($type == 'drag_menu'){
649 527 $cur_forum = $this->wpforo->db->get_row("SELECT `cat_layout`, `topics`, `posts` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid), ARRAY_A);
650 528 $cat_layout_name = ( $cur_forum['cat_layout'] == 2 ? 'Simplified Layout' : ( $cur_forum['cat_layout'] == 3 ? 'QA Layout' : 'Extended Layout' ) ); ?>
651 529
@@ -654,19 +532,17 @@
654 532 <input id="parentid-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][parentid]"/>
655 533 <input id="order-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][order]"/>
656 534 <dl class="menu-item-bar">
657 535 <dt class="menu-item-handle forum_width">
658 - <span class="item-title forumtitle"><span style="font-weight:400; cursor:help;" title="Forum ID"><?php echo $forumid; ?> &nbsp;|&nbsp;</span> <?php echo esc_html($name) ?></span>
536 + <span class="item-title forumtitle"><?php echo esc_html($name) ?></span>
537 + <span class="wpforo-cat-layout"><?php echo ( $depth != 0 ? __('Topics', 'wpforo') . '&nbsp;(' . intval($cur_forum['topics']) . ')&nbsp;,&nbsp;' . __('Posts', 'wpforo') . '&nbsp;(' . intval($cur_forum['posts']) . ')&nbsp;&nbsp;' : '' ) ?><?php echo ( $depth == 0 ? '(&nbsp;<i>' . esc_html($cat_layout_name) . '</i>&nbsp;)' : '' ); ?></span>
659 538 <span class="item-controls">
660 - <span class="wpforo-cat-layout"><?php echo ( $depth != 0 ? __('Topics', 'wpforo') . '&nbsp;(' . intval($cur_forum['topics']) . ')&nbsp;,&nbsp;' . __('Posts', 'wpforo') . '&nbsp;(' . intval($cur_forum['posts']) . ')&nbsp; | &nbsp;' : '' ) ?><?php echo ( $depth == 0 ? '(&nbsp;<i>' . esc_html($cat_layout_name) . '</i>&nbsp;)&nbsp; | &nbsp;' : '' ); ?></span>
661 - <span class="menu_add"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&action=add&parentid=' . intval($forumid) ) ?>" > <img src="<?php echo WPFORO_URL ?>/wpf-assets/images/icons/plus<?php echo ((!$depth) ? '-dark' : ''); ?>.png" title="<?php if( $depth ) : _e('Add a new SubForum', 'wpforo'); else: _e('Add a new Forum in this Category', 'wpforo'); endif; ?>"/></a></span> &nbsp;|&nbsp;
662 - <span class="menu_edit"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=edit' ) ?>"><img src="<?php echo WPFORO_URL ?>/wpf-assets/images/icons/pencil<?php echo ((!$depth) ? '-dark' : ''); ?>.png" title="<?php _e('edit', 'wpforo') ?>"/></a></span>&nbsp;|&nbsp;
663 - <?php if( $this->wpforo->perm->usergroup_can('df') ): ?>
664 - <span class="menu_delete"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=del' ) ?>"><img src="<?php echo WPFORO_URL ?>/wpf-assets/images/icons/trash<?php echo ((!$depth) ? '-dark' : ''); ?>.png" title="<?php _e('delete', 'wpforo') ?>"/></a></span>&nbsp;|&nbsp;
665 - <?php endif; ?>
666 - <span class="menu_view"><a href="<?php echo esc_url(wpforo_forum($forumid, 'url')); ?>" > <img src="<?php echo WPFORO_URL ?>/wpf-assets/images/icons/eye<?php echo ((!$depth) ? '-dark' : ''); ?>.png" title="<?php _e('View', 'wpforo') ?>"/> </a> </span>
667 -
668 - </span>
539 + <span class="menu_edit"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=edit' ) ?>"><?php _e('edit', 'wpforo') ?></a></span>&nbsp;|&nbsp;
540 + <?php if( $this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'df') ): ?>
541 + <span class="menu_delete"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=del' ) ?>"><?php _e('delete', 'wpforo') ?></a></span>&nbsp;|&nbsp;
542 + <?php endif; ?>
543 + <span class="menu_view"><a href="<?php echo esc_url($this->get_forum_url($forumid)) ?>" > <?php _e('View', 'wpforo') ?> </a> </span>
544 + </span>
669 545 </dt>
670 546 </dl>
671 547 <ul class="menu-item-transport"></ul>
672 548 </li>
@@ -679,16 +555,16 @@
679 555 if(isset($old_depth) && $old_depth > $depth) echo '</dd></dl>';
680 556 $old_depth = $depth;
681 557 if(isset($wpforo->current_object) && isset($wpforo->current_object['forumid'])){
682 558 if( $forumid == $wpforo->current_object['forumid'] ){
683 - echo'<span class="wpf-dl-item wpf-dl-current"><i class="fa fa-comments-o"></i><strong>'.esc_html($name).'</strong><a href="' . esc_url( wpforo_forum($forumid, 'url') ) . '" >&nbsp;&raquo;</a></span>';
559 + echo'<span class="wpf-dl-item wpf-dl-current"><i class="fa fa-comments-o"></i><strong>'.esc_html($name).'</strong><a href="' . esc_url($this->get_forum_url($forumid)) . '" >&nbsp;&raquo;</a></span>';
684 560 }
685 561 else{
686 - echo'<span class="wpf-dl-item"><a href="'.esc_url( wpforo_forum($forumid, 'url') ).'" ><i class="fa fa-comments-o"></i>'.esc_html($name).'</a></span>';
562 + echo'<span class="wpf-dl-item"><a href="'.esc_url($this->get_forum_url($forumid)).'" ><i class="fa fa-comments-o"></i>'.esc_html($name).'</a></span>';
687 563 }
688 564 }
689 565 else{
690 - echo'<span class="wpf-dl-item"><a href="'.esc_url( wpforo_forum($forumid, 'url') ).'" ><i class="fa fa-comments-o"></i>'.esc_html($name).'</a></span>';
566 + echo'<span class="wpf-dl-item"><a href="'.esc_url($this->get_forum_url($forumid)).'" ><i class="fa fa-comments-o"></i>'.esc_html($name).'</a></span>';
691 567 }
692 568 }
693 569 $subforums = $this->get_child_forums($forumid);
694 570 if( !empty($subforums) ){
@@ -696,41 +572,19 @@
696 572 }
697 573 }
698 574 }
699 575
700 - function tree( $type = 'front_list', $cats = TRUE, $topicid = 0 ){
576 + function tree($type = 'front_list', $cats = TRUE, $topicid = 0){
701 577 $parentids = $this->wpforo->db->get_results("SELECT `forumid` AS parentid FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `parentid` = 0 ORDER BY `order`", ARRAY_A);
702 578 if(!empty($parentids)){
703 579 foreach( $parentids as $parentid ){
704 580 $data[] = $parentid['parentid'];
705 581 }
706 - if( !wpforo_is_admin() ){
707 - $key = md5( serialize($data) . $type . (int)$cats . $this->wpforo->current_user_groupid );
708 - $html = get_option( 'wpforo_forum_tree_' . $key );
709 - if( $html ){
710 - echo $html;
711 - }
712 - elseif( function_exists('ob_start') ){
713 - ob_start();
714 - $this->forum_list($data, $type, $cats);
715 - $html = ob_get_clean();
716 - if($type != 'drag_menu'){
717 - update_option( 'wpforo_forum_tree_' . $key, $html );
718 - }
719 - echo $html;
720 - }
721 - }
722 - else{
723 - $this->forum_list($data, $type, $cats);
724 - }
582 + $this->forum_list($data, $type, $cats);
725 583 }
726 584 }
727 585 // end forums tree for drop down menu
728 586
729 - public function delete_tree_cache() {
730 - $this->wpforo->db->query("DELETE FROM " . $this->wpforo->db->options . " WHERE `option_name` LIKE 'wpforo_forum_tree_%'");
731 - }
732 -
733 587 function parentid( $topicid = 0 ){
734 588 if(isset($_GET['page']) && $_GET['page'] == 'wpforo-forums'){
735 589 if( isset($_GET['id'])) return $this->wpforo->db->get_var("SELECT `parentid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($_GET['id']));
736 590 }
@@ -736,9 +590,9 @@
736 590 }
737 591 elseif( isset($_GET['page']) && $_GET['page'] == 'wpforo-topics' ){
738 592 if( isset($_GET['id'])) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($_GET['id']));
739 593 }else{
740 - if( $topicid ) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($topicid));
594 + if( isset($topicid)) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($topicid));
741 595 }
742 596 }
743 597
744 598 function permissions(){
@@ -759,18 +613,15 @@
759 613 <td>'.esc_html($name).'</td>
760 614 <td>
761 615 <select name="forum[permission]['.intval($groupid).']">';
762 616 foreach($access_arr as $value){
763 -
764 617 echo '<option value="'.esc_attr($value['access']).'" '.
765 618 ((isset($permissions_arr[$groupid]) && $value['access'] == $permissions_arr[$groupid])
766 - || (!isset($permissions_arr[$groupid])
767 - && (($name == 'Guest' && $value['access'] == 'read_only')
768 - || ($name == 'Registered' && $value['access'] == 'standard')
769 - || ($name == 'Customer' && $value['access'] == 'standard')
770 - || ($name == 'Moderator' && $value['access'] == 'moderator')
771 - || ($name == 'Admin' && $value['access'] == 'full')
772 - || ($name != 'Guest' && $name != 'Registered' && $name != 'Customer' && $name != 'Moderator' && $name != 'Admin' && $value['access'] == 'standard') )) ? ' selected ' : '').'>'.esc_html( __( $value['title'], 'wpforo') ).'</option>';
619 + || (!isset($permissions_arr[$groupid]) && (($name == 'Guest' && $value['access'] == 'read_only')
620 + || ($name == 'Registered' && $value['access'] == 'standard')
621 + || ($name == 'Customer' && $value['access'] == 'standard')
622 + || ($name == 'Moderator' && $value['access'] == 'moderator')
623 + || ($name == 'Admin' && $value['access'] == 'full'))) ? 'selected' : '').'>'.esc_html($value['title']).'</option>';
773 624 }
774 625 echo'
775 626 </select>
776 627 </td>
@@ -858,20 +709,14 @@
858 709 }
859 710
860 711 function get_forum_url($forum){
861 712
862 - if( !is_array($forum) ){
863 - if(is_numeric($forum)){
864 - $forum = $this->get_forum($forum);
865 - }else{
866 - $forum = array('slug' => $forum);
867 - }
868 - }
713 + if( !is_array($forum) ) $forum = $this->get_forum($forum);
869 714
870 715 if( is_array($forum) && !empty($forum) ){
871 - return wpforo_home_url( utf8_uri_encode($forum['slug']) );
716 + return WPFORO_BASE_URL . $forum['slug'];
872 717 }else{
873 - return wpforo_home_url();
718 + return WPFORO_BASE_URL;
874 719 }
875 720 }
876 721
877 722 function get_all_relative_ids($forumid, &$relative_ids){
@@ -885,61 +730,10 @@
885 730 $relative_ids = array_reverse($relative_ids);
886 731 }
887 732 }
888 733
889 - function get_count( $args = array() ){
890 - $sql = "SELECT COUNT(`forumid`) FROM `".$this->wpforo->db->prefix."wpforo_forums`";
891 - if( !empty($args) ){
892 - $wheres = array();
893 - foreach ($args as $key => $value) $wheres[] = "`$key` = " . intval($value);
894 - if($wheres) $sql .= " WHERE " . implode(' AND ', $wheres);
895 - }
896 - return $this->wpforo->db->get_var($sql);
734 + function get_count(){
735 + return $this->wpforo->db->get_var( "SELECT COUNT(`forumid`) FROM `".$this->wpforo->db->prefix."wpforo_forums`" );
897 736 }
898 -
899 - function get_lastinfo( $ids = array() ){
900 - $lastinfo = array();
901 - if(!empty($ids)){
902 - $ids = implode(',', array_map('intval', $ids));
903 - $lastinfo = $this->wpforo->db->get_row( "SELECT `userid` as last_userid, `topicid` as last_topicid, `postid` as last_postid, `created` as last_post_date FROM `" . $this->wpforo->db->prefix . "wpforo_posts` WHERE forumid IN(" . $ids .") ORDER BY `created` DESC LIMIT 1", ARRAY_A);
904 - }
905 - return $lastinfo;
906 - }
907 -
908 - function forums(){
909 - $forums = $this->get_forums( array('parentid' => 0) );
910 - return $this->children($forums);
911 - }
912 -
913 - function children($forums, $parentId = 0, $level = 0) {
914 - if(empty($forums) || !is_array($forums)) return;
915 - $items = array();
916 - $level = $level + 1;
917 - foreach ($forums as $forum) {
918 - if ( !isset($forum['forumid']) || !$this->wpforo->perm->forum_can('vf', $forum['forumid'])) continue;
919 - $forum['level'] = $level + 1;
920 - if ($forum['parentid'] == $parentId) {
921 - $children = $this->children($forums, $forum['forumid'], $level);
922 - if ($children) {
923 - $forum['children'] = $children;
924 - }
925 - $items[] = $forum;
926 - }
927 - }
928 - return $items;
929 - }
930 -
931 - function dropdown( $forums = array() ){
932 - if( empty($forums) ){
933 - $forums = $this->forums();
934 - }
935 - foreach( $forums as $forum ){
936 - if( isset($forum['level']) ) $forum['level'] = $forum['level'] - 2;
937 - $prefix = ( $forum['level'] == 0 ) ? '' : str_repeat( '&mdash;', $forum['level']);
938 - echo '<option value="' . esc_attr( $forum['forumid'] ) . '"> ' . $prefix . '&nbsp;' . esc_html($forum['title']) . '</option>';
939 - if( !empty($forum['children']) ){
940 - $this->dropdown( $forum['children'] );
941 - }
942 - }
943 - }
944 -
945 -}
737 +}
738 +
739 +?>