PluginProbe
wpForo Forum / 1.0.2
wpForo Forum v1.0.2
3.1.6 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 All 138 releases
wpforo / wpf-includes / functions.php

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

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