| 1 | <?php
|
|---|
| 2 | function groups_directory_groups_setup() {
|
|---|
| 3 | global $bp, $current_blog;
|
|---|
| 4 |
|
|---|
| 5 | if ( $bp['current_component'] == $bp['groups']['slug'] && $bp['current_action'] == '' ) {
|
|---|
| 6 | add_action( 'bp_template_content', 'groups_directory_groups_content' );
|
|---|
| 7 | add_action( 'bp_template_sidebar', 'groups_directory_groups_sidebar' );
|
|---|
| 8 |
|
|---|
| 9 | wp_enqueue_script( 'bp-groups-directory-groups', site_url( MUPLUGINDIR . '/bp-groups/js/directory-groups.js' ), array( 'jquery', 'jquery-livequery-pack' ) );
|
|---|
| 10 | wp_enqueue_style( 'bp-groups-directory-groups', site_url( MUPLUGINDIR . '/bp-groups/css/directory-groups.css' ) );
|
|---|
| 11 |
|
|---|
| 12 | if ( file_exists( TEMPLATEPATH . '/plugin-template.php' ) )
|
|---|
| 13 | bp_core_load_template('plugin-template');
|
|---|
| 14 | else
|
|---|
| 15 | wp_die( __( 'To enable the group directory you must drop the "plugin-template.php" file into your theme directory.', 'buddypress' ) );
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 | add_action( 'wp', 'groups_directory_groups_setup', 5 );
|
|---|
| 19 |
|
|---|
| 20 | function groups_directory_groups_content() {
|
|---|
| 21 | global $bp;
|
|---|
| 22 |
|
|---|
| 23 | $pag_page = isset( $_GET['page'] ) ? intval( $_GET['page'] ) : 1;
|
|---|
| 24 | $pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : 10;
|
|---|
| 25 |
|
|---|
| 26 | if ( isset( $_GET['s'] ) )
|
|---|
| 27 | $groups = BP_Groups_Group::search_groups( $_GET['s'], $pag_num, $pag_page );
|
|---|
| 28 | else
|
|---|
| 29 | $groups = groups_get_active( $pag_num, $pag_page );
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | $pag_links = paginate_links( array(
|
|---|
| 33 | 'base' => add_query_arg( 'page', '%#%' ),
|
|---|
| 34 | 'format' => '',
|
|---|
| 35 | 'total' => ceil( $groups['total'] / $pag_num ),
|
|---|
| 36 | 'current' => $pag_page,
|
|---|
| 37 | 'prev_text' => '«',
|
|---|
| 38 | 'next_text' => '»',
|
|---|
| 39 | 'mid_size' => 1
|
|---|
| 40 | ));
|
|---|
| 41 |
|
|---|
| 42 | $from_num = intval( ( $pag_page - 1 ) * $pag_num ) + 1;
|
|---|
| 43 | $to_num = ( $from_num + ( $pag_num - 1 ) > $groups['total'] ) ? $groups['total'] : $from_num + ( $pag_num - 1 );
|
|---|
| 44 |
|
|---|
| 45 | ?>
|
|---|
| 46 | <div id="content" class="narrowcolumn">
|
|---|
| 47 |
|
|---|
| 48 | <form action="<?php echo site_url() . '/' ?>" method="post" id="groups-directory-form">
|
|---|
| 49 | <div class="widget">
|
|---|
| 50 | <h2 class="widgettitle"><?php _e( 'Group Directory', 'buddypress' ) ?></h2>
|
|---|
| 51 | <ul id="letter-list">
|
|---|
| 52 | <li><a href="#a" id="letter-a">A</a></li>
|
|---|
| 53 | <li><a href="#b" id="letter-b">B</a></li>
|
|---|
| 54 | <li><a href="#c" id="letter-c">C</a></li>
|
|---|
| 55 | <li><a href="#d" id="letter-d">D</a></li>
|
|---|
| 56 | <li><a href="#e" id="letter-e">E</a></li>
|
|---|
| 57 | <li><a href="#f" id="letter-f">F</a></li>
|
|---|
| 58 | <li><a href="#g" id="letter-g">G</a></li>
|
|---|
| 59 | <li><a href="#h" id="letter-h">H</a></li>
|
|---|
| 60 | <li><a href="#i" id="letter-i">I</a></li>
|
|---|
| 61 | <li><a href="#j" id="letter-j">J</a></li>
|
|---|
| 62 | <li><a href="#k" id="letter-k">K</a></li>
|
|---|
| 63 | <li><a href="#l" id="letter-l">L</a></li>
|
|---|
| 64 | <li><a href="#m" id="letter-m">M</a></li>
|
|---|
| 65 | <li><a href="#n" id="letter-n">N</a></li>
|
|---|
| 66 | <li><a href="#o" id="letter-o">O</a></li>
|
|---|
| 67 | <li><a href="#p" id="letter-p">P</a></li>
|
|---|
| 68 | <li><a href="#q" id="letter-q">Q</a></li>
|
|---|
| 69 | <li><a href="#r" id="letter-r">R</a></li>
|
|---|
| 70 | <li><a href="#s" id="letter-s">S</a></li>
|
|---|
| 71 | <li><a href="#t" id="letter-t">T</a></li>
|
|---|
| 72 | <li><a href="#u" id="letter-u">U</a></li>
|
|---|
| 73 | <li><a href="#v" id="letter-v">V</a></li>
|
|---|
| 74 | <li><a href="#w" id="letter-w">W</a></li>
|
|---|
| 75 | <li><a href="#x" id="letter-x">X</a></li>
|
|---|
| 76 | <li><a href="#y" id="letter-y">Y</a></li>
|
|---|
| 77 | <li><a href="#z" id="letter-z">Z</a></li>
|
|---|
| 78 | </ul>
|
|---|
| 79 |
|
|---|
| 80 | <div class="clear"></div>
|
|---|
| 81 | </div>
|
|---|
| 82 |
|
|---|
| 83 | <div class="widget">
|
|---|
| 84 | <h2 class="widgettitle"><?php _e( 'Group Listing', 'buddypress' ) ?></h2>
|
|---|
| 85 |
|
|---|
| 86 | <div id="group-dir-list">
|
|---|
| 87 | <?php if ( $groups['groups'] ) : ?>
|
|---|
| 88 | <div id="group-dir-count" class="pag-count">
|
|---|
| 89 | <?php echo sprintf( __( 'Viewing group %d to %d (%d total active groups)', 'buddypress' ), $from_num, $to_num, $groups['total'] ); ?>
|
|---|
| 90 | <img id="ajax-loader-groups" src="<?php echo $bp['core']['image_base'] ?>/ajax-loader.gif" height="7" alt="<?php _e( "Loading", "buddypress" ) ?>" style="display: none;" />
|
|---|
| 91 | </div>
|
|---|
| 92 |
|
|---|
| 93 | <div class="pagination-links" id="group-dir-pag">
|
|---|
| 94 | <?php echo $pag_links ?>
|
|---|
| 95 | </div>
|
|---|
| 96 |
|
|---|
| 97 | <ul id="groups-list" class="item-list">
|
|---|
| 98 | <?php foreach ( $groups['groups'] as $group ) : ?>
|
|---|
| 99 | <?php $group = new BP_Groups_Group( $group->group_id, false, false ); ?>
|
|---|
| 100 | <li>
|
|---|
| 101 | <div class="item-avatar">
|
|---|
| 102 | <a href="<?php echo bp_group_permalink( $group ) ?>" title="<?php echo $group->name ?>"><img src="<?php echo $group->avatar_thumb ?>" class="avatar" alt="<?php echo $group->name ?> Avatar" /></a>
|
|---|
| 103 | </div>
|
|---|
| 104 |
|
|---|
| 105 | <div class="item">
|
|---|
| 106 | <div class="item-title"><a href="<?php echo bp_group_permalink( $group ) ?>" title="<?php echo $group->name ?>"><?php echo $group->name ?></a></div>
|
|---|
| 107 | <div class="item-meta"><span class="activity"><?php echo bp_core_get_last_activity( groups_get_groupmeta( $group->id, 'last_activity' ), __('active %s ago', 'buddypress') ) ?></span></div>
|
|---|
| 108 | <div class="item-meta desc"><?php echo bp_create_excerpt( $group->description ) ?></div>
|
|---|
| 109 | </div>
|
|---|
| 110 |
|
|---|
| 111 | <div class="action">
|
|---|
| 112 | <?php bp_group_join_button( $group ) ?>
|
|---|
| 113 | <div class="meta">
|
|---|
| 114 | <?php $member_count = groups_get_groupmeta( $group->id, 'total_member_count' ) ?>
|
|---|
| 115 | <?php echo ucwords($group->status) ?> <?php _e( 'Group', 'buddypress' ) ?> /
|
|---|
| 116 | <?php if ( $member_count == 1 ) : ?>
|
|---|
| 117 | <?php printf( __( '%d member', 'buddypress' ), $member_count ) ?>
|
|---|
| 118 | <?php else : ?>
|
|---|
| 119 | <?php printf( __( '%d members', 'buddypress' ), $member_count ) ?>
|
|---|
| 120 | <?php endif; ?>
|
|---|
| 121 | </div>
|
|---|
| 122 | </div>
|
|---|
| 123 |
|
|---|
| 124 | <div class="clear"></div>
|
|---|
| 125 | </li>
|
|---|
| 126 | <?php endforeach; ?>
|
|---|
| 127 | </ul>
|
|---|
| 128 |
|
|---|
| 129 | <?php
|
|---|
| 130 | if ( isset( $_GET['s'] ) ) {
|
|---|
| 131 | echo '<input type="hidden" id="search_terms" value="' . $_GET['s'] . '" name="search_terms" />';
|
|---|
| 132 | }
|
|---|
| 133 | ?>
|
|---|
| 134 |
|
|---|
| 135 | <?php else: ?>
|
|---|
| 136 | <div id="message" class="info">
|
|---|
| 137 | <p><?php _e( 'No groups found.', 'buddypress' ) ?></p>
|
|---|
| 138 | </div>
|
|---|
| 139 | <?php endif; ?>
|
|---|
| 140 | </div>
|
|---|
| 141 |
|
|---|
| 142 | </div>
|
|---|
| 143 |
|
|---|
| 144 | <?php do_action( 'groups_directory_groups_content' ) ?>
|
|---|
| 145 |
|
|---|
| 146 | <?php wp_nonce_field('directory_groups', '_wpnonce-group-filter' ) ?>
|
|---|
| 147 | </form>
|
|---|
| 148 |
|
|---|
| 149 | </div>
|
|---|
| 150 | <?php
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | function groups_directory_groups_sidebar() {
|
|---|
| 154 | global $bp;
|
|---|
| 155 | ?>
|
|---|
| 156 | <div class="widget">
|
|---|
| 157 | <h2 class="widgettitle"><?php _e( 'Find Groups', 'buddypress' ) ?></h2>
|
|---|
| 158 | <form action="<?php echo site_url() . '/' . $bp['groups']['slug'] . '/search/' ?>" method="post" id="search-groups-form">
|
|---|
| 159 | <label><input type="text" name="groups_search" id="groups_search" value="<?php if ( isset( $_GET['s'] ) ) { echo $_GET['s']; } else { _e('Search anything...', 'buddypress' ); } ?>" onfocus="if (this.value == '<?php _e('Search anything...', 'buddypress' ) ?>') {this.value = '';}" onblur="if (this.value == '') {this.value = '<?php _e('Search anything...', 'buddypress' ) ?>';}" /></label>
|
|---|
| 160 | <input type="submit" id="groups_search_submit" name="groups_search_submit" value="Search" />
|
|---|
| 161 | </form>
|
|---|
| 162 | </div>
|
|---|
| 163 |
|
|---|
| 164 | <div class="widget">
|
|---|
| 165 | <h2 class="widgettitle"><?php _e( 'Featured Groups', 'buddypress' ) ?></h2>
|
|---|
| 166 |
|
|---|
| 167 | <?php $groups = BP_Groups_Group::get_random( 3, 1 ) ?>
|
|---|
| 168 |
|
|---|
| 169 | <?php if ( $groups['groups'] ) { ?>
|
|---|
| 170 | <ul id="featured-group-list" class="item-list">
|
|---|
| 171 | <?php foreach( $groups['groups'] as $group ) : ?>
|
|---|
| 172 | <?php $group = new BP_Groups_Group( $group->group_id, false, false ); ?>
|
|---|
| 173 | <li>
|
|---|
| 174 | <div class="item-avatar">
|
|---|
| 175 | <a href="<?php echo bp_group_permalink( $group ) ?>" title="<?php echo $group->name ?>"><img src="<?php echo $group->avatar_thumb ?>" class="avatar" alt="<?php echo $group->name ?> Avatar" /></a>
|
|---|
| 176 | </div>
|
|---|
| 177 |
|
|---|
| 178 | <div class="item">
|
|---|
| 179 | <div class="item-title"><a href="<?php echo bp_group_permalink( $group ) ?>" title="<?php echo $group->name ?>"><?php echo $group->name ?></a></div>
|
|---|
| 180 | <div class="item-meta"><span class="activity"><?php echo bp_core_get_last_activity( groups_get_groupmeta( $group->id, 'last_activity' ), __('active %s ago', 'buddypress') ) ?></span></div>
|
|---|
| 181 |
|
|---|
| 182 | <div class="item-title group-data">
|
|---|
| 183 | <p class="field-name"><?php _e( 'Members', 'buddypress' ) ?>: <span><?php echo groups_get_groupmeta( $group->id, 'total_member_count' ) ?></span></p>
|
|---|
| 184 | <p class="field-name"><?php _e( 'Description', 'buddypress' ) ?>:</p>
|
|---|
| 185 | <?php echo bp_create_excerpt( $group->description ) ?>
|
|---|
| 186 | </div>
|
|---|
| 187 | </div>
|
|---|
| 188 | </li>
|
|---|
| 189 | <?php endforeach; ?>
|
|---|
| 190 | </ul>
|
|---|
| 191 | <?php } else { ?>
|
|---|
| 192 | <div id="message" class="info">
|
|---|
| 193 | <p><?php _e( 'There are no groups to feature.', 'buddypress' ) ?></p>
|
|---|
| 194 | </div>
|
|---|
| 195 | <?php } ?>
|
|---|
| 196 | </div>
|
|---|
| 197 |
|
|---|
| 198 | <?php do_action( 'groups_directory_groups_sidebar' ) ?>
|
|---|
| 199 |
|
|---|
| 200 | <?php
|
|---|
| 201 | }
|
|---|