{catmenu} для DLE ниже 12 версий
{catemenu} - Это доработка DLE, которая была внедрена в функционал CMS DLE в 12 версии.
Функционал позволяет выводить в любом месте шаблона название всех существующих категорий и ссылками на них.
Грубо говоря можно запросто создать 'автозаполняемое' навигационное меню для своего сайта.
Но беда в том что на данный момент многие DLE проекты построены на старых версиях cms, и такой функции в них попросту нет.
Тут я вам покажу как её установить отдельно.
На совсем старых версиях DLE я его не проверял, но думаю если постараться, то внедрить можно.
Касаемо совсем старых версий DLE, для них я посоветую специальные модули с таким функционалом. На просторах интернета есть несколько вариантов.
Установка {catemenu} на dle 11-11.x
Открываем файл engine/classes/templates.class.php и ищем строку:
if( strpos( $this->template, "{include file=" ) !== false ) {
Выше добавляем:if (strpos ( $this->template, "{catmenu" ) !== false) {
$this->template = preg_replace_callback ( "#\\{catmenu(.*?)\\}#is", array( &$this, 'build_cat_menu'), $this->template );
}
if (strpos ( $this->template, "{catnewscount" ) !== false) {
$this->template = preg_replace_callback ( "#\\{catnewscount id=['\"](.+?)['\"]\\}#i", array( &$this, 'catnewscount'), $this->template );
}
Далее. Находим в том же файле:
return $template;
}
function clear_url_dir($var) {
Выше вставляем:
if (strpos ( $template, "{catnewscount" ) !== false) {
$template = preg_replace_callback ( "#\\{catnewscount id=['\"](.+?)['\"]\\}#i", array( &$this, 'catnewscount'), $template );
}
if (strpos ( $template, "{catmenu" ) !== false) {
$template = preg_replace_callback ( "#\\{catmenu(.*?)\\}#is", array( &$this, 'build_cat_menu'), $template );
}
Снова, в этом же файле ищем:
function _clear() {
Выше добавляем:
function catnewscount( $matches=array() ) {
global $cat_info;
$id = intval($matches[1]);
return intval($cat_info[$id]['newscount']);
}
function build_tree( $data ) {
$tree = array();
foreach ($data as $id=>&$node) {
if ($node['parentid'] == 0) {
$tree[$id] = &$node;
} else {
if (!isset($data[$node['parentid']]['children'])) $data[$node['parentid']]['children'] = array();
$data[$node['parentid']]['children'][$id] = &$node;
}
}
return $tree;
}
function recursive_array_search($needle, $haystack, $subcat = true, &$item = false) {
if(!$item) $item = array();
foreach($haystack as $key => $value) {
if(in_array($key, $needle)) {
$item[$key] = $value;
if(!$subcat AND is_array( $value['children'] ) ) {
unset($item[$key]['children']);
$this->recursive_array_search($needle, $value['children'], $subcat, $item);
}
} elseif (is_array( $value['children'] ) ) {
$this->recursive_array_search($needle, $value['children'], $subcat, $item);
}
}
return $item;
}
function build_cat_menu( $matches=array() ) {
global $cat_info, $config;
if(!count($cat_info)) return "";
if( !is_array($this->category_tree) ) {
$this->category_tree = $this->build_tree($cat_info);
}
if(!count($this->category_tree)) return "";
$param_str = trim($matches[1]);
$allow_cache = $config['allow_cache'];
$config['allow_cache'] = false;
$catlist = $this->category_tree;
$cache_id = md5($param_str);
if( $config['category_newscount'] ) $cache_prefix = "news"; else $cache_prefix = "catmenu";
if( preg_match( "#cache=['\"](.+?)['\"]#i", $param_str, $match ) ) {
if( $match[1] == "yes" ) $config['allow_cache'] = 1;
}
$content = dle_cache( $cache_prefix, $cache_id );
if( $content !== false ) {
$config['allow_cache'] = $allow_cache;
return $content;
} else {
if( preg_match( "#subcat=['\"](.+?)['\"]#i", $param_str, $match ) ) {
$subcat = trim($match[1]);
if($subcat == "yes") $subcat = true; else $subcat = false;
} else $subcat = true;
if( preg_match( "#id=['\"](.+?)['\"]#i", $param_str, $match ) ) {
$temp_array = array();
$match[1] = explode (',', $match[1]);
foreach ($match[1] as $value) {
if( count(explode('-', $value)) == 2 ) $temp_array[] = get_mass_cats($value);
else $temp_array[] = intval($value);
}
$temp_array = implode(',', $temp_array);
$catlist= $this->recursive_array_search( explode(',', $temp_array), $catlist, $subcat);
if(!count($catlist)) return "";
}
if( preg_match( "#template=['\"](.+?)['\"]#i", $param_str, $match ) ) {
$template_name = trim($match[1]);
} else $template_name = "categorymenu";
$template = $this->sub_load_template( $template_name . '.tpl' );
$template = str_replace( "[root]", "", $template );
$template = str_replace( "[/root]", "", $template );
if( preg_match( "'\\[sub-prefix\\](.+?)\\[/sub-prefix\\]'si", $template, $match ) ) {
$prefix = trim($match[1]);
$template = str_replace( $match[0], "", $template );
}
if( preg_match( "'\\[sub-suffix\\](.+?)\\[/sub-suffix\\]'si", $template, $match ) ) {
$suffix = trim($match[1]);
$template = str_replace( $match[0], "", $template );
}
if($config['allow_cache']) {
$template = preg_replace( "'\\[active\\](.+?)\\[/active\\]'si", "", $template );
}
if( preg_match( "'\\[item\\](.+?)\\[/item\\]'si", $template, $match ) ) {
$item = trim($match[1]);
$template = str_replace( $match[0], "{items}", $template );
$template = str_replace( "{items}", $this->compile_menu($catlist, $prefix, $item, $suffix, false, 0), $template );
}
create_cache( $cache_prefix, $template, $cache_id);
$config['allow_cache'] = $allow_cache;
return $template;
}
}
function compile_menu( $nodes, $prefix, $item_template, $suffix, $sublevelmarker = false, $indent = 0 ) {
$item = "";
foreach ($nodes as $node) {
$item .= $this->compile_item($node, $item_template);
if (isset($node['children'])) {
if ( stripos ( $item_template, "{sub-item}" ) !== false ) {
$item = str_replace( "{sub-item}", $this->compile_menu($node['children'], $prefix, $item_template, $suffix, true, $indent+1), $item );
} else {
$item .= $this->compile_menu($node['children'], $prefix, $item_template, $suffix, true, $indent+1);
}
}
}
if( $sublevelmarker ) {
$item = $prefix.$item.$suffix;
}
return $item;
}
function compile_item( $row, $template) {
global $config, $category_id;
$category = intval($category_id);
$template = str_replace( "{name}", $row['name'], $template );
$template = str_replace( "{icon}", $row['icon'], $template );
$template = str_replace( "{url}", $config['http_home_url'] . get_url( $row['id'] ) . "/" , $template );
$template = str_replace( "{news-count}", intval($row['newscount']), $template );
if($category == $row['id']) {
$template = str_replace( "[active]", "", $template );
$template = str_replace( "[/active]", "", $template );
} else {
$template = preg_replace( "'\\[active\\](.+?)\\[/active\\]'si", "", $template );
}
if(!isset($row['children'])) {
$template = str_replace( "{sub-item}", "", $template );
$template = preg_replace( "'\\[isparent\\](.+?)\\[/isparent\\]'si", "", $template );
} else {
$template = str_replace( "[isparent]", "", $template );
$template = str_replace( "[/isparent]", "", $template );
}
return $template;
}
Готово. Теперь можем использовать теги:
{catmenu}
{catmenu id="1,2,3-5" subcat="yes" template="custom" cache="yes"}
Посетители, находящиеся в группе Гости, не могут оставлять комментарии к данной публикации.