Postie - Version 1.7.26

Version Description

(2015-12-28) = * Detect oEmbedable links and don't linkify

Download this release

Release Info

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

Code changes from version 1.7.25 to 1.7.26

Files changed (6) hide show
  1. docs/Changes.txt +3 -0
  2. docs/Postie.txt +1 -1
  3. lib_autolink.php +28 -10
  4. postie-functions.php +8 -92
  5. postie.php +3 -3
  6. readme.txt +4 -1
docs/Changes.txt CHANGED
@@ -27,6 +27,9 @@ 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.25 (2015-12-15) =
31
  * Fix settings page for new category matching flavors
32
 
27
  Attachments are now processed in the order they were attached.
28
 
29
  == CHANGELOG ==
30
+ = 1.7.26 (2015-12-28) =
31
+ * Detect oEmbedable links and don't linkify
32
+
33
  = 1.7.25 (2015-12-15) =
34
  * Fix settings page for new category matching flavors
35
 
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.4
9
- Stable tag: 1.7.25
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.4
9
+ Stable tag: 1.7.26
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
lib_autolink.php CHANGED
@@ -15,15 +15,15 @@ class PostieAutolink {
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;
@@ -125,21 +125,19 @@ class PostieAutolink {
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
  #
@@ -158,7 +156,27 @@ class PostieAutolink {
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
 
15
  #
16
  ####################################################################
17
 
18
+ function autolink($text, $oembed = null, $limit = 200, $tagfill = '', $auto_title = true) {
19
 
20
+ $text = $this->autolink_do($text, '![a-z][a-z-]+://!i', $limit, $tagfill, $auto_title, null, $oembed);
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://', $oembed);
23
  return $text;
24
  }
25
 
26
+ function autolink_do($text, $sub, $limit, $tagfill, $auto_title, $force_prefix = null, $oembed = null) {
27
 
28
  $text_l = StrToLower($text);
29
  $cursor = 0;
125
  #
126
 
127
  $link_url = $url;
128
+
129
  $display_url = $url;
130
 
131
+ if ($force_prefix) {
132
  $link_url = $force_prefix . $link_url;
133
+ }
134
 
135
  if (preg_match('!^(http|https)://!i', $display_url, $m)) {
 
136
  $display_url = substr($display_url, strlen($m[1]) + 3);
137
  }
138
 
 
139
  $display_url = $this->autolink_label($display_url, $limit);
140
 
 
141
  #
142
  # add the url
143
  #
156
  $link_url_enc = HtmlSpecialChars($link_url);
157
  $display_url_enc = HtmlSpecialChars($display_url);
158
 
159
+ DebugEcho("autolink_do: link=$link_url");
160
+
161
+ $skip = false;
162
+ if (!empty($oembed)) {
163
+ $provider = $oembed->get_provider($link_url, array('discover' => false));
164
+ if (false !== $provider) {
165
+ DebugEcho("autolink_do: provider=$provider");
166
+ $skip = true;
167
+ } else {
168
+ DebugEcho("autolink_do: no provider");
169
+ }
170
+ } else {
171
+ DebugEcho("autolink_do: no oembed");
172
+ }
173
+ if ($skip) {
174
+ DebugEcho("autolink_do: oembed source, skipping $link_url");
175
+ $buffer .= $link_url_enc;
176
+ } else {
177
+ DebugEcho("autolink_do: linkifying $link_url");
178
+ $buffer .= "<a href=\"{$link_url_enc}\"$currentTagfill>{$display_url_enc}</a>";
179
+ }
180
  } else {
181
  #echo "fail 3 at $cursor<br />\n";
182
 
postie-functions.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- $Id: postie-functions.php 1309274 2015-12-15 17:33:07Z WayneAllen $
4
  */
5
 
6
  class PostiePostModifiers {
@@ -303,11 +303,6 @@ function CreatePost($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config, $
303
  }
304
 
305
  if ($config['converturls']) {
306
- $content = filter_Videos($content, $config['shortcode']); //videos first so linkify doesn't mess with them
307
- if ($fulldebug) {
308
- DebugEcho("post video: $content");
309
- }
310
-
311
  $content = filter_Linkify($content, 'html' == $config['prefer_text_type']);
312
  if ($fulldebug) {
313
  DebugEcho("post linkify: $content");
@@ -523,101 +518,22 @@ function tag_PostType(&$subject, $postmodifiers, $config) {
523
  return $post_type;
524
  }
525
 
526
- function filter_Linkify($text, $isHtml) {
527
  DebugEcho("begin: filter_linkify");
 
 
 
528
  $al = new PostieAutolink();
529
- $text = $al->autolink($text);
 
 
530
  return $al->autolink_email($text);
531
-
532
- // if ($isHtml) {
533
- // $html = LoadDOM($text);
534
- // if (false !== $html) {
535
- // //DebugEcho("filter_linkify: " . $html->save());
536
- // foreach ($html->find('text') as $element) {
537
- // //DebugEcho("filter_linkify: " . $element->innertext);
538
- // $element->innertext = make_links($element->innertext);
539
- // }
540
- // $ret = $html->save();
541
- // }
542
- // } else {
543
- // $ret = make_links($text);
544
- // }
545
- //DebugEcho("end: filter_linkify");
546
- //return $ret;
547
  }
548
 
549
  function LoadDOM($text) {
550
  return str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
551
  }
552
 
553
- function filter_Videos($text, $shortcode = false) {
554
- return $text;
555
-
556
- $ret = ' ' . $text;
557
- if (strpos($ret, 'youtube') !== false) {
558
- // try to embed youtube videos
559
- $youtube = "#(^|[\n ]|>)[\w]+?://(www\.)?youtube\.com/watch\?v=([_a-zA-Z0-9-]+).*?([ \n]|$|<)#is";
560
- if ($shortcode) {
561
- $youtube_replace = "\\1[youtube \\3]\\4";
562
- } else {
563
- $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";
564
- }
565
- $ret = preg_replace($youtube, $youtube_replace, $ret);
566
- DebugEcho("youtube: $ret");
567
- }
568
-
569
- if (strpos($ret, 'youtu.be') !== false) {
570
- // try to embed youtube videos
571
- $youtube = "#(^|[\n ]|>)[\w]+?://(www\.)?youtu\.be/([_a-zA-Z0-9-]+).*?([ \n]|$|<)#is";
572
- if ($shortcode) {
573
- $youtube_replace = "\\1[youtube \\3]\\4";
574
- } else {
575
- $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";
576
- }
577
- $ret = preg_replace($youtube, $youtube_replace, $ret);
578
- DebugEcho("youtube: $ret");
579
- }
580
-
581
- if (strpos($ret, 'vimeo') !== false) {
582
- // try to embed vimeo videos
583
- # : http://vimeo.com/6348141
584
- $vimeo = "#(^|[\n ]|>)[\w]+?://(www\.)?vimeo\.com/([_a-zA-Z0-9-]+).*?([ \n]|$|<)#is";
585
- if ($shortcode) {
586
- $vimeo_replace = "\\1[vimeo \\3]\\4";
587
- } else {
588
- $vimeo_replace = "\\1<object width='400' height='300'><param name='allowfullscreen' value='true' /><param name='allowscriptaccess' value='always' /><param name='movie' value='http://vimeo.com/moogaloop.swf?clip_id=\\3&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' /><embed src='http://vimeo.com/moogaloop.swf?clip_id=\\3&server=vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1' type='application/x-shockwave-flash' allowfullscreen='true' allowscriptaccess='always' width='400' height='300'></embed></object>\\4";
589
- }
590
- $ret = preg_replace($vimeo, $vimeo_replace, $ret);
591
- DebugEcho("vimeo: $ret");
592
- }
593
-
594
- // Remove our padding..
595
- $ret = substr($ret, 1);
596
- return $ret;
597
- }
598
-
599
- function make_links($text) {
600
- return preg_replace(
601
- array(
602
- '/(?(?=<a[^>]*>.+<\/a>)
603
- (?:<a[^>]*>.+<\/a>)
604
- |
605
- ([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+)
606
- )/iex',
607
- '/<a([^>]*)target="?[^"\']+"?/i',
608
- '/<a([^>]+)>/i',
609
- '/(^|\s)(www.[^<> \n\r]+)/iex',
610
- '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
611
- (\\.[A-Za-z0-9-]+)*)/iex'
612
- ), array(
613
- "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))",
614
- '<a\\1',
615
- '<a\\1 >',
616
- "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))",
617
- "stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
618
- ), $text);
619
- }
620
-
621
  /* we check whether or not the email is a forwards or a redirect. If it is
622
  * a fwd, then we glean the author details from the body of the post.
623
  * Otherwise we get them from the headers
1
  <?php
2
  /*
3
+ $Id: postie-functions.php 1317583 2015-12-28 22:03:06Z WayneAllen $
4
  */
5
 
6
  class PostiePostModifiers {
303
  }
304
 
305
  if ($config['converturls']) {
 
 
 
 
 
306
  $content = filter_Linkify($content, 'html' == $config['prefer_text_type']);
307
  if ($fulldebug) {
308
  DebugEcho("post linkify: $content");
518
  return $post_type;
519
  }
520
 
521
+ function filter_Linkify($text) {
522
  DebugEcho("begin: filter_linkify");
523
+ require_once( ABSPATH . WPINC . '/class-oembed.php' );
524
+ $oe = _wp_oembed_get_object();
525
+
526
  $al = new PostieAutolink();
527
+ DebugEcho("begin: filter_linkify (html)");
528
+ $text = $al->autolink($text, $oe);
529
+ DebugEcho("begin: filter_linkify (email)");
530
  return $al->autolink_email($text);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  }
532
 
533
  function LoadDOM($text) {
534
  return str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
535
  }
536
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
537
  /* we check whether or not the email is a forwards or a redirect. If it is
538
  * a fwd, then we glean the author details from the body of the post.
539
  * Otherwise we get them from the headers
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.25
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
@@ -28,12 +28,12 @@
28
  */
29
 
30
  /*
31
- $Id: postie.php 1309308 2015-12-15 18:34:13Z 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.25');
37
  define("POSTIE_ROOT", dirname(__FILE__));
38
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
39
 
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.26
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
28
  */
29
 
30
  /*
31
+ $Id: postie.php 1317583 2015-12-28 22:03:06Z 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.26');
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.4
9
- Stable tag: 1.7.25
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -235,6 +235,9 @@ 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.25 (2015-12-15) =
239
  * Fix settings page for new category matching flavors
240
 
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.4
9
+ Stable tag: 1.7.26
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.26 (2015-12-28) =
239
+ * Detect oEmbedable links and don't linkify
240
+
241
  = 1.7.25 (2015-12-15) =
242
  * Fix settings page for new category matching flavors
243