Beispiel #1
0
 function testRmdir()
 {
     $dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/module_plug_root/prova/");
     $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/"));
     $this->assertFalse($dir->exists(), "La directory c'e' gia'!!");
     $dir->touch();
     $this->assertTrue($dir->exists(), "La directory non e' stata creata!!");
     $plug->rmdir("prova");
     $this->assertFalse($dir->exists(), "La directory non e' stata eliminata!!");
 }
 function add()
 {
     if (Upload::isUploadSuccessful("my_file")) {
         $peer = new ImmaginiPeer();
         $do = $peer->new_do();
         $peer->setupByParams($do);
         $d = new Dir("/immagini/user/" . Session::get("/session/username") . Params::get("folder"));
         if (!$d->exists()) {
             $d->touch();
         }
         $do->save_folder = $d->getPath();
         $do->real_name = Upload::getRealFilename("my_file");
         $do->folder = Params::get("folder");
         $tokens = explode(".", Upload::getRealFilename("my_file"));
         $extension = $tokens[count($tokens) - 1];
         $do->hash_name = md5(uniqid()) . "." . strtolower($extension);
         Upload::saveTo("my_file", $do->save_folder, $do->hash_name);
         $peer->save($do);
         if (is_html()) {
             Flash::ok("Immagine aggiunta con successo.");
             return Redirect::success();
         } else {
             return ActiveRecordUtils::toArray($do);
         }
     } else {
         Flash::error(Upload::getUploadError("my_file"));
         return Redirect::failure();
     }
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 function testCompressUncompress()
 {
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/compress/test.ffa");
     $f->delete();
     FFArchive::compress($f, new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/compress/data/"));
     $ext_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/");
     $ext_dir->touch();
     $f = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/compress/test.ffa");
     $this->assertTrue($f->exists(), "Il file da decomprimere non esiste!!");
     FFArchive::extract($f, $ext_dir);
     $f1 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/cartella.png");
     $this->assertTrue($f1->exists(), "Il file cartella.png non e' stato estratto!!");
     $this->assertEqual($f1->getSize(), 441, "La dimensione di cartella.png non corrisponde!!");
     $f2 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/file1.txt");
     $this->assertTrue($f2->exists(), "Il file file1.txt non e' stato estratto!!");
     $f3 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/file2.dat");
     $this->assertTrue($f3->exists(), "Il file file2.dat non e' stato estratto!!");
     $d1 = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/empty_folder");
     $this->assertTrue($d1->exists(), "La cartella vuota non e' stata estratta!!");
     $d2 = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/folder");
     $this->assertTrue($d2->exists(), "La cartella folder non e' stata estratta!!");
     $f4 = new File("/" . FRAMEWORK_CORE_PATH . "tests/utils/extract/folder/sub/yep.txt");
     $this->assertTrue($f4->exists(), "Il file yep.txt non e' stato estratto!!");
     $this->assertEqual($f4->getSize(), 10, "La dimensione di yep.txt non corrisponde!!");
     $this->assertTrue($ext_dir->delete(true), "La directory coi file estratti non e' stata elimintata!!");
     $this->assertFalse($f1->exists(), "Il file cartella.png esiste ancora!!");
 }
Beispiel #5
0
 /**
  * Creates a directory
  *
  *  <code>
  *      Dir::create('folder1');
  *  </code>
  *
  * @param  string  $dir   Name of directory to create
  * @param  integer $chmod Chmod
  * @return boolean
  */
 public static function create($dir, $chmod = 0775)
 {
     // Redefine vars
     $dir = (string) $dir;
     // Create new dir if $dir !exists
     return !Dir::exists($dir) ? @mkdir($dir, $chmod, true) : true;
 }
 function add()
 {
     ini_set('upload_max_filesize', 8388608 * 4);
     if (Upload::isUploadSuccessful("my_file")) {
         $peer = new DocumentiPeer();
         $do = $peer->new_do();
         $peer->setupByParams($do);
         $d = new Dir("/documenti/user/" . Session::get("/session/username") . "/contenuti/");
         if (!$d->exists()) {
             $d->touch();
         }
         $do->save_folder = $d->getPath();
         $do->real_name = Upload::getRealFilename("my_file");
         $do->folder = Params::get("folder");
         $tokens = explode(".", Upload::getRealFilename("my_file"));
         $extension = $tokens[count($tokens) - 1];
         $do->hash_name = md5(uniqid()) . "." . strtolower($extension);
         Upload::saveTo("my_file", $do->save_folder, $do->hash_name);
         $peer->save($do);
         Flash::ok("Documento aggiunto con successo.");
         return Redirect::success();
     } else {
         return Redirect::failure(Upload::getUploadError("my_file"));
     }
 }
Beispiel #7
0
 static function set_modules_path($new_modules_path)
 {
     $dir = new Dir(DS . $new_modules_path);
     if (!$dir->exists()) {
         Log::error("ModuleUtils::set_modules_path", "Error : modules root directory must exist -> " . $new_modules_path);
     } else {
         self::$modules_path = $new_modules_path;
     }
 }
Beispiel #8
0
 /**
  * 
  * @param string absolute path to config file
  */
 function __construct(Dir $path)
 {
     if (!$path->exists()) {
         throw new RepositoryListException('Given path(' . $path . ') not exists.');
     }
     $this->path = $path;
     $this->list = $path->getFile('list.txt');
     $this->createContext();
 }
Beispiel #9
0
 static function list_files($plugin_path)
 {
     $plugin_dir = new Dir(self::DEFAULT_DIR . $plugin_path);
     $final_result = array();
     if ($plugin_dir->exists()) {
         $all_files = $plugin_dir->findFilesEndingWith(self::DEFAULT_EXTENSION);
         foreach ($all_files as $f) {
             $final_result[] = $f->getIncludePath();
         }
     }
     return $final_result;
 }
Beispiel #10
0
 function rename($new_name)
 {
     if (strstr($new_name, "/") !== false) {
         throw new InvalidParameterException("Il nome contiene caratteri non ammessi ( / )!!");
     }
     $parent_dir = $this->getParentDir();
     $target_path = $parent_dir->getPath() . "/" . $new_name;
     $target_dir = new Dir($target_path);
     if ($target_dir->exists()) {
         return false;
     }
     return rename($this->__full_path, $target_dir->getFullPath());
 }
 function __saveAttachedFile($do)
 {
     if ($this->__uploadMaxFilesize() != null) {
         ini_set('upload_max_filesize', $this->__uploadMaxFilesize());
     }
     $d = new Dir($this->__saveFolderPath());
     if (!$d->exists()) {
         $d->touch();
     }
     $do->save_folder = $d->getPath();
     $do->real_name = Upload::getRealFilename("my_file");
     $tokens = explode(".", Upload::getRealFilename("my_file"));
     $extension = $tokens[count($tokens) - 1];
     $do->hash_name = md5(uniqid()) . "." . strtolower($extension);
     Upload::saveTo("my_file", $do->save_folder, $do->hash_name);
 }
Beispiel #12
0
 function testExtractFromArchive()
 {
     $result_file = new File(ModuleArchiver::MODULES_ARCHIVE_DIR . "test__category-1_2_3.ffa");
     $this->assertFalse($result_file->exists(), "Il file del modulo non e' stato creato!!");
     ModuleUtils::set_modules_path("/" . FRAMEWORK_CORE_PATH . "tests/modules/fakeroot2/modules/");
     ModuleArchiver::save_as_archive("test", "category");
     ModuleUtils::set_modules_path("/" . FRAMEWORK_CORE_PATH . "tests/modules/fakeroot2/modules_out/");
     ModuleArchiver::extract_from_archive("test__category-1_2_3.ffa");
     $extracted_module_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/modules/fakeroot2/modules_out/test/category/");
     $this->assertTrue($extracted_module_dir->exists(), "La cartella del modulo non e' stata creata!!");
     $module_file = $extracted_module_dir->newFile(AvailableModules::MODULE_DEFINITION_FILE);
     $this->assertTrue($module_file->exists(), "Il file di definizione del modulo non esiste!!");
     $parent_module_dir = $extracted_module_dir->getParentDir();
     $parent_module_dir->delete(true);
     ModuleUtils::set_modules_path("/framework/modules/");
 }
Beispiel #13
0
 /**
  *
  */
 static function pack(Dir $source, File $target)
 {
     if (!$source->exists()) {
         throw new PackerException('Source folder ' . $source . ' not readable.');
     }
     if (!$target->getParent()->canWrite()) {
         throw new PackerException('Target file ' . $target . ' not writable.');
     }
     $cmd = str_replace(array('{FILE}', '{TARGET}'), array($source, $target), self::$config['pack_template']);
     exec($cmd, $out, $res);
     if ($res) {
         $out[] = PHP_EOL . 'Exit code: ' . $res . PHP_EOL;
         $f = Dir::get(Config::getInstance()->root_dir, true)->getDir(self::$config['logDir'])->getFile('pack_' . basename($source) . '.log');
         file_put_contents($f, implode(PHP_EOL, $out));
         throw new PackerException('Error while unpacking. Return code: ' . $res . '. Log file stored at ' . $f);
     }
 }
Beispiel #14
0
 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());
     }
 }
