From 3ff03dc4f0a72432b34c00da620272cf011e4ddd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Jul 2021 14:17:20 +1000 Subject: Publishing h-node.org code. - this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers) --- h-source/admin/Library/Image/Gd/Captcha.php | 85 +++++++++++++++ h-source/admin/Library/Image/Gd/Thumbnail.php | 151 ++++++++++++++++++++++++++ h-source/admin/Library/Image/Gd/index.html | 1 + h-source/admin/Library/Image/index.html | 1 + 4 files changed, 238 insertions(+) create mode 100644 h-source/admin/Library/Image/Gd/Captcha.php create mode 100644 h-source/admin/Library/Image/Gd/Thumbnail.php create mode 100644 h-source/admin/Library/Image/Gd/index.html create mode 100644 h-source/admin/Library/Image/index.html (limited to 'h-source/admin/Library/Image') diff --git a/h-source/admin/Library/Image/Gd/Captcha.php b/h-source/admin/Library/Image/Gd/Captcha.php new file mode 100644 index 0000000..ace4806 --- /dev/null +++ b/h-source/admin/Library/Image/Gd/Captcha.php @@ -0,0 +1,85 @@ + 150, + 'boxHeight' => 100, + 'charNumber' => 6, + 'fontPath' => $here.'/External/Fonts/FreeFont/FreeMono.ttf', + 'undulation' => true, + 'align' => false, + 'charHeight' => 28 + ); + + //set the $this->scaffold->params array + if (is_array($params)) + { + foreach ($params as $key => $value) + { + $defaultParams[$key] = $value; + } + } + $this->params = $defaultParams; + + $this->string = generateString($this->params['charNumber']); + } + + public function render() + { + //space among characters + $space = $this->params['boxWidth'] / ($this->params['charNumber']+1); + //create the image box + $img = imagecreatetruecolor($this->params['boxWidth'],$this->params['boxHeight']); + + $background = imagecolorallocate($img,255,255,255); + $border = imagecolorallocate($img,0,0,0); + $colors[] = imagecolorallocate($img,mt_rand(0,125),mt_rand(0,125),mt_rand(0,125)); + $colors[] = imagecolorallocate($img,mt_rand(0,125),mt_rand(0,125),mt_rand(0,125)); + $colors[] = imagecolorallocate($img,mt_rand(0,125),mt_rand(0,125),mt_rand(0,125)); + + //create the background + imagefilledrectangle($img,1,1,$this->params['boxWidth']-2,$this->params['boxHeight']-2,$background); + imagerectangle($img,0,0,$this->params['boxWidth']-1,$this->params['boxHeight']-2,$border); + + //set the text + for ($i=0; $i< $this->params['charNumber']; $i++) + { + $color = $colors[$i % count($colors)]; + $char = substr($this->string,$i,1); + $fontPath = $this->params['fontPath']; + $angle = $this->params['undulation'] === false ? 0 : -20+rand(0,40); + $yposFixed = (int)(($this->params['boxHeight'])/2); + $ypos = $this->params['align'] === true ? $yposFixed : $yposFixed + mt_rand(0,10); + $charHeight = $this->params['charHeight']; + imagettftext($img,$charHeight + rand(0,8),$angle,($i+0.3)*$space,$ypos,$color,$fontPath,$char); + } + + $noiseColor = imagecolorallocate($img, mt_rand(125,255), mt_rand(125,255), mt_rand(125,255)); + /* generate random dots in background */ + for( $i=0; $i<($this->params['boxWidth'] * $this->params['boxHeight'])/7; $i++ ) { + imagefilledellipse($img, mt_rand(0,$this->params['boxWidth']), mt_rand(0,$this->params['boxHeight']), 1, 1, $noiseColor); + } + + $_SESSION['captchaString'] = $this->string; + header('Content-Type: image/png'); + imagepng($img); + imagedestroy($img); + } + +} \ No newline at end of file diff --git a/h-source/admin/Library/Image/Gd/Thumbnail.php b/h-source/admin/Library/Image/Gd/Thumbnail.php new file mode 100644 index 0000000..5981175 --- /dev/null +++ b/h-source/admin/Library/Image/Gd/Thumbnail.php @@ -0,0 +1,151 @@ +basePath = $basePath; + + $defaultParams = array( + 'imgWidth' => 100, + 'imgHeight' => 100, + 'defaultImage' => null, + 'cropImage' => 'no', + 'horizAlign' => 'left', + 'vertAlign' => 'top' + ); + + //set the $this->scaffold->params array + if (is_array($params)) + { + foreach ($params as $key => $value) + { + $defaultParams[$key] = $value; + } + } + $this->params = $defaultParams; + } + + //create the thumbnail + //$imageName: the name of the file inside $this->basePath + public function render($imageFile) + { + $imagePath = $this->basePath . basename($imageFile); + + if (!file_exists($imagePath) and isset($this->params['defaultImage'])) $imagePath = $this->params['defaultImage']; + + $img = null; + $ext = strtolower(end(explode('.', $imagePath))); + + if (strcmp($ext,'jpg') === 0 or strcmp($ext,'jpeg') === 0) { + $img = @imagecreatefromjpeg($imagePath); + } else if (strcmp($ext,'png') === 0) { + $img = @imagecreatefrompng($imagePath); + } else if (strcmp($ext,'gif') === 0) { + $img = @imagecreatefromgif($imagePath); + } + + //If an image was successfully loaded, test the image for size + if ($img) { + //image size + $width = imagesx($img); + $height = imagesy($img); + + if ($this->params['cropImage'] === 'no') + { + $scale = min($this->params['imgWidth']/$width, $this->params['imgHeight']/$height); + } + else if ($this->params['cropImage'] === 'yes') + { + $scale = max($this->params['imgWidth']/$width, $this->params['imgHeight']/$height); + } + + if ($scale < 1) { + + $xSrc = 0; + $ySrc = 0; + + if ($this->params['cropImage'] === 'no') + { + $newWidth = floor($scale*$width); + $newHeight = floor($scale*$height); + } + else if ($this->params['cropImage'] === 'yes') + { + + $newWidth = $this->params['imgWidth']; + $newHeight = $this->params['imgHeight']; + $oldWidth = $width; + $oldHeight = $height; + $width = floor($newWidth/$scale); + $height = floor($newHeight/$scale); + + switch ($this->params['horizAlign']) + { + case 'left': + $xSrc = 0; + break; + case 'right': + $xSrc = floor(($oldWidth-$width)); + break; + case 'center': + $xSrc = floor(($oldWidth-$width)/2); + break; + default: + $xSrc = $this->params['horizAlign']; + } + + switch ($this->params['vertAlign']) + { + case 'top': + $ySrc = 0; + break; + case 'bottom': + $ySrc = floor(($oldHeight-$height)); + break; + case 'center': + $ySrc = floor(($oldHeight-$height)/2); + break; + default: + $ySrc = $this->params['vertAlign']; + } + + } + + //temp image + $tmpImg = imagecreatetruecolor($newWidth, $newHeight); + + //copy and resize + imagecopyresized($tmpImg, $img, 0, 0, $xSrc, $ySrc,$newWidth, $newHeight, $width, $height); + imagedestroy($img); + $img = $tmpImg; + } + + } + + if (!$img) { + $img = imagecreate($this->params['imgWidth'], $this->params['imgHeight']); + imagecolorallocate($img,200,200,200); + } + + //print the image + header("Content-type: image/jpeg"); + imagejpeg($img); + + } + +} \ No newline at end of file diff --git a/h-source/admin/Library/Image/Gd/index.html b/h-source/admin/Library/Image/Gd/index.html new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/h-source/admin/Library/Image/Gd/index.html @@ -0,0 +1 @@ + diff --git a/h-source/admin/Library/Image/index.html b/h-source/admin/Library/Image/index.html new file mode 100644 index 0000000..8d1c8b6 --- /dev/null +++ b/h-source/admin/Library/Image/index.html @@ -0,0 +1 @@ + -- cgit v1.2.3