diff options
Diffstat (limited to 'mod/categories')
| -rw-r--r-- | mod/categories/actions/save.php | 23 | ||||
| -rw-r--r-- | mod/categories/activate.php | 11 | ||||
| -rw-r--r-- | mod/categories/deactivate.php | 6 | ||||
| -rw-r--r-- | mod/categories/languages/en.php | 23 | ||||
| -rw-r--r-- | mod/categories/manifest.xml | 23 | ||||
| -rw-r--r-- | mod/categories/pages/categories/listing.php | 39 | ||||
| -rw-r--r-- | mod/categories/readme.txt | 9 | ||||
| -rw-r--r-- | mod/categories/settings.php | 43 | ||||
| -rw-r--r-- | mod/categories/start.php | 141 | ||||
| -rw-r--r-- | mod/categories/views/default/categories.php | 54 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/css.php | 63 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/list.php | 41 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/settings.php | 26 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/settingsform.php | 7 | ||||
| -rw-r--r-- | mod/categories/views/default/categories/view.php | 21 | ||||
| -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 |
18 files changed, 292 insertions, 345 deletions
diff --git a/mod/categories/actions/save.php b/mod/categories/actions/save.php deleted file mode 100644 index c8d8bd051..000000000 --- a/mod/categories/actions/save.php +++ /dev/null @@ -1,23 +0,0 @@ -<?php - - /** - * Elgg categories plugin category saver - * - * @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/ - */ - - $categories = get_input('categories'); - $categories = string_to_tag_array($categories); - - global $CONFIG; - $site = $CONFIG->site; - $site->categories = $categories; - system_message(elgg_echo("categories:save:success")); - - forward($_SERVER['HTTP_REFERER']); - -?> 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 ecd01a9df..422fe81a4 100644 --- a/mod/categories/languages/en.php +++ b/mod/categories/languages/en.php @@ -1,14 +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.', - - ); - - add_translation("en",$english); +$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>", +); -?>
\ 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 443872e57..4a6bd0864 100644 --- a/mod/categories/manifest.xml +++ b/mod/categories/manifest.xml @@ -1,10 +1,17 @@ <?xml version="1.0" encoding="UTF-8"?> -<plugin_manifest> - <field key="author" value="Curverider" /> - <field key="version" value="1.7" /> - <field key="description" value="Site wide categories" /> - <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" /> +<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..d51e6c19e --- /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, + 'type' => $type, + 'subtype' => $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 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/settings.php b/mod/categories/settings.php deleted file mode 100644 index 85696730a..000000000 --- a/mod/categories/settings.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - - /** - * Elgg categories plugin settings page - * - * @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/ - */ - - // Load engine and restrict to admins - - require_once(dirname(dirname(dirname(__FILE__))) . '/engine/start.php'); - admin_gatekeeper(); - - // Set context - - set_context('admin'); - - // Get site and categories - - global $CONFIG; - $site = $CONFIG->site; - $categories = $site->categories; - - if (empty($categories)) $categories = array(); - - // Load category save view - - $body = elgg_view('categories/settings',array( - 'categories' => $categories, - )); - - // Layout - - $body = elgg_view_layout('two_column_left_sidebar','', $body); - - // View page - page_draw(elgg_echo('categories:settings'),$body); - -?>
\ No newline at end of file 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 diff --git a/mod/categories/views/default/categories.php b/mod/categories/views/default/categories.php index f5a41cfa1..8577ef01b 100644 --- a/mod/categories/views/default/categories.php +++ b/mod/categories/views/default/categories.php @@ -1,48 +1,12 @@ <?php +/** + * Categories input view + * + * @package ElggCategories + * + * @deprecated 1.8 + */ - /** - * 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/ - */ +elgg_deprecated_notice("Use input/categories instead of categories", 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 - - } else { - echo '<input type="hidden" name="universal_category_marker" value="on" />'; - } - -?>
\ No newline at end of file +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 d2cf5a8a8..5f38e2867 100644 --- a/mod/categories/views/default/categories/css.php +++ b/mod/categories/views/default/categories/css.php @@ -1,61 +1,12 @@ <?php - /** - * Categories CSS extender - * - * @package Elgg File Repository - * @copyright Curverider Ltd 2008-2010 - * @link http://elgg.com/ - */ +/** + * Categories CSS extender + * + * @package Categories + */ ?> -.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 b6f9f4302..000000000 --- a/mod/categories/views/default/categories/list.php +++ /dev/null @@ -1,41 +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']; - if ($cats = get_tags(0,999,'universal_categories','object',$vars['subtype'],$owner_guid)) - 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 } - -}?>
\ No newline at end of file diff --git a/mod/categories/views/default/categories/settings.php b/mod/categories/views/default/categories/settings.php deleted file mode 100644 index 6c55d88f9..000000000 --- a/mod/categories/views/default/categories/settings.php +++ /dev/null @@ -1,26 +0,0 @@ -<?php - - echo elgg_view_title(elgg_echo('categories:settings')); - -?> - - <div class="contentWrapper"> - <p> - <?php echo elgg_echo('categories:explanation'); ?> - </p> - - -<?php - - echo elgg_view( - 'input/form', - array( - 'action' => $vars['url'] . 'action/categories/save', - 'method' => 'post', - 'body' => elgg_view('categories/settingsform',$vars) - ) - ); - -?> - -</div>
\ No newline at end of file diff --git a/mod/categories/views/default/categories/settingsform.php b/mod/categories/views/default/categories/settingsform.php deleted file mode 100644 index 044f01dcd..000000000 --- a/mod/categories/views/default/categories/settingsform.php +++ /dev/null @@ -1,7 +0,0 @@ -<?php - - echo elgg_view('input/tags',array('value' => $vars['categories'], - 'internalname' => 'categories')); - -?> - <input type="submit" value="<?php echo elgg_echo('save'); ?>" />
\ No newline at end of file diff --git a/mod/categories/views/default/categories/view.php b/mod/categories/views/default/categories/view.php index ef092ce84..6d1f7c1bb 100644 --- a/mod/categories/views/default/categories/view.php +++ b/mod/categories/views/default/categories/view.php @@ -1,19 +1,8 @@ <?php +/** + * @deprecated 1.8 + */ - $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 = $vars['url'] . 'search?tagtype=universal_categories&tag=' . urlencode($category); - if (!empty($linkstr)) $linkstr .= ', '; - $linkstr .= '<a href="'.$link.'">' . $category . '</a>'; - } - } - - } - echo $linkstr; +elgg_deprecated_notice("Use output/categories instead of categories/view", 1.8); -?>
\ No newline at end of file +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 |
