1
0
mirror of https://github.com/typemill/typemill.git synced 2025-08-04 21:27:41 +02:00

V2.2.2 Refactor keyPathArray for live-navigation and fix refItem typo

This commit is contained in:
trendschau
2024-02-18 19:51:19 +01:00
parent 386495b20e
commit ca0dffa5f0
6 changed files with 199 additions and 67 deletions

View File

@@ -2,13 +2,8 @@ meta:
navtitle: 'manage access'
title: 'Manage access'
description: ' Restrict Access for the Website'
heroimage: null
heroimagealt: null
owner: Sebastian
author: Sebastian
allowedrole: null
alloweduser: null
manualdate: null
modified: '2023-05-06'
created: '2023-06-12'
time: 22-36-36

File diff suppressed because one or more lines are too long

View File

@@ -3,7 +3,7 @@
hide: false
noindex: false
path: /00-welcome
keyPath: 0
keyPath: '0'
/welcome/setup-your-website:
navtitle: 'setup your website'
hide: false
@@ -39,7 +39,7 @@
hide: false
noindex: false
path: /01-cyanine-theme
keyPath: 1
keyPath: '1'
/cyanine-theme/landingpage:
navtitle: landingpage
hide: false

View File

@@ -103,7 +103,8 @@ class ControllerWebFrontend extends Controller
$liveNavigation = $navigation->removeHiddenPages($liveNavigation);
# SET PAGEs ACTIVE
$liveNavigation = $navigation->setActiveNaviItems($liveNavigation, $breadcrumb);
# $liveNavigation = $navigation->setActiveNaviItems($liveNavigation, $breadcrumb);
$liveNavigation = $navigation->setActiveNaviItemsWithKeyPath($liveNavigation, $item->keyPathArray);
# DISPATCH LIVE NAVIGATION
$liveNavigation = $this->c->get('dispatcher')->dispatch(new OnPagetreeLoaded($liveNavigation), 'onPagetreeLoaded')->getData();
@@ -111,7 +112,8 @@ class ControllerWebFrontend extends Controller
# For FOLDERS use item without drafts and hidden pages
if(!$home && $item->elementType == 'folder')
{
$item = $navigation->getItemWithUrl($liveNavigation, $item->urlRelWoF);
# $item = $navigation->getItemWithUrl($liveNavigation, $item->urlRelWoF);
$item = $navigation->getItemWithKeyPath($liveNavigation, $item->keyPathArray);
}
# ADD BACKWARD-/FORWARD PAGINATION
@@ -173,7 +175,7 @@ class ControllerWebFrontend extends Controller
{
$metadata = $meta->getMetaData($refitem);
$metadata = $meta->addMetaDefaults($metadata, $refitem, $this->settings['author']);
$metadata = $meta->addMetaTitleDescription($metadata, $refItem, $markdownArray);
$metadata = $meta->addMetaTitleDescription($metadata, $refitem, $markdownArray);
}
break;

View File

