This class makes it easy to create/edit/delete directories on the filesystem
コード例 #1
0
ファイル: Dir.class.php プロジェクト: remco-pc/System
 public function read($url = '', $recursive = false, $format = 'flat')
 {
     if (substr($url, -1) !== Application::DS) {
         $url .= Application::DS;
     }
     if ($this->ignore('find', $url)) {
         return array();
     }
     $list = array();
     $cwd = getcwd();
     chdir($url);
     if ($handle = opendir($url)) {
         while (false !== ($entry = readdir($handle))) {
             $recursiveList = array();
             if ($entry == '.' || $entry == '..') {
                 continue;
             }
             $file = new stdClass();
             $file->url = $url . $entry;
             if (is_dir($file->url)) {
                 $file->url .= Application::DS;
                 $file->type = 'dir';
             }
             if ($this->ignore('find', $file->url)) {
                 continue;
             }
             $file->name = $entry;
             if (isset($file->type)) {
                 if (!empty($recursive)) {
                     $directory = new dir();
                     $directory->ignore('list', $this->ignore());
                     $recursiveList = $directory->read($file->url, $recursive, $format);
                     if ($format !== 'flat') {
                         $file->list = $recursiveList;
                         unset($recursiveList);
                     }
                 }
             } else {
                 $file->type = 'file';
             }
             if (is_link($entry)) {
                 $file->link = true;
             }
             /* absolute url is_link wont work probably the targeting type
             			if(is_link($file->url)){
             				$file->link = true;
             			}
             			*/
             $list[] = $file;
             if (!empty($recursiveList)) {
                 foreach ($recursiveList as $recursive_nr => $recursive_file) {
                     $list[] = $recursive_file;
                 }
             }
         }
     }
     closedir($handle);
     return $list;
 }
コード例 #2
0
ファイル: Uninstall.php プロジェクト: getkirby/cli
 protected function uninstall($plugin, $output)
 {
     $root = $this->kirby()->roots()->plugins() . DS . $plugin;
     dir::remove($root);
     $output->writeln('<comment>The "' . $plugin . '" plugin has been removed!</comment>');
     $output->writeln('');
 }
コード例 #3
0
ファイル: mediaUtils.php プロジェクト: pasterntt/dynao-CMS
 public static function deleteFile($id)
 {
     $values = [];
     for ($i = 1; $i <= 10; $i++) {
         $values[] = '`media' . $i . '` = ' . $id;
     }
     for ($i = 1; $i <= 10; $i++) {
         $values[] = '`medialist' . $i . '` LIKE "%|' . $id . '|%"';
     }
     $sql = sql::factory();
     $sql->query('SELECT id FROM ' . sql::table('structure_area') . ' WHERE ' . implode(' OR ', $values))->result();
     if ($sql->num()) {
         echo message::warning(lang::get('file_in_use'));
     } else {
         $sql = sql::factory();
         $sql->setTable('media');
         $sql->setWhere('id=' . $id);
         $sql->select('filename');
         $sql->result();
         if (unlink(dir::media($sql->get('filename')))) {
             $sql->delete();
             return message::success(lang::get('file_deleted'), true);
         } else {
             return message::warning(sprintf(lang::get('file_not_deleted'), dyn::get('hp_url'), $sql->get('filename')), true);
         }
     }
 }
コード例 #4
0
 static function uninstall()
 {
     graphics::remove_rules("watermark");
     module::delete("watermark");
     Database::instance()->query("DROP TABLE `watermarks`");
     dir::unlink(VARPATH . "modules/watermark");
 }
