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(); } }