Skip to content

Commit

Permalink
refactor: simplify isTwInWorkingFolder
Browse files Browse the repository at this point in the history
  • Loading branch information
YakovL committed Dec 19, 2023
1 parent b889b55 commit 27b3003
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,15 +756,11 @@ function isInWokringFolder($file_name_in_current_workingFolder) { // file or fol
$filesAndFolders = scandir($workingFolder); // files' and folders' names in current directory
return in_array($file_name_in_current_workingFolder, $filesAndFolders);
}
// checks whether it's a tw-like html from the current working folder
function isTwInWorkingFolder($file_name_in_current_workingFolder) {
function isTwLikeInCurrentWorkingFolder($file_name) {

if(!isInWokringFolder($file_name_in_current_workingFolder))
return false;
$fullPath = Options::getWorkingFolder() . "/" . $file_name_in_current_workingFolder;
if(!isTwLike($fullPath))
return false;
return true;
if(!isInWokringFolder($file_name)) return false;
$fullPath = Options::getWorkingFolder() . "/" . $file_name;
return isTwLike($fullPath);
}
function getListOfTwLikeHtmls($folder) {

Expand Down Expand Up @@ -1333,7 +1329,7 @@ function getFullWikiLink($nameOrPath) {
if(isset($_POST['save']) || isset($_POST['saveChanges']))
{
$nameOfTwToUpdate = $_POST['wiki'] ? $_POST['wiki'] : Options::get('wikiname');
if(!isTwInWorkingFolder($nameOfTwToUpdate)) {
if(!isTwLikeInCurrentWorkingFolder($nameOfTwToUpdate)) {
http_response_code(404);
echo "error: \"$nameOfTwToUpdate\" is not a valid TiddlyWiki in the working folder";
return;
Expand Down Expand Up @@ -1362,7 +1358,7 @@ function getFullWikiLink($nameOrPath) {
else if(isset($_POST['backupByName']))
{
$twToBackupFileName = $_REQUEST['wiki'] ? $_REQUEST['wiki'] : Options::get('wikiname');
if(!isTwInWorkingFolder($twToBackupFileName)) {
if(!isTwLikeInCurrentWorkingFolder($twToBackupFileName)) {
http_response_code(404);
exit("error: \"$twToBackupFileName\" is not a valid TiddlyWiki in the working folder");
}
Expand Down Expand Up @@ -1567,7 +1563,7 @@ function resolvePath($path) { //# .oO is needed for relative ones? set \ instead
if($isSameFolder) {

//# to support cyrillics and may be other symbols in Win (filename; filepath below), see https://gist.github.com/YakovL/a5425e7f4e116aee87fb121a3ab0b26d (fixFilenameEncoding)
if(isTwInWorkingFolder($requestedFileDecodedName))
if(isTwLikeInCurrentWorkingFolder($requestedFileDecodedName))
showTW($workingFolder . "/" . $requestedFileDecodedName);
//# grab and serve resources other than TWs? test pictures in included tiddlers
} else if($isSubfolder) {
Expand Down

0 comments on commit 27b3003

Please sign in to comment.