-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.php
More file actions
37 lines (31 loc) · 953 Bytes
/
plugin.php
File metadata and controls
37 lines (31 loc) · 953 Bytes
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: Suffix Append
Plugin URI: http://shengye.wang
Description: Append short URL suffix to long URL
Version: 1.0
Author: Shengye Wang
Author URI: http://shengye.wang
*/
// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();
yourls_add_filter( 'get_request', 'shengye_org_extract_and_save_suffix' );
function shengye_org_extract_and_save_suffix( $request ) {
$result = $request;
$to_append = '';
$pos = strpos($request, '/');
if ($pos !== false) {
$result = substr($request, 0, $pos);
$to_append = substr($request, $pos);
}
$GLOBALS['YOURLS_PLUGIN_SUFFIX_APPEND'] = $to_append;
return $result;
}
yourls_add_filter( 'get_keyword_info', 'shengye_org_append_suffix' );
function shengye_org_append_suffix( $return, $keyword, $field, $notfound ) {
if ($field != 'url' || $return === $notfound) {
return $return;
} else {
return rtrim($return, '/') . $GLOBALS['YOURLS_PLUGIN_SUFFIX_APPEND'];
}
}