Ejemplo n.º 1
0
 function get_active_layout()
 {
     //return T3Parameter::_getParam('layouts');
     $params = T3Common::get_template_params();
     $device = T3Common::mobile_device_detect();
     if (!$device) {
         //desktop
         //get from override profile
         $active_profile = T3Common::get_active_profile();
         $default_profile = T3Common::get_default_profile();
         if ($active_profile != $default_profile && $active_profile != 'default') {
             $path = 'etc' . DS . 'profiles' . DS . $active_profile . '.ini';
             $file = T3Path::path(T3_TEMPLATE_LOCAL) . DS . $path;
             if (!is_file($file)) {
                 $file = T3Path::path(T3_TEMPLATE_CORE) . DS . $path;
             }
             if (is_file($file)) {
                 $content = file_get_contents($file);
                 $params = new JParameter($content);
                 $layout = $params->get('desktop_layout', '');
                 if (T3Common::layout_exists($layout)) {
                     return $layout;
                 }
             }
         }
         //cannot get from override profile for this page, get from usersetting
         $layout = T3Parameter::get('layouts', '');
         if (T3Common::layout_exists($layout)) {
             return $layout;
         }
         //get default
         $layout = $params->get('desktop_layout', '');
         if (!T3Common::layout_exists($layout)) {
             $layout = 'default';
         }
     } else {
         $layout = $params->get($device . '_layout', '');
         if (!$layout) {
             $layout = $params->get('handheld_layout', '');
         }
         if ($layout == -1) {
             //disable => use layout from desktop
             $device = '';
             $layout = $params->get('desktop_layout', '');
             if (!T3Common::layout_exists($layout)) {
                 $layout = 'default';
             }
         } else {
             if ($layout == 1) {
                 //default => use layout from t3 engine
                 $layout = $device;
                 if (!T3Common::layout_exists($layout)) {
                     $layout = 'handheld';
                 }
             } else {
                 if (!T3Common::layout_exists($layout)) {
                     $layout = 'handheld';
                 }
             }
         }
     }
     return $layout;
 }
Ejemplo n.º 2
0
 /**
  * Use a shorter and readable filename. use version to tell the browser that the file content is change.
  * Read content from array of files $files and write to one cached file if need update $needupdate or cached file not exists
  *
  * @param array  $files       List of file
  * @param string $ext         Extension
  * @param bool   $needupdate  Indicate need to update file or not
  *
  * @return The new file url
  */
 function store_file2($files, $ext, $needupdate)
 {
     $cache_path = T3Parameter::get('optimize_folder', 't3-assets');
     $optimize_level = T3Parameter::get('optimize_' . $ext, 1);
     $path = T3Path::path($cache_path);
     if (!is_dir($path)) {
         if (!@JFolder::create($path)) {
             return false;
             //cannot create cache folder for js/css optimize
         }
     }
     if (!is_file($path . DS . 'index.html')) {
         $indexcontent = '<html><body></body></html>';
         if (!@JFile::write($path . DS . 'index.html', $indexcontent)) {
             return false;
             //cannot create blank index.html to prevent list files
         }
     }
     static $filemap = array();
     //data.php contain filename maps
     $datafile = $path . '/data.php';
     if (is_file($datafile)) {
         include_once $datafile;
     }
     //get a salt
     if (!isset($filemap['salt']) || !$filemap['salt']) {
         $filemap['salt'] = rand();
     }
     //build destination file
     $file = md5($filemap['salt'] . serialize($files));
     $filename = $ext . '_' . substr($file, 0, 5) . ".{$ext}";
     $destfile = $path . DS . $filename;
     //re-populate $needupdate in case $destfile exists & keep original (not minify)
     if ($optimize_level == 1 && is_file($destfile)) {
         foreach ($files as $f) {
             if (@filemtime($f[0]) > @filemtime($destfile)) {
                 $needupdate = true;
                 break;
             }
         }
     }
     //check if need update
     if (!$needupdate && is_file($destfile)) {
         $fileversion = isset($filemap[$ext]) && isset($filemap[$ext][$file]) ? $filemap[$ext][$file] : 1;
         $fileversion = $fileversion == 1 ? "" : "?v=" . $filemap[$ext][$file];
         if ($optimize_level < 3) {
             return T3Path::url($cache_path) . '/' . $filename . $fileversion;
         } else {
             //$url = JRoute::_("index.php?jat3action=gzip&jat3type=$ext&jat3file=".urlencode ($cache_path.'/'.$filename).$fileversion);
             $url = "jat3action=gzip&amp;jat3type={$ext}&amp;jat3file=" . urlencode($cache_path . '/' . $filename) . $fileversion;
             // Fix when enable languagefilter plugin
             $url = self::buildURL($url);
             return $url;
         }
     }
     //get files content
     $content = '';
     foreach ($files as $f) {
         $media = count($f) > 2 ? trim($f[2]['media']) : "";
         if ($ext == 'css') {
             if ($optimize_level == 1) {
                 $content .= "@import url(\"{$f[1]}\") {$media};\n";
             } elseif (!empty($media)) {
                 $content .= "/* " . substr(basename($f[0]), 33) . " */\n" . "@media " . $f[2]['media'] . " {\n" . @JFile::read($f[0]) . "\n}\n\n";
             } else {
                 $content .= "/* " . substr(basename($f[0]), 33) . " */\n" . @JFile::read($f[0]) . "\n\n";
             }
         } else {
             $content .= "/* " . substr(basename($f[0]), 33) . " */\n" . @JFile::read($f[0]) . "\n\n";
         }
     }
     if (!isset($filemap[$ext])) {
         $filemap[$ext] = array();
     }
     if (!isset($filemap[$ext][$file])) {
         $filemap[$ext][$file] = 0;
         //store file version
     }
     //update file version
     $filemap[$ext][$file] = $filemap[$ext][$file] + 1;
     $fileversion = $filemap[$ext][$file] == 1 ? "" : "?v=" . $filemap[$ext][$file];
     //update datafile
     $filemapdata = '<?php $filemap = ' . var_export($filemap, true) . '; ?>';
     @JFile::write($datafile, $filemapdata);
     //create new file
     if (!@JFile::write($destfile, $content)) {
         return false;
         // Cannot create file
     }
     //return result
     //check if need compress
     if ($optimize_level == 3) {
         //compress
         //$url = JRoute::_("index.php?jat3action=gzip&type=$ext&file=".urlencode ($cache_path.'/'.$filename).$fileversion);
         $url = "jat3action=gzip&amp;jat3type={$ext}&amp;jat3file=" . urlencode($cache_path . '/' . $filename) . $fileversion;
         // Fix when enable languagefilter plugin
         $url = self::buildURL($url);
         return $url;
     }
     return T3Path::url($cache_path) . '/' . $filename . $fileversion;
 }