Postie - Version 1.7.15

Version Description

(2015-10-02) = * Completely replace linkify logic * Support youtu.be links

Download this release

Release Info

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

Code changes from version 1.7.14 to 1.7.15

Files changed (6) hide show
  1. docs/Changes.txt +5 -1
  2. docs/Postie.txt +1 -1
  3. lib_autolink.php +314 -0
  4. postie-functions.php +32 -36
  5. postie.php +4 -3
  6. readme.txt +6 -2
docs/Changes.txt CHANGED
@@ -27,8 +27,12 @@ All script, style and body tags are stripped from html emails.
27
  Attachments are now processed in the order they were attached.
28
 
29
  == CHANGELOG ==
 
 
 
 
30
  = 1.7.14 (2015-10-01) =
31
- * Fix bug is new linkify logic
32
 
33
  = 1.7.13 (2015-10-01) =
34
  * Fix support for "Automatically convert urls to links" with html
27
  Attachments are now processed in the order they were attached.
28
 
29
  == CHANGELOG ==
30
+ = 1.7.15 (2015-10-02) =
31
+ * Completely replace linkify logic
32
+ * Support youtu.be links
33
+
34
  = 1.7.14 (2015-10-01) =
35
+ * Fix bug in new linkify logic
36
 
37
  = 1.7.13 (2015-10-01) =
38
  * Fix support for "Automatically convert urls to links" with html
