Esempio n. 1
0
 public function beforeSave(Event $event, Attribute $attribute)
 {
     if (!$attribute->language_id) {
         $attribute->language_id = Wasabi::contentLanguage()->id;
     }
     if ($attribute->content === '') {
         $attribute->content = null;
     }
 }
Esempio n. 2
0
 public function renderMenuItem(Event $event, MenuHelper $helper)
 {
     /** @var MenuItem $menuItem */
     $menuItem = $event->subject();
     if ($menuItem->foreign_model !== 'Wasabi/Cms.Pages' || $menuItem->get('Pages')['id'] === null) {
         return;
     }
     $event->result = $helper->Html->link($menuItem->name, ['model' => $menuItem->foreign_model, 'foreign_key' => $menuItem->get('Pages')['id'], 'language_id' => Wasabi::contentLanguage()->id, '_name' => 'wasabi']);
     $event->stopPropagation();
 }
Esempio n. 3
0
 /**
  * Add action
  * AJAX POST
  *
  * @throws MethodNotAllowedException
  * @throws BadRequestException
  * @return void
  */
 public function add()
 {
     if (!$this->request->isAll(['ajax', 'post'])) {
         throw new MethodNotAllowedException();
     }
     $model = $this->request->data('model');
     $foreignKey = (int) $this->request->data('foreign_key');
     $languageId = Wasabi::contentLanguage()->id;
     $url = $this->_formatUrl($this->request->data('url'));
     $routeType = (int) $this->request->data('route_type');
     $element = $this->request->data('element');
     $routeData = ['url' => $url, 'model' => $model, 'foreign_key' => $foreignKey, 'language_id' => $languageId];
     $route = $this->_addRoute($routeType, $routeData);
     $this->_render($route, $element);
 }
Esempio n. 4
0
 public function view($pageId, $languageId, $pageNumber)
 {
     Wasabi::loadLanguages($languageId);
     $this->loadModel('Wasabi/Cms.Pages');
     $page = $this->Pages->getForFrontend($pageId);
     $startPage = $this->Pages->getStartPage();
     $titleSuffix = Configure::read('Settings.Core.html_title_suffix');
     $instanceName = Configure::read('Settings.Core.instance_name');
     WasabiCms::page($page);
     WasabiCms::startPage($startPage);
     WasabiCms::titleSuffix($titleSuffix);
     WasabiCms::instanceName($instanceName);
     $page->initializeContentAreas();
     $this->viewBuilder()->theme($page->getTheme()->getNameForViewBuilder());
     $this->viewBuilder()->layout($page->getLayout()->name());
     $this->viewBuilder()->className($page->getTheme()->getViewClassNameForViewBuilder());
     $this->set(['page' => $page]);
 }
Esempio n. 5
0
 /**
  * HeartBeat action
  * AJAX POST
  *
  * @return void
  */
 public function heartBeat()
 {
     if (!$this->request->isAll(['ajax', 'post'])) {
         throw new MethodNotAllowedException();
     }
     $loginTime = $this->request->session()->check('loginTime') ? $this->request->session()->read('loginTime') : 0;
     $maxLoggedInTime = (int) Wasabi::setting('Core.Login.HeartBeat.max_login_time', 0) / 1000;
     $logoutTime = $loginTime + $maxLoggedInTime;
     if (time() <= $logoutTime) {
         $this->set(['status' => 200, '_serialize' => ['status']]);
     } else {
         $this->Auth->logout();
         $this->set(['status' => 401, '_serialize' => ['status']]);
     }
 }
Esempio n. 6
0
 /**
  * Get the theme instance.
  *
  * @return Theme
  */
 public static function getTheme()
 {
     return ThemeManager::theme(Wasabi::setting('Cms.Theme.id'));
 }
Esempio n. 7
0
 /**
  * Returns the access level of the user for the given plugin controller action path.
  *
  * @param array $url The url to get the access level for.
  * @return int|bool
  */
 public function getAccessLevel($url = null)
 {
     if ($url === null) {
         $url = Wasabi::getCurrentUrlArray();
     }
     $path = guardian()->getPathFromUrl($url);
     if (!array_key_exists($path, $this->permissions)) {
         return 0;
     }
     return $this->permissions[$path];
 }
Esempio n. 8
0
 /**
  * Render the ld+json script tag to set the schema.org context for a page.
  *
  * @return string
  */
 public function ldJson()
 {
     $attributes = ['@context' => 'http://schema.org', '@type' => 'WebSite', 'url' => $this->Url->build('/', true), 'potentialAction' => ['@type' => 'SearchAction', 'query-input' => 'required name=search_term_string', 'target' => $this->Url->build(['plugin' => 'Wasabi/Cms', 'controller' => 'Frontend/Search', 'action' => 'search', 'language_id' => Wasabi::contentLanguage()->id], true) . '?q={search_term_string}']];
     if (!empty(WasabiCms::$instanceName)) {
         $attributes['name'] = WasabiCms::$instanceName;
     }
     $sameAsKeys = ['Settings.Cms.SEO.Social.facebook_url', 'Settings.Cms.SEO.Social.instagram_url', 'Settings.Cms.SEO.Social.linkedin_url', 'Settings.Cms.SEO.Social.myspace_url', 'Settings.Cms.SEO.Social.pinterest_url', 'Settings.Cms.SEO.Social.youtube_url', 'Settings.Cms.SEO.Social.googleplus_url'];
     $sameAs = [];
     foreach ($sameAsKeys as $key) {
         $setting = Configure::read($key);
         if (!empty($setting)) {
             $sameAs[] = $setting;
         }
     }
     $twitterName = Configure::read('Settings.Cms.SEO.Social.twitter_username');
     if (!empty($twitterName)) {
         $sameAs[] = 'https://twitter.com/' . $twitterName;
     }
     if (!empty($sameAs)) {
         $attributes['sameAs'] = $sameAs;
     }
     return '<script type="application/ld+json">' . json_encode($attributes) . '</script>';
 }
