start.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * This file is loaded when all the active plugins get loaded
  4. */
  5. define('QUESTIONS_EXPERT_ROLE', 'questions_expert');
  6. require_once(dirname(__FILE__) . '/lib/functions.php');
  7. require_once(dirname(__FILE__) . '/lib/events.php');
  8. require_once(dirname(__FILE__) . '/lib/hooks.php');
  9. require_once(dirname(__FILE__) . '/lib/page_handlers.php');
  10. elgg_register_event_handler('init', 'system', 'questions_init');
  11. /**
  12. * This function is executed when the system is initialized
  13. *
  14. * @return void
  15. */
  16. function questions_init() {
  17. elgg_extend_view("page/elements/sidebar", "questions/sidebar");
  18. // extend CSS/JS
  19. elgg_extend_view('css/elgg', 'css/questions/site');
  20. elgg_extend_view('js/elgg', 'js/questions/site');
  21. elgg_register_menu_item('site', [
  22. 'name' => 'questions',
  23. 'text' => elgg_echo('questions'),
  24. 'href' => 'questions/all',
  25. ]);
  26. // make question searchable
  27. elgg_register_entity_type('object', 'question');
  28. elgg_register_plugin_hook_handler('search', 'object:question', '\ColdTrick\Questions\Search::handleQuestionsSearch');
  29. elgg_register_plugin_hook_handler('search_params', 'search:combined', '\ColdTrick\Questions\SearchAdvanced::combinedParams');
  30. // register widget
  31. elgg_register_widget_type('questions', elgg_echo('widget:questions:title'), elgg_echo('widget:questions:description'), ['index', 'profile', 'dashboard', 'groups'], true);
  32. // register page handler for nice urls
  33. elgg_register_page_handler('questions', 'questions_page_handler');
  34. elgg_register_page_handler('answers', 'answers_page_handler');
  35. // register group options
  36. add_group_tool_option('questions', elgg_echo('questions:enable'), false);
  37. elgg_extend_view('groups/tool_latest', 'questions/group_module');
  38. elgg_extend_view('groups/edit', 'questions/groups_edit');
  39. // plugin hooks
  40. elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'questions_owner_block_menu_handler');
  41. elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'questions_user_hover_menu_handler');
  42. elgg_register_plugin_hook_handler('register', 'menu:entity', 'questions_entity_menu_handler');
  43. elgg_register_plugin_hook_handler('register', 'menu:filter', 'questions_filter_menu_handler');
  44. elgg_register_plugin_hook_handler('container_permissions_check', 'object', 'questions_container_permissions_handler');
  45. elgg_register_plugin_hook_handler('permissions_check', 'object', 'questions_permissions_handler');
  46. elgg_register_plugin_hook_handler('widget_url', 'widget_manager', 'questions_widget_url_handler');
  47. elgg_register_plugin_hook_handler('cron', 'daily', 'questions_daily_cron_handler');
  48. elgg_register_plugin_hook_handler('index_entity_type_subtypes', 'elasticsearch', '\ColdTrick\Questions\Elasticsearch::indexTypes');
  49. elgg_register_plugin_hook_handler('likes:is_likable', 'object:' . \ElggQuestion::SUBTYPE, '\Elgg\Values::getTrue');
  50. elgg_register_plugin_hook_handler('likes:is_likable', 'object:' . \ElggAnswer::SUBTYPE, '\Elgg\Values::getTrue');
  51. // notifications
  52. elgg_register_notification_event('object', ElggQuestion::SUBTYPE, ['create', 'move']);
  53. elgg_register_notification_event('object', ElggAnswer::SUBTYPE, ['create', 'correct']);
  54. elgg_register_plugin_hook_handler('prepare', 'notification:create:object:' . ElggQuestion::SUBTYPE, '\ColdTrick\Questions\Notifications::createQuestion');
  55. elgg_register_plugin_hook_handler('prepare', 'notification:move:object:' . ElggQuestion::SUBTYPE, '\ColdTrick\Questions\Notifications::moveQuestion');
  56. elgg_register_plugin_hook_handler('prepare', 'notification:create:object:' . ElggAnswer::SUBTYPE, '\ColdTrick\Questions\Notifications::createAnswer');
  57. elgg_register_plugin_hook_handler('prepare', 'notification:correct:object:' . ElggAnswer::SUBTYPE, '\ColdTrick\Questions\Notifications::correctAnswer');
  58. elgg_register_plugin_hook_handler('prepare', 'notification:create:object:comment', '\ColdTrick\Questions\Notifications::createCommentOnAnswer');
  59. elgg_register_plugin_hook_handler('get', 'subscriptions', '\ColdTrick\Questions\Notifications::addExpertsToSubscribers');
  60. elgg_register_plugin_hook_handler('get', 'subscriptions', '\ColdTrick\Questions\Notifications::addQuestionOwnerToAnswerSubscribers');
  61. elgg_register_plugin_hook_handler('get', 'subscriptions', '\ColdTrick\Questions\Notifications::addAnswerOwnerToAnswerSubscribers');
  62. elgg_register_plugin_hook_handler('get', 'subscriptions', '\ColdTrick\Questions\Notifications::addQuestionSubscribersToAnswerSubscribers');
  63. elgg_register_plugin_hook_handler('entity_types', 'content_subscriptions', '\ColdTrick\Questions\ContentSubscriptions::getEntityTypes');
  64. elgg_register_event_handler('create', 'object', '\ColdTrick\Questions\ContentSubscriptions::createAnswer');
  65. elgg_register_event_handler('create', 'object', '\ColdTrick\Questions\ContentSubscriptions::createCommentOnAnswer');
  66. // events
  67. elgg_register_event_handler('leave', 'group', 'questions_leave_group_handler');
  68. elgg_register_event_handler('delete', 'member_of_site', 'questions_leave_site_handler');
  69. // actions
  70. elgg_register_action('questions/toggle_expert', dirname(__FILE__) . '/actions/toggle_expert.php');
  71. elgg_register_action('questions/group_settings', dirname(__FILE__) . '/actions/group_settings.php');
  72. // question
  73. $actions_base = dirname(__FILE__) . '/actions/object/question';
  74. elgg_register_action('object/question/save', "{$actions_base}/save.php");
  75. elgg_register_action('object/question/move_to_discussions', "{$actions_base}/move_to_discussions.php");
  76. elgg_register_action('questions/delete', "{$actions_base}/delete.php");
  77. // answer
  78. $actions_base = dirname(__FILE__) . '/actions/object/answer';
  79. elgg_register_action('object/answer/add', "{$actions_base}/save.php");
  80. elgg_register_action('object/answer/edit', "{$actions_base}/save.php");
  81. elgg_register_action('answers/delete', "{$actions_base}/delete.php");
  82. elgg_register_action('answers/toggle_mark', "{$actions_base}/toggle_mark.php");
  83. }