Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Press-to-Save Bookmarklet is broken in several ways. #130

Closed
benlk opened this issue Jan 24, 2018 · 7 comments
Closed

The Press-to-Save Bookmarklet is broken in several ways. #130

benlk opened this issue Jan 24, 2018 · 7 comments

Comments

@benlk
Copy link
Collaborator

benlk commented Jan 24, 2018

I simply wanted to let you know that the bookmarklet for the Link Roundups plugin is broken. It will not let me add the bookmarklet to any browser, there is no text to copy to manually add the bookmarklet, and the mobile link also does not work.

@benlk
Copy link
Collaborator Author

benlk commented May 24, 2018

  • provide text to manually copy for bookmarklet
  • make sure that browsers support bookmarklets?
  • examine the mobile link

@benlk benlk modified the milestones: 0.4.2, v0.5 Mar 5, 2019
@benlk benlk changed the title Is the bookmarklet broken? The Bookmarklet is broken in several ways. Mar 5, 2019
@benlk
Copy link
Collaborator Author

benlk commented Mar 5, 2019

WordPress 4.9 removed the "Press this!" bookmarklet functionality, and all associated code, including the key function get_shortcut_link() which is used by this plugin.

The code formerly output by that link is as follows:

javascript:(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",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+o(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?h=a.getSelection()+"":b.getSelection?h=b.getSelection()+"":b.selection&&(h=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+o(b.title.substr(0,256))),h&&(d+="&s="+o(h.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=f<800||f>5e3?600:.7*f,g=g<800||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);i=q.getElementsByTagName("meta")||[];for(var t=0;t<i.length&&!(t>200);t++){var u=i[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");x&&(v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x))}j=q.getElementsByTagName("link")||[];for(var y=0;y<j.length&&!(y>=50);y++){var z=j[y],A=z.getAttribute("rel");"canonical"!==A&&"icon"!==A&&"shortlink"!==A||e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(k=b.body.getElementsByClassName("hfeed")[0]),k=b.getElementById("content")||k||b.body,l=k.getElementsByTagName("img")||[];for(var B=0;B<l.length&&!(B>=100);B++)n=l[B],n.src.indexOf("avatar")>-1||n.className.indexOf("avatar")>-1||n.width&&n.width<256||n.height&&n.height<128||e("_images[]",n.src);m=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<m.length&&!(C>=50);C++)e("_embeds[]",m[C].src);b.title&&e("t",b.title),h&&e("s",h),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",r),p.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,"https:\/\/largo.test\/wp-admin\/press-this.php?v=8");

@benlk benlk changed the title The Bookmarklet is broken in several ways. The Press-to-Save Bookmarklet is broken in several ways. Apr 29, 2019
@benlk
Copy link
Collaborator Author

benlk commented May 7, 2019

Do we want to just remove the press-to-save functionality here?

@benlk
Copy link
Collaborator Author

benlk commented May 11, 2019

Looks like this functionality was spun out into an "Official plugin" in 4.9: https://make.wordpress.org/core/2017/11/02/press-this-in-4-9/

The resulting plugin is https://wordpress.org/plugins/press-this/#description

It has not received any commits in GitHub since 2017: https://github.com/WordPress/press-this/commits/master

Or in Trac since 18 months ago: https://plugins.trac.wordpress.org/log/press-this/

So I'm pretty sure that the plugin is dead.

@benlk
Copy link
Collaborator Author

benlk commented May 13, 2019

Morning notes:

  • take 30m to test this plugin in combination with the press-this plugin

@benlk
Copy link
Collaborator Author

benlk commented May 13, 2019

This is what the "Add Browser Bookmark" page looks like under WordPress 4.9:

Screen Shot 2019-05-13 at 16 26 35

