Skip to content

Commit

Permalink
Merge pull request #1025 from Codeinwp/feat/pro/564
Browse files Browse the repository at this point in the history
Save post sharing logs to ROP API
  • Loading branch information
vytisbulkevicius authored Feb 6, 2025
2 parents 31a1b1a + 897205f commit 2826ccf
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 0 deletions.
45 changes: 45 additions & 0 deletions includes/admin/abstract/class-rop-services-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,4 +922,49 @@ function( $d ) {
return $valid;
}

/**
* Capture logs on ROP API.
*
* @since 9.1.3
* @access public
*
* @param array $data API payload data.
* @return bool
*/
public function save_logs_on_rop( $data = array() ) {
if ( empty( $data ) ) {
return false;
}

$license_key = apply_filters( 'product_rop_license_key', '' );
$license_status = apply_filters( 'product_rop_license_status', 'invalid' );

// Send API request.
$response = wp_remote_post(
ROP_POST_LOGS_API,
apply_filters(
'rop_post_capture_logs_api_args',
array(
'timeout' => 100,
'body' => array_merge(
array(
'website' => get_site_url(),
'license' => $license_key,
'license_status' => $license_status,
),
$data
),
)
)
);

if ( is_wp_error( $response ) ) {
return false;
}

$body = json_decode( wp_remote_retrieve_body( $response ) );
$response_code = wp_remote_retrieve_response_code( $response );
return 200 === $response_code ? $body->status : false;
}

}
21 changes: 21 additions & 0 deletions includes/admin/services/class-rop-facebook-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,17 @@ public function share( $post_details, $args = array() ) {

$response = Rop_Pro_Instagram_Service::share( $post_details, $hashtags, $args );

if ( $response ) {
// Save log.
$this->save_logs_on_rop(
array(
'network' => $post_details['service'],
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);
}
return $response;

}
Expand Down Expand Up @@ -540,6 +551,16 @@ public function share( $post_details, $args = array() ) {
}

if ( $this->try_post( $sharing_data['post_data'], $args['id'], $args['access_token'], $post_id, $sharing_data['type'] ) ) {
// Save log.
$this->save_logs_on_rop(
array(
'network' => $post_details['service'],
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);

$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on %s ',
Expand Down
9 changes: 9 additions & 0 deletions includes/admin/services/class-rop-gmb-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,15 @@ public function share( $post_details, $args = array() ) {

if ( in_array( $response->state, array( 'LIVE', 'PROCESSING' ), true ) ) {

// Save log.
$this->save_logs_on_rop(
array(
'network' => $post_details['service'],
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);
$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on Google My Business ',
Expand Down
11 changes: 11 additions & 0 deletions includes/admin/services/class-rop-linkedin-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,17 @@ public function share( $post_details, $args = array() ) {
}

$title = isset( $new_post['content']['media']['title'] ) ? $new_post['content']['media']['title'] : $new_post['content']['article']['title'];

// Save log.
$this->save_logs_on_rop(
array(
'network' => $post_details['service'],
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);

$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on %s ',
Expand Down
10 changes: 10 additions & 0 deletions includes/admin/services/class-rop-tumblr-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,16 @@ public function share( $post_details, $args = array() ) {

$api->createPost( $args['id'] . '.tumblr.com', $new_post );

// Save log.
$this->save_logs_on_rop(
array(
'network' => $post_details['service'],
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);

$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on %s ',
Expand Down
12 changes: 12 additions & 0 deletions includes/admin/services/class-rop-twitter-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ public function share( $post_details, $args = array() ) {
}

if ( isset( $response['data'] ) && ! empty( $response['data']['id'] ) ) {

if ( $api && ! empty( $this->share_link_text ) ) {
// Post the first comment (replying to the tweet).
$comment = $api->post(
Expand All @@ -764,6 +765,17 @@ public function share( $post_details, $args = array() ) {
);
}
}

// Save log.
$this->save_logs_on_rop(
array(
'network' => $post_details['service'],
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);

$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on %s ',
Expand Down
11 changes: 11 additions & 0 deletions includes/admin/services/class-rop-vk-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ public function share( $post_details, $args = array() ) {
);

if ( ! empty( $response['post_id'] ) ) {

// Create the first comment if the share link text is not empty.
if ( ! empty( $this->share_link_text ) ) {
$create_comment = $client->wall()->createComment(
Expand All @@ -520,6 +521,16 @@ public function share( $post_details, $args = array() ) {
}
}

// Save log.
$this->save_logs_on_rop(
array(
'network' => 'Vkontakte',
'handle' => $args['user'],
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);

$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on Vkontakte ',
Expand Down
10 changes: 10 additions & 0 deletions includes/admin/services/class-rop-webhook-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ function( $header ) {
$this->logger->alert_error( $log_account_used . Rop_I18n::get_labels( 'errors.webhook_error' ) . $response->get_error_message() );
return false;
} elseif ( true === $response ) {
// Save log.
$this->save_logs_on_rop(
array(
'network' => $this->service_name,
'handle' => $this->display_name,
'content' => $post_details['content'],
'link' => $post_details['post_url'],
)
);

$this->logger->alert_success(
sprintf(
'Successfully shared %s to %s on %s ',
Expand Down
1 change: 1 addition & 0 deletions tweet-old-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function run_rop() {
define( 'ROP_INSTALL_TOKEN_OPTION', 'rop_install_token' );
define( 'ROP_POST_SHARING_CONTROL_API', ROP_AUTH_APP_URL . '/wp-json/auth-option/v1/post-sharing-control' );
define( 'ROP_POST_ON_X_API', ROP_AUTH_APP_URL . '/wp-json/auth-option/v1/post-on-x' );
define( 'ROP_POST_LOGS_API', ROP_AUTH_APP_URL . '/wp-json/auth-option/v1/logs' );

add_filter(
'themeisle_sdk_compatibilities/' . basename( ROP_LITE_PATH ),
Expand Down

0 comments on commit 2826ccf

Please sign in to comment.