Okay, for making a plugin with the restriction, you would do the following. I just assume you're using Version 0.8 of Serendipity; if not, you should be able to apply that to 0.7 code easily.
First you'd open the file include/admin/category.inc.php
There you'd spot the code:
Code: Select all
$query = "INSERT INTO {$serendipity['dbPrefix']}category (category_name, category_description, authorid, category_icon, parentid, category_left, category_right) values ('$name', '$desc', $authorid, '$icon', $parentid, 0, 0)";
serendipity_db_query($query);
echo '<div class="serendipityAdminMsgSuccess">'. CATEGORY_SAVED .'</div>';
(This is line 26-28 for my latest version).
You would modify this code to read:
Code: Select all
$query = "INSERT INTO {$serendipity['dbPrefix']}category (category_name, category_description, authorid, category_icon, parentid, category_left, category_right) values ('$name', '$desc', $authorid, '$icon', $parentid, 0, 0)";
serendipity_plugin_api::hook_event('backend_create_category', $query);
serendipity_db_query($query);
echo '<div class="serendipityAdminMsgSuccess">'. CATEGORY_SAVED .'</div>';
This way, you inserted a plugin hook which plugins can now use. You would create a simple event plugin called plugins/serendipity_event_categorycheck/serendipity_event_categorycheck.php:
Code: Select all
<?php
class serendipity_event_categorycheck extends serendipity_event {
function introspect(&$propbag) {
global $serendipity;
$propbag->add('name', 'Check Category Creation');
$propbag->add('description', 'Check Category Creation');
$propbag->add('event_hooks', array('backend_create_category' => true));
$propbag->add('configuration', array('maxcategory'));
$propbag->add('author', 'Garvin Hicking');
$propbag->add('version', '1.0');
$propbag->add('stackable', false);
}
function introspect_config_item($name, &$propbag) {
switch($name) {
case 'maxcategory':
$propbag->add('type', 'string');
$propbag->add('name', 'How many categories per author?');
$propbag->add('description', 'Enter a number');
$propbag->add('default', 1);
break;
default:
return false;
}
return true;
}
function event_hook($event, &$bag, &$eventData, $addData = null) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'backend_create_category':
$check = "SELECT count(categoryid) as ccount FROM {$serendipity['dbPrefix']} WHERE authorid = '" . $serendipity['authorid'] . "' GROUP BY authorid";
$rows = serendipity_db_query($check, true);
if ($rows['ccount'] > $this->get_config('maxcategory')) {
echo 'You cannot create more than ' . $this->get_config('maxcategory') . ' categories!';
$eventData = ""; // Create an empty SQL dummy query for execution in event hook
}
return true;
break;
default:
return false;
break;
}
} else {
return false;
}
}
}
/* vim: set sts=4 ts=4 expandtab : */
(I hardcoded language strings to make the code smaller - but for a final version you would use language Constants like all the other plugins)
You can see that the plugin executes on the event hook, performs an SQL query to check how many authors exist, and depending on the outcome either leaves the SQL query for creating a category intact, or sets it to an empty string.
You can easily expand the system to check if a superuser is creating a category, or if the category to be created is a subcategory, or whatever. You may need to use $serendipity['GET'] and $serendipity['POST'] for some variable access.
About the browser issues: Yes, IE5 sometimes has problems. Also mod_gzip on a server creates some troubles. But this is more a IE5/CSS problem, and not one of Serendipity per se...
HTH,
Garvin.