public function getScripts()
 {
     if (defined('HTTP_CATALOG')) {
         return $this->scripts;
     }
     $oc_root = dirname(DIR_APPLICATION);
     $cache = NULL;
     $cachefile = NULL;
     $filename = NULL;
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     //load NitroCache
     require_once $oc_root . DS . 'system' . DS . 'nitro' . DS . 'config.php';
     require_once $oc_root . DS . 'system' . DS . 'nitro' . DS . 'core' . DS . 'core.php';
     $nitroSettings = getNitroPersistence();
     if (empty($nitroSettings['Nitro']['Enabled']) || $nitroSettings['Nitro']['Enabled'] != 'yes' || empty($nitroSettings['Nitro']['Mini']['Enabled']) || empty($nitroSettings['Nitro']['Mini']['JS']) || $nitroSettings['Nitro']['Mini']['Enabled'] != 'yes' || $nitroSettings['Nitro']['Mini']['JS'] != 'yes' || function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl()) {
         return $this->scripts;
     }
     if (!file_exists($oc_root . DS . 'assets')) {
         mkdir($oc_root . DS . 'assets');
     }
     if (!file_exists($oc_root . DS . 'assets' . DS . 'script')) {
         mkdir($oc_root . DS . 'assets' . DS . 'script');
     }
     $jsExclude = array();
     if (!empty($nitroSettings['Nitro']['Mini']['JSExclude'])) {
         $jsExclude = explode("\n", $nitroSettings['Nitro']['Mini']['JSExclude']);
         foreach ($jsExclude as $k => $scriptname) {
             $jsExclude[$k] = trim($scriptname, "\n\r ");
         }
     }
     //extract local fylesystem path
     foreach ($this->scripts as $hash => $script) {
         $url_info = parse_url($script);
         if (!empty($url_info['path'])) {
             $f = trim($url_info['path'], '/');
             if (file_exists($oc_root . DS . $f)) {
                 $this->scripts[$hash] = $f;
             } else {
                 if (empty($nitroSettings['Nitro']['Mini']['JSExclude'])) {
                     $nitroSettings['Nitro']['Mini']['JSExclude'] = '';
                 }
                 $jsExclude[] = basename($style['href']);
             }
         } else {
             if (empty($nitroSettings['Nitro']['Mini']['JSExclude'])) {
                 $nitroSettings['Nitro']['Mini']['JSExclude'] = '';
             }
             $jsExclude[] = basename($style['href']);
         }
     }
     if (!empty($nitroSettings['Nitro']['Mini']['JSCombine']) && $nitroSettings['Nitro']['Mini']['JSCombine'] == 'yes') {
         $cachefile = $oc_root . DS . 'assets' . DS . 'script' . DS . getSSLCachePrefix() . 'scripts-combined.cache';
         if (!file_exists($cachefile)) {
             touch($cachefile);
             file_put_contents($cachefile, json_encode(array()));
         }
         $cache = json_decode(file_get_contents($cachefile), true);
         $comboHash = '';
         $excludedScripts = array();
         $includedScripts = 0;
         foreach ($this->scripts as $hash => $script) {
             if (!in_array(trim(basename($script), "\r\n"), $jsExclude)) {
                 $comboHash .= $hash;
                 $includedScripts++;
             } else {
                 $excludedScripts[$hash] = $script;
             }
         }
         $comboHash = md5($comboHash);
         $target = '/assets/script/' . getSSLCachePrefix() . 'nitro-combined-' . $comboHash . '.js';
         $targetAbsolutePath = $oc_root . DS . trim(str_replace('/', DS, $target), DS);
         $recache = false;
         foreach ($this->scripts as $hash => $script) {
             if (!in_array(trim(basename($script), "\r\n"), $jsExclude)) {
                 $filename = $oc_root . DS . trim(str_replace('/', DS, $script), DS);
                 if (!empty($cache[$comboHash][$filename])) {
                     if ($cache[$comboHash][$filename] != filemtime($filename)) {
                         $recache = true;
                         break;
                     }
                 } else {
                     $recache = true;
                     break;
                 }
             }
         }
         $minifiedCombined = '';
         if ($recache || !file_exists($targetAbsolutePath)) {
             include_once $oc_root . DS . 'system' . DS . 'nitro' . DS . 'lib' . DS . 'minifier' . DS . 'JSMin.php';
             $counter = 0;
             foreach ($this->scripts as $hash => $script) {
                 if (!in_array(trim(basename($script), "\r\n"), $jsExclude)) {
                     $filename = $oc_root . DS . trim(str_replace('/', DS, $script), DS);
                     $scriptSrc = file_get_contents($filename);
                     //minify
                     $scriptSrc = JSMin::minify($scriptSrc);
                     if (substr($scriptSrc, -1) == ')') {
                         $scriptSrc .= ';';
                     }
                     $minifiedCombined .= ($counter > 0 ? PHP_EOL : '') . $scriptSrc;
                     unset($scriptSrc);
                     $cache[$comboHash][$filename] = filemtime($filename);
                     $counter++;
                 }
             }
             file_put_contents($targetAbsolutePath, $minifiedCombined);
         }
         file_put_contents($cachefile, json_encode($cache));
         if ($includedScripts > 0) {
             return array_merge($excludedScripts, array(md5($target) => trim($target, '/')));
         } else {
             return $excludedScripts;
         }
     } else {
         $cachefile = $oc_root . DS . 'assets' . DS . 'script' . DS . getSSLCachePrefix() . 'scripts.cache';
         if (!file_exists($cachefile)) {
             touch($cachefile);
             file_put_contents($cachefile, json_encode(array()));
         }
         $cache = json_decode(file_get_contents($cachefile), true);
         include_once $oc_root . DS . 'system' . DS . 'nitro' . DS . 'lib' . DS . 'minifier' . DS . 'JSMin.php';
         foreach ($this->scripts as $hash => $script) {
             $recache = false;
             if (!in_array(trim(basename($script), "\r\n"), $jsExclude)) {
                 $filename = $oc_root . DS . trim(str_replace('/', DS, $script), DS);
                 $basefilename = basename($script, '.js');
                 $target = '/assets/script/' . getSSLCachePrefix() . 'nitro-mini-' . $basefilename . '.js';
                 $targetAbsolutePath = $oc_root . DS . trim(str_replace('/', DS, $target), DS);
                 if (!empty($cache[$filename])) {
                     if ($cache[$filename] != filemtime($filename)) {
                         $recache = true;
                     }
                 } else {
                     $recache = true;
                 }
                 if ($recache || !file_exists($targetAbsolutePath)) {
                     touch($targetAbsolutePath);
                     $scriptSrc = file_get_contents($filename);
                     //minify
                     $scriptSrc = JSMin::minify($scriptSrc);
                     file_put_contents($targetAbsolutePath, $scriptSrc);
                     $cache[$filename] = filemtime($filename);
                 }
                 $this->scripts[$hash] = trim($target, '/');
             }
         }
         file_put_contents($cachefile, json_encode($cache));
         return $this->scripts;
     }
 }
 public function resize($filename, $width, $height, $type = "")
 {
     if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
         return;
     }
     $info = pathinfo($filename);
     $extension = $info['extension'];
     $old_image = $filename;
     $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension;
     if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) {
         $path = '';
         $directories = explode('/', dirname(str_replace('../', '', $new_image)));
         foreach ($directories as $directory) {
             $path = $path . '/' . $directory;
             if (!file_exists(DIR_IMAGE . $path)) {
                 @mkdir(DIR_IMAGE . $path, 0777);
             }
         }
         list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
         require_once DIR_SYSTEM . 'nitro/config.php';
         require_once DIR_SYSTEM . 'nitro/core/core.php';
         $nitroPersistence = getNitroPersistence();
         if (!empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['ImageCache']['OverrideCompression']) && $nitroPersistence['Nitro']['ImageCache']['OverrideCompression'] == 'yes') {
         }
         if ($width_orig != $width || $height_orig != $height) {
             $image = new Image(DIR_IMAGE . $old_image);
             $image->resize($width, $height, $type);
             $image->save(DIR_IMAGE . $new_image);
             if (!empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['PageCache']['Enabled']) && $nitroPersistence['Nitro']['PageCache']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['SmushIt']['OnDemand']) && $nitroPersistence['Nitro']['SmushIt']['OnDemand'] == 'yes' && !(function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl())) {
                 include_once dirname(DIR_SYSTEM) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'smushit.php';
                 try {
                     $file = new SmushIt(DIR_IMAGE . $new_image, SmushIt::LOCAL_ORIGIN);
                     // And finaly, replace original file by the compressed version
                     // Sometimes, Smush.it convert files. We don't want that to happen.
                     $src = pathinfo($file->source, PATHINFO_EXTENSION);
                     $dst = pathinfo($file->destination, PATHINFO_EXTENSION);
                     if ($src == $dst and copy($file->destination, DIR_IMAGE . $new_image)) {
                         // Success !
                         //echo 'Smushed File: '.$source.'<br>';
                     }
                 } catch (Exception $e) {
                     set_time_limit(30);
                 }
             }
         } else {
             copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
             if (!empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['PageCache']['Enabled']) && $nitroPersistence['Nitro']['PageCache']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['SmushIt']['OnDemand']) && $nitroPersistence['Nitro']['SmushIt']['OnDemand'] == 'yes' && !(function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl())) {
                 include_once dirname(DIR_SYSTEM) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'smushit.php';
                 try {
                     $file = new SmushIt(DIR_IMAGE . $new_image, SmushIt::LOCAL_ORIGIN);
                     // And finaly, replace original file by the compressed version
                     // Sometimes, Smush.it convert files. We don't want that to happen.
                     $src = pathinfo($file->source, PATHINFO_EXTENSION);
                     $dst = pathinfo($file->destination, PATHINFO_EXTENSION);
                     if ($src == $dst and copy($file->destination, DIR_IMAGE . $new_image)) {
                         // Success !
                         //echo 'Smushed File: '.$source.'<br>';
                     }
                 } catch (Exception $e) {
                     set_time_limit(30);
                 }
             }
         }
     }
     return $this->getImageUrl($new_image);
 }
