PluginProbe
wpForo Forum / 1.2.0
wpForo Forum v1.2.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.2.0, at wpf-includes/functions.php

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