start.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Elgg Reported content.
  4. *
  5. * @package ElggReportedContent
  6. */
  7. elgg_register_event_handler('init', 'system', 'reportedcontent_init');
  8. /**
  9. * Initialize the plugin
  10. */
  11. function reportedcontent_init() {
  12. // Register a page handler, so we can have nice URLs
  13. elgg_register_page_handler('reportedcontent', 'reportedcontent_page_handler');
  14. // Extend CSS
  15. elgg_extend_view('css/elgg', 'reportedcontent/css');
  16. elgg_extend_view('css/admin', 'reportedcontent/admin_css');
  17. if (elgg_is_logged_in()) {
  18. elgg_require_js('elgg/reportedcontent');
  19. // Extend footer with report content link
  20. elgg_register_menu_item('extras', array(
  21. 'name' => 'report_this',
  22. 'href' => 'reportedcontent/add',
  23. 'title' => elgg_echo('reportedcontent:this:tooltip'),
  24. 'text' => elgg_view_icon('report-this'),
  25. 'priority' => 500,
  26. 'section' => 'default',
  27. 'link_class' => 'elgg-lightbox',
  28. ));
  29. }
  30. elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'reportedcontent_user_hover_menu');
  31. // Add admin menu item
  32. // @todo Might want to move this to a 'feedback' section. something other than utils
  33. elgg_register_admin_menu_item('administer', 'reportedcontent', 'administer_utilities');
  34. elgg_register_widget_type(
  35. 'reportedcontent',
  36. elgg_echo('reportedcontent'),
  37. elgg_echo('reportedcontent:widget:description'),
  38. array('admin'));
  39. // Register actions
  40. $action_path = elgg_get_plugins_path() . "reportedcontent/actions/reportedcontent";
  41. elgg_register_action('reportedcontent/add', "$action_path/add.php");
  42. elgg_register_action('reportedcontent/delete', "$action_path/delete.php", 'admin');
  43. elgg_register_action('reportedcontent/archive', "$action_path/archive.php", 'admin');
  44. }
  45. /**
  46. * Reported content page handler
  47. *
  48. * Serves the add report page
  49. *
  50. * @param array $page Array of page routing elements
  51. * @return bool
  52. */
  53. function reportedcontent_page_handler($page) {
  54. // only logged in users can report things
  55. elgg_gatekeeper();
  56. if (elgg_extract(0, $page) === 'add' && elgg_is_xhr()) {
  57. echo elgg_view('resources/reportedcontent/add_form');
  58. return true;
  59. }
  60. $title = elgg_echo('reportedcontent:this');
  61. $content = elgg_view_form('reportedcontent/add');
  62. $sidebar = elgg_echo('reportedcontent:instructions');
  63. $params = array(
  64. 'title' => $title,
  65. 'content' => $content,
  66. 'sidebar' => $sidebar,
  67. );
  68. $body = elgg_view_layout('one_sidebar', $params);
  69. echo elgg_view_page($title, $body);
  70. return true;
  71. }
  72. /**
  73. * Add report user link to hover menu
  74. */
  75. function reportedcontent_user_hover_menu($hook, $type, $return, $params) {
  76. $user = $params['entity'];
  77. /* @var ElggUser $user */
  78. $profile_url = urlencode($user->getURL());
  79. $name = urlencode($user->name);
  80. $url = "reportedcontent/add?address=$profile_url&title=$name";
  81. if (elgg_is_logged_in() && elgg_get_logged_in_user_guid() != $user->guid) {
  82. $item = new ElggMenuItem(
  83. 'reportuser',
  84. elgg_echo('reportedcontent:user'),
  85. $url);
  86. $item->setSection('action');
  87. $item->addLinkClass('elgg-lightbox');
  88. $return[] = $item;
  89. }
  90. return $return;
  91. }