function getCache() { if (count($this->_files) == 0 && $this->_text == '') { return false; } if ($this->_cacheTime == 'static' || $this->_cacheTime == 0) { $folder = $this->_path . 'static' . DIRECTORY_SEPARATOR; $currentcachetime = 0; } else { $time = time(); $currentcachetime = $time - $time % $this->_cacheTime; $folder = $this->_path . $this->_prename . $currentcachetime . DIRECTORY_SEPARATOR; } $this->createCacheSubFolder($folder, $currentcachetime); $hash = $this->createHash(); $cachefile = $folder . $hash . '.' . $this->_filetype; $cachefilegzip = $folder . $hash . '.php'; if (!NextendFilesystem::existsFile($cachefile)) { $cached = "/* " . date('l jS \\of F Y h:i:s A') . "*/\n\n"; for ($i = 0; $i < count($this->_files); $i++) { $cached .= $this->parseFile(NextendFilesystem::readFile($this->_files[$i]), $this->_files[$i], $i); } $cached .= $this->_text; NextendFilesystem::createFile($cachefile, $this->parseCached($cached)); if ($this->_gzip) { $php = '<?php ' . $this->getgzipHeader($currentcachetime) . 'if (extension_loaded("zlib") && (ini_get("output_handler") != "ob_gzhandler")) {' . 'ini_set("zlib.output_compression", 1);' . '}' . 'readfile("' . str_replace('\\', '/', $cachefile) . '");'; NextendFilesystem::createFile($cachefilegzip, $php); } } if ($this->_gzip) { return NextendFilesystem::pathToAbsoluteURL($cachefilegzip); } return NextendFilesystem::pathToAbsoluteURL($cachefile); }
function render($tpl) { $tplpath = $this->_path . 'tpl/' . $tpl . '.php'; if (NextendFilesystem::existsFile($tplpath)) { include $tplpath; } }
function getFontUrl() { $css = NextendCss::getInstance(); $url = 'https://fonts.googleapis.com/css?family='; $subset = ''; if (count($this->_fonts)) { foreach ($this->_fonts as $family => $font) { $style = explode(',', $font[0]); $style = array_filter(array_unique($style)); foreach ($style as $k => $s) { $file = NEXTENDLIBRARYASSETS . 'fonts/' . preg_replace("/[^a-z0-9]/", '', strtolower($family)) . '/' . $s . '/s.css'; if (NextendFilesystem::existsFile($file)) { unset($style[$k]); $css->addCssFile($file, null, true); } } if (count($style)) { $url .= urlencode($family) . ':' . implode(',', $style) . '|'; $subset .= $font[1] . ','; } } } if ($url == 'https://fonts.googleapis.com/css?family=') { return ''; } $url = substr($url, 0, -1); $subset = explode(',', $subset); $subset = array_filter(array_unique($subset)); $url .= '&subset=' . implode(',', $subset); return $url; }
function onNextendSliderGeneratorList(&$group, &$list, $showall = false) { if ($showall || smartsliderIsFull()) { $installed = NextendFilesystem::existsFile(JPATH_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_jshopping' . DIRECTORY_SEPARATOR . 'jshopping.php'); if ($showall || $installed) { $group[$this->_group] = 'JoomShopping'; if (!isset($list[$this->_group])) { $list[$this->_group] = array(); } $list[$this->_group][$this->_group . '_products'] = array(NextendText::_('Products'), $this->getPath() . 'products' . DIRECTORY_SEPARATOR, true, true, $installed ? true : 'http://extensions.joomla.org/extensions/e-commerce/shopping-cart/5378', 'product'); } } }
function colorizeImage($img, $targetColor, $baseColor) { $cachefile = $this->_folder . 'colorize' . md5($img) . $targetColor . $baseColor . '.' . $this->_filetype; if (!NextendFilesystem::existsFile($cachefile)) { $targetHexArr = NextendColor::hex82hex($targetColor); $targetColor = $targetHexArr[0]; $alpha = hexdec($targetHexArr[1]); $c1 = NextendColor::hex2hsl($baseColor); $c2 = NextendColor::hex2hsl($targetColor); $im = imagecreatefrompng($img); $width = imagesx($im); $height = imagesy($im); $this->createIm($width, $height); $rgb = NextendColor::rgb2array($targetColor); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $rgba = ImageColorAt($im, $x, $y); $rgb = array($rgba >> 16 & 0xff, $rgba >> 8 & 0xff, $rgba & 0xff); $hsl = NextendColor::rgb2hsl($rgb); $a[0] = $hsl[0] + ($c2[0] - $c1[0]); $a[1] = $hsl[1] * ($c2[1] / $c1[1]); if ($a[1] > 1) { $a[1] = 1; } $a[2] = exp(log($hsl[2]) * log($c2[2]) / log($c1[2])); if ($a[2] > 1) { $a[2] = 1; } $rgb = NextendColor::hsl2rgb($a); $A = 0xff - ($rgba >> 24) * 2 & 0xff; $A = (int) ($A * ($alpha / 0xff)); if ($A > 0xff) { $A = 0xff; } $A = (int) ((0xff - $A) / 2); imagesetpixel($this->_im, $x, $y, imagecolorallocatealpha($this->_im, $rgb[0], $rgb[1], $rgb[2], $A)); } } $this->saveIm($cachefile); imagedestroy($im); } return NextendFilesystem::pathToAbsoluteURL($cachefile); }
function resizeImage($imageurl, $width, $height, $mode = 'cover', $resizeremote = false) { $originalimageurl = $imageurl; if ($width > 0 && $height > 0 && function_exists('exif_imagetype') && function_exists('imagecreatefrompng')) { $extra = array(); if (substr($imageurl, 0, 2) == '//') { $imageurl = parse_url(NextendUri::getBaseuri(), PHP_URL_SCHEME) . ':' . $imageurl; } $imageurl = NextendUri::relativetoabsolute($imageurl); $imagepath = NextendFilesystem::absoluteURLToPath($imageurl); if ($imagepath == $imageurl) { if (!$resizeremote) { return $originalimageurl; } $imagepath = parse_url($imageurl, PHP_URL_PATH); } else { $extra[] = @filemtime($imagepath); $imageurl = $imagepath; } $extension = strtolower(pathinfo($imagepath, PATHINFO_EXTENSION)); $filetype = ''; if ($extension == 'png') { $filetype = 'png'; } else { if ($extension == 'jpg' || $extension == 'jpeg') { $filetype = 'jpg'; } } if ($filetype != '') { $hash = $this->createHashFromArray(array_merge(func_get_args(), $this->backgrouncolor, $extra)); $cachefile = $this->_folder . $hash . '.' . $filetype; if (!NextendFilesystem::existsFile($cachefile)) { $imagetype = @exif_imagetype($imageurl); if ($imagetype) { if ($imagetype == IMAGETYPE_PNG) { $filetype = 'png'; } else { if ($imagetype == IMAGETYPE_JPEG) { $filetype = 'jpg'; } else { $filetype = ''; } } if ($filetype) { $img = null; $rotated = null; if ($filetype == 'png') { $img = @imagecreatefrompng($imageurl); } else { if ($filetype == 'jpg') { $img = @imagecreatefromjpeg($imageurl); if (function_exists("exif_read_data")) { $exif = exif_read_data($imageurl); if ($exif && !empty($exif['Orientation'])) { switch ($exif['Orientation']) { case 3: $rotated = imagerotate($img, 180, 0); break; case 6: $rotated = imagerotate($img, -90, 0); break; case 8: $rotated = imagerotate($img, 90, 0); break; } } if ($rotated) { imagedestroy($img); $img = $rotated; } } } } if ($img) { $owidth = imagesx($img); $oheight = imagesy($img); if ($rotated || $owidth != $width || $oheight != $height) { $image = imagecreatetruecolor($width, $height); if ($filetype == 'png') { imagesavealpha($image, true); imagealphablending($image, false); $white = imagecolorallocatealpha($image, 255, 255, 255, 127); imagefilledrectangle($image, 0, 0, $width, $height, $white); } else { if ($filetype == 'jpg') { $bg = imagecolorallocate($image, $this->backgrouncolor[0], $this->backgrouncolor[1], $this->backgrouncolor[2]); imagefilledrectangle($image, 0, 0, $width, $height, $bg); } } $dst_x = 0; $dst_y = 0; $src_x = 0; $src_y = 0; $dst_w = $width; $dst_h = $height; $src_w = $owidth; $src_h = $oheight; $horizontalRatio = $width / $owidth; $verticalRatio = $height / $oheight; if ($mode == 'cover') { if ($horizontalRatio > $verticalRatio) { $new_h = $horizontalRatio * $oheight; $dst_y = ($height - $new_h) / 2; $dst_h = $new_h; } else { $new_w = $verticalRatio * $owidth; $dst_x = ($width - $new_w) / 2; $dst_w = $new_w; } } else { if ($mode == 'contain') { if ($horizontalRatio < $verticalRatio) { $new_h = $horizontalRatio * $oheight; $dst_y = ($height - $new_h) / 2; $dst_h = $new_h; } else { $new_w = $verticalRatio * $owidth; $dst_x = ($width - $new_w) / 2; $dst_w = $new_w; } } } imagecopyresampled($image, $img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); imagedestroy($img); if ($filetype == 'png') { imagepng($image, $cachefile); } else { if ($filetype == 'jpg') { imagejpeg($image, $cachefile, 100); } } imagedestroy($image); return NextendFilesystem::pathToAbsoluteURL($cachefile); } else { imagedestroy($img); } } } } } else { return NextendFilesystem::pathToAbsoluteURL($cachefile); } } } return $originalimageurl; }
function resizeImage($image, $w, $h) { $w = intval($w); $h = intval($h); $cachefile = $this->_folder . 'resize' . md5($image) . $w . '_' . $h . '.' . $this->_filetype; if (!NextendFilesystem::existsFile($cachefile)) { if ($image && $w >= 1 && $h >= 1) { if (strpos($image, 'http') === 0) { //url } else { if (!NextendFilesystem::existsFile($image)) { $image = NextendFilesystem::getBasePath() . $image; } } if (is_readable($image)) { $orig = null; switch (exif_imagetype($image)) { case IMAGETYPE_JPEG: $orig = imagecreatefromjpeg($image); break; case IMAGETYPE_PNG: $orig = imagecreatefrompng($image); break; } if ($orig) { $this->createIm($w, $h); $ow = imagesx($orig); $oh = imagesy($orig); $ratioX = $ow / $w; $ratioY = $oh / $h; if ($ratioX > $ratioY) { $ow = $ratioY * $w; } else { $oh = $ratioX * $h; } imagecopyresampled($this->_im, $orig, 0, 0, 0, 0, $w, $h, $ow, $oh); $this->saveIm($cachefile); imagedestroy($orig); return NextendFilesystem::pathToAbsoluteURL($cachefile); } } else { return $image; } } else { return $image; } } return NextendFilesystem::pathToAbsoluteURL($cachefile); }