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');
     }
 }
 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);
 }