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