Skip to content

Commit

Permalink
Merge branch 'development' into fix/license-field
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Jul 12, 2024
2 parents 85d4b78 + fb30c51 commit f19af03
Show file tree
Hide file tree
Showing 19 changed files with 1,143 additions and 86 deletions.
38 changes: 36 additions & 2 deletions assets/css/rop_core.css
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,33 @@ a.active {
border-left-color: #fff;
}

#rop_core .btn.btn-webhook {
border-color: #0071a6;
color: #fff;
background: #FFBC42;
}

#rop_core .btn.btn-webhook:focus {
box-shadow: 0 0 0 0.1rem rgba(0, 123, 181, 0.2);
}

#rop_core .btn.btn-webhook:is( :focus, :hover ) {
border-color: #006a9c;
color: #fff;
background: #0074ab;
}

#rop_core .btn.btn-webhook:is( :active, .active ) {
border-color: #005882;
color: #fff;
background: #006391;
}

#rop_core .btn.btn-webhook.loading::after {
border-bottom-color: #fff;
border-left-color: #fff;
}

#rop_core .btn.btn-sm {
height: 1.2rem;
padding: 0.05rem 0.3rem;
Expand Down Expand Up @@ -2849,14 +2876,17 @@ a.active {
cursor: default;
}

#rop_core .modal:target .modal-container,
#rop_core .modal.active .modal-container {
#rop_core :is( .modal:target, .modal.active ) .modal-container {
z-index: 99999;
max-width: 640px;
-webkit-animation: slide-down 0.2s ease 1;
animation: slide-down 0.2s ease 1;
}

#rop_core :is( .modal:target, .modal.active ) .modal-container:has(.webhook-headers) {
max-width: 960px;
}

#rop_core .modal.modal-sm .modal-container {
max-width: 320px;
}
Expand Down Expand Up @@ -4168,6 +4198,10 @@ a.active {
background-color: #bd081c;
}

.icon_box.webhook {
background-color: #FFBC42;;
}

#rop_core .avatar .avatar-icon {
border-radius: 50%;
background: #333;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/build/dashboard.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions includes/admin/class-rop-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1269,8 +1269,8 @@ public function check_cron_status() {
* @access public
*/
public function rop_wp_cron_notice() {
//TODO - we need to rework this as the constant is not saying that cron is not working only that the default scheduling is, the user can still use server cron instead.
return;
// TODO - we need to rework this as the constant is not saying that cron is not working only that the default scheduling is, the user can still use server cron instead.
return;
if ( ! defined( 'DISABLE_WP_CRON' ) ) {
return;
}
Expand Down
27 changes: 27 additions & 0 deletions includes/admin/class-rop-global-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ class Rop_Global_Settings {
'active' => false,
'name' => 'Vk',
),
'webhook' => array(
'active' => false,
'name' => 'Webhook',
'two_step_sign_in' => true,
),
);

/**
Expand Down Expand Up @@ -327,6 +332,28 @@ class Rop_Global_Settings {
'utm_campaign_medium' => 'social',
'utm_campaign_name' => 'ReviveOldPost',
),
'webhook' => 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' => 'is.gd',
'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',
),
);

/**
Expand Down
119 changes: 117 additions & 2 deletions includes/admin/class-rop-rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,21 @@ private function save_post_format( $data ) {
}
}

// New users will require a pro plan.
$global_settings = new Rop_Global_Settings();
$is_new_user = (int) get_option( 'rop_is_new_user', 0 );
if ( $global_settings->license_type() <= 0 && $is_new_user ) {
if ( 'custom_field' === $data['data']['post_content'] ) {
$data['data']['post_content'] = 'post_title';
}
if ( ! in_array( $data['data']['hashtags'], array( 'no-hashtags', 'common-hashtags' ), true ) ) {
$data['data']['hashtags'] = 'no-hashtags';
}
if ( ! in_array( $data['data']['short_url_service'], array( 'rviv.ly', 'wp_short_url' ), true ) ) {
$data['data']['short_url_service'] = 'rviv.ly';
}
}

try {
if ( $data['data']['short_url_service'] !== 'wp_short_url' ) {
$shortner = $sh_factory->build( $data['data']['short_url_service'] );
Expand Down Expand Up @@ -896,8 +911,11 @@ function ( $value ) {
}
}
if ( ${$data['service'] . '_services'} ) {
/* @noinspection PhpUndefinedMethodInspection */
$url = ${$data['service'] . '_services'}->sign_in_url( $data );
if ( method_exists( ${$data['service'] . '_services'}, 'sign_in_url' ) ) {
$url = ${$data['service'] . '_services'}->sign_in_url( $data );
} else {
$url = '';
}
}
} catch ( Exception $exception ) {
// Service can't be built. Not found or otherwise. Maybe log this.
Expand Down Expand Up @@ -1365,4 +1383,101 @@ private function set_license( $data ) {
->set_data( array( 'success' => true ) )
->to_array();
}

/**
* API method called to add Webhook account.
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
*
* @since 9.1.0
* @access private
*
* @param array $data Webhook account data.
*
* @return array
*/
private function add_account_webhook( $data ) {
$services = array();
$webhook_service = new Rop_Webhook_Service();
$model = new Rop_Services_Model();
$db = new Rop_Db_Upgrade();

if ( ! $webhook_service->add_webhook( $data ) ) {
$this->response->set_code( '422' )
->set_data( array() );

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

$services[ $webhook_service->get_service_id() ] = $webhook_service->get_service();
$active_accounts = $webhook_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();
}

/**
* API method called to edit Webhook account.
*
* @SuppressWarnings(PHPMD.UnusedPrivateMethod) As it is called dynamically.
*
* @since 9.1.0
* @access private
*
* @param array $data Webhook account data.
*
* @return array
*/
private function edit_account_webhook( $data ) {
$webhook_service = new Rop_Webhook_Service();
$model = new Rop_Services_Model();

if ( ! $webhook_service->add_webhook( $data ) ) {
$this->response->set_code( '422' )
->set_data( array() );

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

$service_id = ! empty( $data['service_id'] ) ? $data['service_id'] : '';
$authenticated_services = $model->get_authenticated_services();

if ( ! isset( $authenticated_services[ $service_id ] ) ) {
$this->response->set_code( '422' )
->set_data( array() );

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

$authenticated_services[ $service_id ] = array_merge( $authenticated_services[ $service_id ], $webhook_service->get_service() );

$model->update_authenticated_services( $authenticated_services );

if ( ! empty( $data['active'] ) && ! empty( $data['full_id'] ) ) {
$model->add_active_accounts( array( $data['full_id'] ) );
}

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

return $this->response->to_array();
}
}
2 changes: 1 addition & 1 deletion includes/admin/models/class-rop-scheduler-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function ( $value ) use ( &$prev ) {
* @since 8.0.0
* @access public
*/
public function generate_upcoming_events( $base = 0, $account_id, $limit = 0 ) {
public function generate_upcoming_events( $base = 0, $account_id = null, $limit = 0 ) {

$schedule = $this->get_schedule( $account_id );
if ( empty( $schedule ) ) {
Expand Down
Loading

0 comments on commit f19af03

Please sign in to comment.