diff options
-rw-r--r-- | mod/categories/actions/save.php | 4 | ||||
-rw-r--r-- | mod/categories/languages/en.php | 5 | ||||
-rw-r--r-- | mod/categories/listing.php | 8 | ||||
-rw-r--r-- | mod/categories/readme.txt | 9 | ||||
-rw-r--r-- | mod/categories/start.php | 11 | ||||
-rw-r--r-- | mod/categories/views/default/categories.php | 46 | ||||
-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 | 45 | ||||
-rw-r--r-- | mod/categories/views/default/output/categories.php | 27 | ||||
-rw-r--r-- | mod/categories/views/default/settings/categories/edit.php | 17 |
11 files changed, 107 insertions, 151 deletions
diff --git a/mod/categories/actions/save.php b/mod/categories/actions/save.php index 3aa8b3261..26222a030 100644 --- a/mod/categories/actions/save.php +++ b/mod/categories/actions/save.php @@ -1,6 +1,8 @@ <?php /** - * Elgg categories plugin category saver + * Saves the available categories for the site + * + * @note The categories for an object are saved through an event handler: categories_save() * * @package ElggCategories */ diff --git a/mod/categories/languages/en.php b/mod/categories/languages/en.php index cbe5a608f..1954ba8d9 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', @@ -9,4 +12,4 @@ $english = array( 'categories:on_enable_reminder' => "You haven't added any categories yet! <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/listing.php b/mod/categories/listing.php index 19fb65069..abbcf6785 100644 --- a/mod/categories/listing.php +++ b/mod/categories/listing.php @@ -1,16 +1,14 @@ <?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'); @@ -24,9 +22,7 @@ $params = array( 'full_view' => FALSE, 'metadata_case_sensitive' => FALSE, ); -elgg_push_context('search'); $objects = elgg_list_entities_from_metadata($params); -elgg_pop_context(); $title = elgg_echo('categories:results', array($category)); 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 aa460677a..5590c0089 100644 --- a/mod/categories/start.php +++ b/mod/categories/start.php @@ -1,11 +1,12 @@ <?php - /** * Elgg categories plugin * * @package ElggCategories */ +elgg_register_event_handler('init', 'system', 'categories_init'); + /** * Initialise categories plugin * @@ -19,8 +20,8 @@ function categories_init() { register_page_handler('categories', 'categories_page_handler'); - elgg_register_event_handler('update','all','categories_save'); - elgg_register_event_handler('create','all','categories_save'); + elgg_register_event_handler('update', 'all', 'categories_save'); + elgg_register_event_handler('create', 'all', 'categories_save'); } @@ -34,7 +35,7 @@ function categories_page_handler() { } /** - * Save site categories to and object upon save / edit + * Save categories to object upon save / edit * */ function categories_save($event, $object_type, $object) { @@ -72,5 +73,3 @@ function categories_on_enable() { function categories_on_disable() { elgg_delete_admin_notice('categories_admin_notice_no_categories'); } - -elgg_register_event_handler('init','system','categories_init');
\ No newline at end of file diff --git a/mod/categories/views/default/categories.php b/mod/categories/views/default/categories.php index f69283e9f..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 = 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); - } - - ?> - -<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/list.php b/mod/categories/views/default/categories/list.php deleted file mode 100644 index 7a6dadff4..000000000 --- a/mod/categories/views/default/categories/list.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -$categories = elgg_get_site_entity()->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..6f57a0c29 --- /dev/null +++ b/mod/categories/views/default/input/categories.php @@ -0,0 +1,45 @@ +<?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; +} +$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); + } + + ?> + +<p class="categories"> + <label><?php echo elgg_echo('categories'); ?></label><br /> + <?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> + + <?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..724c46037 --- /dev/null +++ b/mod/categories/views/default/output/categories.php @@ -0,0 +1,27 @@ +<?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() . 'pg/categories/list/?category=' . urlencode($category); + if (!empty($linkstr)) { + $linkstr .= ', '; + } + $linkstr .= '<a href="'.$link.'">' . $category . '</a>'; + } + } + +} + +echo $linkstr; diff --git a/mod/categories/views/default/settings/categories/edit.php b/mod/categories/views/default/settings/categories/edit.php index 9e0af0e48..e4750f02f 100644 --- a/mod/categories/views/default/settings/categories/edit.php +++ b/mod/categories/views/default/settings/categories/edit.php @@ -1,11 +1,11 @@ <?php /** - * Elgg categories plugin settings page + * Administrator sets the categories for the site * * @package ElggCategories */ -// Get site and categories +// Get site categories $site = elgg_get_site_entity(); $categories = $site->categories; @@ -14,11 +14,8 @@ if (empty($categories)) { } ?> -<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 +<p> + <?php echo elgg_echo('categories:explanation'); ?> +</p> +<?php +echo elgg_view('input/tags', array('value' => $categories, 'internalname' => 'categories')); |