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

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

1,738 lines 70.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5 function wpforo_verify_form( $mode = 'full' ){
6 if( $mode == 'nonce' || $mode == 'full'){
7 if(!isset($_POST['wpforo_form']) || !wp_verify_nonce( $_POST['wpforo_form'], 'wpforo_verify_form' )) {
8 wpforo_phrase('Sorry, something wrong with your data.');
9 exit();
10 }
11 }
12 if( $mode == 'ref' || $mode == 'full'){
13 if( !isset($_SERVER['HTTP_REFERER']) || !$_SERVER['HTTP_REFERER'] ) {
14 exit('Error 2252 | Please contact to forum admin.');
15 }
16 $ref = $_SERVER['HTTP_REFERER'];
17 $url = get_bloginfo('url');
18 $ref_domain = trim(strtolower(parse_url($ref, PHP_URL_HOST)));
19 $web_domain = trim(strtolower(parse_url($url, PHP_URL_HOST)));
20 if( $ref_domain != $web_domain ){
21 exit('Error 2253 | Please contact to forum admin.');
22 }
23 }
24 }
25
26 function wpforo_home_url($str = '', $echo = false, $absolute = true){
27 global $wpforo;
28
29 if( strpos($str, 'http') === 0 ){
30 $base_url = preg_replace('#/?\?.*$#isu', '', wpforo_home_url());
31 $base_url = preg_replace('#index\.php/?#isu', '', $base_url, 1);
32 $str = preg_replace('#index\.php/?#isu', '', $str, 1);
33 $str = preg_replace('#^'.preg_quote( rtrim($base_url, '/\\') ).'/?#isu', '', $str, 1);
34 }
35 $str = trim(WPFORO_BASE_PERMASTRUCT, '/\\') . '/' . trim($str, '/\\');
36
37 if( $absolute ){
38 $url = $wpforo->user_trailingslashit( home_url($str) );
39 //-START- check is url maybe wordpress home
40 $maybe_home_url = trim( preg_replace('#/?index\.php/?(\?.*)?$#isu', '', $url), '/\\' );
41 $home_url = trim( home_url(), '/\\' );
42 if( $maybe_home_url == $home_url ){
43 $url = preg_replace('#index\.php/?#isu', '', $url, 1);
44 $url = $wpforo->user_trailingslashit($url);
45 }
46 //-END- check is url maybe wordpress home
47 }
48 else{
49 echo $url = $wpforo->user_trailingslashit( $str );
50 }
51
52 if(!$echo) return $url;
53 echo $url;
54 }
55
56 function wpforo_is_ajax(){
57 if( defined('DOING_AJAX') && DOING_AJAX ) return TRUE;
58 return FALSE;
59 }
60
61 function wpforo_is_admin(){
62 if( is_admin() && !wpforo_is_ajax() ) return TRUE;
63 return FALSE;
64 }
65
66 function is_wpforo_page($url = ''){
67 if( wpforo_is_admin() ) return FALSE;
68 if(!$url) $url = wpforo_get_request_uri();
69 if( is_wpforo_exclude_url($url) ) return FALSE;
70 if( is_wpforo_shortcode_page() ) return TRUE;
71 return is_wpforo_url($url);
72 }
73
74 function is_wpforo_exclude_url($url = ''){
75 global $wpforo;
76
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('wp_loaded', 'wpforo_cookie_logs', 10);
891
892 function wpforo_cookie_logs(){
893 global $wpforo;
894 if(!wpforo_feature('view-logging', $wpforo)) return;
895 $key = ''; $logid = 0; $log = false;
896 $data = $wpforo->current_object;
897 if( $data['template'] == 'post' && isset($data['topicid']) && $data['topicid'] ){
898 $logid = $data['topicid'];
899 $key = 'wpf_viewed_topics';
900 }
901 elseif( $data['template'] == 'topic' && isset($data['forumid']) && $data['forumid'] ){
902 $logid = $data['forumid'];
903 $key = 'wpf_viewed_forums';
904 }
905 if( $logid && $key ) {
906 $viwed_ids = wpforo_getcookie( $key, true );
907 if( !$viwed_ids ){
908 $log = true;
909 $viwed_ids = array( $logid );
910 }
911 elseif( is_array($viwed_ids) && !in_array( $logid , $viwed_ids ) ){
912 $log = true;
913 $viwed_ids[] = $logid;
914 }
915 if( $log ){
916 wpforo_setcookie( $key, $viwed_ids, true );
917 }
918 }
919 }
920
921 add_action('wpforo_bottom_hook', 'wpforo_user_logging');
922 function wpforo_user_logging(){
923 global $wpforo;
924 $data = $wpforo->current_object;
925 if( $data['template'] == 'post' && isset($data['topicid']) && $data['topicid'] ){
926 $current_user_id = get_current_user_id();
927 $current_time = current_time( 'timestamp', 1 );
928 if( $current_user_id ){
929 //registered user
930 $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);
931 if( !$view['vid'] ){
932 $sql = "INSERT INTO ". $wpforo->db->prefix ."wpforo_views( `userid` , `topicid` , `created` ) VALUES ( '".intval($current_user_id)."', " . intval($data['topicid']) . ", '" . esc_sql($current_time) . "' ) ";
933 $wpforo->db->query($sql);
934 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_topics` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
935 }else{
936 $sql = "UPDATE ". $wpforo->db->prefix ."wpforo_views SET `created` = " . intval($current_time) . " WHERE `userid` = " . intval($current_user_id) . " AND `topicid` = " . intval($data['topicid']);
937 $wpforo->db->query($sql);
938 if( $current_time - $view['created'] > 86400 ){
939 $wpforo->db->query("UPDATE `".$wpforo->db->prefix."wpforo_topics` SET `views` = `views` + 1 WHERE `topicid` = " . intval($data['topicid']));
940 }
941 }
942 }
943 }
944 }
945
946
947 add_action( 'init', 'wpforo_setcookie', 10, 2);
948
949 function wpforo_setcookie( $key = '', $args = array(), $implode = false ) {
950 if( !empty($args) && is_array($args) && $implode ) {
951 $num = count($args);
952 if( $num > 200 ){ $delta = $num - 200; if( $delta > 0 ) $args = array_slice($args, $delta); }
953 $value = trim( implode( ',', $args ), ',' );
954 }
955 elseif( !empty($args) && is_array($args) && !$implode ){
956 $value = serialize($args);
957 }
958 if( $key && $value ){
959 @setcookie( $key, $value , time() + 7776000, COOKIEPATH, COOKIE_DOMAIN );
960 }
961 }
962
963 add_action( 'wp_head', 'wpforo_getcookie' );
964 function wpforo_getcookie( $key = '', $explode = false ) {
965 if( $key ){
966 if( isset($_COOKIE[$key]) && $_COOKIE[$key] ){
967 if($explode){
968 return explode(',', $_COOKIE[$key]);
969 }
970 else{
971 return $_COOKIE[$key];
972 }
973 }else{
974 return FALSE;
975 }
976 }
977 }
978
979 //Option value filter and output
980 function wpfo( $option = '', $echo = true, $esc = 'esc_attr' ){
981 if( is_string($option) ){
982 $option = stripslashes( $option );
983 if( $esc == 'esc_attr' ){
984 $option = esc_attr( $option );
985 }
986 elseif( $esc == 'esc_html' ){
987 $option = esc_html( $option );
988 }
989 elseif( $esc == 'esc_url' ){
990 $option = esc_url( $option );
991 }
992 elseif( $esc == 'esc_textarea' ){
993 $option = esc_textarea( $option );
994 }
995 }
996
997 if( $echo ){
998 echo $option;
999 }
1000 else{
1001 return $option;
1002 }
1003 }
1004
1005 //Option maker for checkbox, radio and select
1006 function wpfo_check( $option = '', $value = '', $type = 'checked' , $echo = true ){
1007 $option = (isset($option) && isset($value) && $option == $value ) ? $type : '';
1008 if( $echo ){
1009 echo $option;
1010 }
1011 else{
1012 return $option;
1013 }
1014 }
1015
1016 function wpforo_human_filesize($bytes, $decimals = 2) {
1017 $size = array('B','KB','MB','GB','TB','PB','EB','ZB','YB');
1018 $factor = floor((strlen($bytes) - 1) / 3);
1019 return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . '&nbsp;' . @$size[$factor];
1020 }
1021
1022 function wpforo_date($date, $type = 'ago', $echo = true ) {
1023 if(is_numeric($date)) $date = date_i18n( 'Y-m-d H:i:s', $date);
1024
1025 global $wpforo;
1026 $d = $date;
1027 $sep = ' ';
1028 $timestamp = strtotime($date);
1029 $timezone_string = get_option('timezone_string');
1030 $current_offset = get_option('gmt_offset');
1031 if(!is_string($type)) $type = 'ago';
1032
1033 if( is_user_logged_in() && !empty($wpforo->current_user) ){
1034 if( isset($wpforo->current_user['timezone']) && $wpforo->current_user['timezone'] != '' ){
1035 if(preg_match('|UTC([\-\+]+.?)|is', $wpforo->current_user['timezone'], $timezone_array)){
1036 $timezone_string = '';
1037 $current_offset = str_replace('+', '', $timezone_array[1]);
1038 }
1039 else{
1040 if(in_array($wpforo->current_user['timezone'], timezone_identifiers_list())){
1041 $timezone_string = $wpforo->current_user['timezone'];
1042 $current_offset = '';
1043 }
1044 else{
1045 $timezone_string = '';
1046 $current_offset = '';
1047 }
1048 }
1049 }
1050 }
1051
1052 if( $timezone_string == '' && $current_offset != '' ){
1053 $timezone_string = timezone_name_from_abbr('', $current_offset * 3600, false);
1054 }
1055
1056 if( class_exists('DateTime') && class_exists('DateTimeZone') && $timezone_string ){
1057 $dt = new DateTime("now", new DateTimeZone($timezone_string));
1058 if( method_exists($dt, 'setTimestamp') ) $dt->setTimestamp($timestamp); //DateTime::setTimestamp() available in PHP 5.3 and higher versions
1059 if( $type == 'human' ){
1060 $d = human_time_diff($timestamp);
1061 }
1062 elseif( $type == 'ago' ){
1063 $d = human_time_diff($timestamp) . '&nbsp;';
1064 $d = sprintf( wpforo_phrase('%s ago', false, false), $d );
1065 }
1066 else{
1067 if( wpforo_feature('wp-date-format', $wpforo) ){
1068 $date_format = get_option('date_format');
1069 $time_format = get_option('time_format');
1070 $type = $date_format . $sep . $time_format;
1071 }
1072 $d = date_i18n($type, strtotime($dt->format('Y-m-d H:i:s')));
1073 }
1074 }
1075 else{
1076
1077 if( $type == 'human' ){
1078 $d = human_time_diff($timestamp);
1079 }
1080 elseif( $type == 'ago' ){
1081 $d = human_time_diff($timestamp) . '&nbsp;';
1082 $d = sprintf( wpforo_phrase('%s ago', false, false), $d );
1083 }
1084 else{
1085 if( wpforo_feature('wp-date-format', $wpforo) ){
1086 $date_format = get_option('date_format');
1087 $time_format = get_option('time_format');
1088 $type = $date_format . $sep . $time_format;
1089 }
1090 $d = date_i18n( $type, $timestamp);
1091 }
1092 }
1093
1094 if( $echo ){
1095 echo $d;
1096 }
1097 else{
1098 return $d;
1099 }
1100 }
1101
1102 function wpforo_write_file( $new_file, $content ){
1103 $return = array( 'error' => false, 'file' => '' );
1104 $ifp = @fopen( $new_file, 'wb' );
1105 if ( ! $ifp ) {
1106 $return = array( 'error' => sprintf( __( 'Could not write file %s' ), $new_file ) );
1107 }
1108 else{
1109 @fwrite( $ifp, $content );
1110 fclose( $ifp );
1111 clearstatcache();
1112 // Set correct file permissions
1113 $stat = @stat( dirname( $new_file ) );
1114 $perms = $stat['mode'] & 0007777;
1115 $perms = $perms & 0000666;
1116 @chmod( $new_file, $perms );
1117 clearstatcache();
1118 $return = array( 'file' => $new_file );
1119 }
1120 return $return;
1121 }
1122
1123
1124 function wpforo_get_file_content( $file ){
1125 $fp = @fopen( $file, 'r' );
1126 if( !$fp ){
1127 return false;
1128 }
1129 else{
1130 $size = @filesize($file);
1131 if( isset($size) && $size > 0 ){
1132 $file_data = fread( $fp, $size );
1133 fclose( $fp );
1134 return $file_data;
1135 }
1136 return false;
1137 }
1138 }
1139
1140 ################################################################################
1141 /**
1142 * Clears file basename and removes trailing slash
1143 *
1144 * @since 1.0.0
1145 *
1146 * @param string filename
1147 *
1148 * @return string
1149 */
1150 function wpforo_clear_basename( $file ) {
1151 $file = str_replace('\\','/',$file);
1152 $file = preg_replace('|/+|','/', $file);
1153 $file = trim($file, '/');
1154 return $file;
1155 }
1156
1157 #################################################################################
1158 /**
1159 * Removes directory with all files and folders
1160 *
1161 * @since 1.0.0
1162 *
1163 * @param string directory name
1164 *
1165 */
1166 function wpforo_remove_directory( $directory ) {
1167 $directory_ns = trim( $directory, '/') . '/';
1168 $directory_ws = '/' . trim( $directory, '/') . '/';
1169 $glob = glob( $directory_ns . '/*' );
1170 if( empty($glob) ) $glob = glob( $directory_ws . '/*' );
1171 foreach( $glob as $item ) {
1172 if( is_dir( $item ) ){
1173 wpforo_remove_directory( $item );
1174 }
1175 else{
1176 unlink( $item );
1177 }
1178 }
1179 return rmdir( $directory );
1180 }
1181
1182 #################################################################################
1183 /**
1184 * Converts bytes to KB, MB, GB
1185 *
1186 * @since 1.0.0
1187 *
1188 * @param integer Bytes
1189 *
1190 * @return string
1191 */
1192 function wpforo_print_size($value, $points = true ){
1193
1194 if($value <= 1024)
1195 {
1196 return $value . (($points) ? " B" : '' );
1197 }
1198 if($value > 1024 && $value <= (1024*1024))
1199 {
1200 $value=round(($value/1024)*10)/10;
1201 return $value . (($points) ? " KB" : '' );
1202 }
1203 if($value > 1024*1024 && $value <= 1024*1024*1024)
1204 {
1205 $value=round(($value/(1024*1024))*10)/10;
1206 return $value . (($points) ? " MB" : '' );
1207 }
1208 if($value > 1024*1024*1024 && $value <= 1024*1024*1024*1024)
1209 {
1210 $value=round(($value/(1024*1024*1024))*10)/10;
1211 return $value . (($points) ? " GB" : '' );
1212 }
1213 }
1214
1215 function wpforo_human_size_to_bytes($sSize)
1216 {
1217 if ( is_numeric( $sSize) ) {
1218 return $sSize;
1219 }
1220 $sSuffix = substr($sSize, -1);
1221 $iValue = substr($sSize, 0, -1);
1222 switch(strtoupper($sSuffix)){
1223 case 'P':
1224 $iValue *= 1024;
1225 case 'T':
1226 $iValue *= 1024;
1227 case 'G':
1228 $iValue *= 1024;
1229 case 'M':
1230 $iValue *= 1024;
1231 case 'K':
1232 $iValue *= 1024;
1233 break;
1234 }
1235 return $iValue;
1236 }
1237
1238
1239 function wpforo_print_number($n, $echo = false) {
1240 $x = str_replace(",","",$n);
1241 $x = intval($x);
1242 $n = 0 + $x;
1243 if(!is_numeric($n)) return false;
1244 if($n>1000000000000) return round(($n/1000000000000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}T',false));
1245 else if($n>1000000000) return round(($n/1000000000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}B',false));
1246 else if($n>1000000) return round(($n/1000000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}M',false));
1247 else if($n>10000) return round(($n/1000),1).' '.str_replace('{number}', '', wpforo_phrase('{number}K',false));
1248 if($echo){
1249 echo number_format($n);
1250 }
1251 else{
1252 return number_format($n);
1253 }
1254 }
1255
1256 function wpforo_bigintval($value) {
1257 if(!is_array($value)) {
1258 $value = trim($value);
1259 }
1260 if (ctype_digit($value)) {
1261 return $value;
1262 }
1263 $value = preg_replace("/[^0-9](.*)$/", '', $value);
1264 if (ctype_digit($value)) {
1265 return $value;
1266 }
1267 return 0;
1268 }
1269
1270 function wpforo_removebb($string){
1271 if(isset($string) && $string ){
1272 $string = preg_replace('|\[\/*[^\]\[]+\]|is', '', $string);
1273 }
1274 return $string;
1275 }
1276
1277 function wpforo_file_upload_error($code){
1278 switch ($code) {
1279 case UPLOAD_ERR_INI_SIZE:
1280 $message = wpforo_phrase("The uploaded file exceeds the upload_max_filesize directive in php.ini", false);
1281 break;
1282 case UPLOAD_ERR_FORM_SIZE:
1283 $message = wpforo_phrase("The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form", false);
1284 break;
1285 case UPLOAD_ERR_PARTIAL:
1286 $message = wpforo_phrase("The uploaded file was only partially uploaded", false);
1287 break;
1288 case UPLOAD_ERR_NO_FILE:
1289 $message = wpforo_phrase("No file was uploaded", false);
1290 break;
1291 case UPLOAD_ERR_NO_TMP_DIR:
1292 $message = wpforo_phrase("Missing a temporary folder", false);
1293 break;
1294 case UPLOAD_ERR_CANT_WRITE:
1295 $message = wpforo_phrase("Failed to write file to disk", false);
1296 break;
1297 case UPLOAD_ERR_EXTENSION:
1298 $message = wpforo_phrase("File upload stopped by extension", false);
1299 break;
1300 default:
1301 $message = wpforo_phrase("Unknown upload error", false);
1302 break;
1303 }
1304 return $message;
1305 }
1306
1307 //$key allowed values are post, strip, data, user_description entities or the name of a field filter such as pre_user_description.
1308 //More info https://core.trac.wordpress.org/browser/tags/4.5.2/src/wp-includes/kses.php#L624
1309 function wpforo_kses( $string = '', $key = 'data' ){
1310
1311 if(!$string || !$key) return $string;
1312 if( $key == 'email' ){
1313 $allowed_html = array( 'a' => array( 'href' => array(), 'title' => array()),
1314 'blockquote' => array(),
1315 'h1' => array(), 'h2' => array(), 'h3' => array(), 'h4' => array(), 'h5' => array(), 'h6' => array(),
1316 'hr' => array(),
1317 'br' => array(),
1318 'p' => array(),
1319 'strong' => array());
1320 }
1321 else{
1322 $allowed_html = wp_kses_allowed_html( $key );
1323 if( $key == 'user_description' ){
1324 $allowed_html['img'] = array( 'alt' => array(), 'align' => array(), 'border' => array(), 'height' => array(), 'hspace' => array(), 'longdesc' => array(), 'vspace' => array(), 'src' => array(), 'usemap' => array(), 'width' => array());
1325 }
1326 else{
1327 global $allowedposttags;
1328 $allowed_html = wpforo_parse_args($allowed_html, $allowedposttags);
1329
1330 $allowed_html['a']['data-gallery'] = array();
1331 $allowed_html['a']['download'] = array();
1332 $allowed_html['iframe']['width'] = array();
1333 $allowed_html['iframe']['height'] = array();
1334 $allowed_html['iframe']['src'] = array();
1335 $allowed_html['iframe']['frameborder'] = array();
1336 $allowed_html['iframe']['allowfullscreen'] = array();
1337 $allowed_html['embed']['flashVars'] = array();
1338 $allowed_html['embed']['src'] = array();
1339 $allowed_html['embed']['width'] = array();
1340 $allowed_html['embed']['height'] = array();
1341 $allowed_html['embed']['wmode'] = array();
1342 $allowed_html['embed']['allowFullScreen'] = array();
1343 $allowed_html['embed']['allowScriptAccess'] = array();
1344 $allowed_html['embed']['name'] = array();
1345 $allowed_html['embed']['pluginspage'] = array();
1346 $allowed_html['embed']['type'] = array();
1347 $allowed_html['blockquote']['class'] = TRUE;
1348 $allowed_html['blockquote']['data-width'] = TRUE;
1349 $allowed_html['p']['lang'] = TRUE;
1350 $allowed_html['p']['dir'] = TRUE;
1351
1352 }
1353 }
1354
1355
1356 return wp_kses( $string, $allowed_html );
1357 }
1358
1359 function wpforo_deep_merge($default, $current = array()){
1360 foreach($default as $k => $v){
1361 if(!empty($v) && is_array($v)){
1362 foreach($v as $kk => $vv){
1363 if(!empty($vv) && is_array($vv)){
1364 foreach($vv as $kkk => $vvv){
1365 if(!empty($vvv) && is_array($vvv)){
1366 foreach($vvv as $kkkk => $vvvv){
1367 if(!empty($vvv) && is_array($vvv)){
1368 //Stop on 5th level
1369 }
1370 else{
1371 if(isset($current[$k][$kk][$kkk][$kkkk])) $default[$k][$kk][$kkk][$kkkk] = $current[$k][$kk][$kkk][$kkkk];
1372 }
1373 }
1374 }
1375 else{
1376 if(isset($current[$k][$kk][$kkk])) $default[$k][$kk][$kkk] = $current[$k][$kk][$kkk];
1377 }
1378 }
1379 }
1380 else{
1381 if(isset($current[$k][$kk])) $default[$k][$kk] = $current[$k][$kk];
1382 }
1383 }
1384 }
1385 else{
1386 if(isset($current[$k])) $default[$k] = $current[$k];
1387 }
1388 }
1389 return $default;
1390 }
1391
1392
1393 function wpforo_is_image($e){
1394 $is_image = false;
1395 $e = strtolower($e);
1396 if( $e == 'jpg' || $e == 'jpeg' || $e == 'png' || $e == 'gif' ){
1397 $is_image = true;
1398 }
1399 return $is_image;
1400 }
1401
1402
1403 function get_wpf_option( $option, $default = false ){
1404 global $wpdb;
1405 $value = get_option($option, $default);
1406 if( $value ){
1407 $value = maybe_unserialize( $value );
1408 }
1409 else{
1410 $value = $wpdb->get_var("SELECT `option_value` FROM `".$wpdb->prefix."options` WHERE `option_name` = '". esc_sql($option) . "'");
1411 if(is_serialized( $value )) {
1412 $check = @unserialize($value);
1413 if( !$check ) $value = wpforo_fixSerializedArray($value);
1414 if( !$value && $value !== 0 ) return NULL;
1415 }
1416 }
1417 if( $default && is_array($default) && is_array($value) ) $value = array_merge( $default, $value );
1418 return $value;
1419 }
1420
1421 /**
1422 * Extract what remains from an unintentionally truncated serialized string
1423 * $data contains your original array (or what remains of it).
1424 * @param string The serialized array
1425 */
1426 function wpforo_fixSerializedArray($serialized){
1427 $tmp = preg_replace('/^a:\d+:\{/', '', $serialized);
1428 return wpforo_fixSerializedArray_R($tmp);
1429 }
1430 /**
1431 * The recursive function that does all of the heavy lifing. Do not call directly.
1432 * @param string The broken serialzized array
1433 * @return string Returns the repaired string
1434 */
1435 function wpforo_fixSerializedArray_R(&$broken){
1436 $data = array();
1437 $index = NULL;
1438 $len = strlen($broken);
1439 $i = 0;
1440 while(strlen($broken)) {
1441 $i++;
1442 if ($i > $len) { break; }
1443 if (substr($broken, 0, 1) == '}') {
1444 $broken = substr($broken, 1); return $data;
1445 }
1446 else{
1447 $bite = substr($broken, 0, 2);
1448 switch($bite) {
1449 case 's:':
1450 $re = '/^s:\d+:"([^\"]*)";/';
1451 if (preg_match($re, $broken, $m)){
1452 if ($index === NULL){ $index = $m[1]; }
1453 else{$data[$index] = $m[1]; $index = NULL;}
1454 $broken = preg_replace($re, '', $broken);
1455 }
1456 break;
1457 case 'i:':
1458 $re = '/^i:(\d+);/';
1459 if (preg_match($re, $broken, $m)){
1460 if ($index === NULL){$index = (int) $m[1]; }
1461 else{$data[$index] = (int) $m[1]; $index = NULL; }
1462 $broken = preg_replace($re, '', $broken);
1463 }
1464 break;
1465 case 'b:':
1466 $re = '/^b:[01];/';
1467 if (preg_match($re, $broken, $m)){
1468 $data[$index] = (bool) $m[1]; $index = NULL; $broken = preg_replace($re, '', $broken);
1469 }
1470 break;
1471 case 'a:':
1472 $re = '/^a:\d+:\{/';
1473 if (preg_match($re, $broken, $m)){
1474 $broken = preg_replace('/^a:\d+:\{/', '', $broken); $data[$index] = wpforo_fixSerializedArray_R($broken); $index = NULL;
1475 }
1476 break;
1477 case 'N;':
1478 $broken = substr($broken, 2); $data[$index] = NULL; $index = NULL;
1479 break;
1480 }
1481 }
1482 }
1483 return $data;
1484 }
1485
1486 function wpforo_insert_to_media_library( $attach_path, $title = '' ){
1487 if( wpforo_feature('attach-media-lib') ){
1488 if(!$attach_path ) return 0;
1489 $attach_fname = basename($attach_path);
1490 if(!$title) $title = $attach_fname;
1491 require_once(ABSPATH . 'wp-admin/includes/media.php');
1492 require_once(ABSPATH . 'wp-admin/includes/file.php');
1493 require_once(ABSPATH . 'wp-admin/includes/image.php');
1494 $wp_upload_dir = wp_upload_dir();
1495 $filetype = wp_check_filetype( $attach_fname, NULL );
1496 $attachment = array( 'guid' => $attach_path, 'post_mime_type' => $filetype['type'], 'post_title' => $title, 'post_content' => '', 'post_status' => 'inherit');
1497 $attach_id = wp_insert_attachment( $attachment, $attach_path );
1498 add_filter( 'intermediate_image_sizes', 'wpforo_attachment_sizes' );
1499 $attach_data = wp_generate_attachment_metadata( $attach_id, $attach_path );
1500 wp_update_attachment_metadata( $attach_id, $attach_data );
1501 remove_filter( 'intermediate_image_sizes', 'wpforo_attachment_sizes' );
1502 return $attach_id;
1503 }
1504 }
1505
1506 function wpforo_attachment_sizes( $sizes ){
1507 return array('thumbnail');
1508 }
1509
1510 function wpforo_debug( $wpforo ){
1511 if( wpforo_feature('debug-mode', $wpforo) ) : ?>
1512 <div id="wpforo-debug" style="display:none">
1513 <h4>Super Globals</h4>
1514 <p>Requests: <?php print_r($_REQUEST); ?></p>
1515 <p>Server: <?php print_r($_REQUEST); ?></p>
1516 <h4>Options and Features</h4>
1517 <textarea style="width:500px; height:300px;"><?php echo @ 'permastruct: ' . $wpforo->permastruct . "\r\n";
1518 echo @ 'use_home_url: ' . $wpforo->use_home_url . "\r\n";
1519 echo @ 'url: ' . wpforo_home_url() . "\r\n";
1520 @print_r($wpforo->general_options) . "\r\n";
1521 echo @ 'pageid:' . $wpforo->pageid . "\r\n";
1522 echo @ 'default_groupid: ' . $wpforo->usergroup->default_groupid . "\r\n";
1523 @print_r($wpforo->forum->options) . "\r\n";
1524 @print_r($wpforo->post->options) . "\r\n";
1525 @print_r($wpforo->member->options) . "\r\n";
1526 @print_r($wpforo->sbscrb->options) . "\r\n";
1527 @print_r($wpforo->features) . "\r\n";
1528 @print_r($wpforo->tpl->style) . "\r\n";
1529 @print_r($wpforo->tpl->options) . "\r\n";
1530 @print_r($wpforo->tpl->theme) . "\r\n";
1531 ?>
1532 </textarea>
1533 </div>
1534 <?php
1535 endif;
1536 }
1537
1538 function wpforo_hook( $name, $args = array() ){
1539 do_action( $name, $args );
1540 }
1541
1542 #################################################################################
1543 /**
1544 * Cleans forum cache
1545 *
1546 * @since 1.2.1
1547 *
1548 * @param integer Item ID (e.g.: $topicid or $postid) | (!) ID is 0 on dome actions (e.g.: delete actions)
1549 * @param string Item View / Template (e.g.: 'forum', 'topic', 'post', 'user', 'widget', etc...)
1550 * @param array Item data as array
1551 *
1552 * @return NULL
1553 */
1554 function wpforo_clean_cache( $id = 0, $template = 'all', $item = array() ){
1555 global $wpforo;
1556 $pageid = url_to_postid( $_SERVER['REQUEST_URI'] );
1557 do_action( 'wpforo_clean_cache_start', $id, $template );
1558 if( $pageid ){
1559 $page = get_post( $pageid );
1560 clean_post_cache( $page );
1561 }
1562 $wpforo->statistic('update', $template);
1563 do_action( 'wpforo_clean_cache', $id, $template );
1564 $wpforo->cache->clean( $id, $template, $item );
1565 do_action( 'wpforo_clean_cache_end', $id, $template );
1566 }
1567
1568 function wpforo_db_check( $args = array() ){
1569 global $wpdb;
1570 $check = trim($args['check']);
1571 $col = esc_sql(trim($args['col']));
1572 $table = esc_sql(trim($args['table']));
1573
1574 if( $check == 'table_exists' ){
1575 return $wpdb->get_var("SHOW TABLES LIKE '" . $table . "';");
1576 }
1577
1578 if( $check == 'col_exists' ){
1579 return $wpdb->get_var("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';");
1580 }
1581
1582 if( $check == 'key_exists' ){
1583 $col = $wpdb->get_row("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';", ARRAY_A);
1584 return $col['Key'];
1585 }
1586
1587 if( $check == 'default_value' ){
1588 $col = $wpdb->get_row("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';", ARRAY_A);
1589 return $col['Default'];
1590 }
1591
1592 if( $check == 'col_type' ){
1593 $col = $wpdb->get_row("SHOW COLUMNS FROM `" . $table . "` LIKE '" . $col . "';", ARRAY_A);
1594 return $col['Type'];
1595 }
1596 }
1597
1598 function wpforo_is_owner( $userid ){
1599 global $wpforo;
1600 if( !empty($wpforo) ){
1601 if( isset($wpforo->current_userid) && $wpforo->current_userid ){
1602 if( $userid == $wpforo->current_userid ) return true;
1603 }
1604 }
1605 return false;
1606 }
1607
1608 function wpforo_make_dname($display_name, $user_nicename){
1609 $display_name = trim($display_name);
1610 $user_nicename = trim($user_nicename);
1611 return ( $display_name ? esc_html($display_name) : esc_html(urldecode($user_nicename)) );
1612 }
1613
1614 function wpforo_strlen($string ){
1615 if(!$string) return 0;
1616 if(function_exists('mb_strlen')){
1617 return mb_strlen($string);
1618 }
1619 else{
1620 return strlen($string);
1621 }
1622 }
1623
1624 function wpforo_string2array( $string, $regexp = '' ){
1625 if( !$regexp ) $regexp = '#' . preg_quote(PHP_EOL) . '#isu';
1626 $array = preg_split($regexp, $string);
1627 return array_filter($array);
1628 }
1629
1630 function wpforo_array_ordered_intersect_key($array1, $array2){
1631 $new_array = array();
1632 foreach ($array2 as $key => $value){
1633 if( isset( $array1[$key] ) ) $new_array[$key] = $array1[$key];
1634 }
1635 return $new_array;
1636 }
1637
1638 function wpforo_urlpath_to_dirpath($urlpath){
1639 $upload_array = wp_upload_dir();
1640 $wp_content_dir = preg_replace('#/wp-content/.+$#isu', '/wp-content/', $upload_array['basedir']);
1641 $dirpath = preg_replace('#^.+?/wp-content/#isu', $wp_content_dir, $urlpath);
1642 return $dirpath;
1643 }
1644
1645 function wpforo_xcopy($source, $dest)
1646 {
1647 // Check for symlinks
1648 if (is_link($source)) {
1649 return symlink(readlink($source), $dest);
1650 }
1651
1652 // Simple copy for a file
1653 if (is_file($source)) {
1654 return copy($source, $dest);
1655 }
1656
1657 // Make destination directory
1658 if (!is_dir($dest)) {
1659 wp_mkdir_p($dest);
1660 }
1661
1662 // Loop through the folder
1663 $dir = dir($source);
1664 while (false !== $entry = $dir->read()) {
1665 // Skip pointers
1666 if ($entry == '.' || $entry == '..') {
1667 continue;
1668 }
1669
1670 // Deep copy directories
1671 wpforo_xcopy( rtrim($source, '/') . "/$entry", rtrim($dest, '/') . "/$entry" );
1672 }
1673
1674 // Clean up
1675 $dir->close();
1676 return true;
1677 }
1678
1679 function wpforo_printf_array($format, $arr){
1680 return call_user_func_array('printf', array_merge((array)$format, (array)$arr));
1681 }
1682
1683 function wpforo_sprintf_array($format, $arr){
1684 return call_user_func_array('sprintf', array_merge((array)$format, (array)$arr));
1685 }
1686
1687 function wpforo_avatar_url($avatar_html){
1688 if( preg_match('#src=[\'"]([^\'"]+?)[\'"]#isu', $avatar_html, $matches) ){
1689 //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);
1690 return $matches[1];
1691 }
1692 return '';
1693 }
1694
1695 function wpforo_get_image_url( $content, $first = true ){
1696 $images = array();
1697 $content = apply_filters('wpforo_content_filter', $content);
1698 preg_match_all('#https?://[^\s\'\"<>]+\.(?:jpg|jpeg|png|gif|ico|svg|bmp|tiff)#isu', $content, $m_img, PREG_SET_ORDER);
1699 if( empty($m_img)) preg_match_all('#//[^\s\'\"<>]+\.(?:jpg|jpeg|png|gif|ico|svg|bmp|tiff)#isu', $content, $m_img, PREG_SET_ORDER);
1700 if(!empty($m_img)){
1701 foreach( $m_img as $match ){
1702 $ext = pathinfo($match[0], PATHINFO_EXTENSION);
1703 if( $ext && wpforo_is_image($ext)){
1704 $images[] = $match[0];
1705 }
1706 }
1707 }
1708 else{
1709 preg_match_all('#https?://[^\s\'\"<>]+#isu', $content, $m_url, PREG_SET_ORDER);
1710 if( empty($m_url)) preg_match_all('#//[^\s\'\"<>]+#isu', $content, $m_url, PREG_SET_ORDER);
1711 if(!empty($m_url)){
1712 foreach( $m_url as $match ){
1713 $ext = pathinfo($match[0], PATHINFO_EXTENSION);
1714 if( $ext && wpforo_is_image($ext)){
1715 $images[] = $match[0];
1716 }
1717 }
1718 }
1719 }
1720 if(!empty($images)){
1721 if( $first ){
1722 return $images[0];
1723 }
1724 else{
1725 return $images;
1726 }
1727 }
1728 return false;
1729 }
1730
1731 function wpforo_return_zero($var = null){
1732 return 0;
1733 }
1734
1735 function wpforo_is_json($string) {
1736 json_decode($string);
1737 return (json_last_error() == JSON_ERROR_NONE);
1738 }