| Server IP : 43.141.49.107 / Your IP : 113.219.202.141 Web Server : Apache System : Linux VM-8-5-opencloudos 6.6.34-9.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 19 19:35:45 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.1.27 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/www.ucppt.com/wp-content/plugins/easy-wp-smtp/src/Providers/ |
Upload File : |
<?php
namespace EasyWPSMTP\Providers;
use EasyWPSMTP\ConnectionInterface;
use EasyWPSMTP\Options;
/**
* Class AuthAbstract.
*
* @since 2.1.0
*/
abstract class AuthAbstract implements AuthInterface {
/**
* The Connection object.
*
* @since 2.1.0
*
* @var ConnectionInterface
*/
protected $connection;
/**
* The connection options object.
*
* @since 2.1.0
*
* @var Options
*/
protected $connection_options;
/**
* Mailer DB options.
*
* @since 2.1.0
*
* @var array
*/
protected $options = [];
/**
* @since 2.1.0
*
* @var mixed
*/
protected $client;
/**
* Mailer slug.
*
* @since 2.1.0
*
* @var string
*/
protected $mailer_slug = '';
/**
* Key for a stored unique state value.
*
* @since 2.1.0
*
* @var string
*/
public $state_key = 'easy_wp_smtp_provider_client_state';
/**
* Auth constructor.
*
* @since 2.1.0
*
* @param ConnectionInterface $connection The Connection object.
*/
public function __construct( $connection = null ) {
if ( ! is_null( $connection ) ) {
$this->connection = $connection;
} else {
$this->connection = easy_wp_smtp()->get_connections_manager()->get_primary_connection();
}
$this->connection_options = $this->connection->get_options();
$this->mailer_slug = $this->connection->get_mailer_slug();
}
/**
* Use the composer autoloader to include the auth library and all dependencies.
*
* @since 2.1.0
*/
protected function include_vendor_lib() {
require_once easy_wp_smtp()->plugin_path . '/vendor/autoload.php';
}
/**
* Get the url, that users will be redirected back to finish the OAuth process.
*
* @since 2.1.0
*
* @return string
*/
public static function get_plugin_auth_url() {
return add_query_arg( 'tab', 'auth', easy_wp_smtp()->get_admin()->get_admin_page_url() );
}
/**
* Update auth code in our DB.
*
* @since 2.1.0
*
* @param string $code
*/
protected function update_auth_code( $code ) {
$all = $this->connection_options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['auth_code'] = $code;
// To save in currently retrieved options array.
$this->options['auth_code'] = $code;
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
$this->connection_options->set( $all, false, true );
}
/**
* Update Setup Wizard flag in our DB.
*
* @since 2.1.0
*
* @param boolean $state A state (true/false) to set the is_setup_wizard_auth mailer setting.
*/
public function update_is_setup_wizard_auth( $state ) {
$all = $this->connection_options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['is_setup_wizard_auth'] = (bool) $state;
// To save in currently retrieved options array.
$this->options['is_setup_wizard_auth'] = (bool) $state;
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
$this->connection_options->set( $all, false, true );
}
/**
* Update access token in our DB.
*
* @since 2.1.0
*
* @param mixed $token
*/
protected function update_access_token( $token ) {
$all = $this->connection_options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['access_token'] = $token;
// To save in currently retrieved options array.
$this->options['access_token'] = $token;
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
$this->connection_options->set( $all, false, true );
}
/**
* Update refresh token in our DB.
*
* @since 2.1.0
*
* @param mixed $token
*/
protected function update_refresh_token( $token ) {
$all = $this->connection_options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['refresh_token'] = $token;
// To save in currently retrieved options array.
$this->options['refresh_token'] = $token;
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
$this->connection_options->set( $all, false, true );
}
/**
* Update access token scopes in our DB.
*
* @since 2.1.0
*
* @param array $scopes Scopes array.
*/
protected function update_scopes( $scopes ) {
$all = $this->connection_options->get_all();
// To save in DB.
$all[ $this->mailer_slug ]['scopes'] = $scopes;
// To save in currently retrieved options array.
$this->options['scopes'] = $scopes;
// NOTE: These options need to be saved by overwriting all options, because WP automatic updates can cause an issue: GH #575!
$this->connection_options->set( $all, false, true );
}
/**
* Get state value that should be used for `state` parameter in OAuth authorization request.
*
* @since 2.1.0
*
* @return string
*/
protected function get_state() {
$state = [
wp_create_nonce( $this->state_key ),
$this->connection->get_id(),
];
return implode( '-', $state );
}
/**
* @inheritdoc
*/
public function is_clients_saved() {
return ! empty( $this->options['client_id'] ) && ! empty( $this->options['client_secret'] );
}
/**
* @inheritdoc
*/
public function is_auth_required() {
return empty( $this->options['access_token'] ) || empty( $this->options['refresh_token'] );
}
}