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

Version 1.3.2: Rename and Hide navigation

This commit is contained in:
trendschau
2020-01-20 18:52:57 +01:00
parent 00368397ce
commit 53f17927fd
26 changed files with 443 additions and 85 deletions

View File

@@ -246,9 +246,12 @@ class ContentApiController extends ContentController
# update the live structure
$this->setStructure($draft = false, $cache = false);
#update the backend structure
# update the backend structure
$this->setStructure($draft = true, $cache = false);
# check if page is in extended structure and delete it
$this->deleteFromExtended();
# dispatch event
$this->c->dispatcher->dispatch('onPageDeleted', new OnPageDeleted($this->item));
@@ -324,12 +327,6 @@ class ContentApiController extends ContentController
$parentKeyFrom = explode('.', $this->params['parent_id_from']);
$parentKeyTo = explode('.', $this->params['parent_id_to']);
/*
echo '<pre>';
print_r(array($itemKeyPath 0,$parentKeyFrom navi,$parentKeyTo 2));
die();
*/
# get the item from structure
$item = Folder::getItemWithKeyPath($this->structure, $itemKeyPath);
@@ -362,10 +359,16 @@ class ContentApiController extends ContentController
# delete item from folderContent
unset($folderContent[$itemKey]);
}
elseif($this->params['active'] == 'active')
else
{
# rename links in extended file
$this->renameExtended($item, $newFolder);
# an active file has been moved to another folder, so send new url with response
$url = $this->uri->getBaseUrl() . '/tm/content/' . $this->settings['editor'] . $newFolder->urlRelWoF . '/' . $item->slug;
if($this->params['active'] == 'active')
{
$url = $this->uri->getBaseUrl() . '/tm/content/' . $this->settings['editor'] . $newFolder->urlRelWoF . '/' . $item->slug;
}
}
# add item to newFolder

View File

@@ -9,6 +9,7 @@ use Typemill\Models\Validation;
use Typemill\Models\Folder;
use Typemill\Models\Write;
use Typemill\Models\WriteCache;
use Typemill\Models\WriteYaml;
abstract class ContentController
{
@@ -182,7 +183,7 @@ abstract class ContentController
# set variables and objects
$this->write = new writeCache();
# check, if cached structure is still valid
if($cache && $this->write->validate('cache', 'lastCache.txt', 600))
{
@@ -199,18 +200,76 @@ abstract class ContentController
# if there is content, then get the content details
if(count($structure) > 0)
{
# create an array of object with the whole content of the folder
$structure = Folder::getFolderContentDetails($structure, $this->uri->getBaseUrl(), $this->uri->getBasePath());
# get the extended structure files with changes like navigation title or hidden pages
$yaml = new writeYaml();
$extended = $yaml->getYaml('cache', 'structure-extended.yaml');
# create an array of object with the whole content of the folder and changes from extended file
$structure = Folder::getFolderContentDetails($structure, $extended, $this->uri->getBaseUrl(), $this->uri->getBasePath());
}
# cache navigation
$this->write->updateCache('cache', $filename, 'lastCache.txt', $structure);
}
$this->structure = $structure;
return true;
}
protected function renameExtended($item, $newFolder)
{
# get the extended structure files with changes like navigation title or hidden pages
$yaml = new writeYaml();
$extended = $yaml->getYaml('cache', 'structure-extended.yaml');
if(isset($extended[$item->urlRelWoF]))
{
$newUrl = $newFolder->urlRelWoF . '/' . $item->slug;
$entry = $extended[$item->urlRelWoF];
unset($extended[$item->urlRelWoF]);
$extended[$newUrl] = $entry;
$yaml->updateYaml('cache', 'structure-extended.yaml', $extended);
}
return true;
}
protected function deleteFromExtended()
{
# get the extended structure files with changes like navigation title or hidden pages
$yaml = new writeYaml();
$extended = $yaml->getYaml('cache', 'structure-extended.yaml');
if($this->item->elementType == "file" && isset($extended[$this->item->urlRelWoF]))
{
unset($extended[$this->item->urlRelWoF]);
$yaml->updateYaml('cache', 'structure-extended.yaml', $extended);
}
if($this->item->elementType == "folder")
{
$changed = false;
# delete all entries with that folder url
foreach($extended as $url => $entries)
{
if( strpos($url, $this->item->urlRelWoF) !== false )
{
$changed = true;
unset($extended[$url]);
}
}
if($changed)
{
$yaml->updateYaml('cache', 'structure-extended.yaml', $extended);
}
}
}
protected function setHomepage()
{
$contentFolder = Folder::scanFolderFlat($this->settings['rootPath'] . $this->settings['contentFolder']);
@@ -251,6 +310,7 @@ abstract class ContentController
}
$this->errors = ['errors' => ['message' => 'requested page-url not found']];
return false;
}
@@ -334,6 +394,9 @@ abstract class ContentController
}
return rmdir($path);
}
# delete all files from the extended file
$this->deleteFromExtended();
}
return false;
}

