Skip to content

Commit

Permalink
Merge pull request #4406 from buddyboss/PROD-7416
Browse files Browse the repository at this point in the history
(Web) Polls
  • Loading branch information
KartikSuthar authored Sep 5, 2024
2 parents bf888cb + 2dc18ad commit 3da35dc
Show file tree
Hide file tree
Showing 14 changed files with 529 additions and 261 deletions.
5 changes: 4 additions & 1 deletion src/bp-activity/bp-activity-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5854,6 +5854,7 @@ function bb_activity_following_post_notification( $args ) {
$media_ids = $activity_metas['bp_media_ids'][0] ?? '';
$document_ids = $activity_metas['bp_document_ids'][0] ?? '';
$video_ids = $activity_metas['bp_video_ids'][0] ?? '';
$poll_id = $activity_metas['bb_poll_id'][0] ?? 0;

if ( $media_ids ) {
$media_ids = array_filter( ! is_array( $media_ids ) ? explode( ',', $media_ids ) : $media_ids );
Expand All @@ -5876,6 +5877,8 @@ function bb_activity_following_post_notification( $args ) {
} else {
$text = __( 'a video', 'buddyboss' );
}
} elseif ( ! empty( $poll_id ) ) {
$text = __( 'a new poll', 'buddyboss' );
} else {
$text = __( 'an update', 'buddyboss' );
}
Expand Down Expand Up @@ -5925,7 +5928,7 @@ function bb_activity_following_post_notification( $args ) {
'user_id' => $user_id,
'notification_type' => 'new-activity-following',
);
$poster_name = bp_core_get_user_displayname( $activity_user_id, $user_id );
$poster_name = bp_core_get_user_displayname( $activity_user_id, $user_id );

$args['tokens']['poster.name'] = $poster_name;
$args['tokens']['unsubscribe'] = esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) );
Expand Down
16 changes: 16 additions & 0 deletions src/bp-activity/classes/class-bp-activity-notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,9 @@ public function bb_render_activity_following_post_notification( $content, $item_
$document_ids = bp_activity_get_meta( $activity->id, 'bp_document_ids', true );
$video_ids = bp_activity_get_meta( $activity->id, 'bp_video_ids', true );
$gif_data = bp_activity_get_meta( $activity->id, '_gif_data', true );
$poll_id = bp_activity_get_meta( $activity->id, 'bb_poll_id' );
$poll = ! empty( $poll_id ) && function_exists( 'bb_load_polls' ) ? bb_load_polls()->bb_get_poll( $poll_id ) : '';
$question = ! empty( $poll->question ) ? $poll->question : '';
$amount = 'single';

if ( 'web_push' === $screen ) {
Expand Down Expand Up @@ -692,6 +695,12 @@ public function bb_render_activity_following_post_notification( $content, $item_
}
} elseif ( ! empty( $gif_data ) ) {
$text = __( 'Posted an update', 'buddyboss' );
} elseif ( ! empty( $question ) ) {
$text = sprintf(
/* translators: %s: question. */
__( 'Posted a poll "%1$s"', 'buddyboss' ),
$question
);
} else {
$text = __( 'Posted an update', 'buddyboss' );
}
Expand Down Expand Up @@ -764,6 +773,13 @@ public function bb_render_activity_following_post_notification( $content, $item_
__( '%1$s posted an update', 'buddyboss' ),
$user_fullname
);
} elseif ( ! empty( $question ) ) {
$text = sprintf(
/* translators: %1$s: User full name, %2$s: question. */
__( '%1$s posted a poll "%2$s"', 'buddyboss' ),
$user_fullname,
$question
);
} else {
$text = sprintf(
/* translators: %s: User full name. */
Expand Down
55 changes: 29 additions & 26 deletions src/bp-core/admin/bp-core-admin-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3409,29 +3409,29 @@ function bb_get_pro_label_notice( $type = 'default' ) {
);
} elseif (
function_exists( 'bb_platform_pro' ) &&
version_compare( bb_platform_pro()->version, '2.4.50', '<' ) &&
! empty( $type ) &&
'reaction' === $type
) {
$bb_pro_notice = sprintf(
'<br/><span class="bb-head-notice"> %1$s <strong>%2$s</strong> %3$s</span>',
esc_html__( 'Update', 'buddyboss' ),
esc_html__( 'BuddyBoss Platform Pro', 'buddyboss' ),
esc_html__( 'to unlock', 'buddyboss' )
);
} elseif (
function_exists( 'bb_platform_pro' ) &&
version_compare( bb_platform_pro()->version, bb_pro_schedule_posts_version(), '<' ) &&
! empty( $type ) &&
'schedule_posts' === $type
(
(
'reaction' === $type &&
version_compare( bb_platform_pro()->version, '2.4.50', '<' )
) ||
(
'schedule_posts' === $type &&
version_compare( bb_platform_pro()->version, bb_pro_schedule_posts_version(), '<' )
) ||
(
'polls' === $type &&
version_compare( bb_platform_pro()->version, bb_pro_poll_version(), '<' )
)
)
) {
$bb_pro_notice = sprintf(
'<br/><span class="bb-head-notice"> %1$s <strong>%2$s</strong> %3$s</span>',
esc_html__( 'Update', 'buddyboss' ),
esc_html__( 'BuddyBoss Platform Pro', 'buddyboss' ),
esc_html__( 'to unlock', 'buddyboss' )
);
} elseif( ! function_exists( 'bb_platform_pro' ) || ! bbp_pro_is_license_valid() ) {
} elseif ( ! function_exists( 'bb_platform_pro' ) || ! bbp_pro_is_license_valid() ) {
$bb_pro_notice = sprintf(
'<br/><span class="bb-head-notice"> %1$s <a target="_blank" href="https://www.buddyboss.com/platform/">%2$s</a> %3$s</span>',
esc_html__( 'Install', 'buddyboss' ),
Expand Down Expand Up @@ -3472,19 +3472,22 @@ function bb_get_pro_fields_class( $type = 'default' ) {
}

if (
! empty( $type ) &&
'reaction' === $type &&
function_exists( 'bb_platform_pro' ) &&
version_compare( bb_platform_pro()->version, '2.4.50', '<' )
) {
$pro_class = 'bb-pro-inactive';
}

if (
! empty( $type ) &&
'schedule_posts' === $type &&
function_exists( 'bb_platform_pro' ) &&
version_compare( bb_platform_pro()->version, bb_pro_schedule_posts_version(), '<' )
(
(
'reaction' === $type &&
version_compare( bb_platform_pro()->version, '2.4.50', '<' )
) ||
(
'schedule_posts' === $type &&
version_compare( bb_platform_pro()->version, bb_pro_schedule_posts_version(), '<' )
) ||
(
'polls' === $type &&
version_compare( bb_platform_pro()->version, bb_pro_poll_version(), '<' )
)
)
) {
$pro_class = 'bb-pro-inactive';
}
Expand Down
27 changes: 24 additions & 3 deletions src/bp-core/admin/settings/bp-admin-setting-activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ function ( $post_type ) {

public function register_fields() {

$pro_class = bb_get_pro_fields_class( 'schedule_posts' );

$this->add_section( 'bp_activity', __( 'Activity Settings', 'buddyboss' ), '', 'bp_activity_settings_tutorial' );

// Allow Activity edit setting.
Expand All @@ -87,6 +85,15 @@ public function register_fields() {
// Allow scopes/tabs.
$this->add_field( '_bb_enable_activity_pinned_posts', __( 'Pinned Post', 'buddyboss' ), 'bb_admin_setting_callback_enable_activity_pinned_posts', 'intval' );

// Allow Poll.
$polls_pro_class = bb_get_pro_fields_class( 'polls' );
$polls_notice = bb_get_pro_label_notice( 'polls' );
$poll_args = array();
$poll_args['class'] = esc_attr( $polls_pro_class );
$poll_args['notice'] = $polls_notice;
$this->add_field( '_bb_enable_activity_post_polls', __( 'Polls', 'buddyboss' ) . $polls_notice, array( $this, 'bb_admin_setting_callback_enable_activity_post_polls' ), 'intval', $poll_args );

$pro_class = bb_get_pro_fields_class( 'schedule_posts' );
$args = array();
$args['class'] = esc_attr( $pro_class );

Expand Down Expand Up @@ -385,7 +392,21 @@ public function bb_admin_setting_callback_enable_activity_schedule_posts() {
$notice = bb_get_pro_label_notice( 'schedule_posts' );
?>
<input id="bb_enable_activity_schedule_posts" name="<?php echo empty( $notice ) ? '_bb_enable_activity_schedule_posts' : ''; ?>" type="checkbox" value="1" <?php echo empty( $notice ) ? checked( $val, true, false ) : ''; ?> />
<label for="bb_enable_activity_schedule_posts"><?php esc_html_e( 'Allow Group Organizers and Moderators to schedule their posts', 'buddyboss' ); ?></label>
<label for="bb_enable_activity_schedule_posts"><?php esc_html_e( 'Allow group owners and moderators to schedule their posts', 'buddyboss' ); ?></label>
<?php
}

/**
* Allow activity poll.
*
* @since BuddyBoss [BBVERSION]
*/
public function bb_admin_setting_callback_enable_activity_post_polls( $args ) {
$val = function_exists( 'bb_is_enabled_activity_post_polls' ) ? bb_is_enabled_activity_post_polls( false ) : false;
$notice = ! empty( $args['notice'] ) ? $args['notice'] : '';
?>
<input id="bb_enable_activity_post_polls" name="<?php echo empty( $notice ) ? '_bb_enable_activity_post_polls' : ''; ?>" type="checkbox" value="1" <?php echo empty( $notice ) ? checked( $val, true, false ) : ''; ?> />
<label for="bb_enable_activity_post_polls"><?php esc_html_e( 'Allow group owners and moderators to post polls', 'buddyboss' ); ?></label>
<?php
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/bp-core/bp-core-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -9878,3 +9878,14 @@ function bb_remove_deleted_user_last_activities() {
$wpdb->query( $delete_query ); // phpcs:ignore
}
}

/**
* Function to return the minimum pro version to show notice for poll.
*
* @since BuddyBoss 2.6.10
*
* @return string
*/
function bb_pro_poll_version() {
return '2.5.91'; // @todo: update when release.
}
8 changes: 7 additions & 1 deletion src/bp-core/classes/class-bp-email-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,13 @@ function_exists( 'bp_use_embed_in_activity' ) &&
}
?>
</div>
<?php echo $this->get_email_media( $activity->id, $tokens ); ?>
<?php
$poll_id = bp_activity_get_meta( $activity->id, 'bb_poll_id' );
if ( ! empty( $poll_id ) && function_exists( 'get_email_poll' ) ) {
echo get_email_poll( $activity->id, $poll_id, $tokens );
}
echo $this->get_email_media( $activity->id, $tokens );
?>
</td>
</tr>
<tr>
Expand Down
3 changes: 3 additions & 0 deletions src/bp-notifications/bp-notifications-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,7 @@ function bb_get_notification_conditional_icon( $notification ) {
$video_ids = $activity_metas['bp_video_ids'][0] ?? '';
$gif_data = ! empty( $activity_metas['_gif_data'][0] ) ? maybe_unserialize( $activity_metas['_gif_data'][0] ) : array();
$excerpt = wp_strip_all_tags( $activity->content );
$bb_poll_id = $activity_metas['bb_poll_id'][0] ?? '';

if ( '&nbsp;' === $excerpt ) {
$excerpt = '';
Expand All @@ -1419,6 +1420,8 @@ function bb_get_notification_conditional_icon( $notification ) {
$icon_class = 'bb-icon-f bb-icon-video';
} elseif ( ! empty( $gif_data ) ) {
$icon_class = 'bb-icon-f bb-icon-activity';
} elseif ( ! empty( $bb_poll_id ) ) {
$icon_class = 'bb-icon-f bb-icon-poll';
} else {
$icon_class = 'bb-icon-f bb-icon-activity';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<span class="bp-item-name">{{data.name}}</span>

<span class="bb-radio-style privacy-radio <# if ( data.selected ) { #>selected<# } #>">
<input type="radio" id="bp-item-opt-{{data.id}}" class="bp-activity-object__radio" name="group-privacy" data-title="{{data.name}}" data-id="{{data.id}}" <# if ( data.allow_schedule ) { #> data-allow-schedule-post="{{data.allow_schedule}}" <# } #> value="opt-value-{{data.id}}" <# if ( data.selected ) { #> checked <# } #>><span></span>
<input type="radio" id="bp-item-opt-{{data.id}}" class="bp-activity-object__radio" name="group-privacy" data-title="{{data.name}}" data-id="{{data.id}}" <# if ( data.allow_schedule ) { #> data-allow-schedule-post="{{data.allow_schedule}}" <# } #> <# if ( data.allow_polls ) { #> data-allow-polls="{{data.allow_polls}}" <# } #> value="opt-value-{{data.id}}" <# if ( data.selected ) { #> checked <# } #>><span></span>
</span>
</label>
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@
?>
<script type="text/html" id="tmpl-whats-new-toolbar">

<?php if ( bp_is_active( 'media' ) && ( ( bp_is_activity_directory() && ( bp_is_profile_media_support_enabled() || bp_is_group_media_support_enabled() ) ) || ( bp_is_user_activity() && bp_is_profile_media_support_enabled() ) || ( bp_is_group_activity() && bp_is_group_media_support_enabled() ) ) ) : ?>
<?php

/**
* Fires at the beginning of the whats new toolbar.
*
* @since BuddyBoss [BBVERSION]
*/
do_action( 'bb_whats_new_toolbar_before' );

if ( bp_is_active( 'media' ) && ( ( bp_is_activity_directory() && ( bp_is_profile_media_support_enabled() || bp_is_group_media_support_enabled() ) ) || ( bp_is_user_activity() && bp_is_profile_media_support_enabled() ) || ( bp_is_group_activity() && bp_is_group_media_support_enabled() ) ) ) : ?>
<div class="post-elements-buttons-item post-media media-support">
<a href="#" id="activity-media-button" class="toolbar-button bp-tooltip" data-bp-tooltip-pos="up-left" data-bp-tooltip="<?php esc_attr_e( 'Attach photo', 'buddyboss' ); ?>">
<i class="bb-icon-l bb-icon-camera"></i>
Expand Down Expand Up @@ -46,5 +55,13 @@
<div class="gif-media-search-dropdown"></div>
</div>
</div>
<?php endif; ?>
<?php endif;

/**
* Fires at the end of the whats new toolbar.
*
* @since BuddyBoss [BBVERSION]
*/
do_action( 'bb_whats_new_toolbar_after' );
?>
</script>
2 changes: 2 additions & 0 deletions src/bp-templates/bp-nouveau/includes/activity/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,8 @@ function bp_nouveau_ajax_post_update() {
$toolbar_option = true;
} elseif ( bp_is_active( 'video' ) && ! empty( $_POST['video'] ) ) {
$toolbar_option = true;
} elseif ( ! empty( sanitize_text_field( wp_unslash( (int) $_POST['poll_id'] ) ) ) ) {
$toolbar_option = true;
}

if ( ! $toolbar_option ) {
Expand Down
12 changes: 9 additions & 3 deletions src/bp-templates/bp-nouveau/includes/groups/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,12 +482,18 @@ function bp_nouveau_prepare_group_for_js( $item ) {
'group_video' => ( bp_is_active( 'video' ) && bp_is_group_video_support_enabled() && bb_video_user_can_upload( bp_loggedin_user_id(), $item->id ) ),
);

$val = function_exists( 'bb_is_enabled_activity_schedule_posts_filter' ) ? bb_is_enabled_activity_schedule_posts_filter() : false;
if ( $val ) {
$allow_schedule = function_exists( 'bb_is_enabled_activity_schedule_posts_filter' ) ? bb_is_enabled_activity_schedule_posts_filter() : false;
$allow_polls = function_exists( 'bb_is_enabled_activity_post_polls' ) ? bb_is_enabled_activity_post_polls( false ) : false;
if ( $allow_schedule || $allow_polls ) {
$is_admin = groups_is_user_admin( bp_loggedin_user_id(), $item->id );
$is_mod = groups_is_user_mod( bp_loggedin_user_id(), $item->id );
if ( $is_admin || $is_mod ) {
$args['allow_schedule'] = 'enabled';
if ( $allow_schedule ) {
$args['allow_schedule'] = 'enabled';
}
if ( $allow_polls ) {
$args['allow_polls'] = 'enabled';
}
if ( bp_is_active( 'activity' ) && bp_is_activity_directory() ) {
$args['group_url'] = trailingslashit( bp_get_group_permalink( $item ) . bp_get_activity_slug() );
}
Expand Down
Loading

0 comments on commit 3da35dc

Please sign in to comment.