Changeset 5829 for trunk/src/includes/common/functions.php
- Timestamp:
- 07/14/2015 12:46:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/common/functions.php
r5827 r5829 126 126 ); 127 127 128 if ( ! empty( $older_date ) && !is_numeric( $older_date ) ) {128 if ( ! empty( $older_date ) && !is_numeric( $older_date ) ) { 129 129 $time_chunks = explode( ':', str_replace( ' ', ':', $older_date ) ); 130 130 $date_chunks = explode( '-', str_replace( ' ', '-', $older_date ) ); … … 135 135 // between a date and the current time. $newer_date will have a value if 136 136 // we want to work out time elapsed between two known dates. 137 $newer_date = ( ! $newer_date ) ? strtotime( current_time( 'mysql', $gmt ) ) : $newer_date;137 $newer_date = ( ! $newer_date ) ? strtotime( current_time( 'mysql', $gmt ) ) : $newer_date; 138 138 139 139 // Difference in seconds … … 162 162 163 163 // If $i iterates all the way to $j, then the event happened 0 seconds ago 164 if ( ! isset( $chunks[$i] ) ) {164 if ( ! isset( $chunks[$i] ) ) { 165 165 $output = $right_now_text; 166 166 … … 242 242 */ 243 243 function bbp_get_redirect_to() { 244 $retval = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';244 $retval = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : ''; 245 245 246 246 return apply_filters( 'bbp_get_redirect_to', $retval ); … … 262 262 263 263 // Are we appending the view=all vars? 264 if ( bbp_get_view_all() || ! empty( $force ) ) {264 if ( bbp_get_view_all() || ! empty( $force ) ) { 265 265 $link = add_query_arg( array( 'view' => 'all' ), $original_link ); 266 266 } else { … … 296 296 */ 297 297 function bbp_get_view_all( $cap = 'moderate' ) { 298 $retval = ( ( ! empty( $_GET['view'] ) && ( 'all' === $_GET['view'] ) && current_user_can( $cap ) ) );298 $retval = ( ( ! empty( $_GET['view'] ) && ( 'all' === $_GET['view'] ) && current_user_can( $cap ) ) ); 299 299 return apply_filters( 'bbp_get_view_all', (bool) $retval ); 300 300 } … … 316 316 317 317 // Check query paged 318 } elseif ( ! empty( $wp_query->query['paged'] ) ) {318 } elseif ( ! empty( $wp_query->query['paged'] ) ) { 319 319 $paged = $wp_query->query['paged']; 320 320 } 321 321 322 322 // Paged found 323 if ( ! empty( $paged ) ) {323 if ( ! empty( $paged ) ) { 324 324 return (int) $paged; 325 325 } … … 354 354 355 355 // Post is not a topic or reply, return 356 if ( ! in_array( $data['post_type'], array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) {356 if ( ! in_array( $data['post_type'], array( bbp_get_topic_post_type(), bbp_get_reply_post_type() ) ) ) { 357 357 return $data; 358 358 } 359 359 360 360 // Is the post by an anonymous user? 361 if ( ( bbp_get_topic_post_type() === $data['post_type'] && ! bbp_is_topic_anonymous( $postarr['ID'] ) ) ||362 ( bbp_get_reply_post_type() === $data['post_type'] && ! bbp_is_reply_anonymous( $postarr['ID'] ) ) ) {361 if ( ( bbp_get_topic_post_type() === $data['post_type'] && ! bbp_is_topic_anonymous( $postarr['ID'] ) ) || 362 ( bbp_get_reply_post_type() === $data['post_type'] && ! bbp_is_reply_anonymous( $postarr['ID'] ) ) ) { 363 363 return $data; 364 364 } … … 480 480 481 481 // Users 482 if ( ! empty( $r['count_users'] ) ) {482 if ( ! empty( $r['count_users'] ) ) { 483 483 $user_count = bbp_get_total_users(); 484 484 } 485 485 486 486 // Forums 487 if ( ! empty( $r['count_forums'] ) ) {487 if ( ! empty( $r['count_forums'] ) ) { 488 488 $forum_count = wp_count_posts( bbp_get_forum_post_type() )->publish; 489 489 } … … 496 496 497 497 // Topics 498 if ( ! empty( $r['count_topics'] ) ) {498 if ( ! empty( $r['count_topics'] ) ) { 499 499 $all_topics = wp_count_posts( bbp_get_topic_post_type() ); 500 500 … … 505 505 506 506 // Private 507 $topics['private'] = ( ! empty( $r['count_private_topics'] ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0;507 $topics['private'] = ( ! empty( $r['count_private_topics'] ) && current_user_can( 'read_private_topics' ) ) ? (int) $all_topics->{$private} : 0; 508 508 509 509 // Spam 510 $topics['spammed'] = ( ! empty( $r['count_spammed_topics'] ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$spam} : 0;510 $topics['spammed'] = ( ! empty( $r['count_spammed_topics'] ) && current_user_can( 'edit_others_topics' ) ) ? (int) $all_topics->{$spam} : 0; 511 511 512 512 // Trash 513 $topics['trashed'] = ( ! empty( $r['count_trashed_topics'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$trash} : 0;513 $topics['trashed'] = ( ! empty( $r['count_trashed_topics'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_topics->{$trash} : 0; 514 514 515 515 // Total hidden (private + spam + trash) … … 517 517 518 518 // Generate the hidden topic count's title attribute 519 $topic_titles[] = ! empty( $topics['private'] ) ? sprintf( __( 'Private: %s', 'bbpress' ), number_format_i18n( $topics['private'] ) ) : '';520 $topic_titles[] = ! empty( $topics['spammed'] ) ? sprintf( __( 'Spammed: %s', 'bbpress' ), number_format_i18n( $topics['spammed'] ) ) : '';521 $topic_titles[] = ! empty( $topics['trashed'] ) ? sprintf( __( 'Trashed: %s', 'bbpress' ), number_format_i18n( $topics['trashed'] ) ) : '';519 $topic_titles[] = ! empty( $topics['private'] ) ? sprintf( __( 'Private: %s', 'bbpress' ), number_format_i18n( $topics['private'] ) ) : ''; 520 $topic_titles[] = ! empty( $topics['spammed'] ) ? sprintf( __( 'Spammed: %s', 'bbpress' ), number_format_i18n( $topics['spammed'] ) ) : ''; 521 $topic_titles[] = ! empty( $topics['trashed'] ) ? sprintf( __( 'Trashed: %s', 'bbpress' ), number_format_i18n( $topics['trashed'] ) ) : ''; 522 522 523 523 // Compile the hidden topic title … … 527 527 528 528 // Replies 529 if ( ! empty( $r['count_replies'] ) ) {529 if ( ! empty( $r['count_replies'] ) ) { 530 530 531 531 $all_replies = wp_count_posts( bbp_get_reply_post_type() ); … … 537 537 538 538 // Private 539 $replies['private'] = ( ! empty( $r['count_private_replies'] ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0;539 $replies['private'] = ( ! empty( $r['count_private_replies'] ) && current_user_can( 'read_private_replies' ) ) ? (int) $all_replies->{$private} : 0; 540 540 541 541 // Spam 542 $replies['spammed'] = ( ! empty( $r['count_spammed_replies'] ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$spam} : 0;542 $replies['spammed'] = ( ! empty( $r['count_spammed_replies'] ) && current_user_can( 'edit_others_replies' ) ) ? (int) $all_replies->{$spam} : 0; 543 543 544 544 // Trash 545 $replies['trashed'] = ( ! empty( $r['count_trashed_replies'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$trash} : 0;545 $replies['trashed'] = ( ! empty( $r['count_trashed_replies'] ) && current_user_can( 'view_trash' ) ) ? (int) $all_replies->{$trash} : 0; 546 546 547 547 // Total hidden (private + spam + trash) … … 549 549 550 550 // Generate the hidden topic count's title attribute 551 $reply_titles[] = ! empty( $replies['private'] ) ? sprintf( __( 'Private: %s', 'bbpress' ), number_format_i18n( $replies['private'] ) ) : '';552 $reply_titles[] = ! empty( $replies['spammed'] ) ? sprintf( __( 'Spammed: %s', 'bbpress' ), number_format_i18n( $replies['spammed'] ) ) : '';553 $reply_titles[] = ! empty( $replies['trashed'] ) ? sprintf( __( 'Trashed: %s', 'bbpress' ), number_format_i18n( $replies['trashed'] ) ) : '';551 $reply_titles[] = ! empty( $replies['private'] ) ? sprintf( __( 'Private: %s', 'bbpress' ), number_format_i18n( $replies['private'] ) ) : ''; 552 $reply_titles[] = ! empty( $replies['spammed'] ) ? sprintf( __( 'Spammed: %s', 'bbpress' ), number_format_i18n( $replies['spammed'] ) ) : ''; 553 $reply_titles[] = ! empty( $replies['trashed'] ) ? sprintf( __( 'Trashed: %s', 'bbpress' ), number_format_i18n( $replies['trashed'] ) ) : ''; 554 554 555 555 // Compile the hidden replies title … … 560 560 561 561 // Topic Tags 562 if ( ! empty( $r['count_tags'] ) && bbp_allow_topic_tags() ) {562 if ( ! empty( $r['count_tags'] ) && bbp_allow_topic_tags() ) { 563 563 564 564 // Get the count … … 566 566 567 567 // Empty tags 568 if ( ! empty( $r['count_empty_tags'] ) && current_user_can( 'edit_topic_tags' ) ) {568 if ( ! empty( $r['count_empty_tags'] ) && current_user_can( 'edit_topic_tags' ) ) { 569 569 $empty_topic_tag_count = wp_count_terms( bbp_get_topic_tag_tax_id() ) - $topic_tag_count; 570 570 } … … 621 621 // Parse arguments against default values 622 622 $r = bbp_parse_args( $args, array ( 623 'bbp_anonymous_name' => ! empty( $_POST['bbp_anonymous_name'] ) ? $_POST['bbp_anonymous_name'] : false,624 'bbp_anonymous_email' => ! empty( $_POST['bbp_anonymous_email'] ) ? $_POST['bbp_anonymous_email'] : false,625 'bbp_anonymous_website' => ! empty( $_POST['bbp_anonymous_website'] ) ? $_POST['bbp_anonymous_website'] : false,623 'bbp_anonymous_name' => ! empty( $_POST['bbp_anonymous_name'] ) ? $_POST['bbp_anonymous_name'] : false, 624 'bbp_anonymous_email' => ! empty( $_POST['bbp_anonymous_email'] ) ? $_POST['bbp_anonymous_email'] : false, 625 'bbp_anonymous_website' => ! empty( $_POST['bbp_anonymous_website'] ) ? $_POST['bbp_anonymous_website'] : false, 626 626 ), 'filter_anonymous_post_data' ); 627 627 … … 686 686 687 687 // Check for anonymous post 688 if ( empty( $r['post_author'] ) && ( ! empty( $r['anonymous_data'] ) && !empty( $r['anonymous_data']['bbp_anonymous_email'] ) ) ) {688 if ( empty( $r['post_author'] ) && ( ! empty( $r['anonymous_data'] ) && ! empty( $r['anonymous_data']['bbp_anonymous_email'] ) ) ) { 689 689 $clauses = get_meta_sql( array( array( 690 690 'key' => '_bbp_anonymous_email', … … 706 706 // Prepare duplicate check query 707 707 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] ); 708 $query .= ! empty( $r['post_parent'] ) ? $bbp_db->prepare( " AND post_parent = %d", $r['post_parent'] ) : '';708 $query .= ! empty( $r['post_parent'] ) ? $bbp_db->prepare( " AND post_parent = %d", $r['post_parent'] ) : ''; 709 709 $query .= " LIMIT 1"; 710 710 $dupe = apply_filters( 'bbp_check_for_duplicate_query', $query, $r ); … … 749 749 750 750 // User is anonymous, so check a transient based on the IP 751 if ( ! empty( $anonymous_data ) && is_array( $anonymous_data ) ) {751 if ( ! empty( $anonymous_data ) && is_array( $anonymous_data ) ) { 752 752 $last_posted = get_transient( '_bbp_' . bbp_current_author_ip() . '_last_posted' ); 753 753 754 if ( ! empty( $last_posted ) && time() < $last_posted + $throttle_time ) {754 if ( ! empty( $last_posted ) && time() < $last_posted + $throttle_time ) { 755 755 return false; 756 756 } 757 757 758 758 // User is logged in, so check their last posted time 759 } elseif ( ! empty( $author_id ) ) {759 } elseif ( ! empty( $author_id ) ) { 760 760 $author_id = (int) $author_id; 761 761 $last_posted = bbp_get_user_last_posted( $author_id ); … … 816 816 817 817 // If data exists, map it 818 if ( ! empty( $user ) ) {818 if ( ! empty( $user ) ) { 819 819 $_post['author'] = $user->display_name; 820 820 $_post['email'] = $user->user_email; … … 916 916 917 917 // Bail if keymaster is author 918 if ( ! empty( $author_id ) && bbp_is_user_keymaster( $author_id ) ) {918 if ( ! empty( $author_id ) && bbp_is_user_keymaster( $author_id ) ) { 919 919 return true; 920 920 } … … 936 936 937 937 // Map anonymous user data 938 if ( ! empty( $anonymous_data ) ) {938 if ( ! empty( $anonymous_data ) ) { 939 939 $_post['author'] = $anonymous_data['bbp_anonymous_name']; 940 940 $_post['email'] = $anonymous_data['bbp_anonymous_email']; … … 942 942 943 943 // Map current user data 944 } elseif ( ! empty( $author_id ) ) {944 } elseif ( ! empty( $author_id ) ) { 945 945 946 946 // Get author data … … 948 948 949 949 // If data exists, map it 950 if ( ! empty( $user ) ) {950 if ( ! empty( $user ) ) { 951 951 $_post['author'] = $user->display_name; 952 952 $_post['email'] = $user->user_email; … … 1074 1074 1075 1075 // Bail if subscriptions are turned off 1076 if ( ! bbp_is_subscriptions_active() ) {1076 if ( ! bbp_is_subscriptions_active() ) { 1077 1077 return false; 1078 1078 } … … 1087 1087 1088 1088 // Bail if topic is not published 1089 if ( ! bbp_is_topic_published( $topic_id ) ) {1089 if ( ! bbp_is_topic_published( $topic_id ) ) { 1090 1090 return false; 1091 1091 } … … 1094 1094 1095 1095 // Bail if reply is not published 1096 if ( ! bbp_is_reply_published( $reply_id ) ) {1096 if ( ! bbp_is_reply_published( $reply_id ) ) { 1097 1097 return false; 1098 1098 } … … 1167 1167 1168 1168 // Don't send notifications to the person who made the post 1169 if ( ! empty( $reply_author ) && (int) $user_id === (int) $reply_author ) {1169 if ( ! empty( $reply_author ) && (int) $user_id === (int) $reply_author ) { 1170 1170 continue; 1171 1171 } … … 1232 1232 1233 1233 // Bail if subscriptions are turned off 1234 if ( ! bbp_is_subscriptions_active() ) {1234 if ( ! bbp_is_subscriptions_active() ) { 1235 1235 return false; 1236 1236 } … … 1324 1324 1325 1325 // Don't send notifications to the person who made the post 1326 if ( ! empty( $topic_author ) && (int) $user_id === (int) $topic_author ) {1326 if ( ! empty( $topic_author ) && (int) $user_id === (int) $topic_author ) { 1327 1327 continue; 1328 1328 } … … 1385 1385 1386 1386 // Rejig the $redirect_to 1387 if ( ! isset( $_SERVER['REDIRECT_URL'] ) || ( $redirect_to !== home_url( $_SERVER['REDIRECT_URL'] ) ) ) {1387 if ( ! isset( $_SERVER['REDIRECT_URL'] ) || ( $redirect_to !== home_url( $_SERVER['REDIRECT_URL'] ) ) ) { 1388 1388 $redirect_to = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : ''; 1389 1389 } … … 1429 1429 1430 1430 // Passively filter the args before the parse 1431 if ( ! empty( $filter_key ) ) {1431 if ( ! empty( $filter_key ) ) { 1432 1432 $r = apply_filters( 'bbp_before_' . $filter_key . '_parse_args', $r ); 1433 1433 } 1434 1434 1435 1435 // Parse 1436 if ( is_array( $defaults ) && ! empty( $defaults ) ) {1436 if ( is_array( $defaults ) && ! empty( $defaults ) ) { 1437 1437 $r = array_merge( $defaults, $r ); 1438 1438 } 1439 1439 1440 1440 // Aggressively filter the args after the parse 1441 if ( ! empty( $filter_key ) ) {1441 if ( ! empty( $filter_key ) ) { 1442 1442 $r = apply_filters( 'bbp_after_' . $filter_key . '_parse_args', $r ); 1443 1443 } … … 1884 1884 1885 1885 // Single forum 1886 if ( ! empty( $select_query_vars ) ) {1886 if ( ! empty( $select_query_vars ) ) { 1887 1887 1888 1888 // Load up our own query … … 1902 1902 1903 1903 // Only forum replies 1904 if ( ! empty( $_GET['type'] ) && ( bbp_get_reply_post_type() === $_GET['type'] ) ) {1904 if ( ! empty( $_GET['type'] ) && ( bbp_get_reply_post_type() === $_GET['type'] ) ) { 1905 1905 1906 1906 // The query … … 1920 1920 1921 1921 // Only forum topics 1922 } elseif ( ! empty( $_GET['type'] ) && ( bbp_get_topic_post_type() === $_GET['type'] ) ) {1922 } elseif ( ! empty( $_GET['type'] ) && ( bbp_get_topic_post_type() === $_GET['type'] ) ) { 1923 1923 1924 1924 // The query … … 1966 1966 1967 1967 // Single topic 1968 if ( ! empty( $select_query_vars ) ) {1968 if ( ! empty( $select_query_vars ) ) { 1969 1969 1970 1970 // Load up our own query … … 2021 2021 2022 2022 // We have a view to display a feed 2023 if ( ! empty( $view ) ) {2023 if ( ! empty( $view ) ) { 2024 2024 2025 2025 // Get the view query … … 2057 2057 2058 2058 // Path is not empty 2059 if ( ! empty( $path ) ) {2059 if ( ! empty( $path ) ) { 2060 2060 2061 2061 // Pretty permalinks are on so path might exist
Note: See TracChangeset
for help on using the changeset viewer.