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; }
/** Загружает данные об странице */ 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'); } }
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('./'); } }
protected static function updateChildUrls($sitemap) { $child = Sitemap_Sample::selectChild($sitemap['id']); foreach ($child as $row) { self::restoreOne($row['id'], $sitemap); Sitemap_History::add($row['id'], $row['name']); } }
/** * Отображает форму редактирования */ 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(); }
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); }
/** * Добавляет к указанной странице доп. урл - алиас * @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); }
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); }
/** * Выводит форму переноса документа */ 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); }
/** * ------------------------------------------------------------------------------------------- * Принимает вызов, возвращает результаты поиск * @return * ------------------------------------------------------------------------------------------- */ public function search($keyword, $start, $limit, $callback) { try { $aResult = Sitemap_Sample::search($keyword, $start, $limit); $nTotal = Sitemap_Sample::getTotalCount(); $this->aOutput['totalcount'] = $nTotal; $this->aOutput['item'] = array(); foreach ($aResult as $row) { $this->aOutput['item'][] = array('id' => $row['id'], 'name' => $row['name'], 'full_url' => $row['full_url'], 'date_updated' => $row['unixtimestamp']); } } catch (Exception $e) { $this->aOutput['error'] = 'Ошибка поиска, слишком короткая фраза'; } $this->outputJSONP($callback); }
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); }
/** * Возвращает полное список предков с их соседями, включая текущий уровень * @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(); }
/** * Возвращает предков меню Метод со встроенным кешем результатов * * @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; }
protected function searchSitemap() { try { ACLUser::checkCurrentUserGrants([SitemapModel::PermissionName]); $items = \Sitemap_Sample::search($this->searchPhrase, 0, 10); } catch (\Exception $e) { $items = []; } foreach ($items as $row) { $isScript = !empty($row['script_admin_url']); $add = new SearchResultModel(); $add->title = $row['name']; $add->icon = 'glyphicon glyphicon-user'; // if (!$isScript) { $route = CMS::getInstance()->getDispatcher()->getNamed('dashboard.sitemap.manage'); $add->link = $route->buildUrl() . '?id=' . $row['id']; } else { $add->link = sprintf('http://%s%s', CMS::getDashboardWWWRoot(), $row['script_admin_url']); } $this->results[] = $add; } }
/** * Тестирует вставку документа */ 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'] . '/'); }
/** * @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; }
/** * ------------------------------------------------------------------------------------------- * Метод осуществляет поиск по карте сайте * @param string $szKeyword строка поисковая ключа * @return array * ------------------------------------------------------------------------------------------- */ public static function selectPaged($nParent, $nStart, $nLimit) { $nParent = intval($nParent); $nStart = intval($nStart); $nLimit = intval($nLimit); // $sql = 'SELECT SQL_CALC_FOUND_ROWS * FROM `%s` WHERE `parent`="%d" ORDER by `order` LIMIT %d,%d'; $sql = sprintf($sql, SITEMAP_TABLE, $nParent, $nStart, $nLimit); $aResult = DB::query($sql); $sql = 'SELECT FOUND_ROWS() as `totalcount`'; $aFound = DB::Get($sql); self::$nItemCount = ceil($aFound['totalcount'] / $nLimit); return $aResult; }
protected function returnByLevel($parentId, $level) { if ($level <= 0) { return array(); } $result = array(); $childList = Sitemap_Sample::selectChild($parentId); foreach ($childList as $row) { $result[] = $row['full_url']; if (!empty($row['count'])) { $result = array_merge($result, $this->returnByLevel($row['id'], $level - 1)); } } return $result; }
/** * Проверяе доступен ли эта запись в 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; }
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; }
/** * Выводит селект для выбора предка */ 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()); }
/** * ------------------------------------------------------------------------------------------- * Проверяет не существует ли страницы с таким именем * @return * ------------------------------------------------------------------------------------------- */ protected static function checkByName($nParent, $szName) { $aResult = Sitemap_Sample::getByNameAndParent($nParent, $szName); if (!empty($aResult)) { throw new SiteMapException('Page with name "' . $szName . '" already exists'); } }
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()); } }