Advertisement
Guest User

bp-activity-shortcode-mods.php

a guest
Jul 14th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.09 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Plugin Name: BuddyPress Activity Shortcode
  4.  * Author: Brajesh Singh(BuddyDev)
  5.  * Plugin URI: http://buddydev.com/plugins/bp-activity-shortcode/
  6.  * Author URI: http://buddydev.com/members/sbrajesh/
  7.  * Version: 1.0.2
  8.  * License: GPL
  9.  */
  10. class BD_Activity_Stream_Shortcodes_Helper{
  11.    
  12.     private static $instance;
  13.  
  14.     private function __construct() {
  15.  
  16.         //register shortcodes
  17.         $this->register_shortcodes();
  18.  
  19.     }
  20.    
  21.     /**
  22.      * Register  shortcodes
  23.      *
  24.      */
  25.     private function register_shortcodes() {
  26.         //[activity-stream display_comments=threaded|none title=somethimg per_page=something]
  27.        
  28.         add_shortcode( 'activity-stream', array( $this, 'generate_activity_stream' ) );
  29.      
  30.                
  31.  
  32.     }
  33.     /**
  34.      * Get Instance
  35.      *
  36.      *
  37.      * @return BD_Activity_Stream_Shortcodes_Helper
  38.      */
  39.     public static function get_instance() {
  40.  
  41.         if ( !isset( self::$instance ) )
  42.             self::$instance = new self();
  43.  
  44.         return self::$instance;
  45.     }
  46.    
  47.    
  48.  
  49.     public function generate_activity_stream( $atts, $content = null ) {
  50.         //allow to use all those args awesome!
  51.        $atts=shortcode_atts(array(
  52.             'title'            => 'Latest Activity',//title of the section
  53.             'pagination'       => 'true',//show or not
  54.             'display_comments' => 'threaded',
  55.             'include'          => false,     // pass an activity_id or string of IDs comma-separated
  56.             'exclude'          => false,     // pass an activity_id or string of IDs comma-separated
  57.             'in'               => false,     // comma-separated list or array of activity IDs among which to search
  58.             'sort'             => 'DESC',    // sort DESC or ASC
  59.             'page'             => 1,         // which page to load
  60.             'per_page'         => 5,         //how many per page
  61.             'max'              => false,     // max number to return
  62.  
  63.             // Scope - pre-built activity filters for a user (friends/groups/favorites/mentions)
  64.             'scope'            => false,
  65.  
  66.             // Filtering
  67.             'user_id'          => false,    // user_id to filter on
  68.             'object'           => false,    // object to filter on e.g. groups, profile, status, friends
  69.             'action'           => false,    // action to filter on e.g. activity_update, new_forum_post, profile_updated
  70.             'primary_id'       => false,    // object ID to filter on e.g. a group_id or forum_id or blog_id etc.
  71.             'secondary_id'     => false,    // secondary object ID to filter on e.g. a post_id
  72.  
  73.             // Searching
  74.             'search_terms'     => false,         // specify terms to search on
  75.             'use_compat'       => bp_use_theme_compat_with_current_theme()
  76.         ), $atts );
  77.        
  78.         extract( $atts );
  79.    
  80.      
  81.        
  82.         ob_start(); ?>
  83.  
  84. <?php if( $use_compat):?>
  85.         <div id="buddypress">
  86. <?php endif;?>     
  87. <?php if ( is_user_logged_in() ) : ?>
  88. <?php include_once( WP_PLUGIN_DIR.'/buddypress/bp-templates/bp-legacy/buddypress/activity/post-form.php'); ?>
  89. <?php endif; ?><br />
  90.     <?php if($title): ?>
  91.             <h3 class="activity-shortcode-title"><?php echo $title; ?></h3>
  92.         <?php endif;?>    
  93.        
  94.         <?php do_action( 'bp_before_activity_loop' ); ?>
  95.  
  96.         <?php if ( bp_has_activities($atts)  ) : ?>
  97.             <div class="activity <?php if(!$display_comments): ?> hide-activity-comments<?php endif; ?> shortcode-activity-stream">
  98.  
  99.                  <?php if ( empty( $_POST['page'] ) ) : ?>
  100.  
  101.                     <ul id="activity-stream" class="activity-list item-list">
  102.  
  103.                  <?php endif; ?>
  104.  
  105.                  <?php while ( bp_activities() ) : bp_the_activity(); ?>
  106.  
  107.                     <?php bp_get_template_part( 'activity/entry'); ?>
  108.  
  109.                  <?php endwhile; ?>
  110.  
  111.                  <?php if ( empty( $_POST['page'] ) ) : ?>
  112.                     </ul>
  113.                  <?php endif; ?>
  114.                
  115.                 <?php if($pagination):?>
  116.                     <div class="pagination">
  117.                         <div class="pag-count"><?php bp_activity_pagination_count(); ?></div>
  118.                         <div class="pagination-links"><?php bp_activity_pagination_links(); ?></div>
  119.                     </div>
  120.                 <?php endif;?>
  121.             </div>
  122.  
  123.    
  124.     <?php else : ?>
  125.  
  126.         <div id="message" class="info">
  127.             <p><?php _e( 'Sorry, there was no activity found. Please try a different filter.', 'buddypress' ); ?></p>
  128.         </div>
  129.            
  130.          
  131.     <?php endif; ?>
  132.            
  133.     <?php do_action( 'bp_after_activity_loop' ); ?>
  134.  
  135.     <form action="" name="activity-loop-form" id="activity-loop-form" method="post">
  136.  
  137.         <?php wp_nonce_field( 'activity_filter', '_wpnonce_activity_filter' ); ?>
  138.  
  139.     </form>
  140.      <?php if( $use_compat ):?>      
  141.         </div>
  142.      <?php endif;?>
  143.     <?php
  144.  
  145.     $output = ob_get_clean();
  146.    
  147.    
  148.     return $output;
  149.  
  150.     }
  151.  
  152. }
  153.  
  154. BD_Activity_Stream_Shortcodes_Helper::get_instance();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement