コード例 #1
4
<?php

/* include hashids lib */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* create the class object with minimum hashid length of 8 */
$hashids = new Hashids\Hashids('this is my salt', 8);
/* encode several numbers into one id (length of id is going to be at least 8) */
$id = $hashids->encode(1337, 5);
/* decode the same id */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
コード例 #2
1
ファイル: Wash.php プロジェクト: pean/wash
 protected function hashids($type, $str)
 {
     $hashids = new \Hashids\Hashids(md5($this->config['salt']));
     if ($type == 'decode') {
         return end($hashids->decode($str));
     } elseif ($type == "encode") {
         return $hashids->encode($str);
     }
 }
コード例 #3
0
ファイル: dbinc.php プロジェクト: Klazen108/gm_fiddle
function addEntry($text, $title, $description)
{
    $success = false;
    $db = connectDB();
    $db->beginTransaction();
    $query = "INSERT INTO " . DB_TABLE . " (text_content,title,description) VALUES ( :text , :title , :desc )";
    $params = array(":text" => $text, ":title" => $title, ":desc" => $description);
    $rowCount = execute($db, $query, $params);
    if ($rowCount > 0) {
        $last_id = $db->lastInsertId();
        $hashids = new Hashids\Hashids('welcome to the salty splatoon how tough are ya');
        $hash = $hashids->encode($last_id);
        $editor_hash = bin2hex(mcrypt_create_iv(22, MCRYPT_DEV_URANDOM));
        $query = "\n\t\tUPDATE " . DB_TABLE . "\n\t\tSET hash = :hash ,\n\t\t\teditor_hash = :ehash \n\t\tWHERE id = :id ";
        $params = array(":hash" => $hash, ":ehash" => $editor_hash, ":id" => $last_id);
        $rowCount = execute($db, $query, $params);
        if ($rowCount > 0) {
            $db->commit();
            $success = true;
        } else {
            $db->rollBack();
        }
    } else {
        $db->rollBack();
        //if ($last_id) execute($db,"DELETE FROM ".DB_TABLE." WHERE id = :id ",array(":id"=>$last_id));
    }
    close($db);
    if ($success) {
        return getEntryById($last_id);
    } else {
        return null;
    }
}
コード例 #4
0
ファイル: Tools.php プロジェクト: sheyooo/testify
 public static function generateHashID($salt, $id)
 {
     $hashids = new Hashids\Hashids($salt, 10);
     $id = $hashids->encode($id);
     //$numbers = $hashids->decode($id);
     //echo $id;
     return $id;
 }
コード例 #5
0
function hashSubscriber($subscriber)
{
    $hashids = new Hashids\Hashids(config('gtw.hashid.salts.subscribers'), 20, config('gtw.hashid.hash_chars'));
    if (!is_int($subscriber)) {
        $subscriber = $subscriber->id;
    }
    return $hashids->encode($subscriber);
}
コード例 #6
0
 public function setFeaturedImage($article_id, $featured_image = null)
 {
     if ($featured_image) {
         $hashids = new Hashids\Hashids(HASHIDS_SALT);
         $id = $hashids->encode($article_id);
         $source = $featured_image['tmp_name'];
         $filename = 'article_' . $id . '_' . $featured_image['name'];
         $manager = new ImageManager();
         $upload_dir = PATH_PORTAL_CONTENT . '/featured/';
         $image = $manager->make($source);
         $image->save($upload_dir . $filename, 90);
         $data['featured_image'] = $filename;
         $this->db->where('id', $article_id);
         $this->db->update('artikel', $data);
         return $image->exif();
     } else {
         return FALSE;
     }
 }
コード例 #7
0
<?php

