Esempio n. 1
0
 /**
  * VQMod::modCheck()
  *
  * @param string $sourceFile path for file
  * @return string
  * @description Checks if a file has modifications and applies them, returning cache files or the file name
  */
 public static function modCheck($sourceFile)
 {
     if (!self::$_folderChecks) {
         if (self::$logging) {
             // Create log folder if it doesn't exist
             $log_folder = self::path(self::$logFolder, true);
             self::dirCheck($log_folder);
         }
         // Create cache folder if it doesn't exist
         $cache_folder = self::path(self::$vqCachePath, true);
         self::dirCheck($cache_folder);
         // Store cache folder path to save on repeat checks for path validity
         self::$_cachePathFull = self::path(self::$vqCachePath);
         self::$_folderChecks = true;
     }
     if (!preg_match('%^([a-z]:)?[\\\\/]%i', $sourceFile)) {
         $sourcePath = self::path($sourceFile);
     } else {
         $sourcePath = self::_realpath($sourceFile);
     }
     if (!$sourcePath || is_dir($sourcePath) || in_array($sourcePath, self::$_doNotMod)) {
         return $sourceFile;
     }
     $stripped_filename = preg_replace('~^' . preg_quote(self::getCwd(), '~i') . '~', '', $sourcePath);
     $cacheFile = self::_cacheName($stripped_filename);
     $file_last_modified = filemtime($sourcePath);
     if (file_exists($cacheFile) && filemtime($cacheFile) >= self::$_lastModifiedTime && filemtime($cacheFile) >= $file_last_modified) {
         return $cacheFile;
     }
     if (isset(self::$_filesModded[$sourcePath])) {
         return self::$_filesModded[$sourcePath]['cached'] ? $cacheFile : $sourceFile;
     }
     $changed = false;
     $fileHash = sha1_file($sourcePath);
     $fileData = file_get_contents($sourcePath);
     foreach (self::$_mods as $modObject) {
         foreach ($modObject->mods as $path => $mods) {
             if (self::_checkMatch($path, $sourcePath)) {
                 $modObject->applyMod($mods, $fileData);
             }
         }
     }
     if (sha1($fileData) != $fileHash) {
         $writePath = $cacheFile;
         if (!file_exists($writePath) || is_writable($writePath)) {
             file_put_contents($writePath, $fileData);
             $changed = true;
         }
     }
     self::$_filesModded[$sourcePath] = array('cached' => $changed);
     return $changed ? $writePath : $sourcePath;
 }