Handle the export theme hook.

@param DOMDocument $xml     Xml document.
@param ZipWriter   $archive Zip archive.
@param int|string  $themeId Theme id.

@return void

@SuppressWarnings(PHPMD.UnusedFormalParameter)
160582
public function onExportTheme(DOMDocument $xml, ZipWriter $archive, $themeId): void
    {
        // Add the tables
        $table = $xml->createElement('table');
        $table->setAttribute('name', 'tl_bs_grid');

        $tables = $xml->getElementsByTagName('tables')->item(0);
        $table  = $tables->appendChild($table);

        /** @var GridModel $adapter */
        $adapter    = $this->framework->getAdapter(GridModel::class);
        $collection = $adapter->findBy('pid', $themeId);

        if ($collection) {
            foreach ($collection as $model) {
                $this->addDataRow($xml, $table, $model->row());
            }
        }
    }
203560
private function SaveArchivePage($archiveID)
    {
        $archive = Archive::Schema()->ByID($archiveID);
        if ($archive) {
            $archive->SetPage($this->Page());
            $archive->Save();
        }
    }
323167
public function writeInnerXml(\XMLWriter  $xmlWriter)
    {
        Validate::notNull($xmlWriter, 'xmlWriter');
        $xmlWriter->writeRaw($this->text);
    }
821887
public function extract(\ZipArchive $archive): void
    {
        $destination = $this->pluginDir;

        if (!is_writable($destination)) {
            throw new PluginExtractionException(sprintf('Destination directory "%s" is not writable', $destination));
        }

        $pluginName = $this->getPluginName($archive);
        $this->validatePluginZip($pluginName, $archive);

        $oldFile = $this->findOldFile($pluginName);
        $backupFile = $this->createBackupFile($oldFile);

        try {
            $archive->extractTo($destination);

            if ($backupFile !== '') {
                $this->filesystem->remove($backupFile);
            }

            unlink($archive->filename);
        } catch (\Exception $e) {
            if ($backupFile !== '') {
                $this->filesystem->rename($backupFile, $oldFile);
            }
            throw $e;
        }

        $this->clearOpcodeCache();
    }
840768
protected function processElements(Plugin $plugin, &$log = '', $xml = false)
    {

        if (!$xml)
            $xml = $this->loadXML($plugin->Path);

        if(!$xml)
            throw new Exception('Missing plugin.xml file for plugin ['.$plugin->Slug.']');

        $processedSlugs = array();

        // add elements
        $elements = $xml->elements;
        if (!empty($elements)) {
            foreach ( $elements->element as $elementNode ) {

                $element = new Element();
                $this->ModelMapper->defaultsOnModel($element);

                $this->SystemXMLConverter->xmlToElement($element, $elementNode);

                $log .= "Processing element descriptor: {$element->Slug}\n";

                if ($this->ElementService->slugExists($element->Slug)) {
                    $existingElement = $this->ElementService->getBySlug($element->Slug);

                    if ($existingElement->PluginID != $plugin->PluginID)
                    {
                        $log .= 'WARNING: Element already exists for slug: '.$existingElement->Slug."\n";
                        continue;
                    }

                    $element->ElementID = $existingElement->ElementID;
                }

                $element->PluginID = $plugin->PluginID;
                $anchorSite = $this->SiteService->getAnchoredSite();
                if(empty($anchorSite))
                    throw new Exception('Cannot install element without anchor site');
                $element->AnchoredSiteSlug = $anchorSite->getSlug();
                $element->AnchoredSiteSlugOverride = $anchorSite->getSlug();
                $element->AnchoredSite = $anchorSite;

                if ($this->ElementService->slugExists($element->Slug)) {
                    $log .= "Element updated...\n";
                    $this->ElementService->edit($element);
                } else {
                    $log .= "Element created...\n";
                    $this->ElementService->add($element);
                }

                $log .= "ID: {$element->ElementID}\n";
                $log .= "Slug: {$element->Slug}\n";
                $log .= "Name: {$element->Name}\n";
                $log .= "Description: {$element->Description}\n";
                $log .= "\n";

                $log .= "Creating element DB schema...";
                $element = $this->ElementService->getBySlug($element->Slug); //refresh schema
                $this->NodeService->createDBSchema($element);
                $log .= "done.\n\n";
            }
        }
    }