コード例 #5
0
ファイル: mentions.php プロジェクト: aizlewood/2016
 public function __construct($params = array())
 {
     $defaults = array('page' => page(), 'headline' => 'Mentions');
     if (is_a($params, 'Page')) {
         $params = array('page' => $params);
     } else {
         if (is_string($params)) {
             $params = array('headline' => $params);
         }
     }
     $this->options = array_merge($defaults, $params);
     $this->page = $this->options['page'];
     $this->root = $this->page->root() . DS . '.webmentions';
     $this->headline = new Field($this->page, 'headline', $this->options['headline']);
     if (!is_dir($this->root)) {
         return;
     }
     $files = dir::read($this->root);
     // flip direction
     rsort($files);
     foreach ($files as $file) {
         // skip the pings cache
         if ($file == 'pings.json') {
             continue;
         }
         // register a new webmention
         try {
             $mention = new Mention($this->page, $this->root . DS . $file);
             $this->append($mention->id(), $mention);
         } catch (Exception $e) {
         }
     }
 }
コード例 #6
0
 protected function checkAvatars()
 {
     $root = kirby()->roots()->avatars();
     // try to create the avatars folder
     dir::make($root);
     return is_writable($root);
 }
コード例 #7
0
 function _clean_up()
 {
     parent::_clean_up();
     dir::rm(MEDIA_DIR);
     $this->db->sql_delete('file_object');
     $this->db->sql_delete('media');
 }
コード例 #8
0
 function write($log_file_data, $string)
 {
     $log_dir = $log_file_data[0];
     $log_name = $log_file_data[1];
     $file_name = $log_dir . $log_name;
     if (!is_dir($log_dir)) {
         dir::mkdir($log_dir, 0775, true);
     }
     $oldumask = @umask(0);
     $file_existed = @file_exists($file_name);
     $log_file = @fopen($file_name, 'a');
     if ($log_file) {
         $time = strftime("%b %d %Y %H:%M:%S", strtotime('now'));
         $notice = '[ ' . $time . " ]\n";
         if ($user_id = user::get_id()) {
             $notice .= '[ ' . $user_id . ' ] [ ' . user::get_login() . ' ] [ ' . user::get_email() . ' ] ';
         }
         $notice .= '[' . sys::client_ip() . '] [' . (isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '') . "]\n" . $string . "\n\n";
         @fwrite($log_file, $notice);
         @fclose($log_file);
         if (!$file_existed) {
             @chmod($file_name, 0664);
         }
         @umask($oldumask);
         $result = true;
     } else {
         @umask($oldumask);
         $result = false;
         debug::write_error("Cannot open log file '{$file_name}' for writing\n" . "The web server must be allowed to modify the file.\n" . "File logging for '{$file_name}' is disabled.", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, false);
     }
     return $result;
 }
コード例 #9
0
 function _update_media_record($id, $tmp_file_path, $file_name, $mime_type)
 {
     if (!file_exists($tmp_file_path)) {
         debug::write_error('file doesnt exist', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('tmp' => $tmp_file_path));
         return false;
     }
     if (function_exists('md5_file')) {
         $etag = md5_file($tmp_file_path);
     } else {
         $fd = fopen($data['tmp_name'], 'rb');
         $contents = fread($fd, filesize($tmp_file_path));
         fclose($fd);
         $etag = md5($contents);
     }
     if (!is_dir(MEDIA_DIR)) {
         dir::mkdir(MEDIA_DIR, 777, true);
     }
     if (!copy($tmp_file_path, MEDIA_DIR . $id . '.media')) {
         debug::write_error('temporary file copy failed', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('src' => $tmp_file_path, 'dst' => MEDIA_DIR . $id . '.media'));
         return false;
     }
     $media_db_table = db_table_factory::instance('media');
     $media_db_table->update_by_id($id, array('file_name' => $file_name, 'mime_type' => $mime_type, 'size' => filesize($tmp_file_path), 'etag' => $etag));
     return true;
 }
