Skip to content

Commit

Permalink
Thu Apr 12 13:03:34 MDT 2012 - Added generic select/option list gener…
Browse files Browse the repository at this point in the history
…ator for template use
  • Loading branch information
jas- committed Apr 12, 2012
1 parent d8bd1fe commit 5a81ae7
Showing 1 changed file with 64 additions and 47 deletions.
111 changes: 64 additions & 47 deletions models/model.libraries.php
Expand Up @@ -240,58 +240,75 @@ public function parsegeo($data)
return $settings;
}

/**
* @function _salt
* @abstract Generate a random salt value of specified length based on input
*/
public function _salt($string, $len=null)
{
return (!empty($len)) ?
hash('sha512', str_pad($string, (strlen($string) + $len), substr(hash('sha512', $string), @round((float)strlen($string)/3, 0, PHP_ROUND_HALF_UP), ($len - strlen($string))), STR_PAD_BOTH)) :
hash('sha512', substr($string, @round((float)strlen($string)/3, 0, PHP_ROUND_HALF_UP), 16));
}
/**
* @function _salt
* @abstract Generate a random salt value of specified length based on input
*/
public function _salt($string, $len=null)
{
return (!empty($len)) ?
hash('sha512', str_pad($string, (strlen($string) + $len), substr(hash('sha512', $string), @round((float)strlen($string)/3, 0, PHP_ROUND_HALF_UP), ($len - strlen($string))), STR_PAD_BOTH)) :
hash('sha512', substr($string, @round((float)strlen($string)/3, 0, PHP_ROUND_HALF_UP), 16));
}

/**
* @function _hash
* @abstract Mimic bcrypt hasing functionality
*/
public function _hash($string, $salt=null)
{
return (CRYPT_BLOWFISH===1) ?
(!empty($salt)) ?
crypt($string, "\$2a\$07\$".substr($salt, 0, CRYPT_SALT_LENGTH)) :
crypt($string, $this->_salt("\$2a\$07\$".substr($string, 0, CRYPT_SALT_LENGTH))) :
false;
}
/**
* @function _hash
* @abstract Mimic bcrypt hasing functionality
*/
public function _hash($string, $salt=null)
{
return (CRYPT_BLOWFISH===1) ?
(!empty($salt)) ?
crypt($string, "\$2a\$07\$".substr($salt, 0, CRYPT_SALT_LENGTH)) :
crypt($string, $this->_salt("\$2a\$07\$".substr($string, 0, CRYPT_SALT_LENGTH))) :
false;
}

/**
* @function _serialize
* @abstract Perform serialization of sent POST data. This is required for the
* jQuery.AJAX plug-in checksum verification as the current PHP
* serialize() function will not create an accurate hash
*/
function _serialize($array)
{
if (count($array)>0){
$x = '';
foreach($array as $key => $value){
$x .= $key.'='.$value.'&';
}
$x = substr($x, 0, -1);
/**
* @function _serialize
* @abstract Perform serialization of sent POST data. This is required for the
* jQuery.AJAX plug-in checksum verification as the current PHP
* serialize() function will not create an accurate hash
*/
function _serialize($array)
{
if (count($array)>0){
$x = '';
foreach($array as $key => $value){
$x .= $key.'='.$value.'&';
}
return (strlen($x)>0) ? $x : false;
$x = substr($x, 0, -1);
}
return (strlen($x)>0) ? $x : false;
}

public function __clone() {
trigger_error('Cloning prohibited', E_USER_ERROR);
}
public function __wakeup() {
trigger_error('Deserialization of singleton prohibited ...', E_USER_ERROR);
}
public function __destruct()
{
unset($this->instance);
return true;
/**
* @function _genOptionsList
* @abstract Generic method of creating an select/option list from array
*/
function _genOptionsList($array)
{
$l = false;
if ((is_array($array)) && (count($array) > 0)) {
foreach($array as $key => $value) {
$l .= '<option id="" value="">'.$value.'</option>';
}
}
return $l;
}

public function __clone() {
trigger_error('Cloning prohibited', E_USER_ERROR);
}

public function __wakeup() {
trigger_error('Deserialization of singleton prohibited ...', E_USER_ERROR);
}

public function __destruct()
{
unset($this->instance);
return true;
}
}
?>

0 comments on commit 5a81ae7

Please sign in to comment.