Changeset 2747387
- Timestamp:
- 06/24/2022 05:21:55 AM (3 years ago)
- Location:
- unwrap-shortlinks
- Files:
-
- 2 edited
- 3 copied
-
tags/0.3.0 (copied) (copied from unwrap-shortlinks/trunk)
-
tags/0.3.0/readme.md (copied) (copied from unwrap-shortlinks/trunk/readme.md) (5 diffs)
-
tags/0.3.0/unwrap-shortlinks.php (copied) (copied from unwrap-shortlinks/trunk/unwrap-shortlinks.php) (4 diffs)
-
trunk/readme.md (modified) (5 diffs)
-
trunk/unwrap-shortlinks.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
unwrap-shortlinks/tags/0.3.0/readme.md
r2741401 r2747387 1 1 # Unwrap Shortlinks 2 2 3 Stable tag: 0. 2.43 Stable tag: 0.3.0 4 4 Tags: urls, links, classicpress 5 5 Requires at least: 3.0 … … 32 32 * fb.me 33 33 * qr.ae 34 * aka.ms 34 35 35 36 ## Installation … … 41 42 ### What if the destination redirects to another link? 42 43 43 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. 44 If the destination is another known URL shortener (ex. t.co pointing to bit.ly pointing to wp.me pointing to a blog post), it'll keep going up to 5 levels (to avoid infinite loops!) or until it gets a URL that isn't on the list. 44 45 45 46 ### How do I add a shortener to the list? … … 65 66 ## Changelog 66 67 68 ### [0.3.0] - 2022-06-23 69 * Follow link trails, add aka.ms. 70 67 71 ### [0.2.4] - 2022-06-13 68 72 * Fix bugs with plaintext URLs at the end of a block. … … 76 80 77 81 [Source on Codeberg](https://codeberg.org/kvibber/unwrap-shortlinks). 78 [Plugin page at WordPress](https://wordpress.org/plugins/unwrap-shortlinks/). 82 [Plugin page at WordPress](https://wordpress.org/plugins/unwrap-shortlinks/). 83 [Plugin page at ClassicPress](https://directory.classicpress.net/plugins/unwrap-shortlinks). 79 84 80 85 (c) 2016-2022 [Kelson Vibber](https://kvibber.com/) -
unwrap-shortlinks/tags/0.3.0/unwrap-shortlinks.php
r2741401 r2747387 4 4 Plugin URI: https://codeberg.org/kvibber/unwrap-shortlinks 5 5 Description: Follow shortened links (t.co, bit.ly, etc) and expand them so that your blog post will point directly to the destination. 6 Version: 0. 2.46 Version: 0.3.0 7 7 Author: Kelson Vibber 8 8 Author URI: https://kvibber.com … … 14 14 15 15 function ktv_unwrap_shortlinks($content) { 16 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);16 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); 17 17 foreach ($matches[1] as $link) { 18 $getlink = ktv_unwrap_shortlinks_replace($link );18 $getlink = ktv_unwrap_shortlinks_replace($link, 5); 19 19 if ($getlink != "") 20 20 $content = str_replace($link, $getlink, $content); … … 25 25 26 26 27 function ktv_unwrap_shortlinks_replace($url ) {27 function ktv_unwrap_shortlinks_replace($url, $countdown) { 28 28 // make a head request and don't follow redirection, just look at the response. 29 29 $response = wp_remote_head( $url ); //, array( 'redirection' => 0 ) ); … … 31 31 $finalURL = wp_remote_retrieve_header( $response, 'location' ); 32 32 33 // If it was a redirect, return the next URL.33 // If it was a redirect, get the next URL 34 34 if ($status == 301 || $status == 302 || $status == 307 || $status == 308) { 35 return esc_url($finalURL); 35 // TODO Is it also a redirector? Do we have iterations left? 36 // If so, try to follow that one! 37 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) ) { 38 return ktv_unwrap_shortlinks_replace($finalURL, $countdown - 1); 39 } else { 40 // Otherwise, send it back up the chain! 41 return esc_url($finalURL); 42 } 36 43 } 37 44 // We didn't get anything, or it didn't redirect, so let's return a blank. -
unwrap-shortlinks/trunk/readme.md
r2741401 r2747387 1 1 # Unwrap Shortlinks 2 2 3 Stable tag: 0. 2.43 Stable tag: 0.3.0 4 4 Tags: urls, links, classicpress 5 5 Requires at least: 3.0 … … 32 32 * fb.me 33 33 * qr.ae 34 * aka.ms 34 35 35 36 ## Installation … … 41 42 ### What if the destination redirects to another link? 42 43 43 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. 44 If the destination is another known URL shortener (ex. t.co pointing to bit.ly pointing to wp.me pointing to a blog post), it'll keep going up to 5 levels (to avoid infinite loops!) or until it gets a URL that isn't on the list. 44 45 45 46 ### How do I add a shortener to the list? … … 65 66 ## Changelog 66 67 68 ### [0.3.0] - 2022-06-23 69 * Follow link trails, add aka.ms. 70 67 71 ### [0.2.4] - 2022-06-13 68 72 * Fix bugs with plaintext URLs at the end of a block. … … 76 80 77 81 [Source on Codeberg](https://codeberg.org/kvibber/unwrap-shortlinks). 78 [Plugin page at WordPress](https://wordpress.org/plugins/unwrap-shortlinks/). 82 [Plugin page at WordPress](https://wordpress.org/plugins/unwrap-shortlinks/). 83 [Plugin page at ClassicPress](https://directory.classicpress.net/plugins/unwrap-shortlinks). 79 84 80 85 (c) 2016-2022 [Kelson Vibber](https://kvibber.com/) -
unwrap-shortlinks/trunk/unwrap-shortlinks.php
r2741401 r2747387 4 4 Plugin URI: https://codeberg.org/kvibber/unwrap-shortlinks 5 5 Description: Follow shortened links (t.co, bit.ly, etc) and expand them so that your blog post will point directly to the destination. 6 Version: 0. 2.46 Version: 0.3.0 7 7 Author: Kelson Vibber 8 8 Author URI: https://kvibber.com … … 14 14 15 15 function ktv_unwrap_shortlinks($content) { 16 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);16 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); 17 17 foreach ($matches[1] as $link) { 18 $getlink = ktv_unwrap_shortlinks_replace($link );18 $getlink = ktv_unwrap_shortlinks_replace($link, 5); 19 19 if ($getlink != "") 20 20 $content = str_replace($link, $getlink, $content); … … 25 25 26 26 27 function ktv_unwrap_shortlinks_replace($url ) {27 function ktv_unwrap_shortlinks_replace($url, $countdown) { 28 28 // make a head request and don't follow redirection, just look at the response. 29 29 $response = wp_remote_head( $url ); //, array( 'redirection' => 0 ) ); … … 31 31 $finalURL = wp_remote_retrieve_header( $response, 'location' ); 32 32 33 // If it was a redirect, return the next URL.33 // If it was a redirect, get the next URL 34 34 if ($status == 301 || $status == 302 || $status == 307 || $status == 308) { 35 return esc_url($finalURL); 35 // TODO Is it also a redirector? Do we have iterations left? 36 // If so, try to follow that one! 37 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) ) { 38 return ktv_unwrap_shortlinks_replace($finalURL, $countdown - 1); 39 } else { 40 // Otherwise, send it back up the chain! 41 return esc_url($finalURL); 42 } 36 43 } 37 44 // We didn't get anything, or it didn't redirect, so let's return a blank.
Note: See TracChangeset
for help on using the changeset viewer.