AVE.CMS v3.28
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.

191 lines
5.2 KiB

8 years ago
<?php
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2017 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
/**
* Формирование хлебных крошек
*
* @return string ссылка
*/
function get_breadcrumb()
{
global $AVE_DB, $AVE_Core;
$bread_crumb = '';
$bread_box = trim(get_settings('bread_box'));
$bread_show_main = trim(get_settings('bread_show_main'));
$bread_show_host = trim(get_settings('bread_show_host'));
$bread_sepparator = trim(get_settings('bread_sepparator'));
$bread_sepparator_use = trim(get_settings('bread_sepparator_use'));
$bread_link_box = trim(get_settings('bread_link_box'));
$bread_link_template = trim(get_settings('bread_link_template'));
$bread_self_box = trim(get_settings('bread_self_box'));
5 years ago
static $crumbs = [];
8 years ago
$curent_document = get_current_document_id();
if (isset($crumbs[$curent_document]))
return $crumbs[$curent_document];
$noprint = null;
if ($bread_show_main)
{
5 years ago
$home_id = ($_SESSION['user_language'] == DEFAULT_LANGUAGE)
? 1
: $curent_document;
$lang_home_alias = getDocument($home_id);
5 years ago
$number = 1;
5 years ago
$search = [
7 years ago
'[name]',
'[link]',
'[count]'
5 years ago
];
7 years ago
5 years ago
$replace = [
7 years ago
$lang_home_alias->document_breadcrum_title,
$bread_show_host ? HOST . '/' . ltrim($lang_home_alias->document_alias, '/') : $lang_home_alias->document_alias,
1
5 years ago
];
8 years ago
$link = str_replace($search, $replace, $bread_link_template);
$bread_crumb = $lang_home_alias
? sprintf($bread_link_box, $link)
: '';
if ($bread_sepparator_use)
$bread_crumb .= $bread_sepparator;
7 years ago
unset ($search, $replace, $link, $sql, $lang_home_alias);
8 years ago
}
if ($curent_document == 1 || $curent_document == PAGE_NOT_FOUND_ID)
$noprint = 1;
5 years ago
$row_document = getDocument($curent_document);
8 years ago
$current = new stdClass();
$current->document_breadcrum_title = (empty($row_document->document_breadcrum_title)
? stripslashes(htmlspecialchars_decode($row_document->document_title))
: stripslashes(htmlspecialchars_decode($row_document->document_breadcrum_title)));
$row_document->document_parent = (isset($AVE_Core->curentdoc->document_parent) && $AVE_Core->curentdoc->document_parent != 0)
? $AVE_Core->curentdoc->document_parent
: $row_document->document_parent;
if (isset($row_document->document_parent) && $row_document->document_parent != 0)
{
$i = 0;
$current->document_parent = $row_document->document_parent;
while ($current->document_parent != 0)
{
5 years ago
$row_doc = getDocument($current->document_parent);
8 years ago
$current->document_parent = $row_doc->document_parent;
if ($row_doc->document_parent == $row_doc->Id)
{
echo "Ошибка! Вы указали в качестве родительского документа текущий документ.<br>";
$current->document_parent = 1;
}
if ($row_doc->document_status==1 && $row_document->document_parent != 0)
{
$crumb['document_breadcrum_title'][$i] = (empty($row_doc->document_breadcrum_title)
? stripslashes(htmlspecialchars_decode($row_doc->document_title))
: stripslashes(htmlspecialchars_decode($row_doc->document_breadcrum_title)));
$crumb['document_alias'][$i] = $row_doc->document_alias;
$crumb['Id'][$i] = $row_doc->Id;
$i++;
}
5 years ago
if ($row_doc->document_parent == 0 AND $row_doc->Id != 1)
8 years ago
$current->document_parent = 1;
}
$length = count($crumb['document_breadcrum_title']);
$crumb['document_breadcrum_title'] = array_reverse($crumb['document_breadcrum_title']);
$crumb['document_alias'] = array_reverse($crumb['document_alias']);
$crumb['Id'] = array_reverse($crumb['Id']);
for ($n = 0; $n < $length; $n++)
{
if ($crumb['Id'][$n] != 1)
{
$number = $n;
if ($bread_show_main)
$number = $number + 1;
$url = rewrite_link('index.php?id=' . $crumb['Id'][$n] . '&amp;doc=' . $crumb['document_alias'][$n]);
5 years ago
$search = ['[name]', '[link]', '[count]'];
$replace = [$crumb['document_breadcrum_title'][$n], $bread_show_host ? HOST . '/' . ltrim($url, '/') : $url, $number];
8 years ago
$link = str_replace($search, $replace, $bread_link_template);
$bread_crumb .= sprintf($bread_link_box, $link);
if (get_settings('bread_link_box_last') == 1)
{
if ($bread_sepparator_use)
$bread_crumb .= $bread_sepparator;
}
else
{
if ($n != $length - 1)
if ($bread_sepparator_use)
$bread_crumb .= $bread_sepparator;
}
5 years ago
unset($search, $replace, $link, $row_doc);
8 years ago
}
}
}
// Последний элемент
7 years ago
if ((isset($AVE_Core->curentdoc->bread_link_box_last) && $AVE_Core->curentdoc->bread_link_box_last == 0))
$bread_crumb .= '';
else if (get_settings('bread_link_box_last') == 1 || (isset($AVE_Core->curentdoc->bread_link_box_last) && $AVE_Core->curentdoc->bread_link_box_last == 1))
5 years ago
$bread_crumb .= str_replace('[count]', $number+1, sprintf($bread_self_box, $current->document_breadcrum_title));
8 years ago
if (! $noprint)
$crumbs[$curent_document] = sprintf($bread_box, $bread_crumb);
else
6 years ago
$crumbs[$curent_document] = '';
8 years ago
unset($bread_crumb);
return $crumbs[$curent_document];
}
7 years ago
?>