示例#1
0
 /**
  * сохранение площадки
  *
  * @param Platform $platform
  */
 public function save(Platform $platform)
 {
     $isNew = $platform->getId() ? false : true;
     $this->em->persist($platform);
     $this->em->flush($platform);
     if ($isNew) {
         $platform->setHashId($this->hashids->encode($platform->getId()));
     }
     $platform->updateUpdatedAt();
     $this->tagManager->saveTagging($platform);
     $this->em->flush();
 }
示例#2
0
 /**
  * Сохраняет кампанию и хеширует id
  *
  * @param Campaign $campaign
  */
 public function save(Campaign $campaign)
 {
     $isNew = $campaign->getId() ? false : true;
     $this->em->persist($campaign);
     $this->em->flush($campaign);
     if ($isNew) {
         $campaign->setHashId($this->hashids->encode($campaign->getId()));
     }
     $campaign->updateUpdatedAt();
     $this->tagManager->saveTagging($campaign);
     $this->em->flush();
 }
 /**
  * Add activity metadata 
  * 
  * @param User $user
  * @param Activity $activity
  * @param array $data    key-value pair data to store
  * @param array $exclude When given exclude keys to be stored in the database
  */
 public static function addUserActivity(User $user, Activity $activity, array $data, array $exclude = [])
 {
     $rows = [];
     $exclude = array_map('strtolower', $exclude);
     // Create a session_id.
     // Session_id is use for easily identify groups of metadata
     $hashids = new Hashids('dma.activity.metadata', 6);
     $user_id = $user->getKey();
     $activity_id = $activity->getKey();
     // Add unixtime and microseconds to avoid session_id collisions
     $micro = microtime(true);
     $unixtime = floor($micro);
     $milseconds = floor(($micro - $unixtime) * pow(10, 8));
     // Create session_id
     $session_id = $hashids->encode($user_id, $activity_id, $unixtime, $milseconds);
     // Current date and time
     $now = date('Y-m-d H:i:s');
     foreach ($data as $key => $value) {
         $key = strtolower($key);
         if (!in_array($key, $exclude)) {
             $row = ['session_id' => $session_id, 'user_id' => $user_id, 'activity_id' => $activity_id, 'key' => $key, 'value' => $value, 'created_at' => $now, 'updated_at' => $now];
             $rows[] = $row;
         }
     }
     if (count($row) > 0) {
         static::insert($rows);
     }
 }
示例#4
0
 public function getHashidsShortcode($id)
 {
     // create hashids for shortcode using the url row id
     $hashids = new Hashids("this is my salt", 5, "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ1234567890");
     $shortcode = $hashids->encode($id);
     // $numbers = $hashids->decode($id);
     return $shortcode;
 }
示例#5
0
 /**
  * Process, filter and return the given data
  * @param mixed $jsonValue the value of the property in the JSON
  * @param mixed $objectValue the value of the property in the Object
  * @param bool $jsonToObject If the process works with the json or object value first
  * @return mixed
  */
 public function process($jsonValue, $objectValue, $jsonToObject = true)
 {
     $hashids = new Hashids(JacksonPhp::$hashIdsSalt, 8);
     if ($jsonToObject) {
         $decodedId = $hashids->decode($jsonValue);
         return count($decodedId) > 0 ? $decodedId[0] : "";
     } else {
         return $hashids->encode($objectValue);
     }
 }
示例#6
0
 /**
  * Generate a hashid based on random data.
  *
  * @param null $salt
  *
  * @return string
  */
 function generate_hashid($salt = null)
 {
     if (empty($salt)) {
         $salt = config('key');
     }
     $hashids = new Hashids($salt);
     $min = rand(1, 1000) * rand(1, 1000);
     $max = rand(1, 1000) * rand(1, 1000);
     $quantity = rand(1, 64);
     $numbers = unique_random_numbers_within_range($min, $max, $quantity);
     return StaticStringy::truncate(StaticStringy::shuffle($hashids->encode($numbers)), 8);
 }
示例#7
0
 public function setAvatar($user_id, $avatar)
 {
     $hashids = new Hashids('amtek123456');
     $source = $avatar;
     $filename = 'avatar_u' . $hashids->encode($user_id);
     $manager = new ImageManager();
     $upload_dir = PATH_AVATAR;
     $image = $manager->make($source);
     $image->save($upload_dir . '/' . $filename, 90);
     $data['avatar'] = $filename;
     $this->db->where('user_id', $user_id);
     $this->db->update('profile', $data);
 }
