Example #1
0
 public function autoloaderClassToFile($class)
 {
     static $classes = array('XenForo_CodeEvent', 'XenForo_Template_Abstract', 'XenForo_ViewRenderer_Json');
     if (in_array($class, $classes, true)) {
         $class = 'DevHelper_' . $class;
     }
     $classFile = parent::autoloaderClassToFile($class);
     $strPos = 0;
     if (substr($class, 0, 9) !== 'DevHelper') {
         $strPos = strpos($class, 'ShippableHelper_');
     }
     if ($strPos > 0) {
         // a helper class is being called, check its version vs. ours
         $classVersionId = 0;
         if (file_exists($classFile)) {
             $classContents = file_get_contents($classFile);
             $classVersionId = DevHelper_Helper_ShippableHelper::getVersionId($class, $classFile, $classContents);
             if ($classVersionId === false) {
                 die('Add-on class version could not be detected: ' . $classFile);
             }
         }
         $oursClass = 'DevHelper_Helper_' . substr($class, $strPos);
         $oursFile = parent::autoloaderClassToFile($oursClass);
         if (file_exists($oursFile)) {
             $oursContents = file_get_contents($oursFile);
             $oursVersionId = DevHelper_Helper_ShippableHelper::getVersionId($oursClass, $oursFile, $oursContents);
             if ($oursVersionId === false) {
                 die('DevHelper class version could not be detected: ' . $oursFile);
             }
         } else {
             die('DevHelper file could not be found: ' . $oursFile);
         }
         if ($classVersionId < $oursVersionId) {
             if (!DevHelper_Helper_ShippableHelper::update($class, $classFile, $oursClass, $oursContents)) {
                 die('Add-on file could not be updated: ' . $classFile);
             }
             // die('Add-on file has been updated: ' . $classFile);
         }
     }
     return $classFile;
 }
Example #2
0
 protected static function _fileExport($entry, &$exportPath, &$rootPath, $options)
 {
     if (empty($entry)) {
         return;
     }
     $relativePath = trim(str_replace($rootPath, '', $entry), '/');
     if (in_array($relativePath, $options['excludes'])) {
         echo "<span style='color: #ddd'>Excluded       {$relativePath}</span>\n";
         return;
     }
     foreach ($options['excludeRegExs'] as $excludeRegEx) {
         if (preg_match($excludeRegEx, $relativePath)) {
             echo "<span style='color: #ddd'>RegExcluded    {$relativePath}</span>\n";
             return;
         }
     }
     if (is_dir($entry)) {
         echo "<span style='color: #ddd'>Browsing       {$relativePath}</span>\n";
         $children = array();
         $dh = opendir($entry);
         while ($child = readdir($dh)) {
             if (substr($child, 0, 1) === '.') {
                 // ignore . (current directory)
                 // ignore .. (parent directory)
                 // ignore hidden files (dot files/directories)
                 continue;
             }
             $children[] = $child;
         }
         foreach ($children as $child) {
             if (!empty($options['force'])) {
                 $options['force'] = false;
             }
             // reset `force` option for children
             self::_fileExport($entry . '/' . $child, $exportPath, $rootPath, $options);
         }
     } elseif (is_file($entry)) {
         $ext = XenForo_Helper_File::getFileExtension($entry);
         if (!empty($options['force']) || in_array($ext, $options['extensions']) && strpos(basename($entry), '.') !== 0 || in_array(strtolower(basename($entry)), $options['filenames_lowercase'])) {
             if ($options['addon_id'] == 'devHelper') {
                 $isDevHelper = strpos($entry, 'DevHelper/DevHelper') !== false;
             } else {
                 $isDevHelper = strpos($entry, 'DevHelper') !== false;
             }
             if (!$isDevHelper) {
                 $entryExportPath = $exportPath . '/' . $relativePath;
                 if ($ext === 'php') {
                     DevHelper_Helper_ShippableHelper::checkForUpdate($entry);
                 }
                 $contents = self::fileGetContents($entry);
                 if (!empty($contents)) {
                     if ($ext === 'php') {
                         DevHelper_Helper_Phrase::parsePhpForPhraseTracking($relativePath, $contents);
                         DevHelper_Helper_Xfcp::parsePhpForXfcpClass($relativePath, $contents);
                     }
                     $result = self::writeFile($entryExportPath, $contents, false, false);
                     if ($result === true) {
                         echo "Exporting      {$relativePath} OK\n";
                     } elseif ($result === 'skip') {
                         echo "<span style='color: #ddd'>Exporting      {$relativePath} SKIPPED</span>\n";
                     }
                 }
             }
         }
     }
 }