Пример #1
0
 /**
  * Export a ZAD Send News manager to XML file.
  * @param \DataContainer
  */
 public function exportManager($dc)
 {
     // get the manager data
     $manager = $this->Database->prepare("SELECT * FROM tl_zad_sendnews WHERE id=?")->execute($dc->id);
     if ($manager->numRows < 1) {
         // error, exit
         return;
     }
     // create a new XML document
     $xml = new \DOMDocument('1.0', 'UTF-8');
     $xml->formatOutput = true;
     // root element
     $tables = $xml->createElement('tables');
     $tables->setAttribute('version', '2.0');
     $tables = $xml->appendChild($tables);
     // add manager table
     $this->exportTable('tl_zad_sendnews', $xml, $tables, $manager);
     // add rules table
     $rules = $this->Database->prepare("SELECT * FROM tl_zad_sendnews_rule WHERE pid=? ORDER BY sorting")->execute($manager->id);
     $this->exportTable('tl_zad_sendnews_rule', $xml, $tables, $rules);
     // add news_archive table
     $news = $this->Database->prepare("SELECT id,title FROM tl_news_archive WHERE id=?")->execute($manager->news_archive);
     $this->exportTable('tl_news_archive', $xml, $tables, $news);
     // add user table
     $user = $this->Database->prepare("SELECT id,username,name,email FROM tl_user WHERE id=?")->execute($manager->news_author);
     $this->exportTable('tl_user', $xml, $tables, $user);
     // create a zip archive
     $tmp = md5(uniqid(mt_rand(), true));
     $zip = new \ZipWriter('system/tmp/' . $tmp);
     // add XML document
     $zip->addString($xml->saveXML(), 'sendnews.xml');
     // close archive
     $zip->close();
     // romanize the file name
     $name = utf8_romanize($manager->name);
     $name = strtolower(str_replace(' ', '_', $name));
     $name = preg_replace('/[^A-Za-z0-9\\._-]/', '', $name);
     $name = basename($name);
     // open the "save as …" dialogue
     $file = new \File('system/tmp/' . $tmp, true);
     // send file
     header('Content-Type: application/octet-stream');
     header('Content-Transfer-Encoding: binary');
     header('Content-Disposition: attachment; filename="' . $name . '.zip"');
     header('Content-Length: ' . $file->filesize);
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Expires: 0');
     $fl = fopen(TL_ROOT . '/system/tmp/' . $tmp, 'rb');
     fpassthru($fl);
     fclose($fl);
     exit;
 }
Пример #2
0
	/**
	 * Export a theme
	 * @param DataContainer
	 */
	public function exportTheme(DataContainer $dc)
	{
		// Get the theme meta data
		$objTheme = $this->Database->prepare("SELECT * FROM tl_theme WHERE id=?")
								   ->limit(1)
								   ->execute($dc->id);

		if ($objTheme->numRows < 1)
		{
			return;
		}

		// Romanize the name
		$strName = utf8_romanize($objTheme->name);
		$strName = strtolower(str_replace(' ', '_', $strName));
		$strName = preg_replace('/[^A-Za-z0-9\._-]/', '', $strName);
		$strName = basename($strName);

		// Create a new XML document
		$xml = new DOMDocument('1.0', 'UTF-8');
		$xml->formatOutput = true;

		// Root element
		$tables = $xml->createElement('tables');
		$tables = $xml->appendChild($tables);

		// Add the tables
		$this->addTableTlTheme($xml, $tables, $objTheme);
		$this->addTableTlStyleSheet($xml, $tables, $objTheme);
		$this->addTableTlModule($xml, $tables, $objTheme);
		$this->addTableTlLayout($xml, $tables, $objTheme);

		// Generate the archive
		$strTmp = md5(uniqid(mt_rand(), true));
		$objArchive = new ZipWriter('system/tmp/'. $strTmp);

		// Add the XML document
		$objArchive->addString($xml->saveXML(), 'theme.xml');

		// Add the folders
		$arrFolders = deserialize($objTheme->folders);

		if (is_array($arrFolders) && !empty($arrFolders))
		{
			foreach ($this->eliminateNestedPaths($arrFolders) as $strFolder)
			{
				$this->addFolderToArchive($objArchive, $strFolder);
			}
		}

		// Add the template files
		$this->addTemplatesToArchive($objArchive, $objTheme->templates);

		// Close the archive
		$objArchive->close();

		// Open the "save as …" dialogue
		$objFile = new File('system/tmp/'. $strTmp);

		header('Content-Type: application/octet-stream');
		header('Content-Transfer-Encoding: binary');
		header('Content-Disposition: attachment; filename="' . $strName . '.cto"');
		header('Content-Length: ' . $objFile->filesize);
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Pragma: public');
		header('Expires: 0');

		$resFile = fopen(TL_ROOT . '/system/tmp/'. $strTmp, 'rb');
		fpassthru($resFile);
		fclose($resFile);

		exit;
	}