コード例 #10
0
ファイル: module.php プロジェクト: dalinhuang/zotop
 public function getUnInstalled()
 {
     $installed = (array) $this->getInstalled();
     $folders = dir::folders(ZPATH_MODULES, '.', false);
     $folders = array_diff($folders, array_keys($installed));
     $modules = array();
     foreach ($folders as $folder) {
         $modulePath = ZPATH_MODULES . DS . $folder;
         $moduleUrl = url::modules() . '/' . $folder;
         $moduleFile = $modulePath . DS . 'module.php';
         if (file::exists($moduleFile)) {
             $m = (include $moduleFile);
             $m['path'] = '$modules/' . $folder;
             $m['url'] = '$modules/' . $folder;
             if (!isset($m['icon'])) {
                 if (!file::exists($modulePath . '/icon.png')) {
                     $m['icon'] = url::theme() . '/image/skin/none.png';
                 } else {
                     $m['icon'] = $moduleUrl . '/icon.png';
                 }
             }
             $modules[$m['id']] = $m;
         }
     }
     return $modules;
 }
コード例 #11
0
ファイル: autoload.php プロジェクト: pasternt/dynaoCMS
 /**
  * Die eigentliche Funktion des Autoloader
  *
  * @param	string	$class			Der Klassennamen
  * @return	bool
  */
 public static function autoloader($class)
 {
     if (self::classExists($class)) {
         return true;
     }
     preg_match_all("/(?:^|[A-Z])[a-z]+/", $class, $treffer);
     $classPath = implode(DIRECTORY_SEPARATOR, array_map('strtolower', $treffer[0]));
     if (isset(self::$classes[$class])) {
         if (is_readable(self::$classes[$class])) {
             self::addClass($class, self::$classes[$class]);
             if (self::classExists($class)) {
                 return true;
             }
         }
         // Datei im Cache drin, jedoch exsistiert sie nichtmehr
         unset(self::$classes[$class]);
         self::$isNewCache = true;
     }
     if (is_readable(dir::classes($classPath . '.php'))) {
         self::addClass($class, dir::classes($classPath . '.php'));
     }
     if (self::classExists($class)) {
         return true;
     }
     $classPath = self::$composer->findFile($class);
     if (!is_null($classPath)) {
         self::addClass($class, $classPath);
     }
     return self::classExists($class);
 }
コード例 #12
0
ファイル: thumb.php プロジェクト: getkirby/toolkit
 /**
  * Constructor
  *
  * @param mixed $source
  * @param array $params
  */
 public function __construct($source, $params = array())
 {
     $this->source = $this->result = is_a($source, 'Media') ? $source : new Media($source);
     $this->options = array_merge(static::$defaults, $this->params($params));
     $this->destination = $this->destination();
     // don't create the thumbnail if it's not necessary
     if ($this->isObsolete()) {
         return;
     }
     // don't create the thumbnail if it exists
     if (!$this->isThere()) {
         // try to create the thumb folder if it is not there yet
         dir::make(dirname($this->destination->root));
         // check for a valid image
         if (!$this->source->exists() || $this->source->type() != 'image') {
             throw new Error('The given image is invalid', static::ERROR_INVALID_IMAGE);
         }
         // check for a valid driver
         if (!array_key_exists($this->options['driver'], static::$drivers)) {
             throw new Error('Invalid thumbnail driver', static::ERROR_INVALID_DRIVER);
         }
         // create the thumbnail
         $this->create();
         // check if creating the thumbnail failed
         if (!file_exists($this->destination->root)) {
             return;
         }
     }
     // create the result object
     $this->result = new Media($this->destination->root, $this->destination->url);
 }
コード例 #13
0
ファイル: packager.php プロジェクト: scarygary/gallery3
 private function _reset()
 {
     $db = Database::instance();
     // Drop all tables
     foreach ($db->list_tables() as $table) {
         $db->query("DROP TABLE IF EXISTS `{$table}`");
     }
     // Clean out data
     dir::unlink(VARPATH . "uploads");
     dir::unlink(VARPATH . "albums");
     dir::unlink(VARPATH . "resizes");
     dir::unlink(VARPATH . "thumbs");
     dir::unlink(VARPATH . "modules");
     dir::unlink(VARPATH . "tmp");
     $db->clear_cache();
     module::$modules = array();
     module::$active = array();
     // Use a known random seed so that subsequent packaging runs will reuse the same random
     // numbers, keeping our install.sql file more stable.
     srand(0);
     gallery_installer::install(true);
     module::load_modules();
     foreach (array("user", "comment", "organize", "info", "rss", "search", "slideshow", "tag") as $module_name) {
         module::install($module_name);
         module::activate($module_name);
     }
 }
