mirror of
https://github.com/typemill/typemill.git
synced 2025-08-04 21:27:41 +02:00
Version 1.4.4: Finished Access Controle
This commit is contained in:
@@ -973,19 +973,24 @@ class ArticleApiController extends ContentController
|
||||
# fix footnotes in parsedown, might break with complicated footnotes
|
||||
$parsedown->setVisualMode();
|
||||
|
||||
# flag for TOC
|
||||
$toc = false;
|
||||
|
||||
$tocMarkup = false;
|
||||
|
||||
# if content is not an array, then transform it
|
||||
if(!is_array($content))
|
||||
{
|
||||
# turn markdown into an array of markdown-blocks
|
||||
$content = $parsedown->markdownToArrayBlocks($content);
|
||||
|
||||
# build toc here to avoid duplicated toc for live content
|
||||
$tocMarkup = $parsedown->buildTOC($parsedown->headlines);
|
||||
}
|
||||
|
||||
# needed for ToC links
|
||||
$relurl = '/tm/content/' . $this->settings['editor'] . '/' . $this->item->urlRel;
|
||||
|
||||
# flag for TOC
|
||||
$toc = false;
|
||||
|
||||
# loop through mardkown-array and create html-blocks
|
||||
foreach($content as $key => $block)
|
||||
{
|
||||
@@ -1003,7 +1008,11 @@ class ArticleApiController extends ContentController
|
||||
|
||||
if($toc)
|
||||
{
|
||||
$tocMarkup = $parsedown->buildTOC($parsedown->headlines);
|
||||
if(!$tocMarkup)
|
||||
{
|
||||
$tocMarkup = $parsedown->buildTOC($parsedown->headlines);
|
||||
}
|
||||
|
||||
$content[$toc] = ['id' => $toc, 'html' => $tocMarkup];
|
||||
}
|
||||
|
||||
|
@@ -129,6 +129,18 @@ class MetaApiController extends ContentController
|
||||
$metascheme[$tabname][$fieldname] = true;
|
||||
$metadata[$tabname][$fieldname] = isset($pagemeta[$tabname][$fieldname]) ? $pagemeta[$tabname][$fieldname] : null;
|
||||
|
||||
|
||||
# check if there is a selectfield for userroles
|
||||
if(isset($fielddefinitions['type']) && ($fielddefinitions['type'] == 'select' ) && isset($fielddefinitions['dataset']) && ($fielddefinitions['dataset'] == 'userroles' ) )
|
||||
{
|
||||
$userroles = [null => null];
|
||||
foreach($this->c->acl->getRoles() as $userrole)
|
||||
{
|
||||
$userroles[$userrole] = $userrole;
|
||||
}
|
||||
$metadefinitions[$tabname]['fields'][$fieldname]['options'] = $userroles;
|
||||
}
|
||||
|
||||
/*
|
||||
# special treatment for customfields
|
||||
if(isset($fielddefinitions['type']) && ($fielddefinitions['type'] == 'customfields' ) && $metadata[$tabname][$fieldname] )
|
||||
@@ -189,7 +201,7 @@ class MetaApiController extends ContentController
|
||||
}
|
||||
|
||||
# if item is a folder
|
||||
if($this->item->elementType == "folder")
|
||||
if($this->item->elementType == "folder" && isset($this->item->contains))
|
||||
{
|
||||
$pagemeta['meta']['contains'] = isset($pagemeta['meta']['contains']) ? $pagemeta['meta']['contains'] : $this->item->contains;
|
||||
|
||||
@@ -217,6 +229,18 @@ class MetaApiController extends ContentController
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if($fieldDefinition && isset($fieldDefinition['type']) && ($fieldDefinition['type'] == 'select' ) && isset($fieldDefinition['dataset']) && ($fieldDefinition['dataset'] == 'userroles' ) )
|
||||
{
|
||||
$userroles = [null => null];
|
||||
foreach($this->c->acl->getRoles() as $userrole)
|
||||
{
|
||||
$userroles[$userrole] = $userrole;
|
||||
}
|
||||
$fieldDefinition['options'] = $userroles;
|
||||
}
|
||||
|
||||
|
||||
# validate user input for this field
|
||||
$result = $validate->objectField($fieldName, $fieldValue, $objectName, $fieldDefinition);
|
||||
|
||||
|
@@ -241,7 +241,7 @@ class PageController extends Controller
|
||||
$shortenedPage = $this->cutRestrictedContent($markdownBlocks);
|
||||
|
||||
# check if there is customized content
|
||||
$restrictionnotice = ( isset($this->settings['restrictionnotice']) && $this->settings['restrictionnotice'] != '' ) ? $this->settings['restrictionnotice'] : 'You are not allowed to access this content.';
|
||||
$restrictionnotice = $this->prepareRestrictionNotice();
|
||||
|
||||
# add notice to shortened content
|
||||
$shortenedPage[] = $restrictionnotice;
|
||||
@@ -478,7 +478,8 @@ class PageController extends Controller
|
||||
# check if page is restricted to certain user
|
||||
if(isset($meta['alloweduser']) && $meta['alloweduser'] && $meta['alloweduser'] !== '' )
|
||||
{
|
||||
if(isset($_SESSION['user']) && $_SESSION['user'] == $meta['alloweduser'])
|
||||
$alloweduser = array_map('trim', explode(",", $meta['alloweduser']));
|
||||
if(isset($_SESSION['user']) && in_array($_SESSION['user'], $alloweduser))
|
||||
{
|
||||
# user has access to the page, so there are no restrictions
|
||||
return false;
|
||||
@@ -539,4 +540,37 @@ class PageController extends Controller
|
||||
|
||||
return $restrictedMarkdown;
|
||||
}
|
||||
|
||||
protected function prepareRestrictionNotice()
|
||||
{
|
||||
if( isset($this->settings['restrictionnotice']) && $this->settings['restrictionnotice'] != '' )
|
||||
{
|
||||
$restrictionNotice = $this->settings['restrictionnotice'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$restrictionNotice = 'You are not allowed to access this content.';
|
||||
}
|
||||
|
||||
if( isset($this->settings['wraprestrictionnotice']) && $this->settings['wraprestrictionnotice'] )
|
||||
{
|
||||
# standardize line breaks
|
||||
$text = str_replace(array("\r\n", "\r"), "\n", $restrictionNotice);
|
||||
|
||||
# remove surrounding line breaks
|
||||
$text = trim($text, "\n");
|
||||
|
||||
# split text into lines
|
||||
$lines = explode("\n", $text);
|
||||
|
||||
$restrictionNotice = '';
|
||||
|
||||
foreach($lines as $key => $line)
|
||||
{
|
||||
$restrictionNotice .= "!!!! " . $line . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return $restrictionNotice;
|
||||
}
|
||||
}
|
@@ -95,6 +95,7 @@ class SettingsController extends Controller
|
||||
'pageaccess' => isset($newSettings['pageaccess']) ? true : null,
|
||||
'hrdelimiter' => isset($newSettings['hrdelimiter']) ? true : null,
|
||||
'restrictionnotice' => $newSettings['restrictionnotice'],
|
||||
'wraprestrictionnotice' => isset($newSettings['wraprestrictionnotice']) ? true : null,
|
||||
'headlineanchors' => isset($newSettings['headlineanchors']) ? $newSettings['headlineanchors'] : null,
|
||||
'displayErrorDetails' => isset($newSettings['displayErrorDetails']) ? true : null,
|
||||
'twigcache' => isset($newSettings['twigcache']) ? true : null,
|
||||
|
Reference in New Issue
Block a user