Welcome to mirror list, hosted at ThFree Co, Russian Federation.

functions-deprecated.php « includes - github.com/YOURLS/YOURLS.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 65141f0ce37edbf0980b4f2390c4ca9f746f3e9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<?php
/**
 * Deprecated functions from past YOURLS versions. Don't use them, as they may be
 * removed in a later version. Use the newer alternatives instead.
 *
 * Note to devs: when deprecating a function, move it here. Then check all the places
 * in core that might be using it, including core plugins.
 */

// @codeCoverageIgnoreStart

/**
 * PHP emulation of JS's encodeURI
 *
 * @link https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI
 * @deprecated 1.9.1
 * @param string $url
 * @return string
 */
function yourls_encodeURI($url) {
    yourls_deprecated_function( __FUNCTION__, '1.9.1', 'no replacement needed' );
    // Decode URL all the way
    $result = yourls_rawurldecode_while_encoded( $url );
    // Encode once
    $result = strtr( rawurlencode( $result ), array (
        '%3B' => ';', '%2C' => ',', '%2F' => '/', '%3F' => '?', '%3A' => ':', '%40' => '@',
        '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*',
        '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#',
    ) );
    // @TODO:
    // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/
    // To fully support IDN URLs, advocate use of a plugin.
    return yourls_apply_filter( 'encodeURI', $result, $url );
}

/**
 * Check if a file is a plugin file
 *
 * @deprecated 1.8.3
 */
function yourls_validate_plugin_file( $file ) {
    yourls_deprecated_function( __FUNCTION__, '1.8.3', 'yourls_is_a_plugin_file' );
    return yourls_is_a_plugin_file($file);
}

/**
 * Return a unique(ish) hash for a string to be used as a valid HTML id
 *
 * @deprecated 1.8.3
 */
function yourls_string2htmlid( $string ) {
    yourls_deprecated_function( __FUNCTION__, '1.8.3', 'yourls_unique_element_id' );
    return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) );
}

/**
 * Get search text from query string variables search_protocol, search_slashes and search
 *
 * Some servers don't like query strings containing "(ht|f)tp(s)://". A javascript bit
 * explodes the search text into protocol, slashes and the rest (see JS function
 * split_search_text_before_search()) and this function glues pieces back together
 * See issue https://github.com/YOURLS/YOURLS/issues/1576
 *
 * @since 1.7
 * @deprecated 1.8.2
 * @return string Search string
 */
function yourls_get_search_text() {
    yourls_deprecated_function( __FUNCTION__, '1.8.2', 'YOURLS\Views\AdminParams::get_search' );
    $view_params = new YOURLS\Views\AdminParams();
    return $view_params->get_search();
}

/**
 * Retrieve the current time based on specified type. Stolen from WP.
 *
 * The 'mysql' type will return the time in the format for MySQL DATETIME field.
 * The 'timestamp' type will return the current timestamp.
 *
 * If $gmt is set to either '1' or 'true', then both types will use GMT time.
 * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
 *
 * @since 1.6
 * @deprecated 1.7.10
 *
 * @param string $type Either 'mysql' or 'timestamp'.
 * @param int|bool $gmt Optional. Whether to use GMT timezone. Default is false.
 * @return int|string String if $type is 'gmt', int if $type is 'timestamp'.
 */
function yourls_current_time( $type, $gmt = 0 ) {
    yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_get_timestamp' );
	switch ( $type ) {
		case 'mysql':
			return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', yourls_get_timestamp( time() ));
		case 'timestamp':
			return ( $gmt ) ? time() : yourls_get_timestamp( time() );
	}
}

/**
 * Lowercase scheme and domain of an URI - see issues 591, 1630, 1889
 *
 * Renamed to yourls_normalize_uri() in 1.7.10 because the function now does more than just
 * lowercasing the scheme and domain.
 *
 * @deprecated 1.7.10
 *
 */
function yourls_lowercase_scheme_domain( $url ) {
    yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_normalize_uri' );
    return yourls_normalize_uri( $url );
}

/**
 * The original string sanitize function
 *
 * @deprecated 1.7.10
 *
 */
function yourls_sanitize_string( $string, $restrict_to_shorturl_charset = false ) {
    yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_sanitize_keyword' );
    return yourls_sanitize_keyword( $string, $restrict_to_shorturl_charset );
}

/**
 * Return favicon URL (either default or custom)
 *
 * @deprecated 1.7.10
 *
 */
function yourls_favicon( $echo = true ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_get_yourls_favicon_url' );
	return yourls_get_yourls_favicon_url( $echo );
}

/**
 * Return array of stats for a given keyword
 *
 * @deprecated 1.7.10
 *
 */
function yourls_get_link_stats( $url ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_get_keyword_stats' );
	return yourls_get_keyword_stats( $url );
}

/**
 * Check if a long URL already exists in the DB. Return NULL (doesn't exist) or an object with URL informations.
 *
 * @since 1.5.1
 * @deprecated 1.7.10
 *
 */
