public function get_edit($id)
 {
     //LOAD JS LIBS
     Asset::container('footer')->add('form', 'bundles/cms/js/jquery.form.js', 'jquery');
     Asset::container('footer')->add('count', 'bundles/cms/js/jquery.charcount.js', 'jquery');
     Asset::container('footer')->add('elastic', 'bundles/cms/js/jquery.elastic.js', 'jquery');
     Asset::container('footer')->add('slug', 'bundles/cms/js/jquery.stringtoslug.js', 'jquery');
     Asset::container('footer')->add('ckcms', 'bundles/cms/js/ck.cms.js', 'jqadapter');
     //CKEDITOR
     if (IS('cms::settings.wysiwyg', 'ckeditor')) {
         Asset::container('footer')->add('ckeditor', 'bundles/cms/ckeditor/ckeditor.js', 'form');
         Asset::container('footer')->add('jqadapter', 'bundles/cms/ckeditor/adapters/jquery.js', 'form');
         Asset::container('footer')->add('ckcms', 'bundles/cms/js/ck.cms.js', 'jqadapter');
     }
     //MARKITUP
     if (IS('cms::settings.wysiwyg', 'markitup')) {
         Asset::container('footer')->add('markitup', 'bundles/cms/markitup/jquery.markitup.js', 'form');
         Asset::container('footer')->add('sethtml', 'bundles/cms/markitup/sets/html/set.js', 'markitup');
         Asset::container('footer')->add('ckcms', 'bundles/cms/js/ck.cms.js', 'jqadapter');
         Asset::container('header')->add('csshtml', 'bundles/cms/markitup/sets/html/style.css');
         Asset::container('header')->add('cssmarkitup', 'bundles/cms/markitup/skins/markitup/style.css');
     }
     //PLUPLOAD
     Asset::container('footer')->add('plupload', 'bundles/cms/js/plupload.js', 'jquery');
     Asset::container('footer')->add('plupload_html4', 'bundles/cms/js/plupload.html4.js', 'plupload');
     Asset::container('footer')->add('plupload_html5', 'bundles/cms/js/plupload.html5.js', 'plupload');
     //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 AUTOSUGGEST LIBS
     Asset::container('header')->add('autosuggestcss', 'bundles/cms/css/autosuggest.css', 'main');
     Asset::container('footer')->add('autosuggest', 'bundles/cms/js/jquery.autosuggest.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');
     Asset::container('footer')->add('timepicker', 'bundles/cms/js/jquery.timepicker.js', 'datepicker');
     //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');
     Asset::container('footer')->add('pages', 'bundles/cms/js/sections/blogs_edit.js', 'cms');
     $this->layout->header_data = array('title' => LL('cms::title.blog_edit', CMSLANG));
     $this->layout->top_data = array('search' => false);
     if (!empty($id)) {
         //GET BLOG DATA
         $blog = CmsBlog::with(array('pages', 'blogrels'))->find($id);
         $pivot = DB::table('blogs_pages')->where_cmsblog_id($id)->where_is_default(1)->first();
         //FILES OF PAGE
         $files = CmsPage::find($pivot->cmspage_id)->files;
         if (!empty($blog)) {
             //GET EXTRA ID
             $extra_ids = Config::get('cms::settings.extra_id');
             //GET PAGE DATA
             $pagedata = CmsPage::where_lang($blog->lang)->where_parent_id(0)->where_extra_id(array_search('blogs', $extra_ids))->order_by('lang', 'asc')->order_by('is_home', 'desc')->order_by('order_id', 'asc')->get();
             $new_data = array();
             foreach ($pagedata as $obj) {
                 $new_data[$obj->id] = $obj;
                 $recursive = call_user_func_array('CmsPage::recursive_pages', array($obj->id));
                 $new_data = $new_data + $recursive;
             }
             //GET BLOG DATA
             $blogdata = CmsBlog::where_lang($blog->lang)->where('id', '<>', $id)->where_is_valid(1)->order_by('datetime_on', 'desc')->order_by('name', 'desc')->paginate(Config::get('cms::settings.pag'));
             if (empty($new_data)) {
                 $new_data = array();
             }
             $this->layout->content = View::make('cms::interface.pages.blog_new_edit')->with('role_fail', CmsRole::role_fail($pivot->cmspage_id))->with('title', LL('cms::title.blog_edit', CMSLANG))->with('blog_id', $id)->with('page_id', $pivot->cmspage_id)->with('blog_lang', $blog->lang)->with('blog_name', $blog->name)->with('blog_parent', CmsPage::select_page_slug($blog->lang, array_search('blogs', $extra_ids)))->with('blog_parent_selected', $pivot->cmspage_id)->with('blog_slug', substr($blog->slug, 1))->with('blog_parent_slug', CmsPage::get_page_slug($pivot->cmspage_id) . '/')->with('blog_zones', CmsElement::select_zone($pivot->cmspage_id))->with('blog_zone_selected', $blog->zone)->with('blog_is_valid', (bool) $blog->is_valid)->with('blog_date_on', $blog->get_datetime_on())->with('blog_date_off', $blog->get_datetime_off())->with('blog_title', $blog->title)->with('blog_preview', $blog->preview)->with('blog_text', $blog->text)->with('blog_keyw', $blog->keyw)->with('blog_descr', $blog->descr)->with('blog_tags', '')->with('files', $files)->with('pagedata', $new_data)->with('pagerels', $blog->pages)->with('blogdata', $blogdata)->with('blogrels', $blog->blogrels);
         }
     }
 }
 public function post_clone_element()
 {
     if (Input::has('page_id') and Input::has('element_id') and Input::has('newpage_id')) {
         $pid = Input::get('page_id');
         $nid = Input::get('newpage_id');
         $eid = Input::get('element_id');
         $now = date('Y-m-d H:i:s');
         if (Input::has('to_clone')) {
             //CREATE NEW ELEMENT
             //GET ELEMENT MODEL
             $element = CmsElement::find($eid);
             $new_element_attr = array('author_id' => AUTHORID, 'name' => $element->name, 'label' => $element->label, 'text' => $element->text, 'zone' => $element->zone, 'lang' => LANG, 'is_valid' => 0);
             $new_element = new CmsElement($new_element_attr);
             $page = CmsPage::find($nid);
             $page->elements()->insert($new_element);
         } else {
             //GET ELEMENT MODEL
             $element = CmsElement::find($eid);
             $clone_array = array('cmselement_id' => $eid, 'cmspage_id' => $nid, 'created_at' => $now, 'updated_at' => $now);
             DB::table('elements_pages')->insert($clone_array);
         }
         Notification::success(LL('cms::alert.clone_element_success', CMSLANG, array('element' => $element->name)), 1500);
         return Redirect::to_action('cms::page', array(LANG));
     } else {
         Notification::error(LL('cms::alert.clone_element_error', CMSLANG), 1500);
         return Redirect::to_action('cms::page', array(LANG));
     }
 }
 /**
  * ELEMENT Marker - Replicates element content
  *
  * [$CONTENT[{
  *	"el":"<elem's id>"
  * }]]
  *
  * @param  array
  * @return string
  */
 public static function ELEMENT($vars = array())
 {
     //Get variables from array $vars
     if (!empty($vars)) {
         extract($vars);
     }
     //Bind variables
     $_el = '';
     if (isset($el) and !empty($el)) {
         $_el = $el;
     }
     if (!empty($_el)) {
         //CACHE DATA
         if (CACHE) {
             $query = Cache::remember('page_element_' . $_el, function () use($_el) {
                 return $menu = CmsElement::find($_el);
             }, 1440);
         } else {
             $query = CmsElement::find($_el);
         }
         $txt = !empty($query) ? $query->text : '';
         return strlen($txt) > 0 ? self::decode($txt, array()) : $txt;
     }
 }
 public function post_order_element()
 {
     $order = Input::get('order');
     if (is_array($order)) {
         foreach ($order as $order_id => $item) {
             $order_id++;
             $p = explode("_", $item);
             $element = CmsElement::find($p[1]);
             $order = array('order_id' => $order_id);
             DB::table('elements_pages')->where_cmspage_id($p[0])->where_cmselement_id($p[1])->update($order);
         }
     }
     return true;
 }
 public function post_search()
 {
     if (Input::has('q') and Input::has('source')) {
         //GET q
         $q = Input::get('q');
         //GET page
         $p = Input::get('page', 1);
         // GET FROM WHERE
         if (Input::has('url')) {
             Session::put('URL', Input::get('url', SLUG_FULL));
         }
         $url = Session::get('URL', '/');
         //ITEMS PER PAGE
         $npp = Config::get('cms::theme.site_pag');
         //GET SOURCE WHERE TO SEARCH
         $source = Input::get('source');
         $sources = explode('-', $source);
         $results = array();
         //PAGES
         $tot = 0;
         if (is_numeric(array_search('pages', $sources))) {
             $elements = CmsElement::with(array('pages'))->where('text', 'LIKE', '%' . $q . '%')->where_lang(SITE_LANG)->where_is_valid(1)->get();
             foreach ($elements as $key => $element) {
                 foreach ($element->pages as $page) {
                     $title = strlen($page->title) > 0 ? $page->title : $page->name;
                     $results[$key + 1]['source'] = LL('cms::label.pages', SITE_LANG)->get();
                     $results[$key + 1]['title'] = $title;
                     $results[$key + 1]['slug'] = $page->slug;
                     $results[$key + 1]['descr'] = $page->descr;
                 }
                 $tot++;
             }
         }
         if (is_numeric(array_search('blogs', $sources))) {
             $blogs = CmsBlog::with(array('pages'))->where('name', 'LIKE', '%' . $q . '%')->or_where('preview', 'LIKE', '%' . $q . '%')->or_where('text', 'LIKE', '%' . $q . '%')->where_lang(SITE_LANG)->where_is_valid(1)->get();
             foreach ($blogs as $key => $blog) {
                 foreach ($blog->pages as $page) {
                     $title = $blog->name;
                     $results[$tot + $key + 1]['source'] = LL('cms::label.blogs', SITE_LANG)->get();
                     $results[$tot + $key + 1]['title'] = $title;
                     $results[$tot + $key + 1]['slug'] = $page->slug . $blog->slug;
                     $results[$tot + $key + 1]['descr'] = $page->descr;
                 }
                 $tot++;
             }
         }
         $unique_results = array_unique($results, SORT_REGULAR);
         $count_results = count($unique_results);
         $output = array_slice($unique_results, $npp * $p - $npp, $npp);
         $paginate = Paginator::make($output, $count_results, $npp);
         //GET SEARCH RESULTS VIEW
         $search_results = Config::get('cms::theme.search_results');
         //LOAD VIEW
         $view = View::make('cms::theme.' . THEME . '.partials.' . $search_results);
         $view['results'] = $paginate;
         $view['q'] = $q;
         $view['source'] = $source;
         //LOAD ZONE TO INJECT IN
         $search_zone = Config::get('cms::theme.search_zone');
         //SEARCH PAGE DETAILS
         $search_template = Config::get('cms::theme.search_template');
         $search_header = Config::get('cms::theme.search_header');
         $search_footer = Config::get('cms::theme.search_footer');
         $search_layout = Config::get('cms::theme.search_layout');
         // RENDER THE PAGE
         CmsRender::page($url, array('template' => $search_template, 'header' => $search_header, 'footer' => $search_footer, 'layout' => $search_layout, 'zone' => $search_zone, 'view' => $view));
     } else {
         return Redirect::home();
     }
 }
 public function post_search()
 {
     if (Input::has('q') and Input::has('source')) {
         //GET q
         $q = Input::get('q');
         //GET page
         $p = Input::get('page', 1);
         //ITEMS PER PAGE
         $npp = Config::get('cms::theme.site_pag');
         //GET SOURCE WHERE TO SEARCH
         $source = Input::get('source');
         $sources = explode('-', $source);
         $results = array();
         //PAGES
         $tot = 0;
         if (is_numeric(array_search('pages', $sources))) {
             $elements = CmsElement::with(array('pages'))->where('text', 'LIKE', '%' . $q . '%')->where_lang(SITE_LANG)->where_is_valid(1)->get();
             foreach ($elements as $key => $element) {
                 foreach ($element->pages as $page) {
                     $title = strlen($page->title) > 0 ? $page->title : $page->name;
                     $results[$key + 1]['source'] = LL('cms::label.pages', SITE_LANG)->get();
                     $results[$key + 1]['title'] = $title;
                     $results[$key + 1]['slug'] = $page->slug;
                     $results[$key + 1]['descr'] = $page->descr;
                 }
                 $tot++;
             }
         }
         if (is_numeric(array_search('blogs', $sources))) {
             $blogs = CmsBlog::with(array('pages'))->where('name', 'LIKE', '%' . $q . '%')->or_where('preview', 'LIKE', '%' . $q . '%')->or_where('text', 'LIKE', '%' . $q . '%')->where_lang(SITE_LANG)->where_is_valid(1)->get();
             foreach ($blogs as $key => $blog) {
                 foreach ($blog->pages as $page) {
                     $title = $blog->name;
                     $results[$tot + $key + 1]['source'] = LL('cms::label.blogs', SITE_LANG)->get();
                     $results[$tot + $key + 1]['title'] = $title;
                     $results[$tot + $key + 1]['slug'] = $page->slug . $blog->slug;
                     $results[$tot + $key + 1]['descr'] = $page->descr;
                 }
                 $tot++;
             }
         }
         $unique_results = array_unique($results, SORT_REGULAR);
         $count_results = count($unique_results);
         $output = array_slice($unique_results, $npp * $p - $npp, $npp);
         $paginate = Paginator::make($output, $count_results, $npp);
         //LOAD VIEW
         $view = View::make('cms::theme.' . THEME . '.partials.search_results');
         $view['results'] = $paginate;
         $view['q'] = $q;
         $view['source'] = $source;
         //LOAD LAYOUT
         $layout = View::make('cms::theme.' . THEME . '.layouts.' . Config::get('cms::theme.search_layout'));
         $_zone = Config::get('cms::theme.search_zone');
         $layout[$_zone] = $view;
         //LOAD TEMPLATE
         $html = View::make('cms::theme.' . THEME . '.templates.' . TEMPLATE)->nest('header', 'cms::theme.' . THEME . '.partials.header_default')->with('title', $q)->with('layout', $layout)->nest('footer', 'cms::theme.' . THEME . '.partials.footer_default');
         CmsRender::clean_code($html);
     } else {
         return Redirect::home();
     }
 }