Beispiel #15
0
 /**
  * Template factory
  *
  *  <code>
  *      $template = Template::factory('templates_path');
  *  </code>
  *
  * @param string|Fenom\ProviderInterface $source path to templates or custom provider
  * @param string $compile_dir path to compiled files
  * @param int|array $options
  * @throws InvalidArgumentException
  * @return Fenom
  */
 public static function factory($source, $compile_dir = '/tmp', $options = 0)
 {
     // Create fenom cache directory if its not exists
     !Dir::exists(CACHE_PATH . '/fenom/') and Dir::create(CACHE_PATH . '/fenom/');
     // Create Unique Cache ID for Theme
     $theme_config_file = THEMES_PATH . '/' . Config::get('system.theme') . '/' . Config::get('system.theme') . '.yml';
     $theme_cache_id = md5('theme' . ROOT_DIR . $theme_config_file . filemtime($theme_config_file));
     // Set current them options
     if (Cache::driver()->contains($theme_cache_id)) {
         Config::set('theme', Cache::driver()->fetch($theme_cache_id));
     } else {
         $theme_config = Yaml::parseFile($theme_config_file);
         Config::set('theme', $theme_config);
         Cache::driver()->save($theme_cache_id, $theme_config);
     }
     $compile_dir = CACHE_PATH . '/fenom/';
     $options = Config::get('system.fenom');
     $fenom = parent::factory($source, $compile_dir, $options);
     $fenom->assign('config', Config::getConfig());
     return $fenom;
 }
 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;
 }
