[buddypress-trac] [BuddyPress Trac] #330: Pagination in Blogs resulting in 404

buddypress-trac noreply at wordpress.org
Wed Mar 20 20:50:00 UTC 2024


#330: Pagination in Blogs resulting in 404
--------------------------+---------------------
 Reporter:  jmax123       |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  minor         |   Milestone:
Component:  (not sure)    |     Version:
 Severity:  trivial       |  Resolution:  fixed
 Keywords:                |
--------------------------+---------------------
Changes (by gorgebilly):

 * component:   => (not sure)
 * severity:   => trivial


Comment:

 Here is the fixed code in changeset

 {{{
 <?php
 2
 3       Class BP_Groups_Group {
 4               var $id;
 5               var $creator_id;
 6               var $name;
 7               var $slug;
 8               var $description;
 9               var $news;
 10              var $status;
 11              var $is_invitation_only;
 12              var $enable_wire;
 13              var $enable_forum;
 14              var $enable_photos;
 15              var $photos_admin_only;
 16              var $date_created;
 17
 18              var $avatar_thumb;
 19              var $avatar_full;
 20
 21              var $user_dataset;
 22
 23              var $admins;
 24              var $total_member_count;
 25              var $random_members;
 26              var $latest_wire_posts;
 27              var $random_photos;
 28
 29              function bp_groups_group( $id = null, $single = false ) {
 30                      if ( $id ) {
 31                              $this->id = $id;
 32                              $this->populate();
 33                      }
 34
 35                      if ( $single ) {
 36                              $this->populate_meta();
 37                      }
 38              }
 39
 40              function populate() {
 41                      global $wpdb, $bp;
 42
 43                      $sql = $wpdb->prepare( "SELECT * FROM " .
 $bp['groups']['table_name'] . " WHERE id = %d", $this->id );
 44                      $group = $wpdb->get_row($sql);
 45
 46                      if ( $group ) {
 47                              $this->creator_id = $group->creator_id;
 48                              $this->name = $group->name;
 49                              $this->slug = $group->slug;
 50                              $this->description = $group->description;
 51                              $this->news = $group->news;
 52                              $this->status = $group->status;
 53                              $this->is_invitation_only =
 $group->is_invitation_only;
 54                              $this->enable_wire = $group->enable_wire;
 55                              $this->enable_forum =
 $group->enable_forum;
 56                              $this->enable_photos =
 $group->enable_photos;
 57                              $this->photos_admin_only =
 $group->photos_admin_only;
 58                              $this->date_created =
 $group->date_created;
 59
 60                              if ( !$group->avatar_thumb )
 61                                      $this->avatar_thumb =
 $bp['groups']['image_base'] . '/none-thumbnail.gif';
 62                              else
 63                                      $this->avatar_thumb =
 $group->avatar_thumb;
 64
 65                              if ( !$group->avatar_full )
 66                                      $this->avatar_full =
 $bp['groups']['image_base'] . '/none.gif';
 67                              else
 68                                      $this->avatar_full =
 $group->avatar_full;
 69
 70                              $this->user_dataset =
 $this->get_user_dataset();
 71                              $this->total_member_count = count(
 $this->user_dataset );
 72                      }
 73              }
 74
 75              function populate_meta() {
 76                      if ( $this->id ) {
 77                              $this->admins =
 $this->get_administrators();
 78                              $this->random_members =
 $this->get_random_members();
 79                              $this->latest_wire_posts =
 $this->get_latest_wire_posts();
 80                              $this->random_photos =
 $this->get_random_photos();
 81                      }
 82              }
 83
 84              function save() {
 85                      global $wpdb, $bp;
 86
 87                      if ( $this->id ) {
 88                              $sql = $wpdb->prepare(
 89                                      "UPDATE " .
 $bp['groups']['table_name'] . " SET
 90                                              creator_id = %d,
 91                                              name = %s,
 92                                              slug = %s,
 93                                              description = %s,
 94                                              news = %s,
 95                                              status = %s,
 96                                              is_invitation_only = %d,
 97                                              enable_wire = %d,
 98                                              enable_forum = %d,
 99                                              enable_photos = %d,
 100                                             photos_admin_only = %d,
 101                                             date_created =
 FROM_UNIXTIME(%d),
 102                                             avatar_thumb = %s,
 103                                             avatar_full = %s
 104                                     WHERE
 105                                             id = %d
 106                                     ",
 107                                             $this->creator_id,
 108                                             $this->name,
 109                                             $this->slug,
 110                                             $this->description,
 111                                             $this->news,
 112                                             $this->status,
 113                                             $this->is_invitation_only,
 114                                             $this->enable_wire,
 115                                             $this->enable_forum,
 116                                             $this->enable_photos,
 117                                             $this->photos_admin_only,
 118                                             $this->date_created,
 119                                             $this->avatar_thumb,
 120                                             $this->avatar_full,
 121                                             $this->id
 122                             );
 123                     } else {
 124                             $sql = $wpdb->prepare(
 125                                     "INSERT INTO " .
 $bp['groups']['table_name'] . " (
 126                                             creator_id,
 127                                             name,
 128                                             slug,
 129                                             description,
 130                                             news,
 131                                             status,
 132                                             is_invitation_only,
 133                                             enable_wire,
 134                                             enable_forum,
 135                                             enable_photos,
 136                                             photos_admin_only,
 137                                             date_created,
 138                                             avatar_thumb,
 139                                             avatar_full
 140                                     ) VALUES (
 141                                             %d, %s, %s, %s, %s, %s,
 %d, %d, %d, %d, %d, FROM_UNIXTIME(%d), %s, %s
 142                                     )",
 143                                             $this->creator_id,
 144                                             $this->name,
 145                                             $this->slug,
 146                                             $this->description,
 147                                             $this->news,
 148                                             $this->status,
 149                                             $this->is_invitation_only,
 150                                             $this->enable_wire,
 151                                             $this->enable_forum,
 152                                             $this->enable_photos,
 153                                             $this->photos_admin_only,
 154                                             $this->date_created,
 155                                             $this->avatar_thumb,
 156                                             $this->avatar_full
 157                             );
 158                     }
 159
 160                     $result = $wpdb->query($sql);
 161
 162                     if ( $wpdb->insert_id )
 163                             $this->id = $wpdb->insert_id;
 164
 165                     return $result;
 166             }
 167
 168             function make_private() {
 169
 170             }
 171
 172             function make_public() {
 173
 174             }
 175
 176             function get_user_dataset() {
 177                     global $wpdb, $bp;
 178
 179                     return $wpdb->get_results( $wpdb->prepare( "SELECT
 user_id, is_admin, inviter_id, user_title FROM " .
 $bp['groups']['table_name_members'] . " WHERE group_id = %d AND
 is_confirmed = 1 ORDER BY rand()", $this->id ) );
 180             }
 181
 182             function get_administrators() {
 183                     for ( $i = 0; $i < count($this->user_dataset);
 $i++ ) {
 184                             if ( $this->user_dataset[$i]->is_admin ) {
 185                                     $admins[] = new BP_Groups_Member(
 $this->user_dataset[$i]->user_id, $this->id );
 186                             }
 187                     }
 188
 189                     return $admins;
 190             }
 191
 192             function get_random_members() {
 193                     $total_randoms = ( $this->total_member_count > 5 )
 ? 5 : $this->total_member_count;
 194
 195                     for ( $i = 0; $i < $total_randoms; $i++ ) {
 196                             $users[] = new BP_Groups_Member(
 $this->user_dataset[$i]->user_id, $this->id );
 197                     }
 198                     return $users;
 199             }
 200
 201             function get_latest_wire_posts() {
 202                     global $wpdb, $bp;
 203
 204
 205             }
 206
 207             function get_random_photos() {
 208                     global $wpdb, $bp;
 209
 210
 211             }
 212
 213             /* Static Functions */
 214
 215             function group_exists( $slug ) {
 216                     global $wpdb, $bp;
 217                     return $wpdb->get_var( $wpdb->prepare( "SELECT id
 FROM " . $bp['groups']['table_name'] . " WHERE slug = %s", $slug ) );
 218             }
 219
 220             function get_id_from_slug( $slug ) {
 221                     return BP_Groups_Group::group_exists( $slug );
 222             }
 223
 224             function get_invites( $group_id ) {
 225                     global $wpdb, $bp;
 226                     return $wpdb->get_col( $wpdb->prepare( "SELECT
 user_id FROM " . $bp['groups']['table_name_members'] . " WHERE group_id =
 %d and is_confirmed = 0", $group_id ) );
 227             }
 228
 229             function search_user_groups( $filter, $limit = null, $page
 = null ) {
 230                     global $wpdb, $bp;
 231
 232                     like_escape($filter);
 233
 234                     if ( $limit && $page )
 235                             $pag_sql = $wpdb->prepare( " LIMIT %d,
 %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 236
 237                     // Get all the user ids for the current user's
 friends.
 238                     $gids = BP_Groups_Member::get_group_ids( $user_id
 );
 239                     $gids = implode( ',', $gids['ids'] );
 240
 241                     $sql = $wpdb->prepare( "SELECT id FROM " .
 $bp['groups']['table_name'] . " WHERE id IN ($gids) AND name LIKE
 '$filter%%' OR description LIKE '$filter%%'$pag_sql" );
 242                     $count_sql = $wpdb->prepare( "SELECT count(id)
 FROM " . $bp['groups']['table_name'] . " WHERE id IN ($gids) AND name LIKE
 '$filter%%' OR description LIKE '$filter%%'" );
 243
 244                     $group_ids = $wpdb->get_col($sql);
 245                     $total_groups = $wpdb->get_var($count_sql);
 246
 247                     for ( $i = 0; $i < count($group_ids); $i++ ) {
 248                             $groups[] = new BP_Groups_Group(
 (int)$group_ids[$i] );
 249                     }
 250
 251                     return array( 'groups' => $groups, 'count' =>
 $total_groups );
 252             }
 253
 254             function search_groups( $filter, $limit = null, $page =
 null ) {
 255                     global $wpdb, $bp;
 256
 257                     like_escape($filter);
 258
 259                     if ( $limit && $page )
 260                             $pag_sql = $wpdb->prepare( " LIMIT %d,
 %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 261
 262                     $sql = $wpdb->prepare( "SELECT id FROM " .
 $bp['groups']['table_name'] . " WHERE name LIKE '$filter%%' OR description
 LIKE '$filter%%'$pag_sql" );
 263                     $count_sql = $wpdb->prepare( "SELECT count(id)
 FROM " . $bp['groups']['table_name'] . " WHERE name LIKE '$filter%%' OR
 description LIKE '$filter%%'" );
 264
 265                     $group_ids = $wpdb->get_col($sql);
 266                     $total_groups = $wpdb->get_var($count_sql);
 267
 268                     for ( $i = 0; $i < count($group_ids); $i++ ) {
 269                             $groups[] = new BP_Groups_Group(
 (int)$group_ids[$i] );
 270                     }
 271
 272                     return array( 'groups' => $groups, 'count' =>
 $total_groups );
 273             }
 274
 275             function check_slug( $slug ) {
 276                     global $wpdb, $bp;
 277
 278                     return $wpdb->get_var( $wpdb->prepare( "SELECT
 slug FROM " . $bp['groups']['table_name'] . " WHERE slug = %s", $slug ) );
 279             }
 280
 281             function get_slug( $group_id ) {
 282                     global $wpdb, $bp;
 283
 284                     return $wpdb->get_var( $wpdb->prepare( "SELECT
 slug FROM " . $bp['groups']['table_name'] . " WHERE id = %d", $group_id )
 );
 285             }
 286
 287             function has_members( $group_id ) {
 288                     global $wpdb, $bp;
 289
 290                     $members = $wpdb->get_var( $wpdb->prepare( "SELECT
 count(id) FROM " . $bp['groups']['table_name_members'] . " WHERE group_id
 = %d", $group_id ) );
 291
 292                     if ( $members < 1 )
 293                             return false;
 294
 295                     return true;
 296             }
 297
 298             function delete( $group_id ) {
 299                     global $wpdb, $bp;
 300
 301                     if ( $wpdb->query( $wpdb->prepare( "DELETE FROM "
 . $bp['groups']['table_name'] . " WHERE id = %d", $group_id ) ) )
 302                             return false;
 303
 304                     return true;
 305             }
 306
 307     }
 308
 309     Class BP_Groups_Member {
 310             var $id;
 311             var $group_id;
 312             var $user_id;
 313             var $inviter_id;
 314             var $is_admin;
 315             var $user_title;
 316             var $date_modified;
 317             var $is_confirmed;
 318
 319             var $user;
 320
 321             function bp_groups_member( $user_id = null, $group_id =
 null, $populate = true ) {
 322                     if ( $user_id && $group_id ) {
 323                             $this->user_id = $user_id;
 324                             $this->group_id = $group_id;
 325
 326                             if ( $populate )
 327                                     $this->populate();
 328                     }
 329             }
 330
 331             function populate() {
 332                     global $wpdb, $bp;
 333
 334                     $sql = $wpdb->prepare( "SELECT * FROM " .
 $bp['groups']['table_name_members'] . " WHERE user_id = %d AND group_id =
 %d", $this->user_id, $this->group_id );
 335                     $member = $wpdb->get_row($sql);
 336
 337                     if ( $member ) {
 338                             $this->id = $member->id;
 339                             $this->inviter_id = $member->inviter_id;
 340                             $this->is_admin = $member->is_admin;
 341                             $this->user_title = $member->user_title;
 342                             $this->date_modified =
 $member->date_modified;
 343                             $this->is_confirmed =
 $member->is_confirmed;
 344
 345                             $this->user = new BP_Core_User(
 $this->user_id );
 346                     }
 347             }
 348
 349             function save() {
 350                     global $wpdb, $bp;
 351
 352                     if ( $this->id ) {
 353                             $sql = $wpdb->prepare( "UPDATE " .
 $bp['groups']['table_name_members'] . " SET inviter_id = %d, is_admin =
 %d, user_title = %s, date_modified = FROM_UNIXTIME(%d), is_confirmed = %d
 WHERE id = %d", $this->inviter_id, $this->is_admin, $this->user_title,
 $this->date_modified, $this->is_confirmed, $this->id );
 354
 355                     } else {
 356                             $sql = $wpdb->prepare( "INSERT INTO " .
 $bp['groups']['table_name_members'] . " ( user_id, group_id, inviter_id,
 is_admin, user_title, date_modified, is_confirmed ) VALUES ( %d, %d, %d,
 %d, %s, FROM_UNIXTIME(%d), %d )", $this->user_id, $this->group_id,
 $this->inviter_id, $this->is_admin, $this->user_title,
 $this->date_modified, $this->is_confirmed );
 357                     }
 358
 359                     if ( !$result = $wpdb->query($sql) )
 360                             return false;
 361
 362                     return true;
 363             }
 364
 365             function promote() {
 366
 367             }
 368
 369             function demote() {
 370
 371             }
 372
 373             function accept_invite() {
 374                     $this->is_confirmed = 1;
 375                     $this->date_modified = time();
 376             }
 377
 378             /* Static Functions */
 379
 380             function get_group_ids( $user_id, $page = false, $limit =
 false ) {
 381                     global $wpdb, $bp;
 382
 383                     if ( !$user_id )
 384                             $user_id = $bp['current_userid'];
 385
 386                     if ( $limit && $page )
 387                             $pag_sql = $wpdb->prepare( " LIMIT %d,
 %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
 388
 389                     $group_ids = $wpdb->get_col( $wpdb->prepare(
 "SELECT DISTINCT group_id FROM " . $bp['groups']['table_name_members'] . "
 WHERE user_id = %d AND is_confirmed = 1$pag_sql", $user_id ) );
 390                     $group_count = $wpdb->get_var( $wpdb->prepare(
 "SELECT DISTINCT count(group_id) FROM " .
 $bp['groups']['table_name_members'] . " WHERE user_id = %d AND
 is_confirmed = 1", $user_id ) );
 391
 392
 393                     return array( 'ids' => $group_ids, 'count' =>
 $group_count );
 394
 395             }
 396
 397             function get_invites( $user_id ) {
 398                     global $wpdb, $bp;
 399
 400                     $group_ids = $wpdb->get_col( $wpdb->prepare(
 "SELECT group_id FROM " . $bp['groups']['table_name_members'] . " WHERE
 user_id = %d and is_confirmed = 0", $user_id ) );
 401
 402                     for ( $i = 0; $i < count($group_ids); $i++ ) {
 403                             $groups[] = new
 BP_Groups_Group($group_ids[$i]);
 404                     }
 405
 406                     return $groups;
 407             }
 408
 409             function delete( $user_id, $group_id ) {
 410                     global $wpdb, $bp;
 411
 412                     $delete_result = $wpdb->query( $wpdb->prepare(
 "DELETE FROM " . $bp['groups']['table_name_members'] . " WHERE user_id =
 %d AND group_id = %d", $user_id, $group_id ) );
 413
 414                     // Check to see if there are any members left for
 the group, if not, delete it.
 415                     if ( !BP_Groups_Group::has_members( $group_id ) )
 {
 416                             BP_Groups_Group::delete( $group_id );
 417                     }
 418
 419                     return $delete_result;
 420             }
 421
 422             function check_is_admin( $user_id, $group_id ) {
 423                     global $wpdb, $bp;
 424
 425                     return $wpdb->query( $wpdb->prepare( "SELECT id
 FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND
 group_id = %d AND is_admin = 1", $user_id, $group_id ) );
 426             }
 427
 428             function check_is_member( $user_id, $group_id ) {
 429                     global $wpdb, $bp;
 430
 431                     return $wpdb->query( $wpdb->prepare( "SELECT id
 FROM " . $bp['groups']['table_name_members'] . " WHERE user_id = %d AND
 group_id = %d", $user_id, $group_id ) );
 432             }
 433     }
 434
 435     ?>
 }}}

-- 
Ticket URL: <https://buddypress.trac.wordpress.org/ticket/330#comment:3>
BuddyPress Trac <http://buddypress.org/>
BuddyPress Trac


More information about the buddypress-trac mailing list