Skip to content

Instantly share code, notes, and snippets.

@webber12
Created August 10, 2014 14:53
Show Gist options
  • Save webber12/384525914fa2743b49f7 to your computer and use it in GitHub Desktop.
Save webber12/384525914fa2743b49f7 to your computer and use it in GitHub Desktop.
<?php
$core = $modx;
if ( ! function_exists('getkey'))
{
/**
* Код MODX гавно, поэтому забываем про TypeHinting
* @param mixed $data
* @param string $key
* @param mixed $default null
* @return mixed
*/
function getkey($data, $key, $default = null)
{
$out = $default;
if(is_array($data) && array_key_exists($key, $data)){
$out = $data[$key];
}
return $out;
}
}
$core->event->params['TplMainOwner'] = getkey($core->event->params, 'TplMainOwner', '@CODE: <ul id="nav" class="menu level-1">[+dl.wrap+]</ul>');
$core->event->params['TplSubOwner'] = getkey($core->event->params, 'TplSubOwner', '@CODE: <ul class="sub-menu level-[+dl.currentDepth+]">[+dl.wrap+]</ul>');
$core->event->params['TplOneItem'] = getkey($core->event->params, 'TplOneItem', '@CODE: <li id="menu-item-[+id+]" class="menu-item [+dl.class+]"><a href="[+url+]" title="[+e.title+]">[+title+]</a>[+dl.submenu+]</li>');
$core->event->params['addWhereList'] = getkey($core->event->params, 'addWhereList', 'c.hidemenu = 0');
$currentDepth = getkey($core->event->params, 'currentDepth', 1);
$currentTpl = getkey($core->event->params, 'TplDepth'.$currentDepth);
if(empty($currentTpl)){
$currentTpl = getkey($core->event->params, 'TplOneItem', '@CODE: <li>[+pagetitle+]</li>');
}
$currentNoChildrenTpl = getkey($core->event->params, 'TplNoChildrenDepth'.$currentDepth);
if(empty($currentNoChildrenTpl)){
$currentNoChildrenTpl = getkey($core->event->params, 'TplNochildrenItem', $currentTpl);
}
$currentOwnerTpl = getkey($core->event->params, 'TplOwner'.$currentDepth);
if(empty($currentOwnerTpl)){
$currentOwnerTpl = '@CODE: [+dl.wrap+]';
if($currentDepth==1){
$currentOwnerTpl = getkey($core->event->params, 'TplMainOwner', $currentOwnerTpl);
}else{
$currentOwnerTpl = getkey($core->event->params, 'TplSubOwner', $currentOwnerTpl);
}
}
return $core->runSnippet('DocLister', array_merge(array(
'orderBy' => 'menuindex ASC, id ASC'
), $core->event->params, array(
'idType' => 'parents',
'parents' => getkey($core->event->params, 'parents', 0),
'params' => $core->event->params,
'tpl' => '@CODE: [+dl.tpl+]',
'ownerTPL' => $currentOwnerTpl,
'mainRowTpl' => $currentTpl,
'noChildrenRowTPL' => $currentNoChildrenTpl,
'noneWrapOuter' => '0',
'prepare' => function($data, DocumentParser $core, DocLister $_DL){
$params = $_DL->getCFGDef('params', array());
if($_DL->getCfgDef('currentDepth', 1) < $_DL->getCFGDef('maxDepth', 5)){
$params['currentDepth'] = $_DL->getCfgDef('currentDepth', 1)+1;
$params['parents'] = $data['id'];
$data['dl.submenu']=$core->runSnippet('BuildMenu', $params);
}else{
$data['dl.submenu'] = '';
}
$data['dl.currentDepth'] = $_DL->getCfgDef('currentDepth', 1);
$data['e.title'] = htmlentities($data['title'], ENT_COMPAT, 'UTF-8', false);
$tpl = empty($data['dl.submenu']) ? 'noChildrenRowTPL' : 'mainRowTpl';
$data['dl.tpl'] = $_DL->parseChunk($_DL->getCfgDef($tpl), $data);
return $data;
}
))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment