/JACKED/JACKED.php
http://poordecisions.googlecode.com/ · PHP · 160 lines · 159 code · 0 blank · 1 comment · 1 complexity · 7c40e3145fa575d42ec74b89bfa35983 MD5 · raw file
- <?php
- //autoload classes from modules folder when they're called
- spl_autoload_register(function($class){
- $did = false;
- $file = JACKED_MODULES_ROOT . $class . '.php';
- if (file_exists($file)){
- require($file);
- $did = true;
- }else{
- throw new Exception("JACKED can't find a class for the module named " . $class . ".");
- }
- return $did;
- });
- //THE fucking class
- class JACKED{
- const moduleName = "JACKED Core";
- const moduleVersion = 3.0;
-
- protected static $_instance = null;
- public $config;
-
- public function __construct($required="", $optional=""){
- self::$_instance = $this;
- self::$_instance->config = new Configur("core");
- //set up debug
- switch(self::$_instance->config->debug){
- case 1:
- ini_set('display_errors', 'On');
- error_reporting(E_ALL ^ E_NOTICE);
- break;
- case 2:
- ini_set('display_errors', 'On');
- error_reporting(-1);
- break;
- case -1:
- ini_set('display_errors', 'On');
- error_reporting(E_ALL ^ E_NOTICE);
- break;
- case -2:
- ini_set('display_errors', 'On');
- error_reporting(-1);
- break;
-
- default:
- ini_set('display_errors', 'Off');
- ini_set('log_errors', 'On');
- error_reporting(E_ALL ^ E_NOTICE);
- break;
- }
-
- self::$_instance->loadDependencies($required);
- self::$_instance->loadOptionalDependencies($optional);
- }
-
- public static function getInstance($required = "", $optional = ""){
- if (self::$_instance === null) {
- self::$_instance = new JACKED();
- }
- self::$_instance->loadDependencies($required);
- self::$_instance->loadOptionalDependencies($optional);
-
- return self::$_instance;
- }
-
- private function isModuleRegistered($name){
- return property_exists(self::$_instance, $name) && self::$_instance->$name->getEnabled();
- }
-
- private function registerModule($name){
- if($name && !self::$_instance->isModuleRegistered($name))
- self::$_instance->$name = new $name(self::$_instance);
- }
-
- public function loadDependencies($deps){
- foreach(explode(", ", $deps) as $module){
- if(!self::$_instance->isModuleRegistered($module)){
- try{
- self::$_instance->registerModule($module);
- }catch(Exception $e){
- self::$_instance->debug_dump('<br />required module <strong>' . $module . '</strong> not found.<br />');
- }
- }
- }
- }
-
- public function loadOptionalDependencies($mods){
- foreach(explode(", ", $mods) as $module){
- if(!self::$_instance->isModuleRegistered($module)){
- try{
- self::$_instance->registerModule($module);
- }catch(Exception $e){
- self::$_instance->$module = new Derper();
- self::$_instance->debug_dump('Couldn\'t find optional module: ' . $module . '.');
- }
- }
- }
- }
-
- public function __destruct(){
- //unload?
- }
-
- //util
-
- //generateHash(string, string) -> string
- //found on the PHP Security Consortium page:
- ////http://phpsec.org/articles/2005/password-hashing.html
- //takes a string and an optional second argument,
- ////if $salt is not provided, the function will add an extra string of random
- ////characters to the plaintext and return the SHA1 hash of the entire string,
- ////and the original salt will be appended to the beginning of the hash.
- ////if $salt is provided, see documentation
- public function generateHash($plainText, $salt = NULL){
- if ($salt === NULL){
- $salt = substr(md5(uniqid(rand(), true)), 0, self::$_instance->config->salt_length);
- }else{
- $salt = substr($salt, 0, self::$_instance->config->salt_length);
- }
- return $salt . sha1($salt . $plainText);
- }
-
- ////////////////////////////////////////////
- // motherfuckin debuggery
- ////////////////////////////////////////////
-
- //MAKE THE PRINTS
- private function print_repr($title, $var){
- echo '<br /><font color="red">' . $title . ':</font><br /><pre><code>';
- echo var_export($var, true);
- echo '</code></pre><br />';
- }
-
- //not yet
- private function log_repr($title, $var){
- //lol
- }
-
- //dumps a given var, if conf->debug is not turned off
- public function debug_dump($var){
- if(self::$_instance->config->debug > 0){
- self::print_repr('DEBUG DUMP', $var);
- }
- }
-
- //prints a backtrace
- public function backtrace(){
- if(self::$_instance->config->debug > 0){
- self::print_repr('DEBUG BACKTRACE', debug_backtrace());
- }
- }
-
-
- //harp darp
- public function derp(){
- return self::$_instance->config->lol;
- }
- }
- ?>