public static function exception($exception, $trace = true) { static::log($exception); ob_get_level() and ob_end_clean(); $message = $exception->getMessage(); $file = $exception->getFile(); $code = $exception->getCode(); $response = "<html>\n<h2>Unhandled Exception</h2>\n<h3>Message:</h3>\n<pre>(" . $code . ") " . $message . "</pre>\n<h3>Location:</h3>\n<pre>" . $file . " on line " . $exception->getLine() . "</pre>\n"; if ($trace) { $response .= "<h3>Stack Trace:</h3>\n<pre>" . $exception->getTraceAsString() . "</pre>\n"; } $response .= "</html>"; Response::code(500); if (Config::item("errors", "show", false)) { echo $response; } if (Config::item("errors", "email", false) && !Request::isLocal() && !Request::isPreview()) { $e = new Email(); $e->from = Config::item("errors", "emailFrom", "*****@*****.**"); $e->to = Config::item("errors", "emailTo", "*****@*****.**"); $e->subject = URL::root() . " - erro!"; $e->content = $response; $e->send(); } return exit(1); }
public static function init() { static::$path = J_APPPATH . "storage" . DS . "cache" . DS; if (Request::isLocal()) { if (!File::exists(static::$path)) { trigger_error("Directory <b>" . static::$path . "</b> doesn't exists."); } else { if (!is_writable(static::$path)) { trigger_error("Directory <b>" . static::$path . "</b> is not writable."); } } } }
public static function routes() { static::loadModules(); foreach (static::$modulesObjects as $object) { $object->routes(); } //Load login routes.. login, logoff, etc.. Router::register("GET", "manager/api/config/", function () { header("Content-Type: text/javascript; charset=utf-8"); if (Request::isLocal()) { if (@DB::query("select id from " . J_TP . "manager_users LIMIT 1;")->success === false) { DB::query("CREATE TABLE `" . J_TP . "manager_users` (\n\t\t\t\t\t\t\t\t`id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t\t\t`name` varchar(255) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`email` varchar(255) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`typeID` int(11) unsigned NULL,\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t`username` varchar(255) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`password` varchar(40) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`active` int(11) DEFAULT NULL,\n\t\t\t\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t\t\t\t) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"); $user = ORM::make("manager_users"); $user->name = "Joy Interactive"; $user->email = "*****@*****.**"; $user->username = "******"; $user->password = "******"; $user->typeID = 1; $user->active = 1; $user->save(); } if (@DB::query("select id from " . J_TP . "manager_tokens LIMIT 1;")->success === false) { DB::query("CREATE TABLE `" . J_TP . "manager_tokens` (\n\t\t\t\t\t\t\t\t`id` int(40) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t\t\t`userID` int(11) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`typeID` int(11) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`token` varchar(100) DEFAULT NULL,\n\t\t\t\t\t\t\t\t`expirationDate` datetime DEFAULT NULL,\n\t\t\t\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t\t\t\t) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;"); } } $config = array(); $config["api_url"] = URL::to("api/"); return "window.config = " . json_encode($config); }); Router::register("GET", "manager/api/structure/", function () { return Response::json(Structure::modules()); }); Router::register("POST", "manager/api/token/", function () { return User::generateToken(); }); Router::register("POST", "manager/api/token/renew/", function () { return User::renewToken(); }); Router::register("GET", "manager/api/logout/", function () { return User::logout(); }); Router::register("GET", "manager/api/customJS/", function () { $path = J_MANAGERPATH . "custom.js"; if (file_exists($path)) { return File::get($path); } }); }
private static function process($route) { $uses = array_get($route->action, 'uses'); if (!is_null($uses)) { //controller if (strpos($uses, "@") > -1) { list($name, $method) = explode("@", $uses); $pieces = explode(DS, $name); $className = $pieces[count($pieces) - 1] = ucfirst(array_last($pieces)) . "Controller"; $path = J_APPPATH . "controllers" . DS . trim(implode(DS, $pieces), DS) . EXT; if (Request::isLocal()) { if (!File::exists($path)) { trigger_error("File <b>" . $path . "</b> doesn't exists"); } } require_once $path; $class = new $className(); if (Request::isLocal()) { if (!method_exists($class, $method)) { trigger_error("Method <b>" . $method . "</b> doesn't exists on class <b>" . $className . "</b>"); } } return call_user_func_array(array(&$class, $method), $route->parameters); } else { $path = J_APPPATH . "views" . DS . $uses . EXT; if (Request::isLocal()) { if (!File::exists($path)) { trigger_error("File <b>" . $path . "</b> doesn't exists"); } } require $path; } } $handler = array_get($route->action, "handler"); //closure function /*$handler = array_first($route->action, function($key, $value) { return is_callable($value); });*/ if (!is_null($handler) && is_callable($handler)) { return call_user_func_array($handler, $route->parameters); } }
public static function restful($uri, $name) { $methods = array("restIndex#GET#/", "restGet#GET#/(:num)", "restNew#GET#/new", "restCreate#POST#/", "restUpdate#PUT#/(:num)", "restDelete#DELETE#/(:num)"); $uri = trim($uri, "/"); $pieces = explode(DS, $name); $className = $pieces[count($pieces) - 1] = ucfirst(array_last($pieces)) . "Controller"; $path = J_APPPATH . "controllers" . DS . trim(implode(DS, $pieces), DS) . EXT; if (Request::isLocal()) { if (!File::exists($path)) { trigger_error("File <b>" . $path . "</b> doesn't exists"); } } require $path; $instance = new $className(); foreach ($methods as $method) { $method = explode("#", $method); if (method_exists($instance, $method[0])) { Router::register($method[1], $uri . $method[2], $name . "@" . $method[0]); } } }
$allowed = true; break; } } if (!$allowed || count($pieces) == 0) { return Response::code(403); } $path = implode(DS, $pieces); if (!File::exists(J_PATH . $path) || is_dir(J_PATH . $path)) { return Response::code(404); } $im = new Image(J_PATH . $path); $im->resize((int) Request::get("width"), (int) Request::get("height"), Request::get("method", "fit"), Request::get("background", 0xffffff)); $im->header(); }); Router::register("*", "(:all)", function () { Response::code(404); if (Request::isLocal()) { echo "URI: " . URI::full() . "<br>\n"; echo "Path Info: " . Request::pathInfo() . "\n"; } return; }); if (URI::isManager()) { Structure::routes(); } Request::$route = Router::route(Request::method(), URI::current()); Event::fire(J_EVENT_RESPONSE_START); echo Request::$route->call(); Event::fire(J_EVENT_RESPONSE_END); //echo "<br><br>" . round(elapsed_time() * 1000000) / 1000 . "ms";