/** * Generate rules for mod rewrite htaccess * @return string */ public static function generate_rewrite_rules() { $dirs = \System\Composer::list_dirs(\System\Loader::DIR_REWRITE); foreach ($dirs as $dir) { $od = opendir($dir); $files = array(); while ($file = readdir($od)) { if (strpos($file, '.') !== 0) { $files[$file] = \System\File::read($dir . '/' . $file); } } ksort($files); } return implode("\n", $files); }
/** Run list of init scripts * @param array $list List of init scripts * @param array $locals Local data * @return void */ public static function run(array $list, array $locals) { // Convert locals into level on variables foreach ((array) $locals as $k => $v) { $k = str_replace('-', '_', $k); ${$k} = $v; } $dirs = \System\Composer::list_dirs('/etc/init.d'); foreach ($list as $init_step) { $found = false; foreach ($dirs as $dir) { if (file_exists($f = $dir . '/' . $init_step . '.php')) { $found = true; require_once $f; break; } } if (!$found) { throw new \System\Error\File(sprintf("Init file '%s' was not found inside init folder '%s'.", $init_step, \System\Init::DIR_INIT)); } } }
public static function read($dir, $assoc_keys = false, &$files = array(), &$temp = array()) { $dirs = \System\Composer::list_dirs($dir); return \System\Json::read_dist_all($dirs, $assoc_keys, $files, $temp); }
/** Get list of available files from user input * @param string $type * @param list $modules * @return array */ public function get_file_list($modules) { $found = array(); $missing = array(); try { $use_cache = \System\Settings::get('cache', 'resources'); } catch (\System\Error\Config $e) { $use_cache = false; } if ($use_cache) { $dirs = array(BASE_DIR . $this::DIR_CACHE); } else { if ($this->src == 'static') { $src = $this::DIR_STATIC; } else { $src = $this::DIR_MEDIA; } $dirs = \System\Composer::list_dirs($src); } foreach ($modules as $module) { $mod_found = false; foreach ($dirs as $dir) { foreach ($this::$postfixes as $postfix) { $path = $dir . DIRECTORY_SEPARATOR . $module; if (file_exists($p = $path . '.list')) { $list = $this->get_file_list(array_map('trim', array_filter(explode("\n", \System\File::read($p))))); $found = array_merge($found, $list[self::KEY_FOUND]); $missing = array_merge($missing, $list[self::KEY_MISSING]); $mod_found = true; break; } else { if (is_file($p = $path) || is_file($p = $path . '.' . $postfix)) { $found[] = $p; $mod_found = true; } } if (is_dir($path)) { $json = null; $meta = self::get_meta($path, 'bower.json'); if (!$meta) { $meta = self::get_meta($path, 'package.json'); } if ($meta) { $files = array(); foreach ($meta as $file) { $files[] = str_replace($dir . '/', '', $path . '/' . $file); } $list = $this->get_file_list($files); $found = array_merge($found, $list[self::KEY_FOUND]); $mod_found = true; break; } else { $files = \System\Directory::find_all_files($path); foreach ($files as $key => $tmp_file) { $files[$key] = str_replace($dir . '/', '', $files[$key]); } $list = $this->get_file_list($files); $found = array_merge($found, $list[self::KEY_FOUND]); $missing = array_merge($missing, $list[self::KEY_MISSING]); $mod_found = true; break; } } } if ($mod_found) { break; } } if (!$mod_found) { $missing[] = $module; } } $this->sum = self::get_module_sum_from_list($modules); return array(self::KEY_FOUND => array_unique(array_filter($found)), self::KEY_MISSING => array_unique(array_filter($missing)), self::KEY_SUM => $this->sum); }
public static function autoload($class_name) { $sources = array('/lib/class', '/lib'); $found = false; $file = \System\Loader::get_class_file_name($class_name, true); $helper_pos = strpos(\System\Loader::get_link_from_class($class_name), 'helper'); $is_helper = $helper_pos !== false && $helper_pos <= 1; foreach ($sources as $key => $source) { $classes = \System\Composer::list_dirs($source); foreach ($classes as $dir) { if (file_exists($f = $dir . '/' . $file)) { $found = (include_once $f); break; } } if ($found) { break; } } }
private static function get_all() { return \System\Composer::list_dirs('/lib/test'); }
public function to_object() { if (!$this->mime) { $this->read_meta(); } $path = str_replace(\System\File::DIR, '', $this->get_path_relative()); $src = 'media'; $cname = $this::RESOURCE_CNAME; $stat = $cname::DIR_STATIC; try { $cache = \System\Settings::get('cache', 'resources'); } catch (\System\Error $e) { $cache = false; } if ($cache) { $dirs = array($stat); } else { $dirs = \System\Composer::list_dirs($stat); array_unshift($dirs, $stat); } foreach ($dirs as $dir) { if (strpos($path, $dir) === 0 || strpos($path, $dir = substr($dir, 1)) === 0) { $path = substr($path, strlen($dir)); $src = 'static'; break; } } $url = \System\Resource::get_url($src, self::RESOURCE_TYPE, preg_replace("/^\\//", '', $path)); return array("url" => $url, "path" => $path, "name" => $this->name, "mime" => $this->mime, "size" => $this->size, "method" => $this->method ? $this->method : 'save'); }