Beispiel #1
0
 protected function loadData()
 {
     $result = [];
     $filteredIDs = true;
     if ($this->getParam('tags')) {
         $filteredIDs = TagManager::getFilter($this->getParam('tags'), 'share_sites');
     }
     if (!empty($filteredIDs)) {
         foreach (E()->getSiteManager() as $siteID => $site) {
             if ($filteredIDs !== true && in_array($siteID, $filteredIDs) || $filteredIDs === true) {
                 $result[] = ['site_id' => $site->id, 'site_name' => $site->name, 'site_host' => $site->protocol . '://' . $site->host . ($site->port != 80 ? ':' . $site->port : '') . $site->root];
             }
         }
     }
     return $result;
 }
 /**
  * @copydoc FeedEditor::autoCompleteTags
  *
  * @throws SystemException 'ERR_NO_DATA'
  */
 protected function autoCompleteTags()
 {
     $b = new JSONCustomBuilder();
     $this->setBuilder($b);
     try {
         if (!isset($_POST['value'])) {
             throw new SystemException('ERR_NO_DATA', SystemException::ERR_CRITICAL);
         } else {
             $tags = TagManager::getTagStartedWith($_POST['value'], 10);
             $result['result'] = true;
             if (is_array($tags) && !empty($tags)) {
                 foreach ($tags as $tag) {
                     $result['data'][] = array('key' => $tag, 'value' => $tag);
                 }
             }
         }
     } catch (\Exception $e) {
         $result = array('result' => false, 'data' => false, 'errors' => array());
     }
     $b->setProperties($result);
 }
 protected function loadData()
 {
     $sitemap = E()->getMap();
     $data = $sitemap->getInfo();
     $this->filteredIDs = true;
     if (!empty($data)) {
         if ($this->getParam('tags')) {
             $this->filteredIDs = TagManager::getFilter($this->getParam('tags'), 'share_sitemap');
         }
         if (!empty($this->filteredIDs)) {
             reset($data);
             while (list($key, $value) = each($data)) {
                 if ($this->filteredIDs !== true && !in_array($key, $this->filteredIDs)) {
                     unset($data[$key]);
                     continue;
                 }
                 if ($key == $sitemap->getDefault()) {
                     unset($data[$key]);
                 } else {
                     $data[$key]['Id'] = $key;
                     $data[$key]['Segment'] = $sitemap->getURLByID($key);
                     $data[$key]['Name'] = $value['Name'];
                     $data[$key]['Redirect'] = Response::prepareRedirectURL($value['RedirectUrl']);
                 }
             }
         } else {
             $data = array();
         }
     }
     return $data;
 }
