2 include("t_config.php");
6 <title>insert plain text files as pages into ewiki db</title>
7 <link rel="stylesheet" type="text/css" href="t_config.css">
9 <body bgcolor="#ffffff" text="#000000">
10 <h1>text file insertion util</h1>
15 if (empty($_REQUEST["from"])) {
19 Use this tool to (re)insert text files as pages into the database (like the
20 automatic initialization if ewiki.php, when it is run for the very first
21 time). Before it overwrites anything you must first select the files to be
22 inserted from the list of found files, in the subdirectory you can select
25 <FORM ACTION="t_textinsert.php" METHOD="GET">
26 subdir with page files: <INPUT NAME="from" VALUE="./init-pages">
28 <INPUT type="submit" VALUE=" list files ">
34 elseif (empty($_REQUEST["insert"])) {
36 if (strstr(substr($from, 3), "/")) die("unallowed subdir name");
39 if ($dh = opendir($from = $_REQUEST["from"] . "/")) {
41 while ($fn = readdir($dh)) {
43 if (is_file($from . $fn)) {
51 echo '<FORM ACTION="t_textinsert.php" METHOD="GET">' .
52 '<INPUT NAME="from" TYPE="hidden" VALUE="'.rtrim($from, "/").'">';
54 echo '<TABLE BORDER="0" CELLSPACING="3" CELLPADDING="2">';
56 foreach ($files as $fn) {
61 $data = ewiki_db::GET($fn);
65 $reason .= "<b>not yet in database</b><br>\n";
67 elseif (!strlen(trim($data["content"]))) {
69 $reason .= "<b>database entry empty</b><br>\n";
71 elseif ($data["lastmodified"] < filemtime($from.$fn)) {
73 $reason .= "<b>database entry is older</b><br>\n";
75 elseif (strlen($data["content"]) < filesize($from.$fn)) {
77 $reason .= "<b>database entry is shorter</b><br>\n";
80 if (strlen($data["content"]) > filesize($from.$fn)) {
82 $reason .= "database entry is <i>longer</i>!<br>\n";
85 if ($data["lastmodified"] >= filemtime($from.$fn)) {
87 $reason .= "database entry is <i>newer</i>!<br>\n";
90 if (!filesize($from . $fn)) {
92 $reason .= "empty file<br>\n";
95 echo '<TR><TD BGCOLOR="#9090B0">';
96 echo '<INPUT NAME="file[' . $fn . ']" TYPE="checkbox" VALUE="1" ' . ($sel ? " CHECKED" : "") . '>';
98 echo "</TD>\n" . '<TD BGCOLOR="#9090B0">';
99 echo $reason . "</TD></TR>\n";
104 '<INPUT TYPE="submit" NAME="insert" VALUE=" insert files ">' .
110 $from = $_REQUEST["from"];
111 $files = $_REQUEST["file"];
112 if (strstr(substr($from, 3), "/")) die("unallowed subdir name");
115 foreach ($files as $fn => $uu) {
117 if (strstr($fn, "/") ||strstr($fn, ".") || (!$uu)) {
118 echo "filename '$fn' not allowed (NOTE: no versioned pages!)...<br>\n";
122 $ctime = filectime($from . $fn);
123 $content = implode("", file($from . $fn));
125 $prev = ewiki_db::GET($fn);
129 "version" => 1+ @$prev["version"],
130 "author" => ewiki_author("ewiki_backdown"),
131 "flags" => EWIKI_DB_F_TEXT | @$prev["flags"],
132 "content" => $content,
134 "lastmodified" => time(),
137 "hits" => 0+ @$prev["hits"],
140 $r = (ewiki_db::WRITE($data) ? "ok" : "error");
142 echo "writing '$fn'... [$r]<br>\n";