Пример #3
0
 /**
  * Export a theme
  * @param \DataContainer
  */
 public function exportTheme(\DataContainer $dc)
 {
     // Get the theme meta data
     $objTheme = $this->Database->prepare("SELECT * FROM tl_theme WHERE id=?")->limit(1)->execute($dc->id);
     if ($objTheme->numRows < 1) {
         return;
     }
     // Romanize the name
     $strName = utf8_romanize($objTheme->name);
     $strName = strtolower(str_replace(' ', '_', $strName));
     $strName = preg_replace('/[^A-Za-z0-9\\._-]/', '', $strName);
     $strName = basename($strName);
     // Create a new XML document
     $xml = new \DOMDocument('1.0', 'UTF-8');
     $xml->formatOutput = true;
     // Root element
     $tables = $xml->createElement('tables');
     $tables = $xml->appendChild($tables);
     // Add the tables
     $this->addTableTlTheme($xml, $tables, $objTheme);
     $this->addTableTlStyleSheet($xml, $tables, $objTheme);
     $this->addTableTlModule($xml, $tables, $objTheme);
     $this->addTableTlLayout($xml, $tables, $objTheme);
     // Generate the archive
     $strTmp = md5(uniqid(mt_rand(), true));
     $objArchive = new \ZipWriter('system/tmp/' . $strTmp);
     // Add the XML document
     $objArchive->addString($xml->saveXML(), 'theme.xml');
     // Add the folders
     $arrFolders = deserialize($objTheme->folders);
     if (!empty($arrFolders) && is_array($arrFolders)) {
         $objFolders = \FilesModel::findMultipleByUuids($arrFolders);
         if ($objFolders !== null) {
             foreach ($this->eliminateNestedPaths($objFolders->fetchEach('path')) as $strFolder) {
                 $this->addFolderToArchive($objArchive, $strFolder);
             }
         }
     }
     // Add the template files
     $this->addTemplatesToArchive($objArchive, $objTheme->templates);
     // Close the archive
     $objArchive->close();
     // Open the "save as …" dialogue
     $objFile = new \File('system/tmp/' . $strTmp, true);
     $objFile->sendToBrowser($strName . '.cto');
 }
Пример #4
0
 /**
  * Export a combined translation file
  */
 protected function export()
 {
     $arrSession = $this->Session->get('filter_translation');
     $arrSession = $arrSession['isotope_translation'];
     $strFolder = 'system/modules/' . $arrSession['module'] . '/languages/' . $this->User->translation;
     $strZip = 'system/html/' . $this->User->translation . '.zip';
     $arrFiles = scan(TL_ROOT . '/' . $strFolder);
     $strHeader = $this->getHeader();
     $objZip = new ZipWriter($strZip);
     foreach ($arrFiles as $file) {
         $strData = '';
         $arrSource = $this->parseFile(TL_ROOT . '/system/modules/' . $arrSession['module'] . '/languages/en/' . $file);
         $arrTranslation = array_merge($this->parseFile(TL_ROOT . '/system/modules/' . $arrSession['module'] . '/languages/' . $this->User->translation . '/' . $file), $this->parseFile(TL_ROOT . '/system/modules/' . $arrSession['module'] . '/languages/' . $this->User->translation . '/local/' . $file));
         foreach (array_keys($arrSource) as $key) {
             $value = str_replace(array("\r\n", "\n", "\r", '\\n'), '\\n', $arrTranslation[$key], $count);
             $strData .= $key . ' = ' . ($count > 0 ? '"' . str_replace('"', '\\"', $value) . '";' . "\n" : "'" . str_replace("'", "\\'", $value) . "';\n");
         }
         $objZip->addString($strHeader . $strData . "\n", $strFolder . '/' . $file);
     }
     $objZip->close();
     $objFile = new File($strZip);
     // Open the "save as …" dialogue
     header('Content-Type: ' . $objFile->mime);
     header('Content-Transfer-Encoding: binary');
     header('Content-Disposition: attachment; filename="' . $objFile->basename . '"');
     header('Content-Length: ' . $objFile->filesize);
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Expires: 0');
     $resFile = fopen(TL_ROOT . '/' . $strZip, 'rb');
     fpassthru($resFile);
     fclose($resFile);
     unlink($strZip);
     // Stop script
     exit;
 }
