Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core\content\export\zipwriter Class Reference

Zip writer wrapper. More...

Public Member Functions

 __construct (\ZipStream\ZipStream $archive, stdClass $options=null)
 zipwriter constructor.
 
 add_file_from_stored_file (context $context, string $filepathinzip, stored_file $file)
 Add a file from the File Storage API.
 
 add_file_from_string (context $context, string $filepathinzip, string $content)
 Add a file from string content.
 
 add_file_from_template (context $context, string $filepathinzip, string $template, stdClass $templatedata)
 Create a file based on a Mustache Template and associated data.
 
 add_pluginfiles_for_content (context $context, string $subdir, string $content, string $component, string $filearea, int $fileitemid, ?int $pluginfileitemid)
 Export files releating to this text area.
 
 finish ()
 Finish writing the zip footer.
 
 get_context_path (context $context, string $filepathinzip)
 Get the full path to the context within the zip.
 
 get_file_path ()
 Get the file path for a file-based zip writer.
 
 get_relative_context_path (context $rootcontext, context $targetcontext, string $filepathinzip)
 Get a relative path to the specified context path.
 
 is_file_in_archive (context $context, string $filepathinzip)
 Check whether the file was actually added to the archive.
 
 set_root_context (context $rootcontext)
 Set a root context for use during the export.
 

Static Public Member Functions

static get_file_writer (string $filename, stdClass $exportoptions=null)
 Get the file writer.
 
static get_stream_writer (string $filename, stdClass $exportoptions=null)
 Get the stream writer.
 

Public Attributes

int const MAX_CONTEXT_NAME_LENGTH = 32
 Maximum folder length name for a context.
 

Protected Member Functions

 add_content_from_dirroot (string $dirrootpath, string $pathinzip)
 Add content from the dirroot into the specified path in the zip file.
 
 add_template_requirements ()
 Ensure that all requirements for a templated page are present.
 
 get_context_folder_name (context $context)
 Get the name of the folder for the specified context.
 
 get_course ()
 Get the course object for the root context.
 
 parse_options (stdClass $options)
 Parse options.
 
 rewrite_other_pluginfile_urls (context $context, string $content, string $component, string $filearea, ?int $pluginfileitemid)
 Rewrite any pluginfile URLs in the content.
 
 sanitise_filename (string $filepath)
 Sanitise the file path, removing any unsuitable characters.
 

Static Protected Member Functions

static get_filepath_for_file (stored_file $file, string $parentdir, bool $escape)
 Get the filepath for the specified stored_file.
 

Protected Attributes

ZipStream ZipStream $archive
 
stdClass $course
 The course relating to the root context.
 
context $coursecontext
 The context of the course for the root contect.
 
array $filesinzip = []
 The files in the zip.
 
int $maxfilesize = 1 * 1024 * 1024 * 10
 Max file size of an individual file in the archive.
 
bool $pagerequirementsadded = false
 Whether page requirements needed for HTML pages have been added.
 
context $rootcontext = null
 The context to use as a base for export.
 
resource $zipfilehandle = null
 File resource for the file handle for a file-based zip stream.
 
string $zipfilepath = null
 File path for a file-based zip stream.
 

Detailed Description

Zip writer wrapper.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\content\export\zipwriter::__construct ( \ZipStream\ZipStream $archive,
stdClass $options = null )

zipwriter constructor.

Parameters
ZipStream\ZipStream$archive
stdClass | null$options

Member Function Documentation

◆ add_content_from_dirroot()

core\content\export\zipwriter::add_content_from_dirroot ( string $dirrootpath,
string $pathinzip )
protected

Add content from the dirroot into the specified path in the zip file.

Parameters
string$dirrootpath
string$pathinzip

◆ add_file_from_stored_file()

core\content\export\zipwriter::add_file_from_stored_file ( context $context,
string $filepathinzip,
stored_file $file )

Add a file from the File Storage API.

Parameters
context$context
string$filepathinzip
stored_file$fileThe file to add

◆ add_file_from_string()

core\content\export\zipwriter::add_file_from_string ( context $context,
string $filepathinzip,
string $content )

