PluginProbe
wpForo Forum / 1.0.1
wpForo Forum v1.0.1
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 1.4.13 All 138 releases
wpforo / wpf-includes / class-forums.php

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

758 lines 29.6 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) : '');
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);
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' => $args, // forumid
291 'slug' => '', // 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 if(isset($args['forumid'])){
299 if( isset(self::$cache['forum'][$args['forumid']]) ){
300 return self::$cache['forum'][$args['forumid']];
301 }
302 }
303 if(!empty($args)){
304 extract($args, EXTR_OVERWRITE);
305
306 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_forums`";
307 $wheres = array();
308 if($forumid != NULL) $wheres[] = "`forumid` = " . intval($forumid);
309 if($status != NULL) $wheres[] = "`status` = " . intval($status);
310 if($type == 'category'){
311 $wheres[] = "`is_cat` = 1";
312 }elseif($type == 'forum'){
313 $wheres[] = "`is_cat` = 0";
314 }
315 if($slug != '') $wheres[] = "`slug` = '" . esc_sql($slug) . "'";
316
317 if(!empty($wheres)){
318 $sql .= " WHERE " . implode( " AND ", $wheres );
319 }
320 $forum = $this->wpforo->db->get_row($sql, ARRAY_A);
321 if(!empty($forum)) {
322 $forum['url'] = $this->get_forum_url( $forum );
323 }
324 if($cache && isset($forumid)){
325 return self::$cache['forum'][$forumid] = $forum;
326 }
327 else{
328 return $forum;
329 }
330 }
331 }
332
333 function get_forums($args = array(), &$items_count = 0){
334 $default = array(
335 'include' => array(), // array( 2, 10, 25 )
336 'exclude' => array(), // array( 2, 10, 25 )
337 'parent_include' => array(), // array( 2, 10, 25 )
338 'parent_exclude' => array(), // array( 2, 10, 25 )
339 'parentid' => NULL,
340 'parent_slug' => '',
341 'status' => NULL,
342 'type' => 'all', // category, forum
343 'orderby' => 'order', // order by `field`
344 'order' => 'ASC', // ASC DESC
345 'offset' => NULL, // OFFSET
346 'row_count' => NULL, // ROW COUNT
347 );
348
349 $args = wpforo_parse_args( $args, $default );
350 if(is_array($args) && !empty($args)){
351 extract($args, EXTR_OVERWRITE);
352
353 $include = wpforo_parse_args( $include );
354 $exclude = wpforo_parse_args( $exclude );
355 $parent_include = wpforo_parse_args( $parent_include );
356 $parent_exclude = wpforo_parse_args( $parent_exclude );
357
358 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_forums`";
359 $wheres = array();
360
361 if(!empty($include)) $wheres[] = "`forumid` IN(" . implode(', ', array_map('intval', $include)) . ")";
362 if(!empty($exclude)) $wheres[] = "`forumid` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
363 if(!empty($parent_include)) $wheres[] = "`parentid` IN(" . implode(', ', array_map('intval', $parent_include)) . ")";
364 if(!empty($parent_exclude)) $wheres[] = "`parentid` NOT IN(" . implode(', ', array_map('intval', $parent_exclude)) . ")";
365 if($parentid != NULL) $wheres[] = " `parentid` = " . intval($parentid);
366 if($status != NULL) $wheres[] = " `status` = " . intval($status);
367
368 if($type == 'category'){
369 $wheres[] = " `is_cat` = 1";
370 }elseif($type == 'forum'){
371 $wheres[] = " `is_cat` = 0";
372 }
373
374 if($parent_slug != '') $wheres[] = "`slug` = '" . esc_sql($parent_slug) . "'";
375
376 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
377
378 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
379 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
380
381 $sql .= esc_sql(" ORDER BY `$orderby` " . $order);
382
383 if($row_count != NULL){
384 if($offset != NULL){
385 $sql .= esc_sql(" LIMIT $offset,$row_count");
386 }else{
387 $sql .= esc_sql(" LIMIT $row_count");
388 }
389 }
390
391 return $this->wpforo->db->get_results($sql, ARRAY_A);
392
393 }
394 }
395
396 function search($needle, $fields = array()){
397
398 if($needle){
399 $needle = sanitize_text_field($needle);
400 if(empty($fields)){
401 $fields = array(
402 'title',
403 'description',
404 'meta_key',
405 'meta_desc'
406 );
407 }
408
409 $sql = "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_forums`";
410 $wheres = array();
411
412 foreach($fields as $field){
413 $wheres[] = "`" . esc_sql($field) . "` LIKE '%" . esc_sql($needle) . "%'";
414 }
415
416 $sql .= " WHERE " . implode(" OR ", $wheres);
417 return $this->wpforo->db->get_col($sql);
418 }
419
420 return array();
421 }
422
423 function update_hierarchy(){
424 if(is_array($_REQUEST['forum']) && !empty($_REQUEST['forum'])){
425 $i = 0;
426 foreach($_REQUEST['forum'] as $hierarchy){
427
428 extract($hierarchy, EXTR_OVERWRITE);
429
430 if(!isset($forumid) || !$forumid = intval($forumid) ) continue;
431
432 if(FALSE !== $this->wpforo->db->update(
433 $this->wpforo->db->prefix . 'wpforo_forums',
434 array(
435 'parentid' => (isset($parentid) ? intval($parentid) : 0),
436 'order' => (isset($order) ? intval($order) : 0),
437 ),
438 array( 'forumid' => intval($forumid) ),
439 array(
440 '%d',
441 '%d'
442 ),
443 array( '%d' )
444 )) $i++;
445
446 if(isset($parentid) && $parentid = intval($parentid) ){
447 $cat_layout = $this->wpforo->db->get_var("SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($parentid));
448 $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix."wpforo_forums` SET `cat_layout` = " . intval($cat_layout) . " WHERE `forumid` = " . intval($forumid));
449 }
450
451 }
452
453 $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix."wpforo_forums` SET `is_cat` = 0");
454 $this->wpforo->db->query("UPDATE `".$this->wpforo->db->prefix."wpforo_forums` SET `is_cat` = 1 WHERE `parentid` = 0");
455
456 if($i){
457 $this->wpforo->notice->add('Forum hierarchy successfully updated', 'success');
458 }else{
459 $this->wpforo->notice->add('Cannot update forum hierarchy', 'error');
460 }
461
462 }
463 }
464
465 function get_childs($forumid, &$data){
466 if(empty($data)) $data[] = $forumid;
467 $sub_forums = $this->wpforo->db->get_results("SELECT `forumid` FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `parentid` = ".intval($forumid), ARRAY_A);
468 if(!empty($sub_forums)){
469 foreach($sub_forums as $sub_forum){
470 $data[] = $sub_forum['forumid'];
471 $this->get_childs($sub_forum['forumid'], $data);
472 }
473 }
474 }
475
476
477 // get forums tree for drop down menu
478
479 /**
480 * Returns depth for this item.
481 *
482 * @since 1.0.0
483 *
484 * @param int item id
485 *
486 * @param int before calling the function $depth = 0
487 *
488 * @return int
489 */
490 function count_depth($forumid, &$depth){
491 $parentid = $this->wpforo->db->get_var("SELECT `parentid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid));
492
493 if($parentid != 0){
494 $depth++;
495 $this->count_depth($parentid, $depth);
496 }
497 }
498
499 function get_child_forums($parent){
500 $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);
501 if(!empty($children)){
502 foreach( $children as $child ){
503 $data[] = $child['childid'];
504 }
505 return $data;
506 }else{
507 return array();
508 }
509 }
510
511 function forum_list( $parent, $type , $cats = TRUE, $topicid = 0 ){
512 static $old_depth;
513 global $wpforo;
514
515 foreach ( $parent as $forumid ) {
516
517 if ($forumid == 0) continue;
518 $depth = 0;
519 $this->count_depth($forumid, $depth);
520 $name = $this->wpforo->db->get_var("SELECT `title` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid));
521 if($type == 'select_box'){
522 if( isset($_GET['page']) && $_GET['page'] == 'wpforo-ads' && isset($_GET['action']) && $_GET['action'] == 'edit' && isset($_GET['id']) && $_GET['id'] ){
523 $ad = $wpforo->ad->get_ad($_GET['id']);
524 $ad_forumids = explode(',', $ad['forumids']);
525 }
526 ?><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
527 }elseif($type == 'drag_menu'){
528 $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);
529 $cat_layout_name = ( $cur_forum['cat_layout'] == 2 ? 'Simplified Layout' : ( $cur_forum['cat_layout'] == 3 ? 'QA Layout' : 'Extended Layout' ) ); ?>
530
531 <li id="menu-item-<?php echo intval($forumid) ?>" class="menu-item menu-item-depth-<?php echo esc_attr($depth) ?>">
532 <input id="forumid-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][forumid]"/>
533 <input id="parentid-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][parentid]"/>
534 <input id="order-<?php echo intval($forumid) ?>" type="hidden" name="forum[<?php echo intval($forumid) ?>][order]"/>
535 <dl class="menu-item-bar">
536 <dt class="menu-item-handle forum_width">
537 <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>
538 <span class="item-controls">
539 <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>
540 <span class="menu_edit"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=edit' ) ?>"><i class="fa fa-pencil" aria-hidden="true" title="<?php _e('edit', 'wpforo') ?>"></i></a></span>&nbsp;|&nbsp;
541 <?php if( $this->wpforo->perm->usergroup_can( $this->wpforo->current_user_groupid, 'df') ): ?>
542 <span class="menu_delete"><a href="<?php echo admin_url( 'admin.php?page=wpforo-forums&id=' . intval($forumid) . '&action=del' ) ?>"><i class="fa fa-trash" aria-hidden="true" title="<?php _e('delete', 'wpforo') ?>"></i></a></span>&nbsp;|&nbsp;
543 <?php endif; ?>
544 <span class="menu_view"><a href="<?php echo esc_url($this->get_forum_url($forumid)) ?>" > <i class="fa fa-eye" aria-hidden="true" title="<?php _e('View', 'wpforo') ?>"></i> </a> </span>
545 </span>
546 </dt>
547 </dl>
548 <ul class="menu-item-transport"></ul>
549 </li>
550
551 <?php
552 }elseif($type == 'front_list'){
553 $slug = $this->wpforo->db->get_var("SELECT `slug` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid));
554 if(isset($old_depth) && $old_depth == $depth) echo '</dd><dd>';
555 if(isset($old_depth) && $old_depth < $depth) echo '<dl><dd>';
556 if(isset($old_depth) && $old_depth > $depth) echo '</dd></dl>';
557 $old_depth = $depth;
558 if(isset($wpforo->current_object) && isset($wpforo->current_object['forumid'])){
559 if( $forumid == $wpforo->current_object['forumid'] ){
560 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>';
561 }
562 else{
563 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>';
564 }
565 }
566 else{
567 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>';
568 }
569 }
570 $subforums = $this->get_child_forums($forumid);
571 if( !empty($subforums) ){
572 $this->forum_list($subforums, $type);
573 }
574 }
575 }
576
577 function tree($type = 'front_list', $cats = TRUE, $topicid = 0){
578 $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);
579 if(!empty($parentids)){
580 foreach( $parentids as $parentid ){
581 $data[] = $parentid['parentid'];
582 }
583 $this->forum_list($data, $type, $cats);
584 }
585 }
586 // end forums tree for drop down menu
587
588 function parentid( $topicid = 0 ){
589 if(isset($_GET['page']) && $_GET['page'] == 'wpforo-forums'){
590 if( isset($_GET['id'])) return $this->wpforo->db->get_var("SELECT `parentid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($_GET['id']));
591 }
592 elseif( isset($_GET['page']) && $_GET['page'] == 'wpforo-topics' ){
593 if( isset($_GET['id'])) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($_GET['id']));
594 }else{
595 if( isset($topicid)) return $this->wpforo->db->get_var( "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = ".intval($topicid));
596 }
597 }
598
599 function permissions(){
600 $access_arr = $this->wpforo->perm->get_accesses();
601 if(!empty( $access_arr )){
602
603 if(isset($_GET['id'])){
604 if($permissions_srlz = $this->wpforo->db->get_var("SELECT `permissions` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($_GET['id']))){
605 $permissions_arr = unserialize($permissions_srlz);
606 }
607 }
608
609 if($usergroups = $this->wpforo->db->get_results("SELECT `groupid`, `name` FROM `".$this->wpforo->db->prefix."wpforo_usergroups`", ARRAY_A)){
610 foreach($usergroups as $usergroup){
611 extract($usergroup, EXTR_OVERWRITE);
612 echo '
613 <tr>
614 <td>'.esc_html($name).'</td>
615 <td>
616 <select name="forum[permission]['.intval($groupid).']">';
617 foreach($access_arr as $value){
618
619 echo '<option value="'.esc_attr($value['access']).'" '.
620 ((isset($permissions_arr[$groupid]) && $value['access'] == $permissions_arr[$groupid])
621 || (!isset($permissions_arr[$groupid])
622 && (($name == 'Guest' && $value['access'] == 'read_only')
623 || ($name == 'Registered' && $value['access'] == 'standard')
624 || ($name == 'Customer' && $value['access'] == 'standard')
625 || ($name == 'Moderator' && $value['access'] == 'moderator')
626 || ($name == 'Admin' && $value['access'] == 'full')
627 || ($name != 'Guest' && $name != 'Registered' && $name != 'Customer' && $name != 'Moderator' && $name != 'Admin' && $value['access'] == 'standard') )) ? 'selected' : '').'>'.esc_html( __( $value['title'], 'wpforo') ).'</option>';
628 }
629 echo'
630 </select>
631 </td>
632 </tr>
633 ';
634 }
635
636
637
638 }
639 }
640 }
641
642 /**
643 * array get_counts(array or id(num))
644 *
645 * @since 1.0.0
646 *
647 * @param array defined arguments array for returning
648 *
649 * @return int count topics
650 */
651 function get_counts($forumids){
652
653 if( !empty($forumids) ){
654
655 $wheres = '';
656
657 if(!is_array($forumids)){
658 $wheres = "`forumid` = " . intval($forumids);
659 }else{
660 $wheres = "`forumid` IN(" . implode(', ', array_map('intval', $forumids)) . ")";
661 }
662
663 $sql = "SELECT SUM(`topics`) as topics, SUM(`posts`) as posts FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE " . $wheres;
664 return $this->wpforo->db->get_row($sql, ARRAY_A);
665
666 }
667
668 return 0;
669 }
670
671 /**
672 * array get_layout(array)
673 *
674 * @since 1.0.0
675 *
676 * @param array defined arguments array for returning
677 *
678 * @return int layout id
679 */
680 function get_layout($args){
681 if(is_array($args)){
682 $default = array(
683 'forumid' => NULL, // forum id
684 'topicid' => NULL, // topic id
685 'postid' => NULL, // post id
686 );
687 }else{
688 $default = array(
689 'forumid' => $args, // forumid
690 'topicid' => NULL, // topic id
691 'postid' => NULL, // post id
692 );
693 }
694 $args = wpforo_parse_args( $args, $default );
695 if(!empty($args)){
696 extract($args, EXTR_OVERWRITE);
697
698 if( $args['forumid'] ){
699 $sql = "SELECT `cat_layout` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = " . intval($args['forumid']);
700 $cat_layout = $this->wpforo->db->get_var($sql);
701 return ( $cat_layout ? $cat_layout : 1 );
702 }elseif( $args['topicid'] ){
703 $sql = "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` = " . intval($args['topicid']);
704 $forumid = $this->wpforo->db->get_var($sql);
705 return $this->get_layout(array( 'forumid' => $forumid ));
706 }elseif( $args['postid'] ){
707 $sql = "SELECT `forumid` FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `postid` = " . intval($args['postid']);
708 $forumid = $this->wpforo->db->get_var($sql);
709 return $this->get_layout(array( 'forumid' => $forumid ));
710 }
711 }
712
713 }
714
715 function get_forum_url($forum){
716
717 if( !is_array($forum) ){
718 if(is_numeric($forum)){
719 $forum = $this->get_forum($forum);
720 }else{
721 $forum = array('slug' => $forum);
722 }
723 }
724
725 if( is_array($forum) && !empty($forum) ){
726 return WPFORO_BASE_URL . utf8_uri_encode($forum['slug']);
727 }else{
728 return WPFORO_BASE_URL;
729 }
730 }
731
732 function get_all_relative_ids($forumid, &$relative_ids){
733 $forum = $this->wpforo->db->get_row("SELECT `parentid`, `forumid` FROM `".$this->wpforo->db->prefix."wpforo_forums` WHERE `forumid` = ".intval($forumid), ARRAY_A);
734
735 if($forum['parentid'] != 0){
736 $relative_ids[] = $forum['forumid'];
737 $this->get_all_relative_ids($forum['parentid'], $relative_ids);
738 }else{
739 $relative_ids[] = $forum['forumid'];
740 $relative_ids = array_reverse($relative_ids);
741 }
742 }
743
744 function get_count(){
745 return $this->wpforo->db->get_var( "SELECT COUNT(`forumid`) FROM `".$this->wpforo->db->prefix."wpforo_forums`" );
746 }
747
748 function get_lastinfo( $ids = array() ){
749 $lastinfo = array();
750 if(!empty($ids)){
751 $ids = implode(',', array_map('intval', $ids));
752 $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);
753 }
754 return $lastinfo;
755 }
756 }
757
758 ?>