PluginProbe
Postie / 1.9.75
Postie v1.9.75
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.75, at postie.php

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