@@ -33,12 +33,82 @@ class Folder
return $folderContent;
}
/*
* scans content of a folder recursively and keeps the index order
* vars: folder path as string
* returns: multi-dimensional array with names of folders and files
*/
public function scanFolder($folderPath, $draft = false)
{
$folderItems = scandir($folderPath);
$folderContent = array();
# if it is the live version and if it is a folder that is not published, then do not show the folder and its content.
if(!$draft && !in_array('index.md', $folderItems)){ return false; }
# Remove '.' and '..' from the array
$folderItems = array_diff($folderItems, array('.', '..'));
# Reindex the array
$folderItems = array_values($folderItems);
foreach ($folderItems as $key => $item)
{
if (is_dir($folderPath . DIRECTORY_SEPARATOR . $item))
{
$subFolder = $item;
$folderPublished = file_exists($folderPath . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'index.md');
# scan that folder only if it is a draft or if the folder is published (contains index.md)
if($draft OR $folderPublished)
{
# we need s countable index here
$folderContent[$key . ':' . $subFolder] = $this->scanFolder($folderPath . DIRECTORY_SEPARATOR . $subFolder, $draft);
}
}
else
{
$nameParts = $this->getStringParts($item);
$fileType = array_pop($nameParts);
if($fileType == 'md')
{
$folderContent[] = $item;
}
if($fileType == 'txt')
{
if(isset($last) && ($last == implode($nameParts)) )
{
array_pop($folderContent);
$item = $item . 'md';
}
$folderContent[] = $item;
if(!$draft)
{
$index = count($folderContent)-1;
unset($folderContent[$index]);
}
}
# store the name of the last file
$last = implode($nameParts);
}
}
return $folderContent;
}
/*
* scans content of a folder recursively
* vars: folder path as string
* returns: multi-dimensional array with names of folders and files
*/
public function scanFolder($folderPath, $draft = false)
public function scanFolderOLD($folderPath, $draft = false)
{
$folderItems = scandir($folderPath);
$folderContent = array();
@@ -90,69 +160,131 @@ class Folder
return $folderContent;
}
/*
* scans content of a folder recursively and keeps the index order
* vars: folder path as string
* returns: multi-dimensional array with names of folders and files
* Transforms array of folder item into an array of item-objects with additional information for each item
* vars: multidimensional array with folder- and file-names
* returns: array of objects. Each object contains information about an item (file or folder).
*/
public function scanFolderCheckIndex($folderPath, $draft = false)
public function getFolderContentDetails(array $folderContent, $language, $baseUrl, $fullSlugWithFolder = NULL, $fullSlugWithoutFolder = NULL, $fullPath = NULL, $keyPath = NULL, $chapter = NULL)
{
$folderItems = scandir($folderPath);
$folderContent = array();
$contentDetails = [];
$iteration = 0;
$chapternr = 1;
# if it is the live version and if it is a folder that is not published, then do not show the folder and its content.
if(!$draft && !in_array('index.md', $folderItems)){ return false; }
foreach ($folderItems as $key => $item)
foreach($folderContent as $key => $name)
{
if (!in_array($item, array(".","..")) && substr($item, 0, 1) != '.')
$item = new \stdClass();
if(is_array($name))
{
if (is_dir($folderPath . DIRECTORY_SEPARATOR . $item))
# get the index of the folder. Limit to 2 parts to ensure only the first ":" is used
$findIndex = explode(':', $key, 2);
$key = $findIndex[0];
$folderName = $findIndex[1];
$nameParts = $this->getStringParts($folderName);
$fileType = '';
if(in_array('index.md', $name))
{
$fileType = 'md';
$status = 'published';
}
if(in_array('index.txt', $name))
{
$fileType = 'txt';
$status = 'unpublished';
}
if(in_array('index.txtmd', $name))
{
$fileType = 'txt';
$status = 'modified';
}
$subFolder = $item;
$folderPublished = file_exists($folderPath . DIRECTORY_SEPARATOR . $item . DIRECTORY_SEPARATOR . 'index.md');
$item->originalName = $folderName;
$item->elementType = 'folder';
$item->contains = $this->getFolderContentType($name, $fullPath . DIRECTORY_SEPARATOR . $key . DIRECTORY_SEPARATOR . 'index.yaml');
$item->status = $status;
$item->fileType = $fileType;
$item->order = count($nameParts) > 1 ? array_shift($nameParts) : NULL;
$item->name = implode(" ",$nameParts);
$item->name = iconv(mb_detect_encoding($item->name, mb_detect_order(), true), "UTF-8", $item->name);
$item->slug = implode("-",$nameParts);
$item->slug = $this->createSlug($item->slug, $language);
$item->path = $fullPath . DIRECTORY_SEPARATOR . $folderName;
$item->pathWithoutType = $fullPath . DIRECTORY_SEPARATOR . $folderName . DIRECTORY_SEPARATOR . 'index';
$item->urlRelWoF = $fullSlugWithoutFolder . '/' . $item->slug;
$item->urlRel = $fullSlugWithFolder . '/' . $item->slug;
$item->urlAbs = $baseUrl . $fullSlugWithoutFolder . '/' . $item->slug;
$item->key = $key;
$item->keyPath = isset($keyPath) ? $keyPath . '.' . $key : $key;
$item->keyPathArray = explode('.', $item->keyPath);
$item->chapter = $chapter ? $chapter . '.' . $chapternr : $chapternr;
$item->active = false;
$item->activeParent = false;
$item->hide = false;
# scan that folder only if it is a draft or if the folder is published (contains index.md)
if($draft OR $folderPublished)
{
# we need s countable index here
$folderContent[$subFolder] = $this->scanFolder($folderPath . DIRECTORY_SEPARATOR . $subFolder, $draft);
}
# sort posts in descending order
if($item->contains == "posts")
{
rsort($name);
}
$item->folderContent = $this->getFolderContentDetails($name, $language, $baseUrl, $item->urlRel, $item->urlRelWoF, $item->path, $item->keyPath, $item->chapter);
}
elseif($name)
{
# do not use index files
if($name == 'index.md' || $name == 'index.txt' || $name == 'index.txtmd' ) continue;
$nameParts = $this->getStringParts($name);
$fileType = array_pop($nameParts);
$nameWithoutType = $this->getNameWithoutType($name);
if($fileType == 'md')
{
$status = 'published';
}
elseif($fileType == 'txt')
{
$status = 'unpublished';
}
else
{
$nameParts = $this->getStringParts($item);
$fileType = array_pop($nameParts);
if($fileType == 'md')
{
$folderContent[] = $item;
}
if($fileType == 'txt')
{
if(isset($last) && ($last == implode($nameParts)) )
{
array_pop($folderContent);
$item = $item . 'md';
}
$folderContent[] = $item;
if(!$draft)
{
$index = count($folderContent)-1;
unset($folderContent[$index]);
}
}
# store the name of the last file
$last = implode($nameParts);
$fileType = 'txt';
$status = 'modified';
}
$item->originalName = $name;
$item->elementType = 'file';
$item->status = $status;
$item->fileType = $fileType;
$item->order = count($nameParts) > 1 ? array_shift($nameParts) : NULL;
$item->name = implode(" ",$nameParts);
$item->name = iconv(mb_detect_encoding($item->name, mb_detect_order(), true), "UTF-8", $item->name);
$item->slug = implode("-",$nameParts);
$item->slug = $this->createSlug($item->slug, $language);
$item->path = $fullPath . DIRECTORY_SEPARATOR . $name;
$item->pathWithoutType = $fullPath . DIRECTORY_SEPARATOR . $nameWithoutType;
$item->key = $key;
$item->keyPath = isset($keyPath) ? $keyPath . '.' . $key : $key;
$item->keyPathArray = explode('.',$item->keyPath);
$item->chapter = $chapter . '.' . $chapternr;
$item->urlRelWoF = $fullSlugWithoutFolder . '/' . $item->slug;
$item->urlRel = $fullSlugWithFolder . '/' . $item->slug;
$item->urlAbs = $baseUrl . $fullSlugWithoutFolder . '/' . $item->slug;
$item->active = false;
$item->activeParent = false;
$item->hide = false;
}
$iteration++;
$chapternr++;
$contentDetails[$key] = $item;
}
return $folderContent;
return $contentDetails;
}
@@ -162,7 +294,7 @@ class Folder
* returns: array of objects. Each object contains information about an item (file or folder).
*/
public function getFolderContentDetails(array $folderContent, $language, $baseUrl, $fullSlugWithFolder = NULL, $fullSlugWithoutFolder = NULL, $fullPath = NULL, $keyPath = NULL, $chapter = NULL)
public function getFolderContentDetailsOLD(array $folderContent, $language, $baseUrl, $fullSlugWithFolder = NULL, $fullSlugWithoutFolder = NULL, $fullPath = NULL, $keyPath = NULL, $chapter = NULL)
{
$contentDetails = [];
$iteration = 0;
@@ -277,6 +409,7 @@ class Folder
return $contentDetails;
}
public function getFolderContentType($folder, $yamlpath)
{
# check if folder is empty or has only index.yaml-file. This is a rare case so make it quick and dirty
@@ -299,7 +432,8 @@ class Folder
}
else
{
$file = $folder[0];
$firstKey = array_key_first($folder);
$file = $folder[$firstKey];
$nameParts = $this->getStringParts($file);
$order = count($nameParts) > 1 ? array_shift($nameParts) : NULL;
$order = substr($order, 0, 7);

View File

@@ -206,6 +206,8 @@ class Navigation extends Folder
{
# todo: filter for userrole or username
$basicLiveNavigation = $this->getBasicLiveNavigation($urlinfo, $language);
$this->liveNavigation = $this->storage->getFile('dataFolder', $this->naviFolder, $this->liveNaviName, 'unserialize');
if($this->liveNavigation)
@@ -246,7 +248,7 @@ class Navigation extends Folder
if(count($liveContentTree) > 0)
{
$liveNavigation = $this->getFolderContentDetails($liveContentTree, $language, $urlinfo['baseurl'], $urlinfo['basepath']);
return $liveNavigation;
}
@@ -334,7 +336,7 @@ class Navigation extends Folder
$item->folderContent = $this->mergeNavigationWithExtended($item->folderContent, $extended);
}
$mergedNavigation[] = $item;
$mergedNavigation[$key] = $item;
}
return $mergedNavigation;
@@ -364,7 +366,7 @@ class Navigation extends Folder
return $item;
}
# only used for folders to get items from live-navigation without hidden and unpublished pages
# NOT IN USE ANYMORE BUT KEEP IT
public function getItemWithUrl($navigation, $url, $result = NULL)
{
foreach($navigation as $key => $item)
@@ -390,7 +392,7 @@ class Navigation extends Folder
}
# used with scan folder that generates own indexes for live version
# NOT IN USE ANYMORE BUT KEEP IT
public function setActiveNaviItems($navigation, $breadcrumb)
{
if($breadcrumb)
@@ -550,7 +552,6 @@ class Navigation extends Folder
return $liveNavigation;
}
public function getBreadcrumb($navigation, $searchArray, $i = NULL, $breadcrumb = NULL)
{
# if it is the first round, create an empty array