diff --git a/README.md b/README.md index ea511c7..c856bda 100644 --- a/README.md +++ b/README.md @@ -443,7 +443,9 @@ To create a model, put in the models folder a directory and file with the code. To use a magic request system, you just need to call a `$this->request` method. For sample, to obtain a POST value, use `$this->request->post['field']` to get the post value with security. For a $_SERVER predefined variables, use `$this->request->server['VALUE']` and `$this->request->get[key]` for $_GET values. + For REST services you can use `$this->request->method` to check if is a POST, GET, PUT, DELETE or other HTTP method. You can use the auxiliary functions to determinate the HTTP method, like `$this->request->isPUT()` to return *true* or *false* for PUT method. Also others methods have your functions, like `$this->request->isPOST()`, `$this->request->isGET()`, `$this->request->isHEAD()`, `$this->request->isCONNECT()`, `$this->request->isOPTIONS()`, `$this->request->isTRACE()`, `$this->request->isPATCH()` or `$this->request->isDELETE()`. All are equivalent to "is" function in request, like this sample: `$this->request->is('PUT')` return true or false for PUT HTTP method. + The advantages to use this requests instead the predefined variables of PHP are more the more security, upgradable and unicode values. ### Sessions diff --git a/system/caches/caches.php b/system/caches/caches.php index 10df317..a0f1299 100644 --- a/system/caches/caches.php +++ b/system/caches/caches.php @@ -52,18 +52,20 @@ public function set($key, $value, $expire = true) { } public function delete($key) { - $files = glob($this->dirCache . preg_replace('/[^A-Z0-9\._-]/i', '', $key) . '.cache'); + $files = glob($this->dirCache . preg_replace('/[^A-Z0-9\.\*_-]/i', '', $key) . '.cache'); if ($files) { foreach ($files as $file) { + if (file_exists($file)) { + unlink($file); - return true; + } } } - return false; + return (count($files)); } private function encode($value){ diff --git a/system/database/autoload.php b/system/database/autoload.php index cd3e9de..123346b 100644 --- a/system/database/autoload.php +++ b/system/database/autoload.php @@ -1,8 +1,9 @@ link); - sqlsrv_query("SET CHARACTER SET utf8", $this->link); + sqlsrv_query($this->link,"SET NAMES 'utf8'"); + sqlsrv_query($this->link, "SET CHARACTER SET utf8"); } public function query($sql) { - $resource = \sqlsrv_query($sql, $this->link); + $resource = \sqlsrv_query($this->link, $sql); if ($resource) { if (is_resource($resource)) { @@ -80,7 +80,7 @@ public function countAffected() { public function getLastId() { $last_id = false; - $resource = \sqlsrv_query("SELECT @@identity AS id", $this->link); + $resource = \sqlsrv_query($this->link, "SELECT @@identity AS id"); if ($row = \sqlsrv_fetch($resource)) { $last_id = trim($row[0]); diff --git a/system/database/library/db.php b/system/database/library/db.php index ed3ada9..70850de 100644 --- a/system/database/library/db.php +++ b/system/database/library/db.php @@ -5,8 +5,8 @@ final class DB { private $cachePrefix = "SQL_"; public function __construct($driver, $hostname, $username, $password, $database) { - if (file_exists(DIR_DATABASE . $driver . '.php')) { - require_once(DIR_DATABASE . $driver . '.php'); + if (file_exists(DIR_DATABASE .'database/'. $driver . '.php')) { + require_once(DIR_DATABASE .'database/'. $driver . '.php'); } else { exit('Error: Could not load database file ' . $driver . '!'); } diff --git a/system/engine/VERSION b/system/engine/VERSION index 3e1ad72..8e03717 100644 --- a/system/engine/VERSION +++ b/system/engine/VERSION @@ -1 +1 @@ -1.5.0 \ No newline at end of file +1.5.1 \ No newline at end of file diff --git a/system/engine/autoload.php b/system/engine/autoload.php index 00c53f9..2deed63 100644 --- a/system/engine/autoload.php +++ b/system/engine/autoload.php @@ -1,13 +1,13 @@ file = $file; - - $info = getimagesize($file); - - $this->info = array( - 'width' => $info[0], - 'height' => $info[1], - 'bits' => $info['bits'], - 'mime' => $info['mime'] - ); - - $this->image = $this->create($file); - } else { - exit('Error: Could not load image ' . $file . '!'); - } - } - - private function create($image) { - $mime = $this->info['mime']; - - if ($mime == 'image/gif') { - return imagecreatefromgif($image); - } elseif ($mime == 'image/png') { - return imagecreatefrompng($image); - } elseif ($mime == 'image/jpeg') { - return imagecreatefromjpeg($image); - } - } - + if($this->infoChk($file)) + $this->image = $this->create($file); + else + throw new \Exception('Error: Could not load image ' . $file . '!'); + + } + + private function infoChk($file, $infoFile = true){ + if (file_exists($file)) { + $this->file = $file; + + $info = getimagesize($file); + + if($infoFile) { + $this->info = array( + 'width' => $info[0], + 'height' => $info[1], + 'bits' => $info['bits'], + 'mime' => $info['mime'] + ); + } + + return true; + } else { + return false; + } + } + + private function create($image) { + $info = getimagesize($image); + $mime = $info['mime']; + + if ($mime == 'image/gif') { + return imagecreatefromgif($image); + } elseif ($mime == 'image/png') { + return imagecreatefrompng($image); + } elseif ($mime == 'image/jpeg') { + return imagecreatefromjpeg($image); + } + } + public function save($file, $quality = 90) { - $info = pathinfo($file); - - $extension = strtolower($info['extension']); - + $info = pathinfo($file); + + $extension = strtolower($info['extension']); + if ($extension == 'jpeg' || $extension == 'jpg') { imagejpeg($this->image, $file, $quality); } elseif($extension == 'png') { @@ -51,56 +62,60 @@ public function save($file, $quality = 90) { } elseif($extension == 'gif') { imagegif($this->image, $file); } - - imagedestroy($this->image); - } - + + imagedestroy($this->image); + } + public function resize($width = 0, $height = 0) { - if (!$this->info['width'] || !$this->info['height']) { - return; - } - - $xpos = 0; - $ypos = 0; - - $scale = min($width / $this->info['width'], $height / $this->info['height']); - - if ($scale == 1) { - return; - } - - $new_width = (int)($this->info['width'] * $scale); - $new_height = (int)($this->info['height'] * $scale); - $xpos = (int)(($width - $new_width) / 2); - $ypos = (int)(($height - $new_height) / 2); - - $image_old = $this->image; + if (!$this->info['width'] || !$this->info['height']) { + return; + } + + $xpos = 0; + $ypos = 0; + + $scale = min($width / $this->info['width'], $height / $this->info['height']); + + if ($scale == 1) { + return; + } + + $new_width = (int)($this->info['width'] * $scale); + $new_height = (int)($this->info['height'] * $scale); + $xpos = (int)(($width - $new_width) / 2); + $ypos = (int)(($height - $new_height) / 2); + + $image_old = $this->image; $this->image = imagecreatetruecolor($width, $height); - - if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') { - imagealphablending($this->image, false); - imagesavealpha($this->image, true); - $background = imagecolorallocatealpha($this->image, 255, 255, 255, 127); - imagecolortransparent($this->image, $background); - } else { - $background = imagecolorallocate($this->image, 255, 255, 255); - } - - imagefilledrectangle($this->image, 0, 0, $width, $height, $background); - + + if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') { + imagealphablending($this->image, false); + imagesavealpha($this->image, true); + $background = imagecolorallocatealpha($this->image, 255, 255, 255, 127); + imagecolortransparent($this->image, $background); + } else { + $background = imagecolorallocate($this->image, 255, 255, 255); + } + + imagefilledrectangle($this->image, 0, 0, $width, $height, $background); + imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']); imagedestroy($image_old); - + $this->info['width'] = $width; $this->info['height'] = $height; } - - public function watermark($file, $position = 'bottomright') { - $watermark = $this->create($file); - + + public function watermark($file, $position = 'bottomright', $opacity = 100) { + + if($this->infoChk($file, false)) + $watermark = $this->create($file); + else + return false; + $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); - + switch($position) { case 'topleft': $watermark_pos_x = 0; @@ -119,68 +134,83 @@ public function watermark($file, $position = 'bottomright') { $watermark_pos_y = $this->info['height'] - $watermark_height; break; } - - imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, 120, 40); - + + imagealphablending( $this->image, true ); + imagesavealpha( $this->image, true ); + + imagealphablending($watermark, false); + imagesavealpha($watermark, true); + $background = imagecolorallocatealpha($watermark, 255, 255, 255, 127); + imagecolortransparent($watermark, $background); + + //$image = $watermark; + $opacity = $opacity/100; + $transparency = 1 - $opacity; + imagefilter($watermark, IMG_FILTER_COLORIZE, 0,0,0,127*$transparency); + //imagepng($watermark, DIR_IMAGE."testeWater".md5(rand()).".png"); + + //$this->imagecopymerge_alpha($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height, $opacity); + imagecopy($this->image, $watermark, $watermark_pos_x, $watermark_pos_y, 0, 0, $watermark_width, $watermark_height); + imagedestroy($watermark); } - + public function crop($top_x, $top_y, $bottom_x, $bottom_y) { $image_old = $this->image; $this->image = imagecreatetruecolor($bottom_x - $top_x, $bottom_y - $top_y); - + imagecopy($this->image, $image_old, 0, 0, $top_x, $top_y, $this->info['width'], $this->info['height']); imagedestroy($image_old); - + $this->info['width'] = $bottom_x - $top_x; $this->info['height'] = $bottom_y - $top_y; } - + public function rotate($degree, $color = 'FFFFFF') { - $rgb = $this->html2rgb($color); - + $rgb = $this->html2rgb($color); + $this->image = imagerotate($this->image, $degree, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); - - $this->info['width'] = imagesx($this->image); - $this->info['height'] = imagesy($this->image); + + $this->info['width'] = imagesx($this->image); + $this->info['height'] = imagesy($this->image); } - + private function filter($filter) { imagefilter($this->image, $filter); } - + private function text($text, $x = 0, $y = 0, $size = 5, $color = '000000') { - $rgb = $this->html2rgb($color); - - imagestring($this->image, $size, $x, $y, $text, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); + $rgb = $this->html2rgb($color); + + imagestring($this->image, $size, $x, $y, $text, imagecolorallocate($this->image, $rgb[0], $rgb[1], $rgb[2])); } - + private function merge($file, $x = 0, $y = 0, $opacity = 100) { $merge = $this->create($file); $merge_width = imagesx($image); $merge_height = imagesy($image); - + imagecopymerge($this->image, $merge, $x, $y, 0, 0, $merge_width, $merge_height, $opacity); } - - private function html2rgb($color) { - if ($color[0] == '#') { - $color = substr($color, 1); - } - - if (strlen($color) == 6) { - list($r, $g, $b) = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]); - } elseif (strlen($color) == 3) { - list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]); - } else { - return false; - } - - $r = hexdec($r); - $g = hexdec($g); - $b = hexdec($b); - - return array($r, $g, $b); - } + + private function html2rgb($color) { + if ($color[0] == '#') { + $color = substr($color, 1); + } + + if (strlen($color) == 6) { + list($r, $g, $b) = array($color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5]); + } elseif (strlen($color) == 3) { + list($r, $g, $b) = array($color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2]); + } else { + return false; + } + + $r = hexdec($r); + $g = hexdec($g); + $b = hexdec($b); + + return array($r, $g, $b); + } } diff --git a/system/mail/autoload.php b/system/mail/autoload.php index 4bbc524..0af70b4 100644 --- a/system/mail/autoload.php +++ b/system/mail/autoload.php @@ -1,3 +1,3 @@ constants = get_defined_constants(true); @@ -167,6 +168,10 @@ public function constantName($constant, $group = 'user') { return $constant; } + public function controllerPreActions() { + return (isset($this->preActions) && is_array($this->preActions)) ? $this->preActions : false; + } + } $engine = new startEngineExacTI(); @@ -327,6 +332,13 @@ public function constantName($constant, $group = 'user') { // SEO URL's $controller->addPreAction(new ActionSystem('url/seo_url')); +//extraPreactions +if($engine->controllerPreActions()){ + foreach ($engine->controllerPreActions() as $action){ + $controller->addPreAction(new Action($action)); + } +} + // Router if (isset($request->get['route'])) { $action = new Action($request->get['route']); @@ -342,4 +354,3 @@ public function constantName($constant, $group = 'user') { // Output $response->output(); - diff --git a/system/url/autoload.php b/system/url/autoload.php index d1c04df..7594c0b 100644 --- a/system/url/autoload.php +++ b/system/url/autoload.php @@ -33,7 +33,7 @@ public function link($route, $args = '', $connection = 'NONSSL') { if ($args) { if (is_array($args)) { - $url .= '&' . http_build_query($args); + $url .= '&' . http_build_query($args); } else { //$url .= str_replace('&', '&', '&' . ltrim($args, '&')); $url .= '&' . ltrim($args, '&'); @@ -56,4 +56,3 @@ public function rewrite($url) { return $url; } } -?> \ No newline at end of file