protected function addFolderToArchive(ZipWriter $objArchive, $strFolder, \DOMDocument $xml, \DOMElement $table, array $arrOrder=array())
	{
		// Strip the custom upload folder name
		$strFolder = preg_replace('@^'.preg_quote(Config::get('uploadPath'), '@').'/@', '', $strFolder);

		// Add the default upload folder name
		if ($strFolder == '')
		{
			$strTarget = 'files';
			$strFolder = Config::get('uploadPath');
		}
		else
		{
			$strTarget = 'files/' . $strFolder;
			$strFolder = Config::get('uploadPath') .'/'. $strFolder;
		}

		if (Validator::isInsecurePath($strFolder))
		{
			throw new \RuntimeException('Insecure path ' . $strFolder);
		}

		// Return if the folder does not exist
		if (!is_dir($this->strRootDir .'/'. $strFolder))
		{
			return;
		}

		// Recursively add the files and subfolders
		foreach (scan($this->strRootDir .'/'. $strFolder) as $strFile)
		{
			// Skip hidden resources
			if (strncmp($strFile, '.', 1) === 0)
			{
				continue;
			}

			if (is_dir($this->strRootDir .'/'. $strFolder .'/'. $strFile))
			{
				$this->addFolderToArchive($objArchive, $strFolder .'/'. $strFile, $xml, $table, $arrOrder);
			}
			else
			{
				// Always store files in files and convert the directory upon import
				$objArchive->addFile($strFolder .'/'. $strFile, $strTarget .'/'. $strFile);

				$arrRow = array();
				$objFile = new File($strFolder .'/'. $strFile);
				$objModel = FilesModel::findByPath($strFolder .'/'. $strFile);

				if ($objModel !== null)
				{
					$arrRow = $objModel->row();

					foreach (array('id', 'pid', 'tstamp', 'uuid', 'type', 'extension', 'found', 'name') as $key)
					{
						unset($arrRow[$key]);
					}
				}

				// Always use files as directory and convert it upon import
				$arrRow['path'] = $strTarget .'/'. $strFile;
				$arrRow['hash'] = $objFile->hash;

				// Add the row
				$this->addDataRow($xml, $table, $arrRow, $arrOrder);
			}
		}
	}
protected function addFolderToArchive(ZipWriter $objArchive, $strFolder, \DOMDocument $xml, \DOMElement $table, array $arrOrder=array())
	{
		
		$strFolder = preg_replace('@^'.preg_quote(Config::get('uploadPath'), '@').'/@', '', $strFolder);

		
		if ($strFolder == '')
		{
			$strTarget = 'files';
			$strFolder = Config::get('uploadPath');
		}
		else
		{
			$strTarget = 'files/' . $strFolder;
			$strFolder = Config::get('uploadPath') .'/'. $strFolder;
		}

		if (Validator::isInsecurePath($strFolder))
		{
			throw new \RuntimeException('Insecure path ' . $strFolder);
		}

		
		if (!is_dir($this->strRootDir .'/'. $strFolder))
		{
			return;
		}

		
		foreach (scan($this->strRootDir .'/'. $strFolder) as $strFile)
		{
			
			if (strncmp($strFile, '.', 1) === 0)
			{
				continue;
			}

			if (is_dir($this->strRootDir .'/'. $strFolder .'/'. $strFile))
			{
				$this->addFolderToArchive($objArchive, $strFolder .'/'. $strFile, $xml, $table, $arrOrder);
			}
			else
			{
				
				$objArchive->addFile($strFolder .'/'. $strFile, $strTarget .'/'. $strFile);

				$arrRow = array();
				$objFile = new File($strFolder .'/'. $strFile);
				$objModel = FilesModel::findByPath($strFolder .'/'. $strFile);

				if ($objModel !== null)
				{
					$arrRow = $objModel->row();

					foreach (array('id', 'pid', 'tstamp', 'uuid', 'type', 'extension', 'found', 'name') as $key)
					{
						unset($arrRow[$key]);
					}
				}

				
				$arrRow['path'] = $strTarget .'/'. $strFile;
				$arrRow['hash'] = $objFile->hash;

				
				$this->addDataRow($xml, $table, $arrRow, $arrOrder);
			}
		}
	}
protected function addFolderToArchive ( ZipWriter $ objArchive , $ strFolder , \ DOMDocument $ xml , \ DOMElement $ table , array $ arrOrder = array ( ) ) { // Strip the custom upload folder name $ strFolder = preg_replace ( '@^' . preg_quote ( Config :: get ( 'uploadPath' ) , '@' ) . '/@' , '' , $ strFolder ) ; // Add the default upload folder name if ( $ strFolder == '' ) { $ strTarget = 'files' ; $ strFolder = Config :: get ( 'uploadPath' ) ; } else { $ strTarget = 'files/' . $ strFolder ; $ strFolder = Config :: get ( 'uploadPath' ) . '/' . $ strFolder ; } if ( Validator :: isInsecurePath ( $ strFolder ) ) { throw new \ RuntimeException ( 'Insecure path ' . $ strFolder ) ; } // Return if the folder does not exist if ( ! is_dir ( $ this -> strRootDir . '/' . $ strFolder ) ) { return ; } // Recursively add the files and subfolders foreach ( scan ( $ this -> strRootDir . '/' . $ strFolder ) as $ strFile ) { // Skip hidden resources if ( strncmp ( $ strFile , '.' , 1 ) === 0 ) { continue ; } if ( is_dir ( $ this -> strRootDir . '/' . $ strFolder . '/' . $ strFile ) ) { $ this -> addFolderToArchive ( $ objArchive , $ strFolder . '/' . $ strFile , $ xml , $ table , $ arrOrder ) ; } else { // Always store files in files and convert the directory upon import $ objArchive -> addFile ( $ strFolder . '/' . $ strFile , $ strTarget . '/' . $ strFile ) ; $ arrRow = array ( ) ; $ objFile = new File ( $ strFolder . '/' . $ strFile ) ; $ objModel = FilesModel :: findByPath ( $ strFolder . '/' . $ strFile ) ; if ( $ objModel !== null ) { $ arrRow = $ objModel -> row ( ) ; foreach ( array ( 'id' , 'pid' , 'tstamp' , 'uuid' , 'type' , 'extension' , 'found' , 'name' ) as $ key ) { unset ( $ arrRow [ $ key ] ) ; } } // Always use files as directory and convert it upon import $ arrRow [ 'path' ] = $ strTarget . '/' . $ strFile ; $ arrRow [ 'hash' ] = $ objFile -> hash ; // Add the row $ this -> addDataRow ( $ xml , $ table , $ arrRow , $ arrOrder ) ; } } }
Recursively add a folder to the archive

@param ZipWriter            $objArchive
@param string               $strFolder
@param \DOMDocument         $xml
@param \DOMNode|\DOMElement $table
@param array                $arrOrder

@throws \Exception If the folder path is insecure
Recursively add a folder to the archive