function bp_reshare_add_reshare_button() { global $bp; if (!is_user_logged_in()) { return false; } $activity_types_resharable = bp_reshare_activity_types(); if (!in_array(bp_get_activity_type(), $activity_types_resharable)) { return false; } if (bp_reshare_activity_is_hidden()) { return false; } if (bp_reshare_is_user_profile_reshares() && $bp->displayed_user->id != $bp->loggedin_user->id) { return false; } $activity_first_id = bp_get_activity_id(); if ('reshare_update' == bp_get_activity_type()) { $activity_first_id = bp_get_activity_secondary_item_id(); } $rs_count = bp_activity_get_meta($activity_first_id, 'reshared_count'); $rs_count = !empty($rs_count) ? $rs_count : 0; if ($bp->loggedin_user->id == bp_get_activity_user_id() || bp_reshare_user_did_reshared($activity_first_id)) { $reshared_class = 'reshared'; } $action_url = wp_nonce_url(bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/?to_reshare=' . $activity_first_id, '_reshare_update'); if ($_POST['scope'] == 'reshares' || bp_reshare_is_user_profile_reshares() || bp_is_activity_component() && !bp_displayed_user_id() && $_COOKIE['bp-activity-scope'] == 'reshares') { $extra_class = 'unshare'; $action_url = wp_nonce_url(bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/?delete_reshare=' . bp_get_activity_id(), '_reshare_delete'); } ?> <a href="<?php echo $action_url; ?> " class="button bp-primary-action bp-agu-reshare" id="bp-agu-reshare-<?php bp_activity_id(); ?> " rel="<?php echo $activity_first_id; ?> "><span class="bp-agu-reshare-img <?php echo $reshared_class . ' ' . $extra_class; ?> "></span><span class="rs-count"><?php echo $rs_count; ?> </span></a> <?php }
/** * let's add reshare if user's browser has javascript turned off */ function bp_reshare_post_reshare() { if (!empty($_GET['to_reshare']) && is_numeric($_GET['to_reshare'])) { check_admin_referer('_reshare_update'); $redirect = remove_query_arg(array('to_reshare', '_wpnonce'), wp_get_referer()); /* We need to check if loggedin user is the author of the original activity and if the loggedin user has already reshared this activity before posting the reshare */ $to_reshare_id = intval($_GET['to_reshare']); if (bp_reshare_user_did_reshared($to_reshare_id)) { // user is the author of the original activity or already reshared do_action('bp_reshare_handle_nojs_already_reshared', $reshared_activity_id); bp_core_add_message(__('OOps, looks like you already reshared this activity or you are the author of it..', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } else { $reshared_args = bp_reshare_prepare_reshare($to_reshare_id); $reshared_activity_id = bp_activity_add($reshared_args); if (!empty($reshared_activity_id)) { do_action('bp_reshare_handle_nojs_posted', $reshared_activity_id); bp_core_add_message(__('Activity reshared !', 'bp-reshare')); bp_core_redirect($redirect); } else { do_action('bp_reshare_handle_nojs_missed', $reshared_activity_id); bp_core_add_message(__('OOps, error while trying to reshare..', 'bp-reshare'), 'error'); bp_core_redirect($redirect); } } } }