From edbc076c7365a8d807dcf5a8b4d4dc2e61d52222 Mon Sep 17 00:00:00 2001 From: Kelson Vibber Date: Sat, 22 Jul 2023 21:55:37 -0700 Subject: [PATCH] Version 0.3.3 - remove tinyurl, confirm works with WordPress 6.3 --- linkchain.txt | 5 ++++- readme.md | 10 +++++++--- unwrap-shortlinks.php | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/linkchain.txt b/linkchain.txt index 434ddf5..9800573 100644 --- a/linkchain.txt +++ b/linkchain.txt @@ -10,6 +10,9 @@ https://bit.ly/3xT4SwX https://t.co/kTzFTX65HT 1. Following the t.co link should get you to the post permalink. -2. Unwrap-shortlinks should replace the t.co link with the blog ?p=xyz link. +2. Unwrap-shortlinks used to replace the t.co link with the blog ?p=xyz link, + but since TinyURL started screening requests using CloudFlare (sometime before + July 2023, requiring a JavaScript-capable browser), we can't follow it anymore. + So now the plugin can only unwrap the t.co link as far as the tinyurl.com link. TODO: Also check URLs ending in ?p=[0-9]+, follow them once and accept the result if the URLs match up to the previous / diff --git a/readme.md b/readme.md index 7d4cfad..66f0906 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,8 @@ # Unwrap Shortlinks -Stable tag: 0.3.2 +Stable tag: 0.3.3 Tags: urls, links, classicpress -Tested up to: 6.2 +Tested up to: 6.3 Contributors: Kelson License: GPLv2 or later @@ -20,13 +20,14 @@ Automatically expands URLs at the following known link shorteners when you save * buff.ly * wp.me * tmblr.co -* tinyurl.com * goo.gl * dlvr.it * fb.me * qr.ae * aka.ms +NOTE: tinyurl.com has been removed from the list because they are blocking automated requests. (See changelog) + ## Installation Install the plugin and activate it. The next time you paste a supported short URL into a post, it will be updated when the post is saved. @@ -59,6 +60,9 @@ It should work going back to the classic editor and forward to the block editor. ## Changelog +### [0.3.3] +* tinyurl.com is screening requests using Cloudflare, and a simple curl request is no longer allowed through. Removing it from the list. + ### [0.3.2] - 2022-10-29 * Tested up through 6.1, clean up headers, no functional changes. diff --git a/unwrap-shortlinks.php b/unwrap-shortlinks.php index f542606..ba993d5 100644 --- a/unwrap-shortlinks.php +++ b/unwrap-shortlinks.php @@ -3,7 +3,7 @@ Plugin Name: Unwrap Shortlinks Plugin URI: https://codeberg.org/kvibber/unwrap-shortlinks Description: Follow shortened links (t.co, bit.ly, etc) and expand them so that your blog post will point directly to the destination. - Version: 0.3.2 + Version: 0.3.3 Requires at least: 3.0 Requires CP: 1.0 Requires PHP: 7.0 @@ -16,7 +16,7 @@ // ini_set('display_errors', '1'); ini_set('error_reporting', E_ALL); function ktv_unwrap_shortlinks($content) { - preg_match_all('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|tinyurl\.com|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms)\/[^\s"\'<>]+)\b/', $content, $matches, PREG_PATTERN_ORDER); + preg_match_all('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms)\/[^\s"\'<>]+)\b/', $content, $matches, PREG_PATTERN_ORDER); foreach ($matches[1] as $link) { $getlink = ktv_unwrap_shortlinks_replace($link, 5); if ($getlink != "") @@ -37,7 +37,7 @@ function ktv_unwrap_shortlinks_replace($url, $countdown) { if ($status == 301 || $status == 302 || $status == 307 || $status == 308) { // TODO Is it also a redirector? Do we have iterations left? // If so, try to follow that one! - if( $countdown > 0 && preg_match('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|tinyurl\.com|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms)\/[^\s"\'<>]+)\b/', $finalURL) ) { + if( $countdown > 0 && preg_match('/\b(https?:\/\/(?:t\.co|bit\.ly|j\.mp|ow\.ly|is\.gd|trib\.al|buff\.ly|tmblr\.co|wp\.me|goo\.gl|dlvr\.it|fb\.me|qr\.ae|aka\.ms)\/[^\s"\'<>]+)\b/', $finalURL) ) { return ktv_unwrap_shortlinks_replace($finalURL, $countdown - 1); } else { // Otherwise, send it back up the chain!