PDA

View Full Version : CP Plugin Sorting and Selection (SD 2.4.0)


Tobias
02-18-2007, 10:24 AM
Subdreamer's display of Custom Plugins and Downloaded Plugins in the Control Panel can get really huge and therefore a struggle to work with as they are not sorted by name.

The code changes to "admin/menu.php" (for v2.4.x) offers these improvements (tested ok with IE7 and FF2):

Sort by Name Asc/Desc links for both
Plugin selection box for both (loads when plugin is selected)
Full list is now a secondary collapsable block (both)
Custom Plugins: option to list by Displayname
Downloaded Plugins: added display of Plugin ID and link to directly open the "Plugin Settings" (same as menu "Settings|Plugins")


Step 1:
Make a backup of "admin/index.php" and "admin/menu.php" before any changes - as usual.

Step 2:
Widen the left "menu" frame to accomodate better display of names:
In "admin/index.php", line 117, find this line:

<frameset cols="185,*" framespacing="0" border="0" frameborder="0" frameborder="no">

Replace that line with below line:

<frameset cols="210,*" framespacing="0" border="0" frameborder="0" frameborder="no">


Step 3:
Open "admin/menu.php" and find at line 222, this:

<table width="150" border="0" cellpadding="0" cellspacing="0" align="center">

Replace that line with below line:

<table width="180" border="0" cellpadding="0" cellspacing="0" align="center">


Step 4:
Find at line 342 - 385, this block of code:

// custom plugins
$getcustomplugins = $DB->query("SELECT custompluginid, name FROM " . TABLE_PREFIX . "customplugins ORDER BY custompluginid ASC");
$showmenu = true;
if($DB->get_num_rows($getcustomplugins) > 0)
{
while($customplugin = $DB->fetch_array($getcustomplugins))
{
if(@in_array($customplugin['custompluginid'], $userinfo['custompluginadminids']))
{
if($showmenu)
{
PrintMenuTitle('Custom Plugins', false);
PrintMenuRow('customplugins.php','<b>Create New Plugin</b>');
$showmenu = false;
}

PrintMenuRow('customplugins.php?custompluginid='.$ customplugin['custompluginid'].'', $customplugin['name']);
}
}
}
EndBlock();

// downloaded plugins
$getdwplugins = $DB->query("SELECT pluginid, name FROM " . TABLE_PREFIX . "plugins WHERE authorname != 'subdreamer' AND authorname != 'subdreamer_cloner' ORDER BY pluginid ASC");
$showmenu = true;
if($DB->get_num_rows($getdwplugins) > 0)
{
while($dwplugin = $DB->fetch_array($getdwplugins))
{
if(@in_array($dwplugin['pluginid'], $userinfo['pluginadminids']))
{
if($showmenu)
{
PrintMenuTitle('Downloaded Plugins', false);
$showmenu = false;
}

PrintMenuRow('myplugins.php?pluginid='.$dwplugin['pluginid'].'', $dwplugin['name']);
}
}
}

EndBlock();
EndMenu();

Replace above block with the enhanced code listed below:

