From 85b6bba689f04a0a6d39f1272e1f9ef5d996cf1a Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Fri, 14 Jun 2019 09:45:40 -0500 Subject: [PATCH 1/3] Changed path_to_tags to interpret ; as : and to allow inheriting categories from parent folders --- core/util.php | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/core/util.php b/core/util.php index 299463d8..57c7577e 100644 --- a/core/util.php +++ b/core/util.php @@ -281,21 +281,44 @@ function manual_include(string $fname): ?string function path_to_tags(string $path): string { $matches = []; - $tags = ""; - if (preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) { - $tags = $matches[1]; - } + $tags = []; + if(preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) { + $tags = explode($matches[1]," "); + } + + $path = dirname($path); + $path = str_replace(";", ":", $path); + $path = str_replace("__", " ", $path); - $dir_tags = dirname($path); - $dir_tags = str_replace("/", " ", $dir_tags); - $dir_tags = str_replace("__", " ", $dir_tags); - $dir_tags = trim($dir_tags); - if ($dir_tags != "") { - $tags = trim($tags)." ".trim($dir_tags); + + $category = ""; + foreach(explode("/", $path) as $dir) { + $category_to_inherit = ""; + foreach(explode(" ", $dir) as $tag) { + $tag = trim($tag); + if($tag=="") { + continue; + } + if(substr_compare($tag, ":", -1) === 0) { + // This indicates a tag that ends in a colon, + // which is for inheriting to tags on the subfolder + $category_to_inherit = $tag; + } else { + if($category!=""&&strpos($tag, ":") === false) { + // This indicates that category inheritance is active, + // and we've encountered a tag that does not specify a category. + // So we attach the inherited category to the tag. + $tag = $category.$tag; + } + array_push($tags, $tag); + } + } + // Category inheritance only works on the immediate subfolder, + // so we hold a category until the next iteration, and then set + // it back to an empty string after that iteration + $category = $category_to_inherit; } - $tags = trim($tags); - - return $tags; + return implode(" ",$tags); } From c951f7d13e18f3ae8bb21d95757a62331a2234e4 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Wed, 19 Jun 2019 19:35:45 -0500 Subject: [PATCH 2/3] Adjusted path-to-dir regex to prevent an error --- core/util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/util.php b/core/util.php index 57c7577e..3c1ef7e1 100644 --- a/core/util.php +++ b/core/util.php @@ -282,7 +282,7 @@ function path_to_tags(string $path): string { $matches = []; $tags = []; - if(preg_match("/\d+ - (.*)\.([a-zA-Z0-9]+)/", basename($path), $matches)) { + if(preg_match("/\d+ - (.+)\.([a-zA-Z0-9]+)/", basename($path), $matches)) { $tags = explode($matches[1]," "); } From a2ac9776ff30c0468947715a6f702f4058168704 Mon Sep 17 00:00:00 2001 From: Matthew Barbour Date: Wed, 19 Jun 2019 23:26:30 -0500 Subject: [PATCH 3/3] path tag corrections --- core/util.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/util.php b/core/util.php index 3c1ef7e1..566474df 100644 --- a/core/util.php +++ b/core/util.php @@ -283,9 +283,9 @@ function path_to_tags(string $path): string $matches = []; $tags = []; if(preg_match("/\d+ - (.+)\.([a-zA-Z0-9]+)/", basename($path), $matches)) { - $tags = explode($matches[1]," "); + $tags = explode(" ",$matches[1]); } - + $path = dirname($path); $path = str_replace(";", ":", $path); $path = str_replace("__", " ", $path); @@ -310,7 +310,7 @@ function path_to_tags(string $path): string // So we attach the inherited category to the tag. $tag = $category.$tag; } - array_push($tags, $tag); + $tags[] = $tag; } } // Category inheritance only works on the immediate subfolder, @@ -318,6 +318,7 @@ function path_to_tags(string $path): string // it back to an empty string after that iteration $category = $category_to_inherit; } + return implode(" ",$tags); }