From 6348e70daa113e8b3203de8fbc919d08c90d972e Mon Sep 17 00:00:00 2001 From: Mike Macgirvin Date: Thu, 1 Jul 2010 16:48:07 -0700 Subject: Initial checkin --- include/Photo.php | 171 +++++++++++++++++++++++++++++++++++++++++ include/Scrape.php | 80 +++++++++++++++++++ include/bbcode.php | 105 +++++++++++++++++++++++++ include/datetime.php | 145 ++++++++++++++++++++++++++++++++++ include/dba.php | 138 +++++++++++++++++++++++++++++++++ include/login.php | 19 +++++ include/security.php | 17 ++++ include/session.php | 76 ++++++++++++++++++ include/system_unavailable.php | 6 ++ 9 files changed, 757 insertions(+) create mode 100644 include/Photo.php create mode 100644 include/Scrape.php create mode 100644 include/bbcode.php create mode 100644 include/datetime.php create mode 100644 include/dba.php create mode 100644 include/login.php create mode 100644 include/security.php create mode 100644 include/session.php create mode 100644 include/system_unavailable.php (limited to 'include') diff --git a/include/Photo.php b/include/Photo.php new file mode 100644 index 000000000..95ccccc88 --- /dev/null +++ b/include/Photo.php @@ -0,0 +1,171 @@ +image = @imagecreatefromstring($data); + if($this->image !== FALSE) { + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } + } + + public function __destruct() { + if($this->image) + imagedestroy($this->image); + } + + public function getWidth() { + return $this->width; + } + + public function getHeight() { + return $this->height; + } + + public function getImage() { + return $this->image; + } + + public function scaleImage($max) { + + $width = $this->width; + $height = $this->height; + + $dest_width = $dest_height = 0; + + if((! $width)|| (! $height)) + return FALSE; + + if($width > $max && $height > $max) { + if($width > $height) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } + } + else { + if( $width > $max ) { + $dest_width = $max; + $dest_height = intval(( $height * $max ) / $width); + } + else { + if( $height > $max ) { + $dest_width = intval(( $width * $max ) / $height); + $dest_height = $max; + } + else { + $dest_width = $width; + $dest_height = $height; + } + } + } + + + $dest = imagecreatetruecolor( $dest_width, $dest_height ); + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + + } + + + + public function scaleImageUp($min) { + + $width = $this->width; + $height = $this->height; + + $dest_width = $dest_height = 0; + + if((! $width)|| (! $height)) + return FALSE; + + if($width < $min && $height < $min) { + if($width > $height) { + $dest_width = $min; + $dest_height = intval(( $height * $min ) / $width); + } + else { + $dest_width = intval(( $width * $min ) / $height); + $dest_height = $min; + } + } + else { + if( $width < $min ) { + $dest_width = $min; + $dest_height = intval(( $height * $min ) / $width); + } + else { + if( $height < $min ) { + $dest_width = intval(( $width * $min ) / $height); + $dest_height = $min; + } + else { + $dest_width = $width; + $dest_height = $height; + } + } + } + + + $dest = imagecreatetruecolor( $dest_width, $dest_height ); + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + + } + + + + public function scaleImageSquare($dim) { + + $dest = imagecreatetruecolor( $dim, $dim ); + imagecopyresampled($dest, $this->image, 0, 0, 0, 0, $dim, $dim, $this->width, $this->height); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } + + + public function cropImage($max,$x,$y,$w,$h) { + $dest = imagecreatetruecolor( $max, $max ); + imagecopyresampled($dest, $this->image, 0, 0, $x, $y, $max, $max, $w, $h); + if($this->image) + imagedestroy($this->image); + $this->image = $dest; + $this->width = imagesx($this->image); + $this->height = imagesy($this->image); + } + + public function saveImage($path) { + imagejpeg($this->image,$path,100); + } + + public function imageString() { + ob_start(); + imagejpeg($this->image,NULL,100); + $s = ob_get_contents(); + ob_end_clean(); + return $s; + } + + +}} + diff --git a/include/Scrape.php b/include/Scrape.php new file mode 100644 index 000000000..cc5015165 --- /dev/null +++ b/include/Scrape.php @@ -0,0 +1,80 @@ +getElementsByTagName('link'); + + // get DFRN link elements + + foreach($items as $item) { + $x = $item->getAttribute('rel'); + if(substr($x,0,5) == "dfrn-") + $ret[$x] = $item->getAttribute('href'); + } + + // Pull out hCard profile elements + + $items = $dom->getElementsByTagName('*'); + foreach($items as $item) { + if(attribute_contains($item->getAttribute('class'), 'vcard')) { + $level2 = $item->getElementsByTagName('*'); + foreach($level2 as $x) { + if(attribute_contains($x->getAttribute('class'),'fn')) + $ret['fn'] = $x->textContent; + if(attribute_contains($x->getAttribute('class'),'photo')) + $ret['photo'] = $x->getAttribute('src'); + if(attribute_contains($x->getAttribute('class'),'key')) + $ret['key'] = $x->textContent; + } + } + } + + return $ret; +}} + + + + + + +if(! function_exists('validate_dfrn')) { +function validate_dfrn($a) { + $errors = 0; + if(! x($a,'key')) + $errors ++; + if(! x($a,'dfrn-request')) + $errors ++; + if(! x($a,'dfrn-confirm')) + $errors ++; + if(! x($a,'dfrn-notify')) + $errors ++; + if(! x($a,'dfrn-poll')) + $errors ++; + return $errors; +}} + + + diff --git a/include/bbcode.php b/include/bbcode.php new file mode 100644 index 000000000..60809a7e2 --- /dev/null +++ b/include/bbcode.php @@ -0,0 +1,105 @@ +", ">", $Text); + + // Convert new line chars to html
tags + $Text = nl2br($Text); + + // Set up the parameters for a URL search string + $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#\'"; + // Set up the parameters for a MAIL search string + $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@"; + + // Perform URL Search + $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '$1', $Text); + $Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '$2', $Text); + //$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '$2', $Text); + + // Perform MAIL Search + $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '$1', $Text); + $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '$2', $Text); + + // Check for bold text + $Text = preg_replace("(\[b\](.+?)\[\/b])is",'$1',$Text); + + // Check for Italics text + $Text = preg_replace("(\[i\](.+?)\[\/i\])is",'$1',$Text); + + // Check for Underline text + $Text = preg_replace("(\[u\](.+?)\[\/u\])is",'$1',$Text); + + // Check for strike-through text + $Text = preg_replace("(\[s\](.+?)\[\/s\])is",'$1',$Text); + + // Check for over-line text + $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'$1',$Text); + + // Check for colored text + $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","$2",$Text); + + // Check for sized text + $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","$2",$Text); + + // Check for list text + $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '' ,$Text); + $Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '' ,$Text); + $Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s",'' ,$Text); + $Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '' ,$Text); + $Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '' ,$Text); + $Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '' ,$Text); + $Text = str_replace("[*]", "
  • ", $Text); + + // Check for font change text + $Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","$2",$Text); + + // Declare the format for [code] layout + $CodeLayout = ' + + + + + + +
    Code:
    $1
    '; + // Check for [code] text + $Text = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $Text); + // Declare the format for [php] layout + $phpLayout = ' + + + + + + +
    Code:
    $1
    '; + // Check for [php] text + $Text = preg_replace("/\[php\](.+?)\[\/php\]/is",$phpLayout, $Text); + + // Declare the format for [quote] layout + $QuoteLayout = ' + + + + + + +
    Quote:
    $1
    '; + + // Check for [quote] text + $Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $Text); + + // Images + // [img]pathtoimage[/img] + $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '', $Text); + + // [img=widthxheight]image source[/img] + $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '', $Text); + + return $Text; + } diff --git a/include/datetime.php b/include/datetime.php new file mode 100644 index 000000000..f75193b1b --- /dev/null +++ b/include/datetime.php @@ -0,0 +1,145 @@ +'; + + usort($timezone_identifiers, 'timezone_cmp'); + $continent = ''; + foreach($timezone_identifiers as $value) { + $ex = explode("/", $value); + if(count($ex) > 1) { + if($ex[0] != $continent) { + if($continent != '') + $o .= ''; + $continent = $ex[0]; + $o .= ""; + } + if(count($ex) > 2) + $city = substr($value,strpos($value,'/')+1); + else + $city = $ex[1]; + } + else { + $city = $ex[0]; + if($continent != 'Miscellaneous') { + $o .= ''; + $continent = 'Miscellaneous'; + $o .= ""; + } + } + $city = str_replace('_', ' ', $city); + $selected = (($value == $current) ? " selected=\"selected\" " : ""); + $o .= ""; + } + $o .= ''; + return $o; +}} + + +if(! function_exists('datetime_convert')) { +function datetime_convert($from = 'UTC', $to = 'UTC', $s = 'now', $fmt = "Y-m-d H:i:s") { + $d = new DateTime($s, new DateTimeZone($from)); + $d->setTimeZone(new DateTimeZone($to)); + return($d->format($fmt)); +}} + + + +if(! function_exists('datesel')) { +function datesel($pre,$ymin,$ymax,$allow_blank,$y,$m,$d) { + + $o = ''; + $o .= "--"; + return $o; +}} + + +// TODO rewrite this buggy sucker +function relative_date($posted_date) { + + $localtime = datetime_convert('UTC',date_default_timezone_get(),$posted_date); + + $in_seconds = strtotime($localtime); + + $diff = time() - $in_seconds; + + $months = floor($diff/2592000); + $diff -= $months*2419200; + $weeks = floor($diff/604800); + $diff -= $weeks*604800; + $days = floor($diff/86400); + $diff -= $days*86400; + $hours = floor($diff/3600); + $diff -= $hours*3600; + $minutes = floor($diff/60); + $diff -= $minutes*60; + $seconds = $diff; + + + if ($months>0) { + // over a month old, + return 'over a month ago'; + } else { + if ($weeks>0) { + // weeks and days + $relative_date .= ($relative_date?', ':'').$weeks.' week'.($weeks!=1 ?'s':''); + + } elseif ($days>0) { + // days and hours + $relative_date .= ($relative_date?', ':'').$days.' day'.($days!=1?'s':''); + + } elseif ($hours>0) { + // hours and minutes + $relative_date .= ($relative_date?', ':'').$hours.' hour'.($hours!=1?'s':''); + + } elseif ($minutes>0) { + // minutes only + $relative_date .= ($relative_date?', ':'').$minutes.' minute'.($minutes!=1?'s':''); + } else { + // seconds only + $relative_date .= ($relative_date?', ':'').$seconds.' second'.($seconds!=1?'s':''); + } + } + // show relative date and add proper verbiage + return $relative_date.' ago'; +} diff --git a/include/dba.php b/include/dba.php new file mode 100644 index 000000000..3cc41ebdd --- /dev/null +++ b/include/dba.php @@ -0,0 +1,138 @@ +db = @new mysqli($server,$user,$pass,$db); + if((mysqli_connect_errno()) && (! install)) + system_unavailable(); + } + + public function q($sql) { + global $debug_text; + + if(! $this->db ) + return false; + + $result = @$this->db->query($sql); + + if($this->debug) { + + $mesg = ''; + + if($this->db->mysqli->errno) + $debug_text .= $this->db->mysqli->error . EOL; + + if($result === false) + $mesg = 'false'; + elseif($result === true) + $mesg = 'true'; + else + $mesg = $result->num_rows.' results' . EOL; + + $str = 'SQL = ' . $sql . EOL . 'SQL returned ' . $mesg . EOL; + + switch($this->debug) { + case 3: + echo $str; + break; + default: + $debug_text .= $str; + break; + } + } + + if(($result === true) || ($result === false)) + return $result; + + $r = array(); + if($result->num_rows) { + while($x = $result->fetch_array(MYSQL_ASSOC)) + $r[] = $x; + $result->free_result(); + } + + if($this->debug == 2) + $debug_text .= print_r($r, true). EOL; +// $debug_text .= quoted_printable_encode(print_r($r, true). EOL); + elseif($this->debug == 3) + echo print_r($r, true) . EOL ; +// echo quoted_printable_encode(print_r($r, true) . EOL) ; + + return($r); + } + + public function dbg($dbg) { + $this->debug = $dbg; + } + + public function escape($str) { + return @$this->db->real_escape_string($str); + } + + function __destruct() { + @$this->db->close(); + } +}} + +// Procedural functions +if(! function_exists('dbg')) { +function dbg($state) { + global $db; + $db->dbg($state); +}} + +if(! function_exists('dbesc')) { +function dbesc($str) { + global $db; + return($db->escape($str)); +}} + + +// Function: q($sql,$args); +// Description: execute SQL query with printf style args. +// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d", +// 'user', 1); + +if(! function_exists('q')) { +function q($sql) { + + global $db; + $args = func_get_args(); + unset($args[0]); + $ret = $db->q(vsprintf($sql,$args)); + return $ret; +}} + + +// Caller is responsible for ensuring that any integer arguments to +// dbesc_array are actually integers and not malformed strings containing +// SQL injection vectors. All integer array elements should be specifically +// cast to int to avoid trouble. + + +if(! function_exists('dbesc_array_cb')) { +function dbesc_array_cb(&$item, $key) { + if(is_string($item)) + $item = dbesc($item); +}} + + +if(! function_exists('dbesc_array')) { +function dbesc_array(&$a) { + if(is_array($a) && count($a)) { + array_walk($a,'dbesc_array_cb'); + } +}} \ No newline at end of file diff --git a/include/login.php b/include/login.php new file mode 100644 index 000000000..b11ee1719 --- /dev/null +++ b/include/login.php @@ -0,0 +1,19 @@ + +
    + + + + + +
    diff --git a/include/security.php b/include/security.php new file mode 100644 index 000000000..8b3452534 --- /dev/null +++ b/include/security.php @@ -0,0 +1,17 @@ + +System Unavailable + +Apologies but this site is unavailable at the moment. Please try again later. + + \ No newline at end of file -- cgit v1.2.3