PluginProbe
wpForo Forum / 1.4.0
wpForo Forum v1.4.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.4.0, at wpf-includes/functions.php

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