Beispiel #4
0
 /**
  * @copydoc DataSet::loadData
  */
 protected function loadData()
 {
     $sitemap = E()->getMap();
     $methodName = 'getChilds';
     if ($this->getParam('recursive')) {
         $methodName = 'getDescendants';
     }
     if (is_numeric($this->getParam('id'))) {
         $param = (int) $this->getParam('id');
         $sitemap = E()->getMap(E()->getSiteManager()->getSiteByPage($param)->id);
     } elseif ($this->getParam('id') == self::PARENT_PAGE) {
         $param = $sitemap->getParent($this->document->getID());
     } elseif ($this->getParam('id') == self::CURRENT_PAGE) {
         $param = $this->document->getID();
     } elseif ($this->getParam('id') == self::ALL_PAGES) {
         $methodName = 'getInfo';
         $param = NULL;
         if (!($siteId = $this->getParam('site'))) {
             $siteId = E()->getSiteManager()->getCurrentSite()->id;
         }
         $sitemap = E()->getMap($siteId);
     } elseif (!$this->getParam('id')) {
         if ($this->getParam('site')) {
             $sitemap = E()->getMap($this->getParam('site'));
         }
         $param = $sitemap->getDefault();
     } else {
         if ($this->getParam('site')) {
             $sitemap = E()->getMap($this->getParam('site'));
         }
         $param = $sitemap->getPagesByTag($this->getParam('id'));
         if (!empty($param)) {
             list($param) = $param;
         }
     }
     $data = call_user_func([$sitemap, $methodName], $param);
     if (!empty($data)) {
         if ($this->getParam('recursive')) {
             $this->getBuilder()->setTree($sitemap->getChilds($param, true));
         }
         $hasDescriptionRtf = (bool) $this->getDataDescription()->getFieldDescriptionByName('DescriptionRtf');
         //По умолчанию - фильтрация отсутствует
         $filteredIDs = true;
         if ($this->getParam('tags')) {
             $filteredIDs = TagManager::getFilter($this->getParam('tags'), 'share_sitemap');
         }
         reset($data);
         while (list($key, $value) = each($data)) {
             if ($filteredIDs !== true && is_array($filteredIDs) && !in_array($key, $filteredIDs)) {
                 unset($data[$key]);
                 continue;
             }
             if ($key == $sitemap->getDefault() && $this->getParam('id') != self::ALL_PAGES) {
                 unset($data[$key]);
             } else {
                 $data[$key]['Id'] = $key;
                 $data[$key]['Segment'] = E()->getMap($data[$key]['Site'])->getURLByID($key);
                 $data[$key]['Name'] = $value['Name'];
                 $data[$key]['Redirect'] = Response::prepareRedirectURL($value['RedirectUrl']);
                 $data[$key]['Site'] = E()->getSiteManager()->getSiteByID($data[$key]['Site'])->base;
                 if ($hasDescriptionRtf) {
                     $data[$key]['DescriptionRtf'] = $value['DescriptionRtf'];
                 }
             }
         }
         //stop($data);
     } else {
         $this->setBuilder(new SimpleBuilder());
     }
     return $data;
 }
Beispiel #5
0
 /**
  * Create calendar.
  * Calendar helps to navigate over the news.
  */
 protected function createCalendar()
 {
     $calendarParams = array();
     $ap = $this->getStateParams(true);
     if ($this->getState() == 'main') {
         if (isset($ap['year']) && isset($ap['month']) && isset($ap['day'])) {
             if ($this->getParam('hasCalendar')) {
                 $calendarParams['month'] = $ap['month'];
                 $calendarParams['year'] = $ap['year'];
                 $calendarParams['date'] = \DateTime::createFromFormat('Y-m-d', $ap['year'] . '-' . $ap['month'] . '-' . $ap['day']);
             }
             $additionalFilter = 'DAY(news_date) = "' . $ap['day'] . '" AND MONTH(news_date) = "' . $ap['month'] . '" AND YEAR(news_date) = "' . $ap['year'] . '"';
         } elseif (isset($ap['year']) && isset($ap['month'])) {
             if ($this->getParam('hasCalendar')) {
                 $calendarParams['month'] = $ap['month'];
                 $calendarParams['year'] = $ap['year'];
             }
             $additionalFilter = 'MONTH(news_date) = "' . $ap['month'] . '" AND YEAR(news_date) = "' . $ap['year'] . '"';
         } elseif (isset($ap['year'])) {
             if ($this->getParam('hasCalendar')) {
                 $calendarParams['year'] = $ap['year'];
             }
             $additionalFilter = 'YEAR(news_date) = "' . $ap['year'] . '"';
         }
         if ($this->getParam('tags')) {
             $filteredIDs = TagManager::getFilter($this->getParam('tags'), $this->getTableName());
             if (!empty($filteredIDs)) {
                 $this->addFilterCondition(array($this->getTableName() . '.news_id' => $filteredIDs));
             } else {
                 $this->addFilterCondition(array($this->getTableName() . '.news_id' => 0));
             }
         }
     } elseif ($this->getState() == 'view' && $this->getParam('hasCalendar')) {
         $calendarParams['month'] = $ap['month'];
         $calendarParams['year'] = $ap['year'];
         $calendarParams['date'] = \DateTime::createFromFormat('Y-m-d', $ap['year'] . '-' . $ap['month'] . '-' . $ap['day']);
     }
     if ($this->getParam('hasCalendar')) {
         $calendarParams['filter'] = $this->getFilter();
         $calendarParams['tableName'] = $this->getTableName();
         //Создаем компонент календаря новостей
         $this->document->componentManager->addComponent($this->calendar = $this->document->componentManager->createComponent('calendar', 'Energine\\apps\\components\\NewsCalendar', $calendarParams));
     }
     if (isset($additionalFilter)) {
         $this->addFilterCondition($additionalFilter);
     }
 }
