예제 #1
0
 /**
  * executes tidy and gets the value
  * @param string column name from transaction
  * @param string string to test
  * @return boolean true if tidy executed succesfully
  * @access private
  */
 function execTidy($colName, $value)
 {
     $arg_test = array('--version');
     if (isset($_SESSION['TidyContent']['ExecPath'])) {
         $loc = array($_SESSION['TidyContent']['ExecPath']);
     } else {
         $loc = $GLOBALS['TidyContent_TidyLocations'];
         if (isset($GLOBALS['KT_prefered_tidy_path'])) {
             array_unshift($loc, $GLOBALS['KT_prefered_tidy_path'] . 'tidy');
             array_unshift($loc, $GLOBALS['KT_prefered_tidy_path'] . 'tidy.exe');
         }
     }
     $shell = new KT_shell();
     $shell->execute($loc, $arg_test);
     if ($shell->hasError()) {
         $arr = $shell->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         return false;
     }
     $execPath = $shell->getExecutedCommand();
     if (!isset($_SESSION['TidyContent']['ExecPath']) && $execPath != '') {
         $_SESSION['TidyContent']['ExecPath'] = $execPath;
         $loc = array($execPath);
     }
     $tidyEncoding = 'raw';
     if (strtolower($this->outEncoding) == 'iso-8859-1') {
         $tidyEncoding = 'ascii';
     }
     if (strpos(strtolower($this->outEncoding), 'utf-8') !== false) {
         $tidyEncoding = 'utf8';
     }
     $string = $value;
     $string = str_replace(" ", " ", $string);
     $string = str_replace(" ", " ", $string);
     if (!file_exists($this->folderName)) {
         $folder = new KT_folder();
         $folder->createFolder($this->folderName);
         if ($folder->hasError()) {
             $arr = $folder->getError();
             $this->setErrorMsg($arr[0], $arr[1]);
             return false;
         }
     }
     $f = tempnam(substr($this->folderName, 0, -1), 'tidy');
     if ($f === false) {
         $err = KT_getResource('ERROR_TIDY_CONTENT', 'tNG', array());
         $this->setErrorMsg($err, $err);
         return false;
     }
     $fout = $f . '_out';
     $file = new KT_file();
     $file->writeFile($f, 'append', $string);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         return false;
     }
     $path = $GLOBALS['TidyContent_TidyConfiguration'];
     $arg = array("-config", $path, '-' . $tidyEncoding, "-o", $fout, $f);
     $shell = new KT_shell();
     $output = $shell->execute($loc, $arg);
     if ($shell->hasError() && !file_exists($fout)) {
         $arr = $shell->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         @unlink($f);
         @unlink($fout);
         return false;
     }
     $file = new KT_file();
     $content = $file->readFile($fout);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         @unlink($f);
         @unlink($fout);
         return false;
     }
     $file->deleteFile($f);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         @unlink($fout);
         return false;
     }
     $file->deleteFile($fout);
     if ($file->hasError()) {
         $arr = $file->getError();
         $this->setErrorMsg($arr[0], $arr[1]);
         return false;
     }
     $content = str_replace(" ", " ", $content);
     $content = str_replace(" ", " ", $content);
     $content = $this->cleanContent($content);
     $this->tidiedValues[$colName] = $content;
     return true;
 }