示例#8
0
 public function test()
 {
     echo __CLASS__, "</br>", __METHOD__, "</br>";
     $id = 12;
     $hashids = new Hashids('this is mysalt111');
     $en = $hashids->encode($id);
     $de = $hashids->decode($en);
     //var_dump($en,$de);
     $a = $_SERVER["REQUEST_URI"];
     $path = $_SERVER["QUERY_STRING"];
     $query = $_SERVER["SCRIPT_NAME"];
     //echo $a,"<br>",$path,"<br>",$query,"<br>",$_SERVER['HOST'];
     var_dump($_SERVER);
     //echo "hiiiiiiiii";
 }
示例#9
0
 public function test()
 {
     $a = $this->one;
     $u = new User();
     $wo = strpos('fling', $a);
     $_SERVER['yyy'] = "xxx";
     header("HTTP/1.1 204 OK");
     header("cache-control:max-age=0");
     header("cache-control:no-cache");
     header("expires:0");
     header("expires:Tue, 01 Jan 1980 1:00:00 GMT");
     header("pragma:no-cache");
     $view = view("testone")->withName("xj");
     // test jsonp
     return $view;
     /*
     echo "head";
     //echo "php_self=".$_SERVER['PHP_SELF']."<BR>";
     //echo "http_referer=".$_SERVER['HTTP_REFERER']."<BR>";
     //return $_SERVER;
     exit;
     echo $_SERVER['SCRIPT_FILENAME']."<BR>";
     echo $_SERVER['HTTP_HOST'],"<BR>";
     echo $_SERVER['REQUEST_URI'],"<BR>";
     //return $_SERVER;
     //      var_dump($_SERVER);
     */
     //exit;
     //echo __CLASS__,"</br>",__METHOD__;
     //$a=Apacl::getinfo("hello");
     //echo $a;
     $a = msgService::add("aaa");
     $b = new msgService();
     $c = $b->info("waa");
     echo $a;
     echo $c;
     exit;
     echo __CLASS__, "</br>", __METHOD__, "</br>";
     $id = 12;
     $hashids = new Hashids('this is mysalt111');
     $en = $hashids->encode($id);
     $de = $hashids->decode($en);
     //var_dump($en,$de);
     $a = $_SERVER["REQUEST_URI"];
     $path = $_SERVER["QUERY_STRING"];
     $query = $_SERVER["SCRIPT_NAME"];
     var_dump($_SERVER);
 }
示例#10
0
文件: Hasher.php 项目: n8b/VMN
 /**
  * Create unqiue hash and store it in the database
  * @return string Hash
  */
 public function save()
 {
     $url = sanitize_string($this->url);
     $hash = sanitize_string($this->hash);
     $time_created = sanitize_int($this->time_created);
     $meta = !is_string($this->meta) ? json_encode($this->meta) : $this->meta;
     $meta = sanitize_string($meta);
     if (!$this->id) {
         $query = "INSERT INTO {$this->dbprefix}url_meta_cache (long_url, hash, meta, time_created)\n\t\t\t\t\tVALUES ('{$url}','{$hash}','{$meta}',{$time_created})\n\t\t\t\t\t\tON DUPLICATE KEY UPDATE long_url='{$url}',meta='{$meta}'";
         $id = insert_data($query);
         $this->id = $id;
         $hashids = new Hashids(get_site_secret());
         $hash = $hashids->encode($id, $this->time_created);
         $query = "UPDATE LOW_PRIORITY {$this->dbprefix}url_meta_cache\n\t\t\t\t\tSET hash = '{$hash}' WHERE id = {$id}";
         update_data($query);
     } else {
         $query = "UPDATE {$this->dbprefix}url_meta_cache SET meta='{$meta}'\n\t\t\t\t\t\tWHERE id='{$this->id}'";
     }
     self::$cache[$this->url] = array('id' => $this->id, 'hash' => $this->hash, 'meta' => $this->meta, 'time_created' > $this->time_created);
     return $hash;
 }
示例#11
0
 public function encode($value)
 {
     $hashids = new Hashids(config('paysera.projectid'), 10);
     return $hashids->encode($value);
 }
