Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added mastodon network service #1029

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/css/rop_core.css
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,13 @@ a.active {
color:#fff;
}

#rop_core .btn.btn-mastodon{
background-color:#6364FF;
color:#fff;
display: flex;
align-items: center;
}

#rop_core
.btn:is(
.btn-facebook,
Expand All @@ -848,6 +855,7 @@ a.active {
.btn-gmb,
.btn-vk,
.btn-webhook
.btn-mastodon
):is(
:focus,
:hover
Expand Down
4 changes: 2 additions & 2 deletions includes/admin/abstract/class-rop-services-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ protected function is_valid_serialize_data( $data ) {
$data = array_map(
function( $d ) {
$d = base64_decode( $d, true );
$d = unserialize( $d, array( 'allowed_classes' => false ) );
$d = maybe_unserialize( $d, array( 'allowed_classes' => false ) );
if ( $d instanceof \__PHP_Incomplete_Class ) {
return false;
}
Expand All @@ -914,7 +914,7 @@ function( $d ) {
$valid = empty( $data ) ? false : true;
} else {
$data = base64_decode( $data, true );
$data = unserialize( $data, array( 'allowed_classes' => false ) );
$data = maybe_unserialize( $data, array( 'allowed_classes' => false ) );
if ( $data instanceof \__PHP_Incomplete_Class ) {
$valid = false;
}
Expand Down
10 changes: 10 additions & 0 deletions includes/admin/class-rop-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,12 @@ public function legacy_auth() {
return;
}

/**
* For mastodon code/state params.
*/
if ( ( empty( $oauth_token ) || empty( $oauth_verifier ) ) && $state === 'mastodon' ) {
$network = $state;
}
switch ( $network ) {
case 'linkedin':
$lk_service = new Rop_Linkedin_Service();
Expand All @@ -555,6 +561,10 @@ public function legacy_auth() {
$pinterest_service = new Rop_Pinterest_Service();
$pinterest_service->authorize();
break;
case 'mastodon':
$mastodon_service = new Rop_Mastodon_Service();
$mastodon_service->authorize();
break;
default:
$fb_service = new Rop_Facebook_Service();
$fb_service->authorize();
Expand Down
29 changes: 28 additions & 1 deletion includes/admin/class-rop-global-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ class Rop_Global_Settings {
'name' => 'Webhook',
'two_step_sign_in' => true,
),
'mastodon' => array(
'active' => false,
'name' => 'Mastodon',
'two_step_sign_in' => true,
),
);

/**
Expand Down Expand Up @@ -356,6 +361,28 @@ class Rop_Global_Settings {
'utm_campaign_medium' => 'social',
'utm_campaign_name' => 'ReviveOldPost',
),
'mastodon' => array(
'wpml_language' => '',
'post_content' => 'post_title',
'custom_meta_field' => '',
'maximum_length' => '1000',
'custom_text' => '',
'shortner_credentials' => array(),
'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,
'image' => false,
'utm_campaign_medium' => 'social',
'utm_campaign_name' => 'ReviveOldPost',
),
);

/**
Expand Down Expand Up @@ -652,7 +679,7 @@ function ( $value ) {
* $service['two_step_sign_in'] = false; For Twitter, this prevent the modal to open up
* Even if the modal displays, the variable $available_services[ $key ] will prevent the form to show up.
*/
if ( 'twitter' !== $key && 'tumblr' !== $key ) {
if ( 'twitter' !== $key && 'tumblr' !== $key && 'mastodon' !== $key ) {
$service['two_step_sign_in'] = false;
$available_services[ $key ] = $service;
}
Expand Down
45 changes: 45 additions & 0 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1485,4 +1485,49 @@ private function edit_account_webhook( $data ) {

return $this->response->to_array();
}

/**
* API method called to add mastodon via app.
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
*
* @since 8.6.1
* @access private
*
* @param array $data Mastodon accounts data.
*
* @return array
*/
private function add_account_mastodon( $data ) {
$services = array();
$active_accounts = array();
$md_service = new Rop_Mastodon_Service();
$model = new Rop_Services_Model();
$db = new Rop_Db_Upgrade();

$md_service->add_account_with_app( $data );

$services[ $md_service->get_service_id() ] = $md_service->get_service();
$active_accounts = array_merge( $active_accounts, $md_service->get_service_active_accounts() );

if ( ! empty( $services ) ) {
$model->add_authenticated_service( $services );
}

if ( ! empty( $active_accounts ) ) {
$db->migrate_schedule( $active_accounts );
$db->migrate_post_formats( $active_accounts );
} else {
$this->response->set_code( '500' )
->set_data( array() );

return $this->response->to_array();
}

$this->response->set_code( '200' )
->set_message( 'OK' )
->set_data( array() );

return $this->response->to_array();
}
}
Loading
Loading