public function get_edit($id) { //SORTING Asset::container('footer')->add('sortable', 'bundles/cms/js/jquery.sortable.js', 'jquery'); Asset::container('footer')->add('serialize', 'bundles/cms/js/jquery.serializetree.js', 'sortable'); //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'); //DATETIME PICKER Asset::container('header')->add('jqueryuicss', 'bundles/cms/css/jquery.ui.css', 'main'); if (LANG !== 'en') { Asset::container('footer')->add('local', 'bundles/cms/js/i18n/jquery.ui.datepicker-' . LANG . '.js', 'jquery'); } Asset::container('footer')->add('datepicker', 'bundles/cms/js/jquery.datepicker.js', 'local'); //LOAD JS LIBS Asset::container('footer')->add('form', 'bundles/cms/js/jquery.form.js', 'jquery'); Asset::container('footer')->add('banner', 'bundles/cms/js/sections/banner_edit.js', 'cms'); $this->layout->header_data = array('title' => LL('cms::title.banner_edit', CMSLANG)); $this->layout->top_data = array('search' => false); //GET BANNER DATA $banner = CmsBanner::with(array('files'))->find($id); //GET FILE DATA $files = CmsFile::where_is_image(1)->where_is_valid(1)->order_by('name', 'asc')->order_by('id', 'asc')->paginate(Config::get('cms::settings.pag')); $this->layout->content = View::make('cms::interface.pages.banner_new_edit')->with('title', LL('cms::title.banner_edit', CMSLANG))->with('banner_id', $id)->with('banner_lang', $banner->lang)->with('banner_name', $banner->name)->with('files', $files)->with('files_select', $banner->files); }
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); } } }
/** * Size of media based on Db * * @param string $path * @return int */ public static function mediasize($image = 1, $type = '') { if (CACHE) { $size = Cache::remember('size_' . $image, function () use($image) { $sum = CmsFile::where_is_image($image)->sum('size'); return $sum; }, 60); } else { $size = CmsFile::where_is_image($image)->sum('size'); } if (empty($type)) { return $size; } return MEDIA_SIZE($size, $type); }
public function get_edit($id) { //SORTING Asset::container('footer')->add('sortable', 'bundles/cms/js/jquery.sortable.js', 'jquery'); Asset::container('footer')->add('serialize', 'bundles/cms/js/jquery.serializetree.js', 'sortable'); //LOAD JS LIBS Asset::container('footer')->add('form', 'bundles/cms/js/jquery.form.js', 'jquery'); Asset::container('footer')->add('files', 'bundles/cms/js/sections/download_edit.js', 'cms'); $this->layout->header_data = array('title' => LL('cms::title.download_edit', CMSLANG)); $this->layout->top_data = array('search' => false); //GET DOWNLOAD DATA $download = CmsDownload::with(array('files'))->find($id); //GET FILE DATA $files = CmsFile::where_is_image(0)->where_is_valid(1)->order_by('name', 'asc')->order_by('id', 'asc')->paginate(Config::get('cms::settings.pag')); $this->layout->content = View::make('cms::interface.pages.download_new_edit')->with('title', LL('cms::title.download_edit', CMSLANG))->with('download_id', $id)->with('download_name', $download->name)->with('files', $files)->with('files_select', $download->files); }
public function get_edit($id) { //SORTING Asset::container('footer')->add('sortable', 'bundles/cms/js/jquery.sortable.js', 'jquery'); Asset::container('footer')->add('serialize', 'bundles/cms/js/jquery.serializetree.js', 'sortable'); //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('form', 'bundles/cms/js/jquery.form.js', 'jquery'); Asset::container('footer')->add('files', 'bundles/cms/js/sections/gallery_edit.js', 'cms'); $this->layout->header_data = array('title' => LL('cms::title.gallery_edit', CMSLANG)); $this->layout->top_data = array('search' => false); //GET GALLERY DATA $gallery = CmsGallery::with(array('files'))->find($id); //GET FILE DATA $files = CmsFile::where_is_image(1)->where_is_valid(1)->order_by('name', 'asc')->order_by('id', 'asc')->paginate(Config::get('cms::settings.pag')); $this->layout->content = View::make('cms::interface.pages.gallery_new_edit')->with('title', LL('cms::title.gallery_edit', CMSLANG))->with('gallery_id', $id)->with('gallery_name', $gallery->name)->with('gallery_thumb', $gallery->thumb)->with('gallery_thumbs', CmsGallery::select_thumb())->with('files', $files)->with('files_select', $gallery->files); }
/** * Special conversion function - takes the details in the old cms switches it over the the new cms **/ public function port_ids() { $file = new CmsFile(); $files = $file->find_all(); foreach ($files as $file) { $new = new WildfireFile(); $s_path = rtrim(str_replace("public/", "", strrchr($file->path, "public/files")), "/"); $new_file = $new->filter("filename = '{$file->filename}' AND rpath LIKE '%{$s_path}%'")->first(); if ($new_file->id) { $new_file->oldid = $file->id; $new_file->description = $file->caption; $new_file->save(); } } exit; }
Validator::register('unique_element_page', function ($attribute, $value, $parameters) { //CHECK UNIQUENESS OF ELEMENT NAME IN A PAGE $page_id = $parameters[0]; $element_id = $parameters[1]; if (isset($parameters[2])) { $attribute = $parameters[2]; } $elements = CmsPage::find($page_id)->elements()->where('cmselement_id', '<>', $element_id)->where($attribute, '=', $value)->count(); return $elements == 0; }); Validator::register('unique_file', function ($attribute, $value, $parameters) { //CHECK UNIQUENESS OF FILE NAME ON DISK $file_name = $parameters[0]; $path = $parameters[1]; // CHECK DB NAME $query = CmsFile::where_name($file_name); return !file_exists(path('public') . $path . $file_name) and $query->count() == 0; }); Validator::register('unique_filename', function ($attribute, $value, $parameters) { //CHECK UNIQUENESS OF FILE NAME $ext = $parameters[0]; if (isset($parameters[1])) { $attribute = $parameters[1]; } $query = DB::table('files')->where($attribute, '=', $value . '.' . $ext); return $query->count() == 0; }); Validator::register('valid_datetime', function ($attribute, $value, $parameters) { //match the format of the date if (!empty($value)) { $d = DateTime::createFromFormat(GET_DATETIME(), $value);
public function post_save_download() { $auth = Auth::check(); if ($auth and is_numeric(AUTHORID)) { $input = Input::get(); //GRAB DATA $download = new CmsDownload(); if (!empty($input['download_id'])) { $download = CmsDownload::find($input['download_id']); } //VALIDATION CHECK $rules = array('download_name' => 'required|alpha_dash|between:2,20|unique:downloads,name,' . $input['download_id']); $messages = array('required' => LL('cms::validation.required', CMSLANG)->get(), 'between' => LL('cms::validation.between.string', CMSLANG)->get(), 'unique' => LL('cms::validation.unique', 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); } $download->name = strtolower($input['download_name']); $download->save(); //DELETE CACHE if (CACHE) { Cache::forget('file_list_' . strtolower($input['download_name'])); } $did = $download->id; // Empty template $template = ''; if (Input::get('file_id') !== '') { $files = Input::get('file_id'); if (is_array($files)) { foreach ($files as $fid) { $check = DB::table('files_downloads')->where_cmsfile_id($fid)->where_cmsdownload_id($did)->first(); if (empty($check)) { $download->files()->attach($fid, array('order_id' => Config::get('cms::settings.order'))); } $img = CmsFile::find($fid); // Template returned $template .= '<li id="' . $did . '_' . $fid . '" class="span1">'; $template .= '<a class="thumbnail" rel="tooltip" data-original-title="' . $img->name . '" href="' . BASE . $img->path . '">'; $template .= '<img src="' . BASE . $img->thumb . '" />'; $template .= '</a>'; $template .= '</li>'; } //DELETE NOT IN DB::table('files_downloads')->where_cmsdownload_id($did)->where_not_in('cmsfile_id', $files)->delete(); } $response = 'success'; $msg = LL('cms::ajax_resp.download_save_success', CMSLANG)->get(); $backurl = $input['back_url']; // Inject container $inject = 'ul.sortable'; $detach = true; } else { //DELETE ALL DOWNLOAD_ID DB::table('files_downloads')->where_cmsdownload_id($did)->delete(); $response = 'success'; $msg = LL('cms::ajax_resp.download_save_success', CMSLANG)->get(); $backurl = $input['back_url']; $template = ''; $inject = ''; $detach = true; } } else { $response = 'error'; $msg = LL('cms::ajax_resp.download_save_error', CMSLANG)->get(); $backurl = '#'; $template = ''; $inject = ''; $detach = true; } $data = array('auth' => $auth, 'cls' => 'download_id', 'id' => $did, 'response' => $response, 'message' => $msg, 'backurl' => $backurl, 'detach' => $detach, 'inject' => $inject, 'template' => $template); return json_encode($data); }
function page ($path, $context = array()) { $cms_page = self::get_page($path); $slug = $cms_page->slug; $pk_lookup = array('parent' => $cms_page->get_pk()); Frix::model('cms', 'CmsFile'); Frix::model('cms', 'CmsImage'); Frix::model('cms', 'CmsVideo'); $context += array( 'cms_page' => $cms_page, 'cms_files' => CmsFile::meta()->all($pk_lookup), 'cms_images' => CmsImage::meta()->all($pk_lookup), 'cms_videos' => CmsVideo::meta()->all($pk_lookup), 'cms_pages' => CmsPage::meta()->filter(array('visible' => True))->all($pk_lookup), 'body_attrs' => array('id' => $slug), ); $t = new Template('cms/custom/' . $slug, 'cms/page'); echo $t->render($context); }
function create_fields () { parent::create_fields(); $this->add_field( 'file', new ImageField('File', array('length' => 100, 'path' => 'cms/image')) ); }
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; }
public function post_upload_media() { $auth = Auth::check(); if ($auth) { $input = Input::all(); $file_name = strtolower(preg_replace('/[^\\w\\._]+/', '_', $input['file']['name'])); $file_name = str_replace('.jpeg', '.jpg', $file_name); $file_size = $input['file']['size']; $file_ext = strtolower(File::extension($file_name)); $page_id = $input['page_id']; $file_w = 0; $file_h = 0; //CREATE UPLOAD PATH $img_mimes = array('jpg', 'jpeg', 'gif', 'png'); if (in_array($file_ext, $img_mimes)) { $up = 'img/'; $is_image = true; } else { $up = $file_ext . '/'; $is_image = false; } //BUILD UPLOAD PATH $upload_path = Config::get('cms::settings.data') . $up; //VALIDATION CHECK $get_mimes = str_replace(' ', '', Config::get('cms::settings.mimes')); $get_max = Config::get('cms::settings.max_size') * 1024000; //1Mb // CHECK SIZE EXCEEDS $exceeds = (!$is_image and $file_size > $get_max) ? true : false; // CHECK SIZE IF IMAGE if ($is_image) { $rules = array('page_id' => 'required', 'file' => 'mimes:' . $get_mimes . '|max:' . $get_max . '|unique_file:' . $file_name . ',' . $upload_path); } else { $rules = array('page_id' => 'required', 'file' => 'mimes:' . $get_mimes . '|unique_file:' . $file_name . ',' . $upload_path); } $messages = array('required' => LL('cms::validation.page_not_set', CMSLANG)->get(), 'mimes' => LL('cms::validation.mimes_not_valid', CMSLANG)->get(), 'max' => LL('cms::validation.max_file_size', CMSLANG)->get(), 'unique_file' => LL('cms::validation.unique_file', CMSLANG)->get()); $validation = Validator::make($input, $rules, $messages); if ($validation->fails()) { //ERROR RESPONSE return json_encode(array('type' => 'label-important', 'message' => $validation->errors->first())); } else { //CREATE DIR IF NOT EXISTS if (!file_exists(path('public') . $upload_path)) { mkdir(path('public') . $upload_path); } $path = strtolower($upload_path . $file_name); // DO UPLOAD ONLY IF IS IMAGE OR LOWER THAN MAX SIZE ALLOWED $status_upload = !$exceeds ? move_uploaded_file($input['file']['tmp_name'], path('public') . $path) : true; // UPLOAD OK if ($status_upload) { //SET ICO PATH $thumb_path = '/bundles/cms/img/' . $file_ext . '_ico.png'; //GET IMG DIMENSIONS if ($is_image) { $img = getimagesize(path('public') . $path); $file_w = $img[0]; $file_h = $img[1]; //GENERATE THUMBS $thumb_path = CmsFile::create_thumb($upload_path, $file_name, $file_ext); } //SAVE TO DB $file_attr = array('name' => $file_name, 'ext' => $file_ext, 'size' => $file_size, 'w' => $file_w, 'h' => $file_h, 'path' => '/' . $path, 'thumb' => $thumb_path, 'is_image' => $is_image ? 1 : 0, 'is_valid' => 1); $file = new CmsFile($file_attr); $page = CmsPage::find($page_id); $page->files()->insert($file); // SUCCESS RESPONSE $resp = array('type' => $exceeds ? 'label-info' : 'label-success', 'message' => $exceeds ? LL('cms::ajax_resp.page_upload_ftp', CMSLANG, array('path' => $upload_path))->get() : LL('cms::ajax_resp.page_upload_success', CMSLANG)->get(), 'name' => $file_name, 'path' => '/' . $path, 'thumb_path' => $thumb_path, 'is_img' => $is_image ? true : false); return json_encode($resp); } else { // ERROR RESPONSE $resp = array('type' => 'label-important', 'message' => LL('cms::ajax_resp.page_upload_error', CMSLANG)->get()); return json_encode($resp); } } } }
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); } } }
public function post_save_banner() { $auth = Auth::check(); if ($auth) { $input = Input::get(); //GRAB DATA $banner = new CmsBanner(); if (!empty($input['banner_id'])) { $banner = CmsBanner::find($input['banner_id']); } //VALIDATION CHECK $rules = array('banner_name' => 'required|alpha_dash|between:2,20|unique_lang:' . $input['banner_id'] . ',' . $input['banner_lang'] . ',banners,name'); $messages = array('required' => LL('cms::validation.required', CMSLANG)->get(), 'between' => LL('cms::validation.between.string', CMSLANG)->get(), 'alpha_dash' => LL('cms::validation.alpha_dash', CMSLANG)->get(), 'unique_lang' => LL('cms::validation.unique', CMSLANG)->get()); $validation = Validator::make($input, $rules, $messages); if ($validation->fails()) { return json_encode($validation->errors); } $banner->name = strtolower($input['banner_name']); $banner->lang = $input['banner_lang']; $banner->save(); //DELETE CACHE if (CACHE) { Cache::forget('img_banner_' . strtolower($input['banner_name'])); } $bid = $banner->id; if (Input::get('file_id') !== '') { $files = Input::get('file_id'); $url = Input::get('url'); $date_off = Input::get('date_off'); $is_blank = Input::get('is_blank', array()); if (is_array($files)) { // Empty template $template = ''; foreach ($files as $key => $fid) { $check = DB::table('files_banners')->where_cmsfile_id($fid)->where_cmsbanner_id($bid)->first(); $blank = array_key_exists($key, $is_blank) ? 1 : 0; if (empty($date_off[$key])) { $off_date = dateTimeFuture(date("Y-m-d H:i:s"), 'P5Y'); } else { $off_date = date2Db(substr($date_off[$key], 0, 10)); } if (empty($check)) { $add_array = array('url' => $url[$key], 'date_off' => $off_date, 'is_blank' => $blank, 'order_id' => 1000000); $banner->files()->attach($fid, $add_array); } else { $update_array = array('url' => $url[$key], 'date_off' => $off_date, 'is_blank' => $blank); DB::table('files_banners')->where_cmsfile_id($fid)->where_cmsbanner_id($bid)->update($update_array); } $img = CmsFile::find($fid); // Template returned $template .= '<li id="' . $bid . '_' . $fid . '" class="span1">'; $template .= '<a class="thumbnail fancy" rel="tooltip" data-original-title="' . $img->name . '" href="' . BASE . $img->path . '">'; $template .= '<img src="' . BASE . $img->thumb . '" />'; $template .= '</a>'; $template .= '</li>'; } //DELETE NOT IN DB::table('files_banners')->where_cmsbanner_id($bid)->where_not_in('cmsfile_id', $files)->delete(); } $response = 'success'; $msg = LL('cms::ajax_resp.banner_save_success', CMSLANG)->get(); $backurl = $input['back_url']; // Inject container $inject = 'ul.sortable'; $detach = true; } else { //DELETE ALL GALLERY_ID DB::table('files_banners')->where_cmsbanner_id($bid)->delete(); $response = 'success'; $msg = LL('cms::ajax_resp.banner_save_success', CMSLANG)->get(); $backurl = $input['back_url']; $template = ''; $inject = ''; $detach = true; } } else { $response = 'error'; $msg = LL('cms::ajax_resp.banner_save_error', CMSLANG)->get(); $backurl = '#'; $template = ''; $inject = ''; $detach = true; } $data = array('auth' => $auth, 'cls' => 'banner_id', 'id' => $bid, 'response' => $response, 'message' => $msg, 'backurl' => $backurl, 'detach' => $detach, 'inject' => $inject, 'template' => $template); return json_encode($data); }
public function post_image_list_add() { if (Input::has('rel') and Input::has('lid') and Input::has('fid')) { $where = Input::get('rel'); $list_id = Input::get('lid'); $file_id = Input::get('fid'); $singular = Str::singular($where); $inser_arr = array('cmsfile_id' => $file_id, 'cms' . $singular . '_id' => $list_id, 'order_id' => Config::get('cms::settings.order')); DB::table('files_' . $where)->insert($inser_arr); $file = CmsFile::find($file_id); if ($where == 'galleries') { $data = array('file' => $file->to_array(), 'list_id' => $list_id, 'del_btn' => LL('cms::button.delete', CMSLANG)->get()); } else { if ($where == 'banners') { } } return json_encode($data); } return false; }