From 4ab8b5764310290f7aec697782d8d5070fb72b1c Mon Sep 17 00:00:00 2001 From: girishpanchal30 Date: Wed, 8 Jan 2025 14:17:16 +0530 Subject: [PATCH 1/4] feat: add facebook share link in first comment --- .../abstract/class-rop-services-abstract.php | 10 +++ includes/admin/class-rop-global-settings.php | 42 +++++------ .../services/class-rop-facebook-service.php | 29 ++++++++ includes/class-rop-i18n.php | 6 ++ vue/src/vue-elements/post-format.vue | 69 +++++++++++++++++++ 5 files changed, 136 insertions(+), 20 deletions(-) diff --git a/includes/admin/abstract/class-rop-services-abstract.php b/includes/admin/abstract/class-rop-services-abstract.php index b29e1149..57b0f530 100644 --- a/includes/admin/abstract/class-rop-services-abstract.php +++ b/includes/admin/abstract/class-rop-services-abstract.php @@ -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. * diff --git a/includes/admin/class-rop-global-settings.php b/includes/admin/class-rop-global-settings.php index 8e4ea47d..c028d060 100644 --- a/includes/admin/class-rop-global-settings.php +++ b/includes/admin/class-rop-global-settings.php @@ -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' => '', diff --git a/includes/admin/services/class-rop-facebook-service.php b/includes/admin/services/class-rop-facebook-service.php index b06f4019..267f9b35 100644 --- a/includes/admin/services/class-rop-facebook-service.php +++ b/includes/admin/services/class-rop-facebook-service.php @@ -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 ) { @@ -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( @@ -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 @@ -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 ( diff --git a/includes/class-rop-i18n.php b/includes/class-rop-i18n.php index f87e0563..75106505 100644 --- a/includes/class-rop-i18n.php +++ b/includes/class-rop-i18n.php @@ -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' ), diff --git a/vue/src/vue-elements/post-format.vue b/vue/src/vue-elements/post-format.vue index 42e29044..cea07752 100644 --- a/vue/src/vue-elements/post-format.vue +++ b/vue/src/vue-elements/post-format.vue @@ -283,6 +283,75 @@ /> + + +
+
+ {{ labels.share_link_title }} +

+ {{ labels.share_link_desc }} +

+
+
+
+ +
+
+
+ +
+
+

+ {{ labels.share_link_upsell }} +

+
+
+ + + +
+
+ {{ labels.first_comment_title }} +

+ +

+
+
+
+