You are here

function shurly_save_url in ShURLy 8

Same name and namespace in other branches
  1. 6 shurly.module \shurly_save_url()
  2. 7 shurly.module \shurly_save_url()

API function to save a URL.

@arg $custom is a TRUE/FALSE

2 calls to shurly_save_url()
ShurlyCreateForm::submitAjaxCall in src/Form/ShurlyCreateForm.php
shurly_shorten in ./shurly.module
API function to shorten a URL.

File

./shurly.module, line 289
Description http://www.youtube.com/watch?v=Qo7qoonzTCE.

Code

function shurly_save_url($long_url, $short_path, $account = NULL, $custom = NULL) {
  if (empty($account)) {
    $account = \Drupal::currentUser();
  }
  $request_time = \Drupal::time()
    ->getRequestTime();
  $record = [];
  $record['destination'] = $long_url;
  $record['hash'] = md5($long_url);
  $record['custom'] = $custom ? 1 : 0;
  $record['created'] = $request_time;
  $record['source'] = $short_path;
  $record['uid'] = $account
    ->id();
  $record['count'] = $record['last_used'] = 0;
  $record['active'] = 1;
  return \Drupal::database()
    ->insert('shurly')
    ->fields($record)
    ->execute();
}