/** * Find files in several directories using several filename patterns * * @param array $pairs each item is an array(0 => $searchBaseDir, 1 => $filePattern) * @return array of file paths */ static function findManyFiles($pairs) { $files = array(); foreach ($pairs as $pair) { list($dir, $pattern) = $pair; $files = array_merge($files, CRM_Utils_File::findFiles($dir, $pattern)); } return $files; }
/** * Search directory tree for files which match a glob pattern * * Note: Dot-directories (like "..", ".git", or ".svn") will be ignored. * Note: In Civi 4.3+, delegate to CRM_Utils_File::findFiles() * * @param $dir string, base dir * @param $pattern string, glob pattern, eg "*.txt" * @return array(string) */ function _api4_civix_find_files($dir, $pattern) { if (is_callable(array('CRM_Utils_File', 'findFiles'))) { return CRM_Utils_File::findFiles($dir, $pattern); } $todos = array($dir); $result = array(); while (!empty($todos)) { $subdir = array_shift($todos); foreach (_api4_civix_glob("{$subdir}/{$pattern}") as $match) { if (!is_dir($match)) { $result[] = $match; } } if ($dh = opendir($subdir)) { while (FALSE !== ($entry = readdir($dh))) { $path = $subdir . DIRECTORY_SEPARATOR . $entry; if ($entry[0] == '.') { } elseif (is_dir($path)) { $todos[] = $path; } } closedir($dh); } } return $result; }
/** * Scan $basedir for a list of extension-keys * * @return array * ($key => $relPath) */ protected function getRelPaths() { if (!is_array($this->relPaths)) { if ($this->cache) { $this->relPaths = $this->cache->get($this->cacheKey); } if (!is_array($this->relPaths)) { $this->relPaths = array(); $infoPaths = CRM_Utils_File::findFiles($this->baseDir, 'info.xml'); foreach ($infoPaths as $infoPath) { $relPath = CRM_Utils_File::relativize(dirname($infoPath), $this->baseDir); try { $info = CRM_Extension_Info::loadFromFile($infoPath); } catch (CRM_Extension_Exception_ParseException $e) { CRM_Core_Session::setStatus(ts('Parse error in extension: %1', array(1 => $e->getMessage())), '', 'error'); CRM_Core_Error::debug_log_message("Parse error in extension: " . $e->getMessage()); continue; } $this->relPaths[$info->key] = $relPath; } if ($this->cache) { $this->cache->set($this->cacheKey, $this->relPaths); } } } return $this->relPaths; }
/** * Load up settings metadata from files. */ public static function loadSettingsMetadata($metaDataFolder) { $settingMetaData = array(); $settingsFiles = CRM_Utils_File::findFiles($metaDataFolder, '*.setting.php'); foreach ($settingsFiles as $file) { $settings = (include $file); $settingMetaData = array_merge($settingMetaData, $settings); } CRM_Core_BAO_Cache::setItem($settingMetaData, 'CiviCRM setting Spec', 'All'); return $settingMetaData; }
/** * Get list of translatable strings for a module. * * @param string $name * Angular module name. * @return array * Translatable strings. */ public function getStrings($name) { $module = $this->getModule($name); $result = array(); if (isset($module['js'])) { foreach ($module['js'] as $file) { $strings = $this->res->getStrings()->get($module['ext'], $this->res->getPath($module['ext'], $file), 'text/javascript'); $result = array_unique(array_merge($result, $strings)); } } if (isset($module['partials'])) { foreach ($module['partials'] as $partialDir) { $partialDir = $this->res->getPath($module['ext']) . '/' . $partialDir; $files = \CRM_Utils_File::findFiles($partialDir, '*.html'); foreach ($files as $file) { $strings = $this->res->getStrings()->get($module['ext'], $file, 'text/html'); $result = array_unique(array_merge($result, $strings)); } } } return $result; }
/** * Load up settings metadata from files. */ protected static function loadSettingsMetadata($metaDataFolder) { $settingMetaData = array(); $settingsFiles = \CRM_Utils_File::findFiles($metaDataFolder, '*.setting.php'); foreach ($settingsFiles as $file) { $settings = (include $file); $settingMetaData = array_merge($settingMetaData, $settings); } return $settingMetaData; }