Ejemplo n.º 1
0
 /**
  * @return LBoxFilesCombineJS
  * @throws Exception
  */
 public static function getInstance()
 {
     try {
         if (!self::$instance instanceof LBoxFilesCombineJS) {
             self::$instance = new LBoxFilesCombineJS();
         }
         return self::$instance;
     } catch (Exception $e) {
         throw $e;
     }
 }
Ejemplo n.º 2
0
 /**
  * kombinuje externi JS do jednoho verzovaneho a nahrazuje v hlavickach jejich includy
  * @param string $input
  * @return string
  */
 protected function combineJS($input = "")
 {
     try {
         switch (LBoxConfigSystem::getInstance()->getParamByPath("output/js_combine")) {
             case 0:
                 return $input;
                 break;
             case -1:
                 if (LBOX_REQUEST_IP == "127.0.0.1") {
                     return $input;
                 }
                 break;
         }
         $out = $input;
         // parseout html header
         $regHeader = "<head((\\s+\\w+(\\s*=\\s*(?:\".*?\"|'.*?'|[^'\">\\s]+))?)+\\s*|\\s*)>(.*)<\\/head>";
         $retHeader = preg_match_all("/{$regHeader}/si", $out, $regsHeader);
         $header = reset(reset($regsHeader));
         // once combined code check
         if (strpos($header, str_replace(LBOX_PATH_PROJECT, "", LBoxFilesCombineJS::getInstance()->getPathDestination()))) {
             return $input;
         }
         // get header javascripts
         $template = '<script type="text/javascript" src="<src>"></script>';
         $reg = $template;
         $reg = str_ireplace("/", '\\/', $reg);
         $reg = str_ireplace("<src>", '(.[^>]*)', $reg);
         $reg = "/{$reg}/si";
         $files = array();
         $ret = preg_match_all($reg, $header, $regs);
         foreach ($regs[1] as $k => $reg) {
             // only local files
             if (preg_match("/^http(s)?:/", $reg)) {
                 unset($regs[0][$k]);
                 unset($regs[1][$k]);
                 continue;
             }
             $files[] = $reg;
         }
         //LBoxFirePHP::log($files);
         if (count($files) > 0) {
             $i = 1;
             foreach ($regs[0] as $reg) {
                 $replace = $i == count($regs[0]) ? str_ireplace("<src>", LBoxFilesCombineJS::getInstance()->combine($files), $template) : "";
                 //LBoxFirePHP::log($reg);
                 //LBoxFirePHP::warn($replace);
                 $out = str_replace($reg, $replace, $out);
                 $i++;
             }
         }
         return $out;
     } catch (Exception $e) {
         throw $e;
     }
 }