Permalink
Browse files

Complete system rewrite. Faster, lighter, better l10n/i18n support, r…

…emoval of modules, full PSR-0 support, migrations system. It's a whole new animal.
  • Loading branch information...
Xeoncross committed Nov 13, 2011
1 parent 285e160 commit 68136a5270700377987fbc8f3d532f7d4a6ce1b2
Showing with 5,242 additions and 160 deletions.
  1. +14 −4 .gitignore
  2. +86 −0 Bootstrap.php
  3. +41 −0 CLI
  4. +31 −0 Class/Controller/Index.php
  5. +19 −0 Class/Controller/Page404.php
  6. +69 −0 Class/Core/Cipher.php
  7. +58 −0 Class/Core/Controller.php
  8. +69 −0 Class/Core/Cookie.php
  9. +370 −0 Class/Core/Database.php
  10. +82 −0 Class/Core/Directory.php
  11. +133 −0 Class/Core/Dispatch.php
  12. +126 −0 Class/Core/Error.php
  13. +246 −0 Class/Core/Form.php
  14. +132 −0 Class/Core/GD.php
  15. +123 −0 Class/Core/HTML.php
  16. +196 −0 Class/Core/Migration.php
  17. +182 −0 Class/Core/Migration/MySQL.php
  18. +193 −0 Class/Core/Migration/PGSQL.php
  19. +623 −0 Class/Core/ORM.php
  20. +43 −0 Class/Core/ORM/APC.php
  21. +164 −0 Class/Core/Pagination.php
  22. +118 −0 Class/Core/Service.php
  23. +86 −0 Class/Core/Session.php
  24. +144 −0 Class/Core/Table.php
  25. +106 −0 Class/Core/Upload.php
  26. +387 −0 Class/Core/Validation.php
  27. +68 −0 Class/Core/View.php
  28. +58 −0 Class/Core/XML.php
  29. +25 −0 Class/Model/Permission.php
  30. +22 −0 Class/Model/Resource.php
  31. +25 −0 Class/Model/Role.php
  32. +14 −0 Class/Model/User.php
  33. +80 −0 Class/MyController.php
  34. +25 −0 Command/Backup.php
  35. +25 −0 Command/Create.php
  36. +25 −0 Command/Restore.php
  37. +27 −0 Command/Run.php
  38. +544 −0 Common.php
  39. +76 −0 Config/Sample.Config.php
  40. +29 −0 Config/Sample.Migration.php
  41. +33 −0 Config/Sample.Route.php
  42. 0 Locale/.gitignore
  43. +16 −51 Public/index.php
  44. +6 −8 README/install.txt
  45. +2 −81 README/sample.htaccess
  46. +27 −16 README/sample.nginx.conf
  47. +2 −0 View/404.php
  48. +2 −0 View/Index/Index.php
  49. +51 −0 View/Layout.php
  50. +6 −0 View/Sidebar.php
  51. +71 −0 View/System/Debug.php
  52. +69 −0 View/System/Error.php
  53. +73 −0 View/System/Exception.php
