start.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace AU\LikedContent;
  3. const PLUGIN_ID = 'liked_content';
  4. require_once __DIR__ . '/lib/hooks.php';
  5. elgg_register_event_handler('init', 'system', __NAMESPACE__ . '\\init');
  6. function init() {
  7. elgg_register_plugin_hook_handler('register', 'menu:owner_block', __NAMESPACE__ . '\\owner_block');
  8. elgg_register_plugin_hook_handler('register', 'menu:entity', __NAMESPACE__ . '\\entity_menu', 1000);
  9. elgg_register_page_handler('liked_content', __NAMESPACE__ . '\\liked_content_page_handler');
  10. if (elgg_is_active_plugin('au_widgets')) {
  11. elgg_register_widget_type(
  12. 'liked_content', elgg_echo('liked_content:widget:your_likes:title'), elgg_echo('liked_content:widget:your_likes:description'), array(
  13. 'profile',
  14. 'dashboard',
  15. 'groups',
  16. 'index'
  17. ), TRUE
  18. );
  19. }
  20. // elgg_register_menu_item('site', array(
  21. // 'name' => 'liked_content',
  22. // 'text' => elgg_echo('liked_content:liked_content'),
  23. // 'href' => 'liked_content/all'
  24. // ));
  25. add_group_tool_option('liked_content', elgg_echo('liked_content:group:enable'), true);
  26. }
  27. function liked_content_page_handler($page) {
  28. switch ($page[0]) {
  29. case 'group':
  30. $entity = get_entity($page[1]);
  31. if (!elgg_instanceof($entity, 'group') || $entity->liked_content_enable == 'no') {
  32. return false;
  33. }
  34. elgg_set_page_owner_guid($entity->guid);
  35. $content = elgg_view('resources/liked_content/group', array(
  36. 'group' => $entity
  37. ));
  38. if ($content) {
  39. echo $content;
  40. return true;
  41. }
  42. break;
  43. case 'user':
  44. $entity = get_user_by_username($page[1]);
  45. if (!elgg_instanceof($entity, 'user')) {
  46. return false;
  47. }
  48. elgg_set_page_owner_guid($entity->guid);
  49. $content = elgg_view('resources/liked_content/user', array(
  50. 'user' => $entity
  51. ));
  52. if ($content) {
  53. echo $content;
  54. return true;
  55. }
  56. break;
  57. // provide page showing all visible likes
  58. case 'all':
  59. $content = elgg_view('resources/liked_content/all');
  60. if ($content) {
  61. echo $content;
  62. return true;
  63. }
  64. break;
  65. }
  66. return false;
  67. }
  68. /**
  69. * set default settings for widget based on old metadata values
  70. * see au_widgets for details
  71. *
  72. * @param type $widget
  73. * @return type
  74. */
  75. function liked_content_set_defaults($widget) {
  76. if ($widget->defaults_set == 1) {
  77. return;
  78. }
  79. $widget->eligo_sortby = 'mostliked';
  80. $widget->eligo_sortby_dir = 'desc';
  81. // set defaults depending on what kind of widget it is
  82. $container = $widget->getContainerEntity();
  83. if (!elgg_instanceof($container, 'group')) {
  84. // profile/dashboard/index
  85. $widget->eligo_owners = 'all';
  86. } else {
  87. // groups
  88. $widget->eligo_owners = 'thisgroup';
  89. }
  90. if (elgg_instanceof($container, 'user')) {
  91. $widget->my_likes = 0;
  92. }
  93. $widget->defaults_set = 1;
  94. }