hooks.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. namespace AU\AnonymousComments;
  3. /**
  4. * Prevent hover menu stuff for our anonymous user
  5. *
  6. * @param type $hook
  7. * @param type $type
  8. * @param type $return
  9. * @param type $params
  10. * @return array
  11. */
  12. function hover_menu_hook($hook, $type, $return, $params) {
  13. $user = $params['entity'];
  14. $anon_user = get_anon_user();
  15. if ($user->guid == $anon_user->guid) {
  16. if (!elgg_is_admin_logged_in()) {
  17. return array();
  18. } else {
  19. // admin here, lets allow them access to the
  20. // edit settings/profile/avatar items
  21. $allowed = array(
  22. 'profile:edit',
  23. 'settings:edit'
  24. );
  25. foreach ($return as $key => $item) {
  26. if (in_array($item->getName(), $allowed)) {
  27. continue;
  28. }
  29. unset($return[$key]);
  30. }
  31. $return = array_values($return);
  32. }
  33. }
  34. return $return;
  35. }
  36. /**
  37. *
  38. * @param type $hook
  39. * @param type $type
  40. * @param type $return
  41. * @param type $params
  42. *
  43. * @return array();
  44. */
  45. function user_icon_vars($hook, $type, $return, $params) {
  46. $user = ($params['vars']['entity'] instanceof \ElggUser) ? $params['vars']['entity'] : elgg_get_logged_in_user_entity();
  47. $anon_user = get_anon_user();
  48. if ($user->guid == $anon_user->guid) {
  49. $return['use_hover'] = false;
  50. }
  51. return $return;
  52. }
  53. /**
  54. * prevent emails to our anonymous user
  55. *
  56. * @param type $hook
  57. * @param type $type
  58. * @param type $returnvalue
  59. * @param type $params
  60. * @return boolean
  61. */
  62. function anon_email_hook($hook, $type, $returnvalue, $params) {
  63. $anon_user = get_anon_user();
  64. if ($anon_user && $anon_user->email == $params['to']) {
  65. return FALSE;
  66. }
  67. return $returnvalue;
  68. }
  69. /**
  70. *
  71. * @param type $hook
  72. * @param type $type
  73. * @param type $return
  74. * @param type $params
  75. * @return boolean
  76. */
  77. function permissions_check($hook, $type, $return, $params) {
  78. $context = elgg_get_context();
  79. if ($context == "AU_anonymous_comments_permissions") {
  80. return true;
  81. }
  82. return $return;
  83. }
  84. /**
  85. * This function checks if the entity is being moderated, if so we need to count
  86. * and return the number of APPROVED comments, not total comments
  87. * called by commments:count plugin hook
  88. *
  89. * @param type $hook
  90. * @param type $type
  91. * @param type $returnvalue
  92. * @param type $params
  93. * @return int
  94. */
  95. function comment_count_hook($hook, $type, $return, $params) {
  96. if (!is_moderated($params['entity'])) {
  97. return $return;
  98. }
  99. if (!$params['entity']->canEdit()) {
  100. return $return;
  101. }
  102. // can edit the content? can moderate
  103. // set a flag for us to see disabled comments
  104. $show_hidden = access_get_show_hidden_status();
  105. access_show_hidden_entities(true);
  106. $options = array(
  107. 'type' => 'object',
  108. 'subtype' => 'comment',
  109. 'container_guid' => $params['entity']->guid,
  110. 'count' => true
  111. );
  112. $total = (int) elgg_get_entities($options);
  113. // restore the flag
  114. access_show_hidden_entities($show_hidden);
  115. return $total;
  116. }
  117. /**
  118. * modify the entity menu for unapproved comments
  119. *
  120. * @param type $hook
  121. * @param type $type
  122. * @param array $return
  123. * @param array $params
  124. * @return array
  125. */
  126. function comment_entity_menu($hook, $type, $return, $params) {
  127. if (!($params['entity'] instanceof \ElggComment)) {
  128. return $return;
  129. }
  130. if ($params['entity']->isEnabled()) {
  131. return $return;
  132. }
  133. $entity = $params['entity']->getContainerEntity();
  134. if ($entity && $entity->canEdit()) {
  135. $return = array();
  136. $href = elgg_add_action_tokens_to_url('action/comments/moderate?guid[]=' . $params['entity']->guid . '&review=approve');
  137. $item = new \ElggMenuItem('approve', elgg_echo('Au_anonymous_comments:approve'), $href);
  138. $return[] = $item;
  139. $delete_url = elgg_add_action_tokens_to_url('action/comments/moderate?guid[]=' . $params['entity']->guid . '&review=delete');
  140. $item = new \ElggMenuItem('delete', elgg_view_icon('delete'), $delete_url);
  141. $item->setConfirmText(elgg_echo('question:areyousure'));
  142. $return[] = $item;
  143. $return = array_values($return);
  144. }
  145. return $return;
  146. }
  147. function htmlawed_config($hook, $type, $return, $params) {
  148. $config = array(
  149. 'safe' => true,
  150. 'deny_attribute' => 'class, on*',
  151. 'anti_link_spam' => array('`.`', ''),
  152. 'schemes' => '*:http,https,ftp,news,mailto,rtsp,teamspeak,gopher,mms,callto',
  153. 'elements' => 'b, i, ul,li, u, blockquote, p, strong, em, s, ol, br,h1,h2,h3'
  154. );
  155. return array_merge($return, $config);
  156. }