From 7a587cd5cc6ba2da5be07c1f46bcb95adf5ff5ad Mon Sep 17 00:00:00 2001 From: Andersom Perozzi Date: Mon, 11 Mar 2019 08:49:03 -0300 Subject: [PATCH] setTimezone, Exception for GD dependent modules --- README.md | 4 +++- system/captcha/autoload.php | 19 ++++++++++++++++++- system/image/autoload.php | 5 ++++- system/system.php | 28 ++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bff0827..3eae496 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ It's much used in children's controllers, like headers and footers. public function index() { $variable = 'value'; - $this->template = 'default\common\header.twig'; + $this->template = 'default/common/header.twig'; $this->render(); } @@ -655,6 +655,8 @@ In a sample case, we have this controller: * **config_seo_url:** Indicates if SEO URL routes is enabled. *(boolean)* * **config_mail_protocol:** Define the method of mail library use to send e-mails (mail or smtp values only). *(string)* * **config_compression:** Output gzip compression value [0-9]. *(integer)* + * **PatternSiteTitle:** Used to `$this->document->setTitle()` function, replaces %s to this value. *(string)* + * **date_timezone:** Define the default timezone to entire application. *(string)* ### Recommended settings SQL Query diff --git a/system/captcha/autoload.php b/system/captcha/autoload.php index 3169d49..fa3b57f 100644 --- a/system/captcha/autoload.php +++ b/system/captcha/autoload.php @@ -7,7 +7,12 @@ class Captcha { protected $numChar = 6; protected $background = 'black'; - function __construct($width = NULL, $height = NULL, $numChar = 6, $background = 'black') { + function __construct($width = NULL, $height = NULL, $numChar = 6, $background = 'black') { + + if(!extension_loaded('gd')){ + throw new \Exception("The captcha function requires GD extension on PHP!"); + } + $this->numChar = $numChar; $this->background = $background; $pos = 'ABCDEFGHJKLMNOPQRSTUWVXZ0123456789abcdefhijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUWVXZ0123456789'; @@ -25,6 +30,18 @@ class Captcha { $this->height = ($height != NULL) ? $height : $this->height; } + public function __help() { + $helpTxt = + array( + "version" => "1.0", + "Description" => "Captcha module.", + "Use" => 'Declare new Captcha($width, $height, $numChar, $background) on a variable, use $variable->getCode() to obtain a plain text captcha code (prefer pass thos code to a SESSION) and return $variable->showImage(\'format\').', + "Formats" => "bmp, jpg, png, wbmp and gif." + ); + + var_dump($helpTxt, true); + } + function getCode(){ return $this->code; } diff --git a/system/image/autoload.php b/system/image/autoload.php index 08b0871..01af6f1 100644 --- a/system/image/autoload.php +++ b/system/image/autoload.php @@ -5,6 +5,10 @@ final class Image { private $info; public function __construct($file) { + if(!extension_loaded('gd')){ + throw new \Exception("The image function requires GD extension on PHP!"); + } + if (file_exists($file)) { $this->file = $file; @@ -180,4 +184,3 @@ final class Image { return array($r, $g, $b); } } -?> \ No newline at end of file diff --git a/system/system.php b/system/system.php index 395db1d..f127013 100644 --- a/system/system.php +++ b/system/system.php @@ -89,6 +89,29 @@ class startEngineExacTI { } } } + + public function setTimezone($utc) { + + try { + $tzc = @date_default_timezone_set($utc); + if (!$tzc){ + throw new \ErrorException($utc. " not found in PHP Compiler."); + } + } catch (\ErrorException $e) { + $trace = ($e->getTrace()); + + echo PHP_EOL.'Timezone Error: ', $e->getMessage() ." on ". $trace[0]['file'] ." in line ". $trace[0]['line'].".", PHP_EOL; + } + + } + + public function getTimezone(){ + return date_default_timezone_get(); + } + + public function listTimezones() { + return DateTimeZone::listIdentifiers(DateTimeZone::ALL); + } } @@ -132,6 +155,11 @@ if(USE_DB_CONFIG === true) { $config->set('config_url', HTTP_URL); $config->set('config_ssl', HTTPS_URL); +//timezone +if($config->get('date_timezone')){ + $engine->setTimezone($config->get('date_timezone')); +} + // Site Title if($config->get('PatternSiteTitle') == true) { define('PATTERSITETITLE', $config->get('PatternSiteTitle'));