Mercurial > owls
changeset 0:3021ce32ee14 owls-0.5
begin of using hg for owls
author | "Meillo r e t u r n s <meillo@marmaro.de>" |
---|---|
date | Sun, 03 Dec 2006 22:32:13 +0100 |
parents | |
children | 6268cdb5fc0b |
files | .hgignore .htaccess Includes/Bbcodeparser.inc.php Includes/Footer.inc.php Includes/Header.inc.php Includes/Loginsys.class.php Includes/Nav.inc.php Owls.css.php Owls.php Setup.php |
diffstat | 10 files changed, 830 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,12 @@ +syntax: glob + +.*.swp +.*.swo +*~ + +_Dev + +Banner.png +Smilies +favicon.ico +robots.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.htaccess Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,16 @@ +RewriteEngine On +Options -MultiViews +DirectoryIndex Owls.php +#ErrorDocument 404 /Owls.php?error=404 + + +# rules + + RewriteRule ^([0-9]+)$ Owls.php?id=$1&action=show [NC] + RewriteRule ^([0-9]+)n$ Owls.php?id=$1&action=new [NC] + RewriteRule ^([0-9]+)e$ Owls.php?id=$1&action=edit [NC] + RewriteRule ^([0-9]+)d$ Owls.php?id=$1&action=delete [NC] + + RewriteRule ^([0-9]+)login$ Owls.php?id=$1&action=login [NC] + RewriteRule ^([0-9]+)logout$ Owls.php?id=$1&action=logout [NC] +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Includes/Bbcodeparser.inc.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,94 @@ +<?php + +/** + * + * BB-Code-Parser + * + * by Meillo r e t u r n s + * + */ + + + function parse_quote1($textinput,$level = 1) { // ohne Quelle + $pattern = '#\[quote\](((?R)|(.*))*)\[/quote\]#isUe'; + $replacement = "'<br />[nl]<span class=\"quote0\">Zitat:</span>[nl]<div class=\"quote1\">[nl]'.parse_quote1('$1', + ". ($level + 1) ." + ).'[nl]</div>[nl]'"; + return preg_replace($pattern, $replacement, $textinput); + } + function parse_quote2($textinput,$level = 1) { // mit Quelle + $pattern = '#\[quote\=(.*)\](((?R)|(.*))*)\[/quote\]#isUe'; + $replacement = "'<br />[nl]<span class=\"quote0\">Zitat: ($1)</span>[nl]<div class=\"quote2\">[nl]'.parse_quote2('$2', + ". ($level + 1) ." + ).'[nl]</div>[nl]'"; + return preg_replace($pattern, $replacement, $textinput); + } + + function smilies($text) { + $smilieDir = 'Pics/Smilies/'; // path to smilies + + $smilies = array( ':-)' => 'Smile.gif', + ':)' => 'Smile.gif', + ';-)' => 'Wink.gif', + ';)' => 'Wink.gif', + ':-D' => 'Biggrin.gif', + ':D' => 'Biggrin.gif', + ':-(' => 'Sad.gif', + ':(' => 'Sad.gif', + ':-P' => 'Lick.gif', + ':P' => 'Lick.gif', + ':o' => 'Talk.gif', + ':-S' => 'Dontknow.gif', + ':dontknow:' => 'Dontknow.gif', + ':-@' => 'Angry.gif', + ':cool:' => 'Cool.gif', + '(H)' => 'Cool.gif', + '%-)' => 'Crosseyed.gif', + '%-(' => 'Crosseyed.gif', + ':rolleyes:' => 'Rolleyes.gif', + ':eek:' => 'Shocked.gif'); + while(list($key, $val) = each($smilies)) { + $text = str_replace($key,'[img]'.$smilieDir.$val.'[/img]',$text); + } + return $text; + } + + + function bbcode($text, $smilies = 0, $images = 0) { + + // smilies + if ($smilies == 1) { + $text = smilies($text); + } + + // new-lines + $text = preg_replace("#(\r\n)|(\r)#", "\n", $text); + $text = str_replace("\n", '<br />[nl]', htmlentities($text)); + + // bold + $text = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>$1</strong>", $text); + // italic + $text = preg_replace("#\[i\](.*?)\[/i\]#i", "<i>$1</i>", $text); + // links + $text = preg_replace("#\[url\](.*)\[/url\]#iU", "<a href=\"$1\">$1</a>", $text); + $text = preg_replace("#\[url=(.*)\](.*)\[/url\]#iU", "<a href=\"$1\">$2</a>", $text); + // lists + //$text = preg_replace("#\[list\]\<br /\>(.*)\[/list\]#iU", "<ul>$1</ul>", $text); + //$text = preg_replace("#\[\*\](.*)\<br \/\>#iU", "<li>$1</li>", $text); + // quotes + $text = parse_quote1($text); + $text = parse_quote2($text); + // images + if ($images == 1) { + $text = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"$1\" alt=\"<[Bild]>\" />", $text); + } + + // remove backslashes + $text = preg_replace("#\\\#is", "", $text); + // new-lines + $text = str_replace('[nl]', "\n", $text); + + return $text; + } + +?> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Includes/Footer.inc.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,7 @@ + </div> + + +</div> + +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Includes/Header.inc.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,71 @@ +<?php + + define('DB_PREFIX', 'rem__1_'); + define('TITLE', 'Owls'); + + require_once '../Db.inc.php'; + require_once 'Includes/Loginsys.class.php'; + include_once 'Includes/Bbcodeparser.inc.php'; + + $lsys = &new Loginsys(); + +?> +<!-- + + `Owls' - some kind of wiki system + + + (c) Copyright 2006 &> by Meillo r e t u r n s + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + + http://prog.marmaro.de/owls/ + +--> + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> + +<html xml:lang="de" xmlns="http://www.w3.org/1999/xhtml"> +<head> + <title><?php echo htmlentities(TITLE); ?></title> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> + <link rel="shortcut icon" href="favicon.ico" /> + <link rel="stylesheet" type="text/css" href="Owls.css.php" /> + <script type="text/javascript"> + <!-- + function sureToDelete(id) { + if (window.prompt("Type 'delete' to delete","") == "delete") { + location.href = id +"d"; + } + } + + + function toggleVisibility(boxId) { + if (document.getElementById('node'+ boxId).style.display == 'none') { + document.getElementById('node'+ boxId).style.display = ""; + document.getElementById('ctrl'+ boxId).firstChild.nodeValue = "-"; + } else{ + document.getElementById('node'+ boxId).style.display = "none"; + document.getElementById('ctrl'+ boxId).firstChild.nodeValue = "+"; + } + } + + //--> + </script> +</head> + +<body> +<div id="websiteContainer"> + + <!-- Banner --> + <img src="Banner.png" id="banner" alt="<?php echo htmlentities(TITLE); ?>" /> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Includes/Loginsys.class.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,65 @@ +<?php + +define('TIME_SESSION_EXPIRES', 1800); + + +class Loginsys { + + // Constructors + + public function __construct() { + session_start(); + $this->heartbeat(); + } + + + + + // Methods + + public function login($loginname, $password_md5) { // login ------------------------------------ + $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' ")); + if (mysql_affected_rows() == 1) { // valid login + $_SESSION[login][id] = $rowuser[id]; + $_SESSION[login][loginname] = $loginname; + $_SESSION[login][logintime] = time(); + } + } + + + + public function logout() { // logout ------------------------------------------------------------ + unset($_SESSION[login]); + } + + + + public function loggedIn() { // return login-status --------------------------------------------- + return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-TIME_SESSION_EXPIRES); + } + + + + public function heartbeat() { + if ($this->loggedIn()) { + $_SESSION[login][logintime] = time(); + } + } + + + + // Getter and Setter + + public function getUserId() { + return $_SESSION[login][id]; + } + + + public function getLoginname() { + return $_SESSION[login][loginname]; + } + +} + + +?>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Includes/Nav.inc.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,86 @@ + <!-- Nav --> + <ul id="nav"> + +<?php + // build nav tree + echo ' '. navtree(0) ."\n"; + + + // find unmatched nodes (orphans) + $sql = sprintf(" + select distinct + idParent + from %sOwls + where + idParent not in (select id from %sOwls) + and idParent != 0 -- not the real root +-- and idParent != id -- avoid endless recursion + order by name asc + ", + DB_PREFIX, + DB_PREFIX + ); + $result = mysql_query($sql) or die(mysql_error()); + unset($sql); + + // output only if there are orphans + if (mysql_num_rows($result)) { + echo ' <li id="orphans">orphans<ul>'; + // output subtree for every orphan + while($row = mysql_fetch_array($result)) { + echo navtree($row['idParent']); + } + unset($row); + mysql_free_result($result); + + echo '</ul></li>'; + } +?> + + <li id="login"> +<?php + if ($lsys->loggedIn()) { + echo ' <a href="'. $_GET['id'] .'logout" style="color: #c00;">logout</a>'; + } else { +?> + <form name="loginform" action="<?php echo $_GET['id']; ?>login" method="post" enctype="multipart/form-data"> + <input name="login_loginname" type="text" /> + <input name="login_password" type="password" /> + <input name="login" type="submit" value="login" style="padding: 0; cursor: pointer;" /> + </form> +<?php + } +?> + </li> + + </ul> + +<?php + + function navtree($root) { + // fetch subcategories + $result = mysql_query("select * from ". DB_PREFIX ."Owls where idParent = $root order by name asc"); + + $return = ''; + while($row = mysql_fetch_array($result)) { + $return .= '<li><a href="'. $row['id'] .'"'. (($_GET['id'] == $row['id']) ? ' id="selected"' : '') .'>'. $row['name'] .'</a>'; + if ($row['id'] != $row['idParent']) { + $subtree = navtree($row['id']); + if (!empty($subtree)) { + $return .= ' <a href="javascript:toggleVisibility(\''. $row[id] .'\')" id="ctrl'. $row['id'] .'" style="display: none;">-</a>'; + $return .= '<ul id="node'. $row['id'] .'">'. $subtree .'</ul>'; + } + unset($subtree); + } + $return .= '</li>'; + } + unset($row); + mysql_free_result($result); + + // return + return $return; + } + +?> + + <!-- Content -->
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Owls.css.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,215 @@ +<?php + header('Content-Type: text/css; charset=utf8'); + + // Caching verhindern + header('Expires: Thu, 05 Apr 1984 04:47:00 GMT'); + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); + header('Cache-Control: no-store'); + header('Pragma: no-cache'); + echo('/* Anti-Caching: '.microtime()." */\r\n"); + + + // colors + $cProject = '#96c'; + + $cBackgroundGlobal = '#666'; + //$cBackgroundContent = '#666'; //eee + + $cBorderGlobal = '#000'; + + $cTextH1 = '#aaa'; + + $cLinkHover = $cProject; + + $cNav = '#333'; + + + $mContentMinHeight = '22em'; + + $mNavWidth = '12em'; + + +?> + + + +/*#### Standard ############################################################*/ +body { + font-family: sans-serif; + margin: 30px 0; + text-align: center; + background-color: <?php echo $cBackgroundGlobal ?>; +} + + +#websiteContainer { + width: 760px; + margin: 0 auto; + text-align: left; +} + +#banner { + display: block; + border: 1px solid <?php echo $cBorderGlobal ?>; +} + + +#content { + margin-left: <?php echo $mNavWidth; ?>; + padding: 1em; +} + + +#edit input, +#edit select, +#edit textarea { + font-family: sans-serif; + font-size: 0.8em; +} + + +p { + text-align: justify; +} + + +a { + text-decoration: underline; +} +a:link { + color: #000; +} +a:visited { + color: #aaa; +} +a:active, +a:hover { + color: <?php echo $cLinkHover; ?>; +} + + +img { + border: none; +} + +.small { + font-size: 0.8em; +} + + + + + + + + + +#nav { + float: left; + width: <?php echo $mNavWidth; ?>; + padding: 0.5em 2em 1em 0.5em; + margin: 2.5em 0 1em 0; + font-size: 0.8em; +} + +#nav ul { + padding-left: 1em; +/* border: 1px solid #060; */ +} + +#nav li { + padding: 1px; + margin: 0; +/* border: 1px solid #006; */ +} + +#nav a { + text-decoration: none; + color: <?php echo $cTextH1; ?>; +} +#nav a:link, +#nav a:visited { + text-decoration: none; +} +#nav a:active, +#nav a:hover { + color: <?php echo $cLinkHover; ?>; + text-decoration: none; +} + +#selected:link, +#selected:visited { + color: <?php echo $cBorderGlobal; ?>; +} +#nav #selected:hover { + color: <?php echo $cLinkHover; ?>; +} + + +li#orphans { + margin-top: 2em; + font-style: italic; + color: #aaa; +} + +li#login { + margin-top: 3em; +} +#login input { + background-color: transparent; + border: none; + border-left: #555 1px solid; + display: block; + font-size: 0.8em; + margin-bottom: 2px; + padding-left: 4px; +} + + + + +.ctrl { + text-align: right; + font-size: 0.8em; +} +.ctrl a { + margin-left: 1em; + color: #eee; +} + + + + + + + + +/*#### BBCode ##############################################################*/ + +.quote1 { + border:1px solid #c0c0c0; + margin:5px; + padding:5px; +} +.quote2 { + border:1px solid #c0c0c0; + margin:5px; + margin-bottom:0px; + padding:5px; +} +.quote0 { + color: #000; + font-size: 0.8em; +} + +ul { + list-style: none; + margin-left: 0; + padding-left: 1em; +} +li { + margin-left: 1em; + padding-left: 0; + /*list-style-image: url(Pics/Bullet.gif);*/ +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Owls.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,212 @@ +<?php + require_once 'Includes/Header.inc.php'; + + + if ($_GET['action'] == 'show') { // show + show($lsys); + + } else if ($_GET['action'] == 'new' && $lsys->loggedIn()) { // new + create($lsys); + + } else if ($_GET['action'] == 'edit' && $lsys->loggedIn()) { // edit + edit($lsys); + + } else if ($_GET['action'] == 'delete' && $lsys->loggedIn()) { // delete + delete($lsys); + + } else if ($_GET['action'] == 'login') { // login + $lsys->login($_POST['login_loginname'], md5($_POST['login_password'])); + show($lsys); + + } else if ($_GET['action'] == 'logout') { // logout + $lsys->logout(); + show($lsys); + + } else { // startpage + $_GET['id'] = 1; + show($lsys); + + } + + + require_once 'Includes/Footer.inc.php'; + + + + + + + + + + + +/* + displays content of the node + performs action 'edit' + shows admincontrols if logged in +*/ +function show($lsys) { + + // perform action: write edited node to db + if (isset($_POST['editDoc']) && $lsys->loggedIn()) { + $_POST['editDoc_title'] = addslashes($_POST['editDoc_title']); + $_POST['editDoc_text'] = addslashes($_POST['editDoc_text']); + mysql_query("update ". DB_PREFIX ."Owls set + name='$_POST[editDoc_title]', + text='$_POST[editDoc_text]', + idParent='$_POST[editDoc_idCategory]', + date=". time() ." + where id='$_GET[id]'") or die(mysql_error()); + } + + // print nav + include 'Includes/Nav.inc.php'; + + + // query data of the node + $result = mysql_query("select * from ". DB_PREFIX ."Owls where id=$_GET[id]"); + + // catch nodes that not exist + if (!mysql_num_rows($result)) { + + $fnord = array('', + 'Fnord is the space between the pixels on your screen.', + 'Fnord is the echo of silence.', + 'Fnord is evaporated herbal tea without the herbs.', + 'Fnord is what you see when you close your eyes.', + 'Fnord is the empty pages at the end of the book.', + 'Fnord is why ducks eat trees.', + 'Fnord is the bucket where they keep the unused serifs for H*lvetica.', + 'Fnord is the source of all the zero bits in your computer.' + ); + +?> + <div id="content"> + <h2>Error 23 - fnord found</h2> + <p> + <?php echo $fnord[rand(0, sizeof($fnord)-1)]; ?> + </p> +<?php + + } else { + + $row = mysql_fetch_array($result); + echo ' <div id="content">'."\n"; + + // display admin controls if logged in + if ($lsys->loggedIn()) { +?> + <div class="ctrl" style="font-size: 0.8em;"> + <a href="<?php echo $row['id'] .'n'; ?>">new</a> + <a href="<?php echo $row['id'] .'e'; ?>">edit</a> +<?php + if ($row['id'] != 1) { + echo '<a href="javascript:sureToDelete('. $row['id'] .')">delete</a>'; + } +?> + </div> +<?php + } + + // print content of the node + echo ' <h2>'.stripslashes($row['name']).'</h2>'."\n"; + if (!empty($row['text'])) { + echo ' <p>'.bbcode(stripslashes($row['text']), 1, 1).'</p>'; + } + } + echo "\n\n"; + +} + + + + + +/* + displays edit form +*/ +function edit($lsys) { + + include 'Includes/Nav.inc.php'; + + $sql = "select * from ". DB_PREFIX ."Owls where id=$_GET[id]"; + $result = mysql_query($sql) or die(mysql_error()); + $row = mysql_fetch_array($result); + echo '<div id="content">'; +?> +<div id="edit"> + <form action="<?php echo $row['id']; ?>" method="post" enctype="multipart/form-data"> +<?php + if ($_GET['id'] != 1) { +?> + <select name="editDoc_idCategory" style="width: 99%;"> +<?php + $result = mysql_query("select * from ". DB_PREFIX ."Owls order by name asc") or die(mysql_error()); + while($rowCats = mysql_fetch_array($result)) { + echo ' <option value="'.$rowCats['id'].'"'. (($row['idParent'] == $rowCats['id']) ? ' selected="selected"' : '') .'>'.stripslashes($rowCats['name']).'</option>'; + } +?> + </select><br /><br /> +<?php + } +?> + <input name="editDoc_title" type="text" value="<?php echo stripslashes($row['name']); ?>" style="width: 99%;" /><br /> + <textarea name="editDoc_text" cols="60" rows="15" style="width: 99%; height: 30em;"><?php + echo stripslashes($row['text']); + ?></textarea><br /><br /> + <input name="editDoc" type="submit" value="edit" class="button" style="width: 99%;" /> + </form> +</div> +<?php + unset($row); + unset($result); +} + + + + + + +/* + performs action 'new' +*/ +function create($lsys) { + + // perform action: new node + mysql_query(" + insert into ". DB_PREFIX ."Owls + (idParent, date) + values('$_GET[id]',". time() .") + ") or die(mysql_error()); + + // set node to jump to (new created node) + $_GET['id'] = mysql_insert_id(); + edit($lsys); +} + + + + + +/* + performs action 'delete' +*/ +function delete($lsys) { + // not allowed to delete the root + if ($_GET['id'] != 1) { + // TODO: get the parent of the one which is to delete + + // delete + mysql_query("delete from ". DB_PREFIX ."Owls where id='$_GET[id]'") or die(mysql_error()); + } + // set node to jump to (TODO: parent from above) + $_GET['id'] = 1; + show($lsys); +} + + + + +?> +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Setup.php Sun Dec 03 22:32:13 2006 +0100 @@ -0,0 +1,52 @@ +<?php + +// you can customize the config here + +$dbPrefix = 'rem__2_'; // the names of the db-tables will be prefixed with this string + +//$modifyProtected = true; // are guests allowed to modify data? (true or false) + +$defaultUser = 'admin'; // useraccount if "modifyProtected = true" above +$defaultUserPassword = 'admin'; // password for useraccount if "modifyProtected = true" above + + + +// dont change anything form here on (except you know what you do) +//################################################################## + + // write db-login-data to textfile + + + // connect to db and create tables + require('../Db.inc.php'); + + + // table 'Owls' for the content data + mysql_query(" + CREATE TABLE IF NOT EXISTS `". $dbPrefix ."Owls` ( + `id` int(11) NOT NULL auto_increment, + `idParent` int(11) default '0', + `name` text NOT NULL, + `text` longtext NOT NULL, + `permission` tinyint(4) NOT NULL default '1', + `date` int(11) NOT NULL default '0', + PRIMARY KEY (`id`) + ) + ") or die(mysql_error()); + + // insert startup nodes + mysql_query("INSERT INTO `". $dbPrefix ."Owls` VALUES (1, 0, 'Index', 'Thanks for using [url=http://prog.marmaro.de/owls/]Owls[/url]!', 0, now())") or die(mysql_error()); + + + + // login should be managed via text file in future + mysql_query("CREATE TABLE IF NOT EXISTS `". $dbPrefix ."User` ( + `id` int(11) NOT NULL auto_increment, + `loginname` tinytext NOT NULL, + `password` tinytext NOT NULL, + PRIMARY KEY (`id`) + )") or die(mysql_error()); + + mysql_query("INSERT INTO `". $dbPrefix ."User` VALUES (1, '". $defaultUser ."', '". md5($defaultUserPassword) ."')") or die(mysql_error()); + +?>