// Custom Plugins
// SDDepot.com: 2007-02-18: added sorting links a plugin selection box
$cp_sortdir = (!empty($_GET['cp_sortdir'])&&ereg("^asc$|^desc$",$_GET['cp_sortdir']))?$_GET['cp_sortdir']:'asc';
$cp_showdispname = (!empty($_GET['cp_showdispname'])&&ereg("^0$|^1$",$_GET['cp_showdispname']))?$_GET['cp_showdispname']:'0';
$getcustomplugins = $DB->query("SELECT custompluginid, name, displayname FROM " .
TABLE_PREFIX . "customplugins ORDER BY ".
($cp_showdispname?'displayname':'name')." $cp_sortdir");
$showmenu = true;
if($DB->get_num_rows($getcustomplugins) > 0)
{
$cp_selection = '
<select name="cpselector" size="1" onchange="LoadCP(this);" style="margin-top:6px;width:145px;font-size=100%;">
<option value="">Choose a Plugin</option>
<option value="">---------------</option>';
$customplugins = array();
while($customplugin = $DB->fetch_array($getcustomplugins))
{
$customplugins[] = array('custompluginid'=>$customplugin['custompluginid'],
'name'=>$customplugin['name'],
'displayname'=>$customplugin['displayname']);
$cp_selection .= '
<option value="'.$customplugin['custompluginid'].'">'.
($cp_showdispname?$customplugin['displayname']:$customplugin['name']).'</option>';
}
$cp_selection .= "\n </select>\n";
for($cpi=0;$cpi<count($customplugins);$cpi++)
{
$customplugin = $customplugins[$cpi];
if(@in_array($customplugin['custompluginid'], $userinfo['custompluginadminids']))
{
if($showmenu)
{
$showmenu = false;
PrintMenuTitle('Custom Plugins', false);
PrintMenuRow('customplugins.php','<strong>Create New Plugin</strong>');
echo '
<div class="menulink-normal" onmouseover="this.className=\'menulink-hover\';" onmouseout="this.className=\'menulink-normal\'">
<span style="color:#819AAD;">Sort by Name: </span>
<a '.($cp_sortdir=='asc'?'style="color:red" ':'').'href="menu.php?cp_showdispname='.$cp_showdispname.'&cp_sortdir=asc" target="leftFrame">Asc</a>
<a '.($cp_sortdir=='desc'?'style="color:red" ':'').'href="menu.php?cp_showdispname='.$cp_showdispname.'&cp_sortdir=desc" target="leftFrame">Desc</a>
<a '.($cp_showdispname=='1'?'style="color:red" ':'').'href="menu.php?cp_showdispname=1&cp_sortdir='.$cp_sortdir.'" target="leftFrame">Displayname ON</a>
<a '.($cp_showdispname=='0'?'style="color:red" ':'').'href="menu.php?cp_showdispname=0&cp_sortdir='.$cp_sortdir.'" target="leftFrame">OFF</a>
<br />
<form name="cp_select" method="post" action="">
<script type="text/javaScript" language="javaScript">
<!--
function LoadCP(x){
var selected="";
selected=x.options[x.selectedIndex].value;
if(selected>0){
window.document.dp_select.dpselector.selectedIndex =0;
parent.frames.mainFrame.location = "customplugins.php?custompluginid="+selected;
//window.document.cp_select.cpselector.selectedIndex =0;
}
}
-->
</script>
<span style="white-space:nowrap;">
'.$cp_selection.'
<a href="javascript:void(0);" title="Reload Plugin" onclick="LoadCP(window.document.cp_select.cpselector);"><strong>&raquo;</strong></a>
</span>
</form>
';
PrintMenuTitle('Custom Plugins ('.count($customplugins).')',false);
}

PrintMenuRow('customplugins.php?custompluginid='.$ customplugin['custompluginid'],
($cp_showdispname?($customplugin['displayname'].'<br /><b>'.$customplugin['name'].'</b>'):
'<b>'.$customplugin['name'].'</b><br />'.$customplugin['displayname']));
}
}
unset($cp_selection);
EndBlock();
EndBlock();
EndBlock();
}

