aboutsummaryrefslogtreecommitdiff
path: root/mod/categories
diff options
context:
space:
mode:
Diffstat (limited to 'mod/categories')
-rw-r--r--mod/categories/activate.php11
-rw-r--r--mod/categories/deactivate.php6
-rw-r--r--mod/categories/languages/en.php15
-rw-r--r--mod/categories/manifest.xml17
-rw-r--r--mod/categories/pages/categories/listing.php39
-rw-r--r--mod/categories/readme.txt25
-rw-r--r--mod/categories/start.php83
-rw-r--r--mod/categories/views/default/categories.php12
-rw-r--r--mod/categories/views/default/categories/css.php12
-rw-r--r--mod/categories/views/default/categories/view.php8
-rw-r--r--mod/categories/views/default/input/categories.php56
-rw-r--r--mod/categories/views/default/output/categories.php29
-rw-r--r--mod/categories/views/default/plugins/categories/settings.php22
13 files changed, 335 insertions, 0 deletions
diff --git a/mod/categories/activate.php b/mod/categories/activate.php
new file mode 100644
index 000000000..80159d089
--- /dev/null
+++ b/mod/categories/activate.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Prompt the user to add categories after activating
+ */
+
+//categories_admin_notice_no_categories
+$site = get_config('site');
+if (!$site->categories) {
+ $message = elgg_echo('categories:on_activate_reminder', array(elgg_normalize_url('admin/plugin_settings/categories')));
+ elgg_add_admin_notice('categories_admin_notice_no_categories', $message);
+} \ No newline at end of file
diff --git a/mod/categories/deactivate.php b/mod/categories/deactivate.php
new file mode 100644
index 000000000..e15e2c6e9
--- /dev/null
+++ b/mod/categories/deactivate.php
@@ -0,0 +1,6 @@
+<?php
+/**
+ * Remove admin notice to populate categories.
+ */
+
+elgg_delete_admin_notice('categories_admin_notice_no_categories');
diff --git a/mod/categories/languages/en.php b/mod/categories/languages/en.php
new file mode 100644
index 000000000..422fe81a4
--- /dev/null
+++ b/mod/categories/languages/en.php
@@ -0,0 +1,15 @@
+<?php
+/**
+ * Categories English language file
+ */
+
+$english = array(
+ 'categories' => 'Categories',
+ 'categories:settings' => 'Set site categories',
+ 'categories:explanation' => 'To set some predefined site-wide categories that will be used throughout your system, enter them below, separated with commas. Compatible tools will then display them when the user creates or edits content.',
+ 'categories:save:success' => 'Site categories were successfully saved.',
+ 'categories:results' => "Results for the site category: %s",
+ 'categories:on_activate_reminder' => "Site-wide Categories won't work until you add categories. <a href=\"%s\">Add categories now.</a>",
+);
+
+add_translation("en", $english); \ No newline at end of file
diff --git a/mod/categories/manifest.xml b/mod/categories/manifest.xml
new file mode 100644
index 000000000..4a6bd0864
--- /dev/null
+++ b/mod/categories/manifest.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<plugin_manifest xmlns="http://www.elgg.org/plugin_manifest/1.8">
+ <name>Site-wide Categories</name>
+ <author>Core developers</author>
+ <version>1.8</version>
+ <category>bundled</category>
+ <category>enhancement</category>
+ <blurb>Add site-wide categories</blurb>
+ <description>Site-wide Categories lets administrators define categories that users across the site can add content to.</description>
+ <website>http://www.elgg.org/</website>
+ <copyright>See COPYRIGHT.txt</copyright>
+ <license>GNU General Public License version 2</license>
+ <requires>
+ <type>elgg_release</type>
+ <version>1.8</version>
+ </requires>
+</plugin_manifest>
diff --git a/mod/categories/pages/categories/listing.php b/mod/categories/pages/categories/listing.php
new file mode 100644
index 000000000..8924506e9
--- /dev/null
+++ b/mod/categories/pages/categories/listing.php
@@ -0,0 +1,39 @@
+<?php
+/**
+ * List entities by category
+ *
+ * @package ElggCategories
+ */
+
+$limit = get_input("limit", 10);
+$offset = get_input("offset", 0);
+$category = get_input("category");
+$owner_guid = get_input("owner_guid", ELGG_ENTITIES_ANY_VALUE);
+$subtype = get_input("subtype", ELGG_ENTITIES_ANY_VALUE);
+$type = get_input("type", 'object');
+
+$params = array(
+ 'metadata_name' => 'universal_categories',
+ 'metadata_value' => $category,
+ 'types' => $type,
+ 'subtypes' => $subtype,
+ 'owner_guid' => $owner_guid,
+ 'limit' => $limit,
+ 'full_view' => FALSE,
+ 'metadata_case_sensitive' => FALSE,
+);
+$objects = elgg_list_entities_from_metadata($params);
+
+$title = elgg_echo('categories:results', array($category));
+
+$content = elgg_view_title($title);
+$content .= $objects;
+
+$body = elgg_view_layout('content', array(
+ 'content' => $content,
+ 'title' => $title,
+ 'filter' => '',
+ 'header' => '',
+));
+
+echo elgg_view_page($title, $body);
diff --git a/mod/categories/readme.txt b/mod/categories/readme.txt
new file mode 100644
index 000000000..48d07fe8f
--- /dev/null
+++ b/mod/categories/readme.txt
@@ -0,0 +1,25 @@
+Site-wide categories
+--------------------
+
+NOTES FOR DEVELOPERS:
+
+If you're not a programmer, don't worry! All the main Elgg tools
+are already adapted to use categories, and a growing number of
+third party Elgg tools use it too.
+
+
+This plugin uses views and events hooks to allow you to easily add
+site-wide categories across Elgg tools.
+
+This is a two-line addition to any plugin.
+
+In your edit/create form:
+
+ echo elgg_view('input/categories', $vars);
+
+In your object view:
+
+ echo elgg_view('output/categories', $vars);
+
+Note that in both cases, $vars['entity'] MUST be populated with
+the entity the categories apply to, if it exists. \ No newline at end of file
diff --git a/mod/categories/start.php b/mod/categories/start.php
new file mode 100644
index 000000000..0aacf11e7
--- /dev/null
+++ b/mod/categories/start.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * Elgg categories plugin
+ *
+ * @package ElggCategories
+ */
+
+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();
+ }
+
+ $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"));
+
+ elgg_delete_admin_notice('categories_admin_notice_no_categories');
+
+ forward(REFERER);
+} \ No newline at end of file
diff --git a/mod/categories/views/default/categories.php b/mod/categories/views/default/categories.php
new file mode 100644
index 000000000..8577ef01b
--- /dev/null
+++ b/mod/categories/views/default/categories.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Categories input view
+ *
+ * @package ElggCategories
+ *
+ * @deprecated 1.8
+ */
+
+elgg_deprecated_notice("Use input/categories instead of categories", 1.8);
+
+echo elgg_view('input/categories', $vars);
diff --git a/mod/categories/views/default/categories/css.php b/mod/categories/views/default/categories/css.php
new file mode 100644
index 000000000..5f38e2867
--- /dev/null
+++ b/mod/categories/views/default/categories/css.php
@@ -0,0 +1,12 @@
+<?php
+/**
+ * Categories CSS extender
+ *
+ * @package Categories
+ */
+?>
+
+.categories li label {
+ font-size: 100%;
+ line-height: 1.2em;
+}
diff --git a/mod/categories/views/default/categories/view.php b/mod/categories/views/default/categories/view.php
new file mode 100644
index 000000000..6d1f7c1bb
--- /dev/null
+++ b/mod/categories/views/default/categories/view.php
@@ -0,0 +1,8 @@
+<?php
+/**
+ * @deprecated 1.8
+ */
+
+elgg_deprecated_notice("Use output/categories instead of categories/view", 1.8);
+
+echo elgg_view('output/categories', $vars);
diff --git a/mod/categories/views/default/input/categories.php b/mod/categories/views/default/input/categories.php
new file mode 100644
index 000000000..b543cde45
--- /dev/null
+++ b/mod/categories/views/default/input/categories.php
@@ -0,0 +1,56 @@
+<?php
+/**
+ * Categories input view
+ *
+ * @package ElggCategories
+ *
+ * @uses $vars['entity'] The entity being edited or created
+ */
+
+if (isset($vars['entity']) && $vars['entity'] instanceof ElggEntity) {
+ $selected_categories = $vars['entity']->universal_categories;
+}
+
+// use sticky values if set
+if (isset($vars['universal_categories_list'])) {
+ $selected_categories = $vars['universal_categories_list'];
+}
+
+$categories = elgg_get_site_entity()->categories;
+if (empty($categories)) {
+ $categories = array();
+}
+if (empty($selected_categories)) {
+ $selected_categories = array();
+}
+
+if (!empty($categories)) {
+ if (!is_array($categories)) {
+ $categories = array($categories);
+ }
+
+ // checkboxes want Label => value, so in our case we need category => category
+ $categories = array_flip($categories);
+ array_walk($categories, create_function('&$v, $k', '$v = $k;'));
+
+ ?>
+
+<div class="categories">
+ <label><?php echo elgg_echo('categories'); ?></label><br />
+ <?php
+ echo elgg_view('input/checkboxes', array(
+ 'options' => $categories,
+ 'value' => $selected_categories,
+ 'name' => 'universal_categories_list',
+ 'align' => 'horizontal',
+ ));
+
+ ?>
+ <input type="hidden" name="universal_category_marker" value="on" />
+</div>
+
+ <?php
+
+} else {
+ echo '<input type="hidden" name="universal_category_marker" value="on" />';
+}
diff --git a/mod/categories/views/default/output/categories.php b/mod/categories/views/default/output/categories.php
new file mode 100644
index 000000000..4b3a3fb6a
--- /dev/null
+++ b/mod/categories/views/default/output/categories.php
@@ -0,0 +1,29 @@
+<?php
+/**
+ * View categories on an entity
+ *
+ * @uses $vars['entity']
+ */
+
+$linkstr = '';
+if (isset($vars['entity']) && $vars['entity'] instanceof ElggEntity) {
+
+ $categories = $vars['entity']->universal_categories;
+ if (!empty($categories)) {
+ if (!is_array($categories)) {
+ $categories = array($categories);
+ }
+ foreach($categories as $category) {
+ $link = elgg_get_site_url() . 'categories/list?category=' . urlencode($category);
+ if (!empty($linkstr)) {
+ $linkstr .= ', ';
+ }
+ $linkstr .= '<a href="'.$link.'">' . $category . '</a>';
+ }
+ }
+
+}
+
+if ($linkstr) {
+ echo '<p class="elgg-output-categories">' . elgg_echo('categories') . ": $linkstr</p>";
+}
diff --git a/mod/categories/views/default/plugins/categories/settings.php b/mod/categories/views/default/plugins/categories/settings.php
new file mode 100644
index 000000000..3802da95a
--- /dev/null
+++ b/mod/categories/views/default/plugins/categories/settings.php
@@ -0,0 +1,22 @@
+<?php
+/**
+ * Administrator sets the categories for the site
+ *
+ * @package ElggCategories
+ */
+
+// Get site categories
+$site = elgg_get_site_entity();
+$categories = $site->categories;
+
+if (empty($categories)) {
+ $categories = array();
+}
+
+?>
+<div>
+ <p><?php echo elgg_echo('categories:explanation'); ?></p>
+<?php
+ echo elgg_view('input/tags', array('value' => $categories, 'name' => 'categories'));
+?>
+</div> \ No newline at end of file