Esempio n. 9
0
 public function contentHasChanged(Page $page)
 {
     $latestContent = $this->Contents->find()->select(['Contents.content'])->where(['Contents.page_id' => $page->id, 'Contents.language_id' => Wasabi::contentLanguage()->id])->order(['Contents.modified' => 'DESC'])->limit(1)->hydrate(false)->first();
     if (empty($latestContent)) {
         return true;
     }
     if (empty($page->current[0])) {
         return false;
     }
     return md5($latestContent['content']) !== md5($page->current[0]->content);
 }
Esempio n. 10
0
 /**
  * Prepare the UserMailer Email instance.
  *
  * @param User $user The user to send the email to.
  * @param string $subject The subject of the email.
  * @return void
  */
 protected function _prepareEmail(User $user, $subject)
 {
     $this->layout('Wasabi/Core.responsive');
     $this->_email->transport('default');
     $this->_email->emailFormat('both');
     $this->_email->from(Wasabi::getSenderEmail(), Wasabi::getSenderName());
     $this->_email->to($user->email, $user->username);
     $this->_email->subject($subject);
     $this->_email->helpers(['Email' => ['className' => 'Wasabi/Core.Email']]);
 }
Esempio n. 11
0
 /**
  * Allow all guest actions.
  *
  * @return void
  */
 protected function _allow()
 {
     $url = Wasabi::getCurrentUrlArray();
     if ($this->Guardian->isGuestAction($url)) {
         $this->Auth->allow($this->request->params['action']);
     }
 }
Esempio n. 12
0
 /**
  * Check if the currently logged in user is authorized to access the given url.
  *
  * @param array $url The url parameters.
  * @return bool
  */
 public function hasAccess($url)
 {
     if ($this->isGuestAction($url)) {
         return true;
     }
     $path = $this->getPathFromUrl($url);
     $groupId = $this->Auth->user('group_id');
     if ($groupId === null) {
         return false;
     }
     if (!is_array($groupId)) {
         $groupId = [$groupId];
     }
     if (in_array(1, $groupId)) {
         return true;
     }
     $user = Wasabi::user();
     if (empty($user->permissions)) {
         Wasabi::user()->permissions = $this->_getGroupPermissions()->findAllForGroup($groupId);
     }
     if (array_key_exists($path, Wasabi::user()->permissions)) {
         return true;
     }
     return false;
 }
Esempio n. 13
0
 /**
  * Edit Action
  * GET | PUT
  *
  * @param $id
  */
 public function edit($id)
 {
     $this->request->allowMethod(['get', 'put']);
     /** @var Page $page */
     $page = $this->Pages->get($id, ['contain' => ['Current', 'Attributes', 'Collections']]);
     ThemeManager::theme(Wasabi::setting('Cms.Theme.id'));
     if ($this->request->is('put')) {
         $page = $this->Pages->patchEntity($page, $this->request->data);
         if ($this->Pages->save($page)) {
             $this->Flash->success(__d('wasabi_cms', 'The page <strong>{0}</strong> has been saved.', $page->name));
             $this->redirect(['action' => 'index']);
             return;
         } else {
             $this->Flash->error($this->formErrorMessage);
         }
     } else {
         /** @var Content $current */
         $current = $page->current;
         if (!is_array($current) && get_class($current) === 'Wasabi\\Cms\\Model\\Entity\\Content' && $current->isNew()) {
             $defaultLayout = ThemeManager::theme()->getLayout('Default');
             $page->current = [(new Content())->set('content', json_encode($defaultLayout->content()))];
         }
     }
     if ($page->meta_robots_index === null) {
         $page->meta_robots_index = (bool) Configure::read('Settings.Cms.SEO.meta-robots-index');
     }
     if ($page->meta_robots_follow === null) {
         $page->meta_robots_follow = (bool) Configure::read('Settings.Cms.SEO.meta-robots-follow');
     }
     $routes = $this->Routes->findAllFor('Wasabi/Cms.Pages', $id, Wasabi::contentLanguage()->id)->order([$this->Routes->aliasField('url') => 'asc']);
     $this->set(['page' => $page, 'layouts' => ThemeManager::theme()->getLayoutsForSelect(), 'availableModules' => ModuleManager::getAvailableModules(), 'changeAttributesUrl' => Router::url(['plugin' => 'Wasabi/Cms', 'controller' => 'Pages', 'action' => 'attributes']), 'attributes' => $page->getLayout()->attributes(), 'routes' => $routes, 'routeTypes' => RouteTypes::getForSelect(), 'formRoute' => $this->Routes->newEntity(['type' => $routes->count() >= 1 ? RouteTypes::TYPE_REDIRECT_ROUTE : RouteTypes::TYPE_DEFAULT_ROUTE])]);
     $this->render('add');
 }
Esempio n. 14
0
 /**
  * Find the current (latest) content revision.
  *
  * @param Query $query
  * @param array $options
  * @return Query
  */
 public function findCurrent(Query $query, array $options)
 {
     $query->where(['Current.language_id' => Wasabi::contentLanguage()->id])->order(['Current.modified' => 'DESC'])->limit(1);
     return $query;
 }