start.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Elgg categories plugin
  4. *
  5. * @package ElggCategories
  6. */
  7. elgg_register_event_handler('init', 'system', 'categories_init');
  8. /**
  9. * Initialise categories plugin
  10. *
  11. */
  12. function categories_init() {
  13. elgg_extend_view('css/elgg', 'categories/css');
  14. elgg_register_page_handler('categories', 'categories_page_handler');
  15. elgg_register_event_handler('update:after', 'all', 'categories_save');
  16. elgg_register_event_handler('create', 'all', 'categories_save');
  17. // To keep the category plugins in the settings area and because we have to do special stuff,
  18. // handle saving ourself.
  19. elgg_register_plugin_hook_handler('action', 'plugins/settings/save', 'categories_save_site_categories');
  20. }
  21. /**
  22. * Category page handler
  23. * @return bool
  24. */
  25. function categories_page_handler() {
  26. include(dirname(__FILE__) . "/pages/categories/listing.php");
  27. return true;
  28. }
  29. /**
  30. * Save categories to object upon save / edit
  31. *
  32. */
  33. function categories_save($event, $object_type, $object) {
  34. if ($object instanceof ElggEntity) {
  35. $marker = get_input('universal_category_marker');
  36. if ($marker == 'on') {
  37. $categories = get_input('universal_categories_list');
  38. if (empty($categories)) {
  39. $categories = array();
  40. }
  41. $object->universal_categories = $categories;
  42. }
  43. }
  44. return TRUE;
  45. }
  46. /**
  47. * Saves the site categories.
  48. *
  49. * @param type $hook
  50. * @param type $type
  51. * @param type $value
  52. * @param type $params
  53. */
  54. function categories_save_site_categories($hook, $type, $value, $params) {
  55. $plugin_id = get_input('plugin_id');
  56. if ($plugin_id != 'categories') {
  57. return $value;
  58. }
  59. $categories = get_input('categories');
  60. $categories = string_to_tag_array($categories);
  61. $site = elgg_get_site_entity();
  62. $site->categories = $categories;
  63. system_message(elgg_echo("categories:save:success"));
  64. elgg_delete_admin_notice('categories_admin_notice_no_categories');
  65. forward(REFERER);
  66. }