forked from mirrors/easyappointments
Added comment banners to helpers.
This commit is contained in:
parent
a8cedcd9aa
commit
b0db1289f4
2 changed files with 179 additions and 156 deletions
|
@ -1,75 +1,86 @@
|
||||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||||
|
|
||||||
/**
|
/* ----------------------------------------------------------------------------
|
||||||
* Database Exception Class
|
* Easy!Appointments - Open Source Web Scheduler
|
||||||
*/
|
*
|
||||||
class DatabaseException extends Exception {}
|
* @package EasyAppointments
|
||||||
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
/**
|
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||||
* Validation Exception Class
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
*/
|
* @link http://easyappointments.org
|
||||||
class ValidationException extends Exception {}
|
* @since v1.0.0
|
||||||
|
* ---------------------------------------------------------------------------- */
|
||||||
/**
|
|
||||||
* Notification Exception Class
|
/**
|
||||||
*/
|
* Database Exception Class
|
||||||
class NotificationException extends Exception {}
|
*/
|
||||||
|
class DatabaseException extends Exception {}
|
||||||
/**
|
|
||||||
* Sync Exception Class
|
/**
|
||||||
*/
|
* Validation Exception Class
|
||||||
class SyncException extends Exception {}
|
*/
|
||||||
|
class ValidationException extends Exception {}
|
||||||
/**
|
|
||||||
* Print an exception to an HTML text.
|
/**
|
||||||
*
|
* Notification Exception Class
|
||||||
* This method is used to display exceptions in a way that is useful and easy
|
*/
|
||||||
* for the user to see. It uses the Bootstrap CSS accordion markup to display
|
class NotificationException extends Exception {}
|
||||||
* the message and when the user clicks on it the exception trace will be revealed.
|
|
||||||
* We display only one exceptions at a time because the user needs to be able
|
/**
|
||||||
* to display the details of each exception seperately. (In contrast with js).
|
* Sync Exception Class
|
||||||
*
|
*/
|
||||||
* @param Exception $exc The exception to be displayed.
|
class SyncException extends Exception {}
|
||||||
* @return string Returns the html markup of the exception.
|
|
||||||
*/
|
/**
|
||||||
function exceptionToHtml($exc) {
|
* Print an exception to an HTML text.
|
||||||
return
|
*
|
||||||
'<div class="accordion" id="error-accordion">
|
* This method is used to display exceptions in a way that is useful and easy
|
||||||
<div class="accordion-group">
|
* for the user to see. It uses the Bootstrap CSS accordion markup to display
|
||||||
<div class="accordion-heading">
|
* the message and when the user clicks on it the exception trace will be revealed.
|
||||||
<a class="accordion-toggle" data-toggle="collapse"
|
* We display only one exceptions at a time because the user needs to be able
|
||||||
data-parent="#error-accordion" href="#error-technical">' .
|
* to display the details of each exception seperately. (In contrast with js).
|
||||||
$exc->getMessage() . '
|
*
|
||||||
</a>
|
* @param Exception $exc The exception to be displayed.
|
||||||
</div>
|
* @return string Returns the html markup of the exception.
|
||||||
<div id="error-technical" class="accordion-body collapse">
|
*/
|
||||||
<div class="accordion-inner">
|
function exceptionToHtml($exc) {
|
||||||
<pre>' . $exc->getTraceAsString() . '</pre>
|
return
|
||||||
</div>
|
'<div class="accordion" id="error-accordion">
|
||||||
</div>
|
<div class="accordion-group">
|
||||||
</div>
|
<div class="accordion-heading">
|
||||||
</div>';
|
<a class="accordion-toggle" data-toggle="collapse"
|
||||||
}
|
data-parent="#error-accordion" href="#error-technical">' .
|
||||||
|
$exc->getMessage() . '
|
||||||
/**
|
</a>
|
||||||
* Get a javascript object of a given exception.
|
</div>
|
||||||
*
|
<div id="error-technical" class="accordion-body collapse">
|
||||||
* This method is pretty useful whenever we need to pass an exception object
|
<div class="accordion-inner">
|
||||||
* to javascript during ajax calls.
|
<pre>' . $exc->getTraceAsString() . '</pre>
|
||||||
*
|
</div>
|
||||||
* @param Exception $exception The given exception object.
|
</div>
|
||||||
* @return string Returns the json encoded object of the exception.
|
</div>
|
||||||
*/
|
</div>';
|
||||||
function exceptionToJavaScript($exception) {
|
}
|
||||||
return json_encode(array(
|
|
||||||
'code' => $exception->getCode(),
|
/**
|
||||||
'file' => $exception->getFile(),
|
* Get a javascript object of a given exception.
|
||||||
'line' => $exception->getLine(),
|
*
|
||||||
'message' => $exception->getMessage(),
|
* This method is pretty useful whenever we need to pass an exception object
|
||||||
'previous' => $exception->getPrevious(),
|
* to javascript during ajax calls.
|
||||||
'trace' => $exception->getTraceAsString()
|
*
|
||||||
));
|
* @param Exception $exception The given exception object.
|
||||||
}
|
* @return string Returns the json encoded object of the exception.
|
||||||
|
*/
|
||||||
/* End of file exception_types_helper.php */
|
function exceptionToJavaScript($exception) {
|
||||||
/* Location: ./application/helpers/exception_types_helper.php */
|
return json_encode(array(
|
||||||
|
'code' => $exception->getCode(),
|
||||||
|
'file' => $exception->getFile(),
|
||||||
|
'line' => $exception->getLine(),
|
||||||
|
'message' => $exception->getMessage(),
|
||||||
|
'previous' => $exception->getPrevious(),
|
||||||
|
'trace' => $exception->getTraceAsString()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of file exception_types_helper.php */
|
||||||
|
/* Location: ./application/helpers/exception_types_helper.php */
|
||||||
|
|
|
@ -1,81 +1,93 @@
|
||||||
<?php
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||||
/**
|
|
||||||
* Get date in RFC3339
|
/* ----------------------------------------------------------------------------
|
||||||
* For example used in XML/Atom
|
* Easy!Appointments - Open Source Web Scheduler
|
||||||
*
|
*
|
||||||
* @link http://stackoverflow.com/questions/5671433/php-time-to-google-calendar-dates-time-format
|
* @package EasyAppointments
|
||||||
*
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
||||||
* @param integer $timestamp
|
* @copyright Copyright (c) 2013 - 2015, Alex Tselegidis
|
||||||
* @return string date in RFC3339
|
* @license http://opensource.org/licenses/GPL-3.0 - GPLv3
|
||||||
* @author Boris Korobkov
|
* @link http://easyappointments.org
|
||||||
*/
|
* @since v1.0.0
|
||||||
function date3339($timestamp=0) {
|
* ---------------------------------------------------------------------------- */
|
||||||
|
|
||||||
if (!$timestamp) {
|
/**
|
||||||
$timestamp = time();
|
* Get date in RFC3339
|
||||||
}
|
* For example used in XML/Atom
|
||||||
$date = date('Y-m-d\TH:i:s', $timestamp);
|
*
|
||||||
|
* @link http://stackoverflow.com/questions/5671433/php-time-to-google-calendar-dates-time-format
|
||||||
$matches = array();
|
*
|
||||||
if (preg_match('/^([\-+])(\d{2})(\d{2})$/', date('O', $timestamp), $matches)) {
|
* @param integer $timestamp
|
||||||
$date .= $matches[1].$matches[2].':'.$matches[3];
|
* @return string date in RFC3339
|
||||||
} else {
|
* @author Boris Korobkov
|
||||||
$date .= 'Z';
|
*/
|
||||||
}
|
function date3339($timestamp=0) {
|
||||||
return $date;
|
|
||||||
}
|
if (!$timestamp) {
|
||||||
|
$timestamp = time();
|
||||||
/**
|
}
|
||||||
* Generate a hash of password string.
|
$date = date('Y-m-d\TH:i:s', $timestamp);
|
||||||
*
|
|
||||||
* For user security, all system passwords are stored in hash string into the database. Use
|
$matches = array();
|
||||||
* this method to produce the hashed password.
|
if (preg_match('/^([\-+])(\d{2})(\d{2})$/', date('O', $timestamp), $matches)) {
|
||||||
*
|
$date .= $matches[1].$matches[2].':'.$matches[3];
|
||||||
* @param string $salt Salt value for current user. This value is stored on the database and
|
} else {
|
||||||
* is used when generating the password hash.
|
$date .= 'Z';
|
||||||
* @param string $password Given string password.
|
}
|
||||||
* @return string Returns the hash string of the given password.
|
return $date;
|
||||||
*/
|
}
|
||||||
function hash_password($salt, $password) {
|
|
||||||
$half = (int)(strlen($salt) / 2);
|
/**
|
||||||
$hash = hash('sha256', substr($salt, 0, $half ) . $password . substr($salt, $half));
|
* Generate a hash of password string.
|
||||||
|
*
|
||||||
for ($i = 0; $i < 100000; $i++) {
|
* For user security, all system passwords are stored in hash string into the database. Use
|
||||||
$hash = hash('sha256', $hash);
|
* this method to produce the hashed password.
|
||||||
}
|
*
|
||||||
|
* @param string $salt Salt value for current user. This value is stored on the database and
|
||||||
return $hash;
|
* is used when generating the password hash.
|
||||||
}
|
* @param string $password Given string password.
|
||||||
|
* @return string Returns the hash string of the given password.
|
||||||
/**
|
*/
|
||||||
* Generate a new password salt.
|
function hash_password($salt, $password) {
|
||||||
*
|
$half = (int)(strlen($salt) / 2);
|
||||||
* This method will not check if the salt is unique in database. This must be done
|
$hash = hash('sha256', substr($salt, 0, $half ) . $password . substr($salt, $half));
|
||||||
* from the calling procedure.
|
|
||||||
*
|
for ($i = 0; $i < 100000; $i++) {
|
||||||
* @return string Returns a salt string.
|
$hash = hash('sha256', $hash);
|
||||||
*/
|
}
|
||||||
function generate_salt() {
|
|
||||||
$max_length = 100;
|
return $hash;
|
||||||
$salt = hash('sha256', (uniqid(rand(), true)));
|
}
|
||||||
return substr($salt, 0, $max_length);
|
|
||||||
}
|
/**
|
||||||
|
* Generate a new password salt.
|
||||||
/**
|
*
|
||||||
* This method generates a random string.
|
* This method will not check if the salt is unique in database. This must be done
|
||||||
*
|
* from the calling procedure.
|
||||||
* @param int $length (OPTIONAL = 10) The length of the generated string.
|
*
|
||||||
* @return string Returns the randomly generated string.
|
* @return string Returns a salt string.
|
||||||
* @link http://stackoverflow.com/a/4356295/1718162
|
*/
|
||||||
*/
|
function generate_salt() {
|
||||||
function generate_random_string($length = 10) {
|
$max_length = 100;
|
||||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
$salt = hash('sha256', (uniqid(rand(), true)));
|
||||||
$random_string = '';
|
return substr($salt, 0, $max_length);
|
||||||
for ($i = 0; $i < $length; $i++) {
|
}
|
||||||
$random_string .= $characters[rand(0, strlen($characters) - 1)];
|
|
||||||
}
|
/**
|
||||||
return $random_string;
|
* This method generates a random string.
|
||||||
}
|
*
|
||||||
|
* @param int $length (OPTIONAL = 10) The length of the generated string.
|
||||||
/* End of file general_helper.php */
|
* @return string Returns the randomly generated string.
|
||||||
/* Location: ./application/helpers/general_helper.php */
|
* @link http://stackoverflow.com/a/4356295/1718162
|
||||||
|
*/
|
||||||
|
function generate_random_string($length = 10) {
|
||||||
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||||
|
$random_string = '';
|
||||||
|
for ($i = 0; $i < $length; $i++) {
|
||||||
|
$random_string .= $characters[rand(0, strlen($characters) - 1)];
|
||||||
|
}
|
||||||
|
return $random_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* End of file general_helper.php */
|
||||||
|
/* Location: ./application/helpers/general_helper.php */
|
||||||
|
|
Loading…
Reference in a new issue