PageRenderTime 65ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/JACKED/JACKED.php

http://poordecisions.googlecode.com/
PHP | 160 lines | 159 code | 0 blank | 1 comment | 1 complexity | 7c40e3145fa575d42ec74b89bfa35983 MD5 | raw file
Possible License(s): Apache-2.0
  1. <?php
  2. //autoload classes from modules folder when they're called
  3. spl_autoload_register(function($class){
  4. $did = false;
  5. $file = JACKED_MODULES_ROOT . $class . '.php';
  6. if (file_exists($file)){
  7. require($file);
  8. $did = true;
  9. }else{
  10. throw new Exception("JACKED can't find a class for the module named " . $class . ".");
  11. }
  12. return $did;
  13. });
  14. //THE fucking class
  15. class JACKED{
  16. const moduleName = "JACKED Core";
  17. const moduleVersion = 3.0;
  18. protected static $_instance = null;
  19. public $config;
  20. public function __construct($required="", $optional=""){
  21. self::$_instance = $this;
  22. self::$_instance->config = new Configur("core");
  23. //set up debug
  24. switch(self::$_instance->config->debug){
  25. case 1:
  26. ini_set('display_errors', 'On');
  27. error_reporting(E_ALL ^ E_NOTICE);
  28. break;
  29. case 2:
  30. ini_set('display_errors', 'On');
  31. error_reporting(-1);
  32. break;
  33. case -1:
  34. ini_set('display_errors', 'On');
  35. error_reporting(E_ALL ^ E_NOTICE);
  36. break;
  37. case -2:
  38. ini_set('display_errors', 'On');
  39. error_reporting(-1);
  40. break;
  41. default:
  42. ini_set('display_errors', 'Off');
  43. ini_set('log_errors', 'On');
  44. error_reporting(E_ALL ^ E_NOTICE);
  45. break;
  46. }
  47. self::$_instance->loadDependencies($required);
  48. self::$_instance->loadOptionalDependencies($optional);
  49. }
  50. public static function getInstance($required = "", $optional = ""){
  51. if (self::$_instance === null) {
  52. self::$_instance = new JACKED();
  53. }
  54. self::$_instance->loadDependencies($required);
  55. self::$_instance->loadOptionalDependencies($optional);
  56. return self::$_instance;
  57. }
  58. private function isModuleRegistered($name){
  59. return property_exists(self::$_instance, $name) && self::$_instance->$name->getEnabled();
  60. }
  61. private function registerModule($name){
  62. if($name && !self::$_instance->isModuleRegistered($name))
  63. self::$_instance->$name = new $name(self::$_instance);
  64. }
  65. public function loadDependencies($deps){
  66. foreach(explode(", ", $deps) as $module){
  67. if(!self::$_instance->isModuleRegistered($module)){
  68. try{
  69. self::$_instance->registerModule($module);
  70. }catch(Exception $e){
  71. self::$_instance->debug_dump('<br />required module <strong>' . $module . '</strong> not found.<br />');
  72. }
  73. }
  74. }
  75. }
  76. public function loadOptionalDependencies($mods){
  77. foreach(explode(", ", $mods) as $module){
  78. if(!self::$_instance->isModuleRegistered($module)){
  79. try{
  80. self::$_instance->registerModule($module);
  81. }catch(Exception $e){
  82. self::$_instance->$module = new Derper();
  83. self::$_instance->debug_dump('Couldn\'t find optional module: ' . $module . '.');
  84. }
  85. }
  86. }
  87. }
  88. public function __destruct(){
  89. //unload?
  90. }
  91. //util
  92. //generateHash(string, string) -> string
  93. //found on the PHP Security Consortium page:
  94. ////http://phpsec.org/articles/2005/password-hashing.html
  95. //takes a string and an optional second argument,
  96. ////if $salt is not provided, the function will add an extra string of random
  97. ////characters to the plaintext and return the SHA1 hash of the entire string,
  98. ////and the original salt will be appended to the beginning of the hash.
  99. ////if $salt is provided, see documentation
  100. public function generateHash($plainText, $salt = NULL){
  101. if ($salt === NULL){
  102. $salt = substr(md5(uniqid(rand(), true)), 0, self::$_instance->config->salt_length);
  103. }else{
  104. $salt = substr($salt, 0, self::$_instance->config->salt_length);
  105. }
  106. return $salt . sha1($salt . $plainText);
  107. }
  108. ////////////////////////////////////////////
  109. // motherfuckin debuggery
  110. ////////////////////////////////////////////
  111. //MAKE THE PRINTS
  112. private function print_repr($title, $var){
  113. echo '<br /><font color="red">' . $title . ':</font><br /><pre><code>';
  114. echo var_export($var, true);
  115. echo '</code></pre><br />';
  116. }
  117. //not yet
  118. private function log_repr($title, $var){
  119. //lol
  120. }
  121. //dumps a given var, if conf->debug is not turned off
  122. public function debug_dump($var){
  123. if(self::$_instance->config->debug > 0){
  124. self::print_repr('DEBUG DUMP', $var);
  125. }
  126. }
  127. //prints a backtrace
  128. public function backtrace(){
  129. if(self::$_instance->config->debug > 0){
  130. self::print_repr('DEBUG BACKTRACE', debug_backtrace());
  131. }
  132. }
  133. //harp darp
  134. public function derp(){
  135. return self::$_instance->config->lol;
  136. }
  137. }
  138. ?>