Permalink
Browse files

seeding

  • Loading branch information...
etivite committed Jan 7, 2012
0 parents commit dd0dbc2eb94e6ba2d19439a214788c5234840ba4
@@ -0,0 +1,110 @@
+<?php
+
+function etivite_bp_community_stats_admin_counts( ) {
+ return array( 'members','active','status','forums','blogs','groups','comments','posts' );
+}
+
+function etivite_bp_community_stats_admin_count_check( $type, $currenttypes ) {
+ if ( is_multisite() && ( $type == 'comments' || $type == 'posts' ) ) {
+ echo 'disabled';
+ return;
+ }
+
+ if ( !is_multisite() && $type == 'blogs' ) {
+ echo 'disabled';
+ return;
+ }
+
+ if ( in_array( $type, $currenttypes) )
+ echo 'checked';
+
+ return;
+}
+
+function etivite_bp_community_stats_admin() {
+ global $bp;
+
+ /* If the form has been submitted and the admin referrer checks out, save the settings */
+ if ( isset( $_POST['submit'] ) && check_admin_referer('etivite_bp_community_stats_admin') ) {
+
+ if( isset($_POST['ab_community_counts'] ) && !empty($_POST['ab_community_counts']) ) {
+ update_option( 'bp_community_stats_display', $_POST['ab_community_counts'] );
+ } else {
+ update_option( 'bp_community_stats_display', false );
+ }
+
+ if( isset($_POST['ab_community_footer'] ) && !empty($_POST['ab_community_footer']) && (int)$_POST['ab_community_footer'] == 1 ) {
+ update_option( 'bp_community_stats_display_footer', true );
+ } else {
+ update_option( 'bp_community_stats_display_footer', false );
+ }
+
+ $updated = true;
+ }
+?>
+ <div class="wrap">
+ <h2><?php _e( 'Community Stats', 'bp-community-stats' ); ?></h2>
+
+ <?php if ( isset($updated) ) : echo "<div id='message' class='updated fade'><p>" . __( 'Settings Updated.', 'bp-community-stats' ) . "</p></div>"; endif; ?>
+
+ <form action="<?php echo network_admin_url('/admin.php?page=bp-community-stats-settings'); ?>" name="bp-community-stats-settings-form" id="bp-community-stats-settings-form" method="post">
+
+ <h4><?php _e( 'Display total counts for:', 'bp-community-stats' ); ?></h4>
+
+ <table class="form-table">
+ <?php
+
+ $enabledcounts = (array) get_option( 'bp_community_stats_display');
+ $totalcounts = etivite_bp_community_stats_admin_counts();
+
+ foreach ($totalcounts as $count) { ?>
+ <tr>
+ <th><label for="type-<?php echo $count ?>"><?php echo $count ?></label></th>
+ <td><input id="type-<?php echo $count ?>" type="checkbox" <?php etivite_bp_community_stats_admin_count_check( $count, $enabledcounts ); ?> name="ab_community_counts[]" value="<?php echo $count ?>" /></td>
+ </tr>
+ <?php } ?>
+ </table>
+
+ <h4><?php _e( 'Display:', 'bp-community-stats' ); ?></h4>
+
+ <table class="form-table">
+ <tr>
+ <th><label for="ab_community_footer"><?php _e('Display in Footer?','bp-community-stats') ?></label></th>
+ <td><input type="checkbox" name="ab_community_footer" id="ab_community_footer" value="1"<?php if ( get_option( 'bp_community_stats_display_footer' ) ) { ?> checked="checked"<?php } ?> /></td>
+ </tr>
+
+ </table>
+
+ <?php wp_nonce_field( 'etivite_bp_community_stats_admin' ); ?>
+
+ <p class="submit"><input type="submit" name="submit" value="Save Settings"/></p>
+
+ <p>A theme and admin dashboard widget are available.</p>
+
+ <?php if ( is_multisite() ) echo '<p class="description">Please note: Total Posts and Comments not support in multisite/network mode</p>'; ?>
+ </form>
+
+ <h3>About:</h3>
+ <div id="plugin-about" style="margin-left:15px;">
+
+ <p>
+ <a href="http://etivite.com/wordpress-plugins/buddypress-community-stats/">BuddyPress Community Stats - About Page</a><br/>
+ </p>
+
+ <div class="plugin-author">
+ <strong>Author:</strong> <a href="http://profiles.wordpress.org/users/etivite/"><img style="height: 24px; width: 24px;" class="photo avatar avatar-24" src="http://www.gravatar.com/avatar/9411db5fee0d772ddb8c5d16a92e44e0?s=24&amp;d=monsterid&amp;r=g" alt=""> rich @etivite</a><br/>
+ <a href="http://twitter.com/etivite">@etivite</a>
+ </div>
+
+ <p>
+ <a href="http://etivite.com">Author's site</a><br/>
+ <a href="http://etivite.com/api-hooks/">Developer Hook and Filter API Reference</a><br/>
+ <a href="http://etivite.com/wordpress-plugins/">WordPress Plugins</a><br/>
+ </p>
+ </div>
+
+ </div>
+<?php
+}
+
+?>
@@ -0,0 +1,50 @@
+<?php
+function etivite_bp_community_stats_dashboard_widget(){
+ wp_add_dashboard_widget('etivite_bp_community_stats_dashboard_widget', __( 'Community Stats', 'bp-community-stats' ), 'etivite_bp_community_stats_get_dashboard_widget');
+}
+
+function etivite_bp_community_stats_get_dashboard_widget() {
+
+ $data = (array) maybe_unserialize( get_option( 'bp_community_stats_display') );
+
+ if ( in_array( 'members', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_members();
+
+ if ( in_array( 'active', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_active();
+
+ if ( in_array( 'status', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_status();
+
+ if ( in_array( 'groups', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_groups();
+
+ if ( in_array( 'forums', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_forums('</li><li>');
+
+ if ( in_array( 'blogs', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_blogs();
+
+ if ( in_array( 'posts', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_posts();
+
+ if ( in_array( 'comments', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_comments();
+
+ echo '<ul>';
+
+ $i = 0;
+ $l = count( $wcounts );
+
+ foreach ( (array) $wcounts as $count) {
+ $isLastItem = ( $i == ( $l - 1 ) );
+
+ echo '<li>' . $count .'</li>';
+
+ ++$i;
+ }
+
+ echo '</ul>';
+
+}
+?>
@@ -0,0 +1,77 @@
+<?php
+/*
+Plugin Name: BuddyPress Community Stats
+Plugin URI: http://wordpress.org/extend/plugins/buddypress-community-stats/
+Description: Display a basic community stats (and widget)
+Author: rich @etiviti
+Author URI: http://etivite.com
+License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt
+Version: 0.5.1
+Text Domain: bp-community-stats
+Network: true
+*/
+
+//TODO
+//need blog posts and ms blog posts count (use activity table - but then missing pre-install data) (use wpcron to loop blogs and count?!?)
+
+//override default 30 days of last active check
+if ( !defined( 'BP_COMMUNITY_STATS_ACTIVE_DAYS' ) )
+ define ( 'BP_COMMUNITY_STATS_ACTIVE_DAYS', 30 );
+
+/* Only load code that needs BuddyPress to run once BP is loaded and initialized. */
+function etivite_bp_community_stats_init() {
+
+ if ( file_exists( dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' ) )
+ load_textdomain( 'bp-community-stats', dirname( __FILE__ ) . '/languages/' . get_locale() . '.mo' );
+
+ require( dirname( __FILE__ ) . '/bp-community-stats.php' );
+
+ if ( get_option( 'bp_community_stats_display_footer' ) )
+ add_action( 'bp_footer', 'etivite_bp_community_stats_footer' );
+
+ add_action( bp_core_admin_hook(), 'etivite_bp_community_stats_admin_add_admin_menu' );
+
+}
+add_action( 'bp_include', 'etivite_bp_community_stats_init', 88 );
+//add_action( 'bp_init', 'etivite_bp_community_stats_init', 88 );
+
+//add admin_menu page
+function etivite_bp_community_stats_admin_add_admin_menu() {
+ global $bp;
+
+ if ( !is_super_admin() )
+ return false;
+
+ //Add the component's administration tab under the "BuddyPress" menu for site administrators
+ require ( dirname( __FILE__ ) . '/admin/bp-community-stats-admin.php' );
+ require ( dirname( __FILE__ ) . '/admin/bp-community-stats-widget-dashboard.php' );
+
+ add_submenu_page( 'bp-general-settings', __( 'Community Stats', 'bp-community-stats' ), __( 'Community Stats', 'bp-community-stats' ), 'manage_options', 'bp-community-stats-settings', 'etivite_bp_community_stats_admin' );
+
+ //set up defaults
+
+ //dashboard widget
+ add_action('wp_dashboard_setup', 'etivite_bp_community_stats_dashboard_widget');
+}
+
+/* Stolen from Welcome Pack - thanks, Paul! then stolen from boone*/
+function etivite_bp_community_stats_admin_add_action_link( $links, $file ) {
+ if ( 'buddypress-community-stats/bp-community-stats-loader.php' != $file )
+ return $links;
+
+ if ( function_exists( 'bp_core_do_network_admin' ) ) {
+ $settings_url = add_query_arg( 'page', 'bp-community-stats-settings', bp_core_do_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ } else {
+ $settings_url = add_query_arg( 'page', 'bp-community-stats-settings', is_multisite() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) );
+ }
+
+ $settings_link = '<a href="' . $settings_url . '">' . __( 'Settings', 'bp-community-stats' ) . '</a>';
+ array_unshift( $links, $settings_link );
+
+ return $links;
+}
+add_filter( 'plugin_action_links', 'etivite_bp_community_stats_admin_add_action_link', 10, 2 );
+
+//widget reference for all
+require( dirname( __FILE__ ) . '/bp-community-stats-widget.php' );
+?>
@@ -0,0 +1,80 @@
+<?php
+
+/* Register widgets for the core component */
+function etivite_bp_community_stats_widget_init() {
+ add_action('widgets_init', create_function('', 'return register_widget("etivite_bp_community_stats_Widget");') );
+}
+add_action( 'bp_register_widgets', 'etivite_bp_community_stats_widget_init', 15 );
+
+class etivite_bp_community_stats_Widget extends WP_Widget {
+
+ function etivite_bp_community_stats_widget() {
+ parent::WP_Widget( false, $name = __( 'Community Stats', 'bp-community-stats' ) );
+ }
+
+ function widget($args, $instance) {
+
+ //don't care to load on these pages
+ if ( bp_is_register_page() || bp_is_activation_page() )
+ return;
+
+ extract( $args );
+
+ $data = (array) maybe_unserialize( get_option( 'bp_community_stats_display') );
+
+ if ( in_array( 'members', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_members();
+
+ if ( in_array( 'active', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_active();
+
+ if ( in_array( 'status', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_status();
+
+ if ( in_array( 'groups', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_groups();
+
+ if ( in_array( 'forums', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_forums('</li><li>');
+
+ if ( in_array( 'blogs', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_blogs();
+
+ if ( in_array( 'posts', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_posts();
+
+ if ( in_array( 'comments', $data ) )
+ $wcounts[] = etivite_bp_community_stats_get_comments();
+
+ echo $before_widget;
+ echo $before_title
+ . $widget_name
+ . $after_title;
+
+
+echo '<ul>';
+ $i = 0;
+ $l = count( $wcounts );
+
+ foreach ( (array) $wcounts as $count) {
+ $isLastItem = ( $i == ( $l - 1 ) );
+
+ echo '<li>' . $count .'</li>';
+
+ ++$i;
+ }
+echo '</ul>';
+
+ echo $after_widget;
+ }
+
+ function update( $new_instance, $old_instance ) {
+
+ }
+
+ function form( $instance ) {
+
+ }
+}
+
+?>
Oops, something went wrong.

0 comments on commit dd0dbc2

Please sign in to comment.