<?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
*/
<?php
+/**
+ * Categories English language file
+ */
$english = array(
'categories' => 'Categories',
'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
<?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');
'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));
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
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
<?php
-
/**
* Elgg categories plugin
*
* @package ElggCategories
*/
+elgg_register_event_handler('init', 'system', 'categories_init');
+
/**
* Initialise categories plugin
*
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');
}
}
/**
- * Save site categories to and object upon save / edit
+ * Save categories to object upon save / edit
*
*/
function categories_save($event, $object_type, $object) {
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
<?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);
+++ /dev/null
-<?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
- }
-
-}
<?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);
--- /dev/null
+<?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" />';
+}
--- /dev/null
+<?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;
<?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;
}
?>
-<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'));