Esempio n. 1
0
 public static function set()
 {
     static::initialize();
     $ipinga = \ipinga\ipinga::getInstance();
     if (count(static::$contents) == 0) {
         // expire it now
         if (isset($_COOKIE[$ipinga->config('cookie.name')]) == true) {
             setcookie($ipinga->config('cookie.name'), '', 1, '/');
         }
         // no need for an else branch, as it wasn't there to begin with
     } else {
         $a = array('kludge' => static::$contents);
         $encrypted = \ipinga\crypto::encrypt(json_encode($a));
         setcookie($ipinga->config('cookie.name'), $encrypted, $ipinga->config('cookie.expiration_time'), '/');
     }
 }
Esempio n. 2
0
 /**
  * @param array $arrayToEncrypt
  *
  * @return string printable encrypted string
  */
 public static function printableEncrypt($arrayToEncrypt)
 {
     $a = array('k' => $arrayToEncrypt);
     return bin2hex(\ipinga\crypto::encrypt(json_encode($a)));
 }
Esempio n. 3
0
 private function _Insert()
 {
     $ipinga = \ipinga\ipinga::getInstance();
     $sqlfields = array();
     $sqlparams = array();
     $sql = 'insert into ' . $this->tableName . ' (';
     foreach ($this->fieldTypes as $fieldName => $fieldType) {
         // timestamp takes care of itself in the database
         if ($fieldType != 'timestamp') {
             $sqlfields[] = $fieldName;
             $sqlparams[] = ':' . $fieldName;
         }
     }
     $sql = $sql . implode(',', $sqlfields) . ') values (' . implode(',', $sqlparams) . ')';
     $this->lastSql = $sql;
     $this->sqlParams = array();
     $sth = $ipinga->pdo()->prepare($sql);
     foreach ($this->fieldTypes as $fieldName => $fieldType) {
         // id and timestamp take care of themselves in the database
         if ($fieldType != 'timestamp') {
             if ($fieldName == 'created') {
                 $created = date('Y-m-d H:i:s');
                 $sth->bindParam(':' . $fieldName, $created);
                 $this->sqlParams[$fieldName] = $created;
             } elseif ($fieldName == 'passwd') {
                 $passwd = bin2Hex(\ipinga\crypto::encrypt($this->field[$fieldName]));
                 //            $passwd = base64_encode($this->field[$fieldName]);
                 $sth->bindParam(':' . $fieldName, $passwd);
                 $this->sqlParams[$fieldName] = $passwd;
             } else {
                 $sth->bindParam(':' . $fieldName, $this->field[$fieldName]);
                 $this->sqlParams[$fieldName] = $this->field[$fieldName];
             }
         }
     }
     $retval = false;
     try {
         $retval = $sth->execute();
         if ($this->field['id'] == 0) {
             $this->field['id'] = $ipinga->pdo()->lastInsertId();
         }
         $this->saved = true;
     } catch (\PDOException $e) {
         echo $e->getMessage() . '<br>' . $sql . '<br><hr>';
         $this->saved = false;
     }
     return $retval;
 }