diff options
Diffstat (limited to 'mod/categories')
| -rw-r--r-- | mod/categories/actions/save.php | 17 | ||||
| -rw-r--r-- | mod/categories/activate.php | 11 | ||||
| -rw-r--r-- | mod/categories/deactivate.php | 6 | ||||
| -rw-r--r-- | mod/categories/languages/en.php | 7 | ||||
| -rw-r--r-- | mod/categories/manifest.xml | 27 | ||||
| -rw-r--r-- | mod/categories/pages/categories/listing.php (renamed from mod/categories/listing.php) | 24 | ||||
| -rw-r--r-- | mod/categories/readme.txt | 9 | ||||
| -rw-r--r-- | mod/categories/start.php | 59 | ||||
| -rw-r--r-- | mod/categories/views/default/categories.php | 46 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/css.php | 51 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/list.php | 62 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/view.php | 24 | ||||
| -rw-r--r-- | mod/categories/views/default/input/categories.php | 56 | ||||
| -rw-r--r-- | mod/categories/views/default/output/categories.php | 29 | ||||
| -rw-r--r-- | mod/categories/views/default/plugins/categories/settings.php | 22 | ||||
| -rw-r--r-- | mod/categories/views/default/settings/categories/edit.php | 24 |
16 files changed, 205 insertions, 269 deletions
diff --git a/mod/categories/actions/save.php b/mod/categories/actions/save.php deleted file mode 100644 index 48f050c14..000000000 --- a/mod/categories/actions/save.php +++ /dev/null @@ -1,17 +0,0 @@ -<?php -/** - * Elgg categories plugin category saver - * - * @package ElggCategories - */ - -$categories = get_input('categories'); -$categories = string_to_tag_array($categories); - -$site = $CONFIG->site; -$site->categories = $categories; -system_message(elgg_echo("categories:save:success")); - -elgg_delete_admin_notice('categories_admin_notice_no_categories'); - -forward($_SERVER['HTTP_REFERER']);
\ No newline at end of file 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 index cbe5a608f..422fe81a4 100644 --- a/mod/categories/languages/en.php +++ b/mod/categories/languages/en.php @@ -1,4 +1,7 @@ <?php +/** + * Categories English language file + */ $english = array( 'categories' => 'Categories', @@ -6,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 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 +add_translation("en", $english);
\ No newline at end of file diff --git a/mod/categories/manifest.xml b/mod/categories/manifest.xml index 635543ee3..4a6bd0864 100644 --- a/mod/categories/manifest.xml +++ b/mod/categories/manifest.xml @@ -1,14 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> -<plugin_manifest> - <field key="name" value="Site-wide Categories" /> - <field key="author" value="Curverider" /> - <field key="version" value="1.7" /> - <field key="description" value="Site-wide Categories lets administrators define categories that users across the site can add content to." /> - <field key="website" value="http://www.elgg.org/" /> - <field key="copyright" value="(C) Curverider 2008-2010" /> - <field key="licence" value="GNU Public License version 2" /> - <field key="elgg_version" value="2010030101" /> - <field key="admin_interface" value="advanced" /> - <field key="on_enable" value="categories_on_enable" /> - <field key="on_disable" value="categories_on_disable" /> +<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/listing.php b/mod/categories/pages/categories/listing.php index 3a279a717..d51e6c19e 100644 --- a/mod/categories/listing.php +++ b/mod/categories/pages/categories/listing.php @@ -1,39 +1,39 @@ <?php /** - * Elgg categories listing page + * List entities by category * * @package ElggCategories */ -require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php"); - $limit = get_input("limit", 10); $offset = get_input("offset", 0); $category = get_input("category"); -$owner_guid = get_input("owner_guid", 0); +$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, + 'type' => $type, + 'subtype' => $subtype, 'owner_guid' => $owner_guid, 'limit' => $limit, 'full_view' => FALSE, 'metadata_case_sensitive' => FALSE, ); -$current_context = get_context(); -set_context('search'); $objects = elgg_list_entities_from_metadata($params); -set_context($current_context); -$title = sprintf(elgg_echo('categories:results'), $category); +$title = elgg_echo('categories:results', array($category)); $content = elgg_view_title($title); $content .= $objects; -$body = elgg_view_layout('two_column_left_sidebar', '', $content); +$body = elgg_view_layout('content', array( + 'content' => $content, + 'title' => $title, + 'filter' => '', + 'header' => '', +)); -page_draw($title, $body); +echo elgg_view_page($title, $body); diff --git a/mod/categories/readme.txt b/mod/categories/readme.txt index 49241b2f4..48d07fe8f 100644 --- a/mod/categories/readme.txt +++ b/mod/categories/readme.txt @@ -1,7 +1,7 @@ Site-wide categories -------------------- -NOTES FOR PROGRAMMERS: +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 @@ -15,12 +15,11 @@ This is a two-line addition to any plugin. In your edit/create form: - echo elgg_view('categories', $vars); + echo elgg_view('input/categories', $vars); In your object view: - echo elgg_view('categories/view', $vars); + 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. (i.e., there's -no need for this on a create form.)
\ No newline at end of file +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 index 2dedb3dc3..0aacf11e7 100644 --- a/mod/categories/start.php +++ b/mod/categories/start.php @@ -1,40 +1,42 @@ <?php - /** * Elgg categories plugin * * @package ElggCategories */ +elgg_register_event_handler('init', 'system', 'categories_init'); + /** * Initialise categories plugin * */ function categories_init() { - global $CONFIG; - elgg_extend_view('css', 'categories/css'); + elgg_extend_view('css/elgg', 'categories/css'); - register_action('settings/categories/save', FALSE, $CONFIG->pluginspath . 'categories/actions/save.php', TRUE); + elgg_register_page_handler('categories', 'categories_page_handler'); - register_page_handler('categories', 'categories_page_handler'); + elgg_register_event_handler('update', 'all', 'categories_save'); + elgg_register_event_handler('create', 'all', 'categories_save'); - register_elgg_event_handler('update','all','categories_save'); - register_elgg_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'); } /** - * Page handler - * + * Category page handler + * @return bool */ function categories_page_handler() { - include(dirname(__FILE__) . "/listing.php"); - return TRUE; + include(dirname(__FILE__) . "/pages/categories/listing.php"); + return true; } /** - * Save site categories to and object upon save / edit + * Save categories to object upon save / edit * */ function categories_save($event, $object_type, $object) { @@ -55,22 +57,27 @@ function categories_save($event, $object_type, $object) { } /** - * Add a reminder to set default categories. + * Saves the site categories. + * + * @param type $hook + * @param type $type + * @param type $value + * @param type $params */ -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); +function categories_save_site_categories($hook, $type, $value, $params) { + $plugin_id = get_input('plugin_id'); + if ($plugin_id != 'categories') { + return $value; } - return TRUE; -} -/** - * Clean up admin notices on disable. - */ -function categories_on_disable() { + $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'); -} -register_elgg_event_handler('init','system','categories_init');
\ No newline at end of file + forward(REFERER); +}
\ No newline at end of file diff --git a/mod/categories/views/default/categories.php b/mod/categories/views/default/categories.php index eb81a7311..8577ef01b 100644 --- a/mod/categories/views/default/categories.php +++ b/mod/categories/views/default/categories.php @@ -1,48 +1,12 @@ <?php - /** - * Elgg categories plugin + * Categories input view * * @package ElggCategories + * + * @deprecated 1.8 */ -if (isset($vars['entity']) && $vars['entity'] instanceof ElggEntity) { - $selected_categories = $vars['entity']->universal_categories; -} -$categories = $vars['config']->site->categories; -if (empty($categories)) { - $categories = array(); -} -if (empty($selected_categories)) { - $selected_categories = array(); -} - -if (!empty($categories)) { - if (!is_array($categories)) { - $categories = array($categories); - } - - ?> - -<div id="content_area_user_title"><h2 class="categoriestitle"><?php echo elgg_echo('categories'); ?></h2></div> -<div class="categories"> - <p> - - <?php - - echo elgg_view('input/checkboxes',array( - 'options' => $categories, - 'value' => $selected_categories, - 'internalname' => 'universal_categories_list' - )); - - ?> - <input type="hidden" name="universal_category_marker" value="on" /> - </p> -</div> - - <?php +elgg_deprecated_notice("Use input/categories instead of categories", 1.8); -} else { - echo '<input type="hidden" name="universal_category_marker" value="on" />'; -} +echo elgg_view('input/categories', $vars); diff --git a/mod/categories/views/default/categories/css.php b/mod/categories/views/default/categories/css.php index 87916c412..5f38e2867 100644 --- a/mod/categories/views/default/categories/css.php +++ b/mod/categories/views/default/categories/css.php @@ -6,54 +6,7 @@ */ ?> -.categories .input-checkboxes { - padding:0; - margin:2px 5px 0 0; -} -.categories label { +.categories li label { font-size: 100%; - line-height:1.2em; -} - -#two_column_left_sidebar_maincontent .contentWrapper h2.categoriestitle { - padding: 0 0 3px 0; - margin:0; - font-size:120%; - color:#333333; -} -#two_column_left_sidebar_maincontent .contentWrapper .categories { - border:1px solid #CCCCCC; - -webkit-border-radius: 4px; - -moz-border-radius: 4px; - padding:5px; - margin:0 0 15px 0; -} -#two_column_left_sidebar_maincontent .contentWrapper .categories p { - margin:0; -} -#two_column_left_sidebar_maincontent .contentWrapper .blog_post .categories { - border:none; - margin:0; - padding:0; -} - -#two_column_left_sidebar .blog_categories { - background:white; - -webkit-border-radius: 8px; - -moz-border-radius: 8px; - padding:10px; - margin:0 10px 10px 10px; -} -#two_column_left_sidebar .blog_categories h2 { - background:none; - border-top:none; - margin:0; - padding:0 0 5px 0; - font-size:1.25em; - line-height:1.2em; - color:#0054A7; + line-height: 1.2em; } -#two_column_left_sidebar .blog_categories ul { - color:#0054A7; - margin:5px 0 0 0; -}
\ No newline at end of file diff --git a/mod/categories/views/default/categories/list.php b/mod/categories/views/default/categories/list.php deleted file mode 100644 index 9b62eff51..000000000 --- a/mod/categories/views/default/categories/list.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -$categories = $vars['config']->site->categories; - -if ($categories) { - if (!is_array($categories)) { - $categories = array($categories); - } - - if (!empty($vars['subtype'])) { - $flag = array(); - $owner_guid = ''; - if (isset($vars['owner_guid'])) { - $owner_guid = (int) $vars['owner_guid']; - } - - elgg_register_tag_metadata_name('universal_categories'); - $params = array( - 'threshold' => 1, - 'limit' => 999, - 'tag_names' => array('universal_categories'), - 'types' => 'object', - 'subtypes' => $vars['subtype'], - 'owner_guid' => $owner_guid, - ); - $cats = elgg_get_tags($params); - if ($cats) { - foreach($cats as $cat) { - $flag[] = $cat->tag; - } - } - - } else { - $flag = null; - } - - if (is_null($flag) || !empty($flag)) { - - ?> - -<h2><?php echo elgg_echo('categories'); ?></h2> -<div class="categories"> - <?php - - $catstring = ''; - if (!empty($categories)) { - foreach($categories as $category) { - if (is_null($flag) || (is_array($flag) && in_array($category,$flag))) { - $catstring .= '<li><a href="'.$vars['baseurl'].urlencode($category).'">'. $category .'</a></li>'; - } - } - } - if (!empty($catstring)) { - echo "<ul>{$catstring}</ul>"; - } - - ?> -</div> - <?php - } - -} diff --git a/mod/categories/views/default/categories/view.php b/mod/categories/views/default/categories/view.php index 043b1d78e..6d1f7c1bb 100644 --- a/mod/categories/views/default/categories/view.php +++ b/mod/categories/views/default/categories/view.php @@ -1,22 +1,8 @@ <?php +/** + * @deprecated 1.8 + */ -$linkstr = ''; -if (isset($vars['entity']) && $vars['entity'] instanceof ElggEntity) { +elgg_deprecated_notice("Use output/categories instead of categories/view", 1.8); - $categories = $vars['entity']->universal_categories; - if (!empty($categories)) { - if (!is_array($categories)) { - $categories = array($categories); - } - foreach($categories as $category) { - $link = elgg_get_site_url() . 'pg/categories/list/?category=' . urlencode($category); - if (!empty($linkstr)) { - $linkstr .= ', '; - } - $linkstr .= '<a href="'.$link.'">' . $category . '</a>'; - } - } - -} - -echo $linkstr; +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 diff --git a/mod/categories/views/default/settings/categories/edit.php b/mod/categories/views/default/settings/categories/edit.php deleted file mode 100644 index de2b8ad62..000000000 --- a/mod/categories/views/default/settings/categories/edit.php +++ /dev/null @@ -1,24 +0,0 @@ -<?php -/** - * Elgg categories plugin settings page - * - * @package ElggCategories - */ - -// Get site and categories -$site = $CONFIG->site; -$categories = $site->categories; - -if (empty($categories)) { - $categories = array(); -} - -?> -<div class="contentWrapper"> - <p> - <?php echo elgg_echo('categories:explanation'); ?> - </p> - <?php - echo elgg_view('input/tags', array('value' => $categories, 'internalname' => 'categories')); - ?> -</div>
\ No newline at end of file |
