diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a6c72e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build +release-svn diff --git a/packagezip.sh b/packagezip.sh new file mode 100755 index 0000000..14ed3cd --- /dev/null +++ b/packagezip.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +ZIPNAME="unwrap-shortlinks" + +echo "Removing old build folder and zip if present" +if test -d "build/$ZIPNAME"; then + rm -rf "build/$ZIPNAME" +fi +if test -f "build/$ZIPNAME.zip"; then + rm "build/$ZIPNAME.zip" +fi + +echo "Copying files to build folder" +if [ ! -d build ]; then + mkdir build +fi + +mkdir build/$ZIPNAME +cp -p *.php *.txt *.md LICENSE "build/$ZIPNAME" +rm "build/$ZIPNAME/readme.md" + +echo "Building $ZIPNAME" +cd build && zip -r "$ZIPNAME.zip" "$ZIPNAME" + diff --git a/readme.md b/readme.md index ba6d831..bff32af 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,16 @@ # Unwrap Shortlinks -Stable tag: 0.2.2 -Tags: urls, links +Stable tag: 0.2.3 +Tags: urls, links, classicpress Requires at least: 3.0 Tested up to: 6.0 +Requires PHP: 7.0 Contributors: Kelson License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html +For ClassicPress +Requires: 1.0 +Tested: 1.4.1 Follow shortened links (t.co, bit.ly, etc) and expand them so that your blog post will point directly to the destination. @@ -36,23 +40,32 @@ Install the plugin and activate it. The next time you paste a supported short UR ### What if the destination redirects to another link? -It won't keep following the trail. Just in case there's a loop, or the destination page has been replaced with a redirection to a home page, etc. - -But if the destination is another known shortener (say you had a t.co link that redirected to a bit.ly link), the next time you save the post, it will follow that one to its destination. +At the moment it'll stop at the first one to avoid infinite redirect loops. But if the destination is another known shortener (say you had a t.co link that redirected to a bit.ly link), the next time you save the post, it will follow that one to its destination. TODO: I plan to make it follow a limited chain of known shorteners. ### How do I add a shortener to the list? It's not supported yet, but I plan on adding an options page for it. +### I'm running on a local server and this doesn't do anything! + +Most likely your system is configured to block your local webserver +from making outgoing connections. This is a sensible default for security! +Depending on your system, it may be blocked by a local or network firewall. +If you're running Fedora Workstation with SELinux (like I am), this will enable it: +``` +sudo setsebool -P httpd_can_network_connect true +``` + +Thanks to [igienger's post](https://wordpress.org/support/topic/error-curl-error-7-3/#post-12637512) on the WordPress support forums! + ### What about compatibility? It should work going back to the classic editor and forward to the block editor. It even works on [ClassicPress](https://www.classicpress.net/). - ## Changelog -### 2022-05-24 -* Confirmed compatible with WordPress 6.0 +### [0.2.3] - 2022-06-10 +* Fix bugs with tinyurl.com and URLs inside HTML links. (Plaintext URLs were working fine.) ### [0.2.2] - 2022-01-29 diff --git a/readme.txt b/readme.txt new file mode 100644 index 0000000..3b58b13 --- /dev/null +++ b/readme.txt @@ -0,0 +1,77 @@ +=== Unwrap Shortlinks === + +Stable tag: 0.2.3 +Tags: urls, links, classicpress +Requires at least: 3.0 +Tested up to: 6.0 +Requires PHP: 7.0 +Contributors: Kelson +License: GPLv2 or later +License URI: http://www.gnu.org/licenses/gpl-2.0.html +For ClassicPress +Requires: 1.0 +Tested: 1.4.1 + +Follow shortened links (t.co, bit.ly, etc) and expand them so that your blog post will point directly to the destination. + +== Description == + +Automatically expands URLs at the following known link shorteners when you save a post: +* t.co +* bit.ly +* ow.ly +* j.mp +* is.gd +* trib.al +* buff.ly +* wp.me +* tmblr.co +* tinyurl.com +* goo.gl +* dlvr.it +* fb.me +* qr.ae + +== 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. + +== Frequently Asked Questions == + += What if the destination redirects to another link? = + +At the moment it'll stop at the first one to avoid infinite redirect loops. But if the destination is another known shortener (say you had a t.co link that redirected to a bit.ly link), the next time you save the post, it will follow that one to its destination. TODO: I plan to make it follow a limited chain of known shorteners. + += How do I add a shortener to the list? = + +It's not supported yet, but I plan on adding an options page for it. + += I'm running on a local server and this doesn't do anything! = + +Most likely your system is configured to block your local webserver +from making outgoing connections. This is a sensible default for security! +Depending on your system, it may be blocked by a local or network firewall. +If you're running Fedora Workstation with SELinux (like I am), this will enable it: +``` +sudo setsebool -P httpd_can_network_connect true +``` + +Thanks to [igienger's post](https://wordpress.org/support/topic/error-curl-error-7-3/#post-12637512) on the WordPress support forums! + += What about compatibility? = + +It should work going back to the classic editor and forward to the block editor. It even works on [ClassicPress](https://www.classicpress.net/). + +== Changelog == + += [0.2.3] - 2022-06-10 = +* Fix bugs with tinyurl.com and URLs inside HTML links. (Plaintext URLs were working fine.) + += [0.2.2] - 2022-01-29 = + +* Initial release based on the code I've been running locally for years, plus changes requested by the WordPress plugin review team. + +[Source on Codeberg](https://codeberg.org/kvibber/unwrap-shortlinks). +[Plugin page at WordPress](https://wordpress.org/plugins/unwrap-shortlinks/). + +(c) 2016-2022 [Kelson Vibber](https://kvibber.com/) diff --git a/unwrap-shortlinks.php b/unwrap-shortlinks.php index 3ed5bdd..917594c 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.2.2 + Version: 0.2.3 Author: Kelson Vibber Author URI: https://kvibber.com License: GPLv2 or later @@ -13,7 +13,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)\/[^\s"\']+)/', $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|tinyurl\.com|goo\.gl|dlvr\.it|fb\.me|qr\.ae)\/[^\s"\']+)\b/', $content, $matches, PREG_PATTERN_ORDER); foreach ($matches[1] as $link) { $getlink = ktv_unwrap_shortlinks_replace($link); if ($getlink != "") @@ -31,7 +31,7 @@ function ktv_unwrap_shortlinks_replace($url) { $finalURL = wp_remote_retrieve_header( $response, 'location' ); // If it was a redirect, return the next URL. - if ($status == 301 || $status == 302 || $status == 307) { + if ($status == 301 || $status == 302 || $status == 307 || $status == 308) { return esc_url($finalURL); } // We didn't get anything, or it didn't redirect, so let's return a blank. diff --git a/update.sh b/update.sh new file mode 100644 index 0000000..ed0965c --- /dev/null +++ b/update.sh @@ -0,0 +1,69 @@ +#!/bin/bash +# https://developer.wordpress.org/plugins/wordpress-org/how-to-use-subversion/ + +VERSION=$1 +ACTION="" +MESSAGE=$2 + +echo "Updating files in trunk." +cp -p *.php *.md release-svn/trunk + + + +if [[ $VERSION == "trunk" ]]; then + if [[ "x$MESSAGE" == "x" ]]; then + echo "Message?" + read MESSAGE + fi + if [[ "x$MESSAGE" == "x" ]]; then + echo "Sorry, a message is required" + exit -1 + fi + + echo "Checking in the updated trunk" + cd release-svn/trunk + svn ci -m "$MESSAGE" + exit 0 +fi + + + +if [[ "x$VERSION" == "x" ]]; then + echo "No release version specified, stopping here." + exit 0 +fi + + + + +if [ ! -f ".git/refs/tags/v$VERSION" ]; then + echo "Error: v$VERSION not found in git tags." + exit -1 +fi + +cd release-svn + +if [ -d "tags/$VERSION" ]; then + echo "Warning: Release $VERSION already exists in local svn." + echo "(r)eplace, (u)pload as-is, or (c)ancel?" + read ACTION + if [[ $ACTION == "r" ]]; then + echo "removing old tag $VERSION" + svn rm --force "tags/$VERSION" + elif [[ ! $ACTION == "u" ]]; then + echo "Cancelling" + exit -1 + fi +fi + +if [[ $ACTION == "u" ]]; then + echo "Leaving release tag unchanged." +else + echo "Tagging release $VERSION in svn." + svn cp trunk "tags/$VERSION" +fi + +echo "Checking in updated version $VERSION" +svn ci -m "tagging version $VERSION" + +