Last active
January 3, 2016 17:59
-
-
Save fulldecent/8498856 to your computer and use it in GitHub Desktop.
A knowledge management system we created in under 5 minutes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$title = "Knowledge Base 0.1"; | |
$datadir = './data/'; | |
if (!is_dir($datadir) || !is_writable($datadir)) die('The DATADIR directory must be writable'); | |
$myurl='http://phor.net/PUB/chris/index'; | |
?> | |
<html> | |
<head> | |
<title><?= $title ?></title> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css"> | |
</head> | |
<body> | |
<table> | |
<tr> | |
<td width="25%" style="background:#ddf"> | |
<?php | |
/** | |
* Returns a list of all files in the photostore | |
* | |
* @return an array of files, in the form 'path'=>basename(path) | |
*/ | |
function ListFiles($path = '', $recur=TRUE) | |
{ | |
global $datadir; | |
$retval = array(); | |
$prefix = $datadir; | |
if ($dir = @opendir($prefix . '/' . $path)) | |
{ | |
$children = array(); | |
while (false !== ($file = readdir($dir))) | |
{ | |
if ($file[0]=='.') continue; | |
$photopath = $path.$file; | |
if ($recur && is_dir($prefix . '/' . $photopath)) | |
{ | |
$retval[$photopath] = 'dir'; | |
$retval += ListFiles($photopath . '/'); | |
} | |
else if (is_file($prefix . '/' . $photopath)) | |
$retval[$photopath] = 'text'; | |
} | |
closedir($dir); | |
sort($children); | |
return $retval; | |
} | |
else | |
{ | |
return $retval; | |
} | |
} | |
echo "<h2><a href=\"?\">$title</a></h2>"; | |
echo '<ul style="list-style:none; margin:0; padding:0">'; | |
foreach (ListFiles() as $name=>$type) { | |
$level = count(split('/',$name)); | |
$weight = $name == $_GET['dir'].$_GET['text'] ? 'bold' : 'normal'; | |
echo "<li style=\"font-weight:$weight\">"; | |
echo '<a href="?'.$type.'='.$name.'">'; | |
echo '<i class="fa fa-file" style="margin-left:'.(10*$level).'px"></i>'; | |
echo " $name</a>\n"; | |
} | |
echo "</ul>"; | |
echo '<p /><form><input name="grep"><input type="submit" value="Search"></form>'; | |
?> | |
<td width="75%" style="padding: 1em"> | |
<?php | |
if ($_GET['dir']) { | |
if ($_GET['new']) { | |
mkdir("$datadir".$_GET['dir']) or die('fail'); | |
die('<h3>CREATED DIRECTORY: '.$_GET['dir']. " <a href=\"$myurl\">continue</a></h3>"); | |
} | |
echo '<h3>You have selected the '.$_GET['dir'].' directory</h3>'; | |
echo '<form method="GET">Create a file named: <input type="hidden" name="new" value="true"><input name="text" value="'.$_GET['dir'].'/"> <input type="submit" value="Go"></form>'; | |
echo '<form method="GET">Create a directory named: <input type="hidden" name="new" value="true"><input name="dir" value="'.$_GET['dir'].'/"> <input type="submit" value="Go"></form>'; | |
} | |
elseif ($_GET['text']) | |
{ | |
if ($_GET['new']) | |
{ | |
touch("$datadir".$_GET['text']) or die('fail'); | |
die('<h3>CREATED FILE: '.$_GET['text']. " <a href=\"$myurl\">continue</a></h3>"); | |
} | |
elseif ($_POST['edittext']) | |
file_put_contents("$datadir".$_GET['text'], $_POST['edittext']); | |
elseif ($_GET['delete']) | |
{ | |
unlink("$datadir".$_GET['text']) or die('fail'); | |
die('<h3>DELETED FILE: '.$_GET['text']. " <a href=\"$myurl\">continue</a></h3>"); | |
} | |
if ($_GET['edit']) | |
{ | |
echo '<h3> Editing file: '.$_GET['text'].'</h3>'; | |
echo '<form method="POST" action="?text='.$_GET['text'].'"><textarea name="edittext" rows=30 cols=80>'.htmlentities(file_get_contents("$datadir".$_GET['text'])).'</textarea><input type="hidden" name="text" value="'.$_GET['text'].'">'; | |
echo '<p><input type=submit value="Save"></p></form>'; | |
} | |
else | |
{ | |
echo '<h3> Displaying file: '.$_GET['text'].'</h3>'; | |
echo '<h4> Options: <a href="?text='.$_GET['text'].'&edit=true">Edit</a> | <a href="?text='.$_GET['text'].'&delete=true">Delete</a></h4>'; | |
$a = file_get_contents("$datadir".$_GET['text']); | |
if (strlen($a)) | |
echo '<pre>'.htmlentities($a).'</pre>'; | |
else | |
echo 'This file is empty'; | |
} | |
} | |
elseif ($_GET['grep']) { | |
chdir($datadir); | |
echo '<pre>'; | |
echo passthru('grep -r '.escapeshellarg($_GET['grep']).' .'); | |
echo '</pre>'; | |
} | |
else { | |
echo '<h3>Please select a file or directory on the left</h3>'; | |
} | |
?> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment