Services
1 month ago
AuthRoutine.php
1 month ago
CronUpdaterManager.php
1 month ago
ErrorReport.php
1 month ago
Request.php
1 month ago
SettingsFilter.php
1 month ago
SinglePostCache.php
1 month ago
TweetAggregator.php
1 month ago
TweetFilterer.php
1 month ago
TweetRepository.php
1 month ago
TweetSetModifier.php
1 month ago
AuthRoutine.php
71 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class Request |
| 4 | * |
| 5 | * Performs a request to the Smash Balloon Twitter API. |
| 6 | * |
| 7 | * @since 2.1 |
| 8 | */ |
| 9 | namespace TwitterFeed\SmashTwitter; |
| 10 | |
| 11 | class AuthRoutine |
| 12 | { |
| 13 | |
| 14 | public function __construct() |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | public function run_register() |
| 19 | { |
| 20 | $auth_required = false; |
| 21 | $data = array( |
| 22 | 'url' => get_home_url() |
| 23 | ); |
| 24 | |
| 25 | $args = array( |
| 26 | 'body' => json_encode($data), |
| 27 | 'timeout' => 60 |
| 28 | ); |
| 29 | |
| 30 | $request = new Request( 'register', '', $args, $auth_required ); |
| 31 | |
| 32 | $return = $request->fetch(); |
| 33 | |
| 34 | $ctf_options = get_option( 'ctf_options', array() ); |
| 35 | |
| 36 | $ctf_options[ CTF_SITE_ACCESS_TOKEN_KEY ] = false; |
| 37 | |
| 38 | if ( ! empty( $return['token'] ) ) { |
| 39 | $ctf_options[ CTF_SITE_ACCESS_TOKEN_KEY ] = $return['token']; |
| 40 | } |
| 41 | |
| 42 | // Failsafe if user is already registered. |
| 43 | if ( ! empty( $return['data']['token'] ) ) { |
| 44 | $ctf_options[ CTF_SITE_ACCESS_TOKEN_KEY ] = $return['data']['token']; |
| 45 | } |
| 46 | update_option( 'ctf_options', $ctf_options ); |
| 47 | |
| 48 | return $ctf_options[ CTF_SITE_ACCESS_TOKEN_KEY ]; |
| 49 | } |
| 50 | |
| 51 | public function run_license_activation( $auth_token ) |
| 52 | { |
| 53 | $ctf_license_key = get_option( 'ctf_license_key', '' ); |
| 54 | |
| 55 | $data = array( |
| 56 | 'url' => get_home_url(), |
| 57 | 'license_key' => $ctf_license_key, |
| 58 | 'action' => 'activate' |
| 59 | ); |
| 60 | |
| 61 | $args = array( |
| 62 | 'body' => json_encode($data), |
| 63 | 'timeout' => 60 |
| 64 | ); |
| 65 | |
| 66 | $request = new Request( 'license', '', $args, $auth_token ); |
| 67 | |
| 68 | $return = $request->fetch(); |
| 69 | return $return; |
| 70 | } |
| 71 | } |