Skip to content
Browse files

Fresh Kohana 3.2 with added modules, file structure and base files.

  • Loading branch information...
0 parents commit 8d64e6e5b059079df4102a15f9179ad7fe19e40c @jmhobbs jmhobbs committed
Showing with 9,689 additions and 0 deletions.
  1. 0 db/.gitignore
  2. +2 −0 www/.gitignore
  3. +14 −0 www/LICENSE.md
  4. +114 −0 www/application/bootstrap.php
  5. +57 −0 www/application/classes/controller/application.php
  6. +6 −0 www/application/classes/controller/content.php
  7. +1 −0 www/application/config/.gitignore
  8. 0 www/application/messages/.gitignore
  9. 0 www/application/views/.gitignore
  10. 0 www/application/views/partials/.gitignore
  11. 0 www/application/views/script/.gitignore
  12. +11 −0 www/application/views/template.php
  13. +1 −0 www/config/.gitignore
  14. +20 −0 www/config/modules.php
  15. +14 −0 www/config/routes.php
  16. +21 −0 www/htdocs/example.htaccess
  17. +114 −0 www/htdocs/index.php
  18. +13 −0 www/modules/auth/README.md
  19. +3 −0 www/modules/auth/classes/auth.php
  20. +3 −0 www/modules/auth/classes/auth/file.php
  21. +169 −0 www/modules/auth/classes/kohana/auth.php
  22. +94 −0 www/modules/auth/classes/kohana/auth/file.php
  23. +17 −0 www/modules/auth/config/auth.php
  24. 0 www/modules/auth/guide/auth/config.md
  25. 0 www/modules/auth/guide/auth/edit.md
  26. 0 www/modules/auth/guide/auth/index.md
  27. 0 www/modules/auth/guide/auth/login.md
  28. +7 −0 www/modules/auth/guide/auth/menu.md
  29. 0 www/modules/auth/guide/auth/register.md
  30. 0 www/modules/auth/guide/auth/roles.md
  31. 0 www/modules/auth/guide/auth/user.md
  32. +59 −0 www/modules/cache/README.md
  33. +3 −0 www/modules/cache/classes/cache.php
  34. +3 −0 www/modules/cache/classes/cache/apc.php
  35. +3 −0 www/modules/cache/classes/cache/arithmetic.php
  36. +3 −0 www/modules/cache/classes/cache/exception.php
  37. +3 −0 www/modules/cache/classes/cache/file.php
  38. +3 −0 www/modules/cache/classes/cache/garbagecollect.php
  39. +3 −0 www/modules/cache/classes/cache/memcache.php
  40. +3 −0 www/modules/cache/classes/cache/memcachetag.php
  41. +3 −0 www/modules/cache/classes/cache/sqlite.php
  42. +3 −0 www/modules/cache/classes/cache/tagging.php
  43. +3 −0 www/modules/cache/classes/cache/wincache.php
  44. +300 −0 www/modules/cache/classes/kohana/cache.php
  45. +166 −0 www/modules/cache/classes/kohana/cache/apc.php
  46. +39 −0 www/modules/cache/classes/kohana/cache/arithmetic.php
  47. +11 −0 www/modules/cache/classes/kohana/cache/exception.php
  48. +466 −0 www/modules/cache/classes/kohana/cache/file.php
  49. +23 −0 www/modules/cache/classes/kohana/cache/garbagecollect.php
  50. +354 −0 www/modules/cache/classes/kohana/cache/memcache.php
  51. +78 −0 www/modules/cache/classes/kohana/cache/memcachetag.php
  52. +336 −0 www/modules/cache/classes/kohana/cache/sqlite.php
  53. +42 −0 www/modules/cache/classes/kohana/cache/tagging.php
  54. +140 −0 www/modules/cache/classes/kohana/cache/wincache.php
  55. +69 −0 www/modules/cache/config/cache.php
  56. +23 −0 www/modules/cache/config/userguide.php
  57. +219 −0 www/modules/cache/guide/cache.usage.md
  58. +162 −0 www/modules/cache/guide/cache/config.md
  59. 0 www/modules/cache/guide/cache/examples.md
  60. +57 −0 www/modules/cache/guide/cache/index.md
  61. +3 −0 www/modules/cache/guide/cache/menu.md
  62. +219 −0 www/modules/cache/guide/cache/usage.md
  63. +297 −0 www/modules/cache/tests/cache/CacheBasicMethodsTest.php
  64. +226 −0 www/modules/cache/tests/cache/CacheTest.php
  65. +91 −0 www/modules/cache/tests/cache/FileTest.php
  66. +37 −0 www/modules/cache/tests/cache/SqliteTest.php
  67. +37 −0 www/modules/cache/tests/cache/WincacheTest.php
  68. +73 −0 www/modules/cache/tests/cache/arithmetic/ApcTest.php
  69. +172 −0 www/modules/cache/tests/cache/arithmetic/CacheArithmeticMethods.php
  70. +103 −0 www/modules/cache/tests/cache/arithmetic/MemcacheTest.php
  71. +19 −0 www/modules/cache/tests/phpunit.xml
  72. +57 −0 www/modules/codebench/classes/bench/arrcallback.php
  73. +70 −0 www/modules/codebench/classes/bench/autolinkemails.php
  74. +186 −0 www/modules/codebench/classes/bench/datespan.php
  75. +34 −0 www/modules/codebench/classes/bench/explodelimit.php
  76. +61 −0 www/modules/codebench/classes/bench/gruberurl.php
  77. +28 −0 www/modules/codebench/classes/bench/ltrimdigits.php
  78. +66 −0 www/modules/codebench/classes/bench/mddobaseurl.php
  79. +66 −0 www/modules/codebench/classes/bench/mddoimageurl.php
  80. +50 −0 www/modules/codebench/classes/bench/mddoincludeviews.php
  81. +37 −0 www/modules/codebench/classes/bench/stripnullbytes.php
  82. +65 −0 www/modules/codebench/classes/bench/transliterate.php
  83. +123 −0 www/modules/codebench/classes/bench/urlsite.php
  84. +58 −0 www/modules/codebench/classes/bench/userfuncarray.php
  85. +116 −0 www/modules/codebench/classes/bench/validcolor.php
  86. +105 −0 www/modules/codebench/classes/bench/validurl.php
  87. +3 −0 www/modules/codebench/classes/codebench.php
  88. +36 −0 www/modules/codebench/classes/controller/codebench.php
  89. +217 −0 www/modules/codebench/classes/kohana/codebench.php
  90. +16 −0 www/modules/codebench/config/codebench.php
  91. +23 −0 www/modules/codebench/config/userguide.php
  92. +76 −0 www/modules/codebench/guide/codebench/index.md
  93. +1 −0 www/modules/codebench/guide/codebench/menu.md
  94. +8 −0 www/modules/codebench/init.php
  95. BIN www/modules/codebench/media/guide/codebench/codebench_screenshot1.png
  96. BIN www/modules/codebench/media/guide/codebench/codebench_screenshot2.png
  97. +260 −0 www/modules/codebench/views/codebench.php
  98. +12 −0 www/modules/database/classes/config/database.php
  99. +15 −0 www/modules/database/classes/config/database/reader.php
  100. +15 −0 www/modules/database/classes/config/database/writer.php
  101. +3 −0 www/modules/database/classes/database.php
  102. +3 −0 www/modules/database/classes/database/exception.php
  103. +3 −0 www/modules/database/classes/database/expression.php
  104. +3 −0 www/modules/database/classes/database/mysql.php
  105. +3 −0 www/modules/database/classes/database/mysql/result.php
  106. +3 −0 www/modules/database/classes/database/pdo.php
  107. +3 −0 www/modules/database/classes/database/query.php
  108. +3 −0 www/modules/database/classes/database/query/builder.php
  109. +3 −0 www/modules/database/classes/database/query/builder/delete.php
  110. +3 −0 www/modules/database/classes/database/query/builder/insert.php
  111. +3 −0 www/modules/database/classes/database/query/builder/join.php
  112. +3 −0 www/modules/database/classes/database/query/builder/select.php
  113. +3 −0 www/modules/database/classes/database/query/builder/update.php
  114. +3 −0 www/modules/database/classes/database/query/builder/where.php
  115. +3 −0 www/modules/database/classes/database/result.php
  116. +3 −0 www/modules/database/classes/database/result/cached.php
  117. +3 −0 www/modules/database/classes/db.php
  118. +15 −0 www/modules/database/classes/kohana/config/database.php
  119. +53 −0 www/modules/database/classes/kohana/config/database/reader.php
  120. +110 −0 www/modules/database/classes/kohana/config/database/writer.php
  121. +709 −0 www/modules/database/classes/kohana/database.php
  122. +11 −0 www/modules/database/classes/kohana/database/exception.php
  123. +138 −0 www/modules/database/classes/kohana/database/expression.php
  124. +445 −0 www/modules/database/classes/kohana/database/mysql.php
  125. +71 −0 www/modules/database/classes/kohana/database/mysql/result.php
  126. +253 −0 www/modules/database/classes/kohana/database/pdo.php
  127. +256 −0 www/modules/database/classes/kohana/database/query.php
  128. +248 −0 www/modules/database/classes/kohana/database/query/builder.php
  129. +93 −0 www/modules/database/classes/kohana/database/query/builder/delete.php
  130. +175 −0 www/modules/database/classes/kohana/database/query/builder/insert.php
  131. +144 −0 www/modules/database/classes/kohana/database/query/builder/join.php
  132. +444 −0 www/modules/database/classes/kohana/database/query/builder/select.php
  133. +134 −0 www/modules/database/classes/kohana/database/query/builder/update.php
