function shurly_next_url in ShURLy 8
Same name and namespace in other branches
- 6 shurly.module \shurly_next_url()
 - 7 shurly.module \shurly_next_url()
 
Return next available short URL.
2 calls to shurly_next_url()
- ShurlyCreateForm::validateForm in src/
Form/ ShurlyCreateForm.php  - Form validation handler.
 - shurly_shorten in ./
shurly.module  - API function to shorten a URL.
 
File
- ./
shurly.module, line 517  - Description http://www.youtube.com/watch?v=Qo7qoonzTCE.
 
Code
function shurly_next_url() {
  $count = \Drupal::state()
    ->get('shurly.settings.shurly_counter', \Drupal::config('shurly.settings')
    ->get('shurly_counter'));
  do {
    $count++;
    // Counter is stored as base 10
    // $index is a-z, A-Z, 0-9, sorted randomly, with confusing characters (01lIO) removed - 57 characters
    // a custom index can be created as a variable override in settings.php.
    $index = \Drupal::config('shurly.settings')
      ->get('shurly_index');
    $str = shurly_dec2any($count, NULL, $index);
    // Check that this string hasn't been used already
    // check that the string is a valid (available) path.
  } while (shurly_url_exists($str) !== FALSE || shurly_path_available($str) === FALSE);
  \Drupal::state()
    ->set('shurly.settings.shurly_counter', $count);
  return $str;
}