function execute() { $file_or_folder = $this->file_or_folder; if (self::$dummy_mode) { echo "Adding : " . $file_or_folder . "<br />"; return; } $root_dir_path = self::$root_dir->getPath(); $file_or_folder = str_replace("\\", "/", $file_or_folder); $file_list = array(); //se finisce con lo slash è una directory if (substr($file_or_folder, strlen($file_or_folder) - 1, 1) == "/") { //creo la cartella $target_dir = new Dir(DS . $root_dir_path . $file_or_folder); $target_dir->touch(); $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder); foreach ($source_dir->listFiles() as $elem) { if ($elem->isDir()) { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getName() . DS)); } else { $file_list = array_merge($file_list, $this->add($file_or_folder . $elem->getFilename())); } } } else { $source_file = new File($this->module_dir->getPath() . $file_or_folder); $target_file = new File($root_dir_path . $file_or_folder); $target_dir = $target_file->getDirectory(); $target_dir->touch(); $source_file->copy($target_dir); $file_list[] = $target_dir->newFile($source_file->getFilename())->getPath(); } return $file_list; }
static function randomFromFolder($path, $autocache = true, $include_sub_dirs = false) { $dir = new Dir($path); if (!$dir->exists()) { Log::error("FileUtils::randomFromFolder", "La cartella {$path} non esiste!!"); } if (!$dir->isDir()) { Log::error("FileUtils::randomFromFolder", "Il percorso {$path} non rappresenta una cartella!!"); } $results = $dir->listFiles(); $valid_results = array(); foreach ($results as $dir_elem) { if ($dir_elem->isDir() && $include_sub_dirs) { $valid_results[] = $dir_elem; } if ($dir_elem->isFile()) { $valid_results[] = $dir_elem; } } if (count($valid_results) == 0) { Log::error("FileUtils::randomFromFolder", "Non sono stati trovati risultati validi!!"); } $selected = $valid_results[rand(0, count($valid_results) - 1)]; $final_result = $selected->getPath(); if ($autocache) { $final_result .= "?mtime=" . $selected->getModificationTime(); } return $final_result; }
function testRemove() { $module_plug_test_root = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/"); $target_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/"); $plug = new DirBridge($target_dir, new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/")); $sub_dir = $module_plug_test_root->newSubdir("blocks"); $block_file = $sub_dir->newFile("test.block.php"); $block_file->setContent("BLA BLA BLA"); $this->assertTrue($block_file->exists(), "Il file test.block.php non e' presente!!"); $plug->remove("blocks/test.block.php"); $this->assertFalse($block_file->exists(), "Il file test.block.php non e' stato rimosso!!"); $js_dir = $module_plug_test_root->newSubdir("js"); $js_dir->touch(); $my_js_lib_subdir = $js_dir->newSubdir("my_js_lib"); $my_js_lib_subdir->touch(); $mylib_file = $my_js_lib_subdir->newFile("mylib.js"); $mylib_file->setContent("HELLO!!"); $this->assertTrue($mylib_file->exists(), "Il file non e' stato creato!!"); $mylib3_file = $my_js_lib_subdir->newFile("mylib3.js"); $mylib3_file->setContent("WORLD!!"); $this->assertTrue($mylib3_file->exists(), "Il file non e' stato creato!!"); $plug->remove("js/"); $this->assertFalse($mylib_file->exists(), "Il file mylib.js non e' stato rimosso!!"); $this->assertTrue($mylib3_file->exists(), "Il file mylib3.js e' stato rimosso!!"); $all_module_plug_files = $module_plug_test_root->listFiles(); foreach ($all_module_plug_files as $ff) { $ff->delete(true); } }
static function get_available_module_archives() { $d = new Dir(self::MODULES_ARCHIVE_DIR); $d->touch(); $d = new Dir(self::MODULES_ARCHIVE_DIR); $all_files = $d->listFiles(); $result = array(); foreach ($all_files as $ff) { $result[] = $ff->getName(); } return $result; }
function testExtractArchive() { $create_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/zip_test/create/"); $this->assertTrue($create_dir->exists(), "La directory create non esiste!!"); $save_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/zip_test/saved/"); $this->assertTrue($save_dir->exists(), "La directory save non esiste!!"); $extract_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/zip_test/extract/"); $this->assertTrue($extract_dir->exists(), "La directory extract non esiste!!"); $extract_dir_files = $extract_dir->listFiles(); foreach ($extract_dir_files as $f) { $f->delete(true); } $target_file = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/zip_test/saved/test_archive.zip"); $this->assertFalse($target_file->exists()); $dir_to_zip = "/" . FRAMEWORK_CORE_PATH . "tests/io/zip_test/create/"; ZipUtils::createArchive($target_file, $dir_to_zip); $this->assertTrue($target_file->exists(), "Il file zip non è stato creato!!"); $this->assertTrue($target_file->getSize() > 0, "Il file creato ha dimensione vuota!!"); //ora estraggo l'archivio $extract_root = "/" . FRAMEWORK_CORE_PATH . "tests/io/zip_test/extract/"; ZipUtils::expandArchive($target_file, $extract_root); $this->assertEqual(count($extract_dir->listFiles()), 3, "Il numero dei file estratti non corrisponde!!"); $f1 = new File($extract_root . "my_file_01.php"); $this->assertTrue($f1->exists(), "Il file my_file_01.php non e' stato estratto!!"); $this->assertTrue(!$f1->isEmpty(), "Il file my_file_01.php e' vuoto!!"); $d1 = new Dir($extract_root . "another_dir/"); $d2 = new Dir($extract_root . "my_subdir/"); $f2 = new File($extract_root . "another_dir/blabla.ini"); $this->assertTrue($f2->exists(), "Il file blabla.ini non e' stato estratto!!"); $this->assertTrue(!$f2->isEmpty(), "Il file blabla.ini e' vuoto!!"); $saved_files = $save_dir->listFiles(); foreach ($saved_files as $f) { $f->delete(true); } $extracted_files = $extract_dir->listFiles(); foreach ($extracted_files as $f) { $f->delete(true); } }
public static function unzipModule($fullPath, $remove = 'no') { if (!preg_match('/.*?\\.(zip|rar)/i', $fullPath)) { return false; } $zip = new Unzip($fullPath); $zip->extract(); if ($remove != 'no') { unlink($fullPath); } $dirPath = dirname($fullPath) . '/'; $listFiles = Dir::listFiles($dirPath); return $listFiles; }
public static function load_from_dir($dir) { if ($dir instanceof Dir) { $my_dir = $dir; } else { $my_dir = new Dir($dir); } self::$css_dirs[] = $my_dir; //CSS_DIRS if ($my_dir->exists() && $my_dir->isDir()) { $file_list = $my_dir->listFiles(); foreach ($file_list as $f) { if ($f->isFile() && $f->getExtension() == "css") { self::require_css_file($f); } } } else { Log::warn("load_from_dir", "Impossibile caricare i css dalla directory : " . $my_dir->getName()); } }
function get_rotator() { $result = array(); $result["rotator_name"] = Params::get("name"); $result["image_list"] = array(); $d = new Dir(self::ROTATOR_GALLERIES_ROOT_PATH . $result["rotator_name"] . "/"); if ($d->exists()) { $files = $d->listFiles(); foreach ($files as $f) { if ($f->isFile()) { $img = array(); $img["path"] = $f->getPath(); $img["title"] = str_replace("_", " ", $f->getName()); $result["image_list"][] = $img; } } } else { echo "Rotator gallery directory not found! : " . $d->getPath(); } return $result; }
function get_gallery() { $gallery_name = Params::get("gallery_name"); $result = array(); $result["gallery_name"] = $gallery_name; $d = new Dir(self::GALLERY_ROOT_PATH . $gallery_name); $files = $d->listFiles(); $image_list = array(); foreach ($files as $f) { if ($f->isFile() && $f->getExtension() != ".ini") { $image = array(); $image["path"] = $f->getPath(); $image["title"] = str_replace("_", " ", $f->getName()); $image_list[$f->getFilename()] = $image; } } $gallery_dir = new Dir(self::GALLERY_ROOT_PATH . $gallery_name . DS); $found_files = $gallery_dir->findFilesEndingWith("gallery.ini"); if (count($found_files) > 0) { $gallery_ini_file = $found_files[0]; $gallery_props = PropertiesUtils::readFromFile($gallery_ini_file, true); $enhanced_image_list = array(); foreach ($section as $s) { $path = $s["path"]; if (strpos($path, "DS") === 0) { $new_image["path"] = $path; } else { $new_image["path"] = self::GALLERY_ROOT_PATH . $gallery_name . $s["path"]; } $f = new File($new_image["path"]); $new_image["title"] = isset($s["title"]) ? $s["title"] : str_replace("_", " ", $f->getName()); $new_image["description"] = isset($s["description"]) ? $s["description"] : null; $enhanced_image_list[] = $new_image; } $result["image_list"] = $enhanced_image_list; } else { $result["image_list"] = $image_list; } return $result; }
function testAdd() { $module_plug_test_root = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/"); $module_plug_test_root->newSubdir("blocks")->touch(); ModulePlug::setRootDir($module_plug_test_root->getPath()); $plug = new ModulePlug(new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/")); $plug->add("js/"); $plug->add("blocks/test.block.php"); $f_block = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/blocks/test.block.php"); $this->assertTrue($f_block->exists(), "Il file test.block.php non e' stato copiato!!"); $f_no_plug = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/blocks/no_plug.block.php"); $this->assertFalse($f_no_plug->exists(), "Il file no_plug.block.php e' stato copiato!!"); $f_jslib1 = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/js/my_js_lib/mylib.js"); $this->assertTrue($f_jslib1->exists(), "Il file libreria js1 non e' stato copiato!!"); $f_jslib2 = new File("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/js/my_js_lib/mylib2.js"); $this->assertTrue($f_jslib2->exists(), "Il file libreria js2 non e' stato copiato!!"); ModulePlug::setRootDir("/"); $all_module_plug_files = $module_plug_test_root->listFiles(); foreach ($all_module_plug_files as $ff) { $ff->delete(true); } }
function execute() { $file_or_folder = $this->file_or_folder; $force = $this->force; if (self::$dummy_mode) { echo "Removing : " . $file_or_folder . "<br />"; return; } $root_dir_path = self::$root_dir->getPath(); //se è una cartella elimino solo i file che sono anche nel modulo if (FileSystemUtils::isDir($this->module_dir->getPath() . $file_or_folder)) { $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder); $target_dir = new Dir($root_dir_path . $file_or_folder); if (!$target_dir->exists()) { return; } $toremove_files = $source_dir->listFiles(); foreach ($toremove_files as $elem) { if ($elem->isDir()) { $this->remove($file_or_folder . $elem->getName() . DS); } else { $this->remove($file_or_folder . $elem->getFilename()); } } if ($target_dir->isEmpty()) { $target_dir->delete(false); } } else { $source_file = new File($this->module_dir->getPath() . $file_or_folder); $target_file = new File($root_dir_path . $file_or_folder); if (!$force && !$source_file->exists()) { return; } //se non esiste nel modulo non lo rimuovo $target_file->delete(); } }
public static function loadByLang($result, $lang, $dir, $recursive = false) { if ($dir instanceof Dir) { $props_dir = new Dir($dir); } else { $props_dir = new Dir($dir); } $all_files = $props_dir->listFiles(); foreach ($all_files as $f) { if ($f->isDir() && $recursive) { $result = array_merge($result, self::loadByLang($result, $lang, $f, true)); } if ($f->isFile()) { $full_extension = $f->getFullExtension(); $ext_parts = explode(".", $full_extension); if (count($ext_parts) == 2 && $ext_parts[1] == "ini") { $lang_part = $ext_parts[0]; if (substr($lang_part, 0, strlen($lang)) == $lang) { $result = array_merge($result, PropertiesUtils::readFromFile($f, false)); } } } } }
static function getAll($folder) { $real_storage_dir = Storage::get_verified_storage(); $result = array(); $folder_dir = new Dir($real_storage_dir->getPath() . $folder . DS); if (!$folder_dir->exists()) { $real_storage_dir->newSubdir($folder); } $all_storages_files = $folder_dir->listFiles(); foreach ($all_storages_files as $f) { if ($f->isFile()) { $result[] = Storage::byExtension($folder, $f->getName(), $f->getExtension()); } } return $result; }
function testCreateStorageOnWrite() { Storage::set_storage_root(DS . FRAMEWORK_CORE_PATH . "tests/io/storage_dir/"); $d = new Dir(DS . FRAMEWORK_CORE_PATH . "tests/io/storage_dir/"); foreach ($d->listFiles() as $f) { $f->delete(true); } $this->assertFalse($d->hasSingleSubdir(), "Lo storage e' gia' presente!!"); $storage = Storage::getPropertiesStorage("boh", "ciccia"); $this->assertFalse($storage->exists(), "Lo storage esiste gia'!!"); $test_props = array("test" => "value", "hello" => "world"); $storage->add("category", $test_props); $this->assertTrue($storage->exists(), "Lo storage non e' stato creato!!"); $storage->delete(); $this->assertFalse($storage->exists(), "Lo storage non e' stato eliminato!!"); $properties = $storage->readAll(); //readAll $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una lettura!!"); $this->assertFalse($properties === null, "Il risultato ritornato e' ===null !!"); $this->assertTrue(is_array($properties), "Il metodo non ha ritornato un array con uno storage inesistente!!"); $this->assertTrue(count($properties) == 0, "L'array ritornato da una lettura di storage vuoto non e' vuoto!!"); $storage->delete(); $storage->remove("blah"); //remove $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una cancellazione!!"); $storage->delete(); $storage->saveAll(array()); //saveAll $this->assertTrue($storage->exists(), "Lo storage non e' stato creato per una cancellazione!!"); $storage->delete(); $this->assertFalse($storage->exists(), "Lo storage non e' stato eliminato!!"); foreach ($d->listFiles() as $f) { $f->delete(true); } Storage::set_storage_root(Storage::get_default_storage_root()); }
function get_gallery() { $gallery_name = Params::get("gallery_name"); $result = array(); $result["gallery_name"] = $gallery_name; $d = new Dir(self::GALLERY_ROOT_PATH . "/" . $gallery_name); $files = $d->listFiles(); $image_list = array(); foreach ($files as $f) { if ($f->isFile() && $f->getExtension() != "ini") { $image = array(); $image["path"] = $f->getPath(); $image["title"] = str_replace("_", " ", $f->getName()); $image["name"] = $f->getFilename(); $image["type"] = "image"; $image_list[] = $image; } } $result["image_list"] = $image_list; return $result; }
<?php $dir = new Dir("/immagini/grafica/layouts/simplesamplesite_interno/le_collezioni/"); $all_files = $dir->listFiles(); $selected = $all_files[rand(0, count($all_files) - 1)]; set_sector("/immagine_sfondo", $selected->getPath()); $contenuto = call("testi", "by_chiave", array("chiave" => "le_collezioni")); Html::set_title("Le collezioni - SimpleSampleSite"); Html::set_layout("simplesamplesite_interno"); include "include/layouts/page_common.php.inc"; start_sector("/contenuto"); echo $contenuto["testo"]; end_sector(); start_sector("/main_menu"); MenuBuilder::build("main", "/contenuti/it/"); end_sector(); start_sector("/citazione/testo"); ?> It is hard to say how much time a customer will take to respond to an email. Sometimes dragons start popping outside, or meteor start falling nearby ... who knows? Everything can happen. <?php end_sector(); set_sector("/citazione/firma", "DevelDevelDevel Guy");
function testDeleteEmptyWithHidden() { $is_local = strpos($_SERVER["HTTP_HOST"], ".") === false; if ($is_local) { $d = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/delete_test_dir_empty/the_dir/"); $this->assertTrue($d->exists(), "La cartella dal eliminare non esiste!!"); if (count($d->listFiles(Dir::SHOW_HIDDEN_FILES)) == 0) { $d->delete(); $this->assertFalse($d->exists(), "La cartella dal eliminare e' stata eliminata!!"); } else { $d->delete(); $this->assertTrue($d->exists(), "La cartella dal eliminare non e' stata eliminata!!"); } $d->touch(); } }