forked from xeoncross/micromvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
53 changed files
with
5,242 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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')); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.