View File

@@ -5,6 +5,7 @@ namespace Typemill\Controllers;
use Slim\Http\Request;
use Slim\Http\Response;
use Typemill\Models\WriteYaml;
use Typemill\Models\Folder;
class MetaApiController extends ContentController
{
@@ -23,10 +24,6 @@ class MetaApiController extends ContentController
$metatabs = $writeYaml->getYaml('system' . DIRECTORY_SEPARATOR . 'author', 'metatabs.yaml');
# load cached metadefinitions
# check if valid
# if not, refresh cache
# loop through all plugins
foreach($this->settings['plugins'] as $name => $plugin)
{
@@ -39,6 +36,14 @@ class MetaApiController extends ContentController
}
}
}
# add the meta from theme settings here
$themeSettings = \Typemill\Settings::getObjectSettings('themes', $this->settings['theme']);
if($themeSettings && isset($themeSettings['metatabs']))
{
$metatabs = array_merge_recursive($metatabs, $themeSettings['metatabs']);
}
return $metatabs;
}
@@ -77,32 +82,37 @@ class MetaApiController extends ContentController
$metadefinitions = $this->aggregateMetaDefinitions();
$metadata = [];
$metascheme = [];
foreach($metadefinitions as $tabname => $tab )
{
$metadata[$tabname] = [];
$metadata[$tabname] = [];
foreach($tab['fields'] as $fieldname => $fielddefinitions)
{
$metascheme[$tabname][$fieldname] = true;
$metadata[$tabname][$fieldname] = isset($pagemeta[$tabname][$fieldname]) ? $pagemeta[$tabname][$fieldname] : null;
}
}
# store the metascheme in cache for frontend
$writeYaml->updateYaml('cache', 'metatabs.yaml', $metascheme);
return $response->withJson(array('metadata' => $metadata, 'metadefinitions' => $metadefinitions, 'errors' => false));
}
public function updateArticleMeta(Request $request, Response $response, $args)
{
/* get params from call */
# get params from call
$this->params = $request->getParams();
$this->uri = $request->getUri();
$tab = isset($this->params['tab']) ? $this->params['tab'] : false;
$metaData = isset($this->params['data']) ? $this->params['data'] : false ;
$metaInput = isset($this->params['data']) ? $this->params['data'] : false ;
$objectName = 'meta';
$errors = false;
if(!$tab or !$metaData)
if(!$tab or !$metaInput)
{
return $response->withJson($this->errors, 404);
}
@@ -114,7 +124,7 @@ class MetaApiController extends ContentController
$validate = $this->getValidator();
# take the user input data and iterate over all fields and values
foreach($metaData as $fieldName => $fieldValue)
foreach($metaInput as $fieldName => $fieldValue)
{
# get the corresponding field definition from original plugin settings */
$fieldDefinition = isset($metaDefinitions[$tab]['fields'][$fieldName]) ? $metaDefinitions[$tab]['fields'][$fieldName] : false;
@@ -147,16 +157,66 @@ class MetaApiController extends ContentController
$writeYaml = new writeYaml();
# get existing metadata for page
$meta = $writeYaml->getYaml($this->settings['contentFolder'], $this->item->pathWithoutType . '.yaml');
$metaPage = $writeYaml->getYaml($this->settings['contentFolder'], $this->item->pathWithoutType . '.yaml');
# get extended structure
$extended = $writeYaml->getYaml('cache', 'structure-extended.yaml');
# flag for changed structure
$structure = false;
if($tab == 'meta')
{
# normalize the meta-input
$metaInput['navtitle'] = (isset($metaInput['navtitle']) && $metaInput['navtitle'] !== null )? $metaInput['navtitle'] : '';
$metaInput['hide'] = (isset($metaInput['hide']) && $metaInput['hide'] !== null) ? $metaInput['hide'] : false;
# input values are empty but entry in structure exists
if(!$metaInput['hide'] && $metaInput['navtitle'] == "" && isset($extended[$this->item->urlRelWoF]))
{
# delete the entry in the structure
unset($extended[$this->item->urlRelWoF]);
$structure = true;
}
# check if navtitle or hide-value has been changed
elseif(
($metaPage['meta']['navtitle'] != $metaInput['navtitle'])
OR
($metaPage['meta']['hide'] != $metaInput['hide'])
)
{
# add new file data. Also makes sure that the value is set.
$extended[$this->item->urlRelWoF] = ['hide' => $metaInput['hide'], 'navtitle' => $metaInput['navtitle']];
$structure = true;
}
if($structure)
{
# store the file
$writeYaml->updateYaml('cache', 'structure-extended.yaml', $extended);
# recreate the draft structure
$this->setStructure($draft = true, $cache = false);
# set item in navigation active again
$activeItem = Folder::getItemForUrl($this->structure, $this->item->urlRel, $this->uri->getBaseUrl());
# send new structure to frontend
$structure = $this->structure;
}
}
# add the new/edited metadata
$meta[$tab] = $metaData;
$meta[$tab] = $metaInput;
# store the metadata
$writeYaml->updateYaml($this->settings['contentFolder'], $this->item->pathWithoutType . '.yaml', $meta);
# return with the new metadata
return $response->withJson(array('metadata' => $metaData, 'errors' => false));
return $response->withJson(array('metadata' => $metaInput, 'structure' => $structure, 'errors' => false));
}
}