예제 #2
0
 /**
  * main class method; Create the image and return the url to the image file;
  * @param string relative path to site root
  * @return mixt image url or error
  */
 function getImageURL($relpath)
 {
     $this->garbageCollector();
     // check write permissions on captcha folder
     $fld = new KT_folder();
     $fld->createFolder(KT_CAPTCHA_TEMP_FOLDER);
     if (!$fld->checkRights(KT_CAPTCHA_TEMP_FOLDER, 'write')) {
         if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') {
             $error = KT_getResource('FOLDER_ERROR_D', 'Captcha', array(KT_CAPTCHA_TEMP_FOLDER));
         } else {
             $error = KT_getResource('FOLDER_ERROR', 'Captcha');
         }
         return $this->formatError($error);
     }
     // with gd
     if ($this->lib == "gd") {
         $arr["GD Version"] = 'GD not available';
         if (function_exists('gd_info')) {
             $arr = gd_info();
             preg_match("/(2)\\.[\\d]+/i", $arr["GD Version"], $matches);
         }
         if (!isset($arr) || !isset($matches[1]) || (int) $matches[1] < 2) {
             $error = KT_getResource('PHP_GD_VERSION_ERROR', 'Captcha', array($arr["GD Version"]));
             return $this->formatError($error);
         }
         $im = imagecreatefrompng(dirname(__FILE__) . '/captcha.png') or $error = KT_getResource('PHP_GD_ERROR', 'Captcha', array());
         if (isset($error)) {
             return $this->formatError($error);
         }
         $string = $this->getTextCaptcha();
         $font = imageloadfont(dirname(__FILE__) . "/fonts/Courier.gdf");
         if ($font === false) {
             $font = 5;
         }
         $fontFileName = dirname(__FILE__) . '/fonts/MyriadWebPro.ttf';
         $wFont = 24;
         $hFont = 24;
         // write the letters
         for ($i = 0; $i < strlen($string); $i++) {
             $color1 = rand(0, 64);
             $color2 = rand(0, 64);
             $color3 = rand(0, 64);
             $text_color = imagecolorallocate($im, $color1, $color2, $color3);
             $okttf = false;
             if (function_exists('imagettftext')) {
                 $okttf = @imagettftext($im, 14, rand(-25, 25), 10 + $i * $wFont, $hFont + rand(4, 26), $text_color, $fontFileName, $string[$i]);
             }
             if ($okttf === false) {
                 $fim = imagecreatetruecolor($wFont + 9, $hFont + 9);
                 $back = imagecolorallocate($fim, 255, 255, 255);
                 imagefilledrectangle($fim, 0, 0, $wFont + 8, $hFont + 8, $back);
                 $transparent2 = imagecolorallocate($fim, 255, 255, 255);
                 $text_color = imagecolorallocate($fim, $color1, $color2, $color3);
                 imagestring($fim, $font, 4, 4, $string[$i], $text_color);
                 if (function_exists("imagerotate")) {
                     $fim = imagerotate($fim, rand(-25, 25), $transparent2);
                 }
                 $iTranspa2 = imagecolortransparent($fim, $transparent2);
                 imagecopymerge($im, $fim, 0 + $i * $wFont, rand(4, 26), 0, 0, $wFont + 9, $hFont + 9, 80);
                 imagedestroy($fim);
             }
         }
         imagepng($im, KT_CAPTCHA_TEMP_FOLDER . $this->filename);
         imagedestroy($im);
         // with imagemagick
     } else {
         $sourceFileName = dirname(__FILE__) . '/captcha.png';
         $fontFileName = dirname(__FILE__) . '/fonts/MyriadWebPro.ttf';
         $destFileName = KT_CAPTCHA_TEMP_FOLDER . $this->filename;
         $arrCommands = array($GLOBALS['KT_prefered_imagemagick_path'] . 'convert');
         $shell = new KT_shell();
         $direction = rand(0, 10);
         if ($direction % 2 == 0) {
             $textRend = -rand(8, 11) . 'x0+' . (5 + (8 - strlen($this->text)) * 20) . '+' . (70 - (8 - strlen($this->text)) * 5);
         } else {
             $textRend = rand(8, 11) . 'x0+' . (5 + (8 - strlen($this->text)) * 20) . '+' . (35 + (8 - strlen($this->text)) * 5);
         }
         $arrArguments = array('-font', $fontFileName, '-pointsize', '34', '-fill', 'rgb(' . rand(0, 32) . ',' . rand(0, 32) . ',' . rand(0, 32) . ')', '-annotate', $textRend, $this->text, '-wave', '3x50', '-region', '100x70+' . rand(0, 100) . '+0', '-swirl', '25', '-region', '100x70+' . rand(0, 100) . '+0', '-swirl', '-25', $sourceFileName, $destFileName);
         $shell->execute($arrCommands, $arrArguments);
         if ($shell->hasError()) {
             $arr = $shell->getError();
             $ret = $this->formatError($arr[0]);
             return $ret;
         }
     }
     return $relpath . KT_CAPTCHA_TEMP_URL . $this->filename;
 }
