Skip to content

Instantly share code, notes, and snippets.

@Dmi3yy
Last active October 1, 2016 20:25
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Dmi3yy/2d54571209afcb770d95 to your computer and use it in GitHub Desktop.
Elements Tab in Tree
//<?php
//OnManagerTreePrerender,OnManagerTreeRender
//Autor: Dmi3yy
//Version: 0.1
if($_SESSION['mgrRole']=='1') {
$e = &$modx->Event;
if($e->name == 'OnManagerTreePrerender'){
$output = '
<style>
#treePane .tab-page UL
{
margin: 0;
padding: 0;
}
#treePane .tab-page UL LI
{
list-style: none;
padding-left: 0;
}
#treePane .tab-page UL LI LI
{
list-style: circle inside;
padding-left: 5px;
}
#treePane .tab {padding: 5px 5px;}
.ext-ico {text-decoration:none!important;color:#97D19C!important;}
</style>
<div class="tab-pane" id="treePane" style="border:0">
<script type="text/javascript" src="media/script/tabpane.js"></script>
<script type="text/javascript">
treePane = new WebFXTabPane(document.getElementById( "treePane" ),true);
</script>
<div class="tab-page" id="tabDoc" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>Doc</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabDoc" ) );</script>
';
$e->output($output);
}
if($e->name == 'OnManagerTreeRender'){
//global $modx;
$tablePre = $modx->db->config['dbase'] . '.`' . $modx->db->config['table_prefix'];
function createResourceList($resourceTable,$action,$tablePre,$nameField = 'name') {
global $modx, $_lang;
$output = '<ul>';
$pluginsql = $resourceTable == 'site_plugins' ? $tablePre.$resourceTable.'`.disabled, ' : '';
$tvsql = $resourceTable == 'site_tmplvars' ? $tablePre.$resourceTable.'`.caption, ' : '';
//$orderby = $resourceTable == 'site_plugins' ? '6,2' : '5,1';
if ($resourceTable == 'site_plugins' || $resourceTable == 'site_tmplvars') {
$orderby= '6,2';
}else{
$orderby= '5,1';
}
$sql = 'SELECT '.$pluginsql.$tvsql.$tablePre.$resourceTable.'`.'.$nameField.' as name, '.$tablePre.$resourceTable.'`.id, '.$tablePre.$resourceTable.'`.description, '.$tablePre.$resourceTable.'`.locked, if(isnull('.$tablePre.'categories`.category),\''.$_lang['no_category'].'\','.$tablePre.'categories`.category) as category FROM '.$tablePre.$resourceTable.'` left join '.$tablePre.'categories` on '.$tablePre.$resourceTable.'`.category = '.$tablePre.'categories`.id ORDER BY '.$orderby;
$rs = $modx->db->query($sql);
$limit = $modx->db->getRecordCount($rs);
if($limit<1){
echo $_lang['no_results'];
}
$preCat = '';
$insideUl = 0;
for($i=0; $i<$limit; $i++) {
$row = $modx->db->getRow($rs);
$row['category'] = stripslashes($row['category']); //pixelchutes
if ($preCat !== $row['category']) {
$output .= $insideUl? '</ul>': '';
$output .= '<li><strong>'.$row['category'].'</strong><ul>';
$insideUl = 1;
}
if ($resourceTable == 'site_plugins') $class = $row['disabled'] ? ' class="disabledPlugin"' : '';
$output .= '<li><span'.$class.'><a href="index.php?id='.$row['id'].'&amp;a='.$action.'" target="main">'.$row['name'].' <small>(' . $row['id'] . ')</small></a>
<a class="ext-ico" href="#" title="Управление элементами" onclick="window.open(\'index.php?id='.$row['id'].'&a='.$action.'\',\'gener\',\'width=800,height=600,top=\'+((screen.height-600)/2)+\',left=\'+((screen.width-800)/2)+\',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no\')"><sup>nw</sup></a>'.($modx_textdir ? '&rlm;' : '').'</span>';
/*
//@TODO: add description as title to link
if ($resourceTable == 'site_tmplvars') {
$output .= !empty($row['description']) ? ' - '.$row['caption'].' &nbsp; <small> ('.$row['description'].')</small>' : ' - '.$row['caption'];
}else{
$output .= !empty($row['description']) ? ' - '.$row['description'] : '' ;
}*/
$output .= $row['locked'] ? ' <em>('.$_lang['locked'].')</em>' : "" ;
$output .= '</li>';
$preCat = $row['category'];
}
$output .= $insideUl? '</ul>': '';
$output .= '</ul>';
return $output;
}
$temp = createResourceList('site_templates',16,$tablePre,'templatename');
$tv = createResourceList('site_tmplvars',301,$tablePre);
$chunk = createResourceList('site_htmlsnippets',78,$tablePre);
$snippet = createResourceList('site_snippets',22,$tablePre);
$plugin = createResourceList('site_plugins',102,$tablePre);
$output = '
</div>
<div class="tab-page" id="tabTemp" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>Tpl</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabTemp" ) );</script>
'.$temp.'
<br/>
<ul class="actionButtons">
<li><a href="index.php?a=19" target="main">Новый шаблон</a></li>
<li><a href="javascript:location.reload();"><img src="media/style/'.$modx->config['manager_theme']. '/images/icons/refresh.png"/></a></li>
</ul>
</div>
<div class="tab-page" id="tabTV" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>TV</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabTV" ) );</script>
'.$tv.'
<br/>
<ul class="actionButtons">
<li><a href="index.php?a=300" target="main">Новый TV</a></li>
<li><a href="javascript:location.reload();"><img src="media/style/'.$modx->config['manager_theme']. '/images/icons/refresh.png"/></a></li>
</ul>
</div>
<div class="tab-page" id="tabCH" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>Ch</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabCH" ) );</script>
'.$chunk.'
<br/>
<ul class="actionButtons">
<li><a href="index.php?a=77" target="main">Новый чанк</a></li>
<li><a href="javascript:location.reload();"><img src="media/style/'.$modx->config['manager_theme']. '/images/icons/refresh.png"/></a></li>
</ul>
</div>
<div class="tab-page" id="tabSN" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>Sn</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabSN" ) );</script>
'.$snippet.'
<br/>
<ul class="actionButtons">
<li><a href="index.php?a=23" target="main">Новый сниппет</a></li>
<li><a href="javascript:location.reload();"><img src="media/style/'.$modx->config['manager_theme']. '/images/icons/refresh.png"/></a></li>
</ul>
</div>
<div class="tab-page" id="tabPL" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>Pl</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabPL" ) );</script>
'.$plugin.'
<br/>
<ul class="actionButtons">
<li><a href="index.php?a=101" target="main">Новый плагин</a></li>
<li><a href="javascript:location.reload();"><img src="media/style/'.$modx->config['manager_theme']. '/images/icons/refresh.png"/></a></li>
</ul>
</div>
<!-- @TODO: добавить возможность управления файлами
<div class="tab-page" id="tabFL" style="padding-left:0; padding-right:0;">
<h2 class="tab"><strong>Fl</strong></h2>
<script type="text/javascript">treePane.addTabPage( document.getElementById( "tabFL" ) );</script>
тут будет дерево файлов
</div>-->
</div>';
$e->output($output);
}
}
@pmfx
Copy link

pmfx commented Oct 1, 2016

Very cool plugin! Should go to the MODX core. Meanwhile I've modified it a little to use MODX hasPermission. Now it displays Templates tab if user can edit templates, Chunks tab if he can edit chunks and so on. https://gist.github.com/pmfx/884210dfdd8f49319f9aa6fb9ef3d7ba

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment