b2evolution PHP Cross Reference Blogging Systems

Source: /inc/cron/jobs/_post_by_email.job.php - 129 lines - 3964 bytes - Text - Print

Description: This file implements the post by mail cron job

   1  <?php
   2  /**
   3   * This file implements the post by mail cron job
   4   *
   5   * Uses MIME E-mail message parser classes written by Manuel Lemos: {@link http://www.phpclasses.org/browse/package/3169.html}
   6   *
   7   * @author Stephan Knauss
   8   * @author tblue246: Tilman Blumenbach
   9   * @author sam2kb: Alex
  10   *
  11   * TODO:
  12   * - Try more exotic email clients like mobile phones
  13   * - TODO Tested and working with thunderbird (text, html, signed), yahoo mail (text, html), outlook webmail, K800i
  14   * - Allow the user to choose whether to upload attachments to the blog media folder or to his user root.
  15   * - Create a copy of check_html_sanity function and clean up dangerous HTML code
  16   * - Add support for shortcodes instead of <tags> similar to:
  17   *    [title Your post title]
  18   *    [category x,y,z]
  19   *    [excerpt]some excerpt[/excerpt]
  20   *    [tags x,y,z]
  21   *    [delay +1 hour]
  22   *    [comments on | off]
  23   *    [status publish | pending | draft | private]
  24   *    [slug some-url-name]
  25   *    [end]  everything after this shortcode is ignored (i.e. signatures)
  26   *    [more]  more tag
  27   *    [nextpage]  pagination
  28   *
  29   * @version $Id: _post_by_email.job.php 5555 2014-01-03 00:10:21Z fplanque $
  30   */
  31  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  32  
  33  global $Settings, $DB, $result_message;
  34  global $pbm_item_files, $pbm_messages, $pbm_items, $post_cntr, $del_cntr, $is_cron_mode;
  35  
  36  // Are we in cron job mode?
  37  $is_cron_mode = 'yes';
  38  
  39  load_funcs( 'cron/model/_post_by_mail.funcs.php');
  40  
  41  if( ! $Settings->get( 'eblog_enabled' ) )
  42  {
  43      pbm_msg( T_('Post by email feature is not enabled.'), true );
  44      return 2; // error
  45  }
  46  
  47  if( ! extension_loaded('imap') )
  48  {
  49      pbm_msg( T_('The php_imap extension is not available to PHP on this server. Please load it in php.ini or ask your hosting provider to do so.'), true );
  50      return 2; // error
  51  }
  52  
  53  load_funcs( '_core/_param.funcs.php' );
  54  load_class( 'items/model/_itemlist.class.php', 'ItemList' );
  55  load_class( '_ext/mime_parser/rfc822_addresses.php', 'rfc822_addresses_class' );
  56  load_class( '_ext/mime_parser/mime_parser.php', 'mime_parser_class' );
  57  
  58  if( isset($GLOBALS['files_Module']) )
  59  {
  60      load_funcs( 'files/model/_file.funcs.php');
  61  }
  62  
  63  if( $Settings->get('eblog_test_mode') )
  64  {
  65      pbm_msg( T_('This is just a test run. Nothing will be posted to the database nor will your inbox be altered.'), true );
  66  }
  67  
  68  if( ! $mbox = pbm_connect() )
  69  {    // We couldn't connect to the mail server
  70      return 2; // error
  71  }
  72  
  73  // Read messages from server
  74  pbm_msg('Reading messages from server');
  75  $imap_obj = imap_check( $mbox );
  76  pbm_msg('Found '.$imap_obj->Nmsgs.' messages');
  77  
  78  if( $imap_obj->Nmsgs == 0 )
  79  {
  80      pbm_msg( T_('There are no messages in the mailbox'), true );
  81      imap_close( $mbox );
  82      return 1; // success
  83  }
  84  
  85  // Create posts
  86  pbm_process_messages( $mbox, $imap_obj->Nmsgs );
  87  
  88  if( ! $Settings->get('eblog_test_mode') && count($del_cntr) > 0 )
  89  {    // We want to delete processed emails from server
  90      imap_expunge( $mbox );
  91      pbm_msg( sprintf('Deleted %d processed message(s) from inbox.', $del_cntr) );
  92  }
  93  
  94  imap_close( $mbox );
  95  
  96  // Send reports
  97  if( $post_cntr > 0 )
  98  {
  99      pbm_msg( sprintf( T_('New posts created: %d'), $post_cntr ), true );
 100  
 101      $UserCache = & get_UserCache();
 102      foreach( $pbm_items as $Items )
 103      {    // Send report to post author
 104          $to_user_ID = 0;
 105          foreach( $Items as $Item )
 106          {
 107              if( $to_user_ID == 0 )
 108              {    // Get author ID
 109                  $to_user_ID = $Item->Author->ID;
 110                  break;
 111              }
 112          }
 113          $email_template_params = array(
 114                  'Items' => $Items
 115              );
 116          $to_User = $UserCache->get_by_ID( $to_user_ID );
 117          // Change locale here to localize the email subject and content
 118          locale_temp_switch( $to_User->get( 'locale' ) );
 119          send_mail_to_User( $to_user_ID, T_('Post by email report'), 'post_by_email_report', $email_template_params );
 120          locale_restore_previous();
 121      }
 122  
 123      // sam2kb> TODO: Send detailed report to blog owner
 124      // global $pbm_messages;
 125      // send_mail( $blog_owner_email, $blog_owner_name, T_('Post by email detailed report'), implode("\n",$pbm_messages) );
 126  }
 127  
 128  return 1; // success
 129  ?>

title

Description

title

Description

title

Description

title

title

Body