예제 #3
0
 /**
  * apply watermark on image using GD;
  * Only for PRO version	 
  * @param string $sourceImage 
  * @param string $destination 
  * @param integer $watermarkAlpha
  * @param string $waterMarkImage;
  * @param array $watermarkResize;
  * @param array $watermarkAlignment horizontal, vertical;
  * @return nothing;
  * @access private
  */
 function watermark_imagemagick($sourceImage, $destination, $watermarkImage, $watermarkAlpha, $watermarkResize, $watermarkAlignment)
 {
     if (!$this->checkImageMagik()) {
         return false;
     }
     if (count($watermarkAlignment) == 0) {
         $watermarkAlignment = array('vertical' => 'center', 'horizontal' => 'center');
     }
     $arr = getimagesize($sourceImage);
     $arr2 = getimagesize($watermarkImage);
     // calculates resize dimensions for watermark in case resize = resize|none
     //and watermark is larger than image
     if ($watermarkResize['mode'] == 'none' && ($arr[0] < $arr2[0] || $arr[1] < $arr2[1]) || $watermarkResize['mode'] == 'resize' && ($arr[0] < $watermarkResize['width'] || $arr[1] < $watermarkResize['height'])) {
         $newWidth = $arr[0];
         $newHeight = $arr[1];
         if ($watermarkResize['mode'] == 'resize') {
             $srcWidth = $watermarkResize['width'];
             $srcHeight = $watermarkResize['height'];
         } else {
             $srcWidth = $arr2[0];
             $srcHeight = $arr2[1];
         }
         $ratioWidth = $srcWidth / $newWidth;
         $ratioHeight = $srcHeight / $newHeight;
         if ($ratioWidth < $ratioHeight) {
             $arr2[0] = (int) ($srcWidth / $ratioHeight);
             $arr2[1] = $newHeight;
         } else {
             $arr2[0] = $newWidth;
             $arr2[1] = (int) ($srcHeight / $ratioWidth);
         }
     }
     if ($watermarkResize['mode'] == 'none' || $watermarkResize['mode'] == 'resize') {
         $cmdArg = $arr2[0] . 'x' . $arr2[1];
         // strecth
     } else {
         $cmdArg = $arr[0] . 'x' . $arr[1] . '!';
     }
     $shell = new KT_shell();
     // resize the watermark
     $folder = dirname($watermarkImage) . DIRECTORY_SEPARATOR;
     $destinationFileName = uniqid("") . ".png";
     $arrCommands = $this->arrCommands;
     $arrArguments = array('-resize', $cmdArg, $watermarkImage, $folder . $destinationFileName);
     $shell->execute($arrCommands, $arrArguments);
     if ($shell->hasError()) {
         @unlink($folder . $destinationFileName);
         $arr = $shell->getError();
         $this->setError('IMAGE_WATERMARK_ERR', array($arr[0]), array($arr[1]));
         return false;
     }
     // apply the watermark
     $shell = new KT_shell();
     $arrCommands = $this->arrCommands;
     for ($i = 0; $i < count($arrCommands); $i++) {
         if (substr($arrCommands[$i], -7) == 'convert') {
             $arrCommands[$i] = substr($arrCommands[$i], 0, strlen($arrCommands[$i]) - 7) . 'composite';
         }
     }
     $arrArguments = array('-dissolve', $watermarkAlpha . '%', '-gravity', $this->getWatermarkPosition('imagemagick', array(), array(), $watermarkAlignment), $folder . $destinationFileName, $sourceImage, $destination);
     $shell->execute($arrCommands, $arrArguments);
     @unlink($folder . $destinationFileName);
     if ($shell->hasError()) {
         $arr = $shell->getError();
         $this->setError('IMAGE_WATERMARK_ERR', array($arr[0]), array($arr[1]));
     } else {
         $this->imageMagickPath = $shell->getExecutedCommand();
         return true;
     }
     return true;
 }