Beispiel #17
0
 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);
     }
 }
 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();
     }
 }
Beispiel #19
0
 public static function restore_table($table_name)
 {
     $backup_dir = new Dir(self::$current_backup_dir);
     if (!$backup_dir->exists()) {
         return false;
     }
     if (!DB::isConnectionOpen()) {
         $keep_open = false;
         DB::openDefaultConnection();
     } else {
         $keep_open = true;
     }
     $importer = DB::newTableDataImportExport();
     $importer->import_data_from_file(self::getTableBackupFile($table_name));
     if (!$keep_open) {
         DB::closeConnection();
     }
     return true;
 }
<?php

// Make sure the user has named the site
if (!defined("SITE_HANDLE")) {
    Alert::error("Invalid Site Name", "You must provide a valid Site Name.");
} else {
    if (!defined("DATABASE_NAME")) {
        Alert::error("Improper DB Name", "You must provide a valid Database Name.");
    }
}
// Make sure that there is a valid application path
if (!defined("APP_PATH")) {
    Alert::error("Improper App Path", "You must set a valid application or application path.");
} else {
    if (!Dir::exists(APP_PATH)) {
        Alert::error("Invalid App Path", "You must set a valid application or application path.");
    }
}
// If the server configuration are acceptable
if (Validate::pass()) {
    // Check if the form was submitted (to continue to the next page)
    if (Form::submitted("install-site-config")) {
        header("Location: /install/config-database");
        exit;
    }
    Alert::success("Site Config", "Your site configurations are valid!");
}
// Installation Header
require dirname(ROUTE_SECOND_PATH) . "/includes/install_header.php";
// Run Global Script
require dirname(ROUTE_SECOND_PATH) . "/includes/install_global.php";
Beispiel #21
0
if (version_compare(PHP_VERSION, "5.3.0", "<")) {
    exit("Panel requires PHP 5.3.0 or greater.");
}
// panel folder
$backend = 'admin';
// Separator
define('DS', DIRECTORY_SEPARATOR);
// Root directory
define('ROOT', rtrim(dirname(__FILE__), '\\/'));
// define access
define('PANEL_ACCESS', true);
// templates
define('TEMPLATES', ROOT . DS . 'templates');
// partials
define('PARTIALS', ROOT . DS . 'partials');
// views
define('VIEWS', ROOT . DS . 'views');
// define for out of admin  ../ folder
define('ROOTBASE', rtrim(str_replace(array($backend), array(''), dirname(__FILE__)), '\\/'));
include_once ROOT . DS . 'api' . DS . 'Morfy.panel.php';
include_once ROOT . DS . 'api' . DS . 'Morfy.routes.php';
// check if exist this folders
if (!Dir::exists(ROOTBASE . DS . 'public' . DS . 'images')) {
    Dir::create(ROOTBASE . DS . 'public' . DS . 'images');
}
if (!Dir::exists(ROOTBASE . DS . 'public' . DS . 'uploads')) {
    Dir::create(ROOTBASE . DS . 'public' . DS . 'uploads');
}
?>

Beispiel #22
0
 function testExecute()
 {
     ModuleUtils::set_modules_path(FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/");
     $ciccia_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/ciccia/");
     $db_desc = DB::newDatabaseDescription();
     $this->assertFalse($db_desc->hasTable("my_entity"), "La tabella my_entity e' gia' presente nel database!!");
     $this->assertFalse($ciccia_dir->exists(), "La directory 'ciccia' esiste gia'!!");
     //dove innesto i moduli
     $module_plug_test_root = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/");
     ModulePlug::setRootDir($module_plug_test_root->getPath());
     $plug = new ModulePlug(new Dir("/" . FRAMEWORK_CORE_PATH . "tests/base/fakeroot/modules/ecommerce/cart/"));
     $def = AvailableModules::get_available_module_definition("ecommerce", "cart");
     $install_data = $def->get_action_data("install");
     $plug->execute($install_data);
     $db_desc = DB::newDatabaseDescription();
     $this->assertTrue($db_desc->hasTable("my_entity"), "La tabella my_entity non e' stata creata!!");
     $sel = DB::newSelect("my_entity");
     $sel->count("*", "num_entries");
     $result = $sel->exec_fetch_assoc();
     $this->assertEqual($result["num_entries"], 2, "Il numero di righe nella tabella non corrisponde!!");
     $table_desc = DB::newTableFieldsDescription("my_entity");
     $this->assertTrue($table_desc->hasField("new_field"), "Il campo new_field non e' stato aggiunto!!");
     $this->assertTrue($table_desc->hasField("int_field"), "Il campo int_field non e' stato aggiunto!!");
     $ciccia_dir = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/modules/module_plug_root/ciccia/");
     $this->assertTrue($ciccia_dir->exists(), "La directory 'ciccia' non e' stata creata!!");
     $uninstall_data = $def->get_action_data("uninstall");
     $plug->execute($uninstall_data[0]);
     $this->assertFalse($ciccia_dir->exists(), "La directory ciccia non e' stata eliminata!!");
     ModulePlug::setRootDir("/");
 }
Beispiel #23
0
 /**
  * Get Cache Driver
  *
  * @access public
  * @return object
  */
 public static function getCacheDriver()
 {
     $driver_name = Config::get('system.cache.driver');
     if (!$driver_name || $driver_name == 'auto') {
         if (extension_loaded('apc')) {
             $driver_name = 'apc';
         } elseif (extension_loaded('wincache')) {
             $driver_name = 'wincache';
         } elseif (extension_loaded('xcache')) {
             $driver_name = 'xcache';
         }
     } else {
         $driver_name = 'file';
     }
     switch ($driver_name) {
         case 'apc':
             $driver = new \Doctrine\Common\Cache\ApcCache();
             break;
         case 'wincache':
             $driver = new \Doctrine\Common\Cache\WinCacheCache();
             break;
         case 'xcache':
             $driver = new \Doctrine\Common\Cache\XcacheCache();
             break;
         case 'memcache':
             $memcache = new \Memcache();
             $memcache->connect(Config::get('system.cache.memcache.server', 'localhost'), Config::get('system.cache.memcache.port', 11211));
             $driver = new \Doctrine\Common\Cache\MemcacheCache();
             $driver->setMemcache($memcache);
             break;
         case 'redis':
             $redis = new \Redis();
             $redis->connect(Config::get('system.cache.redis.server', 'localhost'), Config::get('system.cache.redis.port', 6379));
             $driver = new \Doctrine\Common\Cache\RedisCache();
             $driver->setRedis($redis);
             break;
         default:
             // Create doctrine cache directory if its not exists
             !Dir::exists($cache_directory = CACHE_PATH . '/doctrine/') and Dir::create($cache_directory);
             $driver = new \Doctrine\Common\Cache\FilesystemCache($cache_directory);
             break;
     }
     return $driver;
 }
Beispiel #24
0
 /**
  * Upload directory.
  * 
  * @param string $local_dir
  * @param string $remote_dir
  */
 public function putDir($local_dir, $remote_dir)
 {
     $entries = Dir::entries($local_dir);
     $this->_log("recursive directory upload {$local_dir} to {$remote_dir}\n");
     foreach ($entries as $entry) {
         if (Dir::exists($entry)) {
             $this->putDir($entry, $remote_dir . '/' . basename($entry));
         } else {
             if (File::exists($entry)) {
                 $this->put($entry, $remote_dir . '/' . basename($entry));
             }
         }
     }
 }
Beispiel #25
0
 /**
  * Move directory.
  *
  * @param string $old_dir
  * @param string $new_dir
  * @param int $opt (default = 0, e.g. Dir::CREATE_TARGET_PATH|Dir::REMOVE_EXISTING)
  */
 public static function move($old_dir, $new_dir, $opt = 0)
 {
     FSEntry::isDir($old_dir);
     if (realpath($old_dir) == realpath($new_dir)) {
         throw new Exception('source and target directory are same', "mv [{$old_dir}] to [{$new_dir}]");
     }
     if ($opt & Dir::REMOVE_EXISTING && Dir::exists($new_dir)) {
         Dir::remove($new_dir);
     }
     if ($opt & Dir::CREATE_TARGET_PATH) {
         Dir::create(dirname($new_dir), 0, true);
     }
     if (!rename($old_dir, $new_dir)) {
         // rename is fast but works only on same device
         Dir::copy($old_dir, $new_dir);
         Dir::remove($old_dir);
     }
     FSEntry::isDir($new_dir);
 }
Beispiel #26
0
     // remove file
     if (Request::get('del')) {
         if (Request::get('token')) {
             File::delete(STORAGE_PATH . '/pages' . Request::get('del') . '.md');
             Request::redirect(Url::getBase());
         } else {
             die('crsf detect !');
         }
     }
     // remove Cache
     if (Request::get('clearcache') == 'true') {
         if (Request::get('token')) {
             if (Dir::exists(CACHE_PATH . '/doctrine/')) {
                 Dir::delete(CACHE_PATH . '/doctrine/');
             }
             if (Dir::exists(CACHE_PATH . '/fenom/')) {
                 Dir::delete(CACHE_PATH . '/fenom/');
             }
             Request::redirect(Url::getBase());
         } else {
             die('crsf detect !');
         }
     }
     // logout
     if (Request::post('access_logout')) {
         Session::delete(Config::get('plugins.edit.name') . '_user');
         Request::redirect(Url::getCurrent());
     }
     // show template
     $template->display('admin.tpl', ['title' => $name, 'content' => $page, 'current' => $url, 'directory' => Dir::scan(STORAGE_PATH . '/pages')]);
 } else {
Beispiel #27
0
define('VIEWS', ROOT . '/views');
// Morfy paths
define('ROOTBASE', rtrim(str_replace(array($backend), array(''), dirname(__FILE__)), '\\/'));
define('LIBRARIES', ROOTBASE . '/libraries');
define('STORAGE', ROOTBASE . '/storage');
define('PAGES', ROOTBASE . '/storage/pages');
define('BLOCKS', ROOTBASE . '/storage/blocks');
define('SITE', ROOTBASE . '/config/site.yml');
define('THEMES', ROOTBASE . '/themes');
define('PLUGINS', ROOTBASE . '/plugins');
// new folders
define('BACKUPS', ROOTBASE . '/backups');
define('PUBLICFOLDER', ROOTBASE . '/public');
define('MEDIA', PUBLICFOLDER . '/media');
define('UPLOADS', PUBLICFOLDER . '/uploads');
// Morfy panel class/routes
include_once API . '/Morfy.panel.php';
include_once API . '/Morfy.routes.php';
// check if exist this folders
if (!Dir::exists(MEDIA)) {
    Dir::create(MEDIA);
}
if (!Dir::exists(UPLOADS)) {
    Dir::create(UPLOADS);
}
if (!Dir::exists(BACKUPS)) {
    Dir::create(BACKUPS);
}
?>

Beispiel #28
0
 function testDeleteRecursive()
 {
     $d = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/delete_test_dir/");
     $this->assertTrue($d->exists(), "La cartella dal eliminare non esiste!!");
     $this->assertTrue($d->isEmpty(), "La cartella da popolare non e' vuota!!");
     $the_dir = $d->newSubdir("the_dir");
     $blabla = $the_dir->newFile("blabla.ini");
     $blabla->setContent("[section]\n\nchiave=valore\n\n");
     $hidden_test = $the_dir->newSubdir("hidden_test");
     $htaccess = $hidden_test->newFile(".htaccess");
     $htaccess->setContent("RewriteEngine on\n\n");
     $prova = $hidden_test->newFile("prova.txt");
     $prova->setContent("Questo e' un file con un testo di prova");
     $the_dir->delete(true);
     $this->assertFalse($the_dir->exists(), "La directory non e' stata eliminata!!");
     $this->assertTrue($d->isEmpty(), "Il contenuto della cartella non e' stato rimosso completamente!!");
 }
Beispiel #29
0
 /**
  * 
  * Renames this directory without moving it.
  * 
  * @param string $new_name The new name to assign to this folder.
  * @return boolean true if the operation was succesfull, false otherwise.
  * @throws \Mbcraft\Piol\IOException if the name contains invalid characters (path components).
  * 
  * @api
  */
 public function rename($new_name)
 {
     FileSystemUtils::checkValidFilename($new_name);
     $parent_dir = $this->getParentDir();
     $target_path = $parent_dir->getPath() . "/" . $new_name;
     $target_dir = new Dir($target_path);
     if ($target_dir->exists()) {
         return false;
     }
     return rename($this->__full_path, $target_dir->getFullPath());
 }
 /**
  * main events admin function
  */
 public static function main()
 {
     $path = ROOT . DS . 'public' . DS . 'uploads' . DS;
     // Request: add event
     if (Request::post('add_event')) {
         if (Security::check(Request::post('csrf'))) {
             if (EventsRepository::insert(EventsAdmin::_getEventData())) {
                 Notification::set('success', __('Event was added with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->insert() returned an error. Event could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus(EventsRepository::getLastId()) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: edit event
     if (Request::post('edit_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('edit_event');
             if (EventsRepository::update($id, EventsAdmin::_getEventData())) {
                 Notification::set('success', __('Event was updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: restore event
     if (Request::post('restore_trash_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('restore_trash_event');
             if (EventsRepository::update($id, array('deleted' => 0))) {
                 Notification::set('success', __('Event has been restored from trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event could not be restored.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete event
     if (Request::post('delete_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_event');
             if (EventsRepository::update($id, array('deleted' => 1))) {
                 Notification::set('success', __('Event has been moved to trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event could not be deleted.', 'events'));
             }
             $record = EventsRepository::getById($id);
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete trash event
     if (Request::post('delete_trash_event')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_trash_event');
             if (EventsRepository::delete($id)) {
                 Notification::set('success', __('Event has been deleted permanently with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->delete() returned an error. Event could not be deleted.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: update event status ['published','draft']
     if (Request::get('eventaction') and Request::get('eventaction') == 'update_status') {
         if (Security::check(Request::get('token'))) {
             $id = (int) Request::get('event_id');
             if (EventsRepository::update($id, array('status' => Request::get('status')))) {
                 Notification::set('success', __('Event status has been updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Event status could not be updated.', 'events'));
             }
             Request::redirect('index.php?id=events#events/' . EventsRepository::getStatus($id) . '-events');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: add category
     if (Request::post('add_category')) {
         if (Security::check(Request::post('csrf'))) {
             if (CategoriesRepository::insert(EventsAdmin::_getCategoryData())) {
                 Notification::set('success', __('Category was added with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->insert() returned an error. Category could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: edit category
     if (Request::post('edit_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('edit_category');
             if (CategoriesRepository::update($id, EventsAdmin::_getCategoryData())) {
                 Notification::set('success', __('Category was updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Category could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: restore category
     if (Request::post('restore_trash_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('restore_trash_category');
             if (CategoriesRepository::update($id, array('deleted' => 0))) {
                 Notification::set('success', __('Category has been restored from trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Category could not be restored.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete category
     if (Request::post('delete_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_category');
             if (!CategoriesRepository::hasEvents($id)) {
                 if (CategoriesRepository::update($id, array('deleted' => 1))) {
                     Notification::set('success', __('Category has been moved to trash with success!', 'events'));
                 } else {
                     Notification::set('error', __('Table->update() returned an error. Category could not be deleted.', 'events'));
                 }
             } else {
                 Notification::set('error', __('Deletion failed. This category is assigned to at least one event. Remove this category from every event to delete it.', 'events'));
             }
             Request::redirect('index.php?id=events#categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete trash category
     if (Request::post('delete_trash_category')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_trash_category');
             if (CategoriesRepository::delete($id)) {
                 Notification::set('success', __('Category has been deleted permanently with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->delete() returned an error. Category could not be deleted.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-categories');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: add location
     if (Request::post('add_location')) {
         if (Security::check(Request::post('csrf'))) {
             if (LocationsRepository::insert(EventsAdmin::_getLocationData())) {
                 Notification::set('success', __('Location was added with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->insert() returned an error. Location could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: edit location
     if (Request::post('edit_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('edit_location');
             if (LocationsRepository::update($id, EventsAdmin::_getLocationData())) {
                 Notification::set('success', __('Location was updated with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Location could not be saved.', 'events'));
             }
             Request::redirect('index.php?id=events#locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: restore location
     if (Request::post('restore_trash_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('restore_trash_location');
             if (LocationsRepository::update($id, array('deleted' => 0))) {
                 Notification::set('success', __('Location has been restored from trash with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->update() returned an error. Location could not be restored.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete location
     if (Request::post('delete_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_location');
             if (!LocationsRepository::hasEvents($id)) {
                 if (LocationsRepository::update($id, array('deleted' => 1))) {
                     Notification::set('success', __('Location has been moved to trash with success!', 'events'));
                 } else {
                     Notification::set('error', __('Table->update() returned an error. Location could not be deleted.', 'events'));
                 }
             } else {
                 Notification::set('error', __('Deletion failed. This location is assigned to at least one event. Remove this location from every event to delete it.', 'events'));
             }
             Request::redirect('index.php?id=events#locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // Request: delete trash location
     if (Request::post('delete_trash_location')) {
         if (Security::check(Request::post('csrf'))) {
             $id = (int) Request::post('delete_trash_location');
             if (LocationsRepository::delete($id)) {
                 Notification::set('success', __('Location has been deleted permanently with success!', 'events'));
             } else {
                 Notification::set('error', __('Table->delete() returned an error. Location could not be deleted.', 'events'));
             }
             Request::redirect('index.php?id=events#trash/trash-locations');
         } else {
             Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
             die;
         }
     }
     // get upload directories
     $directory_list = Dir::scan($path);
     $directories = array(DS => DS);
     if (!empty($directory_list)) {
         foreach ($directory_list as $directory_name) {
             $directories[$directory_name] = DS . $directory_name;
         }
         ksort($directories);
     }
     // Get files
     $file_list = File::scan($path . Option::get('events_image_directory'));
     $files = array('' => '');
     if (!empty($file_list)) {
         foreach ($file_list as $file_name) {
             $files[$file_name] = $file_name;
         }
         ksort($files);
     }
     if (Request::get('action')) {
         switch (Request::get('action')) {
             // Request: configuration
             case "configuration":
                 // Request: options
                 if (Request::post('events_options_update') or Request::post('events_options_update_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         Option::update('events_image_directory', (string) Request::post('events_image_directory'));
                         Option::update('events_placeholder_archive', (string) Request::post('events_placeholder_archive'));
                         Notification::set('success', __('Configuration has been saved with success!', 'events'));
                         Request::redirect('index.php?id=events' . (Request::post('events_options_update') ? '&action=configuration' : ''));
                     } else {
                         Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
                         die;
                     }
                 }
                 // Request: action: resize images
                 if (Request::post('events_action_resize_images') or Request::post('events_action_resize_images_and_exit')) {
                     if (Security::check(Request::post('csrf'))) {
                         $n = 0;
                         $size = (int) Request::post('events_action_resize_size');
                         $image_dir = $path . Option::get('events_image_directory');
                         $image_dir_res = $path . Option::get('events_image_directory') . DS . 'resized';
                         $images = File::scan($image_dir);
                         if (!empty($images)) {
                             // create 'resized' directory if not exists
                             if (!Dir::exists($image_dir_res)) {
                                 Dir::create($image_dir_res);
                             }
                             foreach ($images as $file_name) {
                                 if (File::exists($image_dir_res . DS . $file_name)) {
                                     if (Request::post('events_action_resize_overwrite')) {
                                         File::delete($image_dir_res . DS . $file_name);
                                     } else {
                                         continue;
                                     }
                                 }
                                 list($width, $height) = getimagesize($image_dir . DS . $file_name);
                                 $image_orientation = $width > $height ? Image::HEIGHT : Image::WIDTH;
                                 Image::factory($image_dir . DS . $file_name)->resize($size, $size, $image_orientation)->save($image_dir_res . DS . $file_name);
                                 $n++;
                             }
                             Notification::set('success', __($n . ' images have been resized and saved with success!', 'events'));
                         } else {
                             Notification::set('error', __('There are no images to resize in configured image directory.', 'events'));
                         }
                         Request::redirect('index.php?id=events' . (Request::post('events_action_resize_images') ? '&action=configuration' : ''));
                     } else {
                         Notification::set('error', __('Request was denied. Invalid security token. Please refresh the page and try again.', 'events'));
                         die;
                     }
                 }
                 // Display configuration view
                 View::factory('events/views/backend/configuration')->assign('directories', $directories)->display();
                 break;
                 // Request: statistics
             // Request: statistics
             case "stats":
                 // category-events
                 $categories = CategoriesRepository::getAll();
                 $categories_active = CategoriesRepository::getActive();
                 $categories_data = array();
                 foreach ($categories_active as $c) {
                     $categories_data[$c['id']] = array('title' => '"' . $c['title'] . '"', 'color' => '"#' . $c['color'] . '"', 'highlight' => '"' . EventsAdmin::adjustBrightness('#' . $c['color'], 25) . '"', 'count' => $categories[$c['id']]['count']);
                 }
                 // location-events
                 $locations = LocationsRepository::getAll();
                 $locations_active = LocationsRepository::getActive();
                 $locations_data = array();
                 foreach ($locations_active as $l) {
                     $locations_data[$l['id']] = array('title' => '"' . $l['title'] . '"', 'count' => $locations[$l['id']]['count']);
                 }
                 $locations_data = EventsAdmin::_sortArrayByFields($locations_data, array('count' => SORT_DESC, 'title' => array(SORT_ASC, SORT_STRING)));
                 // year-events and year-visitors
                 $years_data = array();
                 $categories_years_events = array();
                 foreach (EventsRepository::getYearEvents() as $year => $events) {
                     $years_data[$year] = array('number_events' => count($events), 'number_visitors' => array_sum(array_column($events, 'number_visitors')));
                     foreach ($events as $event) {
                         $categories_years_events[$event['category']][$year][] = $event;
                     }
                 }
                 $categories_years_data = array();
                 $categories_years_visitors = array();
                 foreach ($categories_years_events as $category => $years) {
                     foreach ($years as $year => $events) {
                         foreach ($years_data as $total_year => $total_count) {
                             if ($year == $total_year) {
                                 $categories_years_data[$category][$year] = count($events);
                                 $categories_years_visitors[$category][$year] = array_sum(array_column($events, 'number_visitors'));
                             } else {
                                 if (array_key_exists($total_year, $categories_years_data[$category])) {
                                     $categories_years_data[$category][$year] = count($events);
                                     $categories_years_visitors[$category][$year] = array_sum(array_column($events, 'number_visitors'));
                                 } else {
                                     $categories_years_data[$category][$total_year] = 0;
                                     $categories_years_visitors[$category][$total_year] = 0;
                                 }
                             }
                         }
                     }
                 }
                 // locations
                 $locations_list = array();
                 $coordinates = array();
                 $longitudes = array();
                 $latitudes = array();
                 // get location data ready to use with OSM JavaScript
                 foreach (LocationsRepository::getActive() as $location) {
                     if ($location['address']) {
                         $locations_list[] = '"' . $location['address'] . '"';
                         $coordinates[] = $location['lon'] . ',' . $location['lat'];
                         $longitudes[] = $location['lon'];
                         $latitudes[] = $location['lat'];
                     }
                 }
                 // calculate map center
                 $longitudes = EventsAdmin::_removeOutliers($longitudes, 0.5);
                 $latitudes = EventsAdmin::_removeOutliers($latitudes, 0.5);
                 $coordinates_average = array('lon' => array_sum($longitudes) / count($longitudes), 'lat' => array_sum($latitudes) / count($latitudes));
                 // event visitors and staff
                 $participants = array();
                 $events = EventsRepository::getVisitorsAndStaff();
                 foreach ($events as $event) {
                     if (!CategoriesRepository::hiddenInArchive($event['category'])) {
                         $participants[$event['category']][] = array('title' => $event['title'], 'visitors' => (int) $event['number_visitors'], 'staff' => (int) $event['number_staff']);
                     }
                 }
                 // Display statistics view
                 View::factory('events/views/backend/statistics')->assign('categories', $categories)->assign('categories_active', $categories_active)->assign('categories_data', $categories_data)->assign('locations', $locations)->assign('locations_active', $locations_active)->assign('locations_data', $locations_data)->assign('years_data', $years_data)->assign('categories_years_data', $categories_years_data)->assign('categories_years_visitors', $categories_years_visitors)->assign('coordinates', $coordinates)->assign('coordinates_average', $coordinates_average)->assign('participants', $participants)->display();
                 break;
         }
     } else {
         // Display index view
         View::factory('events/views/backend/index')->assign('categories', CategoriesRepository::getAll())->assign('categories_active', CategoriesRepository::getActive())->assign('categories_select', CategoriesRepository::getActiveForSelect())->assign('categories_deleted', CategoriesRepository::getDeleted())->assign('locations', LocationsRepository::getAll())->assign('locations_active', LocationsRepository::getActive())->assign('locations_select', LocationsRepository::getActiveForSelect())->assign('locations_deleted', LocationsRepository::getDeleted())->assign('events_active', EventsRepository::getActive())->assign('events_upcoming', EventsRepository::getUpcoming())->assign('events_past', EventsRepository::getPast())->assign('events_draft', EventsRepository::getDraft())->assign('events_deleted', EventsRepository::getDeleted())->assign('imagepath', DS . 'public' . DS . 'uploads' . DS . Option::get('events_image_directory') . DS)->assign('files', $files)->display();
     }
 }