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/menus_edit.js', 'cms');
     $this->layout->header_data = array('title' => LL('cms::title.menu_edit', CMSLANG));
     $this->layout->top_data = array('search' => false);
     //GET MENU DATA
     $menu = CmsMenu::find($id);
     //GET PAGE DATA
     $data = CmsPage::with(array('menus'))->where_lang($menu->lang)->where_parent_id(0)->order_by('lang', 'asc')->order_by('is_home', 'desc')->order_by('order_id', 'asc')->get();
     $new_data = array();
     foreach ($data as $obj) {
         $new_data[$obj->id] = $obj;
         $recursive = call_user_func_array('CmsPage::recursive_menuspages', array($obj->id));
         $new_data = $new_data + $recursive;
     }
     if (empty($new_data)) {
         $new_data = array();
     }
     //GET PAGES IN MENU
     $pages = CmsMenu::find($id)->pages;
     $this->layout->content = View::make('cms::interface.pages.menu_new_edit')->with('title', LL('cms::title.menu_edit', CMSLANG))->with('menu_id', $id)->with('menu_name', $menu->name)->with('menu_lang', $menu->lang)->with('menu_is_nested', (bool) $menu->is_nested)->with('menu_parent_start', CmsPage::select_top_slug($menu->lang, 0, true))->with('menu_parent_start_selected', $menu->parent_start)->with('pages', $pages)->with('menu_pages', $new_data);
 }
 public function get_sitemap($lang = LANG)
 {
     //GET PAGE DATA
     $data = CmsPage::with(array('files' => function ($query) {
         $query->where_is_image(1)->where_is_valid(1);
     }))->where_parent_id(0)->where_lang($lang)->order_by('is_home', 'desc')->order_by('slug', 'asc')->get();
     $new_data = array();
     foreach ($data as $value) {
         $new_data[$value->id] = $value;
     }
     foreach ($new_data as $page) {
         $recursive = call_user_func_array('CmsPage::recursive_site_sitemap', array($page->id));
         $new_data = array_insert($new_data, $page->id, $recursive);
     }
     $view = View::make('cms::theme.' . THEME . '.templates.sitemap')->with('encoding', '<?xml version="1.0" encoding="UTF-8" ?>')->with('base', Config::get('application.url'))->with('data', $new_data);
     $headers = array('Content-Type' => 'text/xml');
     return Response::make($view, 200, $headers);
 }
 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_popover_details()
 {
     $auth = Auth::check();
     if ($auth) {
         if (Input::has('id')) {
             $pid = Input::get('id');
             //CACHE DATA
             if (CACHE) {
                 $page = Cache::remember('page_' . $pid . '_details', function () use($pid) {
                     return CmsPage::with(array('user', 'pagerels', 'elements'))->find($pid);
                 }, 60);
             } else {
                 $page = CmsPage::with(array('user', 'pagerels', 'elements'))->find($pid);
             }
             return View::make('cms::interface.partials.page_details')->with('author', $page->user->username)->with('created_at', $page->created_date)->with('updated_at', $page->updated_date)->with('header', $page->header)->with('layout', $page->layout)->with('footer', $page->footer)->with('is_valid', (bool) $page->is_valid)->with('lang', $page->lang)->with('elements', $page->elements)->with('pagerels', $page->pagerels);
         }
     }
 }
 public function action_search_page()
 {
     $auth = Auth::check();
     if ($auth and is_numeric(AUTHORID)) {
         //LOAD JS LIBS
         Asset::container('footer')->add('ias', 'bundles/cms/js/jquery.ias.js', 'jquery');
         Asset::container('footer')->add('pages', 'bundles/cms/js/sections/pages_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/page/search', 'q' => $q);
             //GET PAGE DATA
             $data = CmsPage::with('user')->where_lang(LANG)->where('name', 'LIKE', '%' . $q . '%')->or_where('title', 'LIKE', '%' . $q . '%')->order_by('name', 'asc')->order_by('slug', 'asc')->order_by('title', 'asc')->paginate(Config::get('cms::settings.pag'));
             $this->layout->content = View::make('cms::interface.pages.page_list')->with('data', $data)->with('lang', '');
         } else {
             $this->layout->header_data = array('title' => LL('cms::title.pages', CMSLANG));
             $this->layout->top_data = array('search' => '/cms/page/search', 'q' => '');
             //GET ALL PAGE DATA
             $data = CmsPage::with('user')->where_lang(LANG)->order_by('order_id', 'asc')->order_by('updated_at', 'desc')->paginate(Config::get('cms::settings.pag'));
             $this->layout->content = View::make('cms::interface.pages.page_list')->with('data', $data)->with('lang', LANG);
         }
     }
 }
 /**
  * MENU_SUB Marker - Shows a submenu linked to sub elements
  *
  * [$MENU_SUB[{
  *	"zone":"<elem's zone>"	=> (default: 1)
  *	"id":"menu_sub"			=> OPTIONAL (menu id container | default: menu_sub)
  *	"class":"<class>",		=> OPTIONAL (default: menu_sub)
  *	"tpl":"menu_sub"		=> OPTIONAL (in /partials/markers)
  * }]]
  *
  * @param  array
  * @return string
  */
 public static function MENU_SUB($vars = array())
 {
     //Get variables from array $vars
     if (!empty($vars)) {
         extract($vars);
     }
     //Bind variables
     $_zone = 'ZONE1';
     if (isset($zone) and !empty($zone)) {
         $_zone = 'ZONE' . $zone;
     }
     $_id = 'menu_sub';
     if (isset($id) and !empty($id)) {
         $_id = $id;
     }
     $_class = 'menu_sub';
     if (isset($class) and !empty($class)) {
         $_class = $class;
     }
     $_tpl = 'menu_sub';
     if (isset($tpl) and !empty($tpl)) {
         $_tpl = $tpl;
     }
     //CACHE DATA
     if (CACHE) {
         $page = Cache::remember('menu_sub_' . md5(SLUG_FULL) . '_' . SITE_LANG, function () use($_zone) {
             return CmsPage::with(array('elements' => function ($query) use($_zone) {
                 $query->where_zone($_zone)->where_is_valid(1);
             }))->where_slug(SLUG_FULL)->where_lang(SITE_LANG)->where_is_valid(1)->first();
         }, 5);
     } else {
         $page = CmsPage::with(array('elements' => function ($query) use($_zone) {
             $query->where_zone($_zone)->where_is_valid(1);
         }))->where_slug(SLUG_FULL)->where_lang(SITE_LANG)->where_is_valid(1)->first();
     }
     $elements = !empty($page->elements) ? $page->elements : array();
     $options = array('id' => $_id, 'class' => $_class);
     $view = LOAD_VIEW($_tpl);
     $view['slug'] = SLUG_FULL;
     $view['elements'] = $elements;
     $view['options'] = HTML::attributes($options);
     return $view;
 }
 /**
  * Render page template with all variables
  *
  * @return string
  */
 public static function page($slug = null, $inject = array())
 {
     // CHECK $slug IS NOT NULL
     $SLUG_FULL = is_null($slug) ? SLUG_FULL : $slug;
     // Page with lang = SITE_LANG and is_homepage = 1
     if ($SLUG_FULL === '/') {
         // HOMEPAGE
         $page = CmsPage::with(array('elements' => function ($query) {
             $query->where_is_valid(1);
         }))->where_lang(SITE_LANG)->where_is_valid(VALID())->first();
         if (empty($page)) {
             return Response::error('404');
         }
         // More pages with lang = SITE_LANG and slug = SLUG_FULL
     } else {
         // MORE PAGES
         // Check slug is not lang
         if (array_key_exists(str_replace('/', '', $SLUG_FULL), Config::get('cms::settings.langs'))) {
             //Redirect al cambio lingua
             return Redirect::to_action('site@lang', array(str_replace('/', '', $SLUG_FULL)));
         }
         // Get page
         $page = self::page_base($SLUG_FULL);
         // Check page exists
         if (empty($page)) {
             // If not exists, look at SLUG_FIRST and save SLUG_LAST
             $page = self::page_base(SLUG_FIRST);
             // Check page exists
             // Not exists
             if (empty($page)) {
                 return Response::error('404');
                 // It exists and it is a ZOOM of EXTRA
             } else {
                 // Get Model to load
                 switch (getExtra($page->extra_id)) {
                     case 'blogs':
                         $model = CmsBlog::with(array('blogrels'));
                         break;
                         //case 'products':
                         //	$model = 'CmsProduct';
                         //	break;
                 }
                 // Load ZOOM if $extra exists
                 if (isset($model)) {
                     $extra = $model->where_lang(SITE_LANG)->where_slug(SLUG_LAST)->where_is_valid(VALID())->first();
                 }
             }
         }
     }
     //Bind $elements / $extra to ZONE
     if (!empty($page)) {
         // Check if SITE_ROLE < access_level -> to_login
         if (SITE_ROLE < $page->access_level) {
             return Redirect::to_action('site@login')->with('back_url', $SLUG_FULL);
         }
         // Set page_layout from DB or default if not set
         $page_layout = $page->layout;
         if (empty($page->layout)) {
             $page_layout = 'default';
         }
         //INJECT PAGE LAYOUT
         if (!empty($inject)) {
             $page_layout = !empty($inject['layout']) ? $inject['layout'] : $page_layout;
         }
         // Get layouts from config.design
         $arr_layout = Config::get('cms::theme.layout_' . $page_layout);
         // Load template
         $layout = View::make('cms::theme.' . THEME . '.layouts.' . $page_layout);
         // Bind page name
         $layout['NAME'] = $page->name;
         $layout['CLASSNAME'] = Str::slug($page->name);
         // Check layout exists
         if (!empty($arr_layout)) {
             // Bind zones as empty to avoid errors
             foreach ($arr_layout as $key => $value) {
                 $layout[strtoupper($key)] = '';
             }
         }
         // Bind contents to layout variables
         if (!empty($page)) {
             // Bind elements to $ZONE in page layout
             if (!empty($page->elements)) {
                 // Create zone array
                 $zone = array();
                 foreach ($page->elements as $item) {
                     $tmp_text = '<div id="' . $item->name . '" class="' . Config::get('cms::theme.ele_class') . '">';
                     $tmp_text .= Marker::decode($item->text);
                     $tmp_text .= '</div>';
                     $zone[$item->zone][] = $tmp_text;
                 }
                 // INJECT EXTERNAL ELEMENT INTO ZONE
                 if (!empty($inject)) {
                     // Clean content
                     // unset($zone);
                     // Append results
                     $zone[$inject['zone']][0] = $inject['view'];
                 }
                 // Bind pageitem text to ZONE which become layout variable
                 foreach ($page->elements as $item) {
                     $layout[strtoupper($item->zone)] = trim(implode("\n", $zone[$item->zone]));
                 }
             } else {
                 $new_page = CmsPage::where_lang(SITE_LANG)->where_parent_id($page->id)->where_is_valid(1)->order_by('order_id', 'asc')->first();
                 if (!empty($new_page)) {
                     return Redirect::to($new_page->slug);
                 }
             }
             // Bind $extra to layout ZONE if present
             if (!empty($extra)) {
                 //EXTRA VIEW ZOOM
                 $extra_what = CONF('cms::settings.extra_id', $page->extra_id);
                 $tmp_text = View::make('cms::theme.' . THEME . '.partials.details.' . $extra_what);
                 $tmp_text['text'] = $extra;
                 // Bind extra name
                 $layout['NAME'] = $extra->name;
                 $layout['CLASSNAME'] = Str::slug($page->name);
                 // Bind pageitem text to ZONE which become layout variable
                 $layout[strtoupper($extra->zone)] = trim(implode("\n", array($tmp_text)));
             }
         }
     } else {
         // Page not found, empty layout
         $layout = '';
     }
     //Set default title
     $title = !empty($page->title) ? $page->title : $page->name;
     //Set $extra title
     $title = isset($extra) ? $extra->name : $title;
     $title = !empty($extra->title) ? $extra->title : $title;
     $title = CmsUtility::string_style($title, Config::get('cms::theme.title_style'));
     // Add preview string to title
     if (SLUG_PREVIEW) {
         $title = LL('cms::title.preview_title', CMSLANG) . $title;
     }
     //Set default keyw
     $keyw = !empty($page->keyw) ? $page->keyw : Config::get('cms::theme.keyw');
     //Set $extra keyw
     $keyw = isset($extra) ? $extra->keyw : $keyw;
     $keyw = !empty($extra->keyw) ? $extra->keyw : $keyw;
     //Set default descr
     $descr = !empty($page->descr) ? $page->descr : Config::get('cms::theme.descr');
     //Set $extra descr
     $descr = isset($extra) ? $extra->descr : $descr;
     $descr = !empty($extra->descr) ? $extra->descr : $descr;
     //Set default template, header, footer, layout se non settati
     $template = !empty($page->template) ? $page->template : 'default';
     $header = !empty($page->header) ? $page->header : 'default';
     $footer = !empty($page->footer) ? $page->footer : 'default';
     // INJECT PAGE PARTIALS
     if (!empty($inject)) {
         $template = !empty($inject['template']) ? $inject['template'] : $template;
         $header = !empty($inject['header']) ? $inject['header'] : $header;
         $footer = !empty($inject['footer']) ? $inject['footer'] : $footer;
     }
     //APPLICATION COMPOSER
     View::composer('cms::theme.' . THEME . '.templates.' . $template, function ($view) {
         CmsRender::asset();
         //BASE JS
         Asset::container('header')->add('base_js', Config::get('application.url') . '/site/js');
         if (!isset($view->title)) {
             $view->title = Config::get('cms::theme.title');
         }
         if (!isset($view->descr)) {
             $view->descr = Config::get('cms::theme.descr');
         }
         if (!isset($view->keyw)) {
             $view->keyw = Config::get('cms::theme.keyw');
         }
         if (!isset($view->header)) {
             $view->header = '';
         }
         if (!isset($view->layout)) {
             $view->layout = '';
         }
         if (!isset($view->footer)) {
             $view->footer = '';
         }
     });
     //Prepare html buffer
     $html = View::make('cms::theme.' . THEME . '.templates.' . $template)->with('title', $title)->with('keyw', $keyw)->with('descr', $descr)->nest('header', 'cms::theme.' . THEME . '.partials.header_' . $header)->with('layout', $layout)->nest('footer', 'cms::theme.' . THEME . '.partials.footer_' . $footer);
     //Output buffer
     self::clean_code($html);
 }