Advertisement
vapvarun

update personal activity with side wide acitivity

Mar 25th, 2015
839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.05 KB | None | 0 0
  1. <?php
  2. require_once('buddypress/bp-core/bp-core-component.php');
  3. class BuddyBoss_Wall_BP_Component extends BP_Component
  4. {
  5. /**
  6. * BUDDYPRESS ACTIVITIES
  7. *
  8. * @since BuddyBoss Wall 1.0
  9. */
  10. public $activities;
  11. public $activity_count = 0;
  12. public $filter_qs = false;
  13. public $like_users = array();
  14.  
  15. /**
  16. * POST FORM
  17. */
  18. public $form_displayed;
  19.  
  20. /**
  21. * LIKES
  22. *
  23. * @since BuddyBoss Wall 1.0
  24. */
  25. public $likes_store = array();
  26.  
  27. /**
  28. * INITIALIZE CLASS
  29. *
  30. * @since BuddyBoss Wall 1.0
  31. */
  32. public function __construct()
  33. {
  34. parent::start(
  35. 'wall',
  36. __( 'Wall' , 'buddyboss-wall' ),
  37. dirname( __FILE__ )
  38. );
  39. }
  40.  
  41. /**
  42. * Convenince method for getting main plugin options.
  43. *
  44. * @since BuddyBoss Wall (1.0.0)
  45. */
  46. public function option( $key )
  47. {
  48. return buddyboss_wall()->option( $key );
  49. }
  50.  
  51. /**
  52. * SETUP BUDDYPRESS GLOBAL OPTIONS
  53. *
  54. * @since BuddyBoss Wall 1.0
  55. */
  56. public function setup_globals( $args = array() )
  57. {
  58. $update_menus = $this->option( 'UPDATE_MENUS' );
  59.  
  60. // Update menu text, this needs to be in the global
  61. // setup function because these actions will have ran already
  62. if ( $update_menus )
  63. {
  64. add_action( 'wp_before_admin_bar_render', array($this, 'update_wp_menus'), 99 );
  65. add_action( 'bp_setup_nav', array($this, 'update_bp_menus'), 98 );
  66. add_action( 'bp_setup_nav', array($this, 'bbg_remove_activity_friends_subnav'), 99 );
  67. add_filter( 'bp_get_displayed_user_nav_activity', array($this, 'bbg_replace_activity_link') );
  68. }
  69.  
  70. parent::setup_globals();
  71. }
  72.  
  73. /**
  74. * SETUP ACTIONS
  75. *
  76. * @since BuddyBoss Wall 1.0
  77. */
  78. public function setup_actions()
  79. {
  80. // Add body class
  81. add_filter( 'body_class', array( $this, 'body_class' ) );
  82.  
  83. // Inject "Whats new" area
  84. add_action( 'wp_footer', array( $this, 'script_template_greeting' ) );
  85.  
  86. // Inject post form fallback if the action
  87. // "bp_before_member_activity_post_form" is missing
  88. // from members/single/activity.php
  89. add_action( 'wp_footer', array( $this, 'script_template_form' ) );
  90.  
  91. // Add inline script templates
  92. add_action( 'bp_before_member_activity_post_form', array( $this, 'post_form' ) );
  93. add_action( 'bp_before_activity_entry_comments', array( $this, 'bp_before_activity_entry_comments' ) );
  94.  
  95. // Front End Assets
  96. if ( ! is_admin() && ! is_network_admin() )
  97. {
  98. add_action( 'wp_enqueue_scripts', array( $this, 'assets' ) );
  99. }
  100.  
  101. // BP filters & actions
  102. if ( buddyboss_wall()->is_enabled() )
  103. {
  104. add_action( 'bp_before_activity_comment', 'buddyboss_wall_add_likes_comments' );
  105. if( !is_admin() || ( defined('DOING_AJAX') && DOING_AJAX ) ){
  106. //global $activity_template used by the method is not available in backend(wp-admin)
  107. //and it generates notices
  108. //temporary fix
  109. add_filter( 'bp_get_activity_action', 'buddyboss_wall_read_filter' );
  110. //the second parameter requred by function is not passed in the action call in admin
  111. //so this function doesn't work in wp-admin
  112. //temporary fix
  113. add_filter( 'bp_get_activity_action', 'buddyboss_wall_replace_placeholders_with_url', 11, 2 );
  114. }
  115. add_filter( 'bp_activity_after_save', 'buddyboss_wall_input_filter' );
  116. add_filter( 'bp_ajax_querystring', 'buddyboss_wall_qs_filter', 111 );
  117. add_filter( 'bp_activity_multiple_at_mentions_notification', 'buddyboss_wall_format_mention_notification', 10, 5 );
  118. add_filter( 'bp_activity_single_at_mentions_notification', 'buddyboss_wall_format_mention_notification', 10, 5 );
  119. add_action( 'bp_activity_screen_my_activity', 'bp_activity_reset_my_new_mentions' );
  120. add_filter( 'bp_has_activities', 'buddyboss_wall_prepare_likes_filter', 10, 3 );
  121. add_filter( 'wp_head', 'buddyboss_wall_inline_styles', 10, 3 );
  122. }
  123.  
  124. parent::setup_actions();
  125. }
  126.  
  127. /**
  128. * Add active wall class
  129. *
  130. * @since BuddyBoss Wall (1.1.1)
  131. */
  132. public function body_class( $classes )
  133. {
  134. $classes[] = apply_filters( 'buddyboss_wall_body_class', 'buddyboss-wall-active' );
  135. return $classes;
  136. }
  137.  
  138. /**
  139. * Prepare array with translated messages/strings to use in JS
  140. *
  141. * @return array Localized BuddyBoss Wall messages
  142. */
  143. public function get_js_translations()
  144. {
  145. $js_translations = array(
  146. 'person' => __( 'person', 'buddyboss-wall' ),
  147. 'people' => __( 'people', 'buddyboss-wall' ),
  148. 'like' => __( 'like', 'buddyboss-wall' ),
  149. 'likes' => __( 'likes', 'buddyboss-wall' ),
  150. 'mark_as_fav' => __( 'Like', 'buddyboss-wall' ),
  151. 'my_favs' => __( 'My Likes', 'buddyboss-wall' ),
  152. 'remove_fav' => __( 'Unlike', 'buddyboss-wall' )
  153. );
  154.  
  155. return apply_filters( 'buddyboss_wall_js_translations', $js_translations );
  156. }
  157.  
  158. /**
  159. * Prepare array with current state that needs to be passed to JS
  160. *
  161. * @return array Current app state
  162. */
  163. public function get_js_app_state()
  164. {
  165. $app_state = buddyboss_wall()->options;
  166.  
  167. return apply_filters( 'buddyboss_wall_app_state', $app_state );
  168. }
  169.  
  170. /**
  171. * Load CSS/JS
  172. * @return void
  173. */
  174. public function assets()
  175. {
  176. $load_css = $this->option( 'LOAD_CSS' );
  177. $load_tooltips = $this->option( 'LOAD_TOOLTIPS' );
  178.  
  179. if ( $load_css )
  180. {
  181. // Wall stylesheet.
  182. wp_enqueue_style( 'buddyboss-wall-main', buddyboss_wall()->assets_url . '/css/buddyboss-wall.min.css', array(), '1.0.7', 'all' );
  183. }
  184.  
  185. // Scripts
  186. if ( $load_tooltips )
  187. {
  188. wp_enqueue_script( 'buddyboss-wall-tooltip', buddyboss_wall()->assets_url . '/js/jquery.tooltipster.min.js', array( 'jquery' ), '3.0.5', true );
  189. }
  190.  
  191. wp_enqueue_script( 'buddyboss-wall-main', buddyboss_wall()->assets_url . '/js/buddyboss-wall.min.js', array( 'jquery', 'buddyboss-wall-tooltip' ), '1.0.7', true );
  192.  
  193. // Localization
  194. $js_vars_array = array_merge(
  195. (array) $this->get_js_translations(),
  196. (array) $this->get_js_app_state()
  197. );
  198.  
  199. $js_vars = apply_filters( 'buddyboss_wall_js_vars', $js_vars_array );
  200.  
  201. wp_localize_script( 'buddyboss-wall-main', 'BuddyBoss_Wall_Appstate', $js_vars );
  202. }
  203.  
  204. /**
  205. * Prints inline script template - greeting label
  206. * @return void
  207. */
  208. public function script_template_greeting()
  209. {
  210. if ( is_user_logged_in() ){
  211. $greeting = '';
  212. if ( bp_is_group() ){
  213. $greeting = sprintf( __( "What's new in %s, %s?", 'buddyboss-wall' ), bp_get_current_group_name(), bp_get_user_firstname() );
  214. } elseif( !bp_is_my_profile() && bp_is_user_activity() ) {
  215. $greeting = sprintf( __( "Write something to %s", 'buddyboss-wall' ), bp_get_displayed_user_fullname() ) ;
  216. } else {
  217. $greeting = sprintf( __( "What's new, %s?", 'buddyboss-wall' ), bp_get_user_firstname() );
  218. }
  219.  
  220. $greeting = apply_filters( 'buddyboss_wall_greeting_template', $greeting );
  221. ?>
  222. <script type="text/html" id="buddyboss-wall-tpl-greeting">
  223. <?php echo $greeting; ?>
  224. </script>
  225. <?php
  226. }
  227. }
  228.  
  229. /**
  230. * Prints inline script template - post form
  231. * @return void
  232. */
  233. public function script_template_form()
  234. {
  235. if ( ! $this->form_displayed && buddyboss_wall()->is_enabled() && is_user_logged_in() && ! bp_is_my_profile() && ( ! bp_current_action() || 'just-me' === bp_current_action() ) )
  236. {
  237. ?>
  238. <script type="text/html" id="buddyboss-wall-tpl-form">
  239. <?php $this->post_form(); ?>
  240. </script>
  241. <?php
  242. }
  243. }
  244. public function post_form()
  245. {
  246. global $bp;
  247.  
  248. // If:
  249. // Wall is enabled
  250. // User is logged in
  251. // We're not on the logged in user's profile
  252. // But we are on a profile/wall ( bp_current_action() )
  253. if ( buddyboss_wall()->is_enabled() && is_user_logged_in() && ! bp_is_my_profile() && bp_is_user() )
  254. {
  255. $this->form_displayed = true;
  256. ?>
  257.  
  258. <?php if ( !is_user_logged_in() ) : ?>
  259.  
  260. <div id="message">
  261. <p><?php printf( __( 'You need to <a href="%s" title="Log in">log in</a>', 'buddyboss-wall' ), wp_login_url() ); ?><?php if ( bp_get_signup_allowed() ) : ?><?php printf( __( ' or <a class="create-account" href="%s" title="Create an account">create an account</a>', 'buddyboss-wall' ), bp_get_signup_page() ); ?><?php endif; ?><?php _e( ' to post to this user\'s Wall.', 'buddyboss-wall' ); ?></p>
  262. </div>
  263.  
  264. <?php elseif (!bp_is_my_profile() && (!is_super_admin() && !buddyboss_wall_is_admin()) && (bp_is_user() && (buddyboss_wall()->is_enabled() && !$this->option('all-members') && !$this->is_friend($bp->displayed_user->id)) )):?>
  265.  
  266. <div id="message" class="info">
  267. <p><?php printf( __( "You and %s are not friends. Request friendship to post to their Wall.", 'buddyboss-wall' ), bp_get_displayed_user_fullname() ) ?></p>
  268. </div>
  269.  
  270. <?php else:?>
  271.  
  272. <?php if ( isset( $_GET['r'] ) ) : ?>
  273. <div id="message" class="info">
  274. <p><?php printf( __( 'You are mentioning %s in a new update, this user will be sent a notification of your message.', 'buddyboss-wall' ), bp_get_mentioned_user_display_name( $_GET['r'] ) ) ?></p>
  275. </div>
  276. <?php endif; ?>
  277.  
  278. <?php bp_get_template_part( 'activity/post-form' ); ?>
  279.  
  280. <?php endif; ?>
  281.  
  282. <?php
  283. }
  284. }
  285. public function bp_before_activity_entry_comments()
  286. {
  287. $has_likes = $this->has_likes( bp_get_activity_id() );
  288. $has_access = is_user_logged_in() && bp_activity_can_comment();
  289. $count = bp_activity_get_comment_count();
  290.  
  291. if ( $has_likes && ! $count ): ?>
  292.  
  293. <script type="text/html" class="buddyboss-wall-tpl-activity-comments" id="buddyboss-wall-tpl-activity-comments-<?php echo bp_get_activity_id(); ?>">
  294. <?php buddyboss_wall_add_likes_comments(); ?>
  295. </script>
  296.  
  297. <?php endif;
  298. }
  299.  
  300. /**
  301. * RENAME ACTIVITY LINK ON PROFILE SIDEBAR MENU
  302. *
  303. * @since BuddyBoss Wall 1.0
  304. */
  305. public function bbg_replace_activity_link( $value )
  306. {
  307. $menu_name = $this->option( "MENU_NAME" );
  308. return str_replace( 'Activity', $menu_name, $value );
  309. }
  310.  
  311. /**
  312. * REMOVE TABS FROM PROFILE HEADER
  313. *
  314. * @since BuddyBoss Wall 1.0
  315. */
  316. public function bbg_remove_activity_friends_subnav()
  317. {
  318. global $bp;
  319.  
  320. bp_core_remove_subnav_item( 'activity', 'friends' );
  321. bp_core_remove_subnav_item( 'activity', 'mentions' );
  322. bp_core_remove_subnav_item( 'activity', 'groups' );
  323.  
  324. if ( ! bp_is_my_profile() )
  325. bp_core_remove_subnav_item( 'activity', 'favorites' );
  326. }
  327.  
  328. /**
  329. * RENAME MENU TABS ON PROFILE
  330. */
  331. public function update_bp_menus()
  332. {
  333. buddyboss_wall_log('Updating Menus');
  334. global $bp;
  335.  
  336. $domain = (!empty($bp->displayed_user->id)) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
  337.  
  338. $profile_link = $domain . $bp->activity->slug . '/';
  339.  
  340. // RENAME PERSONAL/WALL TAB
  341. bp_core_new_subnav_item( array(
  342. 'name' => __( 'Wall', 'buddyboss-wall' ),
  343. 'slug' => 'just-me',
  344. 'parent_url' => $profile_link,
  345. 'parent_slug' => $bp->activity->slug,
  346. 'screen_function' => 'bp_activity_screen_my_activity' ,
  347. 'position' => 10
  348. ) );
  349.  
  350. // ADD NEWS FEED TAB
  351. if ( bp_is_my_profile() )
  352. {
  353. bp_core_new_subnav_item( array(
  354. 'name' => __( 'News Feed', 'buddyboss-wall' ),
  355. 'slug' => 'news-feed',
  356. 'parent_url' => $profile_link,
  357. 'parent_slug' => $bp->activity->slug,
  358. 'screen_function' =>'bp_activity_screen_my_activity' ,
  359. 'position' => 11
  360. ) );
  361. }
  362.  
  363. // RENAME FAVORITES TAB
  364. bp_core_new_subnav_item( array(
  365. 'name' => __( 'My Likes', 'buddyboss-wall' ),
  366. 'slug' => 'favorites',
  367. 'parent_url' => $profile_link,
  368. 'parent_slug' => $bp->activity->slug,
  369. 'screen_function' => 'bp_activity_screen_favorites',
  370. 'position' => 12
  371. ) );
  372. }
  373.  
  374. /**
  375. * REDIRECT LOGOUT FROM NEWSFEED
  376. * @since BuddyBoss Wall 1.0
  377. */
  378. public function newsfeed_logout_redirect_url()
  379. {
  380. global $bp;
  381.  
  382. $action = $bp->current_action;
  383.  
  384. if ( $action == 'news-feed' )
  385. {
  386. add_filter( 'logout_url', array( $this, 'set_newsfeed_logout_url' ) );
  387. }
  388. }
  389.  
  390. public function set_newsfeed_logout_url( $logout_url )
  391. {
  392. global $bp;
  393.  
  394. $parts = explode( 'redirect_to', $logout_url );
  395.  
  396. if ( count( $parts ) > 1 )
  397. {
  398. $domain = (!empty($bp->displayed_user->id)) ? $bp->displayed_user->domain : $bp->loggedin_user->domain;
  399.  
  400. $profile_link = $domain . $bp->activity->slug . '/';
  401.  
  402. $logout_url = $parts[0] . '&redirect_to=' . urlencode( $profile_link );
  403. }
  404.  
  405. return $logout_url;
  406. }
  407.  
  408. /**
  409. * RENAME WORDPRESS MENU ITEMS
  410. *
  411. * @since BuddyBoss Wall 1.0
  412. */
  413. public function update_wp_menus()
  414. {
  415. global $wp_admin_bar, $bp;
  416.  
  417. $domain = $bp->loggedin_user->domain;
  418.  
  419. $profile_link = $domain . $bp->activity->slug . '/';
  420.  
  421. $activity_link = trailingslashit( $domain . $bp->activity->slug );
  422.  
  423. // ADD ITEMS
  424. if ( is_user_logged_in() )
  425. {
  426. // REMOVE ITEMS
  427. $wp_admin_bar->remove_menu('my-account-activity-mentions');
  428. $wp_admin_bar->remove_menu('my-account-activity-personal');
  429. $wp_admin_bar->remove_menu('my-account-activity-favorites');
  430. $wp_admin_bar->remove_menu('my-account-activity-friends');
  431. $wp_admin_bar->remove_menu('my-account-activity-groups');
  432.  
  433. // Change menus item to link to wall
  434. $user_info = $wp_admin_bar->get_node( 'user-info' );
  435. if ( ! is_object( $user_info ) ) $user_info = new stdClass();
  436. $user_info->href = trailingslashit( $activity_link );
  437. $wp_admin_bar->add_node( $user_info );
  438.  
  439. $my_acct = $wp_admin_bar->get_node( 'my-account' );
  440. if ( ! is_object( $my_acct ) ) $my_acct = new stdClass();
  441. $my_acct->href = trailingslashit( $activity_link );
  442. $wp_admin_bar->add_node( $my_acct );
  443.  
  444.  
  445. // Change 'Activity' to 'Wall'
  446. $wp_admin_bar->add_menu( array(
  447. 'parent' => 'my-account-buddypress',
  448. 'id' => 'my-account-' . $bp->activity->id,
  449. 'title' => __( 'Wall', 'buddyboss-wall' ),
  450. 'href' => trailingslashit( $activity_link )
  451. ) );
  452.  
  453. // Personal/Wall
  454. $wp_admin_bar->add_menu( array(
  455. 'parent' => 'my-account-' . $bp->activity->id,
  456. 'id' => 'my-account-' . $bp->activity->id . '-wall',
  457. 'title' => __( 'Wall', 'buddyboss-wall' ),
  458. 'href' => trailingslashit( $activity_link )
  459. ) );
  460.  
  461. // News Feed
  462. $wp_admin_bar->add_menu( array(
  463. 'parent' => 'my-account-' . $bp->activity->id,
  464. 'id' => 'my-account-' . $bp->activity->id . '-feed',
  465. 'title' => __( 'News Feed', 'buddyboss-wall' ),
  466. 'href' => trailingslashit( $activity_link . 'news-feed' )
  467. ) );
  468.  
  469. // Favorites
  470. $wp_admin_bar->add_menu( array(
  471. 'parent' => 'my-account-' . $bp->activity->id,
  472. 'id' => 'my-account-' . $bp->activity->id . '-favorites',
  473. 'title' => __( 'My Likes', 'buddyboss-wall' ),
  474. 'href' => trailingslashit( $activity_link . 'favorites' )
  475. ) );
  476. }
  477. }
  478.  
  479. /**
  480. * WRAPPER FUNCTION, WILL BE DEPRECATED
  481. */
  482. public function is_friend( $id )
  483. {
  484. return buddyboss_wall_is_my_friend( $id );
  485. }
  486.  
  487. /**
  488. * GET WALL ACTIVITES
  489. */
  490. public function get_wall_activities( $page = 0, $per_page=20 )
  491. {
  492. global $bp, $wpdb, $buddyboss_ajax_qs;
  493.  
  494. $min = ($page>0)? ($page-1) * $per_page : 0;
  495. $max = ($page+1) * $per_page;
  496. $per_page = bp_get_activity_per_page();
  497. buddyboss_wall_log(" per page $per_page");
  498.  
  499. if (isset($bp->loggedin_user) && isset($bp->loggedin_user->id) && $bp->displayed_user->id == $bp->loggedin_user->id)
  500. {
  501. $myprofile = true;
  502. }
  503. else {
  504. $myprofile = false;
  505. }
  506. // $wpdb->show_errors = BUDDYBOSS_DEBUG;
  507. $user_id = $bp->displayed_user->id;
  508.  
  509. buddyboss_wall_log("Looking at $user_id" );
  510. $user_filter = $bp->displayed_user->domain;
  511.  
  512. // buddyboss_wall_log($friend_id_list);
  513. $table = bp_core_get_table_prefix() . 'bp_activity';
  514. $table2 = bp_core_get_table_prefix() . 'bp_activity_meta';
  515.  
  516. // Default WHERE
  517. $where = "WHERE ( $table.user_id = $user_id AND $table.type!='activity_comment' AND $table.type!='friends' )";
  518.  
  519. // Add @mentions
  520. $mentions_modifier = "OR ( $table.content LIKE '%$user_filter%' AND $table.type!='activity_comment' ) ";
  521.  
  522. // If we have a filter enabled, let's handle that
  523. $ajax_qs = ! empty( $buddyboss_ajax_qs )
  524. ? wp_parse_args( $buddyboss_ajax_qs )
  525. : false;
  526.  
  527. if ( is_array( $ajax_qs ) && isset( $ajax_qs['action'] ) )
  528. {
  529. // Clear the @mentions modifier
  530. $mentions_modifier = '';
  531.  
  532. $filter_qs = $ajax_qs['action'];
  533.  
  534. // Check for commas and adjust
  535. if ( strpos( $filter_qs, ',' ) )
  536. {
  537. $filters = explode( ',', $filter_qs );
  538. }
  539. else {
  540. $filters = (array)$filter_qs;
  541. }
  542.  
  543. // Clean each filter
  544. $filters_clean = array();
  545.  
  546. foreach( $filters as $filter )
  547. {
  548. $filters_clean[] = $wpdb->escape( $filter );
  549. }
  550.  
  551. $filter_sql = "AND ( $table.type='" . implode( "' OR $table.type='", $filters_clean ) . "' )";
  552.  
  553. $where = "WHERE ( $table.user_id = $user_id $filter_sql )";
  554. }
  555.  
  556. // Filter where SQL
  557. $where_filtered = apply_filters( 'buddyboss_wall_query_wall_activity_ids_where', $where );
  558.  
  559. // Filter modifier SQL
  560. $mentions_filtered = apply_filters( 'buddyboss_wall_query_wall_activity_ids_mentions', $mentions_modifier );
  561.  
  562. // Build Query
  563. $query_sql = "SELECT DISTINCT $table.id FROM $table LEFT JOIN $table2 ON $table.id=$table2.activity_id
  564. ORDER BY date_recorded DESC LIMIT $min, 40";
  565.  
  566. // Filter full query SQL
  567. $query_filtered = apply_filters( 'buddyboss_wall_query_wall_activity_ids_full', $query_sql );
  568.  
  569. // Run query
  570. $activities = $wpdb->get_results( $query_filtered, ARRAY_A );
  571.  
  572. buddyboss_wall_log($query_filtered);
  573. buddyboss_wall_log($activities);
  574.  
  575. if ( empty( $activities ) ) return null;
  576.  
  577. $tmp = array();
  578.  
  579. foreach ( $activities as $activity )
  580. {
  581. $tmp[] = $activity ["id"];
  582. }
  583.  
  584. $activity_list = implode( ",", $tmp );
  585.  
  586. return $activity_list;
  587. }
  588.  
  589.  
  590. /**
  591. * GET FEED ACTIVITES
  592. */
  593. public function get_feed_activities( $page = 0, $per_page = 20 )
  594. {
  595. global $bp, $wpdb, $buddyboss_ajax_qs;
  596.  
  597. $min = ( $page > 0 ) ? ( $page - 1 ) * $per_page : 0;
  598. $max = ( $page + 1 ) * $per_page;
  599. $per_page = bp_get_activity_per_page();
  600.  
  601. buddyboss_wall_log( "per page: $per_page" );
  602.  
  603. if ( isset( $bp->loggedin_user ) && isset( $bp->loggedin_user->id )
  604. && intval( $bp->displayed_user->id ) === intval( $bp->loggedin_user->id ) )
  605. {
  606. $myprofile = true;
  607. }
  608. else {
  609. $myprofile = false;
  610. }
  611.  
  612. $wpdb->show_errors = $this->option( 'DEBUG' );
  613.  
  614. $user_id = $bp->displayed_user->id;
  615.  
  616. $user_name = $bp->displayed_user->userdata->user_login;
  617.  
  618. $filter = $bp->displayed_user->domain;
  619.  
  620. buddyboss_wall_log( "Looking at $user_id" );
  621.  
  622. // Get friend's user IDs
  623. if ( function_exists( 'friends_get_friend_user_ids' ) )
  624. {
  625. $user_ids = friends_get_friend_user_ids( $user_id, false, false );
  626. }
  627. else {
  628. $user_ids = array();
  629. }
  630.  
  631. // Get user's groups
  632. if ( function_exists( 'groups_get_user_groups' ) )
  633. {
  634. $groups = groups_get_user_groups( $user_id, false, false );
  635.  
  636. if ( empty( $groups['groups'] ) )
  637. {
  638. $group_ids = array();
  639. }
  640. else {
  641. $group_ids = $groups['groups'];
  642. }
  643. }
  644. else {
  645. $group_ids = array();
  646. }
  647.  
  648. $user_list = implode( ',', $user_ids );
  649. $group_list = implode( ',', $group_ids );
  650.  
  651. $groups_object = $bp->groups->id;
  652.  
  653. // @todo: We should check if both friend's component and groups component is
  654. // active, then check if we have IDs for either and generate a query based
  655. // on that information. For now we'll force ID 0 so an empty query doesn't
  656. // generate an error
  657. if ( empty( $user_list ) )
  658. {
  659. $user_list = 0;
  660. }
  661.  
  662. if ( empty( $group_list ) )
  663. {
  664. $group_list = 0;
  665. }
  666.  
  667. // buddyboss_wall_log( $friend_id_list );
  668. $table = bp_core_get_table_prefix() . 'bp_activity';
  669. $table2 = bp_core_get_table_prefix() . 'bp_activity_meta';
  670.  
  671. // Gets friend's updates. If friend's component isn't enabled this returns nothing.
  672. $where = "WHERE ( $table.user_id IN ($user_list) AND $table.type != 'activity_comment' )";
  673.  
  674. // Get's updates from user's groups
  675. $group_modifier = "OR ( $table.item_id IN ($group_list) AND $table.component = '$groups_object' ) ";
  676.  
  677. // If we have a filter enabled, let's handle that
  678. $ajax_qs = ! empty( $buddyboss_ajax_qs )
  679. ? wp_parse_args( $buddyboss_ajax_qs )
  680. : false;
  681.  
  682. if ( is_array( $ajax_qs ) && isset( $ajax_qs['action'] ) )
  683. {
  684. // Clear group modifier
  685. $group_modifier = '';
  686.  
  687. $filter_qs = $ajax_qs['action'];
  688.  
  689. // Check for commas and adjust
  690. if ( strpos( $filter_qs, ',' ) )
  691. {
  692. $filters = explode( ',', $filter_qs );
  693. }
  694. else {
  695. $filters = (array)$filter_qs;
  696. }
  697.  
  698. // Clean each filter
  699. $filters_clean = array();
  700.  
  701. foreach( $filters as $filter )
  702. {
  703. $filters_clean[] = $wpdb->escape( $filter );
  704. }
  705.  
  706. $filter_sql = "AND ( $table.type='" . implode( "' OR $table.type='", $filters_clean ) . "' )";
  707.  
  708. $where = "WHERE ( $table.user_id IN ($user_list) $filter_sql )";
  709. }
  710.  
  711. // Filter where SQL
  712. $where_filtered = apply_filters( 'buddyboss_wall_query_feed_activity_ids_where', $where );
  713.  
  714. // Filter modifier SQL
  715. $group_filtered = apply_filters( 'buddyboss_wall_query_feed_activity_ids_groups', $group_modifier );
  716.  
  717. // Build Query
  718. $query_sql = "SELECT DISTINCT $table.id FROM $table LEFT JOIN $table2 ON $table.id = $table2.activity_id
  719. $where_filtered
  720. $group_filtered
  721. ORDER BY date_recorded DESC LIMIT $min, 40";
  722.  
  723. // Filter full query SQL
  724. $query_filtered = apply_filters( 'buddyboss_wall_query_feed_activity_ids_full', $query_sql );
  725.  
  726. // Run query
  727. $activities = $wpdb->get_results( $query_filtered, ARRAY_A );
  728.  
  729. buddyboss_wall_log($query_filtered);
  730. buddyboss_wall_log($activities);
  731.  
  732. if ( empty( $activities ) ) return null;
  733.  
  734. $tmp = array();
  735.  
  736. foreach ($activities as $activity )
  737. {
  738. $tmp[] = $activity["id"];
  739. }
  740.  
  741. $activity_list = implode( ",", $tmp );
  742.  
  743. return $activity_list;
  744. }
  745.  
  746. /**
  747. * Retrieve likes for current activity (within activity loop)
  748. *
  749. * @since 1.0
  750. */
  751. public function has_likes( $activity_id = null )
  752. {
  753. if ( $activity_id === null ) $activity_id = bp_get_activity_id();
  754.  
  755. return bp_activity_get_meta( $activity_id, 'favorite_count' );
  756. }
  757. }
  758. add_action( 'init', 'buddyboss_class_custom' );
  759. function buddyboss_class_custom()
  760. {
  761. new BuddyBoss_Wall_BP_Component;
  762. }
  763.  
  764. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement