Пример #1
0
 public function process($params)
 {
     $service = BOL_NavigationService::getInstance();
     /* @var $service BOL_NavigationService */
     $menuItem = new BOL_MenuItem();
     $doc_key = UTIL_HtmlTag::generateAutoId('page');
     $menuItem->setDocumentKey($doc_key);
     $menuItem->setPrefix('base');
     $menuItem->setKey($doc_key);
     $menuItem->setType($params['type']);
     $order = $service->findMaxSortOrderForMenuType($params['type']);
     $order;
     $menuItem->setOrder($order);
     $visibleFor = 0;
     $arr = !empty($_POST['visible-for']) ? $_POST['visible-for'] : array();
     foreach ($arr as $val) {
         $visibleFor += $val;
     }
     //hotfix
     if ($visibleFor === 0) {
         $visibleFor = 3;
     }
     $menuItem->setVisibleFor($visibleFor);
     $url = '';
     $languageService = BOL_LanguageService::getInstance();
     $prefixDto = $languageService->findPrefix($menuItem->getPrefix());
     switch ($_POST['type']) {
         case 'local':
             $service->saveMenuItem($menuItem);
             $document = new BOL_Document();
             $document->setIsStatic(true);
             $document->setKey($menuItem->getKey());
             $url = str_replace(UTIL_String::removeFirstAndLastSlashes(OW::getRouter()->getBaseUrl()), '', UTIL_String::removeFirstAndLastSlashes($_POST['local-url']));
             $document->setUri(UTIL_String::removeFirstAndLastSlashes($url));
             $service->saveDocument($document);
             //- name
             $currentLanguageId = $languageService->getCurrent()->getId();
             $keyDto = $languageService->addKey($prefixDto->getId(), $menuItem->getKey());
             $menuName = $_POST['name'];
             $languageService->addValue($currentLanguageId, $menuItem->getPrefix(), $keyDto->getKey(), $menuName);
             //- title
             $keyDto = $languageService->addKey($prefixDto->getId(), 'local_page_title_' . $menuItem->getKey());
             $title = empty($_POST['title']) ? '' : $_POST['title'];
             $languageService->addValue($currentLanguageId, $menuItem->getPrefix(), $keyDto->getKey(), $title);
             //-	meta tags
             $keyDto = $languageService->addKey($prefixDto->getId(), 'local_page_meta_tags_' . $menuItem->getKey());
             $metaTagsStr = empty($_POST['meta-tags']) ? '' : $_POST['meta-tags'];
             $languageService->addValue($currentLanguageId, $menuItem->getPrefix(), $keyDto->getKey(), $metaTagsStr);
             //- content
             $keyDto = $languageService->addKey($prefixDto->getId(), 'local_page_content_' . $menuItem->getKey());
             $contentStr = empty($_POST['content']) ? '' : $_POST['content'];
             $languageService->addValue($currentLanguageId, $menuItem->getPrefix(), $keyDto->getKey(), $contentStr);
             //~
             $languageService->generateCache($currentLanguageId);
             break;
         case 'external':
             $menuItem->setExternalUrl($_POST['external-url']);
             $menuItem->setNewWindow(!empty($_POST['ext-open-in-new-window']) && $_POST['ext-open-in-new-window'] == 'on' ? true : false);
             $service->saveMenuItem($menuItem);
             $keyDto = $languageService->addKey($prefixDto->getId(), $menuItem->getKey());
             $languageService->addValue($languageService->getCurrent()->getId(), $menuItem->getPrefix(), $keyDto->getKey(), $_POST['name']);
             $languageService->generateCache($languageService->getCurrent()->getId());
             break;
     }
     header('location: ' . OW::getRouter()->urlForRoute('admin_pages_main'));
     exit;
 }
 /**
  * 
  * @param string $menu
  * @param int $order
  * @return BOL_MenuItem
  */
 public function createEmptyItem($menu, $order)
 {
     $menuItem = new BOL_MenuItem();
     $documentKey = UTIL_HtmlTag::generateAutoId('mobile_page');
     $menuItem->setDocumentKey($documentKey);
     $menuItem->setPrefix(self::MENU_PREFIX);
     $menuItem->setKey($documentKey);
     $menuItem->setType($menu);
     $menuItem->setOrder($order);
     $this->navigationService->saveMenuItem($menuItem);
     $document = new BOL_Document();
     $document->isStatic = true;
     $document->isMobile = true;
     $document->setKey($menuItem->getKey());
     $document->setUri($menuItem->getKey());
     $this->navigationService->saveDocument($document);
     $document->setUri("cp-" . $document->getId());
     $this->navigationService->saveDocument($document);
     $this->editItem($menuItem, array(self::SETTING_LABEL => OW::getLanguage()->text("mobile", "admin_nav_default_menu_name"), self::SETTING_TITLE => OW::getLanguage()->text("mobile", "admin_nav_default_page_title"), self::SETTING_CONTENT => OW::getLanguage()->text("mobile", "admin_nav_default_page_content"), self::SETTING_VISIBLE_FOR => 3, self::SETTING_TYPE => "local", self::SETTING_URL => null));
     return $menuItem;
 }