示例#12
0
 /**
  * Store a newly created Url in storage.
  * Required: long_url
  * Optional: custom_key, category
  */
 public function create(Request $request)
 {
     //	Get the largest Id of url from db
     $maxId = Url::withTrashed()->max('id');
     //	Validate maxId, and fix it
     if (!isset($maxId)) {
         $maxId = 0;
     }
     //	Validate custom Key (key for short url), and generate new one using MAXID
     if (empty($request["custom_key"])) {
         $hashids = new Hashids('smpx', 6);
         $hashedUrl = $hashids->encode($maxId++);
     } else {
         $hashedUrl = $request["custom_key"];
     }
     //	trim long url (Original Url)
     $longUrl = trim($request["long_url"]);
     //	Validate Long Url and send error if invalid
     if (strlen($longUrl) <= 0) {
         $error = Utility::getError(null, 400, 'Error', 'Invalid Url');
         return response()->json($error, 400);
     }
     //	Check whether Long url contains http protocol or not, If not then append 'http://'
     //	Here not checking for protocols other than http
     if (substr($longUrl, 0, 7) !== "http://" and substr($longUrl, 0, 8) !== "https://") {
         $longUrl = 'http://' . $longUrl;
     }
     //	Validate category
     if (!isset($request["category"]) || $request["category"] == '') {
         $category = 'no_category';
     } else {
         $category = $request["category"];
     }
     //	build array object of Url data to save to DB
     $array = array('long_url' => $longUrl, 'short_url' => config('app.url') . '/' . $hashedUrl, 'is_active' => true, 'clicks' => 0, 'category' => $category);
     try {
         //	save Url data to DB
         $urlInstance = Url::create($array);
     } catch (QueryException $e) {
         // Make logging for QueryException
         $error = Utility::getError(null, 400, 'Error', 'Duplicate Entry of short Url');
         return response()->json($error, 400);
     }
     //	Add attribute 'time' containing humna readable time format
     $urlInstance['time'] = $urlInstance['created_at']->diffForHumans(Carbon::now());
     //	Build response object
     $res = new \stdClass();
     $res->status = 'Success';
     $res->data = $urlInstance;
     $res->message = 'Successfully created';
     //	Send response Object in json string
     return response()->json($res, 200);
 }
