PluginProbe
Postie / 1.9.78
Postie v1.9.78
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.78, at postie.php

417 lines 16.6 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.78
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
209 function enable_post_by_email_configuration($enabled) {
210 return false;
211 }
212
213 function plugin_row_meta_filter($links, $file) {
214 if (strpos($file, strval(plugin_basename(__FILE__))) !== false) {
215 $new_links = array(
216 '<a href="http://postieplugin.com/" target="_blank">Support</a>',
217 '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=s-xclick&hosted_button_id=HPK99BJ88V4C2" target="_blank">Donate</a>'
218 );
219
220 $links = array_merge($links, $new_links);
221 }
222
223 return $links;
224 }
225
226 function parse_request_action($wp) {
227 if (array_key_exists('postie', $wp->query_vars)) {
228 switch ($wp->query_vars['postie']) {
229 case 'get-mail':
230 postie_get_mail();
231 die();
232 case 'test-config':
233 postie_test_config();
234 die();
235 default :
236 die('Unknown option: ' . htmlentities($wp->query_vars['postie']));
237 }
238 }
239 }
240
241 function admin_init_action() {
242 wp_register_style('postie-style', plugins_url('css/style.css', __FILE__));
243 register_setting('postie-settings', 'postie-settings', array($this, 'lazy_validate_settings'));
244 }
245
246 function lazy_validate_settings($in) {
247 $pconfig = new PostieConfig();
248 return $pconfig->config_ValidateSettings($in);
249 }
250
251 function admin_menu_action() {
252 $page = add_menu_page('Postie', 'Postie', 'manage_options', 'postie-settings', array($this, 'postie_show_config_page'));
253 add_action('admin_print_styles-' . $page, array($this, 'postie_admin_styles'));
254 }
255
256 function admin_head_action() {
257 ?>
258 <style type="text/css">
259 #adminmenu #toplevel_page_postie-settings div.wp-menu-image:before {
260 content: "\f466";
261 }
262 </style>
263 <?php
264
265 }
266
267 function whitelist_options_filter($options) {
268 $added = array('postie-settings' => array('postie-settings'));
269 return add_allowed_options($added, $options);
270 }
271
272 function cron_schedules_filter($schedules) {
273 //Do not echo output in filters, it seems to break some installs
274 //error_log("cron_schedules_filter: setting cron schedules");
275 $schedules['weekly'] = array('interval' => (60 * 60 * 24 * 7), 'display' => __('Once Weekly', 'postie'));
276 $schedules['twohours'] = array('interval' => 60 * 60 * 2, 'display' => __('Every 2 hours', 'postie'));
277 $schedules['twiceperhour'] = array('interval' => 60 * 30, 'display' => __('Twice per hour', 'postie'));
278 $schedules['tenminutes'] = array('interval' => 60 * 10, 'display' => __('Every 10 minutes', 'postie'));
279 $schedules['fiveminutes'] = array('interval' => 60 * 5, 'display' => __('Every 5 minutes', 'postie'));
280 $schedules['oneminute'] = array('interval' => 60 * 1, 'display' => __('Every 1 minute', 'postie'));
281 $schedules['thirtyseconds'] = array('interval' => 30, 'display' => __('Every 30 seconds', 'postie'));
282 $schedules['fifteenseconds'] = array('interval' => 15, 'display' => __('Every 15 seconds', 'postie'));
283 return $schedules;
284 }
285
286 function query_vars_filter($vars) {
287 $vars[] = 'postie';
288 return $vars;
289 }
290
291 function plugin_action_links_filter($links) {
292 $links[] = '<a href="admin.php?page=postie-settings">Settings</a>';
293 return $links;
294 }
295
296 function postie_show_config_page() {
297 global $g_postie;
298 require_once POSTIE_ROOT . '/config_form.php';
299 }
300
301 function postie_admin_styles() {
302 wp_enqueue_style('postie-style');
303 }
304
305 /**
306 * This function looks for markdown which causes problems with postie
307 */
308 function postie_isMarkdownInstalled() {
309 if (in_array("markdown.php", get_option("active_plugins"))) {
310 return true;
311 }
312 return false;
313 }
314
315 function postie_markdown_warning() {
316 echo "<div id='postie-lst-warning' class='error'><p><strong>";
317 _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');
318 echo "</strong></p></div>";
319 }
320
321 function postie_enter_info() {
322 echo "<div id='postie-info-warning' class='updated fade'><p><strong>" . __('Postie is almost ready.', 'postie') . "</strong> "
323 . sprintf(__('You must <a href="%1$s">enter your email settings</a> for it to work.', 'postie'), "admin.php?page=postie-settings")
324 . "</p></div> ";
325 }
326
327 function postie_iconv_warning() {
328 echo "<div id='postie-lst-warning' class='error'><p><strong>";
329 _e("Warning! Postie requires that iconv be enabled.", 'postie');
330 echo "</strong></p></div>";
331 }
332
333 function postie_php_warning() {
334 echo "<div id='postie-lst-warning' class='error'><p><strong>";
335 _e("Warning! Postie requires that PHP be verion 5.2 or higher. You have version " . phpversion(), 'postie');
336 echo "</strong></p></div>";
337 }
338
339 function postie_curl_warning() {
340 $cv = curl_version();
341 echo "<div id='postie-lst-warning' class='error'><p><strong>";
342 _e("Warning! Postie requires cURL 7.30.0 or newer be installed. {$cv['version']} is installed.", 'postie');
343 echo "</strong></p></div>";
344 }
345
346 function postie_adminuser_warning() {
347 echo "<div id='postie-mbstring-warning' class='error'><p><strong>";
348 echo __('Warning: the Default Poster is not a valid WordPress login. Postie may reject emails if this is not corrected.', 'postie');
349 echo "</strong></p></div>";
350 }
351
352 function postie_IsIconvInstalled($display = true) {
353 $function_list = array('iconv');
354 return($this->postie_HasFunctions($function_list, $display));
355 }
356
357 /**
358 * Handles verifying that a list of functions exists
359 * @return boolean
360 * @param array
361 */
362 function postie_HasFunctions($function_list, $display = true) {
363 foreach ($function_list as $function) {
364 if (!function_exists($function)) {
365 if ($display) {
366 EchoError("Missing $function");
367 }
368 return false;
369 }
370 }
371 return true;
372 }
373
374 function postie_warnings() {
375 $config = postie_config_read();
376
377 if ((empty($config->mail_server) ||
378 empty($config->mail_server_port) ||
379 empty($config->mail_userid) ||
380 empty($config->mail_password)
381 ) && !isset($_POST['submit'])) {
382
383 add_action('admin_notices', array($this, 'postie_enter_info'));
384 }
385
386 if ($this->postie_isMarkdownInstalled() && $config->prefer_text_type == 'html') {
387 add_action('admin_notices', array($this, 'postie_markdown_warning'));
388 }
389
390 if (!$this->postie_IsIconvInstalled()) {
391 add_action('admin_notices', array($this, 'postie_iconv_warning'));
392 }
393
394 if (!fCore::checkVersion('5.2.0')) {
395 add_action('admin_notices', array($this, 'postie_php_warning'));
396 }
397
398 if (function_exists('curl_version')) {
399 $cv = curl_version();
400 } else {
401 $cv['version'] = '1.0.0';
402 }
403 if ($config->input_connection == 'curl' && !version_compare($cv['version'], '7.30.0', 'ge')) {
404 add_action('admin_notices', array($this, 'postie_curl_warning'));
405 }
406
407 $userdata = WP_User::get_data_by('login', $config->admin_username);
408 if (!$userdata) {
409 add_action('admin_notices', array($this, 'postie_adminuser_warning'));
410 }
411 }
412 }
413
414 global $g_postie_init; //need to declare as global for wp cli
415 $g_postie_init = new PostieInit();
416 }
417