diff options
Diffstat (limited to 'mod/categories/start.php')
| -rw-r--r-- | mod/categories/start.php | 141 |
1 files changed, 77 insertions, 64 deletions
diff --git a/mod/categories/start.php b/mod/categories/start.php index 1a8e686fe..0aacf11e7 100644 --- a/mod/categories/start.php +++ b/mod/categories/start.php @@ -1,70 +1,83 @@ <?php +/** + * Elgg categories plugin + * + * @package ElggCategories + */ - /** - * Elgg categories plugin - * - * @package ElggCategories - * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2 - * @author Curverider Ltd <info@elgg.com> - * @copyright Curverider Ltd 2008-2010 - * @link http://elgg.com/ - */ - - /** - * Initialise categories actions etc - * - */ - function categories_init() { - - // Get config - global $CONFIG; - - elgg_extend_view('css', 'categories/css'); - - // Register action - register_action('categories/save',false,$CONFIG->pluginspath . 'categories/actions/save.php',true); - - } - - /** - * Set up menu items - * - */ - function categories_pagesetup() - { - if (get_context() == 'admin' && isadminloggedin()) { - global $CONFIG; - add_submenu_item(elgg_echo('categories:settings'), $CONFIG->wwwroot . 'mod/categories/settings.php'); - } - } - - /** - * Save categories - * - */ - function categories_save($event, $object_type, $object) { - - if ($object instanceof ElggEntity) { - - $marker = get_input('universal_category_marker'); - if ($marker == 'on') { - - $categories = get_input('universal_categories_list'); - if (empty($categories)) $categories = array(); - - $object->universal_categories = $categories; - - } - +elgg_register_event_handler('init', 'system', 'categories_init'); + +/** + * Initialise categories plugin + * + */ +function categories_init() { + + elgg_extend_view('css/elgg', 'categories/css'); + + elgg_register_page_handler('categories', 'categories_page_handler'); + + elgg_register_event_handler('update', 'all', 'categories_save'); + elgg_register_event_handler('create', 'all', 'categories_save'); + + // To keep the category plugins in the settings area and because we have to do special stuff, + // handle saving ourself. + elgg_register_plugin_hook_handler('action', 'plugins/settings/save', 'categories_save_site_categories'); +} + + +/** + * Category page handler + * @return bool + */ +function categories_page_handler() { + include(dirname(__FILE__) . "/pages/categories/listing.php"); + return true; +} + +/** + * Save categories to object upon save / edit + * + */ +function categories_save($event, $object_type, $object) { + if ($object instanceof ElggEntity) { + $marker = get_input('universal_category_marker'); + + if ($marker == 'on') { + $categories = get_input('universal_categories_list'); + + if (empty($categories)) { + $categories = array(); } - return true; - + + $object->universal_categories = $categories; } - + } + return TRUE; +} + +/** + * Saves the site categories. + * + * @param type $hook + * @param type $type + * @param type $value + * @param type $params + */ +function categories_save_site_categories($hook, $type, $value, $params) { + $plugin_id = get_input('plugin_id'); + if ($plugin_id != 'categories') { + return $value; + } + + $categories = get_input('categories'); + $categories = string_to_tag_array($categories); + + $site = elgg_get_site_entity(); + $site->categories = $categories; + system_message(elgg_echo("categories:save:success")); - register_elgg_event_handler('init','system','categories_init'); - register_elgg_event_handler('pagesetup','system','categories_pagesetup'); - register_elgg_event_handler('update','all','categories_save'); - register_elgg_event_handler('create','all','categories_save'); + elgg_delete_admin_notice('categories_admin_notice_no_categories'); -?>
\ No newline at end of file + forward(REFERER); +}
\ No newline at end of file |