コード例 #14
0
ファイル: dyn.php プロジェクト: pasterntt/dynaoCMS
 public static function save()
 {
     if (!self::$isChange) {
         return true;
     }
     $newEntrys = array_merge(self::$params, self::$newEntrys);
     return file_put_contents(dir::backend('lib' . DIRECTORY_SEPARATOR . 'config.json'), json_encode($newEntrys, JSON_PRETTY_PRINT));
 }
コード例 #15
0
ファイル: config.php プロジェクト: pasterntt/dynao-CMS
 public static function getConfig($name)
 {
     $configFile = dir::addon($name, 'config.json');
     if (file_exists($configFile)) {
         return json_decode(file_get_contents($configFile), true);
     }
     return false;
 }
コード例 #16
0
ファイル: cache.php プロジェクト: narrenfrei/kirbycms
 static function flush()
 {
     $root = c::get('root.cache');
     if (!is_dir($root)) {
         return $root;
     }
     dir::clean($root);
 }
コード例 #17
0
ファイル: dataModelControl.php プロジェクト: com-itzcy/hdjob
 /**
  * 列出前台风格的模型视图界面
  */
 private function _listModaltpl()
 {
     $dir = array();
     $front_config = (include PATH_ROOT . '/config/app.php');
     $style = $front_config['TPL_DIR'] . '/' . $front_config['TPL_STYLE'];
     $dir = dir::tree($style . '/model');
     return $dir;
 }
コード例 #18
0
ファイル: cache.php プロジェクト: pasterntt/dynao-CMS
 public static function write($content, $id, $type = 'article')
 {
     $file = self::getFileName($id, $type);
     if (!file_put_contents(dir::cache(self::FOLDER . DIRECTORY_SEPARATOR . $file), $content, LOCK_EX)) {
         return false;
     }
     return true;
 }
コード例 #19
0
 function test_mkdir_windows()
 {
     if (sys::os_type() != 'win32') {
         return;
     }
     dir::mkdir(VAR_DIR . '/./tmp\\../tmp/wow////hey/', 0777, true);
     $this->assertTrue(is_dir(VAR_DIR . '/tmp/wow/hey/'));
 }
コード例 #20
0
ファイル: widgets.php プロジェクト: nsteiner/kdoc
 public function custom()
 {
     $kirby = kirby();
     $root = $kirby->roots()->widgets();
     foreach (dir::read($root) as $dir) {
         $kirby->registry->set('widget', $dir, $root . DS . $dir, true);
     }
 }
コード例 #21
0
ファイル: dyn_mailer.php プロジェクト: pasterntt/dynao-CMS
 public static function saveConfig($from, $fromName, $confirmReading, $bbc)
 {
     $config = dyn::get('addons')['phpmailer'];
     $config['settings']['from'] = $from;
     $config['settings']['fromName'] = $fromName;
     $config['settings']['confirmReading'] = $confirmReading;
     $config['settings']['bbc'] = $bbc;
     return file_put_contents(dir::addon('phpmailer', 'config.json'), json_encode($config, JSON_PRETTY_PRINT));
 }
