[Shuttlebb-svn] SF.net SVN: shuttlebb: [90] trunk
Brought to you by:
afterlife69,
danb00
|
From: <aft...@us...> - 2006-12-20 13:07:29
|
Revision: 90
http://svn.sourceforge.net/shuttlebb/?rev=90&view=rev
Author: afterlife69
Date: 2006-12-20 05:07:28 -0800 (Wed, 20 Dec 2006)
Log Message:
-----------
T.T re-adding files would help.
Added Paths:
-----------
trunk/
trunk/index.php
trunk/install/
trunk/install/index.php
trunk/install/sources/
trunk/install/sources/functions_install.php
trunk/install/sources/index.html
trunk/install/sql/
trunk/install/sql/index.html
trunk/install/sql/mysql_data.sql
trunk/install/sql/mysql_schema.sql
trunk/language/
trunk/language/english/
trunk/language/english/global.php
trunk/language/english/lang_index.php
trunk/module/
trunk/module/module_main.php
trunk/plugins/
trunk/plugins/Hello_World.php
trunk/plugins/index.html
trunk/require/
trunk/require/configuration.php
trunk/require/constants.php
trunk/require/extensions.php
trunk/sources/
trunk/sources/cache/
trunk/sources/cache/cache_directory.php
trunk/sources/cache/cache_sql.php
trunk/sources/cache/cache_template.php
trunk/sources/cache/cache_xml.php
trunk/sources/cache/index.html
trunk/sources/captcha/
trunk/sources/captcha/captcha_legacy.php
trunk/sources/captcha/captcha_shape.php
trunk/sources/captcha/index.html
trunk/sources/class_access_control.php
trunk/sources/class_bbcode.php
trunk/sources/class_cache.php
trunk/sources/class_captcha.php
trunk/sources/class_dbal.php
trunk/sources/class_email_handler.php
trunk/sources/class_file.php
trunk/sources/class_hooks.php
trunk/sources/class_language.php
trunk/sources/class_message.php
trunk/sources/class_module_loader.php
trunk/sources/class_privmsg.php
trunk/sources/class_session.php
trunk/sources/class_template.php
trunk/sources/class_user.php
trunk/sources/dbal/
trunk/sources/dbal/dbal_mysql.php
trunk/sources/dbal/dbal_mysqli.php
trunk/sources/dbal/index.html
trunk/sources/error/
trunk/sources/error/index.html
trunk/sources/error/templates/
trunk/sources/error/templates/index.html
trunk/sources/functions_general.php
trunk/sources/functions_handlers.php
trunk/sources/index.html
trunk/sources/smarty/
trunk/sources/smarty/Config_File.class.php
trunk/sources/smarty/Smarty.class.php
trunk/sources/smarty/Smarty_Compiler.class.php
trunk/sources/smarty/debug.tpl
trunk/sources/smarty/index.html
trunk/sources/smarty/internals/
trunk/sources/smarty/internals/core.assemble_plugin_filepath.php
trunk/sources/smarty/internals/core.assign_smarty_interface.php
trunk/sources/smarty/internals/core.create_dir_structure.php
trunk/sources/smarty/internals/core.display_debug_console.php
trunk/sources/smarty/internals/core.get_include_path.php
trunk/sources/smarty/internals/core.get_microtime.php
trunk/sources/smarty/internals/core.get_php_resource.php
trunk/sources/smarty/internals/core.is_secure.php
trunk/sources/smarty/internals/core.is_trusted.php
trunk/sources/smarty/internals/core.load_plugins.php
trunk/sources/smarty/internals/core.load_resource_plugin.php
trunk/sources/smarty/internals/core.process_cached_inserts.php
trunk/sources/smarty/internals/core.process_compiled_include.php
trunk/sources/smarty/internals/core.read_cache_file.php
trunk/sources/smarty/internals/core.rm_auto.php
trunk/sources/smarty/internals/core.rmdir.php
trunk/sources/smarty/internals/core.run_insert_handler.php
trunk/sources/smarty/internals/core.smarty_include_php.php
trunk/sources/smarty/internals/core.write_cache_file.php
trunk/sources/smarty/internals/core.write_compiled_include.php
trunk/sources/smarty/internals/core.write_compiled_resource.php
trunk/sources/smarty/internals/core.write_file.php
trunk/sources/smarty/internals/index.html
trunk/sources/smarty/plugins/
trunk/sources/smarty/plugins/block.textformat.php
trunk/sources/smarty/plugins/compiler.assign.php
trunk/sources/smarty/plugins/function.assign_debug_info.php
trunk/sources/smarty/plugins/function.config_load.php
trunk/sources/smarty/plugins/function.counter.php
trunk/sources/smarty/plugins/function.cycle.php
trunk/sources/smarty/plugins/function.debug.php
trunk/sources/smarty/plugins/function.eval.php
trunk/sources/smarty/plugins/function.fetch.php
trunk/sources/smarty/plugins/function.html_checkboxes.php
trunk/sources/smarty/plugins/function.html_image.php
trunk/sources/smarty/plugins/function.html_options.php
trunk/sources/smarty/plugins/function.html_radios.php
trunk/sources/smarty/plugins/function.html_select_date.php
trunk/sources/smarty/plugins/function.html_select_time.php
trunk/sources/smarty/plugins/function.html_table.php
trunk/sources/smarty/plugins/function.mailto.php
trunk/sources/smarty/plugins/function.math.php
trunk/sources/smarty/plugins/function.popup.php
trunk/sources/smarty/plugins/function.popup_init.php
trunk/sources/smarty/plugins/index.html
trunk/sources/smarty/plugins/modifier.capitalize.php
trunk/sources/smarty/plugins/modifier.cat.php
trunk/sources/smarty/plugins/modifier.count_characters.php
trunk/sources/smarty/plugins/modifier.count_paragraphs.php
trunk/sources/smarty/plugins/modifier.count_sentences.php
trunk/sources/smarty/plugins/modifier.count_words.php
trunk/sources/smarty/plugins/modifier.date_format.php
trunk/sources/smarty/plugins/modifier.debug_print_var.php
trunk/sources/smarty/plugins/modifier.default.php
trunk/sources/smarty/plugins/modifier.escape.php
trunk/sources/smarty/plugins/modifier.indent.php
trunk/sources/smarty/plugins/modifier.lower.php
trunk/sources/smarty/plugins/modifier.nl2br.php
trunk/sources/smarty/plugins/modifier.regex_replace.php
trunk/sources/smarty/plugins/modifier.replace.php
trunk/sources/smarty/plugins/modifier.spacify.php
trunk/sources/smarty/plugins/modifier.string_format.php
trunk/sources/smarty/plugins/modifier.strip.php
trunk/sources/smarty/plugins/modifier.strip_tags.php
trunk/sources/smarty/plugins/modifier.truncate.php
trunk/sources/smarty/plugins/modifier.upper.php
trunk/sources/smarty/plugins/modifier.wordwrap.php
trunk/sources/smarty/plugins/outputfilter.trimwhitespace.php
trunk/sources/smarty/plugins/shared.escape_special_chars.php
trunk/sources/smarty/plugins/shared.make_timestamp.php
trunk/template/
trunk/template/Default/
trunk/template/Default/cache/
trunk/template/Default/cache/index.html
trunk/template/Default/compile/
trunk/template/Default/compile/index.html
trunk/template/Default/config/
trunk/template/Default/config/index.html
trunk/template/Default/index.html
trunk/template/Default/module_index.html
trunk/template/index.html
Added: trunk/index.php
===================================================================
--- trunk/index.php (rev 0)
+++ trunk/index.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,149 @@
+<?php
+/**
+ * ShuttleBB Core
+ *
+ * $Id: index.php 82 2006-12-05 16:19:23Z afterlife69 $
+ * $Date: 2006-12-06 03:19:23 +1100 (Wed, 06 Dec 2006) $
+ * $Rev: 82 $
+ */
+
+$sbb_start_var = microtime(true);
+
+/**
+ * Define self
+ */
+define('IN_SBB', true);
+
+/**
+ * Define full paths for security
+ */
+define('PHPEX', '.php');
+define('ROOT_PATH', dirname(__FILE__) . '/');
+define('INC_PATH', ROOT_PATH . 'sources/');
+define('REQ_PATH', ROOT_PATH . 'require/');
+define('LANG_PATH', ROOT_PATH . 'language/');
+define('TPL_PATH', ROOT_PATH . 'template/');
+define('MOD_PATH', ROOT_PATH . 'module/');
+define('PLUG_PATH', ROOT_PATH . 'plugins/');
+
+/**
+ * Start output buffering
+ */
+ob_start();
+
+/**
+ * Require some static files
+ */
+require (REQ_PATH . 'configuration' . PHPEX);
+require (REQ_PATH . 'constants' . PHPEX);
+require (REQ_PATH . 'extensions' . PHPEX);
+
+/**
+ * Look for a valid installation
+ */
+if ( ! defined ('SBB_INSTALLED') )
+{
+ // If config not found, start installer
+ require (ROOT_PATH . 'install/index' . PHPEX);
+ exit;
+}
+
+/**
+ * Require functions
+ */
+require (INC_PATH . 'functions_general' . PHPEX);
+require (INC_PATH . 'functions_handlers' . PHPEX);
+
+/**
+ * Require smarty templating system
+ */
+require (INC_PATH . 'smarty/Smarty.class' . PHPEX);
+
+/**
+ * Include base sources
+ */
+handler_load('class_session', 'session');
+handler_load('class_user', 'user');
+/* Smarty is on trial atm.
+handler_load('class_template', 'template'); */
+handler_load('class_dbal', 'dbal');
+handler_load('class_module_loader', 'module_loader');
+handler_load('class_access_control', 'acl_core');
+handler_load('class_language', 'language');
+
+/**
+ * Construct the database abstraction layer
+ */
+$db = new dbal(DB_LAYER);
+$db->sql_connect(DB_USER, DB_PASS, DB_NAME, DB_SERVER, DB_PERSISTANT);
+
+/**
+ * Construct some important objects
+ */
+$session = new session();
+$user = new user($session);
+$auth = new acl_core();
+/* Removed for smarty
+$template = new template(TPL_PATH . $user->_get_current_template() . '/'); */
+$language = new language($user->data['user_lang']);
+$module = new module_loader(MOD_PATH);
+
+/**
+ * Build the smarty object
+ *
+ * @link http://smarty.php.net
+ */
+$template = new Smarty; // Construct the smarty template object
+$template->plugin_dir = (INC_PATH . 'smarty/plugins/'); // Set the plugins directory
+$template->template_dir = (TPL_PATH . $user->_get_current_template() . '/'); // Set the template directory
+$template->cache_dir = ($template->template_dir . 'cache/'); // Set the caching directory
+$template->compile_dir = ($template->template_dir . 'compile/'); // Set the template compilation directory
+$template->config_dir = ($template->template_dir . 'config/'); // Set the configuration directory
+$template->debugging = false; // Turn debugging console off
+$template->compile_check = true; // Turn the compile check on
+$template->caching = true; // Turn overall caching on
+$template->force_compile = false; // Never force compiling
+
+/**
+ * Assign some important information to smarty
+ */
+$template->assign('user', $user->data);
+$template->assign('session', $session->data);
+$template->assign('constants', array(
+ 'guest_id' => UNREGISTERED,
+ 'root_path' => ROOT_PATH,
+ 'inc_path' => INC_PATH,
+ 'tpl_path' => $template->template_dir,
+ 'req_path' => REQ_PATH,
+ 'lang_path' => LANG_PATH . $user->data['user_lang'] . '/',
+ 'mod_path' => MOD_PATH,
+ 'plug_path' => PLUG_PATH)
+);
+
+/**
+ * Load the active module
+ */
+$this_module = ( isset ( $_GET['module'] ) ) ? $_GET['module'] : false;
+$module->load_module($this_module);
+
+/**
+ * Unload the modules, close the db connection
+ */
+$module->deconstruct();
+$db->sql_close();
+
+/**
+ * Stop output buffering and output
+ */
+$output = ob_get_contents();
+ob_end_clean();
+echo $output;
+
+echo 'Generation time: ' . ($sbb_start_var - time());
+
+/**
+ * Bye!
+ */
+exit;
+
+?>
\ No newline at end of file
Added: trunk/install/index.php
===================================================================
--- trunk/install/index.php (rev 0)
+++ trunk/install/index.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,25 @@
+<?php
+/**
+ * ShuttleBB Installer
+ *
+ * $Id: index.php 77 2006-12-05 07:55:32Z afterlife69 $
+ * $Rev: 77 $
+ * $Date: 2006-12-05 18:55:32 +1100 (Tue, 05 Dec 2006) $
+ */
+
+if ( ! defined ( 'IN_SBB' ) )
+{
+ return;
+}
+
+if ( defined ( 'SBB_INSTALLED' ) )
+{
+ return;
+}
+
+// Get installer functions
+require (ROOT_PATH . 'install/sources/functions_install' . PHPEX);
+
+echo 'Placeholder';
+
+?>
\ No newline at end of file
Added: trunk/install/sources/functions_install.php
===================================================================
--- trunk/install/sources/functions_install.php (rev 0)
+++ trunk/install/sources/functions_install.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Required functions for installer
+ *
+ * $Id: functions_install.php 77 2006-12-05 07:55:32Z afterlife69 $
+ * $Rev: 77 $
+ * $Date: 2006-12-05 18:55:32 +1100 (Tue, 05 Dec 2006) $
+ */
+
+if ( ! defined ( 'IN_SBB' ) )
+{
+ return;
+}
+
+if ( defined ( 'SBB_INSTALLED' ) )
+{
+ return;
+}
+
+echo 'Placeholder';
+
+?>
\ No newline at end of file
Added: trunk/install/sources/index.html
===================================================================
Added: trunk/install/sql/index.html
===================================================================
Added: trunk/install/sql/mysql_data.sql
===================================================================
--- trunk/install/sql/mysql_data.sql (rev 0)
+++ trunk/install/sql/mysql_data.sql 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,2 @@
+INSERT INTO `sbb_users` (`user_id`, `username`, `password`, `user_email`, `user_active`, `user_code`, `user_msn`, `user_icq`, `user_yim`, `user_aim`, `user_sig`, `user_rank`, `user_web`, `user_ip`)
+ VALUES (-1, 'Guest', '37a6259cc0c1dae299a7866489dff0bd', 'webmaster@127.0.0.1', 0, '0', NULL, NULL, NULL, NULL, NULL, 0, NULL, '');
\ No newline at end of file
Added: trunk/install/sql/mysql_schema.sql
===================================================================
--- trunk/install/sql/mysql_schema.sql (rev 0)
+++ trunk/install/sql/mysql_schema.sql 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,39 @@
+CREATE TABLE `sbb_users` (
+ `user_id` int(255) NOT NULL auto_increment,
+ `username` varchar(255) NOT NULL,
+ `password` varchar(32) NOT NULL,
+ `user_email` text NOT NULL,
+ `user_active` tinyint(1) NOT NULL,
+ `user_code` varchar(12) NOT NULL,
+ `user_msn` varchar(255) default NULL,
+ `user_icq` int(255) default NULL,
+ `user_yim` varchar(255) default NULL,
+ `user_aim` varchar(255) default NULL,
+ `user_sig` text collate latin1_general_ci,
+ `user_rank` int(255) NOT NULL,
+ `user_web` varchar(255) default NULL,
+ `user_ip` varchar(255) NOT NULL,
+ PRIMARY KEY (`user_id`)
+);
+
+CREATE TABLE `sbb_config` (
+ `config_key` varchar(90) NOT NULL,
+ `config_value` text NOT NULL,
+ PRIMARY KEY (`config_key`)
+);
+
+CREATE TABLE `sbb_session_keys` (
+ `key_name` varchar(16) NOT NULL,
+ `key_expire` int(90) NOT NULL,
+ `user_id` int(255) NOT NULL,
+ PRIMARY KEY (`key_name`)
+);
+
+CREATE TABLE `sbb_sessions` (
+ `session_id` varchar(32) NOT NULL,
+ `session_ip` varchar(15) NOT NULL,
+ `session_agent` varchar(255) NOT NULL,
+ `session_time` int(20) NOT NULL,
+ `session_page` int(10) NOT NULL,
+ `user_id` int(255) NOT NULL
+);
\ No newline at end of file
Added: trunk/language/english/global.php
===================================================================
--- trunk/language/english/global.php (rev 0)
+++ trunk/language/english/global.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,21 @@
+<?php
+/**
+ * Base language entries
+ *
+ * This is the base for all modules language
+ *
+ * $Id: global.php 86 2006-12-10 09:24:27Z afterlife69 $
+ * $Rev: 86 $
+ * $Date: 2006-12-10 20:24:27 +1100 (Sun, 10 Dec 2006) $
+ */
+
+if ( ! define ( 'IN_SBB' ) )
+{
+ return;
+}
+
+$lang = array(
+ 'Board_Index' => 'Board Index'
+);
+
+?>
\ No newline at end of file
Added: trunk/language/english/lang_index.php
===================================================================
--- trunk/language/english/lang_index.php (rev 0)
+++ trunk/language/english/lang_index.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,19 @@
+<?php
+/**
+ * Language file for "index" module.
+ *
+ * $Id: lang_index.php 53 2006-12-02 04:52:12Z afterlife69 $
+ * $Rev: 53 $
+ * $Date: 2006-12-02 15:52:12 +1100 (Sat, 02 Dec 2006) $
+ */
+
+if ( ! define ( 'IN_SBB' ) )
+{
+ return;
+}
+
+$lang = array(
+ 'Lang_key' => 'Lang_value'
+);
+
+?>
\ No newline at end of file
Added: trunk/module/module_main.php
===================================================================
--- trunk/module/module_main.php (rev 0)
+++ trunk/module/module_main.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,106 @@
+<?php
+/**
+ * ShuttleBB "Hello World" Module.
+ *
+ * $Id: module_main.php 80 2006-12-05 12:18:29Z afterlife69 $
+ * $Date: 2006-12-05 23:18:29 +1100 (Tue, 05 Dec 2006) $
+ * $Rev: 80 $
+ */
+
+/**
+ * Standard security
+ *
+ * This prevents the module from being executed directly.
+ */
+if ( ! defined ( 'IN_SBB' ) )
+{
+ return;
+}
+
+/**
+ * C/C++ Programmers will pick up the module system very fast, it is based on filename
+ * and gos as followed: module_x.php becomes class:module_x and is constructed on init
+ * the constructor (function with the same name as the class) is called when the object
+ * is constructed (go figure).
+ *
+ * Just like C/C++, the default module is "main" or module_main, this is called when a
+ * module is not found, or there is no module defined. All module authors are expected
+ * to use the phpDoc syntax when packing their modules, and if they require external
+ * sources, the sources should be stored in a directory inside the modules folder with
+ * the same name as the module itself (ie, module_main would have the directory "main").
+ *
+ * When external sources are used, their package must be the same as the "subpackage"
+ * name used on the base module (in this case "main") and the subpackage would be their
+ * actual package name.
+ *
+ * @package shuttlebb
+ * @subpackage main
+ * @author Dean Newman <web...@au...>
+ */
+class module_main
+{
+ /**
+ *
+ */
+ function module_main()
+ {
+ // All pre-init sources
+ global $session;
+ global $user;
+ global $module;
+ global $language;
+ global $auth;
+ global $template;
+
+ $template->display('module_index.html');
+
+ // Start module proper
+ echo 'Hello World!';
+
+ // Init another class in this module
+ new module_main_required();
+
+ // Call a function
+ random_function();
+
+ return;
+ }
+}
+
+/**
+ * Is it possible to execute commands outside of the module class
+ * however this is not permitted by the module coding standards
+ * which are provided with the documents in the package you downloaded
+ */
+echo 'This is not permitted!';
+
+/**
+ * However, you may include other classes or functions in your module.
+ */
+class module_main_required
+{
+ function module_main_required()
+ {
+ echo 'This is permitted';
+ }
+}
+
+function random_function()
+{
+ echo 'Wow, A function!';
+}
+
+/**
+ * Also, constants can also be added to your module, however you must
+ * follow the coding standards to ensure the constant is uppercase with
+ * underscores to seperate words.
+ */
+define('MY_CONSTANT', 'value!');
+
+/**
+ * As a final note, these rules only apply if you are planning to release
+ * your module to the shuttlebb community.
+ */
+return;
+
+?>
\ No newline at end of file
Added: trunk/plugins/Hello_World.php
===================================================================
--- trunk/plugins/Hello_World.php (rev 0)
+++ trunk/plugins/Hello_World.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Basic "Hello World" Plugin that hooks the index.
+ *
+ * $Id: Hello_World.php 71 2006-12-04 03:53:33Z afterlife69 $
+ * $Rev: 71 $
+ * $Date: 2006-12-04 14:53:33 +1100 (Mon, 04 Dec 2006) $
+ */
+
+/**
+ * Standard security
+ *
+ * This prevents the plugin from being executed directly.
+ */
+if ( ! defined ( 'IN_SBB' ) )
+{
+ return;
+}
+
+/**
+ * This is a basic "Hello World" function that the hooks system will execute.
+ */
+function hello_world($date = 0)
+{
+ echo 'Hello World, The current date is ' . ($date) ? date('d-m-Y', $date) : date('d-m-Y') . '.';
+}
+
+/**
+ * The "register" method requires 2 parameters ($handle, $function) and everything after
+ * that is used as a parameter for the function call.
+ * For a full list of hooks, see {@link http://shuttlebb.com/coming_soon}
+ */
+hooks::register('index/login', 'hello_world'); // This hook does not call the parameter
+hooks::register('index/statistics', 'hello_world', time()); // This hook does call the parameter
+
+?>
\ No newline at end of file
Added: trunk/plugins/index.html
===================================================================
Added: trunk/require/configuration.php
===================================================================
--- trunk/require/configuration.php (rev 0)
+++ trunk/require/configuration.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,22 @@
+<?php
+/**
+ * ShuttleBB Configuration File
+ *
+ * Defines the constants and variables needed for the system to init.
+ *
+ * $Id: configuration.php 77 2006-12-05 07:55:32Z afterlife69 $
+ * $Date: 2006-12-05 18:55:32 +1100 (Tue, 05 Dec 2006) $
+ * $Rev: 77 $
+ */
+
+define('SBB_INSTALLED', 1);
+
+define('DB_USER', 'root');
+define('DB_PASS', '');
+define('DB_NAME', 'sbb');
+define('DB_SERVER', 'localhost');
+define('DB_LAYER', 'mysql');
+define('DB_PERSISTANT', 1);
+define('DB_PREFIX', 'sbb_');
+
+?>
\ No newline at end of file
Added: trunk/require/constants.php
===================================================================
--- trunk/require/constants.php (rev 0)
+++ trunk/require/constants.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,32 @@
+<?php
+/**
+ * ShuttleBB Constants File
+ *
+ * Defines the constants and variables needed for the system to init.
+ *
+ * $Id: constants.php 81 2006-12-05 16:05:08Z afterlife69 $
+ * $Date: 2006-12-06 03:05:08 +1100 (Wed, 06 Dec 2006) $
+ * $Rev: 81 $
+ */
+
+if ( ! defined ( 'IN_SBB' ) )
+{
+ return;
+}
+
+//
+// Table definitions
+//
+define('SESSIONS_TABLE', DB_PREFIX . 'sessions');
+define('SESSIONS_KEY_TABLE', DB_PREFIX . 'session_keys');
+define('USERS_TABLE', DB_PREFIX . 'users');
+define('CONFIG_TABLE', DB_PREFIX . 'config');
+define('BBCODE_TABLE', DB_PREFIX . 'bbcode');
+define('ACL_TABLE', DB_PREFIX . 'acl');
+
+/**
+ * This constant is used to identify "Guest" users.
+ */
+define('UNREGISTERED', '-1');
+
+?>
\ No newline at end of file
Added: trunk/require/extensions.php
===================================================================
--- trunk/require/extensions.php (rev 0)
+++ trunk/require/extensions.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,40 @@
+<?php
+/**
+ * This file is responcible for loading all required extensions
+ *
+ * @todo Test the file
+ *
+ * $Id: extensions.php 45 2006-11-04 10:24:04Z afterlife69 $
+ * $Date: 2006-11-04 21:24:04 +1100 (Sat, 04 Nov 2006) $
+ * $Rev: 45 $
+ */
+
+define('EXT_PREFIX', ( ( PHP_SHLIB_SUFFIX === 'dll' ) ? 'php_' : '') );
+define('EXT_POSTFIX', '.' . PHP_SHLIB_SUFFIX);
+define('EXT_PATH', ( ini_get('extension_dir') ) ? ini_get('extension_dir') : '' );
+
+$required_exts = array(
+ 'mysql',
+ 'xml'
+);
+
+// Loop through the required extensions
+while ( list ( , $extension ) = @each ( $required_exts ) )
+{
+ // Check if the extension is loaded
+ $extfile = (EXT_PATH . EXT_PREFIX . $extension . EXT_POSTFIX);
+ if ( ! extension_loaded ( $extension ) )
+ {
+ // Is the file binary and readable?
+ if ( is_executable($extfile) && is_readable($extfile) )
+ {
+ // Attempt to load the extension
+ if ( ! dl($extfile) )
+ {
+ trigger_error('Unable to load required extension, Please check system requirements.', ERROR_FATAL);
+ }
+ }
+ }
+}
+
+?>
\ No newline at end of file
Added: trunk/sources/cache/cache_directory.php
===================================================================
--- trunk/sources/cache/cache_directory.php (rev 0)
+++ trunk/sources/cache/cache_directory.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,10 @@
+<?php
+/**
+ * @todo Create cache::directory for caching directory contents (recursive)
+ *
+ * $Id: cache_directory.php 36 2006-10-29 04:23:43Z afterlife69 $
+ * $Date: 2006-10-29 15:23:43 +1100 (Sun, 29 Oct 2006) $
+ * $Rev: 36 $
+ */
+
+?>
\ No newline at end of file
Added: trunk/sources/cache/cache_sql.php
===================================================================
--- trunk/sources/cache/cache_sql.php (rev 0)
+++ trunk/sources/cache/cache_sql.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,10 @@
+<?php
+/**
+ * @todo Create cache::sql for caching database results
+ *
+ * $Id: cache_sql.php 36 2006-10-29 04:23:43Z afterlife69 $
+ * $Date: 2006-10-29 15:23:43 +1100 (Sun, 29 Oct 2006) $
+ * $Rev: 36 $
+ */
+
+?>
\ No newline at end of file
Added: trunk/sources/cache/cache_template.php
===================================================================
--- trunk/sources/cache/cache_template.php (rev 0)
+++ trunk/sources/cache/cache_template.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,10 @@
+<?php
+/**
+ * @todo Create cache::template for caching compiled templates
+ *
+ * $Id: cache_template.php 36 2006-10-29 04:23:43Z afterlife69 $
+ * $Date: 2006-10-29 15:23:43 +1100 (Sun, 29 Oct 2006) $
+ * $Rev: 36 $
+ */
+
+?>
\ No newline at end of file
Added: trunk/sources/cache/cache_xml.php
===================================================================
--- trunk/sources/cache/cache_xml.php (rev 0)
+++ trunk/sources/cache/cache_xml.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,10 @@
+<?php
+/**
+ * @todo Create cache::xml for caching parsed xml
+ *
+ * $Id: cache_xml.php 36 2006-10-29 04:23:43Z afterlife69 $
+ * $Date: 2006-10-29 15:23:43 +1100 (Sun, 29 Oct 2006) $
+ * $Rev: 36 $
+ */
+
+?>
\ No newline at end of file
Added: trunk/sources/cache/index.html
===================================================================
Added: trunk/sources/captcha/captcha_legacy.php
===================================================================
Added: trunk/sources/captcha/captcha_shape.php
===================================================================
Added: trunk/sources/captcha/index.html
===================================================================
Added: trunk/sources/class_access_control.php
===================================================================
--- trunk/sources/class_access_control.php (rev 0)
+++ trunk/sources/class_access_control.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,63 @@
+<?php
+/**
+ * $Id: class_access_control.php 60 2006-12-03 12:49:18Z afterlife69 $
+ * $Date: 2006-12-03 23:49:18 +1100 (Sun, 03 Dec 2006) $
+ * $Rev: 60 $
+ */
+
+define('ACL_USER', 1);
+define('ACL_GROUP', 2);
+
+define('ACL_ALL', 0);
+define('ACL_ACTION', 1);
+define('ACL_ACCESS', 2);
+
+class acl_core
+{
+ function acl_core()
+ {
+
+ }
+
+ function append($permission, $row_id, $row_type = ACL_USER)
+ {
+ switch ( $row_type )
+ {
+ default:
+ case ACL_USER:
+
+ break;
+ case ACL_GROUP:
+
+ break;
+ }
+ }
+
+ function remove($permission, $row_id, $row_type = ACL_USER)
+ {
+ switch ( $row_type )
+ {
+ default:
+ case ACL_USER:
+
+ break;
+ case ACL_GROUP:
+
+ break;
+ }
+ }
+
+ function query($row_id, $row_type = ACL_USER, $acl_type = ACL_ALL)
+ {
+ $sql = "SELECT {$acl_fields} FROM " . TABLE_ACL . "
+ WHERE acl_handle_type = '{$row_type}' AND acl_handle = '{$row_id}'
+ GROUP BY acl_name, acl_type LIMIT 1";
+ $db->sql_query($sql);
+ $return = $db->sql_fetchrow();
+ $db->sql_freeresult();
+
+ return $return;
+ }
+}
+
+?>
\ No newline at end of file
Added: trunk/sources/class_bbcode.php
===================================================================
--- trunk/sources/class_bbcode.php (rev 0)
+++ trunk/sources/class_bbcode.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,78 @@
+<?php
+/**
+ * $Id: class_bbcode.php 73 2006-12-04 07:38:33Z afterlife69 $
+ * $Date: 2006-12-04 18:38:33 +1100 (Mon, 04 Dec 2006) $
+ * $Rev: 73 $
+ */
+
+/**
+ * BBCode Management Class
+ *
+ * @author Dean Newman <web...@au...>
+ */
+class bbcode
+{
+ /**
+ * Constructor, useless?
+ *
+ * @return bbcode
+ */
+ function bbcode()
+ {
+ }
+
+ /**
+ * Insert new bbcode into database
+ *
+ * @param string $tag The name of the bbcode tag
+ * @param string $regex The regular expression used to validate the bbcode
+ * @param string $replacement The replacement text for the bbcode
+ * @param string $description The tooltip that will appear on hover
+ */
+ function insert($tag, $regex, $replacement, $description = '')
+ {
+ }
+
+ /**
+ * Remove the bbcode by tag or id from the database
+ *
+ * @param string|int $tag The tag or row ID
+ * @param string $type The type of id used to remove the bbcode
+ */
+ function remove($tag, $type = 'tag')
+ {
+ }
+
+ /**
+ * Perform a bbcode transformation
+ *
+ * @param string $text The text to transform
+ */
+ function transform($text)
+ {
+ $tags = $this->select();
+
+ $find = $replace = array();
+ for ( $i = 0; $i < count($tags); $i++ )
+ {
+ $find[] = $tags[$i]['bbcode_regex'];
+ $replace[] = $tags[$i]['bbcode_replace'];
+ }
+
+ return preg_replace ( $find, $replace, $text );;
+ }
+
+ /**
+ * Select the bbcode data from the database
+ *
+ * @return array
+ */
+ function select()
+ {
+ $sql = 'SELECT bbcode_tag, bbcode_regex, bbcode_replace FROM ' . BBCODE_TABLE . ' WHERE bbcode_active = 1';
+ $result = $db->sql_query($sql);
+ return $db->sql_fetchrowset($result, 'assoc');
+ }
+}
+
+?>
\ No newline at end of file
Added: trunk/sources/class_cache.php
===================================================================
--- trunk/sources/class_cache.php (rev 0)
+++ trunk/sources/class_cache.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,169 @@
+<?php
+/**
+ * Cache Handler
+ *
+ * This handler is responcible for caching of all kinds, it will
+ * generate files, check expiration dates, remove expired files
+ * and load cached data into other classes throughout the software.
+ *
+ * $Id: class_cache.php 58 2006-12-03 12:30:18Z afterlife69 $
+ * $Date: 2006-12-03 23:30:18 +1100 (Sun, 03 Dec 2006) $
+ * $Rev: 58 $
+ */
+
+if ( class_exists ( 'cache_handler' ) )
+{
+ return;
+}
+
+/**
+ * Cache Handler
+ *
+ * @package ShuttleBB
+ * @subpackage cache_handler
+ * @copyright Copyright 2006, ShuttleBB Development Team
+ * @author ShuttleBB Development Team <dev...@sh...>
+ * @author Dean Newman <web...@au...>
+ */
+class cache_handler
+{
+// var $xml;
+ var $sql;
+ var $tpl;
+ var $dir;
+ var $stats;
+
+ function cache_handler()
+ {
+ // Include sources
+ // include(INC_PATH . 'cache/cache_xml' . PHPEX);
+ include(INC_PATH . 'cache/cache_sql' . PHPEX);
+ include(INC_PATH . 'cache/cache_tpl' . PHPEX);
+ include(INC_PATH . 'cache/cache_dir' . PHPEX);
+
+ // Init objects
+ // $this->xml = new cache_xml();
+ $this->sql = new cache_sql();
+ $this->tpl = new cache_tpl();
+ $this->dir = new cache_dir();
+
+ // Expire invalid cache
+ $this->expire();
+ }
+
+ function expire()
+ {
+ $cached = $this->_log_get();
+ $sizeof_cached = sizeof($cached);
+ if ( ! is_array ( $cached ) )
+ {
+ return;
+ }
+
+ // Check validity
+ while ( list ( $key, $data ) = each ( $cached ) )
+ {
+ /**
+ * Structure of $data ...
+ *
+ * $data = array(
+ * 'ttl' => (int) time(),
+ * 'type' => (string) substr(__CLASS__, 5);
+ * 'stamp' => (int) time(),
+ * 'handle'=> (sting) $cachename,
+ * 'path' => (string) (INC_PATH . 'cache/cached/' . $cachename),
+ * 'hash' => (string) md5_file(INC_PATH . 'cache/cached/' . $cachename)
+ * );
+ */
+
+ // Handle different types differently
+ switch ( $data['type'] )
+ {
+ default:
+ trigger_error('Cache_unknown_type');
+ break;
+ case 'sql':
+ if ( time() > $data['ttl'] )
+ {
+ $this->$data['type']->expire($data['handle']);
+ unset($cached[$key]);
+ }
+ break;
+ case 'tpl':
+ case 'dir':
+ // case 'xml':
+ $lastmod = @mtime(INC_PATH . 'cache/cached/' . $data['path']);
+
+ if ( ! $data['ttl'] || ! $lastmod )
+ {
+ if ( $lastmod > $data['stamp'] )
+ {
+ $this->$data['type']->expire($data['handle']);
+ unset($cached[$key]);
+ }
+ }
+ else
+ {
+ if ( time() > $data['ttl'] )
+ {
+ $this->$data['type']->expire($data['handle']);
+ unset($cached[$key]);
+ }
+ }
+
+ break;
+ }
+ }
+
+ if ( $sizeof_cached <> sizeof($cached) )
+ {
+ $this->_log_update($cached);
+ }
+
+ return;
+ }
+
+ function validate()
+ {
+
+ }
+
+ function _log_get()
+ {
+ // Check the log file exists
+ if ( ! file_exists ( INC_PATH . 'cache/cached.log' ) )
+ {
+ // If not, create
+ @touch(INC_PATH . 'cache/cached.log');
+ @chmod(INC_PATH . 'cache/cached.log', 0777);
+ }
+
+ // Get the data
+ $serialized = @file_get_contents(INC_PATH . 'cache/cached.log');
+ if ( ! $serialized )
+ {
+ return;
+ }
+
+ // Convert data
+ $cached = unserialize($serialized);
+ if ( ! is_array ( $cache ) )
+ {
+ return;
+ }
+
+ return $cached;
+ }
+
+ function _log_update($cached)
+ {
+ // Write to the
+ $file = new file_handler(INC_PATH . 'cache/cached.log', 'w');
+ $file->write(serialize($cached));
+ $file->close();
+
+ return;
+ }
+}
+
+?>
\ No newline at end of file
Added: trunk/sources/class_captcha.php
===================================================================
--- trunk/sources/class_captcha.php (rev 0)
+++ trunk/sources/class_captcha.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,496 @@
+<?php
+/**
+ * Captcha abstraction layer
+ *
+ * This handler is responcible for caching of all kinds, it will
+ * generate files, check expiration dates, remove expired files
+ * and load cached data into other classes throughout the software.
+ *
+ * $Id: class_captcha.php 85 2006-12-06 05:34:36Z afterlife69 $
+ * $Date: 2006-12-06 16:34:36 +1100 (Wed, 06 Dec 2006) $
+ * $Rev: 85 $
+ */
+
+/**
+ * Constants
+ */
+define ( CAPTCHA_TABLE, $table_prefix . 'captcha' );
+
+/*
+CREATE TABLE `sbb_captcha` (
+ `captcha_id` INT( 1 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+ `captcha_string` TEXT NOT NULL ,
+ `user_id` TEXT NOT NULL
+);
+*/
+
+
+/**
+ * CAPTCHA Class.
+ * Allows advanced CAPTCHA creation using simple wrapper functions.
+ *
+ * @todo This class should be an abstract master layer (abstract = parent only)
+ *
+ * @author Tyler King <ai...@ya...>
+ * @author Dean Newman <web...@au...>
+ */
+class captcha
+{
+ /**
+ * Contains the directory path to the TFF fonts.
+ *
+ * @var string
+ */
+ var $font_path;
+
+ /**
+ * Contains the directory path to the image backgrounds.
+ *
+ * @var string
+ */
+ var $background_path;
+
+ /**
+ * Contains the CAPTCHA configuration.
+ *
+ * @var string
+ */
+ var $data;
+
+ /**
+ * Contains randomly assigned colors.
+ *
+ * @var string
+ */
+ var $rgb;
+
+ /**
+ * Initilizes the class.
+ */
+ function captcha ( )
+ {
+ // Set up the in-class variables.
+ $this->font_path = './ttf/';
+ $this->background_path = './backgrounds/';
+ $this->data = array ( );
+ $this->rgb = $this->gen_rand_color ( );
+ }
+
+ /**
+ * Generates random RGB colors.
+ *
+ * @param integer $start
+ * @param integer $end
+ * @return array
+ */
+ function gen_rand_color ( $start = 0, $end = 255 )
+ {
+ return array ( rand ( $start, $end ), rand ( $start, $end ), rand ( $start, $end ) );
+ }
+
+ /**
+ * Converts hex values to RGB values.
+ *
+ * @param string $color
+ * @return array
+ */
+ function hex_rgb ( $color )
+ {
+ // Remove the hex identifier.
+ $color = str_replace ( '#', '', $color );
+ for ( $i = 0; $i < 3; $i++ )
+ {
+ // Convert to RGB decimal values.
+ $rgb[ ] = hexdec ( substr ( $color, ( 2 * $i ), 2 ) );
+ }
+
+ return $rgb;
+ }
+
+ /**
+ * Walk a directory to return it's files.
+ *
+ * @param string $dir_path
+ * @return array
+ */
+ function walk_dir ( $dir_path )
+ {
+ // Open the directory. Set up the file array.
+ $dh = @opendir ( $dir_path );
+ $files = array ( );
+
+ while ( $file = @readdir ( $dh ) )
+ {
+ // A hidden file ?
+ if ( $file == '.' || $file == '..' || $file{0} == '.' )
+ {
+ // Yes, it is hidden. Skip it.
+ continue;
+ }
+ else
+ {
+ // No, it is not hidden. Append it.
+ $files[ ] = $file;
+ }
+ }
+ @closedir ( $dh );
+
+ return $files;
+ }
+
+ /**
+ * Resizes a background image to the CAPTCHA dimensions.
+ *
+ * @param string $image
+ * @return object
+ */
+ function resize_image ( $image )
+ {
+ // Get the background's height and width.
+ $image_data = getimagesize ( $image );
+
+ // Resize it.
+ $im = imagecreatetruecolor( $this->data[ 'width' ], $this->data[ 'height' ] );
+ $image = imagecreatefrompng ( $image );
+ imagecopyresampled ( $im, $image, 0, 0, 0, 0, $this->data[ 'width' ], $this->data[ 'width' ], $image_data[ 0 ], $image_data[ 1 ] );
+
+ return $im;
+ }
+
+ /**
+ * Check if a CAPTCHA code entered by a user is correct.
+ *
+ * @param string $code
+ * @return boolean
+ */
+ function confirm ( $code )
+ {
+ global $db;
+ global $userdata;
+
+ // Get the CAPTCHAs.
+ $sql = 'SELECT * FROM ' . CAPTCHA_TABLE;
+ $result = $db->sql_query ( $sql );
+ $row = $db->sql_fetchrow ( $result );
+
+ // Does the string entered by user match the database ?
+ if ( strtolower ( $row[ 'captcha_string' ] ) == strtolower ( $code ) )
+ {
+ // Yes. Delete it. Return true for correct.
+ $sql = 'DELETE FROM ' . CAPTCHA_TABLE . ' WHERE user_id = ' . $userdata[ 'user_id' ];
+ $db->sql_query ( $sql );
+
+ return true;
+ }
+ else
+ {
+ // No. Delete it. Return false for incorrect.
+ $sql = 'DELETE FROM ' . CAPTCHA_TABLE . ' WHERE user_id = ' . $userdata[ 'user_id' ];
+ $db->sql_query ( $sql );
+
+ return false;
+ }
+ }
+
+ /**
+ * (Wrapper) Set the size for the CAPTCHA.
+ *
+ * @param integer $height
+ * @param integer $width
+ */
+ function size ( $height, $width )
+ {
+ $this->data[ 'width' ] = $width;
+ $this->data[ 'height' ] = $height;
+ }
+
+ /**
+ * (Wrapper) Set the color for strings and backgrounds of the CAPTCHA.
+ *
+ * @param string $color
+ */
+ function color ( $color = '' )
+ {
+ // Is it a hex value ?
+ if ( strstr ( $color, '#' ) )
+ {
+ // Yes. Convert it to RGB.
+ $this->data[ 'color' ] = $this->hex_rgb ( $background );
+ }
+ else
+ {
+ // No. Randomize a color.
+ $this->data[ 'color' ] = $this->gen_rand_color ( 200, 255 );
+ }
+ }
+
+ /**
+ * (Wrapper) Set the CAPTCHA code length.
+ *
+ * @param integer $length
+ */
+ function string_length ( $length )
+ {
+ $this->data[ 'string.length' ] = $length;
+ }
+
+ /**
+ * (Wrapper) Set the background image for the CAPTCHA.
+ *
+ * @param boolean/string $background
+ */
+ function background ( $background = true )
+ {
+ // True = random background image. String = background image.
+ $this->data[ 'background' ] = $background;
+ }
+
+ /**
+ * (Wrapper) Set lines for the CAPTCHA.
+ *
+ * @param integer $lines
+ * @param string $layer
+ */
+ function lines ( $lines = 0, $layer = 'background' )
+ {
+ $this->data[ 'lines.layer' ] = $layer;
+ $this->data[ 'lines' ] = ( $lines > 0 ) ? $lines : rand ( 4, 5 );
+ }
+
+ /**
+ * (Wrapper) Set noise for the CAPTCHA.
+ *
+ * @param integer $amount
+ * @param string $layer
+ */
+ function noise ( $amount = '', $layer = 'background' )
+ {
+ $this->data[ 'noise.layer' ] = $layer;
+ $this->data[ 'noise' ] = ( $amount > 0 ) ? $amount : rand ( 4, 5 );
+ }
+
+ /**
+ * (Wrapper) Set ellipses for the CAPTCHA.
+ *
+ * @param integer $amount
+ * @param string $layer
+ */
+ function ellipse ( $amount = '', $layer = 'background' )
+ {
+ $this->data[ 'ellipse.layer' ] = $layer;
+ $this->data[ 'ellipse' ] = ( $amount > 0 ) ? $amount : rand ( 4, 5 );
+ }
+
+ /**
+ * (Wrapper) Set filters for the CAPTCHA
+ *
+ * @param integer $amount
+ * @param string $filter
+ */
+ function filter ( $amount = '', $filter = 'random' )
+ {
+ if ( strtolower ( $filter ) == 'blur' )
+ {
+ $type = IMG_FILTER_GAUSSIAN_BLUR;
+ }
+ else if ( strtolower ( $filter ) == 'contrast' )
+ {
+ $type = IMG_FILTER_CONTRAST;
+ }
+ else if ( strtolower ( $filter ) == 'colorize' )
+ {
+ $type = IMG_FILTER_COLORIZE;
+ }
+ else if ( strtolower ( $filter ) == 'emboss' )
+ {
+ $type = IMG_FILTER_EMBOSS;
+ }
+ else if ( strtolower ( $filter ) == 'highlight' )
+ {
+ $type = IMG_FILTER_EDGEDETECT;
+ }
+ else if ( strtolower ( $filter ) == 'sketch' )
+ {
+ $type = IMG_FILTER_MEAN_REMOVAL;
+ }
+ else if ( strtolower ( $filter ) == 'smooth' )
+ {
+ $type = IMG_FILTER_SMOOTH;
+ }
+ else
+ {
+ // Nothing set, randomize.
+ $type = rand ( ) & count ( array ( IMG_FILTER_GAUSSIAN_BLUR, IMG_FILTER_CONTRAST, IMG_FILTER_COLORIZE, IMG_FILTER_EMBOSS, IMG_FILTER_EDGEDETECT, IMG_FILTER_MEAN_REMOVAL, IMG_FILTER_SMOOTH0 ) );
+ }
+
+ $this->data[ 'filter' ] = $type;
+ $this->data[ 'filter.amount' ] = $amount;
+ }
+
+ /**
+ * Render the CAPTCHA image with all the configurations set.
+ *
+ * @return object.
+ */
+ function render ( )
+ {
+ global $db;
+ global $userdata;
+
+ // Walk the directories to return the files.
+ $walked = $this->walk_dir ( $this->font_path );
+ $backgrounds = $this->walk_dir ( $this->background_path );
+
+ if ( !empty ( $this->data[ 'background' ] ) )
+ {
+ // Background set. Resize the background.
+ $captcha = $this->resize_image ( $this->background_path . $backgrounds[ rand ( ) % count ( $backgrounds ) ] );
+ }
+ else
+ {
+ // No background set.
+ $captcha = imagecreate ( $this->data[ 'width' ], $this->data[ 'height' ] );
+ }
+
+ if ( !empty ( $this->data[ 'string.length' ] ) )
+ {
+ // Length set.
+ $string_length = strlen ( $this->data[ 'string.length' ] );
+ }
+ else
+ {
+ // No length set, randomize.
+ $string_length = rand ( 4, 5 );
+ }
+
+ for ( $i = 0; $i < $string_length; $i++ )
+ {
+ // Convert the integers into characters.
+ $string .= chr ( rand ( 65, 90 ) );
+ }
+
+ if ( !empty ( $this->data[ 'color' ] ) )
+ {
+ // Color set (already converted into RGB).
+ $colors = $this->data[ 'color' ];
+ }
+ else
+ {
+ // No color set, randomize.
+ $colors = $this->gen_rand_color ( 200, 255 );
+ }
+
+ $back_color = imagecolorallocate ( $captcha, $colors[ 0 ], $colors[ 1 ], $colors[ 2 ] );
+ if ( !empty ( $this->data[ 'lines.layer' ] ) && $this->data[ 'lines.layer' ] == 'background' )
+ {
+ for ( $i = 0; $i < $this->data[ 'lines' ]; $i++ )
+ {
+ // All the X, Y and length of things.
+ $rx1 = rand ( 0, $this->data[ 'width' ] );
+ $rx2 = rand ( 0, $this->data[ 'width' ] );
+ $ry1 = rand ( 0, $this->data[ 'height' ] );
+ $ry2 = rand ( 0, $this->data[ 'height' ] );
+ $rcVal = rand ( 0, 255 );
+
+ $rc1 = imagecolorallocate ( $captcha, rand ( 0, 255 ), rand ( 0, 255 ), rand ( 100, 255 ) );
+ imageline ( $captcha, $rx1, $ry1, $rx2, $ry2, $rc1 );
+ }
+ }
+
+ if ( !empty ( $this->data[ 'noise.layer' ] ) && $this->data[ 'noise.layer' ] == 'background' )
+ {
+ for ( $i = 0; $i< $this->data[ 'noise' ]; $i++ )
+ {
+ // Set where the pixel is and it's color.
+ imagesetpixel ( $captcha, rand ( 0, $this->data[ 'width' ] ), rand ( 0, $this->data[ 'height' ] ), rand ( 0, 255 ) );
+ }
+ }
+
+ if ( !empty ( $this->data[ 'ellipse.layer' ] ) && $this->data[ 'ellipse.layer' ] == 'background' )
+ {
+ for ( $i = 1; $i < $this->data[ 'ellipse' ]; $i++ )
+ {
+ // Set where the ellipse is and it's color. (Random colors).
+ imageellipse ( $captcha, rand ( 1, 200 ), rand ( 1, 50 ), rand ( 50, 100 ), rand ( 12, 25 ), $colors[ rand ( 0, 24 ) ] );
+ }
+
+ for ( $i = 1; $i < $this->data[ 'ellipse' ]; $i++ )
+ {
+ // Set where the ellipse is and it's color. (Set colors).
+ imageellipse ( $captcha, rand ( 1, 200 ), rand ( 1, 50 ), rand ( 50, 100 ), rand ( 12, 25 ), $back_color );
+ }
+ }
+
+ for ( $i = 0; $i < 25; $i++ )
+ {
+ // Get some random colors to use.
+ $rgb = $this->gen_rand_color ( rand ( 0, 125 ), rand ( 125, 255 ) );
+ $colors[ ] = imagecolorallocate ( $captcha, $rgb[ 0 ], $rgb[ 1 ], $rgb[ 2 ] );
+ }
+
+ for ( $i = 1; $i <= $string_length; $i++ )
+ {
+ $c_c = ( rand ( 1, 2 ) == 1 ) ? rand ( 0, 45 ) : rand ( 315, 360 );
+
+ // Add in a character with color and a random font.
+ imagettftext ( $captcha, rand ( 14, 20 ), $c_c, ( $i * 25 ), 30, $colors[ rand ( 0, 24 ) ], $this->font_path . $walked[ rand ( ) % count ( $walked ) ], substr ( $string, ( $i - 1 ), 1 ) );
+ }
+
+ if ( !empty ( $this->data[ 'ellipse.layer' ] ) && $this->data[ 'ellipse.layer' ] == 'foreground' )
+ {
+ for ( $i = 1; $i < $this->data[ 'ellipse' ]; $i++ )
+ {
+ // Set where the ellipse is and it's color. (Random colors).
+ imageellipse ( $captcha, rand ( 1, 200 ), rand ( 1, 50 ), rand ( 50, 100 ), rand ( 12, 25 ), $colors[ rand ( 0, 24 ) ] );
+ }
+
+ for ( $i = 1; $i < $this->data[ 'ellipse' ]; $i++ )
+ {
+ // Set where the ellipse is and it's color. (Set colors).
+ imageellipse ( $captcha, rand ( 1, 200 ), rand ( 1, 50 ), rand ( 50, 100 ), rand ( 12, 25 ), $backcolor );
+ }
+ }
+
+ if ( !empty ( $this->data[ 'noise.layer' ] ) && $this->data[ 'noise.layer' ] == 'foreground' )
+ {
+ for ( $i = 0; $i < $this->data[ 'noise' ]; $i++ )
+ {
+ // Set where the pixel is and it's color.
+ imagesetpixel ( $captcha, rand ( 0, $this->data[ 'width' ] ), rand ( 0, $this->data[ 'height' ] ), rand ( 0, 255 ) );
+ }
+ }
+
+ if ( !empty ( $this->data[ 'lines.layer' ] ) && $this->data[ 'lines.layer' ] == 'foreground' )
+ {
+ for ( $i = 0; $i < $this->data[ 'lines' ]; $i++ )
+ {
+ // All the X, Y and length of things.
+ $rx1 = rand ( 0, $this->data[ 'width' ] );
+ $rx2 = rand ( 0, $this->data[ 'width' ] );
+ $ry1 = rand ( 0, $this->data[ 'height' ] );
+ $ry2 = rand ( 0, $this->data[ 'height' ] );
+ $rcVal = rand ( 0, 255 );
+
+ $rc1 = imagecolorallocate ( $captcha, rand ( 0, 255 ), rand ( 0, 255 ), rand ( 100, 255 ) );
+ imageline ( $captcha, $rx1, $ry1, $rx2, $ry2, $rc1 );
+ }
+ }
+
+ if ( !empty ( $this->data[ 'filter' ] ) && phpversion ( ) >= 5 )
+ {
+ // Assign the filter if the PHP version is not less then 5.
+ imagefilter ( $captcha, $type, ( !empty ( $this->data[ 'filter.amount' ] ) ) ? $this->data[ 'filter.amount' ] : 50 );
+ }
+
+ // Insert it into the database for later.
+ $sql = 'INSERT INTO ' . CAPTCHA_TABLE . ' (captcha_id, captcha_string, user_id) VALUES ("NULL", "' . $string . '", "' . $userdata[ 'user_id' ] . '")';
+ $db->sql_query ( $sql );
+
+ // Output it.
+ header ( 'Content-Type: image/png' );
+ imagepng ( $captcha );
+ imagedestroy ( $captcha );
+ }
+}
+
+?>
Added: trunk/sources/class_dbal.php
===================================================================
--- trunk/sources/class_dbal.php (rev 0)
+++ trunk/sources/class_dbal.php 2006-12-20 13:07:28 UTC (rev 90)
@@ -0,0 +1,547 @@
+<?php
+/**
+ * ShuttleBB DBAL -
+ *
+ * This database abstaction layer was written, benchmarked, and tested by Dean Newman;
+ * it is designed and optimized for maximum performance and security.
+ *
+ * The purpose of this package is to provide support to many different databases without
+ * the need of seperate releases and/or increased lines of code.
+ *
+ * This package depends on a couple of vital includes from the shuttlebb core including
+ * but not limited to: Caching, Constants, Configuration and The Error Handler.
+ *
+ * You are permitted to use this system in your own projects for personal use only,
+ * however the ShuttleBB Development Team will not be responcible for support, security
+ * or any other issues that may occur.
+ *
+ * The main interface class also contains a number of small methods to make sql queries
+ * and database interface much easier and cleaner; these include field management, simple
+ * updating, simple inserts and many other useful methods and functions.
+ *
+ * $Id: class_dbal.php 66 2006-12-03 13:45:51Z afterlife69 $
+ * $Date: 2006-12-04 00:45:51 +1100 (Mon, 04 Dec 2006) $
+ * $Rev: 66 $
+ */
+
+/**
+ * @todo Caching Object(s) <<<
+ *
+ * The new caching object should include seperate subclasses for different handling of caching,
+ * the main object will be just a shell.
+ *
+ * The following are used in this API:
+ * - cache::cache_sql::store($cache_name);
+ * - cache::cache_sql::load($cache_name);
+ *
+ * >>>
+ */
+
+/**
+ * Prevent include errors
+ */
+if ( class_exists ( 'dbal' ) )
+{
+ return;
+}
+
+/**
+ * Secure the class
+ */
+if ( ! defined ( 'IN_SBB' ) )
+{
+ trigger_error('Error_Security_Include');
+ exit;
+}
+
+/**
+ * Database Abstraction Layer
+ *
+ * This wrapper handles all the caching and debugging jobs,
+ * while interfacing with a specific database layer.
+ *
+ * @package shuttlebb
+ * @subpackage dbal
+ * @author Dean Newman
+ * @copyright © 2006, ShuttleBB Development Team
+ * @access Public
+ */
+class dbal
+{
+ var $layer;
+ var $error;
+ var $cache;
+ var $stats;
+
+ /**
+ * Constructor
+ *
+ * @param string $db_type The name of the db layer to use
+ * @return dbal
+ */
+ function dbal ( $db_type = DB_LAYER )
+ {
+ // Typecast the DB layer for error prevention
+ $db_type = (string) $db_type;
+ $db_layer = (string) 'dbal_' . $db_type;
+
+ // Ensure the file exists
+ if ( ! file_exists ( INC_PATH . 'dbal/' . $db_layer . PHPEX ) )
+ {
+ // If not, die
+ trigger_error('Error_DB_Include');
+ exit;
+ }
+
+ // Include layer and ensure file is secure
+ include ( INC_PATH . 'dbal/' . $db_layer . PHPEX );
+ if ( ! class_exists ( $db_layer ) )
+ {
+ // If not, die
+ trigger_error('Error_DB_Include,Error_DB_Security_Include');
+ exit;
+ }
+
+ // Init the object as a subclass
+ $this->layer = new $db_layer();
+
+ // Fill some values
+ $this->stats = array(
+ 'queries' => 0,
+ 'cached' => 0,
+ );
+ $this->cache = array();
+ $this->error = array();
+ }
+
+ /**
+ * Connects to the database server
+ *
+ * @param string $db_user Username for db server
+ * @param string $db_pass Password for db server
+ * @param string $db_name Name of the database
+ * @param string $db_server The db server to connect to
+ * @param boolean $db_persistant Use a persistant connection?
+ * @return boolean
+ */
+ function sql_connect($db_user, $db_pass, $db_name, $db_server, $db_persistant)
+ {
+ // Attempt to the connection
+ $connection = $this->layer->sql_connect($db_user, $db_pass, $db_name, $db_server, $db_persistant);
+
+ // Check if it connected
+ if ( ! $connection )
+ {
+ // If not, error.
+ trigger_error('Error_DB_Connect');
+ }
+
+ // Return connection identifier
+ return $connection;
+ }
+
+ /**
+ * Close the database connection
+ *
+ * @return boolean
+ */
+ function sql_close()
+ {
+ // Close the db connection
+ return $this->layer->sql_close();
+ }
+
+ /**
+ * Execute an sql query, Cache the result if needed, Load the result
+ * if available.
+ *
+ * @global object $cache Cache object included for sql caching
+ * @param string $sql The sql query to be executed
+ * @param string $cache_name The cache handle for this query
+ * @return mixed
+ */
+ function sql_query($sql, $cache_name = false)
+ {
+ global $cache;
+
+ // Increment the query counter.
+ $this->stats['queries']++;
+
+ // Check for caching
+ if ( $cache_name != false && class_exists ( 'cache_handler' ) )
+ {
+ // Allow the query to be cached without a handle
+ if ( gettype($cache_name) == 'boolean' )
+ {
+ // The handle becomes an md5 string of the sql
+ $cache_name = md5($sql);
+ }
+
+ // If not, execute and handle bad results.
+ if ( ! $result = $this->layer->sql_query($sql) )
+ {
+ // Report a query error.
+ trigger_error('Error_DB_Query');
+ }
+
+ // Attempt to load cache
+ if ( ! $this->cache[$cache_name] = $cache->sql->load($cache_name) )
+ {
+ // If load fails, free var
+ $this->sql_freeresult($result);
+ }
+
+ // Only execute if not already set
+ if ( ! isset ( $this->cache[$cache_name] ) )
+ {
+ // Handle caching if needed
+ $cache[$cache_name] = $this->sql_fetchrowset($result, 'assoc');
+ $cache->sql->store($cache_name, $cache[$cache_name]);
+
+ // Free the result
+ $this->sql_freeresult($result);
+ }
+
+ // Return as cache handle
+ $result = $cache_name;
+
+ // Increment cached queries
+ $this->stats['cached']++;
+ }
+
+ // Check if cache loaded
+ if ( ! isset ( $result ) )
+ {
+ // If not, execute and handle bad results.
+ if ( ! $result = $this->layer->sql_query($sql) )
+ {
+ // Report a query error.
+ trigger_error('Error_DB_Query(' . $this->layer->sql_error($result) . ',' . $sql . ')');
+ }
+ }
+
+ // Return Identifier
+ return $result;
+ }
+
+ /**
+ * Get a database result row
+ *
+ * @param mixed $resource Either the query resource identifier or the cache handle
+ * @param string $type The type of output to return (assoc, object or index)
+ * @return mixed
+ */
+ function sql_fetchrow($result, $type = 'assoc')
+ {
+ if ( is_string($result) && isset ( $this->cache[$result] ) && is_array ( $this->cache[$result] ) )
+ {
+ $row = current($this->cache[$result]);
+ next($this->cache[$result]);
+
+ $typecast = '';
+ switch ($type)
+ {
+ default:
+ case 'assoc':
+ $typecast = 'array';
+ break;
+ case 'object':
+ $typecast = 'object';
+ break;
+ case 'index':
+ $row = array_values($row);
+ $typecast = 'array';
+ }
+
+ return $row;
+ }
+
+ return $this->layer->sql_fetchrow($result, $type);
+ }
+
+ /**
+ * Get a set of database result rows
+ *
+ * @param mixed $resource Either the query resource identifier or the cache handle
+ * @param string $type The type of output to return (assoc, object or index)
+ * @return array
+ */
+ function sql_fetchrowset($result, $row_type = 'assoc')
+ {
+ $rowset = array();
+ while ( $row = $this->sql_fetchrow($result, $row_type) )
+ {
+ $rowset[] = $row;
+ }
+
+ return $rowset;
+ }
+
+ /**
+ * Free the result from a mysql query
+ *
+ * @param mixed $resource Either the query resource identifier or the cache handle
+ * @return boolean
+ */
+ function sql_freeresult($resource = false)
+ {
+ // Allow loose coding (no set resource)
+ $resource = ( $resource == false ) ? array_pop($this->layer->queries) : $resource;
+
+ // Check if the resource is actualy a cache handle
+ if ( is_string($resource) && isset ( $this->cache[$resource] ) )
+ {
+ // If so, unset and return
+ unset($this->cache[$resource]);
+ return true;
+ }
+
+ // Return boolean
+ return $this->layer->sql_freeresult($resource);
+ }
+
+ /**
+ * Escape a single value, or array of values for safe entry in the db
+ *
+ * @param mixed $value A value or array of values to escape for sql entry
+ */
+ function sql_escape(&$value)
+ {
+ // Check if the value is an array of values
+ if ( is_array ( $value ) )
+ {
+ // If so, Loop through them
+ while ( list ( $key, ) = @each ( $value ) )
+ {
+ // And escape each value
+ $value[$key] = $this->layer->sql_escape($value[$key]);
+ }
+ }
+ else
+ {
+ // Else escape single value
+ $value = $this->layer->sql_escape($value);
+ }
+
+ // Return escaped value(s)
+ return $value;
+ }
+
+ /**
+ * Build the sql for an update query
+ *
+ * @param array $valueset The value set to use in the build, if no fieldset is defined array keys will be used.
+ * @param array $fieldset A set of field names to match the values.
+ * @param boolean $escape_val Automatically escapes values if true.
+ */
+ function sql_build_update($valueset, $fieldset = false, $escape_val = false)
+ {
+ // Check for a fieldset
+ if ( ! $fieldset )
+ {
+ // If none defined, use valueset keys
+ $fieldset = array_keys($valueset);
+ }
+
+ // Unsure the arrays are not assoc
+ $valueset = array_values($valueset);
+ $fieldset = array_values($fieldset);
+
+ // Ensure the arrays are the same size
+ if ( sizeof ( $valueset ) <> sizeof ( $fieldset ) )
+ {
+ // Return false if so.
+ return false;
+ }
+
+ // Loop through the fields and values.
+ $return = array();
+ for ( $i = 0 ; $i < sizeof ( $valueset ) ; $i++ )
+ {
+ // Escape the value if needed
+ $valueset[$i] = ( $escape_val ) ? $this->sql_escape($valueset[$i]) : $valueset[$i];
+
+ // Add to the return values (Backticks for multi-word fields)
+ $return[] = "`{$fieldset[$i]}` = '{$valueset[$i]}'";
+ }
+
+ // Return the update string
+ return 'SET ' . implode(', ', $return);
+ }
+
+ /**
+ * Build the sql for an insert query
+ *
+ * @param array $valueset The value set to use in the build, if no fieldset is defined array keys will be used.
+ * @param array $fieldset A set of field names to match the values.
+ * @param boolean $escape_val Automatically escapes values if true.
+ */
+ function sql_build_insert($valueset, $fieldset = false, $escape_val = false)
+ {
+ // Check for a fieldset
+ if ( ! $fieldset )
+ {
+ // If none defined, use valueset keys
+ $fieldset = array_keys($valueset);
+ }
+
+ // Unsure the arrays are not assoc
+ $valueset = array_values($valueset);
+ $fieldset = array_values($fieldset);
+
+ // Ensure the arrays are the same size
+ if ( sizeof ( $valueset ) <> sizeof ( $fieldset ) )
+ {
+ // Return false if so.
+ return false;
+ }
+
+ // Make the fields part
+ $fields = array();
+ for ( $i = 0 ; $i < sizeof ( $fieldset ) ; $i++ )
+ {
+ // Add to fields, backtick for multi-word fields
+ $fields[] = "`{$fieldset[$i]}`";
+ }
+
+ // Make the values part
+ $values = array();
+ for ( $i = 0 ; $i < sizeof ( $valueset ) ; $i++ )
+ {
+ // Escape the value if needed
+ $valueset[$i] = ( $escape_val ) ? $this->sql_escape($valueset[$i]) : $valueset[$i];
+
+ // Add to values
+ $values[] = "'{$valueset[$i]}'";
+ }
+
+ // Implode the fields and values
+ $fields = implode(', ', $fields);
+ $values = implode(', ', $values);
+
+ return "({$fields}) VALUES ({$values})";
+ }
+
+ /**
+ * Executes an sql insert instruction
+ *
+ * @param string $table The table to insert the row into
+ * @param array $valueset The value set to use in the build, if no fieldset is defined array keys will be used.
+ * @param array $fieldset A set of field names to match the values.
+ * @param boolean $escape_val Automatically escapes values if true.
+ */
+ function sql_insert($table, $valueset, $fieldset = false, $escape_val = false)
+ {
+ // Build the query
+ $sql = 'INSERT INTO `' . $table . '` ' . $this->sql_build_insert($valueset, $fieldset, $escape_val);
+
+ // Execute the query
+ $result = $this->sql_query($sql);
+
+ // Free the result
+ $this->sql_freeresult($result);
+
+ return;
+ }
+
+ /**
+ * Executes an sql update instruction
+ *
+ * @param string $table The table to update values for
+ * @param array $valueset The value set to use in the build, if no fieldset is defined array keys will be used.
+ * @param array $fieldset A set of field names to match the values.
+ * @param string $where_sql The where condition for the update.
+ * @param boolean $escape_val Automatically escapes values if true.
+ */
+ function sql_update($table, $valueset, $fieldset = false, $escape_val = false, $where_sql = '')
+ {
+ // Build the query
+ $sql = 'UPDATE `' . $table . '` ' . $this->sql_build_update($valueset, $fieldset, $escape_val) . ' ' . $where_sql;
+
+ // Execute the query
+ $result = $this->sql_query($sql);
+
+ // Free the result
+ $this->sql_freeresult($result);
+
+ return;
+ }
+
+ /**
+ * Returns all available information for a field pointer or name
+ *
+ * @param string $field_key The field name or pointer (depending on parameter 2)
+ * @param boolean $force_pointer Forces the field name parameter to use the pointer instead
+ * @return array An associative array of various field information
+ */
+ function sql_field_info($field_key, $force_pointer = false)
+ {
+ return array();
+ }
+
+ /**
+ * Show tables in the current database.
+ *
+ * @return array
+ */
+ function sql_list_tables()
+ {
+ $sql = 'SHOW TABLES FROM `' . $this->layer->db_name . '`';
+ $result = $this->sql_query($sql);
+ $this->sql_fr...
[truncated message content] |