1 balupton Jun 27, 2006 20:29
3 balupton Jul 02, 2006 23:10
Here is the code for this feature:
Add to line 251, file /blogs/inc/_misc/_plugin.class.php
/**
* Grouping
*/
var $group = '';
var $sub_group = '';
Add to line 251, file /blogs/inc/_misc/_plugin.class.php
/**
* Grouping
*/
var $group = '';
var $sub_group = '';
Then in /blogs/inc/VIEW/settings/_set_plugins.form.php look for the start and end of the following code and then replace it :
if( empty($AvailablePlugins) || ! is_a( $AvailablePlugins, 'Plugins_no_DB' ) ) // may have been instantiated for action='info'
{
// Discover available plugins:
$AvailablePlugins = & new Plugins_no_DB(); // do not load registered plugins/events from DB
$AvailablePlugins->discover();
// $AvailablePlugins->sort('name'); - Not needed as we sort by group in the next line
}
// Sort the plugins by group
$AvailablePlugins->sort('group');
?>
<fieldset>
<legend><?php echo T_('Available plugins') ?></legend>
<div class="right_icons"><?php
// "Hide available plugins":
echo action_icon( T_('Hide available plugins'), 'close', regenerate_url( 'plugins_disp_avail', 'plugins_disp_avail=0' ) )
?></div>
<table class="grouped" cellspacing="0">
<tbody>
<tr>
<th class="firstcol"><?php echo T_('Plugin') ?></th>
<th><?php echo T_('Description') ?></th>
<th><?php echo T_('Version') ?></th>
<th><?php echo T_('Help') ?></th>
<th class="lastcol"><?php echo T_('Actions') ?></th>
</tr>
<?php
// Grouping
$Current_group = false;
$Current_sub_group = false;
//
$AvailablePlugins->restart(); // make sure iterator is at start position
$count = 0;
while( $loop_Plugin = & $AvailablePlugins->get_next() )
{
if( $loop_Plugin->group !== $Current_group ) {
$Current_group = $loop_Plugin->group;
$Current_sub_group = false;
?>
<tr class="PluginsSeperator">
<th colspan="5"></th>
</tr>
<tr class="PluginsGroup">
<th colspan="5"><?php
echo T_(
( $Current_group == '' || $Current_group == 'Un-Grouped' ) ? 'Un-Grouped' : $Current_group
); ?></th>
</tr>
<?php
$count = 0;/*New Thing*/
}
if( $loop_Plugin->sub_group !== $Current_sub_group && $Current_group !== '' && $loop_Plugin->name != $Current_group ) {
$Current_sub_group = $loop_Plugin->sub_group;
?>
<tr class="PluginsSubGroup">
<th colspan="5"><?php
echo T_(
( $Current_sub_group == '' || $Current_sub_group == 'Un-Grouped' ) ? 'Un-Grouped' : $Current_sub_group
); ?></th>
</tr>
<?php
$count = 0;/*New Thing*/
}
?>
<tr class="<?php echo (($count++ % 2) ? 'odd' : 'even'); if ( $Current_sub_group != false ) echo ' PluginsSubGroup'; ?>">
<td class="firstcol">
<strong><a title="<?php echo T_('Display info') ?>" href="<?php echo regenerate_url( 'action,plugin_ID', 'action=info&plugin_ID='.$loop_Plugin->ID ) ?>"><?php $loop_Plugin->name(); ?></a></strong>
</td>
Then at the end of the file add:
$AvailablePlugins->sort('name'); // Sort the AvaliablePlugins by Name again
And in the file /blogs/inc/VIEW/_menutop.php use the following at the end of the file, replace appropriatly
// CALL PLUGINS NOW:
global $Plugins;
$Plugins->trigger_event( 'AdminEndHtmlHead', array() );
?>
<style type="text/css">
table.grouped tr.PluginsGroup,
table.grouped tr.PluginsSubGroup {
text-align:left;
}
table.grouped tr.PluginsGroup th,
table.grouped tr.PluginsSubGroup th {
border-left:none;
}
table.grouped tr.PluginsSeperator th {
height:7px;
background-color: #f5f3ef;
border-top: 1px solid #9e9286;
}
table.grouped tr.PluginsSubGroup th {/*New Thing*/
border-bottom: 1px solid #9e9286;
border-top: 1px solid #9e9286;
}
table.grouped tr.PluginsSubGroup th {
background-color: #efede0;
color:#666666;
}
table.grouped tr.PluginsSubGroup th,
table.grouped tr.PluginsSubGroup td.firstcol {
padding-left:15px;
}
</style>
</head>
And in /blogs/inc/_misc/_plugins.class.php add/replace the following code appropriatly
/**
* Sort the list of {@link $Plugins}.
*
* WARNING: do NOT sort by anything else than priority unless you're handling a list of NOT-YET-INSTALLED plugins!
*
* @param string Order: 'priority' (default), 'name'
*/
function sort( $order = 'priority' )
{
$this->load_plugins_table();
foreach( $this->sorted_IDs as $plugin_ID )
{ // Instantiate every plugin, so invalid ones do not get unregistered during sorting (crashes PHP, because $sorted_IDs gets changed etc)
$this->get_by_ID( $plugin_ID );
}
switch( $order )
{
case 'name':
usort( $this->sorted_IDs, array( & $this, 'sort_Plugin_name') );
break;
case 'group':
usort( $this->sorted_IDs, array( & $this, 'sort_Plugin_group') );
break;
default:
// Sort array by priority:
usort( $this->sorted_IDs, array( & $this, 'sort_Plugin_priority') );
}
}
/**
* Callback function to sort plugins by group.
*
* WARNING: do NOT sort by anything else than priority unless you're handling a list of NOT-YET-INSTALLED plugins
*/
function sort_Plugin_group( & $a_ID, & $b_ID )
{
$a_Plugin = & $this->get_by_ID( $a_ID );
$b_Plugin = & $this->get_by_ID( $b_ID );
// Compare Group
$r = strcasecmp( $a_Plugin->group, $b_Plugin->group );
if( $r != 0 )
return $r;
else {
// Compare Sub Group
$r = strcasecmp( $a_Plugin->sub_group, $b_Plugin->sub_group );
if( $r != 0 )
return $r;
else {
// Compare Name
return strcasecmp( $a_Plugin->name, $b_Plugin->name );
}
}
}
And you will have a plugin settings page that looks like the attached image
The only change i would like to make to the above code is this:
If you look at the image you will see 'Welcome Panel', in the sub group 'Panels', would be good if in the panel listing the ' Panel' part in the panel's name could be removed. But we'll see how it goes atm.
4 balupton Jul 03, 2006 05:22
Updated the code to fix some display issues, just search for /*New Stuff*/ for lines that have changed, should be a total of 3.
5 balupton Jul 03, 2006 07:24
The following functions should also be added into Plugins Class
function get_Plugins_in_group ( $group ) {
$result = array();
foreach( $this->sorted_IDs as $plugin_ID )
{
$Plugin = & $this->get_by_ID( $plugin_ID );
if( $Plugin->group == $group )
$result[] = & $Plugin;
}
return $result;
}
function get_Plugins_in_sub_group ( $group, $sub_group = '' ) {
$result = array();
foreach( $this->sorted_IDs as $plugin_ID )
{
$Plugin = & $this->get_by_ID( $plugin_ID );
if( $Plugin->group == $group && $Plugin->sub_group == $sub_group )
$result[] = & $Plugin;
}
return $result;
}
6 balupton Jul 03, 2006 07:39
I've made several changes to _set_plugins.form.php, get them from the attached file.
7 balupton Jul 10, 2006 21:15
Hack for the v1.8-beta release;
http://forums.b2evolution.net//viewtopic.php?t=8435&start=0&postdays=0&postorder=asc&highlight=
Can this get added into the b2evolution releases?
8 blueyed Jul 10, 2006 21:35
Can this get added into the b2evolution releases?
If you would provide a patch file, instead of the find&replace instructions in the linked post, I'd take a look at it.
If you cannot provide a patch file (output from "cvs -q diff -u" mainly), I'll look into it nonetheless, but with lower priority.
9 balupton Jul 10, 2006 21:40
I could make a php file that could patch it up... Would that do?
Ahh i get you. Give me 30mins.
10 balupton Jul 10, 2006 23:10
Heres the cvs patch;
http://forums.b2evolution.net//viewtopic.php?p=39690#39690
From now on i will also include cvs patches for large changes.
11 blueyed Jul 11, 2006 00:56
Committed to HEAD, your patch was for v-1-8. Because the list of installed plugins already uses the Results object, I've added it there as an additional column (only the main group). This should probably get enhanced, at least perhaps include the subgroups in a column there.
Perhaps even the Results class should get enhanced to feature "groups" and there would be a checkbox which would trigger that behaviour.
12 balupton Jul 11, 2006 08:02
So do you want the grouping to be like the installed plugins or the avaliable plugins... I don't know why you wouldn't have it the same style as avaliable plugins. ( Avaliable plugins -> the intended way ).
Edit:
If it's due to the user being able to sort the columns, just make it so it sorts by group, then subgroup, then by (whatever the user wants to sort by).
As the layout of grouping, should be consitant, and the sticking the groupname in the column would lose one it's purpose (for the users side).
13 blueyed Jul 11, 2006 19:15
Yep, could work. But ATM I have no interest in extending the Results class for this.
And if you want to provide a patch, please do so against HEAD, obviously.
14 balupton Jul 11, 2006 19:38
Ok... so should i add the intended style of plugin grouping to the installed-plugins table in the HEAD branch?
15 blueyed Jul 11, 2006 19:50
Yes, but as I've said it will include extending the Results class..
And btw: "HEAD" is not a branch, but the trunk.
16 balupton Jul 11, 2006 19:54
Ohhh, actually i don't think it will require any extending of the results class, the only changes that i can see will be in the '_set_plugins.form.php' file.
I may be wrong but i'll have a go.
And thanks for the correction, i'll go update the wiki....
Added sub_groups, and SayIt extension, to the first post.