PluginProbe
wpForo Forum / 1.3.0
wpForo Forum v1.3.0
3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 All 137 releases
wpforo / wpf-includes / functions.php

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

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