Skip to:
Content

BuddyPress.org

Changeset 5708


Ignore:
Timestamp:
02/11/2012 04:18:44 AM (12 years ago)
Author:
johnjamesjacoby
Message:

PHP5'ize bp-core-classes.php - Set methods as public, private, static, and kill off PHP4 constructors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/bp-core-classes.php

    r5683 r5708  
    109109    var $total_groups;
    110110
    111     /**
    112      * PHP4 constructor.
    113      *
    114      * @see BP_Core_User::__construct()
    115      */
    116     function bp_core_user( $user_id, $populate_extras = false ) {
    117         $this->__construct( $user_id, $populate_extras );
    118     }
     111    /** Public Method*s *******************************************************/
    119112
    120113    /**
     
    124117     * @param boolean $populate_extras Whether to fetch extra information such as group/friendship counts or not.
    125118     */
    126     function __construct( $user_id, $populate_extras = false ) {
    127         if ( $user_id ) {
     119    public function __construct( $user_id, $populate_extras = false ) {
     120        if ( !empty( $user_id ) ) {
    128121            $this->id = $user_id;
    129122            $this->populate();
    130123
    131             if ( $populate_extras )
     124            if ( !empty( $populate_extras ) ) {
    132125                $this->populate_extras();
    133         }
    134     }
     126            }
     127        }
     128    }
     129
     130    /** Private Methods *******************************************************/
    135131
    136132    /**
     
    144140     * @uses bp_profile_last_updated_date() Returns the last updated date for a user.
    145141     */
    146     function populate() {
     142    private function populate() {
    147143
    148144        if ( bp_is_active( 'xprofile' ) )
     
    177173     * Populates extra fields such as group and friendship counts.
    178174     */
    179     function populate_extras() {
     175    private function populate_extras() {
    180176
    181177        if ( bp_is_active( 'friends' ) ) {
     
    189185    }
    190186
    191     function get_profile_data() {
     187    private function get_profile_data() {
    192188        return BP_XProfile_ProfileData::get_all_for_user( $this->id );
    193189    }
    194190
    195     /** Static Functions ******************************************************/
    196 
    197     function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
     191    /** Static Methods ********************************************************/
     192
     193    public static function get_users( $type, $limit = 0, $page = 1, $user_id = 0, $include = false, $search_terms = false, $populate_extras = true, $exclude = false, $meta_key = false, $meta_value = false ) {
    198194        global $wpdb, $bp;
    199195
     
    222218        }
    223219
    224         $sql['from'] = "FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON um.user_id = u.ID";
     220        $sql['from'] = "FROM {$wpdb->users} u LEFT JOIN {$wpdb->usermeta} um ON um.user_id = u.ID";
    225221
    226222        // We search against xprofile fields, so we must join the table
     
    260256        }
    261257
    262         if ( $include ) {
     258        if ( !empty( $include ) ) {
    263259            if ( is_array( $include ) ) {
    264260                $uids = $wpdb->escape( implode( ',', (array)$include ) );
     
    270266                $sql['where_users'] = "AND u.ID IN ({$uids})";
    271267            }
    272         } elseif ( $user_id && bp_is_active( 'friends' ) ) {
     268        } elseif ( !empty( $user_id ) && bp_is_active( 'friends' ) ) {
    273269            $friend_ids = friends_get_friend_user_ids( $user_id );
    274270            $friend_ids = $wpdb->escape( implode( ',', (array)$friend_ids ) );
     
    283279        }
    284280
    285         if ( $search_terms && bp_is_active( 'xprofile' ) ) {
     281        if ( !empty( $search_terms ) && bp_is_active( 'xprofile' ) ) {
    286282            $search_terms             = like_escape( $wpdb->escape( $search_terms ) );
    287283            $sql['where_searchterms'] = "AND spd.value LIKE '%%$search_terms%%'";
    288284        }
    289285
    290         if ( $meta_key ) {
     286        if ( !empty( $meta_key ) ) {
    291287            $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key );
    292288
     
    315311        }
    316312
    317         if ( $limit && $page ) {
     313        if ( !empty( $limit ) && !empty( $page ) ) {
    318314            $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    319315        }
     
    382378     * @static
    383379     */
    384     function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {
     380    public static function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {
    385381        global $bp, $wpdb;
    386382
     
    444440     * @static
    445441     */
    446     function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
     442    public static function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
    447443        global $wpdb;
    448444
     
    489485     * @static
    490486     */
    491     function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
     487    public static function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
    492488        global $bp, $wpdb;
    493489
     
    532528     * @static
    533529     */
    534     function get_user_extras( &$paged_users, &$user_ids, $type = false ) {
     530    public static function get_user_extras( &$paged_users, &$user_ids, $type = false ) {
    535531        global $bp, $wpdb;
    536532
     
    612608     * @static
    613609     */
    614     function get_core_userdata( $user_id ) {
     610    public static function get_core_userdata( $user_id ) {
    615611        global $wpdb;
    616612
     
    688684    var $is_new;
    689685
    690 
    691     /**
    692      * PHP4 constructor
     686    /** Public Methods ********************************************************/
     687
     688    /**
     689     * Constructor
    693690     *
    694691     * @param integer $id
    695692     */
    696     function bp_core_notification( $id = 0 ) {
    697         $this->__construct($id);
    698     }
    699 
    700     /**
    701      * Constructor
    702      *
    703      * @param integer $id
    704      */
    705     function __construct( $id = 0 ) {
    706         if ( $id ) {
     693    public function __construct( $id = 0 ) {
     694        if ( !empty( $id ) ) {
    707695            $this->id = $id;
    708696            $this->populate();
     
    711699
    712700    /**
    713      * Fetches the notification data from the database.
     701     * Update or insert notification details into the database.
    714702     *
    715703     * @global object $bp Global BuddyPress settings object
    716704     * @global wpdb $wpdb WordPress database object
    717      */
    718     function populate() {
     705     * @return bool Success or failure
     706     */
     707    public function save() {
     708        global $bp, $wpdb;
     709
     710        // Update
     711        if ( !empty( $this->id ) ) {
     712            $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
     713
     714        // Save
     715        } else {
     716            $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
     717        }
     718
     719        if ( !$result = $wpdb->query( $sql ) )
     720            return false;
     721
     722        $this->id = $wpdb->insert_id;
     723
     724        return true;
     725    }
     726
     727    /** Private Methods *******************************************************/
     728
     729    /**
     730     * Fetches the notification data from the database.
     731     *
     732     * @global object $bp Global BuddyPress settings object
     733     * @global wpdb $wpdb WordPress database object
     734     */
     735    private function populate() {
    719736        global $bp, $wpdb;
    720737
     
    730747    }
    731748
    732     /**
    733      * Update or insert notification details into the database.
    734      *
    735      * @global object $bp Global BuddyPress settings object
    736      * @global wpdb $wpdb WordPress database object
    737      * @return bool Success or failure
    738      */
    739     function save() {
    740         global $bp, $wpdb;
    741 
    742         // Update
    743         if ( $this->id )
    744             $sql = $wpdb->prepare( "UPDATE {$bp->core->table_name_notifications} SET item_id = %d, secondary_item_id = %d, user_id = %d, component_name = %s, component_action = %d, date_notified = %s, is_new = %d ) WHERE id = %d", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new, $this->id );
    745 
    746         // Save
    747         else
    748             $sql = $wpdb->prepare( "INSERT INTO {$bp->core->table_name_notifications} ( item_id, secondary_item_id, user_id, component_name, component_action, date_notified, is_new ) VALUES ( %d, %d, %d, %s, %s, %s, %d )", $this->item_id, $this->secondary_item_id, $this->user_id, $this->component_name, $this->component_action, $this->date_notified, $this->is_new );
    749 
    750         if ( !$result = $wpdb->query( $sql ) )
    751             return false;
    752 
    753         $this->id = $wpdb->insert_id;
    754         return true;
    755     }
    756 
    757     /** Static functions ******************************************************/
    758 
    759     function check_access( $user_id, $notification_id ) {
     749    /** Static Methods ********************************************************/
     750
     751    public static function check_access( $user_id, $notification_id ) {
    760752        global $wpdb, $bp;
    761753
     
    773765     * @static
    774766     */
    775     function get_all_for_user( $user_id, $status = 'is_new' ) {
     767    public static function get_all_for_user( $user_id, $status = 'is_new' ) {
    776768        global $bp, $wpdb;
    777769
     
    791783     * @static
    792784     */
    793     function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
     785    public static function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
    794786        global $bp, $wpdb;
    795787
     
    809801     * @static
    810802     */
    811     function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
     803    public static function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id = false ) {
    812804        global $bp, $wpdb;
    813805
     
    827819     * @static
    828820     */
    829     function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
     821    public static function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
    830822        global $bp, $wpdb;
    831823
     
    844836     * @static
    845837     */
    846     function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
     838    public static function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
    847839        global $bp, $wpdb;
    848840
     
    996988     * @return bool False if not allowed
    997989     */
    998     function bp_button( $args = '' ) {
    999         $this->__construct($args);
    1000     }
    1001 
    1002     function __construct( $args = '' ) {
     990    public function __construct( $args = '' ) {
    1003991
    1004992        // Default arguments
     
    11041092     * @return string
    11051093     */
    1106     function contents() {
     1094    public function contents() {
    11071095        return $this->contents;
    11081096    }
     
    11131101     * Output contents of button
    11141102     */
    1115     function display() {
     1103    public function display() {
    11161104        if ( !empty( $this->contents ) )
    11171105            echo $this->contents;
     
    11291117 */
    11301118class BP_Embed extends WP_Embed {
     1119
    11311120    /**
    11321121     * Constructor
     
    11341123     * @global unknown $wp_embed
    11351124     */
    1136     function __construct() {
     1125    public function __construct() {
    11371126        global $wp_embed;
    11381127
     
    11831172     * @return string The embed HTML on success, otherwise the original URL.
    11841173     */
    1185     function shortcode( $attr, $url = '' ) {
     1174    public function shortcode( $attr, $url = '' ) {
    11861175        if ( empty( $url ) )
    11871176            return '';
     
    12481237     * @return string The embed HTML on success, otherwise the original URL.
    12491238     */
    1250     function parse_oembed( $id, $url, $attr, $rawattr ) {
     1239    public function parse_oembed( $id, $url, $attr, $rawattr ) {
    12511240        $id = intval( $id );
    12521241
     
    12811270    }
    12821271}
     1272
    12831273?>
Note: See TracChangeset for help on using the changeset viewer.