Пример #3
0
 public function __construct($name, BOL_MenuItem $menu)
 {
     parent::__construct($name);
     $navigationService = BOL_NavigationService::getInstance();
     $document = $navigationService->findDocumentByKey($menu->getDocumentKey());
     if ($document === null) {
         $document = new BOL_Document();
         $document->setKey($menu->getDocumentKey());
     }
     $language = OW_Language::getInstance();
     $languageService = BOL_LanguageService::getInstance();
     $currentLanguageId = $languageService->getCurrent()->getId();
     $plugin = OW::getPluginManager()->getPlugin('base');
     $adminPlugin = OW::getPluginManager()->getPlugin('admin');
     $nameTextField = new TextField('name');
     $langValueDto = $languageService->getValue($currentLanguageId, $plugin->getKey(), $menu->getKey());
     $langValue = $langValueDto === null ? '' : $language->text($plugin->getKey(), $menu->getKey());
     $this->addElement($nameTextField->setValue($langValue)->setLabel(OW::getLanguage()->text('admin', 'pages_edit_local_menu_name'))->setRequired());
     $titleTextField = new TextField('title');
     $langValueDto = $languageService->getValue($currentLanguageId, $plugin->getKey(), 'local_page_title_' . $menu->getKey());
     $langValue = $langValueDto === null ? '' : $language->text($plugin->getKey(), 'local_page_title_' . $menu->getKey());
     $this->addElement($titleTextField->setValue($langValue)->setLabel(OW::getLanguage()->text('admin', 'pages_edit_local_page_title'))->setRequired(true));
     $urlTextField = new TextField('url');
     $urlTextField->addValidator(new LocalPageUniqueValidator($document->getUri()));
     $this->addElement($urlTextField->setValue($document->getUri())->setLabel(OW::getLanguage()->text('admin', 'pages_edit_local_page_url'))->setRequired(true));
     $visibleForCheckboxGroup = new CheckboxGroup('visible-for');
     $visibleFor = $menu->getVisibleFor();
     $options = array('1' => OW::getLanguage()->text('admin', 'pages_edit_visible_for_guests'), '2' => OW::getLanguage()->text('admin', 'pages_edit_visible_for_members'));
     $values = array();
     foreach ($options as $value => $option) {
         if (!($value & $visibleFor)) {
             continue;
         }
         $values[] = $value;
     }
     $this->addElement($visibleForCheckboxGroup->setOptions($options)->setValue($values)->setLabel(OW::getLanguage()->text('admin', 'pages_edit_local_visible_for')));
     $metaTagsTextarea = new Textarea('meta-tags');
     $langValueDto = $languageService->getValue($currentLanguageId, $plugin->getKey(), 'local_page_meta_tags_' . $menu->getKey());
     $langValue = $langValueDto === null ? '' : $language->text($plugin->getKey(), 'local_page_meta_tags_' . $menu->getKey());
     $this->addElement($metaTagsTextarea->setLabel('Page meta tags')->setValue($langValue)->setDescription(OW::getLanguage()->text('admin', 'pages_page_field_meta_desc'))->setId('meta-tags'));
     $contentTextArea = new Textarea('content');
     $contentTextArea->setDescription(OW::getLanguage()->text('admin', 'pages_page_field_content_desc', array('src' => OW::getThemeManager()->getCurrentTheme()->getStaticImagesUrl() . 'question.png', 'url' => '#')));
     $langValueDto = $languageService->getValue($currentLanguageId, $plugin->getKey(), 'local_page_content_' . $menu->getKey());
     $langValue = $langValueDto === null ? '' : $language->text($plugin->getKey(), 'local_page_content_' . $menu->getKey());
     $this->addElement($contentTextArea->setLabel(OW::getLanguage()->text('admin', 'pages_edit_local_page_content'))->setValue($langValue)->setId('content'));
     $saveSubmit = new Submit('save');
     $this->addElement($saveSubmit->setValue($language->text($adminPlugin->getKey(), 'save_btn_label')));
 }