PluginProbe
wpForo Forum / 1.1.0
wpForo Forum v1.1.0
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 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / class-forums.php

class-forums.php in wpForo Forum 1.1.0, at wpf-includes/class-forums.php

768 lines 30.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5
6 class wpForoForum{
7
8 private $wpforo;
9 private static $cache = array();
10
11 function __construct( $wpForo ){
12 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
13 }
14
15 private function unique_slug($slug, $parentid = 0, $forumid = 0){
16 $new_slug = wpforo_text($slug, 250, false);
17 $forumid = intval($forumid);
18 $i = 2;
19 while( $this->wpforo->db->get_var("SELECT `forumid` FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `slug` = '" . esc_sql($new_slug) . "'" . ($forumid ? ' AND `forumid` != '. intval($forumid) : '')) ){
20 if( !isset($parent_slug) && $parentid = intval($parentid) ){
21 $parent_slug = $this->wpforo->db->get_var("SELECT `slug` FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `forumid` = " . intval($parentid) );
22 $new_slug = $parent_slug . "-" . wpforo_text($slug, 250, false);
23 }else{
24 $new_slug = wpforo_text($slug, 250, false) . '-' . $i;
25 }
26 $i++;
27 }
28 return $new_slug;
29 }
30
31 public function add( $args = array(), $checkperm = TRUE ){
32 if( $checkperm && !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'cf') ){
33 $this->wpforo->notice->add('Permission denied for add forum', 'error');
34 return FALSE;
35 }
36
37 if( empty($args) && empty($_REQUEST['forum']) ) return FALSE;
38 if( empty($args) && !empty($_REQUEST['forum']) ) $args = $_REQUEST['forum'];
39
40 extract($args, EXTR_OVERWRITE);
41
42 if( !isset($title) || !$title ){
43 $this->wpforo->notice->add('Please insert required fields!', 'error');
44 return FALSE;
45 }
46
47 $title = sanitize_text_field($title);
48 $title = wpforo_text($title, 250, false);
49 $description = (isset($description) ? wpforo_kses($description, 'post') : '');
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";}';
51 $meta_key = (isset($meta_key)) ? sanitize_text_field($meta_key) : '';
52 $meta_desc = (isset($meta_desc)) ? sanitize_text_field($meta_desc) : '';
53 $parentid = (isset($parentid)) ? intval($parentid) : 0;
54 $slug = (isset($slug) && $slug) ? sanitize_title($slug) : ((isset($title)) ? sanitize_title($title) : md5(time()));
55 $slug = $this->unique_slug($slug, $parentid);
56 $icon = (isset($icon)) ? sanitize_text_field($icon) : '';
57 $topics = (isset($topics)) ? intval($topics) : 0;
58 $posts = (isset($posts)) ? intval($posts) : 0;
59 $order = (isset($order)) ? intval($order) : 0;
60 $cat_layout = (isset($cat_layout)) ? intval($cat_layout) : 1;
61 $status = (isset($status)) ? intval($status) : 1;
62 $is_cat = (isset($is_cat)) ? intval($is_cat) : 0;
63 if(!$parentid) $is_cat = 1;
64
65 if($parentid) {
66 $cat_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix ."wpforo_forums` WHERE `forumid` = " . intval($parentid) );
67 $cat_layout = intval($cat_layout);
68 }
69
70 if( $this->wpforo->db->insert(
71 $this->wpforo->db->prefix . 'wpforo_forums',
72 array(
73 'title' => stripslashes($title),
74 'slug' => $slug,
75 'description' => stripslashes($description),
76 'parentid' => $parentid,
77 'icon' => $icon,
78 'topics' => $topics,
79 'posts' => $posts,
80 'permissions' => $permission,
81 'meta_key' => $meta_key,
82 'meta_desc' => $meta_desc,
83 'status' => $status,
84 'is_cat' => $is_cat,
85 'cat_layout' => $cat_layout,
86 'order' => $order
87 ),
88 array('%s','%s','%s','%d','%s','%d','%d','%s','%s','%s','%d','%d','%d','%d')
89 )
90 ){
91 $this->wpforo->notice->add('Your forum successfully added', 'success');
92 return $this->wpforo->db->insert_id;
93 }
94
95 $this->wpforo->notice->add('Can\'t add forum', 'error');
96 return FALSE;
97 }
98
99 public function edit( $args = array() ){
100 if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'ef') ){
101 $this->wpforo->notice->add('Permission denied for edit forum', 'error');
102 return FALSE;
103 }
104
105 if( empty($args) && empty($_REQUEST['forum']) ) return FALSE;
106 if( empty($args) && !empty($_REQUEST['forum']) ) $args = $_REQUEST['forum'];
107 if( !isset($args['forumid']) && isset($_GET['id']) ) $args['forumid'] = $_GET['id'];
108
109 extract($args, EXTR_OVERWRITE);
110
111 if( !isset($forumid) || !$forumid ){
112 $this->wpforo->notice->add('Forum update error', 'error');
113 return FALSE;
114 }
115
116 if( !isset($title) || !$title ){
117 $this->wpforo->notice->add('Please insert required fields!', 'error');
118 return FALSE;
119 }
120
121 $forumid = intval($forumid);
122 $title = sanitize_text_field($title);
123 $title = wpforo_text($title, 250, false);
124 $description = wpforo_kses($description, 'post');
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";}';
126 $meta_key = (isset($meta_key)) ? sanitize_text_field($meta_key) : '';
127 $meta_desc = (isset($meta_desc)) ? sanitize_text_field($meta_desc) : '';
128 $parentid = (isset($parentid)) ? intval($parentid) : 0;
129 $slug = (isset($slug)) ? sanitize_title($slug) : ((isset($title)) ? sanitize_title($title) : md5(time()));
130 $slug = $this->unique_slug($slug, $parentid, $forumid);
131 $icon = (isset($icon)) ? sanitize_text_field($icon) : '';
132 $topics = (isset($topics)) ? intval($topics) : 0;
133 $posts = (isset($posts)) ? intval($posts) : 0;
134 $order = (isset($order)) ? intval($order) : 0;
135 $cat_layout = (isset($cat_layout)) ? intval($cat_layout) : 1;
136 $status = (isset($status)) ? intval($status) : 1;
137 $is_cat = (isset($is_cat)) ? intval($is_cat) : 0;
138 if(!$parentid) $is_cat = 1;
139
140 if($parentid) {
141 $cat_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix ."wpforo_forums` WHERE `forumid` = " . intval($parentid) );
142 $cat_layout = intval($cat_layout);
143 }
144
145 if( FALSE !== $this->wpforo->db->update(
146 $this->wpforo->db->prefix . 'wpforo_forums',
147 array(
148 'title' => stripslashes($title),
149 'slug' => $slug,
150 'description' => stripslashes($description),
151 'parentid' => $parentid,
152 'icon' => $icon,
153 'permissions' => $permission,
154 'meta_key' => $meta_key,
155 'meta_desc' => $meta_desc,
156 'status' => $status,
157 'is_cat' => $is_cat,
158 'cat_layout' => $cat_layout
159 ),
160 array('forumid' => $forumid),
161 array('%s','%s','%s','%d','%s','%s','%s','%s','%d','%d','%d'),
162 array('%d')
163 )
164 ){
165 if( isset($cat_layout) ){
166 $childs = array();
167 $this->get_childs($forumid, $childs);
168 $sql = "UPDATE `".$this->wpforo->db->prefix . "wpforo_forums` SET `cat_layout` = ".intval($cat_layout)." WHERE `forumid` IN(". implode(',', array_map('intval', $childs)).")";
169 $this->wpforo->db->query($sql);
170 }
171 $this->wpforo->notice->add('Forum successfully updated', 'success');
172 return $forumid;
173 }
174
175 $this->wpforo->notice->add('Forum update error', 'error');
176 return FALSE;
177 }
178
179 function delete(){
180 if( !$this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'df') ){
181 $this->wpforo->notice->add('Permission denied for delete forum', 'error');
182 return FALSE;
183 }
184
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 }
203 }
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
222 $merge_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($mergeid) );
223
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) .")" )){
225 $this->wpforo->notice->add('Forum merging error', 'error');
226 return FALSE;
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 }
244 }
245 }
246 }
247
248 public function rebuild_last_infos($forumid){
249
250 $forumid = intval($forumid);
251
252 $last_topicid = 0;
253 $last_postid = 0;
254 $last_userid = 0;
255 $last_post_date = '0000-00-00 00:00:00';
256
257 $last_topics = $this->wpforo->topic->get_topics( array('forumid' => $forumid, 'orderby' => 'topicid', 'order' => 'DESC', 'row_count' => 1) );
258 if(!empty($last_topics)){
259 $last_topic = $last_topics[0];
260 $last_topicid = $last_topic['topicid'];
261 }
262 $last_posts = $this->wpforo->topic->get_topics( array('forumid' => $forumid, 'orderby' => 'modified', 'order' => 'DESC', 'row_count' => 1) );
263 if(!empty($last_posts)){
264 $last_post = $last_posts[0];
265 $last_post_data = $this->wpforo->post->get_post($last_post['last_post']);
266 if(!empty($last_post_data)){
267 $last_postid = $last_post_data['postid'];
268 $last_userid = $last_post_data['userid'];
269 $last_post_date = $last_post_data['created'];
270 }
271 }
272
273 $this->wpforo->db->query( "UPDATE `".$this->wpforo->db->prefix."wpforo_forums`
274 SET `last_topicid` = ".intval($last_topicid).", `last_postid` = ".intval($last_postid).",
275 `last_userid` = ".intval($last_userid).", `last_post_date` = '".esc_sql($last_post_date)."'
276 WHERE `forumid` = ".intval($forumid) );
277 }
278
279 function get_forum( $args, $cache = false){
280 if(is_array($args)){
281 $default = array(
282 'forumid' => NULL, // forumid
283 'slug' => '', // slug
284 'status' => NULL, // status forum 1 OR 0
285 'cat_layout' => 1, // forum layout
286 'type' => 'all' // category, forum
287 );
288 }else{
289 $default = array(
290 'forumid' => ( is_numeric($args) ? intval($args) : NULL ), // forumid
291 'slug' => ( !is_numeric($args) ? $args : '' ), // slug
292 'cat_layout' => 1, // forum layout
293 'status' => NULL, // status forum 1 OR 0
294 'type' => 'all' // category, forum
295 );
296 }
297 $args = wpforo_parse_args( $args, $default );
298
299 if(!empty($args['forumid'])){
300 if( !empty(self::$cache['forum'][$args['forumid']]) ){
301 return self::$cache['forum'][$args['forumid']];
302 }
303 }
304
305 if(!empty($args['slug'])){
306 if( !empty(self::$cache['forum'][addslashes($args['slug'])]) ){
307 return self::$cache['forum'][addslashes($args['slug'])];
308 }
309 }
310 if(!empty($args)){
311 extract($args, EXTR_OVERWRITE);
312
313 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_forums`";
314 $wheres = array();
315 if($forumid != NULL) $wheres[] = "`forumid` = " . intval($forumid);
316 if($status != NULL) $wheres[] = "`status` = " . intval($status);
317 if($type == 'category'){
318 $wheres[] = "`is_cat` = 1";
319 }elseif($type == 'forum'){
320 $wheres[] = "`is_cat` = 0";
321 }
322 if($slug != '') $wheres[] = "`slug` = '" . esc_sql($slug) . "'";
323
324 if(!empty($wheres)){
325 $sql .= " WHERE " . implode( " AND ", $wheres );
326 }
327 $forum = $this->wpforo->db->get_row($sql, ARRAY_A);
328 if(!empty($forum)) {
329 $forum['url'] = $this->get_forum_url( $forum );
330 }
331 if($cache && isset($forumid)){
332 self::$cache['forum'][addslashes($forum['slug'])] = $forum;
333 return self::$cache['forum'][$forum['forumid']] = $forum;
334 }
335 else{
336 return $forum;
337 }
338 }
339 }
340
341 function get_forums($args = array(), &$items_count = 0){
342 $default = array(
343 'include' => array(), // array( 2, 10, 25 )
344 'exclude' => array(), // array( 2, 10, 25 )
345 'parent_include' => array(), // array( 2, 10, 25 )
346 'parent_exclude' => array(), // array( 2, 10, 25 )
347 'parentid' => NULL,
348 'parent_slug' => '',
349 'status' => NULL,
350 'type' => 'all', // category, forum
351 'orderby' => 'order', // order by `field`
352 'order' => 'ASC', // ASC DESC
353 'offset' => NULL, // OFFSET
354 'row_count' => NULL, // ROW COUNT
355 );
356
357 $args = wpforo_parse_args( $args, $default );
358 if(is_array($args) && !empty($args)){
359 extract($args, EXTR_OVERWRITE);
360
361 $include = wpforo_parse_args( $include );
362 $exclude = wpforo_parse_args( $exclude );
363 $parent_include = wpforo_parse_args( $parent_include );
364 $parent_exclude = wpforo_parse_args( $parent_exclude );
365
366 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_forums`";
367 $wheres = array();
368
369 if(!empty($include)) $wheres[] = "`forumid` IN(" . implode(', ', array_map('intval', $include)) . ")";
370 if(!empty($exclude)) $wheres[] = "`forumid` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
371 if(!empty($parent_include)) $wheres[] = "`parentid` IN(" . implode(', ', array_map('intval', $parent_include)) . ")";
372 if(!empty($parent_exclude)) $wheres[] = "`parentid` NOT IN(" . implode(', ', array_map('intval', $parent_exclude)) . ")";
373 if($parentid != NULL) $wheres[] = " `parentid` = " . intval($parentid);
374 if($status != NULL) $wheres[] = " `status` = " . intval($status);
375
376 if($type == 'category'){
377 $wheres[] = " `is_cat` = 1";
378 }elseif($type == 'forum'){
379 $wheres[] = " `is_cat` = 0";
380 }
381
382 if($parent_slug != '') $wheres[] = "`slug` = '" . esc_sql($parent_slug) . "'";
383
384 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
385
386 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
387 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
388
389 $sql .= esc_sql(" ORDER BY `$orderby` " . $order);
390
391 if($row_count != NULL){
392 if($offset != NULL){
393 $sql .= esc_sql(" LIMIT $offset,$row_count");
394 }else{
395 $sql .= esc_sql(" LIMIT $row_count");
396 }
397 }
398
399 return $this->wpforo->db->get_results($sql, ARRAY_A);
400
401 }
402 }
403
404 function search($needle, $fields = array()){
405
406 if($needle){
407 $needle = sanitize_text_field($needle);
408 if(empty($fields)){
409 $fields = array(
410 'title',
411 'description',
412 'meta_key',
413 'meta_desc'
414 );
415 }
416
417 $sql = "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_forums`";
418 $wheres = array();
419
420 foreach($fields as $field){
421 $wheres[] = "`" . esc_sql($field) . "` LIKE '%" . esc_sql($needle) . "%'";
422 }
423
424 $sql .= " WHERE " . implode(" OR ", $wheres);
425 return $this->wpforo->db->get_col($sql);
426 }
427
428 return array();
429 }
430
431 function update_hierarchy(){
432 if(is_array($_REQUEST['forum']) && !empty($_REQUEST['forum'])){
433 $i = 0;
434 foreach($_REQUEST['forum'] as $hierarchy){
435
436 extract($hierarchy, EXTR_OVERWRITE);
437
438 if(!isset($forumid) || !$forumid = intval($forumid) ) continue;
439
440 if(FALSE !== $this->wpforo->db->update(
441 $this->wpforo->db->prefix . 'wpforo_forums',
442 array(
443 'parentid' => (isset($parentid) ? intval($parentid) : 0),
444 'order' => (isset($order) ? intval($order) : 0),
445 ),
446 array( 'forumid' => intval($forumid) ),
447 array(
448 '%d',
449 '%d'
450 ),
451 array( '%d' )
452 )) $i++;
453
454 if(isset($parentid) && $parentid = intval($parentid) ){
455 $cat_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($parentid));
456 $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix."wpforo_forums` SET `cat_layout` = " . intval($cat_layout) . " WHERE `forumid` = " . intval($forumid));
457 }
458
459 }
460
461 $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix."wpforo_forums` SET `is_cat` = 0");
462 $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix."wpforo_forums` SET `is_cat` = 1 WHERE `parentid` = 0");
463
464 if($i){
465 $this->wpforo->notice->add('Forum hierarchy successfully updated', 'success');
466 }else{
467 $this->wpforo->notice->add('Cannot update forum hierarchy', 'error');
468 }
469
470 }
471 }
472
473 function get_childs($forumid, &$data){
474 if(empty($data)) $data[] = $forumid;
475 $sub_forums = $this->wpforo->db->get_results("SELECT `forumid` FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `parentid` = ".intval($forumid), ARRAY_A);
476 if(!empty($sub_forums)){
477 foreach($sub_forums as $sub_forum){
478 $data[] = $sub_forum['forumid'];
479 $this->get_childs($sub_forum['forumid'], $data);
480 }
481 }
482 }
483
484
485 // get forums tree for drop down menu
486
487 /**
488 * Returns depth for this item.
489 *
490 * @since 1.0.0
491 *
492 * @param int item id
493 *
494 * @param int before calling the function $depth = 0
495 *
496 * @return int
497 */
498 function count_depth($forumid, &$depth){
499 $parentid = $this->wpforo->db->get_var("SELECT `parentid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid));
500
501 if($parentid != 0){
502 $depth++;
503 $this->count_depth($parentid, $depth);
504 }
505 }
506
507 function get_child_forums($parent){
508 $children = $this->wpforo->db->get_results("SELECT `forumid` AS childid FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `parentid` = ".intval($parent)." ORDER BY `order`", ARRAY_A);
509 if(!empty($children)){
510 foreach( $children as $child ){
511 $data[] = $child['childid'];
512 }
513 return $data;
514 }else{
515 return array();
516 }
517 }
518
519 function forum_list( $parent, $type , $cats = TRUE, $topicid = 0 ){
520 static $old_depth;
521 global $wpforo;
522
523 foreach ( $parent as $forumid ) {
524
525 if ($forumid == 0) continue;
526 $depth = 0;
527 $this->count_depth($forumid, $depth);
528 $name = $this->wpforo->db->get_var("SELECT `title` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid));
529 if($type == 'select_box'){
530 if( isset($_GET['page']) && $_GET['page'] == 'wpforo-ads' && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id']) && $_GET['id'] ){
531 $ad = $wpforo->ad->get_ad($_GET['id']);
532 $ad_forumids = explode(',', $ad['forumids']);
533 }
534 ?><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
535 }elseif($type == 'drag_menu'){
536 $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);
537 $cat_layout_name = ( $cur_forum['cat_layout'] == 2 ? 'Simplified Layout' : ( $cur_forum['cat_layout'] == 3 ? 'QA Layout' : 'Extended Layout' ) ); ?>
538
539 <li id="menu-item-<?php echo intval($forumid) ?>" class="menu-item menu-item-depth-<?php echo esc_attr($depth) ?>">
540 <input id="forumid-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][forumid]"/>
541 <input id="parentid-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][parentid]"/>
542 <input id="order-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][order]"/>
543 <dl class="menu-item-bar">
544 <dt class="menu-item-handle forum_width">
545 <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>
546 <span class="item-controls">
547 <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>
548 <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;
549 <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;
550 <?php if( $this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'df') ): ?>
551 <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;
552 <?php endif; ?>
553 <span class="menu_view"><a href="<?php echo esc_url($this->get_forum_url($forumid)) ?>" > <img src="<?php echo WPFORO_URL ?>/wpf-assets/images/icons/eye<?php echo ((!$depth) ? '-dark' : ''); ?>.png" title="<?php _e('View', 'wpforo') ?>"/> </a> </span>
554
555 </span>
556 </dt>
557 </dl>
558 <ul class="menu-item-transport"></ul>
559 </li>
560
561 <?php
562 }elseif($type == 'front_list'){
563 $slug = $this->wpforo->db->get_var("SELECT `slug` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid));
564 if(isset($old_depth) && $old_depth == $depth) echo '</dd><dd>';
565 if(isset($old_depth) && $old_depth < $depth) echo '<dl><dd>';
566 if(isset($old_depth) && $old_depth > $depth) echo '</dd></dl>';
567 $old_depth = $depth;
568 if(isset($wpforo->current_object) && isset($wpforo->current_object['forumid'])){
569 if( $forumid == $wpforo->current_object['forumid'] ){
570 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>';
571 }
572 else{
573 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>';
574 }
575 }
576 else{
577 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>';
578 }
579 }
580 $subforums = $this->get_child_forums($forumid);
581 if( !empty($subforums) ){
582 $this->forum_list($subforums, $type);
583 }
584 }
585 }
586
587 function tree($type = 'front_list', $cats = TRUE, $topicid = 0){
588 $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);
589 if(!empty($parentids)){
590 foreach( $parentids as $parentid ){
591 $data[] = $parentid['parentid'];
592 }
593 $this->forum_list($data, $type, $cats);
594 }
595 }
596 // end forums tree for drop down menu
597
598 function parentid( $topicid = 0 ){
599 if(isset($_GET['page']) && $_GET['page'] == 'wpforo-forums'){
600 if( isset($_GET['id'])) return $this->wpforo->db->get_var("SELECT `parentid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($_GET['id']));
601 }
602 elseif( isset($_GET['page']) && $_GET['page'] == 'wpforo-topics' ){
603 if( isset($_GET['id'])) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($_GET['id']));
604 }else{
605 if( isset($topicid)) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($topicid));
606 }
607 }
608
609 function permissions(){
610 $access_arr = $this->wpforo->perm->get_accesses();
611 if(!empty( $access_arr )){
612
613 if(isset($_GET['id'])){
614 if($permissions_srlz = $this->wpforo->db->get_var("SELECT `permissions` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($_GET['id']))){
615 $permissions_arr = unserialize($permissions_srlz);
616 }
617 }
618
619 if($usergroups = $this->wpforo->db->get_results("SELECT `groupid`, `name` FROM `".$this->wpforo->db->prefix."wpforo_usergroups`", ARRAY_A)){
620 foreach($usergroups as $usergroup){
621 extract($usergroup, EXTR_OVERWRITE);
622 echo '
623 <tr>
624 <td>'.esc_html($name).'</td>
625 <td>
626 <select name="forum[permission]['.intval($groupid).']">';
627 foreach($access_arr as $value){
628
629 echo '<option value="'.esc_attr($value['access']).'" '.
630 ((isset($permissions_arr[$groupid]) && $value['access'] == $permissions_arr[$groupid])
631 || (!isset($permissions_arr[$groupid])
632 && (($name == 'Guest' && $value['access'] == 'read_only')
633 || ($name == 'Registered' && $value['access'] == 'standard')
634 || ($name == 'Customer' && $value['access'] == 'standard')
635 || ($name == 'Moderator' && $value['access'] == 'moderator')
636 || ($name == 'Admin' && $value['access'] == 'full')
637 || ($name != 'Guest' && $name != 'Registered' && $name != 'Customer' && $name != 'Moderator' && $name != 'Admin' && $value['access'] == 'standard') )) ? 'selected' : '').'>'.esc_html( __( $value['title'], 'wpforo') ).'</option>';
638 }
639 echo'
640 </select>
641 </td>
642 </tr>
643 ';
644 }
645
646
647
648 }
649 }
650 }
651
652 /**
653 * array get_counts(array or id(num))
654 *
655 * @since 1.0.0
656 *
657 * @param array defined arguments array for returning
658 *
659 * @return int count topics
660 */
661 function get_counts($forumids){
662
663 if( !empty($forumids) ){
664
665 $wheres = '';
666
667 if(!is_array($forumids)){
668 $wheres = "`forumid` = " . intval($forumids);
669 }else{
670 $wheres = "`forumid` IN(" . implode(', ', array_map('intval', $forumids)) . ")";
671 }
672
673 $sql = "SELECT SUM(`topics`) as topics, SUM(`posts`) as posts FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE " . $wheres;
674 return $this->wpforo->db->get_row($sql, ARRAY_A);
675
676 }
677
678 return 0;
679 }
680
681 /**
682 * array get_layout(array)
683 *
684 * @since 1.0.0
685 *
686 * @param array defined arguments array for returning
687 *
688 * @return int layout id
689 */
690 function get_layout($args){
691 if(is_array($args)){
692 $default = array(
693 'forumid' => NULL, // forum id
694 'topicid' => NULL, // topic id
695 'postid' => NULL, // post id
696 );
697 }else{
698 $default = array(
699 'forumid' => $args, // forumid
700 'topicid' => NULL, // topic id
701 'postid' => NULL, // post id
702 );
703 }
704 $args = wpforo_parse_args( $args, $default );
705 if(!empty($args)){
706 extract($args, EXTR_OVERWRITE);
707
708 if( $args['forumid'] ){
709 $sql = "SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($args['forumid']);
710 $cat_layout = $this->wpforo->db->get_var($sql);
711 return ( $cat_layout ? $cat_layout : 1 );
712 }elseif( $args['topicid'] ){
713 $sql = "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = " . intval($args['topicid']);
714 $forumid = $this->wpforo->db->get_var($sql);
715 return $this->get_layout(array( 'forumid' => $forumid ));
716 }elseif( $args['postid'] ){
717 $sql = "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `postid` = " . intval($args['postid']);
718 $forumid = $this->wpforo->db->get_var($sql);
719 return $this->get_layout(array( 'forumid' => $forumid ));
720 }
721 }
722
723 }
724
725 function get_forum_url($forum){
726
727 if( !is_array($forum) ){
728 if(is_numeric($forum)){
729 $forum = $this->get_forum($forum);
730 }else{
731 $forum = array('slug' => $forum);
732 }
733 }
734
735 if( is_array($forum) && !empty($forum) ){
736 return WPFORO_BASE_URL . utf8_uri_encode($forum['slug']);
737 }else{
738 return WPFORO_BASE_URL;
739 }
740 }
741
742 function get_all_relative_ids($forumid, &$relative_ids){
743 $forum = $this->wpforo->db->get_row("SELECT `parentid`, `forumid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid), ARRAY_A);
744
745 if($forum['parentid'] != 0){
746 $relative_ids[] = $forum['forumid'];
747 $this->get_all_relative_ids($forum['parentid'], $relative_ids);
748 }else{
749 $relative_ids[] = $forum['forumid'];
750 $relative_ids = array_reverse($relative_ids);
751 }
752 }
753
754 function get_count(){
755 return $this->wpforo->db->get_var( "SELECT COUNT(`forumid`) FROM `".$this->wpforo->db->prefix."wpforo_forums`" );
756 }
757
758 function get_lastinfo( $ids = array() ){
759 $lastinfo = array();
760 if(!empty($ids)){
761 $ids = implode(',', array_map('intval', $ids));
762 $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);
763 }
764 return $lastinfo;
765 }
766 }
767
768 ?>