| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
Plugin Name: Postie |
| 5 |
Plugin URI: http://PostiePlugin.com/ |
| 6 |
Description: Create posts via email. Significantly upgrades the Post by Email features of WordPress. |
| 7 |
Version: 1.9.8 |
| 8 |
Author: Wayne Allen |
| 9 |
Author URI: http://PostiePlugin.com/ |
| 10 |
License: GPL3 |
| 11 |
Text Domain: postie |
| 12 |
*/ |
| 13 |
|
| 14 |
/* Copyright (c) 2015-17 Wayne Allen (email : wayne@postieplugin.com) |
| 15 |
|
| 16 |
This program is free software: you can redistribute it and/or modify |
| 17 |
it under the terms of the GNU General Public License as published by |
| 18 |
the Free Software Foundation, either version 3 of the License, or |
| 19 |
(at your option) any later version. |
| 20 |
|
| 21 |
This program is distributed in the hope that it will be useful, |
| 22 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 |
GNU General Public License for more details. |
| 25 |
|
| 26 |
You should have received a copy of the GNU General Public License |
| 27 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 28 |
*/ |
| 29 |
|
| 30 |
/* |
| 31 |
$Id$ |
| 32 |
*/ |
| 33 |
|
| 34 |
if (!defined('WPINC')) { |
| 35 |
die; // Exit if accessed directly |
| 36 |
} |
| 37 |
|
| 38 |
define('POSTIE_VERSION', '1.9.8'); |
| 39 |
define('POSTIE_ROOT', dirname(__FILE__)); |
| 40 |
define('POSTIE_URL', WP_PLUGIN_URL . '/' . basename(dirname(__FILE__))); |
| 41 |
|
| 42 |
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-compatibility.php'); |
| 43 |
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-api.php'); |
| 44 |
|
| 45 |
if (!class_exists('PostieInit')) { |
| 46 |
|
| 47 |
class PostieInit { |
| 48 |
|
| 49 |
public function __construct() { |
| 50 |
//WordPress Actions |
| 51 |
add_action('init', array($this, 'init_action'), 20); |
| 52 |
add_action('parse_request', array($this, 'parse_request_action')); |
| 53 |
add_action('admin_init', array($this, 'admin_init_action')); |
| 54 |
add_action('admin_menu', array($this, 'admin_menu_action')); |
| 55 |
add_action('admin_head', array($this, 'admin_head_action')); |
| 56 |
add_action('plugins_loaded', array($this, 'plugins_loaded_action')); |
| 57 |
|
| 58 |
//WordPress filters |
| 59 |
add_filter('whitelist_options', array($this, 'whitelist_options_filter')); |
| 60 |
add_filter('cron_schedules', array($this, 'cron_schedules_filter')); |
| 61 |
add_filter('query_vars', array($this, 'query_vars_filter')); |
| 62 |
add_filter("plugin_action_links_" . plugin_basename(__FILE__), array($this, 'plugin_action_links_filter')); |
| 63 |
add_filter('plugin_row_meta', array($this, 'plugin_row_meta_filter'), 10, 2); |
| 64 |
|
| 65 |
//WordPress Hooks |
| 66 |
register_activation_hook(__FILE__, array('PostieInit', 'postie_activate_hook')); |
| 67 |
register_activation_hook(__FILE__, array('PostieInit', 'postie_cron_hook')); |
| 68 |
register_deactivation_hook(__FILE__, array('PostieInit', 'postie_decron_hook')); |
| 69 |
|
| 70 |
//Postie actions |
| 71 |
add_action('check_postie_hook', 'postie_check'); |
| 72 |
|
| 73 |
if (is_admin()) { |
| 74 |
$this->postie_warnings(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
static function postie_activate_hook() { |
| 79 |
/* |
| 80 |
* called by WP when activating the plugin |
| 81 |
* Note that you can't do any output during this funtion or activation |
| 82 |
* will fail on some systems. This means no DebugEcho, EchoInfo or DebugDump. |
| 83 |
*/ |
| 84 |
} |
| 85 |
|
| 86 |
static function postie_cron_hook($interval = false) { |
| 87 |
//Do not echo output in filters, it seems to break some installs |
| 88 |
//error_log("postie_cron: setting up cron task: $interval"); |
| 89 |
//$schedules = wp_get_schedules(); |
| 90 |
//error_log("postie_cron\n" . print_r($schedules, true)); |
| 91 |
|
| 92 |
if (empty($interval)) { |
| 93 |
$interval = 'hourly'; |
| 94 |
//error_log("Postie: setting up cron task: defaulting to hourly"); |
| 95 |
} |
| 96 |
|
| 97 |
if ($interval == 'manual') { |
| 98 |
PostieInit::postie_decron_hook(); |
| 99 |
//error_log("postie_cron: clearing cron (manual)"); |
| 100 |
} else { |
| 101 |
if ($interval != wp_get_schedule('check_postie_hook')) { |
| 102 |
PostieInit::postie_decron_hook(); //remove existing |
| 103 |
//try to create the new schedule with the first run in 5 minutes |
| 104 |
if (false === wp_schedule_event(time() + 5 * 60, $interval, 'check_postie_hook')) { |
| 105 |
//error_log("postie_cron: Failed to set up cron task: $interval"); |
| 106 |
} else { |
| 107 |
//error_log("postie_cron: Set up cron task: $interval"); |
| 108 |
} |
| 109 |
} else { |
| 110 |
//error_log("postie_cron: OK: $interval"); |
| 111 |
//don't need to do anything, cron already scheduled |
| 112 |
} |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
static function postie_decron_hook() { |
| 117 |
//don't use DebugEcho or EchoInfo here as it is not defined when called as a hook |
| 118 |
//error_log("postie_decron: clearing cron"); |
| 119 |
wp_clear_scheduled_hook('check_postie_hook'); |
| 120 |
} |
| 121 |
|
| 122 |
function plugins_loaded_action() { |
| 123 |
load_plugin_textdomain('postie', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
| 124 |
} |
| 125 |
|
| 126 |
function init_action() { |
| 127 |
remove_filter('content_save_pre', 'wp_filter_post_kses'); |
| 128 |
} |
| 129 |
|
| 130 |
function plugin_row_meta_filter($links, $file) { |
| 131 |
if (strpos($file, plugin_basename(__FILE__)) !== false) { |
| 132 |
$new_links = array( |
| 133 |
'<a href="http://postieplugin.com/" target="_blank">Support</a>', |
| 134 |
'<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=HPK99BJ88V4C2" target="_blank">Donate</a>' |
| 135 |
); |
| 136 |
|
| 137 |
$links = array_merge($links, $new_links); |
| 138 |
} |
| 139 |
|
| 140 |
return $links; |
| 141 |
} |
| 142 |
|
| 143 |
function parse_request_action($wp) { |
| 144 |
if (array_key_exists('postie', $wp->query_vars)) { |
| 145 |
switch ($wp->query_vars['postie']) { |
| 146 |
case 'get-mail': |
| 147 |
postie_get_mail(); |
| 148 |
die(); |
| 149 |
case 'test-config': |
| 150 |
postie_test_config(); |
| 151 |
die(); |
| 152 |
default : |
| 153 |
dir('Unknown option: ' . $wp->query_vars['postie']); |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
function admin_init_action() { |
| 159 |
wp_register_style('postie-style', plugins_url('css/style.css', __FILE__)); |
| 160 |
register_setting('postie-settings', 'postie-settings', array(new PostieConfig(), 'config_ValidateSettings')); |
| 161 |
} |
| 162 |
|
| 163 |
function admin_menu_action() { |
| 164 |
$page = add_menu_page('Postie', 'Postie', 'manage_options', 'postie-settings', array($this, 'postie_show_config_page')); |
| 165 |
add_action('admin_print_styles-' . $page, array($this, 'postie_admin_styles')); |
| 166 |
} |
| 167 |
|
| 168 |
function admin_head_action() { |
| 169 |
?> |
| 170 |
<style type="text/css"> |
| 171 |
#adminmenu #toplevel_page_postie-settings div.wp-menu-image:before { |
| 172 |
content: "\f466"; |
| 173 |
} |
| 174 |
</style> |
| 175 |
<?php |
| 176 |
|
| 177 |
} |
| 178 |
|
| 179 |
function whitelist_options_filter($options) { |
| 180 |
$added = array('postie-settings' => array('postie-settings')); |
| 181 |
$options = add_option_whitelist($added, $options); |
| 182 |
return $options; |
| 183 |
} |
| 184 |
|
| 185 |
function cron_schedules_filter($schedules) { |
| 186 |
//Do not echo output in filters, it seems to break some installs |
| 187 |
//error_log("cron_schedules_filter: setting cron schedules"); |
| 188 |
$schedules['weekly'] = array('interval' => (60 * 60 * 24 * 7), 'display' => __('Once Weekly', 'postie')); |
| 189 |
$schedules['twohours'] = array('interval' => 60 * 60 * 2, 'display' => __('Every 2 hours', 'postie')); |
| 190 |
$schedules['twiceperhour'] = array('interval' => 60 * 30, 'display' => __('Twice per hour', 'postie')); |
| 191 |
$schedules['tenminutes'] = array('interval' => 60 * 10, 'display' => __('Every 10 minutes', 'postie')); |
| 192 |
$schedules['fiveminutes'] = array('interval' => 60 * 5, 'display' => __('Every 5 minutes', 'postie')); |
| 193 |
$schedules['oneminute'] = array('interval' => 60 * 1, 'display' => __('Every 1 minute', 'postie')); |
| 194 |
$schedules['thirtyseconds'] = array('interval' => 30, 'display' => __('Every 30 seconds', 'postie')); |
| 195 |
$schedules['fifteenseconds'] = array('interval' => 15, 'display' => __('Every 15 seconds', 'postie')); |
| 196 |
return $schedules; |
| 197 |
} |
| 198 |
|
| 199 |
function query_vars_filter($vars) { |
| 200 |
$vars[] = 'postie'; |
| 201 |
return $vars; |
| 202 |
} |
| 203 |
|
| 204 |
function plugin_action_links_filter($links) { |
| 205 |
$links[] = '<a href="admin.php?page=postie-settings">Settings</a>'; |
| 206 |
return $links; |
| 207 |
} |
| 208 |
|
| 209 |
function postie_show_config_page() { |
| 210 |
global $g_postie; |
| 211 |
require_once POSTIE_ROOT . '/config_form.php'; |
| 212 |
} |
| 213 |
|
| 214 |
function postie_admin_styles() { |
| 215 |
wp_enqueue_style('postie-style'); |
| 216 |
} |
| 217 |
|
| 218 |
/** |
| 219 |
* This function looks for markdown which causes problems with postie |
| 220 |
*/ |
| 221 |
function postie_isMarkdownInstalled() { |
| 222 |
if (in_array("markdown.php", get_option("active_plugins"))) { |
| 223 |
return true; |
| 224 |
} |
| 225 |
return false; |
| 226 |
} |
| 227 |
|
| 228 |
function postie_markdown_warning() { |
| 229 |
echo "<div id='postie-lst-warning' class='error'><p><strong>"; |
| 230 |
_e("You currently have the Markdown plugin installed. It will cause problems if you send in HTML email. Please turn it off if you intend to send email using HTML.", 'postie'); |
| 231 |
echo "</strong></p></div>"; |
| 232 |
} |
| 233 |
|
| 234 |
function postie_enter_info() { |
| 235 |
echo "<div id='postie-info-warning' class='updated fade'><p><strong>" . __('Postie is almost ready.', 'postie') . "</strong> " |
| 236 |
. sprintf(__('You must <a href="%1$s">enter your email settings</a> for it to work.', 'postie'), "admin.php?page=postie-settings") |
| 237 |
. "</p></div> "; |
| 238 |
} |
| 239 |
|
| 240 |
function postie_iconv_warning() { |
| 241 |
echo "<div id='postie-lst-warning' class='error'><p><strong>"; |
| 242 |
_e("Warning! Postie requires that iconv be enabled.", 'postie'); |
| 243 |
echo "</strong></p></div>"; |
| 244 |
} |
| 245 |
|
| 246 |
function postie_php_warning() { |
| 247 |
echo "<div id='postie-lst-warning' class='error'><p><strong>"; |
| 248 |
_e("Warning! Postie requires that PHP be verion 5.2 or higher. You have version " . phpversion(), 'postie'); |
| 249 |
echo "</strong></p></div>"; |
| 250 |
} |
| 251 |
|
| 252 |
function postie_curl_warning() { |
| 253 |
$cv = curl_version(); |
| 254 |
echo "<div id='postie-lst-warning' class='error'><p><strong>"; |
| 255 |
_e("Warning! Postie requires cURL 7.30.0 or newer be installed. {$cv['version']} is installed.", 'postie'); |
| 256 |
echo "</strong></p></div>"; |
| 257 |
} |
| 258 |
|
| 259 |
function postie_adminuser_warning() { |
| 260 |
echo "<div id='postie-mbstring-warning' class='error'><p><strong>"; |
| 261 |
echo __('Warning: the Default Poster is not a valid WordPress login. Postie may reject emails if this is not corrected.', 'postie'); |
| 262 |
echo "</strong></p></div>"; |
| 263 |
} |
| 264 |
|
| 265 |
function postie_IsIconvInstalled($display = true) { |
| 266 |
$function_list = array('iconv'); |
| 267 |
return($this->postie_HasFunctions($function_list, $display)); |
| 268 |
} |
| 269 |
|
| 270 |
/** |
| 271 |
* Handles verifying that a list of functions exists |
| 272 |
* @return boolean |
| 273 |
* @param array |
| 274 |
*/ |
| 275 |
function postie_HasFunctions($function_list, $display = true) { |
| 276 |
foreach ($function_list as $function) { |
| 277 |
if (!function_exists($function)) { |
| 278 |
if ($display) { |
| 279 |
EchoError("Missing $function"); |
| 280 |
} |
| 281 |
return false; |
| 282 |
} |
| 283 |
} |
| 284 |
return true; |
| 285 |
} |
| 286 |
|
| 287 |
function postie_warnings() { |
| 288 |
$config = postie_config_read(); |
| 289 |
|
| 290 |
if ((empty($config['mail_server']) || |
| 291 |
empty($config['mail_server_port']) || |
| 292 |
empty($config['mail_userid']) || |
| 293 |
empty($config['mail_password']) |
| 294 |
) && !isset($_POST['submit'])) { |
| 295 |
|
| 296 |
add_action('admin_notices', array($this, 'postie_enter_info')); |
| 297 |
} |
| 298 |
|
| 299 |
if ($this->postie_isMarkdownInstalled() && $config['prefer_text_type'] == 'html') { |
| 300 |
add_action('admin_notices', array($this, 'postie_markdown_warning')); |
| 301 |
} |
| 302 |
|
| 303 |
if (!$this->postie_IsIconvInstalled()) { |
| 304 |
add_action('admin_notices', array($this, 'postie_iconv_warning')); |
| 305 |
} |
| 306 |
|
| 307 |
if (!fCore::checkVersion('5.2.0')) { |
| 308 |
add_action('admin_notices', array($this, 'postie_php_warning')); |
| 309 |
} |
| 310 |
|
| 311 |
if (function_exists('curl_version')) { |
| 312 |
$cv = curl_version(); |
| 313 |
} else { |
| 314 |
$cv = '1.0.0'; |
| 315 |
} |
| 316 |
if ($config['input_connection'] == 'curl' && !version_compare($cv['version'], '7.30.0', 'ge')) { |
| 317 |
add_action('admin_notices', array($this, 'postie_curl_warning')); |
| 318 |
} |
| 319 |
|
| 320 |
$userdata = WP_User::get_data_by('login', $config['admin_username']); |
| 321 |
if (!$userdata) { |
| 322 |
add_action('admin_notices', array($this, 'postie_adminuser_warning')); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
} |
| 327 |
|
| 328 |
$g_postie_init = new PostieInit(); |
| 329 |
} |
| 330 |
|