Пример #1
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        );");
     }
 }