You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
2.9 KiB
137 lines
2.9 KiB
<?php |
|
|
|
/** |
|
* AVE.cms - Модуль Карта сайта |
|
* |
|
* @package AVE.cms |
|
* @subpackage module_SiteMap |
|
* @filesource |
|
*/ |
|
|
|
if(!defined('BASE_DIR')) exit; |
|
|
|
/** |
|
* Функция вывода карты сайта |
|
* |
|
* @param int $navi_ids - идентификатор меню навигации |
|
* или нескольких меню указанных через запятую |
|
* для формирования карты сайта. |
|
* Если идентификатор не указан используются все меню |
|
*/ |
|
function mod_sitemap($navi_ids = '') |
|
{ |
|
global $AVE_DB; |
|
|
|
if (!empty($navi_ids)) |
|
{ |
|
$sql = array(); |
|
|
|
$navi_ids = explode(',', $navi_ids); |
|
|
|
foreach ($navi_ids as $navi_id) |
|
{ |
|
if (is_numeric($navi_id) && check_navi_permission($navi_id)) |
|
{ |
|
array_push($sql, |
|
"( |
|
SELECT * |
|
FROM " . PREFIX . "_navigation_items |
|
WHERE status = '1' |
|
AND navigation_id = " . $navi_id . " |
|
ORDER BY position ASC |
|
)" |
|
); |
|
} |
|
} |
|
|
|
$sql = implode(' UNION ', $sql); |
|
|
|
if (empty($sql)) return; |
|
} |
|
else |
|
{ |
|
$navigations = get_navigations(); |
|
|
|
if (empty($navigations)) return; |
|
|
|
$navi_in = array(); |
|
foreach ($navigations as $navigation) |
|
{ |
|
if (in_array(UGROUP, $navigation->navi_user_group)) |
|
{ |
|
array_push($navi_in, $navigation->id); |
|
} |
|
} |
|
|
|
if (sizeof($navi_in)) { |
|
$sql = " |
|
SELECT * |
|
FROM " . PREFIX . "_navigation_items |
|
WHERE status = '1' |
|
AND navigation_id IN(" . implode(',', $navi_in) . ") |
|
ORDER BY navigation_id ASC, position ASC |
|
"; |
|
} |
|
else |
|
{ |
|
return; |
|
} |
|
} |
|
|
|
$nav_items = array(); |
|
$sql = $AVE_DB->Query($sql); |
|
while ($row_nav_item = $sql->FetchAssocArray()) |
|
{ |
|
$nav_items[$row_nav_item['parent_id']][] = $row_nav_item; |
|
} |
|
|
|
$sitemap = ''; |
|
if (sizeof($nav_items)) |
|
{ |
|
printSitemap($nav_items, $sitemap); |
|
} |
|
|
|
echo $sitemap; |
|
} |
|
|
|
/** |
|
* Рекурсивная функция формирования карты сайта |
|
* |
|
* @param int $nav_items |
|
* @param string $sitemap |
|
* @param int $parent |
|
*/ |
|
function printSitemap(&$nav_items, &$sitemap = '', $parent = 0) |
|
{ |
|
$sitemap .= empty($sitemap) ? '<ul class="sitemap">' : '<ul>'; |
|
|
|
foreach ($nav_items[$parent] as $row) |
|
{ |
|
if (strpos($row['alias'], 'module=') === false && start_with('index.php?', $row['alias'])) |
|
{ |
|
$row['alias'] .= '&doc=' . (empty($row['alias']) ? prepare_url($row['title']) : $row['alias']); |
|
} |
|
|
|
if (start_with('www.', $row['alias'])) |
|
{ |
|
$row['alias'] = str_replace('www.', 'http://www.', $row['alias']); |
|
} |
|
|
|
$row['alias'] = str_ireplace('"//"','"/"',str_ireplace('///','/',rewrite_link($row['alias']))); |
|
|
|
|
|
$sitemap .= '<li><a href="' . $row['alias'] . '" target="' . $row['target'] . '">'; |
|
$sitemap .= pretty_chars($row['title']) . '</a>'; |
|
|
|
if (isset($nav_items[$row['navigation_item_id']])) |
|
{ |
|
printSitemap($nav_items, $sitemap, $row['navigation_item_id']); |
|
} |
|
|
|
$sitemap .= '</li>'; |
|
} |
|
|
|
$sitemap .= '</ul>'; |
|
} |
|
|
|
?>
|