ID ) { //Error or Not logged in. return TRUE; } if( !empty($opt_by_id) ){ $arr = array(); foreach( $opt_by_id as $k=>$v ) $arr[$v]=1; if( isset($arr[$current_user->user_email]) || isset($arr[$current_user->user_login]) || isset($arr[$current_user->ID]) ){ unset($arr); return FALSE; }else{ unset($arr); } } $result = TRUE; if( !empty($opt_by_role) ){ $role_arr = array( array(0,0), array(1,1), array(2,4), array(5,7), array(8,10), ); $x = $current_user->user_level; foreach( $opt_by_role as $k=>$v ){ $role_id = $role_arr[$v-1]; if( $x >= $role_id[0] && $x <= $role_id[1] ){ $result = FALSE; break; } } unset($role_arr); } return $result; } /* Utilities */ function print_gzipped_page($custom_header=array()) { $encoding = false; if( !headers_sent() && isset($_SERVER['HTTP_ACCEPT_ENCODING']) ){ if( strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip') !== false ){ $encoding = 'x-gzip'; }elseif( strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false ){ $encoding = 'gzip'; } } if( $encoding ){ $contents = ob_get_contents(); ob_end_clean(); if( !empty($custom_header) ){ foreach($custom_header as $k=>$v){ header($k.': '.$v); } } header('Content-Encoding: '.$encoding); print("\x1f\x8b\x08\x00\x00\x00\x00\x00"); $size = strlen($contents); $contents = gzcompress($contents, 9); $contents = substr($contents, 0, $size); print($contents); exit(); }else{ if( !empty($custom_header) ){ foreach($custom_header as $k=>$v){ header($k.': '.$v); } } ob_end_flush(); exit(); } } function normalize_array_val($str='', $sep=','){ $result = array(); if( empty($str) ) return FALSE; $dummy = explode($sep, $str); foreach($dummy as $i){ $i = trim($i); if( !empty($i) && is_numeric($i) && intval($i)>0 ){ $i = intval($i); if( !in_array($i, $result) ) $result[] = $i; }elseif( !empty($i) && !in_array($i, $result) ){ $result[] = $i; } } unset($dummy); if( empty($result) ){ return FALSE; }else{ return $result; } } function get_array_checkbox_el($name, $opt=array(), $selected=array()){ $result = ''; if( empty($name) || empty($opt) || !is_array($opt) ) return $result; $count = 0; foreach($opt as $k=>$item){ $count++; } $count_per = round($count/3); $i = 0; $ended = false; foreach($opt as $k=>$item){ if( $i == 0 ){ $result .= '
'; $ended = false; } $i++; $is_selected = ''; if( !empty($selected) && is_array($selected) && in_array($k, $selected) ) $is_selected = 'checked="checked" '; $result .= ' '.$item.'
'; if( $i>= $count_per ){ $i = 0; $result .= '
'; $ended = true; } } $result = trim($result); if( !empty($result) ){ if( !$ended ) $result .= ''; $result .= '
'; } return $result; } function array_checkbox_val($el=array(), $sep=','){ $result = array(); if( empty($el) || !is_array($el) ) return ''; foreach($el as $i){ $i = trim($i); if( !empty($i) && is_numeric($i) && intval($i)>0 ){ $i = intval($i); if( !in_array($i, $result) ) $result[] = $i; }elseif( !empty($i) && !in_array($i, $result) ){ $result[] = $i; } } if( empty($result) ){ return ''; }else{ return implode($sep, $result); } } function get_my_current_ip(){ $ipaddress = ''; if (getenv(HTTP_X_FORWARDED_FOR)) { $ipaddress = getenv(HTTP_X_FORWARDED_FOR); } else { $ipaddress = getenv(REMOTE_ADDR); } return $ipaddress; } function normalize_single_uri($str=''){ $result = ''; $str = strtolower(trim($str)); if( empty($str) ) return $result; $dummy = explode('?', $str); $str = trim($dummy[0]); $dummy = explode('#', $str); $str = trim($dummy[0]); unset($dummy); $result = $str; if( stripos($result, get_bloginfo('home')) === 0 ){ $result = str_ireplace(get_bloginfo('home'), '', $result); } return trim($result); } function normalize_uri($arr=array()){ $result = array(); if( empty($arr) || !is_array($arr) ) return FALSE; foreach($arr as $s){ $s = normalize_single_uri($s); if( !empty($s) && !in_array($s, $result) ) $result[] = $s; } if( empty($result) ){ return FALSE; }else{ return $result; } } function wildcard_uri($arr=array()){ $result = array(); if( empty($arr) || !is_array($arr) ) return FALSE; $wildcard = FALSE; foreach($arr as $arr_key=>$s){ $dummy = explode('.', $s); if( stripos($s,'*')!==FALSE && count($dummy) == 4 ){ $wildcard = TRUE; $new_ip = ''; $done = FALSE; for($k=0;$k