Example #1
0
 public function missingMethod($args = null)
 {
     if (!$args) {
         return;
         // parent::missingMethod($args);
     }
     $modelClass = \Devhook::getClassByKey($args[0]);
     $this->model = new $modelClass();
     $action = ucfirst(isset($args[1]) ? $args[1] : 'List');
     $methodAction = strtolower($_SERVER['REQUEST_METHOD']) . $action;
     $anyAction = 'any' . $action;
     $args = array_splice($args, 2);
     $modelActions = $this->model->getModelActions();
     $this->link = $modelActions['list']['link'];
     \AdminUI::menu('navbar')->active('data');
     foreach ($modelActions as $key => $act) {
         $menuItem = \AdminUI::menu('actions')->add($act['link'], $act['title']);
         if (!empty($act['icon'])) {
             $menuItem->icon($act['icon']);
         }
     }
     return call_user_func_array(array($this, $methodAction), $args);
     if (method_exists($this, $methodAction)) {
         return call_user_func_array(array($this, $methodAction), $args);
     } elseif (method_exists($this, $anyAction)) {
         return call_user_func_array(array($this, $anyAction), $args);
     }
     return parent::missingMethod($args);
 }
 public function getEnabled($modelKey, $id, $enabled = 1)
 {
     $modelClass = \Devhook::getClassByKey($modelKey);
     $model = $modelClass::find($id);
     $model->enabled = (int) (bool) $enabled;
     $model->forceSave();
     return Redirect::back();
 }
 public function register()
 {
     $this->app['devhook'] = $this->app->share(function ($app) {
         return Devhook::get_instance();
     });
     $this->app['adminUI'] = $this->app->share(function ($app) {
         return AdminUI::get_instance();
     });
 }
Example #4
0
 public function missingMethod($args)
 {
     if (count($args) < 3) {
         return parent::missingMethod($args);
     }
     if ($args[0] == 'force') {
         array_shift($args);
     }
     $modelKeyword = $args[0];
     $modelClass = \Devhook::getClassByKey($modelKeyword);
     $id = $args[1];
     $file = $args[2];
     $parts = explode('-', $file);
     if (count($parts) == 3) {
         list($field, $sizeKey, $file) = $parts;
         @(list($imageId, $ext) = explode('.', $file));
     } else {
         $imageId = false;
         @(list($field, $file) = $parts);
         @(list($sizeKey, $ext) = explode('.', $file));
     }
     if (!$field || !$sizeKey || $ext != 'jpg') {
         return parent::missingMethod($args);
     }
     $model = $modelClass::find($id);
     if (!$model || !$model->{$field}) {
         return parent::missingMethod($args);
     }
     // $fileExt = pathinfo($model->$field, PATHINFO_EXTENSION);
     $fields = (array) $model->getFields();
     $modelField = isset($fields[$field]) ? $fields[$field] : false;
     if (!$modelField || empty($modelField->type)) {
         return parent::missingMethod($args);
     }
     $imageTypes = array('image');
     $type = $modelField->type;
     $sizes = (array) $modelField->settings('sizes');
     $imageAdminThumb = Config::get('devhook.imageAdminThumb');
     if (!in_array($type, $imageTypes) || empty($sizes[$sizeKey])) {
         return parent::missingMethod($args);
     }
     $watermark = $modelField->settings('watermark');
     $size = $sizes[$sizeKey];
     $width = $size[0];
     $hegiht = $size[1];
     $crop = isset($size[2]) ? $size[2] : false;
     $quality = isset($size[3]) ? $size[3] : 95;
     if ($imageId) {
         $imageFile = \Image::where('imageable_type', $modelKeyword)->where('imageable_id', $id)->find($imageId);
         if (!$imageFile) {
             return parent::missingMethod($args);
         }
         $imageFile = $imageFile->path;
     } else {
         $imageFile = $model->{$field};
     }
     ini_set('memory_limit', '200M');
     $image = new IMG(public_path($imageFile));
     if ($crop) {
         $image->grab($width, $hegiht);
     } else {
         $image->resize($width, $hegiht, true);
     }
     if ($watermark) {
         if (!$watermark['sizes'] || in_array($sizeKey, $watermark['sizes'])) {
             $image->insert($watermark['image'], $watermark['offset'][0], $watermark['offset'][1], $watermark['position']);
         }
     }
     $tmpFile = public_path($model->{$field}) . '.tmp_' . uniqid();
     $newFile = public_path(Config::get('devhook.imageRoute') . '/' . implode('/', $args));
     $newPath = dirname($newFile);
     if (!File::exists($newPath)) {
         File::makeDirectory($newPath, 0777, true);
     }
     $image->save($newFile, $quality);
     $img = $image->encode($ext, $quality);
     $response = Response::make($img, 200);
     $response->header('Content-Type', 'image/jpeg');
     return $response;
 }