[ Index ]

PHP Cross Reference of YOURLS

title

Body

[close]

/includes/ -> functions-deprecated.php (source)

   1  <?php
   2  /**
   3   * Deprecated functions from past YOURLS versions. Don't use them, as they may be
   4   * removed in a later version. Use the newer alternatives instead.
   5   *
   6   * Note to devs: when deprecating a function, move it here. Then check all the places
   7   * in core that might be using it, including core plugins.
   8   *
   9   * Usage :  yourls_deprecated_function( 'function_name', 'version', 'replacement' );
  10   * Output:  "{function_name} is deprecated since version {version}! Use {replacement} instead."
  11   *
  12   * Usage :  yourls_deprecated_function( 'function_name', 'version' );
  13   * Output:  "{function_name} is deprecated since version {version} with no alternative available."
  14   *
  15   * @see yourls_deprecated_function()
  16   */
  17  
  18  // @codeCoverageIgnoreStart
  19  
  20  /**
  21   * Return current admin page, or null if not an admin page. Was not used anywhere.
  22   *
  23   * @return mixed string if admin page, null if not an admin page
  24   * @since 1.6
  25   * @deprecated 1.9.1
  26   */
  27  function yourls_current_admin_page() {
  28      yourls_deprecated_function( __FUNCTION__, '1.9.1' );
  29      if( yourls_is_admin() ) {
  30          $current = substr( yourls_get_request(), 6 );
  31          if( $current === false )
  32              $current = 'index.php'; // if current page is http://sho.rt/admin/ instead of http://sho.rt/admin/index.php
  33  
  34          return $current;
  35      }
  36      return null;
  37  }
  38  
  39  /**
  40   * PHP emulation of JS's encodeURI
  41   *
  42   * @link https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/encodeURI
  43   * @deprecated 1.9.1
  44   * @param string $url
  45   * @return string
  46   */
  47  function yourls_encodeURI($url) {
  48      yourls_deprecated_function( __FUNCTION__, '1.9.1', '' );
  49      // Decode URL all the way
  50      $result = yourls_rawurldecode_while_encoded( $url );
  51      // Encode once
  52      $result = strtr( rawurlencode( $result ), array (
  53          '%3B' => ';', '%2C' => ',', '%2F' => '/', '%3F' => '?', '%3A' => ':', '%40' => '@',
  54          '%26' => '&', '%3D' => '=', '%2B' => '+', '%24' => '$', '%21' => '!', '%2A' => '*',
  55          '%27' => '\'', '%28' => '(', '%29' => ')', '%23' => '#',
  56      ) );
  57      // @TODO:
  58      // Known limit: this will most likely break IDN URLs such as http://www.académie-française.fr/
  59      // To fully support IDN URLs, advocate use of a plugin.
  60      return yourls_apply_filter( 'encodeURI', $result, $url );
  61  }
  62  
  63  /**
  64   * Check if a file is a plugin file
  65   *
  66   * @deprecated 1.8.3
  67   */
  68  function yourls_validate_plugin_file( $file ) {
  69      yourls_deprecated_function( __FUNCTION__, '1.8.3', 'yourls_is_a_plugin_file' );
  70      return yourls_is_a_plugin_file($file);
  71  }
  72  
  73  /**
  74   * Return a unique(ish) hash for a string to be used as a valid HTML id
  75   *
  76   * @deprecated 1.8.3
  77   */
  78  function yourls_string2htmlid( $string ) {
  79      yourls_deprecated_function( __FUNCTION__, '1.8.3', 'yourls_unique_element_id' );
  80      return yourls_apply_filter( 'string2htmlid', 'y'.abs( crc32( $string ) ) );
  81  }
  82  
  83  /**
  84   * Get search text from query string variables search_protocol, search_slashes and search
  85   *
  86   * Some servers don't like query strings containing "(ht|f)tp(s)://". A javascript bit
  87   * explodes the search text into protocol, slashes and the rest (see JS function
  88   * split_search_text_before_search()) and this function glues pieces back together
  89   * See issue https://github.com/YOURLS/YOURLS/issues/1576
  90   *
  91   * @since 1.7
  92   * @deprecated 1.8.2
  93   * @return string Search string
  94   */
  95  function yourls_get_search_text() {
  96      yourls_deprecated_function( __FUNCTION__, '1.8.2', 'YOURLS\Views\AdminParams::get_search' );
  97      $view_params = new YOURLS\Views\AdminParams();
  98      return $view_params->get_search();
  99  }
 100  
 101  /**
 102   * Retrieve the current time based on specified type. Stolen from WP.
 103   *
 104   * The 'mysql' type will return the time in the format for MySQL DATETIME field.
 105   * The 'timestamp' type will return the current timestamp.
 106   *
 107   * If $gmt is set to either '1' or 'true', then both types will use GMT time.
 108   * if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.
 109   *
 110   * @since 1.6
 111   * @deprecated 1.7.10
 112   *
 113   * @param string $type Either 'mysql' or 'timestamp'.
 114   * @param int|bool $gmt Optional. Whether to use GMT timezone. Default is false.
 115   * @return int|string String if $type is 'gmt', int if $type is 'timestamp'.
 116   */
 117  function yourls_current_time( $type, $gmt = 0 ) {
 118      yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_get_timestamp' );
 119      switch ( $type ) {
 120          case 'mysql':
 121              return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', yourls_get_timestamp( time() ));
 122          case 'timestamp':
 123              return ( $gmt ) ? time() : yourls_get_timestamp( time() );
 124      }
 125  }
 126  
 127  /**
 128   * Lowercase scheme and domain of an URI - see issues 591, 1630, 1889
 129   *
 130   * Renamed to yourls_normalize_uri() in 1.7.10 because the function now does more than just
 131   * lowercasing the scheme and domain.
 132   *
 133   * @deprecated 1.7.10
 134   *
 135   */
 136  function yourls_lowercase_scheme_domain( $url ) {
 137      yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_normalize_uri' );
 138      return yourls_normalize_uri( $url );
 139  }
 140  
 141  /**
 142   * The original string sanitize function
 143   *
 144   * @deprecated 1.7.10
 145   *
 146   */
 147  function yourls_sanitize_string( $string, $restrict_to_shorturl_charset = false ) {
 148      yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_sanitize_keyword' );
 149      return yourls_sanitize_keyword( $string, $restrict_to_shorturl_charset );
 150  }
 151  
 152  /**
 153   * Return favicon URL (either default or custom)
 154   *
 155   * @deprecated 1.7.10
 156   *
 157   */
 158  function yourls_favicon( $echo = true ) {
 159      yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_get_yourls_favicon_url' );
 160      return yourls_get_yourls_favicon_url( $echo );
 161  }
 162  
 163  /**
 164   * Return array of stats for a given keyword
 165   *
 166   * @deprecated 1.7.10
 167   *
 168   */
 169  function yourls_get_link_stats( $url ) {
 170      yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_get_keyword_stats' );
 171      return yourls_get_keyword_stats( $url );
 172  }
 173  
 174  /**
 175   * Check if a long URL already exists in the DB. Return NULL (doesn't exist) or an object with URL informations.
 176   *
 177   * @since 1.5.1
 178   * @deprecated 1.7.10
 179   *
 180   */
 181  function yourls_url_exists( $url ) {
 182      yourls_deprecated_function( __FUNCTION__, '1.7.10', 'yourls_long_url_exists' );
 183      return yourls_long_url_exists( $url );
 184  }
 185  
 186  /**
 187   * Return word or words if more than one
 188   *
 189   */
 190  function yourls_plural( $word, $count=1 ) {
 191      yourls_deprecated_function( __FUNCTION__, '1.6', 'yourls_n' );
 192      return $word . ($count > 1 ? 's' : '');
 193  }
 194  
 195  /**
 196   * Return list of all shorturls associated to the same long URL. Returns NULL or array of keywords.
 197   *
 198   */
 199  function yourls_get_duplicate_keywords( $longurl ) {
 200      yourls_deprecated_function( __FUNCTION__, '1.7', 'yourls_get_longurl_keywords' );
 201      if( !yourls_allow_duplicate_longurls() )
 202          return NULL;
 203      return yourls_apply_filter( 'get_duplicate_keywords', yourls_get_longurl_keywords ( $longurl ), $longurl );
 204  }
 205  
 206  /**
 207   * Make sure a integer is safe
 208   *
 209   * Note: this function is dumb and dumbly named since it does not intval(). DO NOT USE.
 210   *
 211   */
 212  function yourls_intval( $int ) {
 213      yourls_deprecated_function( __FUNCTION__, '1.7', 'yourls_sanitize_int' );
 214      return yourls_escape( $int );
 215  }
 216  
 217  /**
 218   * Get remote content via a GET request using best transport available
 219   *
 220   */
 221  function yourls_get_remote_content( $url,  $maxlen = 4096, $timeout = 5 ) {
 222      yourls_deprecated_function( __FUNCTION__, '1.7', 'yourls_http_get_body' );
 223      return yourls_http_get_body( $url );
 224  }
 225  
 226  /**
 227   * Alias for yourls_apply_filter because I never remember if it's _filter or _filters
 228   *
 229   * At first I thought it made semantically more sense but thinking about it, I was wrong. It's one filter.
 230   * There may be several function hooked into it, but it still the same one filter.
 231   *
 232   * @since 1.6
 233   * @deprecated 1.7.1
 234   *
 235   * @param string $hook the name of the YOURLS element or action
 236   * @param mixed $value the value of the element before filtering
 237   * @return mixed
 238   */
 239  function yourls_apply_filters( $hook, $value = '' ) {
 240      yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_apply_filter' );
 241      return yourls_apply_filter( $hook, $value );
 242  }
 243  
 244  /**
 245   * Check if we'll need interface display function (ie not API or redirection)
 246   *
 247   */
 248  function yourls_has_interface() {
 249      yourls_deprecated_function( __FUNCTION__, '1.7.1' );
 250      if( yourls_is_API() or yourls_is_GO() )
 251          return false;
 252      return true;
 253  }
 254  
 255  /**
 256   * Check if a proxy is defined for HTTP requests
 257   *
 258   * @uses YOURLS_PROXY
 259   * @since 1.7
 260   * @deprecated 1.7.1
 261   * @return bool true if a proxy is defined, false otherwise
 262   */
 263  function yourls_http_proxy_is_defined() {
 264      yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_http_get_proxy' );
 265      return yourls_apply_filter( 'http_proxy_is_defined', defined( 'YOURLS_PROXY' ) );
 266  }
 267  
 268  /**
 269   * Displays translated string with gettext context
 270   *
 271   * This function has been renamed yourls_xe() for consistency with other *e() functions
 272   *
 273   * @see yourls_x()
 274   * @since 1.6
 275   * @deprecated 1.7.1
 276   *
 277   * @param string $text Text to translate
 278   * @param string $context Context information for the translators
 279   * @param string $domain Optional. Domain to retrieve the translated text
 280   * @return string Translated context string without pipe
 281   */
 282  function yourls_ex( $text, $context, $domain = 'default' ) {
 283      yourls_deprecated_function( __FUNCTION__, '1.7.1', 'yourls_xe' );
 284      echo yourls_xe( $text, $context, $domain );
 285  }
 286  
 287  /**
 288   * Escape a string or an array of strings before DB usage. ALWAYS escape before using in a SQL query. Thanks.
 289   *
 290   * Deprecated in 1.7.3 because we moved onto using PDO and using built-in escaping functions, instead of
 291   * rolling our own.
 292   *
 293   * @deprecated 1.7.3
 294   * @param string|array $data string or array of strings to be escaped
 295   * @return string|array escaped data
 296   */
 297  function yourls_escape( $data ) {
 298      yourls_deprecated_function( __FUNCTION__, '1.7.3', 'PDO' );
 299      if( is_array( $data ) ) {
 300          foreach( $data as $k => $v ) {
 301              if( is_array( $v ) ) {
 302                  $data[ $k ] = yourls_escape( $v );
 303              } else {
 304                  $data[ $k ] = yourls_escape_real( $v );
 305              }
 306          }
 307      } else {
 308          $data = yourls_escape_real( $data );
 309      }
 310  
 311      return $data;
 312  }
 313  
 314  /**
 315   * "Real" escape. This function should NOT be called directly. Use yourls_escape() instead.
 316   *
 317   * This function uses a "real" escape if possible, using PDO, MySQL or MySQLi functions,
 318   * with a fallback to a "simple" addslashes
 319   * If you're implementing a custom DB engine or a custom cache system, you can define an
 320   * escape function using filter 'custom_escape_real'
 321   *
 322   * @since 1.7
 323   * @deprecated 1.7.3
 324   * @param string $a string to be escaped
 325   * @return string escaped string
 326   */
 327  function yourls_escape_real( $string ) {
 328      yourls_deprecated_function( __FUNCTION__, '1.7.3', 'PDO' );
 329      global $ydb;
 330      if( isset( $ydb ) && ( $ydb instanceof \YOURLS\Database\YDB ) )
 331          return $ydb->escape( $string );
 332  
 333      // YOURLS DB classes have been bypassed by a custom DB engine or a custom cache layer
 334      return yourls_apply_filter( 'custom_escape_real', addslashes( $string ), $string );
 335  }
 336  
 337  // @codeCoverageIgnoreEnd


Generated: Wed Sep 28 05:10:02 2022 Cross-referenced by PHPXref 0.7.1