PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/site_v1.0/wordpress/wp-content/plugins/cimy-swift-smtp/cimy_swift_smtp.php

http://pumpmyvote.googlecode.com/
PHP | 249 lines | 190 code | 21 blank | 38 comment | 28 complexity | a6cde08b613898632726b3d9077fc6d1 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-3.0, AGPL-1.0, GPL-2.0
  1. <?php
  2. /*
  3. Plugin Name: Cimy Swift SMTP
  4. Plugin URI: http://www.marcocimmino.net/cimy-wordpress-plugins/cimy-swift-smtp/
  5. Description: Send email via SMTP (Compatible with GMAIL)
  6. Author: Marco Cimmino
  7. Version: 1.2.3
  8. Author URI: mailto:cimmino.marco@gmail.com
  9. Copyright (c) 2007-2009 Marco Cimmino
  10. original plug-in is from Marcus Vanstone
  11. http://www.shiftthis.net/wordpress-swift-smtp-plugin/
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  23. The full copy of the GNU General Public License is available here: http://www.gnu.org/licenses/gpl.txt
  24. */
  25. $cimy_swift_plugin_path = plugin_basename(dirname(__FILE__))."/";
  26. include('swift_engine.php');
  27. st_smtp_check_config(); //Initialize Configuration Variables
  28. add_action('admin_menu', 'st_smtp_add_pages'); //Add page menu links
  29. if (isset($_POST['st_smtp_submit_options']))
  30. add_action('init', 'st_smtp_options_submit'); //Update Options
  31. // Load Options
  32. $st_smtp_config = get_option('st_smtp_config');
  33. $cimy_swift_domain = 'cimy_swift_smtp';
  34. $cimy_swift_i18n_is_setup = 0;
  35. cimy_swift_i18n_setup();
  36. function cimy_swift_i18n_setup() {
  37. global $cimy_swift_domain, $cimy_swift_i18n_is_setup, $cimy_swift_plugin_path;
  38. if ($cimy_swift_i18n_is_setup)
  39. return;
  40. load_plugin_textdomain($cimy_swift_domain, PLUGINDIR.'/'.$cimy_swift_plugin_path.'langs', $cimy_swift_plugin_path.'langs');
  41. }
  42. /*-------------------------------------------------------------
  43. Name: st_smtp_add_pages
  44. Purpose: Add pages to admin menus
  45. -------------------------------------------------------------*/
  46. function st_smtp_add_pages() {
  47. global $cimy_top_menu;
  48. if (isset($cimy_top_menu))
  49. add_submenu_page('cimy_series.php', "Cimy Swift SMTP", "Swift SMTP", 10, "swift_smtp", 'st_smtp_options_page');
  50. else
  51. add_options_page('Cimy Swift SMTP', 'Cimy Swift SMTP', 10, "swift_smtp", 'st_smtp_options_page');
  52. }
  53. function st_smtp_options_page() {
  54. global $cimy_swift_domain;
  55. if (isset($_GET['error']) || (!current_user_can('manage_options')))
  56. return;
  57. // Make sure we have the freshest copy of the options
  58. $st_smtp_config = get_option('st_smtp_config');
  59. $st_smtp_config['server'] = attribute_escape($st_smtp_config['server']);
  60. $st_smtp_config['username'] = attribute_escape($st_smtp_config['username']);
  61. $st_smtp_config['password'] = attribute_escape($st_smtp_config['password']);
  62. $st_smtp_config['sender_name'] = attribute_escape($st_smtp_config['sender_name']);
  63. $st_smtp_config['sender_mail'] = attribute_escape($st_smtp_config['sender_mail']);
  64. if ($st_smtp_config['overwrite_sender'])
  65. $overwrite_sender = ' checked="checked"';
  66. else
  67. $overwrite_sender = '';
  68. ?>
  69. <div class="wrap">
  70. <?php
  71. if (function_exists(screen_icon))
  72. screen_icon();
  73. ?>
  74. <h2>Cimy Swift SMTP</h2>
  75. <p><?php _e("Add here your SMTP server details", $cimy_swift_domain); ?><br /><?php _e("<strong>Note:</strong> Gmail users need to use the server 'smtp.gmail.com' with TLS enabled and port 465", $cimy_swift_domain); ?></p>
  76. <form method="post" action="<?php echo admin_url("options-general.php?page=swift_smtp&amp;updated=true"); ?>">
  77. <input type="hidden" name="st_smtp_submit_options" value="true" />
  78. <table width="600">
  79. <tr>
  80. <td width="30%">
  81. <label for="css_sender_name"><?php _e("Sender name:", $cimy_swift_domain); ?></label>
  82. </td>
  83. <td width="70%">
  84. <input id="css_sender_name" name="css_sender_name" type="text" size="25" value="<?php echo $st_smtp_config['sender_name'];?>" />
  85. </td>
  86. </tr>
  87. <tr>
  88. <td>
  89. <label for="css_sender_mail"><?php _e("Sender e-mail:", $cimy_swift_domain); ?></label>
  90. </td>
  91. <td>
  92. <input id="css_sender_mail" name="css_sender_mail" type="text" size="25" value="<?php echo $st_smtp_config['sender_mail'];?>" />
  93. </td>
  94. </tr>
  95. <tr>
  96. <td>
  97. <label for="css_sender_overwrite"><?php _e("Always overwrite the sender:", $cimy_swift_domain); ?></label>
  98. </td>
  99. <td>
  100. <input id="css_sender_overwrite" name="css_sender_overwrite" type="checkbox" value="1"<?php echo $overwrite_sender;?> />
  101. </td>
  102. </tr>
  103. <tr>
  104. <td>
  105. <label for="css_server"><?php _e("SMTP server address:", $cimy_swift_domain); ?></label>
  106. </td>
  107. <td>
  108. <input id="css_server" name="css_server" type="text" size="25" value="<?php echo $st_smtp_config['server'];?>" />
  109. </td>
  110. </tr>
  111. <tr>
  112. <td>
  113. <label for="css_port"><?php _e("Port:", $cimy_swift_domain); ?></label>
  114. </td>
  115. <td>
  116. <select id="css_port" name="css_port">
  117. <option value="25" <?php if ($st_smtp_config['port'] == "25"){echo "selected='selected'";}?>><?php _e("25 (Default SMTP Port)", $cimy_swift_domain); ?></option>
  118. <option value="465" <?php if ($st_smtp_config['port'] == "465"){echo "selected='selected'";}?>><?php _e("465 (Use for SSL/TLS/GMAIL)", $cimy_swift_domain); ?></option>
  119. <option value="custom" <?php if ( ($st_smtp_config['port'] != "465") && ($st_smtp_config['port'] != "25") ){echo "selected='selected'";}?>><?php _e("Custom Port: (Use Box)", $cimy_swift_domain); ?></option>
  120. </select>&nbsp;<input name="css_customport" type="text" size="4" value="<?php if (($st_smtp_config['port'] != "465") && ($st_smtp_config['port'] != "25")) { echo $st_smtp_config['port']; } ?>" />
  121. </td>
  122. </tr>
  123. <tr>
  124. <td>
  125. <label for="css_username"><?php _e("Username:", $cimy_swift_domain); ?></label>
  126. </td>
  127. <td>
  128. <input id="css_username" name="css_username" type="text" size="25" value="<?php echo $st_smtp_config['username'];?>" />
  129. </td>
  130. </tr>
  131. <tr>
  132. <td>
  133. <label for="css_password"><?php _e("Password:", $cimy_swift_domain); ?></label>
  134. </td>
  135. <td>
  136. <input id="css_password" name="css_password" type="password" size="25" value="<?php echo $st_smtp_config['password'];?>" />
  137. </td>
  138. </tr>
  139. <tr>
  140. <td>
  141. <label for="css_ssl"><?php _e("Use SSL or TLS?:", $cimy_swift_domain); ?></label>
  142. </td>
  143. <td>
  144. <select id="css_ssl" name="css_ssl">
  145. <option value="" <?php if ($st_smtp_config['ssl'] == ''){echo 'selected="selected"';}?>><?php _e("No", $cimy_swift_domain); ?></option>
  146. <option value="ssl" <?php if ($st_smtp_config['ssl'] == 'ssl'){echo 'selected="selected"';}?>><?php _e("SSL", $cimy_swift_domain); ?></option>
  147. <option value="tls" <?php if ($st_smtp_config['ssl'] == 'tls'){echo 'selected="selected"';}?>><?php _e("TLS (Use for Gmail)", $cimy_swift_domain); ?></option>
  148. </select>
  149. </td>
  150. </tr>
  151. </table>
  152. <p class="submit" style="text-align:left">
  153. <input class="button-primary" type="submit" name="Submit" value="<?php _e("Save Changes"); ?>" />
  154. </p>
  155. </form>
  156. <br />
  157. <h2><?php _e("Test Connection", $cimy_swift_domain); ?></h2>
  158. <p><?php _e("Once you've saved your settings, click the link below to test your connection.", $cimy_swift_domain); ?></p>
  159. <form method="post" action="">
  160. <input type="hidden" name="test" value="1" />
  161. <label><?php _e("Send Test Email to this Address:", $cimy_swift_domain); ?> <input type="text" name="testemail" size="25" /> <input class="button" type="submit" value="<?php _e("Send Test", $cimy_swift_domain); ?>" /></label><br />
  162. </form>
  163. <?php
  164. if (isset($_POST['test'])) {
  165. ?><br /><br /><h2><?php _e("Test result", $cimy_swift_domain); ?></h2><?php
  166. $email = $_POST['testemail'];
  167. if ($email == "")
  168. $email = form_option('admin_email');
  169. $text = __("This is a test mail sent using the Cimy Swift SMTP Plugin. If you've received this email it means your connection has been set up properly! Cool!", $cimy_swift_domain);
  170. if (wp_mail($email, 'Cimy Swift SMTP Test', $text)) {
  171. echo "<p><strong>".__("TEST EMAIL SENT - Connection Verified.", $cimy_swift_domain)."<br />".__("If you don't receive the e-mail check also the spam folder.", $cimy_swift_domain)."</strong></p>";
  172. }
  173. }
  174. ?>
  175. </div>
  176. <?php
  177. }
  178. function st_smtp_check_config() {
  179. if (!$option = get_option('st_smtp_config')) {
  180. // Default Options
  181. update_option('st_smtp_config', $option);
  182. }
  183. }
  184. function st_smtp_options_submit() {
  185. if (!current_user_can('manage_options'))
  186. return;
  187. //options page
  188. $option['server'] = $_POST['css_server'];
  189. $option['username'] = $_POST['css_username'];
  190. $option['password'] = $_POST['css_password'];
  191. $option['ssl'] = $_POST['css_ssl'];
  192. $option['sender_name'] = $_POST['css_sender_name'];
  193. $option['sender_mail'] = $_POST['css_sender_mail'];
  194. if (isset($_POST['css_sender_overwrite']))
  195. $option['overwrite_sender'] = true;
  196. else
  197. $option['overwrite_sender'] = false;
  198. if ($_POST['css_port'] != 'custom'){
  199. $option['port'] = $_POST['css_port'];
  200. } else {
  201. $option['port'] = intval($_POST['css_customport']);
  202. }
  203. update_option('st_smtp_config', $option);
  204. }
  205. ?>