Advertisement
Guest User

Bp-custom class overide

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