Skip to content

Commit

Permalink
feat: share link in first comment
Browse files Browse the repository at this point in the history
  • Loading branch information
girishpanchal30 committed Jan 8, 2025
1 parent 03aabb2 commit b731175
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 20 deletions.
10 changes: 10 additions & 0 deletions includes/admin/abstract/class-rop-services-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,16 @@ public function get_service_id() {

}

/**
* Share the post link in the first comment.
*
* @access public
*
* @param string $url API endpoint.
* @param array $data API data.
*/
public function share_as_first_comment( $url, $data = array() ) {}

/**
* Method to request a token from api.
*
Expand Down
42 changes: 22 additions & 20 deletions includes/admin/class-rop-global-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,26 +180,28 @@ class Rop_Global_Settings {
*/
private $post_format_defaults = array(
'facebook' => array(
'wpml_language' => '',
'post_content' => 'post_title',
'custom_meta_field' => '',
'maximum_length' => '1000',
'custom_text' => '',
'custom_text_pos' => 'beginning',
'include_link' => true,
'url_from_meta' => false,
'url_meta_key' => '',
'short_url' => false,
'short_url_service' => 'rviv.ly',
'hashtags' => 'no-hashtags',
'hashtags_length' => '200',
'hashtags_common' => '',
'hashtags_custom' => '',
'hashtags_randomize' => false,
'shortner_credentials' => array(),
'image' => false,
'utm_campaign_medium' => 'social',
'utm_campaign_name' => 'ReviveOldPost',
'wpml_language' => '',
'post_content' => 'post_title',
'custom_meta_field' => '',
'maximum_length' => '1000',
'custom_text' => '',
'custom_text_pos' => 'beginning',
'include_link' => true,
'url_from_meta' => false,
'url_meta_key' => '',
'short_url' => false,
'short_url_service' => 'rviv.ly',
'hashtags' => 'no-hashtags',
'hashtags_length' => '200',
'hashtags_common' => '',
'hashtags_custom' => '',
'hashtags_randomize' => false,
'shortner_credentials' => array(),
'image' => false,
'utm_campaign_medium' => 'social',
'utm_campaign_name' => 'ReviveOldPost',
'share_link_in_comment' => false,
'share_link_text' => '',
),
'twitter' => array(
'wpml_language' => '',
Expand Down
29 changes: 29 additions & 0 deletions includes/admin/services/class-rop-facebook-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ public function share( $post_details, $args = array() ) {
$share_as_image_post = $post_details['post_with_image'];
$global_settings = new Rop_Global_Settings();

$share_link_text = '';
if ( ! empty( $post_format['share_link_in_comment'] ) && ! empty( $post_format['share_link_text'] ) ) {
$share_link_text = str_replace( '{link}', $post_url, $post_format['share_link_text'] );
}

if ( array_key_exists( 'account_type', $args ) ) {

if ( ( $args['account_type'] === 'instagram_account' || $args['account_type'] === 'facebook_group' ) && $global_settings->license_type() < 1 ) {
Expand Down Expand Up @@ -534,6 +539,8 @@ public function share( $post_details, $args = array() ) {
return false;
}

$sharing_data['post_data']['share_link_text'] = $share_link_text;

if ( $this->try_post( $sharing_data['post_data'], $args['id'], $args['access_token'], $post_id, $sharing_data['type'] ) ) {
$this->logger->alert_success(
sprintf(
Expand Down Expand Up @@ -694,6 +701,20 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type
$this->set_api( $this->credentials['app_id'], $this->credentials['secret'] );
}

if ( ! class_exists( 'ROP_Pro_Facebook_Helper' ) ) {
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );

if ( is_plugin_active( 'tweet-old-post-pro/tweet-old-post-pro.php' ) ) {
require_once ROP_PRO_PATH . 'includes/helpers/class-rop-pro-facebook-helper.php';
}
}

$share_link_text = '';
if ( isset( $new_post['share_link_text'] ) ) {
$share_link_text = $new_post['share_link_text'];
unset( $new_post['share_link_text'] );
}

if ( $this->get_api() && empty( $installed_with_app ) ) {
// Page was added using user application (old method)
// Try post via Facebook Graph SDK
Expand Down Expand Up @@ -819,6 +840,14 @@ private function try_post( $new_post, $page_id, $token, $post_id, $posting_type
}

if ( ! empty( $body['id'] ) ) {
$fb_helper = new ROP_Pro_Facebook_Helper();
$fb_helper->share_as_first_comment(
$body['id'],
array(
'message' => $share_link_text,
'access_token' => $token,
)
);
return true;
} elseif ( ! empty( $body['error']['message'] ) ) {
if (
Expand Down
6 changes: 6 additions & 0 deletions includes/class-rop-i18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ public static function get_labels( $key = '' ) {
'custom_meta_field_upsell' => __( 'Custom meta fields are only available in the Pro version.', 'tweet-old-post' ),
'custom_meta_upsell' => __( 'Custom fields are only available in the Pro version.', 'tweet-old-post' ),
'hashtag_field_upsell' => __( 'The selected option is only available in the Pro version.', 'tweet-old-post' ),
'first_comment_title' => __( 'Comment Text', 'tweet-old-post' ),
'first_comment_desc' => __( 'Should Revive Social add the post link in the first comment when sharing a post?', 'tweet-old-post' ),
'first_comment_placeholder' => __( 'Read more on {link}', 'tweet-old-post' ),
'share_link_title' => __( 'Share link', 'tweet-old-post' ),
'share_link_desc' => __( 'Share the post link in the first comment?', 'tweet-old-post' ),
'share_link_upsell' => __( 'Share first comment is only available in the Pro version.', 'tweet-old-post' ),
),
'schedule' => array(
'menu_item' => __( 'Custom Schedule', 'tweet-old-post' ),
Expand Down
69 changes: 69 additions & 0 deletions vue/src/vue-elements/post-format.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,75 @@
/>
</div>
</div>

<span
v-if="post_format.include_link"
class="divider"
/>
<div
v-if="post_format.include_link"
class="columns py-2"
:class="'rop-control-container-'+isPro"
>
<div class="column col-6 col-sm-12 vertical-align rop-control">
<b>{{ labels.share_link_title }}</b>
<p class="text-gray">
{{ labels.share_link_desc }}
</p>
</div>
<div class="column col-6 col-sm-12 vertical-align rop-control">
<div class="input-group">
<label class="form-checkbox">
<input
v-model="post_format.share_link_in_comment"
type="checkbox"
:disabled="!isPro"
>
<i class="form-icon" /> {{ labels.yes_text }}
</label>
</div>
</div>
</div>

<div
v-if="!isPro && post_format.include_link"
class="columns "
>
<div class="column text-center">
<p class="upsell">
<i class="fa fa-info-circle" /> {{ labels.share_link_upsell }}
</p>
</div>
</div>

<span
v-if="isPro && ( post_format.include_link && post_format.share_link_in_comment )"
class="divider"
/>
<!-- Share First Comment -->
<div
v-if="isPro && ( post_format.include_link && post_format.share_link_in_comment )"
class="columns py-2"
:class="'rop-control-container-'+isPro"
>
<div class="column col-6 col-sm-12 vertical-align rop-control">
<b>{{ labels.first_comment_title }}</b>
<p class="text-gray">
<span v-html="labels.first_comment_desc" />
</p>
</div>
<div class="column col-6 col-sm-12 vertical-align rop-control">
<div class="form-group">
<textarea
v-model="post_format.share_link_text"
class="form-input"
:placeholder="labels.first_comment_placeholder"
:disabled="!isPro"
/>
</div>
</div>
</div>

<span class="divider" />
<div
class="columns py-2"
Expand Down

0 comments on commit b731175

Please sign in to comment.