Add a file from string content.

Parameters
context$context
string$filepathinzip
string$content

◆ add_file_from_template()

core\content\export\zipwriter::add_file_from_template ( context $context,
string $filepathinzip,
string $template,
stdClass $templatedata )

Create a file based on a Mustache Template and associated data.

Parameters
context$context
string$filepathinzip
string$template
stdClass$templatedata

◆ add_pluginfiles_for_content()

core\content\export\zipwriter::add_pluginfiles_for_content ( context $context,
string $subdir,
string $content,
string $component,
string $filearea,
int $fileitemid,
?int $pluginfileitemid )

Export files releating to this text area.

Parameters
context$context
string$subdirThe sub directory to export any files to
string$content
string$component
string$filearea
int$fileitemidThe itemid as used in the Files API
null | int$pluginfileitemidThe itemid to use in the pluginfile URL when composing any required URLs
Return values
exported_item

◆ add_template_requirements()

core\content\export\zipwriter::add_template_requirements ( )
protected

Ensure that all requirements for a templated page are present.

This includes CSS, and any other similar content.

◆ get_context_folder_name()

core\content\export\zipwriter::get_context_folder_name ( context $context)
protected

Get the name of the folder for the specified context.

Parameters
context$context
Return values
string

◆ get_context_path()

core\content\export\zipwriter::get_context_path ( context $context,
string $filepathinzip )

Get the full path to the context within the zip.

Parameters
context$context
string$filepathinzip
Return values
string

◆ get_course()

core\content\export\zipwriter::get_course ( )
protected

Get the course object for the root context.

Return values
stdClass

◆ get_file_path()

core\content\export\zipwriter::get_file_path ( )

Get the file path for a file-based zip writer.

If this is not a file-based writer then no value is returned.

Return values
null|string

◆ get_file_writer()

static core\content\export\zipwriter::get_file_writer ( string $filename,
stdClass $exportoptions = null )
static

Get the file writer.

Parameters
string$filename
stdClass | null$exportoptions
Return values
static

◆ get_filepath_for_file()

static core\content\export\zipwriter::get_filepath_for_file ( stored_file $file,
string $parentdir,
bool $escape )
staticprotected

Get the filepath for the specified stored_file.

Parameters
stored_file$file
string$parentdirAny parent directory to place this file in
bool$escape
Return values
string

◆ get_relative_context_path()

core\content\export\zipwriter::get_relative_context_path ( context $rootcontext,
context $targetcontext,
string $filepathinzip )

Get a relative path to the specified context path.

Parameters
context$rootcontext
context$targetcontext
string$filepathinzip
Return values
string

◆ get_stream_writer()

static core\content\export\zipwriter::get_stream_writer ( string $filename,
stdClass $exportoptions = null )
static

Get the stream writer.

Parameters
string$filename
stdClass | null$exportoptions
Return values
static

◆ is_file_in_archive()

core\content\export\zipwriter::is_file_in_archive ( context $context,
string $filepathinzip )

Check whether the file was actually added to the archive.

Parameters
context$context
string$filepathinzip
Return values
bool

◆ parse_options()

core\content\export\zipwriter::parse_options ( stdClass $options)
protected

Parse options.

Parameters
stdClass$options

◆ rewrite_other_pluginfile_urls()

core\content\export\zipwriter::rewrite_other_pluginfile_urls ( context $context,
string $content,
string $component,
string $filearea,
?int $pluginfileitemid )
protected

Rewrite any pluginfile URLs in the content.

Parameters
context$context
string$content
string$component
string$filearea
null | int$pluginfileitemidThe itemid to use in the pluginfile URL when composing any required URLs
Return values
string

◆ sanitise_filename()

core\content\export\zipwriter::sanitise_filename ( string $filepath)
protected

Sanitise the file path, removing any unsuitable characters.

Parameters
string$filepath
Return values
string

◆ set_root_context()

core\content\export\zipwriter::set_root_context ( context $rootcontext)

Set a root context for use during the export.

This is primarily used for creating paths within the archive relative to the root context.

Parameters
context$rootcontext

The documentation for this class was generated from the following file: