Thread: [Astrospaces-commits] SF.net SVN: astrospaces: [98] trunk (Page 2)
Brought to you by:
p3net
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: <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: <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: <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: <p3...@us...> - 2007-03-18 11:14:10
|
Revision: 13 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=13&view=rev Author: p3net Date: 2007-03-17 15:48:13 -0700 (Sat, 17 Mar 2007) Log Message: ----------- -Add as friend function --Added -Update TODO --List of users who have requested to be your friend Modified Paths: -------------- trunk/TODO.txt trunk/common.php trunk/includes/profile.php trunk/profile.php trunk/space.php trunk/styles/default/space.tpl Modified: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2007-03-17 19:55:05 UTC (rev 12) +++ trunk/TODO.txt 2007-03-17 22:48:13 UTC (rev 13) @@ -1,6 +1,6 @@ TODO: --Edit space.tpl after we have all of our functions done (add comment, send PM, add friend, etc) ---Add as friend function +--Accept friend request function --Comment function --PM function \ No newline at end of file Modified: trunk/common.php =================================================================== --- trunk/common.php 2007-03-17 19:55:05 UTC (rev 12) +++ trunk/common.php 2007-03-17 22:48:13 UTC (rev 13) @@ -181,4 +181,27 @@ $_query=$db->array($_query); return $_query["icon"]; } +function is_friend($id) +{ + if(!logged_in()) + { + return 0; + } + else + { + $_query="SELECT `id` FROM " . DB_FRIENDS . " WHERE `from`='" . SESSION_ID . + "' AND `to`='" . $id . "' OR `to`='" . SESSION_ID . "' AND `from`='" . + $id . "'"; + + $_query=$db->array($db->query($_query)); + if(count($_query)>0) + { + return 1; + } + else + { + return 0; + } + } +} ?> \ No newline at end of file Modified: trunk/includes/profile.php =================================================================== --- trunk/includes/profile.php 2007-03-17 19:55:05 UTC (rev 12) +++ trunk/includes/profile.php 2007-03-17 22:48:13 UTC (rev 13) @@ -252,5 +252,37 @@ $db->query($_query); thankyou("updating your profile", "to your space", "space.php"); } + function friend_request($id) + { + //If we aren't logged in, let's do it now + if(!logged_in()) + { + redirect("?action=login"); + } + + //Are they our friend? + $_query="SELECT `accepted` FROM " . DB_FRIENDS . " WHERE `from`='" . SESSION_ID + . " AND `to`='" . $id . "'"; + if(count($db->array($db->query($_query)))>0) + { + thankyou("for attempting to add this user as a friend. However, they already are.", + "to return to your space", "space.php"); + } + $_query="SELECT `accepted` FROM " . DB_FRIENDS . " WHERE `to`='" . SESSION_ID + . " AND `from`='" . $id . "'"; + if(count($db->array($db->query($_query)))>0) + { + thankyou("for attempting to add this user as a friend. However, they already are.", + "to return to your space", "space.php"); + } + + //OK, they're not, so let's add them now + //However, they'll still be unaccepted... + $_query="INSERT INTO " . DB_FRIENDS . " VALUES('" . SESSION_ID . "', '" . $id . + "', '0');"; + $db->query($_query); + thankyou("for adding this user as your friend. They will be added to your friends list when your + request is accepted.", "return to your space", "space.php"); + } } ?> \ No newline at end of file Modified: trunk/profile.php =================================================================== --- trunk/profile.php 2007-03-17 19:55:05 UTC (rev 12) +++ trunk/profile.php 2007-03-17 22:48:13 UTC (rev 13) @@ -65,5 +65,8 @@ case 'update': $profile->update($_POST, $_FILES); break; + case 'friend_request': + $profile->request($_GET["id"]); + break; } ?> \ No newline at end of file Modified: trunk/space.php =================================================================== --- trunk/space.php 2007-03-17 19:55:05 UTC (rev 12) +++ trunk/space.php 2007-03-17 22:48:13 UTC (rev 13) @@ -150,6 +150,17 @@ $space->set('friend_id', $friends_id); //Friend's ID $space->set('friend_icon', $friends_icon); //Friend's Icon +//Few more things + +//Owner of the space? +$me= (SESSION_ID == $id) ? '1' : '0'; + +//Friend? +$friend= (is_friend($id)) ? '1' : '0'; + +$space->set('me', $me); +$space->set('friend', $friend); +$space->set('level', SESSION_LEVEL); //Now it's time to finish the template $outer =& new template('outer.tpl'); $outer->set('content', $space); Modified: trunk/styles/default/space.tpl =================================================================== --- trunk/styles/default/space.tpl 2007-03-17 19:55:05 UTC (rev 12) +++ trunk/styles/default/space.tpl 2007-03-17 22:48:13 UTC (rev 13) @@ -2,7 +2,9 @@ <?php echo $username; ?><br> "<?php echo $headline; ?>"<br> <img src="uploads/<?php echo $id; ?>/<?php echo $icon; ?>"><br> - <!-- Links to do stuff go here --> + <?php if($level>0 && friend==0) { ?> + <a href="profile.php?mode=friend_request&id=<?php echo $id; ?>">Add as Friend</a> + <?php } ?> <?php echo $space_left; ?> </div> <div id="right"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <p3...@us...> - 2007-07-28 17:20:51
|
Revision: 16 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=16&view=rev Author: p3net Date: 2007-07-28 10:20:52 -0700 (Sat, 28 Jul 2007) Log Message: ----------- We are gathered here today to mourn the passing of the old files. They hath served us well. Removed Paths: ------------- trunk/TODO.txt trunk/admin/ trunk/common.php trunk/config.php trunk/doc/ trunk/includes/ trunk/index.php trunk/install/ trunk/lang/ trunk/profile.php trunk/space.php trunk/styles/ trunk/uploads/ Deleted: trunk/TODO.txt =================================================================== --- trunk/TODO.txt 2007-03-18 17:42:04 UTC (rev 15) +++ trunk/TODO.txt 2007-07-28 17:20:52 UTC (rev 16) @@ -1,4 +0,0 @@ -TODO: - ---Edit space.tpl after we have all of our functions done (send PM, etc) ---PM function \ No newline at end of file Deleted: trunk/common.php =================================================================== --- trunk/common.php 2007-03-18 17:42:04 UTC (rev 15) +++ trunk/common.php 2007-07-28 17:20:52 UTC (rev 16) @@ -1,207 +0,0 @@ -<?php -/****************************************************************************** -* 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, -* database abstraction, etc. It also includes things in the includes -* directory that we may need on a regular basis -* -* 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$ -******************************************************************************/ - -//Die if this file was accessed directly -if(!(defined('IN_ASTRO'))) -{ - die("Hacking Attempt"); -} - -//Manage creation of error message -function general_error($msg) -{ - //For the time being, just die() -- After template engine is implemented, - //we can make it look nice - die("<b>General Error</b><br /><b><u>Debug Mode</u></b><br /><br />" . $msg); -} - -//Manage our sessions -function session() -{ - //Start our session - session_start(); - - //Perform a check to make sure session vars are working well - $_SESSION["test"]="check"; - if($_SESSION["test"]!="check") - { - general_error("Could not instantiate session"); - } - - //If we made it out of our if statement, we're good to go. - //Now let's get rid of that un-needed $_SESSION value - $_SESSION["test"]=null; - - //Put important parts of the session array into defined values - - /******************* - VALUES IN ARRAY - id - User ID - level - 0 is normal, 1 is admin - ********************/ - $id=!(empty($_SESSION["id"])) ? $_SESSION["id"] : "-1"; //-1 represents an unauth'd user - $level=!(empty($_SESSION["level"])) ? $_SESSION["level"] : "-1" //-1, once again, represents unauth'd user - - define('SESSION_ID', $id); - define('SESSION_LEVEL', $level); - - //Unload the two vars we just used as temps - unset($id); - unset($level); -} - -//Construct and include everything needed on every page. -//This must be called on EVERY page -function construct() -{ - //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(); - - //Connect to the database - $db->connect(); - - //Start our session - session(); - - //Get all of our db schema constants - $db->schema(); - - //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(strtoupper("CONFIG_" . $temp["config_name"]), $temp["config_value"]); - } - $temp=null; //Unload the $temp var -} - -//Our page parsing object (for templateS) -function parse_page($content) -{ - $head =& new template('outer.tpl'); - $head->set('level', SESSION_LEVEL); - $head->set('name', CONFIG_SITE_NAME); - $head->set('content', $content); -} - -//Check to see if we are logged in -function login_check() -{ - if(SESSION_LEVEL > -1) - { - return true; - } - else - { - return false; - } -} -function sanitize($tag) -{ - //Strip out HTML - $tag=strip_tags($tag); - - //Make safe for MySQL - if($dbms == "mysql") - { - $tag=mysql_real_escape_string($tag); - } - //...and for PostgreSQL - else if($dmbs == "pgsql") - { - $tag=pg_escape_string($tag); - } - - return $tag; -} - -//Because we do a lot of thank-you type things -//We're going to write a function to output -//all of them... -function thankyou($for,$link1="",$to1="",$link2="",$to2="") -{ - $thnx =& new template('thankyou.tpl'); - $thnx->set('action',$for); - $thnx->set('link1', $link1); - $thnx->set('link2', $link2); - $thnx->set('to1', $to1); - $thnx->set('to2', $to2); - - $outer =& new template('outer.tpl'); - $outer->set('content', $thnx); -} -function redirect($to) -{ - header('location: ' . $to); -} -function get_username_by_id($id) -{ - $_query="SELECT `username` FROM " . DB_USERS . " WHERE `id`='" . $id . "'"; - $_query=$db->query($_query); - $_query=$db->array($_query); - return $_query["username"]; -} -function get_icon_by_id($id) -{ - $_query="SELECT `icon` FROM " . DB_USERS . "WHERE `id`='" . $id . "'"; - $_query=$db->query($_query); - $_query=$db->array($_query); - return $_query["icon"]; -} -function is_friend($id) -{ - if(!logged_in()) - { - return 0; - } - else - { - $_query="SELECT `id` FROM " . DB_FRIENDS . " WHERE `from`='" . SESSION_ID . - "' AND `to`='" . $id . "' OR `to`='" . SESSION_ID . "' AND `from`='" . - $id . "'"; - - $_query=$db->array($db->query($_query)); - if(count($_query)>0) - { - return 1; - } - else - { - return 0; - } - } -} -?> \ No newline at end of file Deleted: trunk/config.php =================================================================== --- trunk/config.php 2007-03-18 17:42:04 UTC (rev 15) +++ trunk/config.php 2007-07-28 17:20:52 UTC (rev 16) @@ -1 +0,0 @@ - Deleted: trunk/index.php =================================================================== --- trunk/index.php 2007-03-18 17:42:04 UTC (rev 15) +++ trunk/index.php 2007-07-28 17:20:52 UTC (rev 16) @@ -1,38 +0,0 @@ -<?php -/****************************************************************************** -* index.php -* AstroSPACES 2 -* -* Description: index.php simply shows our home page. It is going to be -* short and sweet, as pretty much everything is handled by profile.php, -* space.php, or comment.php. -* -* 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$ -******************************************************************************/ - -//Setup everything we need -define('IN_ASTRO', 1); -require('common.php'); -construct(); - -//Eventually, we'll get our 3 most recent users and provide a -//login box. Until then, we'll just display the page. - -$index =& new Template('index_body.tpl'); -parse_page($index); -?> \ No newline at end of file Deleted: trunk/profile.php =================================================================== --- trunk/profile.php 2007-03-18 17:42:04 UTC (rev 15) +++ trunk/profile.php 2007-07-28 17:20:52 UTC (rev 16) @@ -1,84 +0,0 @@ -<?php -/****************************************************************************** -* profile.php -* AstroSPACES 2 -* -* Description: profile.php handles all user related functions: login, logout, -* friend requests, and registrations. -* -* 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$ -******************************************************************************/ -//Setup everything we need -define('IN_ASTRO', 1); -require('common.php'); -construct(); - -//Try to get our mode -$mode=$_REQUEST["mode"]; - -//If we don't have one, error out -if(empty($mode)) -{ - general_error("No mode specified."); -} - -//Setup our profiler -require('includes/profile.php'); -$profile =& new profile(); - -//Our template switch -switch($mode) -{ - case 'register': - $profile->register(); - break; - case 'process': - $profile->regsub($_POST); - break; - case 'login': - $profile->login(); - break; - case 'loginpro': - $profile->loginGo($_POST); - break; - case 'logout': - $profile->logout(); - break; - case 'edit': - $profile->edit(); - break; - case 'update': - $profile->update($_POST, $_FILES); - break; - case 'friend_request': - $profile->request($_GET["id"]); - break; - case 'request_list': - $profile->request_list(); - break; - case 'approve': - $profile->approve($_GET["id"]); - break; - case 'comment': - $profile->comment($_GET["to"]); - break; - case 'comm_proc': - $profile->comment_proccess($_POST); - break; -} -?> \ No newline at end of file Deleted: trunk/space.php =================================================================== --- trunk/space.php 2007-03-18 17:42:04 UTC (rev 15) +++ trunk/space.php 2007-07-28 17:20:52 UTC (rev 16) @@ -1,158 +0,0 @@ -<?php -/****************************************************************************** -* space.php -* AstroSPACES 2 -* -* Description: space.php is essentially the brains of the operation. It handles -* the display of a users space... and really, that's about it. -* However, this being the script that it is, that's fairly -* important. -* -* -* 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$ -******************************************************************************/ - -//The things we need on everything! -define('IN_ASTRO', 1); -require('common.php'); -construct(); - -//What's our ID? -$id = $_REQUEST["id"]; - -//Let's see if it's empty -if(empty($_REQUEST["id"])) -{ - //It is. Let's see if we're logged in... - if(login_check) - { - //We are, so set the ID to our session ID! - $id = SESSION_ID; - } - else - { - //We're not, so redirect to login - redirect('profile.php?mode=login'); - } -} -//Get all of our info from the users, friends, and space table, etc. -//This is going to be a big JOIN query. Let's hope it works... -$_query="SELECT " . DB_USERS . ".id, " . DB_USERS . ".username, " . - DB_USERS . ".theme, " . DB_USERS . ".icon" . - " DB_USERS . ".last_login, " . DB_USERS . ".headline, " . - DB_SPACE . ".left, " . DB_SPACE . ".right , " . - DB_FRIENDS . ".to, " . DB_FRIENDS . ".from , ". - DB_FRIENDS . ".approved, " " . DB_COMMENTS . - ".comm_id, " . DB_COMMENTS . ".time, " . DB_COMMENTS . - ".to, " . DB_COMMENTS . ".comm_from, " . DB_COMMENTS . - ".comm_to, " . DB_COMMENTS . ".comm_content FROM " . DB_USERS . - " JOIN " . DB_SPACE . " ON " . DB_USERS . ".id = " . DB_SPACE . - ".id JOIN " . DB_FRIENDS . " ON " . DB_SPACE . - ".id = " . DB_FRIENDS . ".to OR " . DB_SPACE . - ".id = " . DB_FRIENDS . ".from AND " . - DB_FRIENDS . ".approved = 1 LIMIT 10 JOIN " . DB_COMMENTS . - " ON " . DB_USERS . ".id = " . DB_COMMENTS . ".to ORDER BY " . - DB_COMMENTS . ".id DESC;"; -//Wow, I can't believe I just wrote that. Anyway, time to run it -$_query=$db->query($_query); //If this doesn't error out I will be amazed - -//NEIL PEART'S GHOST! IT WORKED! (Wait, he isn't dead yet...) -//Note: Bonus points to the first user who knows who Neil Peart is - -//Initialize our template so we can assign stuff in the next loop -$space =& new template('space.tpl'); -//OK, now it's time to sort through that mess... - -$i=0; -$j=0; -while($array=$db->array($_query)) -{ - //First, we're going to get a few things that won't change - //Make sure we only do this once to conserve resources - if($i==0) - { - $space->set('id', $array["id"]); - $space->set('username', $array["username"]); - $space->set('theme' , $array["theme"]); - $space->set('last_login', $array["last_login"]); - $space->set('space_left', $array["left"]); - $space->set('space_right', $array["right"]); - $space->set('icon', $array["icon"]); - $space->set('headline', $array["headline"]); - - //Finally, increment the value of $i so we don't do this - //again - $i++; - } - //Whoo... OK... time to get our hands dirty! - - //First: Friends, Second: Comments - if($array["to"] == $id) - { - $friends_id[$j]=$array["to"]; - } - else - { - $friends_id[$j]=$array["from"]; - } - - //Next: Comments (these will be fun...) - $comments_from[$j]=$array["comm_from"]; - $comments_content[$j]=$array["comm_content"]; - $comm_time[$j]=$array["time"]; - - //Now we need to do some lookup stuff (ie, put a username to these ID's) - $comments_from_username[$j]=get_username_by_id($comments_from[$j]); - $friends_username[$j]=get_username_by_id($friends_id[$j]); - $comments_from_icon[$j]=get_icon_by_id($comments_from[$j]); - $friends_icon[$j]=get_icon_by_id($friends_id[$j]); - $j++; -} -//Now we need to look up some permission stuff (ie, if a user is our friend) -//Now it's time to assign some of our vars from up above -$space->set('from_username', $comments_from_username); //Comment author -$space->set('from_id', $comments_from); //Comment author ID -$space->set('from_icon', $comments_from_icon); //Comment author icon -$space->set('comm_content', $comments_content); //Comment content -$space->set('time', date($comm_time)); //Comment time -$space->set('friend', $friends_username); //Friend's Username -$space->set('friend_id', $friends_id); //Friend's ID -$space->set('friend_icon', $friends_icon); //Friend's Icon - -//Few more things - -//Owner of the space? -$me= (SESSION_ID == $id) ? '1' : '0'; - -//Friend? -$friend= (is_friend($id)) ? '1' : '0'; - -//Number of friend requests -$_query="SELECT `from` FROM " . DB_FRIENDS . " WHERE `approved`='0'"; -$space->set('friend_req', count($db->array($db->query($_query))); -$space->set('me', $me); -$space->set('friend', $friend); -$space->set('level', SESSION_LEVEL); -//Now it's time to finish the template -$outer =& new template('outer.tpl'); -$outer->set('content', $space); - -// -///That's all, folks! -// $Id :$ -?> \ 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-07-30 19:40:18
|
Revision: 41 http://astrospaces.svn.sourceforge.net/astrospaces/?rev=41&view=rev Author: p3net Date: 2007-07-30 12:40:16 -0700 (Mon, 30 Jul 2007) Log Message: ----------- We're storing images as blobs. It's nicer that way. Modified Paths: -------------- trunk/config.php trunk/develop/new-schema.sql trunk/functions/template.php Removed Paths: ------------- branches/ tags/ Modified: trunk/config.php =================================================================== --- trunk/config.php 2007-07-30 19:29:45 UTC (rev 40) +++ trunk/config.php 2007-07-30 19:40:16 UTC (rev 41) @@ -1,15 +1,8 @@ <?php -/* Old-style -$db_info = array( - 'user' => '', - 'pass' => '', - 'host' => '', - 'name' => '' - ); +/* These settings are autogenerated by AstroSPACES + do not change them unless you know what you are + doing! */ -define('AS_EXT', '.php'); -define('AS_LANG', 'en-us'); - define('AS_DB_TYPE', 'mysql'); define('AS_DB_PREFIX', 'as_'); define('AS_DB_HOST', 'localhost'); @@ -17,9 +10,16 @@ define('AS_DB_USER', 'user'); define('AS_DB_PASS', 'pass'); +define('AS_EXT', '.php'); +define('AS_LANG', 'en-us'); + define('AS_LOC_URL', AS_DB_PREFIX.'http://localhost/'); define('AS_LOC_DIRECT', AS_DB_PREFIX.'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'); Modified: trunk/develop/new-schema.sql =================================================================== --- trunk/develop/new-schema.sql 2007-07-30 19:29:45 UTC (rev 40) +++ trunk/develop/new-schema.sql 2007-07-30 19:40:16 UTC (rev 41) @@ -77,7 +77,7 @@ CREATE TABLE `as_images` ( `img_id` int(10) unsigned NOT NULL auto_increment, `owner_id` int(10) unsigned NOT NULL, - `content` varchar(45) NOT NULL COMMENT 'path to image on server', + `content` blob NOT NULL COMMENT 'binary image', `desc` text NOT NULL, `width` int(4) unsigned NOT NULL, `height` int(4) unsigned NOT NULL, Modified: trunk/functions/template.php =================================================================== --- trunk/functions/template.php 2007-07-30 19:29:45 UTC (rev 40) +++ trunk/functions/template.php 2007-07-30 19:40:16 UTC (rev 41) @@ -16,7 +16,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$ *********************************************************/ class template { 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. |