예제 #1
0
function FilesForDirectory($dirPath, $recursive = true, $returnObject = false)
{
    $iterator = new DirectoryIterator($dirPath);
    $files = array();
    foreach ($iterator as $file) {
        if ($file->isFile()) {
            if ($returnObject) {
                $files[] = $file->getFileInfo();
            } else {
                $files[] = $file->getPathname();
            }
        } elseif ($file->isDir() && !$file->isDot() && $recursive === true) {
            $subdirFiles = FilesForDirectory($file->getPathname(), true, $returnObject);
            foreach ($subdirFiles as $subdirFile) {
                $files[] = $subdirFile;
            }
        }
    }
    return $files;
}
예제 #2
0
 public static function indexModules($save = true)
 {
     $modulesList = new stdClass();
     $modulesList->controllers = array();
     $modulesList->models = array();
     $modulesList->blocksets = array();
     $modulesList->extensions = array();
     $modulesList->skins = array();
     $modulesList->acpcontrollers = array();
     $modulesList->acpinfofiles = array();
     // searching
     foreach (new DirectoryIterator(BundlesPath) as $dir) {
         // if not a bundle, or Installer bundle
         if (!$dir->isDir() || $dir->isDot() || $dir->getFilename() == 'installer') {
             continue;
         }
         $bundleName = $dir->getFilename();
         // skins
         if (substr($bundleName, -5) == '_skin' && file_exists(BundlesPath . $bundleName . '/skin.php')) {
             $modulesList->skins[] = $bundleName;
         }
         // acp info files
         if (file_exists(BundlesPath . $bundleName . '/' . $bundleName . '.acpinfo.php')) {
             $modulesList->acpinfofiles[] = $bundleName;
         }
         // modules
         $moduleTypes = array('controller', 'model', 'blockset', 'extension');
         $files = FilesForDirectory(BundlesPath . $bundleName, false, true);
         foreach ($files as $file) {
             // controllers, models, blocksets and extensions
             foreach ($moduleTypes as $moduleType) {
                 $ext = '.' . $moduleType . '.php';
                 $extLen = strlen($ext);
                 if (substr($file->getFilename(), -$extLen) == $ext) {
                     // .acp.controller.php and .controller.php are different module types
                     if (substr($file->getFilename(), -($extLen + 4)) == '.acp' . $ext) {
                         continue;
                     }
                     // adding
                     $moduleName = substr($file->getFilename(), 0, -$extLen);
                     $modulesList->{$moduleType . 's'}[$moduleName] = $bundleName;
                 }
             }
             // ACP controllers
             $ext = '.acp.controller.php';
             if (substr($file->getFilename(), -19) == $ext) {
                 $moduleName = substr($file->getFilename(), 0, -19);
                 $modulesList->acpcontrollers[$moduleName] = $bundleName;
             }
         }
     }
     // saving or returning
     if ($save) {
         // if something has changed
         if (serialize($modulesList) != serialize(self::$config->modulesList)) {
             self::$config->modulesList = $modulesList;
             Config::set('wmelon.wmelon', self::$config);
         }
     } else {
         return $modulesList;
     }
 }
예제 #3
0
 public static function init()
 {
     self::$textile = new Textile_Lib();
     // once every 1000 views, clearing Textile cache
     if (mt_rand(0, 1000) == 0) {
         $items1 = FilesForDirectory(CachePath . 'textile/');
         $items2 = FilesForDirectory(CachePath . 'textile_restricted/');
         foreach (array_merge($items1, $items2) as $path) {
             if (substr($path, -4) == '.php') {
                 unlink($path);
             }
         }
     }
 }