PressThis: add inline comments and some cleanup for the images and embeds regex.
Props stephdau. Fixes #31373. git-svn-id: https://develop.svn.wordpress.org/trunk@31739 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
6d9c5ea526
commit
2707b39c63
|
@ -382,7 +382,7 @@ class WP_Press_This {
|
||||||
} else if ( preg_match( '/\/pixel\.(mathtag|quantserve)\.com/', $src ) ) {
|
} else if ( preg_match( '/\/pixel\.(mathtag|quantserve)\.com/', $src ) ) {
|
||||||
// See mathtag.com and https://www.quantcast.com/how-we-do-it/iab-standard-measurement/how-we-collect-data/
|
// See mathtag.com and https://www.quantcast.com/how-we-do-it/iab-standard-measurement/how-we-collect-data/
|
||||||
return '';
|
return '';
|
||||||
} else if ( false !== strpos( $src, '/g.gif' ) ) {
|
} else if ( preg_match( '/\/[gb]\.gif(\?.+)?$/', $src ) ) {
|
||||||
// Classic WP stats gif
|
// Classic WP stats gif
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
@ -393,23 +393,28 @@ class WP_Press_This {
|
||||||
private function _limit_embed( $src ) {
|
private function _limit_embed( $src ) {
|
||||||
$src = $this->_limit_url( $src );
|
$src = $this->_limit_url( $src );
|
||||||
|
|
||||||
if ( preg_match( '/\/\/www\.youtube\.com\/(embed|v)\/([^\?]+)\?.+$/', $src, $src_matches ) ) {
|
if ( preg_match( '/\/\/(m|www)\.youtube\.com\/(embed|v)\/([^\?]+)\?.+$/', $src, $src_matches ) ) {
|
||||||
$src = 'https://www.youtube.com/watch?v=' . $src_matches[2];
|
// Embedded Youtube videos (www or mobile)
|
||||||
|
$src = 'https://www.youtube.com/watch?v=' . $src_matches[3];
|
||||||
} else if ( preg_match( '/\/\/player\.vimeo\.com\/video\/([\d]+)([\?\/]{1}.*)?$/', $src, $src_matches ) ) {
|
} else if ( preg_match( '/\/\/player\.vimeo\.com\/video\/([\d]+)([\?\/]{1}.*)?$/', $src, $src_matches ) ) {
|
||||||
|
// Embedded Vimeo iframe videos
|
||||||
$src = 'https://vimeo.com/' . (int) $src_matches[1];
|
$src = 'https://vimeo.com/' . (int) $src_matches[1];
|
||||||
} else if ( preg_match( '/\/\/vimeo\.com\/moogaloop\.swf\?clip_id=([\d]+)$/', $src, $src_matches ) ) {
|
} else if ( preg_match( '/\/\/vimeo\.com\/moogaloop\.swf\?clip_id=([\d]+)$/', $src, $src_matches ) ) {
|
||||||
|
// Embedded Vimeo Flash videos
|
||||||
$src = 'https://vimeo.com/' . (int) $src_matches[1];
|
$src = 'https://vimeo.com/' . (int) $src_matches[1];
|
||||||
} else if ( preg_match( '/\/\/vine\.co\/v\/([^\/]+)\/embed/', $src, $src_matches ) ) {
|
} else if ( preg_match( '/\/\/vine\.co\/v\/([^\/]+)\/embed/', $src, $src_matches ) ) {
|
||||||
|
// Embedded Vine videos
|
||||||
$src = 'https://vine.co/v/' . $src_matches[1];
|
$src = 'https://vine.co/v/' . $src_matches[1];
|
||||||
} else if ( preg_match( '/\/\/(www\.)?dailymotion\.com\/embed\/video\/([^\/\?]+)([\/\?]{1}.+)?/', $src, $src_matches ) ) {
|
} else if ( preg_match( '/\/\/(www\.)?dailymotion\.com\/embed\/video\/([^\/\?]+)([\/\?]{1}.+)?/', $src, $src_matches ) ) {
|
||||||
|
// Embedded Daily Motion videos
|
||||||
$src = 'https://www.dailymotion.com/video/' . $src_matches[2];
|
$src = 'https://www.dailymotion.com/video/' . $src_matches[2];
|
||||||
} else if ( ! preg_match( '/\/\/(m\.|www\.)?youtube\.com\/watch\?/', $src )
|
} else if ( ! preg_match( '/\/\/(m|www)\.youtube\.com\/watch\?/', $src ) // Youtube video page (www or mobile)
|
||||||
&& ! preg_match( '/\/youtu\.be\/.+$/', $src )
|
&& ! preg_match( '/\/youtu\.be\/.+$/', $src ) // Youtu.be video page
|
||||||
&& ! preg_match( '/\/\/vimeo\.com\/[\d]+$/', $src )
|
&& ! preg_match( '/\/\/vimeo\.com\/[\d]+$/', $src ) // Vimeo video page
|
||||||
&& ! preg_match( '/\/\/(www\.)?dailymotion\.com\/video\/.+$/', $src )
|
&& ! preg_match( '/\/\/(www\.)?dailymotion\.com\/video\/.+$/', $src ) // Daily Motion video page
|
||||||
&& ! preg_match( '/\/\/soundcloud\.com\/.+$/', $src )
|
&& ! preg_match( '/\/\/soundcloud\.com\/.+$/', $src ) // SoundCloud audio page
|
||||||
&& ! preg_match( '/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/', $src )
|
&& ! preg_match( '/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/', $src ) // Twitter status page
|
||||||
&& ! preg_match( '/\/\/vine\.co\/v\/[^\/]+/', $src ) ) {
|
&& ! preg_match( '/\/\/vine\.co\/v\/[^\/]+/', $src ) ) { // Vine video page
|
||||||
$src = '';
|
$src = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@
|
||||||
form.appendChild( input );
|
form.appendChild( input );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( href.match( /\/\/www\.youtube\.com\/watch/ ) ||
|
if ( href.match( /\/\/(www|m)\.youtube\.com\/watch/ ) ||
|
||||||
href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ||
|
href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ||
|
||||||
href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ||
|
href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ||
|
||||||
href.match( /\/\/soundcloud\.com\/.+$/ ) ||
|
href.match( /\/\/soundcloud\.com\/.+$/ ) ||
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",o.appendChild(d)}}var f,g,h,i,j,k,l,m,n=a.encodeURIComponent,o=b.createElement("form"),p=b.getElementsByTagName("head")[0],q=new Image,r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+n(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?m=a.getSelection()+"":b.getSelection?m=b.getSelection()+"":b.selection&&(m=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+n(b.title.substr(0,256))),m&&(d+="&s="+n(m.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);(c.match(/\/\/www\.youtube\.com\/watch/)||c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)||c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)||c.match(/\/\/soundcloud\.com\/.+$/)||c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)||c.match(/\/\/vine\.co\/v\/[^\/]+/))&&e("_embeds[]",c),h=p.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=p.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");("canonical"===A||"icon"===A||"shortlink"===A)&&e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=50);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(q.src=k[B].src,q.width>=256&&q.height>=128&&e("_images[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embeds[]",l[C].src);b.title&&e("t",b.title),m&&e("s",m),o.setAttribute("method","POST"),o.setAttribute("action",d),o.setAttribute("target",r),o.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(o),o.submit()}})(window,document,top.location.href,window.pt_url);
|
(function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",o.appendChild(d)}}var f,g,h,i,j,k,l,m,n=a.encodeURIComponent,o=b.createElement("form"),p=b.getElementsByTagName("head")[0],q=new Image,r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+n(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?m=a.getSelection()+"":b.getSelection?m=b.getSelection()+"":b.selection&&(m=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+n(b.title.substr(0,256))),m&&(d+="&s="+n(m.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);(c.match(/\/\/(www|m)\.youtube\.com\/watch/)||c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)||c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)||c.match(/\/\/soundcloud\.com\/.+$/)||c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)||c.match(/\/\/vine\.co\/v\/[^\/]+/))&&e("_embeds[]",c),h=p.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=p.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");("canonical"===A||"icon"===A||"shortlink"===A)&&e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=50);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(q.src=k[B].src,q.width>=256&&q.height>=128&&e("_images[]",q.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=50);C++)e("_embeds[]",l[C].src);b.title&&e("t",b.title),m&&e("s",m),o.setAttribute("method","POST"),o.setAttribute("action",d),o.setAttribute("target",r),o.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(o),o.submit()}})(window,document,top.location.href,window.pt_url);
|
Loading…
Reference in New Issue