function importPageDirectory($dir, $prefix = "") { echo "\n<!-- Checking page directory " . xmlCommentSafe($dir) . " -->\n"; $mydir = opendir($dir); while ($entry = readdir($mydir)) { if (preg_match('/^(.+)\\.db$/', $entry, $m)) { echo importPage($prefix . $m[1]); } else { if (is_dir("{$dir}/{$entry}")) { if ($entry != '.' && $entry != '..') { importPageDirectory("{$dir}/{$entry}", "{$entry}/"); } } else { echo "<!-- File '" . xmlCommentSafe($entry) . "' doesn't seem to contain an article. Skipping. -->\n"; } } } }
if (isset($_GET['delete']) && !empty($_GET['delete'])) { deleteBook(); } // display writted log asked if (isset($_GET['logs'])) { logsPage(); } // display settings log asked if (isset($_GET['settings'])) { settingsPage(); } // display export page asked if (isset($_GET['export'])) { exportPage(); } // display import page asked if (isset($_GET['import'])) { importPage(); } // nothing to do: 404 error function notFound() { global $tpl; header('HTTP/1.1 404 Not Found', true, 404); $tpl->assign('page_title', 'Error 404'); $tpl->assign('menu_links', Path::menu('error')); $tpl->assign('menu_links_admin', Path::menuAdmin('error')); $tpl->draw('404'); exit; } notFound();
function importFile($file) { $name = decodeName($file); if (!$_REQUEST['xpf']) { // Treat the contents of the file as literal data. if (!($source = file_get_contents($file))) { return false; } return importPage($name, $source, array('stamp' => filemtime($file))); } // Treat the file as a page written in XPF: // Build a version history. if (!($f = fopen($file, "r"))) { return false; } $history = array(); $head = array(); while ($line = fgets($f, 16384)) { if ($line == "\n") { if (!$head['stamp'] && !$head['size']) { pieError("FormatError", array('page' => htmlspecialchars($name))); } $head['offset'] = ftell($f); if (fseek($f, $head['size'], SEEK_CUR) == -1) { pieError("FormatError", array('page' => htmlspecialchars($name))); } $history[$head['stamp']] = $head; $head = array(); } elseif (preg_match('/^(\\w+)=(.+)$/', $line, $match)) { $head[$match[1]] = $match[2]; } else { pieError("FormatError", array('page' => htmlspecialchars($name))); } } // Process all versions in order from oldest to latest. ksort($history); foreach ($history as $stamp => $head) { if ($head['type'] == 'alias') { importPage($name, '', $head); continue; } if (fseek($f, $head['offset'], CUR_SET) == -1) { pieError("FormatError", array('page' => htmlspecialchars($name))); } if (!($source = fread($f, $head['size']))) { pieError("FormatError", array('page' => htmlspecialchars($name))); } unset($head['offset']); if (!importPage($name, $source, $head)) { return false; } } fclose($f); return true; }