/** * The main() function which generates a zip archive of a PhpWiki. * * If $include_archive is false, only the current version of each page * is included in the zip file; otherwise all archived versions are * included as well. */ function MakeWikiZip($include_archive = false) { global $dbi, $WikiPageStore, $ArchivePageStore; $pages = GetAllWikiPageNames($dbi); $zipname = "wiki.zip"; if ($include_archive) { $zipname = "wikidb.zip"; } $zip = new ZipWriter("Created by PhpWiki", $zipname); for (reset($pages); $pagename = current($pages); next($pages)) { set_time_limit(30); // Reset watchdog. $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore); if (!is_array($pagehash)) { continue; } if ($include_archive) { $oldpagehash = RetrievePage($dbi, $pagename, $ArchivePageStore); } else { $oldpagehash = false; } $attrib = array('mtime' => $pagehash['lastmodified'], 'is_ascii' => 1); if (($pagehash['flags'] & FLAG_PAGE_LOCKED) != 0) { $attrib['write_protected'] = 1; } $content = MailifyPage($pagehash, $oldpagehash); $zip->addRegularFile(encode_pagename_for_wikizip($pagehash['pagename']), $content, $attrib); } $zip->finish(); }
/** * 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; }
public function generateArchiveOutput(WatchlistItemModel $objItem, \ZipWriter $objZip) { $objFile = \FilesModel::findById($objItem->uuid); if ($objFile === null) { return $objZip; } $objZip->addFile($objFile->path, $objFile->name); return $objZip; }
/** * 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; }
function MakeWikiZipHtml(&$request) { $request->_TemplatesProcessed = array(); $zipname = "wikihtml.zip"; $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); $dbi =& $request->_dbi; $thispage = $request->getArg('pagename'); // for "Return to ..." if ($exclude = $request->getArg('exclude')) { // exclude which pagenames $excludeList = explodePageList($exclude); } else { $excludeList = array(); } if ($pages = $request->getArg('pages')) { // which pagenames if ($pages == '[]') { // current page $pages = $thispage; } $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages)); } else { $page_iter = $dbi->getAllPages(false, false, false, $excludeList); } global $WikiTheme; if (defined('HTML_DUMP_SUFFIX')) { $WikiTheme->HTML_DUMP_SUFFIX = HTML_DUMP_SUFFIX; } $WikiTheme->DUMP_MODE = 'ZIPHTML'; $_bodyAttr = @$WikiTheme->_MoreAttr['body']; unset($WikiTheme->_MoreAttr['body']); /* ignore fatals in plugins */ if (check_php_version(4, 1)) { global $ErrorManager; $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); } $request_args = $request->args; $timeout = !$request->getArg('start_debug') ? 20 : 240; while ($page = $page_iter->next()) { $request->args = $request_args; // some plugins might change them (esp. on POST) longer_timeout($timeout); // Reset watchdog $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) { continue; } $pagename = $page->getName(); if (in_array($pagename, $excludeList)) { continue; } $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1); if ($page->get('locked')) { $attrib['write_protected'] = 1; } $request->setArg('pagename', $pagename); // Template::_basepage fix $filename = FilenameForPage($pagename) . $WikiTheme->HTML_DUMP_SUFFIX; $revision = $page->getCurrentRevision(); $transformedContent = $revision->getTransformedContent(); $template = new Template('browse', $request, array('revision' => $revision, 'CONTENT' => $transformedContent)); $data = GeneratePageasXML($template, $pagename); $zip->addRegularFile($filename, $data, $attrib); if (USECACHE) { $request->_dbi->_cache->invalidate_cache($pagename); unset($request->_dbi->_cache->_pagedata_cache); unset($request->_dbi->_cache->_versiondata_cache); unset($request->_dbi->_cache->_glv_cache); } unset($request->_dbi->_cache->_backend->_page_data); unset($revision->_transformedContent); unset($revision); unset($template->_request); unset($template); unset($data); } $page_iter->free(); $attrib = false; // Deal with css and images here. if (!empty($WikiTheme->dumped_images) and is_array($WikiTheme->dumped_images)) { // dirs are created automatically //if ($WikiTheme->dumped_images) $zip->addRegularFile("images", "", $attrib); foreach ($WikiTheme->dumped_images as $img_file) { if ($from = $WikiTheme->_findFile($img_file, true) and basename($from)) { $target = "images/" . basename($img_file); if (check_php_version(4, 3)) { $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib); } else { $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib); } } } } if (!empty($WikiTheme->dumped_buttons) and is_array($WikiTheme->dumped_buttons)) { //if ($WikiTheme->dumped_buttons) $zip->addRegularFile("images/buttons", "", $attrib); foreach ($WikiTheme->dumped_buttons as $text => $img_file) { if ($from = $WikiTheme->_findFile($img_file, true) and basename($from)) { $target = "images/buttons/" . basename($img_file); if (check_php_version(4, 3)) { $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib); } else { $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib); } } } } if (!empty($WikiTheme->dumped_css) and is_array($WikiTheme->dumped_css)) { foreach ($WikiTheme->dumped_css as $css_file) { if ($from = $WikiTheme->_findFile(basename($css_file), true) and basename($from)) { $target = basename($css_file); if (check_php_version(4, 3)) { $zip->addRegularFile($target, file_get_contents($WikiTheme->_path . $from), $attrib); } else { $zip->addRegularFile($target, join('', file($WikiTheme->_path . $from)), $attrib); } } } } $zip->finish(); if (check_php_version(4, 1)) { global $ErrorManager; $ErrorManager->popErrorHandler(); } $WikiTheme->HTML_DUMP_SUFFIX = ''; $WikiTheme->DUMP_MODE = false; $WikiTheme->_MoreAttr['body'] = $_bodyAttr; }
/** * 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; }
/** * Add templates to the archive * * @param \ZipWriter $objArchive * @param string $strFolder */ protected function addTemplatesToArchive(\ZipWriter $objArchive, $strFolder) { // Strip the templates folder name $strFolder = preg_replace('@^templates/@', '', $strFolder); // Re-add the templates folder name if ($strFolder == '') { $strFolder = 'templates'; } else { $strFolder = 'templates/' . $strFolder; } if (\Validator::isInsecurePath($strFolder)) { throw new \RuntimeException('Insecure path ' . $strFolder); } // Return if the folder does not exist if (!is_dir(TL_ROOT . '/' . $strFolder)) { return; } $arrAllowed = trimsplit(',', \Config::get('templateFiles')); array_push($arrAllowed, 'sql'); // see #7048 // Add all template files to the archive foreach (scan(TL_ROOT . '/' . $strFolder) as $strFile) { if (preg_match('/\\.(' . implode('|', $arrAllowed) . ')$/', $strFile) && strncmp($strFile, 'be_', 3) !== 0 && strncmp($strFile, 'nl_', 3) !== 0) { $objArchive->addFile($strFolder . '/' . $strFile); } } }
/** * Add templates to the archive * @param ZipWriter * @param string */ protected function addTemplatesToArchive(ZipWriter $objArchive, $strFolder) { // Sanitize the folder name $strFolder = str_replace('../', '', $strFolder); $strFolder = preg_replace('@^templates/@', '', $strFolder); if ($strFolder == '') { $strFolder = 'templates'; } else { $strFolder = 'templates/' . $strFolder; } // Return if the folder does not exist if (!is_dir(TL_ROOT .'/'. $strFolder)) { return; } $arrAllowed = trimsplit(',', $GLOBALS['TL_CONFIG']['templateFiles']); // Add all template files to the archive foreach (scan(TL_ROOT .'/'. $strFolder) as $strFile) { if (preg_match('/\.(' . implode('|', $arrAllowed) . ')$/', $strFile) && strncmp($strFile, 'be_', 3) !== 0 && strncmp($strFile, 'nl_', 3) !== 0) { $objArchive->addFile($strFolder .'/'. $strFile); } } }
/** * The main() function which generates a zip archive of a PhpWiki. * * If $include_archive is false, only the current version of each page * is included in the zip file; otherwise all archived versions are * included as well. */ function MakeWikiZip(&$request) { global $ErrorManager; if ($request->getArg('include') == 'all') { $zipname = WIKI_NAME . _("FullDump") . date('Ymd-Hi') . '.zip'; $include_archive = true; } else { $zipname = WIKI_NAME . _("LatestSnapshot") . date('Ymd-Hi') . '.zip'; $include_archive = false; } $include_empty = false; if ($request->getArg('include') == 'empty') { $include_empty = true; } $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $zipname); /* ignore fatals in plugins */ $ErrorManager->pushErrorHandler(new WikiFunctionCb('_dump_error_handler')); $dbi =& $request->_dbi; $thispage = $request->getArg('pagename'); // for "Return to ..." if ($exclude = $request->getArg('exclude')) { // exclude which pagenames $excludeList = explodePageList($exclude); } else { $excludeList = array(); } if ($pages = $request->getArg('pages')) { // which pagenames if ($pages == '[]') { // current page $pages = $thispage; } $page_iter = new WikiDB_Array_PageIterator(explodePageList($pages)); } else { $page_iter = $dbi->getAllPages(false, false, false, $excludeList); } $request_args = $request->args; $timeout = !$request->getArg('start_debug') ? 30 : 240; while ($page = $page_iter->next()) { $request->args = $request_args; // some plugins might change them (esp. on POST) longer_timeout($timeout); // Reset watchdog $current = $page->getCurrentRevision(); if ($current->getVersion() == 0) { continue; } $pagename = $page->getName(); $wpn = new WikiPageName($pagename); if (!$wpn->isValid()) { continue; } if (in_array($page->getName(), $excludeList)) { continue; } $attrib = array('mtime' => $current->get('mtime'), 'is_ascii' => 1); if ($page->get('locked')) { $attrib['write_protected'] = 1; } if ($include_archive) { $content = MailifyPage($page, 0); } else { $content = MailifyPage($page); } $zip->addRegularFile(FilenameForPage($pagename), $content, $attrib); } $zip->finish(); $ErrorManager->popErrorHandler(); }
function dumpFile(&$thispage, $filename) { include_once "lib/loadsave.php"; $mailified = MailifyPage($thispage); $attrib = array('mtime' => $thispage->get('mtime'), 'is_ascii' => 1); $zip = new ZipWriter("Created by PhpWiki " . PHPWIKI_VERSION, $filename); $zip->addRegularFile(FilenameForPage($thispage->getName()), $mailified, $attrib); $zip->finish(); }
/** * 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); }
/** * Starts the download of the specified messages. * * @param string $pmIDs */ public static function downloadAll($pmIDs) { // count messages $sql = "SELECT\tCOUNT(*) AS count\n\t\t\tFROM\twcf" . WCF_N . "_pm\n\t\t\tWHERE\tpmID IN (" . $pmIDs . ")"; $row = WCF::getDB()->getFirstRow($sql); $count = $row['count']; // get recipients $recpients = array(); $sql = "SELECT\t\t*\n\t\t\tFROM\t\twcf" . WCF_N . "_pm_to_user\n\t\t\tWHERE\t\tpmID IN (" . $pmIDs . ")\n\t\t\t\t\tAND isBlindCopy = 0\n\t\t\tORDER BY\trecipient"; $result = WCF::getDB()->sendQuery($sql); while ($row = WCF::getDB()->fetchArray($result)) { if (!isset($recpients[$row['pmID']])) { $recpients[$row['pmID']] = array(); } $recpients[$row['pmID']][] = new PMRecipient(null, null, $row); } // get messages if ($count > 1) { $zip = new ZipWriter(); } $sql = "SELECT\t\trecipient.*,\n\t\t\t\t\tpm.*\n\t\t\tFROM\t\twcf" . WCF_N . "_pm pm\n\t\t\tLEFT JOIN \twcf" . WCF_N . "_pm_to_user recipient\n\t\t\tON \t\t(recipient.pmID = pm.pmID\n\t\t\t\t\tAND recipient.recipientID = " . WCF::getUser()->userID . "\n\t\t\t\t\tAND recipient.isDeleted < 2)\n\t\t\tWHERE\t\tpm.pmID IN (" . $pmIDs . ")\n\t\t\tGROUP BY\tpm.pmID\n\t\t\tORDER BY\tpm.time DESC"; $result = WCF::getDB()->sendQuery($sql); $messageNo = 1; while ($row = WCF::getDB()->fetchArray($result)) { $pm = new PM(null, $row); $pm->setRecipients(isset($recpients[$row['pmID']]) ? $recpients[$row['pmID']] : array()); // get parsed text require_once WCF_DIR . 'lib/data/message/bbcode/MessageParser.class.php'; $parser = MessageParser::getInstance(); $parser->setOutputType('text/plain'); $parsedText = $parser->parse($pm->message, $pm->enableSmilies, $pm->enableHtml, $pm->enableBBCodes, false); $data = array('$author' => $pm->username ? $pm->username : WCF::getLanguage()->get('wcf.pm.author.system'), '$date' => DateUtil::formatTime(null, $pm->time), '$recipient' => implode(', ', $pm->getRecipients()), '$subject' => $pm->subject, '$text' => $parsedText); if ($count == 1) { // send headers // file type @header('Content-Type: text/plain'); // file name @header('Content-disposition: attachment; filename="' . $pm->pmID . '-' . preg_replace('~[^a-z0-9_ -]+~i', '', $pm->subject) . '.txt"'); // no cache headers @header('Pragma: no-cache'); @header('Expires: 0'); // output message echo (CHARSET == 'UTF-8' ? "" : '') . WCF::getLanguage()->get('wcf.pm.download.message', $data); exit; } else { $zip->addFile((CHARSET == 'UTF-8' ? "" : '') . WCF::getLanguage()->get('wcf.pm.download.message', $data), $pm->pmID . '-' . preg_replace('~[^a-z0-9_ -]+~i', '', $pm->subject) . '.txt', $pm->time); } $messageNo++; } if ($messageNo > 1) { // send headers // file type @header('Content-Type: application/octet-stream'); // file name @header('Content-disposition: attachment; filename="messages-' . ($messageNo - 1) . '.zip"'); // no cache headers @header('Pragma: no-cache'); @header('Expires: 0'); // output file echo $zip->getFile(); exit; } }
public function __construct($strFile) { parent::__construct($strFile); }