コード例 #1
0
ファイル: mailjet-options.php プロジェクト: sebfabiani/vcv
 /**
  * Save the Mailjet's plugin settings when we click "Save options" button
  *
  * @param void
  * @return void
  */
 public function save_settings()
 {
     // Get the variables which we'll save
     $fields['mailjet_enabled'] = isset($_POST['mailjet_enabled']) ? 1 : 0;
     $fields['mailjet_test'] = isset($_POST['mailjet_test']) ? 1 : 0;
     $fields['mailjet_ssl'] = isset($_POST['mailjet_ssl']) ? 'ssl' : '';
     $fields['mailjet_test_address'] = strip_tags(filter_var($_POST['mailjet_test_address'], FILTER_VALIDATE_EMAIL));
     $fields['mailjet_from_email'] = strip_tags(filter_var($_POST['mailjet_from_email'], FILTER_VALIDATE_EMAIL));
     $fields['mailjet_username'] = trim(strip_tags(filter_var($_POST['mailjet_username'], FILTER_SANITIZE_STRING)));
     $fields['mailjet_password'] = trim(strip_tags(filter_var($_POST['mailjet_password'], FILTER_SANITIZE_STRING)));
     $fields['mailjet_port'] = strip_tags(filter_var($_POST['mailjet_port'], FILTER_SANITIZE_NUMBER_INT));
     $fields['mailjet_auto_subscribe_list_id'] = $fields['mailjet_username'] != get_option('mailjet_username') || $fields['mailjet_password'] != get_option('mailjet_password') ? false : strip_tags(filter_var($_POST['mailjet_auto_subscribe_list_id'], FILTER_SANITIZE_NUMBER_INT));
     if (current_user_can('administrator')) {
         $fields['mailjet_access_editor'] = isset($_POST['mailjet_access_editor']) ? 1 : 0;
         $fields['mailjet_access_author'] = isset($_POST['mailjet_access_author']) ? 1 : 0;
         $fields['mailjet_access_contributor'] = isset($_POST['mailjet_access_contributor']) ? 1 : 0;
         $fields['mailjet_access_subscriber'] = isset($_POST['mailjet_access_subscriber']) ? 1 : 0;
     }
     // Set error messages if we've any
     $errors = array();
     if ($fields['mailjet_test'] && empty($fields['mailjet_test_address'])) {
         $errors[] = 'mailjet_test_address';
     }
     if (!empty($fields['mailjet_test_address'])) {
         if (!filter_var($fields['mailjet_test_address'], FILTER_VALIDATE_EMAIL)) {
             $errors[] = 'mailjet_test_address';
         }
     }
     if (empty($fields['mailjet_username'])) {
         $errors[] = 'mailjet_username';
     }
     if (empty($fields['mailjet_password'])) {
         $errors[] = 'mailjet_password';
     }
     // If there are no errors, then update the new settings
     if (!count($errors)) {
         if ($fields['mailjet_ssl'] == 'ssl') {
             $fields['mailjet_port'] = 465;
         }
         // Update the new settings
         update_option('mailjet_enabled', $fields['mailjet_enabled']);
         update_option('mailjet_token' . $_SERVER['REMOTE_ADDR'], json_encode(array('timestamp' => 0)));
         update_option('mailjet_test', $fields['mailjet_test']);
         update_option('mailjet_test_address', $fields['mailjet_test_address']);
         update_option('mailjet_from_email', $fields['mailjet_from_email']);
         update_option('mailjet_username', $fields['mailjet_username']);
         update_option('mailjet_password', $fields['mailjet_password']);
         update_option('mailjet_ssl', $fields['mailjet_ssl']);
         update_option('mailjet_port', $fields['mailjet_port']);
         update_option('mailjet_auto_subscribe_list_id', $fields['mailjet_auto_subscribe_list_id']);
         if (current_user_can('administrator')) {
             update_option('mailjet_access_editor', $fields['mailjet_access_editor']);
             update_option('mailjet_access_author', $fields['mailjet_access_author']);
             update_option('mailjet_access_contributor', $fields['mailjet_access_contributor']);
             update_option('mailjet_access_subscriber', $fields['mailjet_access_subscriber']);
         }
         // Extablish API connection because we will need it to check if the API Key and Secrect Key are correct
         $this->api = new WP_Mailjet_Api(get_option('mailjet_username'), get_option('mailjet_password'));
         // Check if there is a connection with the Mailjet's server
         $configs = array(array('', 25), array('tls', 25), array('ssl', 465), array('tls', 587), array('', 587), array('', 588), array('', 80));
         $host = $this->api->mj_host;
         $connected = FALSE;
         if (get_option('mailjet_ssl')) {
             $protocol = 'ssl://';
         } else {
             $protocol = '';
         }
         $soc = @fsockopen($protocol . $host, get_option('mailjet_port'), $errno, $errstr, 5);
         if ($soc) {
             $connected = TRUE;
             $port = get_option('mailjet_port');
             $ssl = get_option('mailjet_ssl');
         } else {
             for ($i = 0; $i < count($configs); ++$i) {
                 if ($configs[$i][0]) {
                     $protocol = $configs[$i][0] . '://';
                 } else {
                     $protocol = '';
                 }
                 $soc = @fsockopen($protocol . $host, $configs[$i][1], $errno, $errstr, 5);
                 if ($soc) {
                     fclose($soc);
                     $connected = $i;
                     $port = $configs[$i][1];
                     $ssl = $configs[$i][0];
                     break;
                 }
             }
         }
         // Get all senders
         $senders = $this->api->getSenders(array('limit' => 0));
         // If there is connection, display successfull message
         if ($connected !== FALSE && is_array($senders)) {
             update_option('mailjet_ssl', $ssl);
             update_option('mailjet_port', $port);
             // Get sender
             $from_email = get_option('mailjet_from_email') ? get_option('mailjet_from_email') : get_option('admin_email');
             $test_sent = FALSE;
             if ($fields['mailjet_test'] && (in_array($from_email, $senders['email']) || in_array(array_pop(explode('@', $from_email)), $senders['domain']))) {
                 // Send a test mail
                 $subject = __('Your test mail from Mailjet', 'wp-mailjet');
                 $message = sprintf(__('Your Mailjet configuration is ok!' . 'SSL: %s Port: %s', 'wp-mailjet'), $ssl ? 'On' : 'Off', $port);
                 $enabled = get_option('mailjet_enabled');
                 update_option('mailjet_enabled', 1);
                 $test_sent = wp_mail($fields['mailjet_test_address'], $subject, $message);
                 update_option('mailjet_enabled', $enabled);
             }
             $sent = '';
             if ($test_sent) {
                 $sent = __(' and your test message was sent.', 'wp-mailjet');
             }
             if ($connected === TRUE) {
                 if (!in_array($from_email, $senders['email']) && !in_array(array_pop(explode('@', $from_email)), $senders['domain'])) {
                     WP_Mailjet_Utils::custom_notice('updated', __('Your settings have been saved successfully', 'wp-mailjet') . '.');
                 } else {
                     WP_Mailjet_Utils::custom_notice('updated', __('Your settings have been saved successfully', 'wp-mailjet') . $sent);
                 }
             } elseif ($connected >= 0) {
                 WP_Mailjet_Utils::custom_notice('updated', __('Your settings have been saved, but your port and SSL settings were changed as follows to ensure delivery', 'wp-mailjet') . $sent);
             }
         } else {
             // Error message
             $link = 'https://www.mailjet.com/account/api_keys';
             WP_Mailjet_Utils::custom_notice('error', sprintf(__('Please verify that you have entered your API and secret key correctly. If this is the case and you have still this error message, please go to Account API keys (<a href="%s" target="_blank">%s</a>) to regenerate a new Secret Key for the plug-in.', 'wp-mailjet'), $link, $link));
             //WP_Mailjet_Utils::custom_notice('error', sprintf (__ ('Please contact Mailjet support to sort this out.<br /><br />%d - %s', 'wp-mailjet'), $errno, $errstr));
         }
     } else {
         // Error message
         WP_Mailjet_Utils::custom_notice('error', __('There is an error with your settings. please correct and try again', 'wp-mailjet'));
     }
 }
