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