function NextendSliderCache($slider) { nextendimportsmartslider2('nextend.smartslider.check'); nextendimport('nextend.css.css'); nextendimport('nextend.javascript.javascript'); nextendimport('nextend.fonts.google'); $this->slider = $slider; $sliderid = $slider->_sliderid; $recache = false; $cached = json_decode(NextendSmartSliderStorage::get('slidercache' . $sliderid), true); if (nextendIsWordpress()) { $time = current_time('timestamp'); } else { $time = time(); } nextendimportsmartslider2('nextend.smartslider.admin.models.slides'); $slidesModel = new NextendSmartsliderAdminModelSlides(null); $slides = $slidesModel->getSlides($sliderid, ''); $slideexpire = null; foreach ($slides as $s) { $publish_up = strtotime($s['publish_up']); if ($publish_up && $publish_up > $time && ($slideexpire == null || $publish_up < $slideexpire)) { $slideexpire = $publish_up; } $publish_down = strtotime($s['publish_down']); if ($publish_down && $publish_down > $time && ($slideexpire == null || $publish_down < $slideexpire)) { $slideexpire = $publish_down; } } if (is_array($cached)) { if (NextendSmartSliderStorage::get('sliderchanged' . $sliderid) == 1) { $recache = true; } else { if (isset($cached['time']) && isset($cached['expire']) && $cached['time'] < time() - $cached['expire'] * 60 * 60) { $recache = true; } else { if (isset($cached['slideexpire']) && $cached['slideexpire'] < $time) { $recache = true; } } } } else { $recache = true; } if (!$recache) { $data = $cached['data']; if (isset($data['css'])) { if (!NextendFilesystem::fileexists(NextendFilesystem::absoluteURLToPath($data['css']))) { $recache = true; } } else { $recache = true; } if (!isset($data['libraries']) || !isset($data['libraries']['jquery']) || !isset($data['libraries']['jquery']['jsfiles']) || count($data['libraries']['jquery']['jsfiles']) == 0) { $recache = true; } } //$recache = true; if ($recache) { $data = $this->render(); $cached = array('time' => time(), 'data' => $data); if ($this->slider->_generatorParams->get('enabled', 0)) { $generatorcached = json_decode(NextendSmartSliderStorage::get('generator' . $sliderid), true); if (is_array($generatorcached)) { $cached['time'] = $generatorcached['time']; $cached['expire'] = $this->slider->_generatorParams->get('cachetime', '24'); } } if ($slideexpire) { $cached['slideexpire'] = $slideexpire; } NextendSmartSliderStorage::set('slidercache' . $sliderid, json_encode($cached)); NextendSmartSliderStorage::set('sliderchanged' . $sliderid, '0'); } $this->cssurl = $data['css']; if (nextendIsWordPress()) { add_action('nextend_css', array($this, 'addCSS')); } elseif (nextendIsMagento()) { Nextend_SmartSlider2_Model_Observer::$sliders[] = array($this, 'addCSS'); } else { $this->addCSS(); } $js = NextendJavascript::getInstance(); foreach ($data['js']['core'] as $j) { $js->addJsFile($j); } if (isset($data['libraries']) && count($data['libraries'])) { foreach ($data['libraries'] as $library => $jss) { $js->loadLibrary($library); if (!empty($jss['js'])) { $js->addLibraryJs($library, $jss['js']); } if (count($jss['jsfiles'])) { foreach ($jss['jsfiles'] as $j) { $js->addLibraryJsFile($library, $j); } } } } if (isset($data['fonts']) && count($data['fonts'])) { $google = NextendFontsGoogle::getInstance(); foreach ($data['fonts'] as $k => $v) { $style = explode(',', $v[0]); $subset = explode(',', $v[1]); for ($i = 0; $i < count($style); $i++) { $google->addFont($k, $style[$i], $subset[$i]); } } } $slider = $data['html']; if (nextendIsJoomla()) { if (version_compare(JVERSION, '1.6.0', 'ge')) { $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $article = new stdClass(); $article->text = $slider; $_p = array(); $dispatcher->trigger('onContentPrepare', array('com_smartslider2', &$article, &$_p, 0)); if (!empty($article->text)) { $slider = $article->text; } } } elseif (nextendIsWordPress()) { if (!function_exists('ss2_attr_shortcode')) { function ss2_attr_shortcode($matches) { return 'data-' . $matches[1] . '="' . str_replace('"', '"', do_shortcode(str_replace('"', '"', $matches[2]))) . '"'; } } $slider = preg_replace_callback("/data-(click|enter|leave)=\"(.*?)\"/", "ss2_attr_shortcode", $slider); $slider = do_shortcode($slider); } echo $slider; }
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 generateAjaxCSS($loadedCSS) { $css = ''; if (count($this->_cssFiles)) { $lesscache = $this->_lesscache; foreach ($this->_cssFiles as $k => $file) { if (!in_array($k, $loadedCSS)) { if (is_array($file)) { $lesscache->addContext($file[1], $file[2]); } else { $css .= preg_replace('#url\\([\'"]([^"\'\\)]+)[\'"]\\)#', 'url(' . NextendFilesystem::pathToAbsoluteURL(dirname($k)) . '/$1)', NextendFilesystem::readFile($k)); } } } if ($lesscache) { $filename = $lesscache->getCache(); if ($filename) { $lessfile = NextendFilesystem::absoluteURLToPath($lesscache->getCache()); $css .= preg_replace('#url\\([\'"]([^"\'\\)]+)[\'"]\\)#', 'url(' . NextendFilesystem::pathToAbsoluteURL(dirname($lessfile)) . '/$1)', NextendFilesystem::readFile($lessfile)); } } } $css .= $this->_css; return $css; }
function ss2_css_image_replace($ms) { global $zip; if (substr($ms[1], 0, 2) == '//') { $ms[1] = 'http:' . $ms[1]; } $path = NextendFilesystem::absoluteURLToPath($ms[1]); if (NextendFilesystem::fileexists($path)) { if (nextendIsJoomla()) { $rel = str_replace('plugins/', 'images/', NextendFilesystem::pathToRelativePath($path)); } else { if (nextendIsWordpress()) { $rel = str_replace(NEXTEND_SMART_SLIDER2 . 'plugins/', 'images/', $path); } } $zip->addFile(NextendFilesystem::readFile($path), $rel); return 'url(' . $rel . ')'; } }
function generateCSS() { if (class_exists('NextendFontsGoogle')) { $fonts = NextendFontsGoogle::getInstance(); $fonts->generateFonts(); } if (count($this->_cssFiles)) { foreach ($this->_cssFiles as $file) { if (is_array($file)) { // LESS $this->_lesscache->addContext($file[1], $file[2]); } else { if (substr($file, 0, 4) == 'http') { $this->serveCSSFile($file); } else { if ($this->_cacheenabled) { $this->_cache->addFile($file); } else { $url = NextendFilesystem::pathToAbsoluteURL($file); $this->serveCSSFile($url); } } } } } if ($this->_cacheenabled) { if ($this->_lesscache) { $this->_cache->addFile(NextendFilesystem::absoluteURLToPath($this->_lesscache->getCache())); } $this->serveCSSFile($this->_cache->getCache()); } else { if ($this->_lesscache) { $this->serveCSSFile($this->_lesscache->getCache()); } } $this->serveCSS(); }