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); } } }
/** * PREVNEXT Marker - Loop paginator between pages or blog posts * * [$PREVNEXT[{ * "separator":"" => OPTIONAL * "class":"<class>", => OPTIONAL (default: search) * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers) * }]] * * @param array * @return string */ public static function PREVNEXT($vars = array()) { //Get variables from array $vars if (!empty($vars)) { extract($vars); } $_separator = ''; if (isset($separator) and !empty($separator)) { $_separator = $separator; } $_class = ''; if (isset($class) and !empty($class)) { $_class = $class; } $_tpl = 'prevnext'; if (isset($tpl) and !empty($tpl)) { $_tpl = $tpl; } //CACHE DATA if (CACHE) { $this_page = Cache::remember('page_' . Str::slug(SLUG_LAST, '_') . '_' . SITE_LANG, function () { return CmsPage::where_lang(SITE_LANG)->where_slug(SLUG_FULL)->first(); }, 5); } else { $this_page = CmsPage::where_lang(SITE_LANG)->where_slug(SLUG_FULL)->first(); } // GET THIS PAGE $this_order = $this_page->order_id; $this_id = $this_page->id; $this_parent = $this_page->parent_id; // GET ALL PAGES if (CACHE) { $pages = Cache::remember('page_' . $this_parent . '_' . SITE_LANG, function () use($this_parent) { return CmsPage::where_lang(SITE_LANG)->where_parent_id($this_parent)->order_by('order_id', 'asc')->order_by('id', 'asc')->get(); }, 5); } else { $pages = CmsPage::where_lang(SITE_LANG)->where_parent_id($this_parent)->order_by('order_id', 'asc')->order_by('id', 'asc')->get(); } // CHECK BY ORDER_ID $order = $this_order == Config::get('cms::settings.order') ? false : true; // ITERATE PAGES TO FIND ARRAY KEY foreach ($pages as $key => $page) { if ($page->id == $this_id) { $page_index = $key; } } $page_count = count($pages); // GET PREV if (array_key_exists($page_index - 1, $pages)) { $prev_slug = $pages[$page_index - 1]->slug; } else { $prev_slug = $pages[$page_count - 1]->slug; } // GET NEXT if (array_key_exists($page_index + 1, $pages)) { $next_slug = $pages[$page_index + 1]->slug; } else { $next_slug = $pages[0]->slug; } $options = array('class' => $_class); $view = LOAD_VIEW($_tpl); $view['separator'] = $_separator; $view['prev_slug'] = $prev_slug; $view['next_slug'] = $next_slug; $view['options'] = HTML::attributes($options); return $view; }
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'); //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'); //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/pages_edit.js', 'cms'); $this->layout->header_data = array('title' => LL('cms::title.page_edit', CMSLANG)); $this->layout->top_data = array('search' => false); if (!empty($id)) { //GET SUBPAGES DATA $subpages = CmsPage::where_parent_id($id)->order_by('order_id', 'asc')->get(); //GET PAGE DATA $page = CmsPage::with(array('files', 'pagerels'))->find($id); if (!empty($page)) { $arr_slugs = explode('/', $page->slug); $slug = '/' . end($arr_slugs); //GET PAGE DATA $pagedata = CmsPage::where_lang($page->lang)->where('id', '<>', $id)->where_parent_id(0)->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; } if (empty($new_data)) { $new_data = array(); } // LOAD LAYOUT PREVIEW $preview_layout = CmsPage::preview_layout_create($page->layout); $this->layout->content = View::make('cms::interface.pages.page_new_edit')->with('role_fail', CmsRole::role_fail($id))->with('title', LL('cms::title.page_edit', CMSLANG))->with('page_id', $id)->with('page_lang', $page->lang)->with('page_name', $page->name)->with('page_parent', CmsPage::select_top_slug($page->lang, $id))->with('page_parent_selected', $page->parent_id)->with('page_slug', str_replace('/', '', $slug))->with('page_parent_slug', str_replace($slug, '', $page->slug))->with('page_owner', CmsRole::select_edit_owners())->with('page_owner_selected', $page->role_id)->with('page_access', CmsRole::select_edit_access())->with('page_access_selected', $page->access_level)->with('page_extra', CmsPage::select_extra_id())->with('page_extra_selected', $page->extra_id)->with('page_is_home', (bool) $page->is_home)->with('page_is_valid', (bool) $page->is_valid)->with('page_template', Config::get('cms::theme.template'))->with('page_template_selected', $page->template)->with('page_header', Config::get('cms::theme.header'))->with('page_header_selected', $page->header)->with('page_layout', Config::get('cms::theme.layout'))->with('page_layout_selected', $page->layout)->with('page_footer', Config::get('cms::theme.footer'))->with('page_footer_selected', $page->footer)->with('page_layout_preview', $preview_layout)->with('page_title', $page->title)->with('page_preview', $page->preview)->with('page_keyw', $page->keyw)->with('page_descr', $page->descr)->with('subpages', $subpages)->with('files', $page->files)->with('pagedata', $new_data)->with('pagerels', $page->pagerels); } else { $this->layout->content = View::make('cms::interface.pages.not_found')->with('message', LL('cms::alert.not_found', CMSLANG)); } } else { $this->layout->content = View::make('cms::interface.pages.not_found')->with('message', LL('cms::alert.not_found', CMSLANG)); } }
/** * 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); }