/* include hashids lib */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode one number */
$id = $hashids->encode(1337);
/* `$id` is always a string */
var_dump($id);
exit;
コード例 #8
0
ファイル: app.php プロジェクト: payberah/LinuxFestival
function submit_reg_form()
{
    //ReCaptcha
    $recaptcha = new ReCaptcha(RECAPTCHA_SECRET);
    $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
    if (!$resp->isSuccess()) {
        throw new Exception('Invalid captcha!');
    }
    //Get & Process form data
    $valid_inputs = 'name|email|tel|inst|std|day1|day2';
    foreach (get_presentations() as $key => $data) {
        $valid_inputs .= "|{$key}";
    }
    $form_data = getInputsWithKey($valid_inputs);
    //----Pricing
    //Count days
    $days = 0;
    for ($i = 1; $i <= 2; $i++) {
        if ($form_data["day{$i}"] != 'no') {
            $days++;
        }
    }
    $price = $days * 35;
    //    if ($days > 1)
    //        $price -= 10;
    //Discount
    $discount_rate = 0;
    if (isset($form_data['std'])) {
        switch ($form_data['std']) {
            case 'aut':
                $discount_rate = 0.6;
                break;
            case 'std':
                $discount_rate = 0.25;
                break;
        }
    }
    $price *= 1.0 - $discount_rate;
    $price = round($price);
    $form_data['price'] = $price;
    //Tel
    $form_data['tel'] = intval($form_data['tel']);
    //Generate tracking code
    $hashids = new Hashids\Hashids(HASHID_SALT);
    $tracking_code = $hashids->encode(time() . rand(0, 100));
    $form_data['code'] = $tracking_code;
    //Check Google Client Expired
    $token = json_decode(gapi_token, true);
    $client = new Google_Client();
    $client->setClientId(GAPI_CLIENT_ID);
    $client->setClientSecret(GAPI_CLIENT_SECRET);
    $client->setAccessToken(gapi_token);
    if ($client->isAccessTokenExpired()) {
        //Refresh on expire
        $client->refreshToken($client->getRefreshToken());
        foreach (json_decode($client->getAccessToken(), true) as $k => $v) {
            $token[$k] = $v;
        }
        file_put_contents(GAPI_TOKEN_LOCATION, "<?php define('gapi_token','" . json_encode($token) . "');");
    }
    //Get Registration sheet
    $serviceRequest = new DefaultServiceRequest($token['access_token']);
    ServiceRequestFactory::setInstance($serviceRequest);
    $spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
    $sheet = $spreadsheetService->getSpreadsheets()->getByTitle('linuxfest_2015')->getWorksheets()->getByTitle('List');
    //Insert Submitted data
    $sheet->getListFeed()->insert($form_data);
    //Message
    $msg = "\n<div dir='rtl'>\n\n       با تشکر، ثبت نام آنلاین شما با موفقیت انجام شد و مورد بررسی قرار خواهد گرفت.\n        <br>\n        هزینه ی ثبت نام شما : <b>{$price}</b> هزار تومان\n                <br>\n        کد رهگیری شما : <b>{$tracking_code}</b>\n        (این کد را برای مراحل بعدی حتما نگهدارید)<br>\n        <br>\n                لطفا در اسرع وقت با مراجعه‌ی حضوری به دفتر انجمن علمی دانشکده هزینه‌ی دوره‌هایی را که در آن‌ها ثبت نام کرده‌اید پرداخت نمایید. در صورتی که مراجعه‌ی حضوری برایتان مقدور نیست هزینه‌ی ثبت نام را به کارت 5022291100266525 (بانک پاسارگاد به نام آرمین باشی‌زاده) واریز نمایید و کد رهگیری و شماره کارت خود را به آدرس hello@linuxfest.ir ارسال کنید. به دلیل محدود بودن ظرفیت کارگاه‌ها، اولویت با کسانی است که زودتر ثبت نام خود را نهایی کنند.\n<br>\nتهران، چهارراه ولی عصر، روبه‌روی خیابان بزرگمهر، دانشگاه صنعتی امیرکبیر ، دانشکده مهندسی کامپیوتر و فناوری اطلاعات ، دفتر انجمن علمی\n\t<br>\n     در صورت تمایل به ایجاد هرگونه تغییر در وضعیت ثبت نام خود از ثبت نام مجدد <b> جدا خودداری فرمایید</b>. در غیر این صورت ثبت نام شما تایید نخواهد شد.<br>\n      می‌توانید این تغییرات را از دو طریق ایمیل جشنواره hello@linuxfest.ir یا مراجعه‌ی حضوری اعلام فرمایید.\n\n</div>\n    ";
    $msg_2 = "جشنواره لینوکس امیرکبیر\n    هزینه ی ثبت نام : {$price} هزار تومان\n    کد رهگیری شما : {$tracking_code}\n    جهت ثبت نام نهایی در اسرع وقت به دفتر انجمن علمی دانشکده مراجعه فرمایید\n    ";
    //Email
    if (isset($form_data['email'])) {
        sendmail($form_data['email'], $msg);
    }
    //SMS
    if (isset($form_data['tel'])) {
        sendsms($form_data['tel'], $msg_2);
    }
    return $msg;
}
コード例 #9
0
ファイル: rooms.php プロジェクト: cul-it/oku-request
  </div>
  <div class="container">
