Advertisement
Guest User

(PHP) Update jQuery Latest Version (Local File)

a guest
Jun 21st, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // -------------------------------------------------------------
  3.  
  4. header('Content-Type: text/html; charset=utf-8');
  5.  
  6. // -------------------------------------------------------------
  7.  
  8.  
  9. $time_stamp = time();
  10. $cache_time = (3600*24*3);
  11.  
  12. $source_url = 'http://code.jquery.com/jquery-latest.min.js';
  13. $local_file = 'jquery-latest.min.js';
  14.  
  15.  
  16. // -------------------------------------------------------------
  17.  
  18. function update_jquery($source_url, $local_file, $cache_time, $time_stamp) {
  19.    
  20.     $vstatus = false;
  21.    
  22.     $last_update = @filemtime($local_file);
  23.    
  24.     if (!$last_update || ($cache_time < ($time_stamp - $last_update))) {
  25.  
  26.     if (!file_exists($local_file)) {
  27.         copy($source_url,$local_file);
  28.         $vstatus = 'new';
  29.     }
  30.     else {
  31.         $pattern = "@\!\s(.*?)\s\|@";
  32.        
  33.         $loc = file_get_contents($local_file);
  34.         preg_match($pattern,$loc,$mloc);
  35.        
  36.         $ext = file_get_contents($source_url);
  37.         preg_match($pattern,$ext,$mext);
  38.        
  39.         if ($mloc[1] == $mext[1]) {
  40.             touch($local_file,$time_stamp);
  41.             $vstatus = 'no_change';
  42.         }
  43.         else {
  44.             copy($source_url,$local_file);
  45.             $vstatus = 'update';
  46.         }
  47.        
  48.     }
  49.    
  50.     }
  51.     else {
  52.     $vstatus = 'cached';
  53.     }
  54.    
  55.     return $vstatus;
  56.  
  57. }
  58.  
  59. // -------------------------------------------------------------
  60.  
  61.  
  62. $jver_status = update_jquery($source_url, $local_file, $cache_time, $time_stamp);
  63.  
  64.  
  65. // -------------------------------------------------------------
  66.  
  67.  
  68. print "<p>Update Status: ".$jver_status."</p>\n";
  69.  
  70.  
  71. // -------------------------------------------------------------
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement