public function get_edit($id) { //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/files_edit.js', 'cms'); $this->layout->header_data = array('title' => LL('cms::title.file_edit', CMSLANG)); $this->layout->top_data = array('search' => false); //GET FILE DATA $file = CmsFile::with(array('pages', 'filetexts' => function ($query) { $query->where('lang', '=', LANG); }))->where_id($id)->first(); if (!empty($file->filetexts)) { foreach ($file->filetexts as $text) { $filetext_alt = !empty($text) ? $text->alt : ''; $filetext_title = !empty($text) ? $text->title : ''; $filetext_caption = !empty($text) ? $text->caption : ''; $filetext_label = !empty($text) ? $text->label : ''; } } else { $filetext_alt = ''; $filetext_title = ''; $filetext_caption = ''; $filetext_label = ''; } //GET PAGE DATA $data = CmsPage::with(array('files'))->where_parent_id(0)->order_by('lang', 'asc')->order_by('is_home', 'desc')->order_by('order_id', 'asc')->get(); $banners = CmsBanner::with(array('files'))->order_by('lang', 'asc')->get(); $galleries = CmsGallery::with(array('files'))->get(); $downloads = CmsDownload::with(array('files'))->get(); //GET SITEMAP ORDER $new_data = array(); foreach ($data as $obj) { $new_data[$obj->id] = $obj; $recursive = call_user_func_array('CmsPage::recursive_filespages', array($obj->id)); $new_data = $new_data + $recursive; } if (empty($new_data)) { $new_data = array(); } $this->layout->content = View::make('cms::interface.pages.file_edit')->with('title', LL('cms::title.file_edit', CMSLANG))->with('file_id', $id)->with('is_image', (bool) $file->is_image)->with('file_path', $file->path)->with('file_name', $file->name)->with('file_thumb', $file->thumb)->with('file_ext', $file->ext)->with('file_pages', $new_data)->with('langs', Config::get('cms::settings.langs'))->with('filetext_title', $filetext_title)->with('filetext_alt', $filetext_alt)->with('filetext_caption', $filetext_caption)->with('filetext_label', $filetext_label)->with('banners', $banners)->with('galleries', $galleries)->with('downloads', $downloads); }
public function post_delete() { if (Input::has('download_id')) { $did = Input::get('download_id'); $download = CmsDownload::find($did); //CHECK IF DOWNLOAD EXISTS if (!empty($download)) { //DELETE FROM DB $download->files()->delete(); $download->delete(); Notification::success(LL('cms::alert.delete_download_success', CMSLANG, array('download' => $download->name)), 1500); return Redirect::to_action('cms::download'); } else { Notification::error(LL('cms::alert.delete_download_error', CMSLANG), 2500); return Redirect::to_action('cms::download'); } } else { Notification::error(LL('cms::alert.delete_download_error', CMSLANG), 1500); return Redirect::to_action('cms::download'); } }
public function post_add_download() { $auth = Auth::check(); if ($auth and is_numeric(AUTHORID)) { if (Input::get('download_id') !== '') { $fid = Input::get('file_id'); $downloads = Input::get('download_id'); if (is_array($downloads)) { foreach ($downloads as $key => $gid) { $check = DB::table('files_downloads')->where_cmsfile_id($fid)->where_cmsdownload_id($gid)->count(); if ($check == 0) { $download = CmsDownload::find($gid); $add_array = array('order_id' => Config::get('cms::settings.order')); $download->files()->attach($fid, $add_array); } } //DELETE NOT IN DB::table('files_downloads')->where_cmsfile_id($fid)->where_not_in('cmsdownload_id', $downloads)->delete(); $response = 'success'; $msg = LL('cms::ajax_resp.download_save_success', CMSLANG)->get(); $backurl = Input::get('back_url'); } else { //DELETE ALL DB::table('files_downloads')->where_cmsfile_id($fid)->delete(); $response = 'success'; $msg = LL('cms::ajax_resp.download_save_success', CMSLANG)->get(); $backurl = '#'; } } else { $response = 'error'; $msg = LL('cms::ajax_resp.download_save_error', CMSLANG)->get(); $backurl = '#'; } } else { $response = 'error'; $msg = LL('cms::ajax_resp.download_save_error', CMSLANG)->get(); $backurl = '#'; } $data = array('auth' => $auth, 'cls' => 'file_id', 'id' => $fid, 'response' => $response, 'message' => $msg, 'backurl' => $backurl); return json_encode($data); }
public function post_save_download() { $auth = Auth::check(); if ($auth) { $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; if (Input::has('file_id')) { $files = Input::get('file_id'); if (is_array($files)) { // Empty template $template = ''; 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' => 1000000)); } $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); }
/** * DOWNLIST Marker - Show a list of download saved in Service / Download * * [$DOWNLIST[{ * "name":"<list name>", * "full":"false", => OPTIONAL (if true, recursive on DOWNLOAD marker) * "class":"<class>", => OPTIONAL (class of <ul>) * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers) * }]] * * @param array * @return string */ public static function DOWNLIST($vars = array()) { //Get variables from array $vars if (!empty($vars)) { extract($vars); } //Bind variables $_name = ''; if (isset($name) and !empty($name)) { $_name = $name; } $_full = false; if (isset($full) and !empty($full) and $full == 'true') { $_full = true; } $_class = null; if (isset($class) and !empty($class)) { $_class = $class; } $_tpl = 'downlist'; if (isset($tpl) and !empty($tpl)) { $_tpl = $tpl; } //Get DB information if (!empty($_name)) { //CACHE DATA if (CACHE) { $list = Cache::remember('file_list_' . $_name . '_' . SITE_LANG, function () use($_name) { return CmsDownload::with(array('files', 'files.filetexts' => function ($query) { $query->where('lang', '=', SITE_LANG); }))->where_name($_name)->first(); }, 1440); } else { $list = CmsDownload::with(array('files', 'files.filetexts' => function ($query) { $query->where('lang', '=', SITE_LANG); }))->where_name($_name)->first(); } //Load file lable and title if (!empty($list->files)) { $files = $list->files; } else { $files = array(); } } else { $files = array(); } $options = array('id' => $_name, 'class' => $_class); $view = LOAD_VIEW($_tpl); $view['files'] = $files; $view['full'] = $_full; $view['options'] = HTML::attributes($options); return $view; }