File NBWiki008alpha.txt Copyright (c) 2003, 2004, Marc Rohlfing and 2005, Nomaz This file is under development. Feel free to try it if you wish. ---- To avoid confusion please do not alter this file unless you first rename it and include an explanatory note here. ---- NBWiki is a PHP based "Wiki" or collaborative website authoring tool developed for (but not limited to) use as an electronic notice board. If you have not already done so please check it out now at . NBWiki is "freeware" but useage is subject to licence terms (given on the website and somewhere below.). If you are happy to abide by these you may use and distribute it (or any derivative) freely. This file is intended to provide all you need to set up an "NBWiki". All, that is, except for a text editor and FTP access to a suitable host website under your control. ---- No liability is accepted for any errors in this document or for any consequences of trying or using NBWiki. But if you follow these instructions you should end up with a working NBWiki which you can then customise. After that, set up as many NBWikis as you like! Your NBWiki could provide the "Home page" of your website (particularly if you have nothing on it so far). More likely, it will be a branch of your site. We will assume that it will be in a directory (folder) called nbwiki (all lower case). A folder with this name will be set up locally then uploaded "on block" - so you don't need an Internet connection for most of the following. ---- It will help it you have two windows open: - One containing this document for reference (the "reference window" - preferably one where you can't make accidental changes, such as a web browser). If you are reading this on screen now then this window could be used. Anyway, don't use a Word Processor - it may change things without asking, such as substituting one sort of quote mark for another. - a separate One with text editing capabilities (the "editing window"). Best use a basic text editor as a Word Processors may (with good intentions) spoil your good work. When you save files from the editing window you may end up with a spurious ".txt" at the end of some filenames. If so, rename the files. Better, tell then editor to behave, usually by specifing the file type as "all files". ---- Stage 1 Create a directory (folder) on your PC (or whatever you are working on) called nbwiki. If your system capitalises the first letter then correct it by doing a rename. Note: Using the correct case of each letter in file and directory names is important with many web hosts. "A" and "a" are regarded as different. Even if your host does not care, you might move to one that does sometime. So please make sure that the names of directories and files you create are exactly as stated. ---- Stage 2 Within the directory nbwiki, create sub-directories called admin (will contain a PHP script for use by the administrator or "super editor") docs (will contain any documents for users to download) editor1 (will contain a PHP script for use a sub-editor) pages (will contain "marked up" text files your NBWiki will interpret and display) pics (will contain graphic files to be displayed within pages) templates (will contain one or more templates used in displaying pages) ---- Stage 3 If you have not yet done so (and so are following these instructions - you were not told to do this above!) then open your editing window now with a blank document in it. Copy the following (between ====start==== and ==== end ====, but excluding them) into the editing window. ====start==== '; $HOME_BUTTON = "NBWiki Home"; $EDIT_BUTTON = "Edit this page"; $DONE_BUTTON = "Save changes"; $PROTECTED_BUTTON = "Editing not permitted"; $SEARCH_BUTTON = "Search"; $SEARCH_RESULTS = "Search results for"; $NEW_PAGE = "New page"; $RECENT_CHANGES = "Recent changes"; $FORCE_REFRESH = '&r=' . rand(1,999); // // End of configuration area // $PHP_FILE = basename(__FILE__); $EDIT_SEED = $EDIT_IF[0] . "\n"; if (! $PAGE_TITLE = $_GET["page"]) { if ($_GET["action"] == "search") $PAGE_TITLE = "$SEARCH_RESULTS \"$_GET[query]\""; elseif ($_GET["action"] == "recent") $PAGE_TITLE = "$RECENT_CHANGES"; else $PAGE_TITLE = "$START_PAGE"; } if (preg_match("/\//", $PAGE_TITLE)) $PAGE_TITLE = $START_PAGE; $action = $_GET["action"]; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (! $file = @fopen($PAGES_DIR . $_POST["page"] . ".txt" , "w")) die ("Could not write page!"); $CONTENT = stripslashes($_POST["content"]); fputs($file, $CONTENT); if (substr($CONTENT, strlen($CONTENT) - 1) != "\n") fputs($file, "\n"); fclose($file); header("location: " . $PHP_FILE . "?page=$_POST[page]". $FORCE_REFRESH); } if (! $file = @fopen($TEMPLATE_FILE, "r")) die ("Template file " . $TEMPLATE_FILE . " is missing!"); $template = fread($file, filesize($TEMPLATE_FILE)); fclose($file); if (($file = @fopen($PAGES_DIR . $PAGE_TITLE . ".txt", "r")) || $action <> "") { $TIME = strftime("$TIME_FORMAT", @filectime($PAGES_DIR . $PAGE_TITLE . ".txt")); $CONTENT = @fread($file, @filesize($PAGES_DIR . $PAGE_TITLE . ".txt")); $MAY_EDIT = false; foreach ($EDIT_IF as $VALUE) { if ($VALUE == substr($CONTENT, 0, strlen($VALUE))){ $MAY_EDIT = true; }; } @fclose($file); } else { $action = "edit"; $TIME = "$NEW_PAGE"; $CONTENT = $EDIT_SEED; } if ($action == "edit" || $action <> "") $html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template); elseif (is_writable($PAGES_DIR . $PAGE_TITLE . ".txt") && $MAY_EDIT ) $html = preg_replace('/{EDIT}/', "$EDIT_BUTTON", $template); else $html = preg_replace('/{EDIT}/', "$PROTECTED_BUTTON", $template); if ($action == "recent") $html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html); else $html = preg_replace('/{RECENT_CHANGES}/', "$RECENT_CHANGES", $html); // $html = preg_replace('/{PAGE_TITLE}/', "$PAGE_TITLE", $html); if ($PAGE_TITLE == $START_PAGE && $action <> "search") $html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html); else $html = preg_replace('/{HOME}/', "$HOME_BUTTON", $html); $html = preg_replace('/{WIKI_TITLE}/', $WIKI_TITLE, $html); $html = preg_replace('/{SEARCH}/', "
", $html); if ($action == "edit") $CONTENT = "

