[Astrospaces-commits] SF.net SVN: astrospaces: [17] trunk
Brought to you by:
p3net
|
From: <p3...@us...> - 2007-07-28 17:23:55
|
Revision: 17
http://astrospaces.svn.sourceforge.net/astrospaces/?rev=17&view=rev
Author: p3net
Date: 2007-07-28 10:23:56 -0700 (Sat, 28 Jul 2007)
Log Message:
-----------
Say hello to the new codebase! :D
Added Paths:
-----------
trunk/blog.php
trunk/config.php
trunk/develop/
trunk/develop/schema.sql
trunk/functions/
trunk/functions/db.php
trunk/functions/session.php
trunk/functions/template.php
trunk/gallery.php
trunk/globals.php
trunk/group.php
trunk/images.php
trunk/index.php
trunk/install/
trunk/logs/
trunk/logs/errors.txt
trunk/profile.php
trunk/template/
trunk/template/drill.tpl
trunk/template/forms/
trunk/template/forms/gallery_comment.tpl
trunk/template/forms/login.tpl
trunk/template/forms/register.tpl
trunk/template/forms/upload_pic.tpl
trunk/template/gallery.tpl
trunk/template/home.tpl
trunk/template/inbox.tpl
trunk/template/messages/
trunk/template/messages/error.tpl
trunk/template/messages/thank.tpl
trunk/template/outer.tpl
trunk/template/read.tpl
trunk/template/send.tpl
trunk/viewspace.php
Added: trunk/blog.php
===================================================================
--- trunk/blog.php (rev 0)
+++ trunk/blog.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,21 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: blog.php 7 2007-07-27 20:05:38Z p3net.tech $
+*********************************************************/
+?>
\ No newline at end of file
Added: trunk/config.php
===================================================================
--- trunk/config.php (rev 0)
+++ trunk/config.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,8 @@
+<?php
+$db_info = array(
+ 'user' => '',
+ 'pass' => '',
+ 'host' => '',
+ 'name' => ''
+ );
+?>
\ No newline at end of file
Added: trunk/develop/schema.sql
===================================================================
--- trunk/develop/schema.sql (rev 0)
+++ trunk/develop/schema.sql 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,109 @@
+CREATE TABLE `users` (
+ `id` int(11) NOT NULL auto_increment,
+ `display_name` text NOT NULL,
+ `password` varchar(40) NOT NULL,
+ `join` date NOT NULL,
+ `last_login` date,
+ `time_offset` tinyint(2) NOT NULL,
+ `blurb` text NOT NULL,
+ `email` varchar(30) NOT NULL,
+ `aim` varchar(20),
+ `yim` varchar(20),
+ `jabber` varchar(20),
+ `irc` varchar(20),
+ `icq` varchar(20),
+ `live` varchar(20),
+ `user_image` int(11),
+ `clean_url` text,
+ `privacy` tinyint(1) NOT NULL default '0'
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `images` (
+ `id` int(11) NOT NULL auto_increment,
+ `owner` int(11) NOT NULL,
+ `content` MEDIUMBLOB NOT NULL,
+ `mime_type` varchar(15) NOT NULL,
+ `desc` text NOT NULL,
+ `width` int(4) NOT NULL,
+ `height` int(4) NOT NULL,
+ `name` text NOT NULL,
+ `views` int(6) NOT NULL
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `images_comments` (
+ `id` int(11) NOT NULL auto_increment,
+ `image` int(11) NOT NULL,
+ `time` date NOT NULL,
+ `author` int(11) NOT NULL,
+ `comment` text NOT NULL
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `blog` (
+ `id` int(11) NOT NULL auto_increment,
+ `title` text NOT NULL,
+ `date` date NOT NULL,
+ `content` text NOT NULL,
+ `author` int(11) NOT NULL,
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `blog_comments` (
+ `id` int(11) NOT NULL auto_increment,
+ `author` int(11) NOT NULL,
+ `body` text NOT NULL,
+ `time` date NOT NULL
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `friends` (
+ `party_1` int(11) NOT NULL,
+ `party_2` int(11) NOT NULL,
+ `accepted` int(1) NOT NULL,
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `actions` (
+ `time` date NOT NULL,
+ `who` int(11) NOT NULL,
+ `action` int(2) NOT NULL,
+ `for` int(11),
+)
+
+CREATE TABLE `groups` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` text NOT NULL,
+ `founder` int(11) NOT NULL,
+ `members` text NOT NULL,
+ `create_date` date NOT NULL
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `comments` (
+ `id` int(11) NOT NULL auto_increment,
+ `time` date NOT NULL,
+ `from` int(11) NOT NULL,
+ `to` int(11) NOT NULL,
+ `body` int(11) NOT NULL
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
+
+CREATE TABLE `sessions` (
+ `id` int(35) NOT NULL,
+ `user_id` int(11) NOT NULL,
+ `ip` varchar(12) NOT NULL,
+ `last_update` date NOT NULL
+ PRIMARY KEY(`id`)
+) TYPE=MyISAM;
+
+CREATE TABLE `private_messages` (
+ `id` int(11) NOT NULL auto_increment,
+ `to` int(11) NOT NULL,
+ `from` int(11) NOT NULL,
+ `date` time() NOT NULL,
+ `subject` text NOT NULL,
+ `message text NOT NULL,
+ `read` int(1) NOT NULL default 0
+ PRIMARY KEY(`id)
+) TYPE=MyISAM AUTO_INCREMENT = 1;
\ No newline at end of file
Added: trunk/functions/db.php
===================================================================
--- trunk/functions/db.php (rev 0)
+++ trunk/functions/db.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,59 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: db.php 7 2007-07-27 20:05:38Z p3net.tech $
+*********************************************************/
+$this =& new db;
+class db
+{
+ function db()
+ {
+ require_once('./../config.php');
+
+ $db = mysql_connect($db_info['host'], $db_info['user'], $db_info['pass']);
+ if(!$db)
+ {
+ $error->general('Could not Connect to Database', mysql_error());
+ }
+ else
+ {
+ if(!mysql_select_db($db_info['name']))
+ {
+ $error->general('Could not Select Database', mysql_error());
+ }
+ }
+ }
+ function query($query)
+ {
+ $query = mysql_query($query)
+ if(!$query)
+ {
+ $error->general('Could not query database', mysql_error());
+ }
+ return $query;
+ }
+ function fetch_array($query)
+ {
+ $query = mysql_fetch_array($query);
+ if(!$query)
+ {
+ $error$db->general('Could not fetch array from database', mysql_error());
+ }
+ return $query;
+}
+?>
\ No newline at end of file
Added: trunk/functions/session.php
===================================================================
--- trunk/functions/session.php (rev 0)
+++ trunk/functions/session.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,280 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: session.php 8 2007-07-27 20:56:25Z p3net.tech $
+*********************************************************/
+/********************************************************
+The name here is a bit of a misnomer. The session class
+handles all user-interaction related processes -- both
+interaction between user and server and interaction
+between user and user
+**********************************************************/
+class session
+{
+ function create()
+ {
+ /* We don't have a session and aren't logged in. Let's create it */
+ $id = md5(time() . rand(1,1000));
+ /* Check to make sure it's unique */
+ $_query="INSERT INTO `sessions` VALUES('" . $id . "', '-1', '" . $REMOTE_ADDR . "', '" . time() . "')";
+ $db->query($_query);
+ $_COOKIE["session_id"] = $id;
+ }
+ function check()
+ {
+ /* We need to check if a session exists by looking for the session cookie. If that's not there,
+ then we return false (since the user isn't logged in). We also match the IP */
+ $ip = $REMOTE_ADDR;
+ $_query = "SELECT * FROM `sessions` WHERE `ip` = '" . $ip . "'";
+ $res = $db->query($_query);
+ if(mysql_num_rows($res) == 0)
+ {
+ $session->create();
+ }
+ else
+ {
+ /* Get an array of our session info */
+ $res = $db->fetch_array($res);
+ if($res['id'] != $_COOKIE["session_id"])
+ {
+ $session->create();
+ }
+ else
+ {
+ foreach($res as $key => $value)
+ {
+ $user->data[$key] = $value;
+ }
+ /* Update our updated time */
+ $_query="UPDATE `sessions` SET `last_update` = '" . time() . "' WHERE `id` = '" . $user->data['id'] . "' LIMIT 1";
+ $db->query($_query);
+ }
+ }
+ /* We also need to get rid of users who haven't done anything in the last half-hour */
+ $_query = "DELETE * FROM `sessions` WHERE `last_update` < " . (time() - (60*30));
+ $db->query($_query);
+ }
+ function logged_in()
+ {
+ if($user->data['id'] != "-1")
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ function login($user_id)
+ {
+ $session->check();
+ if($session->logged_in())
+ {
+ /* Wait - what? */
+ $error->general("Already logged in", "Session already populated");
+ }
+ else
+ {
+ $_query = "UPDATE `sessions` SET `user_id` = '" . $user_id . "' WHERE `id` = '" . $_COOKIE["session_id"] . " LIMIT 1";
+ $db->query($_query);
+ /* Run the session check again. It'll make the row and populate $user->data */
+ $session->check();
+ }
+ }
+ function logout()
+ {
+ if($session->logged_in())
+ {
+ $_query = "UPDATE `sessions` SET `user_id` = '-1' WHERE `id` = '" . $user->data['id'] . "' AND `ip` = '" . $user->data['ip'] . "' LIMIT 1";
+ $db->query($_query);
+ $user->data = null;
+ }
+ else
+ {
+ $error->general('Not logged in', 'User ID = -1');
+ }
+ }
+ function is_friend($id)
+ {
+ if(!$user->logged_in())
+ {
+ return false;
+ }
+ else
+ {
+ $_query = "SELECT * FROM `friends` WHERE `party_1` = '" . $user->data['user_id'] . "' AND AND `party_2`='" . $id . "' AND `accepted`='1'";
+ $_query = $db->query($_query);
+ if(mysql_num_rows($_query) > 0)
+ {
+ return true;
+ }
+ else
+ {
+ $_query = "SELECT * FROM `friends` WHERE `party_2` = '" . $user->data['user_id'] . "' AND `party_1`='" . $id . "' AND `accepted`='1'";
+ $_query = $db->query($_query);
+ if(mysql_num_rows($_query) > 0)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ }
+ function action($action, $who="")
+ {
+ /*List of actions:
+ 1. Updated Space
+ 2. Left you a comment
+ 3. Left a comment on one of your pictures
+ 4. Uploaded a picture
+ 5. Added you as a friend
+ 6. New blog post
+ 7. Left you a comment on a blog post
+ 8. Joined a group
+ 9. Created a group */
+ $_query="INSERT INTO `actions` VALUES('" . time() . "', '" . $user->data['user_id'] . "', '" . $action . "', '" . $who . "')";
+ $db->query($_query);
+ return true;
+ }
+ function add_friend($id)
+ {
+ if(!$user->logged_in())
+ {
+ $error->general("Not logged in", "Add as friend");
+ }
+ else
+ {
+ if($user->is_friend($id))
+ {
+ $error->general("Already friend", "Add as friend");
+ }
+ else
+ {
+ $_query = "SELECT * FROM `friends` WHERE `party_1`='" . $user->data['user_id'] . " AND `party_2`='" . $id . "'";
+ $_query=$db->query($_query);
+ if(mysql_num_rows($_query) > 0)
+ {
+ $error->general("Already added as friend, awaiting acception", "Add as friend");
+ }
+ else
+ {
+ $_query = "SELECT * FROM `friends` WHERE `party_2`='" . $user->data['user_id'] . " AND `party_1`='" . $id . "'";
+ $_query=$db->query($_query);
+ if(mysql_num_rows($_query) > 0)
+ {
+ $error->general("User has already added you as a friend. Accept them in your friend control panel.", "Add as friend");
+ }
+ else
+ {
+ $_query="INSERT INTO `friends` VALUES('" . $user->data['user_id'] . "', '" . $id . "', '0'";
+ $db->query($_query);
+ $message->thank("adding this user as your friend. You will be alerted when they accept you as a friend.", "to go back", "javascript:history.go(-1)");
+ }
+ }
+ }
+ }
+ }
+ 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 can_view($id)
+ {
+ /*We're simply checking whether or not we have the permissions to view this space */
+ /*First we need to figure out what the space privacy setting is*/
+ $_query="SELECT `privacy` FROM `users` WHERE `id`='" . $id . "' LIMIT 1";
+ $_query=$db->query($_query);
+ $_query=$db->fetch_array($_query);
+ $res=$_query['privacy'];
+ if($res == '0')
+ {
+ /*All users can view this space*/
+ return true;
+ }
+ else
+ {
+ /*We need to check if we're they're friend*/
+ if($session->is_friend($id))
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+ function add_comment($id)
+ {
+ if($session->is_friend($id))
+ {
+ /*Okay, we have permission to leave this comment*/
+ foreach($_POST as $key => $value)
+ {
+ $var[$key] = mysql_real_escape_string($value);
+ }
+ $_query="INSERT INTO `comments` VALUES('', '" . time() . "', '" . $user->data['user_id'] . "', '" . $id . "', '" . $var['body'] .
+ "'";
+ $db->query($_query);
+ $session->action('2', $id);
+ }
+ }
+ function get_username($id)
+ {
+ $_query="SELECT `display_name` FROM `users` WHERE `id`='" . $id . "'";
+ $_query=$db->query($_query);
+ $res=$db->fetch_array($_query);
+ return $res['display_name'];
+ }
+ function add_image_comment($id)
+ {
+ $owner = "SELECT `owner` FROM `images` WHERE `id`='" . $id . "'";
+ $owner = $db->query($owner);
+ $owner = $db->fetch_array($owner);
+ $owner = $owner['owner'];
+ if($session->is_friend($owner)
+ {
+ foreach($_POST as $key => value)
+ {
+ $var[$key] = mysql_real_escape_string($value);
+ }
+ $_query="INSERT INTO `image_comments` VALUES('', '" . $id . "', '" . time() . "', '" . $user->data['user_id'] . "', '" . $var['comment'] . "'";
+ $db->query($_query);
+ }
+ }
+ function generate_timestamp($time)
+ {
+ if($session->logged_in())
+ {
+ $_query="SELECT `time_offset` FROM `users` WHERE `id`='" . $user->data['user_id'] . "'";
+ $_query=$db->query($_query);
+ $_query=$db->fetch_array($_query);
+ $offset=$_query['time_offset'];
+
+ $diff = $offset * 60 * 60;
+ }
+ $time = $time + $diff;
+ return date('m/d/Y G:i:s', $time);
+ }
+}
+?>
\ No newline at end of file
Added: trunk/functions/template.php
===================================================================
--- trunk/functions/template.php (rev 0)
+++ trunk/functions/template.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,50 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: template.php 7 2007-07-27 20:05:38Z p3net.tech $
+*********************************************************/
+$this =& new template;
+class template
+{
+ function template($file=null)
+ {
+ $this->$file = $file;
+ }
+ function set($name, $value)
+ {
+ $this->vars[$name] = is_object($value) ? $value->fetch() : $value;
+ }
+ function fetch($file = null)
+ {
+ if(!$file) $file = $this->file;
+
+ extract($this->vars);
+ ob_start();
+ include('../template/' . $file);
+ $contents = ob_get_contents();
+ ob_end_clean();
+ return $contents;
+ }
+ function parse($content)
+ {
+ $head =& new template('outer.tpl');
+ $head->set('title', $title);
+ $head->set('content', $content);
+ }
+}
+?>
\ No newline at end of file
Added: trunk/gallery.php
===================================================================
--- trunk/gallery.php (rev 0)
+++ trunk/gallery.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,115 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: gallery.php 8 2007-07-27 20:56:25Z p3net.tech $
+*********************************************************/
+class gallery
+{
+ function view($id)
+ {
+ if($id == 0)
+ {
+ $error->general('Must be logged in!', 'Tried to access gallery as owner while unauthenticated');
+ }
+ else
+ {
+ if($session->is_friend($id))
+ {
+ $_query="SELECT `id` FROM `images` WHERE `owner`='" . $id . "'";
+ $_query=$db->query($_query);
+ $_query=$db->fetch_array($_query);
+ $gallery =& new template('gallery.tpl');
+ $gallery->set('gallery', $_query);
+ }
+ }
+ }
+ function drill($img_id, $owner)
+ {
+ if(empty($img_id))
+ {
+ $error->general('An image must be specified', 'Tried to access drill without specifying image id');
+ }
+ else
+ {
+ if($session->is_friend($owner))
+ {
+ $_query = "SELECT * FROM `images` WHERE `id`='" . $img_id . "'";
+ $img = $db->query($_query);
+
+ $_query = "SELECT * FROM `images_comments` WHERE `image`='" . $img_id . "'";
+ $img_com = $db->query($_query);
+
+ foreach($db->fetch_array($img_com) as $key => value)
+ {
+ foreach($value as $key_name => $key_value)
+ {
+ if($key_value == 'author')
+ {
+ $key_value = $session->get_username($key_value);
+ }
+ $com[$key_name] = $key_value;
+ }
+ }
+ $img=$db->fetch_array($img);
+ if(isset($user->data['user_id'] && $user->data['user_id'] != $img['owner'])
+ {
+ $img['views']++;
+ $_query="UPDATE `images` SET `views`='" . $views . "' WHERE `id`='" . $img_id . "'";
+ $db->query($_query);
+ }
+ $drill =& new template('drill.tpl');
+ $drill->set('id', $img_id);
+ $drill->set('comments', $com);
+ $drill->set('views', $img['views']);
+ $drill->set('desc', $img['desc']);
+ $drill->set('name', $img['name']);
+ }
+ }
+ }
+ function comment($id, $owner)
+ {
+ if($session->is_friend($owner))
+ {
+ $form =& new template('forms/gallery_comment.tpl');
+ }
+ }
+ function comment_process()
+ {
+ $img_id=$_POST["id"];
+ $session->add_image_comment($img_id);
+ }
+}
+$gallery =& new gallery;
+$mode = empty($_GET["mode"]) ? 'view' : $_GET["mode"];
+$id = empty($_GET["id"]) ? ($session->logged_in() ? $user->data['user_id'] : 0) : mysql_real_escape_string($_GET["id"]);
+switch $mode
+{
+ case 'view':
+ $gallery->view($id);
+ break;
+ case 'drill':
+ $gallery->drill(mysql_real_escape_string($_GET["img"]), $id);
+ break;
+ case 'comment':
+ $gallery->comment($id, $owner_id);
+ break;
+ case 'process':
+ $gallery->comment_process();
+ break;
+}
+?>
\ No newline at end of file
Added: trunk/globals.php
===================================================================
--- trunk/globals.php (rev 0)
+++ trunk/globals.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,63 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: globals.php 6 2007-07-27 19:03:49Z p3net.tech $
+*********************************************************/
+/* Include our larger functions */
+require_once('./functions/db.php');
+require_once('./functions/template.php');
+require_once('./session.php');
+
+/*The smaller ones*/
+class error
+{
+ function general($err, $verbose)
+ {
+ $error =& new template('messages/error.tpl');
+ $error->set('err', $err);
+ $handle = fopen('logs/errors.txt', 'w');
+ if($handle)
+ {
+ $entry = "[" . date('d M Y H:i:s') . "][" . $REMOTE_ADDR . "] " . $err . " - " . $verbose;
+ if(!fwrite($handle, $entry))
+ {
+ continue();
+ }
+ }
+ fclose($handle);
+ exit();
+ }
+}
+function message
+{
+ function thank($message, $go1, $res1, $go2="", $res2="")
+ {
+ $message =& new template('message/thank.tpl');
+ $message->set('go1', $go1);
+ $message->set('go2', $go2);
+ $message->set('res1', $res1);
+ $message->set('res2', $res2);
+ $message->set('message', $message);
+ }
+}
+$error =& new error;
+$db =& new db;
+$template =& new template;
+$user =& new session();
+$message =& new message();
+?>
\ No newline at end of file
Added: trunk/group.php
===================================================================
--- trunk/group.php (rev 0)
+++ trunk/group.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,21 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: group.php 7 2007-07-27 20:05:38Z p3net.tech $
+*********************************************************/
+?>
\ No newline at end of file
Added: trunk/images.php
===================================================================
--- trunk/images.php (rev 0)
+++ trunk/images.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,110 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: images.php 5 2007-07-26 23:43:48Z p3net.tech $
+*********************************************************/
+include('globals.php');
+class image
+{
+ function full($id)
+ {
+ $id = is_numeric($_GET["id"]) ? $_GET["id"] : null;
+ if(empty($id))
+ {
+ $error->general("Invalid ID specified", "Not an (int)");
+ }
+ $_query = "SELECT * FROM `images` WHERE `id`='" . $id . "'";
+ $img=$db->fetch_array($db->query($_query));
+
+ header('Content-type: ' . $img['mine_type']);
+ header('Content-Disposition: attachment; filename=' . $img['name']);
+ echo $img['content'];
+ }
+ function thumb($id)
+ {
+ $id = is_numeric($_GET["id"]) ? $_GET["id"] : null;
+ if(empty($id))
+ {
+ $error->general("Invalid ID specified", "Not an (int)");
+ }
+ $_query = "SELECT * FROM `images` WHERE `id`='" . $id . "'";
+ $img=$db->fetch_array($db->query($_query));
+
+ /* We're going to resize the larger dimension to 150px */
+ if($img['width'] > $img['height'])
+ {
+ $scale_percentage = $img['width'] / 150;
+ }
+ else
+ {
+ $scale_percentage = $img['height'] / 150;
+ }
+ $new_dimensions = array(
+ 'width' => ($scale_percentage < 1) ? $img['width'] * $scale_percentage : $img['width'],
+ 'height' => ($scale_percentage < 1) ? $img['height'] * $scale_percentage : $img['height']
+ );
+ header('Content-type: ' . $img['mine_type']);
+ header('Content-Disposition: attachment; filename=' . $img['name']);
+
+ $type = explode("/", $img['mine_type']);
+ $type = $type[1];
+ switch $type
+ {
+ case 'jpeg':
+ $new_image = imagecreatefromjpeg($img['content']);
+ break;
+ case 'png':
+ $new_image = imagecreatefrompng($img['content']);
+ break;
+ case 'gif':
+ $new_image = imagecreatefromgif($img['content']);
+ break;
+ }
+ $res = imagecreatetruecolor($new_dimensions['width'], $new_dimensions['height']);
+ imagecopyresized($res, $new_image, 0, 0, 0, 0, $new_dimensions['width'], $new_dimensions['height'], $img['width'], $img['height']);
+
+ switch $type
+ {
+ case 'jpeg':
+ imagejpeg($res);
+ break;
+ case 'png':
+ imagepng($res);
+ break;
+ case 'gif':
+ imagegif($res);
+ break;
+ }
+ }
+}
+
+$this =& new image;
+
+/* Actually handle the data here */
+$mode=$_GET["mode"];
+switch $mode
+{
+ case 'view':
+ $this->full();
+ break;
+
+ case 'thumb':
+ $this->thumb();
+ break;
+}
+?>
\ No newline at end of file
Added: trunk/index.php
===================================================================
--- trunk/index.php (rev 0)
+++ trunk/index.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,34 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: index.php 5 2007-07-26 23:43:48Z p3net.tech $
+*********************************************************/
+include('globals.php');
+/* 5 most recent users should be enough. We can fill the rest with ads or something */
+$_query = "SELECT `id`, `display_name`, `user_image` FROM `users` SORT BY `id` DESC LIMIT 5";
+$res = ($db->query($_query);
+while($user = $db->fetch_array($_query))
+{
+ $userdetail[$user['display_name']] = array(
+ 'id' => $user['id'],
+ `icon` => $user['user_image']
+ );
+}
+$index =& new template('home.tpl');
+$index->set('userdetail', $userdetail);
+?>
\ No newline at end of file
Added: trunk/logs/errors.txt
===================================================================
Added: trunk/profile.php
===================================================================
--- trunk/profile.php (rev 0)
+++ trunk/profile.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,190 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: profile.php 8 2007-07-27 20:56:25Z p3net.tech $
+*********************************************************/
+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");
+ }
+ $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");
+
+ $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;
+}
+?>
\ No newline at end of file
Added: trunk/template/drill.tpl
===================================================================
Added: trunk/template/forms/gallery_comment.tpl
===================================================================
Added: trunk/template/forms/login.tpl
===================================================================
--- trunk/template/forms/login.tpl (rev 0)
+++ trunk/template/forms/login.tpl 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,4 @@
+<form action="profile.php?mode=login&step=2" method="post">
+Email Address: <input type="text" name="email"> <br />
+Password: <input type="password" name="password"><br />
+</form>
\ No newline at end of file
Added: trunk/template/forms/register.tpl
===================================================================
Added: trunk/template/forms/upload_pic.tpl
===================================================================
--- trunk/template/forms/upload_pic.tpl (rev 0)
+++ trunk/template/forms/upload_pic.tpl 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,4 @@
+<form action="profile.php?mode=pics&step=2" method="post">
+Picture: <input type="file" name="pic"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><br />
+Description: <textarea rows="4" cols="60" name="desc"></textarea><br />
+</form>
\ No newline at end of file
Added: trunk/template/gallery.tpl
===================================================================
Added: trunk/template/home.tpl
===================================================================
--- trunk/template/home.tpl (rev 0)
+++ trunk/template/home.tpl 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,7 @@
+<!-- New Members -->
+<?php
+foreach($userdetail as $key => $value)
+{
+ echo "<img src=\"images.php?mode=thumb&id=" . $value['user_image'] . "\" /><br /><a href=\"&id=" . $value['id'] . "\">" . $key . "</a>";
+}
+?>
\ No newline at end of file
Added: trunk/template/inbox.tpl
===================================================================
Added: trunk/template/messages/error.tpl
===================================================================
--- trunk/template/messages/error.tpl (rev 0)
+++ trunk/template/messages/error.tpl 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,2 @@
+<b>General Error</b> - <?php echo $err; ?><br /><br />
+This error and debugging information has been written to the error log. If it continues, please <a href="mailto:">contact the administrator</a>.
\ No newline at end of file
Added: trunk/template/messages/thank.tpl
===================================================================
--- trunk/template/messages/thank.tpl (rev 0)
+++ trunk/template/messages/thank.tpl 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,3 @@
+<b>Thank you <?php echo $message; ?></b><br /><br />
+<a href="<?php echo $go1; ?>">Click here</a> <?php echo $res1; ?><br />
+<?php if(!empty($go2)) { ?> <a href="<?php echo $go2; ?>">Click here</a><?php echo $res2; ?></br ><?php } ?>
\ No newline at end of file
Added: trunk/template/outer.tpl
===================================================================
--- trunk/template/outer.tpl (rev 0)
+++ trunk/template/outer.tpl 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>Project Orange | <?php echo $title; ?></title>
+ </head>
+ <body>
+ <?php echo $contents; ?>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/template/read.tpl
===================================================================
Added: trunk/template/send.tpl
===================================================================
Added: trunk/viewspace.php
===================================================================
--- trunk/viewspace.php (rev 0)
+++ trunk/viewspace.php 2007-07-28 17:23:56 UTC (rev 17)
@@ -0,0 +1,23 @@
+<?php
+/*******************************************************
+ * Copyright (C) 2007 http://p3net.net
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ 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: viewspace.php 7 2007-07-27 20:05:38Z p3net.tech $
+*********************************************************/
+/* Todo: If no id is set or id is yours, show you owner view instead
+ Alternatively, actual view will be shown if &view=real is appended*/
+?>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|