aboutsummaryrefslogtreecommitdiff
path: root/mod/categories/start.php
blob: 60ee01065fc4e0eef5455c6928e0473fb4d5daa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php

/**
 * 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 plugin
 *
 */
function categories_init() {
	global $CONFIG;

	elgg_extend_view('css', 'categories/css');

	register_action('settings/categories/save', FALSE, $CONFIG->pluginspath . 'categories/actions/save.php', TRUE);

	register_page_handler('categories', 'categories_page_handler');

	register_elgg_event_handler('update','all','categories_save');
	register_elgg_event_handler('create','all','categories_save');
}


/**
 * Page handler
 *
 */
function categories_page_handler() {
	include(dirname(__FILE__) . "/listing.php");
	return TRUE;
}

/**
 * Save site categories to and 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();
			}

			$object->universal_categories = $categories;
		}
	}
	return TRUE;
}

/**
 * Add a reminder to set default categories.
 */
function categories_on_enable() {
	if (!$site->categories) {
		global $CONFIG;
		$message = sprintf(elgg_echo('categories:on_enable_reminder'), "{$CONFIG->url}pg/admin/plugin_settings/categories");
		elgg_add_admin_notice('categories_admin_notice_no_categories', $message);
	}
	return TRUE;
}

/**
 * Clean up admin notices on disable.
 */
function categories_on_disable() {
	elgg_delete_admin_notice('categories_admin_notice_no_categories');
}

register_elgg_event_handler('init','system','categories_init');