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