Skip to:
Content

BuddyPress.org

Changeset 4462


Ignore:
Timestamp:
06/05/2011 08:26:32 PM (15 years ago)
Author:
djpaul
Message:

Add some tasty phpdoc. Props Backie, see #2345

Location:
trunk/bp-core
Files:
2 edited

Legend:

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

    r4400 r4462  
    279279}
    280280
     281/**
     282 * Delete an existing avatar
     283 *
     284 * Accepted values for $args are:
     285 *  item_id - item id which relates to the object type.
     286 *  object - the objetc type user, group, blog, etc.
     287 *  avatar_dir - The directory where the avatars to be uploaded.
     288 *
     289 * @global object $bp BuddyPress global settings
     290 * @param mixed $args
     291 * @return bool Success/failure
     292 */
    281293function bp_core_delete_existing_avatar( $args = '' ) {
    282294        global $bp;
     
    337349}
    338350
     351/**
     352 * Handles avatar uploading.
     353 *
     354 * The functions starts off by checking that the file has been uploaded properly using bp_core_check_avatar_upload().
     355 * It then checks that the file size is within limits, and that it has an accepted file extension (jpg, gif, png).
     356 * If everything checks out, crop the image and move it to its real location.
     357 *
     358 * @global object $bp BuddyPress global settings
     359 * @param array $file The appropriate entry the from $_FILES superglobal.
     360 * @param string $upload_dir_filter A filter to be applied to upload_dir
     361 * @return bool Success/failure
     362 * @see bp_core_check_avatar_upload()
     363 * @see bp_core_check_avatar_type()
     364 */
    339365function bp_core_avatar_handle_upload( $file, $upload_dir_filter ) {
    340366        global $bp;
     
    422448}
    423449
     450/**
     451 * Crop an uploaded avatar
     452 *
     453 * $args has the following parameters:
     454 *  object - What component the avatar is for, e.g. "user"
     455 *  avatar_dir  The absolute path to the avatar
     456 *  item_id - Item ID
     457 *  original_file - The absolute path to the original avatar file
     458 *  crop_w - Crop width
     459 *  crop_h - Crop height
     460 *  crop_x - The horizontal starting point of the crop
     461 *  crop_y - The vertical starting point of the crop
     462 *
     463 * @global object $bp BuddyPress global settings
     464 * @param mixed $args
     465 * @return bool Success/failure
     466 */
    424467function bp_core_avatar_handle_crop( $args = '' ) {
    425468        global $bp;
     
    538581add_filter( 'get_avatar', 'bp_core_fetch_avatar_filter', 10, 5 );
    539582
    540 function bp_core_check_avatar_upload($file) {
     583/**
     584 * Has the current avatar upload generated an error?
     585 *
     586 * @param array $file
     587 * @return bool
     588 */
     589function bp_core_check_avatar_upload( $file ) {
    541590        if ( isset( $file['error'] ) && $file['error'] )
    542591                return false;
     
    545594}
    546595
    547 function bp_core_check_avatar_size($file) {
     596/**
     597 * Is the file size of the current avatar upload permitted?
     598 *
     599 * @param array $file
     600 * @return bool
     601 */
     602function bp_core_check_avatar_size( $file ) {
    548603        if ( $file['file']['size'] > BP_AVATAR_ORIGINAL_MAX_FILESIZE )
    549604                return false;
     
    552607}
    553608
     609/**
     610 * Does the current avatar upload have an allowed file type?
     611 *
     612 * Permitted file types are JPG, GIF and PNG.
     613 *
     614 * @param string $file
     615 * @return bool
     616 */
    554617function bp_core_check_avatar_type($file) {
    555618        if ( ( !empty( $file['file']['type'] ) && !preg_match('/(jpe?g|gif|png)$/i', $file['file']['type'] ) ) || !preg_match( '/(jpe?g|gif|png)$/i', $file['file']['name'] ) )
  • trunk/bp-core/bp-core-classes.php

    r4444 r4462  
    1414 */
    1515class BP_Core_User {
     16
     17        /**
     18         * ID of the user which the object relates to.
     19         *
     20         * @var integer
     21         */
    1622        var $id;
     23
     24        /**
     25         * The URL to the full size of the avatar for the user.
     26         *
     27         * @var string
     28         */
    1729        var $avatar;
     30
     31        /**
     32         * The URL to the thumb size of the avatar for the user.
     33         *
     34         * @var string
     35         */
    1836        var $avatar_thumb;
     37
     38        /**
     39         * The URL to the mini size of the avatar for the user.
     40         *
     41         * @var string
     42         */
    1943        var $avatar_mini;
     44
     45        /**
     46         * The full name of the user
     47         *
     48         * @var string
     49         */
    2050        var $fullname;
     51
     52        /**
     53         * The email for the user.
     54         *
     55         * @var string
     56         */
    2157        var $email;
    2258
     59        /**
     60         * The absolute url for the user's profile.
     61         *
     62         * @var string
     63         */
    2364        var $user_url;
     65
     66        /**
     67         * The HTML for the user link, with the link text being the user's full name.
     68         *
     69         * @var string
     70         */
    2471        var $user_link;
    2572
     73        /**
     74         * Contains a formatted string when the last time the user was active.
     75         *
     76         * Example: "active 2 hours and 50 minutes ago"
     77         *
     78         * @var string
     79         */
    2680        var $last_active;
    2781
    2882        /* Extras */
     83
     84        /**
     85         * The total number of "Friends" the user has on site.
     86         *
     87         * @var integer
     88         */
    2989        var $total_friends;
     90
     91        /**
     92         * The total number of blog posts posted by the user
     93         *
     94         * @var integer
     95         */
    3096        var $total_blogs;
     97
     98        /**
     99         * The total number of groups the user is a part of.
     100         *
     101         * Example: "1 group", "2 groups"
     102         *
     103         * @var string
     104         */
    31105        var $total_groups;
    32106
     107        /**
     108         * PHP4 constructor.
     109         *
     110         * @see BP_Core_User::__construct()
     111         */
    33112        function bp_core_user( $user_id, $populate_extras = false ) {
    34113                $this->__construct( $user_id, $populate_extras );
    35114        }
    36115
    37                 function __construct( $user_id, $populate_extras = false ) {
     116        /**
     117         * Class constructor.
     118         *
     119         * @param integer $user_id The ID for the user
     120         * @param boolean $populate_extras Whether to fetch extra information such as group/friendship counts or not.
     121         */
     122        function __construct( $user_id, $populate_extras = false ) {
    38123                if ( $user_id ) {
    39124                        $this->id = $user_id;
     
    46131
    47132        /**
    48          * populate()
    49          *
    50133         * Populate the instantiated class with data based on the User ID provided.
    51134         *
    52          * @package BuddyPress Core
    53          * @global $userdata WordPress user data for the current logged in user.
     135         * @global object $bp Global BuddyPress settings object
    54136         * @uses bp_core_get_userurl() Returns the URL with no HTML markup for a user based on their user id
    55137         * @uses bp_core_get_userlink() Returns a HTML formatted link for a user with the user's full name as the link text
     
    61143        function populate() {
    62144                global $bp;
    63                
     145
    64146                if ( bp_is_active( 'xprofile' ) )
    65147                        $this->profile_data = $this->get_profile_data();
     
    88170        }
    89171
     172        /**
     173         * Populates extra fields such as group and friendship counts.
     174         *
     175         * @global object $bp Global BuddyPress settings object
     176         */
    90177        function populate_extras() {
    91178                global $bp;
     
    96183                if ( bp_is_active( 'groups' ) ) {
    97184                        $this->total_groups = BP_Groups_Member::total_group_count( $this->id );
    98 
    99                         if ( $this->total_groups ) {
    100                                 if ( 1 == $this->total_groups )
    101                                         $this->total_groups .= ' ' . __( 'group', 'buddypress' );
    102                                 else
    103                                         $this->total_groups .= ' ' . __( 'groups', 'buddypress' );
    104                         }
     185                        $this->total_groups = sprintf( _n( '%d group', '%d groups', $this->total_groups ), $this->total_groups );
    105186                }
    106187        }
     
    127208                if ( 'alphabetical' == $type )
    128209                        $sql['select_alpha'] = ", pd.value as fullname";
    129                
     210
    130211                if ( $meta_key ) {
    131212                        $sql['select_meta'] = ", umm.meta_key";
    132                        
     213
    133214                        if ( $meta_value )
    134215                                $sql['select_meta'] .= ", umm.meta_value";
     
    139220                if ( $search_terms && bp_is_active( 'xprofile' ) || 'alphabetical' == $type )
    140221                        $sql['join_profiledata'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
    141                        
     222
    142223                if ( $meta_key )
    143224                        $sql['join_meta'] = "LEFT JOIN {$wpdb->usermeta} umm ON umm.user_id = u.ID";
     
    187268                        $sql['where_searchterms'] = "AND pd.value LIKE '%%$search_terms%%'";
    188269                }
    189                
     270
    190271                if ( $meta_key ) {
    191272                        $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key );
    192                        
     273
    193274                        // If a meta value is provided, match it
    194275                        if ( $meta_value ) {
     
    262343        }
    263344
    264         function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = false ) {
    265                 global $wpdb, $bp;
     345
     346        /**
     347         * Fetches the user details for all the users who username starts with the letter given.
     348         *
     349         * @global object $bp Global BuddyPress settings object
     350         * @global wpdb $wpdb WordPress database object
     351         * @param string $letter The letter the users names are to start with.
     352         * @param integer $limit The number of users we wish to retrive.
     353         * @param integer $page The page number we are currently on, used in conjunction with $limit to get the start position for the limit.
     354         * @param boolean $populate_extras Populate extra user fields?
     355         * @param string $exclude Comma-separated IDs of users whose results aren't to be fetched.
     356         * @return mixed False on error, otherwise associative array of results.
     357         * @static
     358         */
     359        function get_users_by_letter( $letter, $limit = null, $page = 1, $populate_extras = true, $exclude = '' ) {
     360                global $bp, $wpdb;
    266361
    267362                $pag_sql = '';
     
    308403        }
    309404
     405        /**
     406         * Get details of specific users from the database
     407         *
     408         * @global object $bp Global BuddyPress settings object
     409         * @global wpdb $wpdb WordPress database object
     410         * @param array $user_ids The user IDs of the users who we wish to fetch information on.
     411         * @param integer $limit The limit of results we want.
     412         * @param integer $page The page we are on for pagination.
     413         * @param boolean $populate_extras Populate extra user fields?
     414         * @return array Associative array
     415         * @static
     416         */
    310417        function get_specific_users( $user_ids, $limit = null, $page = 1, $populate_extras = true ) {
    311                 global $wpdb, $bp;
     418                global $bp, $wpdb;
    312419
    313420                $pag_sql = '';
     
    336443        }
    337444
     445        /**
     446         * Find users who match on the value of an xprofile data.
     447         *
     448         * @global object $bp Global BuddyPress settings object
     449         * @global wpdb $wpdb WordPress database object
     450         * @param string $search_terms The terms to search the profile table value column for.
     451         * @param integer $limit The limit of results we want.
     452         * @param integer $page The page we are on for pagination.
     453         * @param boolean $populate_extras Populate extra user fields?
     454         * @return array Associative array
     455         * @static
     456         */
    338457        function search_users( $search_terms, $limit = null, $page = 1, $populate_extras = true ) {
    339                 global $wpdb, $bp;
     458                global $bp, $wpdb;
    340459
    341460                if ( $limit && $page )
     
    367486        }
    368487
     488        /**
     489         * Fetch extra user information, such as friend count and last profile update message.
     490         *
     491         * Accepts multiple user IDs to fetch data for.
     492         *
     493         * @global object $bp Global BuddyPress settings object
     494         * @global wpdb $wpdb WordPress database object
     495         * @param array $paged_users an array of stdClass containing the users
     496         * @param string $user_ids the user ids to select information about
     497         * @param string $type the type of fields we wish to get
     498         * @return mixed False on error, otherwise associative array of results.
     499         * @static
     500         */
    369501        function get_user_extras( &$paged_users, &$user_ids, $type = false ) {
    370502                global $bp, $wpdb;
     
    439571        }
    440572
     573        /**
     574         * Get WordPress user details for a specified user.
     575         *
     576         * @global wpdb $wpdb WordPress database object
     577         * @param integer $user_id User ID
     578         * @return array Associative array
     579         * @static
     580         */
    441581        function get_core_userdata( $user_id ) {
    442582                global $wpdb;
     
    458598
    459599class BP_Core_Notification {
     600
     601        /**
     602         * The notification id
     603         *
     604         * @var integer
     605         */
    460606        var $id;
     607
     608        /**
     609         * The ID to which the notification relates to within the component.
     610         *
     611         * @var integer
     612         */
    461613        var $item_id;
     614
     615        /**
     616         * The secondary ID to which the notification relates to within the component.
     617         *
     618         * @var integer
     619         */
    462620        var $secondary_item_id = null;
     621
     622        /**
     623         * The user ID for who the notification is for.
     624         *
     625         * @var integer
     626         */
    463627        var $user_id;
     628
     629        /**
     630         * The name of the component that the notification is for.
     631         *
     632         * @var string
     633         */
    464634        var $component_name;
     635
     636        /**
     637         * The action within the component which the notification is related to.
     638         *
     639         * @var string
     640         */
    465641        var $component_action;
     642
     643        /**
     644         * The date the notification was created.
     645         *
     646         * @var string
     647         */
    466648        var $date_notified;
     649
     650        /**
     651         * Is the notification new or has it already been read.
     652         *
     653         * @var boolean
     654         */
    467655        var $is_new;
    468656
    469         function bp_core_notification( $id = false ) {
     657
     658        /**
     659         * PHP4 constructor
     660         *
     661         * @param integer $id
     662         */
     663        function bp_core_notification( $id = 0 ) {
    470664                $this->__construct($id);
    471665        }
    472                
    473         function __construct( $id = false ) {
     666
     667        /**
     668         * Constructor
     669         *
     670         * @param integer $id
     671         */
     672        function __construct( $id = 0 ) {
    474673                if ( $id ) {
    475674                        $this->id = $id;
     
    478677        }
    479678
     679        /**
     680         * Fetches the notification data from the database.
     681         *
     682         * @global object $bp Global BuddyPress settings object
     683         * @global wpdb $wpdb WordPress database object
     684         */
    480685        function populate() {
    481                 global $wpdb, $bp;
     686                global $bp, $wpdb;
    482687
    483688                if ( $notification = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE id = %d", $this->id ) ) ) {
     
    492697        }
    493698
     699        /**
     700         * Update or insert notification details into the database.
     701         *
     702         * @global object $bp Global BuddyPress settings object
     703         * @global wpdb $wpdb WordPress database object
     704         * @return bool Success or failure
     705         */
    494706        function save() {
    495                 global $wpdb, $bp;
     707                global $bp, $wpdb;
    496708
    497709                // Update
     
    518730        }
    519731
     732        /**
     733         * Fetches all the notifications in the database for a specific user.
     734         *
     735         * @global object $bp Global BuddyPress settings object
     736         * @global wpdb $wpdb WordPress database object
     737         * @param integer $user_id User ID
     738         * @return array Associative array
     739         * @static
     740         */
    520741        function get_all_for_user( $user_id ) {
    521                 global $wpdb, $bp;
     742                global $bp, $wpdb;
    522743
    523744                return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND is_new = 1", $user_id ) );
    524745        }
    525746
     747        /**
     748         * Delete all the notifications for a user based on the component name and action.
     749         *
     750         * @global object $bp Global BuddyPress settings object
     751         * @global wpdb $wpdb WordPress database object
     752         * @param integer $user_id
     753         * @param string $component_name
     754         * @param string $component_action
     755         * @static
     756         */
    526757        function delete_for_user_by_type( $user_id, $component_name, $component_action ) {
    527                 global $wpdb, $bp;
     758                global $bp, $wpdb;
    528759
    529760                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE user_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
    530761        }
    531762
     763        /**
     764         * Delete all the notifications that have a specific item id, component name and action.
     765         *
     766         * @global object $bp Global BuddyPress settings object
     767         * @global wpdb $wpdb WordPress database object
     768         * @param integer $user_id The ID of the user who the notifications are for.
     769         * @param integer $item_id The item ID of the notifications we wish to delete.
     770         * @param string $component_name The name of the component that the notifications we wish to delete.
     771         * @param string $component_action The action of the component that the notifications we wish to delete.
     772         * @param integer $secondary_item_id (optional) The secondary item id of the notifications that we wish to use to delete.
     773         * @static
     774         */
    532775        function delete_for_user_by_item_id( $user_id, $item_id, $component_name, $component_action, $secondary_item_id ) {
    533                 global $wpdb, $bp;
     776                global $bp, $wpdb;
    534777
    535778                $secondary_item_sql = !empty( $secondary_item_id ) ? $wpdb->prepare( " AND secondary_item_id = %d", $secondary_item_id ) : '';
     
    538781        }
    539782
     783        /**
     784         * Deletes all the notifications sent by a specific user, by component and action.
     785         *
     786         * @global object $bp Global BuddyPress settings object
     787         * @global wpdb $wpdb WordPress database object
     788         * @param integer $user_id The ID of the user whose sent notifications we wish to delete.
     789         * @param string $component_name The name of the component the notification was sent from.
     790         * @param string $component_action The action of the component the notification was sent from.
     791         * @static
     792         */
    540793        function delete_from_user_by_type( $user_id, $component_name, $component_action ) {
    541                 global $wpdb, $bp;
     794                global $bp, $wpdb;
    542795
    543796                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE item_id = %d AND component_name = %s AND component_action = %s", $user_id, $component_name, $component_action ) );
    544797        }
    545798
     799        /**
     800         * Deletes all the notifications for all users by item id, and optional secondary item id, and component name and action.
     801         *
     802         * @global object $bp Global BuddyPress settings object
     803         * @global wpdb $wpdb WordPress database object
     804         * @param string $item_id The item id that they notifications are to be for.
     805         * @param string $component_name The component that the notifications are to be from.
     806         * @param string $component_action The action that the notificationsa are to be from.
     807         * @param string $secondary_item_id Optional secondary item id that the notifications are to have.
     808         * @static
     809         */
    546810        function delete_all_by_type( $item_id, $component_name, $component_action, $secondary_item_id ) {
    547                 global $wpdb, $bp;
     811                global $bp, $wpdb;
    548812
    549813                if ( $component_action )
     
    570834 */
    571835class BP_Button {
    572 
    573836        // Button properties
     837
     838        /**
     839         * The button ID
     840         *
     841         * @var integer
     842         */
    574843        var $id;
     844
     845        /**
     846         * The component name that button belongs to.
     847         *
     848         * @var string
     849         */
    575850        var $component;
     851
     852        /**
     853         * Does the user need to be logged in to see this button?
     854         *
     855         * @var boolean
     856         */
    576857        var $must_be_logged_in;
     858
     859        /**
     860         * True or false if the button should not be displayed while viewing your own profile.
     861         *
     862         * @var boolean
     863         */
    577864        var $block_self;
    578865
     866
    579867        // Wrapper
     868
     869        /**
     870         * What type of DOM element to use for a wrapper.
     871         *
     872         *
     873         * @var mixed div|span|p|li, or false for no wrapper
     874         */
    580875        var $wrapper;
     876
     877        /**
     878         * The DOM class of the button wrapper
     879         *
     880         * @var string
     881         */
    581882        var $wrapper_class;
     883
     884        /**
     885         * The DOM ID of the button wrapper
     886         *
     887         * @var string
     888         */
    582889        var $wrapper_id;
    583890
     891
    584892        // Button
     893
     894        /**
     895         * The destination link of the button
     896         *
     897         * @var string
     898         */
    585899        var $link_href;
     900
     901        /**
     902         * The DOM class of the button link
     903         *
     904         * @var string
     905         */
    586906        var $link_class;
     907
     908        /**
     909         * The DOM ID of the button link
     910         *
     911         * @var string
     912         */
    587913        var $link_id;
     914
     915        /**
     916         * The DOM rel value of the button link
     917         *
     918         * @var string
     919         */
    588920        var $link_rel;
     921
     922        /**
     923         * Title of the button link
     924         *
     925         * @var string
     926         */
    589927        var $link_title;
     928
     929        /**
     930         * The contents of the button link
     931         *
     932         * @var string
     933         */
    590934        var $link_text;
    591935
     936
    592937        // HTML result
     938
    593939        var $contents;
    594940
     
    617963                $this->__construct($args);
    618964        }
    619        
     965
    620966        function __construct( $args = '' ) {
    621967
Note: See TracChangeset for help on using the changeset viewer.