Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 481 lines (390 sloc) 11.992 kb
b1ba0ea initial commit
stevenfrank880 authored
1 <?php
2 /*
4031ba5 @BenWard Restructure: Separate libs.
authored
3 * Simpliwiki
4 *
5 * Copyright (C) 2010 Ben Ward <http://benward.me>
6 * Parts from W2, Copyright (C) 2007-2009 Steven Frank <http://stevenf.com/>
b1ba0ea initial commit
stevenfrank880 authored
7 *
8 * Code may be re-used as long as the above copyright notice is retained.
9 * See README.txt for full details.
10 */
4031ba5 @BenWard Restructure: Separate libs.
authored
11
12 include_once "lib/markdown.php";
b1ba0ea initial commit
stevenfrank880 authored
13
14 // User configurable options:
15
63dc02e changes for 1.0.1
stevenfrank880 authored
16 include_once "config.php";
17
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
18 ini_set('session.gc_maxlifetime', W2_SESSION_LIFETIME);
2748379 set longer cookie expiration; expand textarea to width of brwoser for de...
stevenfrank880 authored
19
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
20 session_set_cookie_params(W2_SESSION_LIFETIME);
21 session_name(W2_SESSION_NAME);
4773d05 added very basic optional password protection
stevenfrank880 authored
22 session_start();
23
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
24 if ( count($allowedIPs) > 0 )
25 {
26 $ip = $_SERVER['REMOTE_ADDR'];
27 $accepted = false;
4031ba5 @BenWard Restructure: Separate libs.
authored
28
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
29 foreach ( $allowedIPs as $allowed )
30 {
31 if ( strncmp($allowed, $ip, strlen($allowed)) == 0 )
32 {
33 $accepted = true;
34 break;
35 }
36 }
4031ba5 @BenWard Restructure: Separate libs.
authored
37
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
38 if ( !$accepted )
39 {
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
40 print "<html><body>Access from IP address $ip is not allowed";
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
41 print "</body></html>";
42 exit;
43 }
44 }
45
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
46 if ( REQUIRE_PASSWORD && !isset($_SESSION['password']) )
4773d05 added very basic optional password protection
stevenfrank880 authored
47 {
7997711 slight reformatting of config file to be prettier; W2_PASSWORD_HASH can ...
stevenfrank880 authored
48 if ( !defined('W2_PASSWORD_HASH') || W2_PASSWORD_HASH == '' )
7b2da78 * passwords are now stored in session as sha1 hashes
abhibeckert authored
49 define('W2_PASSWORD_HASH', sha1(W2_PASSWORD));
4031ba5 @BenWard Restructure: Separate libs.
authored
50
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
51 if ( (isset($_POST['p'])) && (sha1($_POST['p']) == W2_PASSWORD_HASH) )
7b2da78 * passwords are now stored in session as sha1 hashes
abhibeckert authored
52 $_SESSION['password'] = W2_PASSWORD_HASH;
4773d05 added very basic optional password protection
stevenfrank880 authored
53 else
54 {
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
55 print "<html><body><form method=\"post\"><input type=\"password\" name=\"p\"><input type=\"submit\" value=\"Go\"></form>";
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
56 print "</body></html>";
4773d05 added very basic optional password protection
stevenfrank880 authored
57 exit;
58 }
59 }
60
63dc02e changes for 1.0.1
stevenfrank880 authored
61 // Support functions
b1ba0ea initial commit
stevenfrank880 authored
62
63 function printToolbar()
64 {
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
65 global $upage, $page, $action;
63dc02e changes for 1.0.1
stevenfrank880 authored
66
b1ba0ea initial commit
stevenfrank880 authored
67 print "<div class=\"toolbar\">";
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
68 print "<a class=\"tool first\" href=\"" . SELF . "?action=edit&amp;page=$upage\">Edit</a> ";
69 print "<a class=\"tool\" href=\"" . SELF . "?action=new\">New</a> ";
63dc02e changes for 1.0.1
stevenfrank880 authored
70
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
71 if ( !DISABLE_UPLOADS )
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
72 print "<a class=\"tool\" href=\"" . SELF . VIEW . "?action=upload\">Upload</a> ";
63dc02e changes for 1.0.1
stevenfrank880 authored
73
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
74 print "<a class=\"tool\" href=\"" . SELF . "?action=all_name\">All</a> ";
75 print "<a class=\"tool\" href=\"" . SELF . "?action=all_date\">Recent</a> ";
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
76 print "<a class=\"tool\" href=\"" . SELF . "\">". DEFAULT_PAGE . "</a>";
4031ba5 @BenWard Restructure: Separate libs.
authored
77
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
78 if ( REQUIRE_PASSWORD )
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
79 print '<a class="tool" href="' . SELF . '?action=logout">Logout</a>';
4031ba5 @BenWard Restructure: Separate libs.
authored
80
b1ba0ea initial commit
stevenfrank880 authored
81 print "</div>\n";
82 }
83
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
84
4031ba5 @BenWard Restructure: Separate libs.
authored
85 function descLengthSort($val_1, $val_2)
86 {
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
87 $retVal = 0;
88
4031ba5 @BenWard Restructure: Separate libs.
authored
89 $firstVal = strlen($val_1);
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
90 $secondVal = strlen($val_2);
91
4031ba5 @BenWard Restructure: Separate libs.
authored
92 if ( $firstVal > $secondVal )
93 $retVal = -1;
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
94
4031ba5 @BenWard Restructure: Separate libs.
authored
95 else if ( $firstVal < $secondVal )
96 $retVal = 1;
97
98 return $retVal;
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
99 }
100
101
b1ba0ea initial commit
stevenfrank880 authored
102 function toHTML($inText)
103 {
104 global $page;
4031ba5 @BenWard Restructure: Separate libs.
authored
105
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
106 $dir = opendir(PAGES_PATH);
107 while ( $filename = readdir($dir) )
108 {
109 if ( $filename{0} == '.' )
110 continue;
4031ba5 @BenWard Restructure: Separate libs.
authored
111
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
112 $filename = preg_replace("/(.*?)\.txt/", "\\1", $filename);
113 $filenames[] = $filename;
114 }
115 closedir($dir);
4031ba5 @BenWard Restructure: Separate libs.
authored
116
117 uasort($filenames, "descLengthSort");
63dc02e changes for 1.0.1
stevenfrank880 authored
118
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
119 if ( AUTOLINK_PAGE_TITLES )
4031ba5 @BenWard Restructure: Separate libs.
authored
120 {
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
121 foreach ( $filenames as $filename )
122 {
123 $inText = preg_replace("/(?<![\>\[\/])($filename)(?!\]\>)/im", "<a href=\"" . SELF . VIEW . "/$filename\">\\1</a>", $inText);
124 }
125 }
4031ba5 @BenWard Restructure: Separate libs.
authored
126
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
127 $inText = preg_replace("/\[\[(.*?)\]\]/", "<a href=\"" . SELF . VIEW . "/\\1\">\\1</a>", $inText);
b1ba0ea initial commit
stevenfrank880 authored
128 $inText = preg_replace("/\{\{(.*?)\}\}/", "<img src=\"images/\\1\" alt=\"\\1\" />", $inText);
a113399 auto-link message: URLs pasted from Apple Mail
stevenfrank880 authored
129 $inText = preg_replace("/message:(.*?)\s/", "[<a href=\"message:\\1\">email</a>]", $inText);
130
561f670 Fixed bug where form was submitting to /index.php/Home when creating a n...
abhibeckert authored
131 $html = Markdown($inText);
63dc02e changes for 1.0.1
stevenfrank880 authored
132
b1ba0ea initial commit
stevenfrank880 authored
133 return $html;
134 }
135
63dc02e changes for 1.0.1
stevenfrank880 authored
136 function sanitizeFilename($inFileName)
b1ba0ea initial commit
stevenfrank880 authored
137 {
63dc02e changes for 1.0.1
stevenfrank880 authored
138 return str_replace(array('..', '~', '/', '\\', ':'), '-', $inFileName);
139 }
140
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
141 function destroy_session()
142 {
143 if ( isset($_COOKIE[session_name()]) )
d2ca097 added nicer error message on save failure
stevenfrank880 authored
144 setcookie(session_name(), '', time() - 42000, '/');
fdbf1f9 minor whitespace tweaks
stevenfrank880 authored
145
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
146 session_destroy();
147 unset($_SESSION["password"]);
148 unset($_SESSION);
149 }
150
63dc02e changes for 1.0.1
stevenfrank880 authored
151 // Support PHP4 by defining file_put_contents if it doesn't already exist
152
153 if ( !function_exists('file_put_contents') )
154 {
d2ca097 added nicer error message on save failure
stevenfrank880 authored
155 function file_put_contents($n, $d)
63dc02e changes for 1.0.1
stevenfrank880 authored
156 {
d2ca097 added nicer error message on save failure
stevenfrank880 authored
157 $f = @fopen($n, "w");
4031ba5 @BenWard Restructure: Separate libs.
authored
158
63dc02e changes for 1.0.1
stevenfrank880 authored
159 if ( !$f )
160 {
161 return false;
162 }
163 else
164 {
d2ca097 added nicer error message on save failure
stevenfrank880 authored
165 fwrite($f, $d);
63dc02e changes for 1.0.1
stevenfrank880 authored
166 fclose($f);
167 return true;
168 }
169 }
b1ba0ea initial commit
stevenfrank880 authored
170 }
171
63dc02e changes for 1.0.1
stevenfrank880 authored
172 // Main code
173
174 if ( isset($_REQUEST['action']) )
175 $action = $_REQUEST['action'];
4031ba5 @BenWard Restructure: Separate libs.
authored
176 else
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
177 $action = 'view';
63dc02e changes for 1.0.1
stevenfrank880 authored
178
4031ba5 @BenWard Restructure: Separate libs.
authored
179 if ( preg_match('@^/@', @$_SERVER["PATH_INFO"]) )
63dc02e changes for 1.0.1
stevenfrank880 authored
180 $page = sanitizeFilename(substr($_SERVER["PATH_INFO"], 1));
4031ba5 @BenWard Restructure: Separate libs.
authored
181 else
561f670 Fixed bug where form was submitting to /index.php/Home when creating a n...
abhibeckert authored
182 $page = sanitizeFilename(@$_REQUEST['page']);
63dc02e changes for 1.0.1
stevenfrank880 authored
183
b1ba0ea initial commit
stevenfrank880 authored
184 $upage = urlencode($page);
185
186 if ( $page == "" )
187 $page = DEFAULT_PAGE;
63dc02e changes for 1.0.1
stevenfrank880 authored
188
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
189 $filename = PAGES_PATH . "/$page.txt";
b1ba0ea initial commit
stevenfrank880 authored
190
191 if ( file_exists($filename) )
192 {
193 $text = file_get_contents($filename);
194 }
195 else
196 {
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
197 if ( $action != "save" && $action != "all_name" && $action != "all_date" && $action != "upload" && $action != "new" && $action != "logout" && $action != "uploaded" && $action != "search" && $action != "view" )
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
198 {
b1ba0ea initial commit
stevenfrank880 authored
199 $action = "edit";
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
200 }
b1ba0ea initial commit
stevenfrank880 authored
201 }
63dc02e changes for 1.0.1
stevenfrank880 authored
202
b1ba0ea initial commit
stevenfrank880 authored
203 if ( $action == "edit" || $action == "new" )
204 {
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
205 $formAction = SELF . (($action == 'edit') ? "/$page" : "");
561f670 Fixed bug where form was submitting to /index.php/Home when creating a n...
abhibeckert authored
206 $html = "<form id=\"edit\" method=\"post\" action=\"$formAction\">\n";
63dc02e changes for 1.0.1
stevenfrank880 authored
207
b1ba0ea initial commit
stevenfrank880 authored
208 if ( $action == "edit" )
63dc02e changes for 1.0.1
stevenfrank880 authored
209 $html .= "<input type=\"hidden\" name=\"page\" value=\"$page\" />\n";
b1ba0ea initial commit
stevenfrank880 authored
210 else
63dc02e changes for 1.0.1
stevenfrank880 authored
211 $html .= "<p>Title: <input id=\"title\" type=\"text\" name=\"page\" /></p>\n";
b1ba0ea initial commit
stevenfrank880 authored
212
213 if ( $action == "new" )
214 $text = "";
215
2748379 set longer cookie expiration; expand textarea to width of brwoser for de...
stevenfrank880 authored
216 $html .= "<p><textarea id=\"text\" name=\"newText\" rows=\"" . EDIT_ROWS . "\">$text</textarea></p>\n";
b1ba0ea initial commit
stevenfrank880 authored
217 $html .= "<p><input type=\"hidden\" name=\"action\" value=\"save\" />";
63dc02e changes for 1.0.1
stevenfrank880 authored
218 $html .= "<input id=\"save\" type=\"submit\" value=\"Save\" />\n";
219 $html .= "<input id=\"cancel\" type=\"button\" onclick=\"history.go(-1);\" value=\"Cancel\" /></p>\n";
b1ba0ea initial commit
stevenfrank880 authored
220 $html .= "</form>\n";
221 }
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
222 else if ( $action == "logout" )
d2ca097 added nicer error message on save failure
stevenfrank880 authored
223 {
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
224 destroy_session();
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
225 header("Location: " . SELF);
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
226 exit;
227 }
b1ba0ea initial commit
stevenfrank880 authored
228 else if ( $action == "upload" )
229 {
230 if ( DISABLE_UPLOADS )
231 {
561f670 Fixed bug where form was submitting to /index.php/Home when creating a n...
abhibeckert authored
232 $html = "<p>Image uploading has been disabled on this installation.</p>";
b1ba0ea initial commit
stevenfrank880 authored
233 }
234 else
235 {
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
236 $html = "<form id=\"upload\" method=\"post\" action=\"" . SELF . "\" enctype=\"multipart/form-data\"><p>\n";
b1ba0ea initial commit
stevenfrank880 authored
237 $html .= "<input type=\"hidden\" name=\"action\" value=\"uploaded\" />";
63dc02e changes for 1.0.1
stevenfrank880 authored
238 $html .= "<input id=\"file\" type=\"file\" name=\"userfile\" />\n";
239 $html .= "<input id=\"upload\" type=\"submit\" value=\"Upload\" />\n";
240 $html .= "<input id=\"cancel\" type=\"button\" onclick=\"history.go(-1);\" value=\"Cancel\" />\n";
b1ba0ea initial commit
stevenfrank880 authored
241 $html .= "</p></form>\n";
242 }
243 }
244 else if ( $action == "uploaded" )
245 {
246 if ( !DISABLE_UPLOADS )
247 {
63dc02e changes for 1.0.1
stevenfrank880 authored
248 $dstName = sanitizeFilename($_FILES['userfile']['name']);
941b7ae Issue 1: Upload allows unsafe file types [FIXED]
abhibeckert authored
249 $fileType = $_FILES['userfile']['type'];
250 preg_match('/\.([^.]+)$/', $dstName, $matches);
251 $fileExt = isset($matches[1]) ? $matches[1] : null;
4031ba5 @BenWard Restructure: Separate libs.
authored
252
941b7ae Issue 1: Upload allows unsafe file types [FIXED]
abhibeckert authored
253 if (in_array($fileType, explode(',', VALID_UPLOAD_TYPES)) &&
254 in_array($fileExt, explode(',', VALID_UPLOAD_EXTS)))
b1ba0ea initial commit
stevenfrank880 authored
255 {
4031ba5 @BenWard Restructure: Separate libs.
authored
256 if ( move_uploaded_file($_FILES['userfile']['tmp_name'],
257 BASE_PATH . "/images/$dstName") === true )
941b7ae Issue 1: Upload allows unsafe file types [FIXED]
abhibeckert authored
258 {
259 $html = "<p class=\"note\">File '$dstName' uploaded</p>\n";
260 }
261 else
262 {
263 $html = "<p class=\"note\">Upload error</p>\n";
264 }
265 } else {
266 $html = "<p class=\"note\">Upload error: invalid file type</p>\n";
b1ba0ea initial commit
stevenfrank880 authored
267 }
268 }
63dc02e changes for 1.0.1
stevenfrank880 authored
269
b1ba0ea initial commit
stevenfrank880 authored
270 $html .= toHTML($text);
271 }
272 else if ( $action == "save" )
273 {
274 $newText = trim(stripslashes($_REQUEST['newText']));
d2ca097 added nicer error message on save failure
stevenfrank880 authored
275
276 $errLevel = error_reporting(0);
277 $success = file_put_contents($filename, $newText);
278 error_reporting($errLevel);
279
4031ba5 @BenWard Restructure: Separate libs.
authored
280 if ( $success )
d2ca097 added nicer error message on save failure
stevenfrank880 authored
281 $html = "<p class=\"note\">Saved</p>\n";
282 else
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
283 $html = "<p class=\"note\">Error saving changes! Make sure your web server has write access to " . PAGES_PATH . "</p>\n";
d2ca097 added nicer error message on save failure
stevenfrank880 authored
284
b1ba0ea initial commit
stevenfrank880 authored
285 $html .= toHTML($newText);
286 }
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
287 else if ( $action == "rename" )
288 {
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
289 $html = "<form id=\"rename\" method=\"post\" action=\"" . SELF . "\">";
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
290 $html .= "<p>Title: <input id=\"title\" type=\"text\" name=\"page\" value=\"" . htmlspecialchars($page) . "\" />";
291 $html .= "<input id=\"rename\" type=\"submit\" value=\"Rename\">";
292 $html .= "<input id=\"cancel\" type=\"button\" onclick=\"history.go(-1);\" value=\"Cancel\" />\n";
293 $html .= "<input type=\"hidden\" name=\"action\" value=\"renamed\" />";
294 $html .= "<input type=\"hidden\" name=\"prevpage\" value=\"" . htmlspecialchars($page) . "\" />";
295 $html .= "</p></form>";
296 }
297 else if ( $action == "renamed" )
298 {
299 $pp = $_REQUEST['prevpage'];
300 $pg = $_REQUEST['page'];
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
301
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
302 $prevpage = sanitizeFilename($pp);
303 $prevpage = urlencode($prevpage);
4031ba5 @BenWard Restructure: Separate libs.
authored
304
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
305 $prevfilename = PAGES_PATH . "/$prevpage.txt";
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
306
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
307 if ( rename($prevfilename, $filename) )
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
308 {
309 // Success. Change links in all pages to point to new page
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
310 if ( $dh = opendir(PAGES_PATH) )
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
311 {
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
312 while ( ($file = readdir($dh)) !== false )
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
313 {
314 $content = file_get_contents($file);
315 $pattern = "/\[\[" . $pp . "\]\]/g";
316 preg_replace($pattern, "[[$pg]]", $content);
317 file_put_contents($file, $content);
318 }
319 }
320 }
321 else
322 {
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
323 $html = "<p class=\"note\">Error renaming file</p>\n";
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
324 }
325 }
b1ba0ea initial commit
stevenfrank880 authored
326 else if ( $action == "all" )
327 {
328 $html = "<ul>\n";
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
329 $dir = opendir(PAGES_PATH);
4031ba5 @BenWard Restructure: Separate libs.
authored
330
b1ba0ea initial commit
stevenfrank880 authored
331 while ( $file = readdir($dir) )
332 {
333 if ( $file{0} == "." )
334 continue;
63dc02e changes for 1.0.1
stevenfrank880 authored
335
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
336 $file = preg_replace("/(.*?)\.txt/", "<a href=\"" . SELF . VIEW . "/\\1\">\\1</a>", $file);
b1ba0ea initial commit
stevenfrank880 authored
337 $html .= "<li>$file</li>\n";
338 }
339
63dc02e changes for 1.0.1
stevenfrank880 authored
340 closedir($dir);
b1ba0ea initial commit
stevenfrank880 authored
341 $html .= "</ul>\n";
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
342 }
343 else if ( $action == "all_name" )
344 {
345 $html = "<ul>\n";
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
346 $dir = opendir(PAGES_PATH);
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
347 $filelist = array();
348 while ( $file = readdir($dir) )
349 {
350 if ( $file{0} == "." )
351 continue;
352
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
353 $file = preg_replace("/(.*?)\.txt/", "<a href=\"" . SELF . VIEW . "/\\1\">\\1</a>", $file);
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
354 array_push($filelist, $file);
355 }
356
357 closedir($dir);
358
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
359 natcasesort($filelist);
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
360 for ($i = 0; $i < count($filelist); $i++)
361 {
362 $html .= "<li>" . $filelist[$i] . "</li>\n";
363 }
364
365 $html .= "</ul>\n";
366 }
367 else if ( $action == "all_date" )
368 {
369 $html = "<ul>\n";
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
370 $dir = opendir(PAGES_PATH);
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
371 $filelist = array();
372 while ( $file = readdir($dir) )
373 {
374 if ( $file{0} == "." )
375 continue;
4031ba5 @BenWard Restructure: Separate libs.
authored
376
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
377 $filelist[preg_replace("/(.*?)\.txt/", "<a href=\"" . SELF . VIEW . "/\\1\">\\1</a>", $file)] = filemtime(PAGES_PATH . "/$file");
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
378 }
379
380 closedir($dir);
381
382 arsort($filelist, SORT_NUMERIC);
383 foreach ($filelist as $key => $value)
384 {
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
385 $html .= "<li>$key <span style=\"font-size: 10px\">(" . date(TITLE_DATE, $value) . ")</span></li>\n";
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
386 }
387 $html .= "</ul>\n";
b1ba0ea initial commit
stevenfrank880 authored
388 }
389 else if ( $action == "search" )
390 {
391 $matches = 0;
392 $q = $_REQUEST['q'];
393 $html = "<h1>Search: $q</h1>\n<ul>\n";
63dc02e changes for 1.0.1
stevenfrank880 authored
394
b1ba0ea initial commit
stevenfrank880 authored
395 if ( trim($q) != "" )
396 {
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
397 $dir = opendir(PAGES_PATH);
4031ba5 @BenWard Restructure: Separate libs.
authored
398
b1ba0ea initial commit
stevenfrank880 authored
399 while ( $file = readdir($dir) )
400 {
401 if ( $file{0} == "." )
402 continue;
63dc02e changes for 1.0.1
stevenfrank880 authored
403
2b3eb93 added PAGES_PATH for moving pages dir; changed default css
stevenfrank880 authored
404 $text = file_get_contents(PAGES_PATH . "/$file");
4031ba5 @BenWard Restructure: Separate libs.
authored
405
b1ba0ea initial commit
stevenfrank880 authored
406 if ( eregi($q, $text) )
407 {
63dc02e changes for 1.0.1
stevenfrank880 authored
408 ++$matches;
dd4a5ee fixes #11 and #12; adds autolinking experimental feature
stevenfrank880 authored
409 $file = preg_replace("/(.*?)\.txt/", "<a href=\"" . SELF . VIEW . "/\\1\">\\1</a>", $file);
b1ba0ea initial commit
stevenfrank880 authored
410 $html .= "<li>$file</li>\n";
411 }
412 }
4031ba5 @BenWard Restructure: Separate libs.
authored
413
b1ba0ea initial commit
stevenfrank880 authored
414 closedir($dir);
415 }
63dc02e changes for 1.0.1
stevenfrank880 authored
416
b1ba0ea initial commit
stevenfrank880 authored
417 $html .= "</ul>\n";
418 $html .= "<p>$matches matched</p>\n";
419 }
420 else
421 {
422 $html = toHTML($text);
423 }
424
1ac617c Added ability to sort 'All Pages' page by date or name, added logout fun...
vrehorst authored
425 $datetime = '';
426
427 if (( $action == "all" ) || ( $action == "all_name") || ($action == "all_date"))
b1ba0ea initial commit
stevenfrank880 authored
428 $title = "All Pages";
4031ba5 @BenWard Restructure: Separate libs.
authored
429
b1ba0ea initial commit
stevenfrank880 authored
430 else if ( $action == "upload" )
431 $title = "Upload Image";
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
432
b1ba0ea initial commit
stevenfrank880 authored
433 else if ( $action == "new" )
434 $title = "New";
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
435
b1ba0ea initial commit
stevenfrank880 authored
436 else if ( $action == "search" )
437 $title = "Search";
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
438
b1ba0ea initial commit
stevenfrank880 authored
439 else
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
440 {
b1ba0ea initial commit
stevenfrank880 authored
441 $title = $page;
16a058a moved a few more hardcoded config variables into config.php
stevenfrank880 authored
442
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
443 if ( TITLE_DATE )
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
444 {
a113399 auto-link message: URLs pasted from Apple Mail
stevenfrank880 authored
445 $datetime = "<span style=\"font-size: 10px\">" . date(TITLE_DATE, @filemtime($filename)) . "</span>";
506cee8 added timestamp in title, configurable edit area size, beginning of rena...
vrehorst authored
446 }
447 }
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
448
63dc02e changes for 1.0.1
stevenfrank880 authored
449 // Disable caching on the client (the iPhone is pretty agressive about this
450 // and it can cause problems with the editing function)
451
452 header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
453 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
454
b1ba0ea initial commit
stevenfrank880 authored
455 print "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
456 print "<html>\n";
457 print "<head>\n";
63dc02e changes for 1.0.1
stevenfrank880 authored
458
459 // Define a viewport that is 320px wide and starts with a scale of 1:1 and goes up to 2:1
460
461 print "<meta name=\"viewport\" content=\"width=320; initial-scale=1.0; maximum-scale=2.0;\" />\n";
462
463 print "<link type=\"text/css\" rel=\"stylesheet\" href=\"" . BASE_URI . "/" . CSS_FILE ."\" />\n";
b1ba0ea initial commit
stevenfrank880 authored
464 print "<title>$title</title>\n";
465 print "</head>\n";
466 print "<body>\n";
f57f330 toolbar optimization; cosmetic changes; allowedIPs added to config
stevenfrank880 authored
467 print "<div class=\"titlebar\">$title <span style=\"font-weight: normal;\">$datetime</span></div>\n";
63dc02e changes for 1.0.1
stevenfrank880 authored
468
b1ba0ea initial commit
stevenfrank880 authored
469 printToolbar();
63dc02e changes for 1.0.1
stevenfrank880 authored
470
b1ba0ea initial commit
stevenfrank880 authored
471 print "<div class=\"main\">\n";
472 print "$html\n";
473 print "</div>\n";
63dc02e changes for 1.0.1
stevenfrank880 authored
474
82d6115 added SELF config variable so script does not have to be named index.php
stevenfrank880 authored
475 print "<form method=\"post\" action=\"" . SELF . "?action=search\">\n";
63dc02e changes for 1.0.1
stevenfrank880 authored
476 print "<div class=\"searchbar\">Search: <input id=\"search\" type=\"text\" name=\"q\" /></div></form>\n";
b1ba0ea initial commit
stevenfrank880 authored
477 print "</body>\n";
478 print "</html>\n";
479
480 ?>
Something went wrong with that request. Please try again.