]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Refs #3746. Updated categories for 1.8. Still some deprecation notices, but functional.
authorBrett Profitt <brett.profitt@gmail.com>
Wed, 24 Aug 2011 22:22:49 +0000 (15:22 -0700)
committerBrett Profitt <brett.profitt@gmail.com>
Wed, 24 Aug 2011 22:22:49 +0000 (15:22 -0700)
mod/categories/actions/save.php [deleted file]
mod/categories/activate.php [new file with mode: 0644]
mod/categories/languages/en.php
mod/categories/start.php
mod/categories/views/default/input/categories.php
mod/categories/views/default/plugins/categories/settings.php [moved from mod/categories/views/default/settings/categories/edit.php with 100% similarity]

diff --git a/mod/categories/actions/save.php b/mod/categories/actions/save.php
deleted file mode 100644 (file)
index 26222a0..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-<?php
-/**
- * Saves the available categories for the site
- *
- * @note The categories for an object are saved through an event handler: categories_save()
- *
- * @package ElggCategories
- */
-
-$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/activate.php b/mod/categories/activate.php
new file mode 100644 (file)
index 0000000..80159d0
--- /dev/null
@@ -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
index 1954ba8d97ffb06df93c4e20b7d525a75f89b1da..eaa65b13e6e7e6dcd9bb30af0c7264b085119f8c 100644 (file)
@@ -9,7 +9,7 @@ $english = array(
        '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_enable_reminder' => "You haven't added any categories yet!  <a href=\"%s\">Add categories now.</a>",
+       'categories:on_activate_reminder' => "Site-wide Cateogires won't work until you add categories. <a href=\"%s\">Add categories now.</a>",
 );
 
 add_translation("en", $english);
\ No newline at end of file
index ff5b01efcf1326fbb91a21345edb98bf5c8aab79..2ccea0d7071bf2392bcde71727a10739b88f5a2b 100644 (file)
@@ -15,13 +15,14 @@ function categories_init() {
 
        elgg_extend_view('css/elgg', 'categories/css');
 
-       $action_base = elgg_get_plugins_path() . 'categories/actions';
-       elgg_register_action('settings/categories/save', "$action_base/save.php", 'admin');
-
        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');
 }
 
 
@@ -54,3 +55,29 @@ function categories_save($event, $object_type, $object) {
        }
        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
index 1f71dc0b42d063583b6e244116c60069f4c5b838..75960d2577fc4dcab3bf64e61a039ce482e5bff5 100644 (file)
@@ -23,6 +23,10 @@ if (!empty($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">