mirror of
https://github.com/sbrl/Pepperminty-Wiki.git
synced 2024-11-25 17:23:00 +00:00
Attempt to detect associated files when rebuilding the pageindex. Implements #27.
This commit is contained in:
parent
9c1b5faf28
commit
1f68038636
2 changed files with 62 additions and 6 deletions
|
@ -678,8 +678,8 @@ function system_mime_type_extension($type) {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sort out the pageindex. We create it if it doesn't exist, and load and parse
|
* Sort out the pageindex. Create it if it doesn't exist, and load + parse it
|
||||||
* it if it does.
|
* if it does.
|
||||||
*/
|
*/
|
||||||
if(!file_exists($paths->pageindex))
|
if(!file_exists($paths->pageindex))
|
||||||
{
|
{
|
||||||
|
@ -701,6 +701,34 @@ if(!file_exists($paths->pageindex))
|
||||||
// Extract the name of the (sub)page without the ".md" or the storage dir
|
// Extract the name of the (sub)page without the ".md" or the storage dir
|
||||||
$pagekey = utf8_encode(substr($pagefilename, strlen($env->storage_prefix), -3));
|
$pagekey = utf8_encode(substr($pagefilename, strlen($env->storage_prefix), -3));
|
||||||
|
|
||||||
|
// Calculate the position of the last dot in the file name
|
||||||
|
$last_dot_pos = strrpos($newentry->filename, ".");
|
||||||
|
// Keep everything up to the last dot
|
||||||
|
$uploaded_file_path = substr($newentry->filename, 0, $last_dot_pos);
|
||||||
|
// Work out the location of the next last dot
|
||||||
|
$next_dot_pos = strrpos($uploaded_file_path, ".");
|
||||||
|
if(
|
||||||
|
// There is another dot in the uploaded file path
|
||||||
|
$next_dot_pos !== false &&
|
||||||
|
// This other dot is after the last slash
|
||||||
|
$next_dot_pos >= strrpos($uploaded_file_path, "/") &&
|
||||||
|
// The file actually exists
|
||||||
|
file_exists($env->storage_prefix . $uploaded_file_path))
|
||||||
|
{
|
||||||
|
// This page (potentially) has an associated file!
|
||||||
|
// Let's investigate.
|
||||||
|
|
||||||
|
// Blindly add the file to the pageindex for now.
|
||||||
|
// Future We might want to do a security check on the file later on. File a bug if you think this is a good idea.
|
||||||
|
$newentry->uploadedfile = true; // Yes this page does have an uploaded file associated with it
|
||||||
|
$newentry->uploadedfilepath = $uploaded_file_path; // It's stored here
|
||||||
|
|
||||||
|
// Work out what kind of file it really is
|
||||||
|
$mimechecker = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
|
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $uploaded_file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Subpage parent checker
|
// Subpage parent checker
|
||||||
if(strpos($pagekey, "/") !== false)
|
if(strpos($pagekey, "/") !== false)
|
||||||
{
|
{
|
||||||
|
|
32
core.php
32
core.php
|
@ -340,8 +340,8 @@ function system_mime_type_extension($type) {
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sort out the pageindex. We create it if it doesn't exist, and load and parse
|
* Sort out the pageindex. Create it if it doesn't exist, and load + parse it
|
||||||
* it if it does.
|
* if it does.
|
||||||
*/
|
*/
|
||||||
if(!file_exists($paths->pageindex))
|
if(!file_exists($paths->pageindex))
|
||||||
{
|
{
|
||||||
|
@ -363,6 +363,34 @@ if(!file_exists($paths->pageindex))
|
||||||
// Extract the name of the (sub)page without the ".md" or the storage dir
|
// Extract the name of the (sub)page without the ".md" or the storage dir
|
||||||
$pagekey = utf8_encode(substr($pagefilename, strlen($env->storage_prefix), -3));
|
$pagekey = utf8_encode(substr($pagefilename, strlen($env->storage_prefix), -3));
|
||||||
|
|
||||||
|
// Calculate the position of the last dot in the file name
|
||||||
|
$last_dot_pos = strrpos($newentry->filename, ".");
|
||||||
|
// Keep everything up to the last dot
|
||||||
|
$uploaded_file_path = substr($newentry->filename, 0, $last_dot_pos);
|
||||||
|
// Work out the location of the next last dot
|
||||||
|
$next_dot_pos = strrpos($uploaded_file_path, ".");
|
||||||
|
if(
|
||||||
|
// There is another dot in the uploaded file path
|
||||||
|
$next_dot_pos !== false &&
|
||||||
|
// This other dot is after the last slash
|
||||||
|
$next_dot_pos >= strrpos($uploaded_file_path, "/") &&
|
||||||
|
// The file actually exists
|
||||||
|
file_exists($env->storage_prefix . $uploaded_file_path))
|
||||||
|
{
|
||||||
|
// This page (potentially) has an associated file!
|
||||||
|
// Let's investigate.
|
||||||
|
|
||||||
|
// Blindly add the file to the pageindex for now.
|
||||||
|
// Future We might want to do a security check on the file later on. File a bug if you think this is a good idea.
|
||||||
|
$newentry->uploadedfile = true; // Yes this page does have an uploaded file associated with it
|
||||||
|
$newentry->uploadedfilepath = $uploaded_file_path; // It's stored here
|
||||||
|
|
||||||
|
// Work out what kind of file it really is
|
||||||
|
$mimechecker = finfo_open(FILEINFO_MIME_TYPE);
|
||||||
|
$newentry->uploadedfilemime = finfo_file($mimechecker, $env->storage_prefix . $uploaded_file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Subpage parent checker
|
// Subpage parent checker
|
||||||
if(strpos($pagekey, "/") !== false)
|
if(strpos($pagekey, "/") !== false)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue