Changeset 7393
- Timestamp:
- 10/07/2013 09:57:01 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-classes.php
r7338 r7393 10 10 if ( !defined( 'ABSPATH' ) ) exit; 11 11 12 /** 13 * Database interaction class for the BuddyPress activity component. 14 * 15 * Instance methods are available for creating/editing an activity, 16 * static methods for querying activities. 17 * 18 * @since BuddyPress (1.0) 19 */ 12 20 class BP_Activity_Activity { 21 22 /** Properties ************************************************************/ 23 24 /** 25 * ID of the activity item. 26 * 27 * @var int 28 */ 13 29 var $id; 30 31 /** 32 * ID of the associated item. 33 * 34 * @var int 35 */ 14 36 var $item_id; 37 38 /** 39 * ID of the associated secondary item. 40 * 41 * @var int 42 */ 15 43 var $secondary_item_id; 44 45 /** 46 * ID of user associated with the activity item. 47 * 48 * @var int 49 */ 16 50 var $user_id; 51 52 /** 53 * The primary URL for the activity in RSS feeds. 54 * 55 * @var string 56 */ 17 57 var $primary_link; 58 59 /** 60 * BuddyPress component the activity item relates to. 61 * 62 * @var string 63 */ 18 64 var $component; 65 66 /** 67 * Activity type, eg 'new_blog_post'. 68 * 69 * @var string 70 */ 19 71 var $type; 72 73 /** 74 * Description of the activity, eg 'Alex updated his profile.' 75 * 76 * @var string 77 */ 20 78 var $action; 79 80 /** 81 * The content of the activity item. 82 * 83 * @var string 84 */ 21 85 var $content; 86 87 /** 88 * The date the activity item was recorded, in 'Y-m-d h:i:s' format. 89 * 90 * @var string 91 */ 22 92 var $date_recorded; 93 94 /** 95 * Whether the item should be hidden in sitewide streams. 96 * 97 * @var int 98 */ 23 99 var $hide_sitewide = false; 100 101 /** 102 * Node boundary start for activity or activity comment. 103 * 104 * @var int 105 */ 24 106 var $mptt_left; 107 108 /** 109 * Node boundary end for activity or activity comment. 110 * 111 * @var int 112 */ 25 113 var $mptt_right; 114 115 /** 116 * Whether this item is marked as spam. 117 * 118 * @var int 119 */ 26 120 var $is_spam; 27 121 122 /** 123 * Constructor method. 124 * 125 * @param int $id Optional. The ID of a specific activity item. 126 */ 28 127 public function __construct( $id = false ) { 29 128 if ( !empty( $id ) ) { … … 33 132 } 34 133 134 /** 135 * Populate the object with data about the specific activity item. 136 */ 35 137 public function populate() { 36 138 global $wpdb, $bp; … … 56 158 } 57 159 160 /** 161 * Save the activity item to the database. 162 * 163 * @return bool True on success. 164 */ 58 165 public function save() { 59 166 global $wpdb, $bp; … … 105 212 } 106 213 107 / / Static Functions214 /** Static Methods ***************************************************/ 108 215 109 216 /** 110 217 * Get activity items, as specified by parameters 111 218 * 112 * @param array $args See $defaults for explanation of arguments 219 * @param array $args { 220 * An array of arguments. Optional. 221 * @int $page The current page number. Default: 1. 222 * @int $per_page The number of items to display per page. Default: 25. 223 * @int $max Maximum number of items to show. Default: false. 224 * @string $sort ASC or DESC. Default: 'DESC'. 225 * @array $exclude Array of activity IDs to exclude. Default: false. 226 * @array $in Array of ids to limit query by (IN). Default: false. 227 * @array $meta_query 228 * @array $filter 229 * @string $search_terms Limit results by a search term. Default: false. 230 * @bool $display_comments Whether to include activity comments. Default: false. 231 * @bool $show_hidden Whether to show items marked hide_sitewide. Default: false. 232 * @string $spam Spam status. Default: 'ham_only' 233 * } 113 234 * @return array 114 235 */ … … 296 417 297 418 /** 298 * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get() 419 * Get the SQL for the 'meta_query' param in BP_Activity_Activity::get(). 299 420 * 300 421 * We use WP_Meta_Query to do the heavy lifting of parsing the … … 308 429 * @param array $meta_query An array of meta_query filters. See the 309 430 * documentation for WP_Meta_Query for details. 310 * @return array $sql_array 'join' and 'where' clauses 431 * @return array $sql_array 'join' and 'where' clauses. 311 432 */ 312 433 public static function get_meta_query_sql( $meta_query = array() ) { … … 337 458 /** 338 459 * In BuddyPress 1.2.x, this was used to retrieve specific activity stream items (for example, on an activity's permalink page). 460 * 339 461 * As of 1.5.x, use BP_Activity_Activity::get() with an 'in' parameter instead. 462 * 463 * @since BuddyPress (1.2) 340 464 * 341 465 * @deprecated 1.5 342 466 * @deprecated Use BP_Activity_Activity::get() with an 'in' parameter instead. 467 * 343 468 * @param mixed $activity_ids Array or comma-separated string of activity IDs to retrieve 344 469 * @param int $max Maximum number of results to return. (Optional; default is no maximum) … … 348 473 * @param bool $display_comments Retrieve an activity item's associated comments or not. (Optional; default is false) 349 474 * @return array 350 * @since BuddyPress (1.2)351 475 */ 352 476 public static function get_specific( $activity_ids, $max = false, $page = 1, $per_page = 25, $sort = 'DESC', $display_comments = false ) { … … 355 479 } 356 480 481 /** 482 * Get the first activity ID that matches a set of criteria. 483 * 484 * @param int $user_id The user ID to filter by. 485 * @param string $component The component to filter by. 486 * @param string $type The activity type to filter by. 487 * @param int $item_id The associated item to filter by. 488 * @param int $secondary_item_id The secondary associated item to filter by. 489 * @param string $action The action to filter by. 490 * @param string $content The content to filter by. 491 * @param string $date_recorded The date to filter by. 492 * @return int|bool Activity ID on success, false if none is found. 493 */ 357 494 public static function get_id( $user_id, $component, $type, $item_id, $secondary_item_id, $action, $content, $date_recorded ) { 358 495 global $bp, $wpdb; … … 392 529 } 393 530 531 /** 532 * Delete activity items from the database. 533 * 534 * To delete a specific activity item, pass an 'id' parameter. 535 * Otherwise use the filters. 536 * 537 * @param array $args { 538 * @int $id Optional. The ID of a specific item to delete. 539 * @string $action Optional. The action to filter by. 540 * @string $content Optional. The content to filter by. 541 * @string $component Optional. The component name to filter by. 542 * @string $type Optional. The activity type to filter by. 543 * @string $primary_link Optional. The primary URL to filter by. 544 * @int $user_id Optional. The user ID to filter by. 545 * @int $item_id Optional. The associated item ID to filter by. 546 * @int $secondary_item_id Optional. The secondary associated item ID to filter by. 547 * @string $date_recorded Optional. The date to filter by. 548 * @int $hide_sitewide Optional. Default: false. 549 * } 550 * @return array|bool An array of deleted activity IDs on success, false on failure. 551 */ 394 552 public static function delete( $args = array() ) { 395 553 global $wpdb, $bp; … … 467 625 } 468 626 627 /** 628 * Delete the comments associated with a set of activity items. 629 * 630 * @param array $activity_ids Activity IDs whose comments should be deleted. 631 * @return bool True on success. 632 */ 469 633 public static function delete_activity_item_comments( $activity_ids = array() ) { 470 634 global $bp, $wpdb; … … 475 639 } 476 640 641 /** 642 * Delete the meta entries associated with a set of activity items. 643 * 644 * @param array $activity_ids Activity IDs whose meta should be deleted. 645 * @return bool True on success. 646 */ 477 647 public static function delete_activity_meta_entries( $activity_ids = array() ) { 478 648 global $bp, $wpdb; … … 488 658 489 659 /** 490 * Append activity comments to their associated activity items 660 * Append activity comments to their associated activity items. 661 * 662 * @since BuddyPress (1.2) 491 663 * 492 664 * @global wpdb $wpdb WordPress database object 493 * @param array $activities494 * @param bool $spam Optional; 'ham_only' (default), 'spam_only' or 'all'.495 * @ return array The updated activities with nested comments496 * @ since BuddyPress (1.2)665 * 666 * @param array $activities Activities to fetch comments for. 667 * @param bool $spam Optional. 'ham_only' (default), 'spam_only' or 'all'. 668 * @return array The updated activities with nested comments. 497 669 */ 498 670 public static function append_comments( $activities, $spam = 'ham_only' ) { … … 514 686 515 687 /** 516 * Get activity comments that are associated with a specific activity ID 517 * 518 * @global BuddyPress $bp The one true BuddyPress instance 519 * @global wpdb $wpdb WordPress database object 520 * @param int $activity_id Activity ID to fetch comments for 521 * @param int $left Left-most node boundary 522 * @param into $right Right-most node boundary 523 * @param bool $spam Optional; 'ham_only' (default), 'spam_only' or 'all'. 524 * @param int $top_level_parent_id The id of the root-level parent activity item 525 * @return array The updated activities with nested comments 688 * Get activity comments that are associated with a specific activity ID. 689 * 526 690 * @since BuddyPress (1.2) 691 * 692 * @global BuddyPress $bp The one true BuddyPress instance. 693 * @global wpdb $wpdb WordPress database object. 694 * 695 * @param int $activity_id Activity ID to fetch comments for. 696 * @param int $left Left-most node boundary. 697 * @param into $right Right-most node boundary. 698 * @param bool $spam Optional. 'ham_only' (default), 'spam_only' or 'all'. 699 * @param int $top_level_parent_id Optional. The id of the root-level parent activity item. 700 * @return array The updated activities with nested comments. 527 701 */ 528 702 public static function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only', $top_level_parent_id = 0 ) { … … 583 757 } 584 758 759 /** 760 * Rebuild nested comment tree under an activity or activity comment. 761 * 762 * @since BuddyPress (1.2) 763 * 764 * @global BuddyPress $bp The one true BuddyPress instance. 765 * @global wpdb $wpdb WordPress database object. 766 * 767 * @param int $parent_id ID of an activty or activity comment. 768 * @param int $left Node boundary start for activity or activity comment. 769 * @return int Right node boundary of activity or activity comment. 770 */ 585 771 public static function rebuild_activity_comment_tree( $parent_id, $left = 1 ) { 586 772 global $wpdb, $bp; … … 607 793 } 608 794 795 /** 796 * Get child comments of an activity or activity comment. 797 * 798 * @since BuddyPress (1.2) 799 * 800 * @global BuddyPress $bp The one true BuddyPress instance. 801 * @global wpdb $wpdb WordPress database object. 802 * 803 * @param int $parent_id ID of an activty or activity comment. 804 * @return object Numerically indexed array of child comments. 805 */ 609 806 public static function get_child_comments( $parent_id ) { 610 807 global $bp, $wpdb; … … 614 811 615 812 /** 616 * Fetch a list of all components that have activity items recorded617 * 618 * @return array 813 * Get a list of components that have recorded activity associated with them 814 * 815 * @return array List of component names. 619 816 */ 620 817 public static function get_recorded_components() { … … 623 820 } 624 821 822 /** 823 * Get sitewide activity items for use in an RSS feed. 824 * 825 * @param int $limit Optional. Number of items to fetch. Default: 35. 826 * @return array $activity_feed List of activity items, with RSS data added. 827 */ 625 828 public static function get_sitewide_items_for_feed( $limit = 35 ) { 626 829 $activities = bp_activity_get_sitewide( array( 'max' => $limit ) ); … … 628 831 629 832 for ( $i = 0, $count = count( $activities ); $i < $count; ++$i ) { 630 631 632 633 634 833 $title = explode( '<span', $activities[$i]['content'] ); 834 $activity_feed[$i]['title'] = trim( strip_tags( $title[0] ) ); 835 $activity_feed[$i]['link'] = $activities[$i]['primary_link']; 836 $activity_feed[$i]['description'] = @sprintf( $activities[$i]['content'], '' ); 837 $activity_feed[$i]['pubdate'] = $activities[$i]['date_recorded']; 635 838 } 636 839 … … 638 841 } 639 842 843 /** 844 * Create SQL IN clause for filter queries. 845 * 846 * @since BuddyPress (1.3) 847 * 848 * @see BP_Activity_Activity::get_filter_sql() 849 * 850 * @param string $field The database field. 851 * @param array|bool $items The values for the IN clause, or false when none are found. 852 */ 640 853 public static function get_in_operator_sql( $field, $items ) { 641 854 global $wpdb; … … 662 875 } 663 876 877 /** 878 * Create filter SQL clauses. 879 * 880 * @since BuddyPress (1.3) 881 * 882 * @param array $filter_array Multidimensional array of fields to filter and values. 883 * @return string The filter clause, for use in a SQL query. 884 */ 664 885 public static function get_filter_sql( $filter_array ) { 665 886 … … 702 923 } 703 924 925 /** 926 * Get the date/time of last recorded activity. 927 * 928 * @since BuddyPress (1.2) 929 * 930 * @return string ISO timestamp. 931 */ 704 932 public static function get_last_updated() { 705 933 global $bp, $wpdb; … … 708 936 } 709 937 938 /** 939 * Get favorite count for a given user. 940 * 941 * @since BuddyPress (1.2) 942 * 943 * @param int The ID of the user whose favorites you're counting. 944 * @return int A count of the user's favorites. 945 */ 710 946 public static function total_favorite_count( $user_id ) { 711 947 if ( !$favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true ) ) … … 715 951 } 716 952 953 /** 954 * Check whether an activity item exists with a given string content. 955 * 956 * @param string $content The content to filter by. 957 * @return int|bool The ID of the first matching item if found, otherwise false. 958 */ 717 959 public static function check_exists_by_content( $content ) { 718 960 global $wpdb, $bp; … … 721 963 } 722 964 965 /** 966 * Hide all activity for a given user. 967 * 968 * @param int $user_id The ID of the user whose activity you want to mark hidden. 969 * @param int 970 */ 723 971 public static function hide_all_for_user( $user_id ) { 724 972 global $wpdb, $bp; … … 859 1107 /** 860 1108 * Setup and validate the class properties. 1109 * 1110 * @access protected 861 1111 */ 862 1112 protected function setup_properties() { … … 881 1131 * Currently, these hooks are used to maintain backwards compatibility with 882 1132 * the RSS feeds previous to BP 1.8. 1133 * 1134 * @access protected 883 1135 */ 884 1136 protected function setup_hooks() { … … 890 1142 /** BACKPAT HOOKS ********************************************************/ 891 1143 1144 /** 1145 * Fire a hook to ensure backward compatibility for RSS attributes. 1146 */ 892 1147 public function backpat_rss_attributes() { 893 1148 do_action( 'bp_activity_' . $this->id . '_feed' ); 894 1149 } 895 1150 1151 /** 1152 * Fire a hook to ensure backward compatibility for channel elements. 1153 */ 896 1154 public function backpat_channel_elements() { 897 1155 do_action( 'bp_activity_' . $this->id . '_feed_head' ); 898 1156 } 899 1157 1158 /** 1159 * Fire a hook to ensure backward compatibility for item elements. 1160 */ 900 1161 public function backpat_item_elements() { 901 1162 switch ( $this->id ) { … … 921 1182 /** 922 1183 * Output the feed's item content. 1184 * 1185 * @access protected 923 1186 */ 924 1187 protected function feed_content() { … … 948 1211 /** 949 1212 * Output the RSS feed. 1213 * 1214 * @access protected 950 1215 */ 951 1216 protected function output() {
Note: See TracChangeset
for help on using the changeset viewer.