PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/php/wordpress/postie/postie.php

http://timoseven.googlecode.com/
PHP | 224 lines | 147 code | 23 blank | 54 comment | 19 complexity | a4d5ea2d92d113b8e872c4206f652b21 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-3.0, AGPL-1.0
  1. <?php
  2. /*
  3. Plugin Name: Postie
  4. Plugin URI: http://blog.robfelty.com/plugins/postie
  5. Description: Signifigantly upgrades the posting by mail features of Word Press (See <a href='options-general.php?page=postie/postie.php'>Settings and options</a>) to configure your e-mail settings. See the <a href='http://wordpress.org/extend/plugins/postie/other_notes'>Readme</a> for usage. Visit the <a href='http://forum.robfelty.com/forum/postie'>postie forum</a> for support.
  6. Version: 1.4.1
  7. Author: Robert Felty
  8. Author URI: http://blog.robfelty.com/
  9. */
  10. /*
  11. $Id: postie.php 234895 2010-04-28 19:59:08Z robfelty $
  12. * -= Requests Pending =-
  13. * German Umlats don't work
  14. * Problems under PHP5
  15. * Problem with some mail server
  16. * Multiple emails should tie to a single account
  17. * Each user should be able to have a default category
  18. * WP Switcher not compatible
  19. * Setup poll
  20. - web server
  21. - mail clients
  22. - plain/html
  23. - phone/computer
  24. - os of server
  25. - os of client
  26. - number of users posting
  27. * Test for calling from the command line
  28. * Support userid/domain as a valid username
  29. * WP-switcher not compatiable http://www.alexking.org/index.php?content=software/wordpress/content.php#wp_120
  30. * Test out a remote cron system
  31. * Add support for http://unknowngenius.com/wp-plugins/faq.html#one-click
  32. * www.cdavies.org/code/3gp-thumb.php.txt
  33. * www.cdavies.org/permalink/watchingbrowserembeddedgpvideosinlinux.php
  34. * Support private posts
  35. * Make it possible to post without a script at all
  36. */
  37. //Older Version History is in the HISTORY file
  38. //error_reporting(E_ALL & ~E_NOTICE);
  39. //ini_set("display_errors", 1);
  40. define("POSTIE_ROOT",dirname(__FILE__));
  41. define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
  42. function postie_loadjs_add_page() {
  43. $postiepage = add_options_page('Postie', 'Postie', 8, POSTIE_ROOT.'/postie.php', 'postie_loadjs_options_page');
  44. add_action( "admin_print_scripts-$postiepage", 'postie_loadjs_admin_head' );
  45. }
  46. function postie_loadjs_options_page() {
  47. require_once POSTIE_ROOT.'/config_form.php';
  48. }
  49. function postie_loadjs_admin_head() {
  50. $plugindir = get_settings('home').'/wp-content/plugins/'.dirname(plugin_basename(__FILE__));
  51. wp_enqueue_script('loadjs', $plugindir . '/js/simpleTabs.jquery.js');
  52. echo '<link type="text/css" rel="stylesheet" href="' .get_bloginfo('url') .'/wp-content/plugins/postie/css/style.css" />'."\n";
  53. echo '<link type="text/css" rel="stylesheet" href="' .get_bloginfo('url') .'/wp-content/plugins/postie/css/simpleTabs.css" />'."\n";
  54. }
  55. if (isset($_GET["postie_read_me"])) {
  56. include_once(ABSPATH . "wp-admin/admin.php");
  57. $title = __("Edit Plugins");
  58. $parent_file = 'plugins.php';
  59. include(ABSPATH . 'wp-admin/admin-header.php');
  60. postie_read_me();
  61. include(ABSPATH . 'wp-admin/admin-footer.php');
  62. }
  63. //Add Menu Configuration
  64. if (is_admin()) {
  65. require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR ."postie-functions.php");
  66. //add_action("admin_menu","PostieMenu");
  67. add_action( 'admin_init', 'postie_admin_settings' );
  68. add_action('admin_menu', 'postie_loadjs_add_page');
  69. if(function_exists('load_plugin_textdomain')){
  70. $plugin_dir = WP_PLUGIN_DIR . '/' . basename(dirname(__FILE__));
  71. function postie_load_domain() {
  72. load_plugin_textdomain( 'postie', $plugin_dir."/languages/",
  73. basename(dirname(__FILE__)). '/languages/');
  74. }
  75. add_action('init', 'postie_load_domain');
  76. }
  77. postie_warnings();
  78. }
  79. function activate_postie() {
  80. static $init = false;
  81. $options = get_option( 'postie-settings' );
  82. if ( $init ) return;
  83. if(!$options) {
  84. $options = array();
  85. }
  86. $default_options = get_config_defaults();
  87. $old_config = array();
  88. $updated = false;
  89. $migration = false;
  90. /*
  91. global $wpdb;
  92. $GLOBALS["table_prefix"]. "postie_config";
  93. $result = $wpdb->get_results("SELECT label,value FROM $postietable ;");
  94. */
  95. $result = GetConfig();
  96. if (is_array($result)) {
  97. foreach ( $result as $key => $val ) {
  98. $old_config[strtolower( $key )] = $val;
  99. }
  100. }
  101. // overlay the options on top of each other:
  102. // the current value of $options takes priority over the $old_config, which takes priority over the $default_options
  103. $options = array_merge( $default_options, $old_config, $options );
  104. $options = postie_validate_settings( $options );
  105. update_option( 'postie-settings', $options );
  106. $init = true;
  107. // $wpdb->query("DROP TABLE IF EXISTS $postietable"); // safely updated options, so we can remove the old table
  108. return $options;
  109. }
  110. register_activation_hook(__FILE__, 'activate_postie');
  111. /**
  112. * set up actions to show relevant warnings,
  113. * if mail server is not set, or if IMAP extension is not available
  114. */
  115. function postie_warnings() {
  116. $config = get_option( 'postie-settings' );
  117. if ( (empty( $config['mail_server'] ) ||
  118. empty( $config['mail_server_port'] ) ||
  119. empty( $config['mail_userid'] ) ||
  120. empty( $config['mail_password'] )
  121. ) && !isset($_POST['submit'] ) ) {
  122. function postie_enter_info() {
  123. echo "
  124. <div id='postie-info-warning' class='updated fade'><p><strong>".
  125. __('Postie is almost ready.', 'postie')."</strong> "
  126. .sprintf(__('You must <a href="%1$s">enter your email settings</a> for it to work.','postie'), "options-general.php?page=postie/postie.php")."</p></div> ";
  127. }
  128. add_action('admin_notices', 'postie_enter_info');
  129. }
  130. if (!function_exists('imap_mime_header_decode') && $_GET['activate']==true) {
  131. function postie_imap_warning() {
  132. echo "<div id='postie-imap-warning' class='error'><p><strong>";
  133. echo __('Warning: the IMAP php extension is not installed.', 'postie');
  134. echo __('Postie may not function correctly without this extension (especially for non-English messages).', 'postie');
  135. echo "</strong> ";
  136. //echo __('Warning: the IMAP php extension is not installed. Postie may not function correctly without this extension (especially for non-English messages) .', 'postie')."</strong> ".
  137. echo sprintf(__('Please see the <a href="%1$s">FAQ </a> for more information.'), "options-general.php?page=postie/postie.php", 'postie')."</p></div> ";
  138. }
  139. add_action('admin_notices', 'postie_imap_warning');
  140. }
  141. }
  142. function disable_kses_content() {
  143. remove_filter('content_save_pre', 'wp_filter_post_kses');
  144. }
  145. add_action('init','disable_kses_content',20);
  146. function postie_whitelist($options) {
  147. $added = array( 'postie-settings' => array( 'postie-settings' ) );
  148. $options = add_option_whitelist( $added, $options );
  149. return $options;
  150. }
  151. add_filter('whitelist_options', 'postie_whitelist');
  152. function check_postie() {
  153. $host = get_option('siteurl');
  154. preg_match("/https?:\/\/(.[^\/]*)(.*)/",$host,$matches);
  155. $host = $matches[1];
  156. $url = "";
  157. if (isset($matches[2])) {
  158. $url .= $matches[2];
  159. }
  160. $url .= "/wp-content/plugins/postie/get_mail.php";
  161. $port = 80;
  162. $fp=fsockopen($host,$port,$errno,$errstr);
  163. fputs($fp,"GET $url HTTP/1.0\r\n");
  164. fputs($fp,"User-Agent: Cronless-Postie\r\n");
  165. fputs($fp,"Host: $host\r\n");
  166. fputs($fp,"\r\n");
  167. $page = '';
  168. while(!feof($fp)) {
  169. $page.=fgets($fp,128);
  170. }
  171. fclose($fp);
  172. }
  173. function postie_cron($interval=false) {
  174. if (!$interval) {
  175. $config=get_option('postie-settings');
  176. $interval = $config['interval'];
  177. }
  178. if (!$interval || $interval=='')
  179. $interval='hourly';
  180. if ($interval=='manual') {
  181. wp_clear_scheduled_hook('check_postie_hook');
  182. } else {
  183. wp_schedule_event(time(),$interval,'check_postie_hook');
  184. }
  185. }
  186. function postie_decron() {
  187. wp_clear_scheduled_hook('check_postie_hook');
  188. }
  189. /* here we add some more options for how often to check for e-mail */
  190. function more_reccurences() {
  191. return array(
  192. 'weekly' => array('interval' => 604800, 'display' => 'Once Weekly'),
  193. 'twiceperhour' => array('interval' => 1800, 'display' => 'Twice per hour '),
  194. 'tenminutes' =>array('interval' => 600, 'display' => 'Every 10 minutes')
  195. );
  196. }
  197. add_filter('cron_schedules', 'more_reccurences');
  198. register_activation_hook(__FILE__,'postie_cron');
  199. register_deactivation_hook(__FILE__,'postie_decron');
  200. add_action('check_postie_hook', 'check_postie');
  201. ?>