Full Press This link code
javascript:(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",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+o(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?h=a.getSelection()+"":b.getSelection?h=b.getSelection()+"":b.selection&&(h=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+o(b.title.substr(0,256))),h&&(d+="&s="+o(h.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=f<800||f>5e3?600:.7*f,g=g<800||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);i=q.getElementsByTagName("meta")||[];for(var t=0;t<i.length&&!(t>200);t++){var u=i[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");x&&(v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x))}j=q.getElementsByTagName("link")||[];for(var y=0;y<j.length&&!(y>=50);y++){var z=j[y],A=z.getAttribute("rel");"canonical"!==A&&"icon"!==A&&"shortlink"!==A||e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(k=b.body.getElementsByClassName("hfeed")[0]),k=b.getElementById("content")||k||b.body,l=k.getElementsByTagName("img")||[];for(var B=0;B<l.length&&!(B>=100);B++)n=l[B],n.src.indexOf("avatar")>-1||n.className.indexOf("avatar")>-1||n.width&&n.width<256||n.height&&n.height<128||e("_images[]",n.src);m=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<m.length&&!(C>=50);C++)e("_embeds[]",m[C].src);b.title&&e("t",b.title),h&&e("s",h),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",r),p.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,"https:\/\/largo.test\/wp-admin\/post-new.php?post_type=rounduplink&v=8");

Clicking it results in URLs like https://largo.test/wp-admin/press-this.php?v=8&u=https%3A%2F%2Fduckduckgo.com%2F%3Fq%3Dwordpress%2Bget%2Bedit%2Bpost%2Blink%26ia%3Dweb&buster=1557780004954

However, in the Saved Links bookmarklet, the bookmarklet and resultant URL are different:

Full Saved Links bookmarklet code
javascript:(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",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r="_press_this_app",s=!0;if(d){if(!c.match(/^https?:/))return void(top.location.href=d);if(d+="&u="+o(c),c.match(/^https:/)&&d.match(/^http:/)&&(s=!1),a.getSelection?h=a.getSelection()+"":b.getSelection?h=b.getSelection()+"":b.selection&&(h=b.selection.createRange().text||""),d+="&buster="+(new Date).getTime(),s||(b.title&&(d+="&t="+o(b.title.substr(0,256))),h&&(d+="&s="+o(h.substr(0,512)))),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=f<800||f>5e3?600:.7*f,g=g<800||g>3e3?700:.9*g,!s)return void a.open(d,r,"location,resizable,scrollbars,width="+f+",height="+g);i=q.getElementsByTagName("meta")||[];for(var t=0;t<i.length&&!(t>200);t++){var u=i[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");x&&(v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x))}j=q.getElementsByTagName("link")||[];for(var y=0;y<j.length&&!(y>=50);y++){var z=j[y],A=z.getAttribute("rel");"canonical"!==A&&"icon"!==A&&"shortlink"!==A||e("_links["+A+"]",z.getAttribute("href"))}b.body.getElementsByClassName&&(k=b.body.getElementsByClassName("hfeed")[0]),k=b.getElementById("content")||k||b.body,l=k.getElementsByTagName("img")||[];for(var B=0;B<l.length&&!(B>=100);B++)n=l[B],n.src.indexOf("avatar")>-1||n.className.indexOf("avatar")>-1||n.width&&n.width<256||n.height&&n.height<128||e("_images[]",n.src);m=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<m.length&&!(C>=50);C++)e("_embeds[]",m[C].src);b.title&&e("t",b.title),h&&e("s",h),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",r),p.setAttribute("style","display: none;"),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,"https:\/\/largo.test\/wp-admin\/press-this.php?v=8");

The difference between the two bookmarklets is as follows:

22c22
< "),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,"https:\/\/largo.test\/wp-admin\/press-this.php?v=8");
---
> "),a.open("about:blank",r,"location,resizable,scrollbars,width="+f+",height="+g),b.body.appendChild(p),p.submit()}})(window,document,top.location.href,"https:\/\/largo.test\/wp-admin\/post-new.php?post_type=rounduplink&v=8");

https://largo.test/wp-admin/post-new.php?post_type=rounduplink&v=8&u=https%3A%2F%2Fwww.nytimes.com%2F&buster=1557780289900

This URL does not depend on any of the Core or Plugin "Press This!" support, save for how the URL is derived from the Press This URL in

$shortcut_link = htmlspecialchars( get_shortcut_link() );

What does get_shortcut_link() provide in that bookmarklet?

  • passing a number of URL parameters from the clicked post
  • the post edit page
  • the popup

@benlk
Copy link
Collaborator Author

benlk commented May 13, 2019

I think we can make this work again with the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant