public function action_search_blog() { $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('blogs', 'bundles/cms/js/sections/blogs_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/blog/search', 'q' => $q); // CHECK IF DATE if (substr_count($q, '/') >= 2) { // CHECK IF DATE RANGE if (substr_count($q, '/') == 4 and substr_count($q, ' ') == 1) { $date_arr = explode(' ', $q); $from = date2Db($date_arr[0]) . ' 00:00:00'; $to = date2Db($date_arr[1]) . ' 23:59:59'; // FROM DATE $from TO DATE $to $data = CmsBlog::with('user')->where_lang(LANG)->where('datetime_on', '>=', $from)->where('datetime_on', '<=', $to)->order_by('datetime_on', 'asc')->order_by('name', 'asc')->order_by('slug', 'asc')->order_by('title', 'asc')->paginate(Config::get('cms::settings.pag')); } else { // FROM DATE XX $data = CmsBlog::with('user')->where_lang(LANG)->where('datetime_on', 'LIKE', date2Db($q) . '%')->order_by('datetime_on', 'asc')->order_by('name', 'asc')->order_by('slug', 'asc')->order_by('title', 'asc')->paginate(Config::get('cms::settings.pag')); } } else { //GET PAGE DATA $data = CmsBlog::with('user')->where_lang(LANG)->where('name', 'LIKE', '%' . $q . '%')->or_where('slug', 'LIKE', '%' . $q . '%')->or_where('title', 'LIKE', '%' . $q . '%')->order_by('datetime_on', 'asc')->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.blog_list')->with('data', $data)->with('lang', ''); } else { $this->layout->header_data = array('title' => LL('cms::title.blogs', CMSLANG)); $this->layout->top_data = array('search' => '/cms/blog/search', 'q' => ''); //GET PAGE DATA $data = CmsBlog::with('user')->where_lang(LANG)->order_by('updated_at', 'desc')->order_by('created_at', 'desc')->paginate(Config::get('cms::settings.pag')); $this->layout->content = View::make('cms::interface.pages.blog_list')->with('data', $data)->with('lang', LANG); } } }
public function post_popover_details() { $auth = Auth::check(); if ($auth) { if (Input::has('id')) { $bid = Input::get('id'); //CACHE DATA if (CACHE) { $blog = Cache::remember('blog_' . $bid . '_details', function () use($bid) { return CmsBlog::with(array('user', 'pages', 'blogrels'))->find($bid); }, 60); } else { $blog = CmsBlog::with(array('user', 'pages'))->find($bid); } return View::make('cms::interface.partials.blog_details')->with('author', $blog->user->username)->with('created_at', $blog->created_date)->with('updated_at', $blog->updated_date)->with('datetime_on', $blog->dt_on)->with('datetime_off', $blog->dt_off)->with('is_valid', (bool) $blog->is_valid)->with('lang', $blog->lang)->with('pagerels', $blog->pages)->with('blogrels', $blog->blogrels); } } }
/** * BLOGVIEW Marker - Shows a list of last n blogs * * [$BLOGVIEW[{ * "source":"<source label>", => (available: blogs, products...) * "time":"<time label>", => (available: future, present, past - default: present) * "n":"<n items per page>", => (default: 5) * "order":"desc", => OPTIONAL (asc, desc default: desc) * "id":"<id>", => OPTIONAL <ul> id * "class":"<class>", => OPTIONAL <ul><li> class (default: list) * "tpl":"<tpl_name>" => OPTIONAL (in /partials/markers) * }]] * * @param array * @return string */ public static function BLOGVIEW($vars = array()) { //Get variables from array $vars if (!empty($vars)) { extract($vars); } //Bind variables $_time = 'present'; if (isset($time) and !empty($time)) { $_time = $time; } $_n = 5; if (isset($n) and !empty($n)) { $_n = $n; } $_order = 'desc'; if (isset($order) and !empty($order)) { $_order = $order; } $_id = 'blogview'; if (isset($id) and !empty($id)) { $_id = $id; } $_class = 'list'; if (isset($class) and !empty($class)) { $_class = $class; } $_tpl = 'blogview'; if (isset($tpl) and !empty($tpl)) { $_tpl = $tpl; } //CHECK SOURCE CLASS if ($_n > 0) { $_sign = '<>'; if ($_time == 'future') { $_sign = '>='; } if ($_time == 'past') { $_sign = '<='; } //CACHE DATA if (CACHE) { $list = Cache::remember('blog_last_' . SITE_LANG, function () use($_sign, $_order, $_n) { return CmsBlog::with(array('pages'))->where_lang(SITE_LANG)->where('datetime_on', $_sign, date('Y-m-d H:i:s'))->where('datetime_off', '>', date('Y-m-d H:i:s'))->where_is_valid(1)->order_by('datetime_on', $_order)->take($_n)->get(); }, 5); } else { $list = CmsBlog::with(array('pages'))->where_lang(SITE_LANG)->where('datetime_on', $_sign, date('Y-m-d H:i:s'))->where('datetime_off', '>', date('Y-m-d H:i:s'))->where_is_valid(1)->order_by('datetime_on', $_order)->take($_n)->get(); } if (!empty($list)) { $ul_options = array('id' => $_id); $li_options = array('class' => $_class); $view = LOAD_VIEW($_tpl); $view['list'] = $list; $view['ul_options'] = HTML::attributes($ul_options); $view['li_options'] = HTML::attributes($li_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); }
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(); } }