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