Ejemplo n.º 1
0
	public static function liveTests(){
		// Set Sandbox to be writable if possible
		@MFile::chmod(_FM_SANDBOX, 755);
		if( ! MFile::isWritable(_FM_SANDBOX)){
			self::$sandboxError = 1;
			return false;
		}
		
		$assets = _FM_SANDBOX .DS . "assets" ;
		$fileSample = _FM_SANDBOX .DS . "assets" . DS ."sample.txt";
		$fileValidate = _FM_SANDBOX .DS . "assets" . DS ."validate.txt";
		$destinationFolder = _FM_SANDBOX . DS . "dest";
		// 1. isDir
		self::$params["live_is_dir"] = (int) @MFile::isDir($assets);
		
		// 2. isFile
		self::$params["live_is_file"] = (int) @MFile::isFile($fileSample);
		
		// 3. Create Dir 
		MFile::createDir($destinationFolder, 0755);
		self::$params["live_create_dir"] = (int) ( @MFile::is($destinationFolder) && @MFile::isDir($destinationFolder));
		
		// 4. Read
		$valid = MFile::readData($fileValidate);
		self::$params["live_read_file"] = (int) $valid == "valid";
		
		// 5. Copy
		MFile::copy($fileValidate, $destinationFolder . DS . basename($fileValidate));
// 		MFile::copy($fileValidate, _FM_SANDBOX . DS . "reserved.txt");
		self::$params["live_copy"] = (int) MFile::is($destinationFolder . DS . basename($fileValidate));
		
		// 6. Rename
		$newValidate = $destinationFolder . DS .  "deleteme.txt";
		MFile::rename($destinationFolder . DS . basename($fileValidate), $newValidate);
		self::$params["live_rename"] = (int) MFile::is($newValidate);
		
		// 7. mode read
		@MFile::chmod($newValidate, 444);
		$mode = MFile::mode($newValidate);
		self::$params["live_mode"] = (int)  (!! $mode);
		
		// 8. CHMOD
		MFile::chmod($newValidate, 666);
		self::$params["live_chmod"] =  (int) ( $mode != MFile::mode($newValidate) );
		
		// 9. Write (Create / Add File)
		MFile::writeData($newValidate,"new",true);
		$validnew = MFile::readData($newValidate);
		self::$params["live_write_file"] = (int) $validnew == "validnew";
		
		// 10. Pack
		$archive = new PclZip(_FM_SANDBOX. DS . 'packed.zip');
		$archive->add($destinationFolder,PCLZIP_OPT_REMOVE_PATH, $destinationFolder);
		self::$params["live_zip"] = (int) MFile::is(_FM_SANDBOX. DS . 'packed.zip');
		
		// 11. Delete File
		MFile::remove($newValidate, 1);
		self::$params["live_delete_file"] = (int) ! MFile::is($newValidate);
		
		// 12. Delete Folder
		MFile::removeDir($destinationFolder);
		self::$params["live_delete_folder"] = (int) ! MFile::is($destinationFolder);
		
		// 13. UNZIP
		$archive = new PclZip(_FM_SANDBOX. DS . 'packed.zip');
		$archive->extract(PCLZIP_OPT_PATH, _FM_SANDBOX);
		self::$params["live_unzip"] = (int) MFile::is(_FM_SANDBOX. DS . 'deleteme.txt');
		
		// 14. Move
		MFile::createDir($destinationFolder, 0777);
		MFile::move(_FM_SANDBOX. DS . 'deleteme.txt', $destinationFolder);
		self::$params["live_move"] = (int) MFile::is($newValidate);
		
		
		// Purge
		MFile::remove(_FM_SANDBOX. DS . 'packed.zip', 1);
		MFile::removeDirAtAllCosts($destinationFolder);
		
		
		
	}
Ejemplo n.º 2
0
 /**
  * @return MDO
  */
 protected function _fetchData()
 {
     $names = $this->getVarNames();
     $data = new stdClass();
     $data->isError = false;
     $data->name = MRequest::clean("name", null);
     $data->nameError = "";
     $data->path = str_replace("\\", "/", MRequest::clean("path", null));
     $data->pathError = "";
     if (!$data->name) {
         $data->nameError .= MRightsHelper::wrapError(MText::_("error_noname"));
     }
     // Just validate if not in demo mode
     if (!_FM_IS_DEMO) {
         if (!$data->path) {
             $data->pathError .= MRightsHelper::wrapError(MText::_("error_nopath"));
         } else {
             if (!MFile::isDir($data->path)) {
                 $data->pathError .= MRightsHelper::wrapError(MText::_("error_pathnofolder"));
             }
         }
     }
     //EOF is not demo
     foreach ($names as $name) {
         $errVar = strtolower($name) . "Error";
         $data->isError = $data->isError || (bool) $data->{$errVar};
     }
     return MDO::instance(null, $data);
 }
Ejemplo n.º 3
0
 function copy()
 {
     global $destination;
     if (!MRights::can("copy")) {
         $this->popupError("copy");
         return;
     }
     $this->view->add2Content('<div style="display:none;">' . md5(uniqid()) . '</div>');
     $selectedFiles = $_REQUEST["selectedFiles"];
     $error = null;
     foreach ($selectedFiles as $selectedFile) {
         $basePath = $selectedFile;
         $selectedFile = _START_FOLDER . urldecode($selectedFile);
         $selectedFile = MValidate::path($selectedFile);
         $pi = pathinfo($selectedFile);
         $destinationFile = $destination . DS . $pi["basename"];
         if (file_exists($destinationFile)) {
             $error .= MText::_("file") . " <b>" . $pi["basename"] . "</b> " . MText::_("already_exists") . "<br>";
         } else {
             if (MFile::isDir($selectedFile)) {
                 $error .= MText::_("folder") . " <b>" . $basePath . "</b> " . MText::_("nofoldercopy") . "<br>";
             } else {
                 MFile::copy($selectedFile, $destinationFile);
             }
         }
     }
     if ($error) {
         $this->view->add2Content('<script noCache="1">newDarkenPopup(\'error\',mText.error,\'' . $error . '\',500,250);</script>');
     }
     $this->view->add2Content(fmGetFiles());
 }
Ejemplo n.º 4
0
 public static function filesByType($dirName, $type)
 {
     if (!MFile::is($dirName) || !MFile::isDir($dirName)) {
         return null;
     }
     $isArray = gettype($type) == "array";
     $array = array();
     $dir = @opendir($dirName);
     while ($entry = @readdir($dir)) {
         if ($entry == '.' || $entry == '..') {
             continue;
         }
         if (MFile::isFile($dirName . DS . $entry)) {
             $info = MFile::info($dirName . DS . $entry);
             if ($isArray) {
                 $typeMatching = in_array($info->extension, $type);
             } else {
                 $typeMatching = $info->extension == $type;
             }
             if ($typeMatching) {
                 $array[] = $info;
             }
         }
     }
     @closedir($dir);
     if (sizeof($array) > 0) {
         return $array;
     } else {
         return null;
     }
 }