astrospaces-commits Mailing List for AstroSPACES (Page 5)
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: <p3...@us...> - 2007-03-11 07:15:18
|
Revision: 4 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=4&view=rev Author: p3net Date: 2007-03-10 23:15:18 -0800 (Sat, 10 Mar 2007) Log Message: ----------- -Added base for template engine -Create base directory for default style -Fix mis-named PostgreSQL function calls in includes/dp.php -Skeleton files for default template --outer.tpl (The shell of the page that the content will go in) --style.css (For later theming) -Fixed the headers on the top of the files so hopefully they appear right Modified Paths: -------------- trunk/common.php trunk/includes/db.php Added Paths: ----------- trunk/includes/template.php trunk/styles/default/ trunk/styles/default/outer.tpl trunk/styles/default/style.css Modified: trunk/common.php =================================================================== --- trunk/common.php 2007-03-11 02:18:38 UTC (rev 3) +++ trunk/common.php 2007-03-11 07:15:18 UTC (rev 4) @@ -82,6 +82,9 @@ //Include everything we need for DB require_once('includes/db.php'); + //Templating engine + require_once('includes/template.php'); + //Instantiate a few classes $db =& new db(); @@ -94,7 +97,20 @@ //Get all of our db schema constants $db->schema(); - //Todo: Get the values of everything in the config table - //(That should be all we need on most pages) + //OK, now let's get all of the information in the config table + $query="SELECT * FROM " . DB_CONFIG; + $query=$db->query($query); + while($temp=$db->array($query)) + { + //Put it in a lovely 'define' variable... + define($temp["config_name"], $temp["config_value"]); + } + $temp=null; //Unload the $temp var } +function parse_page($content) +{ + $head =& new template('outer.tpl'); + $head->set('level', SESSION_LEVEL); + $head->set('content', $content); +} ?> \ No newline at end of file Modified: trunk/includes/db.php =================================================================== --- trunk/includes/db.php 2007-03-11 02:18:38 UTC (rev 3) +++ trunk/includes/db.php 2007-03-11 07:15:18 UTC (rev 4) @@ -21,7 +21,7 @@ * with this program; if not, write to the Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * -* ID: $Id:$ * +* ID: $Id:$ * * Author: $Author:$ * ******************************************************************************/ @@ -86,7 +86,7 @@ //PostgreSQL else if($dmbs == "pgsql") { - $_query=pg_query($query) or die("Error executing query " . $query . ": " . pg_error()); + $_query=pg_query($query) or die("Error executing query " . $query . ": " . pg_last_error()); } } function array($_query) @@ -99,7 +99,7 @@ } else if($dbms == "pgsql") { - $result=pg_fetch_array($_query) or general_error("Could not fetch array: " . pg_error()); + $result=pg_fetch_array($_query) or general_error("Could not fetch array: " . pg_last_error()); } } } Added: trunk/includes/template.php =================================================================== --- trunk/includes/template.php (rev 0) +++ trunk/includes/template.php 2007-03-11 07:15:18 UTC (rev 4) @@ -0,0 +1,72 @@ +<?php +/****************************************************************************** +* includes/template.php * +* AstroSPACES 2 * +* * +* Description: template.php is the templating engine for AstroSPACES. While * +* not very complex, it gets the job done... * +* * +* Code borrowed shamelessly from * +* http://www.massassi.com/php/articles/template_engines/ * +* * +* 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$ * +* Author: $Author$ * +******************************************************************************/ + +/****************************************************************************** +How to use this templating engine: + +It may look complex, but it really isn't. Simply create a new instance of the +class template (by using, for example, $page =& new template();) Then assign +all the vars you need for your template file by using +$page->set('name', 'value'); After you've done that, simply call +page_parse($page), and your page will be parsed. + +Note when creating template files, variables you assign are addressed as they +would be in PHP. That also means that array's are assigned and addressed the +same way. To loop through an array, use foreach or something similar to that. +*******************************************************************************/ + +//Die if this file was accessed directly +if(!(defined('IN_ASTRO'))) +{ + die("Hacking Attempt"); +} +class template() +{ + function template($file=null) + { + $this->$file = $file; + } + function set($name, $value) + { + $this->vars[$name] = is_object($value) ? $value->fetch() : $value; + } + function fetch($file = null) + { + $stylename = is_defined('STYLE_NAME') ? STYLE_NAME : 'default'; + if(!$file) $file = $this->file; + + extract($this->vars); // Extract the vars to local namespace + ob_start(); // Start output buffering + include('../styles/' . $stylename . '/' . $file); // Include the file + $contents = ob_get_contents(); // Get the contents of the buffer + ob_end_clean(); // End buffering and discard + return $contents; // Return the contents + } +} +?> \ No newline at end of file Added: trunk/styles/default/outer.tpl =================================================================== --- trunk/styles/default/outer.tpl (rev 0) +++ trunk/styles/default/outer.tpl 2007-03-11 07:15:18 UTC (rev 4) @@ -0,0 +1,27 @@ +<html> + <head> + <title>AstroSPACES</title> + <meta name="generator" content="Bluefish 1.0.6"> + <style type="text/css"> + @import('style.css'); + </style> + </head> + <body> + <!--Menu--> + <!--All Users--> + <a href="index.php">Home</a> + <!--/All Users--> + <!--Auth'd Only--> + <?php if($level>-1) { ?> + <!--Links here--> + <?php } ?> + <!--/Auth'd Only--> + <!--Admin--> + <?php if($level==2) { ?> + <!--Links here--> + <?php } ?> + <!--/Admin--> + <!--/Menu--> + <?php echo $contents; ?> + </body> +</html> \ No newline at end of file Added: trunk/styles/default/style.css =================================================================== --- trunk/styles/default/style.css (rev 0) +++ trunk/styles/default/style.css 2007-03-11 07:15:18 UTC (rev 4) @@ -0,0 +1 @@ + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-03-11 02:18:37
|
Revision: 3 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=3&view=rev Author: p3net Date: 2007-03-10 18:18:38 -0800 (Sat, 10 Mar 2007) Log Message: ----------- -Finish basic database abstraction -Add uploads directory (for avatars and stuff) -Fix the misformed header portion (the copyright) on includes/db.php -Fix the misformed header portion (the copyright) on common.php Modified Paths: -------------- trunk/common.php trunk/includes/db.php Added Paths: ----------- trunk/uploads/ Modified: trunk/common.php =================================================================== --- trunk/common.php 2007-03-10 23:36:04 UTC (rev 2) +++ trunk/common.php 2007-03-11 02:18:38 UTC (rev 3) @@ -1,7 +1,7 @@ <?php /****************************************************************************** -* common.php * -* AstroSPACES 2 * +* common.php * +* AstroSPACES 2 * * * * Description: common.php is included by every script in the AstroSPACES * * package. It sets up things we need for every page, like sessions, * Modified: trunk/includes/db.php =================================================================== --- trunk/includes/db.php 2007-03-10 23:36:04 UTC (rev 2) +++ trunk/includes/db.php 2007-03-11 02:18:38 UTC (rev 3) @@ -1,7 +1,7 @@ <?php /****************************************************************************** -* includes/db.php * -* AstroSPACES 2 * +* includes/db.php * +* AstroSPACES 2 * * * * Description: db.php handles database abstraction, making AstroSPACES * * compatible with multiple db engines. It also handles connecting to the db, * @@ -21,8 +21,8 @@ * with this program; if not, write to the Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * * -* ID: $Id$ * -* Author: $Author$ * +* ID: $Id:$ * +* Author: $Author:$ * ******************************************************************************/ //Die if this file was accessed directly @@ -55,7 +55,7 @@ } //Connect to a Postgre SQL database - else if($dmbs = "pgsql") + else if($dmbs == "pgsql") { pg_connect("host=" . $db_server . " dbname=" . $db_database . " dbuser=" . $db_user . " db_password=" . $db_password) or general_error("Could not connect to database"); @@ -72,5 +72,35 @@ define('DB_CONFIG', $prefix . "config"); define('DB_THEMES', $prefix . "themes"); } + function query($query) + { + //Query for SQL databases + + //MySQL + if($dbms == "mysql") + { + $_query=mysql_query($query) or general_error("Error executing query " . $query . ": " . mysql_error()); + return $_query; + } + + //PostgreSQL + else if($dmbs == "pgsql") + { + $_query=pg_query($query) or die("Error executing query " . $query . ": " . pg_error()); + } + } + function array($_query) + { + //We're going to assume $_query is a resource. If it isn't, something's wrong. + if($dbms == "mysql") + { + $result=mysql_fetch_array($_query) or general_error("Could not fetch array: " . mysql_error()); + return $result; + } + else if($dbms == "pgsql") + { + $result=pg_fetch_array($_query) or general_error("Could not fetch array: " . pg_error()); + } + } } ?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |