| @@ -5,17 +5,13 @@ | ||
| 5 | 5 | |
| 6 | 6 | class wpForoForum{ |
| 7 | 7 | |
| 8 | 8 | private $wpforo; |
| 9 | - static $cache = array( 'forums' => array(), 'forum' => array(), 'item' => array() ); | |
| 9 | + private static $cache = array(); | |
| 10 | 10 | |
| 11 | - public function __construct( $wpForo ){ | |
| 11 | + function __construct( $wpForo ){ | |
| 12 | 12 | if(!isset($this->wpforo)) $this->wpforo = $wpForo; |
| 13 | 13 | } |
| 14 | - | |
| 15 | - public function get_cache( $var ){ | |
| 16 | - if( isset(self::$cache[$var]) ) return self::$cache[$var]; | |
| 17 | - } | |
| 18 | 14 | |
| 19 | 15 | private function unique_slug($slug, $parentid = 0, $forumid = 0){ |
| 20 | 16 | $new_slug = wpforo_text($slug, 250, false); |
| 21 | 17 | $forumid = intval($forumid); |
| @@ -32,9 +28,9 @@ | ||
| 32 | 28 | return $new_slug; |
| 33 | 29 | } |
| 34 | 30 | |
| 35 | 31 | public function add( $args = array(), $checkperm = TRUE ){ |
| 36 | - if( $checkperm && !$this->wpforo->perm->usergroup_can('cf') ){ | |
| 32 | + if( $checkperm && !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'cf') ){ | |
| 37 | 33 | $this->wpforo->notice->add('Permission denied for add forum', 'error'); |
| 38 | 34 | return FALSE; |
| 39 | 35 | } |
| 40 | 36 | |
| @@ -49,9 +45,9 @@ | ||
| 49 | 45 | } |
| 50 | 46 | |
| 51 | 47 | $title = sanitize_text_field($title); |
| 52 | 48 | $title = wpforo_text($title, 250, false); |
| 53 | - $description = (isset($description) ? wpforo_kses($description, 'post') : ''); | |
| 49 | + $description = (isset($description) ? wpforo_kses($description) : ''); | |
| 54 | 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";}'; |
| 55 | 51 | $meta_key = (isset($meta_key)) ? sanitize_text_field($meta_key) : ''; |
| 56 | 52 | $meta_desc = (isset($meta_desc)) ? sanitize_text_field($meta_desc) : ''; |
| 57 | 53 | $parentid = (isset($parentid)) ? intval($parentid) : 0; |
| @@ -91,13 +87,10 @@ | ||
| 91 | 87 | ), |
| 92 | 88 | array('%s','%s','%s','%d','%s','%d','%d','%s','%s','%s','%d','%d','%d','%d') |
| 93 | 89 | ) |
| 94 | 90 | ){ |
| 95 | - $forumid = $this->wpforo->db->insert_id; | |
| 96 | - $this->delete_tree_cache(); | |
| 97 | - wpforo_clean_cache($forumid, 'forum'); | |
| 98 | 91 | $this->wpforo->notice->add('Your forum successfully added', 'success'); |
| 99 | - return $forumid; | |
| 92 | + return $this->wpforo->db->insert_id; | |
| 100 | 93 | } |
| 101 | 94 | |
| 102 | 95 | $this->wpforo->notice->add('Can\'t add forum', 'error'); |
| 103 | 96 | return FALSE; |
| @@ -103,9 +96,9 @@ | ||
| 103 | 96 | return FALSE; |
| 104 | 97 | } |
| 105 | 98 | |
| 106 | 99 | public function edit( $args = array() ){ |
| 107 | - if( !$this->wpforo->perm->usergroup_can('ef') ){ | |
| 100 | + if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'ef') ){ | |
| 108 | 101 | $this->wpforo->notice->add('Permission denied for edit forum', 'error'); |
| 109 | 102 | return FALSE; |
| 110 | 103 | } |
| 111 | 104 | |
| @@ -127,9 +120,9 @@ | ||
| 127 | 120 | |
| 128 | 121 | $forumid = intval($forumid); |
| 129 | 122 | $title = sanitize_text_field($title); |
| 130 | 123 | $title = wpforo_text($title, 250, false); |
| 131 | - $description = wpforo_kses($description, 'post'); | |
| 124 | + $description = wpforo_kses($description); | |
| 132 | 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";}'; |
| 133 | 126 | $meta_key = (isset($meta_key)) ? sanitize_text_field($meta_key) : ''; |
| 134 | 127 | $meta_desc = (isset($meta_desc)) ? sanitize_text_field($meta_desc) : ''; |
| 135 | 128 | $parentid = (isset($parentid)) ? intval($parentid) : 0; |
| @@ -151,11 +144,11 @@ | ||
| 151 | 144 | |
| 152 | 145 | if( FALSE !== $this->wpforo->db->update( |
| 153 | 146 | $this->wpforo->db->prefix . 'wpforo_forums', |
| 154 | 147 | array( |
| 155 | - 'title' => stripslashes($title), | |
| 148 | + 'title' => $title, | |
| 156 | 149 | 'slug' => $slug, |
| 157 | - 'description' => stripslashes($description), | |
| 150 | + 'description' => $description, | |
| 158 | 151 | 'parentid' => $parentid, |
| 159 | 152 | 'icon' => $icon, |
| 160 | 153 | 'permissions' => $permission, |
| 161 | 154 | 'meta_key' => $meta_key, |
| @@ -174,10 +167,8 @@ | ||
| 174 | 167 | $this->get_childs($forumid, $childs); |
| 175 | 168 | $sql = "UPDATE `".$this->wpforo->db->prefix . "wpforo_forums` SET `cat_layout` = ".intval($cat_layout)." WHERE `forumid` IN(". implode(',', array_map('intval', $childs)).")"; |
| 176 | 169 | $this->wpforo->db->query($sql); |
| 177 | 170 | } |
| 178 | - $this->delete_tree_cache(); | |
| 179 | - wpforo_clean_cache($forumid, 'forum'); | |
| 180 | 171 | $this->wpforo->notice->add('Forum successfully updated', 'success'); |
| 181 | 172 | return $forumid; |
| 182 | 173 | } |
| 183 | 174 | |
| @@ -184,52 +175,51 @@ | ||
| 184 | 175 | $this->wpforo->notice->add('Forum update error', 'error'); |
| 185 | 176 | return FALSE; |
| 186 | 177 | } |
| 187 | 178 | |
| 188 | - public function delete($forumid = 0){ | |
| 189 | - $forumid = intval($forumid); | |
| 190 | - if(!$forumid && isset( $_REQUEST['id'] ) ) $forumid = intval($_REQUEST['id']); | |
| 191 | - | |
| 192 | - if( !$this->wpforo->perm->usergroup_can('df') ){ | |
| 179 | + function delete(){ | |
| 180 | + if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'df') ){ | |
| 193 | 181 | $this->wpforo->notice->add('Permission denied for delete forum', 'error'); |
| 194 | 182 | return FALSE; |
| 195 | 183 | } |
| 196 | 184 | |
| 197 | - $childs = array(); | |
| 198 | - $this->get_childs($forumid, $childs); | |
| 199 | - $forumids = implode(',', array_map('intval', $childs)); | |
| 200 | - | |
| 201 | - // START delete topic posts include first post | |
| 202 | - if( $topicids = $this->wpforo->db->get_col( "SELECT `topicid` FROM ".$this->wpforo->db->prefix."wpforo_topics WHERE `forumid` IN(". esc_sql($forumids) .")" ) ){ | |
| 203 | - foreach($topicids as $topicid){ | |
| 204 | - $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 | + } | |
| 205 | 203 | } |
| 206 | - } | |
| 207 | - // END delete topic posts include first post | |
| 208 | - | |
| 209 | - if($this->wpforo->db->query( "DELETE FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `forumid` IN(". esc_sql($forumids) .")" )){ | |
| 210 | - $this->delete_tree_cache(); | |
| 211 | - wpforo_clean_cache(); | |
| 212 | - $this->wpforo->notice->add('Your forum successfully deleted', 'success'); | |
| 213 | - return TRUE; | |
| 214 | - } | |
| 215 | - | |
| 216 | - $this->wpforo->notice->add('Forum deleting error', 'error'); | |
| 217 | - return FALSE; | |
| 218 | - } | |
| 219 | - | |
| 220 | - public function merge($forumid = 0, $mergeid = 0){ | |
| 221 | - $forumid = intval($forumid); | |
| 222 | - $mergeid = intval($mergeid); | |
| 223 | - | |
| 224 | - if(!$forumid && isset( $_REQUEST['id'] ) ) $forumid = intval($_REQUEST['id']); | |
| 225 | - if(!$mergeid && isset( $_REQUEST['forum']['mergeid'] ) ) $mergeid = intval($_REQUEST['forum']['mergeid']); | |
| 226 | - | |
| 227 | - if( !$forumid || !$mergeid ) return false; | |
| 228 | - | |
| 229 | - if( $child_forumids = $this->get_child_forums( $forumid ) ){ | |
| 230 | - $forumids = trim( implode(',', array_map('intval', $child_forumids)) ); | |
| 231 | - 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 | + | |
| 232 | 222 | $merge_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($mergeid) ); |
| 233 | 223 | |
| 234 | 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) .")" )){ |
| 235 | 225 | $this->wpforo->notice->add('Forum merging error', 'error'); |
| @@ -234,38 +224,26 @@ | ||
| 234 | 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) .")" )){ |
| 235 | 225 | $this->wpforo->notice->add('Forum merging error', 'error'); |
| 236 | 226 | return FALSE; |
| 237 | 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 | + } | |
| 238 | 244 | } |
| 239 | 245 | } |
| 240 | - | |
| 241 | - $this->wpforo->db->update( | |
| 242 | - $this->wpforo->db->prefix . 'wpforo_topics', | |
| 243 | - array( 'forumid' => $mergeid ), | |
| 244 | - array( 'forumid' => $forumid ), | |
| 245 | - array( '%d' ), | |
| 246 | - array( '%d' ) | |
| 247 | - ); | |
| 248 | - $this->wpforo->db->update( | |
| 249 | - $this->wpforo->db->prefix . 'wpforo_posts', | |
| 250 | - array( 'forumid' => $mergeid ), | |
| 251 | - array( 'forumid' => $forumid ), | |
| 252 | - array( '%d' ), | |
| 253 | - array( '%d' ) | |
| 254 | - ); | |
| 255 | - | |
| 256 | - $this->rebuild_last_infos($mergeid); | |
| 257 | - $this->rebuild_stats($mergeid); | |
| 258 | - | |
| 259 | - if($this->wpforo->db->delete( $this->wpforo->db->prefix.'wpforo_forums', array( 'forumid' => $forumid ), array( '%d' ) )){ | |
| 260 | - $this->delete_tree_cache(); | |
| 261 | - wpforo_clean_cache(0, 'forum'); | |
| 262 | - $this->wpforo->notice->add('Forum is successfully merged', 'success'); | |
| 263 | - return TRUE; | |
| 264 | - } | |
| 265 | - | |
| 266 | - $this->wpforo->notice->add('Forum merging error', 'error'); | |
| 267 | - return FALSE; | |
| 268 | 246 | } |
| 269 | 247 | |
| 270 | 248 | public function rebuild_last_infos($forumid){ |
| 271 | 249 | |
| @@ -295,33 +273,11 @@ | ||
| 295 | 273 | $this->wpforo->db->query( "UPDATE `".$this->wpforo->db->prefix."wpforo_forums` |
| 296 | 274 | SET `last_topicid` = ".intval($last_topicid).", `last_postid` = ".intval($last_postid).", |
| 297 | 275 | `last_userid` = ".intval($last_userid).", `last_post_date` = '".esc_sql($last_post_date)."' |
| 298 | 276 | WHERE `forumid` = ".intval($forumid) ); |
| 299 | - wpforo_clean_cache(0, 'forum'); | |
| 300 | 277 | } |
| 301 | - | |
| 302 | - public function rebuild_stats($forumid){ | |
| 303 | - if( !$forumid = intval($forumid) ) return false; | |
| 304 | - $topics = $this->wpforo->topic->get_count( array('forumid' => $forumid) ); | |
| 305 | - $posts = $this->wpforo->post->get_count( array('forumid' => $forumid) ); | |
| 306 | - | |
| 307 | - if( false !== $this->wpforo->db->update( | |
| 308 | - $this->wpforo->db->prefix . "wpforo_forums", | |
| 309 | - array('topics' => $topics, 'posts' => $posts ), | |
| 310 | - array('forumid' => $forumid), | |
| 311 | - array('%d', '%d'), | |
| 312 | - array('%d') | |
| 313 | - ) ) { | |
| 314 | - wpforo_clean_cache(0, 'forum'); | |
| 315 | - return true; | |
| 316 | - } | |
| 317 | - return false; | |
| 318 | - } | |
| 319 | 278 | |
| 320 | - function get_forum( $args){ | |
| 321 | - | |
| 322 | - $cache = $this->wpforo->cache->on('memory_cashe'); | |
| 323 | - | |
| 279 | + function get_forum( $args, $cache = false){ | |
| 324 | 280 | if(is_array($args)){ |
| 325 | 281 | $default = array( |
| 326 | 282 | 'forumid' => NULL, // forumid |
| 327 | 283 | 'slug' => '', // slug |
| @@ -330,10 +286,10 @@ | ||
| 330 | 286 | 'type' => 'all' // category, forum |
| 331 | 287 | ); |
| 332 | 288 | }else{ |
| 333 | 289 | $default = array( |
| 334 | - 'forumid' => ( is_numeric($args) ? intval($args) : NULL ), // forumid | |
| 335 | - 'slug' => ( !is_numeric($args) ? $args : '' ), // slug | |
| 290 | + 'forumid' => $args, // forumid | |
| 291 | + 'slug' => '', // slug | |
| 336 | 292 | 'cat_layout' => 1, // forum layout |
| 337 | 293 | 'status' => NULL, // status forum 1 OR 0 |
| 338 | 294 | 'type' => 'all' // category, forum |
| 339 | 295 | ); |
| @@ -338,22 +294,16 @@ | ||
| 338 | 294 | 'type' => 'all' // category, forum |
| 339 | 295 | ); |
| 340 | 296 | } |
| 341 | 297 | $args = wpforo_parse_args( $args, $default ); |
| 342 | - | |
| 343 | - if( $cache && !empty($args['forumid']) ){ | |
| 344 | - if( !empty(self::$cache['forum'][$args['forumid']]) ){ | |
| 298 | + if(isset($args['forumid'])){ | |
| 299 | + if( isset(self::$cache['forum'][$args['forumid']]) ){ | |
| 345 | 300 | return self::$cache['forum'][$args['forumid']]; |
| 346 | 301 | } |
| 347 | 302 | } |
| 348 | - | |
| 349 | - if( $cache && !empty($args['slug']) ){ | |
| 350 | - if( !empty(self::$cache['forum'][addslashes($args['slug'])]) ){ | |
| 351 | - return self::$cache['forum'][addslashes($args['slug'])]; | |
| 352 | - } | |
| 353 | - } | |
| 354 | 303 | if(!empty($args)){ |
| 355 | 304 | extract($args, EXTR_OVERWRITE); |
| 305 | + | |
| 356 | 306 | $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_forums`"; |
| 357 | 307 | $wheres = array(); |
| 358 | 308 | if($forumid != NULL) $wheres[] = "`forumid` = " . intval($forumid); |
| 359 | 309 | if($status != NULL) $wheres[] = "`status` = " . intval($status); |
| @@ -361,9 +311,9 @@ | ||
| 361 | 311 | $wheres[] = "`is_cat` = 1"; |
| 362 | 312 | }elseif($type == 'forum'){ |
| 363 | 313 | $wheres[] = "`is_cat` = 0"; |
| 364 | 314 | } |
| 365 | - if($slug != '') $wheres[] = "`slug` = '" . esc_sql($slug) . "'"; | |
| 315 | + if($slug != '') $wheres[] = "`slug` = '" . sanitize_title($slug) . "'"; | |
| 366 | 316 | |
| 367 | 317 | if(!empty($wheres)){ |
| 368 | 318 | $sql .= " WHERE " . implode( " AND ", $wheres ); |
| 369 | 319 | } |
| @@ -370,12 +320,10 @@ | ||
| 370 | 320 | $forum = $this->wpforo->db->get_row($sql, ARRAY_A); |
| 371 | 321 | if(!empty($forum)) { |
| 372 | 322 | $forum['url'] = $this->get_forum_url( $forum ); |
| 373 | 323 | } |
| 374 | - $forum = apply_filters('wpforo_get_forum', $forum); | |
| 375 | 324 | if($cache && isset($forumid)){ |
| 376 | - self::$cache['forum'][addslashes($forum['slug'])] = $forum; | |
| 377 | - return self::$cache['forum'][$forum['forumid']] = $forum; | |
| 325 | + return self::$cache['forum'][$forumid] = $forum; | |
| 378 | 326 | } |
| 379 | 327 | else{ |
| 380 | 328 | return $forum; |
| 381 | 329 | } |
| @@ -381,12 +329,9 @@ | ||
| 381 | 329 | } |
| 382 | 330 | } |
| 383 | 331 | } |
| 384 | 332 | |
| 385 | - function get_forums($args = array(), &$items_count = 0 ){ | |
| 386 | - | |
| 387 | - $cache = $this->wpforo->cache->on('object_cashe'); | |
| 388 | - | |
| 333 | + function get_forums($args = array(), &$items_count = 0){ | |
| 389 | 334 | $default = array( |
| 390 | 335 | 'include' => array(), // array( 2, 10, 25 ) |
| 391 | 336 | 'exclude' => array(), // array( 2, 10, 25 ) |
| 392 | 337 | 'parent_include' => array(), // array( 2, 10, 25 ) |
| @@ -402,9 +347,8 @@ | ||
| 402 | 347 | ); |
| 403 | 348 | |
| 404 | 349 | $args = wpforo_parse_args( $args, $default ); |
| 405 | 350 | if(is_array($args) && !empty($args)){ |
| 406 | - | |
| 407 | 351 | extract($args, EXTR_OVERWRITE); |
| 408 | 352 | |
| 409 | 353 | $include = wpforo_parse_args( $include ); |
| 410 | 354 | $exclude = wpforo_parse_args( $exclude ); |
| @@ -426,14 +370,13 @@ | ||
| 426 | 370 | }elseif($type == 'forum'){ |
| 427 | 371 | $wheres[] = " `is_cat` = 0"; |
| 428 | 372 | } |
| 429 | 373 | |
| 430 | - if($parent_slug != '') $wheres[] = "`slug` = '" . esc_sql($parent_slug) . "'"; | |
| 374 | + if($parent_slug != '') $wheres[] = "`slug` = '" . esc_sql(sanitize_text_field($parent_slug)) . "'"; | |
| 431 | 375 | |
| 432 | 376 | if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres ); |
| 433 | 377 | |
| 434 | - $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql); | |
| 435 | - 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)); | |
| 436 | 379 | |
| 437 | 380 | $sql .= esc_sql(" ORDER BY `$orderby` " . $order); |
| 438 | 381 | |
| 439 | 382 | if($row_count != NULL){ |
| @@ -443,18 +386,10 @@ | ||
| 443 | 386 | $sql .= esc_sql(" LIMIT $row_count"); |
| 444 | 387 | } |
| 445 | 388 | } |
| 446 | 389 | |
| 447 | - 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); | |
| 448 | 391 | |
| 449 | - $forums = $this->wpforo->db->get_results($sql, ARRAY_A); | |
| 450 | - $forums = apply_filters('wpforo_get_topics', $forums); | |
| 451 | - | |
| 452 | - if($cache && isset($object_key) && !empty($forums)){ | |
| 453 | - self::$cache['forums'][$object_key]['items'] = $forums; | |
| 454 | - self::$cache['forums'][$object_key]['items_count'] = $items_count; | |
| 455 | - } | |
| 456 | - return $forums; | |
| 457 | 392 | } |
| 458 | 393 | } |
| 459 | 394 | |
| 460 | 395 | function search($needle, $fields = array()){ |
| @@ -484,11 +419,8 @@ | ||
| 484 | 419 | return array(); |
| 485 | 420 | } |
| 486 | 421 | |
| 487 | 422 | function update_hierarchy(){ |
| 488 | - | |
| 489 | - $this->delete_tree_cache(); | |
| 490 | - | |
| 491 | 423 | if(is_array($_REQUEST['forum']) && !empty($_REQUEST['forum'])){ |
| 492 | 424 | $i = 0; |
| 493 | 425 | foreach($_REQUEST['forum'] as $hierarchy){ |
| 494 | 426 | |
| @@ -589,9 +521,9 @@ | ||
| 589 | 521 | if( isset($_GET['page']) && $_GET['page'] == 'wpforo-ads' && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id']) && $_GET['id'] ){ |
| 590 | 522 | $ad = $wpforo->ad->get_ad($_GET['id']); |
| 591 | 523 | $ad_forumids = explode(',', $ad['forumids']); |
| 592 | 524 | } |
| 593 | - ?><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 | |
| 594 | 526 | }elseif($type == 'drag_menu'){ |
| 595 | 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); |
| 596 | 528 | $cat_layout_name = ( $cur_forum['cat_layout'] == 2 ? 'Simplified Layout' : ( $cur_forum['cat_layout'] == 3 ? 'QA Layout' : 'Extended Layout' ) ); ?> |
| 597 | 529 | |
| @@ -600,19 +532,17 @@ | ||
| 600 | 532 | <input id="parentid-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][parentid]"/> |
| 601 | 533 | <input id="order-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][order]"/> |
| 602 | 534 | <dl class="menu-item-bar"> |
| 603 | 535 | <dt class="menu-item-handle forum_width"> |
| 604 | - <span class="item-title forumtitle"><span style="font-weight:400; cursor:help;" title="Forum ID"><?php echo $forumid; ?> | </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') . ' (' . intval($cur_forum['topics']) . ') , ' . __('Posts', 'wpforo') . ' (' . intval($cur_forum['posts']) . ') ' : '' ) ?><?php echo ( $depth == 0 ? '( <i>' . esc_html($cat_layout_name) . '</i> )' : '' ); ?></span> | |
| 605 | 538 | <span class="item-controls"> |
| 606 | - <span class="wpforo-cat-layout"><?php echo ( $depth != 0 ? __('Topics', 'wpforo') . ' (' . intval($cur_forum['topics']) . ') , ' . __('Posts', 'wpforo') . ' (' . intval($cur_forum['posts']) . ') | ' : '' ) ?><?php echo ( $depth == 0 ? '( <i>' . esc_html($cat_layout_name) . '</i> ) | ' : '' ); ?></span> | |
| 607 | - <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> | | |
| 608 | - <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> | | |
| 609 | - <?php if( $this->wpforo->perm->usergroup_can('df') ): ?> | |
| 610 | - <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> | | |
| 611 | - <?php endif; ?> | |
| 612 | - <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> | |
| 613 | - | |
| 614 | - </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> | | |
| 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> | | |
| 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> | |
| 615 | 545 | </dt> |
| 616 | 546 | </dl> |
| 617 | 547 | <ul class="menu-item-transport"></ul> |
| 618 | 548 | </li> |
| @@ -625,16 +555,16 @@ | ||
| 625 | 555 | if(isset($old_depth) && $old_depth > $depth) echo '</dd></dl>'; |
| 626 | 556 | $old_depth = $depth; |
| 627 | 557 | if(isset($wpforo->current_object) && isset($wpforo->current_object['forumid'])){ |
| 628 | 558 | if( $forumid == $wpforo->current_object['forumid'] ){ |
| 629 | - 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') ) . '" > »</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)) . '" > »</a></span>'; | |
| 630 | 560 | } |
| 631 | 561 | else{ |
| 632 | - 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>'; | |
| 633 | 563 | } |
| 634 | 564 | } |
| 635 | 565 | else{ |
| 636 | - 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>'; | |
| 637 | 567 | } |
| 638 | 568 | } |
| 639 | 569 | $subforums = $this->get_child_forums($forumid); |
| 640 | 570 | if( !empty($subforums) ){ |
| @@ -642,41 +572,19 @@ | ||
| 642 | 572 | } |
| 643 | 573 | } |
| 644 | 574 | } |
| 645 | 575 | |
| 646 | - function tree( $type = 'front_list', $cats = TRUE, $topicid = 0 ){ | |
| 576 | + function tree($type = 'front_list', $cats = TRUE, $topicid = 0){ | |
| 647 | 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); |
| 648 | 578 | if(!empty($parentids)){ |
| 649 | 579 | foreach( $parentids as $parentid ){ |
| 650 | 580 | $data[] = $parentid['parentid']; |
| 651 | 581 | } |
| 652 | - if( !wpforo_is_admin() ){ | |
| 653 | - $key = md5( serialize($data) . $type . (int)$cats . $this->wpforo->current_user_groupid ); | |
| 654 | - $html = get_option( 'wpforo_forum_tree_' . $key ); | |
| 655 | - if( $html ){ | |
| 656 | - echo $html; | |
| 657 | - } | |
| 658 | - elseif( function_exists('ob_start') ){ | |
| 659 | - ob_start(); | |
| 660 | - $this->forum_list($data, $type, $cats); | |
| 661 | - $html = ob_get_clean(); | |
| 662 | - if($type != 'drag_menu'){ | |
| 663 | - update_option( 'wpforo_forum_tree_' . $key, $html ); | |
| 664 | - } | |
| 665 | - echo $html; | |
| 666 | - } | |
| 667 | - } | |
| 668 | - else{ | |
| 669 | - $this->forum_list($data, $type, $cats); | |
| 670 | - } | |
| 582 | + $this->forum_list($data, $type, $cats); | |
| 671 | 583 | } |
| 672 | 584 | } |
| 673 | 585 | // end forums tree for drop down menu |
| 674 | 586 | |
| 675 | - public function delete_tree_cache() { | |
| 676 | - $this->wpforo->db->query("DELETE FROM " . $this->wpforo->db->options . " WHERE `option_name` LIKE 'wpforo_forum_tree_%'"); | |
| 677 | - } | |
| 678 | - | |
| 679 | 587 | function parentid( $topicid = 0 ){ |
| 680 | 588 | if(isset($_GET['page']) && $_GET['page'] == 'wpforo-forums'){ |
| 681 | 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'])); |
| 682 | 590 | } |
| @@ -682,9 +590,9 @@ | ||
| 682 | 590 | } |
| 683 | 591 | elseif( isset($_GET['page']) && $_GET['page'] == 'wpforo-topics' ){ |
| 684 | 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'])); |
| 685 | 593 | }else{ |
| 686 | - 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)); | |
| 687 | 595 | } |
| 688 | 596 | } |
| 689 | 597 | |
| 690 | 598 | function permissions(){ |
| @@ -705,18 +613,15 @@ | ||
| 705 | 613 | <td>'.esc_html($name).'</td> |
| 706 | 614 | <td> |
| 707 | 615 | <select name="forum[permission]['.intval($groupid).']">'; |
| 708 | 616 | foreach($access_arr as $value){ |
| 709 | - | |
| 710 | 617 | echo '<option value="'.esc_attr($value['access']).'" '. |
| 711 | 618 | ((isset($permissions_arr[$groupid]) && $value['access'] == $permissions_arr[$groupid]) |
| 712 | - || (!isset($permissions_arr[$groupid]) | |
| 713 | - && (($name == 'Guest' && $value['access'] == 'read_only') | |
| 714 | - || ($name == 'Registered' && $value['access'] == 'standard') | |
| 715 | - || ($name == 'Customer' && $value['access'] == 'standard') | |
| 716 | - || ($name == 'Moderator' && $value['access'] == 'moderator') | |
| 717 | - || ($name == 'Admin' && $value['access'] == 'full') | |
| 718 | - || ($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>'; | |
| 719 | 624 | } |
| 720 | 625 | echo' |
| 721 | 626 | </select> |
| 722 | 627 | </td> |
| @@ -804,20 +709,14 @@ | ||
| 804 | 709 | } |
| 805 | 710 | |
| 806 | 711 | function get_forum_url($forum){ |
| 807 | 712 | |
| 808 | - if( !is_array($forum) ){ | |
| 809 | - if(is_numeric($forum)){ | |
| 810 | - $forum = $this->get_forum($forum); | |
| 811 | - }else{ | |
| 812 | - $forum = array('slug' => $forum); | |
| 813 | - } | |
| 814 | - } | |
| 713 | + if( !is_array($forum) ) $forum = $this->get_forum($forum); | |
| 815 | 714 | |
| 816 | 715 | if( is_array($forum) && !empty($forum) ){ |
| 817 | - return wpforo_home_url( utf8_uri_encode($forum['slug']) ); | |
| 716 | + return WPFORO_BASE_URL . $forum['slug']; | |
| 818 | 717 | }else{ |
| 819 | - return wpforo_home_url(); | |
| 718 | + return WPFORO_BASE_URL; | |
| 820 | 719 | } |
| 821 | 720 | } |
| 822 | 721 | |
| 823 | 722 | function get_all_relative_ids($forumid, &$relative_ids){ |
| @@ -831,25 +730,10 @@ | ||
| 831 | 730 | $relative_ids = array_reverse($relative_ids); |
| 832 | 731 | } |
| 833 | 732 | } |
| 834 | 733 | |
| 835 | - function get_count( $args = array() ){ | |
| 836 | - $sql = "SELECT COUNT(`forumid`) FROM `".$this->wpforo->db->prefix."wpforo_forums`"; | |
| 837 | - if( !empty($args) ){ | |
| 838 | - $wheres = array(); | |
| 839 | - foreach ($args as $key => $value) $wheres[] = "`$key` = " . intval($value); | |
| 840 | - if($wheres) $sql .= " WHERE " . implode(' AND ', $wheres); | |
| 841 | - } | |
| 842 | - return $this->wpforo->db->get_var($sql); | |
| 843 | - } | |
| 844 | - | |
| 845 | - function get_lastinfo( $ids = array() ){ | |
| 846 | - $lastinfo = array(); | |
| 847 | - if(!empty($ids)){ | |
| 848 | - $ids = implode(',', array_map('intval', $ids)); | |
| 849 | - $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); | |
| 850 | - } | |
| 851 | - return $lastinfo; | |
| 734 | + function get_count(){ | |
| 735 | + return $this->wpforo->db->get_var( "SELECT COUNT(`forumid`) FROM `".$this->wpforo->db->prefix."wpforo_forums`" ); | |
| 852 | 736 | } |
| 853 | 737 | } |
| 854 | 738 | |
| 855 | 739 | ?> |