Пример #5
0
    public function createBackup($vhostDir)
    {
        $backupHosts = htmlspecialchars_decode($vhostDir);
        $arrOutput = array();
        if ($this->Input->post("FORM_SUBMIT") == 'c2g_createbackup') {
            if (!$backupHosts) {
                $arrOutput[] = $GLOBALS['TL_LANG']['tl_content']['c2g_unknownvhost'];
            }
            if (!file_exists(TL_ROOT . '/vhosts/' . $backupHosts)) {
                $arrOutput[] = $GLOBALS['TL_LANG']['tl_content']['c2g_vhostnotexist'];
            }
            if (count($arrOutput) == 0) {
                $backupTime = time();
                $fileName = standardize($backupHosts . '____' . $backupTime);
                $arrConfigReturn = $this->c2g_functions->loadVHostConfig(TL_ROOT . '/vhosts/' . $backupHosts);
                $descFile = array();
                $descFile[] = sprintf('$GLOBALS["package"]["Name"] = "%s";', $backupHosts);
                $descFile[] = sprintf('$GLOBALS["package"]["Description"] = "%s";', htmlspecialchars(nl2br($this->Input->post("description"))));
                $descFile[] = sprintf('$GLOBALS["package"]["Time"] = "%s";', $backupTime);
                $descFile[] = '$GLOBALS["package"]["RootDir"] = "vhosts";';
                $arrOutput[] = $GLOBALS['TL_LANG']['tl_content']['c2g_createdescription'];
                $arrFiles = $this->c2g_functions->getDirectoryTree('vhosts/' . $backupHosts);
                $objZip = new ZipWriter("/backups/" . $fileName . '.c2g');
                $arrDir = array();
                // add ".empty" file to all directories.
                // so, all directory including empty ones are added to the backup
                foreach ($arrFiles as $file) {
                    if (is_dir($file)) {
                        $objEmptyFile = new File($file . '/.empty');
                    }
                }
                foreach ($arrFiles as $file) {
                    if (is_file($file)) {
                        $objSourceFile = new File($file);
                        $strData = $objSourceFile->getContent();
                        if (basename($file) == 'localconfig.php') {
                            $strData = $this->c2g_functions->rewriteLocalconfig($strData, '', '', $arrConfigReturn['localconfig']['dbDatabase'], '', '', $arrConfigReturn['localconfig']['websitePath']);
                        }
                        $objSourceFile->close();
                        $objZip->addString($strData, str_replace("vhosts/", "", $file));
                    } else {
                        $arrDir[$file] = $file;
                    }
                }
                $objZip->addString($this->c2g_functions->createMYSQLDump($arrConfigReturn['localconfig']['dbDatabase']), $fileName . '.sql');
                $objZip->addString(implode("\r\n", $descFile), "description.php");
                //$objZip->addString(implode("\r\n",$arrDir),"directories.dat");
                $objZip->close();
                $arrOutput[] = sprintf('<a href="%s" title="%s">%s</a>', $this->pathMySelf, $GLOBALS['TL_LANG']['tl_content']['c2g_backupreturntooverview'], $GLOBALS['TL_LANG']['tl_content']['c2g_backupreturntooverview']);
            }
        } else {
            $backupTime = time();
            $fileName = standardize($backupHosts . '__' . $backupTime);
            $arrOutput[] = '
<form action="" id="c2g_createbackup" method="post" enctype="multipart/form-data">

<div class="formbody">
<input type="hidden" name="FORM_SUBMIT" value="c2g_createbackup" />
<input type="hidden" name="MAX_FILE_SIZE" value="200000000" />
<input type="hidden" name="REQUEST_TOKEN" value="{{request_token}}" />
  <div class="label"><label>' . $GLOBALS['TL_LANG']['tl_content']['c2g_form_title'] . '</label> </div>
  ' . $fileName . '<br />
  <div class="clear"></div>
  <div class="label"><label>' . $GLOBALS['TL_LANG']['tl_content']['c2g_form_description'] . '</label> </div>
  <textarea name="description" id="ctrl_c2g_form_description" class="textarea" rows="5" cols="40"></textarea><br />
	<div class="submit_container"><input type="submit" id="ctrl_c2g_submit" class="submit" value="' . $GLOBALS['TL_LANG']['tl_content']['c2g_form_submit'] . '" onclick="AjaxRequest.displayBox(\'' . $GLOBALS['TL_LANG']['tl_content']['c2g_pleasewait'] . '\');"/></div>
</div>
</form>
';
        }
        return implode("<br />\r\n", $arrOutput);
    }