diff --git a/modules/action-protect.php b/modules/action-protect.php
index f0141fa..7139298 100644
--- a/modules/action-protect.php
+++ b/modules/action-protect.php
@@ -1,42 +1,42 @@
"Page protection",
- "version" => "0.1",
+ "version" => "0.2",
"author" => "Starbeamrainbowlabs",
"description" => "Exposes Pepperminty Wiki's new page protection mechanism and makes the protect button in the 'More...' menu on the top bar work.",
"id" => "action-protect",
"code" => function() {
add_action("protect", function() {
global $env, $pageindex;
-
+
// Make sure that the user is logged in as an admin / mod.
if($env->is_admin)
{
// They check out ok, toggle the page's protection.
$page = $env->page;
-
+
$toggled = false;
if(!isset($pageindex->$page->protect))
{
$pageindex->$page->protect = true;
$toggled = true;
}
-
+
if(!$toggled && $pageindex->$page->protect === true)
{
$pageindex->$page->protected = false;
$toggled = false;
}
-
+
if(!$toggled && $pageindex->$page->protect === false)
{
$pageindex->$page->protected = true;
$toggled = true;
}
-
+
// Save the pageindex
- file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
-
+ file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
+
$state = ($pageindex->$page->protect ? "enabled" : "disabled");
$title = "Page protection $state.";
exit(page_renderer::render_main($title, "
Page protection for $env->page has been $state.
Go back ."));
diff --git a/modules/action-raw.php b/modules/action-raw.php
index b0e84e1..35773cd 100644
--- a/modules/action-raw.php
+++ b/modules/action-raw.php
@@ -1,18 +1,18 @@
"Raw page source",
- "version" => "0.3",
+ "version" => "0.4",
"author" => "Starbeamrainbowlabs",
"description" => "Adds a 'raw' action that shows you the raw source of a page.",
"id" => "action-raw",
"code" => function() {
add_action("raw", function() {
global $env;
-
+
http_response_code(307);
header("x-filename: " . rawurlencode($env->page) . ".md");
header("content-type: text/markdown");
- exit(file_get_contents("$env->page.md"));
+ exit(file_get_contents("$env->storage_prefix$env->page.md"));
exit();
});
}
diff --git a/modules/feature-search.php b/modules/feature-search.php
index 72e39bc..6f539cb 100644
--- a/modules/feature-search.php
+++ b/modules/feature-search.php
@@ -1,7 +1,7 @@
"Search",
- "version" => "0.1",
+ "version" => "0.2",
"author" => "Starbeamrainbowlabs",
"description" => "Adds proper search functionality to Pepperminty Wiki. Note that this module, at the moment, just contains test code while I figure out how best to write a search engine.",
"id" => "feature-search",
@@ -13,7 +13,7 @@ register_module([
header("content-type: text/plain");
- $source = file_get_contents("$env->page.md");
+ $source = file_get_contents("$env->storage_prefix$env->page.md");
$index = search::index($source);
@@ -35,11 +35,11 @@ register_module([
$search_start = microtime(true);
- $invindex = search::load_invindex("invindex.json");
+ $invindex = search::load_invindex($paths->searchindex);
$results = search::query_invindex($_GET["query"], $invindex);
-
+
$search_end = microtime(true) - $search_start;
-
+
$title = $_GET["query"] . " - Search results - $settings->sitename";
$content = "\n";
@@ -65,7 +65,7 @@ register_module([
foreach($results as $result)
{
$link = "?page=" . rawurlencode($result["pagename"]);
- $pagesource = file_get_contents($result["pagename"] . ".md");
+ $pagesource = file_get_contents($env->storage_prefix . $result["pagename"] . ".md");
$context = search::extract_context($_GET["query"], $pagesource);
$context = search::highlight_context($_GET["query"], $context);
/*if(strlen($context) == 0)
@@ -102,7 +102,7 @@ class search
public static $stop_words = [
"a", "about", "above", "above", "across", "after", "afterwards", "again",
"against", "all", "almost", "alone", "along", "already", "also",
- "although", "always", "am", "among", "amongst", "amoungst", "amount",
+ "although", "always", "am", "among", "amongst", "amoungst", "amount",
"an", "and", "another", "any", "anyhow", "anyone", "anything", "anyway",
"anywhere", "are", "around", "as", "at", "back", "be", "became",
"because", "become", "becomes", "becoming", "been", "before",
@@ -192,7 +192,7 @@ class search
$invindex = [];
foreach($pageindex as $pagename => $pagedetails)
{
- $pagesource = file_get_contents("$pagename.md");
+ $pagesource = file_get_contents("$env->storage_prefix$pagename.md");
$index = self::index($pagesource);
self::merge_into_invindex($invindex, ids::getid($pagename), $index);
diff --git a/modules/feature-upload.php b/modules/feature-upload.php
index d24c9c8..b30d7e4 100644
--- a/modules/feature-upload.php
+++ b/modules/feature-upload.php
@@ -1,7 +1,7 @@
"Uploader",
- "version" => "0.1",
+ "version" => "0.2",
"author" => "Starbeamrainbowlabs",
"description" => "Adds the ability to upload files to Pepperminty Wiki. Uploaded files act as pages and have the special 'File:' prefix.",
"id" => "feature-upload",
@@ -92,7 +92,7 @@ register_module([
$file_extension = system_mime_type_extension($mime_type);
- $new_filename = "Files/$target_name.$file_extension";
+ $new_filename = "$paths->upload_file_prefix$target_name.$file_extension";
$new_description_filename = "$new_filename.md";
if(isset($pageindex->$new_filename))
@@ -101,20 +101,19 @@ register_module([
if(!file_exists("Files"))
mkdir("Files", 0664);
- if(!move_uploaded_file($temp_filename, $new_filename))
+ if(!move_uploaded_file($temp_filename, $env->storage_prefix . $new_filename))
{
http_response_code(409);
exit(page_renderer::render("Upload Error - $settings->sitename", "The file you uploaded was valid, but $settings->sitename couldn't verify that it was tampered with during the upload process. This probably means that $settings->sitename has been attacked. Please contact " . $settings->admindetails . ", your $settings->sitename Administrator.
"));
}
- file_put_contents($new_description_filename, $_POST["description"]);
-
$description = $_POST["description"];
+ // Escape the raw html in the provided description if the setting is enabled
if($settings->clean_raw_html)
$description = htmlentities($description, ENT_QUOTES);
- file_put_contents($new_description_filename, $description);
+ file_put_contents($env->storage_prefix . $new_description_filename, $description);
// Construct a new entry for the pageindex
$entry = new stdClass();
@@ -133,7 +132,7 @@ register_module([
$pageindex->$new_filename = $entry;
// Save the pageindex
- file_put_contents("pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
+ file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
header("location: ?action=view&page=$new_filename&upload=success");
@@ -143,9 +142,25 @@ register_module([
add_action("preview", function() {
global $settings, $env, $pageindex;
- $filepath = $pageindex->{$env->page}->uploadedfilepath;
+ $filepath = $env->storage_prefix . $pageindex->{$env->page}->uploadedfilepath;
$mime_type = $pageindex->{$env->page}->uploadedfilemime;
+ if(isset($_GET["size"]) and $_GET["size"] == "original")
+ {
+ // Get the file size
+ $filesize = filesize($filepath);
+
+ // Send some headers
+ header("content-length: $filesize");
+ header("content-type: $mime_type");
+
+ // Open the file and send it to the user
+ $handle = fopen($filepath, "rb");
+ fpassthru($handle);
+ fclose($handle);
+ exit();
+ }
+
// Determine the target size of the image
$target_size = 512;
if(isset($_GET["size"]))
@@ -220,6 +235,8 @@ register_module([
$filepath = $pageindex->{$env->page}->uploadedfilepath;
$mime_type = $pageindex->{$env->page}->uploadedfilemime;
$image_link = "//" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . $filepath;
+ if($env->storage_prefix !== "./")
+ $image_link = "?action=preview&size=original&page=" . rawurlencode($env->page);
$preview_sizes = [ 256, 512, 768, 1024, 1536 ];
$preview_html = "
diff --git a/modules/page-delete.php b/modules/page-delete.php
index 9a708cd..3a95437 100644
--- a/modules/page-delete.php
+++ b/modules/page-delete.php
@@ -1,7 +1,7 @@
"Page deleter",
- "version" => "0.7",
+ "version" => "0.8",
"author" => "Starbeamrainbowlabs",
"description" => "Adds an action to allow administrators to delete pages.",
"id" => "page-delete",
@@ -30,11 +30,11 @@ register_module([
// Delete the associated file if it exists
if(!empty($pageindex->$page->uploadedfile))
{
- unlink($pageindex->$page->uploadedfilepath);
+ unlink($env->storage_prefix . $pageindex->$page->uploadedfilepath);
}
unset($pageindex->$page); //delete the page from the page index
- file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT)); //save the new page index
- unlink("./$env->page.md"); //delete the page from the disk
+ file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT)); //save the new page index
+ unlink("$env->storage_prefix$env->page.md"); //delete the page from the disk
exit(page_renderer::render_main("Deleting $env->page - $settings->sitename", "$env->page has been deleted. Go back to the main page .
"));
});
diff --git a/modules/page-edit.php b/modules/page-edit.php
index aafc90c..edaf360 100644
--- a/modules/page-edit.php
+++ b/modules/page-edit.php
@@ -1,7 +1,7 @@
"Page editor",
- "version" => "0.11",
+ "version" => "0.12",
"author" => "Starbeamrainbowlabs",
"description" => "Allows you to edit pages by adding the edit and save actions. You should probably include this one.",
"id" => "page-edit",
@@ -19,7 +19,7 @@ register_module([
add_action("edit", function() {
global $pageindex, $settings, $env;
- $filename = "$env->page.md";
+ $filename = "$env->storage_prefix$env->page.md";
$page = $env->page;
$creatingpage = !isset($pageindex->$page);
if((isset($_GET["newpage"]) and $_GET["newpage"] == "true") or $creatingpage)
@@ -104,7 +104,7 @@ register_module([
{
http_response_code(403);
header("refresh: 5; url=index.php?page=$env->page");
- exit("$env->page is protected, and you aren't logged in as an administrastor or moderator. Your edit was not saved. Redirecting in 5 seconds...");
+ exit("$env->page is protected, and you aren't logged in as an administrator or moderator. Your edit was not saved. Redirecting in 5 seconds...");
}
if(!isset($_POST["content"]))
{
@@ -114,10 +114,10 @@ register_module([
}
// Make sure that the directory in which the page needs to be saved exists
- if(!is_dir(dirname("$env->page.md")))
+ if(!is_dir(dirname("$env->storage_prefix$env->page.md")))
{
// Recursively create the directory if needed
- mkdir(dirname("$env->page.md"), null, true);
+ mkdir(dirname("$env->storage_prefix$env->page.md"), null, true);
}
// Read in the new page content
@@ -155,7 +155,7 @@ register_module([
- if(file_put_contents("$env->page.md", $pagedata) !== false)
+ if(file_put_contents("$env->storage_prefix$env->page.md", $pagedata) !== false)
{
$page = $env->page;
// Make sure that this page's parents exist
@@ -187,10 +187,10 @@ register_module([
}
if($pagedata !== $pagedata_orig)
- file_put_contents("$env->page.md", $pagedata);
+ file_put_contents("$env->storage_prefix$env->page.md", $pagedata);
- file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
+ file_put_contents($paths->pageindex, json_encode($pageindex, JSON_PRETTY_PRINT));
if(isset($_GET["newpage"]))
http_response_code(201);
diff --git a/modules/page-export.php b/modules/page-export.php
index 46657a8..2f00958 100644
--- a/modules/page-export.php
+++ b/modules/page-export.php
@@ -1,7 +1,7 @@
"Export",
- "version" => "0.2",
+ "version" => "0.3",
"author" => "Starbeamrainbowlabs",
"description" => "Adds a page that you can use to export your wiki as a .zip file. Uses \$settings->export_only_allow_admins, which controls whether only admins are allowed to export the wiki.",
"id" => "page-export",
@@ -27,7 +27,7 @@ register_module([
foreach($pageindex as $entry)
{
- $zip->addFile("./$entry->filename", $entry->filename);
+ $zip->addFile("$env->storage_prefix$entry->filename", $entry->filename);
}
if($zip->close() !== true)
diff --git a/modules/page-move.php b/modules/page-move.php
index 5ccb8be..8c090ad 100644
--- a/modules/page-move.php
+++ b/modules/page-move.php
@@ -62,12 +62,12 @@ register_module([
// Move the file in the pageindex
$pageindex->$new_name->uploadedfilepath = $new_name;
// Move the file on disk
- rename($env->page, $new_name);
+ rename($env->storage_prefix . $env->page, $env->storage_prefix . $new_name);
}
file_put_contents("./pageindex.json", json_encode($pageindex, JSON_PRETTY_PRINT));
//move the page on the disk
- rename("$env->page.md", "$new_name.md");
+ rename("$env->storage_prefix$env->page.md", "$env->storage_prefix$new_name.md");
exit(page_renderer::render_main("Moving $env->page", "$env->page has been moved to $new_name successfully.
"));
});