Advertisement
Guest User

Update jQuery Latest Version

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