Beispiel #3
0
function nitro_resolve_cdn($path, $real_url)
{
    if (!empty($real_url)) {
        $real_url = nitro_clean_path(rtrim($real_url, '/'), null, '/');
    }
    if (getNitroPersistence('CDNStandard.GenericURL')) {
        $real_url = nitro_clean_path(rtrim(getNitroPersistence('CDNStandard.GenericURL'), '/'), null, '/');
    } else {
        if (empty($real_url)) {
            $real_url = '';
        }
    }
    if (stripos($path, 'http') === 0 || stripos($path, '//') === 0) {
        return $path;
    }
    $path = ltrim($path, '/');
    if (areWeInIgnoredUrl() && getNitroPersistence('PageCache.Enabled')) {
        return $real_url . $path;
    }
    $type = nitro_get_file_type($path);
    $cdn_persistence = '';
    $cdn_http = '';
    $cdn_https = '';
    if (getNitroPersistence('CDNStandard.Enabled')) {
        $cdn_persistence = '3';
        switch ($type) {
            case 'image':
                if (getNitroPersistence('CDNStandard.ServeImages')) {
                    $cdn_http = getNitroPersistence('CDNStandard.ImagesHttpUrl');
                    $cdn_https = getNitroPersistence('CDNStandard.ImagesHttpsUrl');
                }
                break;
            case 'js':
                if (getNitroPersistence('CDNStandard.ServeJavaScript')) {
                    $cdn_http = getNitroPersistence('CDNStandard.JavaScriptHttpUrl');
                    $cdn_https = getNitroPersistence('CDNStandard.JavaScriptHttpsUrl');
                }
                break;
            case 'css':
                if (getNitroPersistence('CDNStandard.ServeCSS')) {
                    $cdn_http = getNitroPersistence('CDNStandard.CSSHttpUrl');
                    $cdn_https = getNitroPersistence('CDNStandard.CSSHttpsUrl');
                }
                break;
        }
    } elseif (getNitroPersistence('CDNAmazon.Enabled')) {
        $cdn_persistence = '1';
        switch ($type) {
            case 'image':
                if (getNitroPersistence('CDNAmazon.ServeImages')) {
                    $cdn_http = getNitroPersistence('CDNAmazon.ImageHttpUrl');
                    $cdn_https = getNitroPersistence('CDNAmazon.ImageHttpsUrl');
                }
                break;
            case 'js':
                if (getNitroPersistence('CDNAmazon.ServeJavaScript')) {
                    $cdn_http = getNitroPersistence('CDNAmazon.JavaScriptHttpUrl');
                    $cdn_https = getNitroPersistence('CDNAmazon.JavaScriptHttpsUrl');
                }
                break;
            case 'css':
                if (getNitroPersistence('CDNAmazon.ServeCSS')) {
                    $cdn_http = getNitroPersistence('CDNAmazon.CSSHttpUrl');
                    $cdn_https = getNitroPersistence('CDNAmazon.CSSHttpsUrl');
                }
                break;
        }
    } elseif (getNitroPersistence('CDNRackspace.Enabled')) {
        $cdn_persistence = '2';
        switch ($type) {
            case 'image':
                if (getNitroPersistence('CDNRackspace.ServeImages')) {
                    $cdn_http = getNitroPersistence('CDNRackspace.ImagesHttpUrl');
                    $cdn_https = getNitroPersistence('CDNRackspace.ImagesHttpsUrl');
                }
                break;
            case 'js':
                if (getNitroPersistence('CDNRackspace.ServeJavaScript')) {
                    $cdn_http = getNitroPersistence('CDNRackspace.JavaScriptHttpUrl');
                    $cdn_https = getNitroPersistence('CDNRackspace.JavaScriptHttpsUrl');
                }
                break;
            case 'css':
                if (getNitroPersistence('CDNRackspace.ServeCSS')) {
                    $cdn_http = getNitroPersistence('CDNRackspace.CSSHttpUrl');
                    $cdn_https = getNitroPersistence('CDNRackspace.CSSHttpsUrl');
                }
                break;
        }
    }
    if (getSSLCachePrefix() == '-1' && !empty($cdn_https)) {
        // We have SSL
        $cdn_url = $cdn_https;
    } else {
        $cdn_url = $cdn_http;
    }
    if (empty($cdn_persistence) || empty($cdn_url)) {
        return $real_url . $path;
    }
    $cdn_url = nitro_clean_path(rtrim($cdn_url, '/'), null, '/');
    global $db;
    $exists = $db->query("SELECT * FROM " . DB_PREFIX . "nitro_cdn_files WHERE file='" . $db->escape($path) . "' AND uploaded=1 AND cdn=" . $cdn_persistence . " LIMIT 0,1");
    if ($exists->num_rows) {
        return $cdn_url . $path;
    } else {
        return $real_url . $path;
    }
}
Beispiel #4
0
function isNitroEnabled()
{
    return getNitroPersistence('Enabled') && !areWeInIgnoredUrl() && !inMaintenanceMode();
}
Beispiel #5
0
function passesPageCacheValidation()
{
    if (NITRO_IGNORE_AJAX_REQUESTS && isAJAXRequest()) {
        return false;
    }
    if (NITRO_IGNORE_POST_REQUESTS && isPOSTRequest()) {
        return false;
    }
    if (isItemsInCart() || isCustomerLogged() || isWishlistAdded() || isAdminLogged() && NITRO_DISABLE_FOR_ADMIN || isYMM()) {
        return false;
    }
    $ignoredRoutes = getIgnoredRoutes();
    global $registry;
    if (!empty($registry)) {
        $current_route = !empty($registry->get('request')->get['route']) ? $registry->get('request')->get['route'] : NULL;
    }
    if (!empty($_GET['route']) && in_array($_GET['route'], $ignoredRoutes) || !empty($current_route) && in_array($current_route, $ignoredRoutes)) {
        return false;
    }
    if (areWeInIgnoredUrl()) {
        return false;
    }
    return true;
}
 protected function index()
 {
     $this->data['title'] = $this->document->getTitle();
     if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
         $server = $this->config->get('config_ssl');
     } else {
         $server = $this->config->get('config_url');
     }
     $this->data['base'] = $server;
     $this->data['description'] = $this->document->getDescription();
     $this->data['keywords'] = $this->document->getKeywords();
     $this->data['links'] = $this->document->getLinks();
     $this->data['styles'] = $this->document->getStyles();
     require_once DIR_SYSTEM . 'nitro/config.php';
     require_once DIR_SYSTEM . 'nitro/core/core.php';
     $nitroPersistence = getNitroPersistence();
     $nitro_has_ftp_to_cdn = !empty($nitroPersistence['Nitro']['CDNStandardFTP']['Enabled']) && $nitroPersistence['Nitro']['CDNStandardFTP']['Enabled'] == 'yes';
     if ($nitro_has_ftp_to_cdn) {
         $nitro_ftp_persistence = getFTPPersistence();
     } else {
         $nitro_ftp_persistence = array();
     }
     $nitro_amazon_persistence = getAmazonPersistence();
     $nitro_rackspace_persistence = getRackspacePersistence();
     $nitro_has_css_minification = !empty($nitroPersistence['Nitro']['Mini']['Enabled']) && $nitroPersistence['Nitro']['Mini']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['Mini']['CSS']) && $nitroPersistence['Nitro']['Mini']['CSS'] == 'yes';
     $nitro_amazon_condition = !empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNAmazon']['Enabled']) && $nitroPersistence['Nitro']['CDNAmazon']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNAmazon']['ServeCSS']) && $nitroPersistence['Nitro']['CDNAmazon']['ServeCSS'] == 'yes';
     $nitro_rackspace_condition = !empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNRackspace']['Enabled']) && $nitroPersistence['Nitro']['CDNRackspace']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNRackspace']['ServeCSS']) && $nitroPersistence['Nitro']['CDNRackspace']['ServeCSS'] == 'yes';
     $nitro_css_minify_condition = $nitro_has_css_minification && $nitro_has_ftp_to_cdn || !$nitro_has_css_minification;
     if (($nitro_css_minify_condition || $nitro_amazon_condition || $nitro_rackspace_condition) && !(function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl())) {
         foreach ($this->data['styles'] as $nitro_index => $nitro_value) {
             $nitro_relative = stripos($nitro_value['href'], 'http://') === 0 ? false : (stripos($nitro_value['href'], 'https://') === 0 ? false : true);
             if ($nitro_css_minify_condition && $nitro_relative && !empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNStandard']['Enabled']) && $nitroPersistence['Nitro']['CDNStandard']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNStandard']['ServeCSS']) && $nitroPersistence['Nitro']['CDNStandard']['ServeCSS'] == 'yes') {
                 $nitro_has_ftp_persistence = false;
                 if ($nitro_has_ftp_to_cdn) {
                     $nitro_check_ftp_value = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                     $nitro_has_ftp_persistence = in_array($nitro_check_ftp_value, $nitro_ftp_persistence);
                 } else {
                     $nitro_has_ftp_persistence = true;
                 }
                 if ($nitro_has_ftp_persistence && !empty($nitroPersistence['Nitro']['CDNStandard']['CSSHttpsUrl']) && isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
                     $nitro_href = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                     $nitro_url = substr($nitroPersistence['Nitro']['CDNStandard']['CSSHttpsUrl'], strlen($nitroPersistence['Nitro']['CDNStandard']['CSSHttpsUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNStandard']['CSSHttpsUrl'] : $nitroPersistence['Nitro']['CDNStandard']['CSSHttpsUrl'] . '/';
                     $this->data['styles'][$nitro_index]['href'] = $nitro_url . $nitro_href;
                 } else {
                     if ($nitro_has_ftp_persistence && !empty($nitroPersistence['Nitro']['CDNStandard']['CSSHttpUrl'])) {
                         $nitro_href = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                         $nitro_url = substr($nitroPersistence['Nitro']['CDNStandard']['CSSHttpUrl'], strlen($nitroPersistence['Nitro']['CDNStandard']['CSSHttpUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNStandard']['CSSHttpUrl'] : $nitroPersistence['Nitro']['CDNStandard']['CSSHttpUrl'] . '/';
                         $this->data['styles'][$nitro_index]['href'] = $nitro_url . $nitro_href;
                     }
                 }
             } else {
                 if ($nitro_amazon_condition && $nitro_relative) {
                     $nitro_check_amazon_value = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                     $nitro_has_amazon_persistence = in_array($nitro_check_amazon_value, $nitro_amazon_persistence);
                     if ($nitro_has_amazon_persistence && !empty($nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl']) && isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
                         $nitro_href = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                         $nitro_url = substr($nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl'], strlen($nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl'] : $nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl'] . '/';
                         $this->data['styles'][$nitro_index]['href'] = $nitro_url . $nitro_href;
                     } else {
                         if ($nitro_has_amazon_persistence && !empty($nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'])) {
                             $nitro_href = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                             $nitro_url = substr($nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'], strlen($nitroPersistence['Nitro']['CDNAmazon']['HttpUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'] : $nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'] . '/';
                             $this->data['styles'][$nitro_index]['href'] = $nitro_url . $nitro_href;
                         }
                     }
                 } else {
                     if ($nitro_rackspace_condition && $nitro_relative) {
                         $nitro_check_rackspace_value = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                         $nitro_has_rackspace_persistence = in_array($nitro_check_rackspace_value, $nitro_rackspace_persistence);
                         if ($nitro_has_rackspace_persistence && !empty($nitroPersistence['Nitro']['CDNRackspace']['CSSHttpsUrl']) && isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
                             $nitro_href = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                             $nitro_url = substr($nitroPersistence['Nitro']['CDNRackspace']['CSSHttpsUrl'], strlen($nitroPersistence['Nitro']['CDNRackspace']['CSSHttpsUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNRackspace']['CSSHttpsUrl'] : $nitroPersistence['Nitro']['CDNRackspace']['CSSHttpsUrl'] . '/';
                             $this->data['styles'][$nitro_index]['href'] = $nitro_url . $nitro_href;
                         } else {
                             if ($nitro_has_rackspace_persistence && !empty($nitroPersistence['Nitro']['CDNRackspace']['CSSHttpUrl'])) {
                                 $nitro_href = substr($nitro_value['href'], 0, 1) == '/' ? substr($nitro_value['href'], 1) : $nitro_value['href'];
                                 $nitro_url = substr($nitroPersistence['Nitro']['CDNRackspace']['CSSHttpUrl'], strlen($nitroPersistence['Nitro']['CDNRackspace']['CSSHttpUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNRackspace']['CSSHttpUrl'] : $nitroPersistence['Nitro']['CDNRackspace']['CSSHttpUrl'] . '/';
                                 $this->data['styles'][$nitro_index]['href'] = $nitro_url . $nitro_href;
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->data['scripts'] = $this->document->getScripts();
     $nitro_has_js_minification = !empty($nitroPersistence['Nitro']['Mini']['Enabled']) && $nitroPersistence['Nitro']['Mini']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['Mini']['JS']) && $nitroPersistence['Nitro']['Mini']['JS'] == 'yes';
     $nitro_js_minify_condition = $nitro_has_js_minification && $nitro_has_ftp_to_cdn || !$nitro_has_js_minification;
     $nitro_rackspace_condition = !empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNRackspace']['Enabled']) && $nitroPersistence['Nitro']['CDNRackspace']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNRackspace']['ServeJavaScript']) && $nitroPersistence['Nitro']['CDNRackspace']['ServeJavaScript'] == 'yes';
     if (($nitro_js_minify_condition || $nitro_amazon_condition || $nitro_rackspace_condition) && !(function_exists('areWeInIgnoredUrl') && areWeInIgnoredUrl())) {
         foreach ($this->data['scripts'] as $nitro_index => $nitro_value) {
             $nitro_relative = stripos($nitro_value, 'http://') === 0 ? false : (stripos($nitro_value, 'https://') === 0 ? false : true);
             if ($nitro_js_minify_condition && $nitro_relative && !empty($nitroPersistence['Nitro']['Enabled']) && $nitroPersistence['Nitro']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNStandard']['Enabled']) && $nitroPersistence['Nitro']['CDNStandard']['Enabled'] == 'yes' && !empty($nitroPersistence['Nitro']['CDNStandard']['ServeJavaScript']) && $nitroPersistence['Nitro']['CDNStandard']['ServeJavaScript'] == 'yes') {
                 $nitro_has_ftp_persistence = false;
                 if ($nitro_has_ftp_to_cdn) {
                     $nitro_check_ftp_value = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                     $nitro_has_ftp_persistence = in_array($nitro_check_ftp_value, $nitro_ftp_persistence);
                 } else {
                     $nitro_has_ftp_persistence = true;
                 }
                 if ($nitro_has_ftp_persistence && !empty($nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpsUrl']) && isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
                     $nitro_href = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                     $nitro_url = substr($nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpsUrl'], strlen($nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpsUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpsUrl'] : $nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpsUrl'] . '/';
                     $this->data['scripts'][$nitro_index] = $nitro_url . $nitro_href;
                 } else {
                     if ($nitro_has_ftp_persistence && !empty($nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpUrl'])) {
                         $nitro_href = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                         $nitro_url = substr($nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpUrl'], strlen($nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpUrl'] : $nitroPersistence['Nitro']['CDNStandard']['JavaScriptHttpUrl'] . '/';
                         $this->data['scripts'][$nitro_index] = $nitro_url . $nitro_href;
                     }
                 }
             } else {
                 if ($nitro_amazon_condition && $nitro_relative) {
                     $nitro_check_amazon_value = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                     $nitro_has_amazon_persistence = in_array($nitro_check_amazon_value, $nitro_amazon_persistence);
                     if ($nitro_has_amazon_persistence && !empty($nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl']) && isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
                         $nitro_href = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                         $nitro_url = substr($nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl'], strlen($nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl'] : $nitroPersistence['Nitro']['CDNAmazon']['HttpsUrl'] . '/';
                         $this->data['scripts'][$nitro_index] = $nitro_url . $nitro_href;
                     } else {
                         if ($nitro_has_amazon_persistence && !empty($nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'])) {
                             $nitro_href = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                             $nitro_url = substr($nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'], strlen($nitroPersistence['Nitro']['CDNAmazon']['HttpUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'] : $nitroPersistence['Nitro']['CDNAmazon']['HttpUrl'] . '/';
                             $this->data['scripts'][$nitro_index] = $nitro_url . $nitro_href;
                         }
                     }
                 } else {
                     if ($nitro_rackspace_condition && $nitro_relative) {
                         $nitro_check_rackspace_value = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                         $nitro_has_rackspace_persistence = in_array($nitro_check_rackspace_value, $nitro_rackspace_persistence);
                         if ($nitro_has_rackspace_persistence && !empty($nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpsUrl']) && isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) {
                             $nitro_href = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                             $nitro_url = substr($nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpsUrl'], strlen($nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpsUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpsUrl'] : $nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpsUrl'] . '/';
                             $this->data['scripts'][$nitro_index] = $nitro_url . $nitro_href;
                         } else {
                             if ($nitro_has_rackspace_persistence && !empty($nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpUrl'])) {
                                 $nitro_href = substr($nitro_value, 0, 1) == '/' ? substr($nitro_value, 1) : $nitro_value;
                                 $nitro_url = substr($nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpUrl'], strlen($nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpUrl']) - 1, 1) == '/' ? $nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpUrl'] : $nitroPersistence['Nitro']['CDNRackspace']['JavaScriptHttpUrl'] . '/';
                                 $this->data['scripts'][$nitro_index] = $nitro_url . $nitro_href;
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->data['lang'] = $this->language->get('code');
     $this->data['direction'] = $this->language->get('direction');
     $this->data['google_analytics'] = html_entity_decode($this->config->get('config_google_analytics'), ENT_QUOTES, 'UTF-8');
     $this->data['name'] = $this->config->get('config_name');
     if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon'))) {
         $this->data['icon'] = $server . 'image/' . $this->config->get('config_icon');
     } else {
         $this->data['icon'] = '';
     }
     if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) {
         $this->data['logo'] = $server . 'image/' . $this->config->get('config_logo');
     } else {
         $this->data['logo'] = '';
     }
     $this->language->load('common/header');
     $this->data['og_url'] = (isset($this->request->server['HTTPS']) ? HTTPS_SERVER : HTTP_SERVER) . substr($this->request->server['REQUEST_URI'], 1, strlen($this->request->server['REQUEST_URI']) - 1);
     $this->data['og_image'] = $this->document->getOgImage();
     $this->data['text_home'] = $this->language->get('text_home');
     $this->data['text_wishlist'] = sprintf($this->language->get('text_wishlist'), isset($this->session->data['wishlist']) ? count($this->session->data['wishlist']) : 0);
     $this->data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
     $this->data['text_search'] = $this->language->get('text_search');
     $this->data['text_welcome'] = sprintf($this->language->get('text_welcome'), $this->url->link('account/login', '', 'SSL'), $this->url->link('account/register', '', 'SSL'));
     $this->data['text_logged'] = sprintf($this->language->get('text_logged'), $this->url->link('account/account', '', 'SSL'), $this->customer->getFirstName(), $this->url->link('account/logout', '', 'SSL'));
     $this->data['text_account'] = $this->language->get('text_account');
     $this->data['text_checkout'] = $this->language->get('text_checkout');
     $this->data['text_page'] = $this->language->get('text_page');
     $this->data['home'] = $this->url->link('common/home');
     $this->data['wishlist'] = $this->url->link('account/wishlist', '', 'SSL');
     $this->data['logged'] = $this->customer->isLogged();
     $this->data['account'] = $this->url->link('account/account', '', 'SSL');
     $this->data['shopping_cart'] = $this->url->link('checkout/cart');
     $this->data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
     // Daniel's robot detector
     $status = true;
     if (isset($this->request->server['HTTP_USER_AGENT'])) {
         $robots = explode("\n", trim($this->config->get('config_robots')));
         foreach ($robots as $robot) {
             if ($robot && strpos($this->request->server['HTTP_USER_AGENT'], trim($robot)) !== false) {
                 $status = false;
                 break;
             }
         }
     }
     // A dirty hack to try to set a cookie for the multi-store feature
     $this->load->model('setting/store');
     $this->data['stores'] = array();
     if ($this->config->get('config_shared') && $status) {
         $this->data['stores'][] = $server . 'catalog/view/javascript/crossdomain.php?session_id=' . $this->session->getId();
         $stores = $this->model_setting_store->getStores();
         foreach ($stores as $store) {
             $this->data['stores'][] = $store['url'] . 'catalog/view/javascript/crossdomain.php?session_id=' . $this->session->getId();
         }
     }
     // Search
     if (isset($this->request->get['search'])) {
         $this->data['search'] = $this->request->get['search'];
     } else {
         $this->data['search'] = '';
     }
     // Menu
     if (isset($this->request->get['path'])) {
         $parts = explode('_', (string) $this->request->get['path']);
     } else {
         $parts = array();
     }
     $this->load->model('catalog/category');
     $this->load->model('catalog/product');
     $this->data['categories'] = array();
     $categories = $this->model_catalog_category->getCategories(0);
     foreach ($categories as $category) {
         if ($category['top']) {
             // Level 2
             $children_data = array();
             $children = $this->model_catalog_category->getCategories($category['category_id']);
             foreach ($children as $child) {
                 //Будем вычислять кол-во товаров в категориях только если это кол-во надо показывать
                 if ($this->config->get('config_product_count')) {
                     $data = array('filter_category_id' => $child['category_id'], 'filter_sub_category' => true);
                     //Optmization
                     //$product_total = $this->model_catalog_product->getTotalProducts($data);
                     $product_total = 0;
                 }
                 $children_data[] = array('name' => $child['name'], 'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']));
             }
             // Level 1
             $this->data['categories'][] = array('name' => $category['name'], 'children' => $children_data, 'active' => in_array($category['category_id'], $parts), 'column' => $category['column'] ? $category['column'] : 1, 'href' => $this->url->link('product/category', 'path=' . $category['category_id']));
         }
     }
     $this->children = array('module/language', 'module/currency', 'module/cart');
     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/header.tpl')) {
         $this->template = $this->config->get('config_template') . '/template/common/header.tpl';
     } else {
         $this->template = 'default/template/common/header.tpl';
     }
     $this->render();
 }
Beispiel #7
0
function passesPageCacheValidation()
{
    if (NITRO_IGNORE_AJAX_REQUESTS == TRUE && isAJAXRequest()) {
        return false;
    }
    if (NITRO_IGNORE_POST_REQUESTS == TRUE && isPOSTRequest()) {
        return false;
    }
    if (isItemsInCart() || isCustomerLogged() || isWishlistAdded()) {
        return false;
    }
    $ignoredRoutes = getIgnoredRoutes();
    if (!empty($_GET['route']) && in_array($_GET['route'], $ignoredRoutes)) {
        return false;
    }
    if (areWeInIgnoredUrl()) {
        return false;
    }
    return true;
}