コード例 #2
0
 public function save_settings()
 {
     $fields['mailjet_enabled'] = isset($_POST['mailjet_enabled']) ? 1 : 0;
     $fields['mailjet_test'] = isset($_POST['mailjet_test']) ? 1 : 0;
     $fields['mailjet_ssl'] = isset($_POST['mailjet_ssl']) ? 'ssl' : '';
     $fields['mailjet_test_address'] = strip_tags(filter_var($_POST['mailjet_test_address'], FILTER_VALIDATE_EMAIL));
     $fields['mailjet_from_email'] = strip_tags(filter_var($_POST['mailjet_from_email'], FILTER_VALIDATE_EMAIL));
     $fields['mailjet_username'] = strip_tags(filter_var($_POST['mailjet_username'], FILTER_SANITIZE_STRING));
     $fields['mailjet_password'] = strip_tags(filter_var($_POST['mailjet_password'], FILTER_SANITIZE_STRING));
     $fields['mailjet_port'] = strip_tags(filter_var($_POST['mailjet_port'], FILTER_SANITIZE_NUMBER_INT));
     $fields['mailjet_auto_subscribe_list_id'] = strip_tags(filter_var($_POST['mailjet_auto_subscribe_list_id'], FILTER_SANITIZE_NUMBER_INT));
     $errors = array();
     if ($fields['mailjet_test'] && empty($fields['mailjet_test_address'])) {
         $errors[] = 'mailjet_test_address';
     }
     if (!empty($fields['mailjet_test_address'])) {
         if (!filter_var($fields['mailjet_test_address'], FILTER_VALIDATE_EMAIL)) {
             $errors[] = 'mailjet_test_address';
         }
     }
     if (empty($fields['mailjet_username'])) {
         $errors[] = 'mailjet_username';
     }
     if (empty($fields['mailjet_password'])) {
         $errors[] = 'mailjet_password';
     }
     if (!count($errors)) {
         if ($fields['mailjet_ssl'] == 'ssl') {
             $fields['mailjet_port'] = 465;
         }
         update_option('mailjet_enabled', $fields['mailjet_enabled']);
         update_option('mailjet_token' . $_SERVER['REMOTE_ADDR'], json_encode(array('timestamp' => 0)));
         update_option('mailjet_test', $fields['mailjet_test']);
         update_option('mailjet_test_address', $fields['mailjet_test_address']);
         update_option('mailjet_from_email', $fields['mailjet_from_email']);
         update_option('mailjet_username', $fields['mailjet_username']);
         update_option('mailjet_password', $fields['mailjet_password']);
         update_option('mailjet_ssl', $fields['mailjet_ssl']);
         update_option('mailjet_port', $fields['mailjet_port']);
         update_option('mailjet_auto_subscribe_list_id', $fields['mailjet_auto_subscribe_list_id']);
         $configs = array(array('', 25), array('tls', 25), array('ssl', 465), array('tls', 587), array('', 587), array('', 588), array('', 80));
         $host = MJ_HOST;
         $connected = false;
         if (get_option('mailjet_ssl')) {
             $protocol = 'ssl://';
         } else {
             $protocol = '';
         }
         $soc = @fsockopen($protocol . $host, get_option('mailjet_port'), $errno, $errstr, 5);
         if ($soc) {
             $connected = true;
             $port = get_option('mailjet_port');
             $ssl = get_option('mailjet_ssl');
         } else {
             for ($i = 0; $i < count($configs); ++$i) {
                 if ($configs[$i][0]) {
                     $protocol = $configs[$i][0] . '://';
                 } else {
                     $protocol = '';
                 }
                 $soc = @fsockopen($protocol . $host, $configs[$i][1], $errno, $errstr, 5);
                 if ($soc) {
                     fclose($soc);
                     $connected = $i;
                     $port = $configs[$i][1];
                     $ssl = $configs[$i][0];
                     break;
                 }
             }
         }
         if ($connected !== false) {
             update_option('mailjet_ssl', $ssl);
             update_option('mailjet_port', $port);
             $test_sent = false;
             if ($fields['mailjet_test']) {
                 $subject = __('Your test mail from Mailjet', 'wp-mailjet');
                 $message = sprintf(__('Your Mailjet configuration is ok!' . 'SSL: %s Port: %s', 'wp-mailjet'), $ssl ? 'On' : 'Off', $port);
                 $enabled = get_option('mailjet_enabled');
                 update_option('mailjet_enabled', 1);
                 $test_sent = wp_mail($fields['mailjet_test_address'], $subject, $message);
                 update_option('mailjet_enabled', $enabled);
             }
             $sent = '';
             if ($test_sent) {
                 $sent = __(' and your test message was sent.', 'wp-mailjet');
             }
             if ($connected === true) {
                 WP_Mailjet_Utils::custom_notice('updated', __('Your settings have been saved successfully', 'wp-mailjet') . $sent);
             } elseif ($connected >= 0) {
                 WP_Mailjet_Utils::custom_notice('updated', __('Your settings have been saved, but your port and SSL settings were changed as follows to ensure delivery', 'wp-mailjet') . $sent);
             }
         } else {
             WP_Mailjet_Utils::custom_notice('error', sprintf(__('Please contact Mailjet support to sort this out.<br /><br />%d - %s', 'wp-mailjet'), $errno, $errstr));
         }
     } else {
         //var_dump($errors);
         WP_Mailjet_Utils::custom_notice('error', __('There is an error with your settings. please correct and try again', 'wp-mailjet'));
     }
 }
コード例 #3
0
 protected function save_list()
 {
     if (isset($_POST) && isset($_POST['name']) && isset($_POST['title'])) {
         if (!preg_match('/^[a-z0-9]+$/i', $_POST['name'])) {
             WP_Mailjet_Utils::custom_notice('error', __('Only alphanumeric characters may be used for the list name', 'wp-mailjet'));
             $this->show_add_list($_POST['name'], $_POST['title']);
         } else {
             $params = array('method' => 'POST', 'label' => $_POST['title'], 'name' => $_POST['name']);
             $response = $this->api->listsCreate($params);
             $this->show_all_lists();
         }
     } else {
         $this->show_add_list();
     }
 }