Reworked 'nodir'-function a bit and included it in the Page-class instead. Started working on a way to edit content files
This commit is contained in:
parent
f723d7bd69
commit
b9cbc947b5
@ -2,6 +2,7 @@
|
|||||||
class Page
|
class Page
|
||||||
{
|
{
|
||||||
public $name, $filename;
|
public $name, $filename;
|
||||||
|
public static $parentDir = "../";
|
||||||
public static $contentFolder = "content/";
|
public static $contentFolder = "content/";
|
||||||
|
|
||||||
public function __construct($name, $filename)
|
public function __construct($name, $filename)
|
||||||
@ -26,11 +27,24 @@ class Page
|
|||||||
return $this->filename;
|
return $this->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function nodir($item)
|
||||||
|
{
|
||||||
|
return (!is_dir(Page::$parentDir . Page::$contentFolder . $item));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fileList()
|
||||||
|
{
|
||||||
|
$dirContent = scandir(Page::$parentDir . Page::$contentFolder);
|
||||||
|
$files = (array_filter($dirContent, "Page::nodir"));
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
// For future-uses...
|
// For future-uses...
|
||||||
public function getName()
|
public function getName()
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
function start_html($title)
|
function start_html($title)
|
||||||
{
|
{
|
||||||
print "
|
print "
|
||||||
<html>
|
<!DOCTYPE html>
|
||||||
<head>
|
<head>
|
||||||
<title>$title</title>
|
<title>$title</title>
|
||||||
</head>
|
</head>
|
||||||
|
@ -3,6 +3,7 @@ function terminate($message="")
|
|||||||
{
|
{
|
||||||
print "$message\n";
|
print "$message\n";
|
||||||
footer();
|
footer();
|
||||||
exit(1);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -78,7 +78,6 @@ $contactPage = new Page("Contact", "contact.html");
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dirContent = scandir(Page::$contentFolder);
|
$dirContent = scandir(Page::$contentFolder);
|
||||||
|
|
||||||
$files = (array_filter($dirContent, "nodir"));
|
$files = (array_filter($dirContent, "nodir"));
|
||||||
|
|
||||||
// Iterate through all the files for a match (from ?content=)
|
// Iterate through all the files for a match (from ?content=)
|
||||||
|
34
user/editfile.php
Normal file
34
user/editfile.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
require ("../includes/content.php");
|
||||||
|
require ("../includes/miscfunc.php");
|
||||||
|
require ("../includes/htmlcode.php");
|
||||||
|
$filename = $_GET['file'];
|
||||||
|
$file = Page::$parentDir . Page::$contentFolder . $filename;
|
||||||
|
|
||||||
|
$filehandle = fopen ("$file", "rw");
|
||||||
|
$content = fread($filehandle, filesize($file));
|
||||||
|
|
||||||
|
start_html("Edit file");
|
||||||
|
print "<form action=\"$_SERVER[PHP_SELF]\" method='post'>
|
||||||
|
Text: <br />
|
||||||
|
<textarea cols='80' rows='30' name='file'>$content</textarea>
|
||||||
|
<br />
|
||||||
|
<input type='submit' value='Save file'>
|
||||||
|
</form>
|
||||||
|
";
|
||||||
|
|
||||||
|
if (!isset($_POST['post']))
|
||||||
|
{
|
||||||
|
end_html();
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fwrite($filehandle, $_POST['post']) === FALSE)
|
||||||
|
{
|
||||||
|
echo "Cannot write to file ($file)";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Success, saved file ($file)";
|
||||||
|
fclose($filehandle);
|
||||||
|
?>
|
10
user/editfiles.php
Normal file
10
user/editfiles.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
require ("../includes/content.php");
|
||||||
|
require ("../includes/miscfunc.php");
|
||||||
|
|
||||||
|
$files = Page::fileList();
|
||||||
|
foreach($files as $file)
|
||||||
|
{
|
||||||
|
print "<a href=\"editfile.php?file=$file\">$file</a><br/>\n";
|
||||||
|
}
|
||||||
|
?>
|
@ -12,6 +12,9 @@ include "../includes/login.inc";
|
|||||||
<a href="edit.php">Edit existing post</a>
|
<a href="edit.php">Edit existing post</a>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
<a href="editfiles.php">Edit content files</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
<a href="logout.php">Logout</a>
|
<a href="logout.php">Logout</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
17
user/updatefile.php
Normal file
17
user/updatefile.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
if (!isset($_POST['post']))
|
||||||
|
{
|
||||||
|
end_html();
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fwrite($filehandle, $_POST['post']) === FALSE)
|
||||||
|
{
|
||||||
|
echo "Cannot write to file ($file)";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Success, saved file ($file)";
|
||||||
|
fclose($filehandle);
|
||||||
|
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user