protected static function get_client() { require_once __DIR__ . '/aws.phar'; $settings = ASNS_Settings::get_settings(); $args = array('credentials' => array('key' => $settings['amazon_key'], 'secret' => $settings['amazon_secret']), 'region' => $settings['amazon_region'], 'version' => '2010-03-31'); return (new Aws\Sdk($args))->createSNS(); }
public static function register_device() { self::validate_settings(ASNS_Settings::get_settings()); $topic_arn = self::get_topic()[1]; $app = self::get_app(); $token = self::get_request_param('token'); if (!$token) { return self::send_ajax_response('Device token not found', false, false); } // Register device with WP $device_id = ASNS_Device::create($app[0], $token); // Register device with Amazon $client = self::get_client(); try { $device_arn = $client->createPlatformEndpoint(['PlatformApplicationArn' => $app[1], 'Token' => $token])->get('EndpointArn'); // Update device ARN ASNS_Device::set_arn($device_id, $device_arn); // Subscribe device to topic $client->subscribe(['Endpoint' => $device_arn, 'TopicArn' => $topic_arn, 'Protocol' => 'application']); } catch (Aws\Sns\Exception\SnsException $ex) { $message = $ex->getStatusCode() . ' / ' . $ex->getAwsErrorCode() . ' / ' . $ex->getMessage(); self::send_ajax_response($message, false, false); } self::send_ajax_response('ok', true, false); }
public static function get_modal() { $topics = ASNS_Settings::get_settings()['topic_keys']; $topic_options = ''; if ($topics) { $topic_options = '<option value="">Choose a topic</option>'; foreach ($topics as $topic) { $topic_options .= '<option value="' . $topic . '">' . $topic . '</option>'; } } else { $topic_options = '<option value="">No topics defined!</option>'; } $search = array('<!--ASNS_TOPICS-->', '<!--ASNS_LOADER-->'); $replace = array($topic_options, plugins_url('/../img/ajax-loader.gif', __FILE__)); echo str_replace($search, $replace, file_get_contents(__DIR__ . '/modal.html')); wp_die(); }
<?php $settings = ASNS_Settings::get_settings(); ?> <div class="wrap"> <h2>Amazon SNS Settings</h2> <form action='options.php' method='post'> <?php settings_fields('asns'); ?> <table class="form-table"> <tbody> <tr> <th scope="row"> <label for="amazon_key">Amazon Key</label> </th> <td> <input type="text" class="regular-text" value="<?php echo $settings['amazon_key']; ?> " id="amazon_key" name="asns_settings[amazon_key]" /> </td>