/** * 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; }
/** * Do the export. * * @param DataContainer $dc */ public function onsubmit_callback(DataContainer $dc) { // Get delimiter switch ($dc->getData('delimiter')) { case 'semicolon': $delimiter = ';'; break; case 'tabulator': $delimiter = "\t"; break; case 'linebreak': $delimiter = "\n"; break; default: $delimiter = ','; break; } // Get enclosure switch ($dc->getData('enclosure')) { case 'single': $enclosure = '\''; break; default: $enclosure = '"'; break; } // Get fields $fields = $dc->getData('fields'); // Get field labels $labels = array(); foreach ($fields as $field) { switch ($field) { default: $fieldConfig = $GLOBALS['TL_DCA']['orm_avisota_recipient']['fields'][$field]; if (empty($fieldConfig['label'][0])) { $labels[] = $field; } else { $labels[] = $fieldConfig['label'][0] . ' [' . $field . ']'; } break; } } $this->Session->set('AVISOTA_EXPORT', array('delimiter' => $dc->getData('delimiter'), 'enclosure' => $dc->getData('enclosure'), 'fields' => $dc->getData('fields'))); // search for the list $list = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_mailing_list WHERE id=?")->execute($this->Input->get('id')); if (!$list->next()) { $this->log('The recipient list ID ' . $this->Input->get('id') . ' does not exists!', 'orm_avisota_recipient_export', TL_ERROR); $this->redirect('contao/main.php?act=error'); } // create temporary file $temporaryPathname = substr(tempnam(TL_ROOT . '/system/tmp', 'recipients_export_') . '.csv', strlen(TL_ROOT) + 1); // create new file object $temporaryFile = new File($temporaryPathname); // open file handle $temporaryFile->write(''); // write the headline fputcsv($temporaryFile->handle, $labels, $delimiter, $enclosure); // write recipient rows $recipient = \Database::getInstance()->prepare("SELECT * FROM orm_avisota_recipient WHERE pid=?")->execute($this->Input->get('id')); while ($recipient->next()) { $row = array(); foreach ($fields as $field) { switch ($field) { default: $row[] = $recipient->{$field}; } } fputcsv($temporaryFile->handle, $row, $delimiter, $enclosure); } // close file handle $temporaryFile->close(); // create temporary zip file $zipFile = $temporaryPathname . '.zip'; // create a zip writer $zip = new ZipWriter($zipFile); // add the temporary csv $zip->addFile($temporaryPathname, $list->title . '.csv'); // close the zip $zip->close(); // create new file object $zip = new File($zipFile); // Open the "save as …" dialogue header('Content-Type: ' . $zip->mime); header('Content-Transfer-Encoding: binary'); header('Content-Disposition: attachment; filename="' . $list->title . '.zip"'); header('Content-Length: ' . $zip->filesize); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Expires: 0'); // send the zip file $resFile = fopen(TL_ROOT . '/' . $zipFile, 'rb'); fpassthru($resFile); fclose($resFile); // delete temporary files $temporaryFile->delete(); $zip->delete(); exit; }
/** * Run the live update * @param BackendTemplate */ protected function runLiveUpdate(BackendTemplate $objTemplate) { $archive = 'system/tmp/' . $this->Input->get('token'); // Download the archive if (!file_exists(TL_ROOT . '/' . $archive)) { $objRequest = new Request(); $objRequest->send($GLOBALS['TL_CONFIG']['liveUpdateBase'] . 'request.php?token=' . $this->Input->get('token')); if ($objRequest->hasError()) { $objTemplate->updateClass = 'tl_error'; $objTemplate->updateMessage = $objRequest->response; return; } $objFile = new File($archive); $objFile->write($objRequest->response); $objFile->close(); } // Create a minimalistic HTML5 document echo '<!DOCTYPE html>' .'<head>' .'<meta charset="utf-8">' .'<title>Contao Live Update</title>' .'<style>' .'body { background:#f5f5f5 url("../system/themes/default/images/hbg.jpg") left top repeat-x; font-family:Verdana,sans-serif; font-size:11px; color:#444; padding:1em; }' .'div { max-width:680px; margin:0 auto; border:1px solid #bbb; background:#fff; }' .'h1 { font-size:12px; color:#fff; margin:1px; padding:2px 6px 4px; background:#b3b6b3 url("../system/themes/default/images/headline.gif") left top repeat-x; }' .'h2 { font-size:14px; color:#8ab858; margin:18px 15px; padding:6px 42px 8px; background:url("../system/themes/default/images/current.gif") left center no-repeat; }' .'ol { border:1px solid #ccc; max-height:430px; margin:0 15px 18px; overflow:auto; padding:3px 18px 3px 48px; background:#fcfcfc; }' .'li { margin-bottom:3px; }' .'p { margin:0 12px; padding:0; overflow:hidden; }' .'.button { font-family:"Trebuchet MS",Verdana,sans-serif; font-size:12px; display:block; float:right; margin:0 3px 18px; border-radius:3px; background:#808080; text-decoration:none; color:#fff; padding:4px 18px; box-shadow:0 1px 3px #bbb; text-shadow:1px 1px 0 #666; }' .'.button:hover,.button:focus { box-shadow:0 0 6px #8ab858; }' .'.button:active { background:#8ab858; }' .'</style>' .'<body>' .'<div>'; $objArchive = new ZipReader($archive); // Table of contents if ($this->Input->get('toc')) { $arrFiles = $objArchive->getFileList(); array_shift($arrFiles); echo '<hgroup>' .'<h1>Contao Live Update</h1>' .'<h2>' . $GLOBALS['TL_LANG']['tl_maintenance']['toc'] . '</h2>' .'</hgroup>' .'<ol>' .'<li>' . implode('</li><li>', $arrFiles) . '</li>' .'</ol>' .'<p>' .'<a href="' . ampersand(str_replace('toc=1', 'toc=', $this->Environment->base . $this->Environment->request)) . '" class="button">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>' .'<a href="' . $this->Environment->base . 'contao/main.php?do=maintenance" class="button">' . $GLOBALS['TL_LANG']['MSC']['cancelBT'] . '</a>' .'</p>' .'</div>'; exit; } // Backup if ($this->Input->get('bup')) { echo '<hgroup>' .'<h1>Contao Live Update</h1>' .'<h2>' . $GLOBALS['TL_LANG']['tl_maintenance']['backup'] . '</h2>' .'</hgroup>' .'<ol>'; $arrFiles = $objArchive->getFileList(); $objBackup = new ZipWriter('LU' . date('YmdHi') . '.zip'); foreach ($arrFiles as $strFile) { if ($strFile == 'TOC.txt' || $strFile == 'system/runonce.php') { continue; } try { $objBackup->addFile($strFile); echo '<li>Backed up ' . $strFile . '</li>'; } catch (Exception $e) { echo '<li>' . $e->getMessage() . ' (skipped)</li>'; } } $objBackup->close(); echo '</ol>' .'<p>' .'<a href="' . ampersand(str_replace('bup=1', 'bup=', $this->Environment->base . $this->Environment->request)) . '" id="continue" class="button">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>' .'<a href="' . $this->Environment->base . 'contao/main.php?do=maintenance" id="back" class="button">' . $GLOBALS['TL_LANG']['MSC']['cancelBT'] . '</a>' .'</p>' .'</div>'; exit; } echo '<hgroup>' .'<h1>Contao Live Update</h1>' .'<h2>' . $GLOBALS['TL_LANG']['tl_maintenance']['update'] . '</h2>' .'</hgroup>' .'<ol>'; // Update while ($objArchive->next()) { if ($objArchive->file_name == 'TOC.txt') { continue; } try { $objFile = new File($objArchive->file_name); $objFile->write($objArchive->unzip()); $objFile->close(); echo '<li>Updated ' . $objArchive->file_name . '</li>'; } catch (Exception $e) { echo '<li><span style="color:#c55">Error updating ' . $objArchive->file_name . ': ' . $e->getMessage() . '</span></li>'; } } // Delete the archive $this->import('Files'); $this->Files->delete($archive); // Add a log entry $this->log('Live update from version ' . VERSION . '.' . BUILD . ' to version ' . $GLOBALS['TL_CONFIG']['latestVersion'] . ' completed', 'LiveUpdate run()', TL_GENERAL); echo '</ol>' .'<p>' .'<a href="' . $this->Environment->base . 'contao/main.php?do=maintenance&act=runonce" id="continue" class="button">' . $GLOBALS['TL_LANG']['MSC']['continue'] . '</a>' .'</p>' .'</div>'; exit; }
/** * 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; }
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); }