docs/Postie.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.3.1
9
- Stable tag: 1.7.14
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.3.1
9
+ Stable tag: 1.7.15
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
lib_autolink.php ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class PostieAutolink {
4
+ #
5
+ # A PHP auto-linking library
6
+ #
7
+ # https://github.com/iamcal/lib_autolink
8
+ #
9
+ # By Cal Henderson <cal@iamcal.com>
10
+ # This code is licensed under the MIT license
11
+ #
12
+ # Modified by Wayne Allen to work with Postie
13
+ # * Wrapped in class
14
+ # * Global options removed
15
+ #
16
+ ####################################################################
17
+
18
+ function autolink($text, $limit = 200, $tagfill = '', $auto_title = true) {
19
+
20
+ $text = $this->autolink_do($text, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title);
21
+ $text = $this->autolink_do($text, '!(mailto|skype):!i', $limit, $tagfill, $auto_title);
22
+ $text = $this->autolink_do($text, '!www\\.!i', $limit, $tagfill, $auto_title, 'http://');
23
+ return $text;
24
+ }
25
+
26
+ function autolink_do($text, $sub, $limit, $tagfill, $auto_title, $force_prefix = null) {
27
+
28
+ $text_l = StrToLower($text);
29
+ $cursor = 0;
30
+ $loop = 1;
31
+ $buffer = '';
32
+
33
+ while (($cursor < strlen($text)) && $loop) {
34
+
35
+ $ok = 1;
36
+ $matched = preg_match($sub, $text_l, $m, PREG_OFFSET_CAPTURE, $cursor);
37
+
38
+ if (!$matched) {
39
+
40
+ $loop = 0;
41
+ $ok = 0;
42
+ } else {
43
+
44
+ $pos = $m[0][1];
45
+ $sub_len = strlen($m[0][0]);
46
+
47
+ $pre_hit = substr($text, $cursor, $pos - $cursor);
48
+ $hit = substr($text, $pos, $sub_len);
49
+ $pre = substr($text, 0, $pos);
50
+ $post = substr($text, $pos + $sub_len);
51
+
52
+ $fail_text = $pre_hit . $hit;
53
+ $fail_len = strlen($fail_text);
54
+
55
+ #
56
+ # substring found - first check to see if we're inside a link tag already...
57
+ #
58
+
59
+ $bits = preg_split("!</a>!i", $pre);
60
+ $last_bit = array_pop($bits);
61
+ if (preg_match("!<a\s!i", $last_bit)) {
62
+
63
+ #echo "fail 1 at $cursor<br />\n";
64
+
65
+ $ok = 0;
66
+ $cursor += $fail_len;
67
+ $buffer .= $fail_text;
68
+ }
69
+ }
70
+
71
+ #
72
+ # looks like a nice spot to autolink from - check the pre
73
+ # to see if there was whitespace before this match
74
+ #
75
+
76
+ if ($ok) {
77
+
78
+ if ($pre) {
79
+ if (!preg_match('![\s\(\[\{>]$!s', $pre)) {
80
+
81
+ #echo "fail 2 at $cursor ($pre)<br />\n";
82
+
83
+ $ok = 0;
84
+ $cursor += $fail_len;
85
+ $buffer .= $fail_text;
86
+ }
87
+ }
88
+ }
89
+
90
+ #
91
+ # we want to autolink here - find the extent of the url
92
+ #
93
+
94
+ if ($ok) {
95
+ if (preg_match('/^([a-z0-9\-\.\/\-_%~!?=,:;&+*#@\(\)\$]+)/i', $post, $matches)) {
96
+
97
+ $url = $hit . $matches[1];
98
+
99
+ $cursor += strlen($url) + strlen($pre_hit);
100
+ $buffer .= $pre_hit;
101
+
102
+ $url = html_entity_decode($url);
103
+
104
+
105
+ #
106
+ # remove trailing punctuation from url
107
+ #
108
+
109
+ while (preg_match('|[.,!;:?]$|', $url)) {
110
+ $url = substr($url, 0, strlen($url) - 1);
111
+ $cursor--;
112
+ }
113
+ foreach (array('()', '[]', '{}') as $pair) {
114
+ $o = substr($pair, 0, 1);
115
+ $c = substr($pair, 1, 1);
116
+ if (preg_match("!^(\\$c|^)[^\\$o]+\\$c$!", $url)) {
117
+ $url = substr($url, 0, strlen($url) - 1);
118
+ $cursor--;
119
+ }
120
+ }
121
+
122
+
123
+ #
124
+ # nice-i-fy url here
125
+ #
126
+
127
+ $link_url = $url;
128
+ $display_url = $url;
129
+
130
+ if ($force_prefix)
131
+ $link_url = $force_prefix . $link_url;
132
+
133
+
134
+ if (preg_match('!^(http|https)://!i', $display_url, $m)) {
135
+
136
+ $display_url = substr($display_url, strlen($m[1]) + 3);
137
+ }
138
+
139
+
140
+ $display_url = $this->autolink_label($display_url, $limit);
141
+
142
+
143
+ #
144
+ # add the url
145
+ #
146
+
147
+ $currentTagfill = $tagfill;
148
+ if ($display_url != $link_url && !preg_match('@title=@msi', $currentTagfill) && $auto_title) {
149
+
150
+ $display_quoted = preg_quote($display_url, '!');
151
+
152
+ if (!preg_match("!^(http|https)://{$display_quoted}$!i", $link_url)) {
153
+
154
+ $currentTagfill .= ' title="' . $link_url . '"';
155
+ }
156
+ }
157
+
158
+ $link_url_enc = HtmlSpecialChars($link_url);
159
+ $display_url_enc = HtmlSpecialChars($display_url);
160
+
161
+ $buffer .= "<a href=\"{$link_url_enc}\"$currentTagfill>{$display_url_enc}</a>";
162
+ } else {
163
+ #echo "fail 3 at $cursor<br />\n";
164
+
165
+ $ok = 0;
166
+ $cursor += $fail_len;
167
+ $buffer .= $fail_text;
168
+ }
169
+ }
170
+ }
171
+
172
+ #
173
+ # add everything from the cursor to the end onto the buffer.
174
+ #
175
+
176
+ $buffer .= substr($text, $cursor);
177
+
178
+ return $buffer;
179
+ }
180
+
181
+ ####################################################################
182
+
183
+ function autolink_label($text, $limit) {
184
+
185
+ if (!$limit) {
186
+ return $text;
187
+ }
188
+
189
+ if (strlen($text) > $limit) {
190
+ return substr($text, 0, $limit - 3) . '...';
191
+ }
192
+
193
+ return $text;
194
+ }
195
+
196
+ ####################################################################
197
+
198
+ function autolink_email($text, $tagfill = '') {
199
+
200
+ $atom = '[^()<>@,;:\\\\".\\[\\]\\x00-\\x20\\x7f]+'; # from RFC822
201
+ #die($atom);
202
+
203
+ $text_l = StrToLower($text);
204
+ $cursor = 0;
205
+ $loop = 1;
206
+ $buffer = '';
207
+
208
+ while (($cursor < strlen($text)) && $loop) {
209
+
210
+ #
211
+ # find an '@' symbol
212
+ #
213
+
214
+ $ok = 1;
215
+ $pos = strpos($text_l, '@', $cursor);
216
+
217
+ if ($pos === false) {
218
+
219
+ $loop = 0;
220
+ $ok = 0;
221
+ } else {
222
+
223
+ $pre = substr($text, $cursor, $pos - $cursor);
224
+ $hit = substr($text, $pos, 1);
225
+ $post = substr($text, $pos + 1);
226
+
227
+ $fail_text = $pre . $hit;
228
+ $fail_len = strlen($fail_text);
229
+
230
+ #die("$pre::$hit::$post::$fail_text");
231
+ #
232
+ # substring found - first check to see if we're inside a link tag already...
233
+ #
234
+
235
+ $bits = preg_split("!</a>!i", $pre);
236
+ $last_bit = array_pop($bits);
237
+ if (preg_match("!<a\s!i", $last_bit)) {
238
+
239
+ #echo "fail 1 at $cursor<br />\n";
240
+
241
+ $ok = 0;
242
+ $cursor += $fail_len;
243
+ $buffer .= $fail_text;
244
+ }
245
+ }
246
+
247
+ #
248
+ # check backwards
249
+ #
250
+
251
+ if ($ok) {
252
+ if (preg_match("!($atom(\.$atom)*)\$!", $pre, $matches)) {
253
+
254
+ # move matched part of address into $hit
255
+
256
+ $len = strlen($matches[1]);
257
+ $plen = strlen($pre);
258
+
259
+ $hit = substr($pre, $plen - $len) . $hit;
260
+ $pre = substr($pre, 0, $plen - $len);
261
+ } else {
262
+
263
+ #echo "fail 2 at $cursor ($pre)<br />\n";
264
+
265
+ $ok = 0;
266
+ $cursor += $fail_len;
267
+ $buffer .= $fail_text;
268
+ }
269
+ }
270
+
271
+ #
272
+ # check forwards
273
+ #
274
+
275
+ if ($ok) {
276
+ if (preg_match("!^($atom(\.$atom)*)!", $post, $matches)) {
277
+
278
+ # move matched part of address into $hit
279
+
280
+ $len = strlen($matches[1]);
281
+
282
+ $hit .= substr($post, 0, $len);
283
+ $post = substr($post, $len);
284
+ } else {
285
+ #echo "fail 3 at $cursor ($post)<br />\n";
286
+
287
+ $ok = 0;
288
+ $cursor += $fail_len;
289
+ $buffer .= $fail_text;
290
+ }
291
+ }
292
+
293
+ #
294
+ # commit
295
+ #
296
+
297
+ if ($ok) {
298
+
299
+ $cursor += strlen($pre) + strlen($hit);
300
+ $buffer .= $pre;
301
+ $buffer .= "<a href=\"mailto:$hit\"$tagfill>$hit</a>";
302
+ }
303
+ }
304
+
305
+ #
306
+ # add everything from the cursor to the end onto the buffer.
307
+ #
308
+
309
+ $buffer .= substr($text, $cursor);
310
+
311
+ return $buffer;
312
+ }
313
+
314
+ }
postie-functions.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- $Id: postie-functions.php 1257771 2015-10-01 22:19:10Z WayneAllen $
4
  */
