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 download($path, $name = null, $headers = array()) { if (!file_exists($path)) { return Response::code(404); } if (is_null($name)) { $name = basename($path); } $ext = File::extension($name); if ($ext == "") { $ext = File::extension($path); } $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => File::mime(File::extension($path)), 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => File::size($path), 'Content-Disposition' => 'attachment; filename="' . str_replace('"', '\\"', $name) . '"'), $headers); foreach ($headers as $k => $v) { header($k . ": " . $v); } readfile($path); }
public function save($value) { $flag = $this->module->flag; $path = File::formatDir($this->path); $destPath = static::storagePath() . File::formatDir($this->path); File::mkdir($destPath); if (!is_writable($destPath)) { Response::code(500); return Response::json(array("error" => true, "error_description" => "Directory '" . $destPath . "' is not writtable.")); } $files = json_decode(Session::get($this->sessionKey), true); if ($flag == "U" || $flag == "D") { $oldFiles = $this->module->orm->field($this->name); if (!is_array(@json_decode($oldFiles, true))) { $oldFiles = json_encode(array()); } $oldFiles = json_decode($oldFiles, true); if ($flag == "U") { //Delete files that are on our table but not on our session list foreach ($oldFiles as $oldFile) { $found = false; foreach ($files as $file) { if (!array_key_exists("_tmpName", $file) && current($oldFile) == current($file)) { $found = true; break; } } if (!$found) { foreach ($oldFile as $sample) { File::delete(static::storagePath() . $sample); } } } } else { if ($flag == "D") { //Delete all files foreach ($oldFiles as $oldFile) { foreach ($oldFile as $sample) { File::delete(static::storagePath() . $sample); } } if (count(File::lsdir($destPath)) == 0) { File::rmdir($destPath); } } } } if ($flag == "C" || $flag == "U") { //Copy tmp files to it's target place and save foreach ($files as $k => $file) { if (array_key_exists("_tmpName", $file)) { $samples = array(); $im = new Image(); $i = 0; $tmpPath = static::tmpPath() . $file["_tmpName"]; foreach ($this->samples as $k2 => $sample) { //if ($k2 == 0) //{ $im->load($tmpPath); //} if (!array_key_exists("width", $sample)) { $sample["width"] = 0; } if (!array_key_exists("height", $sample)) { $sample["height"] = 0; } if ($sample["width"] != 0 || $sample["height"] != 0) { $im->resize($sample["width"], $sample["height"], $sample["resizeMethod"], $sample["background"]); } if ($this->customFilters) { foreach ($this->customFilters as $filter) { call_user_func($filter, $im); } } $fileName = $file["_name"]; if ($sample["key"] != "original") { $fileName = File::removeExtension($file["_name"]) . "-" . $sample["key"] . "." . File::extension($file["_name"]); } $unique = static::unique($destPath . $fileName); $im->save($unique); $samples[$sample["key"]] = $path . File::fileName($unique); $samples["caption"] = array_key_exists('caption', $file) ? $file['caption'] : ""; $i++; } File::delete($tmpPath); $files[$k] = $samples; } } $this->module->orm->setField($this->name, json_encode($files)); } }
public function save($value) { $flag = $this->module->flag; $path = File::formatDir($this->path); $destPath = static::storagePath() . File::formatDir($this->path); File::mkdir($destPath); if (!is_writable($destPath)) { Response::code(500); return Response::json(array("error" => true, "error_description" => "Directory '" . $destPath . "' is not writtable.")); } $files = json_decode(Session::get($this->sessionKey), true); if ($flag == "U" || $flag == "D") { $oldFiles = $this->module->orm->field($this->name); if (!is_array(@json_decode($oldFiles, true))) { $oldFiles = json_encode(array()); } $oldFiles = json_decode($oldFiles, true); if ($flag == "U") { //Delete files that are on our table but not on our session list foreach ($oldFiles as $oldFile) { $found = false; foreach ($files as $file) { if (!array_key_exists("_tmpName", $file) && $oldFile["path"] == $file["path"]) { $found = true; break; } } if (!$found) { File::delete(static::storagePath() . $oldFile["path"]); } } } else { if ($flag == "D") { //Delete all files foreach ($oldFiles as $oldFile) { File::delete(static::storagePath() . $oldFile["path"]); } if (count(File::lsdir($destPath)) == 0) { File::rmdir($destPath); } } } } if ($flag == "C" || $flag == "U") { //Copy tmp files to it's target place and save foreach ($files as $k => $file) { if (array_key_exists("_tmpName", $file)) { $unique = static::unique($destPath . $file["_name"]); File::move(static::tmpPath() . $file["_tmpName"], $unique); $files[$k] = array("path" => $path . File::fileName($unique), "caption" => array_key_exists('caption', $file) ? $file['caption'] : ""); } } $this->module->orm->setField($this->name, json_encode($files)); } }
$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";
public static function error($code, $description) { Response::code($code); return Response::json(array("error" => true, "error_description" => $description)); }