Beispiel #1
0
 public static function createFile(&$body, $src_files, $excluded_files, $replace_tags, $conds, $comments, $indexes)
 {
     $arr = plgSystemJBetolo::param('files');
     $abs_excl_minify = plgSystemJBetolo::param('minify_exclude');
     if ($abs_excl_minify) {
         $abs_excl_minify = explode(',', $abs_excl_minify);
     }
     $abs_excl_gzip = plgSystemJBetolo::param('gzip_exclude');
     if ($abs_excl_gzip) {
         $abs_excl_gzip = explode(',', $abs_excl_gzip);
     }
     $excl_js_imports = $excl_css_imports = '';
     $css_imports = $js_imports = array();
     $js_placement = plgSystemJBetolo::param('js_placement');
     $age = plgSystemJBetolo::param('cache_age');
     $app = JFactory::getApplication()->getName();
     $tmpl = JFactory::getApplication()->getTemplate();
     $paramHasChanged = false;
     $external_custom_orders = array();
     /**
      * app[administrator|site],type[css|js],attr[css=media,js='']
      */
     foreach ($src_files as $type => $_src_files) {
         if (empty($_src_files)) {
             continue;
         }
         $skipFiles = array_merge($conds[$type], $comments[$type]);
         $merge = plgSystemJBetolo::param($type . '_merge');
         $is_gz = JBETOLO_IS_GZ && plgSystemJBetolo::param($type . '_gzip') && jbetoloHelper::clientEncoding();
         $is_minify = JBETOLO_IS_MINIFY && plgSystemJBetolo::param($type . '_minify');
         $excl_files = $excluded_files[$type];
         if ($merge) {
             $mergeMode = plgSystemJBetolo::param($type . '_merge_mode', 'mono');
             $are_files_changed = $new_files_found = false;
             if (count($arr) == 0 || !isset($arr[$app]) || !isset($arr[$app][$tmpl]) || !isset($arr[$app][$tmpl][$type]) || !is_array($arr[$app][$tmpl][$type])) {
                 $arr[$app][$tmpl][$type] = array();
             }
             if ($mergeMode == 'mono') {
                 if (count($arr[$app][$tmpl][$type])) {
                     foreach ($arr[$app][$tmpl][$type] as $attr => $rec) {
                         $merged = array();
                         $merged_file = JBETOLO_CACHE_DIR . $rec['merged'];
                         $found_files = array();
                         $delete_merged_file = false;
                         foreach ($_src_files as $s => $src_file) {
                             if ($type == 'js' || isset($indexes['css'][$s]['attr']) && $attr == $indexes['css'][$s]['attr']) {
                                 if (!in_array($src_file, $rec['srcs'])) {
                                     $found_files[] = $src_file;
                                     $delete_merged_file = true;
                                 }
                             }
                         }
                         if (!empty($found_files)) {
                             $merged = array_merge($merged, $found_files);
                         }
                         $merged_file_exists = JFile::exists($merged_file);
                         if (empty($found_files) && $merged_file_exists) {
                             $are_files_changed = self::areFilesChanged($rec['parts']);
                             if ($are_files_changed) {
                                 $delete_merged_file = true;
                             }
                         }
                         if ($delete_merged_file && $merged_file_exists) {
                             JFile::delete($merged_file);
                         }
                         $merged_file_exists = JFile::exists($merged_file);
                         if (!$merged_file_exists) {
                             $merged = array_merge($merged, $rec['srcs']);
                         }
                         if (!empty($merged)) {
                             $merged = array_unique($merged);
                             $merged = jbetoloFileHelper::customOrder($merged, $type);
                             if ($type == 'js') {
                                 jbetoloJS::setJqueryFile($merged, jbetoloHelper::getArrayValues($excl_files, 'src'));
                                 $res = jbetoloJS::build($merged);
                             } else {
                                 $res = jbetoloCSS::build($merged, array_fill(0, count($merged), $attr));
                             }
                             $arr[$app][$tmpl][$type][$attr] = $res[$attr];
                             $paramHasChanged = true;
                         }
                     }
                 } else {
                     $_src_files = array_unique($_src_files);
                     if ($type == 'js') {
                         jbetoloJS::setJqueryFile($_src_files, jbetoloHelper::getArrayValues($excl_files, 'src'));
                     }
                     $arr[$app][$tmpl][$type] = $type == 'css' ? jbetoloCSS::build($_src_files, '', true, $indexes['css']) : jbetoloJS::build($_src_files);
                     $paramHasChanged = true;
                 }
                 $imports = $arr[$app][$tmpl][$type];
             } else {
                 if ($mergeMode == 'url') {
                     $files_key = jbetoloHelper::currentURL();
                 } else {
                     if ($mergeMode == 'resource') {
                         $_src_files = array_unique($_src_files);
                         $files_key = $_src_files;
                         sort($files_key);
                         $files_key = implode('', $files_key);
                     }
                 }
                 if (isset($arr[$app][$tmpl][$type][$files_key])) {
                     $rec = $arr[$app][$tmpl][$type][$files_key];
                     $add_key = key($rec);
                     $rec = $rec[$add_key];
                     if (self::areFilesChanged($rec['parts'])) {
                         if (JFile::exists(JBETOLO_CACHE_DIR . $rec['merged'])) {
                             JFile::delete(JBETOLO_CACHE_DIR . $rec['merged']);
                         }
                         $paramHasChanged = true;
                     }
                 } else {
                     $paramHasChanged = true;
                 }
                 if ($paramHasChanged) {
                     $arr[$app][$tmpl][$type][$files_key] = $type == 'css' ? jbetoloCSS::build($_src_files, '', true, $indexes['css']) : jbetoloJS::build($_src_files);
                 }
                 $imports = $arr[$app][$tmpl][$type][$files_key];
             }
             $external_custom_orders[$type] = jbetoloHelper::replaceTags($body, $replace_tags[$type], "", $indexes[$type], plgSystemJBetolo::param($type . '_external_custom_order_before'), plgSystemJBetolo::param($type . '_external_custom_order_after'));
             /**
              * @@todo: if cdn enabled just provide the file and no dynamic url
              */
             foreach ($imports as $attr => $rec) {
                 $url = jbetoloFileHelper::getServingURL($rec['merged'], $type, $is_gz, $age);
                 if ($type == 'js') {
                     $js_imports[] = "\n" . '<script type="text/javascript" src="' . $url . '"></script>';
                 } else {
                     $attrs = jbetoloHelper::returnAttributes($attr);
                     $css_imports[] = "\n" . '<link rel="stylesheet" type="text/css" href="' . $url . '" ' . $attrs . ' />';
                 }
             }
         }
         $gzip_excluded = plgSystemJBetolo::param($type . '_gzip_excluded');
         $minify_excluded = plgSystemJBetolo::param($type . '_minify_excluded');
         if (($is_gz && $gzip_excluded || $is_minify && $minify_excluded) && count($excl_files)) {
             $jqueryNoConflict = plgSystemJBetolo::param('js_jquery_no_conflict');
             foreach ($excl_files as $excl_file) {
                 $src = $excl_file['src'];
                 if (jbetoloFileHelper::fileInArray($src, $skipFiles)) {
                     continue;
                 }
                 $_minify = $is_minify && !jbetoloFileHelper::isFileExcluded($src, $abs_excl_minify);
                 $_gz = $is_gz && !jbetoloFileHelper::isFileExcluded($src, $abs_excl_gzip);
                 if (($_minify || $_gz) && !$excl_file['dynamic']) {
                     $src = str_replace(JBETOLO_URI_BASE, '', $src);
                     $attr = $type == 'css' ? jbetoloHelper::extractAttributes($excl_file['tag']) : 'main';
                     $file = $type == 'css' ? jbetoloCSS::build($src, array($attr)) : jbetoloJS::build($src);
                     $file = $file[$attr]['merged'];
                     $src = jbetoloFileHelper::getServingURL($file, $type, $is_gz, $age);
                     if ($type == 'js') {
                         $excl_js_imports .= "\n" . '<script type="text/javascript" src="' . $src . '"></script>';
                     } else {
                         if ($type == 'css') {
                             $attrs = jbetoloHelper::returnAttributes($attr);
                             $excl_css_imports .= "\n" . '<link rel="stylesheet" type="text/css" href="' . $src . '" ' . $attrs . ' />';
                         }
                     }
                     $body = str_ireplace($excl_file['tag'], '', $body);
                 }
             }
         }
     }
     jbetoloFileHelper::placeTags($body, $excl_css_imports, 'css');
     jbetoloFileHelper::placeTags($body, $js_imports, 'js', $js_placement, isset($external_custom_orders['js']) ? $external_custom_orders['js']['before'] : array(), isset($external_custom_orders['js']['after']) ? $external_custom_orders['js']['after'] : array(), true);
     jbetoloFileHelper::placeTags($body, $excl_js_imports, 'js', $js_placement, null, null, true);
     jbetoloFileHelper::placeTags($body, $css_imports, 'css');
     if ($paramHasChanged) {
         plgSystemJBetolo::param('files', $arr, 'set');
     }
 }
Beispiel #2
0
 public static function dontJbetolo($type = 'jbetolo')
 {
     if (self::param('listen_request', 0) && JRequest::getCmd('nojbetolo', 0) == 1) {
         return true;
     }
     $app = JFactory::getApplication()->getName();
     $user = JFactory::getUser();
     $allowedIn = $type == 'jbetolo' ? self::param('allow_in') : 'site';
     if (!self::$allowAll && ($allowedIn == 'anonymous' && !$user->guest || $allowedIn != 'anonymous' && $app != $allowedIn && $allowedIn != 'all' || $app == 'administrator' && $user->guest)) {
         return true;
     }
     $document = JFactory::getDocument();
     $doctype = $document->getType();
     if ($doctype != 'html') {
         return true;
     }
     if ($type == 'cdn') {
         if (!(bool) self::param('cdn_enabled', false)) {
             return true;
         }
     }
     $donts = self::$donts[$type];
     if ($type == 'jbetolo') {
         $excludeComponents = self::param('exclude_components');
     } else {
         $excludeComponents = self::param($type . '_exclude_components');
     }
     if (!empty($excludeComponents)) {
         $excludeComponents = explode(',', $excludeComponents);
         foreach ($excludeComponents as $i => $component) {
             if (substr($component, 0, 4) != 'com_') {
                 $excludeComponents[$i] = 'com_' . $component;
             }
         }
         if (is_array($donts['option'])) {
             $donts['option'] = array_merge($donts['option'], $excludeComponents);
         } else {
             $donts['option'] = $excludeComponents;
         }
     }
     $excludeURLs = self::param('exclude_urls', array());
     if (!empty($excludeURLs)) {
         $excludeURLs = explode(',', $excludeURLs);
         foreach ($excludeURLs as &$url) {
             if (strpos($url, self::EXCLUDE_REG_PREFIX) === false) {
                 parse_str($url, $url);
             } else {
                 $url = str_replace(self::EXCLUDE_REG_PREFIX, '', $url);
             }
         }
     }
     $excludeURLs[] = array('option' => 'com_maqmahelpdesk', 'task' => 'ticket_view');
     $excludeURLs[] = array('option' => 'com_jevents', 'task' => 'icalevent.edit');
     $excludeURLs[] = array('option' => 'com_content', 'task' => 'article.add');
     $excludeURLs[] = array('option' => 'com_content', 'task' => 'article.edit');
     $excludeURLs[] = array('option' => 'com_k2', 'task' => 'article.add');
     $excludeURLs[] = array('option' => 'com_k2', 'task' => 'article.edit');
     $excludeURLs[] = array('option' => 'com_easydiscuss', 'view' => 'ask');
     $currentURL = jbetoloHelper::currentURL();
     if (!empty($excludeURLs)) {
         $input = JFactory::getApplication()->input;
         foreach ($excludeURLs as $url) {
             $match = true;
             if (is_string($url)) {
                 $match = preg_match('#' . preg_quote($url) . '#', $currentURL);
             } else {
                 foreach ($url as $k => $v) {
                     //                                                $val = JRequest::getVar($k, self::$dontsEmpty);
                     $val = $input->get($k, self::$dontsEmpty);
                     if ($val != $v) {
                         $match = false;
                         break;
                     }
                 }
             }
             if ($match) {
                 return true;
             }
         }
     }
     if (self::checkRules($donts)) {
         return true;
     }
     $excludeBrowsers = self::param('exclude_browsers');
     if (!empty($excludeBrowsers)) {
         $excludeBrowsers = explode("\n", $excludeBrowsers);
         jimport('joomla.environment.browser');
         $navigator = JBrowser::getInstance();
         foreach ($excludeBrowsers as $excludeBrowser) {
             $excludeBrowser = strtolower($excludeBrowser);
             $excludeBrowser = trim($excludeBrowser);
             $additionalCheck = false;
             $_excludeBrowser = explode('-version', $excludeBrowser);
             $_excludeBrowser[0] = jbetoloHelper::browser($_excludeBrowser[0]);
             if (count($_excludeBrowser) > 1) {
                 if ($navigator->isBrowser($_excludeBrowser[0])) {
                     if (self::browserCompare($_excludeBrowser, 'version', $navigator)) {
                         return true;
                     }
                 }
                 $additionalCheck = true;
             }
             if (!$additionalCheck) {
                 $excludeBrowser = jbetoloHelper::browser($excludeBrowser);
                 if ($navigator->isBrowser($excludeBrowser)) {
                     return true;
                 }
             }
         }
     }
     if ((bool) self::param('exclude_mobile', 0)) {
         jimport('joomla.environment.browser');
         $navigator = JBrowser::getInstance();
         if ($navigator->isMobile()) {
             return true;
         }
     }
     return false;
 }