Beispiel #1
0
 private static function processResources($resource)
 {
     static $enabled;
     if (!isset($enabled)) {
         $enabled = array('compress' => explode(',', plgSystemJBetolo::param('css_compress_resources')), 'datauri' => explode(',', plgSystemJBetolo::param('css_datauri')), 'datauri-max' => (int) plgSystemJBetolo::param('css_datauri_max', 0), 'datauri-files' => explode(',', plgSystemJBetolo::param('css_datauri_files')));
         $app = JFactory::getApplication()->getName();
         $allowedIn = plgSystemJBetolo::param('css_datauri_allow_in');
         if ($app != $allowedIn && $allowedIn != 'all') {
             $enabled['datauri'] = array();
         }
     }
     $types = array('font' => array('eot', 'ttf', 'svg', 'otf', 'woff'));
     $ext = jbetoloFileHelper::getExt($resource);
     $type = jbetoloHelper::getArrayKey($types, $ext);
     $processed = false;
     if (JBETOLO_IS_GZ && (in_array($ext, $enabled['compress']) || $ext == 'woff')) {
         $path = jbetoloFileHelper::normalizeCall($resource, true, true);
         $file_name = basename($path);
         $cache_file = JBETOLO_CACHE_DIR . $file_name;
         if (!JFile::exists($cache_file)) {
             if ($type == 'font') {
                 $data = file_get_contents($path);
                 $processed = jbetoloFileHelper::writeToFile($file_name, $data, 'font', $ext != 'woff');
             }
         }
         $resource = jbetoloFileHelper::getServingURL($file_name, $type, $ext != 'woff');
     }
     if (!$processed) {
         $included = is_array($enabled['datauri-files']) && jbetoloFileHelper::isFileIncluded($resource, $enabled['datauri-files']);
         if (in_array($ext, $enabled['datauri']) || $included) {
             $path = jbetoloFileHelper::normalizeCall($resource, true, true);
             $max = (int) $enabled['datauri-max'];
             if ($path && is_file($path) && ($included || ($max <= 0 || filesize($path) <= $max))) {
                 $contentType = $type == 'font' ? 'application/octet-stream' : 'image/' . $ext;
                 $resource = '"data:' . $contentType . ';base64,' . base64_encode(file_get_contents($path)) . '"';
                 $processed = true;
             }
         }
     }
     return $resource;
 }