-
Notifications
You must be signed in to change notification settings - Fork 5
/
plugin.php
37 lines (31 loc) · 1.22 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/*
Plugin Name: Thumbnail URL image
Plugin URI: https://github.com/prog-it/yourls-thumbnail-url
Description: Add .i to shorturls to display Thumbnail URL image
Version: 1.1
Author: progit
Author URI: https://github.com/prog-it
*/
// EDIT THIS
// Thumbnail Image service URL with params
// Choose one. Uncomment if need
define( 'PROGIT_THUMB_URL', 'https://api.site-shot.com/?width=1024&height=768&scaled_width=800&format=jpeg&url=' );
//define( 'PROGIT_THUMB_URL', 'https://api.webthumbnail.org/?width=800&height=600&screen=1024&url=' );
// Kick in if the loader does not recognize a valid pattern
yourls_add_action( 'loader_failed', 'progit_yourls_thumbnail' );
function progit_yourls_thumbnail( $request ) {
// Get authorized charset in keywords and make a regexp pattern
$pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() );
// Shorturl is like bleh.i ?
if( preg_match( "@^([$pattern]+)\.i?/?$@", $request[0], $matches ) ) {
// this shorturl exists ?
$keyword = yourls_sanitize_keyword( $matches[1] );
if( yourls_is_shorturl( $keyword ) ) {
$url = yourls_get_keyword_longurl( $keyword );
// Show the Thubmnail long URL then!
header('Location: '.PROGIT_THUMB_URL . $url);
exit;
}
}
}