astrospaces-commits Mailing List for AstroSPACES
Brought to you by:
p3net
You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
(13) |
Apr
|
May
|
Jun
|
Jul
(65) |
Aug
(21) |
Sep
(3) |
Oct
|
Nov
|
Dec
|
---|
From: <del...@us...> - 2007-09-17 01:05:06
|
Revision: 104 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=104&view=rev Author: deltalabs Date: 2007-09-16 18:05:07 -0700 (Sun, 16 Sep 2007) Log Message: ----------- I finished viewspace.php, I think. Let me know if anything is missing. Modified Paths: -------------- trunk/viewspace.php Modified: trunk/viewspace.php =================================================================== --- trunk/viewspace.php 2007-09-04 00:40:20 UTC (rev 103) +++ trunk/viewspace.php 2007-09-17 01:05:07 UTC (rev 104) @@ -66,7 +66,24 @@ $viewspace->parse_slice_to_parent('static_private_details'); // Output all dynamic fields/values + $_query = 'SELECT dynamic_profile_field_id FROM ' . AS_TBL_DYNPROFFIELD; + $_query = $db->Execute($_query); + $dynfields = $db->GetArray($_query); + foreach ($dynfields as $dynfield) + { + $_query = 'SELECT field_name,field_value FROM ' . AS_TBL_DYNPROFVAL . + ' WHERE user_id = ' . $_GET["uid"] . ' AND dynamic_profile_field_id = ' . $dynfield['dynamic_profile_field_id']; + $_query = $db->Execute($_query); + $dynvalue = $db->FetchRow($_query); + + $viewspace->define_var('dynamic_field_name', $dynvalue['field_name']); + $viewspace->define_var('dynamic_field_value', $dynvalue['field_value']); + + $viewspace->parse_slice_to_parent('dynamic_detail'); + } + unset($dynfield); + $viewspace->parse_slice_to_parent('dynamic_private_details'); $viewspace->pparse(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-09-04 00:40:20
|
Revision: 103 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=103&view=rev Author: deltalabs Date: 2007-09-03 17:40:20 -0700 (Mon, 03 Sep 2007) Log Message: ----------- Modified Paths: -------------- trunk/config.php trunk/viewspace.php Property Changed: ---------------- trunk/ Property changes on: trunk ___________________________________________________________________ Name: svn:ignore + viewspace-backup.php Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-09-03 04:56:22 UTC (rev 102) +++ trunk/config.php 2007-09-04 00:40:20 UTC (rev 103) @@ -23,24 +23,26 @@ be altered. Doing so will prevent AstroSPACES from functioning. */ -define('AS_TBL_USERS', AS_DB_PREFIX.'users'); -define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); -define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); -define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); -define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); -define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); -define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); -define('AS_TBL_IMG', AS_DB_PREFIX.'images'); -define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); -define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); -define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); -define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); -define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); -define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); -define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); -define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); -define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); -define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); +define('AS_TBL_USERS', AS_DB_PREFIX.'users'); +define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); +define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_DYNPROFFIELD', AS_DB_PREFIX.'dynamic_profile_fields'); +define('AS_TBL_DYNPROFVAL', AS_DB_PREFIX.'dynamic_profile_values'); +define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); +define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); +define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); +define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); +define('AS_TBL_IMG', AS_DB_PREFIX.'images'); +define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); +define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); +define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); +define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); +define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); +define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); +define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); +define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); +define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); define('AS_DIR_TPL', 'template/'); define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); Modified: trunk/viewspace.php =================================================================== --- trunk/viewspace.php 2007-09-03 04:56:22 UTC (rev 102) +++ trunk/viewspace.php 2007-09-04 00:40:20 UTC (rev 103) @@ -18,78 +18,57 @@ @id: $Id$ *********************************************************/ +/* I'm completely rewriting this. I do have a backup of the old version if it's needed, but I'm not committing it. */ include('./globals.php'); -class space -{ - /* Function Name: view - Arguments: (int) id -- Space ID to view - Description: View a Space - */ - function view($id) - { - if($user->can_view($id)) - { - $_query = "SELECT * FROM " . AS_TBL_USER . " WHERE `id`='" . $id . "'"; - $db->Execute($_query); - $arr = $db->FetchArray(); - - if(isset($db->user['user_id']) && $db->user['user_id'] == $id) - { - $_query = "SELECT * FROM " . AS_TBL_CMT . " WHERE `recipient_id`='" . $id . "'"; - $db->Execute($_query); - $comments = $db->FetchArray(); - - /* We need to rewrite this to JOIN with the friends table so we can get all - non-specific notifications from our friends */ - $_query = "SELECT * FROM " . AS_TBL_ACTION . " WHERE `for`='" . $id . "'"; - $db->Execute($_query); - $notifications = $db->FetchArray(); - } - else - { - /* Stop -- comment count! */ - $_query="SELECT COUNT(*) FROM " . AS_TBL_CMT . " WHERE `recipient_id`='" . $id . "'"; - $db->Execute($_query); - $comm_count = $db->FetchArray(); - $comm_count = $comm_count['COUNT(*)']; - } - $viewspace =& new template('viewspace.tpl'); - $viewspace->set('user_info', $arr); - /* These two are only displayed if you are the space owner */ - $viewspace->set('owner_comments', (isset($comments) ? $comments : '')); //If empty, do NOT reference comments - $viewspace->set('notifications', (isset($notifications) ? $notications : '')); //If empty, do NOT reference notifications. - /* This one is not displayed if you are the space owner */ - $viewspace->set('comm_count', (isset($comm_count) ? $comm_count : '')); //Display only if comment array is empty - } - else - { - /* Show limited page (username, default picture for user, and add as friend button if logged in */ - } - } -} -$mode = empty($_GET["mode"]) ? 'view' : $_GET["mode"]; -/* Since I can't get this to work as a ternary */ -if(empty($_GET["id"])) -{ - if($user->logged_in()) - { - $id = $user->data['id']; - } - else - { - $error->general('No ID specified', 'Empty'); -} -else -{ - $id = $_GET["id"]; -} -/* Okay, now that that is over with... */ -} -switch($mode) -{ - case 'view': - $space->view($id); - break; -} -?> \ No newline at end of file +if (isset($_GET["uid"])) { + if (!$user->logged_in() || $user->can_view($user->data['id'])) { + $_query = 'SELECT display_name,user_image,blurb FROM '.AS_TBL_STATIC_PROFILE_FIELDS.' WHERE static_profile_field_id = ' . $_GET["uid"]; + $_query = $db->Execute($_query); + $res = $db->GetArray($_query); + + $static_user_details = $_query->FetchRow(); + + $viewspace = template(AS_TPL.'viewspace.tpl'); + + $viewspace->define_var('display_name', $static_user_details['display_name']); + $viewspace->define_var('user_image', $static_user_details['user_image']); + $viewspace->define_var('blurb', $static_user_details['blurb']); + + $viewspace->parse_slice_to_parent('public_details'); + + $viewspace->pparse(); + } + else + { + $_query = 'SELECT display_name,user_image,blurb,aim,yim,jabber,irc,icq,msn FROM '. + AS_TBL_STATIC_PROFILE_FIELDS.' WHERE user_id = ' . $_GET["uid"]; + $_query = $db->Execute($_query); + $static_user_details = $db->FetchRow($_query); + + $static_user_details = $_query->FetchRow(); + + $viewspace = template(AS_TPL.'viewspace.tpl'); + + $viewspace->define_var('display_name', $static_user_details['display_name']); + $viewspace->define_var('user_image', $static_user_details['user_image']); + $viewspace->define_var('blurb', $static_user_details['blurb']); + + $viewspace->parse_slice_to_parent('public_details'); + + $viewspace->define_var('aim', $static_user_details['aim']); + $viewspace->define_var('yim', $static_user_details['yim']); + $viewspace->define_var('jabber', $static_user_details['jabber']); + $viewspace->define_var('irc', $static_user_details['irc']); + $viewspace->define_var('icq', $static_user_details['icq']); + $viewspace->define_var('msn', $static_user_details['msn']); + + $viewspace->parse_slice_to_parent('static_private_details'); + + // Output all dynamic fields/values + + $viewspace->parse_slice_to_parent('dynamic_private_details'); + + $viewspace->pparse(); + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cal...@us...> - 2007-09-03 04:56:25
|
Revision: 102 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=102&view=rev Author: caleb870 Date: 2007-09-02 21:56:22 -0700 (Sun, 02 Sep 2007) Log Message: ----------- Updated the template system so that it now supports conditional. Also started on a generic template for testing. Modified Paths: -------------- trunk/config.php trunk/develop/template-example/test.tpl trunk/develop/template-example/tester.php trunk/functions/template.php trunk/globals.php Added Paths: ----------- trunk/template/default/header.tpl.htm trunk/template/default/index.tpl.htm trunk/template/default/style.css Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-08-18 22:04:27 UTC (rev 101) +++ trunk/config.php 2007-09-03 04:56:22 UTC (rev 102) @@ -14,9 +14,11 @@ define('AS_LANG', 'en-us'); define('AS_LOC_URL', 'http://localhost/'); -define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); +define('AS_LOC_DIRECT', 'C:/Program Files/xampp/htdocs/as/'); define('AS_LOC_CACHE', AS_LOC_DIRECT.'cache/'); +define('AS_SITENAME', 'AstroSPACES Beta'); + /* These settings are constants and must NOT be altered. Doing so will prevent AstroSPACES from functioning. Modified: trunk/develop/template-example/test.tpl =================================================================== --- trunk/develop/template-example/test.tpl 2007-08-18 22:04:27 UTC (rev 101) +++ trunk/develop/template-example/test.tpl 2007-09-03 04:56:22 UTC (rev 102) @@ -1,16 +1,17 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html lang="en"> +<!-- IF head --> <head> <title>[LANG:ERROR_MUST_BE_LOGGEDIN]</title> </head> +<!-- ENDIF head --> <body> <!-- INCLUDE 'header.tpl' --> -<!-- INCLUDE 'leftnav.tpl' --> - <h1>[LANG:BLOG_AUTHOR] Test page</h1> -<!-- START one --> + <h1>[LANG:BLOG_AUTHOR] Test page</h1><!-- START one --> + <div style="background-color: [color]; margin: 3px">[content]</div> <!-- START two --> - <b style="color: [color]">[two.bold] testing my [two.morez]</b> + <b style="color: [color]">[start] testing my [end].</b> <!-- END two --> <p color="green">[var]</p> <!-- START three --> Modified: trunk/develop/template-example/tester.php =================================================================== --- trunk/develop/template-example/tester.php 2007-08-18 22:04:27 UTC (rev 101) +++ trunk/develop/template-example/tester.php 2007-09-03 04:56:22 UTC (rev 102) @@ -3,18 +3,21 @@ $time = microtime(); include '../../functions/template.php'; $tpl = new tpl_base('test.tpl','tester.cache',5); -$tpl->load_lang_file('../../lang/en/lang_main.php'); -$tpl->compile_slices(); - +if ($tpl->compiled === false) +{ + echo 'Not compiled<br />'; + $tpl->load_lang_file('../../lang/en/lang_main.php'); + $tpl->compile(); +} +$tpl->show('head'); +$tpl->define('color','#AABBBB','one'); +$tpl->define('content','Even more sample content.. Just can't get enough!','one'); $tpl->set(array('address' => '123 Sample Street NW')); -$tpl->set_multi(array(array('two.bold' => 'Just', 'two.morez' => ' script <br />'),array('two.bold' => 'Im', 'two.morez' => ' pie.', 'color' => ' red')),'two'); -//echo "<a href=\"http://www.deltalabs.net/othercrap/musicsample.zip\">CLICK ME</a>"; -//$tpl-> -$tpl->parse_slice_to_parent('one'); -//print_r($tpl->slices); +$tpl->set_multiple(array(array('start' => 'Just', 'end' => 'script', 'color' => '#0000AA'), + array('start' => 'And', 'end' => 'template', 'color' => '#AAAAAA')),'two'); +$tpl->parse_to_parent('one'); $tpl->pparse(); $tpl->finish(); -//print_r($tpl->slices); echo microtime() - $time; ?> \ No newline at end of file Modified: trunk/functions/template.php =================================================================== --- trunk/functions/template.php 2007-08-18 22:04:27 UTC (rev 101) +++ trunk/functions/template.php 2007-09-03 04:56:22 UTC (rev 102) @@ -1,6 +1,6 @@ <?php /******************************************************* - * Copyright (C) 2007 http://p3net.net + * Copyright (C) 2007 http://deltalabs.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 @@ -29,92 +29,112 @@ define('TPL_INCLUDE', '\<\!--\s*INCLUDE\s*\'%s\'\s*--\>'); define('TPL_SLICE_START', '\<\!--\s*START\s+%s\s*--\>'); define('TPL_SLICE_END', '\<\!--\s*END\s+%s\s*--\>'); +define('TPL_COND_FINDER', '[a-zA-Z0-9_.-]+'); +define('TPL_COND_START', '\<\!--\s*IF\s+%s\s*--\>'); +define('TPL_COND_END', '\<\!--\s*ENDIF\s+%s\s*--\>'); -class tpl_base { +class cobalt_tpl { - var $slices; - var $lang; - + var $slices; // Holds slices variables and templates. + var $lang; // Holds language variables var $slice_array; // System-only variable - var $tpl_folder; - var $tpl_file; - var $cache_file; - var $cache_life; - var $cache_age; + var $compiled; // Boolean of wether the slice has been compiled or not. + var $tpl_folder; // Folder where the template file is located. + var $tpl_file; // Template filename. + var $cache_file; // Cache filename. + var $cache_life; // Lifespan of the cache before it expires. + var $booleans; // Holds the booleans of what conditional blocks should + // be parsed and which ones shouldn't. var $cache_exists = false; - function tpl_base($file, $cache_to, $cache_life = 600) + /* =========================== + COMPILATION FUNCTIONS + =========================== */ + + function cobalt_tpl( $file, $cache_to = null, $cache_life = 600 ) { $this->tpl_folder = dirname($file).'/'; $this->tpl_file = $file; $this->cache_file = $cache_to; $this->cache_life = $cache_life; + $this->compiled = false; - if (isset($cache_to)) + /* Caching is disabled if the second parameter is NULL */ + if (isset($cache_to) or $cache_life === 0) { - $cache_age = @filemtime($cache_to); - $this->cache_age = $cache_age; - if ($cache_age === false) + $age = @filemtime( AS_LOC_CACHE.$cache_to ); + if ( $age === false ) { + /* If cache doesn't exist. */ $this->cache_exists = false; return $this->load_from_file($file); } - elseif (time() - $cache_life < $cache_age or $cache_life === 0) + elseif (time() - $cache_life < $age or $cache_life === 0) { - $content = file( $cache_to ); - if ($content === false) + /* If cache exists and hasn't expired */ + $cache = file( AS_LOC_CACHE.$cache_to ); + if ($cache === false) { return false; } $this->cache_exists = true; - $cache = unserialize(implode(null,$content)); - $this->slices = $cache->slices; - $this->lang = $cache->lang; - echo "cache exists<br />"; + $cache = unserialize( implode( null, $cache ) ); + + /* Transfering cached data into the current template object */ + $this->slices = $cache->slices; + $this->slice_array = $cache->slice_array; + $this->lang = $cache->lang; + $this->compiled = true; return true; } - elseif ($cache_age != false) + elseif ($age != false) { + /* If the cache exists, but expired. */ $this->cache_exists = false; - return $this->load_from_file($file); + return $this->load_from_file( $file ); } } - + /* If caching is disabled */ $this->cache_exists = true; return $this->load_from_file($file); - } + } function load_from_file ( $file ) { @$content = file( $file ); if ($content === false) { - return false; + return false; // Loading failed } else { $this->load(implode(null,$content)); - return true; + return true; // Loading completed successfully. } } function load( $template ) { - $template = $this->include_files($template); - $this->slices['root'] = new tpl_slice( $template ); + /* Includes references to other template files */ + $this->slices['root']['template'] = $this->include_files($template); + + /* Searches for all the slices in the template */ $regex = '/'.sprintf(TPL_SLICE_START,'('.TPL_SLICE_FINDER.')').'/smiU'; preg_match_all($regex, $template, $slice_array); $this->slice_array = $slice_array[1]; } - function include_files($template) + function include_files( $template ) { + // Searches for all the inclusion statements in the template. preg_match_all('/'.sprintf(TPL_INCLUDE, '(.*)').'/smU', $template, $files); - if (count($files) === 0) return; + // If there are no inclusion statements, just return. + if ( count($files) === 0 ) return true; - foreach ($files[1] as $file) + // Replaces all inclusion statements with the template specified. + foreach ( $files[1] as $file ) { @$content = file( $this->tpl_folder.$file ); if ($content === false) @@ -123,12 +143,12 @@ } else { $content = implode(null,$content); } - $regex = '/'.sprintf(TPL_INCLUDE, str_replace('/','\/',preg_quote($file))).'/sm'; $template = preg_replace($regex, $content, $template); } - if (preg_match('/'.sprintf(TPL_INCLUDE, '(.*)').'/sm', $template, $files)) + // Checks for any inclusion statements missed. + if ( preg_match('/'.sprintf(TPL_INCLUDE, '(.*)').'/sm', $template, $files) ) { $template = $this->include_files($template); } @@ -139,6 +159,7 @@ { if ($this->cache_exists === false) { + // Load language variables @$array = include($filename); if ($array != false) { @@ -149,23 +170,26 @@ } } - function determine_parent( $name ) // System-only function. No longer usable after compile_slices(). + function determine_parent( $name ) // System-only function. { $name_reg = preg_quote( $name ); - if (count($this->slice_array) === 0) return 'root'; - foreach ($this->slice_array as $slice) + if ( count($this->slice_array) === 0) return 'root'; + // Iterates through every slice finding the parent slice for each slice. + foreach ( $this->slice_array as $slice ) { $slice_reg = preg_quote($slice); $regex = '/'.sprintf(TPL_SLICE_START,$slice_reg).'(?:.*)'.sprintf(TPL_SLICE_START,$name_reg).'(?:.*)'.sprintf(TPL_SLICE_END,$slice_reg).'/sm'; - if (preg_match($regex, $this->slices['root']->template, $results)) + if (preg_match($regex, $this->slices['root']['template'], $results)) $array[$slice] = strlen($results[0]); } - if (count($array) === 0) return 'root'; - foreach ($array as $slice_name => $number) + if ( count($array) === 0) return 'root'; + // Iterates through every slice the slice is within, the one with the + // least amount of data is the parent. + foreach ( $array as $slice_name => $number ) { - if (isset($biggest_num)) + if ( isset($biggest_num) ) { if ($number < $biggest_num) { @@ -181,96 +205,207 @@ return $biggest_slice; } - function compile_slices () + function compile () { // Parse every language variable. - if (!empty($this->lang)) + if ( !empty($this->lang) ) { foreach ($this->lang as $name => $value) { - $this->slices['root']->template = str_replace(sprintf(TPL_VAR,TPL_LANG_PRE.$name), $value, $this->slices['root']->template); + $this->slices['root']['template'] = str_replace(sprintf(TPL_VAR,TPL_LANG_PRE.$name), $value, $this->slices['root']['template']); } } // Find all the slices in the template and make them into tpl_slice objects. $regex = '/'.sprintf(TPL_SLICE_END,'(.*)').'/smiU'; - preg_match_all( $regex, $this->slices['root']->template, $sub_slices); + preg_match_all( $regex, $this->slices['root']['template'], $sub_slices); $slices = $sub_slices[1]; - foreach ($slices as $slice) + foreach ( $slices as $slice ) { // Assemble the slice object $regex = '/'.sprintf(TPL_SLICE_START,$slice).'(.*)\r\n\s*'.sprintf(TPL_SLICE_END,$slice).'\s*\r?\n?/si'; - preg_match($regex, $this->slices['root']->template, $resultset); + preg_match($regex, $this->slices['root']['template'], $resultset); if (count($resultset) > 0) { - $this->slices[$slice] = new tpl_slice($resultset[1]); - $this->slices[$slice]->parent = $this->determine_parent(preg_quote($slice)); - $this->slices['root']->template = preg_replace($regex, sprintf(TPL_VAR,TPL_SLICE_PRE_REG.$slice)."\r\n", $this->slices['root']->template); + $this->slices[$slice]['template'] = $resultset[1]; + $this->slices[$slice]['parent'] = $this->determine_parent(preg_quote($slice)); + $this->slices['root']['template'] = preg_replace($regex, sprintf(TPL_VAR,TPL_SLICE_PRE_REG.$slice)."\r\n", $this->slices['root']['template']); } } + + + reset($this->slices); + // Generates a list of conditional statements in each slice. + while ( $slice = key($this->slices) ) + { + $regex = '/'.sprintf(TPL_COND_END,'('.TPL_COND_FINDER.')').'/s'; + preg_match_all($regex, $this->slices[$slice]['template'], $results); + + if ( !empty($results[1]) ) + { + foreach( $results[1] as $result ) + { + $this->slices[$slice]['conditionals'][$result] = true; + } + } + next($this->slices); + } + $this->slice_array[] = 'root'; + $this->compiled = true; + } + + /* =========================== + DECLARATION FUNCTIONS + =========================== */ + + function define( $name, $value, $slice = 'root' ) + { + $this->slices[$slice]['vars'][$name] .= $value; } - function set($var_array, $slice_name = 'root') + function set( $array, $slice = 'root' ) { - foreach ($var_array as $name => $value) + foreach ($array as $name => $value) { - $this->slices[$slice_name]->vars[$name] = $value; + $this->slices[$slice]['vars'][$name] .= $value; } } - function set_multi($var_array, $slice_name = 'root') + function set_multiple( $array, $slice = 'root' ) { - if ($slice_name == 'root') + if ($slice == 'root') { - foreach ($var_array as $id => $vars) + foreach ( $array as $id => $vars ) { - foreach ($vars as $name => $value) + foreach ( $vars as $name => $value ) { - $this->slices[$slice_name]->vars[$name] = $value; + $this->slices['root']['vars'][$name] .= $value; } - $this->pparse(false); + $this->pparse(); } } else { - foreach ($var_array as $id => $vars) + foreach ($array as $id => $vars) { - foreach ($vars as $name => $value) + foreach ( $vars as $name => $value ) { - $this->slices[$slice_name]->vars[$name] = $value; + $this->slices[$slice]['vars'][$name] .= $value; } - $this->slices[$this->slices[$slice_name]->parent]->define(TPL_SLICE_PRE.$slice_name, $this->slices[$slice_name]->parse()); + $this->parse_to_parent($slice); } } } - function parse_slice_to_parent ( $slice_name ) + function set_global( $name, $value ) { - $parent = $this->slices[$slice_name]->parent; - $root_var_name = TPL_SLICE_PRE.$slice_name; - $content = $this->slices[$slice_name]->parse(); - $this->slices[$parent]->define($root_var_name, $content); - return $parsed_result; + foreach ( $this->slice_array as $slice ) + { + $this->slices[$slice]['vars'][$name] = $value; + } } + + function global_burn ( $name, $value ) + { + foreach ($this->slice_array as $slice) + { + $this->slices[$slice]['template'] = + str_replace(sprintf(TPL_VAR,$name), $value, $this->slices[$slice]['template']); + } + } + + function show( $name ) + { + $this->booleans[$name] = true; + } + + function unshow( $name ) + { + $this->booleans[$name] = null; + } + + function burn_var( $name, $slice = 'root' ) + { + $this->slices[$slice]['template'] = + str_replace(sprintf(TPL_VAR,$name),$this->slices[$slice]['vars'][$name], + $this->slices[$slice]['template']); + } + + /* =========================== + PARSING FUNCTIONS + =========================== */ + + function parse_to_parent ( $slice ) + { + $parent = $this->slices[$slice]['parent']; + $name = TPL_SLICE_PRE.$slice; + $value = $this->parse_slice($slice); + $this->slices[$parent]['vars'][$name] .= $value; + return $value; + } function parse () { - return $this->slices['root']->parse(); + return $this->parse_slice(); } function pparse () { - $result = $this->slices['root']->parse(); + $result = $this->parse_slice(); echo $result; return $result; } - function dir($location, $dir) + function parse_slice( $slice = 'root' ) { + // Adds and removes conditional blocks. + $result = $this->slices[$slice]['template']; + if ( !empty($this->slices[$slice]['conditionals']) ) + { + foreach($this->slices[$slice]['conditionals'] as $name => $useless) + { + if ($this->booleans[$name] === true) + { + $regex = '/\r?\n?\s*'.sprintf(TPL_COND_START, $name).'/s'; + $result = preg_replace($regex,'',$result); + $regex = '/\r?\n?\s*'.sprintf(TPL_COND_END, $name).'/s'; + $result = preg_replace($regex,'',$result); + } else { + $regex = '/\r?\n?\s*'.sprintf(TPL_COND_START, $name).'(.*)'.sprintf(TPL_COND_END, $name).'/sU'; + $result = preg_replace($regex,'',$result); + } + } + } + + // Parses variables. + if ( count($this->slices[$slice]['vars']) > 0) + { + foreach( $this->slices[$slice]['vars'] as $name => $value ) + { + $regex = '/(?:\r\n\s+)?'.sprintf(TPL_VAR_REG, preg_quote($name)).'\r?\n?/si'; + $result = preg_replace( $regex, $value, $result ); + } + } + $regex = '/\r?\n?'.sprintf(TPL_VAR_REG, TPL_VAR_FINDER).'\r?\n?/sU'; + $result = preg_replace( $regex, '', $result ); + $this->flush($slice); + return $result; + } + + function flush( $slice = 'root' ) + { + $this->slices[$slice]['vars'] = array(); + } + + /* =========================== + CACHING FUNCTIONS + =========================== */ + + function dir( $location, $dir ) + { $array = explode('/',$dir); if ($array === '.') return true; $count = count($array); - print_r($array); for ($i = 0; $i < $count; $i++) { @@ -286,7 +421,6 @@ if (!file_exists($location.$path)) { $missing = $i; - //echo $i; break 1; } } @@ -304,7 +438,6 @@ $path .= '/'.$array[$ii]; } } - if (!mkdir($location.$path)) return false; } } @@ -315,13 +448,15 @@ { if ($this->cache_exists === false) { + // If the folder the cache file is going to be put in doesn't exist, + // then it will create the folder. if (!file_exists(dirname(AS_LOC_CACHE.$this->cache_file))) { - $this->dir(AS_LOC_CACHE, dirname($this->cache_file)); } $resource = fopen(AS_LOC_CACHE.$this->cache_file, 'w'); $this->cache_exists = true; + // Writes serialized version of the template object to the cache file. return fwrite($resource, serialize($this)); } return true; @@ -329,55 +464,7 @@ function clear_cache() { - unlink($this->cache_file); + unlink($this->cache_file); // Deletes cache file. Optional function. } } - -class tpl_slice -{ - var $parent; - var $vars; - var $template; - - function tpl_slice($content) - { - $this->template = $content; - } - - function define($name, $value) - { - $this->vars[$name] .= $value; - } - - function burn_var($name) - { - if (!empty($name)) - { - $this->template = str_replace(sprintf(TPL_VAR,$name),$this->vars[$name],$this->template); - } - } - - function parse() - { - $result = $this->template; - if ($this->vars != null) - { - foreach($this->vars as $name => $value) - { - $regex = '/\r?\n?\s*'.sprintf(TPL_VAR_REG, preg_quote($name)).'\r?\n?/si'; - $result = preg_replace( $regex, $value, $result ); - } - } - - $regex = '/\r?\n?'.sprintf(TPL_VAR_REG, TPL_VAR_FINDER).'\r?\n?/sU'; - $result = preg_replace( $regex, '', $result ); - $this->flush(); - return $result; - } - - function flush() - { - $this->vars = null; - } -} ?> \ No newline at end of file Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-08-18 22:04:27 UTC (rev 101) +++ trunk/globals.php 2007-09-03 04:56:22 UTC (rev 102) @@ -35,7 +35,7 @@ */ function general($err, $verbose) { - $error =& new template(AS_TPL.'messages/error.tpl'); + $error =& new cobalt_tpl(AS_TPL.'messages/error.tpl.htm'); $error->set('err', $err); $handle = fopen('logs/errors.txt', 'w'); if($handle) @@ -60,7 +60,7 @@ */ function thank($message, $go1, $res1, $go2="", $res2="") { - $message =& new template(AS_TPL.'message/thank.tpl'); + $message =& new cobalt_tpl(AS_TPL.'message/thank.tpl.htm'); $message->set_var('go1', $go1); $message->set_var('go2', $go2); $message->set_var('res1', $res1); @@ -70,7 +70,7 @@ } /* Our functions living in globals.php */ -$error =& new error; +$error =& new error(); $message =& new message(); global $db; Added: trunk/template/default/header.tpl.htm =================================================================== --- trunk/template/default/header.tpl.htm (rev 0) +++ trunk/template/default/header.tpl.htm 2007-09-03 04:56:22 UTC (rev 102) @@ -0,0 +1,38 @@ +<html> + +<head> +<meta http-equiv="Content-Language" content="en-us"> +<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> +<link rel="stylesheet" type="text/css" href="[STYLE_ROOT]style.css" /> +<title>[TITLE]</title> +</head> + +<body> +<div id="center"> +<div class="header"> +<h1 style="color: #5C6366; margin: 15px 5px 20px 15px">[SITE_NAME]</h1> +<div class="nav"> +<a href="localhost"><img src="[STYLE_ROOT]img/home.png" class="nav_img" width="16" height="16" />Site Index</a> +<!-- IF LOGGED_OUT --> + | <a href="localhost"><img src="[STYLE_ROOT]img/login.png" class="nav_img" width="16" height="16" />Login</a> + | <a href="localhost"><img src="[STYLE_ROOT]img/register.png" class="nav_img" width="16" height="16" />Register</a> +<!-- ENDIF LOGGED_OUT --> +<!-- IF LOGGED_IN --> + | <a href="localhost"><img src="[STYLE_ROOT]img/my-profile.png" class="nav_img" width="16" height="16" />My Profile</a> + | <a href="localhost"><img src="[STYLE_ROOT]img/messages.png" class="nav_img" width="16" height="16" />Messages ([MESSAGE_COUNT] new)</a> + | <a href="localhost"><img src="[STYLE_ROOT]img/blog.png" class="nav_img" width="16" height="16" />Blog</a> +<!-- ENDIF LOGGED_IN --> + | <a href="localhost"><img src="[STYLE_ROOT]img/search.png" class="nav_img" width="16" height="16" />Search</a> +</div> +</div> +<!-- IF LOGGED_OUT --> +<div id="login"> +<form method="POST" action="[LOGIN_FORM]" style="display: inline"> + <label for="username" style="margin-left: 5px">[LANG:USERNAME]</label> + <input type="text" name="username" id="username" style="margin-right: 20px" /> + <label for="password">[LANG:PASSWORD]</label> + <input type="text" name="password" id="password" /> + <input type="submit" value="[LANG:LOGIN]" id="login_button" /> +</form> +</div> +<!-- ENDIF LOGGED_OUT --> \ No newline at end of file Added: trunk/template/default/index.tpl.htm =================================================================== --- trunk/template/default/index.tpl.htm (rev 0) +++ trunk/template/default/index.tpl.htm 2007-09-03 04:56:22 UTC (rev 102) @@ -0,0 +1,29 @@ +<!-- INCLUDE 'header.tpl.htm' --> +<!-- IF LOGGED_IN --> +<div id="main"> + <div id="body"> + <h3>[WELCOME_MESSAGE]</h3> + <p> + <!-- IF UNREAD_MESSAGES --> + <b>[UNREAD_MESSAGES]</b><br /> + <!-- ENDIF UNREAD_MESSAGES --> + <!-- IF FRIEND_REQUESTS --> + <b>[PENDING_REQUESTS]</b><br /> + <!-- ENDIF FRIEND_REQUESTS --> + [FRIENDS_COUNT]<br /> + </p> + </div> +</div> +<div id="side"> + <div class="message"> + <h4 style="display: inline">Recent Messages</h4> + <!-- START message --> + <a href="[URL]">[TITLE]</a> <a href="[USER.URL]">[USER]</a> + <!-- END message --> + </div> +</div> +</div> +<!-- ENDIF LOGGED_IN --> +<!-- INCLUDE 'footer.tpl.htm' --> +</body> +</html> \ No newline at end of file Added: trunk/template/default/style.css =================================================================== --- trunk/template/default/style.css (rev 0) +++ trunk/template/default/style.css 2007-09-03 04:56:22 UTC (rev 102) @@ -0,0 +1,115 @@ +/* #################### + ## Header Classes ## + #################### */ +body +{ + background-color: #A2AEB3 +} + +#center +{ +position: absolute; +width: 740px; +right: 50%; +margin: 0 -370px 0 0; +} + +div.header +{ +background-color: #CEDEE5; +border: 1px solid #7C868A; +} + +div.header a, a:link, a:visited +{ +color: #5C6366; +font-family: verdana, tahoma, sans-serif; +font-size: 9pt +} + +div.nav +{ +width: 100%; +border-top: 1px solid #7C868A; +background-color: #B8C6CC +} + +div.header a:hover, a:active +{ +color: #000000; +font-family: verdana, tahoma, sans-serif +} + +img.nav_img +{ +border: 0px none #FFFFFF; +margin: 5px; +vertical-align: middle +} + +#login +{ +background-color: #CEDEE5; +margin-top: 10px; +padding: 5px; +border: 1px solid #7C868A; +font-family: tahoma, sans-serif; +font-size: 9pt; +color: #5C6366; +font-weight: bold +} + +#login_button +{ + border: 1px solid #5C6366; + background-color: #CEDEE5; + color: #5C6366; + font-family: tahoma, sans-serif; + margin-left: 20px; + font-weight: bold +} + +#username, #password +{ + background-color: #E7EFF3; + border: 1px solid #5C6366; + color: #5C6366 +} + +/* ################## + ## Body Classes ## + ################## */ +#main +{ + width: 540px; + margin-top: 10px; + float: left +} + +#body +{ + background-color: #CEDEE5; + border: 1px solid #7C868A; +} + +#wide +{ + margin-top: 10px; + width: 740px; + background-color: #CEDEE5; + border: 1px solid #7C868A; +} + +#side +{ + float: right; + margin-left: 10px; + margin-top: 10px; + width: 190px; +} + +.message +{ + background-color: #CEDEE5; + border: 1px solid #7C868A; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cal...@us...> - 2007-08-18 22:04:59
|
Revision: 101 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=101&view=rev Author: caleb870 Date: 2007-08-18 15:04:27 -0700 (Sat, 18 Aug 2007) Log Message: ----------- Just another small tweak to fix globals.php. Now globals.php parses properly. LET THE CODING BEGIN! Modified Paths: -------------- trunk/globals.php Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-08-18 21:31:59 UTC (rev 100) +++ trunk/globals.php 2007-08-18 22:04:27 UTC (rev 101) @@ -74,6 +74,6 @@ $message =& new message(); global $db; -$db =& new ADONewConnection(AS_DB_TYPE); +$db =& ADONewConnection(AS_DB_TYPE); $db->Connect(AS_DB_HOST, AS_DB_USER, AS_DB_PASS, AS_DB_SCHEMA); ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cal...@us...> - 2007-08-18 21:31:57
|
Revision: 100 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=100&view=rev Author: caleb870 Date: 2007-08-18 14:31:59 -0700 (Sat, 18 Aug 2007) Log Message: ----------- Finally completed the entire template system with caching and many other features. The template system is now ready for use and now we can get on with designing AstroSPACES. Modified Paths: -------------- trunk/config.php trunk/develop/template-example/tester.php trunk/functions/template.php trunk/globals.php Added Paths: ----------- trunk/cache/ Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/config.php 2007-08-18 21:31:59 UTC (rev 100) @@ -1,45 +1,45 @@ -<?php -/* These settings are autogenerated by AstroSPACES - do not change them unless you know what you are - doing! -*/ -define('AS_DB_TYPE', 'mysql'); -define('AS_DB_PREFIX', 'as_'); -define('AS_DB_HOST', 'localhost'); -define('AS_DB_SCHEMA', 'schema'); -define('AS_DB_USER', 'user'); -define('AS_DB_PASS', 'pass'); - -define('AS_EXT', '.php'); -define('AS_LANG', 'en-us'); - -define('AS_LOC_URL', 'http://localhost/'); -define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); - -/* These settings are constants and must NOT - be altered. Doing so will prevent AstroSPACES - from functioning. -*/ -define('AS_TBL_USERS', AS_DB_PREFIX.'users'); -define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); -define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); -define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); -define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); -define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); -define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); -define('AS_TBL_IMG', AS_DB_PREFIX.'images'); -define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); -define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); -define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); -define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); -define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); -define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); -define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); -define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); -define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); -define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); - -define('AS_DIR_TPL', 'template/'); -define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); -?> - +<?php +/* These settings are autogenerated by AstroSPACES + do not change them unless you know what you are + doing! +*/ +define('AS_DB_TYPE', 'mysql'); +define('AS_DB_PREFIX', 'as_'); +define('AS_DB_HOST', 'localhost'); +define('AS_DB_SCHEMA', 'schema'); +define('AS_DB_USER', 'user'); +define('AS_DB_PASS', 'pass'); + +define('AS_EXT', '.php'); +define('AS_LANG', 'en-us'); + +define('AS_LOC_URL', 'http://localhost/'); +define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); +define('AS_LOC_CACHE', AS_LOC_DIRECT.'cache/'); + +/* These settings are constants and must NOT + be altered. Doing so will prevent AstroSPACES + from functioning. +*/ +define('AS_TBL_USERS', AS_DB_PREFIX.'users'); +define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); +define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); +define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); +define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); +define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); +define('AS_TBL_IMG', AS_DB_PREFIX.'images'); +define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); +define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); +define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); +define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); +define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); +define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); +define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); +define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); +define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); + +define('AS_DIR_TPL', 'template/'); +define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); +?> \ No newline at end of file Modified: trunk/develop/template-example/tester.php =================================================================== --- trunk/develop/template-example/tester.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/develop/template-example/tester.php 2007-08-18 21:31:59 UTC (rev 100) @@ -1,19 +1,20 @@ <?php +define('AS_LOC_CACHE', 'C:/Program Files/xampp/htdocs/as/cache/'); $time = microtime(); include '../../functions/template.php'; -$tpl = new template('test.tpl','test.cache',5); +$tpl = new tpl_base('test.tpl','tester.cache',5); $tpl->load_lang_file('../../lang/en/lang_main.php'); $tpl->compile_slices(); -//print_r($tpl); $tpl->set(array('address' => '123 Sample Street NW')); $tpl->set_multi(array(array('two.bold' => 'Just', 'two.morez' => ' script <br />'),array('two.bold' => 'Im', 'two.morez' => ' pie.', 'color' => ' red')),'two'); //echo "<a href=\"http://www.deltalabs.net/othercrap/musicsample.zip\">CLICK ME</a>"; -$tpl->set_lang_var('var','GALLERY_COMMENTS','one','5'); +//$tpl-> $tpl->parse_slice_to_parent('one'); //print_r($tpl->slices); $tpl->pparse(); $tpl->finish(); //print_r($tpl->slices); echo microtime() - $time; + ?> \ No newline at end of file Modified: trunk/functions/template.php =================================================================== --- trunk/functions/template.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/functions/template.php 2007-08-18 21:31:59 UTC (rev 100) @@ -18,23 +18,23 @@ @id: $Id$ *********************************************************/ -class template { +define('TPL_LANG_PRE', 'LANG:'); +define('TPL_LANG_PRE_REG', 'LANG:'); +define('TPL_SLICE_PRE', 'SLICE:'); +define('TPL_SLICE_PRE_REG', 'SLICE:'); +define('TPL_VAR', '[%s]'); +define('TPL_VAR_REG', '\[%s\]'); +define('TPL_VAR_FINDER', '[a-zA-Z0-9_.-:]+'); +define('TPL_SLICE_FINDER', '[a-zA-Z0-9_.-]+'); +define('TPL_INCLUDE', '\<\!--\s*INCLUDE\s*\'%s\'\s*--\>'); +define('TPL_SLICE_START', '\<\!--\s*START\s+%s\s*--\>'); +define('TPL_SLICE_END', '\<\!--\s*END\s+%s\s*--\>'); +class tpl_base { + var $slices; var $lang; - var $lang_prefix = 'LANG:'; - var $lang_prefix_reg = 'LANG:'; - var $slice_prefix_reg = 'SLICE:'; - var $slice_prefix = 'SLICE:'; - var $start_symbol_reg = '\['; - var $end_symbol_reg = '\]'; - var $start_symbol = '['; - var $end_symbol = ']'; - - var $include_reg = '\<\!--\s*INCLUDE\s*\'%s\'\s*--\>'; - var $slice_start = '\<\!--\s*START %s\s*--\>'; - var $slice_end = '\<\!--\s*END %s\s*--\>'; var $slice_array; // System-only variable var $tpl_folder; @@ -42,76 +42,10 @@ var $cache_file; var $cache_life; var $cache_age; - var $recache = true; var $cache_exists = false; - /* - [FUNCTIONS] - - [ LOADING ] - load_from_file - Load template from a file's contents - $file - The file. - load - Load template from a variable in PHP - $template - Variable with template - - [ VARIABLES ] - define_var - Defines a variable - $var_name - Name of variable, overwrites previous - $value - Value of variable - $parent (optional) - Parent of variable. Meant for situations when using slices. - add_to_var - Add to the existing value of a variable - $var_name - Name of variable - $add_what - Add what to the variable - $parent (optional) - Parent of variable. Meant for situations when using slices. - set - Sets an array or variables. - $var_array - Array of variables to set. Valid input would be like: - array('var_one' => 'value', 'var_two' => 'another value') - $slice_name - Name of slice to set the variables of. Is set to the root template by default. - set_multi - Sets an array of variables to a slice and then parses it. Then sets the next - set of variables, and parses until the array is fully iterated. - Svar_array - Array of variables to set. Valid input would be like: - array(array('var1' => 'value', 'var2' => 'value again'), - array('var1' => 'new value', 'var2' => 'another new value')) - $slice_name - Name of slice to set the variables of. Is set to the root template by default. - - [ SLICES & SLICE PARSING ] - parse_slice_to_parent - Parses a slices result to it location in it's parent. - $slice_name - Name of slice to parse. - parse_slice_to_var - Parse the result of a slice to a variable - $slice_name - Name of slice to be parsed - $root_var_name - Name of variable to parse the slice to. - $parent (optional) - Parent of variable. Meant for situations when using slices. - parse_slice - Parse a slice. Returns the result to the caller. - $slice_name - Name of slice to be parsed. - - [ ROOT PARSING ] - parse - Parses the root with echoing the result, yet returning the result to the caller. - (No parameters needed) - pparse - Parses the root and echoes the result. - - [ MISCELLANEOUS ] - flush_template - Drops the current data of template - flush_slice - Drops the current data of the slice - $slice_name - Name of slice to drop - reset_template - Resets the entire template and drops all information. - - [ TERMINOLOGY ] - Slice - A Removable or a part of a template that can be repetitively parsed. - - Root - The core template. Slices must be parsed to a variable in the root - in order to be seen, otherwise they are never printed. - - [ HOW IT WORKS ] - When you load a file, it loads all the slices in the file and removes them - from the root template. When you define a variable, it is only added to - a list of variables to be parsed. They can still be added to before it - is parsed. Once it is parsed it echoes the result and resets it so that - it may be parsed again. - - */ - - function template($file, $cache_to, $cache_life = 600) + function tpl_base($file, $cache_to, $cache_life = 600) { $this->tpl_folder = dirname($file).'/'; $this->tpl_file = $file; @@ -122,7 +56,6 @@ { $cache_age = @filemtime($cache_to); $this->cache_age = $cache_age; - // ($cache_age != false AND time() - $cache_life < $cache_age) or ($cache_age != false and $cache_life === 0) if ($cache_age === false) { $this->cache_exists = false; @@ -137,20 +70,9 @@ } $this->cache_exists = true; $cache = unserialize(implode(null,$content)); - $this->slices = $cache->slices; - $this->lang = $cache->lang; - $this->lang_prefix = $cache->lang_prefix; - $this->lang_prefix_reg = $cache->lang_prefix_reg; - $this->slice_prefix_reg = $cache->slice_prefix_reg; - $this->slice_prefix = $cache->slice_prefix; - - $this->start_symbol_reg = $cache->start_symbol_reg; - $this->end_symbol_reg = $cache->end_symbol_reg; - $this->start_symbol = $cache->start_symbol; - $this->end_symbol = $cache->end_symbol; - - $this->slice_start = $cache->slice_start; - $this->slice_end = $cache->slice_end; + $this->slices = $cache->slices; + $this->lang = $cache->lang; + echo "cache exists<br />"; return true; } elseif ($cache_age != false) @@ -178,19 +100,17 @@ function load( $template ) { - $this->slices['root']['template'] = $template; - $this->slices['root']['result'] = $template; - $this->slices['root']['name'] = 'root'; - $this->include_files(); - $regex = '/'.$this->slice_start('(.*)').'/smiU'; + $template = $this->include_files($template); + $this->slices['root'] = new tpl_slice( $template ); + $regex = '/'.sprintf(TPL_SLICE_START,'('.TPL_SLICE_FINDER.')').'/smiU'; preg_match_all($regex, $template, $slice_array); $this->slice_array = $slice_array[1]; } - function include_files() + function include_files($template) { - preg_match_all('/'.sprintf($this->include_reg, '(.*)').'/smU', - $this->slices['root']['template'], + preg_match_all('/'.sprintf(TPL_INCLUDE, '(.*)').'/smU', + $template, $files); if (count($files) === 0) return; @@ -204,14 +124,15 @@ $content = implode(null,$content); } - $regex = '/'.sprintf($this->include_reg, str_replace('/','\/',preg_quote($file))).'/sm'; - $this->slices['root']['template'] = preg_replace($regex, $content, $this->slices['root']['template']); + $regex = '/'.sprintf(TPL_INCLUDE, str_replace('/','\/',preg_quote($file))).'/sm'; + $template = preg_replace($regex, $content, $template); } - if (preg_match('/'.sprintf($this->include_reg, '(.*)').'/sm', $this->slices['root']['template'], $files)) + if (preg_match('/'.sprintf(TPL_INCLUDE, '(.*)').'/sm', $template, $files)) { - $this->include_files(); + $template = $this->include_files($template); } + return $template; } function load_lang_file ( $filename ) @@ -228,29 +149,6 @@ } } - function parse_lang_vars() - { - if (empty($this->lang)) return false; - - foreach ($this->lang as $name => $value) - { - if (strstr($value, '%s') === false) - { - $this->slices['root']['template'] = str_replace($this->start_symbol.$this->lang_prefix.$name.$this->end_symbol, $value, $this->slices['root']['template']); - } - } - return true; - } - - function set_lang_var ( $var_name, $lang_name, $parent, $value, $value2 = null, $value3 = null, $value4 = null ) - { - $this->define_var($var_name, sprintf($this->lang[$lang_name], $value, $value2, $value3, $value4),$parent); - } - - function slice_start ( $name ) { return sprintf( $this->slice_start, $name); } // System-only function - - function slice_end ( $name ) { return sprintf( $this->slice_end, $name); } // System-only function - function determine_parent( $name ) // System-only function. No longer usable after compile_slices(). { $name_reg = preg_quote( $name ); @@ -259,8 +157,8 @@ foreach ($this->slice_array as $slice) { $slice_reg = preg_quote($slice); - $regex = '/'.$this->slice_start($slice_reg).'(?:.*)'.$this->slice_start($name_reg).'(?:.*)'.$this->slice_end($slice_reg).'/sm'; - if (preg_match($regex, $this->slices['root']['template'], $results)) + $regex = '/'.sprintf(TPL_SLICE_START,$slice_reg).'(?:.*)'.sprintf(TPL_SLICE_START,$name_reg).'(?:.*)'.sprintf(TPL_SLICE_END,$slice_reg).'/sm'; + if (preg_match($regex, $this->slices['root']->template, $results)) $array[$slice] = strlen($results[0]); } @@ -283,47 +181,42 @@ return $biggest_slice; } - function compile_slices () // System-only function + function compile_slices () { - $this->parse_lang_vars(); - $regex = '/'.$this->slice_end('(.*)').'/smiU'; - preg_match_all( $regex, $this->slices['root']['template'], $sub_slices); - foreach ($sub_slices[1] as $slice) + // Parse every language variable. + if (!empty($this->lang)) { - $this->assemble_slice($slice); + foreach ($this->lang as $name => $value) + { + $this->slices['root']->template = str_replace(sprintf(TPL_VAR,TPL_LANG_PRE.$name), $value, $this->slices['root']->template); + } } - } - - function assemble_slice ( $slice_name ) // System-only function - { - $regex = '/'.$this->slice_start($slice_name).'(.*)\r\n\s*'.$this->slice_end($slice_name).'\s*\r?\n?/si'; - preg_match($regex, $this->slices['root']['template'], $resultset); - if (count($resultset) > 0) + // Find all the slices in the template and make them into tpl_slice objects. + $regex = '/'.sprintf(TPL_SLICE_END,'(.*)').'/smiU'; + preg_match_all( $regex, $this->slices['root']->template, $sub_slices); + $slices = $sub_slices[1]; + foreach ($slices as $slice) { - $this->slices[$slice_name]['template'] = $resultset[1]; - $this->slices[$slice_name]['result'] = $resultset[1]; - $this->slices[$slice_name]['name'] = $slice_name; - $this->slices[$slice_name]['parent'] = $this->determine_parent(preg_quote($slice_name)); - $newTemplate = preg_replace($regex, $this->start_symbol.$this->slice_prefix.$slice_name.$this->end_symbol."\r\n", $this->slices['root']['template']); - $this->slices['root']['template'] = $newTemplate; - $this->slices['root']['result'] = $newTemplate; + // Assemble the slice object + $regex = '/'.sprintf(TPL_SLICE_START,$slice).'(.*)\r\n\s*'.sprintf(TPL_SLICE_END,$slice).'\s*\r?\n?/si'; + preg_match($regex, $this->slices['root']->template, $resultset); + + if (count($resultset) > 0) + { + + $this->slices[$slice] = new tpl_slice($resultset[1]); + $this->slices[$slice]->parent = $this->determine_parent(preg_quote($slice)); + $this->slices['root']->template = preg_replace($regex, sprintf(TPL_VAR,TPL_SLICE_PRE_REG.$slice)."\r\n", $this->slices['root']->template); + } } } - function count_slices ( $parent ) - { - $regex = '/'.$this->slice_start($parent).'(?:.*)('.$this->slice_start('(.*)').')(?:.*)'.$this->slice_end($parent).'/smi'; - preg_match( $regex, $this->slices['root']['template'], $sub_slices ); - $count = count($sub_slices); - return $count; - } - function set($var_array, $slice_name = 'root') { foreach ($var_array as $name => $value) { - $this->define_var($name, $value, $slice_name); + $this->slices[$slice_name]->vars[$name] = $value; } } @@ -333,134 +226,51 @@ { foreach ($var_array as $id => $vars) { - foreach ($vars as $var_name => $var_value) + foreach ($vars as $name => $value) { - $this->define_var($var_name, $var_value, $slice_name); + $this->slices[$slice_name]->vars[$name] = $value; } $this->pparse(false); } } else { foreach ($var_array as $id => $vars) { - foreach ($vars as $var_name => $var_value) + foreach ($vars as $name => $value) { - $this->define_var($var_name, $var_value, $slice_name); + $this->slices[$slice_name]->vars[$name] = $value; } - $this->parse_slice_to_var($slice_name, $this->slice_prefix.$slice_name, $this->slices[$parent]['parent'], false); + $this->slices[$this->slices[$slice_name]->parent]->define(TPL_SLICE_PRE.$slice_name, $this->slices[$slice_name]->parse()); } } } - - function define_var ( $var_name, $value, $parent = 'root') - { - $this->slices[$parent]['vars'][$var_name] = $value; - } - function add_to_var ( $var_name, $add_what, $parent = 'root' ) - { - $this->slices[$parent]['vars'][$var_name] .= $add_what; - } - - function parse_slice_to_var ( $slice_name, $root_var_name, $parent = 'root', $overwrite = true ) // Use parse_slice_to_parent instead - { - $content = $this->parse_slice( $slice_name ); - if ($overwrite) - { - $this->define_var($root_var_name, $content, $parent); - } else { - $this->add_to_var($root_var_name, $content, $this->slices[$slice_name]['parent']); - } - return $parsed_result; - } - function parse_slice_to_parent ( $slice_name ) { - $parent = $this->slices[$slice_name]['parent']; - $root_var_name = $this->slice_prefix.$slice_name; - $content = $this->parse_slice( $slice_name ); - $this->add_to_var($root_var_name, $content, $parent); + $parent = $this->slices[$slice_name]->parent; + $root_var_name = TPL_SLICE_PRE.$slice_name; + $content = $this->slices[$slice_name]->parse(); + $this->slices[$parent]->define($root_var_name, $content); return $parsed_result; } - - function parse_slice ( $slice_name ) - { - if ($this->slices[$slice_name]['vars'] != Null) - { - foreach($this->slices[$slice_name]['vars'] as $name => $value) - { - $replacement_regex = '/\r?\n?\s*' . $this->start_symbol_reg . preg_quote($name).$this->end_symbol_reg.'\r?\n?/si'; - $result = preg_replace( $replacement_regex, $value, $this->slices[$slice_name]['result'] ); - $this->slices[$slice_name]['result'] = $result; - } - } - - $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.'(.*)'.$this->end_symbol_reg.'\r?\n?/sU'; - $this->slices[$slice_name]['result'] = preg_replace( $replacement_regex, '', $this->slices[$slice_name]['result'] ); - - $parsed_result = $this->slices[$slice_name]['result']; - - $this->flush_slice( $slice_name ); - /*$parsed_result = str_replace("\n", "\nLF", $parsed_result); - $parsed_result = str_replace("\r", "CR", $parsed_result);*/ - return $parsed_result; - } function parse () { - if ($this->slices['root']['vars'] != null) - { - foreach($this->slices['root']['vars'] as $name => $value) - { - $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.preg_quote($name).$this->end_symbol_reg.'\r?\n?/si'; - $result = preg_replace($replacement_regex,$value,$this->slices['root']['result']); - $this->slices['root']['result'] = $result; - } - } - - $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.'(.*)'.$this->end_symbol_reg.'\r?\n?/siU'; - $this->slices['root']['result'] = preg_replace( $replacement_regex, '', $this->slices['root']['result'] ); - - $parsed_result = $this->slices['root']['result']; - - $this->flush_template(); - - return $parsed_result; + return $this->slices['root']->parse(); } - function pparse ($die_on_finish = false) + function pparse () { - echo $this->parse(); - - if ($die_on_finish == true) - { - die(); - } + $result = $this->slices['root']->parse(); + echo $result; + return $result; } - - function flush_template () - { - $this->slices['root']['result'] = $this->slices['root']['template']; - unset($this->slices['root']['vars']); - } - function flush_slice ( $slice_name ) + function dir($location, $dir) { - $this->slices[$slice_name]['result'] = $this->slices[$slice_name]['template']; - $this->slices[$slice_name]['vars'] = null; - } - - function reset_template () - { - $this->slices['root']['template'] = null; - $this->slices['root']['result'] = null; - $this->slices = null; - } - - function dir($location, $dir) // done and tested - { $array = explode('/',$dir); if ($array === '.') return true; $count = count($array); + print_r($array); for ($i = 0; $i < $count; $i++) { @@ -476,6 +286,7 @@ if (!file_exists($location.$path)) { $missing = $i; + //echo $i; break 1; } } @@ -504,7 +315,12 @@ { if ($this->cache_exists === false) { - $resource = fopen($this->cache_file, 'w'); + if (!file_exists(dirname(AS_LOC_CACHE.$this->cache_file))) + { + + $this->dir(AS_LOC_CACHE, dirname($this->cache_file)); + } + $resource = fopen(AS_LOC_CACHE.$this->cache_file, 'w'); $this->cache_exists = true; return fwrite($resource, serialize($this)); } @@ -516,4 +332,52 @@ unlink($this->cache_file); } } + +class tpl_slice +{ + var $parent; + var $vars; + var $template; + + function tpl_slice($content) + { + $this->template = $content; + } + + function define($name, $value) + { + $this->vars[$name] .= $value; + } + + function burn_var($name) + { + if (!empty($name)) + { + $this->template = str_replace(sprintf(TPL_VAR,$name),$this->vars[$name],$this->template); + } + } + + function parse() + { + $result = $this->template; + if ($this->vars != null) + { + foreach($this->vars as $name => $value) + { + $regex = '/\r?\n?\s*'.sprintf(TPL_VAR_REG, preg_quote($name)).'\r?\n?/si'; + $result = preg_replace( $regex, $value, $result ); + } + } + + $regex = '/\r?\n?'.sprintf(TPL_VAR_REG, TPL_VAR_FINDER).'\r?\n?/sU'; + $result = preg_replace( $regex, '', $result ); + $this->flush(); + return $result; + } + + function flush() + { + $this->vars = null; + } +} ?> \ No newline at end of file Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-08-07 17:22:04 UTC (rev 99) +++ trunk/globals.php 2007-08-18 21:31:59 UTC (rev 100) @@ -21,7 +21,6 @@ /* Include our larger functions */ require('config.php'); require(AS_LOC_DIRECT.'functions/template.php'); -$template =& new template(); require(AS_LOC_DIRECT.'functions/user.php'); $user =& new user(); require(AS_LOC_DIRECT.'functions/adodb/adodb.inc.php'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cal...@us...> - 2007-08-07 17:22:03
|
Revision: 99 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=99&view=rev Author: caleb870 Date: 2007-08-07 10:22:04 -0700 (Tue, 07 Aug 2007) Log Message: ----------- Completed the template system with language files and caching. Next thing is to allow the user to tell the system what to cache. I also included an example of how the template system works in /develop/template-example. Modified Paths: -------------- trunk/functions/template.php trunk/globals.php Added Paths: ----------- trunk/develop/template-example/ trunk/develop/template-example/footer.tpl trunk/develop/template-example/header.tpl trunk/develop/template-example/sub.tpl trunk/develop/template-example/test.cache trunk/develop/template-example/test.tpl trunk/develop/template-example/tester.php Added: trunk/develop/template-example/footer.tpl =================================================================== --- trunk/develop/template-example/footer.tpl (rev 0) +++ trunk/develop/template-example/footer.tpl 2007-08-07 17:22:04 UTC (rev 99) @@ -0,0 +1,14 @@ +<div style="width: 100%; background-color: #EEEEEE; border: 1px solid #CCCCCC"> +Copyright George Won Kong. +<p>In pulvinar leo quis ipsum tempor pellentesque. Sed viverra tellus porttitor quam. +Cras quis dui et velit consectetuer placerat. Nunc feugiat pulvinar quam. Nam +sollicitudin. Donec erat metus, aliquam sed, malesuada sit amet, tristique +laoreet, augue. Nunc eu sem. Sed vel enim. Quisque eu mauris. Suspendisse risus +neque, sodales non, adipiscing lacinia, elementum vitae, lacus. Vestibulum +tortor neque, congue ac, lobortis eget, aliquam ut, tellus. Vestibulum varius +blandit purus. Morbi porta pede fringilla arcu. Cras tristique, eros sit amet +porttitor nonummy, arcu nibh euismod quam, pharetra semper nibh leo vel elit. +Phasellus dignissim leo sit amet turpis.</p> +[address] +</div> +<!-- INCLUDE 'sub.tpl' --> \ No newline at end of file Added: trunk/develop/template-example/header.tpl =================================================================== --- trunk/develop/template-example/header.tpl (rev 0) +++ trunk/develop/template-example/header.tpl 2007-08-07 17:22:04 UTC (rev 99) @@ -0,0 +1,15 @@ +<div style="width: 100%; background-color: #EEEEEE; border: 1px solid #CCCCCC"> +<h1>[LANG:BLOG_AUTHOR]</h1> +</div> +<p> +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dictum accumsan ante. +Vestibulum hendrerit vulputate sapien. Donec ac enim. In pulvinar leo quis ipsum tempor +pellentesque. Sed viverra tellus porttitor quam. Cras quis dui et velit consectetuer +placerat. Nunc feugiat pulvinar quam. Nam sollicitudin. Donec erat metus, aliquam sed, +malesuada sit amet, tristique laoreet, augue. Nunc eu sem. Sed vel enim. Quisque eu +mauris. Suspendisse risus neque, sodales non, adipiscing lacinia, elementum vitae, lacus. +Vestibulum tortor neque, congue ac, lobortis eget, aliquam ut, tellus. Vestibulum varius +blandit purus. Morbi porta pede fringilla arcu. Cras tristique, eros sit amet porttitor +nonummy, arcu nibh euismod quam, pharetra semper nibh leo vel elit. Phasellus dignissim +leo sit amet turpis. +</p> \ No newline at end of file Added: trunk/develop/template-example/sub.tpl =================================================================== --- trunk/develop/template-example/sub.tpl (rev 0) +++ trunk/develop/template-example/sub.tpl 2007-08-07 17:22:04 UTC (rev 99) @@ -0,0 +1 @@ +<p><b>All rights reserved to nobody</b></p> \ No newline at end of file Added: trunk/develop/template-example/test.cache =================================================================== --- trunk/develop/template-example/test.cache (rev 0) +++ trunk/develop/template-example/test.cache 2007-08-07 17:22:04 UTC (rev 99) @@ -0,0 +1,101 @@ +O:8:"template":21:{s:6:"slices";a:5:{s:4:"root";a:3:{s:8:"template";s:2085:"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<head> + <title>You must be logged in to access this page</title> +</head> +<body> +<div style="width: 100%; background-color: #EEEEEE; border: 1px solid #CCCCCC"> +<h1>Author</h1> +</div> +<p> +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dictum accumsan ante. +Vestibulum hendrerit vulputate sapien. Donec ac enim. In pulvinar leo quis ipsum tempor +pellentesque. Sed viverra tellus porttitor quam. Cras quis dui et velit consectetuer +placerat. Nunc feugiat pulvinar quam. Nam sollicitudin. Donec erat metus, aliquam sed, +malesuada sit amet, tristique laoreet, augue. Nunc eu sem. Sed vel enim. Quisque eu +mauris. Suspendisse risus neque, sodales non, adipiscing lacinia, elementum vitae, lacus. +Vestibulum tortor neque, congue ac, lobortis eget, aliquam ut, tellus. Vestibulum varius +blandit purus. Morbi porta pede fringilla arcu. Cras tristique, eros sit amet porttitor +nonummy, arcu nibh euismod quam, pharetra semper nibh leo vel elit. Phasellus dignissim +leo sit amet turpis. +</p> +<!-- Template Error: Including ./leftnav.tpl failed! --> + <h1>Author Test page</h1> +[SLICE:one] +<pre> +[pre] +</pre> +<div style="width: 100%; background-color: #EEEEEE; border: 1px solid #CCCCCC"> +Copyright George Won Kong. +<p>In pulvinar leo quis ipsum tempor pellentesque. Sed viverra tellus porttitor quam. +Cras quis dui et velit consectetuer placerat. Nunc feugiat pulvinar quam. Nam +sollicitudin. Donec erat metus, aliquam sed, malesuada sit amet, tristique +laoreet, augue. Nunc eu sem. Sed vel enim. Quisque eu mauris. Suspendisse risus +neque, sodales non, adipiscing lacinia, elementum vitae, lacus. Vestibulum +tortor neque, congue ac, lobortis eget, aliquam ut, tellus. Vestibulum varius +blandit purus. Morbi porta pede fringilla arcu. Cras tristique, eros sit amet +porttitor nonummy, arcu nibh euismod quam, pharetra semper nibh leo vel elit. +Phasellus dignissim leo sit amet turpis.</p> +[address] +</div> +<p><b>All rights reserved to nobody</b></p> +</body> +</html>";s:6:"result";s:2085:"<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<head> + <title>You must be logged in to access this page</title> +</head> +<body> +<div style="width: 100%; background-color: #EEEEEE; border: 1px solid #CCCCCC"> +<h1>Author</h1> +</div> +<p> +Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Morbi dictum accumsan ante. +Vestibulum hendrerit vulputate sapien. Donec ac enim. In pulvinar leo quis ipsum tempor +pellentesque. Sed viverra tellus porttitor quam. Cras quis dui et velit consectetuer +placerat. Nunc feugiat pulvinar quam. Nam sollicitudin. Donec erat metus, aliquam sed, +malesuada sit amet, tristique laoreet, augue. Nunc eu sem. Sed vel enim. Quisque eu +mauris. Suspendisse risus neque, sodales non, adipiscing lacinia, elementum vitae, lacus. +Vestibulum tortor neque, congue ac, lobortis eget, aliquam ut, tellus. Vestibulum varius +blandit purus. Morbi porta pede fringilla arcu. Cras tristique, eros sit amet porttitor +nonummy, arcu nibh euismod quam, pharetra semper nibh leo vel elit. Phasellus dignissim +leo sit amet turpis. +</p> +<!-- Template Error: Including ./leftnav.tpl failed! --> + <h1>Author Test page</h1> +[SLICE:one] +<pre> +[pre] +</pre> +<div style="width: 100%; background-color: #EEEEEE; border: 1px solid #CCCCCC"> +Copyright George Won Kong. +<p>In pulvinar leo quis ipsum tempor pellentesque. Sed viverra tellus porttitor quam. +Cras quis dui et velit consectetuer placerat. Nunc feugiat pulvinar quam. Nam +sollicitudin. Donec erat metus, aliquam sed, malesuada sit amet, tristique +laoreet, augue. Nunc eu sem. Sed vel enim. Quisque eu mauris. Suspendisse risus +neque, sodales non, adipiscing lacinia, elementum vitae, lacus. Vestibulum +tortor neque, congue ac, lobortis eget, aliquam ut, tellus. Vestibulum varius +blandit purus. Morbi porta pede fringilla arcu. Cras tristique, eros sit amet +porttitor nonummy, arcu nibh euismod quam, pharetra semper nibh leo vel elit. +Phasellus dignissim leo sit amet turpis.</p> +[address] +</div> +<p><b>All rights reserved to nobody</b></p> +</body> +</html>";s:4:"name";s:4:"root";}s:3:"two";a:5:{s:8:"template";s:69:" + <b style="color: [color]">[two.bold] testing my [two.morez]</b>";s:6:"result";s:69:" + <b style="color: [color]">[two.bold] testing my [two.morez]</b>";s:4:"name";s:3:"two";s:6:"parent";s:3:"one";s:4:"vars";N;}s:4:"blah";a:4:{s:8:"template";s:29:" + <p>Content!</p>";s:6:"result";s:29:" + <p>Content!</p>";s:4:"name";s:4:"blah";s:6:"parent";s:5:"three";}s:5:"three";a:4:{s:8:"template";s:47:" + <b>[two.bolder]</b> + [SLICE:blah]";s:6:"result";s:47:" + <b>[two.bolder]</b> + [SLICE:blah]";s:4:"name";s:5:"three";s:6:"parent";s:3:"one";}s:3:"one";a:5:{s:8:"template";s:137:" + <div style="background-color: [color]; margin: 3px">[content]</div> + [SLICE:two] +<p color="green">[var]</p> + [SLICE:three]";s:6:"result";s:137:" + <div style="background-color: [color]; margin: 3px">[content]</div> + [SLICE:two] +<p color="green">[var]</p> + [SLICE:three]";s:4:"name";s:3:"one";s:6:"parent";s:4:"root";s:4:"vars";N;}}s:4:"lang";a:15:{s:11:"BLOG_AUTHOR";s:6:"Author";s:9:"BLOG_TIME";s:9:"Posted at";s:12:"BLOG_COMMENT";s:23:"This post has 1 comment";s:13:"BLOG_COMMENTS";s:25:"This post has %s comments";s:18:"BLOG_LEAVE_COMMENT";s:40:"Click %s to leave a comment on this post";s:9:"BLOG_POST";s:13:"New blog post";s:22:"BLOG_COMMENT_SUBMITTED";s:31:"Your comment has been submitted";s:19:"BLOG_POST_SUBMITTED";s:28:"Your post has been submitted";s:13:"GALLERY_VIEWS";s:8:"%s views";s:13:"GALLERY_OWNER";s:11:"Uploaded by";s:15:"GALLERY_COMMENT";s:24:"This image has 1 comment";s:16:"GALLERY_COMMENTS";s:26:"This image has %s comments";s:22:"GALLERY_LEAVE_COMMEMNT";s:41:"Click %s to leave a comment on this image";s:11:"GLOBAL_HERE";s:4:"here";s:22:"ERROR_MUST_BE_LOGGEDIN";s:41:"You must be logged in to access this page";}s:11:"lang_prefix";s:5:"LANG:";s:15:"lang_prefix_reg";s:5:"LANG:";s:16:"slice_prefix_reg";s:6:"SLICE:";s:12:"slice_prefix";s:6:"SLICE:";s:16:"start_symbol_reg";s:2:"\[";s:14:"end_symbol_reg";s:2:"\]";s:12:"start_symbol";s:1:"[";s:10:"end_symbol";s:1:"]";s:11:"include_reg";s:30:"\<\!--\s*INCLUDE\s*'%s'\s*--\>";s:11:"slice_start";s:24:"\<\!--\s*START %s\s*--\>";s:9:"slice_end";s:22:"\<\!--\s*END %s\s*--\>";s:11:"slice_array";a:4:{i:0;s:3:"one";i:1;s:3:"two";i:2;s:5:"three";i:3;s:4:"blah";}s:10:"tpl_folder";s:2:"./";s:8:"tpl_file";s:8:"test.tpl";s:10:"cache_file";s:10:"test.cache";s:10:"cache_life";i:5;s:9:"cache_age";i:1186507160;s:7:"recache";b:1;s:12:"cache_exists";b:1;} \ No newline at end of file Added: trunk/develop/template-example/test.tpl =================================================================== --- trunk/develop/template-example/test.tpl (rev 0) +++ trunk/develop/template-example/test.tpl 2007-08-07 17:22:04 UTC (rev 99) @@ -0,0 +1,28 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<head> + <title>[LANG:ERROR_MUST_BE_LOGGEDIN]</title> +</head> +<body> +<!-- INCLUDE 'header.tpl' --> +<!-- INCLUDE 'leftnav.tpl' --> + <h1>[LANG:BLOG_AUTHOR] Test page</h1> +<!-- START one --> + <div style="background-color: [color]; margin: 3px">[content]</div> + <!-- START two --> + <b style="color: [color]">[two.bold] testing my [two.morez]</b> + <!-- END two --> + <p color="green">[var]</p> + <!-- START three --> + <b>[two.bolder]</b> + <!-- START blah --> + <p>Content!</p> + <!-- END blah --> + <!-- END three --> +<!-- END one --> +<pre> +[pre] +</pre> +<!-- INCLUDE 'footer.tpl' --> +</body> +</html> \ No newline at end of file Added: trunk/develop/template-example/tester.php =================================================================== --- trunk/develop/template-example/tester.php (rev 0) +++ trunk/develop/template-example/tester.php 2007-08-07 17:22:04 UTC (rev 99) @@ -0,0 +1,19 @@ +<?php +$time = microtime(); +include '../../functions/template.php'; +$tpl = new template('test.tpl','test.cache',5); +$tpl->load_lang_file('../../lang/en/lang_main.php'); +$tpl->compile_slices(); +//print_r($tpl); + +$tpl->set(array('address' => '123 Sample Street NW')); +$tpl->set_multi(array(array('two.bold' => 'Just', 'two.morez' => ' script <br />'),array('two.bold' => 'Im', 'two.morez' => ' pie.', 'color' => ' red')),'two'); +//echo "<a href=\"http://www.deltalabs.net/othercrap/musicsample.zip\">CLICK ME</a>"; +$tpl->set_lang_var('var','GALLERY_COMMENTS','one','5'); +$tpl->parse_slice_to_parent('one'); +//print_r($tpl->slices); +$tpl->pparse(); +$tpl->finish(); +//print_r($tpl->slices); +echo microtime() - $time; +?> \ No newline at end of file Modified: trunk/functions/template.php =================================================================== --- trunk/functions/template.php 2007-08-07 17:20:03 UTC (rev 98) +++ trunk/functions/template.php 2007-08-07 17:22:04 UTC (rev 99) @@ -20,32 +20,38 @@ *********************************************************/ class template { - var $template; - var $result; var $slices; - var $var; var $lang; - var $lang_prefix = 'lang:'; - var $lang_prefix_reg = 'lang:'; - var $slice_prefix_reg = 'slice:'; - var $slice_prefix = 'slice:'; + var $lang_prefix = 'LANG:'; + var $lang_prefix_reg = 'LANG:'; + var $slice_prefix_reg = 'SLICE:'; + var $slice_prefix = 'SLICE:'; var $start_symbol_reg = '\['; var $end_symbol_reg = '\]'; var $start_symbol = '['; var $end_symbol = ']'; - var $slice_start = '\<\!-- START %s --\>'; // The %s is required - var $slice_end = '\<\!-- END %s --\>'; // The %s is required + var $include_reg = '\<\!--\s*INCLUDE\s*\'%s\'\s*--\>'; + var $slice_start = '\<\!--\s*START %s\s*--\>'; + var $slice_end = '\<\!--\s*END %s\s*--\>'; var $slice_array; // System-only variable - //var $line_break = '\r\n'; // Only SINGLE quotes + var $tpl_folder; + var $tpl_file; + var $cache_file; + var $cache_life; + var $cache_age; + var $recache = true; + + var $cache_exists = false; + /* [FUNCTIONS] [ LOADING ] load_from_file - Load template from a file's contents - $file - The file + $file - The file. load - Load template from a variable in PHP $template - Variable with template @@ -105,6 +111,59 @@ */ + function template($file, $cache_to, $cache_life = 600) + { + $this->tpl_folder = dirname($file).'/'; + $this->tpl_file = $file; + $this->cache_file = $cache_to; + $this->cache_life = $cache_life; + + if (isset($cache_to)) + { + $cache_age = @filemtime($cache_to); + $this->cache_age = $cache_age; + // ($cache_age != false AND time() - $cache_life < $cache_age) or ($cache_age != false and $cache_life === 0) + if ($cache_age === false) + { + $this->cache_exists = false; + return $this->load_from_file($file); + } + elseif (time() - $cache_life < $cache_age or $cache_life === 0) + { + $content = file( $cache_to ); + if ($content === false) + { + return false; + } + $this->cache_exists = true; + $cache = unserialize(implode(null,$content)); + $this->slices = $cache->slices; + $this->lang = $cache->lang; + $this->lang_prefix = $cache->lang_prefix; + $this->lang_prefix_reg = $cache->lang_prefix_reg; + $this->slice_prefix_reg = $cache->slice_prefix_reg; + $this->slice_prefix = $cache->slice_prefix; + + $this->start_symbol_reg = $cache->start_symbol_reg; + $this->end_symbol_reg = $cache->end_symbol_reg; + $this->start_symbol = $cache->start_symbol; + $this->end_symbol = $cache->end_symbol; + + $this->slice_start = $cache->slice_start; + $this->slice_end = $cache->slice_end; + return true; + } + elseif ($cache_age != false) + { + $this->cache_exists = false; + return $this->load_from_file($file); + } + } + + $this->cache_exists = true; + return $this->load_from_file($file); + } + function load_from_file ( $file ) { @$content = file( $file ); @@ -119,44 +178,75 @@ function load( $template ) { - $template = $this->parse_lang_vars($template); $this->slices['root']['template'] = $template; $this->slices['root']['result'] = $template; $this->slices['root']['name'] = 'root'; + $this->include_files(); $regex = '/'.$this->slice_start('(.*)').'/smiU'; preg_match_all($regex, $template, $slice_array); $this->slice_array = $slice_array[1]; - - $this->compile_slices(); // KEEP THIS HERE! } - function load_lang_file ( $filename ) + function include_files() { - @$array = include($filename); - if ($array != false) + preg_match_all('/'.sprintf($this->include_reg, '(.*)').'/smU', + $this->slices['root']['template'], + $files); + if (count($files) === 0) return; + + foreach ($files[1] as $file) { - $this->lang = array_merge($this->lang, $array); - } else { - $error->general('Language file could not be loaded', $filename); + @$content = file( $this->tpl_folder.$file ); + if ($content === false) + { + $content = '<!-- Template Error: Including '.$this->tpl_folder.$file.' failed! -->'; + } else { + $content = implode(null,$content); + } + + $regex = '/'.sprintf($this->include_reg, str_replace('/','\/',preg_quote($file))).'/sm'; + $this->slices['root']['template'] = preg_replace($regex, $content, $this->slices['root']['template']); } + + if (preg_match('/'.sprintf($this->include_reg, '(.*)').'/sm', $this->slices['root']['template'], $files)) + { + $this->include_files(); + } } - function langData ( $array ) + function load_lang_file ( $filename ) { - $this->lang = array_merge($this->lang, $array); + if ($this->cache_exists === false) + { + @$array = include($filename); + if ($array != false) + { + $this->lang = array_merge($this->lang, $array); + } else { + $error->general('Language file could not be loaded', $filename); + } + } } - function parse_lang_vars( $input ) + function parse_lang_vars() { - if (empty($this->lang)) return $input; + if (empty($this->lang)) return false; foreach ($this->lang as $name => $value) { - $input = str_replace($this->start_symbol.$this->lang_prefix.$name.$this->end_symbol, $value, $input); + if (strstr($value, '%s') === false) + { + $this->slices['root']['template'] = str_replace($this->start_symbol.$this->lang_prefix.$name.$this->end_symbol, $value, $this->slices['root']['template']); + } } - return $input; + return true; } + function set_lang_var ( $var_name, $lang_name, $parent, $value, $value2 = null, $value3 = null, $value4 = null ) + { + $this->define_var($var_name, sprintf($this->lang[$lang_name], $value, $value2, $value3, $value4),$parent); + } + function slice_start ( $name ) { return sprintf( $this->slice_start, $name); } // System-only function function slice_end ( $name ) { return sprintf( $this->slice_end, $name); } // System-only function @@ -195,6 +285,7 @@ function compile_slices () // System-only function { + $this->parse_lang_vars(); $regex = '/'.$this->slice_end('(.*)').'/smiU'; preg_match_all( $regex, $this->slices['root']['template'], $sub_slices); foreach ($sub_slices[1] as $slice) @@ -364,5 +455,65 @@ $this->slices['root']['result'] = null; $this->slices = null; } + + function dir($location, $dir) // done and tested + { + $array = explode('/',$dir); + if ($array === '.') return true; + $count = count($array); + + for ($i = 0; $i < $count; $i++) + { + for ($ii = 0; $ii < $i; $ii++) + { + if ($ii === 0) + { + $path = $array[$ii]; + } else { + $path .= '/'.$array[$ii]; + } + } + if (!file_exists($location.$path)) + { + $missing = $i; + break 1; + } + } + + if ($missing != Null) + { + for ($i = $missing; $i <= $count; $i++) + { + for ($ii = 0; $ii < $i; $ii++) + { + if ($ii === 0) + { + $path = $array[$ii]; + } else { + $path .= '/'.$array[$ii]; + } + } + + if (!mkdir($location.$path)) return false; + } + } + return true; + } + + function finish() + { + if ($this->cache_exists === false) + { + $resource = fopen($this->cache_file, 'w'); + $this->cache_exists = true; + return fwrite($resource, serialize($this)); + } + return true; + } + + function clear_cache() + { + unlink($this->cache_file); + } } ?> \ No newline at end of file Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-08-07 17:20:03 UTC (rev 98) +++ trunk/globals.php 2007-08-07 17:22:04 UTC (rev 99) @@ -19,7 +19,7 @@ @id: $Id$ *********************************************************/ /* Include our larger functions */ -require('./config.php'); //We can't include using a constant defined in the file we're including +require('config.php'); require(AS_LOC_DIRECT.'functions/template.php'); $template =& new template(); require(AS_LOC_DIRECT.'functions/user.php'); @@ -74,6 +74,7 @@ $error =& new error; $message =& new message(); -$db =& new ADOConnection(AS_DB_TYPE); +global $db; +$db =& new ADONewConnection(AS_DB_TYPE); $db->Connect(AS_DB_HOST, AS_DB_USER, AS_DB_PASS, AS_DB_SCHEMA); ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-07 17:20:04
|
Revision: 98 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=98&view=rev Author: deltalabs Date: 2007-08-07 10:20:03 -0700 (Tue, 07 Aug 2007) Log Message: ----------- Added settings table to schema and config, and added several things to the front page. Modified Paths: -------------- trunk/config.php trunk/develop/new-schema.sql trunk/index.php Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-08-07 05:34:01 UTC (rev 97) +++ trunk/config.php 2007-08-07 17:20:03 UTC (rev 98) @@ -21,7 +21,8 @@ from functioning. */ define('AS_TBL_USERS', AS_DB_PREFIX.'users'); -define('AS_TBL_STATIC_PROFILE_FIELDS', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_SETTINGS', AS_DB_PREFIX.'settings'); +define('AS_TBL_STATPROF', AS_DB_PREFIX.'static_profile_fields'); define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-08-07 05:34:01 UTC (rev 97) +++ trunk/develop/new-schema.sql 2007-08-07 17:20:03 UTC (rev 98) @@ -157,3 +157,10 @@ `field_value` varchar(128), ) ENGINE=MyISAM DEFAULT CHARSET=latin1; +DROP TABLE IF EXISTS `as_settings`; +CREATE TABLE `as_settings` ( + `setting_id` int(10) unsigned NOT NULL auto_increment, + `setting_name` varchar(45) NOT NULL, + `setting_value` varchar(45) NOT NULL, + PRIMARY KEY (`setting_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; \ No newline at end of file Modified: trunk/index.php =================================================================== --- trunk/index.php 2007-08-07 05:34:01 UTC (rev 97) +++ trunk/index.php 2007-08-07 17:20:03 UTC (rev 98) @@ -19,23 +19,75 @@ @id: $Id$ *********************************************************/ include('globals.php'); + /* 5 most recent users should be enough. We can fill the rest with ads or something */ $_query = 'SELECT user_id, display_name, user_image FROM '.AS_TBL_USER.' SORT BY user_id DESC LIMIT 5'; $_query = $db->Execute($_query); -while($user = $_query->FetchRow()) +while($usr = $_query->FetchRow()) { - $userdetails[$user['user_id']] = array( - 'id' => $user['user_id'], - 'display_name' => $user['display_name'], - 'icon' => $user['user_image'] + $userdetails[$usr['user_id']] = array( + 'id' => $usr['user_id'], + 'display_name' => $usr['display_name'], + 'icon' => $usr['user_image'] ); } + +//login stuff +$show_login = false; +if (!isset($_POST['email']) && isset($_POST['passwd'])) +{ + $_query = 'SELECT user_id,password FROM ' . AS_TBL_USERS . ' WHERE email = ' . $db->qstr($_POST['email']) . ' LIMIT 1'; + $_query = $db->Execute($_query); + $userlogin = $_query->FetchRow(); + if ($_POST['passwd'] == $userlogin['password']) + { + $user->login($userlogin['user_id']); + $loginmessage = "Successfully logged in!"; + } +} +else +{ + $show_login = true; +} + +//show user message +if ($user->logged_in()) +{ + $_query = 'SELECT display_name FROM ' . AS_TBL_STATIC_PROFILE_FIELDS . ' WHERE user_id = ' . $userlogin['user_id']; + $_query = $db->Execute($_query); + $dispname = $_query->FetchRow(); + $_query = 'SELECT setting_value FROM ' . AS_TBL_SETTINGS . " WHERE setting_name = 'user_message'"; + $_query = $db->Execute($_query); + $usermessage = $_query->FetchRow(); + $usermessage = str_replace('%displayname', $dispname['display_name'], $usermessage['setting_value']); +} +else +{ + $_query = 'SELECT setting_value FROM ' . AS_TBL_SETTINGS . " WHERE setting_name = 'anonymous_user_message'"; + $_query = $db->Execute($_query); + $usermessage = $_query->FetchRow(); + $usermessage = $usermessage['setting_value']; +} + +// Show number of users +$_query = 'SELECT count(*) FROM' . AS_TBL_USERS; +$num_users = $db->GetOne($_query); + $index = template(AS_TPL.'home.tpl'); +$index->define_var('loginmessage', $loginmessage); +$index->define_var('usermessage', $usermessage); +$index->define_var('num_users', $num_users); + foreach ($userdetails as $userdetail) { - set($userdetail, 'userdetail'); - parse_slice_to_parent('userdetail'); + $index->set($userdetail, 'userdetail'); + $index->parse_slice_to_parent('userdetail'); } + +if ($show_login) +{ + parse_slice_to_parent('login_form'); +} $index->pparse(); ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-07 05:34:01
|
Revision: 97 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=97&view=rev Author: deltalabs Date: 2007-08-06 22:34:01 -0700 (Mon, 06 Aug 2007) Log Message: ----------- fixed current code to work with the new template system. Modified Paths: -------------- trunk/index.php Modified: trunk/index.php =================================================================== --- trunk/index.php 2007-08-07 04:47:05 UTC (rev 96) +++ trunk/index.php 2007-08-07 05:34:01 UTC (rev 97) @@ -24,11 +24,18 @@ $_query = $db->Execute($_query); while($user = $_query->FetchRow()) { - $userdetail[$user['display_name']] = array( - 'id' => $user['user_id'], - 'icon' => $user['user_image'] + $userdetails[$user['user_id']] = array( + 'id' => $user['user_id'], + 'display_name' => $user['display_name'], + 'icon' => $user['user_image'] ); } $index = template(AS_TPL.'home.tpl'); -$index->set_var('userdetail', $userdetail); + +foreach ($userdetails as $userdetail) +{ + set($userdetail, 'userdetail'); + parse_slice_to_parent('userdetail'); +} +$index->pparse(); ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cal...@us...> - 2007-08-07 04:47:06
|
Revision: 96 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=96&view=rev Author: caleb870 Date: 2007-08-06 21:47:05 -0700 (Mon, 06 Aug 2007) Log Message: ----------- Fixed the semi-colon error and remodeled it to fit the exact format the template system loads language files. Modified Paths: -------------- trunk/lang/en/lang_main.php Modified: trunk/lang/en/lang_main.php =================================================================== --- trunk/lang/en/lang_main.php 2007-08-06 05:15:04 UTC (rev 95) +++ trunk/lang/en/lang_main.php 2007-08-07 04:47:05 UTC (rev 96) @@ -18,9 +18,8 @@ @id: $Id$ *********************************************************/ -$lang = array(); -$main=array( - 'BLOG_AUTHOR' => 'Author', +$main = array( + 'BLOG_AUTHOR' => 'Author', 'BLOG_TIME' => 'Posted at', 'BLOG_COMMENT' => 'This post has 1 comment', 'BLOG_COMMENTS' => 'This post has %s comments', @@ -35,6 +34,6 @@ 'GALLERY_LEAVE_COMMEMNT' => 'Click %s to leave a comment on this image', 'GLOBAL_HERE' => 'here', 'ERROR_MUST_BE_LOGGEDIN' => 'You must be logged in to access this page' -) -$lang=array_merge($lang, $main); +); +return $main; ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cal...@us...> - 2007-08-06 05:15:14
|
Revision: 95 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=95&view=rev Author: caleb870 Date: 2007-08-05 22:15:04 -0700 (Sun, 05 Aug 2007) Log Message: ----------- A complete fix-up of the template system. It's almost done as language files need to be implemented yet. And I MIGHT even work on caching. Modified Paths: -------------- trunk/functions/template.php Modified: trunk/functions/template.php =================================================================== --- trunk/functions/template.php 2007-08-06 05:12:05 UTC (rev 94) +++ trunk/functions/template.php 2007-08-06 05:15:04 UTC (rev 95) @@ -25,13 +25,20 @@ var $slices; var $var; var $lang; - var $lang_prefix = 'lang:'; + var $lang_prefix = 'lang:'; + var $lang_prefix_reg = 'lang:'; + var $slice_prefix_reg = 'slice:'; + var $slice_prefix = 'slice:'; + var $start_symbol_reg = '\['; + var $end_symbol_reg = '\]'; var $start_symbol = '['; var $end_symbol = ']'; - var $slice_start = '<!-- START %s -->'; // The %s is required - var $slice_end = '<!-- END %s -->'; // The %s is required + var $slice_start = '\<\!-- START %s --\>'; // The %s is required + var $slice_end = '\<\!-- END %s --\>'; // The %s is required + var $slice_array; // System-only variable + //var $line_break = '\r\n'; // Only SINGLE quotes /* [FUNCTIONS] @@ -51,8 +58,20 @@ $var_name - Name of variable $add_what - Add what to the variable $parent (optional) - Parent of variable. Meant for situations when using slices. + set - Sets an array or variables. + $var_array - Array of variables to set. Valid input would be like: + array('var_one' => 'value', 'var_two' => 'another value') + $slice_name - Name of slice to set the variables of. Is set to the root template by default. + set_multi - Sets an array of variables to a slice and then parses it. Then sets the next + set of variables, and parses until the array is fully iterated. + Svar_array - Array of variables to set. Valid input would be like: + array(array('var1' => 'value', 'var2' => 'value again'), + array('var1' => 'new value', 'var2' => 'another new value')) + $slice_name - Name of slice to set the variables of. Is set to the root template by default. [ SLICES & SLICE PARSING ] + parse_slice_to_parent - Parses a slices result to it location in it's parent. + $slice_name - Name of slice to parse. parse_slice_to_var - Parse the result of a slice to a variable $slice_name - Name of slice to be parsed $root_var_name - Name of variable to parse the slice to. @@ -100,22 +119,21 @@ function load( $template ) { - $this->slice_start = preg_quote($this->slice_start); - $this->slice_end = preg_quote($this->slice_end); + $template = $this->parse_lang_vars($template); + $this->slices['root']['template'] = $template; + $this->slices['root']['result'] = $template; + $this->slices['root']['name'] = 'root'; + $regex = '/'.$this->slice_start('(.*)').'/smiU'; + preg_match_all($regex, $template, $slice_array); + $this->slice_array = $slice_array[1]; - $this->start_symbol = preg_quote($this->start_symbol); - $this->end_symbol = preg_quote($this->end_symbol); - - $this->template = $template; - $this->result = $template; - $this->compile_slices(); // KEEP THIS HERE! } function load_lang_file ( $filename ) { @$array = include($filename); - if ($array === true) + if ($array != false) { $this->lang = array_merge($this->lang, $array); } else { @@ -123,132 +141,195 @@ } } - function langValue ( $var_name ) + function langData ( $array ) { - if ($this->lang[$var_name] != NULL) - { - return $this->lang[$var_name]; - } else { - return false; - } + $this->lang = array_merge($this->lang, $array); } - function langPrefix($name) + function parse_lang_vars( $input ) { - return $this->lang_prefix . $name; + if (empty($this->lang)) return $input; + + foreach ($this->lang as $name => $value) + { + $input = str_replace($this->start_symbol.$this->lang_prefix.$name.$this->end_symbol, $value, $input); + } + return $input; } - function slice_start ( $name ) { return sprintf( $this->slice_start, $name); } + function slice_start ( $name ) { return sprintf( $this->slice_start, $name); } // System-only function - function slice_end ( $name ) { return sprintf( $this->slice_end, $name); } + function slice_end ( $name ) { return sprintf( $this->slice_end, $name); } // System-only function - function compile_slices ($parent = null) + function determine_parent( $name ) // System-only function. No longer usable after compile_slices(). { - if (!empty($parent)) + $name_reg = preg_quote( $name ); + + if (count($this->slice_array) === 0) return 'root'; + foreach ($this->slice_array as $slice) { - // Searchs for slices in a specified slice - $regex = '/'. $this->slice_start($slice_name) .'(?:.*)'.$this->slice_start('(.*)').'(?:.*)'.$this->slice_end($slice_name).'/smiU'; - preg_match_all( $regex, $this->template, $sub_slices); - } else { - $regex = '/'.$this->slice_end('(.*)').'/smiU'; - preg_match_all( $regex, $this->template, $sub_slices); + $slice_reg = preg_quote($slice); + $regex = '/'.$this->slice_start($slice_reg).'(?:.*)'.$this->slice_start($name_reg).'(?:.*)'.$this->slice_end($slice_reg).'/sm'; + if (preg_match($regex, $this->slices['root']['template'], $results)) + $array[$slice] = strlen($results[0]); } - foreach ($sub_slices[1] as $slice) + + if (count($array) === 0) return 'root'; + foreach ($array as $slice_name => $number) { - if ($this->count_slices($slice) > 0) + if (isset($biggest_num)) { - $this->compile_slices($slice); + if ($number < $biggest_num) + { + $biggest_num = $number; + $biggest_slice = $slice_name; + } } else { - $this->assemble_slice($slice); + $biggest_num = $number; + $biggest_slice = $slice_name; } } - if (!empty($parent)) + return $biggest_slice; + } + + function compile_slices () // System-only function + { + $regex = '/'.$this->slice_end('(.*)').'/smiU'; + preg_match_all( $regex, $this->slices['root']['template'], $sub_slices); + foreach ($sub_slices[1] as $slice) { - $this->assemble_slice($parent); + $this->assemble_slice($slice); } - } - function assemble_slice ( $slice_name ) + function assemble_slice ( $slice_name ) // System-only function { - $regex = '/'.$this->slice_start($slice_name).'(.*)\n\s*'.$this->slice_end($slice_name).'\n?/si'; - preg_match($regex, $this->template, $resultset); + $regex = '/'.$this->slice_start($slice_name).'(.*)\r\n\s*'.$this->slice_end($slice_name).'\s*\r?\n?/si'; + preg_match($regex, $this->slices['root']['template'], $resultset); if (count($resultset) > 0) { $this->slices[$slice_name]['template'] = $resultset[1]; $this->slices[$slice_name]['result'] = $resultset[1]; $this->slices[$slice_name]['name'] = $slice_name; - $newTemplate = preg_replace($regex,'',$this->template); - $this->template = $newTemplate; - $this->result = $newTemplate; + $this->slices[$slice_name]['parent'] = $this->determine_parent(preg_quote($slice_name)); + $newTemplate = preg_replace($regex, $this->start_symbol.$this->slice_prefix.$slice_name.$this->end_symbol."\r\n", $this->slices['root']['template']); + $this->slices['root']['template'] = $newTemplate; + $this->slices['root']['result'] = $newTemplate; } } function count_slices ( $parent ) { $regex = '/'.$this->slice_start($parent).'(?:.*)('.$this->slice_start('(.*)').')(?:.*)'.$this->slice_end($parent).'/smi'; - preg_match( $regex, $this->template, $sub_slices ); + preg_match( $regex, $this->slices['root']['template'], $sub_slices ); $count = count($sub_slices); return $count; } + + function set($var_array, $slice_name = 'root') + { + foreach ($var_array as $name => $value) + { + $this->define_var($name, $value, $slice_name); + } + } + + function set_multi($var_array, $slice_name = 'root') + { + if ($slice_name == 'root') + { + foreach ($var_array as $id => $vars) + { + foreach ($vars as $var_name => $var_value) + { + $this->define_var($var_name, $var_value, $slice_name); + } + $this->pparse(false); + } + } else { + foreach ($var_array as $id => $vars) + { + foreach ($vars as $var_name => $var_value) + { + $this->define_var($var_name, $var_value, $slice_name); + } + $this->parse_slice_to_var($slice_name, $this->slice_prefix.$slice_name, $this->slices[$parent]['parent'], false); + } + } + } function define_var ( $var_name, $value, $parent = 'root') { - $this->slices[$parent]['vars'][$var_name]['name'] = $var_name; - $this->slices[$parent]['vars'][$var_name]['value'] = $value; + $this->slices[$parent]['vars'][$var_name] = $value; } function add_to_var ( $var_name, $add_what, $parent = 'root' ) { - $this->slices[$parent]['vars'][$var_name]['value'] .= $add_what; + $this->slices[$parent]['vars'][$var_name] .= $add_what; } - function parse_slice_to_var ( $slice_name, $root_var_name, $parent = 'root' ) + function parse_slice_to_var ( $slice_name, $root_var_name, $parent = 'root', $overwrite = true ) // Use parse_slice_to_parent instead { $content = $this->parse_slice( $slice_name ); - $this->define_var($root_var_name, $content, $parent); + if ($overwrite) + { + $this->define_var($root_var_name, $content, $parent); + } else { + $this->add_to_var($root_var_name, $content, $this->slices[$slice_name]['parent']); + } return $parsed_result; } + function parse_slice_to_parent ( $slice_name ) + { + $parent = $this->slices[$slice_name]['parent']; + $root_var_name = $this->slice_prefix.$slice_name; + $content = $this->parse_slice( $slice_name ); + $this->add_to_var($root_var_name, $content, $parent); + return $parsed_result; + } + function parse_slice ( $slice_name ) { if ($this->slices[$slice_name]['vars'] != Null) { - foreach($this->slices[$slice_name]['vars'] as $variable) + foreach($this->slices[$slice_name]['vars'] as $name => $value) { - $replacement_regex = '/' . $this->start_symbol . preg_quote($variable['name']).$this->end_symbol.'\n?/si'; - $result = preg_replace( $replacement_regex, $variable['value'], $this->slices["$slice_name"]['result'] ); + $replacement_regex = '/\r?\n?\s*' . $this->start_symbol_reg . preg_quote($name).$this->end_symbol_reg.'\r?\n?/si'; + $result = preg_replace( $replacement_regex, $value, $this->slices[$slice_name]['result'] ); $this->slices[$slice_name]['result'] = $result; } } - $replacement_regex = '/'.$this->start_symbol.'(.*)'.$this->end_symbol.'\n?/si'; + $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.'(.*)'.$this->end_symbol_reg.'\r?\n?/sU'; $this->slices[$slice_name]['result'] = preg_replace( $replacement_regex, '', $this->slices[$slice_name]['result'] ); $parsed_result = $this->slices[$slice_name]['result']; $this->flush_slice( $slice_name ); + /*$parsed_result = str_replace("\n", "\nLF", $parsed_result); + $parsed_result = str_replace("\r", "CR", $parsed_result);*/ return $parsed_result; } - function parse() + function parse () { if ($this->slices['root']['vars'] != null) { - foreach($this->slices['root']['vars'] as $variable) + foreach($this->slices['root']['vars'] as $name => $value) { - $replacement_regex = '/'.$this->start_symbol.$variable['name'].$this->end_symbol.'\n?/si'; - $result = preg_replace($replacement_regex,$variable['value'],$this->result); - $this->result = $result; + $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.preg_quote($name).$this->end_symbol_reg.'\r?\n?/si'; + $result = preg_replace($replacement_regex,$value,$this->slices['root']['result']); + $this->slices['root']['result'] = $result; } } - $replacement_regex = '/'.$this->start_symbol.'(.*)'.$this->end_symbol.'\n?/si'; - $this->result = preg_replace( $replacement_regex, '', $this->result ); + $replacement_regex = '/\r?\n?'.$this->start_symbol_reg.'(.*)'.$this->end_symbol_reg.'\r?\n?/siU'; + $this->slices['root']['result'] = preg_replace( $replacement_regex, '', $this->slices['root']['result'] ); - $parsed_result = $this->result; + $parsed_result = $this->slices['root']['result']; $this->flush_template(); @@ -267,8 +348,8 @@ function flush_template () { - $this->result = $this->template; - $this->slices['root']['vars'] = null; + $this->slices['root']['result'] = $this->slices['root']['template']; + unset($this->slices['root']['vars']); } function flush_slice ( $slice_name ) @@ -279,9 +360,9 @@ function reset_template () { - $this->template = null; - $this->result = null; + $this->slices['root']['template'] = null; + $this->slices['root']['result'] = null; $this->slices = null; } } -?> +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-06 05:12:07
|
Revision: 94 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=94&view=rev Author: deltalabs Date: 2007-08-05 22:12:05 -0700 (Sun, 05 Aug 2007) Log Message: ----------- Finished friends Modified Paths: -------------- trunk/functions/user.php Modified: trunk/functions/user.php =================================================================== --- trunk/functions/user.php 2007-08-05 04:25:02 UTC (rev 93) +++ trunk/functions/user.php 2007-08-06 05:12:05 UTC (rev 94) @@ -353,13 +353,33 @@ { $_query = 'DELETE FROM ' . AS_TBL_FRIEND . ' WHERE user2_id = ' . $user_id . ' AND user1_id = ' . $user->data['user_id']; if ($db->Execute($_query) === false) - { + { $error->general('<b>DB Error!</b>', 'user.php - remove_friend(): '.$db->ErrorMsg()); return false; } } return true; } + /* + Function Name: list_friends + Purpose: get a list of friends of the user + */ + function list_friends() + { + $_query = 'SELECT user1_id FROM ' . AS_TBL_FRIENDS . ' WHERE user2_id = ' . $user->data['user_id'] . ' AND accepted = 1'; + if (($listpart1 = $db->fetch_array($_query)) === false) + { + $error->general('<b>DB Error!</b>', 'user.php - list_friends(): '.$db->ErrorMsg()); + return false; + } + $_query = 'SELECT user2_id FROM ' . AS_TBL_FRIENDS . ' WHERE user1_id = ' . $user->data['user_id'] . ' AND accepted = 1'; + if (($listpart2 = $db->fetch_array($_query)) === false) + { + $error->general('<b>DB Error!</b>', 'user.php - list_friends(): '.$db->ErrorMsg()); + return false; + } + return array_merge($listpart1, $listpart2); + } /* Function Name: add_coment Arguments: (int) id -- ID of user who comment is directed to This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-05 04:25:03
|
Revision: 93 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=93&view=rev Author: deltalabs Date: 2007-08-04 21:25:02 -0700 (Sat, 04 Aug 2007) Log Message: ----------- added remove_friend function Modified Paths: -------------- trunk/functions/user.php Modified: trunk/functions/user.php =================================================================== --- trunk/functions/user.php 2007-08-05 03:43:57 UTC (rev 92) +++ trunk/functions/user.php 2007-08-05 04:25:02 UTC (rev 93) @@ -180,16 +180,16 @@ } else { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE user2_id = ' . $user->data['user_id'] . ' AND user2_id = ' . $id . ' AND accepted = 1'; - $_query = $db->Execute($_query); - if($_query->fields[0] > 0) - { - return true; - } - else - { - return false; - } + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE user2_id = ' . $user->data['user_id'] . ' AND user2_id = ' . $id . ' AND accepted = 1'; + $_query = $db->Execute($_query); + if($_query->fields[0] > 0) + { + return true; + } + else + { + return false; + } } } } @@ -330,6 +330,36 @@ } } } + /* + Function Name: remove_friend + Arguments: (int) user_id -- user_id of the friend to remove + Purpose: Remove a user from your friends list + */ + function remove_friend($user_id) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + if($user->is_friend($id)) + { + $error->general("Already friend", "Add as friend"); + } + + $_query = 'DELETE FROM ' . AS_TBL_FRIEND . ' WHERE user1_id = ' . $user_id . ' AND user2_id = ' . $user->data['user_id']; + if ($db->Execute($_query) === false) + { + $_query = 'DELETE FROM ' . AS_TBL_FRIEND . ' WHERE user2_id = ' . $user_id . ' AND user1_id = ' . $user->data['user_id']; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'user.php - remove_friend(): '.$db->ErrorMsg()); + return false; + } + } + return true; + } /* Function Name: add_coment Arguments: (int) id -- ID of user who comment is directed to @@ -484,7 +514,7 @@ . $user->data['user_id'] . ', ' . $grp_id . ', ' . ', ' . time(). ')'; if ($db->Execute($_query) === false) { - $error->general('Problem joining group', 'Unknown problem joining group: ' . $db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - join_group(): '.$db->ErrorMsg()); return false; } } @@ -505,7 +535,7 @@ . $user->data['user_id'] . ' AND group_id = ' . $grp_id; if ($db->Execute($_query) === false) { - $error->general('Problem leaving group', 'Unknown problem leaving group: ' . $db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - leave_group(): '.$db->ErrorMsg()); return false; } } @@ -537,7 +567,7 @@ $_query = 'DELETE FROM ' . AS_TBL_GRPRES . ' WHERE group_id = ' . $grp_id . ' AND user_id = ' . $user_id; if ($db->Execute($_query) === false) { - $error->general('Failed to kick user', 'Unknown problem removing user from group: ' . $db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - kick_from_group(): '.$db->ErrorMsg()); return false; } return true; @@ -560,7 +590,7 @@ . '(' . $db->qstr($name) . ', ' . $db->qstr($desc) . ', ' . $user->data['user_id'] . ', ' . time() . ')'; if ($db->Execute($_query) === false) { - $error->general('Problem creating group', 'Unknown problem creating group: ' . $db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - create_group(): '.$db->ErrorMsg()); return false; } return true; @@ -589,7 +619,7 @@ . ' WHERE group_id = ' . $grp_id; if ($db->Execute($_query) === false) { - $error->general('Problem editing group', 'Unknown problem editing group: ' . $db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - edit_group(): '.$db->ErrorMsg()); return false; } return true; @@ -622,7 +652,7 @@ $_query = 'DELETE FROM ' . AS_TBL_GRPS . ' WHERE group_id = ' . $grp_id; if ($db->Execute($_query) === false) { - $error->general('Problem deleting group', 'Unknown problem deleting group: ' . $db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - delete_group(): '.$db->ErrorMsg()); return false; } return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-05 03:43:56
|
Revision: 92 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=92&view=rev Author: deltalabs Date: 2007-08-04 20:43:57 -0700 (Sat, 04 Aug 2007) Log Message: ----------- Finished groups and added a description field to the group table. Modified Paths: -------------- trunk/develop/new-schema.sql trunk/functions/user.php Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-08-04 00:18:45 UTC (rev 91) +++ trunk/develop/new-schema.sql 2007-08-05 03:43:57 UTC (rev 92) @@ -60,6 +60,7 @@ CREATE TABLE `as_groups` ( `group_id` int(10) unsigned NOT NULL auto_increment, `name` varchar(45) NOT NULL, + `desc` text NOT NULL, `founder` int(11) unsigned NOT NULL, `create_timestamp` int(10) unsigned NOT NULL, PRIMARY KEY (`group_id`) Modified: trunk/functions/user.php =================================================================== --- trunk/functions/user.php 2007-08-04 00:18:45 UTC (rev 91) +++ trunk/functions/user.php 2007-08-05 03:43:57 UTC (rev 92) @@ -448,25 +448,192 @@ } /* Function Name: is_in_group - Arguments: (int) user_id -- id of user, (int) grp_id -- id of group + Arguments: (int) grp_id -- id of group Purpose: check to see whether or not user is part of a particular group */ - function is_in_group ($user_id, $grp_id) + function is_in_group ($grp_id) { - if (!is_numeric($user_id) and $user_id != null) + if (!is_numeric($grp_id) and $grp_id != null) { - $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); return false; } - else if (!is_numeric($grp_id) and $grp_id != null) + + $_query = 'SELECT pair_id FROM '.AS_TBL_GRPRES.' WHERE user_id = ' . $user->data['user_id'] . ' AND group_id = ' . $grp_id; + $res = $db->GetArray($db->Execute($_query)); + if (count($res) > 0) { + return true; + } + return false; + } + /* + Function Name: join_group + Arguments: (int) grp_id -- id of group + Purpose: join a group + */ + function join_group ($grp_id) + { + if (!is_numeric($grp_id) and $grp_id != null) + { $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); return false; } + + $_query = 'INSERT INTO ' . AS_TBL_GRPRES . ' (user_id, group_id, join_date) VALUES (' + . $user->data['user_id'] . ', ' . $grp_id . ', ' . ', ' . time(). ')'; + if ($db->Execute($_query) === false) + { + $error->general('Problem joining group', 'Unknown problem joining group: ' . $db->ErrorMsg()); + return false; + } + } + /* + Function Name: leave_group + Arguments: (int) grp_id -- id of group + Purpose: leave a group + */ + function leave_group ($grp_id) + { + if (!is_numeric($grp_id) and $grp_id != null) + { + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + $_query = 'DELETE FROM ' . AS_TBL_GRPRES . ' WHERE user_id = ' + . $user->data['user_id'] . ' AND group_id = ' . $grp_id; + if ($db->Execute($_query) === false) + { + $error->general('Problem leaving group', 'Unknown problem leaving group: ' . $db->ErrorMsg()); + return false; + } + } + /* + Function Name: kick_from_group + Arguments: (int) grp_id -- id of group, (int) user_id -- id of user to kick + Purpose: forcefully remove a user from your group + */ + function kick_from_group ($grp_id, $user_id) + { + $_query = 'SELECT founder FROM ' . AS_TBL_GRP . ' WHERE founder = ' . $user->data['user_id']; + $_query = $db->Execute($_query); + $res = $db->GetArray($_query); + $founder_id = $res[0]['founder']; - /* Work in progress... */ + if ($user->data['user_id'] == $founder_id) + { + if (!is_numeric($grp_id) and $grp_id != null) + { + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + else if (!is_numeric($user_id) and $user_id != null) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + $_query = 'DELETE FROM ' . AS_TBL_GRPRES . ' WHERE group_id = ' . $grp_id . ' AND user_id = ' . $user_id; + if ($db->Execute($_query) === false) + { + $error->general('Failed to kick user', 'Unknown problem removing user from group: ' . $db->ErrorMsg()); + return false; + } + return true; + } } /* + Function Name: create_group + Arguments: (string) name -- name of group, (string) desc -- description of the group + Purpose: create a group + */ + function create_group ($name, $desc) + { + if (!is_numeric($grp_id) and $grp_id != null) + { + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + $_query = 'INSERT INTO ' . AS_TBL_GRPS . ' (name, desc, founder, create_timestamp) VALUES ' + . '(' . $db->qstr($name) . ', ' . $db->qstr($desc) . ', ' . $user->data['user_id'] . ', ' . time() . ')'; + if ($db->Execute($_query) === false) + { + $error->general('Problem creating group', 'Unknown problem creating group: ' . $db->ErrorMsg()); + return false; + } + return true; + } + /* + Function Name: edit_group + Arguments: (int) grp_id, id of the group to edit, (string) new_name -- new name of group, (string) desc -- new description of the group + Purpose: modify a group + */ + function edit_group ($grp_id, $new_name, $new_desc) + { + $_query = 'SELECT founder FROM ' . AS_TBL_GRP . ' WHERE founder = ' . $user->data['user_id']; + $_query = $db->Execute($_query); + $res = $db->GetArray($_query); + $founder_id = $res[0]['founder']; + + if ($user->data['user_id'] == $founder_id) + { + if (!is_numeric($grp_id) and $grp_id != null) + { + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + $_query = 'UPDATE ' . AS_TBL_GRPS . ' SET name = ' . $db->qstr($new_name) . ', desc = ' . $db->qstr($new_desc) + . ' WHERE group_id = ' . $grp_id; + if ($db->Execute($_query) === false) + { + $error->general('Problem editing group', 'Unknown problem editing group: ' . $db->ErrorMsg()); + return false; + } + return true; + } + else + { + $error->general('Problem editing group', "You don't have permission to edit this group!"); + return false; + } + } + /* + Function Name: delete_group + Arguments: (int) grp_id + Purpose: remove an existing group + */ + function delete_group ($grp_id) + { + $_query = 'SELECT founder FROM ' . AS_TBL_GRP . ' WHERE founder = ' . $user->data['user_id']; + $_query = $db->Execute($_query); + $res = $db->GetArray($_query); + $founder_id = $res[0]['founder']; + if ($user->data['user_id'] == $founder_id) + { + if (!is_numeric($grp_id) and $grp_id != null) + { + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + $_query = 'DELETE FROM ' . AS_TBL_GRPS . ' WHERE group_id = ' . $grp_id; + if ($db->Execute($_query) === false) + { + $error->general('Problem deleting group', 'Unknown problem deleting group: ' . $db->ErrorMsg()); + return false; + } + return true; + } + else + { + $error->general('Problem deleting group', "You don't have permission to delete this group!"); + return false; + } + } + /* Function Name: generate_timestamp Arguments: (int) time -- time to parse Purpose: Generate datestamp of time passed, taking user's time offset into consideration This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-04 00:18:42
|
Revision: 91 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=91&view=rev Author: deltalabs Date: 2007-08-03 17:18:45 -0700 (Fri, 03 Aug 2007) Log Message: ----------- had to add the constant for the static_profile_fields table to config.php, and finished fitting the queries in user.php to the new schema. I also added the `who` field to the actions table in the schema Modified Paths: -------------- trunk/config.php trunk/develop/new-schema.sql trunk/functions/user.php Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-08-03 23:08:43 UTC (rev 90) +++ trunk/config.php 2007-08-04 00:18:45 UTC (rev 91) @@ -21,6 +21,7 @@ from functioning. */ define('AS_TBL_USERS', AS_DB_PREFIX.'users'); +define('AS_TBL_STATIC_PROFILE_FIELDS', AS_DB_PREFIX.'static_profile_fields'); define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-08-03 23:08:43 UTC (rev 90) +++ trunk/develop/new-schema.sql 2007-08-04 00:18:45 UTC (rev 91) @@ -1,6 +1,7 @@ DROP TABLE IF EXISTS `as_actions`; CREATE TABLE `as_actions` ( `action_id` int(10) unsigned NOT NULL auto_increment, + `who` int(11) unsigned NOT NULL, `action_timestamp` int(10) unsigned NOT NULL, `action` int(2) unsigned NOT NULL, `for` int(11) unsigned NOT NULL, Modified: trunk/functions/user.php =================================================================== --- trunk/functions/user.php 2007-08-03 23:08:43 UTC (rev 90) +++ trunk/functions/user.php 2007-08-04 00:18:45 UTC (rev 91) @@ -30,10 +30,10 @@ /* 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 '.AS_TBL_SESSION.' (id, user_id, ip, last_update) VALUES(' . $id . ','.$db->qstr('-1').',' . $db->qstr($_SERVER['REMOTE_ADDR']) . ',' . time() . ')'; + $_query = 'INSERT INTO '.AS_TBL_SESSION.' (session_id, user_id, ip, last_update) VALUES(' . $id . ','.$db->qstr('-1').',' . $db->qstr($_SERVER['REMOTE_ADDR']) . ',' . time() . ')'; if ($db->Execute($_query) === false) { - $error->general('<b>DB Error!</b>', 'session.php - create(): '.$db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - create(): '.$db->ErrorMsg()); return false; } $_COOKIE['session_id'] = $id; @@ -74,7 +74,7 @@ } } /* Update our updated time */ - $_query = 'UPDATE '.AS_TBL_SESSION.' SET last_update = ' . time() . ' WHERE id = ' . $user->data['id'] . ' LIMIT 1'; + $_query = 'UPDATE '.AS_TBL_SESSION.' SET last_update = ' . time() . ' WHERE session_id = ' . $user->data['id'] . ' LIMIT 1'; if ($db->Execute($_query) === false) { $error->general('<b>DB Error!</b>', 'session.php - check(): '.$db->ErrorMsg()); @@ -126,10 +126,10 @@ } else { - $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = ' . $user_id . ' WHERE id = ' . $db->qstr($_COOKIE["session_id"]) . ' LIMIT 1'; + $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = ' . $user_id . ' WHERE session_id = ' . $db->qstr($_COOKIE["session_id"]) . ' LIMIT 1'; if ($db->Execute($_query) === false) { - $error->general('<b>DB Error!</b>', 'session.php - login(): '.$db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - login(): '.$db->ErrorMsg()); return false; } /* Run the session check again. It'll make the row and populate $user->data */ @@ -145,7 +145,7 @@ { if($session->logged_in()) { - $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = '.$db->qstr('-1').' WHERE id = ' . $user->data['id'] . ' AND ip = ' . $db->qstr($user->data['ip']) . ' LIMIT 1'; + $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = '.$db->qstr('-1').' WHERE session_id = ' . $user->data['id'] . ' AND ip = ' . $db->qstr($user->data['ip']) . ' LIMIT 1'; $db->query($_query); $user->data = null; } @@ -172,7 +172,7 @@ } else { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_1 = ' . $user->data['user_id'] . ' AND party_2 = ' . $id . ' AND accepted = 1'; + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE user1_id = ' . $user->data['user_id'] . ' AND user2_id = ' . $id . ' AND accepted = 1'; $_query = $db->Execute($_query); if($_query->fields[0] > 0) { @@ -180,7 +180,7 @@ } else { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_2 = ' . $user->data['user_id'] . ' AND party_1 = ' . $id . ' AND accepted = 1'; + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE user2_id = ' . $user->data['user_id'] . ' AND user2_id = ' . $id . ' AND accepted = 1'; $_query = $db->Execute($_query); if($_query->fields[0] > 0) { @@ -221,7 +221,7 @@ 7. Left you a comment on a blog post 8. Joined a group 9. Created a group */ - $_query = 'INSERT INTO '.AS_TBL_ACTION.' (time, who, action, for) VALUES(' . time() . ',' . $user->data['user_id'] . ', ' . $action . ', ' . $who . ')'; + $_query = 'INSERT INTO '.AS_TBL_ACTION.' (action_timestamp, who, action, for) VALUES(' . time() . ',' . $user->data['user_id'] . ', ' . $action . ', ' . $who . ')'; $db->query($_query); return true; } @@ -250,7 +250,7 @@ } else { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE (party_1 = ' . $user->data['user_id'] . ' AND party_2 = ' . $id; + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE (user1_id = ' . $user->data['user_id'] . ' AND user2_id = ' . $id; $_query = $db->query($_query); if ($_query->fields[0] > 0) { @@ -258,7 +258,7 @@ } else { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_2 = ' . $user->data['user_id'] . ' AND party_1 = ' . $id; + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE user1_id = ' . $user->data['user_id'] . ' AND user1_id = ' . $id; $_query = $db->Execute($_query); if ($_query->fields[0] > 0) { @@ -290,7 +290,7 @@ $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); return false; } - $_query= 'UPDATE '.AS_TBL_FRIEND.' SET accepted = 1 WHERE party_2 = '.$data->user['user_id'].' AND party_1 = '.$id.' LIMIT 1'; + $_query= 'UPDATE '.AS_TBL_FRIEND.' SET accepted = 1 WHERE user2_id = '.$data->user['user_id'].' AND user1_id = '.$id.' LIMIT 1'; $db->query($_query); $user->action(5, $id); } @@ -308,7 +308,7 @@ } /*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 '.AS_TBL_USER.' WHERE id = ' . $id . ' LIMIT 1'; + $_query = 'SELECT privacy FROM '.AS_TBL_USER.' WHERE user_id = ' . $id . ' LIMIT 1'; $_query = $db->Execute($_query); $_query = $db->GetArray($_query); $res = $_query[0]['privacy']; @@ -414,7 +414,7 @@ $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); return false; } - $_query = 'SELECT display_name FROM '.AS_TBL_USER.' WHERE id = ' . $id; + $_query = 'SELECT display_name FROM '.AS_TBL_STATIC_PROFILE_FIELDS.' WHERE static_profile_field_id = ' . $id; $_query = $db->Execute($_query); $res = $db->GetArray($_query); return $res[0]['display_name']; @@ -432,13 +432,13 @@ return false; } - $owner = 'SELECT owner_id FROM '.AS_TBL_IMG.' WHERE id = ' . $id; + $owner = 'SELECT owner_id FROM '.AS_TBL_IMG.' WHERE img_id = ' . $id; $owner = $db->query($owner); $owner = $db->fetch_array($owner); $owner = $owner['owner']; if ($session->is_friend($owner)) { - $_query = 'INSERT INTO '.AS_TBL_IMG_CMT.' (image_id, post_timestamp, author, comment) VALUES('. $id . ',' . time() . ',' . $user->data['user_id'] . ',' . $db->qstr($_POST['comment'],get_magic_quotes_gpc()) . ')'; + $_query = 'INSERT INTO '.AS_TBL_IMG_CMT.' (img_id, post_timestamp, author, comment) VALUES('. $id . ',' . time() . ',' . $user->data['user_id'] . ',' . $db->qstr($_POST['comment'],get_magic_quotes_gpc()) . ')'; if ($db->Execute($_query) === false) { $error->general('<b>DB Error!</b>', 'session.php - add_img_comment(): '.$db->ErrorMsg()); @@ -447,6 +447,26 @@ } } /* + Function Name: is_in_group + Arguments: (int) user_id -- id of user, (int) grp_id -- id of group + Purpose: check to see whether or not user is part of a particular group + */ + function is_in_group ($user_id, $grp_id) + { + if (!is_numeric($user_id) and $user_id != null) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + else if (!is_numeric($grp_id) and $grp_id != null) + { + $error->general('Invalid groupID', "Invalid groupID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + /* Work in progress... */ + } + /* Function Name: generate_timestamp Arguments: (int) time -- time to parse Purpose: Generate datestamp of time passed, taking user's time offset into consideration @@ -461,7 +481,7 @@ if($session->logged_in()) { - $_query = 'SELECT time_offset FROM '.AS_TBL_USER.' WHERE id = ' . $user->data['user_id']; + $_query = 'SELECT time_offset FROM '.AS_TBL_USER.' WHERE user_id = ' . $user->data['user_id']; $_query = $db->Execute($_query); $_query = $query->GetArray($_query); $offset = $_query[0]['time_offset']; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <del...@us...> - 2007-08-03 23:08:43
|
Revision: 90 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=90&view=rev Author: deltalabs Date: 2007-08-03 16:08:43 -0700 (Fri, 03 Aug 2007) Log Message: ----------- Finished edit_comment and delete_comment functions Modified Paths: -------------- trunk/functions/user.php Modified: trunk/functions/user.php =================================================================== --- trunk/functions/user.php 2007-08-01 23:42:24 UTC (rev 89) +++ trunk/functions/user.php 2007-08-03 23:08:43 UTC (rev 90) @@ -349,13 +349,60 @@ time() . ',' . $user->data['user_id'] . ',' . $id . ',' . $db->qstr($_POST['body']).')'; if ($db->Execute($_query) === false) { - $error->general('<b>DB Error!</b>', 'session.php - add_comment(): '.$db->ErrorMsg()); + $error->general('<b>DB Error!</b>', 'user.php - add_comment(): '.$db->ErrorMsg()); return false; } $session->action('2', $id); } } /* + Function Name: delete_comment + Arguments: (int) id -- comment_ID of comment to be deleted + Purpose: Delete comment + */ + function delete_comment($id) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid userID', "Invalid userD = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + if($session->is_friend($id)) + { + /* Okay, we have permission to remove this comment */ + $_query = 'DELETE FROM ' . AS_TBL_CMT . ' WHERE comment_id = ' . $id; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'user.php - delete_comment(): '.$db->ErrorMsg()); + return false; + } + } + } + /* + Function Name: edit_comment + Arguments: (int) id -- comment_ID of comment to be edited + Purpose: Edit comment + */ + function edit_comment($id) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid userID', "Invalid userD = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + if($session->is_friend($id)) + { + /* Okay, we have permission to edit this comment */ + $_query = 'UPDATE ' . AS_TBL_CMT . ' SET comment = ' . $db->qstr($_POST['body']) . ' WHERE comment_id = ' + . $id; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'user.php - edit_comment(): '.$db->ErrorMsg()); + return false; + } + } + } + /* Function Name: get_username Arguments: (int) id -- User ID Purpose: Fetch username of user based on their unique ID This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-08-01 23:42:24
|
Revision: 89 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=89&view=rev Author: p3net Date: 2007-08-01 16:42:24 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Add user_level to users table to see if user is an admin or not. Modified Paths: -------------- trunk/develop/new-schema.sql trunk/functions/user.php Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-08-01 23:36:20 UTC (rev 88) +++ trunk/develop/new-schema.sql 2007-08-01 23:42:24 UTC (rev 89) @@ -1,156 +1,157 @@ -DROP TABLE IF EXISTS `as_actions`; -CREATE TABLE `as_actions` ( - `action_id` int(10) unsigned NOT NULL auto_increment, - `action_timestamp` int(10) unsigned NOT NULL, - `action` int(2) unsigned NOT NULL, - `for` int(11) unsigned NOT NULL, - PRIMARY KEY (`action_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_blog`; -CREATE TABLE `as_blog` ( - `blog_id` int(10) unsigned NOT NULL auto_increment, - `title` varchar(45) NOT NULL, - `blog_timestamp` int(10) unsigned NOT NULL, - `content` text NOT NULL, - `author_id` int(11) unsigned NOT NULL, - PRIMARY KEY (`blog_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_blog_comment`; -CREATE TABLE `as_blog_comment` ( - `comment_id` int(10) unsigned NOT NULL auto_increment, - `post_id` int(10) unsigned NOT NULL, - `author_id` int(10) unsigned NOT NULL, - `comment` text NOT NULL, - `post_timestamp` int(10) unsigned NOT NULL, - PRIMARY KEY (`comment_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_comments`; -CREATE TABLE `as_comments` ( - `comment_id` int(10) unsigned NOT NULL auto_increment, - `comment_timestamp` int(10) unsigned NOT NULL, - `poster_id` int(11) unsigned NOT NULL, - `recipient_id` int(11) unsigned NOT NULL, - `comment` text NOT NULL, - PRIMARY KEY (`comment_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_friends`; -CREATE TABLE `as_friends` ( - `couple_id` int(10) unsigned NOT NULL auto_increment, - `user1_id` int(10) unsigned NOT NULL, - `user2_id` int(10) unsigned NOT NULL, - `accepted` tinyint(1) unsigned NOT NULL, - PRIMARY KEY (`couple_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_group_resolver`; -CREATE TABLE `as_group_resolver` ( - `pair_id` int(10) unsigned NOT NULL auto_increment, - `user_id` int(10) unsigned NOT NULL, - `group_id` int(10) unsigned NOT NULL, - `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', - PRIMARY KEY (`pair_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_groups`; -CREATE TABLE `as_groups` ( - `group_id` int(10) unsigned NOT NULL auto_increment, - `name` varchar(45) NOT NULL, - `founder` int(11) unsigned NOT NULL, - `create_timestamp` int(10) unsigned NOT NULL, - PRIMARY KEY (`group_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_image_comments`; -CREATE TABLE `as_image_comments` ( - `comment_id` int(10) unsigned NOT NULL auto_increment, - `image_id` int(11) unsigned NOT NULL, - `post_timestamp` int(10) unsigned NOT NULL, - `author` int(11) unsigned NOT NULL, - `comment` text NOT NULL, - PRIMARY KEY (`comment_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_images`; -CREATE TABLE `as_images` ( - `img_id` int(10) unsigned NOT NULL auto_increment, - `owner_id` int(10) unsigned NOT NULL, - `content` blob NOT NULL COMMENT 'binary image', - `desc` text NOT NULL, - `width` int(4) unsigned NOT NULL, - `height` int(4) unsigned NOT NULL, - `name` text NOT NULL, - `views` int(6) unsigned NOT NULL, - `mime_type` varchar(20) NOT NULL, - PRIMARY KEY (`img_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_private_messages`; -CREATE TABLE `as_private_messages` ( - `message_id` int(10) unsigned NOT NULL auto_increment, - `sender_id` int(11) unsigned NOT NULL, - `recipient_id` int(11) unsigned NOT NULL, - `send_date` int(10) unsigned NOT NULL, - `subject` varchar(80) NOT NULL, - `message` text NOT NULL, - `read` tinyint(1) unsigned NOT NULL default '0', - PRIMARY KEY (`message_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_sessions`; -CREATE TABLE `as_sessions` ( - `session_id` int(10) unsigned NOT NULL auto_increment, - `user_id` int(11) unsigned NOT NULL, - `ip` varchar(12) NOT NULL, - `last_update` int(10) unsigned NOT NULL, - PRIMARY KEY (`session_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_users`; -CREATE TABLE `as_users` ( - `user_id` int(10) unsigned NOT NULL auto_increment, - `password` varchar(16) NOT NULL, - `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', - `last_login` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', - `time_offset` tinyint(3) unsigned NOT NULL, - `email` varchar(60) NOT NULL, - `privacy` tinyint(1) unsigned NOT NULL default '0', - PRIMARY KEY (`user_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_static_profile_fields`; -CREATE TABLE `as_static_profile_fields` ( - `static_profile_field_id` int(10) unsigned NOT NULL auto_increment, - `user_id` int(10) unsigned NOT NULL, - `display_name` varchar(45) NOT NULL, - `blurb` text NOT NULL, - `aim` varchar(45) NOT NULL, - `yim` varchar(45) NOT NULL, - `jabber` varchar(45) NOT NULL, - `irc` varchar(45) NOT NULL, - `icq` varchar(45) NOT NULL, - `msn` varchar(45) NOT NULL, - `user_image` int(11) unsigned NOT NULL, - PRIMARY KEY (`static_profile_field_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - - -DROP TABLE IF EXISTS `as_dynamic_profile_fields`; -CREATE TABLE `as_dynamic_profile_fields` ( - `dynamic_profile_field_id` int(10) unsigned NOT NULL auto_increment, - `field_name` varchar(128) NOT NULL default 'new field', - `field_description` varchar(128), - PRIMARY KEY (`dynamic_profile_field_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_dynamic_profile_values`; -CREATE TABLE `as_dynamic_profile_values` ( - `dynamic_profile_field_id` int(10) unsigned NOT NULL auto_increment, - `user_id` int(10) unsigned NOT NULL, - `field_name` varchar(128) NOT NULL default 'new field', - `field_value` varchar(128), -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - +DROP TABLE IF EXISTS `as_actions`; +CREATE TABLE `as_actions` ( + `action_id` int(10) unsigned NOT NULL auto_increment, + `action_timestamp` int(10) unsigned NOT NULL, + `action` int(2) unsigned NOT NULL, + `for` int(11) unsigned NOT NULL, + PRIMARY KEY (`action_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_blog`; +CREATE TABLE `as_blog` ( + `blog_id` int(10) unsigned NOT NULL auto_increment, + `title` varchar(45) NOT NULL, + `blog_timestamp` int(10) unsigned NOT NULL, + `content` text NOT NULL, + `author_id` int(11) unsigned NOT NULL, + PRIMARY KEY (`blog_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_blog_comment`; +CREATE TABLE `as_blog_comment` ( + `comment_id` int(10) unsigned NOT NULL auto_increment, + `post_id` int(10) unsigned NOT NULL, + `author_id` int(10) unsigned NOT NULL, + `comment` text NOT NULL, + `post_timestamp` int(10) unsigned NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_comments`; +CREATE TABLE `as_comments` ( + `comment_id` int(10) unsigned NOT NULL auto_increment, + `comment_timestamp` int(10) unsigned NOT NULL, + `poster_id` int(11) unsigned NOT NULL, + `recipient_id` int(11) unsigned NOT NULL, + `comment` text NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_friends`; +CREATE TABLE `as_friends` ( + `couple_id` int(10) unsigned NOT NULL auto_increment, + `user1_id` int(10) unsigned NOT NULL, + `user2_id` int(10) unsigned NOT NULL, + `accepted` tinyint(1) unsigned NOT NULL, + PRIMARY KEY (`couple_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_group_resolver`; +CREATE TABLE `as_group_resolver` ( + `pair_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(10) unsigned NOT NULL, + `group_id` int(10) unsigned NOT NULL, + `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', + PRIMARY KEY (`pair_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_groups`; +CREATE TABLE `as_groups` ( + `group_id` int(10) unsigned NOT NULL auto_increment, + `name` varchar(45) NOT NULL, + `founder` int(11) unsigned NOT NULL, + `create_timestamp` int(10) unsigned NOT NULL, + PRIMARY KEY (`group_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_image_comments`; +CREATE TABLE `as_image_comments` ( + `comment_id` int(10) unsigned NOT NULL auto_increment, + `image_id` int(11) unsigned NOT NULL, + `post_timestamp` int(10) unsigned NOT NULL, + `author` int(11) unsigned NOT NULL, + `comment` text NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_images`; +CREATE TABLE `as_images` ( + `img_id` int(10) unsigned NOT NULL auto_increment, + `owner_id` int(10) unsigned NOT NULL, + `content` blob NOT NULL COMMENT 'binary image', + `desc` text NOT NULL, + `width` int(4) unsigned NOT NULL, + `height` int(4) unsigned NOT NULL, + `name` text NOT NULL, + `views` int(6) unsigned NOT NULL, + `mime_type` varchar(20) NOT NULL, + PRIMARY KEY (`img_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_private_messages`; +CREATE TABLE `as_private_messages` ( + `message_id` int(10) unsigned NOT NULL auto_increment, + `sender_id` int(11) unsigned NOT NULL, + `recipient_id` int(11) unsigned NOT NULL, + `send_date` int(10) unsigned NOT NULL, + `subject` varchar(80) NOT NULL, + `message` text NOT NULL, + `read` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`message_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_sessions`; +CREATE TABLE `as_sessions` ( + `session_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(11) unsigned NOT NULL, + `ip` varchar(12) NOT NULL, + `last_update` int(10) unsigned NOT NULL, + PRIMARY KEY (`session_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_users`; +CREATE TABLE `as_users` ( + `user_id` int(10) unsigned NOT NULL auto_increment, + `password` varchar(16) NOT NULL, + `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', + `last_login` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', + `time_offset` tinyint(3) unsigned NOT NULL, + `email` varchar(60) NOT NULL, + `privacy` tinyint(1) unsigned NOT NULL default '0', + `user_level` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_static_profile_fields`; +CREATE TABLE `as_static_profile_fields` ( + `static_profile_field_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(10) unsigned NOT NULL, + `display_name` varchar(45) NOT NULL, + `blurb` text NOT NULL, + `aim` varchar(45) NOT NULL, + `yim` varchar(45) NOT NULL, + `jabber` varchar(45) NOT NULL, + `irc` varchar(45) NOT NULL, + `icq` varchar(45) NOT NULL, + `msn` varchar(45) NOT NULL, + `user_image` int(11) unsigned NOT NULL, + PRIMARY KEY (`static_profile_field_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + + +DROP TABLE IF EXISTS `as_dynamic_profile_fields`; +CREATE TABLE `as_dynamic_profile_fields` ( + `dynamic_profile_field_id` int(10) unsigned NOT NULL auto_increment, + `field_name` varchar(128) NOT NULL default 'new field', + `field_description` varchar(128), + PRIMARY KEY (`dynamic_profile_field_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_dynamic_profile_values`; +CREATE TABLE `as_dynamic_profile_values` ( + `dynamic_profile_field_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(10) unsigned NOT NULL, + `field_name` varchar(128) NOT NULL default 'new field', + `field_value` varchar(128), +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + Modified: trunk/functions/user.php =================================================================== --- trunk/functions/user.php 2007-08-01 23:36:20 UTC (rev 88) +++ trunk/functions/user.php 2007-08-01 23:42:24 UTC (rev 89) @@ -424,5 +424,28 @@ $time = $time + $diff; return date('m/d/Y G:i:s', $time); } + function is_admin() + { + if($session->logged_in()) + { + $_query="SELECT `user_level` FROM " . AS_TBL_USERS . " WHERE `user_id`='" . $user->data['user_id'] . "'"; + $db->Execute($_query); + + $res = $db->FetchArray($_query); + $res = $res['user_leve']; + if($res == 1) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } + } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-08-01 23:36:19
|
Revision: 88 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=88&view=rev Author: p3net Date: 2007-08-01 16:36:20 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Remove delete() as I really don't see a need for it. We can allow admin to delete user, but no real reason for users to delete themselves. Modified Paths: -------------- trunk/profile.php Modified: trunk/profile.php =================================================================== --- trunk/profile.php 2007-08-01 23:35:29 UTC (rev 87) +++ trunk/profile.php 2007-08-01 23:36:20 UTC (rev 88) @@ -74,15 +74,6 @@ } /* - 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 @@ -247,9 +238,6 @@ case 'edit': $profile->edit(); break; - case 'delete': - $profile->delete(); - break; case 'pics': $profile->pics(); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-08-01 23:35:29
|
Revision: 87 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=87&view=rev Author: p3net Date: 2007-08-01 16:35:29 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Fix a bit of loopiness caused by caleb and frcole Modified Paths: -------------- trunk/profile.php Modified: trunk/profile.php =================================================================== --- trunk/profile.php 2007-08-01 23:32:07 UTC (rev 86) +++ trunk/profile.php 2007-08-01 23:35:29 UTC (rev 87) @@ -1,270 +1,272 @@ -<?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$ -*********************************************************/ -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(AS_TPL.'forms/register.tpl'); - } - else if($step == 2) - { - $_query = 'INSERT INTO '.AS_TBL_USERS.' (display_name, password, join_date, time_offset) '; - $_query .= 'VALUES('.$db->qstr($vars["display_name"],get_magic_quotes_gpc()).','; - $_query .= $db->qstr(md5($vars["password"]),get_magic_quotes_gpc()).','; - $_query .= mktime().','.qstr($vars["offset"],get_magic_quotes_gpc()).')'; - - if ($db->Execute($_query) === false) - { - $error->general("<b>DB Error!</b>", $db->ErrorMsg()); - return false; - } else { - $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() - { - - // DONT USE ME YET, IM STILL BROKEN!!! - $form =& new template(AS_TPL.'forms/edit_profile.tpl'); - - $_query1 = "SELECT * from " . AS_TBL_USERS . " where user_id='" . $user_id . "'"; - $_query2 = "SELECT * from " . AS_TBL_SPROFLDS . " where user_id='" . $user_id . "'"; - $_query3 = "SELECT * from " . AS_TBL_DPROFLDS . " where user_id='" . $user_id . "'"; - - if (($db->Execute($_query1) == false) || ($db->Execute($_query2) == false) || ($db->Execute($_query3) == false)) - { - $error->general("<b>DB Error!</b>", $db->ErrorMsg()); - return false; - } - - } - /* - 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(AS_TPL.'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 '.AS_TBL_IMG.' (owner_id, content, mime_type, desc, width, height, name, views)' - .'VALUES('. $user->data["user_id"] . ',' . $db->qstr($content) . ',' . $db->qstr($file_type) . "', ''" - .$db->qstr(htmlspecialchars($_POST["desc"]),get_magic_quotes_gpc()).','.$width.','.$height.','.$db->qstr($file_name,get_magic_quotes_gpc()).", '0')"; - if ($db->Execute($_query) === false) - { - $error->general("<b>DB Error!</b>", $db->ErrorMsg()); - return false; - } - - $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(AS_TPL.'forms/login.tpl'); - } - else - { - foreach($_POST as $key => $value) - { - $var[$key] = $db->qstr(htmlspecialchars($value),get_magic_quotes_gpc()); - } - $_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); - $_query = $db->Execute($_query); - $num = $_query->RecordCount(); - if($num > 0) - { - $id = $_query->GetArray(); - $session->login($id[0]['user_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() - { - $_uid_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); - $_uid_query = $db->Execute($_query); - $uid = $_query->GetArray(); - $_query = 'SELECT message_id, sender_id, send_date, subject, read FROM '.AS_TBL_PM.' WHERE recipient_id = '.$uid[0]['user_id'].' ORDER BY id DESC'; - $_query = $db->Execute($_query); - $count = $_query->RecordCount(); - for ($i = 0; $i < $count; $i++) - { - $pm[$i] = array( - 'id' => $_query->Fields('message_id'), - 'from' => $session->get_username($_query->Fields('sender_id')), - 'date' => $session->generate_timestamp($_query->Fields('send_date')), - 'subject' => $_query->Fields('subject'), - 'read' => $_query->Fields('read') - ); - $_query->MoveNext(); - } - $template =& new template(AS_TPL.'inbox.tpl'); - $template->set_var('pm', $pm); - } - /* - Function Name: message - Arguments: (int) id -- Private message ID - Purpose: Display a private message - */ - function message($id) - { - if (!is_numeric($id)) - { - $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - $_query = 'SELECT * FROM '.AS_TBL_PM.' WHERE message_id = ' . $id; - $_query = $db->Execute($_query); - $array = $db->GetArray($_query); - $read =& new template(AS_TPL.'read.tpl'); - $read->set_var('from', $session->get_username($array[0]["sender_id"])); - $read->set_var('date', $session->generate_timestamp($array[0]["send_date"])); - $read->set_var('subject', $array[0]["subject"]); - $read->set_var('message', $array[0]["message"]); - if($array[0]['read'] != '1') - { - $_query = 'UPDATE '.AS_TBL_PM.' SET read = 1 WHERE id = ' . $id; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', $db->ErrorMsg()); - return false; - } - } - } - /* - Function Name: send - Arguments: none - Purpose: Display a form to send a private message - */ - function send() - { - $template =& new template(AS_TPL.'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; -} -?> +<?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$ +*********************************************************/ +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(AS_TPL.'forms/register.tpl'); + } + else if($step == 2) + { + $_query = 'INSERT INTO '.AS_TBL_USERS.' (display_name, password, join_date, time_offset) '; + $_query .= 'VALUES('.$db->qstr($vars["display_name"],get_magic_quotes_gpc()).','; + $_query .= $db->qstr(md5($vars["password"]),get_magic_quotes_gpc()).','; + $_query .= mktime().','.qstr($vars["offset"],get_magic_quotes_gpc()).')'; + + if ($db->Execute($_query) === false) + { + $error->general("<b>DB Error!</b>", $db->ErrorMsg()); + return false; + } + else + { + $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() + { + + // DONT USE ME YET, IM STILL BROKEN!!! + $form =& new template(AS_TPL.'forms/edit_profile.tpl'); + + $_query1 = "SELECT * from " . AS_TBL_USERS . " where user_id='" . $user->data['user_id'] . "'"; + $_query2 = "SELECT * from " . AS_TBL_SPROFLDS . " where user_id='" . $user->data['user_id'] . "'"; + $_query3 = "SELECT * from " . AS_TBL_DPROFLDS . " where user_id='" . $user->data['user_id'] . "'"; + + if (($db->Execute($_query1) == false) || ($db->Execute($_query2) == false) || ($db->Execute($_query3) == false)) + { + $error->general("<b>DB Error!</b>", $db->ErrorMsg()); + return false; + } + + } + /* + 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(AS_TPL.'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 '.AS_TBL_IMG.' (owner_id, content, mime_type, desc, width, height, name, views)' + .'VALUES('. $user->data["user_id"] . ',' . $db->qstr($content) . ',' . $db->qstr($file_type) . "', ''" + .$db->qstr(htmlspecialchars($_POST["desc"]),get_magic_quotes_gpc()).','.$width.','.$height.','.$db->qstr($file_name,get_magic_quotes_gpc()).", '0')"; + if ($db->Execute($_query) === false) + { + $error->general("<b>DB Error!</b>", $db->ErrorMsg()); + return false; + } + + $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(AS_TPL.'forms/login.tpl'); + } + else + { + foreach($_POST as $key => $value) + { + $var[$key] = $db->qstr(htmlspecialchars($value),get_magic_quotes_gpc()); + } + $_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); + $_query = $db->Execute($_query); + $num = $_query->RecordCount(); + if($num > 0) + { + $id = $_query->GetArray(); + $user->login($id[0]['user_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() + { + $_uid_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); + $_uid_query = $db->Execute($_query); + $uid = $_query->GetArray(); + $_query = 'SELECT message_id, sender_id, send_date, subject, read FROM '.AS_TBL_PM.' WHERE recipient_id = '.$uid[0]['user_id'].' ORDER BY id DESC'; + $_query = $db->Execute($_query); + $count = $_query->RecordCount(); + for ($i = 0; $i < $count; $i++) + { + $pm[$i] = array( + 'id' => $_query->Fields('message_id'), + 'from' => $user->get_username($_query->Fields('sender_id')), + 'date' => $user->generate_timestamp($_query->Fields('send_date')), + 'subject' => $_query->Fields('subject'), + 'read' => $_query->Fields('read') + ); + $_query->MoveNext(); + } + $template =& new template(AS_TPL.'inbox.tpl'); + $template->set_var('pm', $pm); + } + /* + Function Name: message + Arguments: (int) id -- Private message ID + Purpose: Display a private message + */ + function message($id) + { + if (!is_numeric($id)) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + $_query = 'SELECT * FROM '.AS_TBL_PM.' WHERE message_id = ' . $id; + $_query = $db->Execute($_query); + $array = $db->GetArray($_query); + $read =& new template(AS_TPL.'read.tpl'); + $read->set_var('from', $user->get_username($array[0]["sender_id"])); + $read->set_var('date', $user->generate_timestamp($array[0]["send_date"])); + $read->set_var('subject', $array[0]["subject"]); + $read->set_var('message', $array[0]["message"]); + if($array[0]['read'] != '1') + { + $_query = 'UPDATE '.AS_TBL_PM.' SET read = 1 WHERE id = ' . $id; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', $db->ErrorMsg()); + return false; + } + } + } + /* + Function Name: send + Arguments: none + Purpose: Display a form to send a private message + */ + function send() + { + $template =& new template(AS_TPL.'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; +} +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-08-01 23:32:09
|
Revision: 86 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=86&view=rev Author: p3net Date: 2007-08-01 16:32:07 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Forgot to commit these Modified Paths: -------------- trunk/gallery.php trunk/globals.php Modified: trunk/gallery.php =================================================================== --- trunk/gallery.php 2007-08-01 22:35:29 UTC (rev 85) +++ trunk/gallery.php 2007-08-01 23:32:07 UTC (rev 86) @@ -1,142 +1,142 @@ -<?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$ -*********************************************************/ - -class gallery -{ - /* - Function Name: view - Arguments: (int) id -- ID of user - Purpose: View gallery of user - */ - 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 img_id FROM '.AS_TBL_IMG.' WHERE owner_id = '.$db->qstr($id,get_magic_quotes_gpc()); - $_query = $db->Execute($_query); - $_query = $db->GetArray($_query); - $gallery = new template(AS_DIR_TPL.'gallery.tpl'); - $gallery->set_var('gallery', $_query); - } - } - } - /* - 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 ) ) - { - $error->general('An image must be specified', 'Tried to access drill without specifying image id'); - } - else - { - if( $session->is_friend($owner) ) - { - $_query = 'SELECT * FROM '.AS_TBL_IMG.' WHERE img_id = '.$db->qstr($img_id,get_magic_quotes_gpc()); - $img = $db->Execute( $_query ); - - $_query = 'SELECT * FROM '.AS_TBL_IMG_CMT.' WHERE image_id = '.$db->qstr($img_id,get_magic_quotes_gpc()); - $img_com = $db->Execute( $_query ); - - $count = $img_com->RecordCount(); - $array = $img_com->GetArray(); - foreach($array[0] as $key_name => $key_value) - { - if (!is_numeric($key_name)) - { - if ($key_value == 'author') - { - $key_value = $session->get_username($key_value); - } - $com[$key_name] = $key_value; - } - } - $img_com->Close(); - $img = $img->GetArray(); - - if ( isset($user->data['user_id']) and $user->data['user_id'] != $img['owner'] ) - { - $img['views']++; - $_query = 'UPDATE '.AS_TBL_IMG." SET views = '" . $views . "' WHERE img_id = '" . $img_id . "'"; - $db->query($_query); - } - $drill = new template(AS_TPL.'drill.tpl'); - $drill->set_var('id', $img_id); - $drill->set_var('comments', $com); - $drill->set_var('views', $img['views']); - $drill->set_var('desc', $img['desc']); - $drill->set_var('name', $img['name']); - } - } - } - /* - 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)) - { - $form = new template(AS_TPL.'forms/gallery_comment.tpl'); - } - } - /* - Function Name: comment_process - Arguments: none - Purpose: Insert image comment into database - */ - function comment_process() - { - $img_id = $_POST['id']; - $session->add_image_comment($img_id); - } -} - -include('globals.php'); -$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; -} +<?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$ +*********************************************************/ + +class gallery +{ + /* + Function Name: view + Arguments: (int) id -- ID of user + Purpose: View gallery of user + */ + function view($id) + { + if($id == 0) + { + $error->general('Must be logged in!', 'Tried to access gallery as owner while unauthenticated'); + } + else + { + if($user->is_friend($id)) + { + $_query = 'SELECT img_id FROM '.AS_TBL_IMG.' WHERE owner_id = '.$db->qstr($id,get_magic_quotes_gpc()); + $_query = $db->Execute($_query); + $_query = $db->GetArray($_query); + $gallery = new template(AS_DIR_TPL.'gallery.tpl'); + $gallery->set_var('gallery', $_query); + } + } + } + /* + 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 ) ) + { + $error->general('An image must be specified', 'Tried to access drill without specifying image id'); + } + else + { + if( $user->is_friend($owner) ) + { + $_query = 'SELECT * FROM '.AS_TBL_IMG.' WHERE img_id = '.$db->qstr($img_id,get_magic_quotes_gpc()); + $img = $db->Execute( $_query ); + + $_query = 'SELECT * FROM '.AS_TBL_IMG_CMT.' WHERE image_id = '.$db->qstr($img_id,get_magic_quotes_gpc()); + $img_com = $db->Execute( $_query ); + + $count = $img_com->RecordCount(); + $array = $img_com->GetArray(); + foreach($array[0] as $key_name => $key_value) + { + if (!is_numeric($key_name)) + { + if ($key_value == 'author') + { + $key_value = $user->get_username($key_value); + } + $com[$key_name] = $key_value; + } + } + $img_com->Close(); + $img = $img->GetArray(); + + if ( isset($user->data['user_id']) and $user->data['user_id'] != $img['owner'] ) + { + $img['views']++; + $_query = 'UPDATE '.AS_TBL_IMG." SET views = '" . $views . "' WHERE img_id = '" . $img_id . "'"; + $db->query($_query); + } + $drill = new template(AS_TPL.'drill.tpl'); + $drill->set_var('id', $img_id); + $drill->set_var('comments', $com); + $drill->set_var('views', $img['views']); + $drill->set_var('desc', $img['desc']); + $drill->set_var('name', $img['name']); + } + } + } + /* + Function Name: comment + Arguments: (int) id -- Image ID; (int) owner -- Image owner ID + Purpose: Display comment form + */ + function comment($id, $owner) + { + if($user->is_friend($owner)) + { + $form = new template(AS_TPL.'forms/gallery_comment.tpl'); + } + } + /* + Function Name: comment_process + Arguments: none + Purpose: Insert image comment into database + */ + function comment_process() + { + $img_id = $_POST['id']; + $user->add_image_comment($img_id); + } +} + +include('globals.php'); +$gallery =& new gallery(); +$mode = empty($_GET["mode"]) ? 'view' : $_GET["mode"]; +$id = empty($_GET["id"]) ? ($user->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 Modified: trunk/globals.php =================================================================== --- trunk/globals.php 2007-08-01 22:35:29 UTC (rev 85) +++ trunk/globals.php 2007-08-01 23:32:07 UTC (rev 86) @@ -1,79 +1,79 @@ -<?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$ -*********************************************************/ -/* Include our larger functions */ -require('./config.php'); //We can't include using a constant defined in the file we're including -require(AS_LOC_DIRECT.'functions/template.php'); -$template =& new template(); -require(AS_LOC_DIRECT.'functions/session.php'); -$user =& new session(); -require(AS_LOC_DIRECT.'functions/adodb/adodb.inc.php'); - -/*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(AS_TPL.'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(); - } -} -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(AS_TPL.'message/thank.tpl'); - $message->set_var('go1', $go1); - $message->set_var('go2', $go2); - $message->set_var('res1', $res1); - $message->set_var('res2', $res2); - $message->set_var('message', $message); - } -} - -/* Our functions living in globals.php */ -$error =& new error; -$message =& new message(); - -$db =& new ADOConnection(AS_DB_TYPE); -$db->Connect(AS_DB_HOST, AS_DB_USER, AS_DB_PASS, AS_DB_SCHEMA); +<?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$ +*********************************************************/ +/* Include our larger functions */ +require('./config.php'); //We can't include using a constant defined in the file we're including +require(AS_LOC_DIRECT.'functions/template.php'); +$template =& new template(); +require(AS_LOC_DIRECT.'functions/user.php'); +$user =& new user(); +require(AS_LOC_DIRECT.'functions/adodb/adodb.inc.php'); + +/*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(AS_TPL.'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(); + } +} +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(AS_TPL.'message/thank.tpl'); + $message->set_var('go1', $go1); + $message->set_var('go2', $go2); + $message->set_var('res1', $res1); + $message->set_var('res2', $res2); + $message->set_var('message', $message); + } +} + +/* Our functions living in globals.php */ +$error =& new error; +$message =& new message(); + +$db =& new ADOConnection(AS_DB_TYPE); +$db->Connect(AS_DB_HOST, AS_DB_USER, AS_DB_PASS, AS_DB_SCHEMA); ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2007-08-01 22:35:26
|
Revision: 85 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=85&view=rev Author: frcole Date: 2007-08-01 15:35:29 -0700 (Wed, 01 Aug 2007) Log Message: ----------- started on edit() function.... roughly. DONT USE IT YET -- frc Modified Paths: -------------- trunk/profile.php Modified: trunk/profile.php =================================================================== --- trunk/profile.php 2007-08-01 22:03:28 UTC (rev 84) +++ trunk/profile.php 2007-08-01 22:35:29 UTC (rev 85) @@ -1,257 +1,270 @@ -<?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$ -*********************************************************/ -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(AS_TPL.'forms/register.tpl'); - } - else if($step == 2) - { - $_query = 'INSERT INTO '.AS_TBL_USER.' (display_name, password, join_date, time_offset) '; - $_query .= 'VALUES('.$db->qstr($vars["display_name"],get_magic_quotes_gpc()).','; - $_query .= $db->qstr(md5($vars["password"]),get_magic_quotes_gpc()).','; - $_query .= mktime().','.qstr($vars["offset"],get_magic_quotes_gpc()).')'; - - if ($db->Execute($_query) === false) - { - $error->general("<b>DB Error!</b>", $db->ErrorMsg()); - return false; - } else { - $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(AS_TPL.'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 '.AS_TBL_IMG.' (owner_id, content, mime_type, desc, width, height, name, views)' - .'VALUES('. $user->data["user_id"] . ',' . $db->qstr($content) . ',' . $db->qstr($file_type) . "', ''" - .$db->qstr(htmlspecialchars($_POST["desc"]),get_magic_quotes_gpc()).','.$width.','.$height.','.$db->qstr($file_name,get_magic_quotes_gpc()).", '0')"; - if ($db->Execute($_query) === false) - { - $error->general("<b>DB Error!</b>", $db->ErrorMsg()); - return false; - } - - $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(AS_TPL.'forms/login.tpl'); - } - else - { - foreach($_POST as $key => $value) - { - $var[$key] = $db->qstr(htmlspecialchars($value),get_magic_quotes_gpc()); - } - $_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); - $_query = $db->Execute($_query); - $num = $_query->RecordCount(); - if($num > 0) - { - $id = $_query->GetArray(); - $session->login($id[0]['user_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() - { - $_uid_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); - $_uid_query = $db->Execute($_query); - $uid = $_query->GetArray(); - $_query = 'SELECT message_id, sender_id, send_date, subject, read FROM '.AS_TBL_PM.' WHERE recipient_id = '.$uid[0]['user_id'].' ORDER BY id DESC'; - $_query = $db->Execute($_query); - $count = $_query->RecordCount(); - for ($i = 0; $i < $count; $i++) - { - $pm[$i] = array( - 'id' => $_query->Fields('message_id'), - 'from' => $session->get_username($_query->Fields('sender_id')), - 'date' => $session->generate_timestamp($_query->Fields('send_date')), - 'subject' => $_query->Fields('subject'), - 'read' => $_query->Fields('read') - ); - $_query->MoveNext(); - } - $template =& new template(AS_TPL.'inbox.tpl'); - $template->set_var('pm', $pm); - } - /* - Function Name: message - Arguments: (int) id -- Private message ID - Purpose: Display a private message - */ - function message($id) - { - if (!is_numeric($id)) - { - $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - $_query = 'SELECT * FROM '.AS_TBL_PM.' WHERE message_id = ' . $id; - $_query = $db->Execute($_query); - $array = $db->GetArray($_query); - $read =& new template(AS_TPL.'read.tpl'); - $read->set_var('from', $session->get_username($array[0]["sender_id"])); - $read->set_var('date', $session->generate_timestamp($array[0]["send_date"])); - $read->set_var('subject', $array[0]["subject"]); - $read->set_var('message', $array[0]["message"]); - if($array[0]['read'] != '1') - { - $_query = 'UPDATE '.AS_TBL_PM.' SET read = 1 WHERE id = ' . $id; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', $db->ErrorMsg()); - return false; - } - } - } - /* - Function Name: send - Arguments: none - Purpose: Display a form to send a private message - */ - function send() - { - $template =& new template(AS_TPL.'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 +<?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$ +*********************************************************/ +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(AS_TPL.'forms/register.tpl'); + } + else if($step == 2) + { + $_query = 'INSERT INTO '.AS_TBL_USERS.' (display_name, password, join_date, time_offset) '; + $_query .= 'VALUES('.$db->qstr($vars["display_name"],get_magic_quotes_gpc()).','; + $_query .= $db->qstr(md5($vars["password"]),get_magic_quotes_gpc()).','; + $_query .= mktime().','.qstr($vars["offset"],get_magic_quotes_gpc()).')'; + + if ($db->Execute($_query) === false) + { + $error->general("<b>DB Error!</b>", $db->ErrorMsg()); + return false; + } else { + $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() + { + + // DONT USE ME YET, IM STILL BROKEN!!! + $form =& new template(AS_TPL.'forms/edit_profile.tpl'); + + $_query1 = "SELECT * from " . AS_TBL_USERS . " where user_id='" . $user_id . "'"; + $_query2 = "SELECT * from " . AS_TBL_SPROFLDS . " where user_id='" . $user_id . "'"; + $_query3 = "SELECT * from " . AS_TBL_DPROFLDS . " where user_id='" . $user_id . "'"; + + if (($db->Execute($_query1) == false) || ($db->Execute($_query2) == false) || ($db->Execute($_query3) == false)) + { + $error->general("<b>DB Error!</b>", $db->ErrorMsg()); + return false; + } + + } + /* + 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(AS_TPL.'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 '.AS_TBL_IMG.' (owner_id, content, mime_type, desc, width, height, name, views)' + .'VALUES('. $user->data["user_id"] . ',' . $db->qstr($content) . ',' . $db->qstr($file_type) . "', ''" + .$db->qstr(htmlspecialchars($_POST["desc"]),get_magic_quotes_gpc()).','.$width.','.$height.','.$db->qstr($file_name,get_magic_quotes_gpc()).", '0')"; + if ($db->Execute($_query) === false) + { + $error->general("<b>DB Error!</b>", $db->ErrorMsg()); + return false; + } + + $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(AS_TPL.'forms/login.tpl'); + } + else + { + foreach($_POST as $key => $value) + { + $var[$key] = $db->qstr(htmlspecialchars($value),get_magic_quotes_gpc()); + } + $_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); + $_query = $db->Execute($_query); + $num = $_query->RecordCount(); + if($num > 0) + { + $id = $_query->GetArray(); + $session->login($id[0]['user_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() + { + $_uid_query = 'SELECT user_id FROM '.AS_TBL_USER.' WHERE email = ' . $var['email'] . ' AND password = ' . qstr(md5($var['password'])); + $_uid_query = $db->Execute($_query); + $uid = $_query->GetArray(); + $_query = 'SELECT message_id, sender_id, send_date, subject, read FROM '.AS_TBL_PM.' WHERE recipient_id = '.$uid[0]['user_id'].' ORDER BY id DESC'; + $_query = $db->Execute($_query); + $count = $_query->RecordCount(); + for ($i = 0; $i < $count; $i++) + { + $pm[$i] = array( + 'id' => $_query->Fields('message_id'), + 'from' => $session->get_username($_query->Fields('sender_id')), + 'date' => $session->generate_timestamp($_query->Fields('send_date')), + 'subject' => $_query->Fields('subject'), + 'read' => $_query->Fields('read') + ); + $_query->MoveNext(); + } + $template =& new template(AS_TPL.'inbox.tpl'); + $template->set_var('pm', $pm); + } + /* + Function Name: message + Arguments: (int) id -- Private message ID + Purpose: Display a private message + */ + function message($id) + { + if (!is_numeric($id)) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + $_query = 'SELECT * FROM '.AS_TBL_PM.' WHERE message_id = ' . $id; + $_query = $db->Execute($_query); + $array = $db->GetArray($_query); + $read =& new template(AS_TPL.'read.tpl'); + $read->set_var('from', $session->get_username($array[0]["sender_id"])); + $read->set_var('date', $session->generate_timestamp($array[0]["send_date"])); + $read->set_var('subject', $array[0]["subject"]); + $read->set_var('message', $array[0]["message"]); + if($array[0]['read'] != '1') + { + $_query = 'UPDATE '.AS_TBL_PM.' SET read = 1 WHERE id = ' . $id; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', $db->ErrorMsg()); + return false; + } + } + } + /* + Function Name: send + Arguments: none + Purpose: Display a form to send a private message + */ + function send() + { + $template =& new template(AS_TPL.'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; +} +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2007-08-01 22:03:26
|
Revision: 84 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=84&view=rev Author: frcole Date: 2007-08-01 15:03:28 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Update config.php to reflect new tables as well as corrected some minor typos. --frc Modified Paths: -------------- trunk/config.php trunk/develop/new-schema.sql Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-08-01 20:09:38 UTC (rev 83) +++ trunk/config.php 2007-08-01 22:03:28 UTC (rev 84) @@ -1,37 +1,43 @@ -<?php -/* These settings are autogenerated by AstroSPACES - do not change them unless you know what you are - doing! -*/ -define('AS_DB_TYPE', 'mysql'); -define('AS_DB_PREFIX', 'as_'); -define('AS_DB_HOST', 'localhost'); -define('AS_DB_SCHEMA', 'schema'); -define('AS_DB_USER', 'user'); -define('AS_DB_PASS', 'pass'); - -define('AS_EXT', '.php'); -define('AS_LANG', 'en-us'); - -define('AS_LOC_URL', 'http://localhost/'); -define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); - -/* These settings are constants and must NOT - be altered. Doing so will prevent AstroSPACES - from functioning. -*/ -define('AS_TBL_USER', AS_DB_PREFIX.'user'); -define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); -define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comments'); -define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); -define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); -define('AS_TBL_IMG', AS_DB_PREFIX.'images'); -define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); -define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); -define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); -define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); -define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); - -define('AS_DIR_TPL', 'template/'); -define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); -?> \ No newline at end of file +<?php +/* These settings are autogenerated by AstroSPACES + do not change them unless you know what you are + doing! +*/ +define('AS_DB_TYPE', 'mysql'); +define('AS_DB_PREFIX', 'as_'); +define('AS_DB_HOST', 'localhost'); +define('AS_DB_SCHEMA', 'schema'); +define('AS_DB_USER', 'user'); +define('AS_DB_PASS', 'pass'); + +define('AS_EXT', '.php'); +define('AS_LANG', 'en-us'); + +define('AS_LOC_URL', 'http://localhost/'); +define('AS_LOC_DIRECT', 'C:/path/to/astrospaces/'); + +/* These settings are constants and must NOT + be altered. Doing so will prevent AstroSPACES + from functioning. +*/ +define('AS_TBL_USERS', AS_DB_PREFIX.'users'); +define('AS_TBL_BLOG', AS_DB_PREFIX.'blog'); +define('AS_TBL_BLOG_CMT', AS_DB_PREFIX.'blog_comment'); +define('AS_TBL_COMMENTS', AS_DB_PREFIX.'comments'); +define('AS_TBL_FRIEND', AS_DB_PREFIX.'friends'); +define('AS_TBL_IMG', AS_DB_PREFIX.'images'); +define('AS_TBL_IMG_CMT', AS_DB_PREFIX.'image_comments'); +define('AS_TBL_ACTION', AS_DB_PREFIX.'actions'); +define('AS_TBL_CMT', AS_DB_PREFIX.'comments'); +define('AS_TBL_SESSION', AS_DB_PREFIX.'sessions'); +define('AS_TBL_PM', AS_DB_PREFIX.'private_messages'); +define('AS_TBL_GRPRES', AS_DB_PREFIX.'group_resolver'); +define('AS_TBL_GRPS', AS_DB_PREFIX.'groups'); +define('AS_TBL_SPROFLDS', AS_DB_PREFIX.'static_profile_fields'); +define('AS_TBL_DPROFLDS', AS_DB_PREFIX.'dynamic_profile_fields'); +define('AS_TBL_DPROVAL', AS_DB_PREFIX.'dynamic_profile_values'); + +define('AS_DIR_TPL', 'template/'); +define('AS_TPL', AS_LOC_URL.AS_DIR_TPL.'default/'); +?> + Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-08-01 20:09:38 UTC (rev 83) +++ trunk/develop/new-schema.sql 2007-08-01 22:03:28 UTC (rev 84) @@ -117,14 +117,14 @@ `last_login` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', `time_offset` tinyint(3) unsigned NOT NULL, `email` varchar(60) NOT NULL, - `user_image` int(11) unsigned NOT NULL, `privacy` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`user_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; DROP TABLE IF EXISTS `as_static_profile_fields`; -CREATE TABLE `as_users` ( - `user_id` int(10) unsigned NOT NULL auto_increment, +CREATE TABLE `as_static_profile_fields` ( + `static_profile_field_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(10) unsigned NOT NULL, `display_name` varchar(45) NOT NULL, `blurb` text NOT NULL, `aim` varchar(45) NOT NULL, @@ -134,5 +134,23 @@ `icq` varchar(45) NOT NULL, `msn` varchar(45) NOT NULL, `user_image` int(11) unsigned NOT NULL, - PRIMARY KEY (`user_id`) + PRIMARY KEY (`static_profile_field_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; + + +DROP TABLE IF EXISTS `as_dynamic_profile_fields`; +CREATE TABLE `as_dynamic_profile_fields` ( + `dynamic_profile_field_id` int(10) unsigned NOT NULL auto_increment, + `field_name` varchar(128) NOT NULL default 'new field', + `field_description` varchar(128), + PRIMARY KEY (`dynamic_profile_field_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_dynamic_profile_values`; +CREATE TABLE `as_dynamic_profile_values` ( + `dynamic_profile_field_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(10) unsigned NOT NULL, + `field_name` varchar(128) NOT NULL default 'new field', + `field_value` varchar(128), +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fr...@us...> - 2007-08-01 20:09:36
|
Revision: 83 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=83&view=rev Author: frcole Date: 2007-08-01 13:09:38 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Split out profile field info into a separate table from user admin data. Will add a seperate table for dynamic/extensible profile fields later. This is necessary to make editing and otherwise maintaining Account data later on. -- frc Modified Paths: -------------- trunk/develop/new-schema.sql Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-08-01 15:11:05 UTC (rev 82) +++ trunk/develop/new-schema.sql 2007-08-01 20:09:38 UTC (rev 83) @@ -1,132 +1,138 @@ -DROP TABLE IF EXISTS `as_actions`; -CREATE TABLE `as_actions` ( - `action_id` int(10) unsigned NOT NULL auto_increment, - `action_timestamp` int(10) unsigned NOT NULL, - `action` int(2) unsigned NOT NULL, - `for` int(11) unsigned NOT NULL, - PRIMARY KEY (`action_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_blog`; -CREATE TABLE `as_blog` ( - `blog_id` int(10) unsigned NOT NULL auto_increment, - `title` varchar(45) NOT NULL, - `blog_timestamp` int(10) unsigned NOT NULL, - `content` text NOT NULL, - `author_id` int(11) unsigned NOT NULL, - PRIMARY KEY (`blog_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_blog_comment`; -CREATE TABLE `as_blog_comment` ( - `comment_id` int(10) unsigned NOT NULL auto_increment, - `post_id` int(10) unsigned NOT NULL, - `author_id` int(10) unsigned NOT NULL, - `comment` text NOT NULL, - `post_timestamp` int(10) unsigned NOT NULL, - PRIMARY KEY (`comment_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_comments`; -CREATE TABLE `as_comments` ( - `comment_id` int(10) unsigned NOT NULL auto_increment, - `comment_timestamp` int(10) unsigned NOT NULL, - `poster_id` int(11) unsigned NOT NULL, - `recipient_id` int(11) unsigned NOT NULL, - `comment` text NOT NULL, - PRIMARY KEY (`comment_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_friends`; -CREATE TABLE `as_friends` ( - `couple_id` int(10) unsigned NOT NULL auto_increment, - `user1_id` int(10) unsigned NOT NULL, - `user2_id` int(10) unsigned NOT NULL, - `accepted` tinyint(1) unsigned NOT NULL, - PRIMARY KEY (`couple_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_group_resolver`; -CREATE TABLE `as_group_resolver` ( - `pair_id` int(10) unsigned NOT NULL auto_increment, - `user_id` int(10) unsigned NOT NULL, - `group_id` int(10) unsigned NOT NULL, - `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', - PRIMARY KEY (`pair_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_groups`; -CREATE TABLE `as_groups` ( - `group_id` int(10) unsigned NOT NULL auto_increment, - `name` varchar(45) NOT NULL, - `founder` int(11) unsigned NOT NULL, - `create_timestamp` int(10) unsigned NOT NULL, - PRIMARY KEY (`group_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_image_comments`; -CREATE TABLE `as_image_comments` ( - `comment_id` int(10) unsigned NOT NULL auto_increment, - `image_id` int(11) unsigned NOT NULL, - `post_timestamp` int(10) unsigned NOT NULL, - `author` int(11) unsigned NOT NULL, - `comment` text NOT NULL, - PRIMARY KEY (`comment_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_images`; -CREATE TABLE `as_images` ( - `img_id` int(10) unsigned NOT NULL auto_increment, - `owner_id` int(10) unsigned NOT NULL, - `content` blob NOT NULL COMMENT 'binary image', - `desc` text NOT NULL, - `width` int(4) unsigned NOT NULL, - `height` int(4) unsigned NOT NULL, - `name` text NOT NULL, - `views` int(6) unsigned NOT NULL, - `mime_type` varchar(20) NOT NULL, - PRIMARY KEY (`img_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_private_messages`; -CREATE TABLE `as_private_messages` ( - `message_id` int(10) unsigned NOT NULL auto_increment, - `sender_id` int(11) unsigned NOT NULL, - `recipient_id` int(11) unsigned NOT NULL, - `send_date` int(10) unsigned NOT NULL, - `subject` varchar(80) NOT NULL, - `message` text NOT NULL, - `read` tinyint(1) unsigned NOT NULL default '0', - PRIMARY KEY (`message_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; - -DROP TABLE IF EXISTS `as_sessions`; -CREATE TABLE `as_sessions` ( - `session_id` int(10) unsigned NOT NULL auto_increment, - `user_id` int(11) unsigned NOT NULL, - `ip` varchar(12) NOT NULL, - `last_update` int(10) unsigned NOT NULL, - PRIMARY KEY (`session_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; - -DROP TABLE IF EXISTS `as_users`; -CREATE TABLE `as_users` ( - `user_id` int(10) unsigned NOT NULL auto_increment, - `display_name` varchar(45) NOT NULL, - `password` varchar(16) NOT NULL, - `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', - `last_login` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', - `time_offset` tinyint(3) unsigned NOT NULL, - `blurb` text NOT NULL, - `email` varchar(60) NOT NULL, - `aim` varchar(45) NOT NULL, - `yim` varchar(45) NOT NULL, - `jabber` varchar(45) NOT NULL, - `irc` varchar(45) NOT NULL, - `icq` varchar(45) NOT NULL, - `msn` varchar(45) NOT NULL, - `user_image` int(11) unsigned NOT NULL, - `clean_url` varchar(45) NOT NULL, - `privacy` tinyint(1) unsigned NOT NULL default '0', - PRIMARY KEY (`user_id`) -) ENGINE=MyISAM DEFAULT CHARSET=latin1; \ No newline at end of file +DROP TABLE IF EXISTS `as_actions`; +CREATE TABLE `as_actions` ( + `action_id` int(10) unsigned NOT NULL auto_increment, + `action_timestamp` int(10) unsigned NOT NULL, + `action` int(2) unsigned NOT NULL, + `for` int(11) unsigned NOT NULL, + PRIMARY KEY (`action_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_blog`; +CREATE TABLE `as_blog` ( + `blog_id` int(10) unsigned NOT NULL auto_increment, + `title` varchar(45) NOT NULL, + `blog_timestamp` int(10) unsigned NOT NULL, + `content` text NOT NULL, + `author_id` int(11) unsigned NOT NULL, + PRIMARY KEY (`blog_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_blog_comment`; +CREATE TABLE `as_blog_comment` ( + `comment_id` int(10) unsigned NOT NULL auto_increment, + `post_id` int(10) unsigned NOT NULL, + `author_id` int(10) unsigned NOT NULL, + `comment` text NOT NULL, + `post_timestamp` int(10) unsigned NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_comments`; +CREATE TABLE `as_comments` ( + `comment_id` int(10) unsigned NOT NULL auto_increment, + `comment_timestamp` int(10) unsigned NOT NULL, + `poster_id` int(11) unsigned NOT NULL, + `recipient_id` int(11) unsigned NOT NULL, + `comment` text NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_friends`; +CREATE TABLE `as_friends` ( + `couple_id` int(10) unsigned NOT NULL auto_increment, + `user1_id` int(10) unsigned NOT NULL, + `user2_id` int(10) unsigned NOT NULL, + `accepted` tinyint(1) unsigned NOT NULL, + PRIMARY KEY (`couple_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_group_resolver`; +CREATE TABLE `as_group_resolver` ( + `pair_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(10) unsigned NOT NULL, + `group_id` int(10) unsigned NOT NULL, + `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', + PRIMARY KEY (`pair_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_groups`; +CREATE TABLE `as_groups` ( + `group_id` int(10) unsigned NOT NULL auto_increment, + `name` varchar(45) NOT NULL, + `founder` int(11) unsigned NOT NULL, + `create_timestamp` int(10) unsigned NOT NULL, + PRIMARY KEY (`group_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_image_comments`; +CREATE TABLE `as_image_comments` ( + `comment_id` int(10) unsigned NOT NULL auto_increment, + `image_id` int(11) unsigned NOT NULL, + `post_timestamp` int(10) unsigned NOT NULL, + `author` int(11) unsigned NOT NULL, + `comment` text NOT NULL, + PRIMARY KEY (`comment_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_images`; +CREATE TABLE `as_images` ( + `img_id` int(10) unsigned NOT NULL auto_increment, + `owner_id` int(10) unsigned NOT NULL, + `content` blob NOT NULL COMMENT 'binary image', + `desc` text NOT NULL, + `width` int(4) unsigned NOT NULL, + `height` int(4) unsigned NOT NULL, + `name` text NOT NULL, + `views` int(6) unsigned NOT NULL, + `mime_type` varchar(20) NOT NULL, + PRIMARY KEY (`img_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_private_messages`; +CREATE TABLE `as_private_messages` ( + `message_id` int(10) unsigned NOT NULL auto_increment, + `sender_id` int(11) unsigned NOT NULL, + `recipient_id` int(11) unsigned NOT NULL, + `send_date` int(10) unsigned NOT NULL, + `subject` varchar(80) NOT NULL, + `message` text NOT NULL, + `read` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`message_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_sessions`; +CREATE TABLE `as_sessions` ( + `session_id` int(10) unsigned NOT NULL auto_increment, + `user_id` int(11) unsigned NOT NULL, + `ip` varchar(12) NOT NULL, + `last_update` int(10) unsigned NOT NULL, + PRIMARY KEY (`session_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; + +DROP TABLE IF EXISTS `as_users`; +CREATE TABLE `as_users` ( + `user_id` int(10) unsigned NOT NULL auto_increment, + `password` varchar(16) NOT NULL, + `join_date` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', + `last_login` int(10) unsigned NOT NULL COMMENT 'Unix timestamp', + `time_offset` tinyint(3) unsigned NOT NULL, + `email` varchar(60) NOT NULL, + `user_image` int(11) unsigned NOT NULL, + `privacy` tinyint(1) unsigned NOT NULL default '0', + PRIMARY KEY (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + +DROP TABLE IF EXISTS `as_static_profile_fields`; +CREATE TABLE `as_users` ( + `user_id` int(10) unsigned NOT NULL auto_increment, + `display_name` varchar(45) NOT NULL, + `blurb` text NOT NULL, + `aim` varchar(45) NOT NULL, + `yim` varchar(45) NOT NULL, + `jabber` varchar(45) NOT NULL, + `irc` varchar(45) NOT NULL, + `icq` varchar(45) NOT NULL, + `msn` varchar(45) NOT NULL, + `user_image` int(11) unsigned NOT NULL, + PRIMARY KEY (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-08-01 15:11:10
|
Revision: 82 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=82&view=rev Author: p3net Date: 2007-08-01 08:11:05 -0700 (Wed, 01 Aug 2007) Log Message: ----------- Rename session.php to user.php and change the class call to . I think I got all of the calls, if not, please fix them as you find the problems. Added Paths: ----------- trunk/functions/user.php Removed Paths: ------------- trunk/functions/session.php Deleted: trunk/functions/session.php =================================================================== --- trunk/functions/session.php 2007-08-01 00:15:01 UTC (rev 81) +++ trunk/functions/session.php 2007-08-01 15:11:05 UTC (rev 82) @@ -1,434 +0,0 @@ -<?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$ -*********************************************************/ -/******************************************************** -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 Name: create - Arguments: none - Purpose: create 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 '.AS_TBL_SESSION.' (id, user_id, ip, last_update) VALUES(' . $id . ','.$db->qstr('-1').',' . $db->qstr($_SERVER['REMOTE_ADDR']) . ',' . time() . ')'; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - create(): '.$db->ErrorMsg()); - return false; - } - $_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, - then we return false (since the user isn't logged in). We also match the IP */ - $ip = $_SERVER['REMOTE_ADDR']; - $_query = 'SELECT * FROM '.AS_TBL_SESSION.' WHERE ip = ' . $db->qstr($ip); - $res = $db->Execute($_query); - $count = $res->RecordCount(); - if($count == 0) - { - $session->create(); - } - else - { - /* Get an array of our session info */ - $res = $res->GetArray(); - if($res[0]['id'] != $_COOKIE['session_id']) - { - $session->create(); - } - else - { - $array = $res->GetArray(); - foreach($array[0] as $key => $value) - { - if (!is_numeric($key)) - { - $user->data[$key] = $value; - } - } - /* Update our updated time */ - $_query = 'UPDATE '.AS_TBL_SESSION.' SET last_update = ' . time() . ' WHERE id = ' . $user->data['id'] . ' LIMIT 1'; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - check(): '.$db->ErrorMsg()); - return false; - } - } - } - /* We also need to get rid of users who haven't done anything in the last half-hour */ - $_query = 'DELETE FROM '.AS_TBL_SESSION.' WHERE last_update < ' . (time() - (60*30)); - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - check(): '.$db->ErrorMsg()); - return false; - } - } - /* - Function Name: logged_in - Arguments: none - Purpose: check if user is logged in - */ - function logged_in() - { - if($user->data['id'] != "-1") - { - return true; - } - else - { - 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) - { - if (!is_numeric($user_id) and $user_id != null) - { - $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$user_id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - $session->check(); - if($session->logged_in()) - { - /* Wait - what? */ - $error->general("Already logged in", "Session already populated"); - } - else - { - $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = ' . $user_id . ' WHERE id = ' . $db->qstr($_COOKIE["session_id"]) . ' LIMIT 1'; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - login(): '.$db->ErrorMsg()); - return false; - } - /* Run the session check again. It'll make the row and populate $user->data */ - $session->check(); - } - } - /* - Function Name: logout - Arguments: none - Purpose: Edit session table to reflect that user is logged out - */ - function logout() - { - if($session->logged_in()) - { - $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = '.$db->qstr('-1').' WHERE id = ' . $user->data['id'] . ' AND ip = ' . $db->qstr($user->data['ip']) . ' LIMIT 1'; - $db->query($_query); - $user->data = null; - } - else - { - $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 (!is_numeric($id)) - { - $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - if(!$user->logged_in()) - { - return false; - } - else - { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_1 = ' . $user->data['user_id'] . ' AND party_2 = ' . $id . ' AND accepted = 1'; - $_query = $db->Execute($_query); - if($_query->fields[0] > 0) - { - return true; - } - else - { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_2 = ' . $user->data['user_id'] . ' AND party_1 = ' . $id . ' AND accepted = 1'; - $_query = $db->Execute($_query); - if($_query->fields[0] > 0) - { - return true; - } - else - { - return false; - } - } - } - } - /* - 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 = null) - { - if (!is_numeric($action) and $action != null) - { - $error->general('Invalid actionID', "Invalid actionID = Possible hack! Input value: \"".$action."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - - if (!is_numeric($who) and $who != null) - { - $error->general('Invalid whoID', "Invalid whoID = Possible hack! Input value: \"".$who."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - /*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 '.AS_TBL_ACTION.' (time, who, action, for) VALUES(' . time() . ',' . $user->data['user_id'] . ', ' . $action . ', ' . $who . ')'; - $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 (!is_numeric($id) and $id != null) - { - $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - - 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 count(*) FROM '.AS_TBL_FRIEND.' WHERE (party_1 = ' . $user->data['user_id'] . ' AND party_2 = ' . $id; - $_query = $db->query($_query); - if ($_query->fields[0] > 0) - { - $error->general("Already added as friend, awaiting acception", "Add as friend"); - } - else - { - $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_2 = ' . $user->data['user_id'] . ' AND party_1 = ' . $id; - $_query = $db->Execute($_query); - if ($_query->fields[0] > 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 '.AS_TBL_FRIEND.' VALUES(' . $user->data['user_id'] . ',' . $id . ',0)'; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - add_friend(): '.$db->ErrorMsg()); - return false; - } - $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 Name: accept_friend - Arguments: (int) id -- ID of user to accept as friend - Purpose: Accept friend - */ - function accept_friend($id) - { - if (!is_numeric($id) and $id != null) - { - $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - $_query= 'UPDATE '.AS_TBL_FRIEND.' 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) - { - if (!is_numeric($id) and $id != null) - { - $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - /*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 '.AS_TBL_USER.' WHERE id = ' . $id . ' LIMIT 1'; - $_query = $db->Execute($_query); - $_query = $db->GetArray($_query); - $res = $_query[0]['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 Name: add_coment - Arguments: (int) id -- ID of user who comment is directed to - Purpose: Add comment - */ - function add_comment($id) - { - if (!is_numeric($id) and $id != null) - { - $error->general('Invalid userID', "Invalid userD = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - if($session->is_friend($id)) - { - /* Okay, we have permission to leave this comment */ - $_query = 'INSERT INTO '.AS_TBL_CMT.' (comment_timestamp, poster_id, recipient_id, comment) VALUES(' . - time() . ',' . $user->data['user_id'] . ',' . $id . ',' . $db->qstr($_POST['body']).')'; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - add_comment(): '.$db->ErrorMsg()); - return false; - } - $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) - { - if (!is_numeric($id) and $id != null) - { - $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - $_query = 'SELECT display_name FROM '.AS_TBL_USER.' WHERE id = ' . $id; - $_query = $db->Execute($_query); - $res = $db->GetArray($_query); - return $res[0]['display_name']; - } - /* - Function Name: add_image_comment - Arguments: (int) id -- Image ID - Purpose: Add comment to image - */ - function add_image_comment($id) - { - if (!is_numeric($id) and $id != null) - { - $error->general('Invalid imageID', "Invalid imageID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - - $owner = 'SELECT owner_id FROM '.AS_TBL_IMG.' WHERE id = ' . $id; - $owner = $db->query($owner); - $owner = $db->fetch_array($owner); - $owner = $owner['owner']; - if ($session->is_friend($owner)) - { - $_query = 'INSERT INTO '.AS_TBL_IMG_CMT.' (image_id, post_timestamp, author, comment) VALUES('. $id . ',' . time() . ',' . $user->data['user_id'] . ',' . $db->qstr($_POST['comment'],get_magic_quotes_gpc()) . ')'; - if ($db->Execute($_query) === false) - { - $error->general('<b>DB Error!</b>', 'session.php - add_img_comment(): '.$db->ErrorMsg()); - return false; - } - } - } - /* - 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 (!is_numeric($time) and $time != null) - { - $error->general('Invalid timestamp', "Invalid timestamp = Possible hack! Input value: \"".$time."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); - return false; - } - - if($session->logged_in()) - { - $_query = 'SELECT time_offset FROM '.AS_TBL_USER.' WHERE id = ' . $user->data['user_id']; - $_query = $db->Execute($_query); - $_query = $query->GetArray($_query); - $offset = $_query[0]['time_offset']; - - $diff = $offset * 60 * 60; - } - $time = $time + $diff; - return date('m/d/Y G:i:s', $time); - } -} -?> \ No newline at end of file Copied: trunk/functions/user.php (from rev 78, trunk/functions/session.php) =================================================================== --- trunk/functions/user.php (rev 0) +++ trunk/functions/user.php 2007-08-01 15:11:05 UTC (rev 82) @@ -0,0 +1,428 @@ +<?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$ +*********************************************************/ +class user +{ + /* + 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 */ + $id = md5(time() . rand(1,1000)); + /* Check to make sure it's unique */ + $_query = 'INSERT INTO '.AS_TBL_SESSION.' (id, user_id, ip, last_update) VALUES(' . $id . ','.$db->qstr('-1').',' . $db->qstr($_SERVER['REMOTE_ADDR']) . ',' . time() . ')'; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - create(): '.$db->ErrorMsg()); + return false; + } + $_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, + then we return false (since the user isn't logged in). We also match the IP */ + $ip = $_SERVER['REMOTE_ADDR']; + $_query = 'SELECT * FROM '.AS_TBL_SESSION.' WHERE ip = ' . $db->qstr($ip); + $res = $db->Execute($_query); + $count = $res->RecordCount(); + if($count == 0) + { + $session->create(); + } + else + { + /* Get an array of our session info */ + $res = $res->GetArray(); + if($res[0]['id'] != $_COOKIE['session_id']) + { + $session->create(); + } + else + { + $array = $res->GetArray(); + foreach($array[0] as $key => $value) + { + if (!is_numeric($key)) + { + $user->data[$key] = $value; + } + } + /* Update our updated time */ + $_query = 'UPDATE '.AS_TBL_SESSION.' SET last_update = ' . time() . ' WHERE id = ' . $user->data['id'] . ' LIMIT 1'; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - check(): '.$db->ErrorMsg()); + return false; + } + } + } + /* We also need to get rid of users who haven't done anything in the last half-hour */ + $_query = 'DELETE FROM '.AS_TBL_SESSION.' WHERE last_update < ' . (time() - (60*30)); + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - check(): '.$db->ErrorMsg()); + return false; + } + } + /* + Function Name: logged_in + Arguments: none + Purpose: check if user is logged in + */ + function logged_in() + { + if($user->data['id'] != "-1") + { + return true; + } + else + { + 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) + { + if (!is_numeric($user_id) and $user_id != null) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$user_id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + $session->check(); + if($session->logged_in()) + { + /* Wait - what? */ + $error->general("Already logged in", "Session already populated"); + } + else + { + $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = ' . $user_id . ' WHERE id = ' . $db->qstr($_COOKIE["session_id"]) . ' LIMIT 1'; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - login(): '.$db->ErrorMsg()); + return false; + } + /* Run the session check again. It'll make the row and populate $user->data */ + $session->check(); + } + } + /* + Function Name: logout + Arguments: none + Purpose: Edit session table to reflect that user is logged out + */ + function logout() + { + if($session->logged_in()) + { + $_query = 'UPDATE '.AS_TBL_SESSION.' SET user_id = '.$db->qstr('-1').' WHERE id = ' . $user->data['id'] . ' AND ip = ' . $db->qstr($user->data['ip']) . ' LIMIT 1'; + $db->query($_query); + $user->data = null; + } + else + { + $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 (!is_numeric($id)) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + if(!$user->logged_in()) + { + return false; + } + else + { + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_1 = ' . $user->data['user_id'] . ' AND party_2 = ' . $id . ' AND accepted = 1'; + $_query = $db->Execute($_query); + if($_query->fields[0] > 0) + { + return true; + } + else + { + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_2 = ' . $user->data['user_id'] . ' AND party_1 = ' . $id . ' AND accepted = 1'; + $_query = $db->Execute($_query); + if($_query->fields[0] > 0) + { + return true; + } + else + { + return false; + } + } + } + } + /* + 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 = null) + { + if (!is_numeric($action) and $action != null) + { + $error->general('Invalid actionID', "Invalid actionID = Possible hack! Input value: \"".$action."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + if (!is_numeric($who) and $who != null) + { + $error->general('Invalid whoID', "Invalid whoID = Possible hack! Input value: \"".$who."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + /*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 '.AS_TBL_ACTION.' (time, who, action, for) VALUES(' . time() . ',' . $user->data['user_id'] . ', ' . $action . ', ' . $who . ')'; + $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 (!is_numeric($id) and $id != null) + { + $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + 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 count(*) FROM '.AS_TBL_FRIEND.' WHERE (party_1 = ' . $user->data['user_id'] . ' AND party_2 = ' . $id; + $_query = $db->query($_query); + if ($_query->fields[0] > 0) + { + $error->general("Already added as friend, awaiting acception", "Add as friend"); + } + else + { + $_query = 'SELECT count(*) FROM '.AS_TBL_FRIEND.' WHERE party_2 = ' . $user->data['user_id'] . ' AND party_1 = ' . $id; + $_query = $db->Execute($_query); + if ($_query->fields[0] > 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 '.AS_TBL_FRIEND.' VALUES(' . $user->data['user_id'] . ',' . $id . ',0)'; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - add_friend(): '.$db->ErrorMsg()); + return false; + } + $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 Name: accept_friend + Arguments: (int) id -- ID of user to accept as friend + Purpose: Accept friend + */ + function accept_friend($id) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + $_query= 'UPDATE '.AS_TBL_FRIEND.' 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) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid friendID', "Invalid friendID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + /*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 '.AS_TBL_USER.' WHERE id = ' . $id . ' LIMIT 1'; + $_query = $db->Execute($_query); + $_query = $db->GetArray($_query); + $res = $_query[0]['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 Name: add_coment + Arguments: (int) id -- ID of user who comment is directed to + Purpose: Add comment + */ + function add_comment($id) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid userID', "Invalid userD = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + if($session->is_friend($id)) + { + /* Okay, we have permission to leave this comment */ + $_query = 'INSERT INTO '.AS_TBL_CMT.' (comment_timestamp, poster_id, recipient_id, comment) VALUES(' . + time() . ',' . $user->data['user_id'] . ',' . $id . ',' . $db->qstr($_POST['body']).')'; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - add_comment(): '.$db->ErrorMsg()); + return false; + } + $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) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid userID', "Invalid userID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + $_query = 'SELECT display_name FROM '.AS_TBL_USER.' WHERE id = ' . $id; + $_query = $db->Execute($_query); + $res = $db->GetArray($_query); + return $res[0]['display_name']; + } + /* + Function Name: add_image_comment + Arguments: (int) id -- Image ID + Purpose: Add comment to image + */ + function add_image_comment($id) + { + if (!is_numeric($id) and $id != null) + { + $error->general('Invalid imageID', "Invalid imageID = Possible hack! Input value: \"".$id."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + $owner = 'SELECT owner_id FROM '.AS_TBL_IMG.' WHERE id = ' . $id; + $owner = $db->query($owner); + $owner = $db->fetch_array($owner); + $owner = $owner['owner']; + if ($session->is_friend($owner)) + { + $_query = 'INSERT INTO '.AS_TBL_IMG_CMT.' (image_id, post_timestamp, author, comment) VALUES('. $id . ',' . time() . ',' . $user->data['user_id'] . ',' . $db->qstr($_POST['comment'],get_magic_quotes_gpc()) . ')'; + if ($db->Execute($_query) === false) + { + $error->general('<b>DB Error!</b>', 'session.php - add_img_comment(): '.$db->ErrorMsg()); + return false; + } + } + } + /* + 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 (!is_numeric($time) and $time != null) + { + $error->general('Invalid timestamp', "Invalid timestamp = Possible hack! Input value: \"".$time."\" User Hostname: ".$_SERVER['REMOTE_ADDR']); + return false; + } + + if($session->logged_in()) + { + $_query = 'SELECT time_offset FROM '.AS_TBL_USER.' WHERE id = ' . $user->data['user_id']; + $_query = $db->Execute($_query); + $_query = $query->GetArray($_query); + $offset = $_query[0]['time_offset']; + + $diff = $offset * 60 * 60; + } + $time = $time + $diff; + return date('m/d/Y G:i:s', $time); + } +} +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-08-01 00:14:58
|
Revision: 81 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=81&view=rev Author: p3net Date: 2007-07-31 17:15:01 -0700 (Tue, 31 Jul 2007) Log Message: ----------- I fail at life :( Modified Paths: -------------- trunk/functions/captcha.php Modified: trunk/functions/captcha.php =================================================================== --- trunk/functions/captcha.php 2007-07-31 06:36:53 UTC (rev 80) +++ trunk/functions/captcha.php 2007-08-01 00:15:01 UTC (rev 81) @@ -63,7 +63,7 @@ $i=0; while($i < 7) { - imagestring($cap, 31, 8*$i, 12*$1, $phrase[$i], $black); + imagestring($cap, 31, 8*$i, 12*$i, $phrase[$i], $black); $i++; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-07-31 06:36:52
|
Revision: 80 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=80&view=rev Author: p3net Date: 2007-07-30 23:36:53 -0700 (Mon, 30 Jul 2007) Log Message: ----------- A VERY basic CAPTCHA model Added Paths: ----------- trunk/functions/captcha.php Added: trunk/functions/captcha.php =================================================================== --- trunk/functions/captcha.php (rev 0) +++ trunk/functions/captcha.php 2007-07-31 06:36:53 UTC (rev 80) @@ -0,0 +1,74 @@ +<?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$ +*********************************************************/ +class captcha +{ + function generate() + { + header('Content-type: image/png'); + $chars = "abcdefghijklmnopqrstuvwxyz"; + $chars .= strtoupper($chars) . "123456789"; + + $phrase = array(); + $rotate = array(); + $i=0; + while($i<7) + { + $num = rand(1,(26+26+9)-1); + $phrase[$i] = substr($chars, $num, 1); + $rotate[$i] = rand(-45, 45); + $i++; + } + $width = "200"; + $height = "50"; + + $cap = ImageCreateTrueColor($width, $height); + $white = ImageColorAllocate($cap, 255, 255, 255); + $black = ImageColorAllocate($cap, 0, 0, 0); + $color = array( + 'red' => ImageColorAllocate($cap, 255, 0, 0), + 'green' => ImageColorAllocate($cap, 0, 255, 0), + 'blue' => ImageColorAllocate($cap, 0, 0, 255) + ); + ImageFillToBorder($cap, 0, 0, $white, $white); + + /* Let's create between 3 and 6 lines */ + $line_count = rand(3, 6); + $a=0; + while($a < $line_count) + { + $col = rand(0, count($color)-1); + $col = $color[$col]; + ImageLine($cap, rand(0, $width-100), rand(0, $height - 20), rand($width-100, $width), rand($height-20, $height), $col); + $a++; + } + /* Letters */ + $i=0; + while($i < 7) + { + imagestring($cap, 31, 8*$i, 12*$1, $phrase[$i], $black); + $i++; + } + + ImagePNG($cap); + imageDestroy($cap); + } +} +?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |