includes/clientside/jsres.php
changeset 779 609e35845ec3
parent 746 f81f2a4f8d04
child 780 f65e35566b63
equal deleted inserted replaced
778:57ce13805b6f 779:609e35845ec3
   183 
   183 
   184 if ( isset($_GET['f']) )
   184 if ( isset($_GET['f']) )
   185 {
   185 {
   186   // requested a single file
   186   // requested a single file
   187   $js_file =& $_GET['f'];
   187   $js_file =& $_GET['f'];
   188   if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
   188   if ( strstr($js_file, ',') )
   189   {
   189   {
   190     header('HTTP/1.1 404 Not Found');
   190     $filelist = explode(',', $js_file);
   191     exit('Not found');
   191     unset($js_file);
   192   }
   192     $everything = '';
   193   
   193     foreach ( $filelist as $js_file )
   194   $apex = filemtime("includes/clientside/static/$js_file");
   194     {
   195   
   195       if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
   196   $file_contents = file_get_contents("includes/clientside/static/$js_file");
   196       {
   197   $everything = jsres_cache_check($js_file, $file_contents);
   197         header('HTTP/1.1 404 Not Found');
       
   198         exit('Not found');
       
   199       }
       
   200       
       
   201       $apex = filemtime("includes/clientside/static/$js_file");
       
   202       
       
   203       $file_contents = file_get_contents("includes/clientside/static/$js_file");
       
   204       $everything .= jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true;';
       
   205     }
       
   206   }
       
   207   else
       
   208   {
       
   209     if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
       
   210     {
       
   211       header('HTTP/1.1 404 Not Found');
       
   212       exit('Not found');
       
   213     }
       
   214     
       
   215     $apex = filemtime("includes/clientside/static/$js_file");
       
   216     
       
   217     $file_contents = file_get_contents("includes/clientside/static/$js_file");
       
   218     $everything = jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true;';
       
   219   }
   198 }
   220 }
   199 else
   221 else
   200 {
   222 {
   201   // compress enano-lib-basic
   223   // compress enano-lib-basic
   202   $libbasic = "$before_includes\n$after_includes";
   224   $libbasic = "$before_includes\n$after_includes";
   292     }
   314     }
   293     if ( is_array($cache_file) && isset($cache_file['md5']) && isset($cache_file['src']) )
   315     if ( is_array($cache_file) && isset($cache_file['md5']) && isset($cache_file['src']) )
   294     {
   316     {
   295       if ( $cache_file['md5'] === $file_md5 )
   317       if ( $cache_file['md5'] === $file_md5 )
   296       {
   318       {
   297         header("X-Cache-Status: cache HIT, hash $file_md5");
   319         @header("X-Cache-Status: cache HIT, hash $file_md5");
   298         $loaded_cache = true;
   320         $loaded_cache = true;
   299         $file_contents = $cache_file['src'];
   321         $file_contents = $cache_file['src'];
   300       }
   322       }
   301     }
   323     }
   302   }
   324   }
   314           'md5' => $file_md5,
   336           'md5' => $file_md5,
   315           'src' => $file_contents
   337           'src' => $file_contents
   316         ));
   338         ));
   317       fwrite($handle, $payload);
   339       fwrite($handle, $payload);
   318       fclose($handle);
   340       fclose($handle);
   319       header("X-Cache-Status: cache MISS, new generated");
   341       @header("X-Cache-Status: cache MISS, new generated");
   320     }
   342     }
   321     else
   343     else
   322     {
   344     {
   323       header("X-Cache-Status: cache MISS, not generated");
   345       @header("X-Cache-Status: cache MISS, not generated");
   324     }
   346     }
   325   }
   347   }
   326   else if ( !$loaded_cache )
   348   else if ( !$loaded_cache )
   327   {
   349   {
   328     header("X-Cache-Status: cache MISS, not generated");
   350     @header("X-Cache-Status: cache MISS, not generated");
   329   }
   351   }
   330   
   352   
   331   return $file_contents;
   353   return $file_contents;
   332 }
   354 }
   333 
   355