コード例 #22
0
ファイル: g2_import.php プロジェクト: squadak/gallery3
 /**
  * Initialize the embedded Gallery 2 instance.  Call this before any other Gallery 2 calls.
  */
 static function init_embed($embed_path)
 {
     if (!is_file($embed_path)) {
         return false;
     }
     // Gallery 2 defines a class called Gallery.  So does Gallery 3.  They don't get along.  So do
     // a total hack here and copy over a few critical files (embed.php, main.php, bootstrap.inc
     // and Gallery.class) and munge them so that we can rename the Gallery class to be
     // G2_Gallery.   Is this retarded?  Why yes it is.
     //
     // Store the munged files in a directory that's the md5 hash of the embed path so that
     // multiple import sources don't interfere with each other.
     $mod_path = VARPATH . "modules/g2_import/" . md5($embed_path);
     if (!file_exists($mod_path) || !file_exists("{$mod_path}/embed.php")) {
         @dir::unlink($mod_path);
         mkdir($mod_path);
         $config_dir = dirname($embed_path);
         if (filesize($embed_path) > 200) {
             // Regular install
             $base_dir = $config_dir;
         } else {
             // Multisite install.  Line 2 of embed.php will be something like:
             //   require('/usr/home/bharat/public_html/gallery2/embed.php');
             $lines = file($embed_path);
             preg_match("#require\\('(.*)/embed.php'\\);#", $lines[2], $matches);
             $base_dir = $matches[1];
         }
         file_put_contents("{$mod_path}/embed.php", str_replace(array("require_once(dirname(__FILE__) . '/modules/core/classes/GalleryDataCache.class');", "require(dirname(__FILE__) . '/modules/core/classes/GalleryEmbed.class');"), array("require_once('{$base_dir}/modules/core/classes/GalleryDataCache.class');", "require('{$base_dir}/modules/core/classes/GalleryEmbed.class');"), array_merge(array("<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n"), file("{$base_dir}/embed.php"))));
         file_put_contents("{$mod_path}/main.php", str_replace(array("include(dirname(__FILE__) . '/bootstrap.inc');", "require_once(dirname(__FILE__) . '/init.inc');"), array("include(dirname(__FILE__) . '/bootstrap.inc');", "require_once('{$base_dir}/init.inc');"), array_merge(array("<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n"), file("{$base_dir}/main.php"))));
         file_put_contents("{$mod_path}/bootstrap.inc", str_replace(array("require_once(dirname(__FILE__) . '/modules/core/classes/Gallery.class');", "require_once(dirname(__FILE__) . '/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', dirname(__FILE__));", "\$gallery =& new Gallery();", "\$GLOBALS['gallery'] =& new Gallery();", "\$gallery = new Gallery();"), array("require_once(dirname(__FILE__) . '/Gallery.class');", "require_once('{$base_dir}/modules/core/classes/GalleryDataCache.class');", "define('GALLERY_CONFIG_DIR', '{$config_dir}');", "\$gallery =& new G2_Gallery();", "\$GLOBALS['gallery'] =& new G2_Gallery();", "\$gallery = new G2_Gallery();"), array_merge(array("<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n"), file("{$base_dir}/bootstrap.inc"))));
         file_put_contents("{$mod_path}/Gallery.class", str_replace(array("class Gallery", "function Gallery"), array("class G2_Gallery", "function G2_Gallery"), array_merge(array("<?php defined(\"SYSPATH\") or die(\"No direct script access.\") ?>\n"), file("{$base_dir}/modules/core/classes/Gallery.class"))));
     }
     require "{$mod_path}/embed.php";
     if (!class_exists("GalleryEmbed")) {
         return false;
     }
     $ret = GalleryEmbed::init();
     if ($ret) {
         return false;
     }
     $admin_group_id = g2(GalleryCoreApi::getPluginParameter("module", "core", "id.adminGroup"));
     $admins = g2(GalleryCoreApi::fetchUsersForGroup($admin_group_id, 1));
     $admin_id = current(array_flip($admins));
     $admin = g2(GalleryCoreApi::loadEntitiesById($admin_id));
     $GLOBALS["gallery"]->setActiveUser($admin);
     // Make sure we have an embed location so that embedded url generation comes out ok.  Without
     // this, the Gallery2 ModRewrite code won't try to do url generation.
     $g2_embed_location = g2(GalleryCoreApi::getPluginParameter("module", "rewrite", "modrewrite.embeddedLocation"));
     if (empty($g2_embed_location)) {
         $g2_embed_location = g2(GalleryCoreApi::getPluginParameter("module", "rewrite", "modrewrite.galleryLocation"));
         g2(GalleryCoreApi::setPluginParameter("module", "rewrite", "modrewrite.embeddedLocation", $g2_embed_location));
         g2($gallery->getStorage()->checkPoint());
     }
     self::$g2_base_url = $g2_embed_location;
     return true;
 }
