Ejemplo n.º 1
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param integer $id
  * @param  array $data
  * @return User
  */
 public function update($id, array $data)
 {
     $page = Page::findOrFail($id);
     $page->created_at = new Carbon();
     $page->update(array_only($data, ['title', 'slug', 'is_redirect', 'breadcrumb', 'meta_title', 'meta_keywords', 'meta_description', 'robots', 'parent_id', 'layout_file', 'behavior', 'status', 'published_at', 'redirect_url']));
     return $page;
 }
 public function boot()
 {
     app('view')->addNamespace('layouts', layouts_path());
     Page::observe(new PageObserver());
     PagePartModel::observe(new PagePartObserver());
     $this->registerWidgets();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Page::truncate();
     PagePart::truncate();
     $rootPage = Page::create(['title' => 'Home', 'breadcrumb' => 'Home', 'slug' => '', 'layout_file' => 'normal.blade', 'published_at' => new Carbon()]);
     $page = new Page(['title' => 'Page not found', 'breadcrumb' => 'Page not found', 'slug' => 'page-not-found', 'behavior' => 'page.not.found', 'status' => FrontendPage::STATUS_HIDDEN, 'published_at' => new Carbon()]);
     $rootPage->children()->save($page);
     $page->parts()->save(new PagePart(['name' => 'content', 'content' => '<h1>Page not found</h1>', 'wysiwyg' => 'ace']));
 }
Ejemplo n.º 4
0
 /**
  * @param PageRepository $repository
  */
 public function getIndex(PageRepository $repository)
 {
     Meta::loadPackage('nestable', 'editable');
     $this->templateScripts['PAGE_STATUSES'] = array_map(function ($value, $key) {
         return ['id' => $key, 'text' => $value];
     }, Page::getStatusList(), array_keys(Page::getStatusList()));
     /** @var Page $page */
     $page = $repository->getRootPage();
     $this->setContent('pages.index', compact('page'));
 }
Ejemplo n.º 5
0
 public function getSearch()
 {
     $query = trim($this->getRequiredParameter('search'));
     $pages = new Page();
     if (strlen($query) == 2 and $query[0] == '.') {
         $page_status = ['d' => FrontendPage::STATUS_DRAFT, 'p' => FrontendPage::STATUS_PUBLISHED, 'h' => FrontendPage::STATUS_HIDDEN];
         if (isset($page_status[$query[1]])) {
             $pages->whereIn('status', $page_status[$query[1]]);
         }
     } else {
         $pages = $pages->searchByKeyword($query);
     }
     $childrens = [];
     $pages = $pages->get();
     foreach ($pages as $page) {
         $page->isExpanded = FALSE;
         $page->hasChildren = FALSE;
         $childrens[] = $page;
     }
     $this->setContent((string) view('pages::pages.children', ['childrens' => $childrens, 'level' => 0]));
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     \DB::table('pages')->truncate();
     $rootPage = Page::create(['title' => 'Home', 'breadcrumb' => 'Home', 'slug' => '', 'published_at' => new Carbon()]);
     $pages = [['title' => 'News', 'breadcrumb' => 'News', 'slug' => 'news', 'behavior' => 'test', 'published_at' => new Carbon()], ['title' => 'Blog', 'breadcrumb' => 'Blog', 'slug' => 'blog', 'published_at' => new Carbon()]];
     foreach ($pages as $i => $page) {
         $pages[$i] = new Page($page);
     }
     $rootPage->children()->saveMany($pages);
     foreach ($pages as $page) {
         $page->children()->save(new Page(['title' => 'Article', 'breadcrumb' => 'Article', 'slug' => 'article', 'published_at' => new Carbon()]));
     }
     $page = new Page(['title' => 'About', 'breadcrumb' => 'About', 'slug' => 'about', 'published_at' => new Carbon(), 'is_redirect' => TRUE, 'redirect_url' => url('about/us')]);
     $rootPage->children()->save($page);
     $page->children()->save(new Page(['title' => 'Us', 'breadcrumb' => 'Us', 'slug' => 'us', 'published_at' => new Carbon()]));
 }
 public function postReorder()
 {
     $pageId = $this->getRequiredParameter('id');
     $data = (array) $this->getRequiredParameter('data');
     /** @var Page $page */
     $page = Page::find($pageId);
     $widgetsData = [];
     foreach ($data as $block => $widgets) {
         foreach ($widgets as $position => $widgetId) {
             $location = ['block' => $block, 'position' => $position];
             $widgetsData[$widgetId] = $location;
         }
     }
     $this->request->merge(['widget' => $widgetsData]);
     $page->save();
     $this->setContent(true);
 }
