break; } return $response; } /** * */ function adminGenerator() { $userfiles_dirs = $this->getDirectoriesDescription(); // default directory if not set - either "Main files" or just the first. $r = array_keys($userfiles_dirs); $category = in_array('special', $r) ? 'special' : $r[0]; if (isset($_GET['category']) && $_GET['category'] > '') { $category = $_GET['category']; } // init $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = true; $xml->formatOutput = true; $root = $xml->createElement('root'); $xml->appendChild($root); // category - single for all files $root->appendChild($xml->createElement('category'))->nodeValue = $category; $root->appendChild($xml->createElement('full-path'))->nodeValue = $userfiles_dirs[$category]['dir']; // directory list $root->appendChild($directories_node = $xml->createElement('directories')); foreach ($userfiles_dirs as $alias => $dir) { $directories_node->appendChild($dir_node = $xml->createElement('directory')); if ($alias == $category) { $dir_node->setAttribute('selected', 'selected'); } $dir_node->appendChild($xml->createElement('caption'))->nodeValue = $dir['caption']; $dir_node->appendChild($xml->createElement('alias'))->nodeValue = $alias; } // if folder selected and exists, output its files if (isset($userfiles_dirs[$category])) { $dir = $userfiles_dirs[$category]; if (file_exists($dir['dir']) && is_dir($dir['dir'])) { $root->appendChild($filelist_node = $xml->createElement('files')); $d = scandir($dir['dir']); foreach ($d as $filename) { $filename = iconv(filesystem_encoding(), 'utf-8', $filename); if (preg_match('~^' . $dir['regexp_filename'] . '$~ui', $filename) > 0) { // only matched files $filelist_node->appendChild($file_node = $xml->createElement('file')); $file_node->appendChild($xml->createElement('filename'))->nodeValue = $filename; $file_node->appendChild($xml->createElement('path'))->nodeValue = $dir['dir'] . $filename;
/** * Restores data from the backup * * @param string $filename * @return mixed true on success, error message on the first error, further processing skipped */ private function restoreBackup($filename) { $result = true; // get archive $zip = new ZipArchive(); if ($zip->open(__DIR__ . '/data/' . $filename) !== true) { return false; } for ($i = 0; $i < $zip->numFiles; $i++) { if (($filename = $zip->getNameIndex($i)) > '') { if (@file_put_contents('./' . iconv('CP866', filesystem_encoding(), $filename), $zip->getFromIndex($i)) === false) { return 'FAILED on : ' . iconv('CP866', 'utf-8', $filename); // output always in UTF-8 } } } return $result; }
/** * * */ function adminGenerator() { // init $xml = new DOMDocument('1.0', 'utf-8'); $xml->preserveWhiteSpace = true; $xml->formatOutput = true; $root = $xml->createElement('root'); $xml->appendChild($root); $dir = __DIR__ . '/templates/'; if (file_exists($dir) && is_dir($dir)) { $root->appendChild($filelist_node = $xml->createElement('files')); $d = scandir($dir); foreach ($d as $filename) { if (substr($filename, 0, 1) == '.') { continue; } $content = file_get_contents(__DIR__ . '/templates/' . $filename); $title = preg_match('~<title>([^<]*)</title>~ui', $content, $match) ? $match[1] : '*** no title ***'; $filename = iconv(filesystem_encoding(), 'utf-8', $filename); $filelist_node->appendChild($file_node = $xml->createElement('file')); $file_node->appendChild($xml->createElement('filename'))->nodeValue = $filename; $file_node->appendChild($xml->createElement('title'))->nodeValue = $title; } } return XSLTransform($xml->saveXML($root), __DIR__ . '/list.xsl'); }