PluginProbe
wpForo Forum / 1.3.1
wpForo Forum v1.3.1
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 / functions.php

functions.php in wpForo Forum 1.3.1, at wpf-includes/functions.php

1,595 lines 66.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 function wpforo_verify_form( $mode = 'full' ){
6 if( $mode == 'nonce' || $mode == 'full'){
7 if(!isset($_POST['wpforo_form']) || !wp_verify_nonce( $_POST['wpforo_form'], 'wpforo_verify_form' )) {
8 wpforo_phrase('Sorry, something wrong with your data.');
9 exit();
10 }
11 }
12 if( $mode == 'ref' || $mode == 'full'){
13 if( !isset($_SERVER['HTTP_REFERER']) || !$_SERVER['HTTP_REFERER'] ) {
14 exit('Error 2252 | Please contact to forum admin.');
15 }
16 $ref = $_SERVER['HTTP_REFERER'];
17 $url = get_bloginfo('url');
18 $ref_domain = trim(strtolower(parse_url($ref, PHP_URL_HOST)));
19 $web_domain = trim(strtolower(parse_url($url, PHP_URL_HOST)));
20 if( $ref_domain != $web_domain ){
21 exit('Error 2253 | Please contact to forum admin.');
22 }
23 }
24 }
25
26 function wpforo_home_url($str = '', $echo = false, $absolute = true){
27 global $wpforo;
28
29 if( strpos($str, 'http') === 0 ){
30 $base_url = preg_replace('#/?\?.*$#isu', '', wpforo_home_url());
31 $base_url = preg_replace('#index\.php/?#isu', '', $base_url, 1);
32 $str = preg_replace('#index\.php/?#isu', '', $str, 1);
33 $str = preg_replace('#^'.preg_quote( rtrim($base_url, '/\\') ).'/?#isu', '', $str, 1);
34 }
35 $str = trim(WPFORO_BASE_PERMASTRUCT, '/\\') . '/' . trim($str, '/\\');
36
37 if( $absolute ){
38 $url = $wpforo->user_trailingslashit( home_url($str) );
39 //-START- check is url maybe wordpress home
40 $maybe_home_url = trim( preg_replace('#/?index\.php/?(\?.*)?$#isu', '', $url), '/\\' );
41 $home_url = trim( home_url(), '/\\' );
42 if( $maybe_home_url == $home_url ){
43 $url = preg_replace('#index\.php/?#isu', '', $url, 1);
44 $url = $wpforo->user_trailingslashit($url);
45 }
46 //-END- check is url maybe wordpress home
47 }
48 else{
49 echo $url = $wpforo->user_trailingslashit( $str );
50 }
51
52 if(!$echo) return $url;
53 echo $url;
54 }
55
56 function wpforo_is_ajax(){
57 if( defined('DOING_AJAX') && DOING_AJAX ) return TRUE;
58 return FALSE;
59 }
60
61 function wpforo_is_admin(){
62 if( is_admin() && !wpforo_is_ajax() ) return TRUE;
63 return FALSE;
64 }
65
66 function is_wpforo_page($url = ''){
67 if( wpforo_is_admin() ) return FALSE;
68 if(!$url) $url = wpforo_get_request_uri();
69 if( is_wpforo_exclude_url($url) ) return FALSE;
70 if( is_wpforo_shortcode_page() ) return TRUE;
71 return is_wpforo_url($url);
72 }
73
74 function is_wpforo_exclude_url($url = ''){
75 global $wpforo;
76 if(!$url) $url = wpforo_get_request_uri();
77 $url = urldecode($url);
78 $url = preg_replace('#/page/\d*/?$#isu', '', $url);
79
80 if( $wpforo->use_home_url && $wpforo->excld_urls ){
81 if( !$current_url = wpforo_get_url_query_vars_str($url) ) return FALSE;
82 $expld = array_filter( explode("\n", $wpforo->excld_urls) );
83 foreach( $expld as $excld_url ){
84 $excld_url = urldecode($excld_url);
85 if( strpos($excld_url, home_url('/')) === FALSE ) continue;
86 $excld_url = wpforo_get_url_query_vars_str($excld_url);
87 if( $excld_url && strtolower($current_url) == strtolower($excld_url) ) return TRUE;
88 }
89 }
90
91 return FALSE;
92 }
93
94 function is_wpforo_url($url = ''){
95 if( wpforo_is_admin() ) return FALSE;
96 if(!$url) $url = wpforo_get_request_uri();
97 global $wpforo;
98
99 if( $wpforo->use_home_url ) return TRUE;
100
101 $current_url = wpforo_get_url_query_vars_str($url);
102
103 if( $wpforo->permastruct && strpos($current_url, $wpforo->permastruct) !== FALSE
104 && strpos($current_url, $wpforo->permastruct) == 0
105 && !wpforo_is_admin() ) return TRUE;
106
107 return FALSE;
108 }
109
110 function is_wpforo_shortcode_page(){
111 if( wpforo_is_admin() ) return FALSE;
112 global $wpforo, $post;
113 if( $post && isset($post->post_content) && has_shortcode( $post->post_content, 'wpforo' ) && !is_wpforo_url() ) return TRUE;
114 return FALSE;
115 }
116
117 function wpforo_get_url_query_vars_str($url = ''){
118 if(!$url) $url = wpforo_get_request_uri();
119
120 $home_url = preg_replace( '#/?\?.*$#isu', '', home_url('/') );
121 $current_url = preg_replace('#https?://[^/\?]+/?#isu', '', $url);
122 $site_url = preg_replace('#https?://[^/\?]+/?#isu', '', $home_url);
123 $current_url = preg_replace( '#^/?'.preg_quote($site_url).'(?:/?index\.php/?)?#isu', '' , $current_url, 1 );
124 $current_url = preg_replace('#^[\r\n\t\s\0/]*(.*?)[\r\n\t\s\0/]*$#isu', '$1', $current_url);
125
126 return $current_url;
127 }
128
129 function wpforo_feature( $option, $wpforo = NULL ){
130 if( empty($wpforo) ) global $wpforo;
131 if( isset($wpforo->features[$option]) && $wpforo->features[$option] ){
132 return true;
133 }
134 else{
135 return false;
136 }
137 }
138
139 function wpforo_dir_size($directory) {
140 $size = 0;
141 if(class_exists('RecursiveIteratorIterator') && class_exists('RecursiveDirectoryIterator')){
142 foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) $size+=$file->getSize();
143 return $size;
144 }
145 else{
146 return 0;
147 }
148 }
149
150 function wpforo_make_hidden_fields_from_url($url = '', $echo = true){
151 if( !$url ) $url = wpforo_get_request_uri();
152
153 $return = '';
154 if( $url_query = parse_url($url, PHP_URL_QUERY) ){
155 parse_str($url_query, $url_query_arr);
156 if( !empty($url_query_arr) ){
157 foreach ($url_query_arr as $key => $value) {
158 $return .= '<input type="hidden" name="'.$key.'" value="'.$value.'">';
159 }
160 }
161 }
162
163 if( !$echo ) return $return;
164 echo $return;
165 }
166
167 #################################################################################
168 /**
169 * Returns merged arguments array from defined and default arguments.
170 *
171 * @since 1.0.0
172 *
173 * @param mixed defined arguments array or query
174 *
175 * @param mixed default arguments array or query
176 *
177 * @return array
178 */
179 function wpforo_parse_args( $args, $default = array() ) {
180
181 if( is_object($args) ) {
182 $defined = get_object_vars($args);
183 }
184 elseif( is_array($args) ) {
185 $defined = $args;
186 }
187 elseif( preg_match('|^[\d\,\s]+$|', $args) ){
188 $defined = explode(',', trim($args));
189 }
190 elseif( is_integer($args) || is_float($args) ){
191 $defined[0] = $args;
192 }
193 elseif( is_serialized($args) ){
194 $defined = unserialize($args);
195 }
196 elseif( strpos($args, '=') !== FALSE ) {
197 parse_str($args, $defined);
198 }
199 else{
200 $defined[0] = $args;
201 }
202 if(!empty($default)) {
203 return array_merge( $default, $defined );
204 }
205 else {
206 return $defined;
207 }
208 }
209
210 // #############################################################################
211 /**
212 * Detects serialized data
213 *
214 * @since 1.0.0
215 *
216 * @param string
217 *
218 * @return boolean
219 */
220 if(!function_exists('is_serialized')){
221 function is_serialized( $value ){
222 if( $value == '' ) return false;
223 if( $value === 0 ) return false;
224 $value = trim($value);
225 $chsd = @unserialize($value);
226 if( $chsd !== false || $value === 'b:0;' ) {
227 return true;
228 }
229 else{
230 return false;
231 }
232 }
233 }
234
235
236 function wpforo_get_request_uri($with_port = FALSE, $get_referer_when_ajax = TRUE){
237 if( $get_referer_when_ajax && wpforo_is_ajax() ){
238 if( isset($_SERVER['HTTP_REFERER']) ){ return $_SERVER['HTTP_REFERER']; }
239 }
240 $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
241 $sp = strtolower($_SERVER["SERVER_PROTOCOL"]);
242 $protocol = substr($sp, 0, strpos($sp, "/")) . $s;
243 $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
244 return $protocol . "://" . $_SERVER['HTTP_HOST'] . ($with_port ? $port : '') . $_SERVER['REQUEST_URI'];
245 }
246
247
248 function wpforo_arr_group_by($array, $key_by){
249 if(!empty($array)){
250 $fltrd = array();
251 foreach($array as $key => $arr){
252 if(is_numeric($key)) $fltrd[] = $arr[$key_by];
253 }
254 $uniq_arr = array_unique($fltrd);
255 asort($uniq_arr);
256 return $uniq_arr;
257 }
258 }
259
260 // #############################################################################
261 /**
262 * Print item's (topics, replyes ...) table in dashboard
263 * @since 1.0.0
264 * @param string item(component) class name
265 * @param string This table primary key field name
266 * @param array table fields
267 * @param array table search fields
268 * @param array table filter fields
269 * @param array action buttons ( full posible values $actions = array( 'edit', 'delete', 'view' ); )
270 *
271 * @return echo html table
272 */
273 function wpforo_create_form_table($varname, $primary_key, $fields = array(), $search_fields = array(), $filter_fields = array(), $actions = array(), $bulk_actions = array() ){
274
275 if(empty($actions)) $actions = array( 'edit', 'delete', 'view' );
276 if(empty($bulk_actions)) $bulk_actions = array( 'del' );
277
278 if(!empty($fields)) :
279 global $wpdb;
280 global $wpforo;
281
282 $args = array();
283
284 if(isset($_GET['s']) && $_GET['s'] != '') $args['include'] = $wpforo->$varname->search(sanitize_text_field($_GET['s']), $search_fields);
285 if(isset($_GET['orderby'])) $args['orderby'] = sanitize_text_field($_GET['orderby']);
286 if(isset($_GET['order'])) $args['order'] = sanitize_text_field($_GET['order']);
287 if(isset($_GET['forumid']) && $_GET['forumid'] != 0) $args['forumid'] = intval($_GET['forumid']);
288 if(isset($_GET['groupid']) && $_GET['groupid'] != 0) $args['groupid'] = intval($_GET['groupid']);
289 if(isset($_GET['member_status']) && $_GET['member_status']) $args['status'] = (array) sanitize_text_field($_GET['member_status']);
290 if(isset($_GET['phrase_package']) && $_GET['phrase_package']) $args['package'] = (array) sanitize_text_field($_GET['phrase_package']);
291 if(isset($_GET['langid']) && $_GET['langid']) $args['langid'] = intval($_GET['langid']);
292 if(isset($_GET['userid']) && $_GET['userid'] != 0) $args['userid'] = intval($_GET['userid']);
293 $paged = isset($_GET['paged']) ? intval($_GET['paged']) : 1;
294
295 $args['offset'] = ($paged - 1) * get_option('wpforo_count_per_page');
296 $args['row_count'] = get_option('wpforo_count_per_page');
297
298
299 if($varname == 'reply'){
300 $func = 'get_replies';
301 }else{
302 $func = 'get_'.$varname.'s';
303 }
304
305 $items_count = 0;
306 if( $varname == 'member' && !isset($_GET['member_status']) ){
307 $args['status'] = array('active');
308 }
309
310 $items = $wpforo->$varname->$func($args, $items_count);
311
312 if(isset($args['include']) && empty($args['include'])){
313 $items_count = 0;
314 $items = array();
315 }
316 $pages_count = ceil($items_count/get_option('wpforo_count_per_page')); ?>
317
318 <script type="text/javascript">
319 function wpforo_check_uncheck_all(status){
320 var inpts = document.getElementById("items").getElementsByTagName("input");
321 for (var i = 0; i < inpts.length; i++) {
322 if (inpts[i].type == 'checkbox') {
323 inpts[i].checked = status;
324 }
325 }
326 }
327
328 function wpforo_doaction(){
329 var action = document.items.action.value;
330 var action2 = document.items.action2.value;
331 if(action != -1 || action2 != -1){
332 var inpts = document.getElementById("items").getElementsByTagName("input");
333
334 var j = 0;
335 var ids_arr = new Array();
336 for (var i = 0; i < inpts.length; i++) {
337 if (inpts[i].type == 'checkbox' && inpts[i].checked == true && inpts[i].value != 'on') {
338 ids_arr[j] = inpts[i].value;
339 j++
340 }
341 }
342 if(ids_arr.length != 0){
343 document.items.ids.value = ids_arr.join();
344 document.items.submit();
345 }
346 }
347 }
348 </script>
349
350
351 <div class="wpforo-search-box">
352 <form name="search" id="srch" action="<?php echo admin_url( 'admin.php' ) ?>" method="GET">
353 <?php if( !empty($_GET) ) : ?>
354 <?php foreach ($_GET as $get_key => $get) : ?>
355 <input type="hidden" name="<?php echo $get_key ?>" value="<?php echo $get ?>"/>
356 <?php endforeach ?>
357 <?php endif ?>
358 <label class="screen-reader-text" for="post-search-input">Search <?php echo esc_attr(ucfirst($varname)); ?>s:</label>
359 <input type="search" id="post-search-input" name="s" value="<?php echo ( isset($_GET['s']) ? esc_attr(sanitize_text_field($_GET['s'])) : '' ) ?>">
360 <input type="submit" name="" id="search-submit" class="button" value="Search <?php echo esc_attr(ucfirst($varname)); ?>s">
361 </form>
362 </div>
363 <?php if($varname == 'moderation'): ?>
364 <?php
365 $total = $wpforo->post->get_count();
366 $up_total = (!isset($_GET['filter_by_status']) || (isset($_GET['filter_by_status']) && $_GET['filter_by_status'] == 1 )) ? $items_count : ($total - $items_count);
367 $ap_total = ((isset($_GET['filter_by_status']) && $_GET['filter_by_status'] == 0 )) ? $items_count : ($total - $items_count);
368 ?>
369 <ul class="subsubsub" style="margin:-25px 0px 5px 0px;">
370 <li><a href="<?php echo admin_url( 'admin.php' ) ?>?page=wpforo-moderations&filter_by_status=1" <?php if( !isset($_GET['filter_by_status']) || (isset($_GET['filter_by_status']) && $_GET['filter_by_status'] == 1 ) ) echo 'class="current"' ?>><?php _e('Unapproved', 'wpforo'); ?> <span class="count">(<?php echo intval($up_total); ?>)</span></a> |</li>
371 <li><a href="<?php echo admin_url( 'admin.php' ) ?>?page=wpforo-moderations&filter_by_status=0" <?php if( (isset($_GET['filter_by_status']) && $_GET['filter_by_status'] == 0 ) ) echo 'class="current"' ?>><?php _e('Published', 'wpforo'); ?> <span class="count">(<?php echo intval($ap_total); ?>)</span></a></li>
372 </ul>
373 <?php elseif($varname == 'member' && (!isset($_GET['groupid']) || (isset($_GET['groupid']) && !$_GET['groupid'])) ): ?>
374 <?php
375 $total = $wpforo->member->get_count();
376 $up_total = (!isset($_GET['member_status']) || (isset($_GET['member_status']) && $_GET['member_status'] == 'active' )) ? $items_count : ($total - $items_count);
377 $ap_total = ((isset($_GET['member_status']) && $_GET['member_status'] == 'banned' )) ? $items_count : ($total - $items_count);
378 ?>
379 <ul class="subsubsub" style="margin:-25px 0px 5px 0px;">
380 <li><a href="<?php echo admin_url( 'admin.php' ) ?>?page=wpforo-members&member_status=active" <?php if( !isset($_GET['member_status']) || (isset($_GET['member_status']) && $_GET['member_status'] == 'active' ) ) echo 'class="current"' ?>><?php _e('Active', 'wpforo'); ?> <span class="count">(<?php echo intval($up_total); ?>)</span></a> |</li>
381 <li><a href="<?php echo admin_url( 'admin.php' ) ?>?page=wpforo-members&member_status=banned" <?php if( (isset($_GET['member_status']) && $_GET['member_status'] == 'banned' ) ) echo 'class="current"' ?>><?php _e('Banned', 'wpforo'); ?> <span class="count">(<?php echo intval($ap_total); ?>)</span></a></li>
382 </ul>
383 <?php endif; ?>
384
385 <form name="items" id="items" action="<?php echo admin_url( 'admin.php' ) ?>" method="GET">
386 <?php wp_nonce_field( 'bulk_action_'.$varname ); ?>
387 <input type="hidden" name="ids" />
388 <input type="hidden" name="page" value="wpforo-<?php echo esc_attr($varname); ?>s"/>
389
390 <div class="tablenav top">
391
392 <div class="alignleft actions">
393 <select name="action">
394 <option value="-1" selected="selected"><?php _e('Bulk Actions', 'wpforo'); ?></option>
395 <?php foreach( $bulk_actions as $bulk_action ) : ?>
396 <option value="<?php echo $bulk_action ?>"><?php _e($bulk_action, 'wpforo'); ?></option>
397 <?php endforeach ?>
398 </select>
399 <input type="button" onclick="wpforo_doaction()" id="doaction" class="button action" value="<?php _e('Apply', 'wpforo'); ?>">
400 </div>
401 <div class="alignleft actions">
402
403 <?php if(!empty($filter_fields)) : ?>
404 <?php foreach($filter_fields as $filter_field) : ?>
405 <?php if($filter_field == 'forumid'){ ?>
406
407 <select name="<?php echo esc_attr($filter_field) ?>">
408 <option value="0"><?php _e('Show all forums', 'wpforo'); ?></option>
409 <?php $wpforo->forum->tree('select_box'); ?>
410 </select>
411
412 <?php }elseif($filter_field == 'langid'){ ?>
413
414 <select name="<?php echo esc_attr($filter_field) ?>">
415 <?php $wpforo->phrase->show_lang_list() ?>
416 </select>
417
418 <?php }elseif($filter_field == 'groupid'){ ?>
419
420 <select name="<?php echo esc_attr($filter_field) ?>">
421 <option value="0"><?php _e('filter by group', 'wpforo') ?></option>
422 <?php foreach($wpforo->usergroup->get_usergroups() as $group) : ?>
423 <?php if( $group['groupid'] != 4 ) : ?>
424 <option value="<?php echo esc_attr($group['groupid']) ?>" <?php echo ( isset($_GET['groupid']) && $_GET['groupid'] == $group['groupid'] ? 'selected' : '' ) ?>><?php echo esc_html($group['name']) ?></option>
425 <?php endif ?>
426 <?php endforeach; ?>
427 </select>
428
429 <?php }elseif( $varname == 'member' && $filter_field == 'status' ){
430 $sql = "SELECT DISTINCT `status` as statuses FROM `" . $wpforo->db->prefix . "wpforo_profiles`";
431 if( $statuses = $wpforo->db->get_col($sql) ){ ?>
432 <select name="member_status">
433 <option value="0"><?php _e('filter by status', 'wpforo') ?></option>
434
435 <?php foreach( $statuses as $status ) : ?>
436 <option value="<?php echo esc_attr($status) ?>" <?php echo ( isset($_GET['member_status']) && $_GET['member_status'] == $status ? 'selected' : '' ) ?>><?php echo esc_html($status) ?></option>
437 <?php endforeach; ?>
438
439 </select>
440
441 <?php
442 }
443
444 }elseif( $varname == 'phrase' && $filter_field == 'package' ){
445
446 $sql = "SELECT DISTINCT `package` as packages FROM `" . $wpforo->db->prefix . "wpforo_phrases`";
447 if( $packages = $wpforo->db->get_col($sql) ){ ?>
448 <select name="phrase_package">
449 <option value="0"><?php _e('filter by package', 'wpforo') ?></option>
450
451 <?php foreach( $packages as $package ) : ?>
452 <option value="<?php echo esc_attr($package) ?>" <?php echo ( isset($_GET['phrase_package']) && $_GET['phrase_package'] == $package ? 'selected' : '' ) ?>><?php echo esc_html($package) ?></option>
453 <?php endforeach; ?>
454
455 </select>
456
457 <?php
458 }
459
460 }elseif( $varname == 'moderation' ){
461 $filter_by_status = intval( ( isset($_GET['filter_by_status']) ? $_GET['filter_by_status'] : 1 ) );
462
463 if($filter_field == 'status'){
464 if( $statuses = $wpforo->moderation->post_statuses ) : ?>
465 <select name="filter_by_status">
466
467 <?php foreach ($statuses as $key => $status) : ?>
468 <option value="<?php echo esc_attr($key) ?>" <?php echo ( $filter_by_status == $key ? 'selected' : '' ) ?>><?php echo esc_html( $status ) ?></option>
469 <?php endforeach; ?>
470
471 </select>
472 <?php
473 endif;
474 }elseif($filter_field == 'userid'){
475 $sql = "SELECT DISTINCT `userid` FROM `".$wpforo->db->prefix."wpforo_posts` WHERE `status` = $filter_by_status";
476 if( $userids = $wpforo->db->get_col($sql) ) : ?>
477 <select name="filter_by_userid">
478 <option value="0"><?php _e('filter by user', 'wpforo') ?></option>
479
480 <?php foreach ($userids as $userid) : $user = $wpforo->member->get_member($userid); ?>
481 <option value="<?php echo esc_attr($userid) ?>" <?php echo ( isset($_GET['filter_by_userid']) && $_GET['filter_by_userid'] == $userid ? 'selected' : '' ) ?>><?php echo esc_html( wpforo_make_dname($user['display_name'], $user['user_nicename']) ) ?></option>
482 <?php endforeach; ?>
483
484 </select>
485 <?php
486 endif;
487 }
488
489 } ?>
490
491 <?php endforeach; ?>
492
493 <input type="submit" name="" id="post-query-submit" class="button" value="Filter">
494
495 <?php endif; ?>
496
497 </div>
498 <div class="tablenav-pages <?php echo ((($items_count/get_option('wpforo_count_per_page')) <= 1) ? 'one-page' : '') ?>"><span class="displaying-num"><?php echo intval($items_count) ?> <?php _e('item', 'wpforo') ?></span>
499 <span class="pagination-links">
500 <?php if( !isset($_GET['paged']) || $_GET['paged'] <= 2 ) : ?>
501 <span class="tablenav-pages-navspan">&laquo;</span>
502 <?php else : ?>
503 <a class="first-page" title="Go to the first page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>">&laquo;</a>
504 <?php endif ?>
505 <?php if( !isset($_GET['paged']) || $_GET['paged'] <= 1 ) : ?>
506 <span class="tablenav-pages-navspan"></span>
507 <?php else : ?>
508 <a class="prev-page" title="Go to the previous page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&paged=<?php echo !isset($_GET['paged']) || $_GET['paged'] <= 1 ? 1 : $_GET['paged'] - 1 ?>"></a>
509 <?php endif ?>
510
511 <span class="paging-input"><input class="current-page" title="Current page" type="text" name="paged" value="<?php echo isset($_GET['paged']) ? intval($_GET['paged']) : 1 ?>" size="1"> of <span class="total-pages"><?php echo intval($pages_count) ?></span></span>
512
513 <?php if( isset($_GET['paged']) && $_GET['paged'] >= $pages_count ) : ?>
514 <span class="tablenav-pages-navspan"></span>
515 <?php else : ?>
516 <a class="next-page" title="Go to the next page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&paged=<?php echo (isset($_GET['paged']) ? ( $_GET['paged'] >= $pages_count ? intval($pages_count) : intval($_GET['paged']) + 1 ) : (!isset($_GET['paged']) ? 2 : intval($_GET['paged']) + 1)) ?>"></a>
517 <?php endif ?>
518 <?php if( (isset($_GET['paged']) && $_GET['paged'] >= $pages_count - 1) || 1 >= $pages_count - 1 ) : ?>
519 <span class="tablenav-pages-navspan">&raquo;</span>
520 <?php else : ?>
521 <a class="last-page" title="Go to the last page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&paged=<?php echo intval($pages_count) ?>">&raquo;</a></span>
522 <?php endif ?>
523 </div> <br class="clear">
524
525 </div>
526
527 <table class="wp-list-table widefat fixed pages" cellspacing="0">
528 <thead>
529 <tr>
530 <th scope="col" id="cb" class="manage-column column-cb check-column" style="vertical-align:middle; padding:17px 0px 10px 5px;">
531 <label class="screen-reader-text" for="cb-select-all-1"><?php _e('Select All', 'wpforo') ?></label><input id="cb-select-all-1" type="checkbox" onclick="wpforo_check_uncheck_all(this.checked)">
532 </th>
533 <?php foreach($fields as $key => $field) : ?>
534 <th scope="col" <?php if($key===0) echo ' style="width:30%"' ?> id="<?php echo esc_attr(sanitize_text_field($field)) ?>" class="manage-column column-<?php echo esc_attr(sanitize_text_field($field)) ?> <?php echo isset($_GET['order']) ? ($_GET['orderby'] == $field ? 'sorted ' : '') . $_GET['order'] : 'sortable asc' ?>">
535 <a href="<?php echo esc_url(preg_replace('#(\&*orderby\=[^\&]*\&*order\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&orderby=<?php echo esc_attr(sanitize_text_field($field)) ?>&order=<?php echo isset($_GET['order']) ? ( $_GET['order'] == 'asc' ? 'desc' : 'asc' ) : 'asc' ?>">
536 <span><?php if($field == 'is_first_post'){ _e('Type', 'wpforo'); }else{ echo sanitize_text_field(str_replace('_', ' ', wpforo_phrase( $field, false ))); } ?></span>
537 <span class="sorting-indicator"></span>
538 </a>
539 </th>
540 <?php endforeach; ?>
541 </tr>
542 </thead>
543
544 <tfoot>
545 <tr>
546 <th scope="col" class="manage-column column-cb check-column" style="vertical-align:middle; padding:17px 0px 10px 5px;">
547 <label class="screen-reader-text" for="cb-select-all-2"><?php _e('Select All', 'wpforo') ?></label><input id="cb-select-all-2" type="checkbox" onclick="wpforo_check_uncheck_all(this.checked)">
548 </th>
549 <?php foreach($fields as $key => $field) : ?>
550 <th scope="col" <?php if($key===0) echo ' style="width:30%"' ?> id="<?php echo esc_attr($field) ?>" class="manage-column column-<?php echo esc_attr($field) ?> <?php echo isset($_GET['order']) ? ($_GET['orderby'] == $field ? 'sorted ' : '') . $_GET['order'] : 'sortable asc' ?>">
551 <a href="<?php echo admin_url( 'admin.php?page=wpforo-' . esc_attr(sanitize_text_field($varname)) . 's&orderby=' . esc_attr(sanitize_text_field($field)) . '&order=' . ( isset($_GET['order']) ? ( $_GET['order'] == 'asc' ? 'desc' : 'asc' ) : 'asc' ) ) ?>">
552 <span><?php if($field == 'is_first_post'){ _e('Type', 'wpforo'); }else{ echo sanitize_text_field(str_replace('_', ' ', wpforo_phrase( $field, false ))); } ?></span>
553 <span class="sorting-indicator"></span>
554 </a>
555 </th>
556 <?php endforeach; ?>
557 </tr>
558 </tfoot>
559
560 <tbody id="the-list">
561
562 <?php
563 if(!empty($items)) :
564
565 if(!empty($items)) :
566 foreach($items as $key => $item) : ?>
567
568 <tr id="post-<?php echo esc_attr($item[$primary_key]) ?>" class="post-<?php echo esc_attr($item[$primary_key]) ?> type-page status-publish hentry <?php echo ($key % 2 == 0) ? 'alternate' : '' ?> iedit author-self" valign="top">
569 <th scope="row" class="check-column">
570 <label class="screen-reader-text" for="cb-select-<?php echo esc_attr($item[$primary_key]) ?>">
571 Select <?php echo esc_html(ucfirst($varname)) ?>
572 </label>
573 <input id="cb-select-<?php echo esc_attr($item[$primary_key]) ?>" type="checkbox" value="<?php echo esc_attr($item[$primary_key]) ?>">
574 <div class="locked-indicator"></div>
575 </th>
576 <?php $i = 0; foreach($fields as $field) :
577 if($i == 0) : ?>
578 <?php
579 if($varname == 'member'){
580 $url = $url_user = admin_url( 'user-edit.php?user_id=' . intval($item[$primary_key]));
581 $url_profile = $wpforo->$varname->get_profile_url($item[$primary_key], 'account');
582 }elseif($varname == 'moderation'){
583 $url = $wpforo->post->get_post_url($item[$primary_key]);
584 }else{
585 $url = admin_url( 'admin.php?page=wpforo-'. $varname .'s&id='.$item[$primary_key] .'&action=edit' );
586 }
587 ?>
588 <td class="post-<?php echo esc_attr($item[$field]) ?> page-<?php echo esc_attr($item[$field]) ?> column-<?php echo esc_attr($item[$field]) ?>">
589 <strong>
590 <a class="row-<?php echo esc_attr($item[$field]) ?>" href="<?php echo esc_url($url) ?>" title="Edit “<?php echo esc_attr($varname) ?>”">
591 <?php
592 if($varname == 'forum'){
593 $depth = 0;
594 $wpforo->forum->count_depth($item[$primary_key], $depth);
595 echo str_repeat( '', $depth);
596 }
597 wpfo($item[$field], true, 'esc_html');
598 ?>
599 </a>
600 </strong>
601 <div class="row-actions">
602 <?php foreach($actions as $act_key => $action) : ?>
603 <?php switch($action) :
604 case 'edit': ?>
605 <span class="edit"><a href="<?php echo esc_url($url); ?>" title="Edit this item"><?php _e('edit', 'wpforo'); ?></a></span>
606 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
607 <?php break;
608 case 'edit_user': ?>
609 <span class="edit"><a href="<?php echo esc_url($url_user); ?>"><?php _e('edit user', 'wpforo'); ?></a></span>
610 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
611 <?php break;
612 case 'edit_profile': ?>
613 <span class="edit"><a href="<?php echo esc_url($url_profile); ?>"><?php _e('edit profile', 'wpforo'); ?></a></span>
614 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
615 <?php break;
616 case 'ban': if($item['userid'] == $wpforo->current_userid) break; ?>
617 <?php $ban_url = wp_nonce_url( admin_url( 'admin.php?page=wpforo-' . esc_attr(sanitize_text_field($varname)) . 's&id=' . intval($item[$primary_key]) . '&action=' . ($item['status'] == 'banned' ? 'unban' : 'ban') ), 'wpforo_admin_table_action_ban' ); ?>
618 <span class="trash"><a class="submitban" title="<?php echo ($item['status'] == 'banned' ? __('unban user', 'wpforo') : __('ban user', 'wpforo') ) ?>" onclick="return confirm('<?php echo ($item['status'] == 'banned' ? __('Are you sure, you want to unban this user?', 'wpforo') : __('Are you sure, you want to ban this user?', 'wpforo') ) ?>');" href="<?php echo esc_url($ban_url); ?>"><?php echo ($item['status'] == 'banned' ? __('unban user', 'wpforo') : __('ban user', 'wpforo') ) ?></a></span>
619 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
620 <?php break;
621 case 'delete': ?>
622 <?php $delete_url = wp_nonce_url( admin_url( 'admin.php?page=wpforo-' . esc_attr(sanitize_text_field($varname)) . 's&id=' . intval($item[$primary_key]) . '&action=del' ), 'wpforo_admin_table_action_delete' ); ?>
623 <span class="trash"><a class="submitdelete" title="<?php _e('Delete this item', 'wpforo') ?>" onclick="return confirm('<?php _e('Are you sure you whant to DELETE this item?', 'wpforo') ?>');" href="<?php echo esc_url($delete_url); ?>"><?php _e('delete', 'wpforo'); ?></a></span>
624 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
625 <?php break;
626 case 'approve': ?>
627 <?php $approve_url = wp_nonce_url( admin_url( 'admin.php?page=wpforo-' . esc_attr(sanitize_text_field($varname)) . 's&id=' . intval($item[$primary_key]) . '&action='.( !$item['status'] ? 'un' : '' ).'approve' ), 'wpforo_admin_table_action_approve' ); ?>
628 <span class="vim-u"><a class="vim-u" title="<?php echo ( !$item['status'] ? __('unapprove this item', 'wpforo') : __('Approve this item', 'wpforo') ) ?>" href="<?php echo esc_url($approve_url); ?>"><?php echo ( !$item['status'] ? __('unapprove', 'wpforo') : __('approve', 'wpforo') ); ?></a></span>
629 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
630 <?php break;
631 case 'user_delete': if($item['userid'] == $wpforo->current_userid) break; ?>
632 <?php $delete_url = wp_nonce_url( "users.php?action=delete&user=".intval($item[$primary_key]), 'bulk-users' ) ?>
633 <span class="trash"><a class="submitdelete" title="<?php _e('Delete this item', 'wpforo') ?>" onclick="return confirm('<?php _e('Are you sure you whant to DELETE this item?', 'wpforo') ?>');" href="<?php echo esc_url($delete_url); ?>"><?php _e('delete', 'wpforo'); ?></a></span>
634 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
635 <?php break;
636 case 'view': ?>
637 <?php
638 if( $varname == 'member' ){
639 $fn_name = "get_profile_url";
640 $item_id = $item['ID'];
641 }elseif($varname == 'moderation'){
642 $fn_name = "get_view_url";
643 $item_id = $item['postid'];
644 }else{
645 $fn_name = "get_".$varname."_url";
646 $item_id = $item[$varname.'id'];
647 }
648 ?>
649 <span class="view">
650 <a href="<?php echo esc_url($wpforo->$varname->$fn_name($item_id)) ?>" target="_blank" title="<?php echo esc_attr( __('view', 'wpforo')); ?> “<?php echo esc_attr($varname) ?>”" rel="permalink">
651 <?php _e('view', 'wpforo'); ?>
652 </a>
653 </span>
654 <?php if( $act_key != ( count($actions) - 1 ) ) echo "&nbsp;|&nbsp;"; ?>
655 <?php break;
656 endswitch ?>
657 <?php endforeach ?>
658 </div>
659 </td>
660 <?php else : ?>
661 <td class="<?php echo esc_attr($item[$field]) ?> column-<?php echo esc_attr($item[$field]) ?>">
662 <?php if($field == 'forumid') : ?>
663 <?php $data = $wpforo->forum->get_forum($item[$field]); echo esc_html($data['title']); ?>
664 <?php elseif($field == 'userid') : ?>
665 <?php if(isset($item['name'])): ?>
666 <?php $data = wpforo_member($item); echo esc_html(wpforo_make_dname($data['display_name'], $data['user_nicename'])); ?>
667 <?php else: ?>
668 <?php $data = $wpforo->member->get_member($item[$field]); echo esc_html(wpforo_make_dname($data['display_name'], $data['user_nicename'])); ?>
669 <?php endif; ?>
670 <?php elseif($field == 'groupid') : ?>
671 <?php $data = $wpforo->usergroup->get_usergroup($item[$field]); echo esc_html($data['name']); ?>
672 <?php elseif($field == 'rank') : ?>
673 <div class="author-rating"><div class="bar wpfw-<?php echo esc_attr($wpforo->member->rating_level($item['posts'])); ?> wpfbg-4"></div></div>
674 <?php elseif($field == 'is_first_post') : ?>
675 <b><?php echo strtoupper( ( $item[$field] ? __('Topic', 'wpforo') : __('Post', 'wpforo') ) ) ?></b>
676 <?php else : ?>
677 <?php wpfo($item[$field], true, 'esc_html') ?>
678 <?php endif; ?>
679 </td>
680
681 <?php endif; $i++; ?>
682
683 <?php endforeach; ?>
684 </tr>
685 <?php endforeach; ?>
686 <?php endif; ?>
687 <?php else : ?>
688 <tr class="no-items"><td class="colspanchange" colspan="7"><?php _e('No items found', 'wpforo') ?></td></tr>
689 <?php endif; ?>
690 </tbody>
691 </table>
692
693 <div class="tablenav bottom">
694 <div class="alignleft actions">
695 <select name="action2">
696 <option value="-1" selected="selected"><?php _e('Bulk Actions', 'wpforo') ?></option>
697 <?php foreach( $bulk_actions as $bulk_action ) : ?>
698 <option value="<?php echo $bulk_action ?>"><?php _e($bulk_action, 'wpforo'); ?></option>
699 <?php endforeach ?>
700 </select>
701 <input type="button" onclick="wpforo_doaction()" id="doaction2" class="button action" value="Apply">
702 </div>
703 <div class="alignleft actions"></div>
704 <div class="tablenav-pages <?php echo (($items_count/get_option('wpforo_count_per_page') <= 1) ? 'one-page' : '') ?>"><span class="displaying-num"><?php echo intval($items_count) ?> <?php _e('item', 'wpforo') ?></span>
705 <span class="pagination-links">
706 <?php if( !isset($_GET['paged']) || $_GET['paged'] <= 2 ) : ?>
707 <span class="tablenav-pages-navspan">&laquo;</span>
708 <?php else : ?>
709 <a class="first-page" title="Go to the first page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>">&laquo;</a>
710 <?php endif ?>
711 <?php if( !isset($_GET['paged']) || $_GET['paged'] <= 1 ) : ?>
712 <span class="tablenav-pages-navspan"></span>
713 <?php else : ?>
714 <a class="prev-page" title="Go to the previous page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&paged=<?php echo !isset($_GET['paged']) || $_GET['paged'] <= 1 ? 1 : intval($_GET['paged']) - 1 ?>"></a>
715 <?php endif ?>
716
717 <span class="paging-input"><input class="current-page" title="Current page" type="text" name="paged" value="<?php echo isset($_GET['paged']) ? intval($_GET['paged']) : 1 ?>" size="1"> of <span class="total-pages"><?php echo intval($pages_count) ?></span></span>
718
719 <?php if( isset($_GET['paged']) && $_GET['paged'] >= $pages_count ) : ?>
720 <span class="tablenav-pages-navspan"></span>
721 <?php else : ?>
722 <a class="next-page" title="Go to the next page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&paged=<?php echo (isset($_GET['paged']) ? ( $_GET['paged'] >= $pages_count ? intval($pages_count) : intval($_GET['paged']) + 1 ) : (!isset($_GET['paged']) ? 2 : intval($_GET['paged']) + 1)) ?>"></a>
723 <?php endif ?>
724 <?php if( (isset($_GET['paged']) && $_GET['paged'] >= $pages_count - 1) || 1 >= $pages_count - 1 ) : ?>
725 <span class="tablenav-pages-navspan">&raquo;</span>
726 <?php else : ?>
727 <a class="last-page" title="Go to the last page" href="<?php echo esc_url(preg_replace('#(\&*paged\=[^\&]*)#is', '', wpforo_get_request_uri())); ?>&paged=<?php echo intval($pages_count) ?>">&raquo;</a></span>
728 <?php endif ?>
729 </div> <br class="clear">
730 </div>
731 </form>
732 <?php endif; ?>
733 <?php
734 }
735
736 function wpforo_phrase($key, $echo = TRUE, $format = 'first-upper'){
737 global $wpforo;
738 $phrase = (isset($wpforo->phrases[addslashes(strtolower($key))])) ? $wpforo->phrases[addslashes(strtolower($key))] : $key;
739 if( $key == $phrase ){
740 $phrase = __($key, 'wpforo');
741 }
742
743 if( $format == 'first-upper' ){
744 $phrase = ucfirst($phrase);
745 }
746 elseif( $format == 'upper' ){
747 if(function_exists('mb_strtoupper')){
748 $phrase = mb_strtoupper($phrase);
749 }
750 else{
751 $phrase = strtoupper($phrase);
752 }
753 }
754 elseif( $format == 'lower' ){
755 if(function_exists('mb_strtolower')){
756 $phrase = mb_strtolower($phrase);
757 }
758 else{
759 $phrase = strtolower($phrase);
760 }
761 }
762
763 $phrase = str_replace('{number}', '', $phrase);
764
765 if($echo){
766 echo $phrase;
767 }else{
768 return $phrase;
769 }
770 }
771
772 function wpforo_screen_option(){ ?>
773
774 <div id="screen-meta" class="metabox-prefs" style="display: none; ">
775 <div id="screen-options-wrap" class="hidden" tabindex="-1" aria-label="Screen Options Tab" style="display: none; ">
776 <form id="adv-settings" action="" method="POST">
777 <h5><?php _e('Show on screen', 'wpforo') ?></h5>
778
779 <div class="screen-options">
780 <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wpforo_screen_option[value]" id="edit_post_per_page" maxlength="3" value="<?php echo intval(get_option('wpforo_count_per_page')) ?>">
781 <label for="edit_post_per_page"><?php _e('Items', 'wpforo') ?></label>
782 <input type="submit" name="screen-options-apply" id="screen-options-apply" class="button" value="<?php _e('Apply', 'wpforo') ?>">
783 </div>
784 </form>
785 </div>
786 </div>
787
788 <div id="screen-meta-links">
789 <div id="screen-options-link-wrap" class="hide-if-no-js screen-meta-toggle" style="">
790 <a href="#screen-options-wrap" id="show-settings-link" class="show-settings screen-meta-active" aria-controls="screen-options-wrap" aria-expanded="true">
791 <?php _e('Screen Options', 'wpforo') ?>
792 </a>
793 </div>
794 </div>
795
796 <?php
797 }
798
799
800 function wpforo_text( $text, $length, $echo = TRUE ){
801 $text = preg_replace('#(?:[^\'\"]|^)(https?://[^\s\'\"<>]+)(?:[^\'\"]|$)#isu', '', $text);
802 $text = preg_replace('#\[attach[^\[\]]*\][^\[\]]*\[/attach\]#isu', '', $text);
803 $text = strip_tags($text);
804 if(function_exists('mb_substr')){
805 if($echo){
806 echo trim( mb_substr( $text, 0, $length, get_option('blog_charset') ) . ( ( function_exists('mb_strlen') ? mb_strlen( $text, get_option('blog_charset') ) : strlen($text) ) > $length ? '...' : '' ) );
807 }else{
808 return trim( mb_substr( $text, 0, $length, get_option('blog_charset') ) . ( ( function_exists('mb_strlen') ? mb_strlen( $text, get_option('blog_charset') ) : strlen($text) ) > $length ? '...' : '' ) );
809 }
810 }else{
811 if($echo){
812 echo trim( substr( $text, 0, $length ) . ( strlen($text) > $length ? '...' : '' ) );
813 }else{
814 return trim( substr( $text, 0, $length ) . ( strlen($text) > $length ? '...' : '' ) );
815 }
816 }
817 }
818
819 function wpforo_admin_options_tabs( $tabs, $current = 'general', $subtab = FALSE, $sub_current = 'general' ) {
820 if(!empty($tabs)){
821 $class_attr = $subtab ? 'vert_tab' : '';
822 echo '<h2 class="nav-tab-wrapper ' . esc_attr($class_attr) . '">';
823 foreach( $tabs as $tab => $name ){
824 $class = ( $tab == $current || ($subtab && $tab == $sub_current ) ) ? ' nav-tab-active' : '';
825 $sub = $subtab ? '&subtab='.esc_attr($tab) : '';
826 $class = esc_attr($class);
827 $class_attr = $class_attr;
828 $current = esc_attr($current);
829 $tab = esc_attr($tab);
830 $sub = esc_attr($sub);
831 $name = esc_html($name);
832 echo "<a class='nav-tab$class $class_attr' href='?page=wpforo-settings&tab=". ($subtab ? $current : $tab ) ."$sub'>$name</a>";
833 }
834 echo '</h2>';
835 }
836 }
837
838 function wpforo_admin_tools_tabs( $tabs, $current = 'antispam', $subtab = FALSE, $sub_current = 'antispam' ) {
839 if(!empty($tabs)){
840 $class_attr = $subtab ? 'vert_tab' : '';
841 echo '<h2 class="nav-tab-wrapper ' . esc_attr($class_attr) . '">';
842 foreach( $tabs as $tab => $name ){
843 $class = ( $tab == $current || ($subtab && $tab == $sub_current ) ) ? ' nav-tab-active' : '';
844 $sub = $subtab ? '&subtab='.esc_attr($tab) : '';
845 $class = esc_attr($class);
846 $class_attr = $class_attr;
847 $current = esc_attr($current);
848 $tab = esc_attr($tab);
849 $sub = esc_attr($sub);
850 $name = esc_html($name);
851 echo "<a class='nav-tab$class $class_attr' href='?page=wpforo-tools&tab=". ($subtab ? $current : $tab ) ."$sub' style='float:left'>$name</a>";
852 }
853 echo '</h2>';
854 }
855 }
856
857 function wpforo_content_filter( $content ){
858 $content = apply_filters('wpforo_body_text_filter', $content);
859 $content = preg_replace('#([^\'\"]|^)(https?://[^\s\'\"<>]+\.(?:jpg|jpeg|png|gif|ico|svg|bmp|tiff))([^\'\"]|$)#isu', '$1 <a class="wpforo-auto-embeded-link" href="$2" target="_blank"><img class="wpforo-auto-embeded-image" src="$2"/></a> $3', $content);
860 $content = preg_replace('#([^\'\"]|^)(https?://[^\s\'\"<>]+)([^\'\"]|$)#isu', '$1 <a class="wpforo-auto-embeded-link" href="$2" target="_blank">$2</a> $3', $content);
861 if(preg_match_all('#<pre([^<>]*)>(.*?class=[\'"]wpforo-auto-embeded[^\'"]*[\'"].*?)</pre>#isu', $content, $matches, PREG_SET_ORDER)){
862 foreach($matches as $match){
863 $match[2] = preg_replace('#<img[^<>]*class=[\'"]wpforo-auto-embeded-image[\'"][^<>]*src=[\'"]([^\'"]*)[\'"][^<>]*>#isu', '$1', $match[2]);
864 $match[2] = preg_replace('#<a[^<>]*class=[\'"]wpforo-auto-embeded-link[\'"][^<>]*href=[\'"]([^\'"]*)[\'"][^<>]*>.*?</a>#isu', '$1', $match[2]);
865 $content = str_replace($match[0], '<pre'.$match[1].'>'.$match[2].'</pre>', $content);
866 }
867 }
868 $content = preg_replace('#(<a[^<>]*>[^<>]*)<a[^<>]*class=[\'"]wpforo-auto-embeded-link[\'"][^<>]*href=[\'"]([^\'"]*)[\'"][^<>]*>[^<>]*</a>([^<>]*</a>)#isu', '$1$2$3', $content);
869 $content = apply_filters('wpforo_content_filter', $content);
870 return wpautop($content);
871 }
872
873 function wpforo_remove_links( $content ){
874 return preg_replace('#([^\'\"]|^)(https?://[^\s\'\"<>]+)([^\'\"]|$)#isu', '$1 [' . wpforo_phrase('removed link', false) . '] $3', $content);
875 }
876
877 add_filter('wpforo_content_filter', 'wpforo_nofollow_tag', 20);
878 function wpforo_nofollow_tag( $content ){
879 $content = preg_replace_callback('|<a[^><]*href=[\'\"]+([^\'\"]+)[\'\"]+[^><]*>.+?</a>|is', 'wpforo_nofollow', $content);
880 return $content;
881 }
882 function wpforo_nofollow($match){
883 $url = get_bloginfo('url');
884 $parse = parse_url($url);
885 if( isset($match[0]) ) $link = $match[0];
886 if( isset($match[1]) && strpos($match[1], $parse['host']) === FALSE ){
887 $link = preg_replace('|(<a[^><]+)>|is', '$1 rel="nofollow">', $match[0]);
888 }
889 return $link;
890 }
891
892 add_action('wpforo_bottom_hook', 'wpforo_page_logging');
893 function wpforo_page_logging(){
894 global $wpforo;
895 $data = $wpforo->current_object;
896
897 if( $data['template'] == 'post' && isset($data['topicid']) && $data['topicid'] ){
898
899 $current_user_id = get_current_user_id();
900 $current_time = current_time( 'timestamp', 1 );
901
902 if( $current_user_id ){
903 //registered user
904 $view = $wpforo->db->get_row("SELECT `vid`, `created` FROM `". $wpforo->db->prefix . "wpforo_views` WHERE `topicid` = " . intval($data['topicid']) ." AND `userid` = " . intval($current_user_id), ARRAY_A);
905 if( !$view['vid'] ){
906 $sql = "INSERT INTO ". $wpforo->db->prefix ."wpforo_views( `userid` , `topicid` , `created` ) VALUES ( '".intval($current_user_id)."', " . intval($data['topicid']) . ", '" . esc_sql($current_time) . "' ) ";
907 $wpforo->db->query($sql);
908 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_topics` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
909 }else{
910 $sql = "UPDATE ". $wpforo->db->prefix ."wpforo_views SET `created` = " . intval($current_time) . " WHERE `userid` = " . intval($current_user_id) . " AND `topicid` = " . intval($data['topicid']);
911 $wpforo->db->query($sql);
912 if( $current_time - $view['created'] > 86400 ){
913 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_topics` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
914 }
915 }
916 }else{
917 //Guest user
918 $viwed_topics_arr = wpforo_getcookie( 'wpforo_view_topics' );
919 if( !in_array( $data['topicid'] , (array)$viwed_topics_arr ) ){
920 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_topics` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
921 $viwed_topics_arr[] = $data['topicid'];
922 $args['topics'] = $viwed_topics_arr;
923 wpforo_setcookie( 'wpforo_view_topics' , $args );
924 }
925 }
926 }
927 }
928
929 add_action( 'init', 'wpforo_setcookie' );
930 function wpforo_setcookie( $mode = '', $args = array() ) {
931 if( $mode == 'wpforo_view_topics' && $args['topics']){
932 $args['topics'] = trim( implode( '|', $args['topics'] ), '|' );
933 @setcookie( 'wpforo_view_topics', $args['topics'] , time() + 86400, COOKIEPATH, COOKIE_DOMAIN );
934 }
935 }
936
937 add_action( 'wp_head', 'wpforo_getcookie' );
938 function wpforo_getcookie( $mode ) {
939 if( $mode == 'wpforo_view_topics' ){
940 if( isset($_COOKIE['wpforo_view_topics']) && $_COOKIE['wpforo_view_topics'] ){
941 return explode('|', $_COOKIE['wpforo_view_topics']);
942 }else{
943 return FALSE;
944 }
945 }
946 }
947
948 //Option value filter and output
949 function wpfo( $option = '', $echo = true, $esc = 'esc_attr' ){
950 if( is_string($option) ){
951 $option = stripslashes( $option );
952 if( $esc == 'esc_attr' ){
953 $option = esc_attr( $option );
954 }
955 elseif( $esc == 'esc_html' ){
956 $option = esc_html( $option );
957 }
958 elseif( $esc == 'esc_url' ){
959 $option = esc_url( $option );
960 }
961 elseif( $esc == 'esc_textarea' ){
962 $option = esc_textarea( $option );
963 }
964 }
965
966 if( $echo ){
967 echo $option;
968 }
969 else{
970 return $option;
971 }
972 }
973
974 //Option maker for checkbox, radio and select
975 function wpfo_check( $option = '', $value = '', $type = 'checked' , $echo = true ){
976 $option = (isset($option) && isset($value) && $option == $value ) ? $type : '';
977 if( $echo ){
978 echo $option;
979 }
980 else{
981 return $option;
982 }
983 }
984
985 function wpforo_human_filesize($bytes, $decimals = 2) {
986 $size = array('B','KB','MB','GB','TB','PB','EB','ZB','YB');
987 $factor = floor((strlen($bytes) - 1) / 3);
988 return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . '&nbsp;' . @$size[$factor];
989 }
990
991 function wpforo_date($date, $type = 'ago', $echo = true ) {
992 if(is_numeric($date)) $date = date_i18n( 'Y-m-d H:i:s', $date);
993
994 global $wpforo;
995 $d = $date;
996 $sep = ' ';
997 $timestamp = strtotime($date);
998 $timezone_string = get_option('timezone_string');
999 $current_offset = get_option('gmt_offset');
1000 if(!is_string($type)) $type = 'ago';
1001
1002 if( is_user_logged_in() && !empty($wpforo->current_user) ){
1003 if( isset($wpforo->current_user['timezone']) && $wpforo->current_user['timezone'] != '' ){
1004 if(preg_match('|UTC([\-\+]+.?)|is', $wpforo->current_user['timezone'], $timezone_array)){
1005 $timezone_string = '';
1006 $current_offset = str_replace('+', '', $timezone_array[1]);
1007 }
1008 else{
1009 if(in_array($wpforo->current_user['timezone'], timezone_identifiers_list())){
1010 $timezone_string = $wpforo->current_user['timezone'];
1011 $current_offset = '';
1012 }
1013 else{
1014 $timezone_string = '';
1015 $current_offset = '';
1016 }
1017 }
1018 }
1019 }
1020
1021 if( $timezone_string == '' && $current_offset != '' ){
1022 $timezone_string = timezone_name_from_abbr('', $current_offset * 3600, false);
1023 }
1024
1025 if( class_exists('DateTime') && class_exists('DateTimeZone') && $timezone_string ){
1026 $dt = new DateTime("now", new DateTimeZone($timezone_string));
1027 if( method_exists($dt, 'setTimestamp') ) $dt->setTimestamp($timestamp); //DateTime::setTimestamp() available in PHP 5.3 and higher versions
1028 if( $type == 'human' ){
1029 $d = human_time_diff($timestamp);
1030 }
1031 elseif( $type == 'ago' ){
1032 $d = human_time_diff($timestamp) . '&nbsp;';
1033 $d = sprintf( wpforo_phrase('%s ago', false, false), $d );
1034 }
1035 else{
1036 if( wpforo_feature('wp-date-format', $wpforo) ){
1037 $date_format = get_option('date_format');
1038 $time_format = get_option('time_format');
1039 $type = $date_format . $sep . $time_format;
1040 }
1041 $d = date_i18n($type, strtotime($dt->format('Y-m-d H:i:s')));
1042 }
1043 }
1044 else{
1045
1046 if( $type == 'human' ){
1047 $d = human_time_diff($timestamp);
1048 }
1049 elseif( $type == 'ago' ){
1050 $d = human_time_diff($timestamp) . '&nbsp;';
1051 $d = sprintf( wpforo_phrase('%s ago', false, false), $d );
1052 }
1053 else{
1054 if( wpforo_feature('wp-date-format', $wpforo) ){
1055 $date_format = get_option('date_format');
1056 $time_format = get_option('time_format');
1057 $type = $date_format . $sep . $time_format;
1058 }
1059 $d = date_i18n( $type, $timestamp);
1060 }
1061 }
1062
1063 if( $echo ){
1064 echo $d;
1065 }
1066 else{
1067 return $d;
1068 }
1069 }
1070
1071 function wpforo_write_file( $new_file, $content ){
1072 $return = array( 'error' => false, 'file' => '' );
1073 $ifp = @fopen( $new_file, 'wb' );
1074 if ( ! $ifp ) {
1075 $return = array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
1076 }
1077 else{
1078 @fwrite( $ifp, $content );
1079 fclose( $ifp );
1080 clearstatcache();
1081 // Set correct file permissions
1082 $stat = @stat( dirname( $new_file ) );
1083 $perms = $stat['mode'] & 0007777;
1084 $perms = $perms & 0000666;
1085 @chmod( $new_file, $perms );
1086 clearstatcache();
1087 $return = array( 'file' => $new_file );
1088 }
1089 return $return;
1090 }
1091
1092
1093 function wpforo_get_file_content( $file ){
1094 $fp = @fopen( $file, 'r' );
1095 if( !$fp ){
1096 return false;
1097 }
1098 else{
1099 $size = @filesize($file);
1100 if( isset($size) && $size > 0 ){
1101 $file_data = fread( $fp, $size );
1102 fclose( $fp );
1103 return $file_data;
1104 }
1105 return false;
1106 }
1107 }
1108
1109 ################################################################################
1110 /**
1111 * Clears file basename and removes trailing slash
1112 *
1113 * @since 1.0.0
1114 *
1115 * @param string filename
1116 *
1117 * @return string
1118 */
1119 function wpforo_clear_basename( $file ) {
1120 $file = str_replace('\\','/',$file);
1121 $file = preg_replace('|/+|','/', $file);
1122 $file = trim($file, '/');
1123 return $file;
1124 }
1125
1126 #################################################################################
1127 /**
1128 * Removes directory with all files and folders
1129 *
1130 * @since 1.0.0
1131 *
1132 * @param string directory name
1133 *
1134 */
1135 function wpforo_remove_directory( $directory ) {
1136 $directory_ns = trim( $directory, '/') . '/';
1137 $directory_ws = '/' . trim( $directory, '/') . '/';
1138 $glob = glob( $directory_ns . '/*' );
1139 if( empty($glob) ) $glob = glob( $directory_ws . '/*' );
1140 foreach( $glob as $item ) {
1141 if( is_dir( $item ) ){
1142 wpforo_remove_directory( $item );
1143 }
1144 else{
1145 unlink( $item );
1146 }
1147 }
1148 return rmdir( $directory );
1149 }
1150
1151 #################################################################################
1152 /**
1153 * Converts bytes to KB, MB, GB
1154 *
1155 * @since 1.0.0
1156 *
1157 * @param integer Bytes
1158 *
1159 * @return string
1160 */
1161 function wpforo_print_size($value, $points = true ){
1162
1163 if($value <= 1024)
1164 {
1165 return $value . (($points) ? " B" : '' );
1166 }
1167 if($value > 1024 && $value <= (1024*1024))
1168 {
1169 $value=round(($value/1024)*10)/10;
1170 return $value . (($points) ? " KB" : '' );
1171 }
1172 if($value > 1024*1024 && $value <= 1024*1024*1024)
1173 {
1174 $value=round(($value/(1024*1024))*10)/10;
1175 return $value . (($points) ? " MB" : '' );
1176 }
1177 if($value > 1024*1024*1024 && $value <= 1024*1024*1024*1024)
1178 {
1179 $value=round(($value/(1024*1024*1024))*10)/10;
1180 return $value . (($points) ? " GB" : '' );
1181 }
1182 }
1183
1184 function wpforo_human_size_to_bytes($sSize)
1185 {
1186 if ( is_numeric( $sSize) ) {
1187 return $sSize;
1188 }
1189 $sSuffix = substr($sSize, -1);
1190 $iValue = substr($sSize, 0, -1);
1191 switch(strtoupper($sSuffix)){
1192 case 'P':
1193 $iValue *= 1024;
1194 case 'T':
1195 $iValue *= 1024;
1196 case 'G':
1197 $iValue *= 1024;
1198 case 'M':
1199 $iValue *= 1024;
1200 case 'K':
1201 $iValue *= 1024;
1202 break;
1203 }
1204 return $iValue;
1205 }
1206
1207
1208 function wpforo_print_number($n, $echo = false) {
1209 $x = str_replace(",","",$n);
1210 $x = intval($x);
1211 $n = 0 + $x;
1212 if(!is_numeric($n)) return false;
1213 if($n>1000000000000) return round(($n/1000000000000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}T',false));
1214 else if($n>1000000000) return round(($n/1000000000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}B',false));
1215 else if($n>1000000) return round(($n/1000000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}M',false));
1216 else if($n>10000) return round(($n/1000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}K',false));
1217 if($echo){
1218 echo number_format($n);
1219 }
1220 else{
1221 return number_format($n);
1222 }
1223 }
1224
1225 function wpforo_bigintval($value) {
1226 if(!is_array($value)) {
1227 $value = trim($value);
1228 }
1229 if (ctype_digit($value)) {
1230 return $value;
1231 }
1232 $value = preg_replace("/[^0-9](.*)$/", '', $value);
1233 if (ctype_digit($value)) {
1234 return $value;
1235 }
1236 return 0;
1237 }
1238
1239 function wpforo_removebb($string){
1240 if(isset($string) && $string ){
1241 $string = preg_replace('|\[\/*[^\]\[]+\]|is', '', $string);
1242 }
1243 return $string;
1244 }
1245
1246 function wpforo_file_upload_error($code){
1247 switch ($code) {
1248 case UPLOAD_ERR_INI_SIZE:
1249 $message = wpforo_phrase("The uploaded file exceeds the upload_max_filesize directive in php.ini", false);
1250 break;
1251 case UPLOAD_ERR_FORM_SIZE:
1252 $message = wpforo_phrase("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", false);
1253 break;
1254 case UPLOAD_ERR_PARTIAL:
1255 $message = wpforo_phrase("The uploaded file was only partially uploaded", false);
1256 break;
1257 case UPLOAD_ERR_NO_FILE:
1258 $message = wpforo_phrase("No file was uploaded", false);
1259 break;
1260 case UPLOAD_ERR_NO_TMP_DIR:
1261 $message = wpforo_phrase("Missing a temporary folder", false);
1262 break;
1263 case UPLOAD_ERR_CANT_WRITE:
1264 $message = wpforo_phrase("Failed to write file to disk", false);
1265 break;
1266 case UPLOAD_ERR_EXTENSION:
1267 $message = wpforo_phrase("File upload stopped by extension", false);
1268 break;
1269 default:
1270 $message = wpforo_phrase("Unknown upload error", false);
1271 break;
1272 }
1273 return $message;
1274 }
1275
1276 //$key allowed values are post, strip, data, user_description entities or the name of a field filter such as pre_user_description.
1277 //More info https://core.trac.wordpress.org/browser/tags/4.5.2/src/wp-includes/kses.php#L624
1278 function wpforo_kses( $string = '', $key = 'data' ){
1279
1280 if(!$string || !$key) return $string;
1281 if( $key == 'email' ){
1282 $allowed_html = array( 'a' => array( 'href' => array(), 'title' => array()),
1283 'blockquote' => array(),
1284 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
1285 'hr' => array(),
1286 'br' => array(),
1287 'p' => array(),
1288 'strong' => array());
1289 }
1290 else{
1291 $allowed_html = wp_kses_allowed_html( $key );
1292 if( $key == 'user_description' ){
1293 $allowed_html['img'] = array( 'alt' => array(), 'align' => array(), 'border' => array(), 'height' => array(), 'hspace' => array(), 'longdesc' => array(), 'vspace' => array(), 'src' => array(), 'usemap' => array(), 'width' => array());
1294 }
1295 else{
1296 global $allowedposttags;
1297 $allowed_html = wpforo_parse_args($allowed_html, $allowedposttags);
1298
1299 $allowed_html['a']['data-gallery'] = array();
1300 $allowed_html['a']['download'] = array();
1301 $allowed_html['iframe']['width'] = array();
1302 $allowed_html['iframe']['height'] = array();
1303 $allowed_html['iframe']['src'] = array();
1304 $allowed_html['iframe']['frameborder'] = array();
1305 $allowed_html['iframe']['allowfullscreen'] = array();
1306 $allowed_html['embed']['flashVars'] = array();
1307 $allowed_html['embed']['src'] = array();
1308 $allowed_html['embed']['width'] = array();
1309 $allowed_html['embed']['height'] = array();
1310 $allowed_html['embed']['wmode'] = array();
1311 $allowed_html['embed']['allowFullScreen'] = array();
1312 $allowed_html['embed']['allowScriptAccess'] = array();
1313 $allowed_html['embed']['name'] = array();
1314 $allowed_html['embed']['pluginspage'] = array();
1315 $allowed_html['embed']['type'] = array();
1316 $allowed_html['blockquote']['class'] = TRUE;
1317 $allowed_html['blockquote']['data-width'] = TRUE;
1318 $allowed_html['p']['lang'] = TRUE;
1319 $allowed_html['p']['dir'] = TRUE;
1320
1321 }
1322 }
1323
1324
1325 return wp_kses( $string, $allowed_html );
1326 }
1327
1328 function wpforo_deep_merge($default, $current = array()){
1329 foreach($default as $k => $v){
1330 if(!empty($v) && is_array($v)){
1331 foreach($v as $kk => $vv){
1332 if(!empty($vv) && is_array($vv)){
1333 foreach($vv as $kkk => $vvv){
1334 if(!empty($vvv) && is_array($vvv)){
1335 foreach($vvv as $kkkk => $vvvv){
1336 if(!empty($vvv) && is_array($vvv)){
1337 //Stop on 5th level
1338 }
1339 else{
1340 if(isset($current[$k][$kk][$kkk][$kkkk])) $default[$k][$kk][$kkk][$kkkk] = $current[$k][$kk][$kkk][$kkkk];
1341 }
1342 }
1343 }
1344 else{
1345 if(isset($current[$k][$kk][$kkk])) $default[$k][$kk][$kkk] = $current[$k][$kk][$kkk];
1346 }
1347 }
1348 }
1349 else{
1350 if(isset($current[$k][$kk])) $default[$k][$kk] = $current[$k][$kk];
1351 }
1352 }
1353 }
1354 else{
1355 if(isset($current[$k])) $default[$k] = $current[$k];
1356 }
1357 }
1358 return $default;
1359 }
1360
1361
1362 function wpforo_is_image($e){
1363 $is_image = false;
1364 $e = strtolower($e);
1365 if( $e == 'jpg' || $e == 'jpeg' || $e == 'png' || $e == 'gif' ){
1366 $is_image = true;
1367 }
1368 return $is_image;
1369 }
1370
1371
1372 function get_wpf_option( $key ){
1373 global $wpdb;
1374 $value = get_option($key);
1375 if( $value ){
1376 $value = maybe_unserialize( $value );
1377 }
1378 else{
1379 $value = $wpdb->get_var("SELECT `option_value` FROM `".$wpdb->prefix."options` WHERE `option_name` = '". esc_sql($key) . "'");
1380 if(is_serialized( $value )) {
1381 $check = @unserialize($value);
1382 if( !$check ) $value = wpforo_fixSerializedArray($value);
1383 if( !$value && $value !== 0 ) return NULL;
1384 }
1385 }
1386 return $value;
1387 }
1388
1389 /**
1390 * Extract what remains from an unintentionally truncated serialized string
1391 * $data contains your original array (or what remains of it).
1392 * @param string The serialized array
1393 */
1394 function wpforo_fixSerializedArray($serialized){
1395 $tmp = preg_replace('/^a:\d+:\{/', '', $serialized);
1396 return wpforo_fixSerializedArray_R($tmp);
1397 }
1398 /**
1399 * The recursive function that does all of the heavy lifing. Do not call directly.
1400 * @param string The broken serialzized array
1401 * @return string Returns the repaired string
1402 */
1403 function wpforo_fixSerializedArray_R(&$broken){
1404 $data = array();
1405 $index = NULL;
1406 $len = strlen($broken);
1407 $i = 0;
1408 while(strlen($broken)) {
1409 $i++;
1410 if ($i > $len) { break; }
1411 if (substr($broken, 0, 1) == '}') {
1412 $broken = substr($broken, 1); return $data;
1413 }
1414 else{
1415 $bite = substr($broken, 0, 2);
1416 switch($bite) {
1417 case 's:':
1418 $re = '/^s:\d+:"([^\"]*)";/';
1419 if (preg_match($re, $broken, $m)){
1420 if ($index === NULL){ $index = $m[1]; }
1421 else{$data[$index] = $m[1]; $index = NULL;}
1422 $broken = preg_replace($re, '', $broken);
1423 }
1424 break;
1425 case 'i:':
1426 $re = '/^i:(\d+);/';
1427 if (preg_match($re, $broken, $m)){
1428 if ($index === NULL){$index = (int) $m[1]; }
1429 else{$data[$index] = (int) $m[1]; $index = NULL; }
1430 $broken = preg_replace($re, '', $broken);
1431 }
1432 break;
1433 case 'b:':
1434 $re = '/^b:[01];/';
1435 if (preg_match($re, $broken, $m)){
1436 $data[$index] = (bool) $m[1]; $index = NULL; $broken = preg_replace($re, '', $broken);
1437 }
1438 break;
1439 case 'a:':
1440 $re = '/^a:\d+:\{/';
1441 if (preg_match($re, $broken, $m)){
1442 $broken = preg_replace('/^a:\d+:\{/', '', $broken); $data[$index] = wpforo_fixSerializedArray_R($broken); $index = NULL;
1443 }
1444 break;
1445 case 'N;':
1446 $broken = substr($broken, 2); $data[$index] = NULL; $index = NULL;
1447 break;
1448 }
1449 }
1450 }
1451 return $data;
1452 }
1453
1454 function wpforo_insert_to_media_library( $attach_path, $title = '' ){
1455 if( wpforo_feature('attach-media-lib') ){
1456 if(!$attach_path ) return 0;
1457 $attach_fname = basename($attach_path);
1458 if(!$title) $title = $attach_fname;
1459 require_once(ABSPATH . 'wp-admin/includes/media.php');
1460 require_once(ABSPATH . 'wp-admin/includes/file.php');
1461 require_once(ABSPATH . 'wp-admin/includes/image.php');
1462 $wp_upload_dir = wp_upload_dir();
1463 $filetype = wp_check_filetype( $attach_fname, NULL );
1464 $attachment = array( 'guid' => $attach_path, 'post_mime_type' => $filetype['type'], 'post_title' => $title, 'post_content' => '', 'post_status' => 'inherit');
1465 $attach_id = wp_insert_attachment( $attachment, $attach_path );
1466 add_filter( 'intermediate_image_sizes', 'wpforo_attachment_sizes' );
1467 $attach_data = wp_generate_attachment_metadata( $attach_id, $attach_path );
1468 wp_update_attachment_metadata( $attach_id, $attach_data );
1469 remove_filter( 'intermediate_image_sizes', 'wpforo_attachment_sizes' );
1470 return $attach_id;
1471 }
1472 }
1473
1474 function wpforo_attachment_sizes( $sizes ){
1475 return array('thumbnail');
1476 }
1477
1478 function wpforo_debug( $wpforo ){
1479 if( wpforo_feature('debug-mode', $wpforo) ) : ?>
1480 <div id="wpforo-debug" style="display:none">
1481 <h4>Current Object</h4>
1482 <p><?php @print_r($wpforo->current_object); ?></p>
1483 <h4>Super Globals</h4>
1484 <p>Requests: <?php print_r($_REQUEST); ?></p>
1485 <p>Server: <?php print_r($_REQUEST); ?></p>
1486 <h4>Options and Features</h4>
1487 <textarea style="width:500px; height:300px;"><?php echo @ 'permastruct: ' . $wpforo->permastruct . "\r\n";
1488 echo @ 'use_home_url: ' . $wpforo->use_home_url . "\r\n";
1489 echo @ 'url: ' . wpforo_home_url() . "\r\n";
1490 @print_r($wpforo->general_options) . "\r\n";
1491 echo @ 'pageid:' . $wpforo->pageid . "\r\n";
1492 echo @ 'default_groupid: ' . $wpforo->default_groupid . "\r\n";
1493 @print_r($wpforo->usergroup_cans) . "\r\n";
1494 @print_r($wpforo->forum_options) . "\r\n";
1495 @print_r($wpforo->forum_cans) . "\r\n";
1496 @print_r($wpforo->post_options) . "\r\n";
1497 @print_r($wpforo->member_options) . "\r\n";
1498 @print_r($wpforo->subscribe_options) . "\r\n";
1499 @print_r($wpforo->features) . "\r\n";
1500 @print_r($wpforo->style_options) . "\r\n";
1501 @print_r($wpforo->theme_options) . "\r\n";
1502 @print_r($wpforo->theme) . "\r\n";
1503 ?>
1504 </textarea>
1505 </div>
1506 <?php
1507 endif;
1508 }
1509
1510 function wpforo_hook( $name, $args = array() ){
1511 do_action( $name, $args );
1512 }
1513
1514 #################################################################################
1515 /**
1516 * Cleans forum cache
1517 *
1518 * @since 1.2.1
1519 *
1520 * @param integer Item ID (e.g.: $topicid or $postid) | (!) ID is 0 on dome actions (e.g.: delete actions)
1521 * @param string Item View / Template (e.g.: 'forum', 'topic', 'post', 'user', 'widget', etc...)
1522 *
1523 * @return NULL
1524 */
1525 function wpforo_clean_cache( $id = 0, $template = 'all' ){
1526 global $wpforo;
1527 $pageid = url_to_postid( $_SERVER['REQUEST_URI'] );
1528 do_action( 'wpforo_clean_cache_start', $id, $template );
1529 if( $pageid ){
1530 $page = get_post( $pageid );
1531 clean_post_cache( $page );
1532 }
1533 $wpforo->statistic('update');
1534 do_action( 'wpforo_clean_cache', $id, $template );
1535 $wpforo->cache->clean( $id, $template );
1536 do_action( 'wpforo_clean_cache_end', $id, $template );
1537 }
1538
1539 function wpforo_db_check( $args = array() ){
1540 global $wpdb;
1541 $check = trim($args['check']);
1542 $col = esc_sql(trim($args['col']));
1543 $table = esc_sql(trim($args['table']));
1544
1545 if( $check == 'table_exists' ){
1546 return $wpdb->get_var("SHOW TABLES LIKE '" . $table . "';");
1547 }
1548
1549 if( $check == 'col_exists' ){
1550 return $wpdb->get_var("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';");
1551 }
1552
1553 if( $check == 'key_exists' ){
1554 $col = $wpdb->get_row("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';", ARRAY_A);
1555 return $col['Key'];
1556 }
1557
1558 if( $check == 'default_value' ){
1559 $col = $wpdb->get_row("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';", ARRAY_A);
1560 return $col['Default'];
1561 }
1562
1563 if( $check == 'col_type' ){
1564 $col = $wpdb->get_row("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';", ARRAY_A);
1565 return $col['Type'];
1566 }
1567 }
1568
1569 function wpforo_is_owner( $userid ){
1570 global $wpforo;
1571 if( !empty($wpforo) ){
1572 if( isset($wpforo->current_userid) && $wpforo->current_userid ){
1573 if( $userid == $wpforo->current_userid ) return true;
1574 }
1575 }
1576 return false;
1577 }
1578
1579 function wpforo_make_dname($display_name, $user_nicename){
1580 $display_name = trim($display_name);
1581 $user_nicename = trim($user_nicename);
1582 return ( $display_name ? esc_html($display_name) : esc_html(urldecode($user_nicename)) );
1583 }
1584
1585 function wpfor_strlen( $string ){
1586 if(!$string) return 0;
1587 if(function_exists('mb_strlen')){
1588 return mb_strlen($string);
1589 }
1590 else{
1591 return strlen($string);
1592 }
1593 }
1594
1595 ?>