Ejemplo n.º 8
0
 /**
  * Получение карты сайта
  * 
  * @param boolean $includeHidden Включить скрытые страницы
  * @return PageSitemap
  */
 public static function get($includeHidden = FALSE)
 {
     $status = (bool) $includeHidden ? 1 : 0;
     if (!array_key_exists($status, static::$sitemap)) {
         $query = Page::orderBy('parent_id', 'asc')->orderBy('position', 'asc');
         if ((bool) $includeHidden === FALSE) {
             $query->whereIn('status_id', [FrontendPage::STATUS_PASSWORD_PROTECTED, FrontendPage::STATUS_PUBLISHED]);
         }
         $pages = [];
         foreach ($query->get() as $page) {
             $pages[$page->id] = $page->toArray();
             $pages[$page->id]['uri'] = '';
             $pages[$page->id]['url'] = '';
             $pages[$page->id]['slug'] = $page->slug;
             $pages[$page->id]['level'] = 0;
             $pages[$page->id]['is_active'] = TRUE;
         }
         $structuredPages = [];
         foreach ($pages as &$page) {
             $structuredPages[$page['parent_id']][] =& $page;
         }
         foreach ($pages as &$page) {
             if (isset($structuredPages[$page['id']])) {
                 foreach ($structuredPages[$page['id']] as &$_page) {
                     $_page['level'] = $page['level'] + 1;
                     $_page['parent'] = $page;
                     $_page['uri'] = $page['uri'] . '/' . $_page['slug'];
                     $_page['url'] = url($_page['uri']);
                     $_page['is_active'] = URL::match($_page['uri']);
                     if (empty($_page['layout_file'])) {
                         $_page['layout_file'] = $page['layout_file'];
                     }
                     if ($_page['is_active']) {
                         $page['is_active'] = TRUE;
                     }
                 }
                 $page['childs'] = $structuredPages[$page['id']];
             }
         }
         static::$sitemap[$status] = new Sitemap(reset($structuredPages));
     }
     return clone static::$sitemap[$status];
 }
Ejemplo n.º 9
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 public function create(array $data)
 {
     $page = Page::create(array_only($data, ['title', 'slug', 'is_redirect', 'breadcrumb', 'meta_title', 'meta_keywords', 'meta_description', 'robots', 'parent_id', 'layout_file', 'behavior', 'status', 'published_at', 'redirect_url']));
     return $page;
 }
Ejemplo n.º 10
0
 /**
  * @param integer $id
  * @return Page
  * @throws HttpResponseException
  */
 protected function getPage($id)
 {
     try {
         return Page::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         $this->throwFailException($this->smartRedirect()->withErrors(trans('pages::core.messages.not_found')));
     }
 }
 public function register()
 {
     Page::observe(new PageObserver());
     PagePart::observe(new PagePartObserver());
     BehaviorManager::init();
 }
Ejemplo n.º 12
0
 /**
  * @param bool $includeHidden
  *
  * @return Builder
  */
 public function getChildrenQuery($includeHidden = false)
 {
     $query = Page::where('parent_id', $this->getId())->whereIn('status', static::getStatuses($includeHidden))->orderBy('position', 'desc');
     if (filter_var(config('pages.check_date'), FILTER_VALIDATE_BOOLEAN)) {
         $query->whereRaw('published_at <= NOW()');
     }
     return $query;
 }
Ejemplo n.º 13
0
 /**
  * @param \KodiCMS\Pages\Model\Page $page
  *
  * @return void
  */
 public function deleted($page)
 {
     // TODO: подумать что лучше делать с дочерними страницами при удалении родителя
     $page->children()->delete();
     $page->behaviorSettings()->delete();
     $page->parts()->delete();
     $this->clearCache($page);
 }
