function call(&$env) { if ($env["PATH_INFO"] == "/") { return array(200, array("Content-Type" => "text/html"), array("Welcome Home")); } elseif (preg_match("/^\\/about\\/?/i", $env["PATH_INFO"])) { return array(200, array("Content-Type" => "text/html"), array("Rack-style middleware is cool.")); } return Rack::not_found(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $key = Input::get('key'); // $locations = \Rack::get(); for ($i = 0; $i < count($locations); $i++) { $locations[$i]->extId = $locations[$i]->_id; unset($locations[$i]->_id); unset($locations[$i]->_token); unset($locations[$i]->thumbnail_url); unset($locations[$i]->large_url); unset($locations[$i]->medium_url); unset($locations[$i]->full_url); unset($locations[$i]->delete_type); unset($locations[$i]->delete_url); unset($locations[$i]->filename); unset($locations[$i]->filesize); unset($locations[$i]->temp_dir); unset($locations[$i]->filetype); unset($locations[$i]->is_image); unset($locations[$i]->is_audio); unset($locations[$i]->is_video); unset($locations[$i]->fileurl); unset($locations[$i]->file_id); unset($locations[$i]->caption); unset($locations[$i]->files); unset($locations[$i]->medium_portrait_url); if (isset($locations[$i]->defaultpictures)) { $dp = $locations[$i]->defaultpictures; unset($dp['delete_type']); unset($dp['delete_url']); unset($dp['temp_dir']); foreach ($dp as $k => $v) { $name = 'picture' . str_replace(' ', '', ucwords(str_replace('_', ' ', $k))); $locations[$i]->{$name} = $v; } unset($locations[$i]->defaultpictures); } else { $locations[$i]->pictureThumbnailUrl = ''; $locations[$i]->pictureLargeUrl = ''; $locations[$i]->pictureMediumUrl = ''; $locations[$i]->pictureFullUrl = ''; $locations[$i]->pictureBrchead = ''; $locations[$i]->pictureBrc1 = ''; $locations[$i]->pictureBrc2 = ''; $locations[$i]->pictureBrc3 = ''; } $locations[$i]->createdDate = date('Y-m-d H:i:s', $locations[$i]->createdDate->sec); $locations[$i]->lastUpdate = date('Y-m-d H:i:s', $locations[$i]->lastUpdate->sec); } $actor = $key; \Event::fire('log.api', array($this->controller_name, 'get', $actor, 'rack list')); return $locations; }
/** * Sólo borro la imagen cuando nadie más la utiliza */ public function DELETE($physical = true) { if (intval($this->getCounter()) == 1) { $image_id = $this->ID(); parent::DELETE($physical = true); Rack::Remove('img', md5($image_id)); // TODO: eliminar imagenes de la cache } else { // Decremento el contador $this->_setCounter($this->getCounter() - 1); } }
/** * Para insertar un nuevo registro, debo pasar la ruta de * un archivo (puede ser de un archivo local o uno remoto con http://...) */ public static function INSERT($file_path, $mime) { $hash = md5_file($file_path); $list = File::SELECT("Hash='" . Database::escape($hash) . "'"); if (count($list)) { $file = $list[0]; $file->_setCounter($file->getCounter() + 1); } else { $file = parent::INSERT(); $file->_setMime($mime); $file->_setHash($hash); $file->_setSize(filesize($file_path)); $file->_setCounter(1); $file->setUser(Session::getUser()); $file->setTimestamp(time()); Rack::Write('file', md5($file->ID()), $file_path); $file->updateSearchIndex(); } return $file; }
<?php $url =& ControllerPhp::$url; if (count($url) == 1) { $file = File::ROW($url[0]); array_shift($url); if ($file != null) { $path = Rack::Path('file', md5($file->ID())); if (file_exists($path)) { header("Content-type: " . $file->getMime()); header('Content-Disposition: attachment; filename="' . $file->getName() . '"'); header("Content-Length: " . filesize($path)); readfile($path); } } }
public function getPrintlabel($sessionname, $printparam, $format = 'html') { $pr = explode(':', $printparam); //2:150:250:300:8:10:12:barcode:undefined:undefined $columns = $pr[0]; $resolution = $pr[1]; $cell_width = $pr[2]; $cell_height = $pr[3]; $margin_right = $pr[4]; $margin_bottom = $pr[5]; $font_size = $pr[6]; $code_type = $pr[7]; $left_offset = $pr[8]; $top_offset = $pr[9]; $session = Printsession::find($sessionname)->toArray(); $labels = Rack::whereIn('_id', $session)->get()->toArray(); $skus = array(); foreach ($labels as $l) { $skus[] = $l['SKU']; } $skus = array_unique($skus); $products = Rack::whereIn('SKU', $skus)->get()->toArray(); $plist = array(); foreach ($products as $product) { $plist[$product['SKU']] = $product; } return View::make('rack.printlabel')->with('columns', $columns)->with('resolution', $resolution)->with('cell_width', $cell_width)->with('cell_height', $cell_height)->with('margin_right', $margin_right)->with('margin_bottom', $margin_bottom)->with('font_size', $font_size)->with('code_type', $code_type)->with('left_offset', $left_offset)->with('top_offset', $top_offset)->with('products', $plist)->with('labels', $labels); }
<?php $id = Router::$parameters['{id}']; $image = Image::ROW($id); if (null == $image) { exit; } $parts = Router::$parts; if (0 == count($parts)) { $path = Rack::Path('img', md5($image->getId())); } elseif (1 == count($parts)) { $transformation = $parts[0]; $hash = md5(Router::$url); $path = Rack::Path('img.cache', $hash); if (!file_exists($path)) { Rack::Make('img.cache', $hash); $prim = Prim::transform($image); $prim->setRules($transformation); $prim->saveTo($path); } } else { exit; } header("Expires: " . date("r", time() + 9999999)); header("Content-type: " . $image->getMime()); header("Content-Length: " . filesize($path)); readfile($path);
public static function getRackDetail($id) { $c = Rack::find($id); return $c; }
private function __construct(&$image) { $this->_image =& $image; $this->_path = Rack::Path('img', md5($image->ID())); }
public static function run() { // build ENV self::$env =& $_SERVER; if (strstr($_SERVER['REQUEST_URI'], '?')) { self::$env["PATH_INFO"] = substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], '?')); } else { self::$env["PATH_INFO"] = $_SERVER['REQUEST_URI']; } self::$env["request.vars"] =& $_REQUEST; self::$env["request.get"] =& $_GET; self::$env["request.post"] =& $_POST; self::$env["request.files"] =& $_FILES; self::$env["request.method"] =& $_SERVER["REQUEST_METHOD"]; self::$env["cookies"] =& $_COOKIE; // construct middlewares self::$constructed = true; $middleware = array_reverse(self::$middleware); $previous = null; foreach ($middleware as $key => $value) { self::$middleware[$key] = new $key($previous); $previous =& self::$middleware[$key]; } // call the middleware stack reset(self::$middleware); $first = current(array_keys(self::$middleware)); list($status, $headers, $body) = self::$middleware[$first]->call(self::$env); // send headers header(self::$env["SERVER_PROTOCOL"] . " " . $status); foreach ($headers as $key => $value) { header($key . ": " . $value); } // output any buffered content from middlewares $buffer = ob_get_contents(); ob_end_clean(); if (!empty($buffer)) { echo $buffer; } // output body if (is_array($body)) { echo implode("", $body); } else { echo $body; } }
private function rackId($rackName, $locationId, $locationName) { $rack = Rack::where('SKU', $rackName)->first(); if ($rack) { return $rack->_id; } else { $rackdata = array('SKU' => $rackName, 'createdDate' => new MongoDate(), 'defaultpic' => '', 'defaultpictures' => array(), 'files' => array(), 'itemDescription' => 'New Rack - ' . $rackName, 'lastUpdate' => new MongoDate(), 'locationId' => $locationId, 'locationName' => $locationName, 'status' => 'active', 'tagArray' => array(), 'tags' => ''); $rackId = Rack::insertGetId($rackdata); return $rackId; } }
<?php define("ROOT", dirname(dirname(__FILE__))); require ROOT . "/lib/rack.php"; // add some middlewares Rack::add("Format", ROOT . "/app/format.php"); Rack::add("App", ROOT . "/app/app.php"); // insert the Api middleware before App Rack::insert_before("App", "Api", ROOT . "/app/api.php"); Rack::run();