Initial checkin
This commit is contained in:
commit
6348e70daa
393 changed files with 59765 additions and 0 deletions
171
include/Photo.php
Normal file
171
include/Photo.php
Normal file
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
if(! class_exists("Photo")) {
|
||||
class Photo {
|
||||
|
||||
private $image;
|
||||
private $width;
|
||||
private $height;
|
||||
|
||||
public function __construct($data) {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
80
include/Scrape.php
Normal file
80
include/Scrape.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
require_once('library/HTML5/Parser.php');
|
||||
|
||||
if(! function_exists('attribute_contains')) {
|
||||
function attribute_contains($attr,$s) {
|
||||
$a = explode(' ', $attr);
|
||||
if(count($a) && in_array($s,$a))
|
||||
return true;
|
||||
return false;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('scrape_dfrn')) {
|
||||
function scrape_dfrn($url) {
|
||||
|
||||
$ret = array();
|
||||
$s = fetch_url($url);
|
||||
|
||||
if(! $s)
|
||||
return $ret;
|
||||
|
||||
$dom = HTML5_Parser::parse($s);
|
||||
|
||||
if(! $dom)
|
||||
return $ret;
|
||||
|
||||
$items = $dom->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;
|
||||
}}
|
||||
|
||||
|
||||
|
105
include/bbcode.php
Normal file
105
include/bbcode.php
Normal file
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
//BBcode 2 HTML was written by WAY2WEB.net
|
||||
|
||||
function bbcode($Text)
|
||||
{
|
||||
// Replace any html brackets with HTML Entities to prevent executing HTML or script
|
||||
// Don't use strip_tags here because it breaks [url] search by replacing & with amp
|
||||
$Text = str_replace("<", "<", $Text);
|
||||
$Text = str_replace(">", ">", $Text);
|
||||
|
||||
// Convert new line chars to html <br /> 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\]/", '<a href="$1" target="_blank">$1</a>', $Text);
|
||||
$Text = preg_replace("(\[url\=([$URLSearchString]*)\](.+?)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||
//$Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||
|
||||
// Perform MAIL Search
|
||||
$Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $Text);
|
||||
$Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);
|
||||
|
||||
// Check for bold text
|
||||
$Text = preg_replace("(\[b\](.+?)\[\/b])is",'<strong>$1</strong>',$Text);
|
||||
|
||||
// Check for Italics text
|
||||
$Text = preg_replace("(\[i\](.+?)\[\/i\])is",'<em>$1</em>',$Text);
|
||||
|
||||
// Check for Underline text
|
||||
$Text = preg_replace("(\[u\](.+?)\[\/u\])is",'<u>$1</u>',$Text);
|
||||
|
||||
// Check for strike-through text
|
||||
$Text = preg_replace("(\[s\](.+?)\[\/s\])is",'<strike>$1</strike>',$Text);
|
||||
|
||||
// Check for over-line text
|
||||
$Text = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);
|
||||
|
||||
// Check for colored text
|
||||
$Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);
|
||||
|
||||
// Check for sized text
|
||||
$Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$Text);
|
||||
|
||||
// Check for list text
|
||||
$Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
|
||||
$Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$Text);
|
||||
$Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s",'<ul class="listlowerroman">$1</ul>' ,$Text);
|
||||
$Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$Text);
|
||||
$Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$Text);
|
||||
$Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$Text);
|
||||
$Text = str_replace("[*]", "<li>", $Text);
|
||||
|
||||
// Check for font change text
|
||||
$Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text);
|
||||
|
||||
// Declare the format for [code] layout
|
||||
$CodeLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td class="quotecodeheader"> Code:</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="codebody">$1</td>
|
||||
</tr>
|
||||
</table>';
|
||||
// Check for [code] text
|
||||
$Text = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $Text);
|
||||
// Declare the format for [php] layout
|
||||
$phpLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td class="quotecodeheader"> Code:</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="codebody">$1</td>
|
||||
</tr>
|
||||
</table>';
|
||||
// Check for [php] text
|
||||
$Text = preg_replace("/\[php\](.+?)\[\/php\]/is",$phpLayout, $Text);
|
||||
|
||||
// Declare the format for [quote] layout
|
||||
$QuoteLayout = '<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td class="quotecodeheader"> Quote:</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="quotebody">$1</td>
|
||||
</tr>
|
||||
</table>';
|
||||
|
||||
// Check for [quote] text
|
||||
$Text = preg_replace("/\[quote\](.+?)\[\/quote\]/is","$QuoteLayout", $Text);
|
||||
|
||||
// Images
|
||||
// [img]pathtoimage[/img]
|
||||
$Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);
|
||||
|
||||
// [img=widthxheight]image source[/img]
|
||||
$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);
|
||||
|
||||
return $Text;
|
||||
}
|
145
include/datetime.php
Normal file
145
include/datetime.php
Normal file
|
@ -0,0 +1,145 @@
|
|||
<?php
|
||||
|
||||
if(! function_exists('timezone_cmp')) {
|
||||
function timezone_cmp($a, $b) {
|
||||
if(strstr($a,'/') && strstr($b,'/')) {
|
||||
if ($a == $b) return 0;
|
||||
return ($a < $b) ? -1 : 1;
|
||||
}
|
||||
if(strstr($a,'/')) return -1;
|
||||
if(strstr($b,'/')) return 1;
|
||||
if ($a == $b) return 0;
|
||||
return ($a < $b) ? -1 : 1;
|
||||
}}
|
||||
|
||||
|
||||
if(! function_exists('select_timezone')) {
|
||||
function select_timezone($current = 'America/Los_Angeles') {
|
||||
|
||||
$timezone_identifiers = DateTimeZone::listIdentifiers();
|
||||
|
||||
$o ='<select id="timezone_select" name="timezone">';
|
||||
|
||||
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 .= '</optgroup>';
|
||||
$continent = $ex[0];
|
||||
$o .= "<optgroup label=\"$continent\">";
|
||||
}
|
||||
if(count($ex) > 2)
|
||||
$city = substr($value,strpos($value,'/')+1);
|
||||
else
|
||||
$city = $ex[1];
|
||||
}
|
||||
else {
|
||||
$city = $ex[0];
|
||||
if($continent != 'Miscellaneous') {
|
||||
$o .= '</optgroup>';
|
||||
$continent = 'Miscellaneous';
|
||||
$o .= "<optgroup label=\"$continent\">";
|
||||
}
|
||||
}
|
||||
$city = str_replace('_', ' ', $city);
|
||||
$selected = (($value == $current) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$value\" $selected >$city</option>";
|
||||
}
|
||||
$o .= '</optgroup></select>';
|
||||
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 .= "<select name=\"{$pre}year\" class=\"{$pre}year\" size=\"1\">";
|
||||
if($allow_blank) {
|
||||
$sel = (($y == '') ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"\" $sel></option>";
|
||||
}
|
||||
|
||||
for($x = $ymin; $x <= $ymax; $x ++) {
|
||||
$sel = (($x == $y) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$x\" $sel>$x</option>";
|
||||
}
|
||||
|
||||
$o .= "</select>-<select name=\"{$pre}month\" class=\"{$pre}month\" size=\"1\">";
|
||||
for($x = 1; $x <= 12; $x ++) {
|
||||
$sel = (($x == $m) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$x\" $sel>$x</option>";
|
||||
}
|
||||
|
||||
$o .= "</select>-<select name=\"{$pre}day\" class=\"{$pre}day\" size=\"1\">";
|
||||
for($x = 1; $x <= 31; $x ++) {
|
||||
$sel = (($x == $d) ? " selected=\"selected\" " : "");
|
||||
$o .= "<option value=\"$x\" $sel>$x</option>";
|
||||
}
|
||||
|
||||
$o .= "</select>";
|
||||
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';
|
||||
}
|
138
include/dba.php
Normal file
138
include/dba.php
Normal file
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
// MySQL database class
|
||||
//
|
||||
// For debugging, insert 'dbg(x);' anywhere in the program flow.
|
||||
// x = 1: display db success/failure following content
|
||||
// x = 2: display full queries following content
|
||||
// x = 3: display full queries using echo; which will mess up display
|
||||
// really bad but will return output in stubborn cases.
|
||||
|
||||
if(! class_exists('dba')) {
|
||||
class dba {
|
||||
|
||||
private $debug = 0;
|
||||
private $db;
|
||||
|
||||
function __construct($server,$user,$pass,$db,$install = false) {
|
||||
$this->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');
|
||||
}
|
||||
}}
|
19
include/login.php
Normal file
19
include/login.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
|
||||
<form action="process-login" method="post" >
|
||||
<div class="login-name-wrapper">
|
||||
<label for="login-name" id="label-login-name">Email address: </label>
|
||||
<input type="text" maxlength="60" name="login-name" id="login-name" value="" />
|
||||
</div>
|
||||
<div class="login-password-wrapper">
|
||||
<label for="login-password" id="label-login-password">Password: </label>
|
||||
<input type="password" maxlength="60" name="password" id="password" value="" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="login-extra-links">
|
||||
<?php if($register) { ?>
|
||||
<a href="register" name="Register" id="register" >Register</a>
|
||||
<?php } ?>
|
||||
<a href="lost-password" name="Lost your password?" id="lost-password">Password Reset</a>
|
||||
</div>
|
||||
<input type="submit" name="submit" id="login-submit" value="Login" />
|
||||
</form>
|
17
include/security.php
Normal file
17
include/security.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
function can_write_wall(&$a,$owner) {
|
||||
if((! (local_user())) && (! (remote_user())))
|
||||
return false;
|
||||
if((local_user()) && ($_SESSION['uid'] == $owner))
|
||||
return true;
|
||||
|
||||
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `id` = %d AND `blocked` = 0",
|
||||
intval($owner),
|
||||
intval($_SESSION['visitor_id'])
|
||||
);
|
||||
if(count($r))
|
||||
return true;
|
||||
return false;
|
||||
|
||||
}
|
76
include/session.php
Normal file
76
include/session.php
Normal file
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
|
||||
// Session management functions. These provide database storage of PHP
|
||||
// session info.
|
||||
|
||||
$session_exists = 0;
|
||||
$session_expire = 180000;
|
||||
|
||||
if(! function_exists('ref_session_open')) {
|
||||
function ref_session_open ($s,$n) {
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_read')) {
|
||||
function ref_session_read ($id) {
|
||||
global $session_exists;
|
||||
if(x($id))
|
||||
$r = q("SELECT `data` FROM `session` WHERE `sid`= '%s'", dbesc($id));
|
||||
if(count($r)) {
|
||||
$session_exists = true;
|
||||
return $r[0]['data'];
|
||||
}
|
||||
return '';
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_write')) {
|
||||
function ref_session_write ($id,$data) {
|
||||
global $session_exists, $session_expire;
|
||||
if(! $id || ! $data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$expire = time() + $session_expire;
|
||||
$default_expire = time() + 300;
|
||||
|
||||
if($session_exists)
|
||||
$r = q("UPDATE `session`
|
||||
SET `data` = '%s', `expire` = '%s'
|
||||
WHERE `sid` = '%s' LIMIT 1",
|
||||
dbesc($data), dbesc($expire), dbesc($id));
|
||||
else
|
||||
$r = q("INSERT INTO `session`
|
||||
SET `sid` = '%s', `expire` = '%s', `data` = '%s'",
|
||||
dbesc($id), dbesc($default_expire), dbesc($data));
|
||||
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_close')) {
|
||||
function ref_session_close() {
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_destroy')) {
|
||||
function ref_session_destroy ($id) {
|
||||
q("DELETE FROM `session` WHERE `sid` = '%s'", dbesc($id));
|
||||
return true;
|
||||
}}
|
||||
|
||||
if(! function_exists('ref_session_gc')) {
|
||||
function ref_session_gc($expire) {
|
||||
q("DELETE FROM `session` WHERE `expire` < %d", dbesc(time()));
|
||||
q("OPTIMIZE TABLE `sess_data`");
|
||||
return true;
|
||||
}}
|
||||
|
||||
$gc_probability = 50;
|
||||
|
||||
ini_set('session.gc_probability', $gc_probability);
|
||||
ini_set('session.use_only_cookies', 1);
|
||||
ini_set('session.cookie_httponly', 1);
|
||||
|
||||
|
||||
session_set_save_handler ('ref_session_open', 'ref_session_close',
|
||||
'ref_session_read', 'ref_session_write',
|
||||
'ref_session_destroy', 'ref_session_gc');
|
6
include/system_unavailable.php
Normal file
6
include/system_unavailable.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<html>
|
||||
<head><title>System Unavailable</title></head>
|
||||
<body>
|
||||
Apologies but this site is unavailable at the moment. Please try again later.
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue