bpModDefaultContentTypes

Wrap the functions for all WP/BP core types.

Defined (1)

The class is defined in the following location(s).

/classes/bpModDefaultContentTypes.php  
  1. class bpModDefaultContentTypes 
  2.  
  3. /** 
  4. * hardcode default modules in bpModeration istance 
  5. * @param bpModeration $bpmod main plugin instance 
  6. */ 
  7. function init(&$bpmod) 
  8.  
  9. //init only if in frontend and only for choosen type 
  10. if (is_a($bpmod, 'bpModFrontend')) { 
  11. $init_types =& $bpmod->options['active_types']; 
  12.  
  13. // TODO: check if corrisponding bp components are active before adding useless data 
  14.  
  15. // status updates 
  16. $bpmod->content_types['status_update'] = new stdClass(); 
  17. $bpmod->content_types['status_update']->label = __('Status update', 'bp-moderation'); 
  18. $bpmod->content_types['status_update']->callbacks = array( 
  19. 'info' => array(__CLASS__, 'activity_info'),  
  20. 'delete' => array(__CLASS__, 'activity_delete') 
  21. ); 
  22.  
  23. if (isset ($init_types['status_update'])) { 
  24. $bpmod->types_map['activity_update'] = 'status_update'; 
  25. add_filter('bp_moderation_activity_loop_link_args_activity_update', array(__CLASS__, 'activity_correct_ids')); 
  26.  
  27. // status comments 
  28. $bpmod->content_types['activity_comment'] = new stdClass(); 
  29. $bpmod->content_types['activity_comment']->label = __('Activity comment', 'bp-moderation'); 
  30. //callbacks are the same of status updates because both content types stay in the activity table 
  31. $bpmod->content_types['activity_comment']->callbacks = array( 
  32. 'info' => array(__CLASS__, 'activity_info'),  
  33. 'delete' => array(__CLASS__, 'activity_delete') 
  34. ); 
  35.  
  36. if (isset ($init_types['activity_comment'])) { 
  37. $bpmod->types_map['activity_comment'] = 'activity_comment'; 
  38. add_filter('bp_moderation_activity_loop_link_args_activity_comment', array(__CLASS__, 'activity_correct_ids')); 
  39. add_action('bp_activity_comment_options', array(__CLASS__, 'activity_comments_print_link')); 
  40.  
  41. // blog posts 
  42. $bpmod->content_types['blog_post'] = new stdClass(); 
  43. $bpmod->content_types['blog_post']->label = __('Blog post', 'bp-moderation'); 
  44. $bpmod->content_types['blog_post']->callbacks = array( 
  45. 'info' => array(__CLASS__, 'blog_post_info'),  
  46. 'edit' => array(__CLASS__, 'blog_post_edit'),  
  47. 'delete' => array(__CLASS__, 'blog_post_delete') 
  48. ); 
  49.  
  50. if (isset ($init_types['blog_post'])) { 
  51. $bpmod->types_map['new_blog_post'] = 'blog_post'; 
  52. add_filter('the_content', array(__CLASS__, 'blog_post_append_link')); 
  53. add_filter('the_excerpt', array(__CLASS__, 'blog_post_append_link')); 
  54.  
  55. // blog page 
  56. $bpmod->content_types['blog_page'] = new stdClass(); 
  57. $bpmod->content_types['blog_page']->label = __('Blog page', 'bp-moderation'); 
  58. $bpmod->content_types['blog_page']->callbacks = array( 
  59. 'info' => array(__CLASS__, 'blog_post_info'),  
  60. 'edit' => array(__CLASS__, 'blog_post_edit'),  
  61. 'delete' => array(__CLASS__, 'blog_post_delete') 
  62. ); 
  63.  
  64. if (isset ($init_types['blog_page'])) { 
  65. add_filter('the_content', array(__CLASS__, 'blog_page_append_link')); 
  66. add_filter('the_excerpt', array(__CLASS__, 'blog_page_append_link')); 
  67.  
  68. // blog comments 
  69. $bpmod->content_types['blog_comment'] = new stdClass(); 
  70. $bpmod->content_types['blog_comment']->label = __('Blog comment', 'bp-moderation'); 
  71. $bpmod->content_types['blog_comment']->callbacks = array( 
  72. 'info' => array(__CLASS__, 'blog_comment_info'),  
  73. 'edit' => array(__CLASS__, 'blog_comment_edit'),  
  74. 'delete' => array(__CLASS__, 'blog_comment_delete') 
  75. ); 
  76. add_filter('bp_moderation_author_details_for_blog_comment', array(__CLASS__, 'blog_comment_author_details'), 10, 2); 
  77.  
  78. if (isset ($init_types['blog_comment'])) { 
  79. $bpmod->types_map['new_blog_comment'] = 'blog_comment'; 
  80. add_filter('get_comment_text', array(__CLASS__, 'blog_comment_append_link')); 
  81.  
  82. // profiles 
  83. $bpmod->content_types['member'] = new stdClass(); 
  84. $bpmod->content_types['member']->label = __('Member', 'bp-moderation'); 
  85. $bpmod->content_types['member']->callbacks = array( 
  86. 'info' => array(__CLASS__, 'member_info'),  
  87. 'edit' => array(__CLASS__, 'member_edit'),  
  88. 'delete' => array(__CLASS__, 'member_delete') 
  89. ); 
  90.  
  91. if (isset ($init_types['member'])) { 
  92. add_action('bp_after_member_home_content', array(__CLASS__, 'member_print_link')); 
  93.  
  94. // groups 
  95. $bpmod->content_types['group'] = new stdClass(); 
  96. $bpmod->content_types['group']->label = __('Group', 'bp-moderation'); 
  97. $bpmod->content_types['group']->callbacks = array( 
  98. 'info' => array(__CLASS__, 'group_info'),  
  99. 'edit' => array(__CLASS__, 'group_edit'),  
  100. 'delete' => array(__CLASS__, 'group_delete') 
  101. ); 
  102.  
  103. if (isset ($init_types['group'])) { 
  104. add_action('bp_after_group_home_content', array(__CLASS__, 'group_print_link')); 
  105.  
  106. // forum topic 
  107. $bpmod->content_types['forum_topic'] = new stdClass(); 
  108. $bpmod->content_types['forum_topic']->label = __('Legacy Forum topic', 'bp-moderation'); 
  109. $bpmod->content_types['forum_topic']->callbacks = array( 
  110. 'info' => array(__CLASS__, 'forum_topic_info'),  
  111. 'edit' => array(__CLASS__, 'forum_topic_edit'),  
  112. 'delete' => array(__CLASS__, 'forum_topic_delete') 
  113. ); 
  114.  
  115. if (isset ($init_types['forum_topic'])) { 
  116. add_action('bp_group_forum_topic_meta', array(__CLASS__, 'forum_topic_print_link')); 
  117.  
  118. // forum post 
  119. $bpmod->content_types['forum_post'] = new stdClass(); 
  120. $bpmod->content_types['forum_post']->label = __('Legacy Forum post', 'bp-moderation'); 
  121. $bpmod->content_types['forum_post']->callbacks = array( 
  122. 'info' => array(__CLASS__, 'forum_post_info'),  
  123. 'edit' => array(__CLASS__, 'forum_post_edit'),  
  124. 'delete' => array(__CLASS__, 'forum_post_delete') 
  125. ); 
  126.  
  127. if (isset ($init_types['forum_post'])) { 
  128. $bpmod->types_map['new_forum_post'] = 'forum_post'; 
  129. $bpmod->types_map['new_forum_topic'] = 'forum_post'; 
  130. add_filter('bp_moderation_activity_loop_link_args_new_forum_topic', array(__CLASS__, 'forum_post_convert_activity_args')); 
  131. add_action('bp_group_forum_post_meta', array(__CLASS__, 'forum_post_print_link')); 
  132.  
  133.  
  134. // private message sender 
  135. $bpmod->content_types['private_message_sender'] = new stdClass(); 
  136. $bpmod->content_types['private_message_sender']->label = __('Private message sender', 'bp-moderation'); 
  137. $bpmod->content_types['private_message_sender']->callbacks = array( 
  138. 'info' => array(__CLASS__, 'member_info'),  
  139. 'edit' => array(__CLASS__, 'member_edit'),  
  140. 'delete' => array(__CLASS__, 'member_delete') 
  141. ); 
  142. if (isset ($init_types['private_message_sender'])) { 
  143. add_action('bp_after_message_thread_list', array(__CLASS__, 'private_message_sender_print_links')); 
  144.  
  145. // private message 
  146. $bpmod->content_types['private_message'] = new stdClass(); 
  147. $bpmod->content_types['private_message']->label = __('Private message', 'bp-moderation'); 
  148. $bpmod->content_types['private_message']->callbacks = array( 
  149. 'info' => array(__CLASS__, 'private_message_info'),  
  150. 'delete' => array(__CLASS__, 'private_message_delete') 
  151. ); 
  152. if (isset ($init_types['private_message'])) { 
  153. add_action('bp_after_message_thread_list', array(__CLASS__, 'private_message_print_links')); 
  154. add_filter('bp_moderation_filter_content_backend_for_private_message', array(__CLASS__, 'private_message_view_link_override')); 
  155. add_action('messages_action_view_message', array(__CLASS__, 'private_message_super_admin_override')); 
  156.  
  157.  
  158. // load custom content types 
  159. if (defined('BPMOD_LOAD_CUSTOM_CONTENT_TYPES') && BPMOD_LOAD_CUSTOM_CONTENT_TYPES) { 
  160. $custom_content_types = glob(WP_PLUGIN_DIR . '/bp-moderation-content-types/*.php'); 
  161.   
  162. foreach ($custom_content_types as $ct) 
  163. include_once ($ct); 
  164.   
  165. /******************************************************************************* 
  166. * status_update & activity_comment 
  167. */ 
  168.  
  169. function activity_info($id, $id2) 
  170. $act = new BP_Activity_Activity($id); 
  171. if (empty($act->user_id)) { 
  172. return false; 
  173.  
  174. $url = bp_core_get_root_domain() . '/' . BP_ACTIVITY_SLUG . '/p/' . $id . '/'; 
  175.  
  176. return array('author' => $act->user_id, 'url' => $url, 'date' => $act->date_recorded); 
  177.  
  178. function activity_delete($id, $id2) 
  179. $act = new BP_Activity_Activity($id); 
  180.  
  181. if (empty($act->user_id)) { 
  182. return true; 
  183. } //was already deleted 
  184.  
  185. return bp_activity_delete(array('id' => $id, 'user_id' => $act->user_id)); 
  186.  
  187. function activity_correct_ids($args) 
  188. $args['id'] = bp_get_activity_id(); 
  189. $args['id2'] = bp_get_activity_item_id(); 
  190. return $args; 
  191.  
  192. function activity_comments_print_link() 
  193. $link = bpModFrontend::get_link(array( 
  194. 'type' => 'activity_comment',  
  195. 'author_id' => bp_get_activity_comment_user_id(),  
  196. 'id' => bp_get_activity_comment_id(),  
  197. 'id2' => bp_get_activity_id(),  
  198. 'custom_class' => 'bpm-no-images bp-secondary-action' 
  199. )); 
  200. echo $link; 
  201.  
  202. /******************************************************************************* 
  203. * blog_post 
  204. */ 
  205.  
  206. function blog_post_info($id, $id2) 
  207. switch_to_blog($id); 
  208.  
  209. if (!$post = get_post($id2)) { 
  210. return restore_current_blog() && false; 
  211.  
  212. $url = home_url("?p=$id2"); 
  213.  
  214. restore_current_blog(); 
  215.  
  216. return array('author' => $post->post_author, 'url' => $url, 'date' => $post->post_date_gmt); 
  217.  
  218. function blog_post_edit($id, $id2) 
  219. switch_to_blog($id); 
  220.  
  221. $url = admin_url("post.php?post=$id2&action=edit"); 
  222.  
  223. restore_current_blog(); 
  224.  
  225. return $url; 
  226.  
  227. function blog_post_delete($id, $id2) 
  228. switch_to_blog($id); 
  229.  
  230. $r = !get_post($id2) || wp_delete_post($id2); 
  231.  
  232. restore_current_blog(); 
  233.  
  234. return $r; 
  235.  
  236. function blog_post_append_link($content) 
  237. global $wpdb, $post; 
  238.  
  239. if ('post' != $post->post_type) { 
  240. return $content; 
  241.  
  242. $link = bpModFrontend::get_link(array( 
  243. 'type' => 'blog_post',  
  244. 'author_id' => $post->post_author,  
  245. 'id' => $wpdb->blogid,  
  246. 'id2' => $post->ID,  
  247. 'unflagged_text' => __('Flag this post as inappropriate', 'bp-moderation') 
  248. )); 
  249.  
  250. return "$content\n\n$link"; 
  251.  
  252. function blog_page_append_link($content) 
  253. global $wpdb, $post; 
  254.  
  255. if ('page' != $post->post_type) { 
  256. return $content; 
  257.  
  258. $link = bpModFrontend::get_link(array( 
  259. 'type' => 'blog_page',  
  260. 'author_id' => $post->post_author,  
  261. 'id' => $wpdb->blogid,  
  262. 'id2' => $post->ID,  
  263. 'unflagged_text' => __('Flag this page as inappropriate', 'bp-moderation') 
  264. )); 
  265.  
  266. return "$content\n\n$link"; 
  267.  
  268. /******************************************************************************* 
  269. * blog_comment 
  270. */ 
  271.  
  272. function blog_comment_info($id, $id2) 
  273. switch_to_blog($id); 
  274.  
  275. if (!$comment = get_comment($id2)) { 
  276. return restore_current_blog() && false; 
  277.  
  278. $url = home_url("?p=$comment->comment_post_ID#comment-$id2"); 
  279. $user = get_user_by_email($comment->comment_author_email); 
  280. $author = (int)$user->ID; 
  281.  
  282. restore_current_blog(); 
  283.  
  284. return array('author' => $author, 'url' => $url, 'date' => $comment->comment_date_gmt); 
  285.  
  286. function blog_comment_edit($id, $id2) 
  287. switch_to_blog($id); 
  288.  
  289. $url = admin_url("comment.php?action=editcomment&c=$id2"); 
  290.  
  291. restore_current_blog(); 
  292.  
  293. return $url; 
  294.  
  295. function blog_comment_delete($id, $id2) 
  296. switch_to_blog($id); 
  297.  
  298. $r = !get_comment($id2) || wp_delete_comment($id2); 
  299.  
  300. restore_current_blog(); 
  301.  
  302. return $r; 
  303.  
  304. function blog_comment_author_details($details, $cont) 
  305. switch_to_blog($cont->item_id); 
  306.  
  307. $email = get_comment_author_email($cont->item_id2); 
  308.  
  309. $details = array( 
  310. 'avatar_img' => get_avatar($email, 32),  
  311. 'user_link' => get_comment_author_link($cont->item_id2),  
  312. 'contact_link' => $email 
  313. ? "<a class='vim-c' href='mailto:$email' title='" . __('Send an email to the author of this content', 'bp-moderation') . "' >" . __('Send email', 'bp-moderation') . "</a>" 
  314. : '' 
  315. ); 
  316.  
  317. restore_current_blog(); 
  318.  
  319. return $details; 
  320.  
  321. function blog_comment_append_link($comment_text) 
  322. global $wpdb, $comment; 
  323.  
  324. $link = bpModFrontend::get_link(array( 
  325. 'type' => 'blog_comment',  
  326. 'author_id' => $comment->user_id,  
  327. 'id' => $wpdb->blogid,  
  328. 'id2' => $comment->comment_ID,  
  329. 'unflagged_text' => __('Flag this comment as inappropriate', 'bp-moderation') 
  330. )); 
  331.  
  332. return $comment_text . "\n\n$link"; 
  333.  
  334. /******************************************************************************* 
  335. * member 
  336. */ 
  337. function member_info($id, $id2) 
  338. if (!$user = get_userdata($id)) { 
  339. return false; 
  340.  
  341. return array('author' => $id, 'url' => bp_core_get_user_domain($id), 'date' => $user->user_registered); 
  342.  
  343. function member_edit($id, $id2) 
  344. if (bp_is_active('x-profile')) { 
  345. return bp_core_get_user_domain($id) . $GLOBALS['bp']->profile->slug . '/edit/'; 
  346. else 
  347. return admin_url("user-edit.php?user_id=$id"); 
  348.  
  349. function member_delete($id, $id2) 
  350. if (!$user = get_userdata($id)) { 
  351. return true; 
  352. if (is_super_admin($id) || bp_loggedin_user_id() == $id) { 
  353. return false; 
  354.  
  355. //let admins delete members also if account deletion disabled 
  356. $disable_deletion = get_site_option('bp-disable-account-deletion'); 
  357. if ($disable_deletion) { 
  358. delete_site_option('bp-disable-account-deletion'); 
  359.  
  360. $r = bp_core_delete_account($id); 
  361.  
  362. if ($disable_deletion) { 
  363. add_site_option('bp-disable-account-deletion', $disable_deletion); 
  364.  
  365. return $r; 
  366.  
  367. function member_print_link() 
  368. $link = bpModFrontend::get_link(array( 
  369. 'type' => 'member',  
  370. 'author_id' => bp_displayed_user_id(),  
  371. 'id' => bp_displayed_user_id(),  
  372. 'unflagged_text' => __('Flag this member as inappropriate', 'bp-moderation') 
  373. )); 
  374.  
  375. echo "<div class='bpm-right-link bpm-bottom-link'>$link</div>"; 
  376.  
  377. /******************************************************************************* 
  378. * group 
  379. */ 
  380. function group_info($id, $id2) 
  381. if (!$group = groups_get_group(array('group_id' => $id))) { 
  382. return false; 
  383. return array('author' => $group->creator_id, 'url' => bp_get_group_permalink($group), 'date' => $group->date_created); 
  384.  
  385. function group_edit($id, $id2) 
  386. return bp_get_group_permalink($id) . 'admin/edit-details/'; 
  387.  
  388. function group_delete($id, $id2) 
  389. return !groups_get_group(array('group_id' => $id)) || groups_delete_group($id); 
  390.  
  391. function group_print_link() 
  392. $group = $GLOBALS['bp']->groups->current_group; 
  393.  
  394. $is_author = $group->creator_id == bp_loggedin_user_id(); 
  395.  
  396. if (!$is_author && !empty($group->admins)) { 
  397. foreach ($group->admins as $admin) { 
  398. if ($admin->user_id == bp_loggedin_user_id()) { 
  399. $is_author = true; 
  400. break; 
  401.  
  402. $link = bpModFrontend::get_link(array( 
  403. 'type' => 'group',  
  404. 'is_author' => $is_author,  
  405. 'id' => $group->id,  
  406. 'id2' => 0,  
  407. 'unflagged_text' => __('Flag this group as inappropriate', 'bp-moderation') 
  408. )); 
  409.  
  410. echo "<div class='bpm-right-link bpm-bottom-link'>$link</div>"; 
  411.  
  412. /******************************************************************************* 
  413. * forum_topic 
  414. */ 
  415.  
  416. function forum_topic_info($id, $id2) 
  417. if (!$topic = bp_forums_get_topic_details($id2)) { 
  418. return false; 
  419.  
  420. $url = bp_core_get_root_domain() . '/' . BP_GROUPS_SLUG . '/' . $topic->object_slug . '/forum/topic/' . $topic->topic_slug . '/'; 
  421.  
  422. return array('author' => $topic->topic_poster, 'url' => $url, 'date' => $topic->topic_start_time); 
  423.  
  424. function forum_topic_edit($id, $id2) 
  425. if (!$topic = bp_forums_get_topic_details($id2)) { 
  426. return false; 
  427.  
  428. $url = bp_core_get_root_domain() . '/' . BP_GROUPS_SLUG . '/' . $topic->object_slug . '/forum/topic/' . $topic->topic_slug . '/edit/'; 
  429.  
  430. return wp_nonce_url($url, 'bp_forums_edit_topic'); 
  431.  
  432. function forum_topic_delete($id, $id2) 
  433. return !bp_forums_get_topic_details($id2) || groups_delete_group_forum_topic($id2); 
  434.  
  435. function forum_topic_print_link() 
  436. $link = bpModFrontend::get_link(array( 
  437. 'type' => 'forum_topic',  
  438. 'author_id' => 0,  
  439. 'id' => $GLOBALS['bp']->groups->current_group->id,  
  440. 'id2' => bp_get_the_topic_id(),  
  441. 'unflagged_text' => __('Flag Whole Topic', 'bp-moderation'),  
  442. 'custom_class' => 'bpm-no-images' 
  443. )); 
  444. echo "<span class='links-separator'> | </span>$link"; 
  445.  
  446. /******************************************************************************* 
  447. * forum_post 
  448. */ 
  449.  
  450. function forum_post_info($id, $id2) 
  451. if (!$post = bp_forums_get_post($id2)) { 
  452. return false; 
  453.  
  454. $topic = bp_forums_get_topic_details($post->topic_id); 
  455. $url = bp_core_get_root_domain() . '/' . BP_GROUPS_SLUG . '/' . $topic->object_slug . '/forum/topic/' . $topic->topic_slug . '/#post-' . $post->post_id; 
  456.  
  457. return array('author' => $post->poster_id, 'url' => $url, 'date' => $post->post_time); 
  458.  
  459. function forum_post_edit($id, $id2) 
  460. if (!$post = bp_forums_get_post($id2)) { 
  461. return false; 
  462.  
  463. $topic = bp_forums_get_topic_details($post->topic_id); 
  464. $url = bp_core_get_root_domain() . '/' . BP_GROUPS_SLUG . '/' . $topic->object_slug . '/forum/topic/' . $topic->topic_slug . '/edit/post/' . $post->post_id . '/'; 
  465.  
  466. return wp_nonce_url($url, 'bp_forums_edit_post'); 
  467.  
  468. function forum_post_delete($id, $id2) 
  469. if (!$post = bp_forums_get_post($id2)) { 
  470. return true; 
  471.  
  472. // deleting a post don't remove it from db, it just set its status to 1 
  473. if (1 == (int)$post->post_status) { 
  474. return true; 
  475.  
  476. if (!groups_delete_group_forum_post($id2, $post->topic_id)) { 
  477. return false; 
  478.  
  479. //if it was the first post (topic), then the activity doesn't get delete by bp because is new_forum_topic, instead of new_forum_post 
  480. //so we check if it is the first post and then delete the activity 
  481. if (function_exists('bp_activity_delete')) { 
  482. $first_post = bp_forums_get_topic_posts(array('topic_id' => $post->topic_id, 'post_status' => 'all', 'page' => 1, 'per_page' => 1)); 
  483. if ($first_post[0]->post_id == $post->post_id) { 
  484. bp_activity_delete(array('item_id' => $id, 'secondary_item_id' => $post->topic_id, 'component' => $GLOBALS['bp']->groups->id, 'type' => 'new_forum_topic')); 
  485.  
  486. return true; 
  487.  
  488. function forum_post_convert_activity_args($args) 
  489. //in the 'new topic' activity we want to flag only the first post, not the whole topic 
  490. $first_post = bp_forums_get_topic_posts(array('topic_id' => $args['id2'], 'post_status' => 'all', 'page' => 1, 'per_page' => 1)); 
  491.  
  492. $args['id2'] = $first_post[0]->post_id; 
  493. return $args; 
  494.  
  495. function forum_post_print_link() 
  496. global $topic_template, $bp; 
  497.  
  498. $link = bpModFrontend::get_link(array( 
  499. 'type' => 'forum_post',  
  500. 'author_id' => $topic_template->post->poster_id,  
  501. 'id' => $bp->groups->current_group->id,  
  502. 'id2' => $topic_template->post->post_id,  
  503. 'unflagged_text' => __('Flag', 'bp-moderation'),  
  504. 'custom_class' => 'bpm-no-images' 
  505. )); 
  506.  
  507. echo "<span class='links-separator'> | </span>$link"; 
  508.  
  509.  
  510. /******************************************************************************* 
  511. * Private message sender 
  512. */ 
  513. function private_message_sender_print_links() 
  514. $report_links = array(); 
  515. foreach((array)$GLOBALS['thread_template']->thread->sender_ids as $sender_id) { 
  516. if ($sender_id != bp_loggedin_user_id()) { 
  517. $report_links[] = bpModFrontend::get_link(array( 
  518. 'type' => 'member',  
  519. 'id' => $sender_id,  
  520. 'unflagged_text' => bp_core_get_user_displayname($sender_id),  
  521. 'flagged_text' => bp_core_get_user_displayname($sender_id),  
  522. 'custom_class' => 'button' 
  523. )); 
  524.  
  525. if (!count($report_links)) { 
  526. return; 
  527.  
  528. echo '<p class="bp-mod-pm-thread-links">'; 
  529. printf(__('Flag sender as inappropriate: %s', 'bp-moderation'), join(' ', $report_links)); 
  530. echo '</p>'; 
  531.  
  532.  
  533. /******************************************************************************* 
  534. * Private message 
  535. */ 
  536. function private_message_info($thread_id, $sender_id) 
  537. $thread = new BP_Messages_Thread($thread_id, 'DESC'); 
  538. if (!in_array($sender_id, $thread->sender_ids)) { 
  539. return false; 
  540. $url = bp_core_get_user_domain($sender_id) . bp_get_messages_slug() . '/view/' . $thread_id; 
  541.  
  542. foreach ((array) $thread->messages as $msg) { 
  543. if ($sender_id == $msg->sender_id) { 
  544. return array('author' => $sender_id, 'url' => $url, 'date' => $msg->date_sent); 
  545.  
  546. return false; 
  547.  
  548. function private_message_delete($thread_id, $sender_id) 
  549. global $wpdb, $bp; 
  550.  
  551. $delete_for_user = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->messages->table_name_recipients} SET is_deleted = 1 WHERE thread_id = %d AND user_id = %d", $thread_id, $sender_id) ); 
  552.  
  553. // Check to see if any more recipients remain for this message 
  554. // if not, then delete the message from the database. 
  555. $recipients = $wpdb->get_results( $wpdb->prepare( "SELECT id FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d AND is_deleted = 0", $thread_id ) ); 
  556.  
  557. if ( empty( $recipients ) ) { 
  558. // Delete all the messages 
  559. $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_messages} WHERE thread_id = %d", $thread_id ) ); 
  560.  
  561. // Delete all the recipients 
  562. $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) ); 
  563.  
  564. return true; 
  565.  
  566. function private_message_print_links() 
  567. $report_links = array(); 
  568. foreach((array)$GLOBALS['thread_template']->thread->sender_ids as $sender_id) { 
  569. if ($sender_id != bp_loggedin_user_id()) { 
  570. $report_links[] = bpModFrontend::get_link(array( 
  571. 'type' => 'private_message',  
  572. 'id' => bp_get_the_thread_id(),  
  573. 'id2' => $sender_id,  
  574. 'unflagged_text' => bp_core_get_user_displayname($sender_id),  
  575. 'flagged_text' => bp_core_get_user_displayname($sender_id),  
  576. 'custom_class' => 'button' 
  577. )); 
  578.  
  579. if (!count($report_links)) { 
  580. return; 
  581.  
  582. echo '<p class="bp-mod-pm-thread-links">'; 
  583. printf(__('Flag as inappropriate messages by: %s', 'bp-moderation'), join(' ', $report_links)); 
  584. echo '</p>'; 
  585.  
  586. function private_message_view_link_override($content) { 
  587. $content->item_url = wp_nonce_url($content->item_url.'?bpmSuperAdminOverridePrivateMessage', 'bpmSuperAdminOverridePrivateMessage'); 
  588. return $content; 
  589.  
  590. function private_message_super_admin_override() { 
  591. if(!isset($_GET['bpmSuperAdminOverridePrivateMessage']) || !is_super_admin()) { 
  592. return; 
  593. check_admin_referer('bpmSuperAdminOverridePrivateMessage'); 
  594.  
  595. $thread_id = (int)bp_action_variable( 0 ); 
  596.  
  597. bp_core_new_subnav_item( array( 
  598. 'name' => sprintf( __( 'Review message by %s', 'bp-moderation' ), bp_get_displayed_user_username() ),  
  599. 'slug' => 'view',  
  600. 'parent_url' => trailingslashit( bp_displayed_user_domain() . bp_get_messages_slug() ),  
  601. 'parent_slug' => bp_get_messages_slug(),  
  602. 'screen_function' => true,  
  603. 'position' => 40,  
  604. 'user_has_access' => is_super_admin(),  
  605. 'link' => bp_displayed_user_domain() . bp_get_messages_slug() . '/view/' . (int) $thread_id 
  606. ) ); 
  607.  
  608. bp_core_load_template( apply_filters( 'messages_template_view_message', 'members/single/home' ) ); 
  609. die();