Beispiel #6
0
 /**
  * @copydoc Feed::main
  */
 protected function main()
 {
     parent::main();
     $m = new AttachmentManager($this->getDataDescription(), $this->getData(), $this->getTableName());
     $m->createFieldDescription();
     $m->createField($this->getPK(), true);
     $m = new TagManager($this->getDataDescription(), $this->getData(), $this->getTableName());
     $m->createFieldDescription();
     $m->createField();
 }
Beispiel #7
0
 protected function prepare()
 {
     parent::prepare();
     if (in_array($this->getState(), array('add', 'edit'))) {
         $fd = new FieldDescription('domains');
         $fd->setType(FieldDescription::FIELD_TYPE_TAB);
         $fd->setProperty('title', $this->translate('TAB_DOMAINS'));
         $this->getDataDescription()->addFieldDescription($fd);
         $field = new Field('domains');
         $state = $this->getState();
         $tab_url = ($state != 'add' ? $this->getData()->getFieldByName($this->getPK())->getRowData(0) : '') . '/domains/';
         $field->setData($tab_url, true);
         $this->getData()->addField($field);
         $fd = $this->getDataDescription()->getFieldDescriptionByName('site_folder');
         $fd->setType(FieldDescription::FIELD_TYPE_SELECT);
         $fd->loadAvailableValues($this->loadFoldersData(), 'key', 'value');
         if ($this->getData()->getFieldByName('site_is_default')->getRowData(0) == 1) {
             $this->getDataDescription()->getFieldDescriptionByName('site_is_default')->setMode(FieldDescription::FIELD_MODE_READ);
         }
         $tagField = new FieldDescription('tags');
         $tagField->setType(FieldDescription::FIELD_TYPE_STRING);
         $tagField->removeProperty('pattern');
         $this->getDataDescription()->addFieldDescription($tagField);
         if ($this->getState() == 'add') {
             //Добавляем селект позволяющий скопировать структуру одного из существующих сайтов в новый
             $fd = new FieldDescription('copy_site_structure');
             $fd->setType(FieldDescription::FIELD_TYPE_SELECT);
             $fd->loadAvailableValues($this->dbh->select('SELECT ss.site_id, site_name FROM share_sites ss LEFT JOIN share_sites_translation sst ON ss.site_id = sst.site_id WHERE lang_id =%s ', $this->document->getLang()), 'site_id', 'site_name');
             $this->getDataDescription()->addFieldDescription($fd);
         } else {
             $this->getDataDescription()->getFieldDescriptionByName($this->getPK())->setType(FieldDescription::FIELD_TYPE_INT)->setMode(FieldDescription::FIELD_MODE_READ);
             $tm = new TagManager($this->getDataDescription(), $this->getData(), $this->getTableName());
             $tm->createFieldDescription();
             $tm->createField();
         }
     }
 }
 /**
  * @copydoc Grid::edit
  */
 protected function edit()
 {
     parent::edit();
     $this->buildRightsTab($smapID = $this->getData()->getFieldByName('smap_id')->getRowData(0));
     //Выводим УРЛ в поле сегмента
     $field = $this->getData()->getFieldByName('smap_pid');
     $site = E()->getSiteManager()->getSiteByID($this->getData()->getFieldByName('site_id')->getRowData(0));
     foreach ([Document::TMPL_CONTENT, Document::TMPL_LAYOUT] as $type) {
         if ($f = $this->getDataDescription()->getFieldDescriptionByName('smap_' . $type)) {
             $f->setType(FieldDescription::FIELD_TYPE_SELECT);
             $old_value = $this->getData()->getFieldByName('smap_' . $type)->getRowData(0);
             $template_data = $this->loadTemplateData($type, $site->folder, $old_value);
             $f->loadAvailableValues($template_data, 'key', 'value');
         }
     }
     //Если изменен  - вносим исправления в список возможных значений
     if ($contentXMLFieldData = $this->dbh->getScalar($this->getTableName(), 'smap_content_xml', ['smap_id' => $this->getData()->getFieldByName('smap_id')->getRowData(0)])) {
         $contentFilename = $this->getData()->getFieldByName('smap_content')->getRowData(0);
         $contentFD = $this->getDataDescription()->getFieldDescriptionByName('smap_content');
         $contentFD->setProperty('reset', $this->translate('TXT_RESET_CONTENT'));
         $av =& $contentFD->getAvailableValues();
         if (isset($av[$contentFilename])) {
             $av[$contentFilename]['value'] .= ' - ' . $this->translate('TXT_CHANGED');
         }
         $newField = new FieldDescription('smap_content_xml');
         $newField->setProperty('nullable', true);
         $newField->setType(FieldDescription::FIELD_TYPE_CODE);
         $newField->setProperty('tableName', $this->getTableName());
         $newField->setProperty('tabName', $contentFD->getPropertyValue('tabName'));
         $this->getDataDescription()->addFieldDescription($newField, DataDescription::FIELD_POSITION_AFTER, 'smap_content');
         $newField = new Field('smap_content_xml');
         $doc = new \DOMDocument();
         $doc->loadXML($contentXMLFieldData);
         $doc->formatOutput = true;
         $doc->preserveWhiteSpace = true;
         $newField->setData($doc->saveXML(null, LIBXML_NOEMPTYTAG), true);
         $this->getData()->addField($newField);
         unset($contentFilename, $contentFD, $av, $doc, $newField);
     }
     $smapSegment = '';
     if ($field->getRowData(0) !== null) {
         $smapSegment = E()->getMap($site->id)->getURLByID($field->getRowData(0));
         $this->getDataDescription()->getFieldDescriptionByName('smap_segment')->removeProperty('nullable');
     } else {
         $this->getDataDescription()->getFieldDescriptionByName('smap_pid')->setMode(FieldDescription::FIELD_MODE_READ)->setType(FieldDescription::FIELD_TYPE_HIDDEN);
         foreach (['smap_is_disabled', 'smap_segment', 'smap_redirect_url', 'smap_meta_robots', 'smap_meta_keywords', 'smap_meta_description'] as $fieldName) {
             if ($f = $this->getDataDescription()->getFieldDescriptionByName($fieldName)) {
                 $this->getDataDescription()->removeFieldDescription($f);
             }
         }
     }
     $smapName = $this->dbh->getScalar($this->getTranslationTableName(), 'smap_name', ['smap_id' => $field->getRowData(0), 'lang_id' => $this->document->getLang()]);
     for ($i = 0; $i < ($langs = count(E()->getLanguage()->getLanguages())); $i++) {
         $field->setRowProperty($i, 'data_name', $smapName);
         $field->setRowProperty($i, 'segment', $smapSegment);
     }
     $tm = new TagManager($this->getDataDescription(), $this->getData(), $this->getTableName());
     $tm->createFieldDescription();
     $tm->createField();
     $this->getDataDescription()->getFieldDescriptionByName('smap_id')->setType(FieldDescription::FIELD_TYPE_INT)->setMode(FieldDescription::FIELD_MODE_READ);
     if (class_exists('AdsManager', false) && AdsManager::isActive()) {
         $ads = new AdsManager();
         $ads->edit($this->getData(), $this->getDataDescription());
     }
 }
Beispiel #9
0
 /**
  * Get tags.
  */
 protected function getTags()
 {
     $builder = new JSONCustomBuilder();
     $this->setBuilder($builder);
     $tag_id = !empty($_REQUEST['tag_id']) ? $_REQUEST['tag_id'] : '';
     $tag_id = array_filter(array_map(create_function('$tag', 'return intval(trim($tag));'), explode(TagManager::TAG_SEPARATOR, $tag_id)));
     if ($tag_id) {
         $tags = TagManager::getTags($tag_id);
         if ($tags) {
             $tags = array_values($tags);
         }
     } else {
         $tags = array();
     }
     $builder->setProperties(array('data' => $tags));
 }