Skip to content

Commit

Permalink
Version 0.3.3 - remove tinyurl, confirm works with WordPress 6.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kvibber committed Jul 23, 2023
1 parent 3d9c0ac commit edbc076
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion linkchain.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 /
10 changes: 7 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
6 changes: 3 additions & 3 deletions unwrap-shortlinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 != "")
Expand All @@ -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!
Expand Down

0 comments on commit edbc076

Please sign in to comment.