AAAAfunctions.class.php000066600000056105151443136000010401 0ustar00"; print_r($str); echo ""; } } class UniteFunctionsHCar { public static function isJoomla3() { if (defined("JVERSION")) { $version = JVERSION; $version = (int) $version; return($version == 3); } if (class_exists("JVersion")) { $jversion = new JVersion; $version = $jversion->getShortVersion(); $version = (int) $version; return($version == 3); } return(!defined("DS")); } public static function throwError($message, $code = null) { if (!empty($code)) throw new Exception($message, $code); else throw new Exception($message); } //-------------------------------------------------------------------------------- //get date db string public static function getDateDBString($timestamp = null) { if ($timestamp == null) $timestamp = time(); date_default_timezone_set('Asia/Jerusalem'); $str = date("Y-m-d H:i:s"); return($str); } //------------------------------------------------------------ // get black value from rgb value public static function yiq($r, $g, $b) { return (($r * 0.299) + ($g * 0.587) + ($b * 0.114)); } //------------------------------------------------------------ // convert colors to rgb public static 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); } //--------------------------------------------------------------------------------------------------- // convert timestamp to time string public static function timestamp2Time($stamp) { $strTime = date("H:i", $stamp); return($strTime); } //--------------------------------------------------------------------------------------------------- // convert timestamp to date and time string public static function timestamp2DateTime($stamp) { $strDateTime = date("d M Y, H:i", $stamp); return($strDateTime); } //--------------------------------------------------------------------------------------------------- // convert timestamp to date string public static function timestamp2Date($stamp) { $strDate = date("d M Y", $stamp); //27 Jun 2009 return($strDate); } /** * get value from array. if not - return alternative */ public static function getVal($arr, $key, $altVal = "") { if (isset($arr[$key])) return($arr[$key]); return($altVal); } //------------------------------------------------------------ public static function toString($obj) { return(trim((string) $obj)); } //------------------------------------------------------------ // get variable from post or from get. get wins. public static function getPostGetVariable($name, $initVar = "") { $var = $initVar; if (isset($_POST[$name])) $var = $_POST[$name]; else if (isset($_GET[$name])) $var = $_GET[$name]; return($var); } //------------------------------------------------------------ public static function getPostVariable($name, $initVar = "") { $var = $initVar; if (isset($_POST[$name])) $var = $_POST[$name]; return($var); } //------------------------------------------------------------ public static function getGetVar($name, $initVar = "") { $var = $initVar; if (isset($_GET[$name])) $var = $_GET[$name]; return($var); } /** * * validate that some file exists, if not - throw error */ public static function validateFilepath($filepath, $errorPrefix = null) { if (file_exists($filepath) == true) return(false); if ($errorPrefix == null) $errorPrefix = "File"; $message = $errorPrefix . " $filepath not exists!"; self::throwError($message); } /** * * validate that some array field (or fields) exists. * could be coma saparaeted fields. */ public static function validateArrayFieldExists($arr, $fields, $messagePrefix = "Field not found") { if (is_array($arr) == false) self::throwError("the array given is not array!!!"); if (empty($fields)) self::throwError("Please give some fields to this function."); $arrFields = explode(",", $fields); foreach ($arrFields as $field) { if (array_key_exists($field, $arr) == false) self::throwError($messagePrefix . ": " . $field . ""); } } /** * * validate that some value is numeric */ public static function validateNumeric($val, $fieldName = "") { self::validateNotEmpty($val, $fieldName); if (empty($fieldName)) $fieldName = "Field"; if (!is_numeric($val)) self::throwError("$fieldName should be numeric "); } /** * * validate that some variable not empty */ public static function validateNotEmpty($val, $fieldName = "") { if (empty($fieldName)) $fieldName = "Field"; if (empty($val) && is_numeric($val) == false) self::throwError("Field $fieldName should not be empty"); } /** * * if directory not exists - create it * @param $dir */ public static function checkCreateDir($dir) { if (!is_dir($dir)) mkdir($dir); } /** * * get some directory cotnents including files and folders, filter the "." and the ".." on the way * type can be all, file, dir */ public static function getFolderContents($path, $type = "all") { if (!is_dir($path)) self::throwError("path not found: $path"); $path = realpath($path) . "/"; $arrDirContents = scandir($path); $arrNew = array(); foreach ($arrDirContents as $key => $file) { if ($file == "." || $file == "..") continue; $filepath = $path . $file; $skip = false; switch ($type) { case "file": if (is_dir($filepath)) $skip = true; break; case "dir": if (is_file($filepath)) $skip = true; break; } if ($skip == true) continue; $arrNew[] = $file; } return($arrNew); } /** * * get only child directories from some folder * */ public static function getFolderDirs($path) { $arrContents = self::getFolderContents($path, "dir"); return($arrContents); } /** * * get only child directories from some folder * */ public static function getFolderFiles($path) { $arrContents = self::getFolderContents($path, "file"); return($arrContents); } /** * filter array, leaving only needed fields - also array */ public static function filterArrFields($arr, $fields) { $arrNew = array(); foreach ($fields as $field) { if (isset($arr[$field])) $arrNew[$field] = $arr[$field]; } return($arrNew); } //------------------------------------------------------------ //get path info of certain path with all needed fields public static function getPathInfo($filepath) { $info = pathinfo($filepath); //fix the filename problem if (!isset($info["filename"])) { $filename = $info["basename"]; if (isset($info["extension"])) $filename = substr($info["basename"], 0, (-strlen($info["extension"]) - 1)); $info["filename"] = $filename; } return($info); } /** * Convert std class to array, with all sons * @param unknown_type $arr */ public static function convertStdClassToArray($arr) { if (getType($arr) != "array" && getType($arr) != "object") return($arr); $arr = (array) $arr; foreach ($arr as $key => $item) { if (getType($item) == "array" || getType($item) == "object") $item = self::convertStdClassToArray($item); $arr[$key] = $item; } return($arr); } //------------------------------------------------------------ //save some file to the filesystem with some text public static function writeFile($str, $filepath) { $fp = fopen($filepath, "w+"); fwrite($fp, $str); fclose($fp); } //------------------------------------------------------------ //save some file to the filesystem with some text public static function writeDebug($str, $filepath = "debug.txt", $showInputs = true) { $post = print_r($_POST, true); $server = print_r($_SERVER, true); if (getType($str) == "array") $str = print_r($str, true); if ($showInputs == true) { $output = "--------------------" . "\n"; $output .= self::getDateDBString() . "\n"; $output .= $str . "\n"; $output .= "Post: " . $post . "\n"; } else { $output = "---" . "\n"; $output .= $str . "\n"; } if (!empty($_GET)) { $get = print_r($_GET, true); $output .= "Get: " . $get . "\n"; } //$output .= "Server: ".$server."\n"; $fp = fopen($filepath, "a+"); fwrite($fp, $output); fclose($fp); } /** * * clear debug file */ public static function clearDebug($filepath = "debug.txt") { if (file_exists($filepath)) unlink($filepath); } /** * * save to filesystem the error */ public static function writeDebugError(Exception $e, $filepath = "debug.txt") { $message = $e->getMessage(); $trace = $e->getTraceAsString(); $output = $message . "\n"; $output .= $trace . "\n"; $fp = fopen($filepath, "a+"); fwrite($fp, $output); fclose($fp); } //------------------------------------------------------------ //save some file to the filesystem with some text public static function addToFile($str, $filepath) { $fp = fopen($filepath, "a+"); fwrite($fp, "---------------------\n"); fwrite($fp, $str . "\n"); fclose($fp); } //-------------------------------------------------------------- //check the php version. throw exception if the version beneath 5 private static function checkPHPVersion() { $strVersion = phpversion(); $version = (float) $strVersion; if ($version < 5) throw new Exception("You must have php5 and higher in order to run the application. Your php version is: $version"); } //-------------------------------------------------------------- // valiadte if gd exists. if not - throw exception private static function validateGD() { if (function_exists('gd_info') == false) throw new Exception("You need GD library to be available in order to run this application. Please turn it on in php.ini"); } //-------------------------------------------------------------- //return if the json library is activated public static function isJsonActivated() { return(function_exists('json_encode')); } /** * * encode array into json for client side */ public static function jsonEncodeForClientSide($arr) { $json = ""; if (!empty($arr)) { $json = json_encode($arr); $json = addslashes($json); } $json = "'" . $json . "'"; return($json); } //-------------------------------------------------------------- //validate if some directory is writable, if not - throw a exception private static function validateWritable($name, $path, $strList, $validateExists = true) { if ($validateExists == true) { //if the file/directory doesn't exists - throw an error. if (file_exists($path) == false) throw new Exception("$name doesn't exists"); } else { //if the file not exists - don't check. it will be created. if (file_exists($path) == false) return(false); } if (is_writable($path) == false) { chmod($path, 0755); //try to change the permissions if (is_writable($path) == false) { $strType = "Folder"; if (is_file($path)) $strType = "File"; $message = "$strType $name is doesn't have a write permissions. Those folders/files must have a write permissions in order that this application will work properly: $strList"; throw new Exception($message); } } } //-------------------------------------------------------------- //validate presets for identical keys public static function validatePresets() { global $g_presets; if (empty($g_presets)) return(false); //check for duplicates $assoc = array(); foreach ($g_presets as $preset) { $id = $preset["id"]; if (isset($assoc[$id])) throw new Exception("Double preset ID detected: $id"); $assoc[$id] = true; } } //-------------------------------------------------------------- //Get url of image for output public static function getImageOutputUrl($filename, $width = 0, $height = 0, $exact = false) { //exact validation: if ($exact == "true" && (empty($width) || empty($height) )) self::throwError("Exact must have both - width and height"); $url = CMGlobals::$URL_GALLERY . "?img=" . $filename; if (!empty($width)) $url .= "&w=" . $width; if (!empty($height)) $url .= "&h=" . $height; if ($exact == true) $url .= "&t=exact"; return($url); } /** * * get list of all files in the directory */ public static function getFileList($path) { $dir = scandir($path); $arrFiles = array(); foreach ($dir as $file) { if ($file == "." || $file == "..") continue; $filepath = $path . "/" . $file; if (is_file($filepath)) $arrFiles[] = $file; } return($arrFiles); } /** * * do "trim" operation on all array items. */ public static function trimArrayItems($arr) { if (gettype($arr) != "array") UniteFunctionsHCar::throwError("trimArrayItems error: The type must be array"); foreach ($arr as $key => $item) $arr[$key] = trim($item); return($arr); } /** * * get url contents */ public static function getUrlContents($url, $arrPost = array(), $method = "post", $debug = false) { $ch = curl_init(); $timeout = 0; $strPost = ''; foreach ($arrPost as $key => $value) { if (!empty($strPost)) $strPost .= "&"; $value = urlencode($value); $strPost .= "$key=$value"; } //set curl options if (strtolower($method) == "post") { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $strPost); } else //get $url .= "?" . $strPost; //remove me //Functions::addToLogFile(SERVICE_LOG_SERVICE, "url", $url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $headers = array(); $headers[] = "User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8"; $headers[] = "Accept-Charset:utf-8;q=0.7,*;q=0.7"; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $response = curl_exec($ch); if ($debug == true) { dmp($url); dmp($response); exit(); } if ($response == false) throw new Exception("getUrlContents Request failed"); curl_close($ch); return($response); } /** * * get link html */ public static function getHtmlLink($link, $text, $id = "", $class = "") { if (!empty($class)) $class = " class='$class'"; if (!empty($id)) $id = " id='$id'"; $html = "$text"; return($html); } /** * * get select from array */ public static function getHTMLSelect($arr, $default = "", $htmlParams = "", $assoc = false) { $html = ""; return($html); } /** * * convert array to assoc array by some field */ public static function arrayToAssoc($arr, $field) { $arrAssoc = array(); foreach ($arr as $item) $arrAssoc[$item[$field]] = $item; return($arrAssoc); } /** * * convert assoc array to array */ public static function assocToArray($assoc) { $arr = array(); foreach ($assoc as $item) $arr[] = $item; return($arr); } /** * * strip slashes from textarea content after ajax request to server */ public static function normalizeTextareaContent($content) { if (empty($content)) return($content); $content = stripslashes($content); $content = trim($content); return($content); } /** * * echo json array, and exit. */ public static function jsonResponse($data) { $json = json_encode($data); echo $json; exit(); } /** * * Enter description here ... * @param unknown_type $response */ public static function jsonErrorResponse($message, $action = "") { $data = array(); $data["success"] = false; $data["message"] = $message; $data["aciton"] = $action; self::jsonResponse($data); } /** * * get all defined constants list with values. */ public static function getDefinedConstants() { $arr = get_defined_constants(true); $arrUser = $arr["user"]; return($arrUser); } /** * * parse settings (name=value) file content */ public static function parseSettingsFile($content) { $arrSettings = array(); $lines = explode("\n", $content); foreach ($lines as $line) { $line = trim($line); if (empty($line)) continue; $arr = explode("=", $line); if (count($arr) != 2) continue; $key = trim($arr[0]); $value = trim($arr[1]); $arrSettings[$key] = $value; } return($arrSettings); } /** * * output error message */ public static function errorHtmlOutput($message) { header("Status: 404 Not Found"); echo $message; exit(); } /** * Generate random string * @param $len */ public static function generateRandomString($len) { $strHash = ""; for ($i = 0; $i < 3; $i++) { $randomNum = 99999 * rand(); $hash = base64_encode($randomNum); $hash = str_replace("=", "", $hash); $strHash .= $hash; } $strHash = strtolower($strHash); $output = substr($strHash, 0, $len); return($output); } /** * * redirect to some url */ public static function redirectToUrl($url) { header("location: $url"); exit(); } /** * return true/false if the email is valid */ public static function isEmailValid($email) { return preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email); } //------------------------------------------------------------------------------------------ // output file for downloading public static function downloadFile($filepath, $filename, $mimeType = "") { $contents = file_get_contents($filepath); $filesize = strlen($contents); if ($mimeType == "") { $info = pathinfo($filepath); $ext = $info["extension"]; switch ($ext) { case "zip": $mimeType = "application/$ext"; break; default: $mimeType = "image/$ext"; break; } } header("Content-Type: $mimeType"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Length: $filesize"); echo $contents; exit(); } } ?>includes.php000066600000001631151443136000007065 0ustar00index.html000066600000000000151443136000006530 0ustar00image_view.class.php000066600000043374151443136000010511 0ustar00pathCache = $pathCache; $this->pathImages = $pathImages; $this->urlImages = $urlImages; $this->pathEmptyImage = $pathEmptyImage; } /** * * set jpg quality output */ public function setJPGQuality($quality){ $this->jpg_quality = $quality; } /** * * get thumb url */ public static function getUrlThumb($urlBase, $filename,$width=null,$height=null,$exact=false,$effect=null,$effect_param=null){ $filename = urlencode($filename); $url = $urlBase."&img=$filename"; if(!empty($width)) $url .= "&w=".$width; if(!empty($height)) $url .= "&h=".$height; if($exact == true){ $url .= "&t=".self::TYPE_EXACT; } if(!empty($effect)){ $url .= "&e=".$effect; if(!empty($effect_param)) $url .= "&ea1=".$effect_param; } return($url); } /** * * throw error */ private function throwError($message,$code=null){ UniteFunctionsHCar::throwError($message,$code); } /** * get thumb filename from the input * */ public static function getThumbFilenameFromInput($filename,$width,$height,$exact){ $info = pathInfo($filename); $ext = UniteFunctionsHCar::getVal($info, "extension"); $name = $info["filename"]; $thumbFilename = $name."_".$width."x".$height; if($exact == true) $thumbFilename .= "_exact"; $postfix = ""; $dirname = UniteFunctionsHCar::getVal($info, "dirname"); if(!empty($dirname)) $postfix = str_replace("/", "-", $dirname); if(!empty($postfix)) $thumbFilename .= "_".$postfix; $thumbFilename.= '.'.$ext; return($thumbFilename); } /** * * get filename for thumbnail save / retrieve * TODO: do input validations - security measures */ private function getThumbFilename(){ $info = pathInfo($this->filename); //add dirname as postfix (if exists) $postfix = ""; $dirname = UniteFunctionsHCar::getVal($info, "dirname"); if(!empty($dirname)){ $postfix = str_replace("/", "-", $dirname); } $ext = $info["extension"]; $name = $info["filename"]; $width = ceil($this->maxWidth); $height = ceil($this->maxHeight); $thumbFilename = $name."_".$width."x".$height; if(!empty($this->type)) $thumbFilename .= "_" . $this->type; if(!empty($this->effect)){ $thumbFilename .= "_e" . $this->effect; if(!empty($this->effect_arg1)){ $thumbFilename .= "x" . $this->effect_arg1; } } //add postfix if(!empty($postfix)) $thumbFilename .= "_".$postfix; $thumbFilename .= ".".$ext; return($thumbFilename); } //------------------------------------------------------------------------------------------ // get thumbnail fielpath by parameters. private function getThumbFilepath(){ $filename = $this->getThumbFilename(); $filepath = $this->pathCache .$filename; return($filepath); } //------------------------------------------------------------------------------------------ // ouptput emtpy image code. private function outputEmptyImageCode(){ echo "empty image"; exit(); } //------------------------------------------------------------------------------------------ // outputs image and exit. private function outputImage($filepath){ $info = UniteFunctionsHCar::getPathInfo($filepath); $ext = $info["extension"]; $filetime = filemtime($filepath); $ext = strtolower($ext); if($ext == "jpg") $ext = "jpeg"; $numExpires = 31536000; //one year $strExpires = @date('D, d M Y H:i:s',time()+$numExpires); $strModified = @date('D, d M Y H:i:s',$filetime); $contents = file_get_contents($filepath); $filesize = strlen($contents); header("Last-Modified: $strModified GMT"); header("Expires: $strExpires GMT"); header("Cache-Control: public"); header("Content-Type: image/$ext"); header("Content-Length: $filesize"); echo $contents; exit(); } //------------------------------------------------------------------------------------------ // get src image from filepath according the image type private function getGdSrcImage($filepath,$type){ // create the image $src_img = false; switch($type){ case IMAGETYPE_JPEG: $src_img = @imagecreatefromjpeg($filepath); break; case IMAGETYPE_PNG: $src_img = @imagecreatefrompng($filepath); break; case IMAGETYPE_GIF: $src_img = @imagecreatefromgif($filepath); break; case IMAGETYPE_BMP: $src_img = @imagecreatefromwbmp($filepath); break; default: $this->throwError("wrong image format, can't resize"); break; } if($src_img == false){ $this->throwError("Can't resize image"); } return($src_img); } //------------------------------------------------------------------------------------------ // save gd image to some filepath. return if success or not private function saveGdImage($dst_img,$filepath,$type){ $successSaving = false; switch($type){ case IMAGETYPE_JPEG: $successSaving = imagejpeg($dst_img,$filepath,$this->jpg_quality); break; case IMAGETYPE_PNG: $successSaving = imagepng($dst_img,$filepath); break; case IMAGETYPE_GIF: $successSaving = imagegif($dst_img,$filepath); break; case IMAGETYPE_BMP: $successSaving = imagewbmp($dst_img,$filepath); break; } return($successSaving); } //------------------------------------------------------------------------------------------ // crop image to specifix height and width , and save it to new path private function cropImageSaveNew($filepath,$filepathNew){ $imgInfo = getimagesize($filepath); $imgType = $imgInfo[2]; $src_img = $this->getGdSrcImage($filepath,$imgType); $width = imageSX($src_img); $height = imageSY($src_img); //crop the image from the top $startx = 0; $starty = 0; //find precrop width and height: $percent = $this->maxWidth / $width; $newWidth = $this->maxWidth; $newHeight = ceil($percent * $height); if($this->type == "exact"){ //crop the image from the middle $startx = 0; $starty = ($newHeight-$this->maxHeight)/2 / $percent; } if($newHeight < $this->maxHeight){ //by width $percent = $this->maxHeight / $height; $newHeight = $this->maxHeight; $newWidth = ceil($percent * $width); if($this->type == "exact"){ //crop the image from the middle $startx = ($newWidth - $this->maxWidth) /2 / $percent; //the startx is related to big image $starty = 0; } } //resize the picture: $tmp_img = ImageCreateTrueColor($newWidth,$newHeight); $this->handleTransparency($tmp_img,$imgType,$newWidth,$newHeight); imagecopyresampled($tmp_img,$src_img,0,0,$startx,$starty,$newWidth,$newHeight,$width,$height); $this->handleImageEffects($tmp_img); //crop the picture: $dst_img = ImageCreateTrueColor($this->maxWidth,$this->maxHeight); $this->handleTransparency($dst_img,$imgType,$this->maxWidth,$this->maxHeight); imagecopy($dst_img, $tmp_img, 0, 0, 0, 0, $newWidth, $newHeight); //save the picture $is_saved = $this->saveGdImage($dst_img,$filepathNew,$imgType); imagedestroy($dst_img); imagedestroy($src_img); imagedestroy($tmp_img); return($is_saved); } //------------------------------------------------------------------------------------------ // if the images are png or gif - handle image transparency private function handleTransparency(&$dst_img,$imgType,$newWidth,$newHeight){ //handle transparency: if($imgType == IMAGETYPE_PNG || $imgType == IMAGETYPE_GIF){ imagealphablending($dst_img, false); imagesavealpha($dst_img,true); $transparent = imagecolorallocatealpha($dst_img, 255, 255, 255, 127); imagefilledrectangle($dst_img, 0, 0, $newWidth, $newHeight, $transparent); } } //------------------------------------------------------------------------------------------ // handle image effects private function handleImageEffects(&$imgHandle){ if(empty($this->effect)) return(false); switch($this->effect){ case self::EFFECT_BW: if(defined("IMG_FILTER_GRAYSCALE")) imagefilter($imgHandle,IMG_FILTER_GRAYSCALE); break; case self::EFFECT_BRIGHTNESS: if(defined("IMG_FILTER_BRIGHTNESS")){ if(!is_numeric($this->effect_arg1)) $this->effect_arg1 = 50; //set default value UniteFunctionsHCar::validateNumeric($this->effect_arg1,"'ea1' argument"); imagefilter($imgHandle,IMG_FILTER_BRIGHTNESS,$this->effect_arg1); } break; case self::EFFECT_CONTRAST: if(defined("IMG_FILTER_CONTRAST")){ if(!is_numeric($this->effect_arg1)) $this->effect_arg1 = -5; //set default value imagefilter($imgHandle,IMG_FILTER_CONTRAST,$this->effect_arg1); } break; case self::EFFECT_EDGE: if(defined("IMG_FILTER_EDGEDETECT")) imagefilter($imgHandle,IMG_FILTER_EDGEDETECT); break; case self::EFFECT_EMBOSS: if(defined("IMG_FILTER_EMBOSS")) imagefilter($imgHandle,IMG_FILTER_EMBOSS); break; case self::EFFECT_BLUR: if(defined("IMG_FILTER_GAUSSIAN_BLUR")) imagefilter($imgHandle,IMG_FILTER_GAUSSIAN_BLUR); break; case self::EFFECT_MEAN: if(defined("IMG_FILTER_MEAN_REMOVAL")) imagefilter($imgHandle,IMG_FILTER_MEAN_REMOVAL); break; case self::EFFECT_SMOOTH: if(defined("IMG_FILTER_SMOOTH")){ if(!is_numeric($this->effect_arg1)) $this->effect_arg1 = 15; //set default value imagefilter($imgHandle,IMG_FILTER_SMOOTH,$this->effect_arg1); } break; default: $this->throwError("Effect not supported: {$this->effect}"); break; } } //------------------------------------------------------------------------------------------ // resize image and save it to new path private function resizeImageSaveNew($filepath,$filepathNew){ $imgInfo = getimagesize($filepath); $imgType = $imgInfo[2]; $src_img = $this->getGdSrcImage($filepath,$imgType); $width = imageSX($src_img); $height = imageSY($src_img); $newWidth = $width; $newHeight = $height; //find new width if($height > $this->maxHeight){ $procent = $this->maxHeight / $height; $newWidth = ceil($width * $procent); $newHeight = $this->maxHeight; } //if the new width is grater than max width, find new height, and remain the width. if($newWidth > $this->maxWidth){ $procent = $this->maxWidth / $newWidth; $newHeight = ceil($newHeight * $procent); $newWidth = $this->maxWidth; } //if the image don't need to be resized, just copy it from source to destanation. if($newWidth == $width && $newHeight == $height && empty($this->effect)){ $success = copy($filepath,$filepathNew); if($success == false) $this->throwError("can't copy the image from one path to another"); } else{ //else create the resized image, and save it to new path: $dst_img = ImageCreateTrueColor($newWidth,$newHeight); $this->handleTransparency($dst_img,$imgType,$newWidth,$newHeight); //copy the new resampled image: imagecopyresampled($dst_img,$src_img,0,0,0,0,$newWidth,$newHeight,$width,$height); $this->handleImageEffects($dst_img); $is_saved = $this->saveGdImage($dst_img,$filepathNew,$imgType); imagedestroy($dst_img); } imagedestroy($src_img); return(true); } /** * * set image effect */ public function setEffect($effect,$arg1 = ""){ $this->effect = $effect; $this->effect_arg1 = $arg1; } //------------------------------------------------------------------------------------------ //return image private function showImage($filename,$maxWidth=-1,$maxHeight=-1,$type=""){ if(empty($filename)) $this->throwError("image filename not found"); //validate input if($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP){ if($maxHeight == -1) $this->throwError("image with exact type must have height!"); if($maxWidth == -1) $this->throwError("image with exact type must have width!"); } $filepath = $this->pathImages.$filename; if(!is_file($filepath)){ if(!empty($this->pathEmptyImage)) $filepath = $this->pathEmptyImage; } if(!is_file($filepath)) $this->outputEmptyImageCode(); //if gd library doesn't exists - output normal image without resizing. if(function_exists("gd_info") == false) $this->throwError("php must support GD Library"); //check conditions for output original image if(empty($this->effect)){ if((is_numeric($maxWidth) == false || is_numeric($maxHeight) == false)) outputImage($filepath); if($maxWidth == -1 && $maxHeight == -1) $this->outputImage($filepath); } if($maxWidth == -1) $maxWidth = 1000000; if($maxHeight == -1) $maxHeight = 100000; //init variables $this->filename = $filename; $this->maxWidth = $maxWidth; $this->maxHeight = $maxHeight; $this->type = $type; $filepathNew = $this->getThumbFilepath(); if(is_file($filepathNew)){ $this->outputImage($filepathNew); exit(); } try{ if($type == self::TYPE_EXACT || $type == self::TYPE_EXACT_TOP){ $isSaved = $this->cropImageSaveNew($filepath,$filepathNew); } else $isSaved = $this->resizeImageSaveNew($filepath,$filepathNew); if($isSaved == false){ $this->outputImage($filepath); exit(); } }catch(Exception $e){ $this->outputImage($filepath); } if(is_file($filepathNew)) $this->outputImage($filepathNew); else $this->outputImage($filepath); exit(); } /** * * show some error messag */ private function showError(){ echo "error ocurred"; exit(); } /** * * validate filename if it's not some error */ private function validateFilename($filename){ //protections: if(strpos($filename, "images/") !== 0) $this->showError(); $info = pathinfo($filename); $extension = UniteFunctionsHCar::getVal($info, "extension"); $extension = strtolower($extension); switch($extension){ case "jpg": case "jpeg": case "png": case "gif": break; default: $this->showError(); break; } } /** * * show image from get params */ public function showImageFromGet(){ $imageFilename = UniteFunctionsHCar::getGetVar("img"); $noencode = UniteFunctionsHCar::getGetVar("noencode",""); if($noencode != "true") $imageFilename = base64_decode($imageFilename); $this->validateFilename($imageFilename); $maxWidth = UniteFunctionsHCar::getGetVar("w",-1); $maxHeight = UniteFunctionsHCar::getGetVar("h",-1); $type = UniteFunctionsHCar::getGetVar("t",""); //set effect $effect = UniteFunctionsHCar::getGetVar("e"); $effectArgument1 = UniteFunctionsHCar::getGetVar("ea1"); if(!empty($effect)) $this->setEffect($effect,$effectArgument1); $this->showImage($imageFilename,$maxWidth,$maxHeight,$type); } //------------------------------------------------------------------------------------------ // download image, change size and name if needed. public function downloadImage($filename){ $filepath = $this->urlImages."/".$filename; if(!is_file($filepath)) { echo "file doesn't exists"; exit(); } $this->outputImageForDownload($filepath,$filename); } //------------------------------------------------------------------------------------------ // output image for downloading private function outputImageForDownload($filepath,$filename,$mimeType=""){ $contents = file_get_contents($filepath); $filesize = strlen($contents); if($mimeType == ""){ $info = UniteFunctionsHCar::getPathInfo($filepath); $ext = $info["extension"]; $mimeType = "image/$ext"; } header("Content-Type: $mimeType"); header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Length: $filesize"); echo $contents; exit(); } /** * * validate type * @param unknown_type $type */ public function validateType($type){ switch($type){ case self::TYPE_EXACT: case self::TYPE_EXACT_TOP: break; default: $this->throwError("Wrong image type: ".$type); break; } } } ?>functions_joomla.class.php000066600000017070151443136000011740 0ustar00getLabel($name,$group); echo $form->getInput($name,$group); } /** * * print fieldset box */ public static function putHtmlFieldsetBox($form,$name,$boxTitle="Settings"){ if(empty($form)) UniteFunctionsHCar::throwError("Form not found!!!"); ?>
addScriptDeclaration($script); } /** * * encode array to registry (json) for saving, in some array of items * */ public static function encodeArrayToRegistry($arr,$field){ if(!isset($arr[$field])) return(""); if(!is_array($arr[$field])) return($arr[$field]); $registry = new JRegistry(); $registry->loadArray($arr[$field]); $value = $registry->toString('JSON'); return($value); } /** * * decode some array item to registry */ public static function decodeRegistryToArray($arr,$field){ $output = array(); if(!isset($arr[$field])) return($output); $value = $arr[$field]; if(is_array($value)) return($value); $registry = new JRegistry(); $registry->loadString($value,'JSON'); $output = $registry->toArray(); return($output); } /** * * get form field value by types. */ public static function getFormFieldValue($form,$field,$group=null){ $objField = $form->getField($field,$group); $value = $objField->value; $type = strtolower($objField->type); switch($type){ case "mycheckbox": $value = $objField->isChecked(); break; } return($value); } /** * * hide some form field * @param $form */ public static function hideFormField(JForm $form,$field, $group=""){ $class = $form->getFieldAttribute($field, "class","",$group); if(!empty($class)) $class .= " hidden"; else $class == "hidden"; $form->setFieldAttribute($field, "hidden", "true",$group); $form->setFieldAttribute($field, "class", $class,$group); } /** * * set alias from title */ public static function normalizeAlias($alias){ $alias = JFilterOutput::stringURLSafe($alias); if(trim(str_replace('-','',$alias)) == '') $alias = JFactory::getDate()->format("Y-m-d-H-i-s"); return($alias); } /** * * put multiple html option boxes */ public static function putHtmlFieldsetBoxes($form,$name){ $arrfieldsets = $form->getFieldsets($name); foreach($arrfieldsets as $arrFieldset) self::putHtmlFieldsetBox($form,$arrFieldset->name,$arrFieldset->label); } /** * * give joomla order to hide main menu. * this must be used on view.html.php */ public static function hideMainMenu(){ JRequest::setVar('hidemainmenu', true); } /** * * get current component */ public static function getCurrentComponent(){ $component = JRequest::getVar("option"); return($component); } /** * * get component url - site side * */ public static function getUrlComponent($args,$component=""){ if(empty($component)) $component = self::$componentName; $url = juri::root()."index.php?option=".$component."&".$args; return($url); } /** * * get view url (admin side) */ public static function getViewUrl($view,$layout="default",$args="",$component=""){ if(empty($component)) $component = self::$componentName; $url = "index.php?option=".$component; $url .= "&view=$view"; //add layout if(!empty($layout)) $url .= "&layout=".$layout; //add additional arguments if(!empty($args)) $url .= "&".$args; //$url = JURI::root().$url; $url = JRoute::_($url,false); return($url); } /** * Get url of image for output */ public static function getImageOutputUrl($filename,$width=0,$height=0,$exact=false,$encode=true){ $pathImages = JPATH_SITE."/"; $filenameThumb = UniteImageViewHCar::getThumbFilenameFromInput($filename,$width,$height,$exact); $pathCache = self::getPathCache(); $filepath = $pathCache.$filenameThumb; if(file_exists($filepath)){ $urlImage = GlobalsUniteHCar::$urlCache.$filenameThumb; return($urlImage); } //exact validation: if(($exact == "true" || $exact == true) && (empty($width) || empty($height) )) UniteFunctionsHCar::throwError("Exact must have both - width and height"); if($encode == true) $filename = base64_encode($filename); $url = "index.php?option=".self::$componentName."&task=showimage&img=$filename"; if(!empty($width)) $url .= "&w=".$width; if(!empty($height)) $url .= "&h=".$height; if($exact == true) $url .= "&t=exact"; if($encode == false) $url .= "&noencode=true"; return($url); } /** * * get image url from filename */ public static function getImageUrl($filename){ $urlImage = JURI::root().$filename; return($urlImage); } /** * get cache path. if not exists - try to crate it */ private static function getPathCache(){ //set cache path $component = self::$componentName; $pathCache = JPATH_SITE."/cache/".$component."/"; if(is_dir($pathCache)) return($pathCache); @mkdir($pathCache); if(is_dir($pathCache)) return($pathCache); //make media cache path $pathCache = JPATH_SITE."/media/".$component."/cache/"; if(is_dir($pathCache)) return($pathCache); @mkdir($pathCache); if(is_dir($pathCache)) return($pathCache); //make component cache path $pathCache = JPATH_COMPONENT_SITE."/cache/"; return($pathCache); } /** * show image from request */ public static function showImageFromRequest(){ $pathCache = self::getPathCache(); $pathImages = JPATH_SITE."/"; $urlImages = JURI::root(); $pathEmptyImage = JPATH_COMPONENT_ADMINISTRATOR."/assets/resizer/empty_image.jpg"; $imageView = new UniteImageViewHCar($pathCache, $pathImages, $urlImages, $pathEmptyImage); $imageView->showImageFromGet(); exit(); } /** * * get post or get application */ public static function getPostGetVar($name,$default="",$filter="STRING"){ if(empty(self::$app)) self::$app = JFactory::getApplication(); $jinput = self::$app->input; $var = $jinput->get($name,$default,$filter); return($var); } } ?>.htaccess000066600000000177151443136000006350 0ustar00 Order allow,deny Deny from all admintable.class.php000066600000005720151443136000010466 0ustar00state = $state; $this->self = $_SERVER["PHP_SELF"]; } /** * * add column type and name */ private function addCol($type=null,$name=null,$title=null,$sort_value = null){ $col = array(); $col["type"] = $type; $col["name"] = $name; $col["title"] = $title; $col["sort_value"] = $sort_value; $this->arrCols[] = $col; } /** * * add "regular" text column */ public function addCol_text($name,$title,$sort_value=null){ $this->addCol(self::COL_TYPE_TEXT,$name,$title,$sort_value); } /** * * add checkboxes column */ public function addCol_checkbox(){ $this->addCol(self::COL_TYPE_CHECKBOX); } /** * * add some filter */ public function addFilter($type){ $filter = array(); $filter["type"] = $type; $this->arrFilters[] = $filter; } /** * * add "published" filter */ public function addFilterPublished(){ $this->addFilter(self::FILTER_TYPE_PUBLISHED); } /** * =========================================================== */ /** * * draw some filter */ private function putFilter($filter){ $type = $filter["type"]; switch($filter["type"]){ case self::FILTER_TYPE_PUBLISHED: ?> arrFilters)) return(false); ?>
arrFilters as $filter) $this->putFilter($filter); ?>
masterview.class.php000066600000000677151443136000010562 0ustar00