Postie - Version 1.4.20

Version Description

(2013.01.08) = * Added Date feature. You can now specify a specific publication date. * Fixed a bug with embeded youtube/vimeo links when shortcodes are turned off

Download this release

Release Info

Developer WayneAllen
Plugin Icon 128x128 Postie
Version 1.4.20
Comparing to
See all releases

Code changes from version 1.4.17 to 1.4.20

Revision CHANGED
@@ -1,2 +1,2 @@
1
- Revision: 647507
2
- Last Changed Date: 2013-01-02 20:29:18 -0800 (Wed, 02 Jan 2013)
1
+ Revision: 649983
2
+ Last Changed Date: 2013-01-07 17:05:33 -0800 (Mon, 07 Jan 2013)
config_form.php CHANGED
@@ -22,7 +22,7 @@
22
  if (isset($_POST["action"])) {
23
  switch ($_POST["action"]) {
24
  case "reset":
25
- ResetPostieConfig();
26
  $message = 1;
27
  break;
28
  case "cronless":
@@ -49,9 +49,9 @@
49
  $parent_file = 'options-general.php';
50
  $config = get_option('postie-settings');
51
  if (empty($config))
52
- $config = ResetPostieConfig();
53
 
54
- $arrays = get_arrayed_settings();
55
  // some fields are stored as arrays, because that makes back-end processing much easier
56
  // and we need to convert those fields to strings here, for the options form
57
  foreach ($arrays as $sep => $fields) {
22
  if (isset($_POST["action"])) {
23
  switch ($_POST["action"]) {
24
  case "reset":
25
+ config_ResetToDefault();
26
  $message = 1;
27
  break;
28
  case "cronless":
49
  $parent_file = 'options-general.php';
50
  $config = get_option('postie-settings');
51
  if (empty($config))
52
+ $config = config_ResetToDefault();
53
 
54
+ $arrays = config_ArrayedSettings();
55
  // some fields are stored as arrays, because that makes back-end processing much easier
56
  // and we need to convert those fields to strings here, for the options form
57
  foreach ($arrays as $sep => $fields) {
docs/Changes.txt CHANGED
@@ -1,8 +1,20 @@
1
  == Upgrade Notice ==
2
  * Attachments are now processed in the order they were attached.
3
  * All script, style and body tags are stripped from html emails.
 
4
 
5
  == CHANGELOG ==
 
 
 
 
 
 
 
 
 
 
 
6
  = 1.4.17 (2013.01.03) =
7
  * Fixed a bug where non image/video attachments were not getting added to the post.
8
 
1
  == Upgrade Notice ==
2
  * Attachments are now processed in the order they were attached.
3
  * All script, style and body tags are stripped from html emails.
4
+ * Many method names have been changed as of 1.4.18. Any custom filters may need to be updated.
5
 
6
  == CHANGELOG ==
7
+ = 1.4.20 (2013.01.08) =
8
+ * Added Date feature. You can now specify a specific publication date.
9
+ * Fixed a bug with embeded youtube/vimeo links when shortcodes are turned off
10
+
11
+ = 1.4.19 (2013.01.07) =
12
+ * Fixed a bug that prevented the settings from being saved
13
+
14
+ = 1.4.18 (2013.01.06) =
15
+ * Fixed a bug where linkifying was doing too much.
16
+ * Updated lots of method names in preparation for some significant structural changes.
17
+
18
  = 1.4.17 (2013.01.03) =
19
  * Fixed a bug where non image/video attachments were not getting added to the post.
20
 
docs/Postie.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
- Stable tag: 1.4.17
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
+ Stable tag: 1.4.20
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
docs/Usage.txt CHANGED
@@ -1,6 +1,8 @@
1
  == Usage ==
2
- * If you put in :start - the message processing won't start until it sees that string
3
- * If you put in :end - the message processing will stop once it sees that string
 
 
4
  * Posts can be delayed by adding a line with delayXdXhXm where X is a number.
5
  * delay:1d - 1 day
6
  * delay:1h - 1 hour
1
  == Usage ==
2
+ * If you put in :start - the message processing won't start until it sees that string.
3
+ * If you put in :end - the message processing will stop once it sees that string.
4
+ * Posts can have a specific publication date.
5
+ * date: <date>
6
  * Posts can be delayed by adding a line with delayXdXhXm where X is a number.
7
  * delay:1d - 1 day
8
  * delay:1h - 1 hour
postie-functions.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  /*
4
- $Id: postie-functions.php 647656 2013-01-04 00:20:35Z WayneAllen $
5
  */
6
 
7
  /* TODO
@@ -130,6 +130,19 @@ function DebugEcho($v) {
130
  }
131
  }
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  /**
134
  * This is the main handler for all of the processing
135
  */
@@ -147,7 +160,7 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
147
  EchoInfo("Message Id is :" . htmlentities($mimeDecodedEmail->headers["message-id"]));
148
  //DebugDump($mimeDecodedEmail);
149
 
150
- FilterTextParts($mimeDecodedEmail, $prefer_text_type);
151
  //DebugDump($mimeDecodedEmail);
152
 
153
  $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost');
@@ -161,16 +174,16 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
161
  //DebugEcho("the content is $content");
162
 
163
  $subject = GetSubject($mimeDecodedEmail, $content, $config);
164
- //DebugEcho("post subject: $content");
165
 
166
  $customImages = SpecialMessageParsing($content, $attachments, $config);
167
- //DebugEcho("post special message: $content");
168
 
169
- $post_excerpt = GetPostExcerpt($content, $filternewlines, $convertnewline);
170
- //DebugEcho("post exerpt: $content");
171
 
172
  $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
173
- //DebugEcho("post author: $content");
174
 
175
  $message_date = NULL;
176
  if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
@@ -184,24 +197,27 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
184
  }
185
  $message_date = HandleMessageEncoding($cte, $cs, $mimeDecodedEmail->headers["date"], $message_encoding, $message_dequote);
186
  }
 
 
187
  list($post_date, $post_date_gmt, $delay) = DeterminePostDate($content, $message_date, $time_offset);
188
- //DebugEcho("post date: $content");
189
 
190
- ubb2HTML($content);
191
- //DebugEcho("post ubb: $content");
192
 
193
  if ($converturls) {
194
- $content = clickableLink($content, $shortcode);
195
- //DebugEcho("post clickable: $content");
 
196
  }
197
 
198
  $id = checkReply($subject);
199
- $post_categories = GetPostCategories($subject, $default_post_category);
200
- $post_tags = postie_get_tags($content, $default_post_tags);
201
- //DebugEcho("post tags: $content");
202
 
203
- $comment_status = AllowCommentsOnPost($content);
204
- //DebugEcho("post comment: $content");
205
 
206
  if ((empty($id) || is_null($id))) {
207
  $id = $post_id;
@@ -238,7 +254,7 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
238
  wp_delete_post($post_id);
239
  }
240
  if ($filternewlines) {
241
- $content = FilterNewLines($content, $convertnewline);
242
  //DebugEcho("post filter newlines: $content");
243
  }
244
 
@@ -248,7 +264,7 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
248
  $post_status = $post_status;
249
  }
250
 
251
- $post_type = GetPostType($subject);
252
 
253
  //DebugEcho("pre-insert content: $content");
254
 
@@ -308,7 +324,7 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
308
  * Custom Post Type name to the email subject separated by
309
  * $custom_post_type_delim, e.g. "Movies // My Favorite Movie"
310
  */
311
- function GetPostType(&$subject) {
312
 
313
  $custom_post_type_delim = "//";
314
  if (strpos($subject, $custom_post_type_delim) !== FALSE) {
@@ -335,13 +351,49 @@ function GetPostType(&$subject) {
335
  return $post_type;
336
  }
337
 
338
- function clickableLink($text, $shortcode = false) {
339
- # this functions deserves credit to the fine folks at phpbb.com
340
  # It turns urls into links, and video urls into embedded players
341
- //DebugEcho("begin: clickableLink");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
- $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
344
- //DebugEcho($text);
 
345
  // pad it with a space so we can match things at the start of the 1st line.
346
  $ret = ' ' . $text;
347
  if (strpos($ret, 'youtube') !== false) {
@@ -350,7 +402,7 @@ function clickableLink($text, $shortcode = false) {
350
  if ($shortcode) {
351
  $youtube_replace = "\\1[youtube \\3]\\4";
352
  } else {
353
- $youtube_replace = "\\1<embed width='425' height='344' allowfullscreen='true' allowscriptaccess='always' type='application/x-shockwave-flash' src=\"http://www.youtube.com/v/\\3&hl=en&fs=1\" />\\4";
354
  }
355
  $ret = preg_replace($youtube, $youtube_replace, $ret);
356
  //DebugEcho("youtube: $ret");
@@ -369,18 +421,8 @@ function clickableLink($text, $shortcode = false) {
369
  //DebugEcho("vimeo: $ret");
370
  }
371
 
372
- // matches an "xxxx://yyyy" URL at the start of a line, or after a space.
373
- // xxxx can only be alpha characters.
374
- // yyyy is anything up to the first space, newline, comma, double quote or <
375
- $ret = preg_replace("#(^|[\n ])<?([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)>?#is", "\\1<a href=\"\\2\" >\\2</a>", $ret);
376
- //DebugEcho("xxxx://yyyy: $ret");
377
- // matches a "www|ftp.xxxx.yyyy[/zzzz]" kinda lazy URL thing
378
- $ret = make_links($ret);
379
- //DebugEcho("www|ftp.xxxx.yyyy[/zzzz]: $ret");
380
  // Remove our padding..
381
  $ret = substr($ret, 1);
382
-
383
- //DebugEcho("end: clickableLink");
384
  return $ret;
385
  }
386
 
@@ -407,11 +449,12 @@ function make_links($text) {
407
  );
408
  }
409
 
 
 
 
 
 
410
  function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail) {
411
- /* we check whether or not the e-mail is a forwards or a redirect. If it is
412
- * a fwd, then we glean the author details from the body of the post.
413
- * Otherwise we get them from the headers
414
- */
415
  global $wpdb;
416
 
417
  $theDate = $mimeDecodedEmail->headers['date'];
@@ -461,15 +504,15 @@ function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail) {
461
  return($theDetails);
462
  }
463
 
464
- function checkReply(&$subject) {
465
- /* we check whether or not the e-mail is a reply to a previously
466
- * published post. First we check whether it starts with Re:, and then
467
- * we see if the remainder matches an already existing post. If so,
468
- * then we add that post id to the details array, which will cause the
469
- * existing post to be overwritten, instead of a new one being
470
- * generated
471
- */
472
 
 
473
  global $wpdb;
474
 
475
  $id = NULL;
@@ -499,7 +542,7 @@ function checkReply(&$subject) {
499
  return $id;
500
  }
501
 
502
- function postie_read_me() {
503
  include(POSTIE_ROOT . DIRECTORY_SEPARATOR . "postie_read_me.php");
504
  }
505
 
@@ -515,7 +558,7 @@ function PostieMenu() {
515
  }
516
 
517
  /**
518
- * This handles actually showing the form
519
  */
520
  function ConfigurePostie() {
521
  include(POSTIE_ROOT . DIRECTORY_SEPARATOR . "config_form.php");
@@ -693,7 +736,7 @@ function PostToDB($details, $isReply, $postToDb = true, $customImageField = fals
693
  * @param string
694
  * @return boolean
695
  */
696
- function BannedFileName($filename, $bannedFiles) {
697
  if (empty($filename) || empty($bannedFiles))
698
  return false;
699
  foreach ($bannedFiles as $bannedFile) {
@@ -716,11 +759,11 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
716
 
717
  //look for banned file names
718
  if (property_exists($part, 'ctype_parameters') && is_array($part->ctype_parameters) && array_key_exists('name', $part->ctype_parameters))
719
- if (BannedFileName($part->ctype_parameters['name'], $banned_files_list))
720
  return NULL;
721
 
722
  if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") {
723
- if ($part->disposition == "attachment") {
724
  $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg");
725
  foreach ($image_endings as $type) {
726
  if (eregi(".$type\$", $part->d_parameters["filename"])) {
@@ -731,7 +774,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
731
  }
732
  } else {
733
  $mimeDecodedEmail = DecodeMIMEMail($part->body);
734
- FilterTextParts($mimeDecodedEmail, $prefer_text_type);
735
  foreach ($mimeDecodedEmail->parts as $section) {
736
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
737
  }
@@ -741,8 +784,8 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
741
  if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") {
742
  DebugEcho("multipart appledouble");
743
  $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body);
744
- FilterTextParts($mimeDecodedEmail, $prefer_text_type);
745
- FilterAppleFile($mimeDecodedEmail);
746
  foreach ($mimeDecodedEmail->parts as $section) {
747
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
748
  }
@@ -757,9 +800,9 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
757
  case 'multipart':
758
  DebugEcho("multipart: " . count($part->parts));
759
  //DebugDump($part);
760
- FilterTextParts($part, $prefer_text_type);
761
  foreach ($part->parts as $section) {
762
- DebugDump($section->headers);
763
 
764
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
765
  }
@@ -794,11 +837,11 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
794
  if ($part->ctype_secondary == 'enriched') {
795
  //convert enriched text to HTML
796
  DebugEcho("enriched");
797
- $meta_return .= etf2HTML($part->body) . "\n";
798
  } elseif ($part->ctype_secondary == 'html') {
799
  //strip excess HTML
800
  DebugEcho("html");
801
- $meta_return .= HTML2HTML($part->body) . "\n";
802
  } else {
803
  DebugEcho("plain text");
804
  if ($allow_html_in_body) {
@@ -809,7 +852,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
809
  DebugEcho("html not allowed (htmlentities)");
810
  $meta_return .= htmlentities($part->body);
811
  }
812
- $meta_return = StripPGP($meta_return);
813
  }
814
 
815
  break;
@@ -820,6 +863,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
820
  $cid = "";
821
  if (array_key_exists('content-id', $part->headers)) {
822
  $cid = trim($part->headers["content-id"], "<>");
 
823
  }
824
 
825
  $the_post = get_post($file_id);
@@ -899,7 +943,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
899
  return $meta_return;
900
  }
901
 
902
- function ubb2HTML(&$text) {
903
  // Array of tags with opening and closing
904
  $tagArray['img'] = array('open' => '<img src="', 'close' => '">');
905
  $tagArray['b'] = array('open' => '<b>', 'close' => '</b>');
@@ -929,7 +973,7 @@ function ubb2HTML(&$text) {
929
  // This function turns Enriched Text into something similar to HTML
930
  // Very basic at the moment, only supports some functionality and dumps the rest
931
  // FIXME: fix colours: <color><param>FFFF,C2FE,0374</param>some text </color>
932
- function etf2HTML($content) {
933
 
934
  $search = array(
935
  '/<bold>/',
@@ -972,7 +1016,7 @@ function etf2HTML($content) {
972
  }
973
 
974
  // This function cleans up HTML in the e-mail
975
- function HTML2HTML($content) {
976
  $html = str_get_html($content);
977
  if ($html) {
978
  DebugEcho("Looking for invalid tags");
@@ -1020,11 +1064,11 @@ function ValidatePoster(&$mimeDecodedEmail, $config) {
1020
  } else {
1021
  $poster = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$admin_username'");
1022
  }
1023
- } elseif ($turn_authorization_off || CheckEmailAddress($from, $authorized_addresses) || CheckEmailAddress($resentFrom, $authorized_addresses)) {
1024
  $poster = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$admin_username'");
1025
  }
1026
 
1027
- $validSMTP = checkSMTP($mimeDecodedEmail, $smtp);
1028
  if (!$poster || !$validSMTP) {
1029
  EchoInfo('Invalid sender: ' . htmlentities($from) . "! Not adding email!");
1030
  if ($forward_rejected_mail) {
@@ -1040,12 +1084,7 @@ function ValidatePoster(&$mimeDecodedEmail, $config) {
1040
  return $poster;
1041
  }
1042
 
1043
- function post_as_admin($admin_username) {
1044
- EchoInfo("$from is authorized to post as the administrator");
1045
- return $poster;
1046
- }
1047
-
1048
- function checkSMTP($mimeDecodedEmail, $smtpservers) {
1049
  if (empty($smtpservers))
1050
  return true;
1051
 
@@ -1068,7 +1107,7 @@ function checkSMTP($mimeDecodedEmail, $smtpservers) {
1068
  * @param string
1069
  * @param string
1070
  */
1071
- function StartFilter($content, $start) {
1072
  $pos = strpos($content, $start);
1073
  if ($pos === false) {
1074
  return $content;
@@ -1083,7 +1122,7 @@ function StartFilter($content, $start) {
1083
  * @param string
1084
  * @param array - a list of patterns to determine if it is a sig block
1085
  */
1086
- function remove_signature($content, $filterList) {
1087
  if (empty($filterList))
1088
  return $content;
1089
  $arrcontent = explode("\n", $content);
@@ -1105,7 +1144,7 @@ function remove_signature($content, $filterList) {
1105
  * @param string
1106
  * @param filter
1107
  */
1108
- function EndFilter($content, $end) {
1109
  $pos = strpos($content, $end);
1110
  if ($pos === false)
1111
  return $content;
@@ -1114,7 +1153,7 @@ function EndFilter($content, $end) {
1114
  }
1115
 
1116
  //filter content for new lines
1117
- function FilterNewLines($content, $convertNewLines = false) {
1118
  $search = array(
1119
  "/\r\n/",
1120
  "/\r/",
@@ -1141,7 +1180,7 @@ function FilterNewLines($content, $convertNewLines = false) {
1141
  }
1142
 
1143
  //strip pgp stuff
1144
- function StripPGP($content) {
1145
  $search = array(
1146
  '/-----BEGIN PGP SIGNED MESSAGE-----/',
1147
  '/Hash: SHA1/'
@@ -1225,7 +1264,7 @@ function DecodeBase64Part(&$part) {
1225
  * Checks for the comments tag
1226
  * @return boolean
1227
  */
1228
- function AllowCommentsOnPost(&$content) {
1229
  $comments_allowed = get_option('default_comment_status'); // 'open' or 'closed'
1230
 
1231
  if (preg_match("/comments:([0|1|2])/i", $content, $matches)) {
@@ -1243,6 +1282,8 @@ function AllowCommentsOnPost(&$content) {
1243
 
1244
  /**
1245
  * Needed to be able to modify the content to remove the usage of the delay tag
 
 
1246
  */
1247
  function DeterminePostDate(&$content, $message_date = NULL, $offset = 0) {
1248
  $delay = 0;
@@ -1285,7 +1326,7 @@ function DeterminePostDate(&$content, $message_date = NULL, $offset = 0) {
1285
  /**
1286
  * This function takes the content of the message - looks for a subject at the begining surrounded by # and then removes that from the content
1287
  */
1288
- function ParseInMessageSubject($content, $defaultTitle) {
1289
  DebugEcho("Looking for subject in email body");
1290
  if (substr($content, 0, 1) != "#") {
1291
  DebugEcho("No subject found, using default [1]");
@@ -1306,7 +1347,7 @@ function ParseInMessageSubject($content, $defaultTitle) {
1306
  * this part of the file attachment is not supported
1307
  * @param object
1308
  */
1309
- function FilterAppleFile(&$mimeDecodedEmail) {
1310
  $newParts = array();
1311
  $found = false;
1312
  for ($i = 0; $i < count($mimeDecodedEmail->parts); $i++) {
@@ -1530,7 +1571,7 @@ function postie_handle_upload(&$file, $overrides = false, $time = null) {
1530
  * that type is present it filters out all other text types. If it is not - then nothing is done
1531
  * @param object
1532
  */
1533
- function FilterTextParts($mimeDecodedEmail, $preferTextType) {
1534
  DebugEcho("FilterTextParts: begin " . count($mimeDecodedEmail->parts));
1535
  $newParts = array();
1536
  $found = false;
@@ -1690,7 +1731,7 @@ function DisplayMIMEPartTypes($mimeDecodedEmail) {
1690
  * @param string - email address
1691
  * @return boolean
1692
  */
1693
- function CheckEmailAddress($address, $authorized) {
1694
  $r = false;
1695
  if (is_array($authorized)) {
1696
  $a = strtolower(trim($address));
@@ -1715,7 +1756,7 @@ function RemoveExtraCharactersInEmailAddress($address) {
1715
  $address = $matches[1];
1716
  }
1717
 
1718
- return($address);
1719
  }
1720
 
1721
  /**
@@ -1865,7 +1906,7 @@ function parseTemplate($id, $type, $template, $size = 'medium') {
1865
  * @param string - text of post
1866
  * @param array - array of HTML for images for post
1867
  */
1868
- function ReplaceImageCIDs(&$content, &$attachments) {
1869
  DebugEcho("ReplaceImageCIDs");
1870
  $used = array();
1871
  foreach ($attachments["cids"] as $key => $info) {
@@ -1876,19 +1917,19 @@ function ReplaceImageCIDs(&$content, &$attachments) {
1876
  $used[] = $info[1]; //Index of html to ignore
1877
  }
1878
  }
1879
- //DebugEcho("# cid attachments: " . count($used));
1880
 
1881
  $html = array();
1882
- // $att = array_values($attachments["html"]); //make sure there are numeric indexes
1883
- // DebugEcho('$attachments');
1884
- // DebugDump($attachments);
1885
- // DebugEcho('$used');
1886
- // DebugDump($used);
1887
- // for ($i = 0; $i < count($attachments["html"]); $i++) {
1888
- // if (!in_array($i, $used)) {
1889
- // $html[] = $att[$i];
1890
- // }
1891
- // }
1892
 
1893
  foreach ($attachments['html'] as $key => $value) {
1894
  if (!in_array($value, $used)) {
@@ -1905,7 +1946,7 @@ function ReplaceImageCIDs(&$content, &$attachments) {
1905
  * @param string - text of post
1906
  * @param array - array of HTML for images for post
1907
  */
1908
- function ReplaceImagePlaceHolders(&$content, $attachments, $config) {
1909
  extract($config);
1910
  if (!$allow_html_in_body) {
1911
  $content = html_entity_decode($content, ENT_QUOTES);
@@ -1984,7 +2025,7 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
1984
  if (!array_key_exists('subject', $mimeDecodedEmail->headers) || empty($mimeDecodedEmail->headers['subject'])) {
1985
  DebugEcho("No subject in email");
1986
  if ($allow_subject_in_mail) {
1987
- list($subject, $content) = ParseInMessageSubject($content, $default_title);
1988
  } else {
1989
  DebugEcho("Using default subject");
1990
  $subject = $default_title;
@@ -1992,8 +2033,13 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
1992
  $mimeDecodedEmail->headers['subject'] = $subject;
1993
  } else {
1994
  $subject = $mimeDecodedEmail->headers['subject'];
 
1995
  DebugEcho(("Predecoded subject: $subject"));
1996
 
 
 
 
 
1997
  if (array_key_exists('content-transfer-encoding', $mimeDecodedEmail->headers)) {
1998
  $encoding = $mimeDecodedEmail->headers["content-transfer-encoding"];
1999
  } else if (array_key_exists("content-transfer-encoding", $mimeDecodedEmail->ctype_parameters)) {
@@ -2042,7 +2088,7 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
2042
  * this function determines tags for the post
2043
  *
2044
  */
2045
- function postie_get_tags(&$content, $defaultTags) {
2046
  $post_tags = array();
2047
  //try and determine tags
2048
  if (preg_match('/tags: ?(.*)$/im', $content, $matches)) {
@@ -2063,13 +2109,13 @@ function postie_get_tags(&$content, $defaultTags) {
2063
  * this function determines excerpt for the post
2064
  *
2065
  */
2066
- function GetPostExcerpt(&$content, $filterNewLines, $convertNewLines) {
2067
  $post_excerpt = '';
2068
  if (preg_match('/:excerptstart ?(.*):excerptend/s', $content, $matches)) {
2069
  $content = str_replace($matches[0], "", $content);
2070
  $post_excerpt = $matches[1];
2071
  if ($filterNewLines)
2072
- $post_excerpt = FilterNewLines($post_excerpt, $convertNewLines);
2073
  }
2074
  return $post_excerpt;
2075
  }
@@ -2078,7 +2124,7 @@ function GetPostExcerpt(&$content, $filterNewLines, $convertNewLines) {
2078
  * This function determines categories for the post
2079
  * @return array
2080
  */
2081
- function GetPostCategories(&$subject, $defaultCategory) {
2082
  global $wpdb;
2083
  $original_subject = $subject;
2084
  $post_categories = array();
@@ -2098,7 +2144,7 @@ function GetPostCategories(&$subject, $defaultCategory) {
2098
  $matchtypes[] = $matches;
2099
  }
2100
  if (preg_match('/(.+): (.*)/', $subject, $matches)) { // <category>:<Subject>
2101
- $category = CategoryLookup($matches[1]);
2102
  if (!empty($category)) {
2103
  $subject = trim($matches[2]);
2104
  $post_categories[] = $category;
@@ -2108,7 +2154,7 @@ function GetPostCategories(&$subject, $defaultCategory) {
2108
  foreach ($matchtypes as $matches) {
2109
  if (count($matches)) {
2110
  foreach ($matches[1] as $match) {
2111
- $category = CategoryLookup($match);
2112
  if (!empty($category)) {
2113
  $post_categories[] = $category;
2114
  }
@@ -2122,7 +2168,7 @@ function GetPostCategories(&$subject, $defaultCategory) {
2122
  return $post_categories;
2123
  }
2124
 
2125
- function CategoryLookup($trial_category) {
2126
  global $wpdb;
2127
  $trial_category = trim($trial_category);
2128
  $found_category = NULL;
@@ -2211,14 +2257,14 @@ function BuildTextArea($label, $id, $current_value, $recommendation = NULL) {
2211
  /**
2212
  * This function resets all the configuration options to the default
2213
  */
2214
- function ResetPostieConfig() {
2215
- $newconfig = get_postie_config_defaults();
2216
  $config = get_option('postie-settings');
2217
  $save_keys = array('mail_password', 'mail_server', 'mail_server_port', 'mail_userid', 'iinput_protocol');
2218
  foreach ($save_keys as $key)
2219
  $newconfig[$key] = $config[$key];
2220
  update_option('postie-settings', $newconfig);
2221
- UpdatePostieConfig($newconfig);
2222
  return $newconfig;
2223
  }
2224
 
@@ -2226,7 +2272,7 @@ function ResetPostieConfig() {
2226
  * This function used to handle updating the configuration.
2227
  * @return boolean
2228
  */
2229
- function UpdatePostieConfig($data) {
2230
  UpdatePostiePermissions($data["role_access"]);
2231
  // We also update the cron settings
2232
  if ($data['interval'] != '') {
@@ -2235,13 +2281,12 @@ function UpdatePostieConfig($data) {
2235
  postie_cron($interval = $data['interval']);
2236
  }
2237
  }
2238
- return(1);
2239
  }
2240
 
2241
  /**
2242
  * return an array of the config defaults
2243
  */
2244
- function get_postie_config_defaults() {
2245
  include('templates/audio_templates.php');
2246
  include('templates/image_templates.php');
2247
  include('templates/video1_templates.php');
@@ -2307,9 +2352,7 @@ function get_postie_config_defaults() {
2307
  'video2types' => array('x-flv'),
2308
  'video1templates' => $video1Templates,
2309
  'video2templates' => $video2Templates,
2310
- 'wrap_pre' => 'no
2311
-
2312
- '
2313
  );
2314
  }
2315
 
@@ -2318,7 +2361,7 @@ function get_postie_config_defaults() {
2318
  * the following functions are only used to retrieve the old (pre 1.4) config, to convert it
2319
  * to the new format
2320
  */
2321
- function GetListOfArrayConfig() {
2322
  return(array('SUPPORTED_FILE_TYPES', 'AUTHORIZED_ADDRESSES',
2323
  'SIG_PATTERN_LIST', 'BANNED_FILES_LIST', 'VIDEO1TYPES',
2324
  'VIDEO2TYPES', 'AUDIOTYPES', 'SMTP'));
@@ -2328,17 +2371,15 @@ function GetListOfArrayConfig() {
2328
  * This function retrieves the old-format config (pre 1.4) from the database
2329
  * @return array
2330
  */
2331
- function ReadDBConfig() {
2332
  $config = array();
2333
  global $wpdb;
2334
- $wpdb->query("SHOW TABLES LIKE '
2335
-
2336
- " . $GLOBALS["table_prefix"] . "postie_config'");
2337
  if ($wpdb->num_rows > 0) {
2338
  $data = $wpdb->get_results("SELECT label,value FROM " . $GLOBALS["table_prefix"] . "postie_config;");
2339
  if (is_array($data)) {
2340
  foreach ($data as $row) {
2341
- if (in_array($row->label, GetListOfArrayConfig())) {
2342
  $config[$row->label] = unserialize($row->value);
2343
  } else {
2344
  $config[$row->label] = $row->value;
@@ -2354,8 +2395,8 @@ function ReadDBConfig() {
2354
  * @return array
2355
  * @access private
2356
  */
2357
- function GetDBConfig() {
2358
- $config = ReadDBConfig();
2359
  if (!isset($config["ADMIN_USERNAME"]))
2360
  $config["ADMIN_USERNAME"] = 'admin';
2361
  if (!isset($config["PREFER_TEXT_TYPE"]))
@@ -2398,8 +2439,7 @@ function GetDBConfig() {
2398
  if (!isset($config["TURN_AUTHORIZATION_OFF"]))
2399
  $config["TURN_AUTHORIZATION_OFF"] = false;
2400
  if (!isset($config["CUSTOM_IMAGE_FIELD"]))
2401
- $config["CUSTOM_IMAGE_
2402
- FIELD"] = false;
2403
  if (!isset($config["CONVERTNEWLINE"]))
2404
  $config["CONVERTNEWLINE"] = false;
2405
  if (!isset($config["SIG_PATTERN_LIST"]))
@@ -2412,22 +2452,17 @@ function GetDBConfig() {
2412
  $config["AUTHORIZED_ADDRESSES"] = array();
2413
  if (!isset($config["MAIL_SERVER"]))
2414
  $config["MAIL_SERVER"] = NULL;
2415
- if (!isset($config["MAIL_SERVER
2416
- _PORT"]))
2417
  $config["MAIL_SERVER_PORT"] = NULL;
2418
- if (!isset($config["MAIL_USERID"]
2419
- ))
2420
  $config["MAIL_USERID"] = NULL;
2421
  if (!isset($config["MAIL_PASSWORD"]))
2422
  $config["MAIL_PASSWORD"] = NULL;
2423
- if (!isset($config["DEFAULT_POST_CATEGO
2424
- RY"]))
2425
  $config["DEFAULT_POST_CATEGORY"] = NULL;
2426
- if (!isset($config["D
2427
- EFAULT_POST_TAGS"]))
2428
  $config["DEFAULT_POST_TAGS"] = NULL;
2429
- if (!isset($config["T
2430
- IME_OFFSET"]))
2431
  $config["TIME_OFFSET"] = get_option('gmt_offset');
2432
  if (!isset($config["WRAP_PRE"]))
2433
  $config["WRAP_PRE"] = 'no';
@@ -2499,8 +2534,8 @@ function GetDBConfig() {
2499
  -format config (pre 1.4)
2500
  * @return array
2501
  */
2502
- function GetConfig() {
2503
- $config = GetDBConfig();
2504
  //These should only be modified if you are testing
2505
  $config["DELETE_MAIL_AFTER_PROCESSING"] = true;
2506
  $config["POST_TO_DB"] = true;
@@ -2544,7 +2579,7 @@ function get_postie_config() {
2544
  * Returns a list of config keys that should be arrays
2545
  * @return array
2546
  */
2547
- function get_arrayed_settings() {
2548
  return array(
2549
  ', ' => array('audiotypes', 'video1types', 'video2types', 'default_post_tags'),
2550
  "\n" => array('smtp', 'authorized_addresses', 'supported_file_types', 'banned_files_list', 'sig_pattern_list'));
@@ -2588,7 +2623,7 @@ function HasFunctions($function_list, $display = true) {
2588
  /**
2589
  * This function tests to see if postie is its own directory
2590
  */
2591
- function TestPostieDirectory() {
2592
  $dir_parts = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
2593
  $last_dir = array_pop($dir_parts);
2594
  if ($last_dir != "postie") {
@@ -2600,7 +2635,7 @@ function TestPostieDirectory() {
2600
  /**
2601
  * This function looks for markdown which causes problems with postie
2602
  */
2603
- function TestForMarkdown() {
2604
  if (in_array("markdown.php", get_option("active_plugins"))) {
2605
  return true;
2606
  }
@@ -2611,13 +2646,13 @@ function TestForMarkdown() {
2611
  * validates the config form output, fills in any gaps by using the defaults,
2612
  * and ensures that arrayed items are stored as such
2613
  */
2614
- function postie_validate_settings($in) {
2615
  //DebugDump($in);
2616
  $out = array();
2617
 
2618
  // use the default as a template:
2619
  // if a field is present in the defaults, we want to store it; otherwise we discard it
2620
- $allowed_keys = get_postie_config_defaults();
2621
  foreach ($allowed_keys as $key => $default)
2622
  $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
2623
 
@@ -2626,7 +2661,7 @@ function postie_validate_settings($in) {
2626
  foreach ($lowercase as $field) {
2627
  $out[$field] = ( is_array($out[$field]) ) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
2628
  }
2629
- $arrays = get_arrayed_settings();
2630
 
2631
  foreach ($arrays as $sep => $fields) {
2632
  foreach ($fields as $field) {
@@ -2644,7 +2679,7 @@ function postie_validate_settings($in) {
2644
  }
2645
  }
2646
 
2647
- UpdatePostieConfig($out);
2648
  return $out;
2649
  }
2650
 
@@ -2652,7 +2687,7 @@ function postie_validate_settings($in) {
2652
  * registers the settings and the admin optionspage
2653
  */
2654
  function postie_admin_settings() {
2655
- register_setting('postie-settings', 'postie-settings', 'postie_validate_settings');
2656
  }
2657
 
2658
  /**
@@ -2722,27 +2757,27 @@ function SpecialMessageParsing(&$content, &$attachments, $config) {
2722
  extract($config);
2723
  if (preg_match('/You have been sent a message from Vodafone mobile/', $content)) {
2724
  DebugEcho("Vodafone message");
2725
- VodafoneHandler($content, $attachments);
2726
  return;
2727
  }
2728
  if ($message_start) {
2729
- $content = StartFilter($content, $message_start);
2730
  //DebugEcho("post start: $content");
2731
  }
2732
  if ($message_end) {
2733
- $content = EndFilter($content, $message_end);
2734
  //DebugEcho("post end: $content");
2735
  }
2736
  if ($drop_signature) {
2737
- $content = remove_signature($content, $sig_pattern_list);
2738
- //DebugEcho("post signature: $content");
2739
  }
2740
  if ($prefer_text_type == "html" && count($attachments["cids"])) {
2741
- ReplaceImageCIDs($content, $attachments);
2742
- //DebugEcho("post CIDs: $content");
2743
  }
2744
  if (!$custom_image_field) {
2745
- ReplaceImagePlaceHolders($content, $attachments["html"], $config);
2746
  //DebugEcho("post placeholders: $content");
2747
  } else {
2748
  $customImages = array();
@@ -2759,13 +2794,13 @@ function SpecialMessageParsing(&$content, &$attachments, $config) {
2759
 
2760
  return $customImages;
2761
  }
2762
- return NULL;
2763
  }
2764
 
2765
  /**
2766
  * Special Vodafone handler - their messages are mostly vendor trash - this strips them down.
2767
  */
2768
- function VodafoneHandler(&$content, &$attachments) {
2769
  $index = strpos($content, "TEXT:");
2770
  if (strpos !== false) {
2771
  $alt_content = substr($content, $index, strlen($content));
1
  <?php
2
 
3
  /*
4
+ $Id: postie-functions.php 649993 2013-01-09 00:40:14Z WayneAllen $
5
  */
6
 
7
  /* TODO
130
  }
131
  }
132
 
133
+ function tag_Date(&$content, $message_date) {
134
+
135
+ if (preg_match("/^date:\s?(.*)$/im", $content, $matches)) {
136
+ $newdate = strtotime($matches[1]);
137
+ if (false !== $newdate) {
138
+ $message_date = date("Y-m-d", $newdate);
139
+ $content = trim(str_replace($matches[0], '', $content));
140
+ }
141
+ }
142
+
143
+ return $message_date;
144
+ }
145
+
146
  /**
147
  * This is the main handler for all of the processing
148
  */
160
  EchoInfo("Message Id is :" . htmlentities($mimeDecodedEmail->headers["message-id"]));
161
  //DebugDump($mimeDecodedEmail);
162
 
163
+ filter_PreferedText($mimeDecodedEmail, $prefer_text_type);
164
  //DebugDump($mimeDecodedEmail);
165
 
166
  $tmpPost = array('post_title' => 'tmptitle', 'post_content' => 'tmpPost');
174
  //DebugEcho("the content is $content");
175
 
176
  $subject = GetSubject($mimeDecodedEmail, $content, $config);
177
+ DebugEcho("post subject: $content");
178
 
179
  $customImages = SpecialMessageParsing($content, $attachments, $config);
180
+ DebugEcho("post special message: $content");
181
 
182
+ $post_excerpt = tag_Excerpt($content, $filternewlines, $convertnewline);
183
+ DebugEcho("post exerpt: $content");
184
 
185
  $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
186
+ DebugEcho("post author: $content");
187
 
188
  $message_date = NULL;
189
  if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
197
  }
198
  $message_date = HandleMessageEncoding($cte, $cs, $mimeDecodedEmail->headers["date"], $message_encoding, $message_dequote);
199
  }
200
+ $message_date = tag_Date(&$content, $message_date);
201
+
202
  list($post_date, $post_date_gmt, $delay) = DeterminePostDate($content, $message_date, $time_offset);
203
+ DebugEcho("post date: $content");
204
 
205
+ filter_ubb2HTML($content);
206
+ DebugEcho("post ubb: $content");
207
 
208
  if ($converturls) {
209
+ $content = filter_Videos($content, $shortcode); //videos first so linkify doesn't mess with them
210
+ $content = filter_linkify($content);
211
+ DebugEcho("post clickable: $content");
212
  }
213
 
214
  $id = checkReply($subject);
215
+ $post_categories = tag_categories($subject, $default_post_category);
216
+ $post_tags = tag_Tags($content, $default_post_tags);
217
+ DebugEcho("post tags: $content");
218
 
219
+ $comment_status = tag_AllowCommentsOnPost($content);
220
+ DebugEcho("post comment: $content");
221
 
222
  if ((empty($id) || is_null($id))) {
223
  $id = $post_id;
254
  wp_delete_post($post_id);
255
  }
256
  if ($filternewlines) {
257
+ $content = filter_newlines($content, $convertnewline);
258
  //DebugEcho("post filter newlines: $content");
259
  }
260
 
264
  $post_status = $post_status;
265
  }
266
 
267
+ $post_type = tag_PostType($subject);
268
 
269
  //DebugEcho("pre-insert content: $content");
270
 
324
  * Custom Post Type name to the email subject separated by
325
  * $custom_post_type_delim, e.g. "Movies // My Favorite Movie"
326
  */
327
+ function tag_PostType(&$subject) {
328
 
329
  $custom_post_type_delim = "//";
330
  if (strpos($subject, $custom_post_type_delim) !== FALSE) {
351
  return $post_type;
352
  }
353
 
354
+ function filter_linkify($text) {
 
355
  # It turns urls into links, and video urls into embedded players
356
+ //DebugEcho("begin: filter_linkify");
357
+
358
+ $html = str_get_html($text);
359
+ if ($html) {
360
+ //DebugEcho("filter_linkify: " . $html->save());
361
+ foreach ($html->find('text') as $element) {
362
+ //DebugEcho("filter_linkify: " . $element->innertext);
363
+ $element->innertext = make_links($element->innertext);
364
+ }
365
+ $ret = $html->save();
366
+ } else {
367
+ $ret = make_links($text);
368
+ }
369
+
370
+ //DebugEcho("end: filter_linkify");
371
+ return $ret;
372
+ }
373
+
374
+ function filter_Videos($text, $shortcode = false) {
375
+ # It turns urls into links, and video urls into embedded players
376
+ //DebugEcho("begin: filter_Videos");
377
+
378
+ $html = str_get_html($text);
379
+ if ($html) {
380
+ //DebugEcho("filter_Videos: " . $html->save());
381
+ foreach ($html->find('text') as $element) {
382
+ //DebugEcho("filter_Videos: " . $element->innertext);
383
+ $element->innertext = linkifyVideo($element->innertext, $shortcode);
384
+ }
385
+ $ret = $html->save();
386
+ } else {
387
+ $ret = linkifyVideo($text, $shortcode);
388
+ }
389
+
390
+ //DebugEcho("end: filter_Videos");
391
+ return $ret;
392
+ }
393
 
394
+ function linkifyVideo($text, $shortcode = false) {
395
+ //$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
396
+ //DebugEcho("linkify1: $text");
397
  // pad it with a space so we can match things at the start of the 1st line.
398
  $ret = ' ' . $text;
399
  if (strpos($ret, 'youtube') !== false) {
402
  if ($shortcode) {
403
  $youtube_replace = "\\1[youtube \\3]\\4";
404
  } else {
405
+ $youtube_replace = "\\1<embed width='425' height='344' allowfullscreen='true' allowscriptaccess='always' type='application/x-shockwave-flash' src='http://www.youtube.com/v/\\3&hl=en&fs=1' />\\4";
406
  }
407
  $ret = preg_replace($youtube, $youtube_replace, $ret);
408
  //DebugEcho("youtube: $ret");
421
  //DebugEcho("vimeo: $ret");
422
  }
423
 
 
 
 
 
 
 
 
 
424
  // Remove our padding..
425
  $ret = substr($ret, 1);
 
 
426
  return $ret;
427
  }
428
 
449
  );
450
  }
451
 
452
+ /* we check whether or not the e-mail is a forwards or a redirect. If it is
453
+ * a fwd, then we glean the author details from the body of the post.
454
+ * Otherwise we get them from the headers
455
+ */
456
+
457
  function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail) {
 
 
 
 
458
  global $wpdb;
459
 
460
  $theDate = $mimeDecodedEmail->headers['date'];
504
  return($theDetails);
505
  }
506
 
507
+ /* we check whether or not the e-mail is a reply to a previously
508
+ * published post. First we check whether it starts with Re:, and then
509
+ * we see if the remainder matches an already existing post. If so,
510
+ * then we add that post id to the details array, which will cause the
511
+ * existing post to be overwritten, instead of a new one being
512
+ * generated
513
+ */
 
514
 
515
+ function checkReply(&$subject) {
516
  global $wpdb;
517
 
518
  $id = NULL;
542
  return $id;
543
  }
544
 
545
+ function postie_ShowReadMe() {
546
  include(POSTIE_ROOT . DIRECTORY_SEPARATOR . "postie_read_me.php");
547
  }
548
 
558
  }
559
 
560
  /**
561
+ * This handles actually showing the form. Called by WordPress
562
  */
563
  function ConfigurePostie() {
564
  include(POSTIE_ROOT . DIRECTORY_SEPARATOR . "config_form.php");
736
  * @param string
737
  * @return boolean
738
  */
739
+ function isBannedFileName($filename, $bannedFiles) {
740
  if (empty($filename) || empty($bannedFiles))
741
  return false;
742
  foreach ($bannedFiles as $bannedFile) {
759
 
760
  //look for banned file names
761
  if (property_exists($part, 'ctype_parameters') && is_array($part->ctype_parameters) && array_key_exists('name', $part->ctype_parameters))
762
+ if (isBannedFileName($part->ctype_parameters['name'], $banned_files_list))
763
  return NULL;
764
 
765
  if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") {
766
+ if (property_exists($part, 'disposition') && $part->disposition == "attachment") {
767
  $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg");
768
  foreach ($image_endings as $type) {
769
  if (eregi(".$type\$", $part->d_parameters["filename"])) {
774
  }
775
  } else {
776
  $mimeDecodedEmail = DecodeMIMEMail($part->body);
777
+ filter_PreferedText($mimeDecodedEmail, $prefer_text_type);
778
  foreach ($mimeDecodedEmail->parts as $section) {
779
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
780
  }
784
  if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") {
785
  DebugEcho("multipart appledouble");
786
  $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body);
787
+ filter_PreferedText($mimeDecodedEmail, $prefer_text_type);
788
+ filter_AppleFile($mimeDecodedEmail);
789
  foreach ($mimeDecodedEmail->parts as $section) {
790
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
791
  }
800
  case 'multipart':
801
  DebugEcho("multipart: " . count($part->parts));
802
  //DebugDump($part);
803
+ filter_PreferedText($part, $prefer_text_type);
804
  foreach ($part->parts as $section) {
805
+ //DebugDump($section->headers);
806
 
807
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
808
  }
837
  if ($part->ctype_secondary == 'enriched') {
838
  //convert enriched text to HTML
839
  DebugEcho("enriched");
840
+ $meta_return .= filter_etf2HTML($part->body) . "\n";
841
  } elseif ($part->ctype_secondary == 'html') {
842
  //strip excess HTML
843
  DebugEcho("html");
844
+ $meta_return .= filter_CleanHtml($part->body) . "\n";
845
  } else {
846
  DebugEcho("plain text");
847
  if ($allow_html_in_body) {
852
  DebugEcho("html not allowed (htmlentities)");
853
  $meta_return .= htmlentities($part->body);
854
  }
855
+ $meta_return = filter_StripPGP($meta_return);
856
  }
857
 
858
  break;
863
  $cid = "";
864
  if (array_key_exists('content-id', $part->headers)) {
865
  $cid = trim($part->headers["content-id"], "<>");
866
+ DebugEcho("found cid: $cid");
867
  }
868
 
869
  $the_post = get_post($file_id);
943
  return $meta_return;
944
  }
945
 
946
+ function filter_ubb2HTML(&$text) {
947
  // Array of tags with opening and closing
948
  $tagArray['img'] = array('open' => '<img src="', 'close' => '">');
949
  $tagArray['b'] = array('open' => '<b>', 'close' => '</b>');
973
  // This function turns Enriched Text into something similar to HTML
974
  // Very basic at the moment, only supports some functionality and dumps the rest
975
  // FIXME: fix colours: <color><param>FFFF,C2FE,0374</param>some text </color>
976
+ function filter_etf2HTML($content) {
977
 
978
  $search = array(
979
  '/<bold>/',
1016
  }
1017
 
1018
  // This function cleans up HTML in the e-mail
1019
+ function filter_CleanHtml($content) {
1020
  $html = str_get_html($content);
1021
  if ($html) {
1022
  DebugEcho("Looking for invalid tags");
1064
  } else {
1065
  $poster = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$admin_username'");
1066
  }
1067
+ } elseif ($turn_authorization_off || isEmailAddressAuthorized($from, $authorized_addresses) || isEmailAddressAuthorized($resentFrom, $authorized_addresses)) {
1068
  $poster = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$admin_username'");
1069
  }
1070
 
1071
+ $validSMTP = isValidSmtpServer($mimeDecodedEmail, $smtp);
1072
  if (!$poster || !$validSMTP) {
1073
  EchoInfo('Invalid sender: ' . htmlentities($from) . "! Not adding email!");
1074
  if ($forward_rejected_mail) {
1084
  return $poster;
1085
  }
1086
 
1087
+ function isValidSmtpServer($mimeDecodedEmail, $smtpservers) {
 
 
 
 
 
1088
  if (empty($smtpservers))
1089
  return true;
1090
 
1107
  * @param string
1108
  * @param string
1109
  */
1110
+ function filter_start($content, $start) {
1111
  $pos = strpos($content, $start);
1112
  if ($pos === false) {
1113
  return $content;
1122
  * @param string
1123
  * @param array - a list of patterns to determine if it is a sig block
1124
  */
1125
+ function filter_RemoveSignature($content, $filterList) {
1126
  if (empty($filterList))
1127
  return $content;
1128
  $arrcontent = explode("\n", $content);
1144
  * @param string
1145
  * @param filter
1146
  */
1147
+ function filter_end($content, $end) {
1148
  $pos = strpos($content, $end);
1149
  if ($pos === false)
1150
  return $content;
1153
  }
1154
 
1155
  //filter content for new lines
1156
+ function filter_newlines($content, $convertNewLines = false) {
1157
  $search = array(
1158
  "/\r\n/",
1159
  "/\r/",
1180
  }
1181
 
1182
  //strip pgp stuff
1183
+ function filter_StripPGP($content) {
1184
  $search = array(
1185
  '/-----BEGIN PGP SIGNED MESSAGE-----/',
1186
  '/Hash: SHA1/'
1264
  * Checks for the comments tag
1265
  * @return boolean
1266
  */
1267
+ function tag_AllowCommentsOnPost(&$content) {
1268
  $comments_allowed = get_option('default_comment_status'); // 'open' or 'closed'
1269
 
1270
  if (preg_match("/comments:([0|1|2])/i", $content, $matches)) {
1282
 
1283
  /**
1284
  * Needed to be able to modify the content to remove the usage of the delay tag
1285
+ *
1286
+ * todo split delay tag from date logic
1287
  */
1288
  function DeterminePostDate(&$content, $message_date = NULL, $offset = 0) {
1289
  $delay = 0;
1326
  /**
1327
  * This function takes the content of the message - looks for a subject at the begining surrounded by # and then removes that from the content
1328
  */
1329
+ function tag_subject($content, $defaultTitle) {
1330
  DebugEcho("Looking for subject in email body");
1331
  if (substr($content, 0, 1) != "#") {
1332
  DebugEcho("No subject found, using default [1]");
1347
  * this part of the file attachment is not supported
1348
  * @param object
1349
  */
1350
+ function filter_AppleFile(&$mimeDecodedEmail) {
1351
  $newParts = array();
1352
  $found = false;
1353
  for ($i = 0; $i < count($mimeDecodedEmail->parts); $i++) {
1571
  * that type is present it filters out all other text types. If it is not - then nothing is done
1572
  * @param object
1573
  */
1574
+ function filter_PreferedText($mimeDecodedEmail, $preferTextType) {
1575
  DebugEcho("FilterTextParts: begin " . count($mimeDecodedEmail->parts));
1576
  $newParts = array();
1577
  $found = false;
1731
  * @param string - email address
1732
  * @return boolean
1733
  */
1734
+ function isEmailAddressAuthorized($address, $authorized) {
1735
  $r = false;
1736
  if (is_array($authorized)) {
1737
  $a = strtolower(trim($address));
1756
  $address = $matches[1];
1757
  }
1758
 
1759
+ return $address;
1760
  }
1761
 
1762
  /**
1906
  * @param string - text of post
1907
  * @param array - array of HTML for images for post
1908
  */
1909
+ function filter_ReplaceImageCIDs(&$content, &$attachments) {
1910
  DebugEcho("ReplaceImageCIDs");
1911
  $used = array();
1912
  foreach ($attachments["cids"] as $key => $info) {
1917
  $used[] = $info[1]; //Index of html to ignore
1918
  }
1919
  }
1920
+ DebugEcho("# cid attachments: " . count($used));
1921
 
1922
  $html = array();
1923
+ $att = array_values($attachments["html"]); //make sure there are numeric indexes
1924
+ DebugEcho('$attachments');
1925
+ DebugDump($attachments);
1926
+ DebugEcho('$used');
1927
+ DebugDump($used);
1928
+ for ($i = 0; $i < count($attachments["html"]); $i++) {
1929
+ if (!in_array($i, $used)) {
1930
+ $html[] = $att[$i];
1931
+ }
1932
+ }
1933
 
1934
  foreach ($attachments['html'] as $key => $value) {
1935
  if (!in_array($value, $used)) {
1946
  * @param string - text of post
1947
  * @param array - array of HTML for images for post
1948
  */
1949
+ function filter_ReplaceImagePlaceHolders(&$content, $attachments, $config) {
1950
  extract($config);
1951
  if (!$allow_html_in_body) {
1952
  $content = html_entity_decode($content, ENT_QUOTES);
2025
  if (!array_key_exists('subject', $mimeDecodedEmail->headers) || empty($mimeDecodedEmail->headers['subject'])) {
2026
  DebugEcho("No subject in email");
2027
  if ($allow_subject_in_mail) {
2028
+ list($subject, $content) = tag_subject($content, $default_title);
2029
  } else {
2030
  DebugEcho("Using default subject");
2031
  $subject = $default_title;
2033
  $mimeDecodedEmail->headers['subject'] = $subject;
2034
  } else {
2035
  $subject = $mimeDecodedEmail->headers['subject'];
2036
+ DebugDump($mimeDecodedEmail->headers);
2037
  DebugEcho(("Predecoded subject: $subject"));
2038
 
2039
+ DebugEcho("detected: " . mb_detect_encoding($subject, mb_list_encodings(), true));
2040
+ DebugEcho("Encoding ISO-8859-2: " . mb_convert_encoding($subject, 'UTF-8', 'ISO-8859-2'));
2041
+ DebugEcho("Encoding Windows-1254: " . mb_convert_encoding($subject, 'UTF-8', 'Windows-1254'));
2042
+
2043
  if (array_key_exists('content-transfer-encoding', $mimeDecodedEmail->headers)) {
2044
  $encoding = $mimeDecodedEmail->headers["content-transfer-encoding"];
2045
  } else if (array_key_exists("content-transfer-encoding", $mimeDecodedEmail->ctype_parameters)) {
2088
  * this function determines tags for the post
2089
  *
2090
  */
2091
+ function tag_Tags(&$content, $defaultTags) {
2092
  $post_tags = array();
2093
  //try and determine tags
2094
  if (preg_match('/tags: ?(.*)$/im', $content, $matches)) {
2109
  * this function determines excerpt for the post
2110
  *
2111
  */
2112
+ function tag_Excerpt(&$content, $filterNewLines, $convertNewLines) {
2113
  $post_excerpt = '';
2114
  if (preg_match('/:excerptstart ?(.*):excerptend/s', $content, $matches)) {
2115
  $content = str_replace($matches[0], "", $content);
2116
  $post_excerpt = $matches[1];
2117
  if ($filterNewLines)
2118
+ $post_excerpt = filter_newlines($post_excerpt, $convertNewLines);
2119
  }
2120
  return $post_excerpt;
2121
  }
2124
  * This function determines categories for the post
2125
  * @return array
2126
  */
2127
+ function tag_categories(&$subject, $defaultCategory) {
2128
  global $wpdb;
2129
  $original_subject = $subject;
2130
  $post_categories = array();
2144
  $matchtypes[] = $matches;
2145
  }
2146
  if (preg_match('/(.+): (.*)/', $subject, $matches)) { // <category>:<Subject>
2147
+ $category = lookup_category($matches[1]);
2148
  if (!empty($category)) {
2149
  $subject = trim($matches[2]);
2150
  $post_categories[] = $category;
2154
  foreach ($matchtypes as $matches) {
2155
  if (count($matches)) {
2156
  foreach ($matches[1] as $match) {
2157
+ $category = lookup_category($match);
2158
  if (!empty($category)) {
2159
  $post_categories[] = $category;
2160
  }
2168
  return $post_categories;
2169
  }
2170
 
2171
+ function lookup_category($trial_category) {
2172
  global $wpdb;
2173
  $trial_category = trim($trial_category);
2174
  $found_category = NULL;
2257
  /**
2258
  * This function resets all the configuration options to the default
2259
  */
2260
+ function config_ResetToDefault() {
2261
+ $newconfig = config_GetDefaults();
2262
  $config = get_option('postie-settings');
2263
  $save_keys = array('mail_password', 'mail_server', 'mail_server_port', 'mail_userid', 'iinput_protocol');
2264
  foreach ($save_keys as $key)
2265
  $newconfig[$key] = $config[$key];
2266
  update_option('postie-settings', $newconfig);
2267
+ config_Update($newconfig);
2268
  return $newconfig;
2269
  }
2270
 
2272
  * This function used to handle updating the configuration.
2273
  * @return boolean
2274
  */
2275
+ function config_Update($data) {
2276
  UpdatePostiePermissions($data["role_access"]);
2277
  // We also update the cron settings
2278
  if ($data['interval'] != '') {
2281
  postie_cron($interval = $data['interval']);
2282
  }
2283
  }
 
2284
  }
2285
 
2286
  /**
2287
  * return an array of the config defaults
2288
  */
2289
+ function config_GetDefaults() {
2290
  include('templates/audio_templates.php');
2291
  include('templates/image_templates.php');
2292
  include('templates/video1_templates.php');
2352
  'video2types' => array('x-flv'),
2353
  'video1templates' => $video1Templates,
2354
  'video2templates' => $video2Templates,
2355
+ 'wrap_pre' => 'no'
 
 
2356
  );
2357
  }
2358
 
2361
  * the following functions are only used to retrieve the old (pre 1.4) config, to convert it
2362
  * to the new format
2363
  */
2364
+ function config_GetListOfArrayConfig() {
2365
  return(array('SUPPORTED_FILE_TYPES', 'AUTHORIZED_ADDRESSES',
2366
  'SIG_PATTERN_LIST', 'BANNED_FILES_LIST', 'VIDEO1TYPES',
2367
  'VIDEO2TYPES', 'AUDIOTYPES', 'SMTP'));
2371
  * This function retrieves the old-format config (pre 1.4) from the database
2372
  * @return array
2373
  */
2374
+ function config_ReadOld() {
2375
  $config = array();
2376
  global $wpdb;
2377
+ $wpdb->query("SHOW TABLES LIKE '" . $GLOBALS["table_prefix"] . "postie_config'");
 
 
2378
  if ($wpdb->num_rows > 0) {
2379
  $data = $wpdb->get_results("SELECT label,value FROM " . $GLOBALS["table_prefix"] . "postie_config;");
2380
  if (is_array($data)) {
2381
  foreach ($data as $row) {
2382
+ if (in_array($row->label, config_GetListOfArrayConfig())) {
2383
  $config[$row->label] = unserialize($row->value);
2384
  } else {
2385
  $config[$row->label] = $row->value;
2395
  * @return array
2396
  * @access private
2397
  */
2398
+ function config_UpgradeOld() {
2399
+ $config = config_ReadOld();
2400
  if (!isset($config["ADMIN_USERNAME"]))
2401
  $config["ADMIN_USERNAME"] = 'admin';
2402
  if (!isset($config["PREFER_TEXT_TYPE"]))
2439
  if (!isset($config["TURN_AUTHORIZATION_OFF"]))
2440
  $config["TURN_AUTHORIZATION_OFF"] = false;
2441
  if (!isset($config["CUSTOM_IMAGE_FIELD"]))
2442
+ $config["CUSTOM_IMAGE_FIELD"] = false;
 
2443
  if (!isset($config["CONVERTNEWLINE"]))
2444
  $config["CONVERTNEWLINE"] = false;
2445
  if (!isset($config["SIG_PATTERN_LIST"]))
2452
  $config["AUTHORIZED_ADDRESSES"] = array();
2453
  if (!isset($config["MAIL_SERVER"]))
2454
  $config["MAIL_SERVER"] = NULL;
2455
+ if (!isset($config["MAIL_SERVER_PORT"]))
 
2456
  $config["MAIL_SERVER_PORT"] = NULL;
2457
+ if (!isset($config["MAIL_USERID"]))
 
2458
  $config["MAIL_USERID"] = NULL;
2459
  if (!isset($config["MAIL_PASSWORD"]))
2460
  $config["MAIL_PASSWORD"] = NULL;
2461
+ if (!isset($config["DEFAULT_POST_CATEGORY"]))
 
2462
  $config["DEFAULT_POST_CATEGORY"] = NULL;
2463
+ if (!isset($config["DEFAULT_POST_TAGS"]))
 
2464
  $config["DEFAULT_POST_TAGS"] = NULL;
2465
+ if (!isset($config["TIME_OFFSET"]))
 
2466
  $config["TIME_OFFSET"] = get_option('gmt_offset');
2467
  if (!isset($config["WRAP_PRE"]))
2468
  $config["WRAP_PRE"] = 'no';
2534
  -format config (pre 1.4)
2535
  * @return array
2536
  */
2537
+ function config_GetOld() {
2538
+ $config = config_UpgradeOld();
2539
  //These should only be modified if you are testing
2540
  $config["DELETE_MAIL_AFTER_PROCESSING"] = true;
2541
  $config["POST_TO_DB"] = true;
2579
  * Returns a list of config keys that should be arrays
2580
  * @return array
2581
  */
2582
+ function config_ArrayedSettings() {
2583
  return array(
2584
  ', ' => array('audiotypes', 'video1types', 'video2types', 'default_post_tags'),
2585
  "\n" => array('smtp', 'authorized_addresses', 'supported_file_types', 'banned_files_list', 'sig_pattern_list'));
2623
  /**
2624
  * This function tests to see if postie is its own directory
2625
  */
2626
+ function isPostieInCorrectDirectory() {
2627
  $dir_parts = explode(DIRECTORY_SEPARATOR, dirname(__FILE__));
2628
  $last_dir = array_pop($dir_parts);
2629
  if ($last_dir != "postie") {
2635
  /**
2636
  * This function looks for markdown which causes problems with postie
2637
  */
2638
+ function isMarkdownInstalled() {
2639
  if (in_array("markdown.php", get_option("active_plugins"))) {
2640
  return true;
2641
  }
2646
  * validates the config form output, fills in any gaps by using the defaults,
2647
  * and ensures that arrayed items are stored as such
2648
  */
2649
+ function config_ValidateSettings($in) {
2650
  //DebugDump($in);
2651
  $out = array();
2652
 
2653
  // use the default as a template:
2654
  // if a field is present in the defaults, we want to store it; otherwise we discard it
2655
+ $allowed_keys = config_GetDefaults();
2656
  foreach ($allowed_keys as $key => $default)
2657
  $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
2658
 
2661
  foreach ($lowercase as $field) {
2662
  $out[$field] = ( is_array($out[$field]) ) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
2663
  }
2664
+ $arrays = config_ArrayedSettings();
2665
 
2666
  foreach ($arrays as $sep => $fields) {
2667
  foreach ($fields as $field) {
2679
  }
2680
  }
2681
 
2682
+ config_Update($out);
2683
  return $out;
2684
  }
2685
 
2687
  * registers the settings and the admin optionspage
2688
  */
2689
  function postie_admin_settings() {
2690
+ register_setting('postie-settings', 'postie-settings', 'config_ValidateSettings');
2691
  }
2692
 
2693
  /**
2757
  extract($config);
2758
  if (preg_match('/You have been sent a message from Vodafone mobile/', $content)) {
2759
  DebugEcho("Vodafone message");
2760
+ filter_VodafoneHandler($content, $attachments);
2761
  return;
2762
  }
2763
  if ($message_start) {
2764
+ $content = filter_start($content, $message_start);
2765
  //DebugEcho("post start: $content");
2766
  }
2767
  if ($message_end) {
2768
+ $content = filter_end($content, $message_end);
2769
  //DebugEcho("post end: $content");
2770
  }
2771
  if ($drop_signature) {
2772
+ $content = filter_RemoveSignature($content, $sig_pattern_list);
2773
+ DebugEcho("post signature: $content");
2774
  }
2775
  if ($prefer_text_type == "html" && count($attachments["cids"])) {
2776
+ filter_ReplaceImageCIDs($content, $attachments);
2777
+ DebugEcho("post CIDs: $content");
2778
  }
2779
  if (!$custom_image_field) {
2780
+ filter_ReplaceImagePlaceHolders($content, $attachments["html"], $config);
2781
  //DebugEcho("post placeholders: $content");
2782
  } else {
2783
  $customImages = array();
2794
 
2795
  return $customImages;
2796
  }
2797
+ return null;
2798
  }
2799
 
2800
  /**
2801
  * Special Vodafone handler - their messages are mostly vendor trash - this strips them down.
2802
  */
2803
+ function filter_VodafoneHandler(&$content, &$attachments) {
2804
  $index = strpos($content, "TEXT:");
2805
  if (strpos !== false) {
2806
  $alt_content = substr($content, $index, strlen($content));
postie.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  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://wordpress.org/support/plugin/postie'>postie forum</a> for support.
7
- Version: 1.4.17
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
@@ -27,7 +27,7 @@
27
  */
28
 
29
  /*
30
- $Id: postie.php 647656 2013-01-04 00:20:35Z WayneAllen $
31
  * -= Requests Pending =-
32
  * Problem with some mail server
33
  * Multiple emails should tie to a single account
@@ -80,7 +80,7 @@ if (isset($_GET["postie_read_me"])) {
80
  $title = __("Edit Plugins");
81
  $parent_file = 'plugins.php';
82
  include(ABSPATH . 'wp-admin/admin-header.php');
83
- postie_read_me();
84
  include(ABSPATH . 'wp-admin/admin-footer.php');
85
  }
86
  //Add Menu Configuration
@@ -113,10 +113,10 @@ function activate_postie() {
113
  if (!$options) {
114
  $options = array();
115
  }
116
- $default_options = get_postie_config_defaults();
117
  $old_config = array();
118
 
119
- $result = GetConfig();
120
  if (is_array($result)) {
121
  foreach ($result as $key => $val) {
122
  $old_config[strtolower($key)] = $val;
@@ -126,7 +126,7 @@ function activate_postie() {
126
  // overlay the options on top of each other:
127
  // the current value of $options takes priority over the $old_config, which takes priority over the $default_options
128
  $options = array_merge($default_options, $old_config, $options);
129
- $options = postie_validate_settings($options);
130
  update_option('postie-settings', $options);
131
  $init = true;
132
  DebugEcho("activate completed");
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  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://wordpress.org/support/plugin/postie'>postie forum</a> for support.
7
+ Version: 1.4.20
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
27
  */
28
 
29
  /*
30
+ $Id: postie.php 649993 2013-01-09 00:40:14Z WayneAllen $
31
  * -= Requests Pending =-
32
  * Problem with some mail server
33
  * Multiple emails should tie to a single account
80
  $title = __("Edit Plugins");
81
  $parent_file = 'plugins.php';
82
  include(ABSPATH . 'wp-admin/admin-header.php');
83
+ postie_ShowReadMe();
84
  include(ABSPATH . 'wp-admin/admin-footer.php');
85
  }
86
  //Add Menu Configuration
113
  if (!$options) {
114
  $options = array();
115
  }
116
+ $default_options = config_GetDefaults();
117
  $old_config = array();
118
 
119
+ $result = config_GetOld();
120
  if (is_array($result)) {
121
  foreach ($result as $key => $val) {
122
  $old_config[strtolower($key)] = $val;
126
  // overlay the options on top of each other:
127
  // the current value of $options takes priority over the $old_config, which takes priority over the $default_options
128
  $options = array_merge($default_options, $old_config, $options);
129
+ $options = config_ValidateSettings($options);
130
  update_option('postie-settings', $options);
131
  $init = true;
132
  DebugEcho("activate completed");
postie_test.php CHANGED
@@ -21,7 +21,7 @@ $images = array("Test.png", "Test.jpg", "Test.gif");
21
  <div class="wrap">
22
  <h1>Postie Configuration Test</h1>
23
  <?php
24
- if (TestForMarkdown()) {
25
  ?>
26
  <h1>Warning!</h1>
27
  <p>You currently have the Markdown plugin installed. It will cause problems if you send in HTML
@@ -29,7 +29,7 @@ $images = array("Test.png", "Test.jpg", "Test.gif");
29
  <?php
30
  }
31
 
32
- if (!TestPostieDirectory()) {
33
  EchoInfo("<b>Warning!</b> Postie expects to be in its own directory named postie.");
34
  } else {
35
  EchoInfo("Postie is in " . dirname(__FILE__));
21
  <div class="wrap">
22
  <h1>Postie Configuration Test</h1>
23
  <?php
24
+ if (isMarkdownInstalled()) {
25
  ?>
26
  <h1>Warning!</h1>
27
  <p>You currently have the Markdown plugin installed. It will cause problems if you send in HTML
29
  <?php
30
  }
31
 
32
+ if (!isPostieInCorrectDirectory()) {
33
  EchoInfo("<b>Warning!</b> Postie expects to be in its own directory named postie.");
34
  } else {
35
  EchoInfo("Postie is in " . dirname(__FILE__));
readme.html CHANGED
@@ -52,14 +52,20 @@ Examples:</p>
52
  <h3>Upgrade Notice</h3>
53
  <dl>
54
  <dt>Attachments are now processed in the order they were attached.
55
- All script, style and body tags are stripped from html emails.</dt>
 
56
  <dd></dd>
57
  </dl>
58
 
59
  <h3 id='Usage'>Usage</h3>
60
  <ul>
61
- <li>If you put in :start - the message processing won't start until it sees that string</li>
62
- <li>If you put in :end - the message processing will stop once it sees that string</li>
 
 
 
 
 
63
  <li>Posts can be delayed by adding a line with delayXdXhXm where X is a number.
64
 
65
  <ul>
52
  <h3>Upgrade Notice</h3>
53
  <dl>
54
  <dt>Attachments are now processed in the order they were attached.
55
+ All script, style and body tags are stripped from html emails.
56
+ Many method names have been changed as of 1.4.18. Any custom filters may need to be updated.</dt>
57
  <dd></dd>
58
  </dl>
59
 
60
  <h3 id='Usage'>Usage</h3>
61
  <ul>
62
+ <li>If you put in :start - the message processing won't start until it sees that string.</li>
63
+ <li>If you put in :end - the message processing will stop once it sees that string.</li>
64
+ <li>Posts can have a specific publication date.
65
+
66
+ <ul>
67
+ <li>date: </li>
68
+ </ul></li>
69
  <li>Posts can be delayed by adding a line with delayXdXhXm where X is a number.
70
 
71
  <ul>
readme.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
- Stable tag: 1.4.17
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -63,8 +63,10 @@ This fetches the mail every five minutes with lynx
63
 
64
  This fetches the mail every ten minutes with wget
65
  == Usage ==
66
- * If you put in :start - the message processing won't start until it sees that string
67
- * If you put in :end - the message processing will stop once it sees that string
 
 
68
  * Posts can be delayed by adding a line with delayXdXhXm where X is a number.
69
  * delay:1d - 1 day
70
  * delay:1h - 1 hour
@@ -368,8 +370,20 @@ It is also possible to turn the WordPress cron off. Please make sure something l
368
  == Upgrade Notice ==
369
  * Attachments are now processed in the order they were attached.
370
  * All script, style and body tags are stripped from html emails.
 
371
 
372
  == CHANGELOG ==
 
 
 
 
 
 
 
 
 
 
 
373
  = 1.4.17 (2013.01.03) =
374
  * Fixed a bug where non image/video attachments were not getting added to the post.
375
 
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
+ Stable tag: 1.4.20
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
63
 
64
  This fetches the mail every ten minutes with wget
65
  == Usage ==
66
+ * If you put in :start - the message processing won't start until it sees that string.
67
+ * If you put in :end - the message processing will stop once it sees that string.
68
+ * Posts can have a specific publication date.
69
+ * date: <date>
70
  * Posts can be delayed by adding a line with delayXdXhXm where X is a number.
71
  * delay:1d - 1 day
72
  * delay:1h - 1 hour
370
  == Upgrade Notice ==
371
  * Attachments are now processed in the order they were attached.
372
  * All script, style and body tags are stripped from html emails.
373
+ * Many method names have been changed as of 1.4.18. Any custom filters may need to be updated.
374
 
375
  == CHANGELOG ==
376
+ = 1.4.20 (2013.01.08) =
377
+ * Added Date feature. You can now specify a specific publication date.
378
+ * Fixed a bug with embeded youtube/vimeo links when shortcodes are turned off
379
+
380
+ = 1.4.19 (2013.01.07) =
381
+ * Fixed a bug that prevented the settings from being saved
382
+
383
+ = 1.4.18 (2013.01.06) =
384
+ * Fixed a bug where linkifying was doing too much.
385
+ * Updated lots of method names in preparation for some significant structural changes.
386
+
387
  = 1.4.17 (2013.01.03) =
388
  * Fixed a bug where non image/video attachments were not getting added to the post.
389
 
test/inlineimageTest.php CHANGED
@@ -40,7 +40,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
40
  $partcnt = count($decoded->parts);
41
  $this->assertEquals(2, $partcnt);
42
 
43
- FilterTextParts($decoded, "plain");
44
 
45
  $attachments = array(
46
  "html" => array(), //holds the html for each image
@@ -87,7 +87,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
87
  $partcnt = count($decoded->parts);
88
  $this->assertEquals(2, $partcnt);
89
 
90
- FilterTextParts($decoded, "plain");
91
 
92
  $attachments = array(
93
  "html" => array(), //holds the html for each image
@@ -108,7 +108,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
108
  $this->assertEquals(null, $customImages);
109
  $this->assertEquals("test content\n\n", $content);
110
 
111
- $post_excerpt = GetPostExcerpt($content, $filternewlines, $convertnewline);
112
 
113
  $postAuthorDetails = getPostAuthorDetails($subject, $content, $decoded);
114
  }
@@ -142,7 +142,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
142
  $decoded = DecodeMIMEMail($email);
143
  print_r($decoded);
144
 
145
- FilterTextParts($decoded, 'html');
146
  $attachments = array(
147
  "html" => array(), //holds the html for each image
148
  "cids" => array(), //holds the cids for HTML email
@@ -157,65 +157,65 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
157
  $config = $this->standardConfig();
158
  $attachements = array("image.jpg" => '<img title="{CAPTION}" />');
159
 
160
- ReplaceImagePlaceHolders($c, array(), $config);
161
  $this->assertEquals("", $c);
162
 
163
- ReplaceImagePlaceHolders($c, $attachements, $config);
164
  $this->assertEquals('<img title="" />', $c);
165
 
166
  $c = "#img1#";
167
- ReplaceImagePlaceHolders($c, $attachements, $config);
168
  $this->assertEquals('<img title="" />', $c);
169
 
170
  $c = "test #img1# test";
171
- ReplaceImagePlaceHolders($c, $attachements, $config);
172
  $this->assertEquals('test <img title="" /> test', $c);
173
 
174
  $c = "test #img1 caption='1'# test";
175
- ReplaceImagePlaceHolders($c, $attachements, $config);
176
  $this->assertEquals('test <img title="1" /> test', $c);
177
 
178
  $c = "test #img1 caption='! @ % ^ & * ( ) ~ \"Test\"'# test";
179
- ReplaceImagePlaceHolders($c, $attachements, $config);
180
  $this->assertEquals('test <img title="! @ % ^ &amp; * ( ) ~ &quot;Test&quot;" /> test', $c);
181
 
182
  $c = "test <div>#img1 caption=&#39;! @ % ^ &amp; * ( ) ~ &quot;Test&quot;&#39;#</div> test";
183
- ReplaceImagePlaceHolders($c, $attachements, $config);
184
  $this->assertEquals("test <div><img title=\"! @ % ^ &amp; * ( ) ~ &quot;Test&quot;\" /></div> test", $c);
185
 
186
  $c = "test #img1 caption=\"I'd like some cheese.\"# test";
187
- ReplaceImagePlaceHolders($c, $attachements, $config);
188
  $this->assertEquals('test <img title="I&#039;d like some cheese." /> test', $c);
189
 
190
  $c = "test #img1 caption=\"Eiskernbrecher mögens laut\"# test";
191
- ReplaceImagePlaceHolders($c, $attachements, $config);
192
  $this->assertEquals('test <img title="Eiskernbrecher mögens laut" /> test', $c);
193
 
194
  $c = "test #img1 caption='[image-caption]'# test";
195
- ReplaceImagePlaceHolders($c, $attachements, $config);
196
  $this->assertEquals('test <img title="[image-caption]" /> test', $c);
197
 
198
  $c = "test #img1 caption='1'# test #img2 caption='2'#";
199
- ReplaceImagePlaceHolders($c, $attachements, $config);
200
  $this->assertEquals('test <img title="1" /> test #img2 caption=\'2\'#', $c);
201
 
202
  $attachements = array("image1.jpg" => 'template with {CAPTION}', "image2.jpg" => 'template with {CAPTION}');
203
  $c = "test #img1 caption='1'# test #img2 caption='2'#";
204
- ReplaceImagePlaceHolders($c, $attachements, $config);
205
  $this->assertEquals("test template with 1 test template with 2", $c);
206
 
207
  $config['auto_gallery'] = true;
208
  $c = "test";
209
- ReplaceImagePlaceHolders($c, $attachements, $config);
210
  $this->assertEquals("[gallery]\ntest", $c);
211
 
212
  $config['images_append'] = true;
213
  $c = "test";
214
- ReplaceImagePlaceHolders($c, $attachements, $config);
215
  $this->assertEquals("test[gallery]", $c);
216
 
217
  $c = "test";
218
- ReplaceImagePlaceHolders($c, array(), $config);
219
  $this->assertEquals("test", $c);
220
  }
221
 
40
  $partcnt = count($decoded->parts);
41
  $this->assertEquals(2, $partcnt);
42
 
43
+ filter_PreferedText($decoded, "plain");
44
 
45
  $attachments = array(
46
  "html" => array(), //holds the html for each image
87
  $partcnt = count($decoded->parts);
88
  $this->assertEquals(2, $partcnt);
89
 
90
+ filter_PreferedText($decoded, "plain");
91
 
92
  $attachments = array(
93
  "html" => array(), //holds the html for each image
108
  $this->assertEquals(null, $customImages);
109
  $this->assertEquals("test content\n\n", $content);
110
 
111
+ $post_excerpt = tag_Excerpt($content, $filternewlines, $convertnewline);
112
 
113
  $postAuthorDetails = getPostAuthorDetails($subject, $content, $decoded);
114
  }
142
  $decoded = DecodeMIMEMail($email);
143
  print_r($decoded);
144
 
145
+ filter_PreferedText($decoded, 'html');
146
  $attachments = array(
147
  "html" => array(), //holds the html for each image
148
  "cids" => array(), //holds the cids for HTML email
157
  $config = $this->standardConfig();
158
  $attachements = array("image.jpg" => '<img title="{CAPTION}" />');
159
 
160
+ filter_ReplaceImagePlaceHolders($c, array(), $config);
161
  $this->assertEquals("", $c);
162
 
163
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
164
  $this->assertEquals('<img title="" />', $c);
165
 
166
  $c = "#img1#";
167
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
168
  $this->assertEquals('<img title="" />', $c);
169
 
170
  $c = "test #img1# test";
171
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
172
  $this->assertEquals('test <img title="" /> test', $c);
173
 
174
  $c = "test #img1 caption='1'# test";
175
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
176
  $this->assertEquals('test <img title="1" /> test', $c);
177
 
178
  $c = "test #img1 caption='! @ % ^ & * ( ) ~ \"Test\"'# test";
179
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
180
  $this->assertEquals('test <img title="! @ % ^ &amp; * ( ) ~ &quot;Test&quot;" /> test', $c);
181
 
182
  $c = "test <div>#img1 caption=&#39;! @ % ^ &amp; * ( ) ~ &quot;Test&quot;&#39;#</div> test";
183
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
184
  $this->assertEquals("test <div><img title=\"! @ % ^ &amp; * ( ) ~ &quot;Test&quot;\" /></div> test", $c);
185
 
186
  $c = "test #img1 caption=\"I'd like some cheese.\"# test";
187
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
188
  $this->assertEquals('test <img title="I&#039;d like some cheese." /> test', $c);
189
 
190
  $c = "test #img1 caption=\"Eiskernbrecher mögens laut\"# test";
191
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
192
  $this->assertEquals('test <img title="Eiskernbrecher mögens laut" /> test', $c);
193
 
194
  $c = "test #img1 caption='[image-caption]'# test";
195
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
196
  $this->assertEquals('test <img title="[image-caption]" /> test', $c);
197
 
198
  $c = "test #img1 caption='1'# test #img2 caption='2'#";
199
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
200
  $this->assertEquals('test <img title="1" /> test #img2 caption=\'2\'#', $c);
201
 
202
  $attachements = array("image1.jpg" => 'template with {CAPTION}', "image2.jpg" => 'template with {CAPTION}');
203
  $c = "test #img1 caption='1'# test #img2 caption='2'#";
204
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
205
  $this->assertEquals("test template with 1 test template with 2", $c);
206
 
207
  $config['auto_gallery'] = true;
208
  $c = "test";
209
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
210
  $this->assertEquals("[gallery]\ntest", $c);
211
 
212
  $config['images_append'] = true;
213
  $c = "test";
214
+ filter_ReplaceImagePlaceHolders($c, $attachements, $config);
215
  $this->assertEquals("test[gallery]", $c);
216
 
217
  $c = "test";
218
+ filter_ReplaceImagePlaceHolders($c, array(), $config);
219
  $this->assertEquals("test", $c);
220
  }
221
 
test/postie-functionsTest.php CHANGED
@@ -14,53 +14,53 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
14
  public function testAllowCommentsOnPost() {
15
  $original_content = "test content, no comment control";
16
  $modified_content = "test content, no comment control";
17
- $allow = AllowCommentsOnPost($modified_content);
18
  $this->assertEquals("open", $allow);
19
  $this->assertEquals($original_content, $modified_content);
20
 
21
  $original_content = "test content, comment control closed ";
22
  $modified_content = "test content, comment control closed comments:0";
23
- $allow = AllowCommentsOnPost($modified_content);
24
  $this->assertEquals("closed", $allow);
25
  $this->assertEquals($original_content, $modified_content);
26
 
27
  $original_content = "test content, comment control open ";
28
  $modified_content = "test content, comment control open comments:1";
29
- $allow = AllowCommentsOnPost($modified_content);
30
  $this->assertEquals("open", $allow);
31
  $this->assertEquals($original_content, $modified_content);
32
 
33
  $original_content = "test content, comment control registered only ";
34
  $modified_content = "test content, comment control registered only comments:2";
35
- $allow = AllowCommentsOnPost($modified_content);
36
  $this->assertEquals("registered_only", $allow);
37
  $this->assertEquals($original_content, $modified_content);
38
  }
39
 
40
  public function testBannedFileName() {
41
- $this->assertFalse(BannedFileName("", null));
42
- $this->assertFalse(BannedFileName("", ""));
43
- $this->assertFalse(BannedFileName("", array()));
44
- $this->assertFalse(BannedFileName("test", array()));
45
- $this->assertTrue(BannedFileName("test", array("test")));
46
- $this->assertFalse(BannedFileName("test", array("test1")));
47
- $this->assertTrue(BannedFileName("test.exe", array("*.exe")));
48
- $this->assertFalse(BannedFileName("test.pdf", array("*.exe")));
49
- $this->assertFalse(BannedFileName("test.pdf", array("*.exe", "*.js", "*.cmd")));
50
- $this->assertFalse(BannedFileName("test.cmd.pdf", array("*.exe", "*.js", "*.cmd")));
51
- $this->assertTrue(BannedFileName("test test.exe", array("*.exe")));
52
  }
53
 
54
  public function testCheckEmailAddress() {
55
- $this->assertFalse(CheckEmailAddress(null, null));
56
- $this->assertFalse(CheckEmailAddress(null, array()));
57
- $this->assertFalse(CheckEmailAddress("", array()));
58
- $this->assertFalse(CheckEmailAddress("", array("")));
59
- $this->assertFalse(CheckEmailAddress("bob", array("jane")));
60
- $this->assertTrue(CheckEmailAddress("bob", array("bob")));
61
- $this->assertTrue(CheckEmailAddress("bob", array("BoB")));
62
- $this->assertTrue(CheckEmailAddress("bob", array("bob", "jane")));
63
- $this->assertTrue(CheckEmailAddress("bob", array("jane", "bob")));
64
  }
65
 
66
  public function testConvertUTF8ToISO_8859_1() {
@@ -144,49 +144,49 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
144
 
145
  public function testEndFilter() {
146
  $c = "test";
147
- $this->assertEquals("test", EndFilter($c, "xxx"));
148
 
149
  $c = "test xxx";
150
- $this->assertEquals("test ", EndFilter($c, "xxx"));
151
 
152
  $c = "test xxx test";
153
- $this->assertEquals("test ", EndFilter($c, "xxx"));
154
 
155
  $c = "tags: Station, Kohnen, Flugzeug\n:end\n21.10.2012";
156
- $this->assertEquals("tags: Station, Kohnen, Flugzeug\n", EndFilter($c, ":end"));
157
 
158
  $c = "This is a test :end";
159
- $this->assertEquals("This is a test ", EndFilter($c, ":end"));
160
  }
161
 
162
  public function testFilterNewLines() {
163
  $c = "test";
164
- $this->assertEquals("test", FilterNewLines($c));
165
- $this->assertEquals("test", FilterNewLines($c, true));
166
 
167
  $c = "test\n";
168
- $this->assertEquals("test ", FilterNewLines($c));
169
- $this->assertEquals("test<br />\n", FilterNewLines($c, true));
170
 
171
  $c = "test\r\n";
172
- $this->assertEquals("test ", FilterNewLines($c));
173
- $this->assertEquals("test<br />\n", FilterNewLines($c, true));
174
 
175
  $c = "test\r";
176
- $this->assertEquals("test ", FilterNewLines($c));
177
- $this->assertEquals("test<br />\n", FilterNewLines($c, true));
178
 
179
  $c = "test\n\n";
180
- $this->assertEquals("test ", FilterNewLines($c));
181
- $this->assertEquals("test<br />\n", FilterNewLines($c, true));
182
 
183
  $c = "test\r\n\r\n";
184
- $this->assertEquals("test ", FilterNewLines($c));
185
- $this->assertEquals("test<br />\n", FilterNewLines($c, true));
186
 
187
  $c = "test\r\n\r\ntest\n\ntest\rtest\r\ntest\ntest";
188
- $this->assertEquals("test test test test test test", FilterNewLines($c));
189
- $this->assertEquals("test<br />\ntest<br />\ntest<br />\ntest<br />\ntest<br />\ntest", FilterNewLines($c, true));
190
  }
191
 
192
  public function testGetNameFromEmail() {
@@ -197,110 +197,110 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
197
 
198
  public function testGetPostType() {
199
  $subject = "test";
200
- $this->assertEquals("post", GetPostType($subject));
201
  $this->assertEquals("test", $subject);
202
 
203
  $subject = "custom//test";
204
- $this->assertEquals("custom", GetPostType($subject));
205
  $this->assertEquals("test", $subject);
206
 
207
  $subject = "//test";
208
- $this->assertEquals("post", GetPostType($subject));
209
  $this->assertEquals("test", $subject);
210
 
211
  $subject = "//";
212
- $this->assertEquals("post", GetPostType($subject));
213
  $this->assertEquals("", $subject);
214
 
215
  $subject = "Image//test";
216
- $this->assertEquals("image", GetPostType($subject));
217
  $this->assertEquals("test", $subject);
218
 
219
  $subject = "Image // test";
220
- $this->assertEquals("image", GetPostType($subject));
221
  $this->assertEquals("test", $subject);
222
 
223
  $subject = "video//test";
224
- $this->assertEquals("video", GetPostType($subject));
225
  $this->assertEquals("test", $subject);
226
  }
227
 
228
  public function testGetPostExcerpt() {
229
  $c = "test";
230
- $this->assertEquals("", GetPostExcerpt($c, false, false));
231
 
232
  $c = ":excerptstart test :excerptend test";
233
- $this->assertEquals("test ", GetPostExcerpt($c, false, false));
234
 
235
  $c = ":excerptstart test";
236
- $this->assertEquals("", GetPostExcerpt($c, false, false));
237
 
238
  $c = "test :excerptend test";
239
- $this->assertEquals("", GetPostExcerpt($c, false, false));
240
  }
241
 
242
  public function testGetPostCategories() {
243
  global $wpdb;
244
 
245
  $s = "test";
246
- $c = GetPostCategories($s, "default");
247
  $this->assertEquals("default", $c[0]);
248
  $this->assertEquals("test", $s);
249
 
250
  $s = ":test";
251
- $c = GetPostCategories($s, "default");
252
  $this->assertEquals("default", $c[0]);
253
  $this->assertEquals(":test", $s);
254
 
255
  $wpdb->t_get_var = "1";
256
  $s = "1: test";
257
- $c = GetPostCategories($s, "default");
258
  $this->assertEquals("1", $c[0]);
259
  $this->assertEquals("test", $s);
260
 
261
  $wpdb->t_get_var = null;
262
  $s = "not a category: test";
263
- $c = GetPostCategories($s, "default");
264
  $this->assertEquals("default", $c[0]);
265
  $this->assertEquals("not a category: test", $s);
266
 
267
  $s = "[not a category] test";
268
- $c = GetPostCategories($s, "default");
269
  $this->assertEquals("default", $c[0]);
270
  $this->assertEquals("[not a category] test", $s);
271
 
272
  $s = "-not a category- test";
273
- $c = GetPostCategories($s, "default");
274
  $this->assertEquals("default", $c[0]);
275
  $this->assertEquals("-not a category- test", $s);
276
 
277
  $wpdb->t_get_var = "general";
278
  $s = "general: test";
279
- $c = GetPostCategories($s, "default");
280
  $this->assertEquals("general", $c[0]);
281
  $this->assertEquals("test", $s);
282
 
283
  $wpdb->t_get_var = "general";
284
  $s = "[general] test";
285
- $c = GetPostCategories($s, "default");
286
  $this->assertEquals("general", $c[0]);
287
  $this->assertEquals("test", $s);
288
 
289
  $wpdb->t_get_var = "general";
290
  $s = "-general- test";
291
- $c = GetPostCategories($s, "default");
292
  $this->assertEquals("general", $c[0]);
293
  $this->assertEquals("test", $s);
294
 
295
  $wpdb->t_get_var = "";
296
  $s = "specific: test";
297
- $c = GetPostCategories($s, "default");
298
  $this->assertEquals("default", $c[0]);
299
  $this->assertEquals("specific: test", $s);
300
 
301
  $wpdb->t_get_var = array("1", "1");
302
  $s = "[1] [1] test";
303
- $c = GetPostCategories($s, "default");
304
  $this->assertEquals(2, count($c));
305
  $this->assertEquals("1", $c[0]);
306
  $this->assertEquals("1", $c[1]);
@@ -308,18 +308,18 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
308
 
309
  $wpdb->t_get_var = array(null, null, null, "general");
310
  $s = "[general] test: with colon";
311
- $c = GetPostCategories($s, "default");
312
  $this->assertEquals("general", $c[0]);
313
  $this->assertEquals("test: with colon", $s);
314
  }
315
 
316
  public function testHTML2HTML() {
317
- $this->assertEquals("", HTML2HTML(""));
318
- $this->assertEquals("test", HTML2HTML("test"));
319
- $this->assertEquals("<div>test</div>\n", HTML2HTML("<html lang='en'><body>test</body></html>"));
320
- $this->assertEquals("<div>test</div>\n", HTML2HTML("<html lang='en'><head><title>title</title></head><body>test</body></html>"));
321
- $this->assertEquals("<div>test</div>\n", HTML2HTML("<body>test</body>"));
322
- $this->assertEquals("<strong>test</strong>", HTML2HTML("<strong>test</strong>"));
323
  }
324
 
325
  public function testSafeFileName() {
@@ -327,15 +327,15 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
327
  }
328
 
329
  public function testremove_signature() {
330
- $this->assertEquals("", remove_signature("", array()));
331
- $this->assertEquals("test", remove_signature("test", array()));
332
- $this->assertEquals("\n", remove_signature("", array("--", "- --")));
333
- $this->assertEquals("test\n", remove_signature("test", array("--", "- --")));
334
- $this->assertEquals("line 1\nline 2\n", remove_signature("line 1\nline 2\n--\nsig line 1\nsig line 2", array("--", "- --")));
335
- $this->assertEquals("line 1\nline 2\n", remove_signature("line 1\nline 2\n- --\nsig line 1\nsig line 2", array("--", "- --")));
336
- $this->assertEquals("line 1\nline 2\n", remove_signature("line 1\nline 2\n-- \nsig line 1\nsig line 2", array("--", "- --")));
337
- $this->assertEquals("line 1\nline 2\n", remove_signature("line 1\nline 2\n --\nsig line 1\nsig line 2", array("--", "- --")));
338
- $this->assertEquals("line 1\nline 2\n", remove_signature("line 1\nline 2\n--", array("--", "- --")));
339
  }
340
 
341
  public function testmore_reccurences() {
@@ -346,75 +346,75 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
346
 
347
  public function testpostie_get_tags() {
348
  $c = "";
349
- $t = postie_get_tags($c, "");
350
  $this->assertEquals(0, count($t));
351
  $this->assertEquals("", $c);
352
 
353
  $c = "test";
354
- $t = postie_get_tags($c, "");
355
  $this->assertEquals(0, count($t));
356
  $this->assertEquals("test", $c);
357
 
358
  $c = "test";
359
- $t = postie_get_tags($c, array("tag1"));
360
  $this->assertEquals(1, count($t));
361
  $this->assertEquals("tag1", $t[0]);
362
  $this->assertEquals("test", $c);
363
 
364
  $c = "test tags:";
365
- $t = postie_get_tags($c, "");
366
  $this->assertEquals(0, count($t));
367
  $this->assertEquals("test tags:", $c);
368
 
369
  $c = "test tags:\n";
370
- $t = postie_get_tags($c, "");
371
  $this->assertEquals(0, count($t));
372
  $this->assertEquals("test tags:\n", $c);
373
 
374
  $c = "test tags: tag1";
375
- $t = postie_get_tags($c, "");
376
  $this->assertEquals(1, count($t));
377
  $this->assertEquals("test ", $c);
378
 
379
  $c = "test\ntags: tag1";
380
- $t = postie_get_tags($c, "");
381
  $this->assertEquals(1, count($t));
382
  $this->assertEquals("test\n", $c);
383
 
384
  $c = "test tags: tag1\n";
385
- $t = postie_get_tags($c, "");
386
  $this->assertEquals(1, count($t));
387
  $this->assertEquals("tag1", $t[0]);
388
  $this->assertEquals("test \n", $c);
389
 
390
  $c = "test tags:tag1";
391
- $t = postie_get_tags($c, "");
392
  $this->assertEquals(1, count($t));
393
  $this->assertEquals("tag1", $t[0]);
394
  $this->assertEquals("test ", $c);
395
 
396
  $c = "test tags:tag1";
397
- $t = postie_get_tags($c, array("tagx"));
398
  $this->assertEquals(1, count($t));
399
  $this->assertEquals("tag1", $t[0]);
400
  $this->assertEquals("test ", $c);
401
 
402
  $c = "test tags:tag1,tag2";
403
- $t = postie_get_tags($c, "");
404
  $this->assertEquals(2, count($t));
405
  $this->assertEquals("tag1", $t[0]);
406
  $this->assertEquals("tag2", $t[1]);
407
  $this->assertEquals("test ", $c);
408
 
409
  $c = "test tags: tag3,tag4\nmore stuff\n:end";
410
- $t = postie_get_tags($c, "");
411
  $this->assertEquals(2, count($t));
412
  $this->assertEquals("tag3", $t[0]);
413
  $this->assertEquals("tag4", $t[1]);
414
  $this->assertEquals("test \nmore stuff\n:end", $c);
415
 
416
  $c = "test tags:tag1,tag2\nmore stuff\n:end";
417
- $t = postie_get_tags($c, "");
418
  $this->assertEquals(2, count($t));
419
  $this->assertEquals("tag1", $t[0]);
420
  $this->assertEquals("tag2", $t[1]);
@@ -422,13 +422,73 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
422
  }
423
 
424
  public function testclickableLink() {
425
- $this->assertEquals("", clickableLink(""));
426
- $this->assertEquals("test", clickableLink("test"));
427
- $this->assertEquals('<a href="http://www.example.com" >http://www.example.com</a>', clickableLink("http://www.example.com"));
428
- $this->assertEquals('<a href="http://www.example.com">www.example.com</a>', clickableLink("www.example.com"));
429
- $this->assertEquals('<a href="http://www.example.com">www.example.com</a> <a href="http://www.example.com">www.example.com</a>', clickableLink("www.example.com www.example.com"));
430
- $this->assertEquals('<a href="mailto:bob@example.com">bob@example.com</a>', clickableLink("bob@example.com"));
 
 
 
 
431
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  }
433
 
434
  ?>
14
  public function testAllowCommentsOnPost() {
15
  $original_content = "test content, no comment control";
16
  $modified_content = "test content, no comment control";
17
+ $allow = tag_AllowCommentsOnPost($modified_content);
18
  $this->assertEquals("open", $allow);
19
  $this->assertEquals($original_content, $modified_content);
20
 
21
  $original_content = "test content, comment control closed ";
22
  $modified_content = "test content, comment control closed comments:0";
23
+ $allow = tag_AllowCommentsOnPost($modified_content);
24
  $this->assertEquals("closed", $allow);
25
  $this->assertEquals($original_content, $modified_content);
26
 
27
  $original_content = "test content, comment control open ";
28
  $modified_content = "test content, comment control open comments:1";
29
+ $allow = tag_AllowCommentsOnPost($modified_content);
30
  $this->assertEquals("open", $allow);
31
  $this->assertEquals($original_content, $modified_content);
32
 
33
  $original_content = "test content, comment control registered only ";
34
  $modified_content = "test content, comment control registered only comments:2";
35
+ $allow = tag_AllowCommentsOnPost($modified_content);
36
  $this->assertEquals("registered_only", $allow);
37
  $this->assertEquals($original_content, $modified_content);
38
  }
39
 
40
  public function testBannedFileName() {
41
+ $this->assertFalse(isBannedFileName("", null));
42
+ $this->assertFalse(isBannedFileName("", ""));
43
+ $this->assertFalse(isBannedFileName("", array()));
44
+ $this->assertFalse(isBannedFileName("test", array()));
45
+ $this->assertTrue(isBannedFileName("test", array("test")));
46
+ $this->assertFalse(isBannedFileName("test", array("test1")));
47
+ $this->assertTrue(isBannedFileName("test.exe", array("*.exe")));
48
+ $this->assertFalse(isBannedFileName("test.pdf", array("*.exe")));
49
+ $this->assertFalse(isBannedFileName("test.pdf", array("*.exe", "*.js", "*.cmd")));
50
+ $this->assertFalse(isBannedFileName("test.cmd.pdf", array("*.exe", "*.js", "*.cmd")));
51
+ $this->assertTrue(isBannedFileName("test test.exe", array("*.exe")));
52
  }
53
 
54
  public function testCheckEmailAddress() {
55
+ $this->assertFalse(isEmailAddressAuthorized(null, null));
56
+ $this->assertFalse(isEmailAddressAuthorized(null, array()));
57
+ $this->assertFalse(isEmailAddressAuthorized("", array()));
58
+ $this->assertFalse(isEmailAddressAuthorized("", array("")));
59
+ $this->assertFalse(isEmailAddressAuthorized("bob", array("jane")));
60
+ $this->assertTrue(isEmailAddressAuthorized("bob", array("bob")));
61
+ $this->assertTrue(isEmailAddressAuthorized("bob", array("BoB")));
62
+ $this->assertTrue(isEmailAddressAuthorized("bob", array("bob", "jane")));
63
+ $this->assertTrue(isEmailAddressAuthorized("bob", array("jane", "bob")));
64
  }
65
 
66
  public function testConvertUTF8ToISO_8859_1() {
144
 
145
  public function testEndFilter() {
146
  $c = "test";
147
+ $this->assertEquals("test", filter_end($c, "xxx"));
148
 
149
  $c = "test xxx";
150
+ $this->assertEquals("test ", filter_end($c, "xxx"));
151
 
152
  $c = "test xxx test";
153
+ $this->assertEquals("test ", filter_end($c, "xxx"));
154
 
155
  $c = "tags: Station, Kohnen, Flugzeug\n:end\n21.10.2012";
156
+ $this->assertEquals("tags: Station, Kohnen, Flugzeug\n", filter_end($c, ":end"));
157
 
158
  $c = "This is a test :end";
159
+ $this->assertEquals("This is a test ", filter_end($c, ":end"));
160
  }
161
 
162
  public function testFilterNewLines() {
163
  $c = "test";
164
+ $this->assertEquals("test", filter_newlines($c));
165
+ $this->assertEquals("test", filter_newlines($c, true));
166
 
167
  $c = "test\n";
168
+ $this->assertEquals("test ", filter_newlines($c));
169
+ $this->assertEquals("test<br />\n", filter_newlines($c, true));
170
 
171
  $c = "test\r\n";
172
+ $this->assertEquals("test ", filter_newlines($c));
173
+ $this->assertEquals("test<br />\n", filter_newlines($c, true));
174
 
175
  $c = "test\r";
176
+ $this->assertEquals("test ", filter_newlines($c));
177
+ $this->assertEquals("test<br />\n", filter_newlines($c, true));
178
 
179
  $c = "test\n\n";
180
+ $this->assertEquals("test ", filter_newlines($c));
181
+ $this->assertEquals("test<br />\n", filter_newlines($c, true));
182
 
183
  $c = "test\r\n\r\n";
184
+ $this->assertEquals("test ", filter_newlines($c));
185
+ $this->assertEquals("test<br />\n", filter_newlines($c, true));
186
 
187
  $c = "test\r\n\r\ntest\n\ntest\rtest\r\ntest\ntest";
188
+ $this->assertEquals("test test test test test test", filter_newlines($c));
189
+ $this->assertEquals("test<br />\ntest<br />\ntest<br />\ntest<br />\ntest<br />\ntest", filter_newlines($c, true));
190
  }
191
 
192
  public function testGetNameFromEmail() {
197
 
198
  public function testGetPostType() {
199
  $subject = "test";
200
+ $this->assertEquals("post", tag_PostType($subject));
201
  $this->assertEquals("test", $subject);
202
 
203
  $subject = "custom//test";
204
+ $this->assertEquals("custom", tag_PostType($subject));
205
  $this->assertEquals("test", $subject);
206
 
207
  $subject = "//test";
208
+ $this->assertEquals("post", tag_PostType($subject));
209
  $this->assertEquals("test", $subject);
210
 
211
  $subject = "//";
212
+ $this->assertEquals("post", tag_PostType($subject));
213
  $this->assertEquals("", $subject);
214
 
215
  $subject = "Image//test";
216
+ $this->assertEquals("image", tag_PostType($subject));
217
  $this->assertEquals("test", $subject);
218
 
219
  $subject = "Image // test";
220
+ $this->assertEquals("image", tag_PostType($subject));
221
  $this->assertEquals("test", $subject);
222
 
223
  $subject = "video//test";
224
+ $this->assertEquals("video", tag_PostType($subject));
225
  $this->assertEquals("test", $subject);
226
  }
227
 
228
  public function testGetPostExcerpt() {
229
  $c = "test";
230
+ $this->assertEquals("", tag_Excerpt($c, false, false));
231
 
232
  $c = ":excerptstart test :excerptend test";
233
+ $this->assertEquals("test ", tag_Excerpt($c, false, false));
234
 
235
  $c = ":excerptstart test";
236
+ $this->assertEquals("", tag_Excerpt($c, false, false));
237
 
238
  $c = "test :excerptend test";
239
+ $this->assertEquals("", tag_Excerpt($c, false, false));
240
  }
241
 
242
  public function testGetPostCategories() {
243
  global $wpdb;
244
 
245
  $s = "test";
246
+ $c = tag_categories($s, "default");
247
  $this->assertEquals("default", $c[0]);
248
  $this->assertEquals("test", $s);
249
 
250
  $s = ":test";
251
+ $c = tag_categories($s, "default");
252
  $this->assertEquals("default", $c[0]);
253
  $this->assertEquals(":test", $s);
254
 
255
  $wpdb->t_get_var = "1";
256
  $s = "1: test";
257
+ $c = tag_categories($s, "default");
258
  $this->assertEquals("1", $c[0]);
259
  $this->assertEquals("test", $s);
260
 
261
  $wpdb->t_get_var = null;
262
  $s = "not a category: test";
263
+ $c = tag_categories($s, "default");
264
  $this->assertEquals("default", $c[0]);
265
  $this->assertEquals("not a category: test", $s);
266
 
267
  $s = "[not a category] test";
268
+ $c = tag_categories($s, "default");
269
  $this->assertEquals("default", $c[0]);
270
  $this->assertEquals("[not a category] test", $s);
271
 
272
  $s = "-not a category- test";
273
+ $c = tag_categories($s, "default");
274
  $this->assertEquals("default", $c[0]);
275
  $this->assertEquals("-not a category- test", $s);
276
 
277
  $wpdb->t_get_var = "general";
278
  $s = "general: test";
279
+ $c = tag_categories($s, "default");
280
  $this->assertEquals("general", $c[0]);
281
  $this->assertEquals("test", $s);
282
 
283
  $wpdb->t_get_var = "general";
284
  $s = "[general] test";
285
+ $c = tag_categories($s, "default");
286
  $this->assertEquals("general", $c[0]);
287
  $this->assertEquals("test", $s);
288
 
289
  $wpdb->t_get_var = "general";
290
  $s = "-general- test";
291
+ $c = tag_categories($s, "default");
292
  $this->assertEquals("general", $c[0]);
293
  $this->assertEquals("test", $s);
294
 
295
  $wpdb->t_get_var = "";
296
  $s = "specific: test";
297
+ $c = tag_categories($s, "default");
298
  $this->assertEquals("default", $c[0]);
299
  $this->assertEquals("specific: test", $s);
300
 
301
  $wpdb->t_get_var = array("1", "1");
302
  $s = "[1] [1] test";
303
+ $c = tag_categories($s, "default");
304
  $this->assertEquals(2, count($c));
305
  $this->assertEquals("1", $c[0]);
306
  $this->assertEquals("1", $c[1]);
308
 
309
  $wpdb->t_get_var = array(null, null, null, "general");
310
  $s = "[general] test: with colon";
311
+ $c = tag_categories($s, "default");
312
  $this->assertEquals("general", $c[0]);
313
  $this->assertEquals("test: with colon", $s);
314
  }
315
 
316
  public function testHTML2HTML() {
317
+ $this->assertEquals("", filter_CleanHtml(""));
318
+ $this->assertEquals("test", filter_CleanHtml("test"));
319
+ $this->assertEquals("<div>test</div>\n", filter_CleanHtml("<html lang='en'><body>test</body></html>"));
320
+ $this->assertEquals("<div>test</div>\n", filter_CleanHtml("<html lang='en'><head><title>title</title></head><body>test</body></html>"));
321
+ $this->assertEquals("<div>test</div>\n", filter_CleanHtml("<body>test</body>"));
322
+ $this->assertEquals("<strong>test</strong>", filter_CleanHtml("<strong>test</strong>"));
323
  }
324
 
325
  public function testSafeFileName() {
327
  }
328
 
329
  public function testremove_signature() {
330
+ $this->assertEquals("", filter_RemoveSignature("", array()));
331
+ $this->assertEquals("test", filter_RemoveSignature("test", array()));
332
+ $this->assertEquals("\n", filter_RemoveSignature("", array("--", "- --")));
333
+ $this->assertEquals("test\n", filter_RemoveSignature("test", array("--", "- --")));
334
+ $this->assertEquals("line 1\nline 2\n", filter_RemoveSignature("line 1\nline 2\n--\nsig line 1\nsig line 2", array("--", "- --")));
335
+ $this->assertEquals("line 1\nline 2\n", filter_RemoveSignature("line 1\nline 2\n- --\nsig line 1\nsig line 2", array("--", "- --")));
336
+ $this->assertEquals("line 1\nline 2\n", filter_RemoveSignature("line 1\nline 2\n-- \nsig line 1\nsig line 2", array("--", "- --")));
337
+ $this->assertEquals("line 1\nline 2\n", filter_RemoveSignature("line 1\nline 2\n --\nsig line 1\nsig line 2", array("--", "- --")));
338
+ $this->assertEquals("line 1\nline 2\n", filter_RemoveSignature("line 1\nline 2\n--", array("--", "- --")));
339
  }
340
 
341
  public function testmore_reccurences() {
346
 
347
  public function testpostie_get_tags() {
348
  $c = "";
349
+ $t = tag_Tags($c, "");
350
  $this->assertEquals(0, count($t));
351
  $this->assertEquals("", $c);
352
 
353
  $c = "test";
354
+ $t = tag_Tags($c, "");
355
  $this->assertEquals(0, count($t));
356
  $this->assertEquals("test", $c);
357
 
358
  $c = "test";
359
+ $t = tag_Tags($c, array("tag1"));
360
  $this->assertEquals(1, count($t));
361
  $this->assertEquals("tag1", $t[0]);
362
  $this->assertEquals("test", $c);
363
 
364
  $c = "test tags:";
365
+ $t = tag_Tags($c, "");
366
  $this->assertEquals(0, count($t));
367
  $this->assertEquals("test tags:", $c);
368
 
369
  $c = "test tags:\n";
370
+ $t = tag_Tags($c, "");
371
  $this->assertEquals(0, count($t));
372
  $this->assertEquals("test tags:\n", $c);
373
 
374
  $c = "test tags: tag1";
375
+ $t = tag_Tags($c, "");
376
  $this->assertEquals(1, count($t));
377
  $this->assertEquals("test ", $c);
378
 
379
  $c = "test\ntags: tag1";
380
+ $t = tag_Tags($c, "");
381
  $this->assertEquals(1, count($t));
382
  $this->assertEquals("test\n", $c);
383
 
384
  $c = "test tags: tag1\n";
385
+ $t = tag_Tags($c, "");
386
  $this->assertEquals(1, count($t));
387
  $this->assertEquals("tag1", $t[0]);
388
  $this->assertEquals("test \n", $c);
389
 
390
  $c = "test tags:tag1";
391
+ $t = tag_Tags($c, "");
392
  $this->assertEquals(1, count($t));
393
  $this->assertEquals("tag1", $t[0]);
394
  $this->assertEquals("test ", $c);
395
 
396
  $c = "test tags:tag1";
397
+ $t = tag_Tags($c, array("tagx"));
398
  $this->assertEquals(1, count($t));
399
  $this->assertEquals("tag1", $t[0]);
400
  $this->assertEquals("test ", $c);
401
 
402
  $c = "test tags:tag1,tag2";
403
+ $t = tag_Tags($c, "");
404
  $this->assertEquals(2, count($t));
405
  $this->assertEquals("tag1", $t[0]);
406
  $this->assertEquals("tag2", $t[1]);
407
  $this->assertEquals("test ", $c);
408
 
409
  $c = "test tags: tag3,tag4\nmore stuff\n:end";
410
+ $t = tag_Tags($c, "");
411
  $this->assertEquals(2, count($t));
412
  $this->assertEquals("tag3", $t[0]);
413
  $this->assertEquals("tag4", $t[1]);
414
  $this->assertEquals("test \nmore stuff\n:end", $c);
415
 
416
  $c = "test tags:tag1,tag2\nmore stuff\n:end";
417
+ $t = tag_Tags($c, "");
418
  $this->assertEquals(2, count($t));
419
  $this->assertEquals("tag1", $t[0]);
420
  $this->assertEquals("tag2", $t[1]);
422
  }
423
 
424
  public function testclickableLink() {
425
+ $this->assertEquals("", filter_linkify(""));
426
+ $this->assertEquals("test", filter_linkify("test"));
427
+ $this->assertEquals('<a href="http://www.example.com" >http://www.example.com</a>', filter_linkify("http://www.example.com"));
428
+ $this->assertEquals('<a href="http://www.example.com">www.example.com</a>', filter_linkify("www.example.com"));
429
+ $this->assertEquals('<a href="http://www.example.com">www.example.com</a> <a href="http://www.example.com">www.example.com</a>', filter_linkify("www.example.com www.example.com"));
430
+ $this->assertEquals('<a href="mailto:bob@example.com">bob@example.com</a>', filter_linkify("bob@example.com"));
431
+ $this->assertEquals("<img src='http://www.example.com'/>", filter_linkify("<img src='http://www.example.com'/>"));
432
+ $this->assertEquals("<html><head><title></title></head><body><img src='http://www.example.com'/></body></html>", filter_linkify("<html><head><title></title></head><body><img src='http://www.example.com'/></body></html>"));
433
+ $this->assertEquals('<html><head><title></title></head><body><img src="http://www.example.com"/><a href="http://www.example.com">www.example.com</a></body></html>', filter_linkify('<html><head><title></title></head><body><img src="http://www.example.com"/>www.example.com</body></html>'));
434
+ $this->assertEquals("<img src='http://www.example.com'/>", filter_linkify("<img src='http://www.example.com'/>"));
435
  }
436
+
437
+ public function testfilter_Videos() {
438
+ $this->assertEquals("A youtube link <embed width='425' height='344' allowfullscreen='true' allowscriptaccess='always' type='application/x-shockwave-flash' src='http://www.youtube.com/v/oAguHwl9Vzq&hl=en&fs=1' />", filter_Videos("A youtube link https://www.youtube.com/watch?v=oAguHwl9Vzq", false));
439
+ $this->assertEquals("A youtube link [youtube oAguHwl9Vzq]", filter_Videos("A youtube link https://www.youtube.com/watch?v=oAguHwl9Vzq",true));
440
+ }
441
+
442
+ public function testtag_Date() {
443
+ $c="";
444
+ $this->assertEquals(null, tag_Date(&$c, null));
445
+ $this->assertEquals("", $c);
446
+
447
+ $c="date:";
448
+ $this->assertEquals(null, tag_Date(&$c, null));
449
+ $this->assertEquals("date:", $c);
450
+
451
+ $c="date: nothing";
452
+ $this->assertEquals(null, tag_Date(&$c, null));
453
+ $this->assertEquals("date: nothing", $c);
454
+
455
+ $c="date: 1";
456
+ $this->assertEquals(null, tag_Date(&$c, null));
457
+ $this->assertEquals("date: 1", $c);
458
+
459
+ $c="date: 12/31/2013";
460
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
461
+ $this->assertEquals("", $c);
462
+
463
+ $c="date:12/31/2013";
464
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
465
+ $this->assertEquals("", $c);
466
+
467
+ $c="Date: 12/31/2013";
468
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
469
+ $this->assertEquals("", $c);
470
+
471
+ $c="DATE: 12/31/2013";
472
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
473
+ $this->assertEquals("", $c);
474
+
475
+ $c="date: 31-12-2013";
476
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
477
+ $this->assertEquals("", $c);
478
+
479
+ $c="date: 31.12.2013";
480
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
481
+ $this->assertEquals("", $c);
482
+
483
+ $c="date: Dec 31, 2013";
484
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
485
+ $this->assertEquals("", $c);
486
+
487
+ $c = "date: 12/31/2013\nstuff";
488
+ $this->assertEquals("2013-12-31", tag_Date(&$c, null));
489
+ $this->assertEquals("stuff", $c);
490
+ }
491
+
492
  }
493
 
494
  ?>