public function beforeSave(Event $event, Attribute $attribute) { if (!$attribute->language_id) { $attribute->language_id = Wasabi::contentLanguage()->id; } if ($attribute->content === '') { $attribute->content = null; } }
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(); }
/** * 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); }
/** * 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>'; }
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); }
/** * 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'); }
/** * 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; }