mirror of
https://github.com/typemill/typemill.git
synced 2025-08-06 22:26:32 +02:00
Fixed frontend forward back navigation
This commit is contained in:
@@ -249,205 +249,6 @@ class Folder
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getHomepageItem($baseUrl)
|
||||
{
|
||||
die('folder model: getHomepageItem moved to navigation model');
|
||||
|
||||
# return a standard item-object
|
||||
$item = new \stdClass;
|
||||
|
||||
$item->status = 'published';
|
||||
$item->originalName = 'home';
|
||||
$item->elementType = 'folder';
|
||||
$item->fileType = 'md';
|
||||
$item->order = false;
|
||||
$item->name = 'home';
|
||||
$item->slug = '';
|
||||
$item->path = '';
|
||||
$item->pathWithoutType = DIRECTORY_SEPARATOR . 'index';
|
||||
$item->key = false;
|
||||
$item->keyPath = false;
|
||||
$item->keyPathArray = false;
|
||||
$item->chapter = false;
|
||||
$item->urlRel = '/';
|
||||
$item->urlRelWoF = '/';
|
||||
$item->urlAbs = $baseUrl;
|
||||
$item->name = 'home';
|
||||
$item->active = false;
|
||||
$item->activeParent = false;
|
||||
$item->hide = false;
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function getItemForUrl($folderContentDetails, $url, $baseUrl, $result = NULL, $home = NULL )
|
||||
{
|
||||
die('folder model: getItemForUrl. Is it in use?');
|
||||
|
||||
# if we are on the homepage
|
||||
if($home)
|
||||
{
|
||||
return $this->getHomepageItem($baseUrl);
|
||||
}
|
||||
|
||||
foreach($folderContentDetails as $key => $item)
|
||||
{
|
||||
# set item active, needed to move item in navigation
|
||||
if($item->urlRel === $url)
|
||||
{
|
||||
$item->active = true;
|
||||
$result = $item;
|
||||
}
|
||||
elseif($item->elementType === "folder")
|
||||
{
|
||||
$result = $this->getItemForUrl($item->folderContent, $url, $baseUrl, $result);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getItemForUrlFrontend($folderContentDetails, $url, $result = NULL)
|
||||
{
|
||||
die('folder: called function getItemForUrlFrontend');
|
||||
|
||||
foreach($folderContentDetails as $key => $item)
|
||||
{
|
||||
# set item active, needed to move item in navigation
|
||||
if($item->urlRelWoF === $url)
|
||||
{
|
||||
$item->active = true;
|
||||
$result = $item;
|
||||
}
|
||||
elseif($item->elementType === "folder")
|
||||
{
|
||||
$result = $this->getItemForUrlFrontend($item->folderContent, $url, $result);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Gets a copy of an item with a key
|
||||
* @param array $content with the full structure of the content as multidimensional array
|
||||
* @param array $searchArray with the key as a one-dimensional array like array(0,3,4)
|
||||
* @return array $item
|
||||
*/
|
||||
|
||||
|
||||
# copy this to navigation
|
||||
# add keypath to the extended index
|
||||
|
||||
public function getItemWithKeyPath($content, array $searchArray)
|
||||
{
|
||||
die('folder: called function getItemWithKeyPath');
|
||||
|
||||
$item = false;
|
||||
|
||||
foreach($searchArray as $key => $itemKey)
|
||||
{
|
||||
$item = isset($content[$itemKey]) ? clone($content[$itemKey]) : false;
|
||||
|
||||
unset($searchArray[$key]);
|
||||
if(!empty($searchArray) && $item)
|
||||
{
|
||||
return $this->getItemWithKeyPath($item->folderContent, $searchArray);
|
||||
}
|
||||
}
|
||||
return $item;
|
||||
}
|
||||
|
||||
# https://www.quora.com/Learning-PHP-Is-there-a-way-to-get-the-value-of-multi-dimensional-array-by-specifying-the-key-with-a-variable
|
||||
# NOT IN USE
|
||||
public function getItemWithKeyPathNew($array, array $keys)
|
||||
{
|
||||
|
||||
die('folder: called function getItemWithKeyPathNew');
|
||||
|
||||
$item = $array;
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
$item = isset($item[$key]->folderContent) ? $item[$key]->folderContent : $item[$key];
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
/*
|
||||
* Extracts an item with a key https://stackoverflow.com/questions/52097092/php-delete-value-of-array-with-dynamic-key
|
||||
* @param array $content with the full structure of the content as multidimensional array
|
||||
* @param array $searchArray with the key as a one-dimensional array like array(0,3,4)
|
||||
* @return array $item
|
||||
* NOT IN USE ??
|
||||
*/
|
||||
|
||||
public function extractItemWithKeyPath($structure, array $keys)
|
||||
{
|
||||
die('folder: called function extractItemWithKeyPath');
|
||||
|
||||
$result = &$structure;
|
||||
$last = array_pop($keys);
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if(isset($result[$key]->folderContent))
|
||||
{
|
||||
$result = &$result[$key]->folderContent;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = &$result[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$item = $result[$last];
|
||||
unset($result[$last]);
|
||||
|
||||
return array('structure' => $structure, 'item' => $item);
|
||||
}
|
||||
|
||||
# NOT IN USE
|
||||
public function deleteItemWithKeyPathNOTINUSE($structure, array $keys)
|
||||
{
|
||||
die('folder: called function deleteItemWithKeyPathNOTINUSE');
|
||||
|
||||
$result = &$structure;
|
||||
$last = array_pop($keys);
|
||||
|
||||
foreach ($keys as $key)
|
||||
{
|
||||
if(isset($result[$key]->folderContent))
|
||||
{
|
||||
$result = &$result[$key]->folderContent;
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = &$result[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$item = $result[$last];
|
||||
unset($result[$last]);
|
||||
|
||||
return $structure;
|
||||
}
|
||||
|
||||
public function getParentItem($content, $searchArray, $iteration = NULL)
|
||||
{
|
||||
die('folder: called function getParentItem');
|
||||
|
||||
if(!$iteration){ $iteration = 0; }
|
||||
while($iteration < count($searchArray)-2)
|
||||
{
|
||||
$content = $content[$searchArray[$iteration]]->folderContent;
|
||||
$iteration++;
|
||||
return $this->getParentItem($content, $searchArray, $iteration);
|
||||
}
|
||||
return $content[$searchArray[$iteration]];
|
||||
}
|
||||
|
||||
public function getStringParts($name)
|
||||
{
|
||||
|
@@ -461,7 +461,6 @@ class Navigation extends Folder
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function removeHiddenPages($liveNavigation)
|
||||
{
|
||||
foreach($liveNavigation as $key => $item)
|
||||
@@ -514,7 +513,7 @@ class Navigation extends Folder
|
||||
}
|
||||
|
||||
return $breadcrumb;
|
||||
}
|
||||
}
|
||||
|
||||
public function getPagingForItem($navigation, $item)
|
||||
{
|
||||
@@ -524,6 +523,64 @@ class Navigation extends Folder
|
||||
return $item;
|
||||
}
|
||||
|
||||
$keyPos = count($item->keyPathArray)-1;
|
||||
$thisChapArray = $item->keyPathArray;
|
||||
|
||||
$item->thisChapter = false;
|
||||
$item->prevItem = false;
|
||||
$item->nextItem = false;
|
||||
|
||||
if($keyPos > 0)
|
||||
{
|
||||
array_pop($thisChapArray);
|
||||
$item->thisChapter = $this->getItemWithKeyPath($navigation, $thisChapArray);
|
||||
}
|
||||
|
||||
$flat = $this->flatten($navigation, $item->keyPath);
|
||||
|
||||
$itemkey = $flat[0];
|
||||
if($itemkey > 1)
|
||||
{
|
||||
$item->prevItem = $flat[$itemkey-1];
|
||||
}
|
||||
if(isset($flat[$itemkey+1]))
|
||||
{
|
||||
$item->nextItem = $flat[$itemkey+1];
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
|
||||
public function flatten($navigation, $keyPath, $flat = [])
|
||||
{
|
||||
foreach($navigation as $key => $item)
|
||||
{
|
||||
$flat[] = clone($item);
|
||||
|
||||
if($keyPath === $item->keyPath)
|
||||
{
|
||||
array_unshift($flat, count($flat));
|
||||
}
|
||||
|
||||
if($item->elementType == 'folder' && !empty($item->folderContent))
|
||||
{
|
||||
$last = array_key_last($flat);
|
||||
unset($flat[$last]->folderContent);
|
||||
$flat = $this->flatten($item->folderContent, $keyPath, $flat);
|
||||
}
|
||||
}
|
||||
|
||||
return $flat;
|
||||
}
|
||||
|
||||
public function getPagingForItemOld($navigation, $item)
|
||||
{
|
||||
# if page is home
|
||||
if(trim($item->pathWithoutType, DIRECTORY_SEPARATOR) == 'index')
|
||||
{
|
||||
return $item;
|
||||
}
|
||||
|
||||
$keyPos = count($item->keyPathArray)-1;
|
||||
$thisChapArray = $item->keyPathArray;
|
||||
$nextItemArray = $item->keyPathArray;
|
||||
|
@@ -42,8 +42,8 @@
|
||||
{% block content %}{% endblock %}
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div id="loginform"></div>
|
||||
<!-- < csrf() | raw > -->
|
||||
|
||||
<script>
|
||||
|
||||
|
@@ -40,6 +40,7 @@
|
||||
<div id="system" v-cloak></div>
|
||||
</article>
|
||||
</div>
|
||||
|
||||
<div id="loginform"></div>
|
||||
|
||||
<script>
|
||||
|
Reference in New Issue
Block a user