View
@@ -1,9 +1,19 @@
+# Linux
+.*
+!.gitignore
+*~
+
+# OS X
.DS_Store
+# Thumbnails
+._*
+
+# Windows
Thumbs.db
-*~
+Desktop.ini
+
+# MicroMVC
*.cache
*.log
Uploads
-config.php
-ignore
-Backups
+Storage
View
@@ -0,0 +1,86 @@
+<?php
+/**
+ * Bootstrap
+ *
+ * This file contains initialization code run immediately after system startup.
+ * Setup i18n and l10n handling, configure system, prepare event hooks.
+ *
+ * @package MicroMVC
+ * @author David Pennington
+ * @copyright (c) 2010 MicroMVC Framework
+ * @license http://micromvc.com/license
+ ********************************** 80 Columns *********************************
+ */
+
+// System Start Time
+define('START_TIME', microtime(true));
+
+// System Start Memory
+define('START_MEMORY_USAGE', memory_get_usage());
+
+// Extension of all PHP files
+define('EXT', '.php');
+
+// Directory separator (Unix-Style works on all OS)
+define('DS', '/');
+
+// Absolute path to the system folder
+define('SP', realpath(__DIR__). DS);
+
+// Is this an AJAX request?
+define('AJAX_REQUEST', strtolower(getenv('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest');
+
+// The current TLD address, scheme, and port
+define('DOMAIN', (strtolower(getenv('HTTPS')) == 'on' ? 'https' : 'http') . '://'
+ . getenv('HTTP_HOST') . (($p = getenv('SERVER_PORT')) != 80 AND $p != 443 ? ":$p" : ''));
+
+// The current site path
+define('PATH', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH));
+
+// Include common system functions
+require(SP . 'Common' . EXT);
+
+// Register events
+foreach(config()->events as $event => $class)
+{
+ event($event, NULL, $class);
+}
+
+/*
+if(preg_match_all('/[\-a-z]{2,}/i', getenv('HTTP_ACCEPT_LANGUAGE'), $locales))
+{
+ $locales = $locales[0];
+}
+*/
+
+// Get locale from user agent
+if(isset($_COOKIE['lang']))
+{
+ $preference = $_COOKIE['lang'];
+}
+else
+{
+ $preference = Locale::acceptFromHttp(getenv('HTTP_ACCEPT_LANGUAGE'));
+}
+
+// Match preferred language to those available, defaulting to generic English
+$locale = Locale::lookup(config()->languages, $preference, false, 'en');
+
+// Default Locale
+Locale::setDefault($locale);
+setlocale(LC_ALL, $locale . '.utf-8');
+//putenv("LC_ALL", $locale);
+
+// Default timezone of server
+date_default_timezone_set('UTC');
+
+// iconv encoding
+iconv_set_encoding("internal_encoding", "UTF-8");
+
+// multibyte encoding
+mb_internal_encoding('UTF-8');
+
+// Enable global error handling
+set_error_handler(array('\Core\Error', 'handler'));
+register_shutdown_function(array('\Core\Error', 'fatal'));
+
View
41 CLI
@@ -0,0 +1,41 @@
+<?php if(PHP_SAPI !== 'cli') die();
+/**
+ * CLI
+ *
+ * This file is the command-line interface (CLI) entry point for the system
+ *
+ * @package MicroMVC
+ * @author David Pennington
+ * @copyright (c) 2010 MicroMVC Framework
+ * @license http://micromvc.com/license
+ ********************************** 80 Columns *********************************
+ */
+
+// Include bootstrap
+require('Bootstrap.php');
+
+// Require a CLI path
+if(empty($argv[1]))
+{
+ die("Please enter a path to the CLI file.\nExample: " . colorize('php cli file.php', 'blue') . "\n");
+}
+
+// Build path to file
+$file = SP . 'Command/' . str_replace(EXT, '', trim($argv[1], '/')) . EXT;
+
+// Does the file exist?
+if( ! is_file($file)) die("Please enter a valid file path\n");
+
+// Require a valid, safe path
+if( ! preg_match('/^[\w\-~\/\.+]{1,600}/', $argv[1])) die(colorize("Invalid path given", 'red'). "\n");
+
+try
+{
+ require($file);
+}
+catch (Exception $e)
+{
+ \Core\Error::exception($e);
+}
+
+// End
View
@@ -0,0 +1,31 @@
+<?php
+/**
+ * Index Page
+ *
+ * Example index page.
+ *
+ * @package MicroMVC
+ * @author David Pennington
+ * @copyright (c) 2011 MicroMVC Framework
+ * @license http://micromvc.com/license
+ ********************************** 80 Columns *********************************
+ */
+namespace Controller;
+
+class Index extends \MyController
+{
+ public function run()
+ {
+ // Load database
+ //$this->db = new DB(config('database'));
+
+ // Set ORM database connection
+ //ORM::$db = $this->db;
+
+ // Load the theme sidebar since we don't need the full page
+ $this->sidebar = new \Core\View('Sidebar');
+
+ // Load the welcome view
+ $this->content = new \Core\View('Index/Index');
+ }
+}
@@ -0,0 +1,19 @@
+<?php
+/**
+ * 404 Page
+ *
+ * @package MicroMVC
+ * @author David Pennington
+ * @copyright (c) 2011 MicroMVC Framework
+ * @license http://micromvc.com/license
+ ********************************** 80 Columns *********************************
+ */
+namespace Controller;
+
+class Page404 extends \MyController
+{
+ public function run()
+ {
+ $this->show_404();
+ }
+}
View
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Cipher
+ *
+ * Provides encryption/decription functionality including URL shortening . By
+ * default the encrypt/decrypt functions use AES to encrypt a string using
+ * Cipher-block chaining (CBC) and then sign it using HMAC-SHA256 to prevent
+ * initialization vector (IV) man-in-the-middle attacks against the first block .
+ *
+ * @package MicroMVC
+ * @author David Pennington
+ * @copyright (c) 2011 MicroMVC Framework
+ * @license http://micromvc.com/license
+ ********************************** 80 Columns *********************************
+ */
+namespace Core;
+
+class Cipher
+{
+
+ /**
+ * Encrypt a string
+ *
+ * @param string $text to encrypt
+ * @param string $key a cryptographically random string
+ * @param int $algo the encryption algorithm
+ * @param int $mode the block cipher mode
+ * @return string
+ */
+ public static function encrypt($text, $key, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
+ {
+ // Create IV for encryption
+ $iv = mcrypt_create_iv(mcrypt_get_iv_size($algo, $mode), MCRYPT_RAND);
+
+ // Encrypt text and append IV so it can be decrypted later
+ $text = mcrypt_encrypt($algo, hash('sha256', $key, TRUE), $text, $mode, $iv) . $iv;
+
+ // Prefix text with HMAC so that IV cannot be changed
+ return hash('sha256', $key . $text) . $text;
+ }
+
+
+ /**
+ * Decrypt an encrypted string
+ *
+ * @param string $text to encrypt
+ * @param string $key a cryptographically random string
+ * @param int $algo the encryption algorithm
+ * @param int $mode the block cipher mode
+ * @return string
+ */
+ public static function decrypt($text, $key, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
+ {
+ $hash = substr($text, 0, 64);
+ $text = substr($text, 64);
+
+ // Invalid HMAC?
+ if(hash('sha256', $key . $text) != $hash) return;
+
+ // Get IV off end of encrypted string
+ $iv = substr($text, -mcrypt_get_iv_size($algo, $mode));
+
+ // Decrypt string using IV and remove trailing \x0 padding added by mcrypt
+ return rtrim(mcrypt_decrypt($algo, hash('sha256', $key, TRUE), substr($text, 0, -strlen($iv)), $mode, $iv), "\x0");
+ }
+
+}
+
+// END
View
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Controller
+ *
+ * Basic outline for standard system controllers.
+ *
+ * @package MicroMVC
+ * @author David Pennington
+ * @copyright (c) 2011 MicroMVC Framework
+ * @license http://micromvc.com/license
+ ********************************** 80 Columns *********************************
+ */
+namespace Core;
+
+abstract class Controller
+{
+ // URL path segment matched to route here
+ public $route = NULL;
+
+ // The dispatch object (Can be used to load other Controllers)
+ public $dispatch = NULL;
+
+ /**
+ * Set error handling and start session
+ */
+ public function __construct($route, \Core\Dispatch $dispatch)
+ {
+ $this->route = $route;
+ $this->dispatch = $dispatch;
+ }
+
+
+ /**
+ * Called before the controller method is run
+ *
+ * @param string $method name that will be run
+ */
+ public function initialize($method) {}
+
+
+ /* HTTP Request Methods
+ abstract public function run(); // Default for all non-defined request methods
+ abstract public function get();
+ abstract public function post();
+ abstract public function put();
+ abstract public function delete();
+ abstract public function options();
+ abstract public function head();
+ */
+
+ /**
+ * Called after the controller method is run to send the response
+ */
+ public function send() {}
+
+}
+
+// End
Oops, something went wrong.

0 comments on commit 68136a5

Please sign in to comment.