"; if ($action == "search") { $dir = opendir(getcwd() . "/$PAGES_DIR"); while ($file = readdir($dir)) { if (preg_match("/.txt/", $file)) { $handle = fopen($PAGES_DIR . $file, "r"); $content = fread($handle, filesize($PAGES_DIR . $file)); fclose($handle); if (preg_match("/$_GET[query]/i", $content) || preg_match("/$_GET[query]/i", "pages/$file")) { $file = substr($file, 0, strlen($file) - 4 ); // 4 for .txt $CONTENT .= "$file

"; } } } $TIME = "-"; } elseif ($action == "recent") { $dir = opendir(getcwd() . "/$PAGES_DIR"); while ($file = readdir($dir)) if (is_int(strpos($file, ".txt"))) $filetime[$file] = filectime($PAGES_DIR . $file); arsort($filetime); $filetime = array_slice($filetime, 0, $RECENT_COUNT); foreach ($filetime as $filename => $timestamp) { $filename = substr($filename, 0, strlen($filename) - 4); $CONTENT .= "$filename (" . strftime("$TIME_FORMAT", $timestamp) . ")

"; } $TIME = "-"; } elseif ($action <> "edit") { $CONTENT = htmlentities($CONTENT); $CONTENT = preg_replace("/{{{.*}}}/U", '', $CONTENT); $CONTENT = preg_replace('/\r\n/m', "\n", $CONTENT); $CONTENT = preg_replace('/\r/m', "\n", $CONTENT); $CONTENT = preg_replace('/^ /m',' ', $CONTENT); $CONTENT = preg_replace('/ /', '  ', $CONTENT); $CONTENT = preg_replace('/\[\[([0-9a-zA-Z\- :\.,\(\)]+)\]\]/U', '$1', $CONTENT); $CONTENT = preg_replace('£\[\%(.*)\|http://([0-9a-zA-Z\$%_\-=:/~#\.? ]+)\%\]£U', '$1', $CONTENT); $CONTENT = preg_replace('/\[\%(.*)\|([0-9a-zA-Z\- :\.,\(\)]+)\%\]/U', '$1', $CONTENT); $CONTENT = preg_replace('/\[\|(.*)\|([0-9a-zA-Z\- :\.,\(\)]+)\|\]/U', '$1', $CONTENT); $CONTENT = preg_replace('£\[\!(.+)\|(http.?://.+)\!\]£U', '$1', $CONTENT); $CONTENT = preg_replace('£\[\!(.+)\!(http.?://.+)\!\]£U', '$1', $CONTENT); $CONTENT = preg_replace("/'''(.*)'''/Um", '$1', $CONTENT); $CONTENT = preg_replace("/''(.*)''/Um", '$1', $CONTENT); $CONTENT = preg_replace('/(^|\|)!!!!(.*)$/Um', "$1

$2

", $CONTENT); $CONTENT = preg_replace('/(^|\|)!!!(.*)$/Um', "$1

$2

", $CONTENT); $CONTENT = preg_replace('/(^|\|)!!(.*)$/Um', "$1

$2

", $CONTENT); $CONTENT = preg_replace('/(^|\|)!(.*)$/Um', "$1

$2

", $CONTENT); $CONTENT = preg_replace('/(^|\|)\*(.*)$/Um', "$1", $CONTENT); $CONTENT = preg_replace('/(^|\|)\#(.*)$/Um', "$1
  1. $2
", $CONTENT); $CONTENT = preg_replace('/(<\/ol>\n
    |<\/ul>\n|
)\n#', "$1", $CONTENT); $CONTENT = preg_replace('#\n(
    |