function mxi_includes_start($fName) { if (!isset($GLOBALS['KT_REL_PATH'])) { $GLOBALS['KT_REL_PATH'] = ""; } $tmpArr = array(); $tmpArr['dirRelPath'] = dirname($fName) . "/"; if ($tmpArr['dirRelPath'] == "./") { $tmpArr['dirRelPath'] = ""; } $tmpArr['relpath'] = KT_CanonizeRelPath($GLOBALS['KT_REL_PATH'] . $tmpArr['dirRelPath']); $tmpArr['relpath'] = $GLOBALS['KT_REL_PATH'] . $tmpArr['dirRelPath']; $tmpArr['dir'] = getcwd() . DIRECTORY_SEPARATOR; $GLOBALS['KT_dir_depth'][] = $tmpArr; $GLOBALS['KT_REL_PATH'] = $tmpArr['relpath']; if ($tmpArr['dirRelPath'] != "") { $chk = @chdir($tmpArr['dirRelPath']); if ($chk === false) { die(KT_getResource('PHP_CHDIR_FAILED', 'MXI', array($tmpArr['dirRelPath']))); } } ob_start(); if (isset($GLOBALS['tNGs'])) { if (!isset($GLOBALS['arrTNGs'])) { $GLOBALS['arrTNGs'] = array(); } $GLOBALS['arrTNGs'][] = $GLOBALS['tNGs']; } }
/** * Transforms a path into its absolute value * Path separator is always "/" and for folders, always adds the trailing "/" * If folder/file does not exist, the "pathName" will be added to the current folder path * @param string $pathName The path to be translated * @param boolean $isFolder Specifies if the path is a folder or a file * @return string return the absolute path */ function KT_realpath($pathName, $isFolder = true) { $isAbsolute = false; if (strtolower(substr(PHP_OS, 0, 3)) === 'win') { if (substr($pathName, 1, 1) == ":") { $isAbsolute = true; } } else { if (substr($pathName, 0, 1) == "/") { $isAbsolute = true; } } if ($isAbsolute) { $realPath = $pathName; } else { $realPath = realpath($pathName); if ($realPath === false) { $realPath = realpath('.') . DIRECTORY_SEPARATOR; $realPath .= $pathName; } } $realPath = str_replace('\\\\', '\\', $realPath); $realPath = str_replace('\\', '/', $realPath); $realPath = str_replace('//', '/', $realPath); if ($isFolder) { if (substr($realPath, strlen($realPath) - 1) != '/') { $realPath .= '/'; } } $realPath = str_replace("/./", "/", $realPath); $realPath = str_replace("/./", "/", $realPath); $realPath = KT_CanonizeRelPath($realPath); return $realPath; }
/** * Main class method. Resize the image and apply the watermark; * @return string error string or url to thumbnail * @access public */ function Execute() { $ret = ""; $relpath = $this->relpath; $folder = KT_TransformToUrlPath($this->folder); $fileName = KT_DynamicData($this->renameRule, null); $fileName = KT_TransformToUrlPath($fileName, false); $fullFolder = KT_realpath($folder, true); $fullFileName = KT_realpath($fullFolder . $fileName, false); $path_info = KT_pathinfo($fullFileName); $thumbnailFolder = $path_info['dirname'] . '/thumbnails/'; if (substr($fullFileName, 0, strlen($fullFolder)) != $fullFolder) { if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $baseFileName = dirname($fullFileName); $errorMsg = KT_getResource("FOLDER_DEL_SECURITY_ERROR_D", "tNG", array($baseFileName, $fullFolder)); $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errorMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } else { $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } } else { if ($this->getFileName() !== false) { // make the resize $proportional = $this->keepProportion; $width = $this->width; $height = $this->height; if (!$this->watermark) { $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . (isset($path_info['extension']) ? '.' . $path_info['extension'] : ''); } else { $hash = tNG_watermarkHash(KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment); $thumbnailName = $path_info['filename'] . '_' . $width . 'x' . $height . '_w_' . $hash . (isset($path_info['extension']) ? '.' . $path_info['extension'] : ''); } $thumbnailFullName = $thumbnailFolder . $thumbnailName; if (!file_exists(KT_realpath($thumbnailFullName, false))) { $imageObj = new KT_image(); $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']); $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']); $imageObj->thumbnail($fullFileName, $thumbnailFolder, $thumbnailName, (int) $width, (int) $height, $proportional); if ($imageObj->hasError()) { $errorArr = $imageObj->getError(); if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $errMsg = $errorArr[1]; $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } else { $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } return $ret; } else { // apply watermark if ($this->watermark) { // delete other watermarks for same picture tNG_deleteThumbnails($thumbnailFolder, $path_info['filename'] . '_' . $width . 'x' . $height, $hash); $imageObj = new KT_image(); $imageObj->setPreferedLib($GLOBALS['tNG_prefered_image_lib']); $imageObj->addCommand($GLOBALS['tNG_prefered_imagemagick_path']); $imageObj->watermark($thumbnailFullName, $thumbnailFullName, KT_realpath($this->watermarkImage, false), $this->watermarkAlpha, $this->watermarkResize, $this->watermarkAlignment); if ($imageObj->hasError()) { @unlink($thumbnailFullName); $arrError = $imageObj->getError(); $errObj = new tNG_error('IMG_WATERMARK', array(), array($arrError[1])); if ($GLOBALS['tNG_debug_mode'] == 'DEVELOPMENT') { $errMsg = $arrError[1]; $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif\" />" . $errMsg . "<img style=\"display:none\" src=\"" . $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } else { $ret = $relpath . "includes/tng/styles/cannot_thumbnail.gif"; } return $ret; } } } $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null); $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName; $ret = KT_CanonizeRelPath($thumbnailURL); if (!$imageObj->hasError()) { //$ret .= '?' . md5(filectime($ret)); } } else { $thumbnailURL = $this->folder . KT_DynamicData($this->renameRule, null); $thumbnailURL = dirname($thumbnailURL) . "/thumbnails/" . $thumbnailName; $ret = KT_CanonizeRelPath($thumbnailURL); } } else { $ret = $relpath . "includes/tng/styles/img_not_found.gif"; } } return $ret; }