PluginProbe
Postie / 1.9.80
Postie v1.9.80
1.9.80 1.9.79 1.9.78 1.9.77 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.10 1.7.11 1.7.12 1.7.13 1.7.14 1.7.15 1.7.16 1.7.17 1.7.18 1.7.2 1.7.20 All 239 releases
postie / postie.php

postie.php in Postie 1.9.80, at postie.php

423 lines 16.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.80
8 Author: Wayne Allen
9 Author URI: http://PostiePlugin.com/
10 License: GPL3
11 Text Domain: postie
12 */
13
14 /* Copyright (c) 2015-20 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 $plugin_data = get_file_data(__FILE__, array('Version' => 'Version'), false);
39 $plugin_version = $plugin_data['Version'];
40
41 define('POSTIE_VERSION', $plugin_version);
42 define('POSTIE_ROOT', __DIR__);
43 define('POSTIE_URL', plugin_dir_url(__FILE__));
44
45 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'postie-compatibility.php');
46 require_once(__DIR__ . DIRECTORY_SEPARATOR . 'postie-api.php');
47
48 if (!class_exists('PostieInit')) {
49
50 class PostieInit {
51
52 public function __construct() {
53 //WordPress Actions
54 add_action('init', array($this, 'init_action'), 20);
55 add_action('parse_request', array($this, 'parse_request_action'));
56 add_action('admin_init', array($this, 'admin_init_action'));
57 add_action('admin_menu', array($this, 'admin_menu_action'));
58 add_action('admin_head', array($this, 'admin_head_action'));
59 add_action('plugins_loaded', array($this, 'plugins_loaded_action'));
60 add_action('pre_post_update', array($this, 'pre_post_update_action'), 10, 2);
61
62 //WordPress filters
63 if (version_compare(get_bloginfo('version'), '5.5', '>=')) {
64 add_filter('allowed_options', array($this, 'whitelist_options_filter'));
65 } else {
66
67 add_filter('whitelist_options', array($this, 'whitelist_options_filter'));
68 }
69 add_filter('cron_schedules', array($this, 'cron_schedules_filter'));
70 add_filter('query_vars', array($this, 'query_vars_filter'));
71 add_filter("plugin_action_links_" . plugin_basename(__FILE__), array($this, 'plugin_action_links_filter'));
72 add_filter('plugin_row_meta', array($this, 'plugin_row_meta_filter'), 10, 2);
73 add_filter('enable_post_by_email_configuration', array($this, 'enable_post_by_email_configuration'));
74 add_filter('site_status_tests', array($this, 'site_status_tests_filter'));
75 add_filter('query', array($this, 'query_filter'));
76
77 //WordPress Hooks
78 register_activation_hook(__FILE__, array('PostieInit', 'postie_activate_hook'));
79 register_activation_hook(__FILE__, array('PostieInit', 'postie_cron_hook'));
80 register_deactivation_hook(__FILE__, array('PostieInit', 'postie_decron_hook'));
81
82 //Postie actions
83 add_action('check_postie_hook', 'postie_check');
84
85 if (is_admin()) {
86 $this->postie_warnings();
87 }
88 }
89
90 static function postie_activate_hook() {
91 /*
92 * called by WP when activating the plugin
93 * Note that you can't do any output during this funtion or activation
94 * will fail on some systems. This means no DebugEcho, EchoInfo or DebugDump.
95 */
96 }
97
98 static function postie_cron_hook($interval = false) {
99 //Do not echo output in filters, it seems to break some installs
100 //error_log("postie_cron: setting up cron task: $interval");
101 //$schedules = wp_get_schedules();
102 //error_log("postie_cron\n" . print_r($schedules, true));
103
104 if (empty($interval)) {
105 $interval = 'hourly';
106 //error_log("Postie: setting up cron task: defaulting to hourly");
107 }
108
109 if ($interval == 'manual') {
110 PostieInit::postie_decron_hook();
111 //error_log("postie_cron: clearing cron (manual)");
112 } else {
113 if ($interval != wp_get_schedule('check_postie_hook')) {
114 PostieInit::postie_decron_hook(); //remove existing
115 //try to create the new schedule with the first run in 5 minutes
116 if (false === wp_schedule_event(time() + 5 * 60, $interval, 'check_postie_hook')) {
117 //error_log("postie_cron: Failed to set up cron task: $interval");
118 } else {
119 //error_log("postie_cron: Set up cron task: $interval");
120 }
121 } else {
122 //error_log("postie_cron: OK: $interval");
123 //don't need to do anything, cron already scheduled
124 }
125 }
126 }
127
128 static function postie_decron_hook() {
129 //don't use DebugEcho or EchoInfo here as it is not defined when called as a hook
130 //error_log("postie_decron: clearing cron");
131 wp_clear_scheduled_hook('check_postie_hook');
132 }
133
134 function site_status_tests_filter($tests) {
135 $tests['direct']['postie1'] = array(
136 'label' => __('Postie Test'),
137 'test' => array($this, 'test_delete_mail_after_processing'),
138 );
139 $tests['direct']['postie2'] = array(
140 'label' => __('Postie Test'),
141 'test' => array($this, 'test_turn_authorization_off'),
142 );
143 return $tests;
144 }
145
146 function query_filter($query) {
147 DebugEcho("Query: $query");
148
149 return $query;
150 }
151
152 //https://make.wordpress.org/core/2019/04/25/site-health-check-in-5-2/
153 function test_delete_mail_after_processing() {
154 $config = postie_config_read();
155 $enabled = $config->delete_mail_after_processing;
156 $result = array(
157 'label' => __('Postie should delete emails after processing'),
158 'status' => $enabled ? 'good' : 'recommended',
159 'badge' => array(
160 'label' => __('Performance'),
161 'color' => 'blue',
162 ),
163 'description' => sprintf('<p>%s</p>', __('If emails are not deleted they will be imported every time Postie runs.')
164 ),
165 'actions' => '',
166 'test' => 'postie_delete_mail_after_processing',
167 );
168
169 return $result;
170 }
171
172 function test_turn_authorization_off() {
173 $config = postie_config_read();
174 $enabled = !$config->turn_authorization_off;
175 $result = array(
176 'label' => __('Postie should only allow authorized users to post'),
177 'status' => $enabled ? 'good' : 'critical',
178 'badge' => array(
179 'label' => __('Security'),
180 'color' => 'blue',
181 ),
182 'description' => sprintf('<p>%s</p>', __('Allowing anyone who knows your Postie email address to post can result in unwanted posts.')
183 ),
184 'actions' => '',
185 'test' => 'postie_turn_authorization_off',
186 );
187
188 return $result;
189 }
190
191 function pre_post_update_action($post_id, $post_data) {
192 DebugEcho('pre_post_update');
193 DebugDump($post_data);
194 }
195
196 function plugins_loaded_action() {
197 load_plugin_textdomain('postie', false, dirname(plugin_basename(__FILE__)) . '/languages/');
198 }
199
200 function init_action() {
201 global $wp_version;
202 if (version_compare($wp_version, '5.3') == -1) {
203 require_once( ABSPATH . WPINC . '/class-oembed.php' );
204 } else {
205 require_once( ABSPATH . WPINC . '/class-wp-oembed.php' );
206 }
207
208 // Self-healing cron check: re-schedule if event is missing and interval is not 'manual'
209 $config = postie_config_read();
210 if ($config->interval !== 'manual' && !wp_next_scheduled('check_postie_hook')) {
211 PostieInit::postie_cron_hook($config->interval);
212 }
213 }
214
215 function enable_post_by_email_configuration($enabled) {
216 return false;
217 }
218
219 function plugin_row_meta_filter($links, $file) {
220 if (strpos($file, strval(plugin_basename(__FILE__))) !== false) {
221 $new_links = array(
222 '<a href="http://postieplugin.com/" target="_blank">Support</a>',
223 '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=s-xclick&hosted_button_id=HPK99BJ88V4C2" target="_blank">Donate</a>'
224 );
225
226 $links = array_merge($links, $new_links);
227 }
228
229 return $links;
230 }
231
232 function parse_request_action($wp) {
233 if (array_key_exists('postie', $wp->query_vars)) {
234 switch ($wp->query_vars['postie']) {
235 case 'get-mail':
236 postie_get_mail();
237 die();
238 case 'test-config':
239 postie_test_config();
240 die();
241 default :
242 die('Unknown option: ' . htmlentities($wp->query_vars['postie']));
243 }
244 }
245 }
246
247 function admin_init_action() {
248 wp_register_style('postie-style', plugins_url('css/style.css', __FILE__));
249 register_setting('postie-settings', 'postie-settings', array($this, 'lazy_validate_settings'));
250 }
251
252 function lazy_validate_settings($in) {
253 $pconfig = new PostieConfig();
254 return $pconfig->config_ValidateSettings($in);
255 }
256
257 function admin_menu_action() {
258 $page = add_menu_page('Postie', 'Postie', 'manage_options', 'postie-settings', array($this, 'postie_show_config_page'));
259 add_action('admin_print_styles-' . $page, array($this, 'postie_admin_styles'));
260 }
261
262 function admin_head_action() {
263 ?>
264 <style type="text/css">
265 #adminmenu #toplevel_page_postie-settings div.wp-menu-image:before {
266 content: "\f466";
267 }
268 </style>
269 <?php
270
271 }
272
273 function whitelist_options_filter($options) {
274 $added = array('postie-settings' => array('postie-settings'));
275 return add_allowed_options($added, $options);
276 }
277
278 function cron_schedules_filter($schedules) {
279 //Do not echo output in filters, it seems to break some installs
280 //error_log("cron_schedules_filter: setting cron schedules");
281 $schedules['weekly'] = array('interval' => (60 * 60 * 24 * 7), 'display' => __('Once Weekly', 'postie'));
282 $schedules['twohours'] = array('interval' => 60 * 60 * 2, 'display' => __('Every 2 hours', 'postie'));
283 $schedules['twiceperhour'] = array('interval' => 60 * 30, 'display' => __('Twice per hour', 'postie'));
284 $schedules['tenminutes'] = array('interval' => 60 * 10, 'display' => __('Every 10 minutes', 'postie'));
285 $schedules['fiveminutes'] = array('interval' => 60 * 5, 'display' => __('Every 5 minutes', 'postie'));
286 $schedules['oneminute'] = array('interval' => 60 * 1, 'display' => __('Every 1 minute', 'postie'));
287 $schedules['thirtyseconds'] = array('interval' => 30, 'display' => __('Every 30 seconds', 'postie'));
288 $schedules['fifteenseconds'] = array('interval' => 15, 'display' => __('Every 15 seconds', 'postie'));
289 return $schedules;
290 }
291
292 function query_vars_filter($vars) {
293 $vars[] = 'postie';
294 return $vars;
295 }
296
297 function plugin_action_links_filter($links) {
298 $links[] = '<a href="admin.php?page=postie-settings">Settings</a>';
299 return $links;
300 }
301
302 function postie_show_config_page() {
303 global $g_postie;
304 require_once POSTIE_ROOT . '/config_form.php';
305 }
306
307 function postie_admin_styles() {
308 wp_enqueue_style('postie-style');
309 }
310
311 /**
312 * This function looks for markdown which causes problems with postie
313 */
314 function postie_isMarkdownInstalled() {
315 if (in_array("markdown.php", get_option("active_plugins"))) {
316 return true;
317 }
318 return false;
319 }
320
321 function postie_markdown_warning() {
322 echo "<div id='postie-lst-warning' class='error'><p><strong>";
323 _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');
324 echo "</strong></p></div>";
325 }
326
327 function postie_enter_info() {
328 echo "<div id='postie-info-warning' class='updated fade'><p><strong>" . __('Postie is almost ready.', 'postie') . "</strong> "
329 . sprintf(__('You must <a href="%1$s">enter your email settings</a> for it to work.', 'postie'), "admin.php?page=postie-settings")
330 . "</p></div> ";
331 }
332
333 function postie_iconv_warning() {
334 echo "<div id='postie-lst-warning' class='error'><p><strong>";
335 _e("Warning! Postie requires that iconv be enabled.", 'postie');
336 echo "</strong></p></div>";
337 }
338
339 function postie_php_warning() {
340 echo "<div id='postie-lst-warning' class='error'><p><strong>";
341 _e("Warning! Postie requires that PHP be verion 5.2 or higher. You have version " . phpversion(), 'postie');
342 echo "</strong></p></div>";
343 }
344
345 function postie_curl_warning() {
346 $cv = curl_version();
347 echo "<div id='postie-lst-warning' class='error'><p><strong>";
348 _e("Warning! Postie requires cURL 7.30.0 or newer be installed. {$cv['version']} is installed.", 'postie');
349 echo "</strong></p></div>";
350 }
351
352 function postie_adminuser_warning() {
353 echo "<div id='postie-mbstring-warning' class='error'><p><strong>";
354 echo __('Warning: the Default Poster is not a valid WordPress login. Postie may reject emails if this is not corrected.', 'postie');
355 echo "</strong></p></div>";
356 }
357
358 function postie_IsIconvInstalled($display = true) {
359 $function_list = array('iconv');
360 return($this->postie_HasFunctions($function_list, $display));
361 }
362
363 /**
364 * Handles verifying that a list of functions exists
365 * @return boolean
366 * @param array
367 */
368 function postie_HasFunctions($function_list, $display = true) {
369 foreach ($function_list as $function) {
370 if (!function_exists($function)) {
371 if ($display) {
372 EchoError("Missing $function");
373 }
374 return false;
375 }
376 }
377 return true;
378 }
379
380 function postie_warnings() {
381 $config = postie_config_read();
382
383 if ((empty($config->mail_server) ||
384 empty($config->mail_server_port) ||
385 empty($config->mail_userid) ||
386 empty($config->mail_password)
387 ) && !isset($_POST['submit'])) {
388
389 add_action('admin_notices', array($this, 'postie_enter_info'));
390 }
391
392 if ($this->postie_isMarkdownInstalled() && $config->prefer_text_type == 'html') {
393 add_action('admin_notices', array($this, 'postie_markdown_warning'));
394 }
395
396 if (!$this->postie_IsIconvInstalled()) {
397 add_action('admin_notices', array($this, 'postie_iconv_warning'));
398 }
399
400 if (!fCore::checkVersion('5.2.0')) {
401 add_action('admin_notices', array($this, 'postie_php_warning'));
402 }
403
404 if (function_exists('curl_version')) {
405 $cv = curl_version();
406 } else {
407 $cv['version'] = '1.0.0';
408 }
409 if ($config->input_connection == 'curl' && !version_compare($cv['version'], '7.30.0', 'ge')) {
410 add_action('admin_notices', array($this, 'postie_curl_warning'));
411 }
412
413 $userdata = WP_User::get_data_by('login', $config->admin_username);
414 if (!$userdata) {
415 add_action('admin_notices', array($this, 'postie_adminuser_warning'));
416 }
417 }
418 }
419
420 global $g_postie_init; //need to declare as global for wp cli
421 $g_postie_init = new PostieInit();
422 }
423