1
0
mirror of https://github.com/typemill/typemill.git synced 2025-07-18 21:11:13 +02:00

moved assets to middleware for proxy detection

This commit is contained in:
trendschau
2020-10-18 08:50:58 +02:00
parent 1e6c42c98a
commit a3167a26ee
15 changed files with 183 additions and 83 deletions

View File

@@ -39,6 +39,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -72,7 +75,7 @@ class ArticleApiController extends ContentController
if(is_array($this->content))
{
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# turn markdown into an array of markdown-blocks
$this->content = $parsedown->arrayBlocksToMarkdown($this->content);
@@ -125,6 +128,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -151,7 +157,7 @@ class ArticleApiController extends ContentController
if(!$this->setContent()){ return $response->withJson($this->errors, 404); }
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# turn markdown into an array of markdown-blocks
$contentArray = $parsedown->markdownToArrayBlocks($this->content);
@@ -219,6 +225,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -237,7 +246,7 @@ class ArticleApiController extends ContentController
# set redirect url to edit page
$url = $this->uri->getBaseUrl() . '/tm/content/' . $this->settings['editor'];
if(isset($this->item->urlRelWoF))
if(isset($this->item->urlRelWoF) && $this->item->urlRelWoF != '/' )
{
$url = $url . $this->item->urlRelWoF;
}
@@ -276,6 +285,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -351,6 +363,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -371,7 +386,7 @@ class ArticleApiController extends ContentController
$updatedContent = '# ' . $this->params['title'] . "\r\n\r\n" . $this->params['content'];
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# turn markdown into an array of markdown-blocks
$contentArray = $parsedown->markdownToArrayBlocks($updatedContent);
@@ -829,7 +844,7 @@ class ArticleApiController extends ContentController
if(!$this->setStructure($draft = true, $cache = false)){ return $response->withJson(array('data' => false, 'errors' => $this->errors, 'url' => $url), 404); }
# set information for homepage
$this->setHomepage();
$this->setHomepage($args = false);
# get item for url and set it active again
if(isset($this->params['url']))
@@ -854,6 +869,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
# set information for homepage
$this->setHomepage($args = false);
/* set item */
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -888,7 +906,7 @@ class ArticleApiController extends ContentController
if(!is_array($content))
{
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# turn markdown into an array of markdown-blocks
$content = $parsedown->markdownToArrayBlocks($content);
@@ -916,6 +934,9 @@ class ArticleApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
# set information for homepage
$this->setHomepage($args = false);
/* set item */
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -947,7 +968,7 @@ class ArticleApiController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# fix footnotes in parsedown, might break with complicated footnotes
$parsedown->setVisualMode();

View File

@@ -33,6 +33,8 @@ class BlockApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
$this->setHomepage($args = false);
/* set item */
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -72,7 +74,7 @@ class BlockApiController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# if content is not an array, then transform it
if(!is_array($pageMarkdown))
@@ -170,7 +172,7 @@ class BlockApiController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# if content is not an array, then transform it
if(!is_array($content))
@@ -229,6 +231,8 @@ class BlockApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
$this->setHomepage($args = false);
/* set item */
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -268,7 +272,7 @@ class BlockApiController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
$parsedown->setVisualMode();
# if content is not an array, then transform it
@@ -384,6 +388,8 @@ class BlockApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -415,7 +421,7 @@ class BlockApiController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# if content is not an array, then transform it
if(!is_array($pageMarkdown))
@@ -490,6 +496,8 @@ class BlockApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -521,7 +529,7 @@ class BlockApiController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# if content is not an array, then transform it
if(!is_array($this->content))

View File

@@ -28,7 +28,7 @@ class ContentBackendController extends ContentController
if(!$this->setStructure($draft = true)){ return $this->renderIntern404($response, array( 'navigation' => true, 'content' => $this->errors )); }
# set information for homepage
$this->setHomepage();
$this->setHomepage($args);
# set item
if(!$this->setItem()){ return $this->renderIntern404($response, array( 'navigation' => $this->structure, 'settings' => $this->settings, 'content' => $this->errors )); }
@@ -44,7 +44,7 @@ class ContentBackendController extends ContentController
# set path
$this->setItemPath($this->item->fileType);
# add the modified date for the file
$this->item->modified = ($this->item->published OR $this->item->drafted) ? filemtime($this->settings['contentFolder'] . $this->path) : false;
@@ -58,7 +58,7 @@ class ContentBackendController extends ContentController
if(is_array($content))
{
# transform array to markdown
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
$content = $parsedown->arrayBlocksToMarkdown($content);
}
@@ -108,7 +108,7 @@ class ContentBackendController extends ContentController
if(!$this->setStructure($draft = true)){ return $this->renderIntern404($response, array( 'navigation' => true, 'content' => $this->errors )); }
# set information for homepage
$this->setHomepage();
$this->setHomepage($args);
# set item
if(!$this->setItem()){ return $this->renderIntern404($response, array( 'navigation' => $this->structure, 'settings' => $this->settings, 'content' => $this->errors )); }
@@ -136,7 +136,7 @@ class ContentBackendController extends ContentController
}
# initialize parsedown extension
$parsedown = new ParsedownExtension();
$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
# to fix footnote-logic in parsedown, set visual mode to true
$parsedown->setVisualMode();

View File

@@ -62,6 +62,8 @@ abstract class ContentController
$this->settings = $this->c->get('settings');
$this->structureLiveName = 'structure.txt';
$this->structureDraftName = 'structure-draft.txt';
$this->c->dispatcher->dispatch('onTwigLoaded');
}
# admin ui rendering
@@ -275,7 +277,8 @@ abstract class ContentController
}
}
protected function setHomepage()
# this is only set by content backend controller
protected function setHomepage($args)
{
$contentFolder = Folder::scanFolderFlat($this->settings['rootPath'] . $this->settings['contentFolder']);
@@ -295,7 +298,7 @@ abstract class ContentController
}
$active = false;
if($this->params['url'] == '/' || $this->params['url'] == $this->uri->getBasePath() )
if($this->params['url'] == '/' || (is_array($args) && empty($args)))
{
$active = 'active';
}
@@ -305,8 +308,11 @@ abstract class ContentController
protected function setItem()
{
# home is only set by backend controller, not by api calls
$home = isset($this->homepage['active']) ? $this->homepage['active'] : false;
# search for the url in the structure
$item = Folder::getItemForUrl($this->structure, $this->params['url'], $this->uri->getBasePath());
$item = Folder::getItemForUrl($this->structure, $this->params['url'], $this->uri->getBaseUrl(), NULL, $home);
if($item)
{

View File

@@ -15,7 +15,8 @@ abstract class Controller
public function __construct(ContainerInterface $c)
{
$this->c = $c;
$this->c = $c;
$this->c->dispatcher->dispatch('onTwigLoaded');
}
# frontend rendering
@@ -23,7 +24,7 @@ abstract class Controller
{
# why commented this out??
$data = $this->c->dispatcher->dispatch('onPageReady', new OnPageReady($data))->getData();
if(isset($_SESSION['old']))
{
unset($_SESSION['old']);

View File

@@ -72,6 +72,9 @@ class MetaApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args = false);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -153,6 +156,9 @@ class MetaApiController extends ContentController
# set structure
if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
# set information for homepage
$this->setHomepage($args);
# set item
if(!$this->setItem()){ return $response->withJson($this->errors, 404); }

View File

@@ -106,10 +106,11 @@ class PageController extends Controller
}
# if the user is on startpage
$home = false;
if(empty($args))
{
$home = true;
$item = Folder::getItemForUrl($navigation, $uri->getBasePath(), $uri->getBasePath());
$item = Folder::getItemForUrl($navigation, $uri->getBasePath(), $uri->getBaseUrl(), NULL, $home);
$urlRel = $uri->getBasePath();
}
else
@@ -178,7 +179,7 @@ class PageController extends Controller
if(isset($item->hide) && !$item->hide)
{
# use the navigation instead of the structure so that hidden elements are erased
$item = Folder::getItemForUrl($navigation, $urlRel, $uri->getBasePath());
$item = Folder::getItemForUrl($navigation, $urlRel, $uri->getBaseUrl(), NULL, $home);
}
}
@@ -200,7 +201,7 @@ class PageController extends Controller
$itemUrl = isset($item->urlRel) ? $item->urlRel : false;
/* initialize parsedown */
$parsedown = new ParsedownExtension($settings['headlineanchors']);
$parsedown = new ParsedownExtension($base_url, $settings['headlineanchors']);
/* set safe mode to escape javascript and html in markdown */
$parsedown->setSafeMode(true);