From 80eb67552391cb8fcd65cf95461455e61b34d045 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Mon, 12 May 2014 20:32:48 +0800 Subject: [PATCH 1/6] Replaced config.php require with a require_once based on the current directory of func.php. Removed some whitespace and trailing spaces. Fixed up some define() calls that were showing warnings. --- php/func.php | 1137 ++++++++++++++++++++++++-------------------------- 1 file changed, 545 insertions(+), 592 deletions(-) diff --git a/php/func.php b/php/func.php index f2acfc5..697e374 100644 --- a/php/func.php +++ b/php/func.php @@ -1,41 +1,24 @@ \n"; - function array2xml($array, $root = 'root', $element = 'element') { + function array2xml($array, $root = 'root', $element = 'element') { $this->output .= $this->make($array, $root, $element); } function make($array, $root, $element) { @@ -51,16 +34,16 @@ function make($array, $root, $element) { } } } - $xml .= "\n"; + $xml .= "\n"; return $xml; } } -function groupInviteHash($iid,$email,$groupid) +function groupInviteHash($iid, $email, $groupid) { global $dbSalt; - + return md5($iid.$email.$groupid.$dbSalt); } @@ -68,13 +51,13 @@ function groupInviteHash($iid,$email,$groupid) function connect() { global $link; - + $link = @mysql_connect (CONFIG_DB_HOSTNAME, CONFIG_DB_USER, CONFIG_DB_PASSWORD); - + if (!$link) die("Unable to connect to database, please come back later"); - - + + return $link; } @@ -84,44 +67,44 @@ function disconnect() @mysql_close($link); } -function mysql_escape_mimic($inp) { - if(is_array($inp)) - return array_map(__METHOD__, $inp); +function mysql_escape_mimic($inp) { + if(is_array($inp)) + return array_map(__METHOD__, $inp); - if(!empty($inp) && is_string($inp)) { - return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp); - } + if(!empty($inp) && is_string($inp)) { + return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp); + } - return $inp; -} + return $inp; +} -function sqlVar($value,$like=false) +function sqlVar($value, $like=false) { - if (get_magic_quotes_gpc()) + if (get_magic_quotes_gpc()) $value = stripslashes($value); - - if (!is_numeric($value)) + + if (!is_numeric($value)) { if ($like) $value = "'%" . mysql_escape_mimic($value) . "%'"; else $value = "'" . mysql_escape_mimic($value) . "'"; } - - + + return $value; } -function sql($query,$db=false) +function sql($query, $db=false) { global $link; - + if (!$db) $db = CONFIG_DB_NAME; - + if (!$link) die("Sorry, please come back in a bit"); - + return @mysql_db_query($db,$query); } @@ -157,7 +140,7 @@ function findUserByName($name) return sqlObject("SELECT * FROM users WHERE verified>=1 AND name=".sqlVar($name)); } -function findUserByEmail($email,$verified=1) +function findUserByEmail($email, $verified=1) { return sqlObject("SELECT * FROM users WHERE verified>=$verified AND email=".sqlVar($email)); } @@ -178,21 +161,21 @@ function plural($num, $str) function timeDiff($dt) { //global $lang; - + $diff = time() - $dt; - + $out=""; - + if ($diff <= (60*60*24)) $out .= ''; - + $secs = round($diff); $mins = round($secs/60); $hours = round($mins/60); $days = round($hours/24); $months = round($days/30); $years = round($days/365); - + if ($secs < 60) $out .= "just now"; @@ -200,10 +183,10 @@ function timeDiff($dt) $out .= $mins." ".plural($mins,'min').' ago'; else if ($hours < 24) $out .= $hours." ".plural($hours,'hr').' ago'; - else - + else + { - if (date("Y",$dt) == date("Y")) + if (date("Y",$dt) == date("Y")) $out .= date("j M",$dt); else $out .= date("j M",$dt)." ".date("Y",$dt); @@ -213,7 +196,7 @@ function timeDiff($dt) $out .= ''; return $out; - + } function timeFormat($dt) @@ -221,20 +204,20 @@ function timeFormat($dt) global $lang; $lt = localtime($dt,true); - + $r = ""; $r .= ($lt['tm_year']+1900); $r .= "/".($lt['tm_mon']+1); $r .= "/".($lt['tm_mday']+1); $wd = mb_substr($lang['dayname'],$lt['tm_wday'],1,"UTF-8"); - - $r .= " ($wd) "; + + $r .= " ($wd) "; $r .= sprintf("%02d",$lt['tm_hour']).":".sprintf("%02d",$lt['tm_min']); - + return $r; - + } function defraction( $fraction ) @@ -262,25 +245,25 @@ function exifGPS($exif) { $northing = 1; } - + $northing *= defraction( $exif['GPSLatitude'][0] ) + ( defraction($exif['GPSLatitude'][1] ) / 60 ) + ( defraction( $exif['GPSLatitude'][2] ) / 3600 ); $loc->lat = $northing; - + // Longitude $easting = -1; if( $exif['GPSLongitudeRef'] && 'E' == $exif['GPSLongitudeRef'] ) { $easting = 1; } - - $easting *= defraction( $exif['GPSLongitude'][0] ) + ( defraction( $exif['GPSLongitude'][1] ) / 60 ) + ( defraction( $exif['GPSLongitude'][2] ) / 3600 ); + + $easting *= defraction( $exif['GPSLongitude'][0] ) + ( defraction( $exif['GPSLongitude'][1] ) / 60 ) + ( defraction( $exif['GPSLongitude'][2] ) / 3600 ); $loc->lng = $easting; - return $loc; - } - + return $loc; + } + return false; - + } @@ -288,7 +271,7 @@ function exifGPS($exif) function GPStoCity($lng,$lat) { // return sqlObject("SELECT *,(((lng - $lng)*(lng - $lng)) + ((lat - $lat)*(lat - $lat))) AS dist FROM cities ORDER BY dist ASC LIMIT 1"); - + $eq = "ACOS(SIN(RADIANS(lat))*SIN(RADIANS($lat))+COS(RADIANS(lat))*COS(RADIANS($lat))*COS(RADIANS($lng-lng)))*6371"; return sqlObject("SELECT *,$eq AS dist FROM cities ORDER BY dist ASC LIMIT 1"); @@ -296,11 +279,11 @@ function GPStoCity($lng,$lat) } function getTypeImage($type,$local) { - if ($type == "pdf") + if ($type == "pdf") return ''; - else if ($type == "archive") + else if ($type == "archive") return ''; - else if ($type == "audio") + else if ($type == "audio") return ''; else if ($type == "html") return ''; @@ -314,45 +297,45 @@ function getTypeImage($type,$local) return ''; else if ($type == "maya") return ''; - else if ($local) + else if ($local) return ''; else return ''; - + } function getURLs($str) { // $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; //$reg_exUrl = "/(http)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; - + // preg_match($reg_exUrl, $str, $urls); preg_match_all('!https?://[\S]+!', $str, $matches); $urls = $matches[0]; - + $urls = array_unique($urls); - + return $urls; } function canAccessMessage($id,$user) { $msg = getMessage($id,$user); - + if ($msg) { if ($user) if (getMember($msg,$user)) return $msg; - + $rmsg = getMessage($msg->root,$user); if (($rmsg && $rmsg->public) || $msg->public) return $msg; - } + } - return null; + return null; } @@ -369,53 +352,53 @@ function getMessage($id,$user=false) $q .= ",assusers.avatar AS assver"; $q .= ",viausers.id AS viaid"; $q .= ",viausers.name AS vianame"; - + if ($user) { $q .= ",members.user AS memberid"; $q .= ",followers.user AS followerid"; } - + $q .= ",messages.root AS rid"; $q .= ",(SELECT plain FROM messages WHERE id=rid) AS rootname"; $q .= ",messages.gparent AS pid"; $q .= ",(SELECT plain FROM messages WHERE id=pid) AS parentname"; - - - $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=0) AS numchildren_pending"; - $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=1) AS numchildren_active"; - $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=2) AS numchildren_done"; - + + + $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=0) AS numchildren_pending"; + $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=1) AS numchildren_active"; + $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=2) AS numchildren_done"; + $q .= ",(SELECT COUNT(*) FROM comments WHERE gparent=gid ) AS numcomments"; $q .= ",(SELECT comments.time FROM comments WHERE gparent=gid ORDER BY comments.time DESC LIMIT 1) AS lastcomment"; - + $q .= " FROM messages"; $q .= " LEFT JOIN users ON users.id=messages.sender"; $q .= " LEFT JOIN users assusers ON assusers.id=messages.assigned"; - $q .= " LEFT JOIN users viausers ON viausers.id=messages.sender"; - + $q .= " LEFT JOIN users viausers ON viausers.id=messages.sender"; + if ($user) { - $q .= " LEFT JOIN members ON members.user=$user->id AND (members.message=messages.id OR members.message=messages.root)"; - $q .= " LEFT JOIN followers ON followers.user=$user->id AND (followers.message=messages.id)"; + $q .= " LEFT JOIN members ON members.user=$user->id AND (members.message=messages.id OR members.message=messages.root)"; + $q .= " LEFT JOIN followers ON followers.user=$user->id AND (followers.message=messages.id)"; } - + $q .= " WHERE users.id>0"; - + $q .= " AND messages.id=".sqlVar($id); - + return sqlObject($q); } - + function findMessages($from,$show,$find,$state,$pmsg,$user,$isFlat=false,$numCols=3) { $q = "SELECT "; - + if (!$from) - $q .= " SQL_CALC_FOUND_ROWS "; + $q .= " SQL_CALC_FOUND_ROWS "; $q .= " messages.*"; $q .= ",users.name AS username"; $q .= ",messages.msgid AS mid"; @@ -431,7 +414,7 @@ function findMessages($from,$show,$find,$state,$pmsg,$user,$isFlat=false,$numCol $q .= ",members.user AS memberid"; $q .= ",followers.user AS followerid"; } - + if (!$pmsg && $isFlat) { $q .= ",messages.root AS rid"; @@ -441,65 +424,65 @@ function findMessages($from,$show,$find,$state,$pmsg,$user,$isFlat=false,$numCol $q .= ",messages.gparent AS pid"; $q .= ",(SELECT plain FROM messages WHERE id=pid) AS parentname"; } - - - - $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=0 AND !deleted) AS numchildren_pending"; - $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=1 AND !deleted) AS numchildren_active"; - $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=2 AND !deleted) AS numchildren_done"; - + + + + $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=0 AND !deleted) AS numchildren_pending"; + $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=1 AND !deleted) AS numchildren_active"; + $q .= ",(SELECT COUNT(*) FROM messages WHERE gparent=gid AND state=2 AND !deleted) AS numchildren_done"; + $q .= ",(SELECT COUNT(*) FROM comments WHERE gparent=gid ) AS numcomments"; $q .= ",(SELECT comments.time FROM comments WHERE gparent=gid ORDER BY comments.time DESC LIMIT 1) AS lastcomment"; - + $q .= " FROM children"; $q .= " LEFT JOIN messages ON messages.id = children.cmessage"; - + $q .= " LEFT JOIN users ON users.id=messages.sender"; $q .= " LEFT JOIN users assusers ON assusers.id=messages.assigned"; - $q .= " LEFT JOIN users viausers ON viausers.id=messages.sender"; + $q .= " LEFT JOIN users viausers ON viausers.id=messages.sender"; // $q .= " LEFT JOIN marked ON marked.message=messages.msgid AND marked.user=$user->id"; if ($user) { - $q .= " LEFT JOIN members ON members.user=$user->id AND (members.message=messages.id OR members.message=messages.root)"; - $q .= " LEFT JOIN followers ON followers.user=$user->id AND (followers.message=messages.id)"; + $q .= " LEFT JOIN members ON members.user=$user->id AND (members.message=messages.id OR members.message=messages.root)"; + $q .= " LEFT JOIN followers ON followers.user=$user->id AND (followers.message=messages.id)"; } - + $q .= " WHERE "; - + $q .= " !messages.deleted"; - - if ($numCols==3 || ($state&8)) + + if ($numCols==3 || ($state&8)) { if ($state & 8) $q .= " AND (1< 100) $show = 100; - + $q .= " GROUP BY messages.id"; - + if ($isFlat) $q .= " ORDER BY messages.id DESC"; else $q .= " ORDER BY messages.ordering DESC"; - + $q .= " LIMIT ".sqlVar($show); - + if ($from) - $q .= " OFFSET ".sqlVar($from); - - + $q .= " OFFSET ".sqlVar($from); + + $messages = sqlArray($q); - - + + $out = ""; - - - + + + $ostate = $numCols==1 ? 3 : $state; - - + + //if (count($messages)) - { - - $out .= '
'; - + { + + $out .= '
'; + if ($isDebug) - { + { $out .= '
'.$q.'
'; } - + foreach ($messages as $m) - { + { $out .= outputMessage($m,$user,null,true,$pmsg->id,$isFlat,$numCols); } - - + + $out .= '
'; - + if ($from==0) { $r = sqlObject("SELECT FOUND_ROWS() AS total"); - + $out .= ''; } } - - - - return $out; + + + + return $out; } @@ -654,33 +637,33 @@ function findMessages($from,$show,$find,$state,$pmsg,$user,$isFlat=false,$numCol function outputMessage($m,$u,$member,$wrapdiv,$parent,$isFlat=0,$numCols=3) { - -/* + +/* $canEdit = ($m->viaid == $u->id) || ($m->assid == $u->id) || ($m->assid==ANYBODY_ID); if (!$canEdit) $attr = 'nomove="1"'; */ - - - if ($wrapdiv) + + + if ($wrapdiv) { - $out .= '
'; -// $out .= '
'; + $out .= '
'; +// $out .= '
'; } - - + + $baseURL = "/?"; if ($isFlat) $baseURL .= "f=1&"; - + if ($numCols!=3) $baseURL .= "c=1&"; - - $baseURLnoP = $baseURL; - + + $baseURLnoP = $baseURL; + if ($parent) $baseURL .= "p=".$parent."&"; @@ -688,26 +671,26 @@ function outputMessage($m,$u,$member,$wrapdiv,$parent,$isFlat=0,$numCols=3) $out .= '
'; - + if ($numCols==1) { $out .= '
'; $out .= '
'; $out .= '
'; - $out .= '
'; + $out .= '
'; $out .= '
'; } - - - + + + $out .= ''; $out .= '
'; $out .= '
'.$m->assname.'
'; $out .= '
'; - + if ($m->root) $out .= '
'.$m->msgid.'
'; - + $out .= '
'; @@ -717,29 +700,29 @@ function outputMessage($m,$u,$member,$wrapdiv,$parent,$isFlat=0,$numCols=3) $numchildren = $m->numchildren_pending + $m->numchildren_active + $m->numchildren_done; $out .= '
'; - + $out .= '
'; $out .= '
'; - - + + $out .= timeDiff($m->idate); if (!$parent && $isFlat) $out .= ' in '.messageTitle($m->rootname).''; else if ($isFlat && $m->gparent!=$parent) $out .= ' in '.messageTitle($m->parentname).''; - + if ($m->viaid != $m->assid) - $out .= ' via '.$m->vianame.''; + $out .= ' via '.$m->vianame.''; if ($m->public) - $out .= ' '; + $out .= ' '; + - $out .= '
'; // num - + $out .= '
'; @@ -751,25 +734,25 @@ function outputMessage($m,$u,$member,$wrapdiv,$parent,$isFlat=0,$numCols=3) if ($numchildren) { $out .= '
'; - $out .= writeBars($m->numchildren_pending,$m->numchildren_active,$m->numchildren_done,$baseURLnoP."p=$m->gid",true); - $out .= '
'; + $out .= writeBars($m->numchildren_pending,$m->numchildren_active,$m->numchildren_done,$baseURLnoP."p=$m->gid",true); + $out .= '
'; } - - - - + + + + if (!$m->root && $m->sender!=$u->id) $out .= ' Remove'; else if ($m->sender == $u->id || $m->assigned == $u->id) $out .= ' Delete'; - - + + if ($m->sender != $u->id && $m->assigned != $u->id) $out .= ' View'; else $out .= ' Edit'; - - + + if (!$numchildren) { $out .= ' Open'; @@ -777,36 +760,36 @@ function outputMessage($m,$u,$member,$wrapdiv,$parent,$isFlat=0,$numCols=3) $out .= '
'; // icons - + $out .= '
'; $out .= '
'; // overlay - - - - - + + + + + $out .= '
'; // topinfo $out .= '
'; $out .= nl2br(makeClickableLinks(htmlspecialchars($m->plain))); - $out .= '
'; - + $out .= '
'; + + + + - - - $out .= '
'; - - + + $out .= '
'; $out .= '
'; $out .= '
'; if ($m->numcomments) { - + $age = time() - $m->lastcomment; $out .= '
'; @@ -822,10 +805,10 @@ function outputMessage($m,$u,$member,$wrapdiv,$parent,$isFlat=0,$numCols=3) $out .= ' no comments'; $out .= '
'; } - + if ($wrapdiv) $out .= "
"; - + return $out; } @@ -851,36 +834,36 @@ function messageTitle($str,$maxlen=15) $text = $line[0]; if ($text=="") - $text = $str; + $text = $str; $out = ""; - + $cut = mb_strcut($text,0,$maxlen,"UTF-8"); - + $out .= htmlspecialchars($cut); - + if ($cut!=$text) $out .= "…"; - - + + return $out; } function writeBars($nump,$numa,$numd,$url,$info) -{ +{ $height = 20; $norm = max($nump,$numa,min($height,$numd)); if ($norm==0) $norm = 1; - + $hp = min($height,round(($nump*$height)/$norm)); $ha = min($height,round(($numa*$height)/$norm)); $hd = min($height,round(($numd*$height)/$norm)); - + @@ -900,10 +883,10 @@ function writeBars($nump,$numa,$numd,$url,$info) $out .= '
'.$nump.' pending
'; $out .= '
'.$numa.' active
'; $out .= '
'.$numd.' done
'; - $out .= '
'; + $out .= ''; } $out .= ' '; - + return $out; } @@ -913,19 +896,19 @@ function getMember($msg,$user) $member = sqlObject("SELECT * FROM members WHERE user=$user->id AND message=$msg->root"); else $member = sqlObject("SELECT * FROM members WHERE user=$user->id AND message=$msg->id"); - + return $member; - + } function checkAccess($id,$user) { $pmsg = getMessage($id); - + if (!getMember($id,$user)) die(); - + } @@ -934,40 +917,40 @@ function writeTopMenu($user,$login=false,$tag=false,$search=false,$location=fals $out = ''; $out .= '
'; - - + + $topmsg = $pmsg; $debug = $user->id==1 || $user->id==3 || $user->id==4; - - + + $baseURL = '/?'; if ($numCols==1) $baseURL .= 'c=1&'; - - $homeURL = $baseURL; - + + $homeURL = $baseURL; + if ($isFlat) $baseURL .= 'f=1&'; - - + + $out .= '
'; - - - $out .= ''; + + + $out .= ''; $out .= ''; $out .= ''; - + $p = ""; - - $cnt=0; + + $cnt=0; while ($topmsg && $cnt<3) { -/* +/* if ($cnt==0) $t = '
  • '; else @@ -975,83 +958,83 @@ function writeTopMenu($user,$login=false,$tag=false,$search=false,$location=fals $t = '
  • '; $t .= ''; } - -*/ + +*/ $t = ''; - - $t .= ''; - - + + $t .= ''; + + $mc = ""; $mc .= '
    '; $mc .= '

    '; $mc .= (nl2br(htmlspecialchars($topmsg->plain))); $mv .= '

    '; - - + + // $mc = outputMessage($topmsg,$user,$member,true,$parent); - $t .= '
    '.$mc.'
    '; - + $t .= '
    '.$mc.'
    '; + // if ($topmsg->assid) // $t .= ''; - + $t .= messageTitle($topmsg->plain,30); //$t .= ''; $t .= '
    '; $p = $t.$p; - + if ($topmsg->last) break; - - - $cnt++; - - $topmsg = getMessage($topmsg->gparent); - - - + + + $cnt++; + + $topmsg = getMessage($topmsg->gparent); + + + }; - + $out .= $p; - - + + if ($search && $numCols==3) { $out .= ''; } - - - $out .= '
  • '; - + + + $out .= '
    '; + $out .= '
    '; - + if ($user) - { + { $baseURL = '/?f=1&'; - + if ($user->latest_notice) { $q = "SELECT COUNT(*) AS total FROM children"; - $q .= " LEFT JOIN members ON members.user=$user->id"; - $q .= " LEFT JOIN messages ON messages.id=children.cmessage"; + $q .= " LEFT JOIN members ON members.user=$user->id"; + $q .= " LEFT JOIN messages ON messages.id=children.cmessage"; $q .= " WHERE "; $q .= " messages.assigned=".NOTICE_ID; $q .= " AND messages.id>$user->latest_notice"; $q .= " AND (children.cmessage=members.message OR children.pmessage=members.message)"; - + //if ($user->id==1) // die($q); - + $r = sqlObject($q); if ($r->total) { @@ -1062,13 +1045,13 @@ function writeTopMenu($user,$login=false,$tag=false,$search=false,$location=fals $out .= ''; $out .= '
    '; } - + }else{ - + sql("UPDATE users SET latest_notice=(SELECT id FROM messages ORDER BY id DESC LIMIT 1) WHERE id=$user->id"); - - } - + + } + } @@ -1078,7 +1061,7 @@ function writeTopMenu($user,$login=false,$tag=false,$search=false,$location=fals $out .= '
  • Tree
  • '; $out .= '
  • All
  • '; $out .= ''; - + //if ($user->id==1) { $out .= ''; } - - -// •● - + + +// •● + } - - - + + + if ($search) { - - - $out .= ''; - } - - + } + + if ($user) - { - + { + $baseURL = '/?'; if ($isFlat) @@ -1117,65 +1100,65 @@ function writeTopMenu($user,$login=false,$tag=false,$search=false,$location=fals $baseURL .= 'p='.$parent.'&'; $out .= '
    '; - $out .= ''; - - $out .= '
    '; - + $out .= '
    '; + + $out .= '
    '; + $out .= '
    '; - $out .= '
      '; + $out .= '
        '; $out .= '
      • '.$user->name.' ▲

      • '; $out .= '
        '; $out .= '
      • Assigned To Me
      • '; $out .= '
      • Home
      • '; - + $out .= '
        '; //$out .= '
      • Notices
      • '; - - + + $out .= '
      • Settings
      • '; - - $out .= '
      • Logout
      • '; - + + $out .= '
      • Logout
      • '; + if (CONFIG_FEEDBACK_SCRIPT) { $out .= '
        '; $out .= '
      • Feedback
      • '; $out .= '
      • Take Survey
      • '; - } - - - - + } + + + + if ($user->id==ADMIN_ID) { $out .= '
        '; - $out .= '
      • Stats
      • '; + $out .= '
      • Stats
      • '; } - - + + $out .= '
      '; $out .= '
    '; - + }else { $out .= ''; } - - + + $out .= ''; - - - - + + + + $out .= ''; - + echo $out; } @@ -1188,7 +1171,7 @@ function rstrpos($haystack,$needle,$offset=NULL) } -function safeFileName($filename) +function safeFileName($filename) { $filename = strtolower($filename); $filename = str_replace("#","_",$filename); @@ -1206,14 +1189,14 @@ function safeFileName($filename) function getLoggedInUser() { $user = sqlObject("SELECT * FROM users WHERE id=".sqlVar($_SESSION['userid'])); - + return $user; } function getTwitterUser($id) { $user = sqlObject("SELECT * FROM users WHERE twitter_id=".sqlVar($id)); - + return $user; } @@ -1244,12 +1227,12 @@ function createUser($email="",$pwdkey="",$name="",$fullname="") $q .= ",0"; // root $q .= ",0"; // ordering $q .= ",0"; // latest_notice - - + + $q .= ")"; - + $id = sqlInsert($q); - + if (CONFIG_EXAMPLE_NOTE) sql("INSERT INTO followers VALUES($id,".CONFIG_EXAMPLE_NOTE.")"); @@ -1259,10 +1242,10 @@ function createUser($email="",$pwdkey="",$name="",$fullname="") function verifyAddEmail($addemail,$addnum,$id) { global $dbSalt; - + $key = md5($dbSalt.$id.$addemail); - + /* $msg = "Please click the following link to verify this email address:

    "; @@ -1290,9 +1273,9 @@ function removeLoginCookies() connect(); // $session = sqlObject("UPDATE sessions SET token='' WHERE userid=".sqlVar($userid)." AND token=".sqlVar($token)); $session = sqlObject("UPDATE sessions SET token='' WHERE userid=".sqlVar($userid)); - disconnect(); - - + disconnect(); + + setcookie("userid","",0,"/"); setcookie("token","",0,"/"); } @@ -1305,54 +1288,52 @@ function checkLoginCookies() connect(); $session = sqlObject("SELECT * FROM sessions WHERE userid=".sqlVar($userid)." AND token=".sqlVar($token)); - + if ($session) - { + { $_SESSION['userid'] = $userid; - + $user = getLoggedInUser(); - + $_SESSION['username'] = $user->name; } disconnect(); - + return $user; - - + + } function setLoginCookies($userid) { global $dbSalt; - + $time = time() + (60*60*24*365); - + $token = md5($dbSalt.$time.$userid); setcookie("userid",$userid,$time,"/"); setcookie("token",$token,$time,"/"); - + connect(); sqlInsert("INSERT INTO sessions VALUES(0,UNIX_TIMESTAMP(),".sqlVar($token).",".$userid.",".sqlVar($_SERVER['REMOTE_ADDR']).")"); disconnect(); } - - function getFileType($path) { $path = strtolower($path); - + $ext = substr($path, rstrpos($path, ".")+1); - - if ($ext == 'bmp' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'gif' || $ext == 'tga' || $ext == 'png') + + if ($ext == 'bmp' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'gif' || $ext == 'tga' || $ext == 'png') return "image"; - + if ($ext == 'pdf') return "pdf"; - + if ($ext == 'doc') return "doc"; @@ -1367,57 +1348,49 @@ function getFileType($path) if ($ext == 'exe' || $ext=="sh" ) return "executable"; - + if ($ext == 'txt' || $ext=="text" ) return "text"; - + if ($ext == 'html' || $ext=="htm" ) return "html"; - + if ($ext == 'mp3' || $ext=="mp4" || $ext=="wav") return "audio"; if ($ext == 'mov' || $ext=="avi" || $ext=="mpg" || $ext=="mpeg") return "movie"; - + if ($ext == 'vcf') return "contact"; - return "unknown"; -} - - -function commentHTML($id,$name,$text,$candel,$time=0) -{ - + return "unknown"; +} +function commentHTML($id, $name, $text, $candel, $time=0) +{ $out .= '
    '; $out .= '
    '; - - if ($candel) + + if ($candel) $out .= ' '; - + $out .= $name; if ($time) $out .= ', '.timeDiff($time); $out .= ' wrote:'; $out .= '
    '; - - - $html = htmlspecialchars($text); + $html = htmlspecialchars($text); $html = $text; - - + $urls = getURLs($html); - - - + foreach($urls as $u) { $thumb = CONFIG_DATADIR."/thumbs/".md5($u)."-100.jpg"; - + if (file_exists($thumb)) { $img = ''; @@ -1427,42 +1400,28 @@ function commentHTML($id,$name,$text,$candel,$time=0) $link = ''.$u.''; $html = str_replace($u,$link,$html); } - - } - - //$html .= " #".count($urls); - - //foreach($urls as $u) - // $html .= "$u "; + } $html = nl2br($html); - - - - - $out .= '
    '.$html; -// $out .= '
    '.nl2br(makeClickableLinks(htmlspecialchars($text))); - $out .= '
    '; -/* - if ($candel) - $out .= '
    [ x ]
    '; -*/ + $out .= '
    '.$html; + $out .= '
    '; $out .= '
    '; return $out; -} - - +} + + function isAscii($str) { return mb_check_encoding($str, 'ASCII'); } + function mecab($input) -{ +{ if (isAscii($input)) return $input; - + $order = array("\r\n", "\n", "\r"); $replace = ' '; @@ -1471,11 +1430,11 @@ function mecab($input) $cmd = "echo ".$input." | /opt/local/bin/mecab -O wakati"; $r = exec($cmd,$lines); - + $s = ""; foreach($lines as $l) $s .= $l; - + return $s; } @@ -1491,16 +1450,16 @@ function mb_wordwrap($str, $width, $break) $return .= mb_substr($str, $i, $br_width, 'UTF-8'); $i += $br_width - 1; } - + if ($count > $width) { $return .= $break; $count = 0; } - + $return .= mb_substr($str, $i, 1, 'UTF-8'); } - + return $return; } @@ -1529,183 +1488,180 @@ function utf8_wordwrap($str, $width, $break, $cut = false) { } -function htmlwrap($str, $width = 60, $break = "\n", $nobreak = "") { +function htmlwrap($str, $width = 60, $break = "\n", $nobreak = "") { - // Split HTML content into an array delimited by < and > - // The flags save the delimeters and remove empty variables - $content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + // Split HTML content into an array delimited by < and > + // The flags save the delimeters and remove empty variables + $content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); - // Transform protected element lists into arrays - $nobreak = explode(" ", strtolower($nobreak)); + // Transform protected element lists into arrays + $nobreak = explode(" ", strtolower($nobreak)); - // Variable setup - $intag = false; - $innbk = array(); - $drain = ""; + // Variable setup + $intag = false; + $innbk = array(); + $drain = ""; - // List of characters it is "safe" to insert line-breaks at - // It is not necessary to add < and > as they are automatically implied - $lbrks = "/?!%)-}]\\\"':;&"; + // List of characters it is "safe" to insert line-breaks at + // It is not necessary to add < and > as they are automatically implied + $lbrks = "/?!%)-}]\\\"':;&"; - // Is $str a UTF8 string? - $utf8 = (preg_match("/^([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/", $str)) ? "u" : ""; + // Is $str a UTF8 string? + $utf8 = (preg_match("/^([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/", $str)) ? "u" : ""; - while (list(, $value) = each($content)) { - switch ($value) { + while (list(, $value) = each($content)) { + switch ($value) { - // If a < is encountered, set the "in-tag" flag - case "<": $intag = true; break; + // If a < is encountered, set the "in-tag" flag + case "<": $intag = true; break; - // If a > is encountered, remove the flag - case ">": $intag = false; break; + // If a > is encountered, remove the flag + case ">": $intag = false; break; - default: + default: - // If we are currently within a tag... - if ($intag) { + // If we are currently within a tag... + if ($intag) { - // Create a lowercase copy of this tag's contents - $lvalue = strtolower($value); + // Create a lowercase copy of this tag's contents + $lvalue = strtolower($value); - // If the first character is not a / then this is an opening tag - if ($lvalue{0} != "/") { + // If the first character is not a / then this is an opening tag + if ($lvalue{0} != "/") { - // Collect the tag name - preg_match("/^(\w*?)(\s|$)/", $lvalue, $t); + // Collect the tag name + preg_match("/^(\w*?)(\s|$)/", $lvalue, $t); - // If this is a protected element, activate the associated protection flag - if (in_array($t[1], $nobreak)) array_unshift($innbk, $t[1]); + // If this is a protected element, activate the associated protection flag + if (in_array($t[1], $nobreak)) array_unshift($innbk, $t[1]); - // Otherwise this is a closing tag - } else { + // Otherwise this is a closing tag + } else { - // If this is a closing tag for a protected element, unset the flag - if (in_array(substr($lvalue, 1), $nobreak)) { - reset($innbk); - while (list($key, $tag) = each($innbk)) { - if (substr($lvalue, 1) == $tag) { - unset($innbk[$key]); - break; - } - } - $innbk = array_values($innbk); - } - } + // If this is a closing tag for a protected element, unset the flag + if (in_array(substr($lvalue, 1), $nobreak)) { + reset($innbk); + while (list($key, $tag) = each($innbk)) { + if (substr($lvalue, 1) == $tag) { + unset($innbk[$key]); + break; + } + } + $innbk = array_values($innbk); + } + } - // Else if we're outside any tags... - } else if ($value) { + // Else if we're outside any tags... + } else if ($value) { - // If unprotected... - if (!count($innbk)) { + // If unprotected... + if (!count($innbk)) { - // Use the ACK (006) ASCII symbol to replace all HTML entities temporarily - $value = str_replace("\x06", "", $value); - preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $value, $ents); - $value = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $value); + // Use the ACK (006) ASCII symbol to replace all HTML entities temporarily + $value = str_replace("\x06", "", $value); + preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $value, $ents); + $value = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $value); - // Enter the line-break loop - do { - $store = $value; + // Enter the line-break loop + do { + $store = $value; - // Find the first stretch of characters over the $width limit - if (preg_match("/^(.*?\s)?([^\s]{".$width."})(?!(".preg_quote($break, "/")."|\s))(.*)$/s{$utf8}", $value, $match)) { + // Find the first stretch of characters over the $width limit + if (preg_match("/^(.*?\s)?([^\s]{".$width."})(?!(".preg_quote($break, "/")."|\s))(.*)$/s{$utf8}", $value, $match)) { - if (strlen($match[2])) { - // Determine the last "safe line-break" character within this match - for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x})); - if (!$ledge) $ledge = strlen($match[2]) - 1; + if (strlen($match[2])) { + // Determine the last "safe line-break" character within this match + for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x})); + if (!$ledge) $ledge = strlen($match[2]) - 1; - // Insert the modified string - $value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[4]; - } - } + // Insert the modified string + $value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[4]; + } + } - // Loop while overlimit strings are still being found - } while ($store != $value); + // Loop while overlimit strings are still being found + } while ($store != $value); - // Put captured HTML entities back into the string - foreach ($ents[0] as $ent) $value = preg_replace("/\x06/", $ent, $value, 1); - } - } - } + // Put captured HTML entities back into the string + foreach ($ents[0] as $ent) $value = preg_replace("/\x06/", $ent, $value, 1); + } + } + } - // Send the modified segment down the drain - $drain .= $value; - } + // Send the modified segment down the drain + $drain .= $value; + } - // Return contents of the drain - return $drain; -} + // Return contents of the drain + return $drain; +} -function makeClickableLinks($text,$wrap=true,$emails=true) { +function makeClickableLinks($text, $wrap=true, $emails=true) { -// $text = preg_replace('/([\S]{26})(?![^a-zA-Z])/', '$1 ', $text); -// $text = preg_replace('/([a-zA-Z]{26})(?![^a-zA-Z])/', '$1 ', $text); -// $text = preg_replace('/([a-zA-Z0-9:=_\]\[,]{26})(?![^a-zA-Z0-9:=_\]\[,])/', '$1 ', $text); -// $text = preg_replace('/([-a-zA-Z0-9@:%_\+.~#?&//=]{26})(?![^a-zA-Z])/', '$1 ', $text); +// $text = preg_replace('/([\S]{26})(?![^a-zA-Z])/', '$1 ', $text); +// $text = preg_replace('/([a-zA-Z]{26})(?![^a-zA-Z])/', '$1 ', $text); +// $text = preg_replace('/([a-zA-Z0-9:=_\]\[,]{26})(?![^a-zA-Z0-9:=_\]\[,])/', '$1 ', $text); +// $text = preg_replace('/([-a-zA-Z0-9@:%_\+.~#?&//=]{26})(?![^a-zA-Z])/', '$1 ', $text); -// $text = preg_replace('/([a-zA-Z0-9:=_\]\[,\/]{26})(?![^a-zA-Z0-9:=_\]\[,\/])/', '$1 ', $text); +// $text = preg_replace('/([a-zA-Z0-9:=_\]\[,\/]{26})(?![^a-zA-Z0-9:=_\]\[,\/])/', '$1 ', $text); // $text = htmlwrap($text, 26, "\n", true); - -// $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:;%_\+.~#?&//=]+)', + +// $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:;%_\+.~#?&//=]+)', -// $text = eregi_replace('(((ftp|http|https)://)[\S]+)', +// $text = eregi_replace('(((ftp|http|https)://)[\S]+)', // $text = mb_eregi_replace('(((ftp|http|https)://)[-a-zA-Z0-9@:;%_\+.~#?&//=]+)' -//, -// $text = mb_eregi_replace('(((ftp|http|https)://)[-a-zA-Z0-9@:;%_\+.~#?&//=]+)', -// '\\1', $text); - - //$text = preg_replace('@((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)@', '$1', $text); - -// $text = mb_eregi_replace('((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)', '\\1', $text); -// $text = mb_eregi_replace('((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)', '\\1', $text); - - $text = mb_eregi_replace('((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\S+)?)?)?)', '\\1', $text); - - $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:;%_\+.~#?&//=]+)', - '\\1\\2', $text); - +//, +// $text = mb_eregi_replace('(((ftp|http|https)://)[-a-zA-Z0-9@:;%_\+.~#?&//=]+)', +// '\\1', $text); + + //$text = preg_replace('@((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)@', '$1', $text); + +// $text = mb_eregi_replace('((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)', '\\1', $text); +// $text = mb_eregi_replace('((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)', '\\1', $text); + + $text = mb_eregi_replace('((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\S+)?)?)?)', '\\1', $text); + + $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:;%_\+.~#?&//=]+)', + '\\1\\2', $text); + if ($emails) - $text = eregi_replace('([\+_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', - '\\1', $text); + $text = eregi_replace('([\+_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', + '\\1', $text); - // $text = preg_replace('@((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)@', '$1', $text); + // $text = preg_replace('@((ftp|https|http)?://([-\w\.]+)+(:\d+)?(/([;\w/_\.]*(\?\S+)?)?)?)@', '$1', $text); if ($wrap) $text = htmlwrap($text,26," "); - + /* - $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', - '[URL]', $text); - $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', - '\\1[URL]', $text); - $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', - '[MAIL]', $text); + $text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', + '[URL]', $text); + $text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', + '\\1[URL]', $text); + $text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', + '[MAIL]', $text); */ - -// $text = preg_replace('/([a-zA-Z:=_]{20})/', '$1 ', $text); -// $text = preg_replace('/(^\s{16})(^\s)/', '$1 ', $text); - - - return $text; +// $text = preg_replace('/([a-zA-Z:=_]{20})/', '$1 ', $text); +// $text = preg_replace('/(^\s{16})(^\s)/', '$1 ', $text); -} + return $text; +} function stateName($state) { @@ -1735,14 +1691,14 @@ function addHistory($action, $id, $value, $parent, $user, $uid=0) } -function sendEmail($to,$subject,$body) +function sendEmail($to, $subject, $body) { - mail($to,$subject,$body,"From:".CONFIG_NOREPLY_EMAIL."\nMIME-Version: 1.0\nContent-type: text/html; Charset=UTF-8\n"); + mail($to,$subject,$body,"From:".CONFIG_NOREPLY_EMAIL."\nMIME-Version: 1.0\nContent-type: text/html; Charset=UTF-8\n"); } function deleteChildrenTree($msg) { - sql("DELETE FROM children WHERE cmessage=".sqlVar($msg->id)); + sql("DELETE FROM children WHERE cmessage=".sqlVar($msg->id)); } function createParentTree($msg) { @@ -1753,10 +1709,10 @@ function createParentTree($msg) $p = $pmsg->gparent; sql("INSERT INTO children VALUES($p,$msg->id)"); $pmsg = sqlObject('SELECT * FROM messages WHERE id='.$p); - + $cnt++; if ($cnt>100) - break; + break; }while($p); } function relocateChildrenTree($msg) @@ -1767,7 +1723,7 @@ function relocateChildrenTree($msg) { deleteChildrenTree($c->cmessage); } - + createParentTree($msg); foreach($children AS $c) { @@ -1776,13 +1732,10 @@ function relocateChildrenTree($msg) } } - - - /** Validate an email address. Provide email address (raw input) -Returns true if the email address has the email +Returns true if the email address has the email address format and the domain exists. */ function validEmail($email) @@ -1833,7 +1786,7 @@ function validEmail($email) (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { - // character not valid in local part unless + // character not valid in local part unless // local part is quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) @@ -1841,19 +1794,19 @@ function validEmail($email) $isValid = false; } } - + if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A"))) { // domain not found in DNS $isValid = false; } - + } return $isValid; } -function makeInviteKey($msgid,$email,$inviteID) +function makeInviteKey($msgid, $email, $inviteID) { global $dbSalt; return md5($dbSalt.$msgid.$email.$inviteID); @@ -1863,39 +1816,39 @@ function login($user) { $_SESSION['userid'] = $user->id; $_SESSION['username'] = $user->name; - - setLoginCookies($user->id); + + setLoginCookies($user->id); } function logout() { session_start(); - + session_destroy(); - + session_unset(); - + removeLoginCookies(); } -function makeAvatar($user,$avatar) +function makeAvatar($user, $avatar) { - + $src = imagecreatefromstring($avatar); - + $size = 50; - - $dst = imagecreatetruecolor($size,$size); - + + $dst = imagecreatetruecolor($size,$size); + $white = imagecolorallocate($dst, 255, 255, 255); imagefill($dst,0,0,$white); - imagecopyresampled($dst,$src,0,0,0,0,$size,$size,imagesx($src),imagesy($src)); - + imagecopyresampled($dst,$src,0,0,0,0,$size,$size,imagesx($src),imagesy($src)); + imagejpeg($dst,CONFIG_DATADIR."/avatars/".$user->id.".jpg",$quality=90); imagejpeg($src,CONFIG_DATADIR."/avatars/".$user->id."-orig.jpg",$quality=90); - + sql("UPDATE users SET avatar=avatar+1 WHERE id=$user->id"); } @@ -1906,4 +1859,4 @@ function makeLoginKey($u) return md5($dbSalt.$u->id.$u->email.$u->twitter_id); } -?> +?> \ No newline at end of file From 83d8d3db9c35d8b7c5d3fa2aef5cf3e86fd450fe Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Mon, 12 May 2014 20:35:56 +0800 Subject: [PATCH 2/6] More whitespace and define() fixups. --- php/config-default.php | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/php/config-default.php b/php/config-default.php index 8cbcd10..a75dd6d 100644 --- a/php/config-default.php +++ b/php/config-default.php @@ -1,27 +1,19 @@ +define('TWITTER_CONSUMER_KEY', ''); +define('TWITTER_CONSUMER_SECRET', ''); +define('TWITTER_OAUTH_CALLBACK', ''); +?> \ No newline at end of file From 8fc9cfe85bc7ac82627a167d27ab55445fbae800 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Mon, 12 May 2014 20:39:04 +0800 Subject: [PATCH 3/6] Bringing README.md in line with the define() fixes. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 6324f2f..8154f3a 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,11 @@ $ cp php/config-default.php php/config.php You will need to define the following strings in php/config.php: ``` -define(CONFIG_DB_NAME, ''); // database name -define(CONFIG_DB_HOSTNAME, ''); // database hostname -define(CONFIG_DB_USER, ''); // database username -define(CONFIG_DB_PASSWORD, ''); // database password -define(CONFIG_DATADIR, ''); // path to read/writable data directory +define('CONFIG_DB_NAME', ''); // database name +define('CONFIG_DB_HOSTNAME', ''); // database hostname +define('CONFIG_DB_USER', ''); // database username +define('CONFIG_DB_PASSWORD', ''); // database password +define('CONFIG_DATADIR', ''); // path to read/writable data directory ``` Most of that is quite self explanatory, basically you just need an empty MySQL @@ -40,5 +40,5 @@ Next, in a web browser open the following page to initialize the database: setup/install.php ``` -And thats it! +And thats it! From ebe7acb731ace54c8579c9522a259e20d8fdd254 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Mon, 12 May 2014 20:43:31 +0800 Subject: [PATCH 4/6] Removed indentation; replaced include with require. --- setup/install.php | 160 ++++++++++++++++++++++------------------------ 1 file changed, 75 insertions(+), 85 deletions(-) diff --git a/setup/install.php b/setup/install.php index 403e210..d6aa4bb 100644 --- a/setup/install.php +++ b/setup/install.php @@ -1,95 +1,85 @@
    "; - - - echo "Checking MYSQL connection... "; - - $link = @mysql_connect (CONFIG_DB_HOSTNAME, CONFIG_DB_USER, CONFIG_DB_PASSWORD); - - showResult($link); - - mysql_select_db(CONFIG_DB_NAME, $link); - - - echo "Creating TABLES... "; - - - $sql = file_get_contents("db.sql"); - - - $queries = preg_split("/;+(?=([^'|^\\\']*['|\\\'][^'|^\\\']*['|\\\'])*[^'|^\\\']*[^'|^\\\']$)/", $sql); - foreach ($queries as $query) - { - if (strlen(trim($query)) > 0) - { - $r = mysql_query($query); - if (!$r) - break; - } - } - showResult($r); - - - - echo "Creating default users... "; - - $r = mysql_query("INSERT INTO users (id,name) VALUES (".NOTICE_ID.',"Notice")'); - showResult($r); - - - - - echo "Checking data directory... "; - - $testfile = CONFIG_DATADIR.'/test'; - - $handle = fopen($testfile, "w"); - showResult($handle); - - unlink($testfile); - - - echo "Creating avatars directory... "; - $r = mkdir(CONFIG_DATADIR.'/avatars'); - showResult($r); - - echo "Creating thumbs directory... "; - $r = mkdir(CONFIG_DATADIR.'/thumbs'); - showResult($r); - - - - echo "Copying default avatars... "; - $r = copy("../images/notice_avatar.jpg", CONFIG_DATADIR.'/avatars/'.NOTICE_ID.'.jpg'); - $r |= copy("../images/anybody_avatar.jpg", CONFIG_DATADIR.'/avatars/'.ANYBODY_ID.'.jpg'); - $r |= copy("../images/default_avatar.jpg", CONFIG_DATADIR.'/avatars/'.DEFAULT_ID.'.jpg'); - - showResult($r); - - - - - - - echo '

    SUCCESS!
    '; - - - mysql_close($link); +echo "Pendactive Setup

    "; +echo "Checking MYSQL connection... "; -function showResult($passed) +$link = @mysql_connect (CONFIG_DB_HOSTNAME, CONFIG_DB_USER, CONFIG_DB_PASSWORD); + +showResult($link); + +mysql_select_db(CONFIG_DB_NAME, $link); + + +echo "Creating TABLES... "; + + +$sql = file_get_contents("db.sql"); + + +$queries = preg_split("/;+(?=([^'|^\\\']*['|\\\'][^'|^\\\']*['|\\\'])*[^'|^\\\']*[^'|^\\\']$)/", $sql); +foreach ($queries as $query) { - if (!$passed) - { - echo 'FAILED
    '; - die(); - }else - echo 'OK
    '; + if (strlen(trim($query)) > 0) + { + $r = mysql_query($query); + if (!$r) + break; + } } +showResult($r); + + + +echo "Creating default users... "; + +$r = mysql_query("INSERT INTO users (id,name) VALUES (".NOTICE_ID.',"Notice")'); +showResult($r); + + + +echo "Checking data directory... "; +$testfile = CONFIG_DATADIR.'/test'; + +$handle = fopen($testfile, "w"); +showResult($handle); + +unlink($testfile); + + +echo "Creating avatars directory... "; +$r = mkdir(CONFIG_DATADIR.'/avatars'); +showResult($r); + +echo "Creating thumbs directory... "; +$r = mkdir(CONFIG_DATADIR.'/thumbs'); +showResult($r); + + + +echo "Copying default avatars... "; +$r = copy("../images/notice_avatar.jpg", CONFIG_DATADIR.'/avatars/'.NOTICE_ID.'.jpg'); +$r |= copy("../images/anybody_avatar.jpg", CONFIG_DATADIR.'/avatars/'.ANYBODY_ID.'.jpg'); +$r |= copy("../images/default_avatar.jpg", CONFIG_DATADIR.'/avatars/'.DEFAULT_ID.'.jpg'); + +showResult($r); + +echo '

    SUCCESS!
    '; + + +mysql_close($link); + +function showResult($passed) +{ + if (!$passed) + { + echo 'FAILED
    '; + die(); + }else + echo 'OK
    '; +} ?> \ No newline at end of file From 45a4f3deec8e86d5fb8df91e043226386126865b Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Mon, 12 May 2014 22:52:58 +0800 Subject: [PATCH 5/6] Refactored install script to be a bit more stylable - should now have a definition list rather than just text in the window. --- setup/install.php | 254 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 189 insertions(+), 65 deletions(-) diff --git a/setup/install.php b/setup/install.php index d6aa4bb..34d3825 100644 --- a/setup/install.php +++ b/setup/install.php @@ -1,85 +1,209 @@
    "; - - -echo "Checking MYSQL connection... "; - -$link = @mysql_connect (CONFIG_DB_HOSTNAME, CONFIG_DB_USER, CONFIG_DB_PASSWORD); - -showResult($link); - -mysql_select_db(CONFIG_DB_NAME, $link); - - -echo "Creating TABLES... "; - - -$sql = file_get_contents("db.sql"); +require_once "../php/func.php"; + +/** + * Given an array of form + * + * array( + * user_string => setup_task + * ) + * + * where user_string string describing the setup task, to be displayed to + * the user + * setup_task name of function to execute, of function signature * + * function hurf(&$flag, &$str, &$odd) + * + * executes the given setup tasks and prints associated markup. + */ +function do_setup_tasks($arr) { + $idx = 0; + foreach ($arr as $str => $func) { + $ok = true; + $infostr = ""; + $classstr = "even"; + if($idx++ % 2 == 1) + $classstr = "odd"; + ?> +
    +
    + +
    + 0) +function create_tables(&$flag, &$str) { + $dbsql = file_get_contents("db.sql"); + $queries = preg_split("/;+(?=([^'|^\\\']*['|\\\'][^'|^\\\']*['|\\\'])*[^'|^\\\']*[^'|^\\\']$)/", $dbsql); + foreach ($queries as $query) { - $r = mysql_query($query); - if (!$r) - break; + if (strlen(trim($query)) > 0) + { + $r = mysql_query($query); + if (!$r) { + $flag = false; + $str = mysql_error(); + break; + } + } } + show_result($r); } -showResult($r); - - - -echo "Creating default users... "; - -$r = mysql_query("INSERT INTO users (id,name) VALUES (".NOTICE_ID.',"Notice")'); -showResult($r); - - - - -echo "Checking data directory... "; - -$testfile = CONFIG_DATADIR.'/test'; - -$handle = fopen($testfile, "w"); -showResult($handle); - -unlink($testfile); +function create_default_users(&$flag, &$str) { + $r = mysql_query("INSERT INTO users (id,name) VALUES (".NOTICE_ID.',"Notice")'); + show_result($r); + if (!$r) { + $flag = false; + $str = mysql_error(); + } +} -echo "Creating avatars directory... "; -$r = mkdir(CONFIG_DATADIR.'/avatars'); -showResult($r); +function check_data_dir(&$flag, &$str) { + $testfile = CONFIG_DATADIR . '/test'; + $handle = @fopen($testfile, "w"); -echo "Creating thumbs directory... "; -$r = mkdir(CONFIG_DATADIR.'/thumbs'); -showResult($r); + if (!$handle) { + $flag = false; + $str = $php_errormsg; + } + fclose($handle); + $unlink = @unlink($testfile); + if (!$unlink) { + $flag = false; + $str = $php_errormsg; + } + show_result($flag); +} -echo "Copying default avatars... "; -$r = copy("../images/notice_avatar.jpg", CONFIG_DATADIR.'/avatars/'.NOTICE_ID.'.jpg'); -$r |= copy("../images/anybody_avatar.jpg", CONFIG_DATADIR.'/avatars/'.ANYBODY_ID.'.jpg'); -$r |= copy("../images/default_avatar.jpg", CONFIG_DATADIR.'/avatars/'.DEFAULT_ID.'.jpg'); +function create_avatar_dir(&$flag, &$str) { + $r = @mkdir(CONFIG_DATADIR.'/avatars'); + show_result($r); + if (!$r) { + $flag = false; + $str = $php_errormsg; + } +} -showResult($r); +function create_thumbs_dir(&$flag, &$str) { + $r = mkdir(CONFIG_DATADIR.'/thumbs'); + show_result($r); + if (!$r) { + $flag = false; + $str = $php_errormsg; + } +} -echo '

    SUCCESS!
    '; +function copy_default_avatars(&$flag, &$str) { + $source = array( + "../images/notice_avatar.jpg", + "../images/anybody_avatar.jpg", + "../images/default_avatar.jpg" + ); + $dest = array( + CONFIG_DATADIR . '/avatars/' . NOTICE_ID . '.jpg', + CONFIG_DATADIR . '/avatars/' . ANYBODY_ID . '.jpg', + CONFIG_DATADIR . '/avatars/' . DEFAULT_ID . '.jpg' + ); + + $r = false; + for ($i = 0; $i < count($source); $i++) { + $success = @copy($source[$i], $dest[$i]); + $r |= $success; + + if(!$success) { + $flag = false; + $str = $php_errormsg; + } + } + show_result($r); +} +function show_result($passed) +{ + $resultClass = "result"; + $resultText = "OK"; -mysql_close($link); -function showResult($passed) -{ if (!$passed) { - echo 'FAILED
    '; - die(); - }else - echo 'OK
    '; + $resultClass = "result result-failed"; + $resultText = "Failed"; + } + ?> + + \ No newline at end of file + +?> + + + + + + + + + + settings + + + + +

    Pendactive Setup

    + +
    + 'connect_to_db', + 'Creating TABLES...' => 'create_tables', + 'Creating default users...' => 'create_default_users', + 'Checking data directory...' => 'check_data_dir', + 'Creating avatars directory...' => 'create_avatar_dir', + 'Creating thumbs directory...' => 'create_thumbs_dir', + 'Creating default avatars...' => 'copy_default_avatars' + )); + ?> +
    SUCCESS!
    + +
    + + + \ No newline at end of file From b0c17778bbf090625239074fdc53bc2506a04140 Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Mon, 12 May 2014 22:59:19 +0800 Subject: [PATCH 6/6] Stylesheets in LESS format, and compiled CSS / sourcemap stuff. Amended .gitignore file. --- .gitignore | 10 +++++++ css/macros.less | 55 ++++++++++++++++++++++++++++++++++++++ css/setup.css | 68 +++++++++++++++++++++++++++++++++++++++++++++++ css/setup.css.map | 1 + css/setup.less | 67 ++++++++++++++++++++++++++++++++++++++++++++++ css/shared.less | 14 ++++++++++ setup/install.php | 3 +-- 7 files changed, 216 insertions(+), 2 deletions(-) create mode 100644 css/macros.less create mode 100644 css/setup.css create mode 100644 css/setup.css.map create mode 100644 css/setup.less create mode 100644 css/shared.less diff --git a/.gitignore b/.gitignore index 33afccc..71a50c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,13 @@ .DS_Store php/config.php +lib/** +css/*.css +css/*.css.map +!css/font-awesome.css +!css/font-aweseome-ie7.css +!css/iphone.css +!css/loading.css +!css/main.css +!css/nav.css +!css/setup.css \ No newline at end of file diff --git a/css/macros.less b/css/macros.less new file mode 100644 index 0000000..d15f625 --- /dev/null +++ b/css/macros.less @@ -0,0 +1,55 @@ +.border-radius(@a) +{ + -webkit-border-radius: @a; + -moz-border-radius: @a; + border-radius: @a; +} + +.box-shadow(@a) +{ + -webkit-box-shadow: @a; + -moz-box-shadow: @a; + box-shadow: @a; +} + +.transition(@a) +{ + -webkit-transition: @a; + -moz-transition: @a; + transition: @a; +} + +.background-radial(@a, @b) +{ + background: radial-gradient( + center, + ellipse cover, + @a 0%, + @b 100% + ); + background: -moz-radial-gradient( + center, + ellipse cover, + @a 0%, + @b 100% + ); + background: -webkit-gradient( + radial, + center center, + 0px, + center center, + 100%, + color-stop( + 0%, + @a + ), + color-stop( + 100%, + @b + ) + ); + background: -webkit-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(196,220,255,1) 100%); + background: -o-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(196,220,255,1) 100%); + background: -ms-radial-gradient(center, ellipse cover, rgba(255,255,255,1) 0%,rgba(196,220,255,1) 100%); + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#ffffff', endColorstr='#c4dcff',GradientType=1 ); +} \ No newline at end of file diff --git a/css/setup.css b/css/setup.css new file mode 100644 index 0000000..7478371 --- /dev/null +++ b/css/setup.css @@ -0,0 +1,68 @@ +html, +body { + width: 100%; + height: 100%; +} +body { + margin: 0; + padding: 0; + background: #fff; + font-family: 'Lato', sans-serif; + -ms-user-select: none; +} +body.setup .pagetitle { + width: 100%; + text-align: center; + text-transform: lowercase; + font-size: 50px; + color: #66a; + font-weight: bold; + text-shadow: rgba(0, 0, 0, 0.3) 1px 1px 2px; +} +.initsteps { + width: 560px; + margin: 0px auto; +} +.initsteps dt, +.initsteps dd { + display: block; + position: relative; + padding: 8px; + height: 20px; +} +.initsteps dt { + float: left; + clear: both; +} +.initsteps dt.success { + float: none; + margin: 0; + text-align: center; + font-weight: bold; +} +.initsteps dd.flag { + width: 64px; + float: right; + text-align: right; + margin: 0px; +} +.initsteps dd.dead { + clear: both; + margin: 0px 40px; +} +.initsteps dd.dead pre { + margin: 0px; +} +.initsteps dd .result { + font-size: 11px; + font-weight: bold; + color: #fff; + text-transform: uppercase; + background-color: #00a65c; + border-radius: 4px; + padding: 2px 4px; +} +.initsteps dd .result.result-failed { + background-color: #cf0909; +} +/*# sourceMappingURL=setup.css.map */ \ No newline at end of file diff --git a/css/setup.css.map b/css/setup.css.map new file mode 100644 index 0000000..f79342d --- /dev/null +++ b/css/setup.css.map @@ -0,0 +1 @@ +{"version":3,"file":"../css/setup.css","sources":["shared.less","setup.less"],"names":[],"mappings":"AAAA;AAAM;EACL,WAAA;EAAY,YAAA;;AAGb;EACC,SAAA;EACA,UAAA;EACA,gBAAA;EAEA,aAAa,kBAAb;EACA,qBAAA;;ACRD,IAAI,MACH;EACC,WAAA;EACA,kBAAA;EACA,yBAAA;EACA,eAAA;EACA,WAAA;EACA,iBAAA;EACA,2CAAA;;AAIF;EACC,YAAA;EACA,gBAAA;;AAFD,UAGC;AAHD,UAGK;EACH,cAAA;EACA,kBAAA;EACA,YAAA;EACA,YAAA;;AAPF,UASC;EACC,WAAA;EACA,WAAA;;AAGA,UALD,GAKE;EACA,WAAA;EACA,SAAA;EACA,kBAAA;EACA,iBAAA;;AAID,UADD,GACE;EACA,WAAA;EACA,YAAA;EACA,iBAAA;EACA,WAAA;;AAED,UAPD,GAOE;EACA,WAAA;EACA,gBAAA;;AAFD,UAPD,GAOE,KAIA;EACC,WAAA;;AAjCJ,UAqBC,GAeC;EACC,eAAA;EACA,iBAAA;EACA,WAAA;EACA,yBAAA;EAEA,yBAAA;EACA,kBAAA;EAEA,gBAAA;;AAEA,UA1BF,GAeC,QAWE;EACA,yBAAA"} \ No newline at end of file diff --git a/css/setup.less b/css/setup.less new file mode 100644 index 0000000..2335938 --- /dev/null +++ b/css/setup.less @@ -0,0 +1,67 @@ +@import 'shared.less'; + +body.setup { + .pagetitle { + width: 100%; + text-align: center; + text-transform:lowercase; + font-size: 50px; + color: #66a; + font-weight: bold; + text-shadow: rgba(0,0,0,0.3) 1px 1px 2px; + } +} + +.initsteps { + width: 560px; + margin: 0px auto; + dt, dd { + display: block; + position: relative; + padding: 8px; + height: 20px; + } + dt { + float: left; + clear: both; + &.even {} + &.odd {} + &.success { + float: none; + margin: 0; + text-align: center; + font-weight: bold; + } + } + dd { + &.flag { + width: 64px; + float: right; + text-align: right; + margin: 0px; + } + &.dead { + clear: both; + margin: 0px 40px; + + pre { + margin: 0px; + } + } + .result { + font-size: 11px; + font-weight: bold; + color: #fff; + text-transform: uppercase; + + background-color: #00a65c; + border-radius: 4px; + + padding: 2px 4px; + + &.result-failed { + background-color: #cf0909; + } + } + } +} \ No newline at end of file diff --git a/css/shared.less b/css/shared.less new file mode 100644 index 0000000..8f2dc9a --- /dev/null +++ b/css/shared.less @@ -0,0 +1,14 @@ +html, body{ + width:100%; height:100%; +} + +body { + margin: 0; + padding: 0; + background: #fff; + + font-family: 'Lato', sans-serif; + -ms-user-select: none; +} + +@import 'macros.less'; \ No newline at end of file diff --git a/setup/install.php b/setup/install.php index 34d3825..76c9bf5 100644 --- a/setup/install.php +++ b/setup/install.php @@ -172,8 +172,7 @@ function show_result($passed) - - + settings