conf['use_special_dates'] && $precision != -1 ) { $date = $this->getSince( $date, $precision, $method, $arr ); if ( is_array( $date ) || !$arr ) { if ( $date[0] == -1 ) return $date[1]; return $date; } } if ( empty( $method ) ) $format = "M j Y, h:i A"; elseif ( $method == "-medium" ) $format = "F j, Y"; elseif ( $method == "-short" ) $format = "m/d/Y"; elseif ( $method == "-RSS" ) $format = "D, j M Y G:i:s Z"; else $format = $method; return gmdate( $format, ($date +(60*60*$bin->conf['time_offset'])) ); } function getSince( $date, $precision, $mod, $arr = true ) { $m = array( "year" => 60*60*24*365, "month" => 60*60*24*30, "day" => 60*60*24, "hour" => 60*60, "minute" => 60, ); if ( !is_numeric( $date ) ) $date = strtotime( $date ); $diff = time() - $date; $minute = round( $diff / $m['minute'], $precision ); $hour = round( $diff / $m['hour'], $precision ); $day = round( $diff / $m['day'], $precision ); $month = round( $diff / $m['month'], $precision ); $year = round( $diff / $m['year'], $precision ); if ( empty( $mod ) ) { if ( $minute < 60 ) return array( $minute, "minute".( ( $minute != 1 ) ? "s" : "" ) ); if ( $hour < 24 ) return array( $hour, "hour".( ( $hour != 1 ) ? "s" : "" ) ); if ( $day < 2 ) return array( -1, "Yesterday" ); if ( $day < 6 ) return array( $day, "days" ); return $date; } if ( !$arr ) return $$mod; return array( $$mod, $mod .( ( $$mod != 1 ) ? "s" : "" ) ); } function encode( $txt, $base = 64 ) { switch ( $base ) { case 2: return $this->base10_encode( $txt ); default: return base64_encode( $txt ); } } function decode( $txt, $base = 64 ) { switch ( $base ) { case 2: return $this->base10_decode( $txt ); default: return base64_decode( $txt ); } } function base10_encode( $txt ) { $ret = ""; $dec = ""; for ( $i = 0; $i < strlen( $txt ); $i++ ) $dec .= ord( $txt{$i} )."."; $dec = explode ( ".", $dec ); for ( $x = 0; $x < count( $dec )-1; $x++ ) { $multiplier = 1; $binary = 0; $code = $dec[$x]; do { if ( ( $code % 2 ) == 1 ) { $code--; $binary += 1 * $multiplier; } $multiplier *= 10; $code /= 2; } while ( $code > 0 ); if ( strlen ( $binary ) < 8 ) for ( $i = 0; $i <= 8 - strlen( $binary ); $i++ ) $binary = "0".$binary; $ret .= $binary; } return $ret; } function base10_decode( $txt ) { $ret = ""; $ascii = ""; $ascii = $this->strtoarray( $txt, 8 ); foreach ( $ascii as $key => $binary ) { $dec = 0; for ( $i = strlen( $binary )-1, $j = 0; $i >= 0; $i--, $j++ ) $dec += ( $binary{$i} ) * (pow( 2, $j )); $ret .= chr( $dec ); } return $ret; } function generateRandom( $length = 8, $case = 0 ) { $chars = array ( 'A','B','C','D','E','F','G','H','I', 'J','K','L','M','N','O','P','Q','R', 'S','T','U','V','W','X','Y','Z','1', '2','3','4','5','6','7','8','9','0', ); $code = ""; for ( $i = 0; $i < $length; $i++ ) { $rand = rand( 0 , count( $chars ) -1 ); if ( $case == 0 && ( rand( 0, 100 ) ) % 3 == 0 ) $code .= strtolower( $chars[$rand] ); else $code .= $chars[$rand]; } if ( $case = 1 ) $code = strtolower( $code ); return $code; } function formatURL() { if ( func_num_args() == 0 ) return ""; $source = func_get_arg( 0 ); $qs = ""; for ( $i = 1; $i < func_num_args(); $i++ ) $qs .= func_get_arg( $i ) . URL_SEP; if ( URL_TYPE != 3 ) $qs = substr( $qs, 0, -1 ); $dot = ""; $ext = URL_EXT; if ( !empty( $ext ) ) $dot = "."; switch ( URL_TYPE ) { case 1: $url = "?". $source . URL_SEP . $qs; break; case 2: $url = $source . URL_SEP . $qs . $dot . URL_EXT; break; case 3: $url = $source . $dot . URL_EXT . URL_SEP . $qs; break; } return ( ( IN_SITE == 2 ) ? "/admin" : "" ) ."/". $url; } function validURL( $input ) { $hex = "%[0-9A-Fa-f]{2,2}"; $vChars = "A-Za-z0-9-_\.!~*'()"; $protocol = "(ftp|https?):\/\/"; $domain = "[".$vChars."]+?"; $tld = "\.?[".$vChars."]+?"; $port = "(:[0-9]{2,5})?"; $path = "\/(".$hex."|[".$vChars."\/])*?"; $query = "(\?(".$hex."|[".$vChars."\/])*?)?"; $regex = "#^".$protocol.$domain.$tld.$port.$path.$query."$#i"; return preg_match( $regex, $input ); } function secureEmail( $email ) { $email = str_replace( "@", ' /at\ ', $email ); $email = str_replace( ".", ' \dot/ ', $email ); return $email; } function validEmail( $email ) { $email = trim( $email ); if ( eregi( "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9]+)+$", $email ) ) return true; return false; } function sendEmail( $to, $subject, $text, $headers = "", $wrap = true ) { global $bin; if ( $wrap ) { $message = "An email has been sent from ".$from." on ".$this->getDate( time() )." to this email address from the website ". $bin->conf['url']; $message .= "\n\n-----------------------Message Start-----------------------\n\n"; $message .= $text; $message .= "\n\n------------------------Message End------------------------\n\n"; $message .= $bin->conf['url'] ." takes no responsibility in what this message contains."; } else $message = $text; return mail( $to, $subject, $message, $headers ); } function stripslashes( &$a ) { if ( !is_array( $a ) && !is_object( $a ) ) return stripslashes( $a ); foreach ( $a as $k => $v ) { if ( is_array( $v ) || is_object( $v ) ) $v = $this->stripslashes( $v ); else ( is_array( $a ) ) ? $a[$k] = stripslashes( $v ) : $a->$k = stripslashes( $v ); } return $a; } function trim( &$a ) { if ( !is_array( $a ) && !is_object( $a ) ) return trim( $a ); foreach ( $a as $k => $v ) { if ( is_array( $v ) || is_object( $v ) ) $v = $this->trim( $v ); else ( is_array( $a ) ) ? $a[$k] = trim( $v ) : $a->$k = trim( $v ); } return $a; } function strtoarray( $str, $len = 1 ) { $str = explode( "|{STRINGRTOARRAY}|", rtrim( chunk_split( $str, $len, "|{STRINGRTOARRAY}|" ), "|{STRINGRTOARRAY}|" ) ); return $str; } function plural( $num ) { if ( $num == 1 ) return ""; else return "s"; } } ?>