Sorry, we could not display the entire diff because too many files (795) changed.
0 db/.gitignore
No changes.
2 www/.gitignore
@@ -0,0 +1,2 @@
+.htaccess
+asset/*
14 www/LICENSE.md
@@ -0,0 +1,14 @@
+# Kohana License Agreement
+
+This license is a legal agreement between you and the Kohana Team for the use of Kohana Framework (the "Software"). By obtaining the Software you agree to comply with the terms and conditions of this license.
+
+Copyright (c) 2007-2010 Kohana Team
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+* Neither the name of the Kohana nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
114 www/application/bootstrap.php
@@ -0,0 +1,114 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+// -- Environment setup --------------------------------------------------------
+
+// Load the core Kohana class
+require SYSPATH.'classes/kohana/core'.EXT;
+
+if (is_file(APPPATH.'classes/kohana'.EXT))
+{
+ // Application extends the core
+ require APPPATH.'classes/kohana'.EXT;
+}
+else
+{
+ // Load empty core extension
+ require SYSPATH.'classes/kohana'.EXT;
+}
+
+if( ! file_exists( CFGPATH.'application'.EXT ) ) {
+ die( '<h1>No Application Configuration File Found</h1><p>CFGPATH/application'.EXT.'</p>' );
+}
+$_app_config = require_once( CFGPATH.'application'.EXT );
+
+/**
+ * Set the default time zone.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ * @see http://php.net/timezones
+ */
+date_default_timezone_set($_app_config['default_timezone']);
+
+/**
+ * Set the default locale.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ * @see http://php.net/setlocale
+ */
+setlocale(LC_ALL, $_app_config['default_locale']);
+
+/**
+ * Enable the Kohana auto-loader.
+ *
+ * @see http://kohanaframework.org/guide/using.autoloading
+ * @see http://php.net/spl_autoload_register
+ */
+spl_autoload_register(array('Kohana', 'auto_load'));
+
+/**
+ * Enable the Kohana auto-loader for unserialization.
+ *
+ * @see http://php.net/spl_autoload_call
+ * @see http://php.net/manual/var.configuration.php#unserialize-callback-func
+ */
+ini_set('unserialize_callback_func', 'spl_autoload_call');
+
+// -- Configuration and initialization -----------------------------------------
+
+/**
+ * Set the default language
+ */
+I18n::lang($_app_config['default_language']);
+
+/**
+ * Set Kohana::$environment if a 'KOHANA_ENV' environment variable has been supplied.
+ *
+ * Note: If you supply an invalid environment name, a PHP warning will be thrown
+ * saying "Couldn't find constant Kohana::<INVALID_ENV_NAME>"
+ */
+if (isset($_SERVER['KOHANA_ENV']))
+{
+ Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV']));
+}
+elseif (isset($_app_config['environment']))
+{
+ Kohana::$environment = constant('Kohana::'.strtoupper($_app_config['environment']));
+}
+
+/**
+ * Initialize Kohana, setting the default options.
+ *
+ * The following options are available:
+ *
+ * - string base_url path, and optionally domain, of your application NULL
+ * - string index_file name of your index file, usually "index.php" index.php
+ * - string charset internal character set used for input and output utf-8
+ * - string cache_dir set the internal cache directory APPPATH/cache
+ * - boolean errors enable or disable error handling TRUE
+ * - boolean profile enable or disable internal profiling TRUE
+ * - boolean caching enable or disable internal caching FALSE
+ */
+Kohana::init(array(
+ 'base_url' => $_app_config['base_url'],
+ 'index_file' => $_app_config['index_file'],
+ 'charset' => $_app_config['charset'],
+ 'cache_dir' => $_app_config['cache_dir'],
+ 'errors' => $_app_config['errors'],
+ 'profile' => $_app_config['profile'],
+ 'caching' => $_app_config['caching'],
+));
+
+/**
+ * Attach the file write to logging. Multiple writers are supported.
+ */
+Kohana::$log->attach(new Log_File(APPPATH.'logs'));
+
+/**
+ * Attach a file reader to config. Multiple readers are supported.
+ */
+Kohana::$config->attach(new Config_File);
+
+require_once( CFGPATH.'modules'.EXT );
+require_once( CFGPATH.'routes'.EXT );
+
+
57 www/application/classes/controller/application.php
@@ -0,0 +1,57 @@
+<?php
+
+ abstract class Controller_Application extends Controller_Template {
+
+ public $template = 'template';
+ public $content = null;
+ public $script = null;
+
+ public $title = null;
+
+ protected $session = null;
+
+ public function before () {
+ parent::before();
+
+ // Bind our views and variables
+ $this->template->bind( 'content', $this->content );
+ $this->template->bind( 'script', $this->script );
+ $this->template->bind( 'title', $this->title );
+
+ // Attempt to auto-load a view for this page
+ try {
+ $this->content = view::factory( implode(
+ '/',
+ array_filter( array(
+ $this->request->directory(),
+ $this->request->controller(),
+ $this->request->action()
+ ) )
+ ) );
+ }
+ catch( View_Exception $e ) { $this->content = null; }
+ }
+
+ public function after () {
+
+ if( is_null( $this->script ) ) {
+ // Attempt to auto-load a script view for this page
+ try {
+ $this->script = view::factory( implode(
+ '/',
+ array_filter( array(
+ 'script',
+ $this->request->directory(),
+ $this->request->controller(),
+ $this->request->action()
+ ) )
+ ) );
+ }
+ catch( View_Exception $e ) { $this->script = null; }
+ }
+
+ parent::after();
+ }
+
+ }
+
6 www/application/classes/controller/content.php
@@ -0,0 +1,6 @@
+<?php
+
+ class Controller_Content extends Controller_Application {
+ public function action_index () {}
+ }
+
1 www/application/config/.gitignore
@@ -0,0 +1 @@
+*.php
0 www/application/messages/.gitignore
No changes.
0 www/application/views/.gitignore
No changes.
0 www/application/views/partials/.gitignore
No changes.
0 www/application/views/script/.gitignore
No changes.
11 www/application/views/template.php
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title><?php echo html::chars( $title ); ?></title>
+ </head>
+ <body>
+ <?php echo $content; ?>
+ <?php echo $script; ?>
+ </body>
+</html>
1 www/config/.gitignore
@@ -0,0 +1 @@
+application.php
20 www/config/modules.php
@@ -0,0 +1,20 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+/**
+ * Enable modules. Modules are referenced by a relative or absolute path.
+ */
+Kohana::modules(array(
+ // 'auth' => MODPATH.'auth', // Basic authentication
+ // 'cache' => MODPATH.'cache', // Caching with multiple backends
+ // 'codebench' => MODPATH.'codebench', // Benchmarking tool
+ // 'database' => MODPATH.'database', // Database access
+ // 'eorm' => MODPATH.'eorm', // Enhanced ORM
+ // 'image' => MODPATH.'image', // Image manipulation
+ // 'mailer' => MODPATH.'mailer', // Plugin backed, view based Mail API
+ // 'mailer_log' => MODPATH.'mailer_log', // Log plugin for mailer
+ // 'message' => MODPATH.'message', // Flash Messages
+ // 'orm' => MODPATH.'orm', // Object Relationship Mapping
+ // 'simpleauth' => MODPATH.'simpleauth', // Helper Classes for Auth Applications
+ // 'unittest' => MODPATH.'unittest', // Unit testing
+ // 'userguide' => MODPATH.'userguide', // User guide and API documentation
+ ));
14 www/config/routes.php
@@ -0,0 +1,14 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+ Route::set('error', '(<directory>/)error/<action>(/<message>)', array('action' => '[0-9]++', 'message' => '.+'))
+ ->defaults(array(
+ 'controller' => 'error',
+ 'directory' => '',
+ ));
+
+ Route::set( 'default', '(<controller>(/<action>(/<id>)))' )
+ ->defaults(array(
+ 'controller' => 'content',
+ 'action' => 'index',
+ ));
+
21 www/htdocs/example.htaccess
@@ -0,0 +1,21 @@
+# Turn on URL rewriting
+RewriteEngine On
+
+# Installation directory
+RewriteBase /
+
+# Protect hidden files from being viewed
+<Files .*>
+ Order Deny,Allow
+ Deny From All
+</Files>
+
+# Protect application and system files from being viewed
+RewriteRule ^(?:application|database|config|modules|system)\b.* index.php/$0 [L]
+
+# Allow any files or directories that exist to be displayed directly
+RewriteCond %{REQUEST_FILENAME} !-f
+RewriteCond %{REQUEST_FILENAME} !-d
+
+# Rewrite all other URLs to index.php/URL
+RewriteRule .* index.php/$0 [PT]
114 www/htdocs/index.php
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * The directory in which your application specific resources are located.
+ * The application directory must contain the bootstrap.php file.
+ *
+ * @see http://kohanaframework.org/guide/about.install#application
+ */
+$application = '../application';
+
+/**
+ * The directory in which your modules are located.
+ *
+ * @see http://kohanaframework.org/guide/about.install#modules
+ */
+$modules = '../modules';
+
+/**
+ * The directory in which the Kohana resources are located. The system
+ * directory must contain the classes/kohana.php file.
+ *
+ * @see http://kohanaframework.org/guide/about.install#system
+ */
+$system = '../system';
+
+$config = '../config';
+
+/**
+ * The default extension of resource files. If you change this, all resources
+ * must be renamed to use the new extension.
+ *
+ * @see http://kohanaframework.org/guide/about.install#ext
+ */
+define('EXT', '.php');
+
+/**
+ * Set the PHP error reporting level. If you set this in php.ini, you remove this.
+ * @see http://php.net/error_reporting
+ *
+ * When developing your application, it is highly recommended to enable notices
+ * and strict warnings. Enable them by using: E_ALL | E_STRICT
+ *
+ * In a production environment, it is safe to ignore notices and strict warnings.
+ * Disable them by using: E_ALL ^ E_NOTICE
+ *
+ * When using a legacy application with PHP >= 5.3, it is recommended to disable
+ * deprecated notices. Disable with: E_ALL & ~E_DEPRECATED
+ */
+error_reporting(E_ALL | E_STRICT);
+
+/**
+ * End of standard configuration! Changing any of the code below should only be
+ * attempted by those with a working knowledge of Kohana internals.
+ *
+ * @see http://kohanaframework.org/guide/using.configuration
+ */
+
+// Set the full path to the docroot
+define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR);
+
+// Make the application relative to the docroot, for symlink'd index.php
+if ( ! is_dir($application) AND is_dir(DOCROOT.$application))
+ $application = DOCROOT.$application;
+
+// Make the modules relative to the docroot, for symlink'd index.php
+if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules))
+ $modules = DOCROOT.$modules;
+
+// Make the system relative to the docroot, for symlink'd index.php
+if ( ! is_dir($system) AND is_dir(DOCROOT.$system))
+ $system = DOCROOT.$system;
+
+// Define the absolute paths for configured directories
+define('APPPATH', realpath($application).DIRECTORY_SEPARATOR);
+define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR);
+define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR);
+define('CFGPATH', realpath($config).DIRECTORY_SEPARATOR);
+
+// Clean up the configuration vars
+unset($application, $modules, $system);
+
+if (file_exists('install'.EXT))
+{
+ // Load the installation check
+ return include 'install'.EXT;
+}
+
+/**
+ * Define the start time of the application, used for profiling.
+ */
+if ( ! defined('KOHANA_START_TIME'))
+{
+ define('KOHANA_START_TIME', microtime(TRUE));
+}
+
+/**
+ * Define the memory usage at the start of the application, used for profiling.
+ */
+if ( ! defined('KOHANA_START_MEMORY'))
+{
+ define('KOHANA_START_MEMORY', memory_get_usage());
+}
+
+// Bootstrap the application
+require APPPATH.'bootstrap'.EXT;
+
+/**
+ * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO'].
+ * If no source is specified, the URI will be automatically detected.
+ */
+echo Request::factory()
+ ->execute()
+ ->send_headers()
+ ->body();
13 www/modules/auth/README.md
@@ -0,0 +1,13 @@
+New Age Auth
+---
+
+I've forked the main Auth module because there were some fundamental flaws with it:
+
+ 1. It's trivial to [bruteforce](http://dev.kohanaframework.org/issues/3163) publicly hidden salt hashes.
+ - I've fixed this by switching the password hashing algorithm to the more secure secret-key based hash_hmac method.
+ 2. ORM drivers were included.
+ - I've fixed this by simply removing them. They cause confusion with new users because they think that Auth requires ORM. The only driver currently provided by default is the file driver.
+ 3. Auth::get_user()'s api is inconsistent because it returns different data types.
+ - I've fixed this by returning an empty user model by default. You can override what gets returned (if you've changed your user model class name for instance) by overloading the get_user() method in your application.
+
+These changes should be merged into the mainline branch eventually, but they completely break the API, so likely won't be done until 3.1.
3 www/modules/auth/classes/auth.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+abstract class Auth extends Kohana_Auth { }
3 www/modules/auth/classes/auth/file.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+class Auth_File extends Kohana_Auth_File { }
169 www/modules/auth/classes/kohana/auth.php
@@ -0,0 +1,169 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+/**
+ * User authorization library. Handles user login and logout, as well as secure
+ * password hashing.
+ *
+ * @package Kohana/Auth
+ * @author Kohana Team
+ * @copyright (c) 2007-2010 Kohana Team
+ * @license http://kohanaframework.org/license
+ */
+abstract class Kohana_Auth {
+
+ // Auth instances
+ protected static $_instance;
+
+ /**
+ * Singleton pattern
+ *
+ * @return Auth
+ */
+ public static function instance()
+ {
+ if ( ! isset(Auth::$_instance))
+ {
+ // Load the configuration for this type
+ $config = Kohana::$config->load('auth');
+
+ if ( ! $type = $config->get('driver'))
+ {
+ $type = 'file';
+ }
+
+ // Set the session class name
+ $class = 'Auth_'.ucfirst($type);
+
+ // Create a new session instance
+ Auth::$_instance = new $class($config);
+ }
+
+ return Auth::$_instance;
+ }
+
+ protected $_session;
+
+ protected $_config;
+
+ /**
+ * Loads Session and configuration options.
+ *
+ * @return void
+ */
+ public function __construct($config = array())
+ {
+ // Save the config in the object
+ $this->_config = $config;
+
+ $this->_session = Session::instance($this->_config['session_type']);
+ }
+
+ abstract protected function _login($username, $password, $remember);
+
+ abstract public function password($username);
+
+ abstract public function check_password($password);
+
+ /**
+ * Gets the currently logged in user from the session.
+ * Returns NULL if no user is currently logged in.
+ *
+ * @return mixed
+ */
+ public function get_user($default = NULL)
+ {
+ return $this->_session->get($this->_config['session_key'], $default);
+ }
+
+ /**
+ * Attempt to log in a user by using an ORM object and plain-text password.
+ *
+ * @param string username to log in
+ * @param string password to check against
+ * @param boolean enable autologin
+ * @return boolean
+ */
+ public function login($username, $password, $remember = FALSE)
+ {
+ if (empty($password))
+ return FALSE;
+
+ return $this->_login($username, $password, $remember);
+ }
+
+ /**
+ * Log out a user by removing the related session variables.
+ *
+ * @param boolean completely destroy the session
+ * @param boolean remove all tokens for user
+ * @return boolean
+ */
+ public function logout($destroy = FALSE, $logout_all = FALSE)
+ {
+ if ($destroy === TRUE)
+ {
+ // Destroy the session completely
+ $this->_session->destroy();
+ }
+ else
+ {
+ // Remove the user from the session
+ $this->_session->delete($this->_config['session_key']);
+
+ // Regenerate session_id
+ $this->_session->regenerate();
+ }
+
+ // Double check
+ return ! $this->logged_in();
+ }
+
+ /**
+ * Check if there is an active session. Optionally allows checking for a
+ * specific role.
+ *
+ * @param string role name
+ * @return mixed
+ */
+ public function logged_in($role = NULL)
+ {
+ return ($this->get_user() !== NULL);
+ }
+
+ /**
+ * Creates a hashed hmac password from a plaintext password. This
+ * method is deprecated, [Auth::hash] should be used instead.
+ *
+ * @deprecated
+ * @param string plaintext password
+ */
+ public function hash_password($password)
+ {
+ return $this->hash($password);
+ }
+
+ /**
+ * Perform a hmac hash, using the configured method.
+ *
+ * @param string string to hash
+ * @return string
+ */
+ public function hash($str)
+ {
+ if ( ! $this->_config['hash_key'])
+ throw new Kohana_Exception('A valid hash key must be set in your auth config.');
+
+ return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
+ }
+
+ protected function complete_login($user)
+ {
+ // Regenerate session_id
+ $this->_session->regenerate();
+
+ // Store username in session
+ $this->_session->set($this->_config['session_key'], $user);
+
+ return TRUE;
+ }
+
+} // End Auth
94 www/modules/auth/classes/kohana/auth/file.php
@@ -0,0 +1,94 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+/**
+ * File Auth driver.
+ * [!!] this Auth driver does not support roles nor autologin.
+ *
+ * @package Kohana/Auth
+ * @author Kohana Team
+ * @copyright (c) 2007-2010 Kohana Team
+ * @license http://kohanaframework.org/license
+ */
+class Kohana_Auth_File extends Auth {
+
+ // User list
+ protected $_users;
+
+ /**
+ * Constructor loads the user list into the class.
+ */
+ public function __construct($config = array())
+ {
+ parent::__construct($config);
+
+ // Load user list
+ $this->_users = Arr::get($config, 'users', array());
+ }
+
+ /**
+ * Logs a user in.
+ *
+ * @param string username
+ * @param string password
+ * @param boolean enable autologin (not supported)
+ * @return boolean
+ */
+ protected function _login($username, $password, $remember)
+ {
+ if (is_string($password))
+ {
+ // Create a hashed password
+ $password = $this->hash($password);
+ }
+
+ if (isset($this->_users[$username]) AND $this->_users[$username] === $password)
+ {
+ // Complete the login
+ return $this->complete_login($username);
+ }
+
+ // Login failed
+ return FALSE;
+ }
+
+ /**
+ * Forces a user to be logged in, without specifying a password.
+ *
+ * @param mixed username
+ * @return boolean
+ */
+ public function force_login($username)
+ {
+ // Complete the login
+ return $this->complete_login($username);
+ }
+
+ /**
+ * Get the stored password for a username.
+ *
+ * @param mixed username
+ * @return string
+ */
+ public function password($username)
+ {
+ return Arr::get($this->_users, $username, FALSE);
+ }
+
+ /**
+ * Compare password with original (plain text). Works for current (logged in) user
+ *
+ * @param string $password
+ * @return boolean
+ */
+ public function check_password($password)
+ {
+ $username = $this->get_user();
+
+ if ($username === FALSE)
+ {
+ return FALSE;
+ }
+
+ return ($password === $this->password($username));
+ }
+
+} // End Auth File
17 www/modules/auth/config/auth.php
@@ -0,0 +1,17 @@
+<?php defined('SYSPATH') or die('No direct access allowed.');
+
+return array(
+
+ 'driver' => 'file',
+ 'hash_method' => 'sha256',
+ 'hash_key' => NULL,
+ 'lifetime' => 1209600,
+ 'session_type' => Session::$default,
+ 'session_key' => 'auth_user',
+
+ // Username/password combinations for the Auth File driver
+ 'users' => array(
+ // 'admin' => 'b3154acf3a344170077d11bdb5fff31532f679a1919e716a02',
+ ),
+
+);
0 www/modules/auth/guide/auth/config.md
No changes.
0 www/modules/auth/guide/auth/edit.md
No changes.
0 www/modules/auth/guide/auth/index.md
No changes.
0 www/modules/auth/guide/auth/login.md
No changes.
7 www/modules/auth/guide/auth/menu.md
@@ -0,0 +1,7 @@
+## [Auth]()
+- [Config](config)
+- [User Model](user)
+- [Register Users](register)
+- [Log in and out](login)
+- [Edit User](edit)
+- [Using Roles](roles)
0 www/modules/auth/guide/auth/register.md
No changes.
0 www/modules/auth/guide/auth/roles.md
No changes.
0 www/modules/auth/guide/auth/user.md
No changes.
59 www/modules/cache/README.md
@@ -0,0 +1,59 @@
+Kohana Cache library
+====================
+
+The cache library for Kohana 3 provides a simple interface to the most common cache solutions. Developers are free to add their own caching solutions that follow the cache design pattern defined within this module.
+
+Supported cache solutions
+-------------------------
+
+Currently this module supports the following cache methods.
+
+1. APC
+2. Memcache
+3. Memcached-tags (Supports tags)
+4. SQLite (Supports tags)
+5. File
+6. Wincache
+
+Planned support
+---------------
+
+In the near future, additional support for the following methods will be included.
+
+1. Memcached
+
+Introduction to caching
+-----------------------
+
+To use caching to the maximum potential, your application should be designed with caching in mind from the outset. In general, the most effective caches contain lots of small collections of data that are the result of expensive computational operations, such as searching through a large data set.
+
+There are many different caching methods available for PHP, from the very basic file based caching to opcode caching in eAccelerator and APC. Caching engines that use physical memory over disk based storage are always faster, however many do not support more advanced features such as tagging.
+
+Using Cache
+-----------
+
+To use Kohana Cache, download and extract the latest stable release of Kohana Cache from [Github](http://github.com/samsoir/kohana-cache). Place the module into your Kohana instances modules folder. Finally enable the module within the application bootstrap within the section entitled _modules_.
+
+Quick example
+-------------
+
+The following is a quick example of how to use Kohana Cache. The example is using the SQLite driver.
+
+ <?php
+ // Get a Sqlite Cache instance
+ $mycache = Cache::instance('sqlite');
+
+ // Create some data
+ $data = array('foo' => 'bar', 'apples' => 'pear', 'BDFL' => 'Shadowhand');
+
+ // Save the data to cache, with an id of test_id and a lifetime of 10 minutes
+ $mycache->set('test_id', $data, 600);
+
+ // Retrieve the data from cache
+ $retrieved_data = $mycache->get('test_id');
+
+ // Remove the cache item
+ $mycache->delete('test_id');
+
+ // Clear the cache of all stored items
+ $mycache->delete_all();
3 www/modules/cache/classes/cache.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+abstract class Cache extends Kohana_Cache {}
3 www/modules/cache/classes/cache/apc.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_Apc extends Kohana_Cache_Apc {}
3 www/modules/cache/classes/cache/arithmetic.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+interface Cache_Arithmetic extends Kohana_Cache_Arithmetic {}
3 www/modules/cache/classes/cache/exception.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_Exception extends Kohana_Cache_Exception {}
3 www/modules/cache/classes/cache/file.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_File extends Kohana_Cache_File {}
3 www/modules/cache/classes/cache/garbagecollect.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+interface Cache_GarbageCollect extends Kohana_Cache_GarbageCollect {}
3 www/modules/cache/classes/cache/memcache.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_Memcache extends Kohana_Cache_Memcache {}
3 www/modules/cache/classes/cache/memcachetag.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_MemcacheTag extends Kohana_Cache_MemcacheTag {}
3 www/modules/cache/classes/cache/sqlite.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_Sqlite extends Kohana_Cache_Sqlite {}
3 www/modules/cache/classes/cache/tagging.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+interface Cache_Tagging extends Kohana_Cache_Tagging {}
3 www/modules/cache/classes/cache/wincache.php
@@ -0,0 +1,3 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+
+class Cache_Wincache extends Kohana_Cache_Wincache {}
300 www/modules/cache/classes/kohana/cache.php
@@ -0,0 +1,300 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Kohana Cache provides a common interface to a variety of caching engines. Tags are
+ * supported where available natively to the cache system. Kohana Cache supports multiple
+ * instances of cache engines through a grouped singleton pattern.
+ *
+ * ### Supported cache engines
+ *
+ * * [APC](http://php.net/manual/en/book.apc.php)
+ * * [eAccelerator](http://eaccelerator.net/)
+ * * File
+ * * [Memcache](http://memcached.org/)
+ * * [Memcached-tags](http://code.google.com/p/memcached-tags/)
+ * * [SQLite](http://www.sqlite.org/)
+ * * [Xcache](http://xcache.lighttpd.net/)
+ *
+ * ### Introduction to caching
+ *
+ * Caching should be implemented with consideration. Generally, caching the result of resources
+ * is faster than reprocessing them. Choosing what, how and when to cache is vital. PHP APC is
+ * presently one of the fastest caching systems available, closely followed by Memcache. SQLite
+ * and File caching are two of the slowest cache methods, however usually faster than reprocessing
+ * a complex set of instructions.
+ *
+ * Caching engines that use memory are considerably faster than the file based alternatives. But
+ * memory is limited whereas disk space is plentiful. If caching large datasets it is best to use
+ * file caching.
+ *
+ * ### Configuration settings
+ *
+ * Kohana Cache uses configuration groups to create cache instances. A configuration group can
+ * use any supported driver, with successive groups using the same driver type if required.
+ *
+ * #### Configuration example
+ *
+ * Below is an example of a _memcache_ server configuration.
+ *
+ * return array(
+ * 'default' => array( // Default group
+ * 'driver' => 'memcache', // using Memcache driver
+ * 'servers' => array( // Available server definitions
+ * array(
+ * 'host' => 'localhost',
+ * 'port' => 11211,
+ * 'persistent' => FALSE
+ * )
+ * ),
+ * 'compression' => FALSE, // Use compression?
+ * ),
+ * )
+ *
+ * In cases where only one cache group is required, if the group is named `default` there is
+ * no need to pass the group name when instantiating a cache instance.
+ *
+ * #### General cache group configuration settings
+ *
+ * Below are the settings available to all types of cache driver.
+ *
+ * Name | Required | Description
+ * -------------- | -------- | ---------------------------------------------------------------
+ * driver | __YES__ | (_string_) The driver type to use
+ *
+ * Details of the settings specific to each driver are available within the drivers documentation.
+ *
+ * ### System requirements
+ *
+ * * Kohana 3.0.x
+ * * PHP 5.2.4 or greater
+ *
+ * @package Kohana/Cache
+ * @category Base
+ * @version 2.0
+ * @author Kohana Team
+ * @copyright (c) 2009-2010 Kohana Team
+ * @license http://kohanaphp.com/license
+ */
+abstract class Kohana_Cache {
+
+ const DEFAULT_EXPIRE = 3600;
+
+ /**
+ * @var string default driver to use
+ */
+ public static $default = 'file';
+
+ /**
+ * @var Kohana_Cache instances
+ */
+ public static $instances = array();
+
+ /**
+ * Creates a singleton of a Kohana Cache group. If no group is supplied
+ * the __default__ cache group is used.
+ *
+ * // Create an instance of the default group
+ * $default_group = Cache::instance();
+ *
+ * // Create an instance of a group
+ * $foo_group = Cache::instance('foo');
+ *
+ * // Access an instantiated group directly
+ * $foo_group = Cache::$instances['default'];
+ *
+ * @param string the name of the cache group to use [Optional]
+ * @return Kohana_Cache
+ * @throws Cache_Exception
+ */
+ public static function instance($group = NULL)
+ {
+ // If there is no group supplied
+ if ($group === NULL)
+ {
+ // Use the default setting
+ $group = Cache::$default;
+ }
+
+ if (isset(Cache::$instances[$group]))
+ {
+ // Return the current group if initiated already
+ return Cache::$instances[$group];
+ }
+
+ $config = Kohana::$config->load('cache');
+
+ if ( ! $config->offsetExists($group))
+ {
+ throw new Cache_Exception(
+ 'Failed to load Kohana Cache group: :group',
+ array(':group' => $group)
+ );
+ }
+
+ $config = $config->get($group);
+
+ // Create a new cache type instance
+ $cache_class = 'Cache_'.ucfirst($config['driver']);
+ Cache::$instances[$group] = new $cache_class($config);
+
+ // Return the instance
+ return Cache::$instances[$group];
+ }
+
+ /**
+ * @var Config
+ */
+ protected $_config = array();
+
+ /**
+ * Ensures singleton pattern is observed, loads the default expiry
+ *
+ * @param array configuration
+ */
+ protected function __construct(array $config)
+ {
+ $this->config($config);
+ }
+
+ /**
+ * Getter and setter for the configuration. If no argument provided, the
+ * current configuration is returned. Otherwise the configuration is set
+ * to this class.
+ *
+ * // Overwrite all configuration
+ * $cache->config(array('driver' => 'memcache', '...'));
+ *
+ * // Set a new configuration setting
+ * $cache->config('servers', array(
+ * 'foo' => 'bar',
+ * '...'
+ * ));
+ *
+ * // Get a configuration setting
+ * $servers = $cache->config('servers);
+ *
+ * @param mixed key to set to array, either array or config path
+ * @param mixed value to associate with key
+ * @return mixed
+ */
+ public function config($key = NULL, $value = NULL)
+ {
+ if ($key === NULL)
+ return $this->_config;
+
+ if (is_array($key))
+ {
+ $this->_config = $key;
+ }
+ else
+ {
+ if ($value === NULL)
+ return Arr::get($this->_config, $key);
+
+ $this->_config[$key] = $value;
+ }
+
+ return $this;
+ }
+
+ /**
+ * Overload the __clone() method to prevent cloning
+ *
+ * @return void
+ * @throws Cache_Exception
+ */
+ final public function __clone()
+ {
+ throw new Cache_Exception('Cloning of Kohana_Cache objects is forbidden');
+ }
+
+ /**
+ * Retrieve a cached value entry by id.
+ *
+ * // Retrieve cache entry from default group
+ * $data = Cache::instance()->get('foo');
+ *
+ * // Retrieve cache entry from default group and return 'bar' if miss
+ * $data = Cache::instance()->get('foo', 'bar');
+ *
+ * // Retrieve cache entry from memcache group
+ * $data = Cache::instance('memcache')->get('foo');
+ *
+ * @param string id of cache to entry
+ * @param string default value to return if cache miss
+ * @return mixed
+ * @throws Cache_Exception
+ */
+ abstract public function get($id, $default = NULL);
+
+ /**
+ * Set a value to cache with id and lifetime
+ *
+ * $data = 'bar';
+ *
+ * // Set 'bar' to 'foo' in default group, using default expiry
+ * Cache::instance()->set('foo', $data);
+ *
+ * // Set 'bar' to 'foo' in default group for 30 seconds
+ * Cache::instance()->set('foo', $data, 30);
+ *
+ * // Set 'bar' to 'foo' in memcache group for 10 minutes
+ * if (Cache::instance('memcache')->set('foo', $data, 600))
+ * {
+ * // Cache was set successfully
+ * return
+ * }
+ *
+ * @param string id of cache entry
+ * @param string data to set to cache
+ * @param integer lifetime in seconds
+ * @return boolean
+ */
+ abstract public function set($id, $data, $lifetime = 3600);
+
+ /**
+ * Delete a cache entry based on id
+ *
+ * // Delete 'foo' entry from the default group
+ * Cache::instance()->delete('foo');
+ *
+ * // Delete 'foo' entry from the memcache group
+ * Cache::instance('memcache')->delete('foo')
+ *
+ * @param string id to remove from cache
+ * @return boolean
+ */
+ abstract public function delete($id);
+
+ /**
+ * Delete all cache entries.
+ *
+ * Beware of using this method when
+ * using shared memory cache systems, as it will wipe every
+ * entry within the system for all clients.
+ *
+ * // Delete all cache entries in the default group
+ * Cache::instance()->delete_all();
+ *
+ * // Delete all cache entries in the memcache group
+ * Cache::instance('memcache')->delete_all();
+ *
+ * @return boolean
+ */
+ abstract public function delete_all();
+
+ /**
+ * Replaces troublesome characters with underscores.
+ *
+ * // Sanitize a cache id
+ * $id = $this->_sanitize_id($id);
+ *
+ * @param string id of cache to sanitize
+ * @return string
+ */
+ protected function _sanitize_id($id)
+ {
+ // Change slashes and spaces to underscores
+ return str_replace(array('/', '\\', ' '), '_', $id);
+ }
+}
+// End Kohana_Cache
166 www/modules/cache/classes/kohana/cache/apc.php
@@ -0,0 +1,166 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * [Kohana Cache](api/Kohana_Cache) APC driver. Provides an opcode based
+ * driver for the Kohana Cache library.
+ *
+ * ### Configuration example
+ *
+ * Below is an example of an _apc_ server configuration.
+ *
+ * return array(
+ * 'apc' => array( // Driver group
+ * 'driver' => 'apc', // using APC driver
+ * ),
+ * )
+ *
+ * In cases where only one cache group is required, if the group is named `default` there is
+ * no need to pass the group name when instantiating a cache instance.
+ *
+ * #### General cache group configuration settings
+ *
+ * Below are the settings available to all types of cache driver.
+ *
+ * Name | Required | Description
+ * -------------- | -------- | ---------------------------------------------------------------
+ * driver | __YES__ | (_string_) The driver type to use
+ *
+ * ### System requirements
+ *
+ * * Kohana 3.0.x
+ * * PHP 5.2.4 or greater
+ * * APC PHP extension
+ *
+ * @package Kohana/Cache
+ * @category Base
+ * @author Kohana Team
+ * @copyright (c) 2009-2010 Kohana Team
+ * @license http://kohanaphp.com/license
+ */
+class Kohana_Cache_Apc extends Cache implements Cache_Arithmetic {
+
+ /**
+ * Check for existence of the APC extension This method cannot be invoked externally. The driver must
+ * be instantiated using the `Cache::instance()` method.
+ *
+ * @param array configuration
+ * @throws Cache_Exception
+ */
+ protected function __construct(array $config)
+ {
+ if ( ! extension_loaded('apc'))
+ {
+ throw new Cache_Exception('PHP APC extension is not available.');
+ }
+
+ parent::__construct($config);
+ }
+
+ /**
+ * Retrieve a cached value entry by id.
+ *
+ * // Retrieve cache entry from apc group
+ * $data = Cache::instance('apc')->get('foo');
+ *
+ * // Retrieve cache entry from apc group and return 'bar' if miss
+ * $data = Cache::instance('apc')->get('foo', 'bar');
+ *
+ * @param string id of cache to entry
+ * @param string default value to return if cache miss
+ * @return mixed
+ * @throws Cache_Exception
+ */
+ public function get($id, $default = NULL)
+ {
+ $data = apc_fetch($this->_sanitize_id($id), $success);
+
+ return $success ? $data : $default;
+ }
+
+ /**
+ * Set a value to cache with id and lifetime
+ *
+ * $data = 'bar';
+ *
+ * // Set 'bar' to 'foo' in apc group, using default expiry
+ * Cache::instance('apc')->set('foo', $data);
+ *
+ * // Set 'bar' to 'foo' in apc group for 30 seconds
+ * Cache::instance('apc')->set('foo', $data, 30);
+ *
+ * @param string id of cache entry
+ * @param string data to set to cache
+ * @param integer lifetime in seconds
+ * @return boolean
+ */
+ public function set($id, $data, $lifetime = NULL)
+ {
+ if ($lifetime === NULL)
+ {
+ $lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
+ }
+
+ return apc_store($this->_sanitize_id($id), $data, $lifetime);
+ }
+
+ /**
+ * Delete a cache entry based on id
+ *
+ * // Delete 'foo' entry from the apc group
+ * Cache::instance('apc')->delete('foo');
+ *
+ * @param string id to remove from cache
+ * @return boolean
+ */
+ public function delete($id)
+ {
+ return apc_delete($this->_sanitize_id($id));
+ }
+
+ /**
+ * Delete all cache entries.
+ *
+ * Beware of using this method when
+ * using shared memory cache systems, as it will wipe every
+ * entry within the system for all clients.
+ *
+ * // Delete all cache entries in the apc group
+ * Cache::instance('apc')->delete_all();
+ *
+ * @return boolean
+ */
+ public function delete_all()
+ {
+ return apc_clear_cache('user');
+ }
+
+ /**
+ * Increments a given value by the step value supplied.
+ * Useful for shared counters and other persistent integer based
+ * tracking.
+ *
+ * @param string id of cache entry to increment
+ * @param int step value to increment by
+ * @return integer
+ * @return boolean
+ */
+ public function increment($id, $step = 1)
+ {
+ return apc_inc($id, $step);
+ }
+
+ /**
+ * Decrements a given value by the step value supplied.
+ * Useful for shared counters and other persistent integer based
+ * tracking.
+ *
+ * @param string id of cache entry to decrement
+ * @param int step value to decrement by
+ * @return integer
+ * @return boolean
+ */
+ public function decrement($id, $step = 1)
+ {
+ return apc_dec($id, $step);
+ }
+
+} // End Kohana_Cache_Apc
39 www/modules/cache/classes/kohana/cache/arithmetic.php
@@ -0,0 +1,39 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Kohana Cache Arithmetic Interface, for basic cache integer based
+ * arithmetic, addition and subtraction
+ *
+ * @package Kohana/Cache
+ * @category Base
+ * @author Kohana Team
+ * @copyright (c) 2009-2011 Kohana Team
+ * @license http://kohanaphp.com/license
+ * @since 3.2.0
+ */
+interface Kohana_Cache_Arithmetic {
+
+ /**
+ * Increments a given value by the step value supplied.
+ * Useful for shared counters and other persistent integer based
+ * tracking.
+ *
+ * @param string id of cache entry to increment
+ * @param int step value to increment by
+ * @return integer
+ * @return boolean
+ */
+ public function increment($id, $step = 1);
+
+ /**
+ * Decrements a given value by the step value supplied.
+ * Useful for shared counters and other persistent integer based
+ * tracking.
+ *
+ * @param string id of cache entry to decrement
+ * @param int step value to decrement by
+ * @return integer
+ * @return boolean
+ */
+ public function decrement($id, $step = 1);
+
+} // End Kohana_Cache_Arithmetic
11 www/modules/cache/classes/kohana/cache/exception.php
@@ -0,0 +1,11 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Kohana Cache Exception
+ *
+ * @package Kohana/Cache
+ * @category Base
+ * @author Kohana Team
+ * @copyright (c) 2009-2010 Kohana Team
+ * @license http://kohanaphp.com/license
+ */
+class Kohana_Cache_Exception extends Kohana_Exception {}
466 www/modules/cache/classes/kohana/cache/file.php
@@ -0,0 +1,466 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * [Kohana Cache](api/Kohana_Cache) File driver. Provides a file based
+ * driver for the Kohana Cache library. This is one of the slowest
+ * caching methods.
+ *
+ * ### Configuration example
+ *
+ * Below is an example of a _file_ server configuration.
+ *
+ * return array(
+ * 'file' => array( // File driver group
+ * 'driver' => 'file', // using File driver
+ * 'cache_dir' => APPPATH.'cache/.kohana_cache', // Cache location
+ * ),
+ * )
+ *
+ * In cases where only one cache group is required, if the group is named `default` there is
+ * no need to pass the group name when instantiating a cache instance.
+ *
+ * #### General cache group configuration settings
+ *
+ * Below are the settings available to all types of cache driver.
+ *
+ * Name | Required | Description
+ * -------------- | -------- | ---------------------------------------------------------------
+ * driver | __YES__ | (_string_) The driver type to use
+ * cache_dir | __NO__ | (_string_) The cache directory to use for this cache instance
+ *
+ * ### System requirements
+ *
+ * * Kohana 3.0.x
+ * * PHP 5.2.4 or greater
+ *
+ * @package Kohana/Cache
+ * @category Base
+ * @author Kohana Team
+ * @copyright (c) 2009-2010 Kohana Team
+ * @license http://kohanaphp.com/license
+ */
+class Kohana_Cache_File extends Cache implements Cache_GarbageCollect {
+
+ /**
+ * Creates a hashed filename based on the string. This is used
+ * to create shorter unique IDs for each cache filename.
+ *
+ * // Create the cache filename
+ * $filename = Cache_File::filename($this->_sanitize_id($id));
+ *
+ * @param string string to hash into filename
+ * @return string
+ */
+ protected static function filename($string)
+ {
+ return sha1($string).'.cache';
+ }
+
+ /**
+ * @var string the caching directory
+ */
+ protected $_cache_dir;
+
+ /**
+ * Constructs the file cache driver. This method cannot be invoked externally. The file cache driver must
+ * be instantiated using the `Cache::instance()` method.
+ *
+ * @param array config
+ * @throws Cache_Exception
+ */
+ protected function __construct(array $config)
+ {
+ // Setup parent
+ parent::__construct($config);
+
+ try
+ {
+ $directory = Arr::get($this->_config, 'cache_dir', Kohana::$cache_dir);
+ $this->_cache_dir = new SplFileInfo($directory);
+ }
+ // PHP < 5.3 exception handle
+ catch (ErrorException $e)
+ {
+ $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
+ }
+ // PHP >= 5.3 exception handle
+ catch (UnexpectedValueException $e)
+ {
+ $this->_cache_dir = $this->_make_directory($directory, 0777, TRUE);
+ }
+
+ // If the defined directory is a file, get outta here
+ if ($this->_cache_dir->isFile())
+ {
+ throw new Cache_Exception('Unable to create cache directory as a file already exists : :resource', array(':resource' => $this->_cache_dir->getRealPath()));
+ }
+
+ // Check the read status of the directory
+ if ( ! $this->_cache_dir->isReadable())
+ {
+ throw new Cache_Exception('Unable to read from the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
+ }
+
+ // Check the write status of the directory
+ if ( ! $this->_cache_dir->isWritable())
+ {
+ throw new Cache_Exception('Unable to write to the cache directory :resource', array(':resource' => $this->_cache_dir->getRealPath()));
+ }
+ }
+
+ /**
+ * Retrieve a cached value entry by id.
+ *
+ * // Retrieve cache entry from file group
+ * $data = Cache::instance('file')->get('foo');
+ *
+ * // Retrieve cache entry from file group and return 'bar' if miss
+ * $data = Cache::instance('file')->get('foo', 'bar');
+ *
+ * @param string id of cache to entry
+ * @param string default value to return if cache miss
+ * @return mixed
+ * @throws Cache_Exception
+ */
+ public function get($id, $default = NULL)
+ {
+ $filename = Cache_File::filename($this->_sanitize_id($id));
+ $directory = $this->_resolve_directory($filename);
+
+ // Wrap operations in try/catch to handle notices
+ try
+ {
+ // Open file
+ $file = new SplFileInfo($directory.$filename);
+
+ // If file does not exist
+ if ( ! $file->isFile())
+ {
+ // Return default value
+ return $default;
+ }
+ else
+ {
+ // Open the file and parse data
+ $created = $file->getMTime();
+ $data = $file->openFile();
+ $lifetime = $data->fgets();
+
+ // If we're at the EOF at this point, corrupted!
+ if ($data->eof())
+ {
+ throw new Cache_Exception(__METHOD__.' corrupted cache file!');
+ }
+
+ $cache = '';
+
+ while ($data->eof() === FALSE)
+ {
+ $cache .= $data->fgets();
+ }
+
+ // Test the expiry
+ if (($created + (int) $lifetime) < time())
+ {
+ // Delete the file
+ $this->_delete_file($file, NULL, TRUE);
+ return $default;
+ }
+ else
+ {
+ return unserialize($cache);
+ }
+ }
+
+ }
+ catch (ErrorException $e)
+ {
+ // Handle ErrorException caused by failed unserialization
+ if ($e->getCode() === E_NOTICE)
+ {
+ throw new Cache_Exception(__METHOD__.' failed to unserialize cached object with message : '.$e->getMessage());
+ }
+
+ // Otherwise throw the exception
+ throw $e;
+ }
+ }
+
+ /**
+ * Set a value to cache with id and lifetime
+ *
+ * $data = 'bar';
+ *
+ * // Set 'bar' to 'foo' in file group, using default expiry
+ * Cache::instance('file')->set('foo', $data);
+ *
+ * // Set 'bar' to 'foo' in file group for 30 seconds
+ * Cache::instance('file')->set('foo', $data, 30);
+ *
+ * @param string id of cache entry
+ * @param string data to set to cache
+ * @param integer lifetime in seconds
+ * @return boolean
+ */
+ public function set($id, $data, $lifetime = NULL)
+ {
+ $filename = Cache_File::filename($this->_sanitize_id($id));
+ $directory = $this->_resolve_directory($filename);
+
+ // If lifetime is NULL
+ if ($lifetime === NULL)
+ {
+ // Set to the default expiry
+ $lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
+ }
+
+ // Open directory
+ $dir = new SplFileInfo($directory);
+
+ // If the directory path is not a directory
+ if ( ! $dir->isDir())
+ {
+ // Create the directory
+ if ( ! mkdir($directory, 0777, TRUE))
+ {
+ throw new Cache_Exception(__METHOD__.' unable to create directory : :directory', array(':directory' => $directory));
+ }
+
+ // chmod to solve potential umask issues
+ chmod($directory, 0777);
+ }
+
+ // Open file to inspect
+ $resouce = new SplFileInfo($directory.$filename);
+ $file = $resouce->openFile('w');
+
+ try
+ {
+ $data = $lifetime."\n".serialize($data);
+ $file->fwrite($data, strlen($data));
+ return (bool) $file->fflush();
+ }
+ catch (ErrorException $e)
+ {
+ // If serialize through an error exception
+ if ($e->getCode() === E_NOTICE)
+ {
+ // Throw a caching error
+ throw new Cache_Exception(__METHOD__.' failed to serialize data for caching with message : '.$e->getMessage());
+ }
+
+ // Else rethrow the error exception
+ throw $e;
+ }
+ }
+
+ /**
+ * Delete a cache entry based on id
+ *
+ * // Delete 'foo' entry from the file group
+ * Cache::instance('file')->delete('foo');
+ *
+ * @param string id to remove from cache
+ * @return boolean
+ */
+ public function delete($id)
+ {
+ $filename = Cache_File::filename($this->_sanitize_id($id));
+ $directory = $this->_resolve_directory($filename);
+
+ return $this->_delete_file(new SplFileInfo($directory.$filename), NULL, TRUE);
+ }
+
+ /**
+ * Delete all cache entries.
+ *
+ * Beware of using this method when
+ * using shared memory cache systems, as it will wipe every
+ * entry within the system for all clients.
+ *
+ * // Delete all cache entries in the file group
+ * Cache::instance('file')->delete_all();
+ *
+ * @return boolean
+ */
+ public function delete_all()
+ {
+ return $this->_delete_file($this->_cache_dir, TRUE);
+ }
+
+ /**
+ * Garbage collection method that cleans any expired
+ * cache entries from the cache.
+ *
+ * @return void
+ */
+ public function garbage_collect()
+ {
+ $this->_delete_file($this->_cache_dir, TRUE, FALSE, TRUE);
+ return;
+ }
+
+ /**
+ * Deletes files recursively and returns FALSE on any errors
+ *
+ * // Delete a file or folder whilst retaining parent directory and ignore all errors
+ * $this->_delete_file($folder, TRUE, TRUE);
+ *
+ * @param SplFileInfo file
+ * @param boolean retain the parent directory
+ * @param boolean ignore_errors to prevent all exceptions interrupting exec
+ * @param boolean only expired files
+ * @return boolean
+ * @throws Cache_Exception
+ */
+ protected function _delete_file(SplFileInfo $file, $retain_parent_directory = FALSE, $ignore_errors = FALSE, $only_expired = FALSE)
+ {
+ // Allow graceful error handling
+ try
+ {
+ // If is file
+ if ($file->isFile())
+ {
+ try
+ {
+ // Handle ignore files
+ if (in_array($file->getFilename(), $this->config('ignore_on_delete')))
+ {
+ $delete = FALSE;
+ }
+ // If only expired is not set
+ elseif ($only_expired === FALSE)
+ {
+ // We want to delete the file
+ $delete = TRUE;
+ }
+ // Otherwise...
+ else
+ {
+ // Assess the file expiry to flag it for deletion
+ $json = $file->openFile('r')->current();
+ $data = json_decode($json);
+ $delete = $data->expiry < time();
+ }
+
+ // If the delete flag is set delete file
+ if ($delete === TRUE)
+ return unlink($file->getRealPath());
+ else
+ return FALSE;
+ }
+ catch (ErrorException $e)
+ {
+ // Catch any delete file warnings
+ if ($e->getCode() === E_WARNING)
+ {
+ throw new Cache_Exception(__METHOD__.' failed to delete file : :file', array(':file' => $file->getRealPath()));
+ }
+ }
+ }
+ // Else, is directory
+ elseif ($file->isDir())
+ {
+ // Create new DirectoryIterator
+ $files = new DirectoryIterator($file->getPathname());
+
+ // Iterate over each entry
+ while ($files->valid())
+ {
+ // Extract the entry name
+ $name = $files->getFilename();
+
+ // If the name is not a dot
+ if ($name != '.' AND $name != '..')
+ {
+ // Create new file resource
+ $fp = new SplFileInfo($files->getRealPath());
+ // Delete the file
+ $this->_delete_file($fp);
+ }
+
+ // Move the file pointer on
+ $files->next();
+ }
+
+ // If set to retain parent directory, return now
+ if ($retain_parent_directory)
+ {
+ return TRUE;
+ }
+
+ try
+ {
+ // Remove the files iterator
+ // (fixes Windows PHP which has permission issues with open iterators)
+ unset($files);
+
+ // Try to remove the parent directory
+ return rmdir($file->getRealPath());
+ }
+ catch (ErrorException $e)
+ {
+ // Catch any delete directory warnings
+ if ($e->getCode() === E_WARNING)
+ {
+ throw new Cache_Exception(__METHOD__.' failed to delete directory : :directory', array(':directory' => $file->getRealPath()));
+ }
+ throw $e;
+ }
+ }
+ else
+ {
+ // We get here if a file has already been deleted
+ return FALSE;
+ }
+ }
+ // Catch all exceptions
+ catch (Exception $e)
+ {
+ // If ignore_errors is on
+ if ($ignore_errors === TRUE)
+ {
+ // Return
+ return FALSE;
+ }
+ // Throw exception
+ throw $e;
+ }
+ }
+
+ /**
+ * Resolves the cache directory real path from the filename
+ *
+ * // Get the realpath of the cache folder
+ * $realpath = $this->_resolve_directory($filename);
+ *
+ * @param string filename to resolve
+ * @return string
+ */
+ protected function _resolve_directory($filename)
+ {
+ return $this->_cache_dir->getRealPath().DIRECTORY_SEPARATOR.$filename[0].$filename[1].DIRECTORY_SEPARATOR;
+ }
+
+ /**
+ * Makes the cache directory if it doesn't exist. Simply a wrapper for
+ * `mkdir` to ensure DRY principles
+ *
+ * @see http://php.net/manual/en/function.mkdir.php
+ * @param string directory
+ * @param string mode
+ * @param string recursive
+ * @param string context
+ * @return SplFileInfo
+ * @throws Cache_Exception
+ */
+ protected function _make_directory($directory, $mode = 0777, $recursive = FALSE, $context = NULL)
+ {
+ if ( ! mkdir($directory, $mode, $recursive, $context))
+ {
+ throw new Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory));
+ }
+ chmod($directory, $mode);
+
+ return new SplFileInfo($directory);;
+ }
+}
23 www/modules/cache/classes/kohana/cache/garbagecollect.php
@@ -0,0 +1,23 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * Garbage Collection interface for caches that have no GC methods
+ * of their own, such as [Cache_File] and [Cache_Sqlite]. Memory based
+ * cache systems clean their own caches periodically.
+ *
+ * @package Kohana/Cache
+ * @category Base
+ * @version 2.0
+ * @author Kohana Team
+ * @copyright (c) 2009-2010 Kohana Team
+ * @license http://kohanaphp.com/license
+ * @since 3.0.8
+ */
+interface Kohana_Cache_GarbageCollect {
+ /**
+ * Garbage collection method that cleans any expired
+ * cache entries from the cache.
+ *
+ * @return void
+ */
+ public function garbage_collect();
+}
354 www/modules/cache/classes/kohana/cache/memcache.php
@@ -0,0 +1,354 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+/**
+ * [Kohana Cache](api/Kohana_Cache) Memcache driver,
+ *
+ * ### Supported cache engines
+ *
+ * * [Memcache](http://www.php.net/manual/en/book.memcache.php)
+ * * [Memcached-tags](http://code.google.com/p/memcached-tags/)
+ *
+ * ### Configuration example
+ *
+ * Below is an example of a _memcache_ server configuration.
+ *
+ * return array(
+ * 'default' => array( // Default group
+ * 'driver' => 'memcache', // using Memcache driver
+ * 'servers' => array( // Available server definitions
+ * // First memcache server server
+ * array(
+ * 'host' => 'localhost',
+ * 'port' => 11211,
+ * 'persistent' => FALSE
+ * 'weight' => 1,
+ * 'timeout' => 1,
+ * 'retry_interval' => 15,
+ * 'status' => TRUE,
+ * 'instant_death' => TRUE,
+ * 'failure_callback' => array('className', 'classMethod')
+ * ),
+ * // Second memcache server
+ * array(
+ * 'host' => '192.168.1.5',
+ * 'port' => 22122,
+ * 'persistent' => TRUE
+ * )
+ * ),
+ * 'compression' => FALSE, // Use compression?
+ * ),
+ * )
+ *
+ * In cases where only one cache group is required, if the group is named `default` there is
+ * no need to pass the group name when instantiating a cache instance.
+ *
+ * #### General cache group configuration settings
+ *
+ * Below are the settings available to all types of cache driver.
+ *
+ * Name | Required | Description
+ * -------------- | -------- | ---------------------------------------------------------------
+ * driver | __YES__ | (_string_) The driver type to use
+ * servers | __YES__ | (_array_) Associative array of server details, must include a __host__ key. (see _Memcache server configuration_ below)
+ * compression | __NO__ | (_boolean_) Use data compression when caching
+ *
+ * #### Memcache server configuration
+ *
+