Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * @return Constructor.
  */
 public function __construct($metaData, $uri, $frontend = true)
 {
     parent::__construct();
     $this->metaService = OASEO_BOL_Service::getInstance();
     $language = OW::getLanguage();
     $uriArray = parse_url($uri);
     $uri = !empty($uriArray['path']) ? $uriArray['path'] : '';
     // need to get uri if url provided
     if (substr($uri, 0, 7) == 'http://') {
         $uri = substr($uri, strlen(OW_URL_HOME));
     } elseif (UTIL_String::removeFirstAndLastSlashes(substr($uri, 0, strlen(OW_URL_HOME) - 7)) == UTIL_String::removeFirstAndLastSlashes(substr(OW_URL_HOME, 7))) {
         $uri = UTIL_String::removeFirstAndLastSlashes(substr($uri, strlen(OW_URL_HOME) - 7));
     } else {
         $uri = trim($uri);
     }
     $metaData['routeData'] = $this->metaService->getRouteData($uri);
     $dispatchAttrs = $this->metaService->getDispatchParamsForUri($uri);
     if ($dispatchAttrs === false) {
         $this->assign('no_compile', true);
         return;
     }
     $entry = $this->metaService->getEntryForDispatchParams($dispatchAttrs);
     if ($entry !== null) {
         $metaArr = json_decode($entry->getMeta(), true);
         if (isset($metaArr['title'])) {
             $titleString = $metaArr['title'];
         }
         if (isset($metaArr['keywords'])) {
             $keywords = $metaArr['keywords'];
         }
         if (isset($metaArr['desc'])) {
             $descString = $metaArr['desc'];
         }
     }
     if (!isset($titleString)) {
         $titleString = $metaData['title'];
     }
     if (!isset($keywords)) {
         $keywords = explode(',', $metaData['keywords']);
         $keywords = array_map('trim', $keywords);
     }
     if (!isset($descString)) {
         $descString = $metaData['desc'];
     }
     $form = new Form('meta_edit');
     $form->setAction(OW::getRouter()->urlFor('OASEO_CTRL_Base', 'updateMeta'));
     $form->setAjax();
     $form->setAjaxResetOnSuccess(false);
     $this->addForm($form);
     $title = new TextField('title');
     $title->setLabel($language->text('oaseo', 'meta_edit_form_title_label'));
     $title->setDescription($language->text('oaseo', 'meta_edit_form_title_fr_desc'));
     $title->setValue($titleString);
     $form->addElement($title);
     $keyword = new OA_CCLASS_TagsField('keywords');
     $keyword->setLabel($language->text('oaseo', 'meta_edit_form_keyword_label'));
     $keyword->setDescription($language->text('oaseo', 'meta_edit_form_keyword_fr_desc'));
     $keyword->setValue($keywords);
     $form->addElement($keyword);
     $desc = new Textarea('desc');
     $desc->setLabel($language->text('oaseo', 'meta_edit_form_desc_label'));
     $desc->setDescription($language->text('oaseo', 'meta_edit_form_desc_fr_desc'));
     $desc->setValue($descString);
     $form->addElement($desc);
     $hidTitle = new HiddenField('hidTitle');
     $hidTitle->setValue($titleString);
     $form->addElement($hidTitle);
     $hidKeyword = new HiddenField('hidKeywords');
     $hidKeyword->setValue(implode('+|+', $keywords));
     $form->addElement($hidKeyword);
     $hidDesc = new HiddenField('hidDesc');
     $hidDesc->setValue($descString);
     $form->addElement($hidDesc);
     if (!empty($metaData['routeData']) && $uri && $dispatchAttrs['controller'] != 'BASE_CTRL_StaticDocument') {
         $this->assign('urlAvail', true);
         $urlField = new OASEO_UrlField('url');
         $urlField->setValue($metaData['routeData']['path']);
         $urlField->setLabel($language->text('oaseo', 'meta_edit_form_url_label'));
         $urlField->setDescription($language->text('oaseo', 'meta_edit_form_url_desc'));
         $form->addElement($urlField);
         $routeName = new HiddenField('routeName');
         $routeName->setValue($metaData['routeData']['name']);
         $form->addElement($routeName);
     }
     $uriEl = new HiddenField('uri');
     $uriEl->setValue($uri);
     $form->addElement($uriEl);
     $submit = new Submit('submit');
     $submit->setValue($language->text('oaseo', 'meta_edit_form_submit_label'));
     $form->addElement($submit);
     $id = uniqid();
     $this->assign('id', $id);
     $this->assign('frontend', $frontend);
     $form->bindJsFunction('success', "function(data){if(data.status){OW.info(data.msg);window.oaseoFB.close();}else{OW.error(data.msg);}}");
     if ($frontend) {
         OW::getDocument()->addOnloadScript("\$('#aoseo_button_{$id}').click(\n            function(){\n                window.oaseoFB = new OA_FloatBox({\n                \$title: '{$language->text('oaseo', 'meta_edit_form_cmp_title')}',\n                \$contents: \$('#oaseo_edit_form_{$id}'),\n                width: 900,\n                icon_class: 'ow_ic_gear'\n            });\n            }\n        );");
     }
 }