538899
protected function create_resource(cc_i_resource &$res, DOMDocument &$doc, $xmlnode=null) {
        $usenew = is_object($xmlnode);
        $dnode  = $usenew ? $xmlnode : $doc->createElementNS($this->ccnamespaces['imscc'], "resource");
        $this->update_attribute($doc, 'identifier', $res->identifier, $dnode);
        $this->update_attribute($doc, 'type', $res->type, $dnode);
        !is_null($res->href) ? $this->update_attribute($doc, 'href', $res->href, $dnode) : null;
        $this->update_attribute($doc, 'base', $res->base, $dnode);

        foreach ($res->files as $file) {
            $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'file');
            $ndatt = $doc->createAttribute('href');
            $ndatt->nodeValue = $file;
            $nd->appendChild($ndatt);
            $dnode->appendChild($nd);
        }
        $this->resources[$res->identifier]   = $res;
        $this->resources_ind[$res->files[0]] = $res->identifier;

        foreach ($res->dependency as $dependency) {
            $nd = $doc->createElementNS($this->ccnamespaces['imscc'], 'dependency');
            $ndatt = $doc->createAttribute('identifierref');
            $ndatt->nodeValue = $dependency;
            $nd->appendChild($ndatt);
            $dnode->appendChild($nd);
        }

        return $dnode;
    }
381116
function saveFileChanges(themeId, folderName, fileName, text) {
        io({
            url:getURL("save") + "/" + themeId + "/" + folderName + "/" + fileName,
            data:{
                content:encodeURI(text)
            },
            callback:function (isSuccess, message, response) {
                if (!isSuccess) {
                    showErrorMsg(message);
                }
            }
        });
    }
106508
public function export( $rootId, $zip = null )
    {
        $rootId         = (int) $rootId;
        $info           = $this->getSiteInfo();
        $domainList     = $this->getDomainList();
        $sheetModel     = $this->getSheetModel();
        $paragraphModel = $this->getParagraphModel();
        $dom            = new DOMImplementation;
        $document       = $dom->createDocument(
            static::GPML_NAMESPACE,
            static::GPML_ROOT,
            $dom->createDocumentType(
                static::GPML_ROOT,
                static::GPML_PUBLIC,
                static::GPML_SYSTEM
            )
        );

        if ( empty( $zip ) )
        {
            $suffix  = '';
            $zipPath = static::PUBLIC_DIR
                     . static::TEMP_DIR
                     . 'paragraph-export-'
                     . $rootId;

            while ( is_file( $zipPath . $suffix . '.zip' ) )
            {
                $suffix--;
            }

            $zip = $zipPath . $suffix . '.zip';
        }

        $zipPath = (string) $zip;
        $zip     = new ZipArchive;
        $open    = $zip->open(
            $zipPath,
            ZipArchive::CREATE | ZipArchive::OVERWRITE
        );

        if ( true !== $open )
        {
            throw new \RuntimeException( sprintf(
                '%s: "%s" cannot be created as a zip file (errno #%d)',
                __METHOD__,
                $zipPath,
                $open
            ) );
        }

        $gpml = $document->documentElement;
     // $gpml->setAttribute( 'xmlns', 'http://gridguyz.com/#gpml' );
        $gpml->setAttribute( 'version', '1.0' );
        $gpml->setAttribute( 'db-schema', $info->getSchema() );

        foreach ( $domainList as $domain )
        {
            $domainTextNode = $document->createTextNode( (string) $domain );
            $domainElement  = $document->createElement( 'domain' );
            $domainElement->appendChild( $domainTextNode );
            $gpml->appendChild( $domainElement );
        }

        $nodeStack  = array( $gpml );
        $paragraphs = new DepthList(
            $paragraphModel->getMapper()
                           ->findRenderListData( $rootId )
        );

        $paragraphs->runin( function ( $paragraph ) use (
            &$nodeStack,
            $document,
            $zip
        ) {
            $nodeStack[] = $node = $document->createElement( 'paragraph' );
            $node->setAttribute( 'id', $paragraph['id'] );
            $node->setAttribute( 'type', $paragraph['type'] );

            if ( isset( $paragraph['name'] ) )
            {
                $node->setAttribute( 'name', $paragraph['name'] );
            }

            if ( ! empty( $paragraph['proxyData'] ) )
            {
                foreach ( $paragraph['proxyData'] as $property )
                {
                    $propNode = $document->createElement( 'paragraph-property' );

                    $propNode->setAttribute(
                        'locale',
                        empty( $property['locale'] )
                            ? '*'
                            : $property['locale']
                    );

                    $propNode->setAttribute( 'name', $property['name'] );

                    if ( isset( $property['value'] ) )
                    {
                        $propNode->setAttribute(
                            'value',
                            $this->setPropertyNodeValue(
                                $zip,
                                $propNode,
                                $property['value']
                            )
                        );
                    }

                    $node->appendChild( $propNode );
                }
            }
        }, function () use ( &$nodeStack ) {
            $append = array_pop( $nodeStack );
            end( $nodeStack )->appendChild( $append );
        } );

        /* @var $sheet \Grid\Customize\Model\Sheet\Structure */
        $sheet = $sheetModel->find( $rootId );

        foreach ( $sheet->rules as $rule )
        {
            /* @var $rule \Grid\Customize\Model\Rule\Structure */
            $ruleNode = $document->createElement( 'customize-rule' );
            $ruleNode->setAttribute( 'selector', $rule->selector );
            $ruleNode->setAttribute( 'media', $rule->media );

            foreach ( $rule->getRawPropertyNames() as $property )
            {
                $propNode = $document->createElement( 'customize-property' );
                $priority = $rule->getRawPropertyPriority( $property );
                $propNode->setAttribute( 'name', $property );

                $propNode->setAttribute(
                    'value',
                    $this->setPropertyNodeValue(
                        $zip,
                        $propNode,
                        $rule->getRawPropertyValue( $property ),
                        true
                    )
                );

                if ( $priority )
                {
                    $propNode->setAttribute( 'priority', $priority );
                }

                $ruleNode->appendChild( $propNode );
            }

            $gpml->appendChild( $ruleNode );
        }

        $extra = trim( $sheet->getExtraContent() );

        if ( ! empty( $extra ) )
        {
            $extraText = $document->createTextNode( "\n$extra\n" );
            $extraNode = $document->createElement( 'customize-extra' );
            $extraNode->appendChild( $extraText );
            $gpml->appendChild( $extraNode );
        }

        $document->formatOutput = true;
        $zip->addFromString( 'paragraph.xml', $document->saveXML() );
        $zip->close();
        return $zipPath;
    }
