public function post_delete()
 {
     if (Input::has('file_id')) {
         $fid = Input::get('file_id');
         $file = CmsFile::find($fid);
         //CHECK IF FILE EXISTS
         if (!empty($file)) {
             $path = MEDIA_PATH($file->path);
             //DELETE MAIN FILE
             if (file_exists($path)) {
                 unlink($path);
             }
             //LOOP ALL THUMBS AND DELETE
             foreach (Config::get('cms::theme.thumb') as $option) {
                 $thumb = MEDIA_NAME($path, $option['suffix']);
                 if (file_exists($thumb)) {
                     unlink($thumb);
                 }
             }
             //DELETE FROM DB
             $file->pages()->delete();
             $file->filetexts()->delete();
             $file->delete();
             Notification::success(LL('cms::alert.delete_file_success', CMSLANG, array('file' => $file->name)), 1500);
             return Redirect::to_action('cms::file');
         } else {
             Notification::error(LL('cms::alert.delete_file_error', CMSLANG), 2500);
             return Redirect::to_action('cms::file');
         }
     } else {
         Notification::error(LL('cms::alert.delete_file_error', CMSLANG), 1500);
         return Redirect::to_action('cms::file');
     }
 }
$wm = (bool) $image->pivot->wm ? 'wm' : 'no';
$title = '';
$alt = '';
if (!empty($attr[$key]->filetexts)) {
    $titles[$key] = ($caption and strlen($attr[$key]->filetexts[0]->caption) > 0) ? '#' . Str::random(10, 'alpha') : '';
    $title = strlen($attr[$key]->filetexts[0]->title) > 0 ? ' title="' . $attr[$key]->filetexts[0]->title . '"' : '';
    $alt = strlen($attr[$key]->filetexts[0]->alt) > 0 ? $attr[$key]->filetexts[0]->alt : '';
} else {
    $titles[$key] = '';
}
// CHECK IF W AND H
$width = (is_null($w) and is_null($h)) ? $image->w : $w;
$height = (is_null($h) and is_null($w)) ? $image->h : $h;
// RESIZE IMAGE IF W AND H
if (is_null($w) and is_null($h)) {
    $img = (strlen($thumb) > 0 and $wm == 'no') ? MEDIA_NAME($image->name, $thumb, true) : URL::to_action('cms::image@resize', array($width, $height, $wm, $image->name));
} else {
    $img = URL::to_action('cms::image@thumb', array($width, $height, $wm, $image->name));
}
// CHECK LINK EXISTS
$is_link = strlen($image->pivot->url) > 0 ? true : false;
?>

			@if($is_link)
			<a href="{{SLUG($image->pivot->url)}}"{{$target}}{{$title}}>
			@endif

				{{HTML::image($img, $alt, array('title' => $titles[$key]))}}

			@if($is_link)
			</a>
 public function post_save_filename()
 {
     $auth = Auth::check();
     if ($auth) {
         $input = Input::get();
         //GRAB DATA
         if (!empty($input['file_id'])) {
             //GRAB DATA
             $file = CmsFile::find($input['file_id']);
             $fid = $file->id;
             $path = MEDIA_PATH($file->path);
             $name = $file->name;
             $ext = '.' . $file->ext;
             $filename = str_replace($ext, '', $name);
             $newname = $input['file_name'];
             //VALIDATION CHECK
             $rules = array('file_name' => 'required|alpha_dash|unique_filename:' . $file->ext . ',name');
             $messages = array('required' => LL('cms::validation.required', CMSLANG)->get(), 'unique_filename' => LL('cms::validation.unique_filename', CMSLANG)->get(), 'alpha_dash' => LL('cms::validation.alpha_dash', CMSLANG)->get());
             $validation = Validator::make($input, $rules, $messages);
             if ($validation->fails()) {
                 return json_encode($validation->errors);
             }
             //VALIDATION OK
             //RENAME DB
             //RENAME NAME
             $file->name = str_replace($filename, $newname, $name);
             //RENAME PATH
             $file->path = str_replace($filename, $newname, $file->path);
             //RENAME THUMB
             $file->thumb = str_replace($filename, $newname, $file->thumb);
             $file->save();
             //RENAME DISK
             //RENAME FILE
             if (file_exists($path)) {
                 rename($path, str_replace($filename, $newname, $path));
             }
             //LOOP ALL THUMBS AND RENAME
             foreach (Config::get('cms::theme.thumb') as $option) {
                 $thumb = MEDIA_NAME($path, $option['suffix']);
                 if (file_exists($thumb)) {
                     rename($thumb, str_replace($filename, $newname, $thumb));
                 }
             }
             $response = 'success';
             $msg = LL('cms::ajax_resp.filename_filename_success', CMSLANG)->get();
             $backurl = $input['back_url'];
         } else {
             $fid = null;
             $response = 'error';
             $msg = LL('cms::ajax_resp.filename_filename_error', CMSLANG)->get();
             $backurl = '#';
         }
     } else {
         $fid = null;
         $response = 'error';
         $msg = LL('cms::ajax_resp.filename_filename_error', CMSLANG)->get();
         $backurl = '#';
     }
     $data = array('auth' => $auth, 'cls' => 'file_id', 'id' => $fid, 'response' => $response, 'message' => $msg, 'backurl' => $backurl);
     return json_encode($data);
 }
 /**
  * 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;
 }
$alt = '';
if (!empty($attr[$key]->filetexts)) {
    $titles[$key] = ($caption and strlen($attr[$key]->filetexts[0]->caption) > 0) ? '#' . Str::random(10, 'alpha') : '';
    $title = strlen($attr[$key]->filetexts[0]->title) > 0 ? ' title="' . $attr[$key]->filetexts[0]->title . '"' : '';
    $alt = strlen($attr[$key]->filetexts[0]->alt) > 0 ? $attr[$key]->filetexts[0]->alt : '';
} else {
    $titles[$key] = '';
}
?>

			@if(strlen($image->pivot->url) > 0)
			<a href="{{SLUG($image->pivot->url)}}"{{$target}}{{$title}}>
			@endif

				<?php 
$img = $wm ? URL::to_action('cms::image@resize', array($image->w, $image->h, 'wm', $image->name)) : MEDIA_NAME($image->path, $thumb);
?>

				{{HTML::image($img, $alt, array('title' => $titles[$key]))}}

			@if(strlen($image->pivot->url) > 0)
			</a>
			@endif

		@endforeach

	</div>

	@if($caption and !empty($titles))

		@foreach($images as $key => $image)