@@ -60,10 +60,10 @@ discard block |
||
60 | 60 | ** YOURLS will auto encrypt plain text passwords in this file |
61 | 61 | ** Read http://yourls.org/userpassword for more information */ |
62 | 62 | $yourls_user_passwords = array( |
63 | - 'username' => 'password', |
|
64 | - // 'username2' => 'password2', |
|
65 | - // You can have one or more 'login'=>'password' lines |
|
66 | - ); |
|
63 | + 'username' => 'password', |
|
64 | + // 'username2' => 'password2', |
|
65 | + // You can have one or more 'login'=>'password' lines |
|
66 | + ); |
|
67 | 67 | |
68 | 68 | /** URL shortening method: 36 or 62 |
69 | 69 | ** 36: generates all lowercase keywords (ie: 13jkm) |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * Define here negative, unwanted or potentially misleading keywords. |
80 | 80 | */ |
81 | 81 | $yourls_reserved_URL = array( |
82 | - 'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', |
|
82 | + 'porn', 'faggot', 'sex', 'nigger', 'fuck', 'cunt', 'dick', |
|
83 | 83 | ); |
84 | 84 | |
85 | 85 | /* |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | */ |
12 | 12 | |
13 | 13 | /** MySQL database username */ |
14 | -define( 'YOURLS_DB_USER', 'your db user name' ); |
|
14 | +define('YOURLS_DB_USER', 'your db user name'); |
|
15 | 15 | |
16 | 16 | /** MySQL database password */ |
17 | -define( 'YOURLS_DB_PASS', 'your db password' ); |
|
17 | +define('YOURLS_DB_PASS', 'your db password'); |
|
18 | 18 | |
19 | 19 | /** The name of the database for YOURLS |
20 | 20 | ** Use lower case letters [a-z], digits [0-9] and underscores [_] only */ |
21 | -define( 'YOURLS_DB_NAME', 'yourls' ); |
|
21 | +define('YOURLS_DB_NAME', 'yourls'); |
|
22 | 22 | |
23 | 23 | /** MySQL hostname. |
24 | 24 | ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */ |
25 | -define( 'YOURLS_DB_HOST', 'localhost' ); |
|
25 | +define('YOURLS_DB_HOST', 'localhost'); |
|
26 | 26 | |
27 | 27 | /** MySQL tables prefix |
28 | 28 | ** YOURLS will create tables using this prefix (eg `yourls_url`, `yourls_options`, ...) |
29 | 29 | ** Use lower case letters [a-z], digits [0-9] and underscores [_] only */ |
30 | -define( 'YOURLS_DB_PREFIX', 'yourls_' ); |
|
30 | +define('YOURLS_DB_PREFIX', 'yourls_'); |
|
31 | 31 | |
32 | 32 | /* |
33 | 33 | ** Site options |
@@ -37,27 +37,27 @@ discard block |
||
37 | 37 | ** All lowercase, no trailing slash at the end. |
38 | 38 | ** If you define it to "http://sho.rt", don't use "http://www.sho.rt" in your browser (and vice-versa) |
39 | 39 | ** To use an IDN domain (eg http://héhé.com), write its ascii form here (eg http://xn--hh-bjab.com) */ |
40 | -define( 'YOURLS_SITE', 'http://your-own-domain-here.com' ); |
|
40 | +define('YOURLS_SITE', 'http://your-own-domain-here.com'); |
|
41 | 41 | |
42 | 42 | /** YOURLS language |
43 | 43 | ** Change this setting to use a translation file for your language, instead of the default English. |
44 | 44 | ** That translation file (a .mo file) must be installed in the user/language directory. |
45 | 45 | ** See http://yourls.org/translations for more information */ |
46 | -define( 'YOURLS_LANG', '' ); |
|
46 | +define('YOURLS_LANG', ''); |
|
47 | 47 | |
48 | 48 | /** Allow multiple short URLs for a same long URL |
49 | 49 | ** Set to true to have only one pair of shortURL/longURL (default YOURLS behavior) |
50 | 50 | ** Set to false to allow multiple short URLs pointing to the same long URL (bit.ly behavior) */ |
51 | -define( 'YOURLS_UNIQUE_URLS', true ); |
|
51 | +define('YOURLS_UNIQUE_URLS', true); |
|
52 | 52 | |
53 | 53 | /** Private means the Admin area will be protected with login/pass as defined below. |
54 | 54 | ** Set to false for public usage (eg on a restricted intranet or for test setups) |
55 | 55 | ** Read http://yourls.org/privatepublic for more details if you're unsure */ |
56 | -define( 'YOURLS_PRIVATE', true ); |
|
56 | +define('YOURLS_PRIVATE', true); |
|
57 | 57 | |
58 | 58 | /** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated |
59 | 59 | ** Hint: copy from http://yourls.org/cookie */ |
60 | -define( 'YOURLS_COOKIEKEY', 'modify this text with something random' ); |
|
60 | +define('YOURLS_COOKIEKEY', 'modify this text with something random'); |
|
61 | 61 | |
62 | 62 | /** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes |
63 | 63 | ** YOURLS will auto encrypt plain text passwords in this file |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | /** URL shortening method: 36 or 62 |
72 | 72 | ** 36: generates all lowercase keywords (ie: 13jkm) |
73 | 73 | ** 62: generates mixed case keywords (ie: 13jKm or 13JKm) */ |
74 | -define( 'YOURLS_URL_CONVERT', 36 ); |
|
74 | +define('YOURLS_URL_CONVERT', 36); |
|
75 | 75 | |
76 | 76 | /** Debug mode to output some internal information |
77 | 77 | ** Default is false for live site. Enable when coding or before submitting a new issue */ |
78 | -define( 'YOURLS_DEBUG', false ); |
|
78 | +define('YOURLS_DEBUG', false); |
|
79 | 79 | |
80 | 80 | /** |
81 | 81 | * Reserved keywords (so that generated URLs won't match them) |
@@ -1,17 +1,17 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // Handle inexistent root favicon requests and exit |
3 | 3 | if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) { |
4 | - header( 'Content-Type: image/gif' ); |
|
5 | - echo base64_decode( "R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==" ); |
|
6 | - exit; |
|
4 | + header( 'Content-Type: image/gif' ); |
|
5 | + echo base64_decode( "R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==" ); |
|
6 | + exit; |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | // Handle inexistent root robots.txt requests and exit |
10 | 10 | if ( '/robots.txt' == $_SERVER['REQUEST_URI'] ) { |
11 | - header( 'Content-Type: text/plain; charset=utf-8' ); |
|
12 | - echo "User-agent: *\n"; |
|
13 | - echo "Disallow:\n"; |
|
14 | - exit; |
|
11 | + header( 'Content-Type: text/plain; charset=utf-8' ); |
|
12 | + echo "User-agent: *\n"; |
|
13 | + echo "Disallow:\n"; |
|
14 | + exit; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // Load YOURLS |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | |
33 | 33 | // if request has a scheme (eg scheme://uri) : "Prefix-n-Shorten" sends to bookmarklet (doesn't work on Windows) |
34 | 34 | if ( yourls_get_protocol($keyword) ) { |
35 | - $url = yourls_sanitize_url_safe($keyword); |
|
36 | - $parse = yourls_get_protocol_slashes_and_rest( $url, [ 'up', 'us', 'ur' ] ); |
|
35 | + $url = yourls_sanitize_url_safe($keyword); |
|
36 | + $parse = yourls_get_protocol_slashes_and_rest( $url, [ 'up', 'us', 'ur' ] ); |
|
37 | 37 | yourls_do_action( 'load_template_redirect_admin', $url ); |
38 | 38 | yourls_do_action( 'pre_redirect_bookmarklet', $url ); |
39 | 39 |
@@ -1,69 +1,69 @@ |
||
1 | 1 | <?php |
2 | 2 | // Handle inexistent root favicon requests and exit |
3 | -if ( '/favicon.ico' == $_SERVER['REQUEST_URI'] ) { |
|
4 | - header( 'Content-Type: image/gif' ); |
|
5 | - echo base64_decode( "R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw==" ); |
|
3 | +if ('/favicon.ico' == $_SERVER['REQUEST_URI']) { |
|
4 | + header('Content-Type: image/gif'); |
|
5 | + echo base64_decode("R0lGODlhEAAQAJECAAAAzFZWzP///wAAACH5BAEAAAIALAAAAAAQABAAAAIplI+py+0PUQAgSGoNQFt0LWTVOE6GuX1H6onTVHaW2tEHnJ1YxPc+UwAAOw=="); |
|
6 | 6 | exit; |
7 | 7 | } |
8 | 8 | |
9 | 9 | // Handle inexistent root robots.txt requests and exit |
10 | -if ( '/robots.txt' == $_SERVER['REQUEST_URI'] ) { |
|
11 | - header( 'Content-Type: text/plain; charset=utf-8' ); |
|
10 | +if ('/robots.txt' == $_SERVER['REQUEST_URI']) { |
|
11 | + header('Content-Type: text/plain; charset=utf-8'); |
|
12 | 12 | echo "User-agent: *\n"; |
13 | 13 | echo "Disallow:\n"; |
14 | 14 | exit; |
15 | 15 | } |
16 | 16 | |
17 | 17 | // Load YOURLS |
18 | -require_once __DIR__ . '/includes/load-yourls.php'; |
|
18 | +require_once __DIR__.'/includes/load-yourls.php'; |
|
19 | 19 | |
20 | 20 | // Get request in YOURLS base (eg in 'http://sho.rt/yourls/abcd' get 'abdc') |
21 | 21 | // At this point, $request is NOT sanitized. |
22 | 22 | $request = yourls_get_request(); |
23 | 23 | |
24 | 24 | // Now load required template and exit |
25 | -yourls_do_action( 'pre_load_template', $request ); |
|
25 | +yourls_do_action('pre_load_template', $request); |
|
26 | 26 | |
27 | 27 | // Let's look at the request : what we want to catch here is "anything", or "anything+" / "anything+all" (stat page) |
28 | -preg_match( "@^(.+?)(\+(all)?)?/?$@", $request, $matches ); |
|
28 | +preg_match("@^(.+?)(\+(all)?)?/?$@", $request, $matches); |
|
29 | 29 | $keyword = isset($matches[1]) ? $matches[1] : null; // 'anything' whatever the request is (keyword, bookmarklet URL...) |
30 | 30 | $stats = isset($matches[2]) ? $matches[2] : null; // null, or '+' if request is 'anything+', '+all' if request is 'anything+all' |
31 | 31 | $stats_all = isset($matches[3]) ? $matches[3] : null; // null, or 'all' if request is 'anything+all' |
32 | 32 | |
33 | 33 | // if request has a scheme (eg scheme://uri) : "Prefix-n-Shorten" sends to bookmarklet (doesn't work on Windows) |
34 | -if ( yourls_get_protocol($keyword) ) { |
|
34 | +if (yourls_get_protocol($keyword)) { |
|
35 | 35 | $url = yourls_sanitize_url_safe($keyword); |
36 | - $parse = yourls_get_protocol_slashes_and_rest( $url, [ 'up', 'us', 'ur' ] ); |
|
37 | - yourls_do_action( 'load_template_redirect_admin', $url ); |
|
38 | - yourls_do_action( 'pre_redirect_bookmarklet', $url ); |
|
36 | + $parse = yourls_get_protocol_slashes_and_rest($url, ['up', 'us', 'ur']); |
|
37 | + yourls_do_action('load_template_redirect_admin', $url); |
|
38 | + yourls_do_action('pre_redirect_bookmarklet', $url); |
|
39 | 39 | |
40 | 40 | // Redirect to /admin/index.php?up=<url protocol>&us=<url slashes>&ur=<url rest> |
41 | - yourls_redirect( yourls_add_query_arg( $parse , yourls_admin_url( 'index.php' ) ), 302 ); |
|
41 | + yourls_redirect(yourls_add_query_arg($parse, yourls_admin_url('index.php')), 302); |
|
42 | 42 | exit; |
43 | 43 | } |
44 | 44 | |
45 | 45 | // if request is an existing short URL keyword ('abc') or stat page ('abc+') or an existing page : |
46 | -if ( yourls_keyword_is_taken($keyword) or yourls_is_page($keyword) ) { |
|
46 | +if (yourls_keyword_is_taken($keyword) or yourls_is_page($keyword)) { |
|
47 | 47 | |
48 | 48 | // we have a short URL or a page |
49 | - if( $keyword && !$stats ) { |
|
50 | - yourls_do_action( 'load_template_go', $keyword ); |
|
51 | - require_once( YOURLS_ABSPATH.'/yourls-go.php' ); |
|
49 | + if ($keyword && !$stats) { |
|
50 | + yourls_do_action('load_template_go', $keyword); |
|
51 | + require_once(YOURLS_ABSPATH.'/yourls-go.php'); |
|
52 | 52 | exit; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // we have a stat page |
56 | - if( $keyword && $stats ) { |
|
56 | + if ($keyword && $stats) { |
|
57 | 57 | $aggregate = $stats_all && yourls_allow_duplicate_longurls(); |
58 | - yourls_do_action( 'load_template_infos', $keyword ); |
|
59 | - require_once( YOURLS_ABSPATH.'/yourls-infos.php' ); |
|
58 | + yourls_do_action('load_template_infos', $keyword); |
|
59 | + require_once(YOURLS_ABSPATH.'/yourls-infos.php'); |
|
60 | 60 | exit; |
61 | 61 | } |
62 | 62 | |
63 | 63 | } |
64 | 64 | |
65 | 65 | // Past this point this is a request the loader could not understand : not a valid shorturl, not a bookmarklet |
66 | -yourls_do_action( 'redirect_keyword_not_found', $keyword ); |
|
67 | -yourls_do_action( 'loader_failed', $request ); |
|
68 | -yourls_redirect( YOURLS_SITE, 302 ); |
|
66 | +yourls_do_action('redirect_keyword_not_found', $keyword); |
|
67 | +yourls_do_action('loader_failed', $request); |
|
68 | +yourls_redirect(YOURLS_SITE, 302); |
|
69 | 69 | exit; |
@@ -9,18 +9,18 @@ discard block |
||
9 | 9 | * |
10 | 10 | */ |
11 | 11 | function yourls_int2string( $num, $chars = null ) { |
12 | - if( $chars == null ) |
|
13 | - $chars = yourls_get_shorturl_charset(); |
|
14 | - $string = ''; |
|
15 | - $len = strlen( $chars ); |
|
16 | - while( $num >= $len ) { |
|
17 | - $mod = bcmod( $num, $len ); |
|
18 | - $num = bcdiv( $num, $len ); |
|
19 | - $string = $chars[ $mod ] . $string; |
|
20 | - } |
|
21 | - $string = $chars[ intval( $num ) ] . $string; |
|
12 | + if( $chars == null ) |
|
13 | + $chars = yourls_get_shorturl_charset(); |
|
14 | + $string = ''; |
|
15 | + $len = strlen( $chars ); |
|
16 | + while( $num >= $len ) { |
|
17 | + $mod = bcmod( $num, $len ); |
|
18 | + $num = bcdiv( $num, $len ); |
|
19 | + $string = $chars[ $mod ] . $string; |
|
20 | + } |
|
21 | + $string = $chars[ intval( $num ) ] . $string; |
|
22 | 22 | |
23 | - return yourls_apply_filter( 'int2string', $string, $num, $chars ); |
|
23 | + return yourls_apply_filter( 'int2string', $string, $num, $chars ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -28,18 +28,18 @@ discard block |
||
28 | 28 | * |
29 | 29 | */ |
30 | 30 | function yourls_string2int( $string, $chars = null ) { |
31 | - if( $chars == null ) |
|
32 | - $chars = yourls_get_shorturl_charset(); |
|
33 | - $integer = 0; |
|
34 | - $string = strrev( $string ); |
|
35 | - $baselen = strlen( $chars ); |
|
36 | - $inputlen = strlen( $string ); |
|
37 | - for ($i = 0; $i < $inputlen; $i++) { |
|
38 | - $index = strpos( $chars, $string[$i] ); |
|
39 | - $integer = bcadd( $integer, bcmul( $index, bcpow( $baselen, $i ) ) ); |
|
40 | - } |
|
31 | + if( $chars == null ) |
|
32 | + $chars = yourls_get_shorturl_charset(); |
|
33 | + $integer = 0; |
|
34 | + $string = strrev( $string ); |
|
35 | + $baselen = strlen( $chars ); |
|
36 | + $inputlen = strlen( $string ); |
|
37 | + for ($i = 0; $i < $inputlen; $i++) { |
|
38 | + $index = strpos( $chars, $string[$i] ); |
|
39 | + $integer = bcadd( $integer, bcmul( $index, bcpow( $baselen, $i ) ) ); |
|
40 | + } |
|
41 | 41 | |
42 | - return yourls_apply_filter( 'string2int', $integer, $string, $chars ); |
|
42 | + return yourls_apply_filter( 'string2int', $integer, $string, $chars ); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | */ |
49 | 49 | function yourls_string2htmlid( $string ) { |
50 | - return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) ); |
|
50 | + return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $valid = yourls_sanitize_url( $keyword ); |
73 | 73 | } |
74 | 74 | |
75 | - return yourls_apply_filter( 'sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset ); |
|
75 | + return yourls_apply_filter( 'sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | * @return string Safe title |
86 | 86 | */ |
87 | 87 | function yourls_sanitize_title( $unsafe_title, $fallback = '' ) { |
88 | - $title = $unsafe_title; |
|
89 | - $title = strip_tags( $title ); |
|
90 | - $title = preg_replace( "/\s+/", ' ', trim( $title ) ); |
|
88 | + $title = $unsafe_title; |
|
89 | + $title = strip_tags( $title ); |
|
90 | + $title = preg_replace( "/\s+/", ' ', trim( $title ) ); |
|
91 | 91 | |
92 | 92 | if ( '' === $title || false === $title ) { |
93 | 93 | $title = $fallback; |
94 | 94 | } |
95 | 95 | |
96 | - return yourls_apply_filter( 'sanitize_title', $title, $unsafe_title, $fallback ); |
|
96 | + return yourls_apply_filter( 'sanitize_title', $title, $unsafe_title, $fallback ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @return string Safe URL |
107 | 107 | */ |
108 | 108 | function yourls_sanitize_url( $unsafe_url, $protocols = array() ) { |
109 | - $url = yourls_esc_url( $unsafe_url, 'redirection', $protocols ); |
|
110 | - return yourls_apply_filter( 'sanitize_url', $url, $unsafe_url ); |
|
109 | + $url = yourls_esc_url( $unsafe_url, 'redirection', $protocols ); |
|
110 | + return yourls_apply_filter( 'sanitize_url', $url, $unsafe_url ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @return string Safe URL |
126 | 126 | */ |
127 | 127 | function yourls_sanitize_url_safe( $unsafe_url, $protocols = array() ) { |
128 | - $url = yourls_esc_url( $unsafe_url, 'safe', $protocols ); |
|
129 | - return yourls_apply_filter( 'sanitize_url_safe', $url, $unsafe_url ); |
|
128 | + $url = yourls_esc_url( $unsafe_url, 'safe', $protocols ); |
|
129 | + return yourls_apply_filter( 'sanitize_url_safe', $url, $unsafe_url ); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -136,18 +136,18 @@ discard block |
||
136 | 136 | * |
137 | 137 | */ |
138 | 138 | function yourls_deep_replace( $search, $subject ){ |
139 | - $found = true; |
|
140 | - while($found) { |
|
141 | - $found = false; |
|
142 | - foreach( (array) $search as $val ) { |
|
143 | - while( strpos( $subject, $val ) !== false ) { |
|
144 | - $found = true; |
|
145 | - $subject = str_replace( $val, '', $subject ); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
139 | + $found = true; |
|
140 | + while($found) { |
|
141 | + $found = false; |
|
142 | + foreach( (array) $search as $val ) { |
|
143 | + while( strpos( $subject, $val ) !== false ) { |
|
144 | + $found = true; |
|
145 | + $subject = str_replace( $val, '', $subject ); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | 149 | |
150 | - return $subject; |
|
150 | + return $subject; |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * |
156 | 156 | */ |
157 | 157 | function yourls_sanitize_int( $int ) { |
158 | - return ( substr( preg_replace( '/[^0-9]/', '', strval( $int ) ), 0, 20 ) ); |
|
158 | + return ( substr( preg_replace( '/[^0-9]/', '', strval( $int ) ), 0, 20 ) ); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | * |
164 | 164 | */ |
165 | 165 | function yourls_sanitize_ip( $ip ) { |
166 | - return preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); |
|
166 | + return preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | * |
172 | 172 | */ |
173 | 173 | function yourls_sanitize_date( $date ) { |
174 | - if( !preg_match( '!^\d{1,2}/\d{1,2}/\d{4}$!' , $date ) ) { |
|
175 | - return false; |
|
176 | - } |
|
177 | - return $date; |
|
174 | + if( !preg_match( '!^\d{1,2}/\d{1,2}/\d{4}$!' , $date ) ) { |
|
175 | + return false; |
|
176 | + } |
|
177 | + return $date; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | */ |
184 | 184 | function yourls_sanitize_date_for_sql( $date ) { |
185 | - if( !yourls_sanitize_date( $date ) ) |
|
186 | - return false; |
|
187 | - return date( 'Y-m-d', strtotime( $date ) ); |
|
185 | + if( !yourls_sanitize_date( $date ) ) |
|
186 | + return false; |
|
187 | + return date( 'Y-m-d', strtotime( $date ) ); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | * |
193 | 193 | */ |
194 | 194 | function yourls_trim_long_string( $string, $length = 60, $append = '[...]' ) { |
195 | - $newstring = $string; |
|
195 | + $newstring = $string; |
|
196 | 196 | if ( mb_strlen( $newstring ) > $length ) { |
197 | 197 | $newstring = mb_substr( $newstring, 0, $length - mb_strlen( $append ), 'UTF-8' ) . $append; |
198 | 198 | } |
199 | - return yourls_apply_filter( 'trim_long_string', $newstring, $string, $length, $append ); |
|
199 | + return yourls_apply_filter( 'trim_long_string', $newstring, $string, $length, $append ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -222,9 +222,9 @@ discard block |
||
222 | 222 | * |
223 | 223 | */ |
224 | 224 | function yourls_sanitize_filename( $file ) { |
225 | - $file = str_replace( '\\', '/', $file ); // sanitize for Win32 installs |
|
226 | - $file = preg_replace( '|/+|' ,'/', $file ); // remove any duplicate slash |
|
227 | - return $file; |
|
225 | + $file = str_replace( '\\', '/', $file ); // sanitize for Win32 installs |
|
226 | + $file = preg_replace( '|/+|' ,'/', $file ); // remove any duplicate slash |
|
227 | + return $file; |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | /** |
@@ -232,22 +232,22 @@ discard block |
||
232 | 232 | * |
233 | 233 | */ |
234 | 234 | function yourls_seems_utf8( $str ) { |
235 | - $length = strlen( $str ); |
|
236 | - for ( $i=0; $i < $length; $i++ ) { |
|
237 | - $c = ord( $str[ $i ] ); |
|
238 | - if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | - elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | - elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | - elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | - elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | - elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
244 | - else return false; # Does not match any model |
|
245 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | - if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
247 | - return false; |
|
248 | - } |
|
249 | - } |
|
250 | - return true; |
|
235 | + $length = strlen( $str ); |
|
236 | + for ( $i=0; $i < $length; $i++ ) { |
|
237 | + $c = ord( $str[ $i ] ); |
|
238 | + if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | + elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | + elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | + elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | + elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | + elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
244 | + else return false; # Does not match any model |
|
245 | + for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | + if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
|
247 | + return false; |
|
248 | + } |
|
249 | + } |
|
250 | + return true; |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | |
@@ -279,28 +279,28 @@ discard block |
||
279 | 279 | * @return string The checked text. |
280 | 280 | */ |
281 | 281 | function yourls_check_invalid_utf8( $string, $strip = false ) { |
282 | - $string = (string) $string; |
|
282 | + $string = (string) $string; |
|
283 | 283 | |
284 | - if ( 0 === strlen( $string ) ) { |
|
285 | - return ''; |
|
286 | - } |
|
284 | + if ( 0 === strlen( $string ) ) { |
|
285 | + return ''; |
|
286 | + } |
|
287 | 287 | |
288 | - // We can't demand utf8 in the PCRE installation, so just return the string in those cases |
|
289 | - if ( ! yourls_supports_pcre_u() ) { |
|
290 | - return $string; |
|
291 | - } |
|
288 | + // We can't demand utf8 in the PCRE installation, so just return the string in those cases |
|
289 | + if ( ! yourls_supports_pcre_u() ) { |
|
290 | + return $string; |
|
291 | + } |
|
292 | 292 | |
293 | - // preg_match fails when it encounters invalid UTF8 in $string |
|
294 | - if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
295 | - return $string; |
|
296 | - } |
|
293 | + // preg_match fails when it encounters invalid UTF8 in $string |
|
294 | + if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
295 | + return $string; |
|
296 | + } |
|
297 | 297 | |
298 | - // Attempt to strip the bad chars if requested (not recommended) |
|
299 | - if ( $strip && function_exists( 'iconv' ) ) { |
|
300 | - return iconv( 'utf-8', 'utf-8', $string ); |
|
301 | - } |
|
298 | + // Attempt to strip the bad chars if requested (not recommended) |
|
299 | + if ( $strip && function_exists( 'iconv' ) ) { |
|
300 | + return iconv( 'utf-8', 'utf-8', $string ); |
|
301 | + } |
|
302 | 302 | |
303 | - return ''; |
|
303 | + return ''; |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | /** |
@@ -319,56 +319,56 @@ discard block |
||
319 | 319 | * @return string The encoded text with HTML entities. |
320 | 320 | */ |
321 | 321 | function yourls_specialchars( $string, $quote_style = ENT_NOQUOTES, $double_encode = false ) { |
322 | - $string = (string) $string; |
|
322 | + $string = (string) $string; |
|
323 | 323 | |
324 | - if ( 0 === strlen( $string ) ) |
|
325 | - return ''; |
|
324 | + if ( 0 === strlen( $string ) ) |
|
325 | + return ''; |
|
326 | 326 | |
327 | - // Don't bother if there are no specialchars - saves some processing |
|
328 | - if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
329 | - return $string; |
|
327 | + // Don't bother if there are no specialchars - saves some processing |
|
328 | + if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
329 | + return $string; |
|
330 | 330 | |
331 | - // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
|
332 | - if ( empty( $quote_style ) ) |
|
333 | - $quote_style = ENT_NOQUOTES; |
|
334 | - elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
335 | - $quote_style = ENT_QUOTES; |
|
331 | + // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
|
332 | + if ( empty( $quote_style ) ) |
|
333 | + $quote_style = ENT_NOQUOTES; |
|
334 | + elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
335 | + $quote_style = ENT_QUOTES; |
|
336 | 336 | |
337 | - $charset = 'UTF-8'; |
|
337 | + $charset = 'UTF-8'; |
|
338 | 338 | |
339 | - $_quote_style = $quote_style; |
|
339 | + $_quote_style = $quote_style; |
|
340 | 340 | |
341 | - if ( $quote_style === 'double' ) { |
|
342 | - $quote_style = ENT_COMPAT; |
|
343 | - $_quote_style = ENT_COMPAT; |
|
344 | - } elseif ( $quote_style === 'single' ) { |
|
345 | - $quote_style = ENT_NOQUOTES; |
|
346 | - } |
|
341 | + if ( $quote_style === 'double' ) { |
|
342 | + $quote_style = ENT_COMPAT; |
|
343 | + $_quote_style = ENT_COMPAT; |
|
344 | + } elseif ( $quote_style === 'single' ) { |
|
345 | + $quote_style = ENT_NOQUOTES; |
|
346 | + } |
|
347 | 347 | |
348 | - // Handle double encoding ourselves |
|
349 | - if ( $double_encode ) { |
|
350 | - $string = @htmlspecialchars( $string, $quote_style, $charset ); |
|
351 | - } else { |
|
352 | - // Decode & into & |
|
353 | - $string = yourls_specialchars_decode( $string, $_quote_style ); |
|
348 | + // Handle double encoding ourselves |
|
349 | + if ( $double_encode ) { |
|
350 | + $string = @htmlspecialchars( $string, $quote_style, $charset ); |
|
351 | + } else { |
|
352 | + // Decode & into & |
|
353 | + $string = yourls_specialchars_decode( $string, $_quote_style ); |
|
354 | 354 | |
355 | - // Guarantee every &entity; is valid or re-encode the & |
|
356 | - $string = yourls_kses_normalize_entities( $string ); |
|
355 | + // Guarantee every &entity; is valid or re-encode the & |
|
356 | + $string = yourls_kses_normalize_entities( $string ); |
|
357 | 357 | |
358 | - // Now re-encode everything except &entity; |
|
359 | - $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
358 | + // Now re-encode everything except &entity; |
|
359 | + $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
360 | 360 | |
361 | - for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | - $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
361 | + for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | + $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
363 | 363 | |
364 | - $string = implode( '', $string ); |
|
365 | - } |
|
364 | + $string = implode( '', $string ); |
|
365 | + } |
|
366 | 366 | |
367 | - // Backwards compatibility |
|
368 | - if ( 'single' === $_quote_style ) |
|
369 | - $string = str_replace( "'", ''', $string ); |
|
367 | + // Backwards compatibility |
|
368 | + if ( 'single' === $_quote_style ) |
|
369 | + $string = str_replace( "'", ''', $string ); |
|
370 | 370 | |
371 | - return $string; |
|
371 | + return $string; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | /** |
@@ -386,51 +386,51 @@ discard block |
||
386 | 386 | * @return string The decoded text without HTML entities. |
387 | 387 | */ |
388 | 388 | function yourls_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { |
389 | - $string = (string) $string; |
|
390 | - |
|
391 | - if ( 0 === strlen( $string ) ) { |
|
392 | - return ''; |
|
393 | - } |
|
394 | - |
|
395 | - // Don't bother if there are no entities - saves a lot of processing |
|
396 | - if ( strpos( $string, '&' ) === false ) { |
|
397 | - return $string; |
|
398 | - } |
|
399 | - |
|
400 | - // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
|
401 | - if ( empty( $quote_style ) ) { |
|
402 | - $quote_style = ENT_NOQUOTES; |
|
403 | - } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
404 | - $quote_style = ENT_QUOTES; |
|
405 | - } |
|
406 | - |
|
407 | - // More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
|
408 | - $single = array( ''' => '\'', ''' => '\'' ); |
|
409 | - $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
410 | - $double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
411 | - $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
412 | - $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
413 | - $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
414 | - |
|
415 | - if ( $quote_style === ENT_QUOTES ) { |
|
416 | - $translation = array_merge( $single, $double, $others ); |
|
417 | - $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
418 | - } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
419 | - $translation = array_merge( $double, $others ); |
|
420 | - $translation_preg = array_merge( $double_preg, $others_preg ); |
|
421 | - } elseif ( $quote_style === 'single' ) { |
|
422 | - $translation = array_merge( $single, $others ); |
|
423 | - $translation_preg = array_merge( $single_preg, $others_preg ); |
|
424 | - } elseif ( $quote_style === ENT_NOQUOTES ) { |
|
425 | - $translation = $others; |
|
426 | - $translation_preg = $others_preg; |
|
427 | - } |
|
428 | - |
|
429 | - // Remove zero padding on numeric entities |
|
430 | - $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
431 | - |
|
432 | - // Replace characters according to translation table |
|
433 | - return strtr( $string, $translation ); |
|
389 | + $string = (string) $string; |
|
390 | + |
|
391 | + if ( 0 === strlen( $string ) ) { |
|
392 | + return ''; |
|
393 | + } |
|
394 | + |
|
395 | + // Don't bother if there are no entities - saves a lot of processing |
|
396 | + if ( strpos( $string, '&' ) === false ) { |
|
397 | + return $string; |
|
398 | + } |
|
399 | + |
|
400 | + // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
|
401 | + if ( empty( $quote_style ) ) { |
|
402 | + $quote_style = ENT_NOQUOTES; |
|
403 | + } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
404 | + $quote_style = ENT_QUOTES; |
|
405 | + } |
|
406 | + |
|
407 | + // More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
|
408 | + $single = array( ''' => '\'', ''' => '\'' ); |
|
409 | + $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
410 | + $double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
411 | + $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
412 | + $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
413 | + $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
414 | + |
|
415 | + if ( $quote_style === ENT_QUOTES ) { |
|
416 | + $translation = array_merge( $single, $double, $others ); |
|
417 | + $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
418 | + } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
419 | + $translation = array_merge( $double, $others ); |
|
420 | + $translation_preg = array_merge( $double_preg, $others_preg ); |
|
421 | + } elseif ( $quote_style === 'single' ) { |
|
422 | + $translation = array_merge( $single, $others ); |
|
423 | + $translation_preg = array_merge( $single_preg, $others_preg ); |
|
424 | + } elseif ( $quote_style === ENT_NOQUOTES ) { |
|
425 | + $translation = $others; |
|
426 | + $translation_preg = $others_preg; |
|
427 | + } |
|
428 | + |
|
429 | + // Remove zero padding on numeric entities |
|
430 | + $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
431 | + |
|
432 | + // Replace characters according to translation table |
|
433 | + return strtr( $string, $translation ); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | * @return string |
444 | 444 | */ |
445 | 445 | function yourls_esc_html( $text ) { |
446 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
447 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
448 | - return yourls_apply_filter( 'esc_html', $safe_text, $text ); |
|
446 | + $safe_text = yourls_check_invalid_utf8( $text ); |
|
447 | + $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
448 | + return yourls_apply_filter( 'esc_html', $safe_text, $text ); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -457,9 +457,9 @@ discard block |
||
457 | 457 | * @return string |
458 | 458 | */ |
459 | 459 | function yourls_esc_attr( $text ) { |
460 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
461 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
462 | - return yourls_apply_filter( 'esc_attr', $safe_text, $text ); |
|
460 | + $safe_text = yourls_check_invalid_utf8( $text ); |
|
461 | + $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
462 | + return yourls_apply_filter( 'esc_attr', $safe_text, $text ); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -482,38 +482,38 @@ discard block |
||
482 | 482 | // trim first -- see #1931 |
483 | 483 | $url = trim( $url ); |
484 | 484 | |
485 | - // make sure there's only one 'http://' at the beginning (prevents pasting a URL right after the default 'http://') |
|
486 | - $url = str_replace( |
|
487 | - array( 'http://http://', 'http://https://' ), |
|
488 | - array( 'http://', 'https://' ), |
|
489 | - $url |
|
490 | - ); |
|
485 | + // make sure there's only one 'http://' at the beginning (prevents pasting a URL right after the default 'http://') |
|
486 | + $url = str_replace( |
|
487 | + array( 'http://http://', 'http://https://' ), |
|
488 | + array( 'http://', 'https://' ), |
|
489 | + $url |
|
490 | + ); |
|
491 | 491 | |
492 | - if ( '' == $url ) |
|
493 | - return $url; |
|
492 | + if ( '' == $url ) |
|
493 | + return $url; |
|
494 | 494 | |
495 | - $original_url = $url; |
|
495 | + $original_url = $url; |
|
496 | 496 | |
497 | - // force scheme and domain to lowercase - see issues 591 and 1630 |
|
497 | + // force scheme and domain to lowercase - see issues 591 and 1630 |
|
498 | 498 | $url = yourls_normalize_uri( $url ); |
499 | 499 | |
500 | - $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); |
|
501 | - // Previous regexp in YOURLS was '|[^a-z0-9-~+_.?\[\]\^#=!&;,/:%@$\|*`\'<>"()\\x80-\\xff\{\}]|i' |
|
502 | - // TODO: check if that was it too destructive |
|
500 | + $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); |
|
501 | + // Previous regexp in YOURLS was '|[^a-z0-9-~+_.?\[\]\^#=!&;,/:%@$\|*`\'<>"()\\x80-\\xff\{\}]|i' |
|
502 | + // TODO: check if that was it too destructive |
|
503 | 503 | |
504 | 504 | // If $context is 'safe', an extra step is taken to make sure no CRLF injection is possible. |
505 | 505 | // To be used when $url can be forged by evil user (eg it's from a $_SERVER variable, a query string, etc..) |
506 | - if ( 'safe' == $context ) { |
|
506 | + if ( 'safe' == $context ) { |
|
507 | 507 | $strip = array( '%0d', '%0a', '%0D', '%0A' ); |
508 | 508 | $url = yourls_deep_replace( $strip, $url ); |
509 | 509 | } |
510 | 510 | |
511 | - // Replace ampersands and single quotes only when displaying. |
|
512 | - if ( 'display' == $context ) { |
|
513 | - $url = yourls_kses_normalize_entities( $url ); |
|
514 | - $url = str_replace( '&', '&', $url ); |
|
515 | - $url = str_replace( "'", ''', $url ); |
|
516 | - } |
|
511 | + // Replace ampersands and single quotes only when displaying. |
|
512 | + if ( 'display' == $context ) { |
|
513 | + $url = yourls_kses_normalize_entities( $url ); |
|
514 | + $url = str_replace( '&', '&', $url ); |
|
515 | + $url = str_replace( "'", ''', $url ); |
|
516 | + } |
|
517 | 517 | |
518 | 518 | // If there's a protocol, make sure it's OK |
519 | 519 | if( yourls_get_protocol($url) !== '' ) { |
@@ -529,7 +529,7 @@ discard block |
||
529 | 529 | // I didn't use KSES function kses_bad_protocol() because it doesn't work the way I liked (returns //blah from illegal://blah) |
530 | 530 | } |
531 | 531 | |
532 | - return yourls_apply_filter( 'esc_url', $url, $original_url, $context ); |
|
532 | + return yourls_apply_filter( 'esc_url', $url, $original_url, $context ); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | * are considered the same. Explicitely mention option and variant to avoid notice |
607 | 607 | * on PHP 7.2 and 7.3 |
608 | 608 | */ |
609 | - $lower['host'] = idn_to_utf8($lower['host'], IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
|
609 | + $lower['host'] = idn_to_utf8($lower['host'], IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | $url = http_build_url($url, $lower); |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | * @return string Escaped text. |
629 | 629 | */ |
630 | 630 | function yourls_esc_js( $text ) { |
631 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
632 | - $safe_text = yourls_specialchars( $safe_text, ENT_COMPAT ); |
|
633 | - $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
634 | - $safe_text = str_replace( "\r", '', $safe_text ); |
|
635 | - $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
636 | - return yourls_apply_filter( 'esc_js', $safe_text, $text ); |
|
631 | + $safe_text = yourls_check_invalid_utf8( $text ); |
|
632 | + $safe_text = yourls_specialchars( $safe_text, ENT_COMPAT ); |
|
633 | + $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
634 | + $safe_text = str_replace( "\r", '', $safe_text ); |
|
635 | + $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
636 | + return yourls_apply_filter( 'esc_js', $safe_text, $text ); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -645,8 +645,8 @@ discard block |
||
645 | 645 | * @return string |
646 | 646 | */ |
647 | 647 | function yourls_esc_textarea( $text ) { |
648 | - $safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
|
649 | - return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); |
|
648 | + $safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
|
649 | + return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | |
@@ -658,18 +658,18 @@ discard block |
||
658 | 658 | * @return string |
659 | 659 | */ |
660 | 660 | function yourls_encodeURI( $url ) { |
661 | - // Decode URL all the way |
|
662 | - $result = yourls_rawurldecode_while_encoded( $url ); |
|
663 | - // Encode once |
|
664 | - $result = strtr( rawurlencode( $result ), array ( |
|
661 | + // Decode URL all the way |
|
662 | + $result = yourls_rawurldecode_while_encoded( $url ); |
|
663 | + // Encode once |
|
664 | + $result = strtr( rawurlencode( $result ), array ( |
|
665 | 665 | '%3B' => ';', '%2C' => ',', '%2F' => '/', '%3F' => '?', '%3A' => ':', '%40' => '@', |
666 | - '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*', |
|
667 | - '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#', |
|
666 | + '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*', |
|
667 | + '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#', |
|
668 | 668 | ) ); |
669 | - // @TODO: |
|
670 | - // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/ |
|
671 | - // To fully support IDN URLs, advocate use of a plugin. |
|
672 | - return yourls_apply_filter( 'encodeURI', $result, $url ); |
|
669 | + // @TODO: |
|
670 | + // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/ |
|
671 | + // To fully support IDN URLs, advocate use of a plugin. |
|
672 | + return yourls_apply_filter( 'encodeURI', $result, $url ); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -696,7 +696,7 @@ discard block |
||
696 | 696 | * @return bool |
697 | 697 | */ |
698 | 698 | function yourls_is_rawurlencoded( $string ) { |
699 | - return rawurldecode( $string ) != $string; |
|
699 | + return rawurldecode( $string ) != $string; |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /** |
@@ -710,11 +710,11 @@ discard block |
||
710 | 710 | * @return string |
711 | 711 | */ |
712 | 712 | function yourls_rawurldecode_while_encoded( $string ) { |
713 | - $string = rawurldecode( $string ); |
|
714 | - if( yourls_is_rawurlencoded( $string ) ) { |
|
715 | - $string = yourls_rawurldecode_while_encoded( $string ); |
|
716 | - } |
|
717 | - return $string; |
|
713 | + $string = rawurldecode( $string ); |
|
714 | + if( yourls_is_rawurlencoded( $string ) ) { |
|
715 | + $string = yourls_rawurldecode_while_encoded( $string ); |
|
716 | + } |
|
717 | + return $string; |
|
718 | 718 | } |
719 | 719 | |
720 | 720 | /** |
@@ -8,46 +8,46 @@ discard block |
||
8 | 8 | * Convert an integer (1337) to a string (3jk). |
9 | 9 | * |
10 | 10 | */ |
11 | -function yourls_int2string( $num, $chars = null ) { |
|
12 | - if( $chars == null ) |
|
11 | +function yourls_int2string($num, $chars = null) { |
|
12 | + if ($chars == null) |
|
13 | 13 | $chars = yourls_get_shorturl_charset(); |
14 | 14 | $string = ''; |
15 | - $len = strlen( $chars ); |
|
16 | - while( $num >= $len ) { |
|
17 | - $mod = bcmod( $num, $len ); |
|
18 | - $num = bcdiv( $num, $len ); |
|
19 | - $string = $chars[ $mod ] . $string; |
|
15 | + $len = strlen($chars); |
|
16 | + while ($num >= $len) { |
|
17 | + $mod = bcmod($num, $len); |
|
18 | + $num = bcdiv($num, $len); |
|
19 | + $string = $chars[$mod].$string; |
|
20 | 20 | } |
21 | - $string = $chars[ intval( $num ) ] . $string; |
|
21 | + $string = $chars[intval($num)].$string; |
|
22 | 22 | |
23 | - return yourls_apply_filter( 'int2string', $string, $num, $chars ); |
|
23 | + return yourls_apply_filter('int2string', $string, $num, $chars); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Convert a string (3jk) to an integer (1337) |
28 | 28 | * |
29 | 29 | */ |
30 | -function yourls_string2int( $string, $chars = null ) { |
|
31 | - if( $chars == null ) |
|
30 | +function yourls_string2int($string, $chars = null) { |
|
31 | + if ($chars == null) |
|
32 | 32 | $chars = yourls_get_shorturl_charset(); |
33 | 33 | $integer = 0; |
34 | - $string = strrev( $string ); |
|
35 | - $baselen = strlen( $chars ); |
|
36 | - $inputlen = strlen( $string ); |
|
34 | + $string = strrev($string); |
|
35 | + $baselen = strlen($chars); |
|
36 | + $inputlen = strlen($string); |
|
37 | 37 | for ($i = 0; $i < $inputlen; $i++) { |
38 | - $index = strpos( $chars, $string[$i] ); |
|
39 | - $integer = bcadd( $integer, bcmul( $index, bcpow( $baselen, $i ) ) ); |
|
38 | + $index = strpos($chars, $string[$i]); |
|
39 | + $integer = bcadd($integer, bcmul($index, bcpow($baselen, $i))); |
|
40 | 40 | } |
41 | 41 | |
42 | - return yourls_apply_filter( 'string2int', $integer, $string, $chars ); |
|
42 | + return yourls_apply_filter('string2int', $integer, $string, $chars); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Return a unique(ish) hash for a string to be used as a valid HTML id |
47 | 47 | * |
48 | 48 | */ |
49 | -function yourls_string2htmlid( $string ) { |
|
50 | - return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) ); |
|
49 | +function yourls_string2htmlid($string) { |
|
50 | + return yourls_apply_filter('string2htmlid', 'y'.abs(crc32($string))); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | * @param bool $restrict_to_shorturl_charset Optional, default false. True if we want the keyword to comply to short URL charset |
64 | 64 | * @return string The sanitized keyword |
65 | 65 | */ |
66 | -function yourls_sanitize_keyword( $keyword, $restrict_to_shorturl_charset = false ) { |
|
67 | - if( $restrict_to_shorturl_charset === true ) { |
|
66 | +function yourls_sanitize_keyword($keyword, $restrict_to_shorturl_charset = false) { |
|
67 | + if ($restrict_to_shorturl_charset === true) { |
|
68 | 68 | // make a regexp pattern with the shorturl charset, and remove everything but this |
69 | - $pattern = yourls_make_regexp_pattern( yourls_get_shorturl_charset() ); |
|
70 | - $valid = (string) substr( preg_replace( '![^'.$pattern.']!', '', $keyword ), 0, 199 ); |
|
69 | + $pattern = yourls_make_regexp_pattern(yourls_get_shorturl_charset()); |
|
70 | + $valid = (string) substr(preg_replace('![^'.$pattern.']!', '', $keyword), 0, 199); |
|
71 | 71 | } else { |
72 | - $valid = yourls_sanitize_url( $keyword ); |
|
72 | + $valid = yourls_sanitize_url($keyword); |
|
73 | 73 | } |
74 | 74 | |
75 | - return yourls_apply_filter( 'sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset ); |
|
75 | + return yourls_apply_filter('sanitize_string', $valid, $keyword, $restrict_to_shorturl_charset); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | * @param string $fallback Optional fallback if after sanitization nothing remains |
85 | 85 | * @return string Safe title |
86 | 86 | */ |
87 | -function yourls_sanitize_title( $unsafe_title, $fallback = '' ) { |
|
87 | +function yourls_sanitize_title($unsafe_title, $fallback = '') { |
|
88 | 88 | $title = $unsafe_title; |
89 | - $title = strip_tags( $title ); |
|
90 | - $title = preg_replace( "/\s+/", ' ', trim( $title ) ); |
|
89 | + $title = strip_tags($title); |
|
90 | + $title = preg_replace("/\s+/", ' ', trim($title)); |
|
91 | 91 | |
92 | - if ( '' === $title || false === $title ) { |
|
92 | + if ('' === $title || false === $title) { |
|
93 | 93 | $title = $fallback; |
94 | 94 | } |
95 | 95 | |
96 | - return yourls_apply_filter( 'sanitize_title', $title, $unsafe_title, $fallback ); |
|
96 | + return yourls_apply_filter('sanitize_title', $title, $unsafe_title, $fallback); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | * @param array $protocols Optional allowed protocols, default to global $yourls_allowedprotocols |
106 | 106 | * @return string Safe URL |
107 | 107 | */ |
108 | -function yourls_sanitize_url( $unsafe_url, $protocols = array() ) { |
|
109 | - $url = yourls_esc_url( $unsafe_url, 'redirection', $protocols ); |
|
110 | - return yourls_apply_filter( 'sanitize_url', $url, $unsafe_url ); |
|
108 | +function yourls_sanitize_url($unsafe_url, $protocols = array()) { |
|
109 | + $url = yourls_esc_url($unsafe_url, 'redirection', $protocols); |
|
110 | + return yourls_apply_filter('sanitize_url', $url, $unsafe_url); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * @param array $protocols Optional allowed protocols, default to global $yourls_allowedprotocols |
125 | 125 | * @return string Safe URL |
126 | 126 | */ |
127 | -function yourls_sanitize_url_safe( $unsafe_url, $protocols = array() ) { |
|
128 | - $url = yourls_esc_url( $unsafe_url, 'safe', $protocols ); |
|
129 | - return yourls_apply_filter( 'sanitize_url_safe', $url, $unsafe_url ); |
|
127 | +function yourls_sanitize_url_safe($unsafe_url, $protocols = array()) { |
|
128 | + $url = yourls_esc_url($unsafe_url, 'safe', $protocols); |
|
129 | + return yourls_apply_filter('sanitize_url_safe', $url, $unsafe_url); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -135,14 +135,14 @@ discard block |
||
135 | 135 | * Stolen from WP's _deep_replace |
136 | 136 | * |
137 | 137 | */ |
138 | -function yourls_deep_replace( $search, $subject ){ |
|
138 | +function yourls_deep_replace($search, $subject) { |
|
139 | 139 | $found = true; |
140 | - while($found) { |
|
140 | + while ($found) { |
|
141 | 141 | $found = false; |
142 | - foreach( (array) $search as $val ) { |
|
143 | - while( strpos( $subject, $val ) !== false ) { |
|
142 | + foreach ((array) $search as $val) { |
|
143 | + while (strpos($subject, $val) !== false) { |
|
144 | 144 | $found = true; |
145 | - $subject = str_replace( $val, '', $subject ); |
|
145 | + $subject = str_replace($val, '', $subject); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
@@ -154,24 +154,24 @@ discard block |
||
154 | 154 | * Make sure an integer is a valid integer (PHP's intval() limits to too small numbers) |
155 | 155 | * |
156 | 156 | */ |
157 | -function yourls_sanitize_int( $int ) { |
|
158 | - return ( substr( preg_replace( '/[^0-9]/', '', strval( $int ) ), 0, 20 ) ); |
|
157 | +function yourls_sanitize_int($int) { |
|
158 | + return (substr(preg_replace('/[^0-9]/', '', strval($int)), 0, 20)); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | 162 | * Sanitize an IP address |
163 | 163 | * |
164 | 164 | */ |
165 | -function yourls_sanitize_ip( $ip ) { |
|
166 | - return preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip ); |
|
165 | +function yourls_sanitize_ip($ip) { |
|
166 | + return preg_replace('/[^0-9a-fA-F:., ]/', '', $ip); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Make sure a date is m(m)/d(d)/yyyy, return false otherwise |
171 | 171 | * |
172 | 172 | */ |
173 | -function yourls_sanitize_date( $date ) { |
|
174 | - if( !preg_match( '!^\d{1,2}/\d{1,2}/\d{4}$!' , $date ) ) { |
|
173 | +function yourls_sanitize_date($date) { |
|
174 | + if (!preg_match('!^\d{1,2}/\d{1,2}/\d{4}$!', $date)) { |
|
175 | 175 | return false; |
176 | 176 | } |
177 | 177 | return $date; |
@@ -181,22 +181,22 @@ discard block |
||
181 | 181 | * Sanitize a date for SQL search. Return false if malformed input. |
182 | 182 | * |
183 | 183 | */ |
184 | -function yourls_sanitize_date_for_sql( $date ) { |
|
185 | - if( !yourls_sanitize_date( $date ) ) |
|
184 | +function yourls_sanitize_date_for_sql($date) { |
|
185 | + if (!yourls_sanitize_date($date)) |
|
186 | 186 | return false; |
187 | - return date( 'Y-m-d', strtotime( $date ) ); |
|
187 | + return date('Y-m-d', strtotime($date)); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | /** |
191 | 191 | * Return trimmed string |
192 | 192 | * |
193 | 193 | */ |
194 | -function yourls_trim_long_string( $string, $length = 60, $append = '[...]' ) { |
|
194 | +function yourls_trim_long_string($string, $length = 60, $append = '[...]') { |
|
195 | 195 | $newstring = $string; |
196 | - if ( mb_strlen( $newstring ) > $length ) { |
|
197 | - $newstring = mb_substr( $newstring, 0, $length - mb_strlen( $append ), 'UTF-8' ) . $append; |
|
196 | + if (mb_strlen($newstring) > $length) { |
|
197 | + $newstring = mb_substr($newstring, 0, $length - mb_strlen($append), 'UTF-8').$append; |
|
198 | 198 | } |
199 | - return yourls_apply_filter( 'trim_long_string', $newstring, $string, $length, $append ); |
|
199 | + return yourls_apply_filter('trim_long_string', $newstring, $string, $length, $append); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | * @param string $version Version number |
211 | 211 | * @return string Sanitized version number |
212 | 212 | */ |
213 | -function yourls_sanitize_version( $version ) { |
|
214 | - preg_match( '/([0-9]+\.[0-9.]+).*$/', $version, $matches ); |
|
213 | +function yourls_sanitize_version($version) { |
|
214 | + preg_match('/([0-9]+\.[0-9.]+).*$/', $version, $matches); |
|
215 | 215 | $version = isset($matches[1]) ? trim($matches[1], '.') : ''; |
216 | 216 | |
217 | 217 | return $version; |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | * Sanitize a filename (no Win32 stuff) |
222 | 222 | * |
223 | 223 | */ |
224 | -function yourls_sanitize_filename( $file ) { |
|
225 | - $file = str_replace( '\\', '/', $file ); // sanitize for Win32 installs |
|
226 | - $file = preg_replace( '|/+|' ,'/', $file ); // remove any duplicate slash |
|
224 | +function yourls_sanitize_filename($file) { |
|
225 | + $file = str_replace('\\', '/', $file); // sanitize for Win32 installs |
|
226 | + $file = preg_replace('|/+|', '/', $file); // remove any duplicate slash |
|
227 | 227 | return $file; |
228 | 228 | } |
229 | 229 | |
@@ -231,18 +231,18 @@ discard block |
||
231 | 231 | * Check if a string seems to be UTF-8. Stolen from WP. |
232 | 232 | * |
233 | 233 | */ |
234 | -function yourls_seems_utf8( $str ) { |
|
235 | - $length = strlen( $str ); |
|
236 | - for ( $i=0; $i < $length; $i++ ) { |
|
237 | - $c = ord( $str[ $i ] ); |
|
238 | - if ( $c < 0x80 ) $n = 0; # 0bbbbbbb |
|
239 | - elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb |
|
240 | - elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb |
|
241 | - elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb |
|
242 | - elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb |
|
243 | - elseif (($c & 0xFE) == 0xFC) $n=5; # 1111110b |
|
234 | +function yourls_seems_utf8($str) { |
|
235 | + $length = strlen($str); |
|
236 | + for ($i = 0; $i < $length; $i++) { |
|
237 | + $c = ord($str[$i]); |
|
238 | + if ($c < 0x80) $n = 0; # 0bbbbbbb |
|
239 | + elseif (($c & 0xE0) == 0xC0) $n = 1; # 110bbbbb |
|
240 | + elseif (($c & 0xF0) == 0xE0) $n = 2; # 1110bbbb |
|
241 | + elseif (($c & 0xF8) == 0xF0) $n = 3; # 11110bbb |
|
242 | + elseif (($c & 0xFC) == 0xF8) $n = 4; # 111110bb |
|
243 | + elseif (($c & 0xFE) == 0xFC) $n = 5; # 1111110b |
|
244 | 244 | else return false; # Does not match any model |
245 | - for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
245 | + for ($j = 0; $j < $n; $j++) { # n bytes matching 10bbbbbb follow ? |
|
246 | 246 | if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) |
247 | 247 | return false; |
248 | 248 | } |
@@ -263,8 +263,8 @@ discard block |
||
263 | 263 | */ |
264 | 264 | function yourls_supports_pcre_u() { |
265 | 265 | static $utf8_pcre; |
266 | - if( !isset( $utf8_pcre ) ) { |
|
267 | - $utf8_pcre = (bool) @preg_match( '/^./u', 'a' ); |
|
266 | + if (!isset($utf8_pcre)) { |
|
267 | + $utf8_pcre = (bool) @preg_match('/^./u', 'a'); |
|
268 | 268 | } |
269 | 269 | return $utf8_pcre; |
270 | 270 | } |
@@ -278,26 +278,26 @@ discard block |
||
278 | 278 | * @param boolean $strip Optional. Whether to attempt to strip out invalid UTF8. Default is false. |
279 | 279 | * @return string The checked text. |
280 | 280 | */ |
281 | -function yourls_check_invalid_utf8( $string, $strip = false ) { |
|
281 | +function yourls_check_invalid_utf8($string, $strip = false) { |
|
282 | 282 | $string = (string) $string; |
283 | 283 | |
284 | - if ( 0 === strlen( $string ) ) { |
|
284 | + if (0 === strlen($string)) { |
|
285 | 285 | return ''; |
286 | 286 | } |
287 | 287 | |
288 | 288 | // We can't demand utf8 in the PCRE installation, so just return the string in those cases |
289 | - if ( ! yourls_supports_pcre_u() ) { |
|
289 | + if (!yourls_supports_pcre_u()) { |
|
290 | 290 | return $string; |
291 | 291 | } |
292 | 292 | |
293 | 293 | // preg_match fails when it encounters invalid UTF8 in $string |
294 | - if ( 1 === @preg_match( '/^./us', $string ) ) { |
|
294 | + if (1 === @preg_match('/^./us', $string)) { |
|
295 | 295 | return $string; |
296 | 296 | } |
297 | 297 | |
298 | 298 | // Attempt to strip the bad chars if requested (not recommended) |
299 | - if ( $strip && function_exists( 'iconv' ) ) { |
|
300 | - return iconv( 'utf-8', 'utf-8', $string ); |
|
299 | + if ($strip && function_exists('iconv')) { |
|
300 | + return iconv('utf-8', 'utf-8', $string); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | return ''; |
@@ -318,55 +318,55 @@ discard block |
||
318 | 318 | * @param boolean $double_encode Optional. Whether to encode existing html entities. Default is false. |
319 | 319 | * @return string The encoded text with HTML entities. |
320 | 320 | */ |
321 | -function yourls_specialchars( $string, $quote_style = ENT_NOQUOTES, $double_encode = false ) { |
|
321 | +function yourls_specialchars($string, $quote_style = ENT_NOQUOTES, $double_encode = false) { |
|
322 | 322 | $string = (string) $string; |
323 | 323 | |
324 | - if ( 0 === strlen( $string ) ) |
|
324 | + if (0 === strlen($string)) |
|
325 | 325 | return ''; |
326 | 326 | |
327 | 327 | // Don't bother if there are no specialchars - saves some processing |
328 | - if ( ! preg_match( '/[&<>"\']/', $string ) ) |
|
328 | + if (!preg_match('/[&<>"\']/', $string)) |
|
329 | 329 | return $string; |
330 | 330 | |
331 | 331 | // Account for the previous behaviour of the function when the $quote_style is not an accepted value |
332 | - if ( empty( $quote_style ) ) |
|
332 | + if (empty($quote_style)) |
|
333 | 333 | $quote_style = ENT_NOQUOTES; |
334 | - elseif ( ! in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) |
|
334 | + elseif (!in_array($quote_style, array(0, 2, 3, 'single', 'double'), true)) |
|
335 | 335 | $quote_style = ENT_QUOTES; |
336 | 336 | |
337 | 337 | $charset = 'UTF-8'; |
338 | 338 | |
339 | 339 | $_quote_style = $quote_style; |
340 | 340 | |
341 | - if ( $quote_style === 'double' ) { |
|
341 | + if ($quote_style === 'double') { |
|
342 | 342 | $quote_style = ENT_COMPAT; |
343 | 343 | $_quote_style = ENT_COMPAT; |
344 | - } elseif ( $quote_style === 'single' ) { |
|
344 | + } elseif ($quote_style === 'single') { |
|
345 | 345 | $quote_style = ENT_NOQUOTES; |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Handle double encoding ourselves |
349 | - if ( $double_encode ) { |
|
350 | - $string = @htmlspecialchars( $string, $quote_style, $charset ); |
|
349 | + if ($double_encode) { |
|
350 | + $string = @htmlspecialchars($string, $quote_style, $charset); |
|
351 | 351 | } else { |
352 | 352 | // Decode & into & |
353 | - $string = yourls_specialchars_decode( $string, $_quote_style ); |
|
353 | + $string = yourls_specialchars_decode($string, $_quote_style); |
|
354 | 354 | |
355 | 355 | // Guarantee every &entity; is valid or re-encode the & |
356 | - $string = yourls_kses_normalize_entities( $string ); |
|
356 | + $string = yourls_kses_normalize_entities($string); |
|
357 | 357 | |
358 | 358 | // Now re-encode everything except &entity; |
359 | - $string = preg_split( '/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
359 | + $string = preg_split('/(&#?x?[0-9a-z]+;)/i', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
360 | 360 | |
361 | - for ( $i = 0; $i < count( $string ); $i += 2 ) |
|
362 | - $string[$i] = @htmlspecialchars( $string[$i], $quote_style, $charset ); |
|
361 | + for ($i = 0; $i < count($string); $i += 2) |
|
362 | + $string[$i] = @htmlspecialchars($string[$i], $quote_style, $charset); |
|
363 | 363 | |
364 | - $string = implode( '', $string ); |
|
364 | + $string = implode('', $string); |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | // Backwards compatibility |
368 | - if ( 'single' === $_quote_style ) |
|
369 | - $string = str_replace( "'", ''', $string ); |
|
368 | + if ('single' === $_quote_style) |
|
369 | + $string = str_replace("'", ''', $string); |
|
370 | 370 | |
371 | 371 | return $string; |
372 | 372 | } |
@@ -385,52 +385,52 @@ discard block |
||
385 | 385 | * @param mixed $quote_style Optional. Converts double quotes if set to ENT_COMPAT, both single and double if set to ENT_QUOTES or none if set to ENT_NOQUOTES. Also compatible with old _wp_specialchars() values; converting single quotes if set to 'single', double if set to 'double' or both if otherwise set. Default is ENT_NOQUOTES. |
386 | 386 | * @return string The decoded text without HTML entities. |
387 | 387 | */ |
388 | -function yourls_specialchars_decode( $string, $quote_style = ENT_NOQUOTES ) { |
|
388 | +function yourls_specialchars_decode($string, $quote_style = ENT_NOQUOTES) { |
|
389 | 389 | $string = (string) $string; |
390 | 390 | |
391 | - if ( 0 === strlen( $string ) ) { |
|
391 | + if (0 === strlen($string)) { |
|
392 | 392 | return ''; |
393 | 393 | } |
394 | 394 | |
395 | 395 | // Don't bother if there are no entities - saves a lot of processing |
396 | - if ( strpos( $string, '&' ) === false ) { |
|
396 | + if (strpos($string, '&') === false) { |
|
397 | 397 | return $string; |
398 | 398 | } |
399 | 399 | |
400 | 400 | // Match the previous behaviour of _wp_specialchars() when the $quote_style is not an accepted value |
401 | - if ( empty( $quote_style ) ) { |
|
401 | + if (empty($quote_style)) { |
|
402 | 402 | $quote_style = ENT_NOQUOTES; |
403 | - } elseif ( !in_array( $quote_style, array( 0, 2, 3, 'single', 'double' ), true ) ) { |
|
403 | + } elseif (!in_array($quote_style, array(0, 2, 3, 'single', 'double'), true)) { |
|
404 | 404 | $quote_style = ENT_QUOTES; |
405 | 405 | } |
406 | 406 | |
407 | 407 | // More complete than get_html_translation_table( HTML_SPECIALCHARS ) |
408 | - $single = array( ''' => '\'', ''' => '\'' ); |
|
409 | - $single_preg = array( '/�*39;/' => ''', '/�*27;/i' => ''' ); |
|
410 | - $double = array( '"' => '"', '"' => '"', '"' => '"' ); |
|
411 | - $double_preg = array( '/�*34;/' => '"', '/�*22;/i' => '"' ); |
|
412 | - $others = array( '<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&' ); |
|
413 | - $others_preg = array( '/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&' ); |
|
414 | - |
|
415 | - if ( $quote_style === ENT_QUOTES ) { |
|
416 | - $translation = array_merge( $single, $double, $others ); |
|
417 | - $translation_preg = array_merge( $single_preg, $double_preg, $others_preg ); |
|
418 | - } elseif ( $quote_style === ENT_COMPAT || $quote_style === 'double' ) { |
|
419 | - $translation = array_merge( $double, $others ); |
|
420 | - $translation_preg = array_merge( $double_preg, $others_preg ); |
|
421 | - } elseif ( $quote_style === 'single' ) { |
|
422 | - $translation = array_merge( $single, $others ); |
|
423 | - $translation_preg = array_merge( $single_preg, $others_preg ); |
|
424 | - } elseif ( $quote_style === ENT_NOQUOTES ) { |
|
408 | + $single = array(''' => '\'', ''' => '\''); |
|
409 | + $single_preg = array('/�*39;/' => ''', '/�*27;/i' => '''); |
|
410 | + $double = array('"' => '"', '"' => '"', '"' => '"'); |
|
411 | + $double_preg = array('/�*34;/' => '"', '/�*22;/i' => '"'); |
|
412 | + $others = array('<' => '<', '<' => '<', '>' => '>', '>' => '>', '&' => '&', '&' => '&', '&' => '&'); |
|
413 | + $others_preg = array('/�*60;/' => '<', '/�*62;/' => '>', '/�*38;/' => '&', '/�*26;/i' => '&'); |
|
414 | + |
|
415 | + if ($quote_style === ENT_QUOTES) { |
|
416 | + $translation = array_merge($single, $double, $others); |
|
417 | + $translation_preg = array_merge($single_preg, $double_preg, $others_preg); |
|
418 | + } elseif ($quote_style === ENT_COMPAT || $quote_style === 'double') { |
|
419 | + $translation = array_merge($double, $others); |
|
420 | + $translation_preg = array_merge($double_preg, $others_preg); |
|
421 | + } elseif ($quote_style === 'single') { |
|
422 | + $translation = array_merge($single, $others); |
|
423 | + $translation_preg = array_merge($single_preg, $others_preg); |
|
424 | + } elseif ($quote_style === ENT_NOQUOTES) { |
|
425 | 425 | $translation = $others; |
426 | 426 | $translation_preg = $others_preg; |
427 | 427 | } |
428 | 428 | |
429 | 429 | // Remove zero padding on numeric entities |
430 | - $string = preg_replace( array_keys( $translation_preg ), array_values( $translation_preg ), $string ); |
|
430 | + $string = preg_replace(array_keys($translation_preg), array_values($translation_preg), $string); |
|
431 | 431 | |
432 | 432 | // Replace characters according to translation table |
433 | - return strtr( $string, $translation ); |
|
433 | + return strtr($string, $translation); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | |
@@ -442,10 +442,10 @@ discard block |
||
442 | 442 | * @param string $text |
443 | 443 | * @return string |
444 | 444 | */ |
445 | -function yourls_esc_html( $text ) { |
|
446 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
447 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
448 | - return yourls_apply_filter( 'esc_html', $safe_text, $text ); |
|
445 | +function yourls_esc_html($text) { |
|
446 | + $safe_text = yourls_check_invalid_utf8($text); |
|
447 | + $safe_text = yourls_specialchars($safe_text, ENT_QUOTES); |
|
448 | + return yourls_apply_filter('esc_html', $safe_text, $text); |
|
449 | 449 | } |
450 | 450 | |
451 | 451 | /** |
@@ -456,10 +456,10 @@ discard block |
||
456 | 456 | * @param string $text |
457 | 457 | * @return string |
458 | 458 | */ |
459 | -function yourls_esc_attr( $text ) { |
|
460 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
461 | - $safe_text = yourls_specialchars( $safe_text, ENT_QUOTES ); |
|
462 | - return yourls_apply_filter( 'esc_attr', $safe_text, $text ); |
|
459 | +function yourls_esc_attr($text) { |
|
460 | + $safe_text = yourls_check_invalid_utf8($text); |
|
461 | + $safe_text = yourls_specialchars($safe_text, ENT_QUOTES); |
|
462 | + return yourls_apply_filter('esc_attr', $safe_text, $text); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -478,58 +478,58 @@ discard block |
||
478 | 478 | * @param array $protocols Optional. Array of allowed protocols, defaults to global $yourls_allowedprotocols |
479 | 479 | * @return string The cleaned $url |
480 | 480 | */ |
481 | -function yourls_esc_url( $url, $context = 'display', $protocols = array() ) { |
|
481 | +function yourls_esc_url($url, $context = 'display', $protocols = array()) { |
|
482 | 482 | // trim first -- see #1931 |
483 | - $url = trim( $url ); |
|
483 | + $url = trim($url); |
|
484 | 484 | |
485 | 485 | // make sure there's only one 'http://' at the beginning (prevents pasting a URL right after the default 'http://') |
486 | 486 | $url = str_replace( |
487 | - array( 'http://http://', 'http://https://' ), |
|
488 | - array( 'http://', 'https://' ), |
|
487 | + array('http://http://', 'http://https://'), |
|
488 | + array('http://', 'https://'), |
|
489 | 489 | $url |
490 | 490 | ); |
491 | 491 | |
492 | - if ( '' == $url ) |
|
492 | + if ('' == $url) |
|
493 | 493 | return $url; |
494 | 494 | |
495 | 495 | $original_url = $url; |
496 | 496 | |
497 | 497 | // force scheme and domain to lowercase - see issues 591 and 1630 |
498 | - $url = yourls_normalize_uri( $url ); |
|
498 | + $url = yourls_normalize_uri($url); |
|
499 | 499 | |
500 | - $url = preg_replace( '|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url ); |
|
500 | + $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url); |
|
501 | 501 | // Previous regexp in YOURLS was '|[^a-z0-9-~+_.?\[\]\^#=!&;,/:%@$\|*`\'<>"()\\x80-\\xff\{\}]|i' |
502 | 502 | // TODO: check if that was it too destructive |
503 | 503 | |
504 | 504 | // If $context is 'safe', an extra step is taken to make sure no CRLF injection is possible. |
505 | 505 | // To be used when $url can be forged by evil user (eg it's from a $_SERVER variable, a query string, etc..) |
506 | - if ( 'safe' == $context ) { |
|
507 | - $strip = array( '%0d', '%0a', '%0D', '%0A' ); |
|
508 | - $url = yourls_deep_replace( $strip, $url ); |
|
506 | + if ('safe' == $context) { |
|
507 | + $strip = array('%0d', '%0a', '%0D', '%0A'); |
|
508 | + $url = yourls_deep_replace($strip, $url); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | // Replace ampersands and single quotes only when displaying. |
512 | - if ( 'display' == $context ) { |
|
513 | - $url = yourls_kses_normalize_entities( $url ); |
|
514 | - $url = str_replace( '&', '&', $url ); |
|
515 | - $url = str_replace( "'", ''', $url ); |
|
512 | + if ('display' == $context) { |
|
513 | + $url = yourls_kses_normalize_entities($url); |
|
514 | + $url = str_replace('&', '&', $url); |
|
515 | + $url = str_replace("'", ''', $url); |
|
516 | 516 | } |
517 | 517 | |
518 | 518 | // If there's a protocol, make sure it's OK |
519 | - if( yourls_get_protocol($url) !== '' ) { |
|
520 | - if ( ! is_array( $protocols ) or ! $protocols ) { |
|
519 | + if (yourls_get_protocol($url) !== '') { |
|
520 | + if (!is_array($protocols) or !$protocols) { |
|
521 | 521 | global $yourls_allowedprotocols; |
522 | - $protocols = yourls_apply_filter( 'esc_url_protocols', $yourls_allowedprotocols ); |
|
522 | + $protocols = yourls_apply_filter('esc_url_protocols', $yourls_allowedprotocols); |
|
523 | 523 | // Note: $yourls_allowedprotocols is also globally filterable in functions-kses.php/yourls_kses_init() |
524 | 524 | } |
525 | 525 | |
526 | - if ( !yourls_is_allowed_protocol( $url, $protocols ) ) |
|
526 | + if (!yourls_is_allowed_protocol($url, $protocols)) |
|
527 | 527 | return ''; |
528 | 528 | |
529 | 529 | // I didn't use KSES function kses_bad_protocol() because it doesn't work the way I liked (returns //blah from illegal://blah) |
530 | 530 | } |
531 | 531 | |
532 | - return yourls_apply_filter( 'esc_url', $url, $original_url, $context ); |
|
532 | + return yourls_apply_filter('esc_url', $url, $original_url, $context); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @param string $url URL |
566 | 566 | * @return string URL with lowercase scheme and protocol |
567 | 567 | */ |
568 | -function yourls_normalize_uri( $url ) { |
|
569 | - $scheme = yourls_get_protocol( $url ); |
|
568 | +function yourls_normalize_uri($url) { |
|
569 | + $scheme = yourls_get_protocol($url); |
|
570 | 570 | |
571 | 571 | if ('' == $scheme) { |
572 | 572 | // Scheme not found, malformed URL? Something else? Not sure. |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | * In this case, we only lowercase the scheme, because depending on it, things after should or should not be lowercased |
580 | 580 | */ |
581 | 581 | if (substr($scheme, -2, 2) != '//') { |
582 | - $url = str_replace( $scheme, strtolower( $scheme ), $url ); |
|
582 | + $url = str_replace($scheme, strtolower($scheme), $url); |
|
583 | 583 | return $url; |
584 | 584 | } |
585 | 585 | |
@@ -591,14 +591,14 @@ discard block |
||
591 | 591 | |
592 | 592 | // Most likely malformed stuff, could not parse : we'll just lowercase the scheme and leave the rest untouched |
593 | 593 | if (false == $parts) { |
594 | - $url = str_replace( $scheme, strtolower( $scheme ), $url ); |
|
594 | + $url = str_replace($scheme, strtolower($scheme), $url); |
|
595 | 595 | return $url; |
596 | 596 | } |
597 | 597 | |
598 | 598 | // URL seems parsable, let's do the best we can |
599 | 599 | $lower = array(); |
600 | - $lower['scheme'] = strtolower( $parts['scheme'] ); |
|
601 | - if( isset( $parts['host'] ) ) { |
|
600 | + $lower['scheme'] = strtolower($parts['scheme']); |
|
601 | + if (isset($parts['host'])) { |
|
602 | 602 | // Convert domain to lowercase, with mb_ to preserve UTF8 |
603 | 603 | $lower['host'] = mb_strtolower($parts['host']); |
604 | 604 | /** |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | * @param string $text The text to be escaped. |
628 | 628 | * @return string Escaped text. |
629 | 629 | */ |
630 | -function yourls_esc_js( $text ) { |
|
631 | - $safe_text = yourls_check_invalid_utf8( $text ); |
|
632 | - $safe_text = yourls_specialchars( $safe_text, ENT_COMPAT ); |
|
633 | - $safe_text = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes( $safe_text ) ); |
|
634 | - $safe_text = str_replace( "\r", '', $safe_text ); |
|
635 | - $safe_text = str_replace( "\n", '\\n', addslashes( $safe_text ) ); |
|
636 | - return yourls_apply_filter( 'esc_js', $safe_text, $text ); |
|
630 | +function yourls_esc_js($text) { |
|
631 | + $safe_text = yourls_check_invalid_utf8($text); |
|
632 | + $safe_text = yourls_specialchars($safe_text, ENT_COMPAT); |
|
633 | + $safe_text = preg_replace('/&#(x)?0*(?(1)27|39);?/i', "'", stripslashes($safe_text)); |
|
634 | + $safe_text = str_replace("\r", '', $safe_text); |
|
635 | + $safe_text = str_replace("\n", '\\n', addslashes($safe_text)); |
|
636 | + return yourls_apply_filter('esc_js', $safe_text, $text); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | /** |
@@ -644,9 +644,9 @@ discard block |
||
644 | 644 | * @param string $text |
645 | 645 | * @return string |
646 | 646 | */ |
647 | -function yourls_esc_textarea( $text ) { |
|
648 | - $safe_text = htmlspecialchars( $text, ENT_QUOTES ); |
|
649 | - return yourls_apply_filter( 'esc_textarea', $safe_text, $text ); |
|
647 | +function yourls_esc_textarea($text) { |
|
648 | + $safe_text = htmlspecialchars($text, ENT_QUOTES); |
|
649 | + return yourls_apply_filter('esc_textarea', $safe_text, $text); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | |
@@ -657,19 +657,19 @@ discard block |
||
657 | 657 | * @param $url |
658 | 658 | * @return string |
659 | 659 | */ |
660 | -function yourls_encodeURI( $url ) { |
|
660 | +function yourls_encodeURI($url) { |
|
661 | 661 | // Decode URL all the way |
662 | - $result = yourls_rawurldecode_while_encoded( $url ); |
|
662 | + $result = yourls_rawurldecode_while_encoded($url); |
|
663 | 663 | // Encode once |
664 | - $result = strtr( rawurlencode( $result ), array ( |
|
664 | + $result = strtr(rawurlencode($result), array( |
|
665 | 665 | '%3B' => ';', '%2C' => ',', '%2F' => '/', '%3F' => '?', '%3A' => ':', '%40' => '@', |
666 | 666 | '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*', |
667 | 667 | '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#', |
668 | - ) ); |
|
668 | + )); |
|
669 | 669 | // @TODO: |
670 | 670 | // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/ |
671 | 671 | // To fully support IDN URLs, advocate use of a plugin. |
672 | - return yourls_apply_filter( 'encodeURI', $result, $url ); |
|
672 | + return yourls_apply_filter('encodeURI', $result, $url); |
|
673 | 673 | } |
674 | 674 | |
675 | 675 | /** |
@@ -695,8 +695,8 @@ discard block |
||
695 | 695 | * @param string $string |
696 | 696 | * @return bool |
697 | 697 | */ |
698 | -function yourls_is_rawurlencoded( $string ) { |
|
699 | - return rawurldecode( $string ) != $string; |
|
698 | +function yourls_is_rawurlencoded($string) { |
|
699 | + return rawurldecode($string) != $string; |
|
700 | 700 | } |
701 | 701 | |
702 | 702 | /** |
@@ -709,10 +709,10 @@ discard block |
||
709 | 709 | * @param string $string |
710 | 710 | * @return string |
711 | 711 | */ |
712 | -function yourls_rawurldecode_while_encoded( $string ) { |
|
713 | - $string = rawurldecode( $string ); |
|
714 | - if( yourls_is_rawurlencoded( $string ) ) { |
|
715 | - $string = yourls_rawurldecode_while_encoded( $string ); |
|
712 | +function yourls_rawurldecode_while_encoded($string) { |
|
713 | + $string = rawurldecode($string); |
|
714 | + if (yourls_is_rawurlencoded($string)) { |
|
715 | + $string = yourls_rawurldecode_while_encoded($string); |
|
716 | 716 | } |
717 | 717 | return $string; |
718 | 718 | } |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | * @param string $code Javascript code |
727 | 727 | * @return string Bookmarklet link |
728 | 728 | */ |
729 | -function yourls_make_bookmarklet( $code ) { |
|
729 | +function yourls_make_bookmarklet($code) { |
|
730 | 730 | $book = new \Ozh\Bookmarkletgen\Bookmarkletgen; |
731 | - return $book->crunch( $code ); |
|
731 | + return $book->crunch($code); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | /** |
@@ -738,11 +738,11 @@ discard block |
||
738 | 738 | * @param string|int $timestamp a timestamp |
739 | 739 | * @return int a timestamp, plus or minus offset if defined |
740 | 740 | */ |
741 | -function yourls_get_timestamp( $timestamp ) { |
|
741 | +function yourls_get_timestamp($timestamp) { |
|
742 | 742 | $offset = yourls_get_time_offset(); |
743 | 743 | $timestamp_offset = $timestamp + ($offset * 3600); |
744 | 744 | |
745 | - return yourls_apply_filter( 'get_timestamp', $timestamp_offset, $timestamp, $offset ); |
|
745 | + return yourls_apply_filter('get_timestamp', $timestamp_offset, $timestamp, $offset); |
|
746 | 746 | } |
747 | 747 | |
748 | 748 | /** |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | * @return int Time offset |
753 | 753 | */ |
754 | 754 | function yourls_get_time_offset() { |
755 | - $offset = defined('YOURLS_HOURS_OFFSET') ? (int)YOURLS_HOURS_OFFSET : 0; |
|
756 | - return yourls_apply_filter( 'get_time_offset', $offset ); |
|
755 | + $offset = defined('YOURLS_HOURS_OFFSET') ? (int) YOURLS_HOURS_OFFSET : 0; |
|
756 | + return yourls_apply_filter('get_time_offset', $offset); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | /** |
@@ -763,8 +763,8 @@ discard block |
||
763 | 763 | * @param string $format Date format string |
764 | 764 | * @return string Date format string |
765 | 765 | */ |
766 | -function yourls_get_datetime_format( $format ) { |
|
767 | - return yourls_apply_filter( 'get_datetime_format', (string)$format ); |
|
766 | +function yourls_get_datetime_format($format) { |
|
767 | + return yourls_apply_filter('get_datetime_format', (string) $format); |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | /** |
@@ -774,8 +774,8 @@ discard block |
||
774 | 774 | * @param string $format Date format string |
775 | 775 | * @return string Date format string |
776 | 776 | */ |
777 | -function yourls_get_date_format( $format ) { |
|
778 | - return yourls_apply_filter( 'get_date_format', (string)$format ); |
|
777 | +function yourls_get_date_format($format) { |
|
778 | + return yourls_apply_filter('get_date_format', (string) $format); |
|
779 | 779 | } |
780 | 780 | |
781 | 781 | /** |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | * @param string $format Date format string |
786 | 786 | * @return string Date format string |
787 | 787 | */ |
788 | -function yourls_get_time_format( $format ) { |
|
789 | - return yourls_apply_filter( 'get_time_format', (string)$format ); |
|
788 | +function yourls_get_time_format($format) { |
|
789 | + return yourls_apply_filter('get_time_format', (string) $format); |
|
790 | 790 | } |
791 | 791 |
@@ -25,124 +25,124 @@ discard block |
||
25 | 25 | * @param string $title option title |
26 | 26 | * @return array array with error/success state and short URL information |
27 | 27 | */ |
28 | -function yourls_add_new_link( $url, $keyword = '', $title = '' ) { |
|
28 | +function yourls_add_new_link($url, $keyword = '', $title = '') { |
|
29 | 29 | // Allow plugins to short-circuit the whole function |
30 | - $pre = yourls_apply_filter( 'shunt_add_new_link', false, $url, $keyword, $title ); |
|
31 | - if ( false !== $pre ) |
|
30 | + $pre = yourls_apply_filter('shunt_add_new_link', false, $url, $keyword, $title); |
|
31 | + if (false !== $pre) |
|
32 | 32 | return $pre; |
33 | 33 | |
34 | - $url = yourls_sanitize_url( $url ); |
|
35 | - if ( !$url || $url == 'http://' || $url == 'https://' ) { |
|
34 | + $url = yourls_sanitize_url($url); |
|
35 | + if (!$url || $url == 'http://' || $url == 'https://') { |
|
36 | 36 | $return['status'] = 'fail'; |
37 | 37 | $return['code'] = 'error:nourl'; |
38 | - $return['message'] = yourls__( 'Missing or malformed URL' ); |
|
38 | + $return['message'] = yourls__('Missing or malformed URL'); |
|
39 | 39 | $return['errorCode'] = '400'; |
40 | - return yourls_apply_filter( 'add_new_link_fail_nourl', $return, $url, $keyword, $title ); |
|
40 | + return yourls_apply_filter('add_new_link_fail_nourl', $return, $url, $keyword, $title); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | // Prevent DB flood |
44 | 44 | $ip = yourls_get_IP(); |
45 | - yourls_check_IP_flood( $ip ); |
|
45 | + yourls_check_IP_flood($ip); |
|
46 | 46 | |
47 | 47 | // Prevent internal redirection loops: cannot shorten a shortened URL |
48 | - if( yourls_get_relative_url( $url ) ) { |
|
49 | - if( yourls_is_shorturl( $url ) ) { |
|
48 | + if (yourls_get_relative_url($url)) { |
|
49 | + if (yourls_is_shorturl($url)) { |
|
50 | 50 | $return['status'] = 'fail'; |
51 | 51 | $return['code'] = 'error:noloop'; |
52 | - $return['message'] = yourls__( 'URL is a short URL' ); |
|
52 | + $return['message'] = yourls__('URL is a short URL'); |
|
53 | 53 | $return['errorCode'] = '400'; |
54 | - return yourls_apply_filter( 'add_new_link_fail_noloop', $return, $url, $keyword, $title ); |
|
54 | + return yourls_apply_filter('add_new_link_fail_noloop', $return, $url, $keyword, $title); |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | |
58 | - yourls_do_action( 'pre_add_new_link', $url, $keyword, $title ); |
|
58 | + yourls_do_action('pre_add_new_link', $url, $keyword, $title); |
|
59 | 59 | |
60 | 60 | $return = array(); |
61 | 61 | |
62 | 62 | // duplicates allowed or new URL => store it |
63 | - if( yourls_allow_duplicate_longurls() || !( $url_exists = yourls_long_url_exists( $url ) ) ) { |
|
63 | + if (yourls_allow_duplicate_longurls() || !($url_exists = yourls_long_url_exists($url))) { |
|
64 | 64 | |
65 | - if( isset( $title ) && !empty( $title ) ) { |
|
66 | - $title = yourls_sanitize_title( $title ); |
|
65 | + if (isset($title) && !empty($title)) { |
|
66 | + $title = yourls_sanitize_title($title); |
|
67 | 67 | } else { |
68 | - $title = yourls_get_remote_title( $url ); |
|
68 | + $title = yourls_get_remote_title($url); |
|
69 | 69 | } |
70 | - $title = yourls_apply_filter( 'add_new_title', $title, $url, $keyword ); |
|
70 | + $title = yourls_apply_filter('add_new_title', $title, $url, $keyword); |
|
71 | 71 | |
72 | 72 | // Custom keyword provided |
73 | - if ( $keyword ) { |
|
73 | + if ($keyword) { |
|
74 | 74 | |
75 | - yourls_do_action( 'add_new_link_custom_keyword', $url, $keyword, $title ); |
|
75 | + yourls_do_action('add_new_link_custom_keyword', $url, $keyword, $title); |
|
76 | 76 | |
77 | - $keyword = yourls_sanitize_keyword( $keyword, true ); |
|
78 | - $keyword = yourls_apply_filter( 'custom_keyword', $keyword, $url, $title ); |
|
77 | + $keyword = yourls_sanitize_keyword($keyword, true); |
|
78 | + $keyword = yourls_apply_filter('custom_keyword', $keyword, $url, $title); |
|
79 | 79 | |
80 | - if ( !yourls_keyword_is_free( $keyword ) ) { |
|
80 | + if (!yourls_keyword_is_free($keyword)) { |
|
81 | 81 | // This shorturl either reserved or taken already |
82 | 82 | $return['status'] = 'fail'; |
83 | 83 | $return['code'] = 'error:keyword'; |
84 | - $return['message'] = yourls_s( 'Short URL %s already exists in database or is reserved', $keyword ); |
|
84 | + $return['message'] = yourls_s('Short URL %s already exists in database or is reserved', $keyword); |
|
85 | 85 | } else { |
86 | 86 | // all clear, store ! |
87 | - yourls_insert_link_in_db( $url, $keyword, $title ); |
|
88 | - $return['url'] = array('keyword' => $keyword, 'url' => $url, 'title' => $title, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip ); |
|
87 | + yourls_insert_link_in_db($url, $keyword, $title); |
|
88 | + $return['url'] = array('keyword' => $keyword, 'url' => $url, 'title' => $title, 'date' => date('Y-m-d H:i:s'), 'ip' => $ip); |
|
89 | 89 | $return['status'] = 'success'; |
90 | - $return['message'] = /* //translators: eg "http://someurl/ added to DB" */ yourls_s( '%s added to database', yourls_trim_long_string( $url ) ); |
|
90 | + $return['message'] = /* //translators: eg "http://someurl/ added to DB" */ yourls_s('%s added to database', yourls_trim_long_string($url)); |
|
91 | 91 | $return['title'] = $title; |
92 | - $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); |
|
92 | + $return['html'] = yourls_table_add_row($keyword, $url, $title, $ip, 0, time()); |
|
93 | 93 | $return['shorturl'] = yourls_link($keyword); |
94 | 94 | } |
95 | 95 | |
96 | 96 | // Create random keyword |
97 | 97 | } else { |
98 | 98 | |
99 | - yourls_do_action( 'add_new_link_create_keyword', $url, $keyword, $title ); |
|
99 | + yourls_do_action('add_new_link_create_keyword', $url, $keyword, $title); |
|
100 | 100 | |
101 | - $timestamp = date( 'Y-m-d H:i:s' ); |
|
101 | + $timestamp = date('Y-m-d H:i:s'); |
|
102 | 102 | $id = yourls_get_next_decimal(); |
103 | 103 | $ok = false; |
104 | 104 | do { |
105 | - $keyword = yourls_int2string( $id ); |
|
106 | - $keyword = yourls_apply_filter( 'random_keyword', $keyword, $url, $title ); |
|
107 | - if ( yourls_keyword_is_free($keyword) ) { |
|
108 | - if (yourls_insert_link_in_db( $url, $keyword, $title )){ |
|
105 | + $keyword = yourls_int2string($id); |
|
106 | + $keyword = yourls_apply_filter('random_keyword', $keyword, $url, $title); |
|
107 | + if (yourls_keyword_is_free($keyword)) { |
|
108 | + if (yourls_insert_link_in_db($url, $keyword, $title)) { |
|
109 | 109 | // everything ok, populate needed vars |
110 | - $return['url'] = array('keyword' => $keyword, 'url' => $url, 'title' => $title, 'date' => $timestamp, 'ip' => $ip ); |
|
110 | + $return['url'] = array('keyword' => $keyword, 'url' => $url, 'title' => $title, 'date' => $timestamp, 'ip' => $ip); |
|
111 | 111 | $return['status'] = 'success'; |
112 | - $return['message'] = /* //translators: eg "http://someurl/ added to DB" */ yourls_s( '%s added to database', yourls_trim_long_string( $url ) ); |
|
112 | + $return['message'] = /* //translators: eg "http://someurl/ added to DB" */ yourls_s('%s added to database', yourls_trim_long_string($url)); |
|
113 | 113 | $return['title'] = $title; |
114 | - $return['html'] = yourls_table_add_row( $keyword, $url, $title, $ip, 0, time() ); |
|
114 | + $return['html'] = yourls_table_add_row($keyword, $url, $title, $ip, 0, time()); |
|
115 | 115 | $return['shorturl'] = yourls_link($keyword); |
116 | 116 | } else { |
117 | 117 | // database error, couldnt store result |
118 | 118 | $return['status'] = 'fail'; |
119 | 119 | $return['code'] = 'error:db'; |
120 | - $return['message'] = yourls_s( 'Error saving url to database' ); |
|
120 | + $return['message'] = yourls_s('Error saving url to database'); |
|
121 | 121 | } |
122 | 122 | $ok = true; |
123 | 123 | } |
124 | 124 | $id++; |
125 | - } while ( !$ok ); |
|
126 | - @yourls_update_next_decimal( $id ); |
|
125 | + } while (!$ok); |
|
126 | + @yourls_update_next_decimal($id); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | // URL was already stored |
130 | 130 | } else { |
131 | 131 | |
132 | - yourls_do_action( 'add_new_link_already_stored', $url, $keyword, $title ); |
|
132 | + yourls_do_action('add_new_link_already_stored', $url, $keyword, $title); |
|
133 | 133 | |
134 | 134 | $return['status'] = 'fail'; |
135 | 135 | $return['code'] = 'error:url'; |
136 | - $return['url'] = array( 'keyword' => $url_exists->keyword, 'url' => $url, 'title' => $url_exists->title, 'date' => $url_exists->timestamp, 'ip' => $url_exists->ip, 'clicks' => $url_exists->clicks ); |
|
137 | - $return['message'] = /* //translators: eg "http://someurl/ already exists" */ yourls_s( '%s already exists in database', yourls_trim_long_string( $url ) ); |
|
136 | + $return['url'] = array('keyword' => $url_exists->keyword, 'url' => $url, 'title' => $url_exists->title, 'date' => $url_exists->timestamp, 'ip' => $url_exists->ip, 'clicks' => $url_exists->clicks); |
|
137 | + $return['message'] = /* //translators: eg "http://someurl/ already exists" */ yourls_s('%s already exists in database', yourls_trim_long_string($url)); |
|
138 | 138 | $return['title'] = $url_exists->title; |
139 | 139 | $return['shorturl'] = yourls_link($url_exists->keyword); |
140 | 140 | } |
141 | 141 | |
142 | - yourls_do_action( 'post_add_new_link', $url, $keyword, $title, $return ); |
|
142 | + yourls_do_action('post_add_new_link', $url, $keyword, $title, $return); |
|
143 | 143 | |
144 | 144 | $return['statusCode'] = 200; // regardless of result, this is still a valid request |
145 | - return yourls_apply_filter( 'add_new_link', $return, $url, $keyword, $title ); |
|
145 | + return yourls_apply_filter('add_new_link', $return, $url, $keyword, $title); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | function yourls_get_shorturl_charset() { |
154 | 154 | static $charset = null; |
155 | - if ( $charset !== null ) { |
|
155 | + if ($charset !== null) { |
|
156 | 156 | return $charset; |
157 | 157 | } |
158 | 158 | |
159 | - if ( defined( 'YOURLS_URL_CONVERT' ) && in_array( YOURLS_URL_CONVERT, [ 62, 64 ] ) ) { |
|
159 | + if (defined('YOURLS_URL_CONVERT') && in_array(YOURLS_URL_CONVERT, [62, 64])) { |
|
160 | 160 | $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
161 | 161 | } |
162 | 162 | else { |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $charset = '0123456789abcdefghijklmnopqrstuvwxyz'; |
165 | 165 | } |
166 | 166 | |
167 | - return yourls_apply_filter( 'get_shorturl_charset', $charset ); |
|
167 | + return yourls_apply_filter('get_shorturl_charset', $charset); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,24 +173,24 @@ discard block |
||
173 | 173 | * @param string $shorturl short URL |
174 | 174 | * @return bool true if registered short URL, false otherwise |
175 | 175 | */ |
176 | -function yourls_is_shorturl( $shorturl ) { |
|
176 | +function yourls_is_shorturl($shorturl) { |
|
177 | 177 | // TODO: make sure this function evolves with the feature set. |
178 | 178 | |
179 | 179 | $is_short = false; |
180 | 180 | |
181 | 181 | // Is $shorturl a URL (http://sho.rt/abc) or a keyword (abc) ? |
182 | - if( yourls_get_protocol( $shorturl ) ) { |
|
183 | - $keyword = yourls_get_relative_url( $shorturl ); |
|
182 | + if (yourls_get_protocol($shorturl)) { |
|
183 | + $keyword = yourls_get_relative_url($shorturl); |
|
184 | 184 | } else { |
185 | 185 | $keyword = $shorturl; |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Check if it's a valid && used keyword |
189 | - if( $keyword && $keyword == yourls_sanitize_keyword( $keyword ) && yourls_keyword_is_taken( $keyword ) ) { |
|
189 | + if ($keyword && $keyword == yourls_sanitize_keyword($keyword) && yourls_keyword_is_taken($keyword)) { |
|
190 | 190 | $is_short = true; |
191 | 191 | } |
192 | 192 | |
193 | - return yourls_apply_filter( 'is_shorturl', $is_short, $shorturl ); |
|
193 | + return yourls_apply_filter('is_shorturl', $is_short, $shorturl); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
@@ -199,28 +199,28 @@ discard block |
||
199 | 199 | * @param string $keyword Short URL keyword |
200 | 200 | * @return bool True if keyword reserved, false if free to be used |
201 | 201 | */ |
202 | -function yourls_keyword_is_reserved( $keyword ) { |
|
202 | +function yourls_keyword_is_reserved($keyword) { |
|
203 | 203 | global $yourls_reserved_URL; |
204 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
204 | + $keyword = yourls_sanitize_keyword($keyword); |
|
205 | 205 | $reserved = false; |
206 | 206 | |
207 | - if ( in_array( $keyword, $yourls_reserved_URL) |
|
207 | + if (in_array($keyword, $yourls_reserved_URL) |
|
208 | 208 | or yourls_is_page($keyword) |
209 | - or is_dir( YOURLS_ABSPATH ."/$keyword" ) |
|
209 | + or is_dir(YOURLS_ABSPATH."/$keyword") |
|
210 | 210 | ) |
211 | 211 | $reserved = true; |
212 | 212 | |
213 | - return yourls_apply_filter( 'keyword_is_reserved', $reserved, $keyword ); |
|
213 | + return yourls_apply_filter('keyword_is_reserved', $reserved, $keyword); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | /** |
217 | 217 | * Delete a link in the DB |
218 | 218 | * |
219 | 219 | */ |
220 | -function yourls_delete_link_by_keyword( $keyword ) { |
|
220 | +function yourls_delete_link_by_keyword($keyword) { |
|
221 | 221 | // Allow plugins to short-circuit the whole function |
222 | - $pre = yourls_apply_filter( 'shunt_delete_link_by_keyword', null, $keyword ); |
|
223 | - if ( null !== $pre ) |
|
222 | + $pre = yourls_apply_filter('shunt_delete_link_by_keyword', null, $keyword); |
|
223 | + if (null !== $pre) |
|
224 | 224 | return $pre; |
225 | 225 | |
226 | 226 | global $ydb; |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $table = YOURLS_DB_TABLE_URL; |
229 | 229 | $keyword = yourls_sanitize_keyword($keyword); |
230 | 230 | $delete = $ydb->fetchAffected("DELETE FROM `$table` WHERE `keyword` = :keyword", array('keyword' => $keyword)); |
231 | - yourls_do_action( 'delete_link', $keyword, $delete ); |
|
231 | + yourls_do_action('delete_link', $keyword, $delete); |
|
232 | 232 | return $delete; |
233 | 233 | } |
234 | 234 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * SQL query to insert a new link in the DB. Returns boolean for success or failure of the inserting |
237 | 237 | * |
238 | 238 | */ |
239 | -function yourls_insert_link_in_db( $url, $keyword, $title = '' ) { |
|
239 | +function yourls_insert_link_in_db($url, $keyword, $title = '') { |
|
240 | 240 | global $ydb; |
241 | 241 | |
242 | 242 | $url = yourls_sanitize_url($url); |
@@ -255,9 +255,9 @@ discard block |
||
255 | 255 | ); |
256 | 256 | $insert = $ydb->fetchAffected("INSERT INTO `$table` (`keyword`, `url`, `title`, `timestamp`, `ip`, `clicks`) VALUES(:keyword, :url, :title, :timestamp, :ip, 0);", $binds); |
257 | 257 | |
258 | - yourls_do_action( 'insert_link', (bool)$insert, $url, $keyword, $title, $timestamp, $ip ); |
|
258 | + yourls_do_action('insert_link', (bool) $insert, $url, $keyword, $title, $timestamp, $ip); |
|
259 | 259 | |
260 | - return (bool)$insert; |
|
260 | + return (bool) $insert; |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | /** |
@@ -269,10 +269,10 @@ discard block |
||
269 | 269 | * @param string $url URL to check if already shortened |
270 | 270 | * @return mixed NULL if does not already exist in DB, or object with URL information as properties (eg keyword, url, title, ...) |
271 | 271 | */ |
272 | -function yourls_long_url_exists( $url ) { |
|
272 | +function yourls_long_url_exists($url) { |
|
273 | 273 | // Allow plugins to short-circuit the whole function |
274 | - $pre = yourls_apply_filter( 'shunt_url_exists', false, $url ); |
|
275 | - if ( false !== $pre ) |
|
274 | + $pre = yourls_apply_filter('shunt_url_exists', false, $url); |
|
275 | + if (false !== $pre) |
|
276 | 276 | return $pre; |
277 | 277 | |
278 | 278 | global $ydb; |
@@ -284,17 +284,17 @@ discard block |
||
284 | 284 | $url_exists = NULL; |
285 | 285 | } |
286 | 286 | |
287 | - return yourls_apply_filter( 'url_exists', $url_exists, $url ); |
|
287 | + return yourls_apply_filter('url_exists', $url_exists, $url); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
291 | 291 | * Edit a link |
292 | 292 | * |
293 | 293 | */ |
294 | -function yourls_edit_link( $url, $keyword, $newkeyword='', $title='' ) { |
|
294 | +function yourls_edit_link($url, $keyword, $newkeyword = '', $title = '') { |
|
295 | 295 | // Allow plugins to short-circuit the whole function |
296 | - $pre = yourls_apply_filter( 'shunt_edit_link', null, $keyword, $url, $keyword, $newkeyword, $title ); |
|
297 | - if ( null !== $pre ) |
|
296 | + $pre = yourls_apply_filter('shunt_edit_link', null, $keyword, $url, $keyword, $newkeyword, $title); |
|
297 | + if (null !== $pre) |
|
298 | 298 | return $pre; |
299 | 299 | |
300 | 300 | global $ydb; |
@@ -304,70 +304,70 @@ discard block |
||
304 | 304 | $keyword = yourls_sanitize_keyword($keyword); |
305 | 305 | $title = yourls_sanitize_title($title); |
306 | 306 | $newkeyword = yourls_sanitize_keyword($newkeyword, true); |
307 | - $strip_url = stripslashes( $url ); |
|
308 | - $strip_title = stripslashes( $title ); |
|
307 | + $strip_url = stripslashes($url); |
|
308 | + $strip_title = stripslashes($title); |
|
309 | 309 | |
310 | - if(!$url OR !$newkeyword) { |
|
310 | + if (!$url OR !$newkeyword) { |
|
311 | 311 | $return['status'] = 'fail'; |
312 | - $return['message'] = yourls__( 'Long URL or Short URL cannot be blank' ); |
|
313 | - return yourls_apply_filter( 'edit_link', $return, $url, $keyword, $newkeyword, $title ); |
|
312 | + $return['message'] = yourls__('Long URL or Short URL cannot be blank'); |
|
313 | + return yourls_apply_filter('edit_link', $return, $url, $keyword, $newkeyword, $title); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | $old_url = $ydb->fetchValue("SELECT `url` FROM `$table` WHERE `keyword` = :keyword", array('keyword' => $keyword)); |
317 | 317 | |
318 | 318 | // Check if new URL is not here already |
319 | - if ( $old_url != $url && !yourls_allow_duplicate_longurls() ) { |
|
319 | + if ($old_url != $url && !yourls_allow_duplicate_longurls()) { |
|
320 | 320 | $new_url_already_there = intval($ydb->fetchValue("SELECT COUNT(keyword) FROM `$table` WHERE `url` = :url;", array('url' => $url))); |
321 | 321 | } else { |
322 | 322 | $new_url_already_there = false; |
323 | 323 | } |
324 | 324 | |
325 | 325 | // Check if the new keyword is not here already |
326 | - if ( $newkeyword != $keyword ) { |
|
327 | - $keyword_is_ok = yourls_keyword_is_free( $newkeyword ); |
|
326 | + if ($newkeyword != $keyword) { |
|
327 | + $keyword_is_ok = yourls_keyword_is_free($newkeyword); |
|
328 | 328 | } else { |
329 | 329 | $keyword_is_ok = true; |
330 | 330 | } |
331 | 331 | |
332 | - yourls_do_action( 'pre_edit_link', $url, $keyword, $newkeyword, $new_url_already_there, $keyword_is_ok ); |
|
332 | + yourls_do_action('pre_edit_link', $url, $keyword, $newkeyword, $new_url_already_there, $keyword_is_ok); |
|
333 | 333 | |
334 | 334 | // All clear, update |
335 | - if ( ( !$new_url_already_there || yourls_allow_duplicate_longurls() ) && $keyword_is_ok ) { |
|
335 | + if ((!$new_url_already_there || yourls_allow_duplicate_longurls()) && $keyword_is_ok) { |
|
336 | 336 | $sql = "UPDATE `$table` SET `url` = :url, `keyword` = :newkeyword, `title` = :title WHERE `keyword` = :keyword"; |
337 | 337 | $binds = array('url' => $url, 'newkeyword' => $newkeyword, 'title' => $title, 'keyword' => $keyword); |
338 | 338 | $update_url = $ydb->fetchAffected($sql, $binds); |
339 | - if( $update_url ) { |
|
340 | - $return['url'] = array( 'keyword' => $newkeyword, 'shorturl' => yourls_link($newkeyword), 'url' => $strip_url, 'display_url' => yourls_trim_long_string( $strip_url ), 'title' => $strip_title, 'display_title' => yourls_trim_long_string( $strip_title ) ); |
|
339 | + if ($update_url) { |
|
340 | + $return['url'] = array('keyword' => $newkeyword, 'shorturl' => yourls_link($newkeyword), 'url' => $strip_url, 'display_url' => yourls_trim_long_string($strip_url), 'title' => $strip_title, 'display_title' => yourls_trim_long_string($strip_title)); |
|
341 | 341 | $return['status'] = 'success'; |
342 | - $return['message'] = yourls__( 'Link updated in database' ); |
|
342 | + $return['message'] = yourls__('Link updated in database'); |
|
343 | 343 | } else { |
344 | 344 | $return['status'] = 'fail'; |
345 | - $return['message'] = /* //translators: "Error updating http://someurl/ (Shorturl: http://sho.rt/blah)" */ yourls_s( 'Error updating %s (Short URL: %s)', yourls_trim_long_string( $strip_url ), $keyword ) ; |
|
345 | + $return['message'] = /* //translators: "Error updating http://someurl/ (Shorturl: http://sho.rt/blah)" */ yourls_s('Error updating %s (Short URL: %s)', yourls_trim_long_string($strip_url), $keyword); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | // Nope |
349 | 349 | } else { |
350 | 350 | $return['status'] = 'fail'; |
351 | - $return['message'] = yourls__( 'URL or keyword already exists in database' ); |
|
351 | + $return['message'] = yourls__('URL or keyword already exists in database'); |
|
352 | 352 | } |
353 | 353 | |
354 | - return yourls_apply_filter( 'edit_link', $return, $url, $keyword, $newkeyword, $title, $new_url_already_there, $keyword_is_ok ); |
|
354 | + return yourls_apply_filter('edit_link', $return, $url, $keyword, $newkeyword, $title, $new_url_already_there, $keyword_is_ok); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
358 | 358 | * Update a title link (no checks for duplicates etc..) |
359 | 359 | * |
360 | 360 | */ |
361 | -function yourls_edit_link_title( $keyword, $title ) { |
|
361 | +function yourls_edit_link_title($keyword, $title) { |
|
362 | 362 | // Allow plugins to short-circuit the whole function |
363 | - $pre = yourls_apply_filter( 'shunt_edit_link_title', null, $keyword, $title ); |
|
364 | - if ( null !== $pre ) |
|
363 | + $pre = yourls_apply_filter('shunt_edit_link_title', null, $keyword, $title); |
|
364 | + if (null !== $pre) |
|
365 | 365 | return $pre; |
366 | 366 | |
367 | 367 | global $ydb; |
368 | 368 | |
369 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
370 | - $title = yourls_sanitize_title( $title ); |
|
369 | + $keyword = yourls_sanitize_keyword($keyword); |
|
370 | + $title = yourls_sanitize_title($title); |
|
371 | 371 | |
372 | 372 | $table = YOURLS_DB_TABLE_URL; |
373 | 373 | $update = $ydb->fetchAffected("UPDATE `$table` SET `title` = :title WHERE `keyword` = :keyword;", array('title' => $title, 'keyword' => $keyword)); |
@@ -381,13 +381,13 @@ discard block |
||
381 | 381 | * @param string $keyword short URL keyword |
382 | 382 | * @return bool true if keyword is taken (ie there is a short URL for it), false otherwise |
383 | 383 | */ |
384 | -function yourls_keyword_is_free( $keyword ) { |
|
384 | +function yourls_keyword_is_free($keyword) { |
|
385 | 385 | $free = true; |
386 | - if ( yourls_keyword_is_reserved( $keyword ) or yourls_keyword_is_taken( $keyword, false ) ) { |
|
386 | + if (yourls_keyword_is_reserved($keyword) or yourls_keyword_is_taken($keyword, false)) { |
|
387 | 387 | $free = false; |
388 | 388 | } |
389 | 389 | |
390 | - return yourls_apply_filter( 'keyword_is_free', $free, $keyword ); |
|
390 | + return yourls_apply_filter('keyword_is_free', $free, $keyword); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | /** |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * @return bool true if is page, false otherwise |
400 | 400 | */ |
401 | 401 | function yourls_is_page($keyword) { |
402 | - return yourls_apply_filter( 'is_page', file_exists( YOURLS_PAGEDIR . "/$keyword.php" ) ); |
|
402 | + return yourls_apply_filter('is_page', file_exists(YOURLS_PAGEDIR."/$keyword.php")); |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -413,11 +413,11 @@ discard block |
||
413 | 413 | * @param bool $use_cache optional, default true: do we want to use what is cached in memory, if any, or force a new SQL query |
414 | 414 | * @return bool true if keyword is taken (ie there is a short URL for it), false otherwise |
415 | 415 | */ |
416 | -function yourls_keyword_is_taken( $keyword, $use_cache = true ) { |
|
416 | +function yourls_keyword_is_taken($keyword, $use_cache = true) { |
|
417 | 417 | |
418 | 418 | // Allow plugins to short-circuit the whole function |
419 | - $pre = yourls_apply_filter( 'shunt_keyword_is_taken', false, $keyword ); |
|
420 | - if ( false !== $pre ) |
|
419 | + $pre = yourls_apply_filter('shunt_keyword_is_taken', false, $keyword); |
|
420 | + if (false !== $pre) |
|
421 | 421 | return $pre; |
422 | 422 | |
423 | 423 | global $ydb; |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | |
426 | 426 | // To check if a keyword is already associated with a short URL, we fetch all info matching that keyword. This |
427 | 427 | // will save a query in case of a redirection in yourls-go.php because info will be cached |
428 | - if ( yourls_get_keyword_infos($keyword, $use_cache) ) { |
|
428 | + if (yourls_get_keyword_infos($keyword, $use_cache)) { |
|
429 | 429 | $taken = true; |
430 | 430 | } |
431 | 431 | |
432 | - return yourls_apply_filter( 'keyword_is_taken', $taken, $keyword ); |
|
432 | + return yourls_apply_filter('keyword_is_taken', $taken, $keyword); |
|
433 | 433 | } |
434 | 434 | |
435 | 435 | /** |
@@ -444,23 +444,23 @@ discard block |
||
444 | 444 | * @param bool $use_cache Default true, set to false to force fetching from DB |
445 | 445 | * @return false|object false if not found, object with URL properties if found |
446 | 446 | */ |
447 | -function yourls_get_keyword_infos( $keyword, $use_cache = true ) { |
|
447 | +function yourls_get_keyword_infos($keyword, $use_cache = true) { |
|
448 | 448 | global $ydb; |
449 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
449 | + $keyword = yourls_sanitize_keyword($keyword); |
|
450 | 450 | |
451 | - yourls_do_action( 'pre_get_keyword', $keyword, $use_cache ); |
|
451 | + yourls_do_action('pre_get_keyword', $keyword, $use_cache); |
|
452 | 452 | |
453 | - if( $ydb->has_infos($keyword) && $use_cache === true ) { |
|
454 | - return yourls_apply_filter( 'get_keyword_infos', $ydb->get_infos($keyword), $keyword ); |
|
453 | + if ($ydb->has_infos($keyword) && $use_cache === true) { |
|
454 | + return yourls_apply_filter('get_keyword_infos', $ydb->get_infos($keyword), $keyword); |
|
455 | 455 | } |
456 | 456 | |
457 | - yourls_do_action( 'get_keyword_not_cached', $keyword ); |
|
457 | + yourls_do_action('get_keyword_not_cached', $keyword); |
|
458 | 458 | |
459 | 459 | $table = YOURLS_DB_TABLE_URL; |
460 | 460 | $infos = $ydb->fetchObject("SELECT * FROM `$table` WHERE `keyword` = :keyword", array('keyword' => $keyword)); |
461 | 461 | |
462 | - if( $infos ) { |
|
463 | - $infos = (array)$infos; |
|
462 | + if ($infos) { |
|
463 | + $infos = (array) $infos; |
|
464 | 464 | $ydb->set_infos($keyword, $infos); |
465 | 465 | } else { |
466 | 466 | // is NULL if not found |
@@ -468,68 +468,68 @@ discard block |
||
468 | 468 | $ydb->set_infos($keyword, false); |
469 | 469 | } |
470 | 470 | |
471 | - return yourls_apply_filter( 'get_keyword_infos', $infos, $keyword ); |
|
471 | + return yourls_apply_filter('get_keyword_infos', $infos, $keyword); |
|
472 | 472 | } |
473 | 473 | |
474 | 474 | /** |
475 | 475 | * Return (string) selected information associated with a keyword. Optional $notfound = string default message if nothing found |
476 | 476 | * |
477 | 477 | */ |
478 | -function yourls_get_keyword_info( $keyword, $field, $notfound = false ) { |
|
478 | +function yourls_get_keyword_info($keyword, $field, $notfound = false) { |
|
479 | 479 | |
480 | 480 | // Allow plugins to short-circuit the whole function |
481 | - $pre = yourls_apply_filter( 'shunt_get_keyword_info', false, $keyword, $field, $notfound ); |
|
482 | - if ( false !== $pre ) |
|
481 | + $pre = yourls_apply_filter('shunt_get_keyword_info', false, $keyword, $field, $notfound); |
|
482 | + if (false !== $pre) |
|
483 | 483 | return $pre; |
484 | 484 | |
485 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
486 | - $infos = yourls_get_keyword_infos( $keyword ); |
|
485 | + $keyword = yourls_sanitize_keyword($keyword); |
|
486 | + $infos = yourls_get_keyword_infos($keyword); |
|
487 | 487 | |
488 | 488 | $return = $notfound; |
489 | - if ( isset( $infos[ $field ] ) && $infos[ $field ] !== false ) |
|
490 | - $return = $infos[ $field ]; |
|
489 | + if (isset($infos[$field]) && $infos[$field] !== false) |
|
490 | + $return = $infos[$field]; |
|
491 | 491 | |
492 | - return yourls_apply_filter( 'get_keyword_info', $return, $keyword, $field, $notfound ); |
|
492 | + return yourls_apply_filter('get_keyword_info', $return, $keyword, $field, $notfound); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
496 | 496 | * Return title associated with keyword. Optional $notfound = string default message if nothing found |
497 | 497 | * |
498 | 498 | */ |
499 | -function yourls_get_keyword_title( $keyword, $notfound = false ) { |
|
500 | - return yourls_get_keyword_info( $keyword, 'title', $notfound ); |
|
499 | +function yourls_get_keyword_title($keyword, $notfound = false) { |
|
500 | + return yourls_get_keyword_info($keyword, 'title', $notfound); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | /** |
504 | 504 | * Return long URL associated with keyword. Optional $notfound = string default message if nothing found |
505 | 505 | * |
506 | 506 | */ |
507 | -function yourls_get_keyword_longurl( $keyword, $notfound = false ) { |
|
508 | - return yourls_get_keyword_info( $keyword, 'url', $notfound ); |
|
507 | +function yourls_get_keyword_longurl($keyword, $notfound = false) { |
|
508 | + return yourls_get_keyword_info($keyword, 'url', $notfound); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
512 | 512 | * Return number of clicks on a keyword. Optional $notfound = string default message if nothing found |
513 | 513 | * |
514 | 514 | */ |
515 | -function yourls_get_keyword_clicks( $keyword, $notfound = false ) { |
|
516 | - return yourls_get_keyword_info( $keyword, 'clicks', $notfound ); |
|
515 | +function yourls_get_keyword_clicks($keyword, $notfound = false) { |
|
516 | + return yourls_get_keyword_info($keyword, 'clicks', $notfound); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
520 | 520 | * Return IP that added a keyword. Optional $notfound = string default message if nothing found |
521 | 521 | * |
522 | 522 | */ |
523 | -function yourls_get_keyword_IP( $keyword, $notfound = false ) { |
|
524 | - return yourls_get_keyword_info( $keyword, 'ip', $notfound ); |
|
523 | +function yourls_get_keyword_IP($keyword, $notfound = false) { |
|
524 | + return yourls_get_keyword_info($keyword, 'ip', $notfound); |
|
525 | 525 | } |
526 | 526 | |
527 | 527 | /** |
528 | 528 | * Return timestamp associated with a keyword. Optional $notfound = string default message if nothing found |
529 | 529 | * |
530 | 530 | */ |
531 | -function yourls_get_keyword_timestamp( $keyword, $notfound = false ) { |
|
532 | - return yourls_get_keyword_info( $keyword, 'timestamp', $notfound ); |
|
531 | +function yourls_get_keyword_timestamp($keyword, $notfound = false) { |
|
532 | + return yourls_get_keyword_info($keyword, 'timestamp', $notfound); |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -541,16 +541,16 @@ discard block |
||
541 | 541 | * @param string $shorturl short URL keyword |
542 | 542 | * @return array stats |
543 | 543 | */ |
544 | -function yourls_get_keyword_stats( $shorturl ) { |
|
544 | +function yourls_get_keyword_stats($shorturl) { |
|
545 | 545 | global $ydb; |
546 | 546 | |
547 | 547 | $table_url = YOURLS_DB_TABLE_URL; |
548 | - $shorturl = yourls_sanitize_keyword( $shorturl ); |
|
548 | + $shorturl = yourls_sanitize_keyword($shorturl); |
|
549 | 549 | |
550 | 550 | $res = $ydb->fetchObject("SELECT * FROM `$table_url` WHERE `keyword` = :keyword", array('keyword' => $shorturl)); |
551 | 551 | $return = array(); |
552 | 552 | |
553 | - if( !$res ) { |
|
553 | + if (!$res) { |
|
554 | 554 | // non existent link |
555 | 555 | $return = array( |
556 | 556 | 'statusCode' => 404, |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | ); |
572 | 572 | } |
573 | 573 | |
574 | - return yourls_apply_filter( 'get_link_stats', $return, $shorturl ); |
|
574 | + return yourls_apply_filter('get_link_stats', $return, $shorturl); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -582,15 +582,15 @@ discard block |
||
582 | 582 | * @param string $order Optional SORT order (can be 'ASC' or 'DESC') |
583 | 583 | * @return array array of keywords |
584 | 584 | */ |
585 | -function yourls_get_longurl_keywords( $longurl, $order = 'ASC' ) { |
|
585 | +function yourls_get_longurl_keywords($longurl, $order = 'ASC') { |
|
586 | 586 | global $ydb; |
587 | 587 | $longurl = yourls_sanitize_url($longurl); |
588 | 588 | $table = YOURLS_DB_TABLE_URL; |
589 | 589 | $sql = "SELECT `keyword` FROM `$table` WHERE `url` = :url"; |
590 | 590 | |
591 | - if (in_array($order, array('ASC','DESC'))) { |
|
591 | + if (in_array($order, array('ASC', 'DESC'))) { |
|
592 | 592 | $sql .= " ORDER BY `keyword` ".$order; |
593 | 593 | } |
594 | 594 | |
595 | - return yourls_apply_filter( 'get_longurl_keywords', $ydb->fetchCol($sql, array('url'=>$longurl)), $longurl ); |
|
595 | + return yourls_apply_filter('get_longurl_keywords', $ydb->fetchCol($sql, array('url'=>$longurl)), $longurl); |
|
596 | 596 | } |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | function yourls_add_new_link( $url, $keyword = '', $title = '' ) { |
29 | 29 | // Allow plugins to short-circuit the whole function |
30 | 30 | $pre = yourls_apply_filter( 'shunt_add_new_link', false, $url, $keyword, $title ); |
31 | - if ( false !== $pre ) |
|
32 | - return $pre; |
|
31 | + if ( false !== $pre ) { |
|
32 | + return $pre; |
|
33 | + } |
|
33 | 34 | |
34 | 35 | $url = yourls_sanitize_url( $url ); |
35 | 36 | if ( !$url || $url == 'http://' || $url == 'https://' ) { |
@@ -105,7 +106,7 @@ discard block |
||
105 | 106 | $keyword = yourls_int2string( $id ); |
106 | 107 | $keyword = yourls_apply_filter( 'random_keyword', $keyword, $url, $title ); |
107 | 108 | if ( yourls_keyword_is_free($keyword) ) { |
108 | - if (yourls_insert_link_in_db( $url, $keyword, $title )){ |
|
109 | + if (yourls_insert_link_in_db( $url, $keyword, $title )) { |
|
109 | 110 | // everything ok, populate needed vars |
110 | 111 | $return['url'] = array('keyword' => $keyword, 'url' => $url, 'title' => $title, 'date' => $timestamp, 'ip' => $ip ); |
111 | 112 | $return['status'] = 'success'; |
@@ -158,8 +159,7 @@ discard block |
||
158 | 159 | |
159 | 160 | if ( defined( 'YOURLS_URL_CONVERT' ) && in_array( YOURLS_URL_CONVERT, [ 62, 64 ] ) ) { |
160 | 161 | $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
161 | - } |
|
162 | - else { |
|
162 | + } else { |
|
163 | 163 | // defined to 36, or wrongly defined |
164 | 164 | $charset = '0123456789abcdefghijklmnopqrstuvwxyz'; |
165 | 165 | } |
@@ -207,8 +207,9 @@ discard block |
||
207 | 207 | if ( in_array( $keyword, $yourls_reserved_URL) |
208 | 208 | or yourls_is_page($keyword) |
209 | 209 | or is_dir( YOURLS_ABSPATH ."/$keyword" ) |
210 | - ) |
|
211 | - $reserved = true; |
|
210 | + ) { |
|
211 | + $reserved = true; |
|
212 | + } |
|
212 | 213 | |
213 | 214 | return yourls_apply_filter( 'keyword_is_reserved', $reserved, $keyword ); |
214 | 215 | } |
@@ -220,8 +221,9 @@ discard block |
||
220 | 221 | function yourls_delete_link_by_keyword( $keyword ) { |
221 | 222 | // Allow plugins to short-circuit the whole function |
222 | 223 | $pre = yourls_apply_filter( 'shunt_delete_link_by_keyword', null, $keyword ); |
223 | - if ( null !== $pre ) |
|
224 | - return $pre; |
|
224 | + if ( null !== $pre ) { |
|
225 | + return $pre; |
|
226 | + } |
|
225 | 227 | |
226 | 228 | global $ydb; |
227 | 229 | |
@@ -272,8 +274,9 @@ discard block |
||
272 | 274 | function yourls_long_url_exists( $url ) { |
273 | 275 | // Allow plugins to short-circuit the whole function |
274 | 276 | $pre = yourls_apply_filter( 'shunt_url_exists', false, $url ); |
275 | - if ( false !== $pre ) |
|
276 | - return $pre; |
|
277 | + if ( false !== $pre ) { |
|
278 | + return $pre; |
|
279 | + } |
|
277 | 280 | |
278 | 281 | global $ydb; |
279 | 282 | $table = YOURLS_DB_TABLE_URL; |
@@ -294,8 +297,9 @@ discard block |
||
294 | 297 | function yourls_edit_link( $url, $keyword, $newkeyword='', $title='' ) { |
295 | 298 | // Allow plugins to short-circuit the whole function |
296 | 299 | $pre = yourls_apply_filter( 'shunt_edit_link', null, $keyword, $url, $keyword, $newkeyword, $title ); |
297 | - if ( null !== $pre ) |
|
298 | - return $pre; |
|
300 | + if ( null !== $pre ) { |
|
301 | + return $pre; |
|
302 | + } |
|
299 | 303 | |
300 | 304 | global $ydb; |
301 | 305 | |
@@ -361,8 +365,9 @@ discard block |
||
361 | 365 | function yourls_edit_link_title( $keyword, $title ) { |
362 | 366 | // Allow plugins to short-circuit the whole function |
363 | 367 | $pre = yourls_apply_filter( 'shunt_edit_link_title', null, $keyword, $title ); |
364 | - if ( null !== $pre ) |
|
365 | - return $pre; |
|
368 | + if ( null !== $pre ) { |
|
369 | + return $pre; |
|
370 | + } |
|
366 | 371 | |
367 | 372 | global $ydb; |
368 | 373 | |
@@ -417,8 +422,9 @@ discard block |
||
417 | 422 | |
418 | 423 | // Allow plugins to short-circuit the whole function |
419 | 424 | $pre = yourls_apply_filter( 'shunt_keyword_is_taken', false, $keyword ); |
420 | - if ( false !== $pre ) |
|
421 | - return $pre; |
|
425 | + if ( false !== $pre ) { |
|
426 | + return $pre; |
|
427 | + } |
|
422 | 428 | |
423 | 429 | global $ydb; |
424 | 430 | $taken = false; |
@@ -479,15 +485,17 @@ discard block |
||
479 | 485 | |
480 | 486 | // Allow plugins to short-circuit the whole function |
481 | 487 | $pre = yourls_apply_filter( 'shunt_get_keyword_info', false, $keyword, $field, $notfound ); |
482 | - if ( false !== $pre ) |
|
483 | - return $pre; |
|
488 | + if ( false !== $pre ) { |
|
489 | + return $pre; |
|
490 | + } |
|
484 | 491 | |
485 | 492 | $keyword = yourls_sanitize_keyword( $keyword ); |
486 | 493 | $infos = yourls_get_keyword_infos( $keyword ); |
487 | 494 | |
488 | 495 | $return = $notfound; |
489 | - if ( isset( $infos[ $field ] ) && $infos[ $field ] !== false ) |
|
490 | - $return = $infos[ $field ]; |
|
496 | + if ( isset( $infos[ $field ] ) && $infos[ $field ] !== false ) { |
|
497 | + $return = $infos[ $field ]; |
|
498 | + } |
|
491 | 499 | |
492 | 500 | return yourls_apply_filter( 'get_keyword_info', $return, $keyword, $field, $notfound ); |
493 | 501 | } |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | * @return array Result of API call |
16 | 16 | */ |
17 | 17 | function yourls_api_action_shorturl() { |
18 | - $url = ( isset( $_REQUEST['url'] ) ? $_REQUEST['url'] : '' ); |
|
19 | - $keyword = ( isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ); |
|
20 | - $title = ( isset( $_REQUEST['title'] ) ? $_REQUEST['title'] : '' ); |
|
21 | - $return = yourls_add_new_link( $url, $keyword, $title ); |
|
22 | - $return['simple'] = ( isset( $return['shorturl'] ) ? $return['shorturl'] : '' ); // This one will be used in case output mode is 'simple' |
|
23 | - unset( $return['html'] ); // in API mode, no need for our internal HTML output |
|
24 | - return yourls_apply_filter( 'api_result_shorturl', $return ); |
|
18 | + $url = ( isset( $_REQUEST['url'] ) ? $_REQUEST['url'] : '' ); |
|
19 | + $keyword = ( isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ); |
|
20 | + $title = ( isset( $_REQUEST['title'] ) ? $_REQUEST['title'] : '' ); |
|
21 | + $return = yourls_add_new_link( $url, $keyword, $title ); |
|
22 | + $return['simple'] = ( isset( $return['shorturl'] ) ? $return['shorturl'] : '' ); // This one will be used in case output mode is 'simple' |
|
23 | + unset( $return['html'] ); // in API mode, no need for our internal HTML output |
|
24 | + return yourls_apply_filter( 'api_result_shorturl', $return ); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * @return array Result of API call |
32 | 32 | */ |
33 | 33 | function yourls_api_action_stats() { |
34 | - $filter = ( isset( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : '' ); |
|
35 | - $limit = ( isset( $_REQUEST['limit'] ) ? $_REQUEST['limit'] : '' ); |
|
36 | - $start = ( isset( $_REQUEST['start'] ) ? $_REQUEST['start'] : '' ); |
|
37 | - return yourls_apply_filter( 'api_result_stats', yourls_api_stats( $filter, $limit, $start ) ); |
|
34 | + $filter = ( isset( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : '' ); |
|
35 | + $limit = ( isset( $_REQUEST['limit'] ) ? $_REQUEST['limit'] : '' ); |
|
36 | + $start = ( isset( $_REQUEST['start'] ) ? $_REQUEST['start'] : '' ); |
|
37 | + return yourls_apply_filter( 'api_result_stats', yourls_api_stats( $filter, $limit, $start ) ); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return array Result of API call |
45 | 45 | */ |
46 | 46 | function yourls_api_action_db_stats() { |
47 | - return yourls_apply_filter( 'api_result_db_stats', yourls_api_db_stats() ); |
|
47 | + return yourls_apply_filter( 'api_result_db_stats', yourls_api_db_stats() ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @return array Result of API call |
55 | 55 | */ |
56 | 56 | function yourls_api_action_url_stats() { |
57 | - $shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' ); |
|
58 | - return yourls_apply_filter( 'api_result_url_stats', yourls_api_url_stats( $shorturl ) ); |
|
57 | + $shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' ); |
|
58 | + return yourls_apply_filter( 'api_result_url_stats', yourls_api_url_stats( $shorturl ) ); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return array Result of API call |
66 | 66 | */ |
67 | 67 | function yourls_api_action_expand() { |
68 | - $shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' ); |
|
69 | - return yourls_apply_filter( 'api_result_expand', yourls_api_expand( $shorturl ) ); |
|
68 | + $shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' ); |
|
69 | + return yourls_apply_filter( 'api_result_expand', yourls_api_expand( $shorturl ) ); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | * @return array Result of API call |
77 | 77 | */ |
78 | 78 | function yourls_api_action_version() { |
79 | - $return['version'] = $return['simple'] = YOURLS_VERSION; |
|
80 | - if( isset( $_REQUEST['db'] ) && $_REQUEST['db'] == 1 ) |
|
81 | - $return['db_version'] = YOURLS_DB_VERSION; |
|
82 | - return yourls_apply_filter( 'api_result_version', $return ); |
|
79 | + $return['version'] = $return['simple'] = YOURLS_VERSION; |
|
80 | + if( isset( $_REQUEST['db'] ) && $_REQUEST['db'] == 1 ) |
|
81 | + $return['db_version'] = YOURLS_DB_VERSION; |
|
82 | + return yourls_apply_filter( 'api_result_version', $return ); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | * @return string API output, as an XML / JSON / JSONP / raw text string |
100 | 100 | */ |
101 | 101 | function yourls_api_output( $mode, $output, $send_headers = true, $echo = true ) { |
102 | - if( isset( $output['simple'] ) ) { |
|
103 | - $simple = $output['simple']; |
|
104 | - unset( $output['simple'] ); |
|
105 | - } |
|
102 | + if( isset( $output['simple'] ) ) { |
|
103 | + $simple = $output['simple']; |
|
104 | + unset( $output['simple'] ); |
|
105 | + } |
|
106 | 106 | |
107 | - yourls_do_action( 'pre_api_output', $mode, $output, $send_headers, $echo ); |
|
107 | + yourls_do_action( 'pre_api_output', $mode, $output, $send_headers, $echo ); |
|
108 | 108 | |
109 | 109 | if( $send_headers ) { |
110 | 110 | if( isset( $output['statusCode'] ) ) { |
@@ -119,43 +119,43 @@ discard block |
||
119 | 119 | |
120 | 120 | $result = ''; |
121 | 121 | |
122 | - switch ( $mode ) { |
|
123 | - case 'jsonp': |
|
122 | + switch ( $mode ) { |
|
123 | + case 'jsonp': |
|
124 | 124 | if( $send_headers ) |
125 | 125 | yourls_content_type_header( 'application/javascript' ); |
126 | 126 | |
127 | 127 | $callback = isset( $output['callback'] ) ? $output['callback'] : ''; |
128 | - $result = $callback . '(' . json_encode( $output ) . ')'; |
|
129 | - break; |
|
128 | + $result = $callback . '(' . json_encode( $output ) . ')'; |
|
129 | + break; |
|
130 | 130 | |
131 | - case 'json': |
|
131 | + case 'json': |
|
132 | 132 | if( $send_headers ) |
133 | 133 | yourls_content_type_header( 'application/json' ); |
134 | 134 | |
135 | - $result = json_encode( $output ); |
|
136 | - break; |
|
135 | + $result = json_encode( $output ); |
|
136 | + break; |
|
137 | 137 | |
138 | - case 'xml': |
|
138 | + case 'xml': |
|
139 | 139 | if( $send_headers ) |
140 | 140 | yourls_content_type_header( 'application/xml' ); |
141 | 141 | |
142 | - $result = yourls_xml_encode( $output ); |
|
143 | - break; |
|
142 | + $result = yourls_xml_encode( $output ); |
|
143 | + break; |
|
144 | 144 | |
145 | - case 'simple': |
|
146 | - default: |
|
145 | + case 'simple': |
|
146 | + default: |
|
147 | 147 | if( $send_headers ) |
148 | 148 | yourls_content_type_header( 'text/plain' ); |
149 | 149 | |
150 | - $result = isset( $simple ) ? $simple : ''; |
|
151 | - break; |
|
152 | - } |
|
150 | + $result = isset( $simple ) ? $simple : ''; |
|
151 | + break; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | if( $echo ) { |
155 | 155 | echo $result; |
156 | 156 | } |
157 | 157 | |
158 | - yourls_do_action( 'api_output', $mode, $output, $send_headers, $echo ); |
|
158 | + yourls_do_action( 'api_output', $mode, $output, $send_headers, $echo ); |
|
159 | 159 | |
160 | 160 | return $result; |
161 | 161 | } |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | * |
166 | 166 | */ |
167 | 167 | function yourls_api_stats( $filter = 'top', $limit = 10, $start = 0 ) { |
168 | - $return = yourls_get_stats( $filter, $limit, $start ); |
|
169 | - $return['simple'] = 'Need either XML or JSON format for stats'; |
|
170 | - $return['message'] = 'success'; |
|
171 | - return yourls_apply_filter( 'api_stats', $return, $filter, $limit, $start ); |
|
168 | + $return = yourls_get_stats( $filter, $limit, $start ); |
|
169 | + $return['simple'] = 'Need either XML or JSON format for stats'; |
|
170 | + $return['message'] = 'success'; |
|
171 | + return yourls_apply_filter( 'api_stats', $return, $filter, $limit, $start ); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -176,14 +176,14 @@ discard block |
||
176 | 176 | * |
177 | 177 | */ |
178 | 178 | function yourls_api_db_stats() { |
179 | - $return = array( |
|
180 | - 'db-stats' => yourls_get_db_stats(), |
|
181 | - 'statusCode' => 200, |
|
182 | - 'simple' => 'Need either XML or JSON format for stats', |
|
183 | - 'message' => 'success', |
|
184 | - ); |
|
185 | - |
|
186 | - return yourls_apply_filter( 'api_db_stats', $return ); |
|
179 | + $return = array( |
|
180 | + 'db-stats' => yourls_get_db_stats(), |
|
181 | + 'statusCode' => 200, |
|
182 | + 'simple' => 'Need either XML or JSON format for stats', |
|
183 | + 'message' => 'success', |
|
184 | + ); |
|
185 | + |
|
186 | + return yourls_apply_filter( 'api_db_stats', $return ); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -191,12 +191,12 @@ discard block |
||
191 | 191 | * |
192 | 192 | */ |
193 | 193 | function yourls_api_url_stats( $shorturl ) { |
194 | - $keyword = str_replace( yourls_get_yourls_site() . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' |
|
195 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
194 | + $keyword = str_replace( yourls_get_yourls_site() . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' |
|
195 | + $keyword = yourls_sanitize_keyword( $keyword ); |
|
196 | 196 | |
197 | - $return = yourls_get_keyword_stats( $keyword ); |
|
198 | - $return['simple'] = 'Need either XML or JSON format for stats'; |
|
199 | - return yourls_apply_filter( 'api_url_stats', $return, $shorturl ); |
|
197 | + $return = yourls_get_keyword_stats( $keyword ); |
|
198 | + $return['simple'] = 'Need either XML or JSON format for stats'; |
|
199 | + return yourls_apply_filter( 'api_url_stats', $return, $shorturl ); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -204,29 +204,29 @@ discard block |
||
204 | 204 | * |
205 | 205 | */ |
206 | 206 | function yourls_api_expand( $shorturl ) { |
207 | - $keyword = str_replace( yourls_get_yourls_site() . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' |
|
208 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
207 | + $keyword = str_replace( yourls_get_yourls_site() . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' |
|
208 | + $keyword = yourls_sanitize_keyword( $keyword ); |
|
209 | 209 | |
210 | - $longurl = yourls_get_keyword_longurl( $keyword ); |
|
210 | + $longurl = yourls_get_keyword_longurl( $keyword ); |
|
211 | 211 | |
212 | - if( $longurl ) { |
|
213 | - $return = array( |
|
214 | - 'keyword' => $keyword, |
|
215 | - 'shorturl' => yourls_link($keyword), |
|
216 | - 'longurl' => $longurl, |
|
212 | + if( $longurl ) { |
|
213 | + $return = array( |
|
214 | + 'keyword' => $keyword, |
|
215 | + 'shorturl' => yourls_link($keyword), |
|
216 | + 'longurl' => $longurl, |
|
217 | 217 | 'title' => yourls_get_keyword_title( $keyword ), |
218 | - 'simple' => $longurl, |
|
219 | - 'message' => 'success', |
|
220 | - 'statusCode' => 200, |
|
221 | - ); |
|
222 | - } else { |
|
223 | - $return = array( |
|
224 | - 'keyword' => $keyword, |
|
225 | - 'simple' => 'not found', |
|
226 | - 'message' => 'Error: short URL not found', |
|
227 | - 'errorCode' => 404, |
|
228 | - ); |
|
229 | - } |
|
230 | - |
|
231 | - return yourls_apply_filter( 'api_expand', $return, $shorturl ); |
|
218 | + 'simple' => $longurl, |
|
219 | + 'message' => 'success', |
|
220 | + 'statusCode' => 200, |
|
221 | + ); |
|
222 | + } else { |
|
223 | + $return = array( |
|
224 | + 'keyword' => $keyword, |
|
225 | + 'simple' => 'not found', |
|
226 | + 'message' => 'Error: short URL not found', |
|
227 | + 'errorCode' => 404, |
|
228 | + ); |
|
229 | + } |
|
230 | + |
|
231 | + return yourls_apply_filter( 'api_expand', $return, $shorturl ); |
|
232 | 232 | } |
@@ -15,13 +15,13 @@ discard block |
||
15 | 15 | * @return array Result of API call |
16 | 16 | */ |
17 | 17 | function yourls_api_action_shorturl() { |
18 | - $url = ( isset( $_REQUEST['url'] ) ? $_REQUEST['url'] : '' ); |
|
19 | - $keyword = ( isset( $_REQUEST['keyword'] ) ? $_REQUEST['keyword'] : '' ); |
|
20 | - $title = ( isset( $_REQUEST['title'] ) ? $_REQUEST['title'] : '' ); |
|
21 | - $return = yourls_add_new_link( $url, $keyword, $title ); |
|
22 | - $return['simple'] = ( isset( $return['shorturl'] ) ? $return['shorturl'] : '' ); // This one will be used in case output mode is 'simple' |
|
23 | - unset( $return['html'] ); // in API mode, no need for our internal HTML output |
|
24 | - return yourls_apply_filter( 'api_result_shorturl', $return ); |
|
18 | + $url = (isset($_REQUEST['url']) ? $_REQUEST['url'] : ''); |
|
19 | + $keyword = (isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : ''); |
|
20 | + $title = (isset($_REQUEST['title']) ? $_REQUEST['title'] : ''); |
|
21 | + $return = yourls_add_new_link($url, $keyword, $title); |
|
22 | + $return['simple'] = (isset($return['shorturl']) ? $return['shorturl'] : ''); // This one will be used in case output mode is 'simple' |
|
23 | + unset($return['html']); // in API mode, no need for our internal HTML output |
|
24 | + return yourls_apply_filter('api_result_shorturl', $return); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | /** |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * @return array Result of API call |
32 | 32 | */ |
33 | 33 | function yourls_api_action_stats() { |
34 | - $filter = ( isset( $_REQUEST['filter'] ) ? $_REQUEST['filter'] : '' ); |
|
35 | - $limit = ( isset( $_REQUEST['limit'] ) ? $_REQUEST['limit'] : '' ); |
|
36 | - $start = ( isset( $_REQUEST['start'] ) ? $_REQUEST['start'] : '' ); |
|
37 | - return yourls_apply_filter( 'api_result_stats', yourls_api_stats( $filter, $limit, $start ) ); |
|
34 | + $filter = (isset($_REQUEST['filter']) ? $_REQUEST['filter'] : ''); |
|
35 | + $limit = (isset($_REQUEST['limit']) ? $_REQUEST['limit'] : ''); |
|
36 | + $start = (isset($_REQUEST['start']) ? $_REQUEST['start'] : ''); |
|
37 | + return yourls_apply_filter('api_result_stats', yourls_api_stats($filter, $limit, $start)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @return array Result of API call |
45 | 45 | */ |
46 | 46 | function yourls_api_action_db_stats() { |
47 | - return yourls_apply_filter( 'api_result_db_stats', yourls_api_db_stats() ); |
|
47 | + return yourls_apply_filter('api_result_db_stats', yourls_api_db_stats()); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @return array Result of API call |
55 | 55 | */ |
56 | 56 | function yourls_api_action_url_stats() { |
57 | - $shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' ); |
|
58 | - return yourls_apply_filter( 'api_result_url_stats', yourls_api_url_stats( $shorturl ) ); |
|
57 | + $shorturl = (isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : ''); |
|
58 | + return yourls_apply_filter('api_result_url_stats', yourls_api_url_stats($shorturl)); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @return array Result of API call |
66 | 66 | */ |
67 | 67 | function yourls_api_action_expand() { |
68 | - $shorturl = ( isset( $_REQUEST['shorturl'] ) ? $_REQUEST['shorturl'] : '' ); |
|
69 | - return yourls_apply_filter( 'api_result_expand', yourls_api_expand( $shorturl ) ); |
|
68 | + $shorturl = (isset($_REQUEST['shorturl']) ? $_REQUEST['shorturl'] : ''); |
|
69 | + return yourls_apply_filter('api_result_expand', yourls_api_expand($shorturl)); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | /** |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function yourls_api_action_version() { |
79 | 79 | $return['version'] = $return['simple'] = YOURLS_VERSION; |
80 | - if( isset( $_REQUEST['db'] ) && $_REQUEST['db'] == 1 ) |
|
80 | + if (isset($_REQUEST['db']) && $_REQUEST['db'] == 1) |
|
81 | 81 | $return['db_version'] = YOURLS_DB_VERSION; |
82 | - return yourls_apply_filter( 'api_result_version', $return ); |
|
82 | + return yourls_apply_filter('api_result_version', $return); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -98,64 +98,64 @@ discard block |
||
98 | 98 | * @param bool $echo Optional, default true: Whether the output should be outputted or just returned |
99 | 99 | * @return string API output, as an XML / JSON / JSONP / raw text string |
100 | 100 | */ |
101 | -function yourls_api_output( $mode, $output, $send_headers = true, $echo = true ) { |
|
102 | - if( isset( $output['simple'] ) ) { |
|
101 | +function yourls_api_output($mode, $output, $send_headers = true, $echo = true) { |
|
102 | + if (isset($output['simple'])) { |
|
103 | 103 | $simple = $output['simple']; |
104 | - unset( $output['simple'] ); |
|
104 | + unset($output['simple']); |
|
105 | 105 | } |
106 | 106 | |
107 | - yourls_do_action( 'pre_api_output', $mode, $output, $send_headers, $echo ); |
|
107 | + yourls_do_action('pre_api_output', $mode, $output, $send_headers, $echo); |
|
108 | 108 | |
109 | - if( $send_headers ) { |
|
110 | - if( isset( $output['statusCode'] ) ) { |
|
109 | + if ($send_headers) { |
|
110 | + if (isset($output['statusCode'])) { |
|
111 | 111 | $code = $output['statusCode']; |
112 | - } elseif ( isset( $output['errorCode'] ) ) { |
|
112 | + } elseif (isset($output['errorCode'])) { |
|
113 | 113 | $code = $output['errorCode']; |
114 | 114 | } else { |
115 | 115 | $code = 200; |
116 | 116 | } |
117 | - yourls_status_header( $code ); |
|
117 | + yourls_status_header($code); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $result = ''; |
121 | 121 | |
122 | - switch ( $mode ) { |
|
122 | + switch ($mode) { |
|
123 | 123 | case 'jsonp': |
124 | - if( $send_headers ) |
|
125 | - yourls_content_type_header( 'application/javascript' ); |
|
124 | + if ($send_headers) |
|
125 | + yourls_content_type_header('application/javascript'); |
|
126 | 126 | |
127 | - $callback = isset( $output['callback'] ) ? $output['callback'] : ''; |
|
128 | - $result = $callback . '(' . json_encode( $output ) . ')'; |
|
127 | + $callback = isset($output['callback']) ? $output['callback'] : ''; |
|
128 | + $result = $callback.'('.json_encode($output).')'; |
|
129 | 129 | break; |
130 | 130 | |
131 | 131 | case 'json': |
132 | - if( $send_headers ) |
|
133 | - yourls_content_type_header( 'application/json' ); |
|
132 | + if ($send_headers) |
|
133 | + yourls_content_type_header('application/json'); |
|
134 | 134 | |
135 | - $result = json_encode( $output ); |
|
135 | + $result = json_encode($output); |
|
136 | 136 | break; |
137 | 137 | |
138 | 138 | case 'xml': |
139 | - if( $send_headers ) |
|
140 | - yourls_content_type_header( 'application/xml' ); |
|
139 | + if ($send_headers) |
|
140 | + yourls_content_type_header('application/xml'); |
|
141 | 141 | |
142 | - $result = yourls_xml_encode( $output ); |
|
142 | + $result = yourls_xml_encode($output); |
|
143 | 143 | break; |
144 | 144 | |
145 | 145 | case 'simple': |
146 | 146 | default: |
147 | - if( $send_headers ) |
|
148 | - yourls_content_type_header( 'text/plain' ); |
|
147 | + if ($send_headers) |
|
148 | + yourls_content_type_header('text/plain'); |
|
149 | 149 | |
150 | - $result = isset( $simple ) ? $simple : ''; |
|
150 | + $result = isset($simple) ? $simple : ''; |
|
151 | 151 | break; |
152 | 152 | } |
153 | 153 | |
154 | - if( $echo ) { |
|
154 | + if ($echo) { |
|
155 | 155 | echo $result; |
156 | 156 | } |
157 | 157 | |
158 | - yourls_do_action( 'api_output', $mode, $output, $send_headers, $echo ); |
|
158 | + yourls_do_action('api_output', $mode, $output, $send_headers, $echo); |
|
159 | 159 | |
160 | 160 | return $result; |
161 | 161 | } |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | * Return array for API stat requests |
165 | 165 | * |
166 | 166 | */ |
167 | -function yourls_api_stats( $filter = 'top', $limit = 10, $start = 0 ) { |
|
168 | - $return = yourls_get_stats( $filter, $limit, $start ); |
|
167 | +function yourls_api_stats($filter = 'top', $limit = 10, $start = 0) { |
|
168 | + $return = yourls_get_stats($filter, $limit, $start); |
|
169 | 169 | $return['simple'] = 'Need either XML or JSON format for stats'; |
170 | 170 | $return['message'] = 'success'; |
171 | - return yourls_apply_filter( 'api_stats', $return, $filter, $limit, $start ); |
|
171 | + return yourls_apply_filter('api_stats', $return, $filter, $limit, $start); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -183,38 +183,38 @@ discard block |
||
183 | 183 | 'message' => 'success', |
184 | 184 | ); |
185 | 185 | |
186 | - return yourls_apply_filter( 'api_db_stats', $return ); |
|
186 | + return yourls_apply_filter('api_db_stats', $return); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Return array for API stat requests |
191 | 191 | * |
192 | 192 | */ |
193 | -function yourls_api_url_stats( $shorturl ) { |
|
194 | - $keyword = str_replace( yourls_get_yourls_site() . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' |
|
195 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
193 | +function yourls_api_url_stats($shorturl) { |
|
194 | + $keyword = str_replace(yourls_get_yourls_site().'/', '', $shorturl); // accept either 'http://ozh.in/abc' or 'abc' |
|
195 | + $keyword = yourls_sanitize_keyword($keyword); |
|
196 | 196 | |
197 | - $return = yourls_get_keyword_stats( $keyword ); |
|
198 | - $return['simple'] = 'Need either XML or JSON format for stats'; |
|
199 | - return yourls_apply_filter( 'api_url_stats', $return, $shorturl ); |
|
197 | + $return = yourls_get_keyword_stats($keyword); |
|
198 | + $return['simple'] = 'Need either XML or JSON format for stats'; |
|
199 | + return yourls_apply_filter('api_url_stats', $return, $shorturl); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Expand short url to long url |
204 | 204 | * |
205 | 205 | */ |
206 | -function yourls_api_expand( $shorturl ) { |
|
207 | - $keyword = str_replace( yourls_get_yourls_site() . '/' , '', $shorturl ); // accept either 'http://ozh.in/abc' or 'abc' |
|
208 | - $keyword = yourls_sanitize_keyword( $keyword ); |
|
206 | +function yourls_api_expand($shorturl) { |
|
207 | + $keyword = str_replace(yourls_get_yourls_site().'/', '', $shorturl); // accept either 'http://ozh.in/abc' or 'abc' |
|
208 | + $keyword = yourls_sanitize_keyword($keyword); |
|
209 | 209 | |
210 | - $longurl = yourls_get_keyword_longurl( $keyword ); |
|
210 | + $longurl = yourls_get_keyword_longurl($keyword); |
|
211 | 211 | |
212 | - if( $longurl ) { |
|
212 | + if ($longurl) { |
|
213 | 213 | $return = array( |
214 | 214 | 'keyword' => $keyword, |
215 | 215 | 'shorturl' => yourls_link($keyword), |
216 | 216 | 'longurl' => $longurl, |
217 | - 'title' => yourls_get_keyword_title( $keyword ), |
|
217 | + 'title' => yourls_get_keyword_title($keyword), |
|
218 | 218 | 'simple' => $longurl, |
219 | 219 | 'message' => 'success', |
220 | 220 | 'statusCode' => 200, |
@@ -228,5 +228,5 @@ discard block |
||
228 | 228 | ); |
229 | 229 | } |
230 | 230 | |
231 | - return yourls_apply_filter( 'api_expand', $return, $shorturl ); |
|
231 | + return yourls_apply_filter('api_expand', $return, $shorturl); |
|
232 | 232 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | // Enforce UTC timezone. Date/time can be adjusted with a plugin. |
31 | 31 | if ($actions->default_timezone === true) { |
32 | - date_default_timezone_set( 'UTC' ); |
|
32 | + date_default_timezone_set('UTC'); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | // Load locale |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | // Abort initialization here if fast init wanted (for tests/debug/do not use) |
66 | - if ($actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT){ |
|
66 | + if ($actions->return_if_fast_init === true && defined('YOURLS_FAST_INIT') && YOURLS_FAST_INIT) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
@@ -74,19 +74,19 @@ discard block |
||
74 | 74 | |
75 | 75 | // Register shutdown function |
76 | 76 | if ($actions->register_shutdown === true) { |
77 | - register_shutdown_function( 'yourls_shutdown' ); |
|
77 | + register_shutdown_function('yourls_shutdown'); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | // Core now loaded |
81 | 81 | if ($actions->core_loaded === true) { |
82 | - yourls_do_action( 'init' ); // plugins can't see this, not loaded yet |
|
82 | + yourls_do_action('init'); // plugins can't see this, not loaded yet |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | // Check if need to redirect to install procedure |
86 | 86 | if ($actions->redirect_to_install === true) { |
87 | 87 | if (!yourls_is_installed() && !yourls_is_installing()) { |
88 | 88 | yourls_no_cache_headers(); |
89 | - yourls_redirect( yourls_admin_url('install.php'), 307 ); |
|
89 | + yourls_redirect(yourls_admin_url('install.php'), 307); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | if ($actions->check_if_upgrade_needed === true) { |
95 | 95 | if (!yourls_is_upgrading() && !yourls_is_installing() && yourls_upgrade_is_needed()) { |
96 | 96 | yourls_no_cache_headers(); |
97 | - yourls_redirect( yourls_admin_url('upgrade.php'), 307 ); |
|
97 | + yourls_redirect(yourls_admin_url('upgrade.php'), 307); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | // Trigger plugin loaded action |
107 | 107 | if ($actions->plugins_loaded_action === true) { |
108 | - yourls_do_action( 'plugins_loaded' ); |
|
108 | + yourls_do_action('plugins_loaded'); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Is there a new version of YOURLS ? |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | if ($actions->init_admin === true) { |
119 | 119 | if (yourls_is_admin()) { |
120 | - yourls_do_action( 'admin_init' ); |
|
120 | + yourls_do_action('admin_init'); |
|
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | */ |
130 | 130 | public function redirect_ssl_if_needed() { |
131 | 131 | if (yourls_is_admin() && yourls_needs_ssl() && !yourls_is_ssl()) { |
132 | - if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { |
|
133 | - yourls_redirect( preg_replace( '|^http://|', 'https://', $_SERVER['REQUEST_URI'] ) ); |
|
132 | + if (0 === strpos($_SERVER['REQUEST_URI'], 'http')) { |
|
133 | + yourls_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); |
|
134 | 134 | } else { |
135 | - yourls_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
|
135 | + yourls_redirect('https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); |
|
136 | 136 | } |
137 | 137 | exit(); |
138 | 138 | } |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | * @return string sanitized DB version |
26 | 26 | */ |
27 | 27 | function yourls_get_database_version() { |
28 | - // Allow plugins to short-circuit the whole function |
|
29 | - $pre = yourls_apply_filter( 'shunt_get_database_version', false ); |
|
30 | - if ( false !== $pre ) |
|
31 | - return $pre; |
|
28 | + // Allow plugins to short-circuit the whole function |
|
29 | + $pre = yourls_apply_filter( 'shunt_get_database_version', false ); |
|
30 | + if ( false !== $pre ) |
|
31 | + return $pre; |
|
32 | 32 | |
33 | - global $ydb; |
|
33 | + global $ydb; |
|
34 | 34 | |
35 | - return yourls_sanitize_version($ydb->mysql_version()); |
|
35 | + return yourls_sanitize_version($ydb->mysql_version()); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | * |
49 | 49 | */ |
50 | 50 | function yourls_is_apache() { |
51 | - if( !array_key_exists( 'SERVER_SOFTWARE', $_SERVER ) ) |
|
52 | - return false; |
|
53 | - return ( |
|
54 | - strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false |
|
55 | - || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false |
|
56 | - ); |
|
51 | + if( !array_key_exists( 'SERVER_SOFTWARE', $_SERVER ) ) |
|
52 | + return false; |
|
53 | + return ( |
|
54 | + strpos( $_SERVER['SERVER_SOFTWARE'], 'Apache' ) !== false |
|
55 | + || strpos( $_SERVER['SERVER_SOFTWARE'], 'LiteSpeed' ) !== false |
|
56 | + ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * |
62 | 62 | */ |
63 | 63 | function yourls_is_iis() { |
64 | - return ( array_key_exists( 'SERVER_SOFTWARE', $_SERVER ) ? ( strpos( $_SERVER['SERVER_SOFTWARE'], 'IIS' ) !== false ) : false ); |
|
64 | + return ( array_key_exists( 'SERVER_SOFTWARE', $_SERVER ) ? ( strpos( $_SERVER['SERVER_SOFTWARE'], 'IIS' ) !== false ) : false ); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -70,55 +70,55 @@ discard block |
||
70 | 70 | * |
71 | 71 | */ |
72 | 72 | function yourls_create_htaccess() { |
73 | - $host = parse_url( yourls_get_yourls_site() ); |
|
74 | - $path = ( isset( $host['path'] ) ? $host['path'] : '' ); |
|
75 | - |
|
76 | - if ( yourls_is_iis() ) { |
|
77 | - // Prepare content for a web.config file |
|
78 | - $content = array( |
|
79 | - '<?'.'xml version="1.0" encoding="UTF-8"?>', |
|
80 | - '<configuration>', |
|
81 | - ' <system.webServer>', |
|
82 | - ' <security>', |
|
83 | - ' <requestFiltering allowDoubleEscaping="true" />', |
|
84 | - ' </security>', |
|
85 | - ' <rewrite>', |
|
86 | - ' <rules>', |
|
87 | - ' <rule name="YOURLS" stopProcessing="true">', |
|
88 | - ' <match url="^(.*)$" ignoreCase="false" />', |
|
89 | - ' <conditions>', |
|
90 | - ' <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />', |
|
91 | - ' <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />', |
|
92 | - ' </conditions>', |
|
93 | - ' <action type="Rewrite" url="'.$path.'/yourls-loader.php" appendQueryString="true" />', |
|
94 | - ' </rule>', |
|
95 | - ' </rules>', |
|
96 | - ' </rewrite>', |
|
97 | - ' </system.webServer>', |
|
98 | - '</configuration>', |
|
99 | - ); |
|
100 | - |
|
101 | - $filename = YOURLS_ABSPATH.'/web.config'; |
|
102 | - $marker = 'none'; |
|
103 | - |
|
104 | - } else { |
|
105 | - // Prepare content for a .htaccess file |
|
106 | - $content = array( |
|
107 | - '<IfModule mod_rewrite.c>', |
|
108 | - 'RewriteEngine On', |
|
109 | - 'RewriteBase '.$path.'/', |
|
110 | - 'RewriteCond %{REQUEST_FILENAME} !-f', |
|
111 | - 'RewriteCond %{REQUEST_FILENAME} !-d', |
|
112 | - 'RewriteRule ^.*$ '.$path.'/yourls-loader.php [L]', |
|
113 | - '</IfModule>', |
|
114 | - ); |
|
115 | - |
|
116 | - $filename = YOURLS_ABSPATH.'/.htaccess'; |
|
117 | - $marker = 'YOURLS'; |
|
118 | - |
|
119 | - } |
|
120 | - |
|
121 | - return ( yourls_insert_with_markers( $filename, $marker, $content ) ); |
|
73 | + $host = parse_url( yourls_get_yourls_site() ); |
|
74 | + $path = ( isset( $host['path'] ) ? $host['path'] : '' ); |
|
75 | + |
|
76 | + if ( yourls_is_iis() ) { |
|
77 | + // Prepare content for a web.config file |
|
78 | + $content = array( |
|
79 | + '<?'.'xml version="1.0" encoding="UTF-8"?>', |
|
80 | + '<configuration>', |
|
81 | + ' <system.webServer>', |
|
82 | + ' <security>', |
|
83 | + ' <requestFiltering allowDoubleEscaping="true" />', |
|
84 | + ' </security>', |
|
85 | + ' <rewrite>', |
|
86 | + ' <rules>', |
|
87 | + ' <rule name="YOURLS" stopProcessing="true">', |
|
88 | + ' <match url="^(.*)$" ignoreCase="false" />', |
|
89 | + ' <conditions>', |
|
90 | + ' <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />', |
|
91 | + ' <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />', |
|
92 | + ' </conditions>', |
|
93 | + ' <action type="Rewrite" url="'.$path.'/yourls-loader.php" appendQueryString="true" />', |
|
94 | + ' </rule>', |
|
95 | + ' </rules>', |
|
96 | + ' </rewrite>', |
|
97 | + ' </system.webServer>', |
|
98 | + '</configuration>', |
|
99 | + ); |
|
100 | + |
|
101 | + $filename = YOURLS_ABSPATH.'/web.config'; |
|
102 | + $marker = 'none'; |
|
103 | + |
|
104 | + } else { |
|
105 | + // Prepare content for a .htaccess file |
|
106 | + $content = array( |
|
107 | + '<IfModule mod_rewrite.c>', |
|
108 | + 'RewriteEngine On', |
|
109 | + 'RewriteBase '.$path.'/', |
|
110 | + 'RewriteCond %{REQUEST_FILENAME} !-f', |
|
111 | + 'RewriteCond %{REQUEST_FILENAME} !-d', |
|
112 | + 'RewriteRule ^.*$ '.$path.'/yourls-loader.php [L]', |
|
113 | + '</IfModule>', |
|
114 | + ); |
|
115 | + |
|
116 | + $filename = YOURLS_ABSPATH.'/.htaccess'; |
|
117 | + $marker = 'YOURLS'; |
|
118 | + |
|
119 | + } |
|
120 | + |
|
121 | + return ( yourls_insert_with_markers( $filename, $marker, $content ) ); |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -136,54 +136,54 @@ discard block |
||
136 | 136 | * @return bool True on write success, false on failure. |
137 | 137 | */ |
138 | 138 | function yourls_insert_with_markers( $filename, $marker, $insertion ) { |
139 | - if ( !file_exists( $filename ) || is_writeable( $filename ) ) { |
|
140 | - if ( !file_exists( $filename ) ) { |
|
141 | - $markerdata = ''; |
|
142 | - } else { |
|
143 | - $markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
|
144 | - } |
|
145 | - |
|
146 | - if ( !$f = @fopen( $filename, 'w' ) ) |
|
147 | - return false; |
|
148 | - |
|
149 | - $foundit = false; |
|
150 | - if ( $markerdata ) { |
|
151 | - $state = true; |
|
152 | - foreach ( $markerdata as $n => $markerline ) { |
|
153 | - if ( strpos( $markerline, '# BEGIN ' . $marker ) !== false ) |
|
154 | - $state = false; |
|
155 | - if ( $state ) { |
|
156 | - if ( $n + 1 < count( $markerdata ) ) |
|
157 | - fwrite( $f, "{$markerline}\n" ); |
|
158 | - else |
|
159 | - fwrite( $f, "{$markerline}" ); |
|
160 | - } |
|
161 | - if ( strpos( $markerline, '# END ' . $marker ) !== false ) { |
|
162 | - if ( $marker != 'none' ) |
|
163 | - fwrite( $f, "# BEGIN {$marker}\n" ); |
|
164 | - if ( is_array( $insertion ) ) |
|
165 | - foreach ( $insertion as $insertline ) |
|
166 | - fwrite( $f, "{$insertline}\n" ); |
|
167 | - if ( $marker != 'none' ) |
|
168 | - fwrite( $f, "# END {$marker}\n" ); |
|
169 | - $state = true; |
|
170 | - $foundit = true; |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - if ( !$foundit ) { |
|
175 | - if ( $marker != 'none' ) |
|
176 | - fwrite( $f, "\n\n# BEGIN {$marker}\n" ); |
|
177 | - foreach ( $insertion as $insertline ) |
|
178 | - fwrite( $f, "{$insertline}\n" ); |
|
179 | - if ( $marker != 'none' ) |
|
180 | - fwrite( $f, "# END {$marker}\n\n" ); |
|
181 | - } |
|
182 | - fclose( $f ); |
|
183 | - return true; |
|
184 | - } else { |
|
185 | - return false; |
|
186 | - } |
|
139 | + if ( !file_exists( $filename ) || is_writeable( $filename ) ) { |
|
140 | + if ( !file_exists( $filename ) ) { |
|
141 | + $markerdata = ''; |
|
142 | + } else { |
|
143 | + $markerdata = explode( "\n", implode( '', file( $filename ) ) ); |
|
144 | + } |
|
145 | + |
|
146 | + if ( !$f = @fopen( $filename, 'w' ) ) |
|
147 | + return false; |
|
148 | + |
|
149 | + $foundit = false; |
|
150 | + if ( $markerdata ) { |
|
151 | + $state = true; |
|
152 | + foreach ( $markerdata as $n => $markerline ) { |
|
153 | + if ( strpos( $markerline, '# BEGIN ' . $marker ) !== false ) |
|
154 | + $state = false; |
|
155 | + if ( $state ) { |
|
156 | + if ( $n + 1 < count( $markerdata ) ) |
|
157 | + fwrite( $f, "{$markerline}\n" ); |
|
158 | + else |
|
159 | + fwrite( $f, "{$markerline}" ); |
|
160 | + } |
|
161 | + if ( strpos( $markerline, '# END ' . $marker ) !== false ) { |
|
162 | + if ( $marker != 'none' ) |
|
163 | + fwrite( $f, "# BEGIN {$marker}\n" ); |
|
164 | + if ( is_array( $insertion ) ) |
|
165 | + foreach ( $insertion as $insertline ) |
|
166 | + fwrite( $f, "{$insertline}\n" ); |
|
167 | + if ( $marker != 'none' ) |
|
168 | + fwrite( $f, "# END {$marker}\n" ); |
|
169 | + $state = true; |
|
170 | + $foundit = true; |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + if ( !$foundit ) { |
|
175 | + if ( $marker != 'none' ) |
|
176 | + fwrite( $f, "\n\n# BEGIN {$marker}\n" ); |
|
177 | + foreach ( $insertion as $insertline ) |
|
178 | + fwrite( $f, "{$insertline}\n" ); |
|
179 | + if ( $marker != 'none' ) |
|
180 | + fwrite( $f, "# END {$marker}\n\n" ); |
|
181 | + } |
|
182 | + fclose( $f ); |
|
183 | + return true; |
|
184 | + } else { |
|
185 | + return false; |
|
186 | + } |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
@@ -200,81 +200,81 @@ discard block |
||
200 | 200 | return $pre; |
201 | 201 | } |
202 | 202 | |
203 | - global $ydb; |
|
203 | + global $ydb; |
|
204 | 204 | |
205 | - $error_msg = array(); |
|
206 | - $success_msg = array(); |
|
205 | + $error_msg = array(); |
|
206 | + $success_msg = array(); |
|
207 | 207 | |
208 | - // Create Table Query |
|
209 | - $create_tables = array(); |
|
210 | - $create_tables[YOURLS_DB_TABLE_URL] = |
|
208 | + // Create Table Query |
|
209 | + $create_tables = array(); |
|
210 | + $create_tables[YOURLS_DB_TABLE_URL] = |
|
211 | 211 | 'CREATE TABLE IF NOT EXISTS `'.YOURLS_DB_TABLE_URL.'` ('. |
212 | - '`keyword` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT "",'. |
|
213 | - '`url` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,'. |
|
214 | - '`title` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,'. |
|
215 | - '`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),'. |
|
216 | - '`ip` varchar(41) COLLATE utf8mb4_unicode_ci NOT NULL,'. |
|
217 | - '`clicks` int(10) unsigned NOT NULL,'. |
|
218 | - 'PRIMARY KEY (`keyword`),'. |
|
219 | - 'KEY `ip` (`ip`),'. |
|
220 | - 'KEY `timestamp` (`timestamp`)'. |
|
212 | + '`keyword` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT "",'. |
|
213 | + '`url` text CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,'. |
|
214 | + '`title` text COLLATE utf8mb4_unicode_ci DEFAULT NULL,'. |
|
215 | + '`timestamp` timestamp NOT NULL DEFAULT current_timestamp(),'. |
|
216 | + '`ip` varchar(41) COLLATE utf8mb4_unicode_ci NOT NULL,'. |
|
217 | + '`clicks` int(10) unsigned NOT NULL,'. |
|
218 | + 'PRIMARY KEY (`keyword`),'. |
|
219 | + 'KEY `ip` (`ip`),'. |
|
220 | + 'KEY `timestamp` (`timestamp`)'. |
|
221 | 221 | ') DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'; |
222 | 222 | |
223 | - $create_tables[YOURLS_DB_TABLE_OPTIONS] = |
|
224 | - 'CREATE TABLE IF NOT EXISTS `'.YOURLS_DB_TABLE_OPTIONS.'` ('. |
|
225 | - '`option_id` bigint(20) unsigned NOT NULL auto_increment,'. |
|
226 | - '`option_name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL default "",'. |
|
227 | - '`option_value` longtext COLLATE utf8mb4_unicode_ci NOT NULL,'. |
|
228 | - 'PRIMARY KEY (`option_id`,`option_name`),'. |
|
229 | - 'KEY `option_name` (`option_name`)'. |
|
230 | - ') AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'; |
|
231 | - |
|
232 | - $create_tables[YOURLS_DB_TABLE_LOG] = |
|
233 | - 'CREATE TABLE IF NOT EXISTS `'.YOURLS_DB_TABLE_LOG.'` ('. |
|
234 | - '`click_id` int(11) NOT NULL auto_increment,'. |
|
235 | - '`click_time` datetime NOT NULL,'. |
|
236 | - '`shorturl` varchar(100) BINARY NOT NULL,'. |
|
237 | - '`referrer` varchar(200) NOT NULL,'. |
|
238 | - '`user_agent` varchar(255) NOT NULL,'. |
|
239 | - '`ip_address` varchar(41) NOT NULL,'. |
|
240 | - '`country_code` char(2) NOT NULL,'. |
|
241 | - 'PRIMARY KEY (`click_id`),'. |
|
242 | - 'KEY `shorturl` (`shorturl`)'. |
|
243 | - ') AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'; |
|
244 | - |
|
245 | - |
|
246 | - $create_table_count = 0; |
|
223 | + $create_tables[YOURLS_DB_TABLE_OPTIONS] = |
|
224 | + 'CREATE TABLE IF NOT EXISTS `'.YOURLS_DB_TABLE_OPTIONS.'` ('. |
|
225 | + '`option_id` bigint(20) unsigned NOT NULL auto_increment,'. |
|
226 | + '`option_name` varchar(64) COLLATE utf8mb4_unicode_ci NOT NULL default "",'. |
|
227 | + '`option_value` longtext COLLATE utf8mb4_unicode_ci NOT NULL,'. |
|
228 | + 'PRIMARY KEY (`option_id`,`option_name`),'. |
|
229 | + 'KEY `option_name` (`option_name`)'. |
|
230 | + ') AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'; |
|
231 | + |
|
232 | + $create_tables[YOURLS_DB_TABLE_LOG] = |
|
233 | + 'CREATE TABLE IF NOT EXISTS `'.YOURLS_DB_TABLE_LOG.'` ('. |
|
234 | + '`click_id` int(11) NOT NULL auto_increment,'. |
|
235 | + '`click_time` datetime NOT NULL,'. |
|
236 | + '`shorturl` varchar(100) BINARY NOT NULL,'. |
|
237 | + '`referrer` varchar(200) NOT NULL,'. |
|
238 | + '`user_agent` varchar(255) NOT NULL,'. |
|
239 | + '`ip_address` varchar(41) NOT NULL,'. |
|
240 | + '`country_code` char(2) NOT NULL,'. |
|
241 | + 'PRIMARY KEY (`click_id`),'. |
|
242 | + 'KEY `shorturl` (`shorturl`)'. |
|
243 | + ') AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;'; |
|
244 | + |
|
245 | + |
|
246 | + $create_table_count = 0; |
|
247 | 247 | |
248 | 248 | yourls_debug_mode(true); |
249 | 249 | |
250 | - // Create tables |
|
251 | - foreach ( $create_tables as $table_name => $table_query ) { |
|
252 | - $ydb->perform( $table_query ); |
|
253 | - $create_success = $ydb->fetchAffected( "SHOW TABLES LIKE '$table_name'" ); |
|
254 | - if( $create_success ) { |
|
255 | - $create_table_count++; |
|
256 | - $success_msg[] = yourls_s( "Table '%s' created.", $table_name ); |
|
257 | - } else { |
|
258 | - $error_msg[] = yourls_s( "Error creating table '%s'.", $table_name ); |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - // Initializes the option table |
|
263 | - if( !yourls_initialize_options() ) |
|
264 | - $error_msg[] = yourls__( 'Could not initialize options' ); |
|
265 | - |
|
266 | - // Insert sample links |
|
267 | - if( !yourls_insert_sample_links() ) |
|
268 | - $error_msg[] = yourls__( 'Could not insert sample short URLs' ); |
|
269 | - |
|
270 | - // Check results of operations |
|
271 | - if ( sizeof( $create_tables ) == $create_table_count ) { |
|
272 | - $success_msg[] = yourls__( 'YOURLS tables successfully created.' ); |
|
273 | - } else { |
|
274 | - $error_msg[] = yourls__( 'Error creating YOURLS tables.' ); |
|
275 | - } |
|
276 | - |
|
277 | - return array( 'success' => $success_msg, 'error' => $error_msg ); |
|
250 | + // Create tables |
|
251 | + foreach ( $create_tables as $table_name => $table_query ) { |
|
252 | + $ydb->perform( $table_query ); |
|
253 | + $create_success = $ydb->fetchAffected( "SHOW TABLES LIKE '$table_name'" ); |
|
254 | + if( $create_success ) { |
|
255 | + $create_table_count++; |
|
256 | + $success_msg[] = yourls_s( "Table '%s' created.", $table_name ); |
|
257 | + } else { |
|
258 | + $error_msg[] = yourls_s( "Error creating table '%s'.", $table_name ); |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + // Initializes the option table |
|
263 | + if( !yourls_initialize_options() ) |
|
264 | + $error_msg[] = yourls__( 'Could not initialize options' ); |
|
265 | + |
|
266 | + // Insert sample links |
|
267 | + if( !yourls_insert_sample_links() ) |
|
268 | + $error_msg[] = yourls__( 'Could not insert sample short URLs' ); |
|
269 | + |
|
270 | + // Check results of operations |
|
271 | + if ( sizeof( $create_tables ) == $create_table_count ) { |
|
272 | + $success_msg[] = yourls__( 'YOURLS tables successfully created.' ); |
|
273 | + } else { |
|
274 | + $error_msg[] = yourls__( 'Error creating YOURLS tables.' ); |
|
275 | + } |
|
276 | + |
|
277 | + return array( 'success' => $success_msg, 'error' => $error_msg ); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -288,12 +288,12 @@ discard block |
||
288 | 288 | * @return bool |
289 | 289 | */ |
290 | 290 | function yourls_initialize_options() { |
291 | - return ( bool ) ( |
|
292 | - yourls_update_option( 'version', YOURLS_VERSION ) |
|
293 | - & yourls_update_option( 'db_version', YOURLS_DB_VERSION ) |
|
294 | - & yourls_update_option( 'next_id', 1 ) |
|
291 | + return ( bool ) ( |
|
292 | + yourls_update_option( 'version', YOURLS_VERSION ) |
|
293 | + & yourls_update_option( 'db_version', YOURLS_DB_VERSION ) |
|
294 | + & yourls_update_option( 'next_id', 1 ) |
|
295 | 295 | & yourls_update_option( 'active_plugins', array() ) |
296 | - ); |
|
296 | + ); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -303,14 +303,14 @@ discard block |
||
303 | 303 | * @return bool |
304 | 304 | */ |
305 | 305 | function yourls_insert_sample_links() { |
306 | - $link1 = yourls_add_new_link( 'http://blog.yourls.org/', 'yourlsblog', 'YOURLS\' Blog' ); |
|
307 | - $link2 = yourls_add_new_link( 'http://yourls.org/', 'yourls', 'YOURLS: Your Own URL Shortener' ); |
|
308 | - $link3 = yourls_add_new_link( 'http://ozh.org/', 'ozh', 'ozh.org' ); |
|
309 | - return ( bool ) ( |
|
310 | - $link1['status'] == 'success' |
|
311 | - & $link2['status'] == 'success' |
|
312 | - & $link3['status'] == 'success' |
|
313 | - ); |
|
306 | + $link1 = yourls_add_new_link( 'http://blog.yourls.org/', 'yourlsblog', 'YOURLS\' Blog' ); |
|
307 | + $link2 = yourls_add_new_link( 'http://yourls.org/', 'yourls', 'YOURLS: Your Own URL Shortener' ); |
|
308 | + $link3 = yourls_add_new_link( 'http://ozh.org/', 'ozh', 'ozh.org' ); |
|
309 | + return ( bool ) ( |
|
310 | + $link1['status'] == 'success' |
|
311 | + & $link2['status'] == 'success' |
|
312 | + & $link3['status'] == 'success' |
|
313 | + ); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | |
@@ -320,24 +320,24 @@ discard block |
||
320 | 320 | */ |
321 | 321 | function yourls_maintenance_mode( $maintenance = true ) { |
322 | 322 | |
323 | - $file = YOURLS_ABSPATH . '/.maintenance' ; |
|
323 | + $file = YOURLS_ABSPATH . '/.maintenance' ; |
|
324 | 324 | |
325 | - // Turn maintenance mode on : create .maintenance file |
|
326 | - if ( (bool)$maintenance ) { |
|
327 | - if ( ! ( $fp = @fopen( $file, 'w' ) ) ) |
|
328 | - return false; |
|
325 | + // Turn maintenance mode on : create .maintenance file |
|
326 | + if ( (bool)$maintenance ) { |
|
327 | + if ( ! ( $fp = @fopen( $file, 'w' ) ) ) |
|
328 | + return false; |
|
329 | 329 | |
330 | - $maintenance_string = '<?php $maintenance_start = ' . time() . '; ?>'; |
|
331 | - @fwrite( $fp, $maintenance_string ); |
|
332 | - @fclose( $fp ); |
|
333 | - @chmod( $file, 0644 ); // Read and write for owner, read for everybody else |
|
330 | + $maintenance_string = '<?php $maintenance_start = ' . time() . '; ?>'; |
|
331 | + @fwrite( $fp, $maintenance_string ); |
|
332 | + @fclose( $fp ); |
|
333 | + @chmod( $file, 0644 ); // Read and write for owner, read for everybody else |
|
334 | 334 | |
335 | - // Not sure why the fwrite would fail if the fopen worked... Just in case |
|
336 | - return( is_readable( $file ) ); |
|
335 | + // Not sure why the fwrite would fail if the fopen worked... Just in case |
|
336 | + return( is_readable( $file ) ); |
|
337 | 337 | |
338 | - // Turn maintenance mode off : delete the .maintenance file |
|
339 | - } else { |
|
340 | - return @unlink($file); |
|
341 | - } |
|
338 | + // Turn maintenance mode off : delete the .maintenance file |
|
339 | + } else { |
|
340 | + return @unlink($file); |
|
341 | + } |
|
342 | 342 | } |
343 | 343 |
@@ -376,8 +376,9 @@ discard block |
||
376 | 376 | } |
377 | 377 | $html .= "</select>\n"; |
378 | 378 | $html = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display ); |
379 | - if( $display ) |
|
380 | - echo $html; |
|
379 | + if( $display ) { |
|
380 | + echo $html; |
|
381 | + } |
|
381 | 382 | return $html; |
382 | 383 | } |
383 | 384 | |
@@ -386,15 +387,18 @@ discard block |
||
386 | 387 | * |
387 | 388 | */ |
388 | 389 | function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) { |
389 | - if ( $shortlink_title == '' ) |
|
390 | - $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>'; |
|
391 | - if ( $share_title == '' ) |
|
392 | - $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>'; |
|
390 | + if ( $shortlink_title == '' ) { |
|
391 | + $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>'; |
|
392 | + } |
|
393 | + if ( $share_title == '' ) { |
|
394 | + $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>'; |
|
395 | + } |
|
393 | 396 | |
394 | 397 | // Allow plugins to short-circuit the whole function |
395 | 398 | $pre = yourls_apply_filter( 'shunt_share_box', false ); |
396 | - if ( false !== $pre ) |
|
397 | - return $pre; |
|
399 | + if ( false !== $pre ) { |
|
400 | + return $pre; |
|
401 | + } |
|
398 | 402 | |
399 | 403 | // Make sure IDN domains are in their UTF8 form |
400 | 404 | $shorturl = yourls_normalize_uri($shorturl); |
@@ -576,12 +580,14 @@ discard block |
||
576 | 580 | } |
577 | 581 | $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp ); |
578 | 582 | |
579 | - if( ! $title ) |
|
580 | - $title = $url; |
|
583 | + if( ! $title ) { |
|
584 | + $title = $url; |
|
585 | + } |
|
581 | 586 | |
582 | 587 | $protocol_warning = ''; |
583 | - if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) |
|
584 | - $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' ); |
|
588 | + if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) { |
|
589 | + $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' ); |
|
590 | + } |
|
585 | 591 | |
586 | 592 | // Row cells: the array |
587 | 593 | $cells = array( |
@@ -686,10 +692,12 @@ discard block |
||
686 | 692 | * |
687 | 693 | */ |
688 | 694 | function yourls_html_link( $href, $title = '', $element = '' ) { |
689 | - if( !$title ) |
|
690 | - $title = $href; |
|
691 | - if( $element ) |
|
692 | - $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); |
|
695 | + if( !$title ) { |
|
696 | + $title = $href; |
|
697 | + } |
|
698 | + if( $element ) { |
|
699 | + $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); |
|
700 | + } |
|
693 | 701 | $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) ); |
694 | 702 | echo yourls_apply_filter( 'html_link', $link ); |
695 | 703 | } |
@@ -778,8 +786,9 @@ discard block |
||
778 | 786 | |
779 | 787 | // Now output menu |
780 | 788 | echo '<nav role="navigation"><ul id="admin_menu">'."\n"; |
781 | - if ( yourls_is_private() && !empty( $logout_link ) ) |
|
782 | - echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>'; |
|
789 | + if ( yourls_is_private() && !empty( $logout_link ) ) { |
|
790 | + echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>'; |
|
791 | + } |
|
783 | 792 | |
784 | 793 | foreach( (array)$admin_links as $link => $ar ) { |
785 | 794 | if( isset( $ar['url'] ) ) { |
@@ -801,8 +810,9 @@ discard block |
||
801 | 810 | } |
802 | 811 | } |
803 | 812 | |
804 | - if ( isset( $help_link ) ) |
|
805 | - echo '<li id="admin_menu_help_link">' . $help_link .'</li>'; |
|
813 | + if ( isset( $help_link ) ) { |
|
814 | + echo '<li id="admin_menu_help_link">' . $help_link .'</li>'; |
|
815 | + } |
|
806 | 816 | |
807 | 817 | yourls_do_action( 'admin_menu' ); |
808 | 818 | echo "</ul></nav>\n"; |
@@ -933,12 +943,15 @@ discard block |
||
933 | 943 | */ |
934 | 944 | function yourls_get_search_text() { |
935 | 945 | $search = ''; |
936 | - if( isset( $_GET['search_protocol'] ) ) |
|
937 | - $search .= $_GET['search_protocol']; |
|
938 | - if( isset( $_GET['search_slashes'] ) ) |
|
939 | - $search .= $_GET['search_slashes']; |
|
940 | - if( isset( $_GET['search'] ) ) |
|
941 | - $search .= $_GET['search']; |
|
946 | + if( isset( $_GET['search_protocol'] ) ) { |
|
947 | + $search .= $_GET['search_protocol']; |
|
948 | + } |
|
949 | + if( isset( $_GET['search_slashes'] ) ) { |
|
950 | + $search .= $_GET['search_slashes']; |
|
951 | + } |
|
952 | + if( isset( $_GET['search'] ) ) { |
|
953 | + $search .= $_GET['search']; |
|
954 | + } |
|
942 | 955 | |
943 | 956 | return htmlspecialchars( trim( $search ) ); |
944 | 957 | } |
@@ -958,8 +971,9 @@ discard block |
||
958 | 971 | <a href="$href" class="bookmarklet" onclick="alert('$alert');return false;">$anchor</a> |
959 | 972 | LINK; |
960 | 973 | |
961 | - if( $echo ) |
|
962 | - echo $link; |
|
974 | + if( $echo ) { |
|
975 | + echo $link; |
|
976 | + } |
|
963 | 977 | return $link; |
964 | 978 | } |
965 | 979 |
@@ -5,8 +5,8 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | function yourls_html_logo() { |
8 | - yourls_do_action( 'pre_html_logo' ); |
|
9 | - ?> |
|
8 | + yourls_do_action( 'pre_html_logo' ); |
|
9 | + ?> |
|
10 | 10 | <header role="banner"> |
11 | 11 | <h1> |
12 | 12 | <a href="<?php echo yourls_admin_url( 'index.php' ) ?>" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/> |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | </h1> |
15 | 15 | </header> |
16 | 16 | <?php |
17 | - yourls_do_action( 'html_logo' ); |
|
17 | + yourls_do_action( 'html_logo' ); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -25,57 +25,57 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function yourls_html_head( $context = 'index', $title = '' ) { |
27 | 27 | |
28 | - yourls_do_action( 'pre_html_head', $context, $title ); |
|
28 | + yourls_do_action( 'pre_html_head', $context, $title ); |
|
29 | 29 | |
30 | - // All components to false, except when specified true |
|
31 | - $share = $insert = $tablesorter = $tabs = $cal = $charts = false; |
|
30 | + // All components to false, except when specified true |
|
31 | + $share = $insert = $tablesorter = $tabs = $cal = $charts = false; |
|
32 | 32 | |
33 | - // Load components as needed |
|
34 | - switch ( $context ) { |
|
35 | - case 'infos': |
|
36 | - $share = $tabs = $charts = true; |
|
37 | - break; |
|
33 | + // Load components as needed |
|
34 | + switch ( $context ) { |
|
35 | + case 'infos': |
|
36 | + $share = $tabs = $charts = true; |
|
37 | + break; |
|
38 | 38 | |
39 | - case 'bookmark': |
|
40 | - $share = $insert = $tablesorter = true; |
|
41 | - break; |
|
39 | + case 'bookmark': |
|
40 | + $share = $insert = $tablesorter = true; |
|
41 | + break; |
|
42 | 42 | |
43 | - case 'index': |
|
44 | - $insert = $tablesorter = $cal = $share = true; |
|
45 | - break; |
|
43 | + case 'index': |
|
44 | + $insert = $tablesorter = $cal = $share = true; |
|
45 | + break; |
|
46 | 46 | |
47 | - case 'plugins': |
|
48 | - case 'tools': |
|
49 | - $tablesorter = true; |
|
50 | - break; |
|
47 | + case 'plugins': |
|
48 | + case 'tools': |
|
49 | + $tablesorter = true; |
|
50 | + break; |
|
51 | 51 | |
52 | - case 'install': |
|
53 | - case 'login': |
|
54 | - case 'new': |
|
55 | - case 'upgrade': |
|
56 | - break; |
|
57 | - } |
|
52 | + case 'install': |
|
53 | + case 'login': |
|
54 | + case 'new': |
|
55 | + case 'upgrade': |
|
56 | + break; |
|
57 | + } |
|
58 | 58 | |
59 | - // Force no cache for all admin pages |
|
60 | - if( yourls_is_admin() && !headers_sent() ) { |
|
59 | + // Force no cache for all admin pages |
|
60 | + if( yourls_is_admin() && !headers_sent() ) { |
|
61 | 61 | yourls_no_cache_headers(); |
62 | - yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) ); |
|
63 | - yourls_do_action( 'admin_headers', $context, $title ); |
|
64 | - } |
|
62 | + yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) ); |
|
63 | + yourls_do_action( 'admin_headers', $context, $title ); |
|
64 | + } |
|
65 | 65 | |
66 | - // Store page context |
|
67 | - yourls_set_html_context($context); |
|
66 | + // Store page context |
|
67 | + yourls_set_html_context($context); |
|
68 | 68 | |
69 | - // Body class |
|
70 | - $bodyclass = yourls_apply_filter( 'bodyclass', '' ); |
|
71 | - $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' ); |
|
69 | + // Body class |
|
70 | + $bodyclass = yourls_apply_filter( 'bodyclass', '' ); |
|
71 | + $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' ); |
|
72 | 72 | |
73 | - // Page title |
|
74 | - $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link(); |
|
75 | - $title = $title ? $title . " « " . $_title : $_title; |
|
76 | - $title = yourls_apply_filter( 'html_title', $title, $context ); |
|
73 | + // Page title |
|
74 | + $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link(); |
|
75 | + $title = $title ? $title . " « " . $_title : $_title; |
|
76 | + $title = yourls_apply_filter( 'html_title', $title, $context ); |
|
77 | 77 | |
78 | - ?> |
|
78 | + ?> |
|
79 | 79 | <!DOCTYPE html> |
80 | 80 | <html <?php yourls_html_language_attributes(); ?>> |
81 | 81 | <head> |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | $num_queries = ''; |
147 | 147 | } |
148 | 148 | |
149 | - ?> |
|
149 | + ?> |
|
150 | 150 | </div><?php // wrap ?> |
151 | 151 | <footer id="footer" role="contentinfo"><p> |
152 | 152 | <?php |
153 | - $footer = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION ); |
|
154 | - $footer .= $num_queries; |
|
155 | - echo yourls_apply_filter( 'html_footer_text', $footer ); |
|
156 | - ?> |
|
153 | + $footer = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION ); |
|
154 | + $footer .= $num_queries; |
|
155 | + echo yourls_apply_filter( 'html_footer_text', $footer ); |
|
156 | + ?> |
|
157 | 157 | </p></footer> |
158 | 158 | <?php if( yourls_get_debug_mode() ) { |
159 | - echo '<div style="text-align:left"><pre>'; |
|
160 | - echo join( "\n", yourls_get_debug_log() ); |
|
161 | - echo '</pre></div>'; |
|
162 | - } ?> |
|
159 | + echo '<div style="text-align:left"><pre>'; |
|
160 | + echo join( "\n", yourls_get_debug_log() ); |
|
161 | + echo '</pre></div>'; |
|
162 | + } ?> |
|
163 | 163 | <?php yourls_do_action( 'html_footer', yourls_get_html_context() ); ?> |
164 | 164 | </body> |
165 | 165 | </html> |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | if ( false !== $pre ) { |
178 | 178 | return $pre; |
179 | 179 | } |
180 | - ?> |
|
180 | + ?> |
|
181 | 181 | <main role="main"> |
182 | 182 | <div id="new_url"> |
183 | 183 | <div> |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | $date_first = $params['date_first']; |
224 | 224 | $date_second = $params['date_second']; |
225 | 225 | |
226 | - ?> |
|
226 | + ?> |
|
227 | 227 | <tfoot> |
228 | 228 | <tr> |
229 | 229 | <th colspan="6"> |
@@ -232,70 +232,70 @@ discard block |
||
232 | 232 | <div id="filter_options"> |
233 | 233 | <?php |
234 | 234 | |
235 | - // First search control: text to search |
|
236 | - $_input = '<input aria-label="' .yourls__( 'Search for' ). '" type="text" name="search" class="text" size="12" value="' . yourls_esc_attr( $search_text ) . '" />'; |
|
237 | - $_options = array( |
|
235 | + // First search control: text to search |
|
236 | + $_input = '<input aria-label="' .yourls__( 'Search for' ). '" type="text" name="search" class="text" size="12" value="' . yourls_esc_attr( $search_text ) . '" />'; |
|
237 | + $_options = array( |
|
238 | 238 | 'all' => yourls__( 'All fields' ), |
239 | - 'keyword' => yourls__( 'Short URL' ), |
|
240 | - 'url' => yourls__( 'URL' ), |
|
241 | - 'title' => yourls__( 'Title' ), |
|
242 | - 'ip' => yourls__( 'IP' ), |
|
243 | - ); |
|
244 | - $_select = yourls_html_select( 'search_in', $_options, $search_in, false, yourls__( 'Search in' ) ); |
|
245 | - /* //translators: "Search for <input field with text to search> in <select dropdown with URL, title...>" */ |
|
246 | - yourls_se( 'Search for %1$s in %2$s', $_input , $_select ); |
|
247 | - echo "–\n"; |
|
248 | - |
|
249 | - // Second search control: order by |
|
250 | - $_options = array( |
|
251 | - 'keyword' => yourls__( 'Short URL' ), |
|
252 | - 'url' => yourls__( 'URL' ), |
|
253 | - 'title' => yourls__( 'Title' ), |
|
254 | - 'timestamp' => yourls__( 'Date' ), |
|
255 | - 'ip' => yourls__( 'IP' ), |
|
256 | - 'clicks' => yourls__( 'Clicks' ), |
|
257 | - ); |
|
258 | - $_select = yourls_html_select( 'sort_by', $_options, $sort_by, false, yourls__( 'Sort by' ) ); |
|
259 | - $sort_order = isset( $sort_order ) ? $sort_order : 'desc' ; |
|
260 | - $_options = array( |
|
261 | - 'asc' => yourls__( 'Ascending' ), |
|
262 | - 'desc' => yourls__( 'Descending' ), |
|
263 | - ); |
|
264 | - $_select2 = yourls_html_select( 'sort_order', $_options, $sort_order, false, yourls__( 'Sort order' ) ); |
|
265 | - /* //translators: "Order by <criteria dropdown (date, clicks...)> in <order dropdown (Descending or Ascending)>" */ |
|
266 | - yourls_se( 'Order by %1$s %2$s', $_select , $_select2 ); |
|
267 | - echo "–\n"; |
|
268 | - |
|
269 | - // Third search control: Show XX rows |
|
270 | - /* //translators: "Show <text field> rows" */ |
|
239 | + 'keyword' => yourls__( 'Short URL' ), |
|
240 | + 'url' => yourls__( 'URL' ), |
|
241 | + 'title' => yourls__( 'Title' ), |
|
242 | + 'ip' => yourls__( 'IP' ), |
|
243 | + ); |
|
244 | + $_select = yourls_html_select( 'search_in', $_options, $search_in, false, yourls__( 'Search in' ) ); |
|
245 | + /* //translators: "Search for <input field with text to search> in <select dropdown with URL, title...>" */ |
|
246 | + yourls_se( 'Search for %1$s in %2$s', $_input , $_select ); |
|
247 | + echo "–\n"; |
|
248 | + |
|
249 | + // Second search control: order by |
|
250 | + $_options = array( |
|
251 | + 'keyword' => yourls__( 'Short URL' ), |
|
252 | + 'url' => yourls__( 'URL' ), |
|
253 | + 'title' => yourls__( 'Title' ), |
|
254 | + 'timestamp' => yourls__( 'Date' ), |
|
255 | + 'ip' => yourls__( 'IP' ), |
|
256 | + 'clicks' => yourls__( 'Clicks' ), |
|
257 | + ); |
|
258 | + $_select = yourls_html_select( 'sort_by', $_options, $sort_by, false, yourls__( 'Sort by' ) ); |
|
259 | + $sort_order = isset( $sort_order ) ? $sort_order : 'desc' ; |
|
260 | + $_options = array( |
|
261 | + 'asc' => yourls__( 'Ascending' ), |
|
262 | + 'desc' => yourls__( 'Descending' ), |
|
263 | + ); |
|
264 | + $_select2 = yourls_html_select( 'sort_order', $_options, $sort_order, false, yourls__( 'Sort order' ) ); |
|
265 | + /* //translators: "Order by <criteria dropdown (date, clicks...)> in <order dropdown (Descending or Ascending)>" */ |
|
266 | + yourls_se( 'Order by %1$s %2$s', $_select , $_select2 ); |
|
267 | + echo "–\n"; |
|
268 | + |
|
269 | + // Third search control: Show XX rows |
|
270 | + /* //translators: "Show <text field> rows" */ |
|
271 | 271 | $_input = '<input aria-label="' .yourls__( 'Number of rows to show' ). '" type="text" name="perpage" class="text" size="2" value="' . $perpage . '" />'; |
272 | - yourls_se( 'Show %s rows', $_input ); |
|
273 | - echo "<br/>\n"; |
|
274 | - |
|
275 | - // Fourth search control: Show links with more than XX clicks |
|
276 | - $_options = array( |
|
277 | - 'more' => yourls__( 'more' ), |
|
278 | - 'less' => yourls__( 'less' ), |
|
279 | - ); |
|
280 | - $_select = yourls_html_select( 'click_filter', $_options, $click_filter, false, yourls__( 'Show links with' ) ); |
|
281 | - $_input = '<input aria-label="' .yourls__( 'Number of clicks' ). '" type="text" name="click_limit" class="text" size="4" value="' . $click_limit . '" /> '; |
|
282 | - /* //translators: "Show links with <more/less> than <text field> clicks" */ |
|
283 | - yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input ); |
|
284 | - echo "<br/>\n"; |
|
285 | - |
|
286 | - // Fifth search control: Show links created before/after/between ... |
|
287 | - $_options = array( |
|
288 | - 'before' => yourls__('before'), |
|
289 | - 'after' => yourls__('after'), |
|
290 | - 'between' => yourls__('between'), |
|
291 | - ); |
|
292 | - $_select = yourls_html_select( 'date_filter', $_options, $date_filter, false, yourls__('Show links created') ); |
|
293 | - $_input = '<input aria-label="' .yourls__('Select a date') . '" type="text" name="date_first" id="date_first" class="text" size="12" value="' . $date_first . '" />'; |
|
294 | - $_and = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> & </span>'; |
|
295 | - $_input2 = '<input aria-label="' .yourls__('Select an end date') . '" type="text" name="date_second" id="date_second" class="text" size="12" value="' . $date_second . '"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '/>'; |
|
296 | - /* //translators: "Show links created <before/after/between> <date input> <"and" if applicable> <date input if applicable>" */ |
|
297 | - yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 ); |
|
298 | - ?> |
|
272 | + yourls_se( 'Show %s rows', $_input ); |
|
273 | + echo "<br/>\n"; |
|
274 | + |
|
275 | + // Fourth search control: Show links with more than XX clicks |
|
276 | + $_options = array( |
|
277 | + 'more' => yourls__( 'more' ), |
|
278 | + 'less' => yourls__( 'less' ), |
|
279 | + ); |
|
280 | + $_select = yourls_html_select( 'click_filter', $_options, $click_filter, false, yourls__( 'Show links with' ) ); |
|
281 | + $_input = '<input aria-label="' .yourls__( 'Number of clicks' ). '" type="text" name="click_limit" class="text" size="4" value="' . $click_limit . '" /> '; |
|
282 | + /* //translators: "Show links with <more/less> than <text field> clicks" */ |
|
283 | + yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input ); |
|
284 | + echo "<br/>\n"; |
|
285 | + |
|
286 | + // Fifth search control: Show links created before/after/between ... |
|
287 | + $_options = array( |
|
288 | + 'before' => yourls__('before'), |
|
289 | + 'after' => yourls__('after'), |
|
290 | + 'between' => yourls__('between'), |
|
291 | + ); |
|
292 | + $_select = yourls_html_select( 'date_filter', $_options, $date_filter, false, yourls__('Show links created') ); |
|
293 | + $_input = '<input aria-label="' .yourls__('Select a date') . '" type="text" name="date_first" id="date_first" class="text" size="12" value="' . $date_first . '" />'; |
|
294 | + $_and = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> & </span>'; |
|
295 | + $_input2 = '<input aria-label="' .yourls__('Select an end date') . '" type="text" name="date_second" id="date_second" class="text" size="12" value="' . $date_second . '"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '/>'; |
|
296 | + /* //translators: "Show links created <before/after/between> <date input> <"and" if applicable> <date input if applicable>" */ |
|
297 | + yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 ); |
|
298 | + ?> |
|
299 | 299 | |
300 | 300 | <div id="filter_buttons"> |
301 | 301 | <input type="submit" id="submit-sort" value="<?php yourls_e('Search'); ?>" class="button primary" /> |
@@ -308,43 +308,43 @@ discard block |
||
308 | 308 | </div> |
309 | 309 | |
310 | 310 | <?php |
311 | - // Remove empty keys from the $params array so it doesn't clutter the pagination links |
|
312 | - $params = array_filter( $params, 'yourls_return_if_not_empty_string' ); // remove empty keys |
|
311 | + // Remove empty keys from the $params array so it doesn't clutter the pagination links |
|
312 | + $params = array_filter( $params, 'yourls_return_if_not_empty_string' ); // remove empty keys |
|
313 | 313 | |
314 | - if( isset( $search_text ) ) { |
|
315 | - $params['search'] = $search_text; |
|
316 | - unset( $params['search_text'] ); |
|
317 | - } |
|
318 | - ?> |
|
314 | + if( isset( $search_text ) ) { |
|
315 | + $params['search'] = $search_text; |
|
316 | + unset( $params['search_text'] ); |
|
317 | + } |
|
318 | + ?> |
|
319 | 319 | |
320 | 320 | <div id="pagination"> |
321 | 321 | <span class="navigation"> |
322 | 322 | <?php if( $total_pages > 1 ) { ?> |
323 | 323 | <span class="nav_total"><?php echo sprintf( yourls_n( '1 page', '%s pages', $total_pages ), $total_pages ); ?></span> |
324 | 324 | <?php |
325 | - $base_page = yourls_admin_url( 'index.php' ); |
|
326 | - // Pagination offsets: min( max ( zomg! ) ); |
|
327 | - $p_start = max( min( $total_pages - 4, $page - 2 ), 1 ); |
|
328 | - $p_end = min( max( 5, $page + 2 ), $total_pages ); |
|
329 | - if( $p_start >= 2 ) { |
|
330 | - $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page ); |
|
331 | - echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '« First' ) . '</a></span>'; |
|
332 | - echo '<span class="nav_link nav_prev"></span>'; |
|
333 | - } |
|
334 | - for( $i = $p_start ; $i <= $p_end; $i++ ) { |
|
335 | - if( $i == $page ) { |
|
336 | - echo "<span class='nav_link nav_current'>$i</span>"; |
|
337 | - } else { |
|
338 | - $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page ); |
|
339 | - echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>'; |
|
340 | - } |
|
341 | - } |
|
342 | - if( ( $p_end ) < $total_pages ) { |
|
343 | - $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page ); |
|
344 | - echo '<span class="nav_link nav_next"></span>'; |
|
345 | - echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to Last Page') . '">' . yourls__( 'Last »' ) . '</a></span>'; |
|
346 | - } |
|
347 | - ?> |
|
325 | + $base_page = yourls_admin_url( 'index.php' ); |
|
326 | + // Pagination offsets: min( max ( zomg! ) ); |
|
327 | + $p_start = max( min( $total_pages - 4, $page - 2 ), 1 ); |
|
328 | + $p_end = min( max( 5, $page + 2 ), $total_pages ); |
|
329 | + if( $p_start >= 2 ) { |
|
330 | + $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page ); |
|
331 | + echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '« First' ) . '</a></span>'; |
|
332 | + echo '<span class="nav_link nav_prev"></span>'; |
|
333 | + } |
|
334 | + for( $i = $p_start ; $i <= $p_end; $i++ ) { |
|
335 | + if( $i == $page ) { |
|
336 | + echo "<span class='nav_link nav_current'>$i</span>"; |
|
337 | + } else { |
|
338 | + $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page ); |
|
339 | + echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>'; |
|
340 | + } |
|
341 | + } |
|
342 | + if( ( $p_end ) < $total_pages ) { |
|
343 | + $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page ); |
|
344 | + echo '<span class="nav_link nav_next"></span>'; |
|
345 | + echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to Last Page') . '">' . yourls__( 'Last »' ) . '</a></span>'; |
|
346 | + } |
|
347 | + ?> |
|
348 | 348 | <?php } ?> |
349 | 349 | </span> |
350 | 350 | </div> |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | * @return string HTML content of the select element |
369 | 369 | */ |
370 | 370 | function yourls_html_select( $name, $options, $selected = '', $display = false, $label = '' ) { |
371 | - $html = "<select aria-label='$label' name='$name' id='$name' size='1'>\n"; |
|
372 | - foreach( $options as $value => $text ) { |
|
373 | - $html .= "<option value='$value' "; |
|
374 | - $html .= $selected == $value ? ' selected="selected"' : ''; |
|
375 | - $html .= ">$text</option>\n"; |
|
376 | - } |
|
377 | - $html .= "</select>\n"; |
|
378 | - $html = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display ); |
|
379 | - if( $display ) |
|
380 | - echo $html; |
|
381 | - return $html; |
|
371 | + $html = "<select aria-label='$label' name='$name' id='$name' size='1'>\n"; |
|
372 | + foreach( $options as $value => $text ) { |
|
373 | + $html .= "<option value='$value' "; |
|
374 | + $html .= $selected == $value ? ' selected="selected"' : ''; |
|
375 | + $html .= ">$text</option>\n"; |
|
376 | + } |
|
377 | + $html .= "</select>\n"; |
|
378 | + $html = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display ); |
|
379 | + if( $display ) |
|
380 | + echo $html; |
|
381 | + return $html; |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -386,33 +386,33 @@ discard block |
||
386 | 386 | * |
387 | 387 | */ |
388 | 388 | function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) { |
389 | - if ( $shortlink_title == '' ) |
|
390 | - $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>'; |
|
391 | - if ( $share_title == '' ) |
|
392 | - $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>'; |
|
393 | - |
|
394 | - // Allow plugins to short-circuit the whole function |
|
395 | - $pre = yourls_apply_filter( 'shunt_share_box', false ); |
|
396 | - if ( false !== $pre ) |
|
397 | - return $pre; |
|
389 | + if ( $shortlink_title == '' ) |
|
390 | + $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>'; |
|
391 | + if ( $share_title == '' ) |
|
392 | + $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>'; |
|
393 | + |
|
394 | + // Allow plugins to short-circuit the whole function |
|
395 | + $pre = yourls_apply_filter( 'shunt_share_box', false ); |
|
396 | + if ( false !== $pre ) |
|
397 | + return $pre; |
|
398 | 398 | |
399 | 399 | // Make sure IDN domains are in their UTF8 form |
400 | 400 | $shorturl = yourls_normalize_uri($shorturl); |
401 | 401 | |
402 | - $text = ( $text ? '"'.$text.'" ' : '' ); |
|
403 | - $title = ( $title ? "$title " : '' ); |
|
404 | - $share = yourls_esc_textarea( $title.$text.$shorturl ); |
|
405 | - $count = 280 - strlen( $share ); |
|
406 | - $hidden = ( $hidden ? 'style="display:none;"' : '' ); |
|
402 | + $text = ( $text ? '"'.$text.'" ' : '' ); |
|
403 | + $title = ( $title ? "$title " : '' ); |
|
404 | + $share = yourls_esc_textarea( $title.$text.$shorturl ); |
|
405 | + $count = 280 - strlen( $share ); |
|
406 | + $hidden = ( $hidden ? 'style="display:none;"' : '' ); |
|
407 | 407 | |
408 | - // Allow plugins to filter all data |
|
409 | - $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' ); |
|
410 | - $data = yourls_apply_filter( 'share_box_data', $data ); |
|
411 | - extract( $data ); |
|
408 | + // Allow plugins to filter all data |
|
409 | + $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' ); |
|
410 | + $data = yourls_apply_filter( 'share_box_data', $data ); |
|
411 | + extract( $data ); |
|
412 | 412 | |
413 | - $_share = rawurlencode( $share ); |
|
414 | - $_url = rawurlencode( $shorturl ); |
|
415 | - ?> |
|
413 | + $_share = rawurlencode( $share ); |
|
414 | + $_url = rawurlencode( $shorturl ); |
|
415 | + ?> |
|
416 | 416 | |
417 | 417 | <div id="shareboxes" <?php echo $hidden; ?>> |
418 | 418 | |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | <a id="share_tw" href="https://twitter.com/intent/tweet?text=<?php echo $_share; ?>" title="<?php yourls_e( 'Tweet this!' ); ?>" onclick="share('tw');return false">Twitter</a> |
442 | 442 | <a id="share_fb" href="https://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e( 'Share on Facebook' ); ?>" onclick="share('fb');return false;">Facebook</a> |
443 | 443 | <?php |
444 | - yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text ); |
|
445 | - // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn. |
|
446 | - ?> |
|
444 | + yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text ); |
|
445 | + // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn. |
|
446 | + ?> |
|
447 | 447 | </p> |
448 | 448 | </div> |
449 | 449 | |
@@ -461,20 +461,20 @@ discard block |
||
461 | 461 | function yourls_die( $message = '', $title = '', $header_code = 200 ) { |
462 | 462 | yourls_do_action( 'pre_yourls_die', $message, $title, $header_code ); |
463 | 463 | |
464 | - yourls_status_header( $header_code ); |
|
464 | + yourls_status_header( $header_code ); |
|
465 | 465 | |
466 | - if( !yourls_did_action( 'html_head' ) ) { |
|
467 | - yourls_html_head(); |
|
468 | - yourls_html_logo(); |
|
469 | - } |
|
470 | - echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" ); |
|
471 | - echo yourls_apply_filter( 'die_message', "<p>$message</p>" ); |
|
466 | + if( !yourls_did_action( 'html_head' ) ) { |
|
467 | + yourls_html_head(); |
|
468 | + yourls_html_logo(); |
|
469 | + } |
|
470 | + echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" ); |
|
471 | + echo yourls_apply_filter( 'die_message', "<p>$message</p>" ); |
|
472 | 472 | // Hook into 'yourls_die' to add more elements or messages to that page |
473 | - yourls_do_action( 'yourls_die' ); |
|
474 | - if( !yourls_did_action( 'html_footer' ) ) { |
|
475 | - yourls_html_footer(false); |
|
476 | - } |
|
477 | - die(); |
|
473 | + yourls_do_action( 'yourls_die' ); |
|
474 | + if( !yourls_did_action( 'html_footer' ) ) { |
|
475 | + yourls_html_footer(false); |
|
476 | + } |
|
477 | + die(); |
|
478 | 478 | } |
479 | 479 | |
480 | 480 | /** |
@@ -485,33 +485,33 @@ discard block |
||
485 | 485 | */ |
486 | 486 | function yourls_table_edit_row( $keyword ) { |
487 | 487 | $keyword = yourls_sanitize_keyword($keyword); |
488 | - $id = yourls_string2htmlid( $keyword ); // used as HTML #id |
|
489 | - $url = yourls_get_keyword_longurl( $keyword ); |
|
490 | - $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) ); |
|
491 | - $safe_url = yourls_esc_attr( $url ); |
|
492 | - $safe_title = yourls_esc_attr( $title ); |
|
493 | - $safe_keyword = yourls_esc_attr( $keyword ); |
|
488 | + $id = yourls_string2htmlid( $keyword ); // used as HTML #id |
|
489 | + $url = yourls_get_keyword_longurl( $keyword ); |
|
490 | + $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) ); |
|
491 | + $safe_url = yourls_esc_attr( $url ); |
|
492 | + $safe_title = yourls_esc_attr( $title ); |
|
493 | + $safe_keyword = yourls_esc_attr( $keyword ); |
|
494 | 494 | |
495 | 495 | // Make strings sprintf() safe: '%' -> '%%' |
496 | 496 | $safe_url = str_replace( '%', '%%', $safe_url ); |
497 | 497 | $safe_title = str_replace( '%', '%%', $safe_title ); |
498 | 498 | |
499 | - $www = yourls_link(); |
|
499 | + $www = yourls_link(); |
|
500 | 500 | |
501 | - $nonce = yourls_create_nonce( 'edit-save_'.$id ); |
|
501 | + $nonce = yourls_create_nonce( 'edit-save_'.$id ); |
|
502 | 502 | |
503 | - if( $url ) { |
|
504 | - $return = <<<RETURN |
|
503 | + if( $url ) { |
|
504 | + $return = <<<RETURN |
|
505 | 505 | <tr id="edit-$id" class="edit-row"><td colspan="5" class="edit-row"><strong>%s</strong>:<input type="text" id="edit-url-$id" name="edit-url-$id" value="$safe_url" class="text" size="70" /><br/><strong>%s</strong>: $www<input type="text" id="edit-keyword-$id" name="edit-keyword-$id" value="$safe_keyword" class="text" size="10" /><br/><strong>%s</strong>: <input type="text" id="edit-title-$id" name="edit-title-$id" value="$safe_title" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-$id" name="edit-submit-$id" value="%s" title="%s" class="button" onclick="edit_link_save('$id');" /> <input type="button" id="edit-close-$id" name="edit-close-$id" value="%s" title="%s" class="button" onclick="edit_link_hide('$id');" /><input type="hidden" id="old_keyword_$id" value="$safe_keyword"/><input type="hidden" id="nonce_$id" value="$nonce"/></td></tr> |
506 | 506 | RETURN; |
507 | - $return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) ); |
|
508 | - } else { |
|
509 | - $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>'; |
|
510 | - } |
|
507 | + $return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) ); |
|
508 | + } else { |
|
509 | + $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>'; |
|
510 | + } |
|
511 | 511 | |
512 | - $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title ); |
|
512 | + $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title ); |
|
513 | 513 | |
514 | - return $return; |
|
514 | + return $return; |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | /** |
@@ -521,116 +521,116 @@ discard block |
||
521 | 521 | */ |
522 | 522 | function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) { |
523 | 523 | $keyword = yourls_sanitize_keyword($keyword); |
524 | - $id = yourls_string2htmlid( $keyword ); // used as HTML #id |
|
525 | - $shorturl = yourls_link( $keyword ); |
|
526 | - |
|
527 | - $statlink = yourls_statlink( $keyword ); |
|
528 | - |
|
529 | - $delete_link = yourls_nonce_url( 'delete-link_'.$id, |
|
530 | - yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) |
|
531 | - ); |
|
532 | - |
|
533 | - $edit_link = yourls_nonce_url( 'edit-link_'.$id, |
|
534 | - yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) |
|
535 | - ); |
|
536 | - |
|
537 | - // Action link buttons: the array |
|
538 | - $actions = array( |
|
539 | - 'stats' => array( |
|
540 | - 'href' => $statlink, |
|
541 | - 'id' => "statlink-$id", |
|
542 | - 'title' => yourls_esc_attr__( 'Stats' ), |
|
543 | - 'anchor' => yourls__( 'Stats' ), |
|
544 | - ), |
|
545 | - 'share' => array( |
|
546 | - 'href' => '', |
|
547 | - 'id' => "share-button-$id", |
|
548 | - 'title' => yourls_esc_attr__( 'Share' ), |
|
549 | - 'anchor' => yourls__( 'Share' ), |
|
550 | - 'onclick' => "toggle_share('$id');return false;", |
|
551 | - ), |
|
552 | - 'edit' => array( |
|
553 | - 'href' => $edit_link, |
|
554 | - 'id' => "edit-button-$id", |
|
555 | - 'title' => yourls_esc_attr__( 'Edit' ), |
|
556 | - 'anchor' => yourls__( 'Edit' ), |
|
557 | - 'onclick' => "edit_link_display('$id');return false;", |
|
558 | - ), |
|
559 | - 'delete' => array( |
|
560 | - 'href' => $delete_link, |
|
561 | - 'id' => "delete-button-$id", |
|
562 | - 'title' => yourls_esc_attr__( 'Delete' ), |
|
563 | - 'anchor' => yourls__( 'Delete' ), |
|
564 | - 'onclick' => "remove_link('$id');return false;", |
|
565 | - ) |
|
566 | - ); |
|
567 | - $actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword ); |
|
568 | - |
|
569 | - // Action link buttons: the HTML |
|
570 | - $action_links = ''; |
|
571 | - foreach( $actions as $key => $action ) { |
|
572 | - $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ; |
|
573 | - $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>', |
|
574 | - $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor'] |
|
575 | - ); |
|
576 | - } |
|
577 | - $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp ); |
|
578 | - |
|
579 | - if( ! $title ) |
|
580 | - $title = $url; |
|
581 | - |
|
582 | - $protocol_warning = ''; |
|
583 | - if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) |
|
584 | - $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' ); |
|
585 | - |
|
586 | - // Row cells: the array |
|
587 | - $cells = array( |
|
588 | - 'keyword' => array( |
|
589 | - 'template' => '<a href="%shorturl%">%keyword_html%</a>', |
|
590 | - 'shorturl' => yourls_esc_url( $shorturl ), |
|
591 | - 'keyword_html' => yourls_esc_html( $keyword ), |
|
592 | - ), |
|
593 | - 'url' => array( |
|
594 | - 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>', |
|
595 | - 'long_url' => yourls_esc_url( $url ), |
|
596 | - 'title_attr' => yourls_esc_attr( $title ), |
|
597 | - 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ), |
|
598 | - 'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ), |
|
599 | - 'warning' => $protocol_warning, |
|
600 | - ), |
|
601 | - 'timestamp' => array( |
|
602 | - 'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%', |
|
524 | + $id = yourls_string2htmlid( $keyword ); // used as HTML #id |
|
525 | + $shorturl = yourls_link( $keyword ); |
|
526 | + |
|
527 | + $statlink = yourls_statlink( $keyword ); |
|
528 | + |
|
529 | + $delete_link = yourls_nonce_url( 'delete-link_'.$id, |
|
530 | + yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) |
|
531 | + ); |
|
532 | + |
|
533 | + $edit_link = yourls_nonce_url( 'edit-link_'.$id, |
|
534 | + yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) |
|
535 | + ); |
|
536 | + |
|
537 | + // Action link buttons: the array |
|
538 | + $actions = array( |
|
539 | + 'stats' => array( |
|
540 | + 'href' => $statlink, |
|
541 | + 'id' => "statlink-$id", |
|
542 | + 'title' => yourls_esc_attr__( 'Stats' ), |
|
543 | + 'anchor' => yourls__( 'Stats' ), |
|
544 | + ), |
|
545 | + 'share' => array( |
|
546 | + 'href' => '', |
|
547 | + 'id' => "share-button-$id", |
|
548 | + 'title' => yourls_esc_attr__( 'Share' ), |
|
549 | + 'anchor' => yourls__( 'Share' ), |
|
550 | + 'onclick' => "toggle_share('$id');return false;", |
|
551 | + ), |
|
552 | + 'edit' => array( |
|
553 | + 'href' => $edit_link, |
|
554 | + 'id' => "edit-button-$id", |
|
555 | + 'title' => yourls_esc_attr__( 'Edit' ), |
|
556 | + 'anchor' => yourls__( 'Edit' ), |
|
557 | + 'onclick' => "edit_link_display('$id');return false;", |
|
558 | + ), |
|
559 | + 'delete' => array( |
|
560 | + 'href' => $delete_link, |
|
561 | + 'id' => "delete-button-$id", |
|
562 | + 'title' => yourls_esc_attr__( 'Delete' ), |
|
563 | + 'anchor' => yourls__( 'Delete' ), |
|
564 | + 'onclick' => "remove_link('$id');return false;", |
|
565 | + ) |
|
566 | + ); |
|
567 | + $actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword ); |
|
568 | + |
|
569 | + // Action link buttons: the HTML |
|
570 | + $action_links = ''; |
|
571 | + foreach( $actions as $key => $action ) { |
|
572 | + $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ; |
|
573 | + $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>', |
|
574 | + $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor'] |
|
575 | + ); |
|
576 | + } |
|
577 | + $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp ); |
|
578 | + |
|
579 | + if( ! $title ) |
|
580 | + $title = $url; |
|
581 | + |
|
582 | + $protocol_warning = ''; |
|
583 | + if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) |
|
584 | + $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' ); |
|
585 | + |
|
586 | + // Row cells: the array |
|
587 | + $cells = array( |
|
588 | + 'keyword' => array( |
|
589 | + 'template' => '<a href="%shorturl%">%keyword_html%</a>', |
|
590 | + 'shorturl' => yourls_esc_url( $shorturl ), |
|
591 | + 'keyword_html' => yourls_esc_html( $keyword ), |
|
592 | + ), |
|
593 | + 'url' => array( |
|
594 | + 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>', |
|
595 | + 'long_url' => yourls_esc_url( $url ), |
|
596 | + 'title_attr' => yourls_esc_attr( $title ), |
|
597 | + 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ), |
|
598 | + 'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ), |
|
599 | + 'warning' => $protocol_warning, |
|
600 | + ), |
|
601 | + 'timestamp' => array( |
|
602 | + 'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%', |
|
603 | 603 | 'timestamp' => $timestamp, |
604 | - 'date' => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )), |
|
605 | - ), |
|
606 | - 'ip' => array( |
|
607 | - 'template' => '%ip%', |
|
608 | - 'ip' => $ip, |
|
609 | - ), |
|
610 | - 'clicks' => array( |
|
611 | - 'template' => '%clicks%', |
|
612 | - 'clicks' => yourls_number_format_i18n( $clicks, 0, '', '' ), |
|
613 | - ), |
|
614 | - 'actions' => array( |
|
615 | - 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>', |
|
616 | - 'actions' => $action_links, |
|
617 | - 'id' => $id, |
|
618 | - 'keyword' => $keyword, |
|
619 | - ), |
|
620 | - ); |
|
621 | - $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp ); |
|
622 | - |
|
623 | - // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value. |
|
624 | - $row = "<tr id=\"id-$id\">"; |
|
625 | - foreach( $cells as $cell_id => $elements ) { |
|
626 | - $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id ); |
|
627 | - $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] ); |
|
628 | - $row .= '</td>'; |
|
629 | - } |
|
630 | - $row .= "</tr>"; |
|
631 | - $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp ); |
|
632 | - |
|
633 | - return $row; |
|
604 | + 'date' => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )), |
|
605 | + ), |
|
606 | + 'ip' => array( |
|
607 | + 'template' => '%ip%', |
|
608 | + 'ip' => $ip, |
|
609 | + ), |
|
610 | + 'clicks' => array( |
|
611 | + 'template' => '%clicks%', |
|
612 | + 'clicks' => yourls_number_format_i18n( $clicks, 0, '', '' ), |
|
613 | + ), |
|
614 | + 'actions' => array( |
|
615 | + 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>', |
|
616 | + 'actions' => $action_links, |
|
617 | + 'id' => $id, |
|
618 | + 'keyword' => $keyword, |
|
619 | + ), |
|
620 | + ); |
|
621 | + $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp ); |
|
622 | + |
|
623 | + // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value. |
|
624 | + $row = "<tr id=\"id-$id\">"; |
|
625 | + foreach( $cells as $cell_id => $elements ) { |
|
626 | + $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id ); |
|
627 | + $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] ); |
|
628 | + $row .= '</td>'; |
|
629 | + } |
|
630 | + $row .= "</tr>"; |
|
631 | + $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp ); |
|
632 | + |
|
633 | + return $row; |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -638,23 +638,23 @@ discard block |
||
638 | 638 | * |
639 | 639 | */ |
640 | 640 | function yourls_table_head() { |
641 | - $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n"; |
|
642 | - echo yourls_apply_filter( 'table_head_start', $start ); |
|
643 | - |
|
644 | - $cells = yourls_apply_filter( 'table_head_cells', array( |
|
645 | - 'shorturl' => yourls__( 'Short URL' ), |
|
646 | - 'longurl' => yourls__( 'Original URL' ), |
|
647 | - 'date' => yourls__( 'Date' ), |
|
648 | - 'ip' => yourls__( 'IP' ), |
|
649 | - 'clicks' => yourls__( 'Clicks' ), |
|
650 | - 'actions' => yourls__( 'Actions' ) |
|
651 | - ) ); |
|
652 | - foreach( $cells as $k => $v ) { |
|
653 | - echo "<th id='main_table_head_$k'>$v</th>\n"; |
|
654 | - } |
|
655 | - |
|
656 | - $end = "</tr></thead>\n"; |
|
657 | - echo yourls_apply_filter( 'table_head_end', $end ); |
|
641 | + $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n"; |
|
642 | + echo yourls_apply_filter( 'table_head_start', $start ); |
|
643 | + |
|
644 | + $cells = yourls_apply_filter( 'table_head_cells', array( |
|
645 | + 'shorturl' => yourls__( 'Short URL' ), |
|
646 | + 'longurl' => yourls__( 'Original URL' ), |
|
647 | + 'date' => yourls__( 'Date' ), |
|
648 | + 'ip' => yourls__( 'IP' ), |
|
649 | + 'clicks' => yourls__( 'Clicks' ), |
|
650 | + 'actions' => yourls__( 'Actions' ) |
|
651 | + ) ); |
|
652 | + foreach( $cells as $k => $v ) { |
|
653 | + echo "<th id='main_table_head_$k'>$v</th>\n"; |
|
654 | + } |
|
655 | + |
|
656 | + $end = "</tr></thead>\n"; |
|
657 | + echo yourls_apply_filter( 'table_head_end', $end ); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * |
663 | 663 | */ |
664 | 664 | function yourls_table_tbody_start() { |
665 | - echo yourls_apply_filter( 'table_tbody_start', '<tbody>' ); |
|
665 | + echo yourls_apply_filter( 'table_tbody_start', '<tbody>' ); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | * |
671 | 671 | */ |
672 | 672 | function yourls_table_tbody_end() { |
673 | - echo yourls_apply_filter( 'table_tbody_end', '</tbody>' ); |
|
673 | + echo yourls_apply_filter( 'table_tbody_end', '</tbody>' ); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
@@ -678,7 +678,7 @@ discard block |
||
678 | 678 | * |
679 | 679 | */ |
680 | 680 | function yourls_table_end() { |
681 | - echo yourls_apply_filter( 'table_end', '</table></main>' ); |
|
681 | + echo yourls_apply_filter( 'table_end', '</table></main>' ); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
@@ -686,12 +686,12 @@ discard block |
||
686 | 686 | * |
687 | 687 | */ |
688 | 688 | function yourls_html_link( $href, $title = '', $element = '' ) { |
689 | - if( !$title ) |
|
690 | - $title = $href; |
|
691 | - if( $element ) |
|
692 | - $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); |
|
693 | - $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) ); |
|
694 | - echo yourls_apply_filter( 'html_link', $link ); |
|
689 | + if( !$title ) |
|
690 | + $title = $href; |
|
691 | + if( $element ) |
|
692 | + $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); |
|
693 | + $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) ); |
|
694 | + echo yourls_apply_filter( 'html_link', $link ); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
@@ -699,20 +699,20 @@ discard block |
||
699 | 699 | * |
700 | 700 | */ |
701 | 701 | function yourls_login_screen( $error_msg = '' ) { |
702 | - yourls_html_head( 'login' ); |
|
702 | + yourls_html_head( 'login' ); |
|
703 | 703 | |
704 | - $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' ); |
|
704 | + $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' ); |
|
705 | 705 | |
706 | - yourls_html_logo(); |
|
707 | - ?> |
|
706 | + yourls_html_logo(); |
|
707 | + ?> |
|
708 | 708 | <div id="login"> |
709 | 709 | <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?> |
710 | 710 | <?php |
711 | - if( !empty( $error_msg ) ) { |
|
712 | - echo '<p class="error">'.$error_msg.'</p>'; |
|
713 | - } |
|
714 | - yourls_do_action( 'login_form_top' ); |
|
715 | - ?> |
|
711 | + if( !empty( $error_msg ) ) { |
|
712 | + echo '<p class="error">'.$error_msg.'</p>'; |
|
713 | + } |
|
714 | + yourls_do_action( 'login_form_top' ); |
|
715 | + ?> |
|
716 | 716 | <p> |
717 | 717 | <label for="username"><?php yourls_e( 'Username' ); ?></label><br /> |
718 | 718 | <input type="text" id="username" name="username" size="30" class="text" /> |
@@ -722,20 +722,20 @@ discard block |
||
722 | 722 | <input type="password" id="password" name="password" size="30" class="text" /> |
723 | 723 | </p> |
724 | 724 | <?php |
725 | - yourls_do_action( 'login_form_bottom' ); |
|
726 | - ?> |
|
725 | + yourls_do_action( 'login_form_bottom' ); |
|
726 | + ?> |
|
727 | 727 | <p style="text-align: right;"> |
728 | 728 | <input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" /> |
729 | 729 | </p> |
730 | 730 | <?php |
731 | - yourls_do_action( 'login_form_end' ); |
|
732 | - ?> |
|
731 | + yourls_do_action( 'login_form_end' ); |
|
732 | + ?> |
|
733 | 733 | </form> |
734 | 734 | <script type="text/javascript">$('#username').focus();</script> |
735 | 735 | </div> |
736 | 736 | <?php |
737 | - yourls_html_footer(); |
|
738 | - die(); |
|
737 | + yourls_html_footer(); |
|
738 | + die(); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | /** |
@@ -744,71 +744,71 @@ discard block |
||
744 | 744 | */ |
745 | 745 | function yourls_html_menu() { |
746 | 746 | |
747 | - // Build menu links |
|
748 | - if( defined( 'YOURLS_USER' ) ) { |
|
749 | - $logout_link = yourls_apply_filter( 'logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' (<a href="' . yourls_admin_url() . '?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' ); |
|
750 | - } else { |
|
751 | - $logout_link = yourls_apply_filter( 'logout_link', '' ); |
|
752 | - } |
|
753 | - $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' ); |
|
754 | - |
|
755 | - $admin_links = array(); |
|
756 | - $admin_sublinks = array(); |
|
757 | - |
|
758 | - $admin_links['admin'] = array( |
|
759 | - 'url' => yourls_admin_url( 'index.php' ), |
|
760 | - 'title' => yourls__( 'Go to the admin interface' ), |
|
761 | - 'anchor' => yourls__( 'Admin interface' ) |
|
762 | - ); |
|
763 | - |
|
764 | - if( yourls_is_admin() ) { |
|
765 | - $admin_links['tools'] = array( |
|
766 | - 'url' => yourls_admin_url( 'tools.php' ), |
|
767 | - 'anchor' => yourls__( 'Tools' ) |
|
768 | - ); |
|
769 | - $admin_links['plugins'] = array( |
|
770 | - 'url' => yourls_admin_url( 'plugins.php' ), |
|
771 | - 'anchor' => yourls__( 'Manage Plugins' ) |
|
772 | - ); |
|
773 | - $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages(); |
|
774 | - } |
|
775 | - |
|
776 | - $admin_links = yourls_apply_filter( 'admin_links', $admin_links ); |
|
777 | - $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks ); |
|
778 | - |
|
779 | - // Now output menu |
|
780 | - echo '<nav role="navigation"><ul id="admin_menu">'."\n"; |
|
781 | - if ( yourls_is_private() && !empty( $logout_link ) ) |
|
782 | - echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>'; |
|
783 | - |
|
784 | - foreach( (array)$admin_links as $link => $ar ) { |
|
785 | - if( isset( $ar['url'] ) ) { |
|
786 | - $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; |
|
787 | - $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; |
|
788 | - printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor ); |
|
789 | - } |
|
790 | - // Output submenu if any. TODO: clean up, too many code duplicated here |
|
791 | - if( isset( $admin_sublinks[$link] ) ) { |
|
792 | - echo "<ul>\n"; |
|
793 | - foreach( $admin_sublinks[$link] as $link => $ar ) { |
|
794 | - if( isset( $ar['url'] ) ) { |
|
795 | - $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; |
|
796 | - $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; |
|
797 | - printf( '<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor ); |
|
798 | - } |
|
799 | - } |
|
800 | - echo "</ul>\n"; |
|
801 | - } |
|
802 | - } |
|
803 | - |
|
804 | - if ( isset( $help_link ) ) |
|
805 | - echo '<li id="admin_menu_help_link">' . $help_link .'</li>'; |
|
806 | - |
|
807 | - yourls_do_action( 'admin_menu' ); |
|
808 | - echo "</ul></nav>\n"; |
|
809 | - yourls_do_action( 'admin_notices' ); |
|
810 | - yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice' |
|
811 | - /* |
|
747 | + // Build menu links |
|
748 | + if( defined( 'YOURLS_USER' ) ) { |
|
749 | + $logout_link = yourls_apply_filter( 'logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' (<a href="' . yourls_admin_url() . '?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' ); |
|
750 | + } else { |
|
751 | + $logout_link = yourls_apply_filter( 'logout_link', '' ); |
|
752 | + } |
|
753 | + $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' ); |
|
754 | + |
|
755 | + $admin_links = array(); |
|
756 | + $admin_sublinks = array(); |
|
757 | + |
|
758 | + $admin_links['admin'] = array( |
|
759 | + 'url' => yourls_admin_url( 'index.php' ), |
|
760 | + 'title' => yourls__( 'Go to the admin interface' ), |
|
761 | + 'anchor' => yourls__( 'Admin interface' ) |
|
762 | + ); |
|
763 | + |
|
764 | + if( yourls_is_admin() ) { |
|
765 | + $admin_links['tools'] = array( |
|
766 | + 'url' => yourls_admin_url( 'tools.php' ), |
|
767 | + 'anchor' => yourls__( 'Tools' ) |
|
768 | + ); |
|
769 | + $admin_links['plugins'] = array( |
|
770 | + 'url' => yourls_admin_url( 'plugins.php' ), |
|
771 | + 'anchor' => yourls__( 'Manage Plugins' ) |
|
772 | + ); |
|
773 | + $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages(); |
|
774 | + } |
|
775 | + |
|
776 | + $admin_links = yourls_apply_filter( 'admin_links', $admin_links ); |
|
777 | + $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks ); |
|
778 | + |
|
779 | + // Now output menu |
|
780 | + echo '<nav role="navigation"><ul id="admin_menu">'."\n"; |
|
781 | + if ( yourls_is_private() && !empty( $logout_link ) ) |
|
782 | + echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>'; |
|
783 | + |
|
784 | + foreach( (array)$admin_links as $link => $ar ) { |
|
785 | + if( isset( $ar['url'] ) ) { |
|
786 | + $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; |
|
787 | + $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; |
|
788 | + printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor ); |
|
789 | + } |
|
790 | + // Output submenu if any. TODO: clean up, too many code duplicated here |
|
791 | + if( isset( $admin_sublinks[$link] ) ) { |
|
792 | + echo "<ul>\n"; |
|
793 | + foreach( $admin_sublinks[$link] as $link => $ar ) { |
|
794 | + if( isset( $ar['url'] ) ) { |
|
795 | + $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; |
|
796 | + $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; |
|
797 | + printf( '<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor ); |
|
798 | + } |
|
799 | + } |
|
800 | + echo "</ul>\n"; |
|
801 | + } |
|
802 | + } |
|
803 | + |
|
804 | + if ( isset( $help_link ) ) |
|
805 | + echo '<li id="admin_menu_help_link">' . $help_link .'</li>'; |
|
806 | + |
|
807 | + yourls_do_action( 'admin_menu' ); |
|
808 | + echo "</ul></nav>\n"; |
|
809 | + yourls_do_action( 'admin_notices' ); |
|
810 | + yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice' |
|
811 | + /* |
|
812 | 812 | To display a notice: |
813 | 813 | $message = "<div>OMG, dude, I mean!</div>" ); |
814 | 814 | yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); |
@@ -820,9 +820,9 @@ discard block |
||
820 | 820 | * |
821 | 821 | */ |
822 | 822 | function yourls_add_notice( $message, $style = 'notice' ) { |
823 | - // Escape single quotes in $message to avoid breaking the anonymous function |
|
824 | - $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style ); |
|
825 | - yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); |
|
823 | + // Escape single quotes in $message to avoid breaking the anonymous function |
|
824 | + $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style ); |
|
825 | + yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
@@ -830,7 +830,7 @@ discard block |
||
830 | 830 | * |
831 | 831 | */ |
832 | 832 | function yourls_notice_box( $message, $style = 'notice' ) { |
833 | - return <<<HTML |
|
833 | + return <<<HTML |
|
834 | 834 | <div class="$style"> |
835 | 835 | <p>$message</p> |
836 | 836 | </div> |
@@ -848,12 +848,12 @@ discard block |
||
848 | 848 | */ |
849 | 849 | function yourls_page( $page ) { |
850 | 850 | if( !yourls_is_page($page)) { |
851 | - yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 ); |
|
851 | + yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 ); |
|
852 | 852 | } |
853 | 853 | |
854 | - yourls_do_action( 'pre_page', $page ); |
|
855 | - include_once( YOURLS_PAGEDIR . "/$page.php" ); |
|
856 | - yourls_do_action( 'post_page', $page ); |
|
854 | + yourls_do_action( 'pre_page', $page ); |
|
855 | + include_once( YOURLS_PAGEDIR . "/$page.php" ); |
|
856 | + yourls_do_action( 'post_page', $page ); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -865,24 +865,24 @@ discard block |
||
865 | 865 | * @since 1.6 |
866 | 866 | */ |
867 | 867 | function yourls_html_language_attributes() { |
868 | - $attributes = array(); |
|
869 | - $output = ''; |
|
870 | - |
|
871 | - $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' ); |
|
872 | - |
|
873 | - $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' ); |
|
874 | - // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR |
|
875 | - if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) { |
|
876 | - if( $doctype == 'xhtml' ) { |
|
877 | - $attributes[] = "xml:lang=\"$lang\""; |
|
878 | - } else { |
|
879 | - $attributes[] = "lang=\"$lang\""; |
|
880 | - } |
|
881 | - } |
|
882 | - |
|
883 | - $output = implode( ' ', $attributes ); |
|
884 | - $output = yourls_apply_filter( 'html_language_attributes', $output ); |
|
885 | - echo $output; |
|
868 | + $attributes = array(); |
|
869 | + $output = ''; |
|
870 | + |
|
871 | + $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' ); |
|
872 | + |
|
873 | + $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' ); |
|
874 | + // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR |
|
875 | + if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) { |
|
876 | + if( $doctype == 'xhtml' ) { |
|
877 | + $attributes[] = "xml:lang=\"$lang\""; |
|
878 | + } else { |
|
879 | + $attributes[] = "lang=\"$lang\""; |
|
880 | + } |
|
881 | + } |
|
882 | + |
|
883 | + $output = implode( ' ', $attributes ); |
|
884 | + $output = yourls_apply_filter( 'html_language_attributes', $output ); |
|
885 | + echo $output; |
|
886 | 886 | } |
887 | 887 | |
888 | 888 | /** |
@@ -891,16 +891,16 @@ discard block |
||
891 | 891 | * @since 1.6 |
892 | 892 | */ |
893 | 893 | function yourls_l10n_calendar_strings() { |
894 | - echo "\n<script>\n"; |
|
895 | - echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n"; |
|
896 | - echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n"; |
|
897 | - echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n"; |
|
898 | - echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n"; |
|
899 | - echo "</script>\n"; |
|
900 | - |
|
901 | - // Dummy returns, to initialize l10n strings used in the calendar |
|
902 | - yourls__( 'Today' ); |
|
903 | - yourls__( 'Close' ); |
|
894 | + echo "\n<script>\n"; |
|
895 | + echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n"; |
|
896 | + echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n"; |
|
897 | + echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n"; |
|
898 | + echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n"; |
|
899 | + echo "</script>\n"; |
|
900 | + |
|
901 | + // Dummy returns, to initialize l10n strings used in the calendar |
|
902 | + yourls__( 'Today' ); |
|
903 | + yourls__( 'Close' ); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | |
@@ -911,13 +911,13 @@ discard block |
||
911 | 911 | */ |
912 | 912 | function yourls_new_core_version_notice() { |
913 | 913 | |
914 | - $checks = yourls_get_option( 'core_version_checks' ); |
|
914 | + $checks = yourls_get_option( 'core_version_checks' ); |
|
915 | 915 | $latest = isset($checks->last_result->latest) ? yourls_sanitize_version($checks->last_result->latest) : false; |
916 | 916 | |
917 | - if( $latest AND version_compare( $latest, YOURLS_VERSION, '>' ) ) { |
|
918 | - $msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest ); |
|
919 | - yourls_add_notice( $msg ); |
|
920 | - } |
|
917 | + if( $latest AND version_compare( $latest, YOURLS_VERSION, '>' ) ) { |
|
918 | + $msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest ); |
|
919 | + yourls_add_notice( $msg ); |
|
920 | + } |
|
921 | 921 | } |
922 | 922 | |
923 | 923 | /** |
@@ -932,15 +932,15 @@ discard block |
||
932 | 932 | * @return string Search string |
933 | 933 | */ |
934 | 934 | function yourls_get_search_text() { |
935 | - $search = ''; |
|
936 | - if( isset( $_GET['search_protocol'] ) ) |
|
937 | - $search .= $_GET['search_protocol']; |
|
938 | - if( isset( $_GET['search_slashes'] ) ) |
|
939 | - $search .= $_GET['search_slashes']; |
|
940 | - if( isset( $_GET['search'] ) ) |
|
941 | - $search .= $_GET['search']; |
|
942 | - |
|
943 | - return htmlspecialchars( trim( $search ) ); |
|
935 | + $search = ''; |
|
936 | + if( isset( $_GET['search_protocol'] ) ) |
|
937 | + $search .= $_GET['search_protocol']; |
|
938 | + if( isset( $_GET['search_slashes'] ) ) |
|
939 | + $search .= $_GET['search_slashes']; |
|
940 | + if( isset( $_GET['search'] ) ) |
|
941 | + $search .= $_GET['search']; |
|
942 | + |
|
943 | + return htmlspecialchars( trim( $search ) ); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | /** |
@@ -5,16 +5,16 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | function yourls_html_logo() { |
8 | - yourls_do_action( 'pre_html_logo' ); |
|
8 | + yourls_do_action('pre_html_logo'); |
|
9 | 9 | ?> |
10 | 10 | <header role="banner"> |
11 | 11 | <h1> |
12 | - <a href="<?php echo yourls_admin_url( 'index.php' ) ?>" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/> |
|
12 | + <a href="<?php echo yourls_admin_url('index.php') ?>" title="YOURLS"><span>YOURLS</span>: <span>Y</span>our <span>O</span>wn <span>URL</span> <span>S</span>hortener<br/> |
|
13 | 13 | <img src="<?php yourls_site_url(); ?>/images/yourls-logo.svg" id="yourls-logo" alt="YOURLS" title="YOURLS" /></a> |
14 | 14 | </h1> |
15 | 15 | </header> |
16 | 16 | <?php |
17 | - yourls_do_action( 'html_logo' ); |
|
17 | + yourls_do_action('html_logo'); |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -23,15 +23,15 @@ discard block |
||
23 | 23 | * @param string $context Context of the page (stats, index, infos, ...) |
24 | 24 | * @param string $title HTML title of the page |
25 | 25 | */ |
26 | -function yourls_html_head( $context = 'index', $title = '' ) { |
|
26 | +function yourls_html_head($context = 'index', $title = '') { |
|
27 | 27 | |
28 | - yourls_do_action( 'pre_html_head', $context, $title ); |
|
28 | + yourls_do_action('pre_html_head', $context, $title); |
|
29 | 29 | |
30 | 30 | // All components to false, except when specified true |
31 | 31 | $share = $insert = $tablesorter = $tabs = $cal = $charts = false; |
32 | 32 | |
33 | 33 | // Load components as needed |
34 | - switch ( $context ) { |
|
34 | + switch ($context) { |
|
35 | 35 | case 'infos': |
36 | 36 | $share = $tabs = $charts = true; |
37 | 37 | break; |
@@ -57,30 +57,30 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | // Force no cache for all admin pages |
60 | - if( yourls_is_admin() && !headers_sent() ) { |
|
60 | + if (yourls_is_admin() && !headers_sent()) { |
|
61 | 61 | yourls_no_cache_headers(); |
62 | - yourls_content_type_header( yourls_apply_filter( 'html_head_content-type', 'text/html' ) ); |
|
63 | - yourls_do_action( 'admin_headers', $context, $title ); |
|
62 | + yourls_content_type_header(yourls_apply_filter('html_head_content-type', 'text/html')); |
|
63 | + yourls_do_action('admin_headers', $context, $title); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Store page context |
67 | 67 | yourls_set_html_context($context); |
68 | 68 | |
69 | 69 | // Body class |
70 | - $bodyclass = yourls_apply_filter( 'bodyclass', '' ); |
|
71 | - $bodyclass .= ( yourls_is_mobile_device() ? 'mobile' : 'desktop' ); |
|
70 | + $bodyclass = yourls_apply_filter('bodyclass', ''); |
|
71 | + $bodyclass .= (yourls_is_mobile_device() ? 'mobile' : 'desktop'); |
|
72 | 72 | |
73 | 73 | // Page title |
74 | - $_title = 'YOURLS — Your Own URL Shortener | ' . yourls_link(); |
|
75 | - $title = $title ? $title . " « " . $_title : $_title; |
|
76 | - $title = yourls_apply_filter( 'html_title', $title, $context ); |
|
74 | + $_title = 'YOURLS — Your Own URL Shortener | '.yourls_link(); |
|
75 | + $title = $title ? $title." « ".$_title : $_title; |
|
76 | + $title = yourls_apply_filter('html_title', $title, $context); |
|
77 | 77 | |
78 | 78 | ?> |
79 | 79 | <!DOCTYPE html> |
80 | 80 | <html <?php yourls_html_language_attributes(); ?>> |
81 | 81 | <head> |
82 | 82 | <title><?php echo $title ?></title> |
83 | - <meta http-equiv="Content-Type" content="<?php echo yourls_apply_filter( 'html_head_meta_content-type', 'text/html; charset=utf-8' ); ?>" /> |
|
83 | + <meta http-equiv="Content-Type" content="<?php echo yourls_apply_filter('html_head_meta_content-type', 'text/html; charset=utf-8'); ?>" /> |
|
84 | 84 | <meta name="generator" content="YOURLS <?php echo YOURLS_VERSION ?>" /> |
85 | 85 | <meta name="description" content="YOURLS » Your Own URL Shortener' | <?php yourls_site_url(); ?>" /> |
86 | 86 | <?php yourls_do_action('html_head_meta', $context); ?> |
@@ -89,29 +89,29 @@ discard block |
||
89 | 89 | <script src="<?php yourls_site_url(); ?>/js/common.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
90 | 90 | <script src="<?php yourls_site_url(); ?>/js/jquery.notifybar.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
91 | 91 | <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/style.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" /> |
92 | - <?php if ( $tabs ) { ?> |
|
92 | + <?php if ($tabs) { ?> |
|
93 | 93 | <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/infos.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" /> |
94 | 94 | <script src="<?php yourls_site_url(); ?>/js/infos.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
95 | 95 | <?php } ?> |
96 | - <?php if ( $tablesorter ) { ?> |
|
96 | + <?php if ($tablesorter) { ?> |
|
97 | 97 | <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/tablesorter.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" /> |
98 | 98 | <script src="<?php yourls_site_url(); ?>/js/jquery-3.tablesorter.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
99 | 99 | <script src="<?php yourls_site_url(); ?>/js/tablesorte.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
100 | 100 | <?php } ?> |
101 | - <?php if ( $insert ) { ?> |
|
101 | + <?php if ($insert) { ?> |
|
102 | 102 | <script src="<?php yourls_site_url(); ?>/js/insert.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
103 | 103 | <?php } ?> |
104 | - <?php if ( $share ) { ?> |
|
104 | + <?php if ($share) { ?> |
|
105 | 105 | <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/share.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" /> |
106 | 106 | <script src="<?php yourls_site_url(); ?>/js/share.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
107 | 107 | <script src="<?php yourls_site_url(); ?>/js/clipboard.min.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
108 | 108 | <?php } ?> |
109 | - <?php if ( $cal ) { ?> |
|
109 | + <?php if ($cal) { ?> |
|
110 | 110 | <link rel="stylesheet" href="<?php yourls_site_url(); ?>/css/cal.css?v=<?php echo YOURLS_VERSION; ?>" type="text/css" media="screen" /> |
111 | 111 | <?php yourls_l10n_calendar_strings(); ?> |
112 | 112 | <script src="<?php yourls_site_url(); ?>/js/jquery.cal.js?v=<?php echo YOURLS_VERSION; ?>" type="text/javascript"></script> |
113 | 113 | <?php } ?> |
114 | - <?php if ( $charts ) { ?> |
|
114 | + <?php if ($charts) { ?> |
|
115 | 115 | <script type="text/javascript" src="https://www.google.com/jsapi"></script> |
116 | 116 | <script type="text/javascript"> |
117 | 117 | google.load('visualization', '1.0', {'packages':['corechart', 'geochart']}); |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | <?php } ?> |
120 | 120 | <script type="text/javascript"> |
121 | 121 | //<![CDATA[ |
122 | - var ajaxurl = '<?php echo yourls_admin_url( 'admin-ajax.php' ); ?>'; |
|
122 | + var ajaxurl = '<?php echo yourls_admin_url('admin-ajax.php'); ?>'; |
|
123 | 123 | //]]> |
124 | 124 | </script> |
125 | - <?php yourls_do_action( 'html_head', $context ); ?> |
|
125 | + <?php yourls_do_action('html_head', $context); ?> |
|
126 | 126 | </head> |
127 | 127 | <body class="<?php echo $context; ?> <?php echo $bodyclass; ?>"> |
128 | 128 | <div id="wrap"> |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * @return void |
140 | 140 | */ |
141 | 141 | function yourls_html_footer($can_query = true) { |
142 | - if($can_query & yourls_get_debug_mode()) { |
|
142 | + if ($can_query & yourls_get_debug_mode()) { |
|
143 | 143 | $num_queries = yourls_get_num_queries(); |
144 | - $num_queries = ' – '. sprintf( yourls_n( '1 query', '%s queries', $num_queries ), $num_queries ); |
|
144 | + $num_queries = ' – '.sprintf(yourls_n('1 query', '%s queries', $num_queries), $num_queries); |
|
145 | 145 | } else { |
146 | 146 | $num_queries = ''; |
147 | 147 | } |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | </div><?php // wrap ?> |
151 | 151 | <footer id="footer" role="contentinfo"><p> |
152 | 152 | <?php |
153 | - $footer = yourls_s( 'Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v ' . YOURLS_VERSION ); |
|
153 | + $footer = yourls_s('Powered by %s', '<a href="http://yourls.org/" title="YOURLS">YOURLS</a> v '.YOURLS_VERSION); |
|
154 | 154 | $footer .= $num_queries; |
155 | - echo yourls_apply_filter( 'html_footer_text', $footer ); |
|
155 | + echo yourls_apply_filter('html_footer_text', $footer); |
|
156 | 156 | ?> |
157 | 157 | </p></footer> |
158 | - <?php if( yourls_get_debug_mode() ) { |
|
158 | + <?php if (yourls_get_debug_mode()) { |
|
159 | 159 | echo '<div style="text-align:left"><pre>'; |
160 | - echo join( "\n", yourls_get_debug_log() ); |
|
160 | + echo join("\n", yourls_get_debug_log()); |
|
161 | 161 | echo '</pre></div>'; |
162 | 162 | } ?> |
163 | - <?php yourls_do_action( 'html_footer', yourls_get_html_context() ); ?> |
|
163 | + <?php yourls_do_action('html_footer', yourls_get_html_context()); ?> |
|
164 | 164 | </body> |
165 | 165 | </html> |
166 | 166 | <?php |
@@ -172,9 +172,9 @@ discard block |
||
172 | 172 | * @param string $url URL to prefill the input with |
173 | 173 | * @param string $keyword Keyword to prefill the input with |
174 | 174 | */ |
175 | -function yourls_html_addnew( $url = '', $keyword = '' ) { |
|
176 | - $pre = yourls_apply_filter( 'shunt_html_addnew', false, $url, $keyword ); |
|
177 | - if ( false !== $pre ) { |
|
175 | +function yourls_html_addnew($url = '', $keyword = '') { |
|
176 | + $pre = yourls_apply_filter('shunt_html_addnew', false, $url, $keyword); |
|
177 | + if (false !== $pre) { |
|
178 | 178 | return $pre; |
179 | 179 | } |
180 | 180 | ?> |
@@ -183,17 +183,17 @@ discard block |
||
183 | 183 | <div> |
184 | 184 | <form id="new_url_form" action="" method="get"> |
185 | 185 | <div> |
186 | - <label for="add-url"><strong><?php yourls_e( 'Enter the URL' ); ?></strong></label>: |
|
186 | + <label for="add-url"><strong><?php yourls_e('Enter the URL'); ?></strong></label>: |
|
187 | 187 | <input type="text" id="add-url" name="url" value="<?php echo $url; ?>" class="text" size="80" placeholder="https://" /> |
188 | - <label for="add-keyword"><?php yourls_e( 'Optional '); ?> : <strong><?php yourls_e('Custom short URL'); ?></strong></label>: |
|
188 | + <label for="add-keyword"><?php yourls_e('Optional '); ?> : <strong><?php yourls_e('Custom short URL'); ?></strong></label>: |
|
189 | 189 | <input type="text" id="add-keyword" name="keyword" value="<?php echo $keyword; ?>" class="text" size="8" /> |
190 | - <?php yourls_nonce_field( 'add_url', 'nonce-add' ); ?> |
|
191 | - <input type="button" id="add-button" name="add-button" value="<?php yourls_e( 'Shorten The URL' ); ?>" class="button" onclick="add_link();" /> |
|
190 | + <?php yourls_nonce_field('add_url', 'nonce-add'); ?> |
|
191 | + <input type="button" id="add-button" name="add-button" value="<?php yourls_e('Shorten The URL'); ?>" class="button" onclick="add_link();" /> |
|
192 | 192 | </div> |
193 | 193 | </form> |
194 | 194 | <div id="feedback" style="display:none"></div> |
195 | 195 | </div> |
196 | - <?php yourls_do_action( 'html_addnew' ); ?> |
|
196 | + <?php yourls_do_action('html_addnew'); ?> |
|
197 | 197 | </div> |
198 | 198 | <?php |
199 | 199 | } |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | * @param array $params Array of all required parameters |
207 | 207 | * @return string Result |
208 | 208 | */ |
209 | -function yourls_html_tfooter( $params = array() ) { |
|
209 | +function yourls_html_tfooter($params = array()) { |
|
210 | 210 | // Manually extract all parameters from the array. We prefer doing it this way, over using extract(), |
211 | 211 | // to make things clearer and more explicit about what var is used. |
212 | 212 | $search = $params['search']; |
@@ -233,54 +233,54 @@ discard block |
||
233 | 233 | <?php |
234 | 234 | |
235 | 235 | // First search control: text to search |
236 | - $_input = '<input aria-label="' .yourls__( 'Search for' ). '" type="text" name="search" class="text" size="12" value="' . yourls_esc_attr( $search_text ) . '" />'; |
|
236 | + $_input = '<input aria-label="'.yourls__('Search for').'" type="text" name="search" class="text" size="12" value="'.yourls_esc_attr($search_text).'" />'; |
|
237 | 237 | $_options = array( |
238 | - 'all' => yourls__( 'All fields' ), |
|
239 | - 'keyword' => yourls__( 'Short URL' ), |
|
240 | - 'url' => yourls__( 'URL' ), |
|
241 | - 'title' => yourls__( 'Title' ), |
|
242 | - 'ip' => yourls__( 'IP' ), |
|
238 | + 'all' => yourls__('All fields'), |
|
239 | + 'keyword' => yourls__('Short URL'), |
|
240 | + 'url' => yourls__('URL'), |
|
241 | + 'title' => yourls__('Title'), |
|
242 | + 'ip' => yourls__('IP'), |
|
243 | 243 | ); |
244 | - $_select = yourls_html_select( 'search_in', $_options, $search_in, false, yourls__( 'Search in' ) ); |
|
244 | + $_select = yourls_html_select('search_in', $_options, $search_in, false, yourls__('Search in')); |
|
245 | 245 | /* //translators: "Search for <input field with text to search> in <select dropdown with URL, title...>" */ |
246 | - yourls_se( 'Search for %1$s in %2$s', $_input , $_select ); |
|
246 | + yourls_se('Search for %1$s in %2$s', $_input, $_select); |
|
247 | 247 | echo "–\n"; |
248 | 248 | |
249 | 249 | // Second search control: order by |
250 | 250 | $_options = array( |
251 | - 'keyword' => yourls__( 'Short URL' ), |
|
252 | - 'url' => yourls__( 'URL' ), |
|
253 | - 'title' => yourls__( 'Title' ), |
|
254 | - 'timestamp' => yourls__( 'Date' ), |
|
255 | - 'ip' => yourls__( 'IP' ), |
|
256 | - 'clicks' => yourls__( 'Clicks' ), |
|
251 | + 'keyword' => yourls__('Short URL'), |
|
252 | + 'url' => yourls__('URL'), |
|
253 | + 'title' => yourls__('Title'), |
|
254 | + 'timestamp' => yourls__('Date'), |
|
255 | + 'ip' => yourls__('IP'), |
|
256 | + 'clicks' => yourls__('Clicks'), |
|
257 | 257 | ); |
258 | - $_select = yourls_html_select( 'sort_by', $_options, $sort_by, false, yourls__( 'Sort by' ) ); |
|
259 | - $sort_order = isset( $sort_order ) ? $sort_order : 'desc' ; |
|
258 | + $_select = yourls_html_select('sort_by', $_options, $sort_by, false, yourls__('Sort by')); |
|
259 | + $sort_order = isset($sort_order) ? $sort_order : 'desc'; |
|
260 | 260 | $_options = array( |
261 | - 'asc' => yourls__( 'Ascending' ), |
|
262 | - 'desc' => yourls__( 'Descending' ), |
|
261 | + 'asc' => yourls__('Ascending'), |
|
262 | + 'desc' => yourls__('Descending'), |
|
263 | 263 | ); |
264 | - $_select2 = yourls_html_select( 'sort_order', $_options, $sort_order, false, yourls__( 'Sort order' ) ); |
|
264 | + $_select2 = yourls_html_select('sort_order', $_options, $sort_order, false, yourls__('Sort order')); |
|
265 | 265 | /* //translators: "Order by <criteria dropdown (date, clicks...)> in <order dropdown (Descending or Ascending)>" */ |
266 | - yourls_se( 'Order by %1$s %2$s', $_select , $_select2 ); |
|
266 | + yourls_se('Order by %1$s %2$s', $_select, $_select2); |
|
267 | 267 | echo "–\n"; |
268 | 268 | |
269 | 269 | // Third search control: Show XX rows |
270 | 270 | /* //translators: "Show <text field> rows" */ |
271 | - $_input = '<input aria-label="' .yourls__( 'Number of rows to show' ). '" type="text" name="perpage" class="text" size="2" value="' . $perpage . '" />'; |
|
272 | - yourls_se( 'Show %s rows', $_input ); |
|
271 | + $_input = '<input aria-label="'.yourls__('Number of rows to show').'" type="text" name="perpage" class="text" size="2" value="'.$perpage.'" />'; |
|
272 | + yourls_se('Show %s rows', $_input); |
|
273 | 273 | echo "<br/>\n"; |
274 | 274 | |
275 | 275 | // Fourth search control: Show links with more than XX clicks |
276 | 276 | $_options = array( |
277 | - 'more' => yourls__( 'more' ), |
|
278 | - 'less' => yourls__( 'less' ), |
|
277 | + 'more' => yourls__('more'), |
|
278 | + 'less' => yourls__('less'), |
|
279 | 279 | ); |
280 | - $_select = yourls_html_select( 'click_filter', $_options, $click_filter, false, yourls__( 'Show links with' ) ); |
|
281 | - $_input = '<input aria-label="' .yourls__( 'Number of clicks' ). '" type="text" name="click_limit" class="text" size="4" value="' . $click_limit . '" /> '; |
|
280 | + $_select = yourls_html_select('click_filter', $_options, $click_filter, false, yourls__('Show links with')); |
|
281 | + $_input = '<input aria-label="'.yourls__('Number of clicks').'" type="text" name="click_limit" class="text" size="4" value="'.$click_limit.'" /> '; |
|
282 | 282 | /* //translators: "Show links with <more/less> than <text field> clicks" */ |
283 | - yourls_se( 'Show links with %1$s than %2$s clicks', $_select, $_input ); |
|
283 | + yourls_se('Show links with %1$s than %2$s clicks', $_select, $_input); |
|
284 | 284 | echo "<br/>\n"; |
285 | 285 | |
286 | 286 | // Fifth search control: Show links created before/after/between ... |
@@ -289,12 +289,12 @@ discard block |
||
289 | 289 | 'after' => yourls__('after'), |
290 | 290 | 'between' => yourls__('between'), |
291 | 291 | ); |
292 | - $_select = yourls_html_select( 'date_filter', $_options, $date_filter, false, yourls__('Show links created') ); |
|
293 | - $_input = '<input aria-label="' .yourls__('Select a date') . '" type="text" name="date_first" id="date_first" class="text" size="12" value="' . $date_first . '" />'; |
|
294 | - $_and = '<span id="date_and"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '> & </span>'; |
|
295 | - $_input2 = '<input aria-label="' .yourls__('Select an end date') . '" type="text" name="date_second" id="date_second" class="text" size="12" value="' . $date_second . '"' . ( $date_filter === 'between' ? ' style="display:inline"' : '' ) . '/>'; |
|
292 | + $_select = yourls_html_select('date_filter', $_options, $date_filter, false, yourls__('Show links created')); |
|
293 | + $_input = '<input aria-label="'.yourls__('Select a date').'" type="text" name="date_first" id="date_first" class="text" size="12" value="'.$date_first.'" />'; |
|
294 | + $_and = '<span id="date_and"'.($date_filter === 'between' ? ' style="display:inline"' : '').'> & </span>'; |
|
295 | + $_input2 = '<input aria-label="'.yourls__('Select an end date').'" type="text" name="date_second" id="date_second" class="text" size="12" value="'.$date_second.'"'.($date_filter === 'between' ? ' style="display:inline"' : '').'/>'; |
|
296 | 296 | /* //translators: "Show links created <before/after/between> <date input> <"and" if applicable> <date input if applicable>" */ |
297 | - yourls_se( 'Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2 ); |
|
297 | + yourls_se('Show links created %1$s %2$s %3$s %4$s', $_select, $_input, $_and, $_input2); |
|
298 | 298 | ?> |
299 | 299 | |
300 | 300 | <div id="filter_buttons"> |
@@ -309,40 +309,40 @@ discard block |
||
309 | 309 | |
310 | 310 | <?php |
311 | 311 | // Remove empty keys from the $params array so it doesn't clutter the pagination links |
312 | - $params = array_filter( $params, 'yourls_return_if_not_empty_string' ); // remove empty keys |
|
312 | + $params = array_filter($params, 'yourls_return_if_not_empty_string'); // remove empty keys |
|
313 | 313 | |
314 | - if( isset( $search_text ) ) { |
|
314 | + if (isset($search_text)) { |
|
315 | 315 | $params['search'] = $search_text; |
316 | - unset( $params['search_text'] ); |
|
316 | + unset($params['search_text']); |
|
317 | 317 | } |
318 | 318 | ?> |
319 | 319 | |
320 | 320 | <div id="pagination"> |
321 | 321 | <span class="navigation"> |
322 | - <?php if( $total_pages > 1 ) { ?> |
|
323 | - <span class="nav_total"><?php echo sprintf( yourls_n( '1 page', '%s pages', $total_pages ), $total_pages ); ?></span> |
|
322 | + <?php if ($total_pages > 1) { ?> |
|
323 | + <span class="nav_total"><?php echo sprintf(yourls_n('1 page', '%s pages', $total_pages), $total_pages); ?></span> |
|
324 | 324 | <?php |
325 | - $base_page = yourls_admin_url( 'index.php' ); |
|
325 | + $base_page = yourls_admin_url('index.php'); |
|
326 | 326 | // Pagination offsets: min( max ( zomg! ) ); |
327 | - $p_start = max( min( $total_pages - 4, $page - 2 ), 1 ); |
|
328 | - $p_end = min( max( 5, $page + 2 ), $total_pages ); |
|
329 | - if( $p_start >= 2 ) { |
|
330 | - $link = yourls_add_query_arg( array_merge( $params, array( 'page' => 1 ) ), $base_page ); |
|
331 | - echo '<span class="nav_link nav_first"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to First Page') . '">' . yourls__( '« First' ) . '</a></span>'; |
|
327 | + $p_start = max(min($total_pages - 4, $page - 2), 1); |
|
328 | + $p_end = min(max(5, $page + 2), $total_pages); |
|
329 | + if ($p_start >= 2) { |
|
330 | + $link = yourls_add_query_arg(array_merge($params, array('page' => 1)), $base_page); |
|
331 | + echo '<span class="nav_link nav_first"><a href="'.$link.'" title="'.yourls_esc_attr__('Go to First Page').'">'.yourls__('« First').'</a></span>'; |
|
332 | 332 | echo '<span class="nav_link nav_prev"></span>'; |
333 | 333 | } |
334 | - for( $i = $p_start ; $i <= $p_end; $i++ ) { |
|
335 | - if( $i == $page ) { |
|
334 | + for ($i = $p_start; $i <= $p_end; $i++) { |
|
335 | + if ($i == $page) { |
|
336 | 336 | echo "<span class='nav_link nav_current'>$i</span>"; |
337 | 337 | } else { |
338 | - $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $i ) ), $base_page ); |
|
339 | - echo '<span class="nav_link nav_goto"><a href="' . $link . '" title="' . sprintf( yourls_esc_attr( 'Page %s' ), $i ) .'">'.$i.'</a></span>'; |
|
338 | + $link = yourls_add_query_arg(array_merge($params, array('page' => $i)), $base_page); |
|
339 | + echo '<span class="nav_link nav_goto"><a href="'.$link.'" title="'.sprintf(yourls_esc_attr('Page %s'), $i).'">'.$i.'</a></span>'; |
|
340 | 340 | } |
341 | 341 | } |
342 | - if( ( $p_end ) < $total_pages ) { |
|
343 | - $link = yourls_add_query_arg( array_merge( $params, array( 'page' => $total_pages ) ), $base_page ); |
|
342 | + if (($p_end) < $total_pages) { |
|
343 | + $link = yourls_add_query_arg(array_merge($params, array('page' => $total_pages)), $base_page); |
|
344 | 344 | echo '<span class="nav_link nav_next"></span>'; |
345 | - echo '<span class="nav_link nav_last"><a href="' . $link . '" title="' . yourls_esc_attr__('Go to Last Page') . '">' . yourls__( 'Last »' ) . '</a></span>'; |
|
345 | + echo '<span class="nav_link nav_last"><a href="'.$link.'" title="'.yourls_esc_attr__('Go to Last Page').'">'.yourls__('Last »').'</a></span>'; |
|
346 | 346 | } |
347 | 347 | ?> |
348 | 348 | <?php } ?> |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | </div> |
351 | 351 | </th> |
352 | 352 | </tr> |
353 | - <?php yourls_do_action( 'html_tfooter' ); ?> |
|
353 | + <?php yourls_do_action('html_tfooter'); ?> |
|
354 | 354 | </tfoot> |
355 | 355 | <?php |
356 | 356 | } |
@@ -367,16 +367,16 @@ discard block |
||
367 | 367 | * @param string $label ARIA label of the element |
368 | 368 | * @return string HTML content of the select element |
369 | 369 | */ |
370 | -function yourls_html_select( $name, $options, $selected = '', $display = false, $label = '' ) { |
|
370 | +function yourls_html_select($name, $options, $selected = '', $display = false, $label = '') { |
|
371 | 371 | $html = "<select aria-label='$label' name='$name' id='$name' size='1'>\n"; |
372 | - foreach( $options as $value => $text ) { |
|
372 | + foreach ($options as $value => $text) { |
|
373 | 373 | $html .= "<option value='$value' "; |
374 | 374 | $html .= $selected == $value ? ' selected="selected"' : ''; |
375 | 375 | $html .= ">$text</option>\n"; |
376 | 376 | } |
377 | 377 | $html .= "</select>\n"; |
378 | - $html = yourls_apply_filter( 'html_select', $html, $name, $options, $selected, $display ); |
|
379 | - if( $display ) |
|
378 | + $html = yourls_apply_filter('html_select', $html, $name, $options, $selected, $display); |
|
379 | + if ($display) |
|
380 | 380 | echo $html; |
381 | 381 | return $html; |
382 | 382 | } |
@@ -385,51 +385,51 @@ discard block |
||
385 | 385 | * Display the Quick Share box |
386 | 386 | * |
387 | 387 | */ |
388 | -function yourls_share_box( $longurl, $shorturl, $title = '', $text='', $shortlink_title = '', $share_title = '', $hidden = false ) { |
|
389 | - if ( $shortlink_title == '' ) |
|
390 | - $shortlink_title = '<h2>' . yourls__( 'Your short link' ) . '</h2>'; |
|
391 | - if ( $share_title == '' ) |
|
392 | - $share_title = '<h2>' . yourls__( 'Quick Share' ) . '</h2>'; |
|
388 | +function yourls_share_box($longurl, $shorturl, $title = '', $text = '', $shortlink_title = '', $share_title = '', $hidden = false) { |
|
389 | + if ($shortlink_title == '') |
|
390 | + $shortlink_title = '<h2>'.yourls__('Your short link').'</h2>'; |
|
391 | + if ($share_title == '') |
|
392 | + $share_title = '<h2>'.yourls__('Quick Share').'</h2>'; |
|
393 | 393 | |
394 | 394 | // Allow plugins to short-circuit the whole function |
395 | - $pre = yourls_apply_filter( 'shunt_share_box', false ); |
|
396 | - if ( false !== $pre ) |
|
395 | + $pre = yourls_apply_filter('shunt_share_box', false); |
|
396 | + if (false !== $pre) |
|
397 | 397 | return $pre; |
398 | 398 | |
399 | 399 | // Make sure IDN domains are in their UTF8 form |
400 | 400 | $shorturl = yourls_normalize_uri($shorturl); |
401 | 401 | |
402 | - $text = ( $text ? '"'.$text.'" ' : '' ); |
|
403 | - $title = ( $title ? "$title " : '' ); |
|
404 | - $share = yourls_esc_textarea( $title.$text.$shorturl ); |
|
405 | - $count = 280 - strlen( $share ); |
|
406 | - $hidden = ( $hidden ? 'style="display:none;"' : '' ); |
|
402 | + $text = ($text ? '"'.$text.'" ' : ''); |
|
403 | + $title = ($title ? "$title " : ''); |
|
404 | + $share = yourls_esc_textarea($title.$text.$shorturl); |
|
405 | + $count = 280 - strlen($share); |
|
406 | + $hidden = ($hidden ? 'style="display:none;"' : ''); |
|
407 | 407 | |
408 | 408 | // Allow plugins to filter all data |
409 | - $data = compact( 'longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden' ); |
|
410 | - $data = yourls_apply_filter( 'share_box_data', $data ); |
|
411 | - extract( $data ); |
|
409 | + $data = compact('longurl', 'shorturl', 'title', 'text', 'shortlink_title', 'share_title', 'share', 'count', 'hidden'); |
|
410 | + $data = yourls_apply_filter('share_box_data', $data); |
|
411 | + extract($data); |
|
412 | 412 | |
413 | - $_share = rawurlencode( $share ); |
|
414 | - $_url = rawurlencode( $shorturl ); |
|
413 | + $_share = rawurlencode($share); |
|
414 | + $_url = rawurlencode($shorturl); |
|
415 | 415 | ?> |
416 | 416 | |
417 | 417 | <div id="shareboxes" <?php echo $hidden; ?>> |
418 | 418 | |
419 | - <?php yourls_do_action( 'shareboxes_before', $longurl, $shorturl, $title, $text ); ?> |
|
419 | + <?php yourls_do_action('shareboxes_before', $longurl, $shorturl, $title, $text); ?> |
|
420 | 420 | |
421 | 421 | <div id="copybox" class="share"> |
422 | 422 | <?php echo $shortlink_title; ?> |
423 | - <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url( $shorturl ); ?>" /></p> |
|
424 | - <p><small><?php yourls_e( 'Long link' ); ?>: <a id="origlink" href="<?php echo yourls_esc_url( $longurl ); ?>"><?php echo yourls_esc_url( $longurl ); ?></a></small> |
|
425 | - <?php if( yourls_do_log_redirect() ) { ?> |
|
426 | - <br/><small><?php yourls_e( 'Stats' ); ?>: <a id="statlink" href="<?php echo yourls_esc_url( $shorturl ); ?>+"><?php echo yourls_esc_url( $shorturl ); ?>+</a></small> |
|
427 | - <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr( $title ); ?>" /> |
|
423 | + <p><input id="copylink" class="text" size="32" value="<?php echo yourls_esc_url($shorturl); ?>" /></p> |
|
424 | + <p><small><?php yourls_e('Long link'); ?>: <a id="origlink" href="<?php echo yourls_esc_url($longurl); ?>"><?php echo yourls_esc_url($longurl); ?></a></small> |
|
425 | + <?php if (yourls_do_log_redirect()) { ?> |
|
426 | + <br/><small><?php yourls_e('Stats'); ?>: <a id="statlink" href="<?php echo yourls_esc_url($shorturl); ?>+"><?php echo yourls_esc_url($shorturl); ?>+</a></small> |
|
427 | + <input type="hidden" id="titlelink" value="<?php echo yourls_esc_attr($title); ?>" /> |
|
428 | 428 | <?php } ?> |
429 | 429 | </p> |
430 | 430 | </div> |
431 | 431 | |
432 | - <?php yourls_do_action( 'shareboxes_middle', $longurl, $shorturl, $title, $text ); ?> |
|
432 | + <?php yourls_do_action('shareboxes_middle', $longurl, $shorturl, $title, $text); ?> |
|
433 | 433 | |
434 | 434 | <div id="sharebox" class="share"> |
435 | 435 | <?php echo $share_title; ?> |
@@ -437,17 +437,17 @@ discard block |
||
437 | 437 | <span id="charcount" class="hide-if-no-js"><?php echo $count; ?></span> |
438 | 438 | <textarea id="tweet_body"><?php echo $share; ?></textarea> |
439 | 439 | </div> |
440 | - <p id="share_links"><?php yourls_e( 'Share with' ); ?> |
|
441 | - <a id="share_tw" href="https://twitter.com/intent/tweet?text=<?php echo $_share; ?>" title="<?php yourls_e( 'Tweet this!' ); ?>" onclick="share('tw');return false">Twitter</a> |
|
442 | - <a id="share_fb" href="https://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e( 'Share on Facebook' ); ?>" onclick="share('fb');return false;">Facebook</a> |
|
440 | + <p id="share_links"><?php yourls_e('Share with'); ?> |
|
441 | + <a id="share_tw" href="https://twitter.com/intent/tweet?text=<?php echo $_share; ?>" title="<?php yourls_e('Tweet this!'); ?>" onclick="share('tw');return false">Twitter</a> |
|
442 | + <a id="share_fb" href="https://www.facebook.com/share.php?u=<?php echo $_url; ?>" title="<?php yourls_e('Share on Facebook'); ?>" onclick="share('fb');return false;">Facebook</a> |
|
443 | 443 | <?php |
444 | - yourls_do_action( 'share_links', $longurl, $shorturl, $title, $text ); |
|
444 | + yourls_do_action('share_links', $longurl, $shorturl, $title, $text); |
|
445 | 445 | // Note: on the main admin page, there are no parameters passed to the sharebox when it's drawn. |
446 | 446 | ?> |
447 | 447 | </p> |
448 | 448 | </div> |
449 | 449 | |
450 | - <?php yourls_do_action( 'shareboxes_after', $longurl, $shorturl, $title, $text ); ?> |
|
450 | + <?php yourls_do_action('shareboxes_after', $longurl, $shorturl, $title, $text); ?> |
|
451 | 451 | |
452 | 452 | </div> |
453 | 453 | |
@@ -458,20 +458,20 @@ discard block |
||
458 | 458 | * Die die die |
459 | 459 | * |
460 | 460 | */ |
461 | -function yourls_die( $message = '', $title = '', $header_code = 200 ) { |
|
462 | - yourls_do_action( 'pre_yourls_die', $message, $title, $header_code ); |
|
461 | +function yourls_die($message = '', $title = '', $header_code = 200) { |
|
462 | + yourls_do_action('pre_yourls_die', $message, $title, $header_code); |
|
463 | 463 | |
464 | - yourls_status_header( $header_code ); |
|
464 | + yourls_status_header($header_code); |
|
465 | 465 | |
466 | - if( !yourls_did_action( 'html_head' ) ) { |
|
466 | + if (!yourls_did_action('html_head')) { |
|
467 | 467 | yourls_html_head(); |
468 | 468 | yourls_html_logo(); |
469 | 469 | } |
470 | - echo yourls_apply_filter( 'die_title', "<h2>$title</h2>" ); |
|
471 | - echo yourls_apply_filter( 'die_message', "<p>$message</p>" ); |
|
470 | + echo yourls_apply_filter('die_title', "<h2>$title</h2>"); |
|
471 | + echo yourls_apply_filter('die_message', "<p>$message</p>"); |
|
472 | 472 | // Hook into 'yourls_die' to add more elements or messages to that page |
473 | - yourls_do_action( 'yourls_die' ); |
|
474 | - if( !yourls_did_action( 'html_footer' ) ) { |
|
473 | + yourls_do_action('yourls_die'); |
|
474 | + if (!yourls_did_action('html_footer')) { |
|
475 | 475 | yourls_html_footer(false); |
476 | 476 | } |
477 | 477 | die(); |
@@ -483,33 +483,33 @@ discard block |
||
483 | 483 | * @param string $keyword Keyword to edit |
484 | 484 | * @return string HTML of the edit row |
485 | 485 | */ |
486 | -function yourls_table_edit_row( $keyword ) { |
|
486 | +function yourls_table_edit_row($keyword) { |
|
487 | 487 | $keyword = yourls_sanitize_keyword($keyword); |
488 | - $id = yourls_string2htmlid( $keyword ); // used as HTML #id |
|
489 | - $url = yourls_get_keyword_longurl( $keyword ); |
|
490 | - $title = htmlspecialchars( yourls_get_keyword_title( $keyword ) ); |
|
491 | - $safe_url = yourls_esc_attr( $url ); |
|
492 | - $safe_title = yourls_esc_attr( $title ); |
|
493 | - $safe_keyword = yourls_esc_attr( $keyword ); |
|
488 | + $id = yourls_string2htmlid($keyword); // used as HTML #id |
|
489 | + $url = yourls_get_keyword_longurl($keyword); |
|
490 | + $title = htmlspecialchars(yourls_get_keyword_title($keyword)); |
|
491 | + $safe_url = yourls_esc_attr($url); |
|
492 | + $safe_title = yourls_esc_attr($title); |
|
493 | + $safe_keyword = yourls_esc_attr($keyword); |
|
494 | 494 | |
495 | 495 | // Make strings sprintf() safe: '%' -> '%%' |
496 | - $safe_url = str_replace( '%', '%%', $safe_url ); |
|
497 | - $safe_title = str_replace( '%', '%%', $safe_title ); |
|
496 | + $safe_url = str_replace('%', '%%', $safe_url); |
|
497 | + $safe_title = str_replace('%', '%%', $safe_title); |
|
498 | 498 | |
499 | 499 | $www = yourls_link(); |
500 | 500 | |
501 | - $nonce = yourls_create_nonce( 'edit-save_'.$id ); |
|
501 | + $nonce = yourls_create_nonce('edit-save_'.$id); |
|
502 | 502 | |
503 | - if( $url ) { |
|
503 | + if ($url) { |
|
504 | 504 | $return = <<<RETURN |
505 | 505 | <tr id="edit-$id" class="edit-row"><td colspan="5" class="edit-row"><strong>%s</strong>:<input type="text" id="edit-url-$id" name="edit-url-$id" value="$safe_url" class="text" size="70" /><br/><strong>%s</strong>: $www<input type="text" id="edit-keyword-$id" name="edit-keyword-$id" value="$safe_keyword" class="text" size="10" /><br/><strong>%s</strong>: <input type="text" id="edit-title-$id" name="edit-title-$id" value="$safe_title" class="text" size="60" /></td><td colspan="1"><input type="button" id="edit-submit-$id" name="edit-submit-$id" value="%s" title="%s" class="button" onclick="edit_link_save('$id');" /> <input type="button" id="edit-close-$id" name="edit-close-$id" value="%s" title="%s" class="button" onclick="edit_link_hide('$id');" /><input type="hidden" id="old_keyword_$id" value="$safe_keyword"/><input type="hidden" id="nonce_$id" value="$nonce"/></td></tr> |
506 | 506 | RETURN; |
507 | - $return = sprintf( $return, yourls__( 'Long URL' ), yourls__( 'Short URL' ), yourls__( 'Title' ), yourls__( 'Save' ), yourls__( 'Save new values' ), yourls__( 'Cancel' ), yourls__( 'Cancel editing' ) ); |
|
507 | + $return = sprintf($return, yourls__('Long URL'), yourls__('Short URL'), yourls__('Title'), yourls__('Save'), yourls__('Save new values'), yourls__('Cancel'), yourls__('Cancel editing')); |
|
508 | 508 | } else { |
509 | - $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">' . yourls__( 'Error, URL not found' ) . '</td></tr>'; |
|
509 | + $return = '<tr class="edit-row notfound"><td colspan="6" class="edit-row notfound">'.yourls__('Error, URL not found').'</td></tr>'; |
|
510 | 510 | } |
511 | 511 | |
512 | - $return = yourls_apply_filter( 'table_edit_row', $return, $keyword, $url, $title ); |
|
512 | + $return = yourls_apply_filter('table_edit_row', $return, $keyword, $url, $title); |
|
513 | 513 | |
514 | 514 | return $return; |
515 | 515 | } |
@@ -519,19 +519,19 @@ discard block |
||
519 | 519 | * |
520 | 520 | * @return string HTML of the edit row |
521 | 521 | */ |
522 | -function yourls_table_add_row( $keyword, $url, $title = '', $ip, $clicks, $timestamp ) { |
|
523 | - $keyword = yourls_sanitize_keyword($keyword); |
|
524 | - $id = yourls_string2htmlid( $keyword ); // used as HTML #id |
|
525 | - $shorturl = yourls_link( $keyword ); |
|
522 | +function yourls_table_add_row($keyword, $url, $title = '', $ip, $clicks, $timestamp) { |
|
523 | + $keyword = yourls_sanitize_keyword($keyword); |
|
524 | + $id = yourls_string2htmlid($keyword); // used as HTML #id |
|
525 | + $shorturl = yourls_link($keyword); |
|
526 | 526 | |
527 | - $statlink = yourls_statlink( $keyword ); |
|
527 | + $statlink = yourls_statlink($keyword); |
|
528 | 528 | |
529 | - $delete_link = yourls_nonce_url( 'delete-link_'.$id, |
|
530 | - yourls_add_query_arg( array( 'id' => $id, 'action' => 'delete', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) |
|
529 | + $delete_link = yourls_nonce_url('delete-link_'.$id, |
|
530 | + yourls_add_query_arg(array('id' => $id, 'action' => 'delete', 'keyword' => $keyword), yourls_admin_url('admin-ajax.php')) |
|
531 | 531 | ); |
532 | 532 | |
533 | - $edit_link = yourls_nonce_url( 'edit-link_'.$id, |
|
534 | - yourls_add_query_arg( array( 'id' => $id, 'action' => 'edit', 'keyword' => $keyword ), yourls_admin_url( 'admin-ajax.php' ) ) |
|
533 | + $edit_link = yourls_nonce_url('edit-link_'.$id, |
|
534 | + yourls_add_query_arg(array('id' => $id, 'action' => 'edit', 'keyword' => $keyword), yourls_admin_url('admin-ajax.php')) |
|
535 | 535 | ); |
536 | 536 | |
537 | 537 | // Action link buttons: the array |
@@ -539,69 +539,69 @@ discard block |
||
539 | 539 | 'stats' => array( |
540 | 540 | 'href' => $statlink, |
541 | 541 | 'id' => "statlink-$id", |
542 | - 'title' => yourls_esc_attr__( 'Stats' ), |
|
543 | - 'anchor' => yourls__( 'Stats' ), |
|
542 | + 'title' => yourls_esc_attr__('Stats'), |
|
543 | + 'anchor' => yourls__('Stats'), |
|
544 | 544 | ), |
545 | 545 | 'share' => array( |
546 | 546 | 'href' => '', |
547 | 547 | 'id' => "share-button-$id", |
548 | - 'title' => yourls_esc_attr__( 'Share' ), |
|
549 | - 'anchor' => yourls__( 'Share' ), |
|
548 | + 'title' => yourls_esc_attr__('Share'), |
|
549 | + 'anchor' => yourls__('Share'), |
|
550 | 550 | 'onclick' => "toggle_share('$id');return false;", |
551 | 551 | ), |
552 | 552 | 'edit' => array( |
553 | 553 | 'href' => $edit_link, |
554 | 554 | 'id' => "edit-button-$id", |
555 | - 'title' => yourls_esc_attr__( 'Edit' ), |
|
556 | - 'anchor' => yourls__( 'Edit' ), |
|
555 | + 'title' => yourls_esc_attr__('Edit'), |
|
556 | + 'anchor' => yourls__('Edit'), |
|
557 | 557 | 'onclick' => "edit_link_display('$id');return false;", |
558 | 558 | ), |
559 | 559 | 'delete' => array( |
560 | 560 | 'href' => $delete_link, |
561 | 561 | 'id' => "delete-button-$id", |
562 | - 'title' => yourls_esc_attr__( 'Delete' ), |
|
563 | - 'anchor' => yourls__( 'Delete' ), |
|
562 | + 'title' => yourls_esc_attr__('Delete'), |
|
563 | + 'anchor' => yourls__('Delete'), |
|
564 | 564 | 'onclick' => "remove_link('$id');return false;", |
565 | 565 | ) |
566 | 566 | ); |
567 | - $actions = yourls_apply_filter( 'table_add_row_action_array', $actions, $keyword ); |
|
567 | + $actions = yourls_apply_filter('table_add_row_action_array', $actions, $keyword); |
|
568 | 568 | |
569 | 569 | // Action link buttons: the HTML |
570 | 570 | $action_links = ''; |
571 | - foreach( $actions as $key => $action ) { |
|
572 | - $onclick = isset( $action['onclick'] ) ? 'onclick="' . $action['onclick'] . '"' : '' ; |
|
573 | - $action_links .= sprintf( '<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>', |
|
571 | + foreach ($actions as $key => $action) { |
|
572 | + $onclick = isset($action['onclick']) ? 'onclick="'.$action['onclick'].'"' : ''; |
|
573 | + $action_links .= sprintf('<a href="%s" id="%s" title="%s" class="%s" %s>%s</a>', |
|
574 | 574 | $action['href'], $action['id'], $action['title'], 'button button_'.$key, $onclick, $action['anchor'] |
575 | 575 | ); |
576 | 576 | } |
577 | - $action_links = yourls_apply_filter( 'action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp ); |
|
577 | + $action_links = yourls_apply_filter('action_links', $action_links, $keyword, $url, $ip, $clicks, $timestamp); |
|
578 | 578 | |
579 | - if( ! $title ) |
|
579 | + if (!$title) |
|
580 | 580 | $title = $url; |
581 | 581 | |
582 | 582 | $protocol_warning = ''; |
583 | - if( ! in_array( yourls_get_protocol( $url ) , array( 'http://', 'https://' ) ) ) |
|
584 | - $protocol_warning = yourls_apply_filter( 'add_row_protocol_warning', '<span class="warning" title="' . yourls__( 'Not a common link' ) . '">★</span>' ); |
|
583 | + if (!in_array(yourls_get_protocol($url), array('http://', 'https://'))) |
|
584 | + $protocol_warning = yourls_apply_filter('add_row_protocol_warning', '<span class="warning" title="'.yourls__('Not a common link').'">★</span>'); |
|
585 | 585 | |
586 | 586 | // Row cells: the array |
587 | 587 | $cells = array( |
588 | 588 | 'keyword' => array( |
589 | 589 | 'template' => '<a href="%shorturl%">%keyword_html%</a>', |
590 | - 'shorturl' => yourls_esc_url( $shorturl ), |
|
591 | - 'keyword_html' => yourls_esc_html( $keyword ), |
|
590 | + 'shorturl' => yourls_esc_url($shorturl), |
|
591 | + 'keyword_html' => yourls_esc_html($keyword), |
|
592 | 592 | ), |
593 | 593 | 'url' => array( |
594 | 594 | 'template' => '<a href="%long_url%" title="%title_attr%">%title_html%</a><br/><small>%warning%<a href="%long_url%">%long_url_html%</a></small>', |
595 | - 'long_url' => yourls_esc_url( $url ), |
|
596 | - 'title_attr' => yourls_esc_attr( $title ), |
|
597 | - 'title_html' => yourls_esc_html( yourls_trim_long_string( $title ) ), |
|
598 | - 'long_url_html' => yourls_esc_html( yourls_trim_long_string( urldecode( $url ) ) ), |
|
595 | + 'long_url' => yourls_esc_url($url), |
|
596 | + 'title_attr' => yourls_esc_attr($title), |
|
597 | + 'title_html' => yourls_esc_html(yourls_trim_long_string($title)), |
|
598 | + 'long_url_html' => yourls_esc_html(yourls_trim_long_string(urldecode($url))), |
|
599 | 599 | 'warning' => $protocol_warning, |
600 | 600 | ), |
601 | 601 | 'timestamp' => array( |
602 | 602 | 'template' => '<span class="timestamp" aria-hidden="true">%timestamp%</span> %date%', |
603 | 603 | 'timestamp' => $timestamp, |
604 | - 'date' => yourls_date_i18n( yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp( $timestamp )), |
|
604 | + 'date' => yourls_date_i18n(yourls_get_datetime_format('M d, Y H:i'), yourls_get_timestamp($timestamp)), |
|
605 | 605 | ), |
606 | 606 | 'ip' => array( |
607 | 607 | 'template' => '%ip%', |
@@ -609,7 +609,7 @@ discard block |
||
609 | 609 | ), |
610 | 610 | 'clicks' => array( |
611 | 611 | 'template' => '%clicks%', |
612 | - 'clicks' => yourls_number_format_i18n( $clicks, 0, '', '' ), |
|
612 | + 'clicks' => yourls_number_format_i18n($clicks, 0, '', ''), |
|
613 | 613 | ), |
614 | 614 | 'actions' => array( |
615 | 615 | 'template' => '%actions% <input type="hidden" id="keyword_%id%" value="%keyword%"/>', |
@@ -618,17 +618,17 @@ discard block |
||
618 | 618 | 'keyword' => $keyword, |
619 | 619 | ), |
620 | 620 | ); |
621 | - $cells = yourls_apply_filter( 'table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp ); |
|
621 | + $cells = yourls_apply_filter('table_add_row_cell_array', $cells, $keyword, $url, $title, $ip, $clicks, $timestamp); |
|
622 | 622 | |
623 | 623 | // Row cells: the HTML. Replace every %stuff% in 'template' with 'stuff' value. |
624 | 624 | $row = "<tr id=\"id-$id\">"; |
625 | - foreach( $cells as $cell_id => $elements ) { |
|
626 | - $row .= sprintf( '<td class="%s" id="%s">', $cell_id, $cell_id . '-' . $id ); |
|
627 | - $row .= preg_replace_callback( '/%([^%]+)?%/', function( $match ) use ( $elements ) { return $elements[ $match[1] ]; }, $elements['template'] ); |
|
625 | + foreach ($cells as $cell_id => $elements) { |
|
626 | + $row .= sprintf('<td class="%s" id="%s">', $cell_id, $cell_id.'-'.$id); |
|
627 | + $row .= preg_replace_callback('/%([^%]+)?%/', function($match) use ($elements) { return $elements[$match[1]]; }, $elements['template']); |
|
628 | 628 | $row .= '</td>'; |
629 | 629 | } |
630 | 630 | $row .= "</tr>"; |
631 | - $row = yourls_apply_filter( 'table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp ); |
|
631 | + $row = yourls_apply_filter('table_add_row', $row, $keyword, $url, $title, $ip, $clicks, $timestamp); |
|
632 | 632 | |
633 | 633 | return $row; |
634 | 634 | } |
@@ -639,22 +639,22 @@ discard block |
||
639 | 639 | */ |
640 | 640 | function yourls_table_head() { |
641 | 641 | $start = '<table id="main_table" class="tblSorter" cellpadding="0" cellspacing="1"><thead><tr>'."\n"; |
642 | - echo yourls_apply_filter( 'table_head_start', $start ); |
|
643 | - |
|
644 | - $cells = yourls_apply_filter( 'table_head_cells', array( |
|
645 | - 'shorturl' => yourls__( 'Short URL' ), |
|
646 | - 'longurl' => yourls__( 'Original URL' ), |
|
647 | - 'date' => yourls__( 'Date' ), |
|
648 | - 'ip' => yourls__( 'IP' ), |
|
649 | - 'clicks' => yourls__( 'Clicks' ), |
|
650 | - 'actions' => yourls__( 'Actions' ) |
|
651 | - ) ); |
|
652 | - foreach( $cells as $k => $v ) { |
|
642 | + echo yourls_apply_filter('table_head_start', $start); |
|
643 | + |
|
644 | + $cells = yourls_apply_filter('table_head_cells', array( |
|
645 | + 'shorturl' => yourls__('Short URL'), |
|
646 | + 'longurl' => yourls__('Original URL'), |
|
647 | + 'date' => yourls__('Date'), |
|
648 | + 'ip' => yourls__('IP'), |
|
649 | + 'clicks' => yourls__('Clicks'), |
|
650 | + 'actions' => yourls__('Actions') |
|
651 | + )); |
|
652 | + foreach ($cells as $k => $v) { |
|
653 | 653 | echo "<th id='main_table_head_$k'>$v</th>\n"; |
654 | 654 | } |
655 | 655 | |
656 | 656 | $end = "</tr></thead>\n"; |
657 | - echo yourls_apply_filter( 'table_head_end', $end ); |
|
657 | + echo yourls_apply_filter('table_head_end', $end); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | /** |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | * |
663 | 663 | */ |
664 | 664 | function yourls_table_tbody_start() { |
665 | - echo yourls_apply_filter( 'table_tbody_start', '<tbody>' ); |
|
665 | + echo yourls_apply_filter('table_tbody_start', '<tbody>'); |
|
666 | 666 | } |
667 | 667 | |
668 | 668 | /** |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | * |
671 | 671 | */ |
672 | 672 | function yourls_table_tbody_end() { |
673 | - echo yourls_apply_filter( 'table_tbody_end', '</tbody>' ); |
|
673 | + echo yourls_apply_filter('table_tbody_end', '</tbody>'); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | /** |
@@ -678,57 +678,57 @@ discard block |
||
678 | 678 | * |
679 | 679 | */ |
680 | 680 | function yourls_table_end() { |
681 | - echo yourls_apply_filter( 'table_end', '</table></main>' ); |
|
681 | + echo yourls_apply_filter('table_end', '</table></main>'); |
|
682 | 682 | } |
683 | 683 | |
684 | 684 | /** |
685 | 685 | * Echo HTML tag for a link |
686 | 686 | * |
687 | 687 | */ |
688 | -function yourls_html_link( $href, $title = '', $element = '' ) { |
|
689 | - if( !$title ) |
|
688 | +function yourls_html_link($href, $title = '', $element = '') { |
|
689 | + if (!$title) |
|
690 | 690 | $title = $href; |
691 | - if( $element ) |
|
692 | - $element = sprintf( 'id="%s"', yourls_esc_attr( $element ) ); |
|
693 | - $link = sprintf( '<a href="%s" %s>%s</a>', yourls_esc_url( $href ), $element, yourls_esc_html( $title ) ); |
|
694 | - echo yourls_apply_filter( 'html_link', $link ); |
|
691 | + if ($element) |
|
692 | + $element = sprintf('id="%s"', yourls_esc_attr($element)); |
|
693 | + $link = sprintf('<a href="%s" %s>%s</a>', yourls_esc_url($href), $element, yourls_esc_html($title)); |
|
694 | + echo yourls_apply_filter('html_link', $link); |
|
695 | 695 | } |
696 | 696 | |
697 | 697 | /** |
698 | 698 | * Display the login screen. Nothing past this point. |
699 | 699 | * |
700 | 700 | */ |
701 | -function yourls_login_screen( $error_msg = '' ) { |
|
702 | - yourls_html_head( 'login' ); |
|
701 | +function yourls_login_screen($error_msg = '') { |
|
702 | + yourls_html_head('login'); |
|
703 | 703 | |
704 | - $action = ( isset( $_GET['action'] ) && $_GET['action'] == 'logout' ? '?' : '' ); |
|
704 | + $action = (isset($_GET['action']) && $_GET['action'] == 'logout' ? '?' : ''); |
|
705 | 705 | |
706 | 706 | yourls_html_logo(); |
707 | 707 | ?> |
708 | 708 | <div id="login"> |
709 | 709 | <form method="post" action="<?php echo $action; ?>"> <?php // reset any QUERY parameters ?> |
710 | 710 | <?php |
711 | - if( !empty( $error_msg ) ) { |
|
711 | + if (!empty($error_msg)) { |
|
712 | 712 | echo '<p class="error">'.$error_msg.'</p>'; |
713 | 713 | } |
714 | - yourls_do_action( 'login_form_top' ); |
|
714 | + yourls_do_action('login_form_top'); |
|
715 | 715 | ?> |
716 | 716 | <p> |
717 | - <label for="username"><?php yourls_e( 'Username' ); ?></label><br /> |
|
717 | + <label for="username"><?php yourls_e('Username'); ?></label><br /> |
|
718 | 718 | <input type="text" id="username" name="username" size="30" class="text" /> |
719 | 719 | </p> |
720 | 720 | <p> |
721 | - <label for="password"><?php yourls_e( 'Password' ); ?></label><br /> |
|
721 | + <label for="password"><?php yourls_e('Password'); ?></label><br /> |
|
722 | 722 | <input type="password" id="password" name="password" size="30" class="text" /> |
723 | 723 | </p> |
724 | 724 | <?php |
725 | - yourls_do_action( 'login_form_bottom' ); |
|
725 | + yourls_do_action('login_form_bottom'); |
|
726 | 726 | ?> |
727 | 727 | <p style="text-align: right;"> |
728 | - <input type="submit" id="submit" name="submit" value="<?php yourls_e( 'Login' ); ?>" class="button" /> |
|
728 | + <input type="submit" id="submit" name="submit" value="<?php yourls_e('Login'); ?>" class="button" /> |
|
729 | 729 | </p> |
730 | 730 | <?php |
731 | - yourls_do_action( 'login_form_end' ); |
|
731 | + yourls_do_action('login_form_end'); |
|
732 | 732 | ?> |
733 | 733 | </form> |
734 | 734 | <script type="text/javascript">$('#username').focus();</script> |
@@ -745,69 +745,69 @@ discard block |
||
745 | 745 | function yourls_html_menu() { |
746 | 746 | |
747 | 747 | // Build menu links |
748 | - if( defined( 'YOURLS_USER' ) ) { |
|
749 | - $logout_link = yourls_apply_filter( 'logout_link', sprintf( yourls__('Hello <strong>%s</strong>'), YOURLS_USER ) . ' (<a href="' . yourls_admin_url() . '?action=logout" title="' . yourls_esc_attr__( 'Logout' ) . '">' . yourls__( 'Logout' ) . '</a>)' ); |
|
748 | + if (defined('YOURLS_USER')) { |
|
749 | + $logout_link = yourls_apply_filter('logout_link', sprintf(yourls__('Hello <strong>%s</strong>'), YOURLS_USER).' (<a href="'.yourls_admin_url().'?action=logout" title="'.yourls_esc_attr__('Logout').'">'.yourls__('Logout').'</a>)'); |
|
750 | 750 | } else { |
751 | - $logout_link = yourls_apply_filter( 'logout_link', '' ); |
|
751 | + $logout_link = yourls_apply_filter('logout_link', ''); |
|
752 | 752 | } |
753 | - $help_link = yourls_apply_filter( 'help_link', '<a href="' . yourls_site_url( false ) .'/readme.html">' . yourls__( 'Help' ) . '</a>' ); |
|
753 | + $help_link = yourls_apply_filter('help_link', '<a href="'.yourls_site_url(false).'/readme.html">'.yourls__('Help').'</a>'); |
|
754 | 754 | |
755 | 755 | $admin_links = array(); |
756 | 756 | $admin_sublinks = array(); |
757 | 757 | |
758 | 758 | $admin_links['admin'] = array( |
759 | - 'url' => yourls_admin_url( 'index.php' ), |
|
760 | - 'title' => yourls__( 'Go to the admin interface' ), |
|
761 | - 'anchor' => yourls__( 'Admin interface' ) |
|
759 | + 'url' => yourls_admin_url('index.php'), |
|
760 | + 'title' => yourls__('Go to the admin interface'), |
|
761 | + 'anchor' => yourls__('Admin interface') |
|
762 | 762 | ); |
763 | 763 | |
764 | - if( yourls_is_admin() ) { |
|
764 | + if (yourls_is_admin()) { |
|
765 | 765 | $admin_links['tools'] = array( |
766 | - 'url' => yourls_admin_url( 'tools.php' ), |
|
767 | - 'anchor' => yourls__( 'Tools' ) |
|
766 | + 'url' => yourls_admin_url('tools.php'), |
|
767 | + 'anchor' => yourls__('Tools') |
|
768 | 768 | ); |
769 | 769 | $admin_links['plugins'] = array( |
770 | - 'url' => yourls_admin_url( 'plugins.php' ), |
|
771 | - 'anchor' => yourls__( 'Manage Plugins' ) |
|
770 | + 'url' => yourls_admin_url('plugins.php'), |
|
771 | + 'anchor' => yourls__('Manage Plugins') |
|
772 | 772 | ); |
773 | 773 | $admin_sublinks['plugins'] = yourls_list_plugin_admin_pages(); |
774 | 774 | } |
775 | 775 | |
776 | - $admin_links = yourls_apply_filter( 'admin_links', $admin_links ); |
|
777 | - $admin_sublinks = yourls_apply_filter( 'admin_sublinks', $admin_sublinks ); |
|
776 | + $admin_links = yourls_apply_filter('admin_links', $admin_links); |
|
777 | + $admin_sublinks = yourls_apply_filter('admin_sublinks', $admin_sublinks); |
|
778 | 778 | |
779 | 779 | // Now output menu |
780 | 780 | echo '<nav role="navigation"><ul id="admin_menu">'."\n"; |
781 | - if ( yourls_is_private() && !empty( $logout_link ) ) |
|
782 | - echo '<li id="admin_menu_logout_link">' . $logout_link .'</li>'; |
|
783 | - |
|
784 | - foreach( (array)$admin_links as $link => $ar ) { |
|
785 | - if( isset( $ar['url'] ) ) { |
|
786 | - $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; |
|
787 | - $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; |
|
788 | - printf( '<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor ); |
|
781 | + if (yourls_is_private() && !empty($logout_link)) |
|
782 | + echo '<li id="admin_menu_logout_link">'.$logout_link.'</li>'; |
|
783 | + |
|
784 | + foreach ((array) $admin_links as $link => $ar) { |
|
785 | + if (isset($ar['url'])) { |
|
786 | + $anchor = isset($ar['anchor']) ? $ar['anchor'] : $link; |
|
787 | + $title = isset($ar['title']) ? 'title="'.$ar['title'].'"' : ''; |
|
788 | + printf('<li id="admin_menu_%s_link" class="admin_menu_toplevel"><a href="%s" %s>%s</a>', $link, $ar['url'], $title, $anchor); |
|
789 | 789 | } |
790 | 790 | // Output submenu if any. TODO: clean up, too many code duplicated here |
791 | - if( isset( $admin_sublinks[$link] ) ) { |
|
791 | + if (isset($admin_sublinks[$link])) { |
|
792 | 792 | echo "<ul>\n"; |
793 | - foreach( $admin_sublinks[$link] as $link => $ar ) { |
|
794 | - if( isset( $ar['url'] ) ) { |
|
795 | - $anchor = isset( $ar['anchor'] ) ? $ar['anchor'] : $link; |
|
796 | - $title = isset( $ar['title'] ) ? 'title="' . $ar['title'] . '"' : ''; |
|
797 | - printf( '<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor ); |
|
793 | + foreach ($admin_sublinks[$link] as $link => $ar) { |
|
794 | + if (isset($ar['url'])) { |
|
795 | + $anchor = isset($ar['anchor']) ? $ar['anchor'] : $link; |
|
796 | + $title = isset($ar['title']) ? 'title="'.$ar['title'].'"' : ''; |
|
797 | + printf('<li id="admin_menu_%s_link" class="admin_menu_sublevel admin_menu_sublevel_%s"><a href="%s" %s>%s</a>', $link, $link, $ar['url'], $title, $anchor); |
|
798 | 798 | } |
799 | 799 | } |
800 | 800 | echo "</ul>\n"; |
801 | 801 | } |
802 | 802 | } |
803 | 803 | |
804 | - if ( isset( $help_link ) ) |
|
805 | - echo '<li id="admin_menu_help_link">' . $help_link .'</li>'; |
|
804 | + if (isset($help_link)) |
|
805 | + echo '<li id="admin_menu_help_link">'.$help_link.'</li>'; |
|
806 | 806 | |
807 | - yourls_do_action( 'admin_menu' ); |
|
807 | + yourls_do_action('admin_menu'); |
|
808 | 808 | echo "</ul></nav>\n"; |
809 | - yourls_do_action( 'admin_notices' ); |
|
810 | - yourls_do_action( 'admin_notice' ); // because I never remember if it's 'notices' or 'notice' |
|
809 | + yourls_do_action('admin_notices'); |
|
810 | + yourls_do_action('admin_notice'); // because I never remember if it's 'notices' or 'notice' |
|
811 | 811 | /* |
812 | 812 | To display a notice: |
813 | 813 | $message = "<div>OMG, dude, I mean!</div>" ); |
@@ -819,17 +819,17 @@ discard block |
||
819 | 819 | * Wrapper function to display admin notices |
820 | 820 | * |
821 | 821 | */ |
822 | -function yourls_add_notice( $message, $style = 'notice' ) { |
|
822 | +function yourls_add_notice($message, $style = 'notice') { |
|
823 | 823 | // Escape single quotes in $message to avoid breaking the anonymous function |
824 | - $message = yourls_notice_box( strtr( $message, array( "'" => "\'" ) ), $style ); |
|
825 | - yourls_add_action( 'admin_notices', function() use ( $message ) { echo (string) $message; } ); |
|
824 | + $message = yourls_notice_box(strtr($message, array("'" => "\'")), $style); |
|
825 | + yourls_add_action('admin_notices', function() use ($message) { echo (string) $message; } ); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
829 | 829 | * Return a formatted notice |
830 | 830 | * |
831 | 831 | */ |
832 | -function yourls_notice_box( $message, $style = 'notice' ) { |
|
832 | +function yourls_notice_box($message, $style = 'notice') { |
|
833 | 833 | return <<<HTML |
834 | 834 | <div class="$style"> |
835 | 835 | <p>$message</p> |
@@ -846,14 +846,14 @@ discard block |
||
846 | 846 | * @since 1.0 |
847 | 847 | * @param $page PHP file to display |
848 | 848 | */ |
849 | -function yourls_page( $page ) { |
|
850 | - if( !yourls_is_page($page)) { |
|
851 | - yourls_die( yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404 ); |
|
849 | +function yourls_page($page) { |
|
850 | + if (!yourls_is_page($page)) { |
|
851 | + yourls_die(yourls_s('Page "%1$s" not found', $page), yourls__('Not found'), 404); |
|
852 | 852 | } |
853 | 853 | |
854 | - yourls_do_action( 'pre_page', $page ); |
|
855 | - include_once( YOURLS_PAGEDIR . "/$page.php" ); |
|
856 | - yourls_do_action( 'post_page', $page ); |
|
854 | + yourls_do_action('pre_page', $page); |
|
855 | + include_once(YOURLS_PAGEDIR."/$page.php"); |
|
856 | + yourls_do_action('post_page', $page); |
|
857 | 857 | } |
858 | 858 | |
859 | 859 | /** |
@@ -868,20 +868,20 @@ discard block |
||
868 | 868 | $attributes = array(); |
869 | 869 | $output = ''; |
870 | 870 | |
871 | - $attributes[] = ( yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"' ); |
|
871 | + $attributes[] = (yourls_is_rtl() ? 'dir="rtl"' : 'dir="ltr"'); |
|
872 | 872 | |
873 | - $doctype = yourls_apply_filter( 'html_language_attributes_doctype', 'html' ); |
|
873 | + $doctype = yourls_apply_filter('html_language_attributes_doctype', 'html'); |
|
874 | 874 | // Experimental: get HTML lang from locale. Should work. Convert fr_FR -> fr-FR |
875 | - if ( $lang = str_replace( '_', '-', yourls_get_locale() ) ) { |
|
876 | - if( $doctype == 'xhtml' ) { |
|
875 | + if ($lang = str_replace('_', '-', yourls_get_locale())) { |
|
876 | + if ($doctype == 'xhtml') { |
|
877 | 877 | $attributes[] = "xml:lang=\"$lang\""; |
878 | 878 | } else { |
879 | 879 | $attributes[] = "lang=\"$lang\""; |
880 | 880 | } |
881 | 881 | } |
882 | 882 | |
883 | - $output = implode( ' ', $attributes ); |
|
884 | - $output = yourls_apply_filter( 'html_language_attributes', $output ); |
|
883 | + $output = implode(' ', $attributes); |
|
884 | + $output = yourls_apply_filter('html_language_attributes', $output); |
|
885 | 885 | echo $output; |
886 | 886 | } |
887 | 887 | |
@@ -892,15 +892,15 @@ discard block |
||
892 | 892 | */ |
893 | 893 | function yourls_l10n_calendar_strings() { |
894 | 894 | echo "\n<script>\n"; |
895 | - echo "var l10n_cal_month = " . json_encode( array_values( yourls_l10n_months() ) ) . ";\n"; |
|
896 | - echo "var l10n_cal_days = " . json_encode( array_values( yourls_l10n_weekday_initial() ) ) . ";\n"; |
|
897 | - echo "var l10n_cal_today = \"" . yourls_esc_js( yourls__( 'Today' ) ) . "\";\n"; |
|
898 | - echo "var l10n_cal_close = \"" . yourls_esc_js( yourls__( 'Close' ) ) . "\";\n"; |
|
895 | + echo "var l10n_cal_month = ".json_encode(array_values(yourls_l10n_months())).";\n"; |
|
896 | + echo "var l10n_cal_days = ".json_encode(array_values(yourls_l10n_weekday_initial())).";\n"; |
|
897 | + echo "var l10n_cal_today = \"".yourls_esc_js(yourls__('Today'))."\";\n"; |
|
898 | + echo "var l10n_cal_close = \"".yourls_esc_js(yourls__('Close'))."\";\n"; |
|
899 | 899 | echo "</script>\n"; |
900 | 900 | |
901 | 901 | // Dummy returns, to initialize l10n strings used in the calendar |
902 | - yourls__( 'Today' ); |
|
903 | - yourls__( 'Close' ); |
|
902 | + yourls__('Today'); |
|
903 | + yourls__('Close'); |
|
904 | 904 | } |
905 | 905 | |
906 | 906 | |
@@ -911,12 +911,12 @@ discard block |
||
911 | 911 | */ |
912 | 912 | function yourls_new_core_version_notice() { |
913 | 913 | |
914 | - $checks = yourls_get_option( 'core_version_checks' ); |
|
914 | + $checks = yourls_get_option('core_version_checks'); |
|
915 | 915 | $latest = isset($checks->last_result->latest) ? yourls_sanitize_version($checks->last_result->latest) : false; |
916 | 916 | |
917 | - if( $latest AND version_compare( $latest, YOURLS_VERSION, '>' ) ) { |
|
918 | - $msg = yourls_s( '<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest ); |
|
919 | - yourls_add_notice( $msg ); |
|
917 | + if ($latest AND version_compare($latest, YOURLS_VERSION, '>')) { |
|
918 | + $msg = yourls_s('<a href="%s">YOURLS version %s</a> is available. Please update!', 'http://yourls.org/download', $latest); |
|
919 | + yourls_add_notice($msg); |
|
920 | 920 | } |
921 | 921 | } |
922 | 922 | |
@@ -933,14 +933,14 @@ discard block |
||
933 | 933 | */ |
934 | 934 | function yourls_get_search_text() { |
935 | 935 | $search = ''; |
936 | - if( isset( $_GET['search_protocol'] ) ) |
|
936 | + if (isset($_GET['search_protocol'])) |
|
937 | 937 | $search .= $_GET['search_protocol']; |
938 | - if( isset( $_GET['search_slashes'] ) ) |
|
938 | + if (isset($_GET['search_slashes'])) |
|
939 | 939 | $search .= $_GET['search_slashes']; |
940 | - if( isset( $_GET['search'] ) ) |
|
940 | + if (isset($_GET['search'])) |
|
941 | 941 | $search .= $_GET['search']; |
942 | 942 | |
943 | - return htmlspecialchars( trim( $search ) ); |
|
943 | + return htmlspecialchars(trim($search)); |
|
944 | 944 | } |
945 | 945 | |
946 | 946 | /** |
@@ -952,13 +952,13 @@ discard block |
||
952 | 952 | * @param bool $echo true to display, false to return the HTML |
953 | 953 | * @return string the HTML for a bookmarklet link |
954 | 954 | */ |
955 | -function yourls_bookmarklet_link( $href, $anchor, $echo = true ) { |
|
956 | - $alert = yourls_esc_attr__( 'Drag to your toolbar!' ); |
|
955 | +function yourls_bookmarklet_link($href, $anchor, $echo = true) { |
|
956 | + $alert = yourls_esc_attr__('Drag to your toolbar!'); |
|
957 | 957 | $link = <<<LINK |
958 | 958 | <a href="$href" class="bookmarklet" onclick="alert('$alert');return false;">$anchor</a> |
959 | 959 | LINK; |
960 | 960 | |
961 | - if( $echo ) |
|
961 | + if ($echo) |
|
962 | 962 | echo $link; |
963 | 963 | return $link; |
964 | 964 | } |
@@ -8,12 +8,12 @@ discard block |
||
8 | 8 | function yourls_db_connect() { |
9 | 9 | global $ydb; |
10 | 10 | |
11 | - if ( !defined( 'YOURLS_DB_USER' ) |
|
12 | - or !defined( 'YOURLS_DB_PASS' ) |
|
13 | - or !defined( 'YOURLS_DB_NAME' ) |
|
14 | - or !defined( 'YOURLS_DB_HOST' ) |
|
11 | + if (!defined('YOURLS_DB_USER') |
|
12 | + or !defined('YOURLS_DB_PASS') |
|
13 | + or !defined('YOURLS_DB_NAME') |
|
14 | + or !defined('YOURLS_DB_HOST') |
|
15 | 15 | ) { |
16 | - yourls_die( yourls__( 'Incorrect DB config, please refer to documentation' ), yourls__( 'Fatal error' ), 503 ); |
|
16 | + yourls_die(yourls__('Incorrect DB config, please refer to documentation'), yourls__('Fatal error'), 503); |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | $dbhost = YOURLS_DB_HOST; |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | $dbname = YOURLS_DB_NAME; |
23 | 23 | |
24 | 24 | // This action is deprecated |
25 | - yourls_do_action( 'set_DB_driver', 'deprecated' ); |
|
25 | + yourls_do_action('set_DB_driver', 'deprecated'); |
|
26 | 26 | |
27 | 27 | // Get custom port if any |
28 | - if ( false !== strpos( $dbhost, ':' ) ) { |
|
29 | - list( $dbhost, $dbport ) = explode( ':', $dbhost ); |
|
30 | - $dbhost = sprintf( '%1$s;port=%2$d', $dbhost, $dbport ); |
|
28 | + if (false !== strpos($dbhost, ':')) { |
|
29 | + list($dbhost, $dbport) = explode(':', $dbhost); |
|
30 | + $dbhost = sprintf('%1$s;port=%2$d', $dbhost, $dbport); |
|
31 | 31 | } |
32 | 32 | |
33 | - $charset = yourls_apply_filter( 'db_connect_charset', 'utf8mb4' ); |
|
33 | + $charset = yourls_apply_filter('db_connect_charset', 'utf8mb4'); |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Data Source Name (dsn) used to connect the DB |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | * 'sqlite:/opt/databases/mydb.sq3' |
41 | 41 | * 'pgsql:host=192.168.13.37;port=5432;dbname=omgwtf' |
42 | 42 | */ |
43 | - $dsn = sprintf( 'mysql:host=%s;dbname=%s;charset=%s', $dbhost, $dbname, $charset ); |
|
44 | - $dsn = yourls_apply_filter( 'db_connect_custom_dsn', $dsn ); |
|
43 | + $dsn = sprintf('mysql:host=%s;dbname=%s;charset=%s', $dbhost, $dbname, $charset); |
|
44 | + $dsn = yourls_apply_filter('db_connect_custom_dsn', $dsn); |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * PDO driver options and attributes |
@@ -51,16 +51,16 @@ discard block |
||
51 | 51 | * The driver options are passed to the PDO constructor, eg array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION) |
52 | 52 | * The attribute options are then set in a foreach($attr as $k=>$v){$db->setAttribute($k, $v)} loop |
53 | 53 | */ |
54 | - $driver_options = yourls_apply_filter( 'db_connect_driver_option', [] ); // driver options as key-value pairs |
|
55 | - $attributes = yourls_apply_filter( 'db_connect_attributes', [] ); // attributes as key-value pairs |
|
54 | + $driver_options = yourls_apply_filter('db_connect_driver_option', []); // driver options as key-value pairs |
|
55 | + $attributes = yourls_apply_filter('db_connect_attributes', []); // attributes as key-value pairs |
|
56 | 56 | |
57 | - $ydb = new \YOURLS\Database\YDB( $dsn, $user, $pass, $driver_options, $attributes ); |
|
57 | + $ydb = new \YOURLS\Database\YDB($dsn, $user, $pass, $driver_options, $attributes); |
|
58 | 58 | $ydb->init(); |
59 | 59 | |
60 | 60 | // Past this point, we're connected |
61 | - yourls_debug_log( sprintf( 'Connected to database %s on %s ', $dbname, $dbhost ) ); |
|
61 | + yourls_debug_log(sprintf('Connected to database %s on %s ', $dbname, $dbhost)); |
|
62 | 62 | |
63 | - yourls_debug_mode( YOURLS_DEBUG ); |
|
63 | + yourls_debug_mode(YOURLS_DEBUG); |
|
64 | 64 | |
65 | 65 | return $ydb; |
66 | 66 | } |
@@ -70,5 +70,5 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function yourls_get_db() { |
72 | 72 | global $ydb; |
73 | - return ( $ydb instanceof \YOURLS\Database\YDB ) ? $ydb : yourls_db_connect(); |
|
73 | + return ($ydb instanceof \YOURLS\Database\YDB) ? $ydb : yourls_db_connect(); |
|
74 | 74 | } |