protected static function _scanClassDir($path, &$map, &$mapPackaged, $exceptPath, $packages, $packagesCfg) { $path = File::fillEndSep($path); $items = File::scanFiles($path, array('.php'), false); if (empty($items)) { return; } foreach ($items as $item) { if (File::getExt($item) === '.php') { $parts = explode(DIRECTORY_SEPARATOR, str_replace($exceptPath, '', substr($item, 0, -4))); $parts = array_map('ucfirst', $parts); $class = implode('_', $parts); $package = false; if (isset($packages[$item]) && $packagesCfg['packages'][$packages[$item]]['active']) { $package = $packagesCfg->get('path') . $packages[$item] . '.php'; } else { $package = $item; } if (!isset($map[$class])) { $map[$class] = $item; } if (!isset($mapPackaged[$class])) { $mapPackaged[$class] = $package; } } else { self::_scanClassDir($item, $map, $mapPackaged, $exceptPath, $packages, $packagesCfg); } } }
/** * Get list of available controllers */ public function controllersAction() { $appPath = $this->_configMain['application_path']; $folders = File::scanFiles($this->_configMain->get('frontend_controllers'), false, true, File::Dirs_Only); $data = array(); if (!empty($folders)) { foreach ($folders as $item) { $name = basename($item); if (file_exists($item . '/Controller.php')) { $name = str_replace($appPath, '', $item . '/Controller.php'); $name = Utils::classFromPath($name); $data[] = array('id' => $name, 'title' => $name); } } } if ($this->_configMain->get('allow_externals')) { $config = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php'); $eExpert = new Externals_Expert($this->_configMain, $config); $classes = $eExpert->getClasses(); $extControllers = $eExpert->getFrontendControllers(); if (!empty($extControllers)) { $data = array_merge($data, array_values($extControllers)); } } Response::jsonSuccess($data); }
public function getlogfilesAction() { //$version = $this->_configMain['development_version']; $logPath = $this->_configMain['orm_log_path']; //$fileName = $logPath . 'default_'.$version . '_build_log.sql'; $files = File::scanFiles($logPath, array('.sql'), false); $data = array(); foreach ($files as $file) { $file = basename($file, '.sql'); $data[] = array('id' => $file); } Response::jsonSuccess($data); }
/** * Get connections list * @param integer $devType * @throws Exception * @return array */ public function getConnections($devType) { if (!$this->typeExists($devType)) { throw new Exception('Backend_Orm_Connections_Manager :: getConnections undefined dev type ' . $devType); } $files = File::scanFiles($this->_config[$devType]['dir'], array('.php'), false, File::Files_Only); $result = array(); if (!empty($files)) { foreach ($files as $item) { $result[substr(basename($item), 0, -4)] = Config::factory(Config::File_Array, $item); } } return $result; }
/** * Get list of registered objects (names only) * @return array */ public function getRegisteredObjects() { if (is_null(self::$_objects)) { $paths = File::scanFiles(Db_Object_Config::getConfigPath(), array('.php'), false, File::Files_Only); self::$_objects = array(); if (!empty($paths)) { foreach ($paths as $path) { self::$_objects[] = substr(basename($path), 0, -4); } } /* * Scan for External objects */ if (self::$_externalsExpert) { $objects = self::$_externalsExpert->getObjects(); if (!empty($objects)) { self::$_objects = array_merge(self::$_objects, array_keys($objects)); } } } return self::$_objects; }
/** * Get list of dictionaries * return array */ public function getList() { if (!is_null(self::$_list)) { return array_keys(self::$_list); } $files = File::scanFiles($this->_path, array('.php'), false, File::Files_Only); $list = array(); if (!empty($files)) { foreach ($files as $path) { $name = substr(basename($path), 0, -4); $list[$name] = $path; } } $external = Dictionary::getExternal(); if (!empty($external)) { $list = array_merge($list, $external); } self::$_list = $list; if ($this->_cache) { $this->_cache->save($list, self::CACHE_KEY_LIST); } return array_keys($list); }
/** * List defined Blocks */ public function classlistAction() { $blocksPath = $this->_configMain['blocks']; $classesPath = $this->_configMain['application_path']; $files = File::scanFiles($blocksPath, array('.php'), true, File::Files_Only); foreach ($files as $k => $file) { $class = Utils::classFromPath(str_replace($classesPath, '', $file)); if ($class != 'Block_Abstract') { $data[] = array('id' => $class, 'title' => $class); } } if ($this->_configMain->get('allow_externals')) { $config = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php'); $eExpert = new Externals_Expert($this->_configMain, $config); $extBlocks = $eExpert->getBlocks(); if (!empty($extBlocks)) { foreach ($extBlocks as $class => $path) { $data[] = array('id' => $class, 'title' => $class); } } } Response::jsonSuccess($data); }
public function listAction() { $modulesCfg = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php')->__toArray(); $vendors = File::scanFiles($this->_configMain->get('external_modules'), false, false, File::Dirs_Only); if (!$this->_configMain->get('allow_externals') || empty($vendors)) { Response::jsonSuccess(array()); } foreach ($vendors as $path) { $vendorName = basename($path); $modules = File::scanFiles($path, false, false, File::Dirs_Only); if (empty($modules)) { continue; } foreach ($modules as $module) { $moduleName = basename($module); $uid = $vendorName . '/' . $moduleName; if (!file_exists($module . '/config.ini')) { continue; } $cfg = parse_ini_file($module . '/config.ini', true); if (!isset($cfg['INFO'])) { continue; } $info = $cfg['INFO']; if (!isset($modulesCfg[$uid])) { $modulesCfg[$uid] = array('active' => false); } $modulesCfg[$uid]['title'] = $info['title']; $modulesCfg[$uid]['description'] = $info['description']; $modulesCfg[$uid]['author'] = $info['author']; $modulesCfg[$uid]['version'] = $info['version']; $modulesCfg[$uid]['id'] = $uid; } } Response::jsonSuccess(array_values($modulesCfg)); }
/** * Get language subpackages * @param string $language - optional * @return array */ public function getSubPackages($lang = false) { if (!$lang) { $lang = $this->_indexLanguage; } $langDir = $this->_appConfig->get('lang_path') . $lang; if (!is_dir($langDir)) { return array(); } $files = File::scanFiles($langDir, array('.php'), false, File::Files_Only); $data = array(); foreach ($files as $file) { // IIS fix if (DIRECTORY_SEPARATOR !== '/') { $file = str_replace(DIRECTORY_SEPARATOR, '/', $file); } $file = str_replace('//', '/', $file); $lang = str_replace($langDir, '', substr($file, 0, -4)); if (basename($file) !== 'objects.php') { $data[] = $lang; } } return $data; }
/** * Recursively remove files and dirs from given $pathname * @param string $pathname * @param bool $removeParentDir * @return boolean */ public static function rmdirRecursive($pathname, $removeParentDir = false) { $filesDirs = File::scanFiles($pathname, false, true, File::Files_Dirs, RecursiveIteratorIterator::CHILD_FIRST); foreach ($filesDirs as $v) { if (is_dir($v)) { if (!rmdir($v)) { return false; } } elseif (is_file($v) || is_link($v)) { if (!unlink($v)) { return false; } } else { return false; } } if ($removeParentDir) { if (!rmdir($pathname)) { return false; } } return true; }
/** * Inerface projects list */ public function fslistAction() { $path = Request::post('node', 'string', ''); $config = $config = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php'); $dirPath = $config->get('configs'); $list = array(); if (!is_dir($dirPath)) { Response::jsonArray(array()); } if ($path === '') { if ($this->_configMain->get('allow_externals')) { $config = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php'); $eExpert = new Externals_Expert($this->_configMain, $config); $extProjects = $eExpert->getProjects(); if (!empty($extProjects)) { foreach ($extProjects as $item) { $list[] = $item; } } } $path = $dirPath . $path; } $files = File::scanFiles($path, array('.dat'), false, File::Files_Dirs); /** * This is hard fix for windows */ if (DIRECTORY_SEPARATOR == '\\') { foreach ($files as &$v) { $v = str_replace('\\', '/', $v); $v = str_replace('//', '/', $v); } unset($v); } if (empty($files)) { Response::jsonArray(array()); } foreach ($files as $k => $fpath) { $text = basename($fpath); if ($text === '.svn') { continue; } $obj = new stdClass(); $obj->id = str_replace($this->_configMain->get('docroot'), './', $fpath); $obj->text = $text; if (is_dir($fpath)) { $obj->expanded = false; $obj->leaf = false; } else { $obj->leaf = true; } $list[] = $obj; } Response::jsonArray($list); }
public function imglistAction() { $templates = $this->_config->get('templates'); $dirPath = $this->_configMain->get('docroot'); $dir = Request::post('dir', 'string', ''); if (!is_dir($dirPath . $dir)) { Response::jsonArray(array()); } $files = File::scanFiles($dirPath . $dir, array('.jpg', '.png', '.gif', '.jpeg'), false, File::Files_Only); if (empty($files)) { Response::jsonArray(array()); } sort($files); $list = array(); foreach ($files as $k => $fpath) { // ms fix $fpath = str_replace('\\', '/', $fpath); $text = basename($fpath); if ($text === '.svn') { continue; } $list[] = array('name' => $text, 'url' => str_replace($dirPath . '/', $this->_configMain->get('wwwroot'), $fpath), 'path' => str_replace($dirPath . '/', $templates['wwwroot'], $fpath)); } Response::jsonSuccess($list); }
/** * Files list * @return void */ public function fslistAction() { $srcDirs = $this->_configMain['autoloader']['paths']; $list = array(); foreach ($srcDirs as $dir) { $list = array_merge($list, File::scanFiles($dir, array('.php'), true)); } foreach ($list as $k => &$fpath) { if (strpos($fpath, '/.svn')) { unset($list[$k]); continue; } } unset($fpath); $existingList = array(); foreach ($this->_packagesConfig->get('packages') as $v) { $existingList = array_merge($existingList, $v['paths']); } $diff = array_diff($list, $existingList); $tree = Utils::fileListToTree($diff); $data = $this->_fillChilds($tree); Response::jsonArray($data); }
/** * Get themes list */ public function themeslistAction() { $themes = File::scanFiles($this->_configMain->get('themes'), false, false, File::Dirs_Only); $result = array(); if (!empty($themes)) { foreach ($themes as $name) { $code = basename($name); if ($code[0] != '.') { $result[] = array('id' => $code, 'title' => $code); } } } if ($this->_configMain->get('allow_externals')) { $config = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php'); $eExpert = new Externals_Expert($this->_configMain, $config); $themes = $eExpert->getThemes(); if (!empty($themes)) { foreach ($themes as $k => $path) { $result[] = array('id' => $k, 'title' => $k); } } } Response::jsonSuccess($result); }
/** * Get list of existing form field adapters */ public function listadaptersAction() { $data = array(); $autoloaderPaths = $this->_configMain['autoloader']; $autoloaderPaths = $autoloaderPaths['paths']; $files = File::scanFiles($this->_config->get('components') . '/Field', array('.php'), true, File::Files_Only); if (!empty($files)) { foreach ($files as $item) { $class = Utils::classFromPath(str_replace($autoloaderPaths, '', $item)); $data[] = array('id' => $class, 'title' => str_replace($this->_config->get('components') . '/', '', substr($item, 0, -4))); } } Response::jsonArray($data); }
* and save a reference for it (for convenience) * @var Config_Simple $appConfig */ $appConfig = Config::factory(Config::Simple, 'main'); $appConfig->setData($config); Registry::set('main', $appConfig, 'config'); /** * Convert the data of main_config file * in to the general form of configuration * and save a reference for it (for convenience) * @var Config_Simple $appConfig */ /* * Starting the application */ $app = new Application($appConfig); $app->setAutoloader($autoloader); $app->init(); // build objects $objectFiles = File::scanFiles($config['object_configs'], array('.php'), false, File::Files_Only); foreach ($objectFiles as $file) { $object = substr(basename($file), 0, -4); echo 'build ' . $object . ' : '; $builder = new Db_Object_Builder($object); if ($builder->build()) { echo 'OK'; } else { echo 'Error! ' . strip_tags(implode(', ', $builder->getErrors())); } echo "\n"; }
/** * Get Orm objects list */ public function objectsAction() { $cfgPath = $this->_configMain['object_configs']; /* * Getting list of objects */ $configs = File::scanFiles($cfgPath, array('.php'), false, File::Files_Only); if (empty($configs)) { Response::jsonSuccess(array()); } $data = array(); foreach ($configs as $file) { $file = basename(substr($file, 0, -4)); $conf = Db_Object_Config::getInstance($file); $data[] = array('id' => $file, 'title' => $conf->get('title')); } Response::jsonArray($data); }
/** * Get list of available renderers */ public function renderersAction() { $data = array(); $autoloaderPaths = $this->_configMain['autoloader']; $autoloaderPaths = $autoloaderPaths['paths']; $files = File::scanFiles($this->_config->get('components') . '/Renderer', array('.php'), true, File::Files_Only); $data[] = array('id' => '', 'title' => $this->_lang->NO); /** * This is hard fix for windows */ if (DIRECTORY_SEPARATOR == '\\') { foreach ($files as &$v) { $v = str_replace('\\', '/', $v); $v = str_replace('//', '/', $v); } unset($v); } if (!empty($files)) { foreach ($files as $item) { $class = Utils::classFromPath(str_replace($autoloaderPaths, '', $item)); $data[] = array('id' => $class, 'title' => str_replace($this->_config->get('components') . '/Renderer/', '', substr($item, 0, -4))); } } Response::jsonArray($data); }
/** * Create FS map using php functions * @return mixed bulean|array */ protected function _fsmapByPhp($toFile = false) { ini_set('max_execution_time', 3600); $deployCfg = Config::factory(Config::File_Array, $this->_appConfig['configs'] . 'deploy.php'); $list = File::scanFiles('.', array(), $recursive = true); $ignore = $deployCfg->get('ignore'); $result = array(); foreach ($list as $k => $lfile) { if (is_dir($lfile)) { continue; } $good = true; $lfile = str_replace('\\', '/', $lfile); $fName = $lfile; if (is_dir($fName)) { $fName .= '/'; } foreach ($ignore as $string) { if (strpos($fName, $string) !== false) { $good = false; break; } } if ($good) { $nameHash = md5($lfile); $fileHash = md5_file($lfile); $result[$nameHash] = array('file' => $lfile, 'md5' => $fileHash); } } if ($toFile !== false) { return Utils::exportArray($toFile, $result); } else { return $result; } }
/** * Scan FS for class files * @return array */ protected function scanFs() { $dirs = $this->config->get('locations'); $exceptions = $this->config->get('exceptions'); $files = $dirs; foreach ($dirs as $path) { $items = File::scanFiles($path, array('.php'), true); $files = array_merge($files, $items); } if (!empty($files)) { foreach ($exceptions as $item) { foreach ($files as $k => $filepath) { if (strpos($filepath, $item) !== false) { unset($files[$k]); } } } } $this->output('Found ' . count($files) . ' files.'); return array_values($files); }
protected function _updateFromSystem($from) { $files = File::scanFiles($from); if (empty($files)) { $this->_errorStatus = self::ERROR_EMPTY_BACKUP; return false; } $pathsToCheck = array(); if ($this->sql) { foreach ($files as $key => $file) { if (strrchr($file, '.') === '.sql') { $this->_sqlPaths[] = $file; unset($files[$key]); } $pathsToCheck[] = str_replace($from, $this->_docRoot, $file); } } $permCheck = File::checkWritePermission($pathsToCheck); if ($permCheck !== true) { $this->_errorStatus = self::ERROR_CANT_WRITE; $this->_errors = $permCheck; return false; } if ($this->execSql && !empty($this->_sqlPaths)) { foreach ($this->_sqlPaths as $path) { if (!$this->_restoreSql($path)) { $this->_errorStatus = self::ERROR_SQL_FAIL; return false; } if (file_exists($path)) { unlink($path); } } } if (!File::copyFiles($this->_docRoot, $files, $from)) { $this->_errorStatus = self::ERROR_CANT_WRITE; return false; } else { return true; } }
public function projectlistAction() { $path = Request::post('node', 'string', ''); $path = str_replace('.', '', $path); $dirPath = $this->_config->get('configs'); if (!is_dir($dirPath)) { Response::jsonArray(array()); } $files = File::scanFiles($dirPath . $path, array('.dat'), false, File::Files_Dirs); if (empty($files)) { Response::jsonArray(array()); } $list = array(); foreach ($files as $k => $fpath) { $text = basename($fpath); if ($text === '.svn') { continue; } $obj = new stdClass(); $obj->id = str_replace($dirPath, '', $fpath); $obj->text = $text; if (is_dir($fpath)) { $obj->expanded = false; $obj->leaf = false; } else { $obj->leaf = true; } $list[] = $obj; } Response::jsonArray($list); }
/** * Get deploy history */ public function viewHistoryAction() { $serverId = Request::post('server_id', 'pagecode', ''); $data = array(); if (!strlen($serverId)) { Response::jsonError($this->_lang->WRONG_REQUEST); } if (!is_dir($this->_deployConfig->get('datadir') . $serverId)) { Response::jsonArray($data); } $list = File::scanFiles($this->_deployConfig->get('datadir') . $serverId, false, false, File::Dirs_Only); if (!empty($list)) { foreach ($list as $k => $name) { $name = basename($name); $data[] = array('id' => $name, 'title' => $name); } } Response::jsonSuccess($data); }
/** * Files list */ public function fslistAction() { $path = Request::post('node', 'string', ''); //$path = str_replace('.','', $path); $dirPath = $this->_config->get('configs'); if ($path === '') { $path = $dirPath . $path; } if (!is_dir($dirPath)) { Response::jsonArray(array()); } $files = File::scanFiles($path, array('.dat'), false, File::Files_Dirs); $list = array(); if (!empty($files)) { $dirs = array(); $pfiles = array(); foreach ($files as $k => $fpath) { $text = basename($fpath); if ($text === '.svn') { continue; } if (is_dir($fpath)) { $dirs[] = $fpath; } else { $pfiles[] = $fpath; } } if (!empty($dirs)) { sort($dirs); foreach ($dirs as $k => $fpath) { $text = basename($fpath); $obj = new stdClass(); $obj->id = str_replace($this->_configMain->get('docroot'), './', $fpath); $obj->text = $text; $obj->expanded = false; $obj->leaf = false; $list[] = $obj; } } if (!empty($pfiles)) { sort($pfiles); foreach ($pfiles as $k => $fpath) { $text = basename($fpath); $obj = new stdClass(); $obj->id = str_replace($this->_configMain->get('docroot'), './', $fpath); $obj->text = $text; $obj->leaf = true; $list[] = $obj; } } } if ($path == '') { if ($this->_configMain->get('allow_externals')) { $config = Config::factory(Config::File_Array, $this->_configMain->get('configs') . 'externals.php'); $eExpert = new Externals_Expert($this->_configMain, $config); $extProjects = $eExpert->getProjects(); if (!empty($extProjects)) { foreach ($extProjects as $item) { $list[] = $item; } } } } Response::jsonArray($list); }
/** * Get list of ACL adapters */ public function listaclAction() { $list = array(array('id' => '', 'title' => '---')); $files = File::scanFiles('./system/app/Acl', array('.php'), true, File::Files_Only); foreach ($files as $v) { $path = str_replace('./system/app/', '', $v); $name = Utils::classFromPath($path); $list[] = array('id' => $name, 'title' => $name); } Response::jsonSuccess($list); }
/** * Create Database tables */ public function createtablesAction() { $mainCfgPath = $this->_docRoot . 'system/config/main.php'; $config = (include $mainCfgPath); $inlineConfig = Config::factory(Config::Simple, 'main'); $inlineConfig->setData($config); $app = new Application($inlineConfig); $app->init(); $zendDb = Model::getGlobalDbConnection(); $installDocs = $this->_session->get('install_docs'); $config = Config::factory(Config::File_Array, $this->_docRoot . 'install/cfg/cfg.php')->__toArray(); if ($installDocs) { try { $dbConfig = $zendDb->getConfig(); $cmd = 'mysql -h' . escapeshellarg($dbConfig['host']) . ' -P ' . escapeshellarg($dbConfig['port']) . ' -u' . escapeshellarg($dbConfig['username']) . ' -p' . escapeshellarg($dbConfig['password']) . ' -D' . escapeshellarg($dbConfig['dbname']) . ' < ' . escapeshellarg($this->_docRoot . $config['docs_sql']); if (system($cmd) === false) { throw new Exception('Cannot exec shell command: ' . $cmd); } } catch (Exception $e) { Response::jsonError($this->_dictionary['INSTALL_DOCS_ERROR'] . ' ' . $e->getMessage()); } } $paths = File::scanFiles($this->_docRoot . $config['configsPath'], array('.php'), false, File::Files_Only); foreach ($paths as &$v) { $v = substr(basename($v), 0, -4); } unset($v); $buildErrors = array(); if (!empty($paths)) { foreach ($paths as $v) { $dbObjectBuilder = new Db_Object_Builder($v); if (!$dbObjectBuilder->build()) { $buildErrors[] = $v; } } } if (!empty($buildErrors)) { Response::jsonError($this->_dictionary['BUILD_ERR'] . ' ' . implode(', ', $buildErrors)); } else { Response::jsonSuccess('', array('msg' => $this->_dictionary['DB_DONE'])); } }