// Downloaded Plugins
// SDDepot.com: 2007-02-18: added sorting links a plugin selection box
$dlp_sortby = (!empty($_GET['dlp_sortby'])&&ereg("^pluginid$|^name$",$_GET['dlp_sortby']))?$_GET['dlp_sortby']:'name';
$dlp_sortdir = (!empty($_GET['dlp_sortdir'])&&ereg("^asc$|^desc$",$_GET['dlp_sortdir']))?$_GET['dlp_sortdir']:'asc';
$getdwplugins = $DB->query("SELECT pluginid, name FROM " . TABLE_PREFIX . "plugins
WHERE authorname != 'subdreamer' AND authorname != 'subdreamer_cloner' ORDER BY $dlp_sortby $dlp_sortdir");
$showmenu = true;
if($DB->get_num_rows($getdwplugins) > 0)
{
$dp_selection = '
<select name="dpselector" size="1" onchange="LoadDP(this);" style="margin-top:6px;width:145px;font-size=100%;">
<option value="">Choose a Plugin</option>
<option value="">---------------</option>';
$dwplugins = array();
while($dwplugin = $DB->fetch_array($getdwplugins))
{
$dwplugins[] = array('pluginid'=>$dwplugin['pluginid'],
'name'=>$dwplugin['name']);
$dp_selection .= '
<option value="'.$dwplugin['pluginid'].'">'.$dwplugin['name'].' ('.$dwplugin['pluginid'].')</option>';
}
$dp_selection .= "\n </select>\n";
for($dpi=0;$dpi<count($dwplugins);$dpi++)
{
$dwplugin = $dwplugins[$dpi];
if(@in_array($dwplugin['pluginid'], $userinfo['pluginadminids']))
{
if($showmenu)
{
$showmenu = false;
PrintMenuTitle('Downloaded Plugins', false);
PrintMenuRow('plugins.php', '<strong>Goto Plugin Settings</strong>');
echo '
<div class="menulink-normal" onmouseover="this.className=\'menulink-hover\';" onmouseout="this.className=\'menulink-normal\'">
<span style="color:#819AAD;">Sort by Name: </span>
<a '.(($dlp_sortby=='name'&&$dlp_sortdir=='asc')?'style="color:red" ':'').'href="menu.php?dlp_sortby=name&dlp_sortdir=asc" target="leftFrame">Asc</a>
<a '.(($dlp_sortby=='name'&&$dlp_sortdir=='desc')?'style="color:red" ':'').'href="menu.php?dlp_sortby=name&dlp_sortdir=desc" target="leftFrame">Desc</a><br />
<span style="color:#819AAD;">Sort by ID: </span>
<a '.(($dlp_sortby=='pluginid'&&$dlp_sortdir=='asc')?'style="color:red" ':'').'href="menu.php?dlp_sortby=pluginid&dlp_sortdir=asc" target="leftFrame">Asc</a>
<a '.(($dlp_sortby=='pluginid'&&$dlp_sortdir=='desc')?'style="color:red" ':'').'href="menu.php?dlp_sortby=pluginid&dlp_sortdir=desc" target="leftFrame">Desc</a>
<br />
<form name="dp_select" method="post" action="">
<script type="text/javaScript" language="javaScript">
<!--
function LoadDP(x){
var selected="";
selected=x.options[x.selectedIndex].value;
if(selected>0){
window.document.cp_select.cpselector.selectedIndex =0;
parent.frames.mainFrame.location = "myplugins.php?pluginid="+selected;
//window.document.dp_select.dpselector.selectedIndex =0;
}
}
-->
</script>
<span style="white-space:nowrap;">
'.$dp_selection.'
<a href="javascript:void(0);" title="Reload Plugin" onclick="LoadDP(window.document.dp_select.dpselector);"><strong>&raquo;</strong></a>
</span>
</form>
';
PrintMenuTitle('Downl. Plugins ('.count($dwplugins).')', false);
}

PrintMenuRow('myplugins.php?pluginid='.$dwplugin['pluginid'].'', $dwplugin['name'].' ('.$dwplugin['pluginid'].')');
}
}
echo '</div>
</div>
';
unset($dp_selection);
EndBlock();
EndBlock();
EndBlock();
}


Step 5:
Upload both changed files into your "admin" folder of your Subdreamer 2.4.x installation.

This MOD is a free courtesy of SDDepot (http://www.sddepot.com).

Cheers,
Tobias

Tobias
02-19-2007, 07:34 PM
Made a Step-by-Step intro on how to apply the new code, which is basically plain copy'n'paste in 3 places - therefore no attached file needed anymore.

Anyone using this?

valdet
02-19-2007, 10:23 PM
A perfect solution Tobias.
This should be included in future release of SD.

Many thanks,
Val.

SKiZZ
02-19-2007, 10:31 PM
A perfect solution Tobias.
This should be included in future release of SD.

Many thanks,
Val.

I would agree as well. Any status on 2.4.1?

william
02-19-2007, 11:17 PM
THANK GOD Tobias (aka Condev1972) to the rescue one more time...I have only been asking for this simple admin fix for oh only a year from the SD staff....THANKS, VERY MUCH!!!


I am gonna cry....it works so...so...beautifully!!!!

X10tion
02-20-2007, 01:11 AM
works perfectly .. and i am sure using it and thanking u :)
save me the hassle from runnin through the list to look for which plugin i need to work with

abcohen
02-20-2007, 05:27 AM
Tobias if you want too you can submit a zip with the replace files into the mods directory...

Tobias
02-20-2007, 06:13 AM
Adam: I initially had the file attached, but I made it a write-up because a] it is a core SD file and b] easier for future SD upgrades. ;)

william
02-20-2007, 07:20 AM
+1 for adding it as a future SD upgrade...this thing is a 'mouse' / 'wrist' saver!!!

abcohen
02-20-2007, 02:32 PM
I'm just saying we could make sections under mods for 2.4 core
2.4.1 core ect ect...
just want to give the people what they want...

jhobbs
02-20-2007, 03:15 PM
just want to give the people what they want...
I want this mod in future SD releases. It works great, and doesn't inhibit anything.
When a new release is available, I hope I don't have to go back and do file compares to find which mods need to be redone.

tyburon
03-11-2007, 04:13 AM
Thanks condev your efforts are truly appreciated, your mods and plugins are excellent, a big time saver and an excellent way to learn.
I also vote to have this mod in future SD releases :)

william
03-29-2007, 07:31 PM
I was really hoping that this would be part of the 2.4.1 upgrade, but it wasn't, HOWEVER it still works so this is great news!

See what you can do for getting it in to the next version please.