<?php 
if ($errorMessage != '') {
    echo "<p>{$errorMessage}";
}
# Not sure if id < 1 is an accurate error flag — the create function
# doesn't say what happens if the write fails.
if ($newIssueId < 1) {
    print "\nSomething went wrong -- your request could not be submitted.";
} else {
    # Create a hashed link ID from the new issue number and the requestor's
    # email address (this can be de-hashed to retrieve the original values)
    $hashids = new Hashids\Hashids($cul_ini_array['hashid_salt']);
    $hash_array = encode_link($newIssueId, $_POST['submitter_email']);
    $link_id = $hashids->encode($hash_array);
    echo "<p>You have created request #{$newIssueId}: {$issueTitle}</p>";
    ?>
  <br><br><p>Thank you for submitting your request using the online Library Space Request Form.</p> 
  <p>It is your responsibility to check the status of your event by going to the following address and checking the list of approvers, their approval, and their comments about your event. If the approver requires more information about your event, please contact him/her immediately.</p>
  <p>Use the following link to access your request:

<?php 
    echo '<strong><a href="' . url_for_client($link_id) . '">' . url_for_client($link_id) . '</a></strong>';
    echo '<p>A confirmation email with this information will be sent to you shortly.</p>';
    echo '</div>';
    send_email($issueTitle, $_POST['submitter_email'], $newIssueId, $link_id);
}
function title($label)
{
    return "\n\n" . str_repeat('-', 10) . ' ' . $label . ' ' . str_repeat('-', 10) . "\n";
コード例 #10
0
ファイル: Format.php プロジェクト: microweber/microweber
 public function encode_ids($data)
 {
     $hashids = new \Hashids\Hashids();
     return $hashids->encode($data);
 }
コード例 #11
0
ファイル: query.php プロジェクト: villa7/imgHost
    return preg_replace('/\\<br(\\s*)?\\/?\\>/i', "\n", $s);
}
if (isset($_GET['upload'])) {
    if ($loggedin) {
        if (!empty($_FILES)) {
            $tFile = $_FILES['file']['tmp_name'];
            $fExt = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
            //$fName = sanitize($_FILES['file']['name']); //this file will be replaced if a matching file is uploaded
            /*$fName = str_replace("'", "", $fName);
            		$fName = str_replace('"', "", $fName);*/
            require 'includes/Hashids/HashGenerator.php';
            require 'includes/Hashids/Hashids.php';
            $hashids = new Hashids\Hashids('this is such a great salt', 8);
            $fName = strtotime(date("Y-m-d H:i:s"));
            $fName += gettimeofday()['usec'];
            $fName = $hashids->encode((int) $fName);
            $fHash = $fName;
            $fName .= '.' . $fExt;
            $targetPath = 'images/' . $fName;
            //this file will be replaced if a matching file is uploaded
            $fType = sanitize($_FILES['file']['type']);
            $fSize = sanitize($_FILES['file']['size']);
            //$mimeType = image_type_to_mime_type('IMAGETYPE_'.$fType);
            $mimeType = $fType;
            $date = ['last_modified' => date("F j, Y, g:i a"), 'today' => date("Y-m-d H:i:s")];
            $lmdf = $date['last_modified'];
            if (!file_exists($targetPath)) {
                if (move_uploaded_file($tFile, $targetPath)) {
                    /*$finfo = finfo_open(FILEINFO_MIME_TYPE);
                      $fileType = finfo_file($finfo, $targetPath);
                      finfo_close($finfo);*/
コード例 #12
0
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object with custom alphabet */
$hashids = new Hashids\Hashids('this is my salt', 0, 'abcdefgh123456789');
/* encode several numbers into one id */
$id = $hashids->encode(1, 2, 3, 4);
/* decode the same id */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
コード例 #13
0
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode several numbers into one id */
$id = $hashids->encode(1337, 5, 77, 12345678);
/* decode that id back */
$numbers = $hashids->decode($id);
/* `$numbers` is always an array */
var_dump($id, $numbers);
exit;
コード例 #14
0
<?php

/* be sure to require `hashids` in your `composer.json` file first */
require_once __DIR__ . '/../vendor/autoload.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode several numbers into one id */
$id = $hashids->encode(45, 434, 1313, 99);
$nid = $hashids->encode(array(45, 434, 1313, 99));
/* `$id` is always a string */
var_dump($id);
var_dump($nid);
var_dump($id === $nid);
exit;
コード例 #15
0
function hashCampaignEmail($campaignEmailId)
{
    $hashids = new Hashids\Hashids(config('gtw.hashid.salts.cmapaign_emails'), 20, config('gtw.hashid.hash_chars'));
    return $hashids->encode($campaignEmailId);
}
コード例 #16
0
ファイル: update_db.php プロジェクト: huberyhe/scripts
<?php

require_once 'vendor/autoload.php';
$hashids = new Hashids\Hashids('this is my salt', 10, 'abcdefghij1234567890');
$db = new mysqli("localhost", "root", "123456", 'iksdb3');
if (mysqli_connect_errno()) {
    print 'Error connect.' . "\n";
    exit;
}
$query = 'SELECT id,username FROM iksdb3.iksuser where username REGEXP "^[0-9]+$"';
$result = $db->query($query);
$num_results = $result->num_rows;
print "There are " . $num_results . ' results.' . "\n\n";
for ($i = 0; $i < $num_results; $i++) {
    $row = $result->fetch_assoc();
    $id = $row['id'];
    $username = $row['username'];
    $username_after = $hashids->encode($username);
    $query = 'update iksdb3.iksuser set username = "******" where id=' . $id;
    $result_update = $db->query($query);
    $affected_rows = $db->affected_rows;
    printf("%5d %s %s %d %d\n", $id, $username, $username_after, $result_update, $affected_rows);
}
$result->free();
$db->close();
コード例 #17
0
ファイル: CiiCache.php プロジェクト: charlesportwoodii/cii
 /**
  * Converts the encryption key into an integer via base64todec, then transforms that into a unique ID via HashIds
  * @return string
  */
 public function getBaseHash()
 {
     $hashids = new Hashids\Hashids(Yii::app()->params['encryptionKey'], 8);
     $id = $hashids->encode($this->base62toDec(Yii::app()->params['encryptionKey']));
     return $id;
 }
コード例 #18
0
ファイル: WashTests.php プロジェクト: pean/wash
 public function generateURLs($type, $n)
 {
     $baseurl = "http://wa.se/";
     if ($type == 'invalid') {
         $validchars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $invalidchars = '/+;:_!"#€%&/()=?';
         $validcharslen = strlen($validchars);
         $invalidcharslen = strlen($invalidchars);
         $urls = array();
         for ($i = 0; $i < $n; $i++) {
             $hash = '';
             $length = rand(1, 10);
             for ($j = 0; $j < $length; $j++) {
                 $hash .= $validchars[rand(0, $validcharslen - 1)];
                 $hash .= $invalidchars[rand(0, $invalidcharslen - 1)];
             }
             $urls[] = $baseurl . $hash;
         }
     } else {
         // Generate som valid urls
         $hashids = new \Hashids\Hashids(md5($this->config['salt']));
         $urls = array();
         for ($i = 0; $i < $n; $i++) {
             $int = rand(0, 1000000);
             $hash = $hashids->encode($int);
             $urls[] = $baseurl . $hash;
         }
     }
     return $urls;
 }
コード例 #19
0
<?php

/* include hashids lib */
require_once __DIR__ . '/../lib/Hashids/Hashids.php';
/* create the class object */
$hashids = new Hashids\Hashids('this is my salt');
/* encode several numbers into one id */
$id = $hashids->encode(45, 434, 1313, 99);
/* `$id` is always a string */
var_dump($id);
exit;
コード例 #20
0
ファイル: gen_hash_string.php プロジェクト: huberyhe/scripts
include "vendor/autoload.php";
function guid()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((double) microtime() * 10000);
        //optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);
        // "-"
        $uuid = chr(123) . substr($charid, 0, 8) . $hyphen . substr($charid, 8, 4) . $hyphen . substr($charid, 12, 4) . $hyphen . substr($charid, 16, 4) . $hyphen . substr($charid, 20, 12) . chr(125);
        // "}"
        return $uuid;
    }
}
echo " . generating hash strings...\n";
echo str_repeat("=", $strLen + 3) . "\n";
for ($i = 0; $i < $strsNum; $i++) {
    $salt = guid();
    $ALPHABET = "abcdefghijklmnpqrstuvwxyz123456789";
    $hashids = new Hashids\Hashids($salt, $strLen, $ALPHABET);
    $id = $hashids->encode($i);
    printf("%02d %s\n", $i + 1, $id);
    // echo $i . " " . $id . "\n";
    // $numbers = $hashids->decode($id);
    // echo $this->guid();
    // var_dump($id, $numbers);
}
echo str_repeat("=", $strLen + 3) . "\n";
echo " . generate hash strings completed.\n\n";
コード例 #21
0
ファイル: init.php プロジェクト: ycms/wordpress
function using_id_as_slug($post_id, $post = null)
{
    global $post_type;
    if ($post_type != 'page' && $post_type) {
        //只对文章生效
        // 如果是文章的版本,不生效
        if (wp_is_post_revision($post_id)) {
            return false;
        }
        // 取消挂载该函数,防止无限循环
        remove_action('save_post', 'using_id_as_slug');
        // 使用文章ID作为文章的别名
        $hashid = new Hashids\Hashids($post_type, 6, 'abcdefghijklmnopqrstuvwxyz0123456789');
        wp_update_post(array('ID' => $post_id, 'post_name' => $hashid->encode($post_id)));
        // 重新挂载该函数
        add_action('save_post', 'using_id_as_slug');
    }
}