function yourls_url_exists( $url ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_long_url_exists' );
	return yourls_long_url_exists( $url );
}

/**
 * Return word or words if more than one
 *
 */
function yourls_plural( $word, $count=1 ) {
	yourls_deprecated_function( __FUNCTION__, '1.6', 'yourls_n' );
	return $word . ($count > 1 ? 's' : '');
}

/**
 * Return list of all shorturls associated to the same long URL. Returns NULL or array of keywords.
 *
 */
function yourls_get_duplicate_keywords( $longurl ) {
	yourls_deprecated_function( __FUNCTION__, '1.7', 'yourls_get_longurl_keywords' );
	if( !yourls_allow_duplicate_longurls() )
		return NULL;
	return yourls_apply_filter( 'get_duplicate_keywords', yourls_get_longurl_keywords ( $longurl ), $longurl );
}

/**
 * Make sure a integer is safe
 *
 * Note: this function is dumb and dumbly named since it does not intval(). DO NOT USE.
 *
 */
function yourls_intval( $int ) {
	yourls_deprecated_function( __FUNCTION__, '1.7', 'yourls_sanitize_int' );
	return yourls_escape( $int );
}

/**
 * Get remote content via a GET request using best transport available
 *
 */
function yourls_get_remote_content( $url,  $maxlen = 4096, $timeout = 5 ) {
	yourls_deprecated_function( __FUNCTION__, '1.7', 'yourls_http_get_body' );
	return yourls_http_get_body( $url );
}

/**
 * Alias for yourls_apply_filter because I never remember if it's _filter or _filters
 *
 * At first I thought it made semantically more sense but thinking about it, I was wrong. It's one filter.
 * There may be several function hooked into it, but it still the same one filter.
 *
 * @since 1.6
 * @deprecated 1.7.1
 *
 * @param string $hook the name of the YOURLS element or action
 * @param mixed $value the value of the element before filtering
 * @return mixed
 */
function yourls_apply_filters( $hook, $value = '' ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_apply_filter' );
	return yourls_apply_filter( $hook, $value );
}

/**
 * Check if we'll need interface display function (ie not API or redirection)
 *
 */
function yourls_has_interface() {
	yourls_deprecated_function( __FUNCTION__, '1.7.1' );
	if( yourls_is_API() or yourls_is_GO() )
		return false;
	return true;
}

/**
 * Check if a proxy is defined for HTTP requests
 *
 * @uses YOURLS_PROXY
 * @since 1.7
 * @deprecated 1.7.1
 * @return bool true if a proxy is defined, false otherwise
 */
function yourls_http_proxy_is_defined() {
	yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_http_get_proxy' );
	return yourls_apply_filter( 'http_proxy_is_defined', defined( 'YOURLS_PROXY' ) );
}

/**
 * Displays translated string with gettext context
 *
 * This function has been renamed yourls_xe() for consistency with other *e() functions
 *
 * @see yourls_x()
 * @since 1.6
 * @deprecated 1.7.1
 *
 * @param string $text Text to translate
 * @param string $context Context information for the translators
 * @param string $domain Optional. Domain to retrieve the translated text
 * @return string Translated context string without pipe
 */
function yourls_ex( $text, $context, $domain = 'default' ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_xe' );
	echo yourls_xe( $text, $context, $domain );
}

/**
 * Escape a string or an array of strings before DB usage. ALWAYS escape before using in a SQL query. Thanks.
 *
 * Deprecated in 1.7.3 because we moved onto using PDO and using built-in escaping functions, instead of
 * rolling our own.
 *
 * @deprecated 1.7.3
 * @param string|array $data string or array of strings to be escaped
 * @return string|array escaped data
 */
function yourls_escape( $data ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.3', 'PDO' );
	if( is_array( $data ) ) {
		foreach( $data as $k => $v ) {
			if( is_array( $v ) ) {
				$data[ $k ] = yourls_escape( $v );
			} else {
				$data[ $k ] = yourls_escape_real( $v );
			}
		}
	} else {
		$data = yourls_escape_real( $data );
	}

	return $data;
}

/**
 * "Real" escape. This function should NOT be called directly. Use yourls_escape() instead.
 *
 * This function uses a "real" escape if possible, using PDO, MySQL or MySQLi functions,
 * with a fallback to a "simple" addslashes
 * If you're implementing a custom DB engine or a custom cache system, you can define an
 * escape function using filter 'custom_escape_real'
 *
 * @since 1.7
 * @deprecated 1.7.3
 * @param string $a string to be escaped
 * @return string escaped string
 */
function yourls_escape_real( $string ) {
	yourls_deprecated_function( __FUNCTION__, '1.7.3', 'PDO' );
	global $ydb;
	if( isset( $ydb ) && ( $ydb instanceof \YOURLS\Database\YDB ) )
		return $ydb->escape( $string );

	// YOURLS DB classes have been bypassed by a custom DB engine or a custom cache layer
	return yourls_apply_filter( 'custom_escape_real', addslashes( $string ), $string );
}

// @codeCoverageIgnoreEnd