コード例 #23
0
ファイル: runtime.php プロジェクト: dalinhuang/zotop
 /**
  * 打包全部的hook文件
  *
  */
 public static function hooks()
 {
     $modules = zotop::data('module');
     foreach ($modules as $module) {
         if ((int) $module['status'] >= 0 && dir::exists($module['path'])) {
             //只加载相应的hook文件
             runtime::$hooks[] = $module['path'] . DS . 'hooks' . DS . ZOTOP_APP_NAME . '.php';
         }
     }
 }
コード例 #24
0
ファイル: KirbytextTest.php プロジェクト: LucasFyl/korakia
 public function runTests($result)
 {
     $root = TEST_ROOT_ETC . DS . 'kirbytext';
     $dirs = dir::read($root);
     foreach ($dirs as $dir) {
         $testFile = $root . DS . $dir . DS . 'test.txt';
         $expectedFile = $root . DS . $dir . DS . 'expected.html';
         $this->assertEquals(f::read($expectedFile), $result(f::read($testFile)), 'test: ' . $dir);
     }
 }
コード例 #25
0
ファイル: Dir_Helper_Test.php プロジェクト: kandsten/gallery3
 public function remove_album_test()
 {
     $dirname = VARPATH . "albums/testdir";
     mkdir($dirname, 0777, true);
     $filename = tempnam($dirname, "file");
     touch($filename);
     dir::unlink($dirname);
     $this->assert_boolean(!file_exists($filename), "File not deleted");
     $this->assert_boolean(!file_exists($dirname), "Directory not deleted");
 }
コード例 #26
0
ファイル: cache.php プロジェクト: DINKIN/rokket
 public static function clear($folder = '')
 {
     if ($dir = opendir(dir::cache($folder))) {
         while (($file = readdir($dir)) !== false) {
             if (is_file($file)) {
                 self::deleteFile($file);
             }
         }
         closedir($dir);
     }
 }
コード例 #27
0
ファイル: page.php プロジェクト: pasternt/dynaoCMS
 public function getTemplate()
 {
     ob_start();
     $content = self::generateArticle($this->get('id'));
     $content = extension::get('FRONTEND_OUTPUT', $content);
     dyn::add('content', $content);
     include dir::template(dyn::get('template'), $this->get('template'));
     $content = ob_get_contents();
     ob_end_clean();
     return $content;
 }
コード例 #28
0
ファイル: games.php プロジェクト: DINKIN/rokket
 public static function getAll()
 {
     $handle = opendir(dir::games(''));
     while ($file = readdir($handle)) {
         if (in_array($file, ['.', '..'])) {
             continue;
         }
         self::$games[] = self::getConfig($file);
     }
     return self::$games;
 }
コード例 #29
0
 function get_classes_list()
 {
     $contents = array_merge(dir::ls(LIMB_DIR . '/core/model/site_objects/'), dir::ls(PROJECT_DIR . '/core/model/site_objects/'));
     $classes_list = array();
     foreach ($contents as $file_name) {
         if (substr($file_name, -10, 10) == '.class.php') {
             $classes_list[] = substr($file_name, 0, strpos($file_name, '.'));
         }
     }
     return $classes_list;
 }
コード例 #30
0
ファイル: widgets.php プロジェクト: LucasFyl/korakia
 public function custom()
 {
     $root = kirby()->roots()->widgets();
     foreach (dir::read($root) as $dir) {
         // add missing widgets to the order array
         if (!array_key_exists($dir, $this->order)) {
             $this->order[$dir] = true;
         }
         $this->load($dir, $root . DS . $dir . DS . $dir . '.php');
     }
 }