示例#13
0
 /**
  * Generate a unique code for this group.
  * This code can be used to join this group
  * @return string
  */
 public function generateCode()
 {
     $hashids = new Hashids('friends', 6, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890');
     $id = $this->getKey();
     $owner_id = $this->owner->getKey();
     $code = $hashids->encode($id, $owner_id);
     return $code;
 }
 /**
  * Generates ticket Hash ID
  *
  * @param integer $id
  *
  * @return string
  */
 public function generateHashId($id)
 {
     $code = new Hashids(Config::get('app.key'), 8, 'ABCDEF1234567890');
     return $code->encode($id);
 }
示例#15
0
 /**
  * Encode the value.
  *
  * @param  mixed  $value
  *
  * @return string
  */
 public function encode($value)
 {
     return $this->hasher->encode($value);
 }
示例#16
0
 /**
  * Accessor for get the public id from a real id as attribute.
  * Simply use: $model->public_id to get the public id value.
  *
  * @access      public
  *
  * @param       integer     $id
  * @return      string
  */
 public function getPublicIdAttribute()
 {
     $hashids = new Hashids(self::getSalt(), self::getMinLength(), self::getAlphabet());
     $primaryKey = $this->primaryKey;
     return $hashids->encode($this->{$primaryKey});
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $hashids = new Hashids('smpx', 6);
     $hashed_url = $hashids->encode(125);
     $url = new Url();
     $url->long_url = $request["long_url"];
     $url->short_url = config('app.url') + '/' + $hashed_url;
     $url->is_active = true;
     $url->clicks = 0;
     $urlInstance = $url->create();
     echo $urlInstance->toJson(), "hoeee";
     return;
 }
示例#18
0
 /**
  * Encodes integers.
  *
  * @since 150424 Adding hash IDs.
  *
  * @param int ...$integers Variadic integers to encode.
  *
  * @return string A hash ID; e.g., `xjFsdcl`
  */
 public function encode(int ...$integers) : string
 {
     return $this->Parser->encode(...$integers);
 }
示例#19
0
文件: hashid.php 项目: xiehaowei/php
<?php

/**
 * Created by PhpStorm.
 * User: xiehaowei
 * Date: 2016/11/8
 * Time: 下午8:02
 */
use Hashids\Hashids;
$hashId = new Hashids('eric', 6, 'abcdefgABCDEFG1234567890');
$h = $hashId->encode(1000);
echo $h . PHP_EOL;
var_dump($h);
var_dump($hashId->decode('g141G0'));
exit;
 /**
  * @return void
  */
 public function testSaveWithField()
 {
     $this->Addresses->behaviors()->Hashid->config('field', 'hash');
     $data = ['city' => 'Foo'];
     $address = $this->Addresses->newEntity($data);
     $res = $this->Addresses->save($address);
     $this->assertTrue((bool) $res);
     $this->assertSame(3, $address->id);
     $hasher = new Hashids();
     $expected = $hasher->encode($address->id);
     $this->assertEquals($expected, $address->hash);
 }
示例#21
0
 public function getCodeHashAttribute()
 {
     $hashids = new Hashids('quizprivate123');
     return $hashids->encode($this->id);
 }
示例#22
0
 /**
  * Generates a link that points to the contents of the uploaded file
  * 
  * @param string $model The name of the model where the file is stored
  * @param string $field The field containing the file
  * @param string $id The id of the record
  * @return string The URL of the uploaded file
  */
 public function uploadUrl($model, $field, $id)
 {
     $encodedId = new Hashids(Configure::read('Security.salt'));
     $url = array('controller' => 'upload', 'action' => 'download', 'plugin' => 'dbupload', 'admin' => false, '?' => array('m' => $model, 'f' => $field, 'i' => $encodedId->encode($id)));
     return Router::url($url);
 }
示例#23
0
/*
 * |--------------------------------------------------------------------------
 * | Routes File
 * |--------------------------------------------------------------------------
 * |
 * | Here is where you will register all of the routes in an application.
 * | It's a breeze. Simply tell Laravel the URIs it should respond to
 * | and give it the controller to call when that URI is requested.
 * |
 */
Route::get('/', function () {
    return view('index');
});
Route::get('/generate/{count}', function ($count) {
    $hashids = new Hashids('smpx', 6);
    echo $hashids->encode($count);
});
Route::resource('/urls', 'UrlController', ['only' => ['index', 'show', 'create', 'store', 'edit', 'destroy', 'update']]);
Route::get('/urls/from/{from}/to/{to}', 'UrlController@getLimitedUrls');
Route::get('/urls/from/{from}', 'UrlController@getLimitedUrlsUsingFrom');
Route::get('/{shortUrl}', 'UrlController@redirect');
/*
 * |--------------------------------------------------------------------------
 * | Application Routes
 * |--------------------------------------------------------------------------
 * |
 * | This route group applies the "web" middleware group to every route
 * | it contains. The "web" middleware group is defined in your HTTP
 * | kernel and includes session state, CSRF protection, and more.
 * |
 */
 /**
  * Number to encode.
  *
  * @param int $number The integer to encode
  * @param int $length The minimum id length setting
  *
  * @return string The hash-like string
  *
  * @api
  */
 public function encodeID(int $number, int $length = 21) : string
 {
     $this->setCipherKey($this->initializationVector);
     $hashids = new Hashids($this->cipherKey, $length);
     return $hashids->encode($number);
 }
示例#25
0
 public function getLinkDownloadAttribute()
 {
     $hashids = new Hashids($this->hashids_salt);
     $id = $hashids->encode($this->id);
     return kelas_url('course/download/' . $id);
 }
示例#26
0
文件: Gateway.php 项目: refo/payment
 /**
  *
  */
 protected function generateId($minLen = 6)
 {
     $salt = 'Muh1tt1n Ne 3tT1n';
     $alphabet = '0123456789ACDEFGHJKLMNPRTUVXYZ';
     $hash = new Hashids($salt, $minLen, $alphabet);
     $mtime = time() - 1420092000;
     // Thu, 01 Jan 2015 06:00:00
     return $hash->encode($mtime);
 }
示例#27
0
 public function getHashids()
 {
     $hashids = new Hashids(HASHIDS_SALT);
     $id = $hashids->encode($this->model->id);
     return $id;
 }
示例#28
0
 /**
  * Get the value of the model's route key.
  *
  * @return mixed
  */
 public function getRouteKey()
 {
     $hashids = new Hashids('MySecretSalt*(&^%$eo&*^%&r', 20);
     return $hashids->encode($this->getKey());
 }
示例#29
0
 /**
  * Use the encode function to obscure the ids in your views
  *
  * @param $id
  * @return string
  */
 public function encode($id)
 {
     $hashids = new Hashids(config('obscure.salt'), config('obscure.length'), config('obscure.alphabet'));
     return $hashids->encode($id);
 }
示例#30
0
 /**
  * Encode an ID to a HASH.
  *
  * @param $id
  * @return string
  */
 private function encode($id)
 {
     return $this->hash->encode($id);
 }