public function action_search_file()
 {
     $auth = Auth::check();
     if ($auth and is_numeric(AUTHORID)) {
         //LOAD FANCYBOX LIBS
         Asset::container('header')->add('fancyboxcss', 'bundles/cms/css/fancybox.css', 'main');
         Asset::container('footer')->add('fancybox', 'bundles/cms/js/jquery.fancybox.js', 'jquery');
         //LOAD JS LIBS
         Asset::container('footer')->add('ias', 'bundles/cms/js/jquery.ias.js', 'jquery');
         Asset::container('footer')->add('files', 'bundles/cms/js/sections/files_list.js', 'cms');
         if (Input::has('q')) {
             $q = Input::get('q');
             $this->layout->header_data = array('title' => $q);
             $this->layout->top_data = array('search' => '/cms/file/search', 'q' => $q);
             //ALLOWED EXTENSIONS
             $ext_str = str_replace(' ', '', Config::get('cms::settings.mimes'));
             $extensions = explode(',', $ext_str);
             //GET PAGE DATA
             $data = CmsFile::where('name', 'LIKE', '%' . $q . '%')->or_where('ext', 'LIKE', '%' . $q . '%')->order_by('ext', 'asc')->order_by('size', 'desc')->order_by('name', 'asc')->paginate(Config::get('cms::settings.pag'));
             $this->layout->content = View::make('cms::interface.pages.file_list')->with('data', $data)->with('page', 0)->with('ext', '')->with('extensions_selected', array())->with('extensions', $extensions);
         } else {
             $this->layout->header_data = array('title' => LL('cms::title.files', CMSLANG));
             $this->layout->top_data = array('search' => '/cms/file/search', 'q' => '');
             //ALLOWED EXTENSIONS
             $ext_str = str_replace(' ', '', Config::get('cms::settings.mimes'));
             $extensions = explode(',', $ext_str);
             //GET DATA
             $data = CmsFile::with('pages')->order_by('ext', 'asc')->order_by('size', 'desc')->order_by('name', 'asc')->paginate(Config::get('cms::settings.pag'));
             $this->layout->content = View::make('cms::interface.pages.file_list')->with('data', $data)->with('page', 0)->with('ext', '')->with('extensions_selected', array())->with('extensions', $extensions);
         }
     }
 }
 public function post_popover_details()
 {
     $auth = Auth::check();
     if ($auth and is_numeric(AUTHORID)) {
         if (Input::has('id')) {
             $fid = Input::get('id');
             //CACHE DATA
             if (CACHE) {
                 $file = Cache::remember('file_' . $fid . '_details', function () use($fid) {
                     return CmsFile::with(array('pages'))->find($fid);
                 }, 60);
             } else {
                 $file = CmsFile::with(array('pages'))->find($fid);
             }
             return View::make('cms::interface.partials.file_details')->with('created_at', $file->created_date)->with('updated_at', $file->updated_date)->with('size', $file->size)->with('w', $file->w)->with('h', $file->h)->with('is_image', $file->is_image ? true : false)->with('pagerels', $file->pages);
         }
     }
 }
 /**
  * THUMB Marker - Show a pre-config or on-the-fly resized thumb image linked to original
  *
  * [$THUMB[{
  *	"file":"<filename>",
  *	"type":"<type of crop>"			=> (default: resize | available: resize || crop)
  *	"thumb":"<type of thumb>",		=> (default: thumb | available as mapped in theme.php thumb array)
  *	"path":"img_path | !img_path"	=> (point to full image path or $caption || $alt slug - default: img_path)
  *	"caption":"false"				=> (default: false)
  *	"w":"100",						=> OPTIONAL (overrides thumb)
  *	"h":"100",						=> OPTIONAL (overrides thumb)
  *	"x":"0",						=> OPTIONAL (if type crop, crop start x)
  *	"y":"0",						=> OPTIONAL (if type crop, crop start y)
  *	"wm":"true | false",			=> OPTIONAL
  *	"id":"<id>",					=> OPTIONAL (id of <a>)
  *	"class":"<class>",				=> OPTIONAL
  *	"tpl":"<tpl_name>"				=> OPTIONAL (in /partials/markers)
  * }]]
  *
  * @param  array
  * @return string
  */
 public static function THUMB($vars = array())
 {
     //Get variables from array $vars
     if (!empty($vars)) {
         extract($vars);
     }
     //Bind variables
     $_file = '';
     if (isset($file) and !empty($file)) {
         $_file = $file;
     }
     $_type = 'resize';
     if (isset($type) and !empty($type)) {
         $_type = $type;
     }
     $_thumb = 'thumb';
     if (isset($thumb) and !empty($thumb)) {
         $_thumb = $thumb;
     }
     $_path = 'img_path';
     if (isset($path) and !empty($path)) {
         $_path = $path;
     }
     $_caption = false;
     if (isset($caption) and !empty($caption) and $caption == 'true') {
         $_caption = true;
     }
     $_w = '';
     if (isset($w) and !empty($w)) {
         $_w = $w;
     }
     $_h = '';
     if (isset($h) and !empty($h)) {
         $_h = $h;
     }
     $_x = 0;
     if (isset($x) and !empty($x)) {
         $_x = $x;
     }
     $_y = 0;
     if (isset($y) and !empty($y)) {
         $_y = $y;
     }
     $_wm = 'no';
     if (isset($wm) and !empty($wm) and $wm == 'true') {
         $_wm = 'wm';
     }
     $_id = null;
     if (isset($id) and !empty($id)) {
         $_id = $id;
     }
     $_class = null;
     if (isset($class) and !empty($class)) {
         $_class = $class;
     }
     $_tpl = 'thumb';
     if (isset($tpl) and !empty($tpl)) {
         $_tpl = $tpl;
     }
     //Get DB information
     if (!empty($_file)) {
         //CACHE DATA
         if (CACHE) {
             $file = Cache::remember('img_' . MEDIA_NOPOINT($_file) . '_' . SITE_LANG, function () use($_file) {
                 return CmsFile::with(array('filetexts' => function ($query) {
                     $query->where('lang', '=', SITE_LANG);
                 }))->where_name($_file)->first();
             }, 1440);
         } else {
             $file = CmsFile::with(array('filetexts' => function ($query) {
                 $query->where('lang', '=', SITE_LANG);
             }))->where_name($_file)->first();
         }
         //Get img dimension
         if (!empty($file) and !empty($_type)) {
             if ($_path == 'img_path') {
                 //LOAD FANCYBOX LIBS
                 Asset::container('header')->add('fancyboxcss', 'bundles/cms/css/fancybox.css', 'site_css');
                 Asset::container('footer')->add('fancybox', 'bundles/cms/js/jquery.fancybox.js', 'jquery_lib');
                 Asset::container('footer')->add('thumb', 'js/markers/thumb.js', 'site_js');
             }
             if ($_type == 'resize') {
                 // GET W OR H
                 if (!empty($_w) or !empty($_h)) {
                     $_filename = $file->name;
                     $dim = MEDIA_DIM($file->w, $file->h, $_w, $_h);
                     $url = URL::to_action('cms::image@resize', array($dim['w'], $dim['h'], $_wm, $_filename));
                     // GET THUMB, DEFAULT THUMB IF NONE
                 } else {
                     $_filename = MEDIA_NAME($_file, Config::get('cms::theme.thumb.' . $_thumb . '.suffix'));
                     $dim['w'] = Config::get('cms::theme.thumb.' . $_thumb . '.width');
                     $dim['h'] = Config::get('cms::theme.thumb.' . $_thumb . '.height');
                     $url = MEDIA_NAME($file->path, Config::get('cms::theme.thumb.' . $_thumb . '.suffix'));
                 }
             }
             if ($_type == 'crop') {
                 $_filename = $file->name;
                 $dim = array('w' => $_w, 'h' => $_h);
                 $url = URL::to_action('cms::image@crop', array($_x, $_y, $_w, $_h, $_wm, $_filename));
             }
             $full_path = $file->path;
             // Apply watermark if required
             if ($_wm == 'wm') {
                 $full_path = URL::to_action('cms::image@resize', array($file->w, $file->h, $_wm, $file->name));
             }
         } else {
             $_filename = '';
             $dim['w'] = '';
             $dim['h'] = '';
         }
         //Load file alt and title
         if (!empty($file->filetexts)) {
             $title = $file->filetexts[0]->title;
             $alt = $file->filetexts[0]->alt;
             $caption = $file->filetexts[0]->caption;
         } else {
             $title = '';
             $alt = '';
             $caption = '';
         }
     } else {
         $full_path = '';
         $title = '';
         $alt = '';
         $caption = '';
         $url = '';
         $dim['w'] = '';
         $dim['h'] = '';
     }
     $img = HTML::image($url, $alt, array('id' => $_id, 'class' => $_class));
     $options = array('id' => $_id, 'class' => $_class, 'title' => $title);
     if ($_path == 'img_path') {
         $options['rel'] = 'fancybox';
     } else {
         $full_path = SLUG_FULL . '/' . Str::slug($alt != '' ? $alt : $caption);
     }
     $view = LOAD_VIEW($_tpl);
     $view['path'] = $full_path;
     $view['img'] = $img;
     $view['options'] = HTML::attributes($options);
     $view['caption'] = $_caption;
     $view['caption_text'] = $caption;
     return $view;
 }
 public function post_image_list()
 {
     $where = Input::get('where');
     $list_id = Input::get('lid');
     //GET FILE DATA
     $files = CmsFile::with(array($where => function ($query) use($where, $list_id) {
         $singular = Str::singular($where);
         $query->where('files_' . $where . '.cms' . $singular . '_id', '=', $list_id);
     }))->where_is_image(1)->order_by('name', 'asc')->get();
     return View::make('cms::interface.partials.image_list')->with('rel', $where)->with('lid', $list_id)->with('media', $files);
 }