Ejemplo n.º 14
0
 /**
  * @param \KodiCMS\Pages\Model\Page $page
  * @return bool
  */
 public function deleted($page)
 {
     // Все дочерние страницы перекидываем в корень
     // TODO: спрашивать у пользователя нужно ли удалять все внутренние страницы
     //Page::where('parent_id', $page->id)->delete();
     Page::where('parent_id', $page->id)->update(['parent_id' => 1]);
     return TRUE;
 }
 /**
  * Register any other events for your application.
  *
  * @param  DispatcherContract $events
  *
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     $events->listen('KodiCMS\\Pages\\Events\\FrontPageFound', function ($event) {
         $this->app->singleton('layout.widgets', function ($app) use($event) {
             return new PageWidgetCollection($app['widget.manager'], $event->getPage()->getId());
         });
         $block = new Block(app('layout.widgets'));
         $this->app->singleton('layout.block', function ($app) use($block) {
             return $block;
         });
     }, 9000);
     $events->listen('view.page.create', function ($page) {
         echo view('widgets::widgets.page.create')->with('page', $page)->with('pages', $page->getSitemap())->render();
     });
     $events->listen('view.page.edit', function ($page) {
         if (acl_check('widgets::list') and $page->hasLayout()) {
             // echo view('widgets::widgets.page.iframe', compact('page'))->render();
             echo view('widgets::widgets.page.list', ['page' => $page, 'widgetsCollection' => (new PageWidgetCollection(app('widget.manager'), $page->id))->getRegisteredWidgets()])->render();
         }
     });
     $events->listen('view.widget.edit', function ($widget) {
         if ($widget->isRenderable()) {
             $commentKeys = app('widget.manager')->getTemplateKeysByType($widget->type);
             $snippets = (new SnippetCollection())->getHTMLSelectChoices();
             echo view('widgets::widgets.partials.renderable', compact('widget', 'commentKeys', 'snippets'))->render();
         }
         if ($widget->isCacheable() and acl_check('widget_settings::cache')) {
             echo view('widgets::widgets.partials.cacheable', compact('widget'))->render();
         }
     });
     $events->listen('view.widget.edit.footer', function ($widget) {
         if ($widget->isRenderable()) {
             $assetsPackages = PackageManager::getHTMLSelectChoice();
             $widgetList = Widget::where('id', '!=', $widget->id)->lists('name', 'id')->all();
             echo view('widgets::widgets.partials.renderable_buttons', compact('widget', 'commentKeys', 'snippets', 'assetsPackages', 'widgetList'))->render();
         }
         if (acl_check('widget_settings::roles') and !$widget->isHandler()) {
             $usersRoles = Role::pluck('name', 'id')->all();
             echo view('widgets::widgets.partials.permissions', compact('widget', 'usersRoles'))->render();
         }
     });
     $events->listen('view.widget.edit.settings', function ($widget) {
         if ($widget->toWidget() instanceof WidgetPaginator) {
             echo view('widgets::widgets.paginator.widget', ['widget' => $widget->toWidget()])->render();
         }
     });
     $events->listen('view.widget.edit.footer', function ($widget) {
         if ($widget->isHandler()) {
             echo view('widgets::widgets.partials.handler', compact('widget'))->render();
         }
     });
     Page::created(function ($page) {
         $pageId = array_get(Request::get('widgets'), 'from_page_id');
         if (!empty($pageId)) {
             app('widget.manager')->copyWidgets($pageId, $page->id);
         }
     });
     Page::deleted(function ($page) {
         app('widget.manager')->deleteWidgetsFromPage($page->id);
     });
     Page::saving(function ($page) {
         $postData = Request::input('widget', []);
         foreach ($postData as $widgetId => $location) {
             if (array_key_exists('block', $location)) {
                 app('widget.manager')->updateWidgetOnPage($widgetId, $page->id, $location);
             }
         }
     });
     Widget::observe(new WidgetObserver());
 }