public function runCrawler() { switch (Input::get('action')) { case 'recreateurls': foreach (Page::all() as $page) { $page->url = Page::getUrl($page->id); $page->save(); } die("Recreated URL:s"); break; case 'crawl': Crawler::url(Input::get('crawl_url'), Input::get('crawl_found_links') ? true : false); if (Input::get('crawl_convert')) { Crawler::createPages(); } break; case 'convertToPages': Crawler::convertToPages(); break; default: return Response::json('Invalid action', 400); break; } if (Request::ajax()) { return Response::json(Lang::get('cms::m.crawler-done'), 200); } else { return Redirect::route('crawler')->with('flash_notice', Lang::get('cms::m.crawler-done')); } }
/** * @param $page */ private function setViewVariables($page) { View::share('page', $page); View::share('title', $page->content->title); //only allow page edit in a page with a page_id View::share('allow_edit_page', $page->id ? true : false); //Breadcrumbs View::share('breadcrumbs', \Cms\Models\Page::subPages($page->id)); }
/** * Removing a Menu must also reset all pages to menu_id = 0 (put in Unsorted Pages) * @param $menu_id * @return mixed */ public function removeMenu($menu_id) { //Remove $menu = Menu::find($menu_id); $menu->delete(); //Set any pages with current menu_id to menu_id = 0 = Unsorted, also set new parent_id to 0 $pages = Page::where("id", "=", $menu_id)->update(array('menu_id' => 0, 'parent_id' => 0)); return Redirect::route('cmsEdit')->with('flash_notice', Lang::get('cms::m.menu-removed')); }
public static function createPageSlug($string, $pageId = 0, $loop = 1) { $slug = trim($string); $slug = strtolower($slug); $slug = str_replace(array('å', 'ä', 'ö', ' '), array('a', 'a', 'o', '-'), $slug); $slug = preg_replace("/[^a-z0-9-]/", "", $slug); $slug = preg_replace("/[-]+/", "-", $slug); if (\Cms\Models\Page::published()->where('slug', '=', $slug)->where("id", "!=", $pageId)->count()) { $loop++; $slug = self::createPageSlug($loop . "-" . $string, $pageId, $loop); //add page_id to ensure is unique } return $slug; }
/** * Creates Pages from Crawl Data * Only not already converted */ public static function convertToPages() { $crawlData = Crawl::whereNull("converted")->get(); foreach ($crawlData as $crawl) { Page::createPage(array("page" => array("published" => $crawl->published, "menu_id" => $crawl->menu_id, "parent_id" => $crawl->parent_id, "slug" => $crawl->slug ? $crawl->slug : Helper::createPageSlug($crawl->title)), "content" => array("title" => $crawl->title, "body" => $crawl->content))); $crawl->converted = date("Y-m-d H:i:s"); $crawl->save(); } }
/** * @param $title * @param array $content (array with body, and any custom data) * @param int $parent_id */ public static function createPage($data = array(), $parent_id = 0) { $page = new Page(); $page->publish_start = date("Y-m-d H:i"); foreach ($data['page'] as $field => $value) { $page->{$field} = $value; } $page->crawled = 1; $page->save(); $pageId = $page->id; $content = new Content(); $content->page_id = $pageId; foreach ($data['content'] as $field => $value) { $content->{$field} = $value; } //$content->custom_content_right = $content['content_right']; $content->save(); }
/** * Removes Pages and its Content * @return mixed */ public function saveUnsortedPages() { switch (Input::get('action')) { case 'remove': if (count(Input::get('page')) > 0) { Content::whereIn("page_id", Input::get('page'))->delete(); Page::whereIn("id", Input::get('page'))->delete(); } break; } return Redirect::route('unsortedPages'); }