[Astrospaces-commits] SF.net SVN: astrospaces: [20] trunk
Brought to you by:
p3net
From: <p3...@us...> - 2007-07-29 06:10:52
|
Revision: 20 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=20&view=rev Author: p3net Date: 2007-07-28 23:10:45 -0700 (Sat, 28 Jul 2007) Log Message: ----------- As per request, document what every function actually does Modified Paths: -------------- trunk/functions/db.php trunk/functions/session.php trunk/gallery.php trunk/globals.php trunk/images.php trunk/profile.php Modified: trunk/functions/db.php =================================================================== --- trunk/functions/db.php 2007-07-28 21:16:51 UTC (rev 19) +++ trunk/functions/db.php 2007-07-29 06:10:45 UTC (rev 20) @@ -21,6 +21,11 @@ $this =& new db; class db { + /* + Function Name: db + Arguments: none + Purpose: Instantiate db class and connect to db + */ function db() { require_once('./../config.php'); @@ -38,6 +43,11 @@ } } } + /* + Function Name: query + Arguments: (string) query -- SQL query + Purpose: Run an SQL query + */ function query($query) { $query = mysql_query($query); @@ -47,6 +57,11 @@ } return $query; } + /* + Function Name: fetch_array + Arguments: (object) query + Purpose: Fetch array results of SQL query + */ function fetch_array($query) { $query = mysql_fetch_array($query); Modified: trunk/functions/session.php =================================================================== --- trunk/functions/session.php 2007-07-28 21:16:51 UTC (rev 19) +++ trunk/functions/session.php 2007-07-29 06:10:45 UTC (rev 20) @@ -26,6 +26,11 @@ **********************************************************/ class session { + /* + Function Name: create + Arguments: none + Purpose: create session + */ function create() { /* We don't have a session and aren't logged in. Let's create it */ @@ -35,6 +40,11 @@ $db->query($_query); $_COOKIE["session_id"] = $id; } + /* + Function Name: check + Arguments: none + Purpose: Check if a session exists + */ function check() { /* We need to check if a session exists by looking for the session cookie. If that's not there, @@ -69,6 +79,11 @@ $_query = "DELETE * FROM `sessions` WHERE `last_update` < " . (time() - (60*30)); $db->query($_query); } + /* + Function Name: logged_in + Arguments: none + Purpose: check if user is logged in + */ function logged_in() { if($user->data['id'] != "-1") @@ -80,6 +95,11 @@ return false; } } + /* + Function Name: login + Arguments: (int) user_id -- ID of user to login + Purpose: Updates session table to reflect that a user is logged in + */ function login($user_id) { $session->check(); @@ -96,6 +116,11 @@ $session->check(); } } + /* + Function Name: logout + Arguments: none + Purpose: Edit session table to reflect that user is logged out + */ function logout() { if($session->logged_in()) @@ -109,6 +134,11 @@ $error->general('Not logged in', 'User ID = -1'); } } + /* + Function Name: is_friend + Arguments: (int) id -- ID of our suspected friend + Purpose: Check if user is your friend + */ function is_friend($id) { if(!$user->logged_in()) @@ -138,6 +168,11 @@ } } } + /* + Function Name: action + Arguments: (int) action -- Add action to action table; (int) who -- ID of friend action is made towards. If unspecified, applies to all + Purpose: + */ function action($action, $who="") { /*List of actions: @@ -154,6 +189,11 @@ $db->query($_query); return true; } + /* + Function Name: add_friend + Arguments: (int) id -- ID of user to add as our friend + Purpose: Add user as (unapproved) friend + */ function add_friend($id) { if(!$user->logged_in()) @@ -192,12 +232,22 @@ } } } + /* + Function Name: accept_friend + Arguments: (int) id -- ID of user to accept as friend + Purpose: Accept friend + */ function accept_friend($id) { $_query="UPDATE `friends` SET `accepted`='1' WHERE `party_2`='" . $data->user['user_id'] . "' AND `party_1='" . $id . "' LIMIT 1"; $db->query($_query); $user->action(5, $id); } + /* + Function Name: can_view + Arguments: (int) id -- ID of user who permissions are being checked for + Purpose: Check if we have permissions to view this users space + */ function can_view($id) { /*We're simply checking whether or not we have the permissions to view this space */ @@ -224,6 +274,11 @@ } } } + /* + Function Name: add_coment + Arguments: (int) id -- ID of user who comment is directed to + Purpose: Add comment + */ function add_comment($id) { if($session->is_friend($id)) @@ -239,6 +294,11 @@ $session->action('2', $id); } } + /* + Function Name: get_username + Arguments: (int) id -- User ID + Purpose: Fetch username of user based on their unique ID + */ function get_username($id) { $_query="SELECT `display_name` FROM `users` WHERE `id`='" . $id . "'"; @@ -246,6 +306,11 @@ $res=$db->fetch_array($_query); return $res['display_name']; } + /* + Function Name: add_image_comment + Arguments: (int) id -- Image ID + Purpose: Add comment to image + */ function add_image_comment($id) { $owner = "SELECT `owner` FROM `images` WHERE `id`='" . $id . "'"; @@ -262,6 +327,11 @@ $db->query($_query); } } + /* + Function Name: generate_timestamp + Arguments: (int) time -- time to parse + Purpose: Generate datestamp of time passed, taking user's time offset into consideration + */ function generate_timestamp($time) { if($session->logged_in()) Modified: trunk/gallery.php =================================================================== --- trunk/gallery.php 2007-07-28 21:16:51 UTC (rev 19) +++ trunk/gallery.php 2007-07-29 06:10:45 UTC (rev 20) @@ -20,6 +20,11 @@ *********************************************************/ class gallery { + /* + Function Name: view + Arguments: (int) id -- ID of user + Purpose: View gallery of user + */ function view($id) { if($id == 0) @@ -38,6 +43,11 @@ } } } + /* + Function Name: drill + Arguments: (int) img_id -- ID of image to view; (int) owner -- ID of image uploader + Purpose: View fullsize image/comments of specific image + */ function drill($img_id, $owner) { if(empty($img_id)) @@ -81,6 +91,11 @@ } } } + /* + Function Name: comment + Arguments: (int) id -- Image ID; (int) owner -- Image owner ID + Purpose: Display comment form + */ function comment($id, $owner) { if($session->is_friend($owner)) @@ -88,6 +103,11 @@ $form =& new template('forms/gallery_comment.tpl'); } } + /* + Function Name: comment_process + Arguments: none + Purpose: Insert image comment into database + */ function comment_process() { $img_id=$_POST["id"]; Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-07-28 21:16:51 UTC (rev 19) +++ trunk/globals.php 2007-07-29 06:10:45 UTC (rev 20) @@ -27,6 +27,11 @@ /*The smaller ones*/ class error { + /* + Function Name: general + Arguments: (string) err -- Error to be printed; (string) verbose -- Error to be written to error log + Purpose: Display error message and write record of error to log + */ function general($err, $verbose) { $error =& new template('messages/error.tpl'); @@ -46,6 +51,12 @@ } class message { + /* + Function Name: thank + Arguments: (string) message -- Thank you message; (string) go1 -- Page to proceed to; (string) res1 -- Desc of page; + (string) (optional) go2 -- Second option to proceed to; (string) (optional) res2 -- Desc of second page + Purpose: + */ function thank($message, $go1, $res1, $go2="", $res2="") { $message =& new template('message/thank.tpl'); Modified: trunk/images.php =================================================================== --- trunk/images.php 2007-07-28 21:16:51 UTC (rev 19) +++ trunk/images.php 2007-07-29 06:10:45 UTC (rev 20) @@ -21,6 +21,11 @@ include('globals.php'); class image { + /* + Function Name: full + Arguments: (int) id -- ID of image + Purpose: Display full-size image uploaded by user + */ function full($id) { $id = is_numeric($_GET["id"]) ? $_GET["id"] : null; @@ -35,6 +40,11 @@ header('Content-Disposition: attachment; filename=' . $img['name']); echo $img['content']; } + /* + Function Name: thumb + Arguments: (int) id -- ID of image uploaded by user + Purpose: Display 150px thumbnail of image + */ function thumb($id) { $id = is_numeric($_GET["id"]) ? $_GET["id"] : null; Modified: trunk/profile.php =================================================================== --- trunk/profile.php 2007-07-28 21:16:51 UTC (rev 19) +++ trunk/profile.php 2007-07-29 06:10:45 UTC (rev 20) @@ -1,4 +1,4 @@ -<?php +<?php /******************************************************* * Copyright (C) 2007 http://p3net.net @@ -14,177 +14,223 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - - @id: $Id$ -*********************************************************/ -include('globals'); -class profile -{ - function register() - { - $step = empty($_GET["step"]) ? '1' : $_GET["step"]; - if($step == 1) - { - $form =& new template('forms/register.tpl'); - } - else if($step == 2) - { - foreach($_POST as $key => $value) - { - $vars[$key] = mysql_real_escape_string($value); - } - $_query = "INSERT INTO users (`id`, `display_name`, `password`, `join`, `time_offset` VALUES('', '" . $vars["display_name"] . "', '" . - md5($vars["password"] . "', '" . time() . "', '" . $vars["offset"] . "')"; - $db->query($_query); - $message->thank('for registering.', 'to proceed to the login page.', 'profile.php?mode=login'); - } - } - function edit() - { - /* I'm too lazy to code this so we'll do it later */ - } - function delete() - { - /* Need to work everything else out first */ - } - function pics() - { - if(!($user->logged_in())) - { - $error->general("Not logged in", "Pics upload"); - } - $step = empty($_GET["step"]) ? '1' : $_GET["step"]; - if($step == 1) - { - $form =& new template('forms/upload_pic.tpl'); - } - else - { - if($_FILES['pic']['size'] < 1) - { - $error->general("No image uploaded", "File size = 0"); - } + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + @id: $Id$ +*********************************************************/ +include('globals.php'); +class profile +{ + /* + Function Name: register + Arguments: none + Purpose: Register user + */ + function register() + { + $step = empty($_GET["step"]) ? '1' : $_GET["step"]; + if($step == 1) + { + $form =& new template('forms/register.tpl'); + } + else if($step == 2) + { + foreach($_POST as $key => $value) + { + $vars[$key] = mysql_real_escape_string($value); + } + $_query = "INSERT INTO users (`id`, `display_name`, `password`, `join`, `time_offset` VALUES('', '" . $vars["display_name"] . "', '" . + md5($vars["password"] . "', '" . time() . "', '" . $vars["offset"] . "')"; + $db->query($_query); + $message->thank('for registering.', 'to proceed to the login page.', 'profile.php?mode=login'); + } + } + /* + Function Name: edit + Arguments: none + Purpose: Edit user profile information (IE, contents of user table) + */ + function edit() + { + /* I'm too lazy to code this so we'll do it later */ + } + /* + Function Name: delete + Arguments: None + Purpose: delete user + */ + function delete() + { + /* Need to work everything else out first */ + } + /* + Function Name: pics + Arguments: none + Purpose: Step 1 -- Display image upload form + Step 2 -- Upload profile image + */ + function pics() + { + if(!($user->logged_in())) + { + $error->general("Not logged in", "Pics upload"); + } + $step = empty($_GET["step"]) ? '1' : $_GET["step"]; + if($step == 1) + { + $form =& new template('forms/upload_pic.tpl'); + } + else + { + if($_FILES['pic']['size'] < 1) + { + $error->general("No image uploaded", "File size = 0"); + } $file_name = $_FILES['pic']['name']; $tmp_name = $_FILES['pic']['tmp_name']; $file_size = $_FILES['pic']['size']; - $file_type = $_FILES['pic']['type']; - - list($width, $height) = getimagesize($tmp_name) or $general->error("Could not upload", "Not an image"); - + $file_type = $_FILES['pic']['type']; + + list($width, $height) = getimagesize($tmp_name) or $general->error("Could not upload", "Not an image"); + $fp = fopen($tmp_name, 'r'); $content = fread($fp, filesize($tmp_name)); $content = addslashes($content); - fclose($fp); - - $_query="INSERT INTO `images` VALUES('', '" . $user->data["user_id"] . "', '" . $content . "', '" . $file_type . "', ''" - . mysql_real_escape_string(htmlspecialchars($_POST["desc"])) "', '" . $width . "', '" . $height . ",'" . $file_name . "', '0');"; - $db->query($_query); - - $user->action(4, ''); - $message->thank('for uploading an image', 'go back to the previous page', 'javascript:history.go(\'-2\')'); - } - } - function login() - { - $step = empty($_GET["step"]) ? '1' : $_GET["step"]; - if($step == 1) - { - $form =& new template('forms/login.tpl'); - } - else - { - foreach($_POST as $key => $value) - { - $var[$key] = mysql_real_escape_string(htmlspecialchars($value)); - } - $_query = "SELECT `id` FROM `users` WHERE `email` = '" . $var['email'] . "' AND `password` = '" . md5($var['password']) . "'"; - $_query = $db->query($_query); - $num = mysql_num_rows($_query); - if($num > 0) - { - $id = $db->fetch_array($_query); - $session->login($id['id']); - $message->thank('logging in', 'to return to the index', 'index.php'); - } - else - { - $error->general('Incorrect Details', print_r($var)); - } - } - } - function inbox() - { - $_query="SELECT `id`, `from`, `date`, `subject`, `read` FROM `private_messages` ORDER BY `id` DESC"; - $_query=$db->query($_query); - $i=0; - while($temp=$db->fetch_array($_query)) - { - $pm[$i] = array( - 'id' => $temp['id'], - 'from' => $session->get_username($temp['from']), - 'date' => $session->generate_timestamp($temp['date']), - 'subject' => $temp['subject'], - 'read' => $temp['read'] - ); - $i++; - } - $template =& new template('inbox.tpl'); - $template->set('pm', $pm); - } - function message(mysql_real_escape_string($id)) - { - $_query="SELECT * FROM `private_messages` WHERE `id`='" . $id . "'"; - $_query=$db->query($_query); - $arr=$db->fetch_array($_query); - $read =& new template('read.tpl'); - $read->set('from', $session->get_username($arr["from"])); - $read->set('date', $session->generate_timestamp($arr["date"])); - $read->set('subject', $arr["subject"]); - $read->set('message', $arr["message"]); - if($arr["read"] != '1') - { - $_query="UPDATE `private_messages` SET `read`='1' WHERE `id`='" . $id . "'"; - $db->query($_query); - } - } - function send() - { - $template =& new template('send.tpl'); - } - function send_process() - { - } -} -$profile =& new profile; -switch $_GET["mode"] -{ - case 'register': - $profile->register(); - break; - case 'edit': - $profile->edit(); - break; - case 'delete': - $profile->delete(); - break; - case 'pics': - $profile->pics(); - break; - case 'login': - $profile->login(); - break; - case 'inbox': - $profile->inbox(); - break; - case 'message': - $profile->message($_GET["id"]); - break; - case 'send': - $profile->send(); - break; - case 'send_process': - $profile->send_process(); - break; -} + fclose($fp); + + $_query="INSERT INTO `images` VALUES('', '" . $user->data["user_id"] . "', '" . $content . "', '" . $file_type . "', ''" + . mysql_real_escape_string(htmlspecialchars($_POST["desc"])) "', '" . $width . "', '" . $height . ",'" . $file_name . "', '0');"; + $db->query($_query); + + $user->action(4, ''); + $message->thank('for uploading an image', 'go back to the previous page', 'javascript:history.go(\'-2\')'); + } + } + /* + Function Name: login + Arguments: None + Purpose: log user in + */ + function login() + { + $step = empty($_GET["step"]) ? '1' : $_GET["step"]; + if($step == 1) + { + $form =& new template('forms/login.tpl'); + } + else + { + foreach($_POST as $key => $value) + { + $var[$key] = mysql_real_escape_string(htmlspecialchars($value)); + } + $_query = "SELECT `id` FROM `users` WHERE `email` = '" . $var['email'] . "' AND `password` = '" . md5($var['password']) . "'"; + $_query = $db->query($_query); + $num = mysql_num_rows($_query); + if($num > 0) + { + $id = $db->fetch_array($_query); + $session->login($id['id']); + $message->thank('logging in', 'to return to the index', 'index.php'); + } + else + { + $error->general('Incorrect Details', print_r($var)); + } + } + } + /* + Function Name: inbox + Arguments: none + Purpose: Diplsay user's PM inbox + */ + function inbox() + { + $_query="SELECT `id`, `from`, `date`, `subject`, `read` FROM `private_messages` ORDER BY `id` DESC"; + $_query=$db->query($_query); + $i=0; + while($temp=$db->fetch_array($_query)) + { + $pm[$i] = array( + 'id' => $temp['id'], + 'from' => $session->get_username($temp['from']), + 'date' => $session->generate_timestamp($temp['date']), + 'subject' => $temp['subject'], + 'read' => $temp['read'] + ); + $i++; + } + $template =& new template('inbox.tpl'); + $template->set('pm', $pm); + } + /* + Function Name: message + Arguments: (int) id -- Private message ID + Purpose: Display a private message + */ + function message(mysql_real_escape_string($id)) + { + $_query="SELECT * FROM `private_messages` WHERE `id`='" . $id . "'"; + $_query=$db->query($_query); + $arr=$db->fetch_array($_query); + $read =& new template('read.tpl'); + $read->set('from', $session->get_username($arr["from"])); + $read->set('date', $session->generate_timestamp($arr["date"])); + $read->set('subject', $arr["subject"]); + $read->set('message', $arr["message"]); + if($arr["read"] != '1') + { + $_query="UPDATE `private_messages` SET `read`='1' WHERE `id`='" . $id . "'"; + $db->query($_query); + } + } + /* + Function Name: send + Arguments: none + Purpose: Display a form to send a private message + */ + function send() + { + $template =& new template('send.tpl'); + } + /* + Function Name: send_process + Arguments: none + Purpose: Send a private message + */ + function send_process() + { + } +} +$profile =& new profile; +switch $_GET["mode"] +{ + case 'register': + $profile->register(); + break; + case 'edit': + $profile->edit(); + break; + case 'delete': + $profile->delete(); + break; + case 'pics': + $profile->pics(); + break; + case 'login': + $profile->login(); + break; + case 'inbox': + $profile->inbox(); + break; + case 'message': + $profile->message($_GET["id"]); + break; + case 'send': + $profile->send(); + break; + case 'send_process': + $profile->send_process(); + break; +} ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |