Ejemplo n.º 1
0
 /**
 Загружает данные об странице
 */
 private function loadSitemapInfo($id)
 {
     $this->sitemapRow = Sitemap_Sample::get($id);
     if (empty($this->sitemapRow)) {
         throw new Exception('Load page failed. Sitemap page with id="' . $id . '" not found');
     }
 }
Ejemplo n.º 2
0
 /**
  * Восстанавливает адрес только конкретного элемента
  *
  * @param int $sitemapId
  */
 public static function restoreOne($sitemapId, $sitemapParent = null)
 {
     $sitemap = is_array($sitemapId) ? $sitemapId : Sitemap_Sample::get($sitemapId);
     if (empty($sitemap)) {
         throw new NotFoundException('Url keeping process failed, sitemap element (' . $sitemapId . ') not found');
     }
     //
     if (is_null($sitemapParent)) {
         $sitemapParent = Sitemap_Sample::get($sitemap['parent']);
     }
     if (empty($sitemapParent)) {
         $baseUrl = self::getCurrentBaseUrl();
     } else {
         $baseUrl = $sitemapParent['full_url'];
     }
     if (self::isDomainPresentInUrlKey($sitemap)) {
         $url = $sitemap['url_key'];
     } else {
         $url = $baseUrl . $sitemap['url_key'] . '/';
     }
     // Если старый и новый адрес равны, то и менять ничего не надо
     if ($url == $sitemap['full_url']) {
         return;
     }
     // Сохраняем изменение
     $sql = 'UPDATE `%s` SET `full_url`="%s" where `id`="%d"';
     $sql = sprintf($sql, SITEMAP_TABLE, \Faid\DB::escape($url), $sitemap['id']);
     $sitemap['full_url'] = $url;
     DB::post($sql);
     //
     self::updateChildUrls($sitemap);
 }
Ejemplo n.º 3
0
 public function show($id)
 {
     // Получаем ряд
     $id = intval($id);
     $this->nId = $id;
     try {
         // Получаем детей
         $aChild = Sitemap::selectChild($id);
         if ($id != 0) {
             $aRow = Sitemap_Sample::get($id);
         } else {
             $aRow = null;
         }
         /*$aData = array();
         		foreach ($aChild as $row)
         		{
         			$aData[] = $row['id'];
         		}*/
         $aData = $aChild;
         //
         $this->formatDesign($aRow);
         // Выводим форму сортировки
         print UParser::parsePHPFile(LIB_PATH . 'sitemap/controller/tpl/order.tpl', array('szTitle' => $this->szTitle, 'aBegin' => $this->aBegin, 'id' => $id, 'back' => $this->back, 'aData' => $aData));
         $this->output();
     } catch (SiteMapException $e) {
         $this->addError(_msg('Ряд не найден в бд'));
         $this->jump('./');
     }
 }
Ejemplo n.º 4
0
 public function getAdminViewValue()
 {
     $sitemapInfo = Sitemap_Sample::get($this->aValue);
     $result = sprintf(' %s <a href="http:%s" target="_blank">[На сайте]</a>', $sitemapInfo['name'], $sitemapInfo['full_url']);
     $result .= sprintf(' <a href="%ssitemap/edit.php?id=%d" target="_blank">[К администрированию]</a>', \Extasy\CMS::getDashboardWWWRoot(), $sitemapInfo['id']);
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Отображает форму редактирования
  */
 protected function outputEditingForm($sheets, $controls)
 {
     $sheetsEmpty = false;
     if (empty($sheets)) {
         $sheetsEmpty = true;
         $sheets = array(array('id' => 'mainTab', 'title' => 'Ошибка'));
     }
     if ($this->schema->getSitemapLink()) {
         $sitemapInfo = Sitemap_Sample::get($this->schema->getSitemapLink());
         array_push($sheets, array('id' => 'sitemapTab', 'title' => 'Свойства'));
     }
     //
     $design = CMSDesign::getInstance();
     $design->forms->begin();
     // Вывод вкладок
     $design->tabs->sheetsBegin($sheets);
     // По вкладкам вывод
     $i = 0;
     if (!empty($controls)) {
         foreach ($controls as $list) {
             $design->tabs->contentBegin($sheets[$i]['id']);
             $design->table->begin();
             foreach ($list as $control) {
                 $design->table->row2cell($control->getTitle(), $control->outputInForm());
             }
             $design->table->end();
             $design->tabs->contentEnd();
             $i++;
         }
     } else {
         $design->tabs->contentBegin($sheets[0]['id']);
         $design->decor->contentBegin();
         printf('У данной схемы пока нету вкладок для редактирования<br/>');
         $auth = CMSAuth::getInstance();
         if ($auth->isSuperAdmin(UsersLogin::getCurrentUser())) {
             printf('Перейти к <a href="%scconfig/manage.php?schema=%s&edit=1">управлению</a> конфигом', \Extasy\CMS::getDashboardWWWRoot(), $this->schema->getName());
         }
         $design->decor->contentEnd();
         $design->tabs->contentEnd();
     }
     if (!empty($sitemapInfo)) {
         $auth = CMSAuth::getInstance();
         if ($auth->isSuperAdmin(UsersLogin::getCurrentUser())) {
             $link = sprintf('<a href="%scconfig/manage.php?schema=%s" target="_blank">Управление конфигом</a>', \Extasy\CMS::getDashboardWWWRoot(), $this->schema->getName());
             $property = array('' => $link);
         } else {
             $property = array();
         }
         SitemapCMSForms::outputSitemapTabSheet($sitemapInfo, $sheets[sizeof($sheets) - 1]['id'], $property);
     }
     $design->tabs->sheetsEnd();
     $design->forms->hidden('schema', $this->schema->getName());
     // Вывод конца
     $design->forms->submit('submit', 'Сохранить');
     $design->forms->end();
     $this->outputFooter();
 }
Ejemplo n.º 6
0
 public function generate()
 {
     if (!empty($this->value)) {
         $urlInfo = Sitemap_Sample::get($this->value);
     } else {
         $urlInfo = array();
     }
     $parseData = array('name' => $this->szName, 'filter' => $this->filter, 'urlInfo' => $urlInfo);
     return UParser::parsePHPFile(LIB_PATH . 'sitemap/control/select.once.tpl', $parseData);
 }
Ejemplo n.º 7
0
 /**
  * Добавляет к указанной странице доп. урл - алиас
  * @param unknown_type $id
  * @param unknown_type $newUrl
  */
 public static function addAlias($id, $newUrl)
 {
     // Удаляем из алиасов все урлы, которые совпадают, новый урл их заместит
     DBSimple::delete(SITEMAP_HISTORY_TABLE, array('url' => $newUrl));
     $page = Sitemap_Sample::get($id);
     if (empty($page)) {
         throw new SiteMapException('addAlias failed. Page with id="' . $id . '" not found');
     }
     $sql = 'INSERT INTO `%s` SET `date`=NOW(),`name`="%s",`page_id`="%s",`url`="%s"';
     $sql = sprintf($sql, SITEMAP_HISTORY_TABLE, \Faid\DB::escape($page['name']), $page['id'], \Faid\DB::escape($newUrl));
     DB::post($sql);
 }
Ejemplo n.º 8
0
 public function generate()
 {
     // Получаем сайтмап данные
     $displayValues = array();
     foreach ($this->values as $id) {
         $sitemap = Sitemap_Sample::get($id);
         if (!empty($sitemap)) {
             $displayValues[] = array($sitemap['id'], $sitemap['name'], $sitemap['full_url']);
         }
     }
     $parseData = array('name' => $this->szName, 'values' => $displayValues);
     return UParser::parsePHPFile(LIB_PATH . 'sitemap/control/select.tpl', $parseData);
 }
Ejemplo n.º 9
0
 /** 
  * Выводит форму переноса документа
  */
 public function showMove($id)
 {
     $aDocument = Sitemap_Sample::get($id);
     if (empty($aDocument['document_name'])) {
         throw new Exception('Requested id isn`t document');
     }
     $szTitle = 'Перемещение документа - ' . $aDocument['name'];
     $szTitle2 = 'Текущий URL - ' . $aDocument['full_url'];
     $aButton = array('Закрыть' => array('id' => 'close_window', 'value' => '#'));
     // Получаем список возможных скриптов, куда можем перенести
     require_once LIB_PATH . 'sitemap/additional/cms.php';
     $aMove = Sitemap_CMS::whereToMove($aDocument['document_name']);
     $this->outputForm($aDocument, $aMove, $szTitle, $szTitle2, $aButton);
 }
Ejemplo n.º 10
0
 public function main()
 {
     $aInfo = \Extasy\sitemap\Route::getCurrentUrlInfo();
     $aMenu = Sitemap_PagesOperations::selectChildWithoutAdditional($aInfo['id'], 1, 0);
     $url = '';
     if (empty($aMenu)) {
         // Получаем предка
         if (!empty($aInfo['parent'])) {
             $aParent = Sitemap_Sample::get($aInfo['parent']);
             $url .= $aParent['full_url'];
             $this->jump($url);
         } else {
             die('Parent empty');
         }
     }
     $url .= $aMenu[0]['full_url'];
     $this->jump($url);
 }
Ejemplo n.º 11
0
 /**
  * Возвращает полное список предков с их соседями, включая текущий уровень
  * @param int $nUntil указывает на каком предке остановится 
  * @param bool $bWithAdditional обозначает необходимость подгрузки доп. информации из моделей
  */
 public static function selectParentMenuToLevel($nUntil = -1, $bWithAdditional = false)
 {
     $aUrlInfo = self::getCurrentUrlInfo();
     $nCurrentId = $aUrlInfo['id'];
     $nOldId = 0;
     //
     $aResult = array();
     $aOld = array();
     // Пока не достигли конца (больше некуда подыматься, текущий уровень 0)
     while (1) {
         // Получаем детей к текущему уровню
         if ($bWithAdditional) {
             $aData = Sitemap_PagesOperations::selectChildWithAdditional($nCurrentId);
         } else {
             $aData = Sitemap_PagesOperations::selectChildWithoutAdditional($nCurrentId);
         }
         // Добавляем к текущему уровню предыдущие вычисления
         foreach ($aData as $key => $row) {
             if ($nOldId == $row['id']) {
                 // Добавляем предыдущий результат в текущий слой меню
                 $aData[$key]['current'] = 1;
                 $aData[$key]['aChild'] = $aOld;
             }
         }
         //
         if (empty($aUrlInfo) || $nCurrentId == $nUntil) {
             return $aData;
         } else {
             // Получаем новый текущий уровень
             $nOldId = $aUrlInfo['id'];
             //
             $aUrlInfo = Sitemap_Sample::get($aUrlInfo['parent']);
             //
             $nCurrentId = $aUrlInfo['id'];
         }
         $aOld = $aData;
     }
     return array();
 }
Ejemplo n.º 12
0
 /**
  * Возвращает предков меню Метод со встроенным кешем результатов
  *
  * @param int $id
  * @param int $nLimitId индекс на котором поиск остановится
  */
 public static function getParents($id, $nLimitId = 0)
 {
     static $cache = array();
     $cacheKey = $id . '_' . $nLimitId;
     if (isset($cache[$cacheKey])) {
         return $cache[$cacheKey];
     }
     $aResult = array();
     //
     $nCurrentId = intval($id);
     $nLimitId = intval($nLimitId);
     while ($nCurrentId != $nLimitId) {
         $aInfo = Sitemap_Sample::get($nCurrentId);
         if (empty($aInfo)) {
             return $aResult;
         }
         $nCurrentId = $aInfo['parent'];
         array_unshift($aResult, $aInfo);
     }
     $cache[$cacheKey] = $aResult;
     return $aResult;
 }
Ejemplo n.º 13
0
 protected function searchInHistory($url)
 {
     $found = DBSimple::get(SITEMAP_HISTORY_TABLE, array('url' => $url));
     if (!empty($found)) {
         return \Sitemap_Sample::get($found['page_id']);
     }
     return null;
 }
Ejemplo n.º 14
0
 /**
  * Тестирует вставку документа
  */
 public function testSavePage()
 {
     $nId = Sitemap::addPage('Test inserting', 'xx', TestDocument::ModelName, 1, 0);
     $data = array('document_name' => TestDocument::ModelName, 'document_id' => 1, 'name' => 'test update', 'url_key' => 'test');
     Sitemap::savePage($data);
     // Получаем запись в бд
     $urlInfo = Sitemap_Sample::get($nId);
     $this->AssertEquals($urlInfo['name'], $data['name']);
     $this->AssertEquals($urlInfo['full_url'], '///' . $data['url_key'] . '/');
 }
Ejemplo n.º 15
0
 /**
  * @param $id
  */
 public static function autoLoad($id)
 {
     $sitemapInfo = Sitemap_Sample::get($id);
     if (empty($sitemapInfo['document_name'])) {
         throw new NotFoundException('Document not found');
     }
     $document = new $sitemapInfo['document_name'](array(), $sitemapInfo);
     $found = $document->get($sitemapInfo['document_id']);
     if (empty($found)) {
         throw new NotFoundException('Sitemap document model not found ');
     }
     return $document;
 }
Ejemplo n.º 16
0
 /**
  * Проверяе доступен ли эта запись в sitemap, конфигу прописанному к скрипту
  */
 protected function checkSecurity($nId, $nParent)
 {
     $bFound = false;
     if ($nId == $this->nParent) {
         $bFound = true;
     }
     while ($nId != 0 && $this->nParent != $nId) {
         $aInfo = Sitemap_Sample::get($nParent);
         // Дошли до корня?
         if (empty($aInfo)) {
             $aInfo = array('id' => 0, 'parent' => 0);
         }
         $nId = $aInfo['id'];
         $nParent = $aInfo['parent'];
         if ($nId == $this->nParent) {
             $bFound = true;
             break;
         }
     }
     return $bFound;
 }
Ejemplo n.º 17
0
 /**
  * Выводит селект для выбора предка
  */
 protected static function outputChangeParentFormFields()
 {
     // Формируем список урлов
     $aSitemapUrl = array(array('id' => '-2', 'name' => 'Никуда не переносить'));
     // Добавляем parent, предка текущего элемента (если он есть)
     if (!empty(self::$sitemap['parent'])) {
         $aParent = Sitemap_Sample::get(self::$sitemap['parent']);
         $aSitemapUrl[] = array('id' => $aParent['parent'], 'name' => '<< Перенести на уровень выше');
     }
     // Переносим в дочерние элементы к соседям данного скрипта
     $aSibling = Sitemap_Sample::selectChild(self::$sitemap['parent']);
     if (!empty($aSibling)) {
         $aSitemapUrl[] = array('id' => -1, 'name' => 'Перенести на в дочерние страницы к соседям');
         foreach ($aSibling as $row) {
             $aSitemapUrl[] = array('id' => $row['id'], 'name' => ' >> ' . $row['name']);
         }
     }
     //
     $design = CMSDesign::getInstance();
     $control = new CSelect();
     $control->name = 'sitemap_move_id';
     $control->style = 'width:99%';
     $control->size = '10';
     $control->current = -2;
     $control->values = $aSitemapUrl;
     $design->row2cell('Перенести скрипт', $control->generate());
 }
Ejemplo n.º 18
0
 /**
  *   -------------------------------------------------------------------------------------------
  *   Обновляет информацию о скрипте
  * @return
  *   -------------------------------------------------------------------------------------------
  */
 public static function updateScript($id, $szName, $szPath, $szUrl, $nParent, $szAdminEditUrl = '', $nOrderEnable = 0)
 {
     // Защищаем данные
     $id = intval($id);
     $szName = \Faid\DB::escape($szName);
     $szUrl = \Faid\DB::escape($szUrl);
     $szPath = \Faid\DB::escape($szPath);
     $szAdminEditUrl = \Faid\DB::escape($szAdminEditUrl);
     $nParent = intval($nParent);
     $nOrderEnable = intval($nOrderEnable);
     try {
         // Получаем скрипт
         $aScript = Sitemap_Sample::get($id);
         if (empty($aScript['script'])) {
             throw new Exception('Isn`t script');
         }
     } catch (SiteMapException $e) {
         throw new SiteMapException('Update script failed. Script ("' . $szPath . '","' . $szUrl . '") not found');
     }
     // проверяем есть ли parent
     self::checkParentExists($nParent);
     // Обновляем скрипт в бд
     self::updateScriptInBD($aScript['id'], $szName, $szPath, $szUrl, $nParent, $szAdminEditUrl, $nOrderEnable);
     self::order($nParent);
     // Если мы перенесли скрипт к другому владельцу пересортируем дочерние элементы бывшего владельца
     if ($nParent != $aScript['parent']) {
         self::order($aScript['parent']);
     }
     //
     self::restoreUrl($aScript['id']);
     Sitemap_History::add($aScript['id'], $szName);
 }
Ejemplo n.º 19
0
 protected function updateScript($to, $name, $url_key)
 {
     $to = intval($to);
     try {
         $aDocument = Sitemap_Sample::get($this->aSitemap['id'], $to);
         if (!empty($aDocument['document_name'])) {
             throw new Exception('Requested id isn`t script');
         }
         // Обновляем скрипт
         Sitemap::updateScript($this->aSitemap['id'], $name, $this->aSitemap['script'], $url_key, $to >= 0 && $to != $this->aSitemap['id'] ? $to : $this->aSitemap['parent'], $this->aSitemap['script_admin_url'], $this->aSitemap['script_manual_order']);
         // Обновляем количество детей у старого и нового предка
         Sitemap::updateParentCount($this->aSitemap['id']);
         Sitemap::updateParentCount($to);
     } catch (Exception $e) {
         $this->addError('Ошибка при перемещении документа. ', $e->getMessage());
     }
 }