5
 
6
  //to turn on debug output add the following line to wp-config.php
@@ -517,23 +517,26 @@ function tag_PostType(&$subject, $postmodifiers, $config) {
517
  }
518
 
519
  function filter_Linkify($text, $isHtml) {
520
- # It turns urls into links, and video urls into embedded players
521
  DebugEcho("begin: filter_linkify");
522
- if ($isHtml) {
523
- $html = LoadDOM($text);
524
- if (false !== $html) {
525
- //DebugEcho("filter_linkify: " . $html->save());
526
- foreach ($html->find('text') as $element) {
527
- //DebugEcho("filter_linkify: " . $element->innertext);
528
- $element->innertext = make_links($element->innertext);
529
- }
530
- $ret = $html->save();
531
- }
532
- } else {
533
- $ret = make_links($text);
534
- }
 
 
 
 
535
  //DebugEcho("end: filter_linkify");
536
- return $ret;
537
  }
538
 
539
  function LoadDOM($text) {
@@ -541,25 +544,6 @@ function LoadDOM($text) {
541
  }
542
 
543
  function filter_Videos($text, $shortcode = false) {
544
- # It turns urls into links, and video urls into embedded players
545
- //DebugEcho("begin: filter_Videos");
546
- // $html = LoadDOM($text);
547
- // if ($html) {
548
- // foreach ($html->find('text') as $element) {
549
- // $element->innertext = linkifyVideo($element->innertext, $shortcode);
550
- // }
551
- // $ret = $html->save();
552
- // } else {
553
- $ret = linkifyVideo($text, $shortcode);
554
- // }
555
- //DebugEcho("end: filter_Videos");
556
- return $ret;
557
- }
558
-
559
- function linkifyVideo($text, $shortcode = false) {
560
- //$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
561
- //DebugEcho("linkify1: $text");
562
- // pad it with a space so we can match things at the start of the 1st line.
563
  $ret = ' ' . $text;
564
  if (strpos($ret, 'youtube') !== false) {
565
  // try to embed youtube videos
@@ -567,7 +551,19 @@ function linkifyVideo($text, $shortcode = false) {
567
  if ($shortcode) {
568
  $youtube_replace = "\\1[youtube \\3]\\4";
569
  } else {
570
- $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";
 
 
 
 
 
 
 
 
 
 
 
 
571
  }
572
  $ret = preg_replace($youtube, $youtube_replace, $ret);
573
  DebugEcho("youtube: $ret");
1
  <?php
2
  /*
3
+ $Id: postie-functions.php 1258511 2015-10-02 22:00:08Z WayneAllen $
4
  */
5
 
6
  //to turn on debug output add the following line to wp-config.php
517
  }
518
 
519
  function filter_Linkify($text, $isHtml) {
 
520
  DebugEcho("begin: filter_linkify");
521
+ $al = new PostieAutolink();
522
+ $text = $al->autolink($text);
523
+ return $al->autolink_email($text);
524
+
525
+ // if ($isHtml) {
526
+ // $html = LoadDOM($text);
527
+ // if (false !== $html) {
528
+ // //DebugEcho("filter_linkify: " . $html->save());
529
+ // foreach ($html->find('text') as $element) {
530
+ // //DebugEcho("filter_linkify: " . $element->innertext);
531
+ // $element->innertext = make_links($element->innertext);
532
+ // }
533
+ // $ret = $html->save();
534
+ // }
535
+ // } else {
536
+ // $ret = make_links($text);
537
+ // }
538
  //DebugEcho("end: filter_linkify");
539
+ //return $ret;
540
  }
541
 
542
  function LoadDOM($text) {
544
  }
545
 
546
  function filter_Videos($text, $shortcode = false) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  $ret = ' ' . $text;
548
  if (strpos($ret, 'youtube') !== false) {
549
  // try to embed youtube videos
551
  if ($shortcode) {
552
  $youtube_replace = "\\1[youtube \\3]\\4";
553
  } else {
554
+ $youtube_replace = "\\1<embed width='425' height='344' allowfullscreen='true' allowscriptaccess='always' type='application/x-shockwave-flash' src='https://www.youtube.com/v/\\3&hl=en&fs=1' />\\4";
555
+ }
556
+ $ret = preg_replace($youtube, $youtube_replace, $ret);
557
+ DebugEcho("youtube: $ret");
558
+ }
559
+
560
+ if (strpos($ret, 'youtu.be') !== false) {
561
+ // try to embed youtube videos
562
+ $youtube = "#(^|[\n ]|>)[\w]+?://(www\.)?youtu\.be/([_a-zA-Z0-9-]+).*?([ \n]|$|<)#is";
563
+ if ($shortcode) {
564
+ $youtube_replace = "\\1[youtube \\3]\\4";
565
+ } else {
566
+ $youtube_replace = "\\1<embed width='425' height='344' allowfullscreen='true' allowscriptaccess='always' type='application/x-shockwave-flash' src='https://www.youtube.com/v/\\3&hl=en&fs=1' />\\4";
567
  }
568
  $ret = preg_replace($youtube, $youtube_replace, $ret);
569
  DebugEcho("youtube: $ret");
postie.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Signifigantly upgrades the Post by Email features of Word Press.
7
- Version: 1.7.14
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
@@ -28,11 +28,12 @@
28
  */
29
 
30
  /*
31
- $Id: postie.php 1257771 2015-10-01 22:19:10Z WayneAllen $
32
  */
 
33
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
34
 
35
- define('POSTIE_VERSION', '1.7.14');
36
  define("POSTIE_ROOT", dirname(__FILE__));
37
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
38
 
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Signifigantly upgrades the Post by Email features of Word Press.
7
+ Version: 1.7.15
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
28
  */
29
 
30
  /*
31
+ $Id: postie.php 1258512 2015-10-02 22:02:03Z WayneAllen $
32
  */
33
+ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib_autolink.php");
34
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
35
 
36
+ define('POSTIE_VERSION', '1.7.15');
37
  define("POSTIE_ROOT", dirname(__FILE__));
38
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
39
 
readme.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.3.1
9
- Stable tag: 1.7.14
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -235,8 +235,12 @@ All script, style and body tags are stripped from html emails.
235
  Attachments are now processed in the order they were attached.
236
 
237
  == CHANGELOG ==
 
 
 
 
238
  = 1.7.14 (2015-10-01) =
239
- * Fix bug is new linkify logic
240
 
241
  = 1.7.13 (2015-10-01) =
242
  * Fix support for "Automatically convert urls to links" with html
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.3.1
9
+ Stable tag: 1.7.15
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
235
  Attachments are now processed in the order they were attached.
236
 
237
  == CHANGELOG ==
238
+ = 1.7.15 (2015-10-02) =
239
+ * Completely replace linkify logic
240
+ * Support youtu.be links
241
+
242
  = 1.7.14 (2015-10-01) =
243
+ * Fix bug in new linkify logic
244
 
245
  = 1.7.13 (2015-10-01) =
246
  * Fix support for "Automatically convert urls to links" with html