Exemple #1
0
 private function processMetaInfo()
 {
     /* hotfix - add static pages for ajax */
     $staticDocs = BOL_NavigationService::getInstance()->findAllStaticDocuments();
     $staticPageDispatchAttrs = OW::getRequestHandler()->getStaticPageAttributes();
     /* @var $value BOL_Document */
     foreach ($staticDocs as $value) {
         OW::getRouter()->addRoute(new OW_Route($value->getKey(), $value->getUri(), $staticPageDispatchAttrs['controller'], $staticPageDispatchAttrs['action'], array('documentKey' => array(OW_Route::PARAM_OPTION_HIDDEN_VAR => $value->getKey()))));
     }
     /* ------------------------------ */
     $language = OW::getLanguage();
     // edit route path
     if (!empty($_POST['routeName']) && !empty($_POST['url'])) {
         $urlUpdArr = json_decode($_POST['url'], true);
         // suuport only latin chars and '-' symbol
         if (preg_match("/[^a-zA-Z0-9\\-]+/", implode('', $urlUpdArr))) {
             throw new Exception(OW::getLanguage()->text('oaseo', 'use_only_latin_for_urls'));
         }
         foreach ($urlUpdArr as $item) {
             if (strlen($item) < 1) {
                 throw new Exception(OW::getLanguage()->text('oaseo', 'url_empty_path_element'));
             }
         }
         $route = OW::getRouter()->getRoute($_POST['routeName']);
         if ($route !== null) {
             $urlDto = $this->metaService->findUrlByRouteName($route->getRouteName());
             $rtArr = (array) $route;
             $path = empty($urlDto) ? $rtArr["OW_RouteroutePath"] : $urlDto->getUrl();
             $pathArr = explode('/', $path);
             $pathUpdate = false;
             foreach ($pathArr as $pathKey => $pathItem) {
                 if (strstr($pathItem, ':')) {
                     continue;
                 }
                 $currPathItem = array_shift($urlUpdArr);
                 if ($pathItem != $currPathItem) {
                     $pathArr[$pathKey] = $currPathItem;
                     $pathUpdate = true;
                 }
             }
             if ($pathUpdate) {
                 if ($urlDto === null) {
                     $urlDto = new OASEO_BOL_Url();
                     $urlDto->setRouteName($route->getRouteName());
                 }
                 $urlDto->setUrl(implode('/', $pathArr));
                 $this->metaService->saveUrl($urlDto);
             }
         }
     }
     // edit meta info
     $entryArr = array();
     if (!empty($_POST['title'])) {
         $entryArr['title'] = trim($_POST['title']);
     }
     if (!empty($_POST['desc'])) {
         $entryArr['desc'] = trim($_POST['desc']);
     }
     if (!empty($_POST['keywords'])) {
         $entryArr['keywords'] = $_POST['keywords'];
     }
     if (!empty($entryArr)) {
         /* spec case for empty URI */
         if (in_array(trim($_POST['uri']), array('', '/'))) {
             $item = BOL_NavigationService::getInstance()->findFirstLocal(OW::getUser()->isAuthenticated() ? BOL_NavigationService::VISIBLE_FOR_MEMBER : BOL_NavigationService::VISIBLE_FOR_GUEST);
             if ($item !== null) {
                 if ($item->getRoutePath()) {
                     $route = OW::getRouter()->getRoute($item->getRoutePath());
                     $dispatchAttrs = $route->getDispatchAttrs();
                 } else {
                     $dispatchAttrs = OW::getRequestHandler()->getStaticPageAttributes();
                 }
             } else {
                 $dispatchAttrs = array('controller' => 'BASE_CTRL_ComponentPanel', 'action' => 'index');
             }
         } else {
             $dispatchAttrs = $this->metaService->getDispatchParamsForUri(trim($_POST['uri']));
         }
         $entry = $this->metaService->getEntryForDispatchParams($dispatchAttrs);
         if ($entry === null) {
             $entry = new OASEO_BOL_Meta();
             $entry->setKey($this->metaService->generateKey($dispatchAttrs));
             $entry->setUri(trim($_POST['uri']));
             $entry->setDispatchAttrs(json_encode($dispatchAttrs));
         }
         $entry->setMeta(json_encode($entryArr));
         $this->metaService->saveEntry($entry);
     }
 }