View File

@@ -40,7 +40,7 @@ class PageController extends Controller
try
{
/* if the cached structure is still valid, use it */
if($cache->validate('cache', 'lastCache.txt',600))
if($cache->validate('cache', 'lastCache.txt', 600))
{
$structure = $this->getCachedStructure($cache);
}
@@ -75,7 +75,15 @@ class PageController extends Controller
echo $e->getMessage();
exit(1);
}
# get the cached navigation here (structure without hidden files )
$navigation = $cache->getCache('cache', 'navigation.txt');
if(!$navigation)
{
# use the structure as navigation if there is no difference
$navigation = $structure;
}
# if the user is on startpage
if(empty($args))
{
@@ -93,7 +101,7 @@ class PageController extends Controller
/* if there is still no item, return a 404-page */
if(!$item)
{
return $this->render404($response, array( 'navigation' => $structure, 'settings' => $settings, 'base_url' => $base_url ));
return $this->render404($response, array( 'navigation' => $navigation, 'settings' => $settings, 'base_url' => $base_url ));
}
/* get breadcrumb for page */
@@ -124,7 +132,6 @@ class PageController extends Controller
# get meta-Information
$writeYaml = new WriteYaml();
$metatabs = $writeYaml->getPageMeta($settings, $item);
if(!$metatabs)
@@ -196,12 +203,19 @@ class PageController extends Controller
$theme = $settings['theme'];
$route = empty($args) && isset($settings['themes'][$theme]['cover']) ? '/cover.twig' : '/index.twig';
# check if there is a custom theme css
$customcss = $writeYaml->checkFile('cache', $theme . '-custom.css');
if($customcss)
{
$this->c->assets->addCSS($base_url . '/cache/' . $theme . '-custom.css');
}
return $this->render($response, $route, [
'home' => $home,
'navigation' => $structure,
'title' => $title,
'navigation' => $navigation,
'title' => $title,
'content' => $contentHTML,
'item' => $item,
'item' => $item,
'breadcrumb' => $breadcrumb,
'settings' => $settings,
'metatabs' => $metatabs,
@@ -225,15 +239,62 @@ class PageController extends Controller
return false;
}
/* create an array of object with the whole content of the folder */
$structure = Folder::getFolderContentDetails($structure, $uri->getBaseUrl(), $uri->getBasePath());
# get the extended structure files with changes like navigation title or hidden pages
$yaml = new writeYaml();
$extended = $yaml->getYaml('cache', 'structure-extended.yaml');
/* cache navigation */
/* create an array of object with the whole content of the folder */
$structure = Folder::getFolderContentDetails($structure, $extended, $uri->getBaseUrl(), $uri->getBasePath());
/* cache structure */
$cache->updateCache('cache', 'structure.txt', 'lastCache.txt', $structure);
if($this->containsHiddenPages($extended))
{
# generate the navigation (delete empty pages)
$navigation = $this->createNavigationFromStructure($structure);
# cache navigation
$cache->updateCache('cache', 'navigation.txt', false, $navigation);
}
else
{
# make sure no separate navigation file is set
$cache->deleteFileWithPath('cache' . DIRECTORY_SEPARATOR . 'navigation.txt');
}
return $structure;
}
protected function containsHiddenPages($extended)
{
foreach($extended as $element)
{
if(isset($element['hide']) && $element['hide'] === true)
{
return true;
}
}
return false;
}
protected function createNavigationFromStructure($navigation)
{
foreach ($navigation as $key => $element)
{
if($element->hide === true)
{
unset($navigation[$key]);
}
elseif(isset($element->folderContent))
{
$navigation[$key]->folderContent = $this->createNavigationFromStructure($element->folderContent);
}
}
return $navigation;
}
protected function updateVersion($baseUrl)
{
/* check the latest public typemill version */

View File

@@ -3,6 +3,7 @@
namespace Typemill\Controllers;
use \Symfony\Component\Yaml\Yaml;
use Typemill\Models\Write;
use Typemill\Models\Fields;
use Typemill\Models\Validation;
use Typemill\Models\User;
@@ -91,7 +92,7 @@ class SettingsController extends Controller
public function showThemes($request, $response, $args)
{
$userSettings = $this->c->get('settings');
$userSettings = $this->c->get('settings');
$themes = $this->getThemes();
$themedata = array();
$fieldsModel = new Fields();
@@ -109,24 +110,40 @@ class SettingsController extends Controller
}
$themeSettings = \Typemill\Settings::getObjectSettings('themes', $themeName);
# add standard-textarea for custom css
$themeSettings['forms']['fields']['customcss'] = ['type' => 'textarea', 'label' => 'Custom CSS', 'rows' => 10, 'class' => 'codearea', 'description' => 'You can overwrite the theme-css with your own css here.'];
# load custom css-file
$write = new write();
$customcss = $write->getFile('cache', $themeName . '-custom.css');
$themeSettings['settings']['customcss'] = $customcss;
if($themeSettings)
{
/* store them as default theme data with author, year, default settings and field-definitions */
$themedata[$themeName] = $themeSettings;
}
if(isset($themeSettings['forms']['fields']))
{
$fields = $fieldsModel->getFields($userSettings, 'themes', $themeName, $themeSettings);
$fields = $fieldsModel->getFields($userSettings, 'themes', $themeName, $themeSettings);
/* overwrite original theme form definitions with enhanced form objects */
$themedata[$themeName]['forms']['fields'] = $fields;
}
/* add the preview image */
$img = getcwd() . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $themeName . DIRECTORY_SEPARATOR . $themeName . '.jpg';
$img = file_exists($img) ? $img : false;
$img = getcwd() . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $themeName . DIRECTORY_SEPARATOR . $themeName;
$jpg = $img . '.jpg';
$png = $img . '.png';
$img = file_exists($jpg) ? $jpg : false;
if(!$img)
{
$img = file_exists($png) ? $png : false;
}
$themedata[$themeName]['img'] = $img;
}
@@ -134,7 +151,7 @@ class SettingsController extends Controller
$user = new User();
$users = $user->getUsers();
$route = $request->getAttribute('route');
return $this->render($response, 'settings/themes.twig', array('settings' => $userSettings, 'themes' => $themedata, 'users' => $users, 'route' => $route->getName() ));
}
@@ -245,6 +262,34 @@ class SettingsController extends Controller
/* set theme name and delete theme settings from user settings for the case, that the new theme has no settings */
$userSettings['theme'] = $themeName;
# extract the custom css from user input
$customcss = isset($userInput['customcss']) ? $userInput['customcss'] : false;
# delete custom css from userinput
unset($userInput['customcss']);
$write = new write();
# make sure no file is set if there is no custom css
if(!$customcss OR $customcss == '')
{
# delete the css file if exists
$write->deleteFileWithPath('cache' . DIRECTORY_SEPARATOR . $themeName . '-custom.css');
}
else
{
if ( $customcss != strip_tags($customcss) )
{
$_SESSION['errors'][$themeName]['customcss'][] = 'custom css contains html';
}
else
{
# store css
$write = new write();
$write->writeFile('cache', $themeName . '-custom.css', $customcss);
}
}
if($userInput)
{
/* validate the user-input */