277494
public function export(\SimpleXMLElement $xml)
    {
        $type = $xml->addChild('library');
        $type->addAttribute('handle', $this->getSystemCaptchaLibraryHandle());
        $type->addAttribute('name', $this->getSystemCaptchaLibraryName());
        $type->addAttribute('package', $this->getPackageHandle());
        $type->addAttribute('activated', $this->isSystemCaptchaLibraryActive() ? '1' : '0');
    }
38350
public function writeInnerXml(\XMLWriter $xmlWriter)
    {
        Validate::notNull($xmlWriter, 'xmlWriter');
        $xmlWriter->writeElementNS(
            'atom',
            'name',
            Resources::ATOM_NAMESPACE,
            $this->name
        );

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'uri',
            Resources::ATOM_NAMESPACE,
            $this->uri
        );

        $this->writeOptionalElementNS(
            $xmlWriter,
            'atom',
            'email',
            Resources::ATOM_NAMESPACE,
            $this->email
        );
    }
1282769
public function saveXML(string $XMLfile): void
    {
        $file = new FileManager();
        $file->saveLittleFile($this->xmlData, $XMLfile);
    }
1013881
public static void writeXML(Document xmldocument, Writer writer) throws IOException {
		assert xmldocument != null : AssertMessages.notNullParameter(0);
		assert writer != null : AssertMessages.notNullParameter(1);
		writeNode(xmldocument, writer);
	}
607273
private function callback($theme, $method, $data)
	{
		if ($theme == NULL)
			throw new CHttpException(400, Yii::t('Api.Theme', 'Missing Theme'));

		if ($method == NULL)
			throw new CHttpException(400, Yii::t('Api.Theme', 'Method name is missing'));

		Yii::import('base.themes.' . $theme . '.Theme');
		$theme = new Theme;

		if (method_exists($theme, $method))
			return $theme->$method($data);

		throw new CHttpException(404, Yii::t('Api.Theme', 'Missing callback method.'));
	}
1238509
public static function send_export_xml($roleid) {
        global $CFG, $DB;
        require_once($CFG->libdir . '/filelib.php');

        $role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST);

        if ($role->shortname) {
            $filename = $role->shortname.'.xml';
        } else {
            $filename = 'role.xml';
        }
        $xml = self::get_export_xml($roleid);
        send_file($xml, $filename, 0, false, true, true);
        die();
    }
187540
protected function resource_bind_handler($xml) {
		if($xml->attrs['type'] == 'result') {
			$this->log->log("Bound to " . $xml->sub('bind')->sub('jid')->data);
			$this->fulljid = $xml->sub('bind')->sub('jid')->data;
			$jidarray = explode('/',$this->fulljid);
			$this->jid = $jidarray[0];
		}
		$id = $this->getId();
		$this->addIdHandler($id, 'session_start_handler');
		$this->send("<iq xmlns='jabber:client' type='set' id='$id'><session xmlns='urn:ietf:params:xml:ns:xmpp-session' /></iq>");
	}
1281693
public function onExtractThemeFiles(\DOMDocument $xml, ZipReader $archive, $themeId): void
    {
        $tables = $xml->getElementsByTagName('table');

        for ($index = 0; $index < $tables->length; $index++) {
            if ($tables->item($index)->getAttribute('name') !== 'tl_bs_grid') {
                continue;
            }

            $this->importGrid($tables->item($index), (int) $themeId);
        }
    }
397028
private function importGrid(\DOMElement $item, int $themeId): void
    {
        $rows = $item->childNodes;

        for ($index = 0; $index < $rows->length; $index++) {
            $values = $this->getRowValues($rows->item($index), $themeId);
            $model  = new GridModel();

            $model->setRow($values);
            $model->save();
        }
    }