New basePath: fix officiel plugin paths and vintage template
This commit is contained in:
parent
bc583903ad
commit
9fbc42294e
39 changed files with 169 additions and 244 deletions
|
@ -60,7 +60,7 @@ class ShaarliMiddleware
|
|||
|
||||
$response = $response->withStatus($e->getCode());
|
||||
|
||||
return $response->write($this->container->pageBuilder->render('error'));
|
||||
return $response->write($this->container->pageBuilder->render('error', $this->container->basePath));
|
||||
} catch (UnauthorizedException $e) {
|
||||
$returnUrl = urlencode($this->container->environment['REQUEST_URI']);
|
||||
|
||||
|
@ -80,7 +80,7 @@ class ShaarliMiddleware
|
|||
|
||||
$response = $response->withStatus(500);
|
||||
|
||||
return $response->write($this->container->pageBuilder->render('error'));
|
||||
return $response->write($this->container->pageBuilder->render('error', $this->container->basePath));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ class ManageShaareController extends ShaarliAdminController
|
|||
// To preserve backward compatibility with 3rd parties, plugins still use arrays
|
||||
$formatter = $this->container->formatterFactory->getFormatter('raw');
|
||||
$data = $formatter->format($bookmark);
|
||||
$data = $this->executeHooks('save_link', $data);
|
||||
$this->executePageHooks('save_link', $data);
|
||||
|
||||
$bookmark->fromArray($data);
|
||||
$this->container->bookmarkService->set($bookmark);
|
||||
|
@ -211,7 +211,7 @@ class ManageShaareController extends ShaarliAdminController
|
|||
}
|
||||
|
||||
$data = $formatter->format($bookmark);
|
||||
$this->container->pluginManager->executeHooks('delete_link', $data);
|
||||
$this->executePageHooks('delete_link', $data);
|
||||
$this->container->bookmarkService->remove($bookmark, false);
|
||||
++ $count;
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ class ManageShaareController extends ShaarliAdminController
|
|||
|
||||
// To preserve backward compatibility with 3rd parties, plugins still use arrays
|
||||
$data = $formatter->format($bookmark);
|
||||
$this->container->pluginManager->executeHooks('save_link', $data);
|
||||
$this->executePageHooks('save_link', $data);
|
||||
$bookmark->fromArray($data);
|
||||
|
||||
$this->container->bookmarkService->set($bookmark, false);
|
||||
|
@ -325,7 +325,7 @@ class ManageShaareController extends ShaarliAdminController
|
|||
|
||||
// To preserve backward compatibility with 3rd parties, plugins still use arrays
|
||||
$data = $formatter->format($bookmark);
|
||||
$this->container->pluginManager->executeHooks('save_link', $data);
|
||||
$this->executePageHooks('save_link', $data);
|
||||
$bookmark->fromArray($data);
|
||||
|
||||
$this->container->bookmarkService->set($bookmark);
|
||||
|
@ -354,7 +354,7 @@ class ManageShaareController extends ShaarliAdminController
|
|||
'default_private_links' => $this->container->conf->get('privacy.default_private_links', false),
|
||||
];
|
||||
|
||||
$data = $this->executeHooks('render_editlink', $data);
|
||||
$this->executePageHooks('render_editlink', $data, TemplatePage::EDIT_LINK);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->assignView($key, $value);
|
||||
|
@ -368,19 +368,4 @@ class ManageShaareController extends ShaarliAdminController
|
|||
|
||||
return $response->write($this->render(TemplatePage::EDIT_LINK));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Variables passed to the template engine
|
||||
*
|
||||
* @return mixed[] Template data after active plugins render_picwall hook execution.
|
||||
*/
|
||||
protected function executeHooks(string $hook, array $data): array
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
$hook,
|
||||
$data
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ class PluginsController extends ShaarliAdminController
|
|||
try {
|
||||
$parameters = $request->getParams() ?? [];
|
||||
|
||||
$this->executeHooks($parameters);
|
||||
$this->executePageHooks('save_plugin_parameters', $parameters);
|
||||
|
||||
if (isset($parameters['parameters_form'])) {
|
||||
unset($parameters['parameters_form']);
|
||||
|
@ -81,19 +81,4 @@ class PluginsController extends ShaarliAdminController
|
|||
|
||||
return $this->redirect($response, '/admin/plugins');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Variables passed to the template engine
|
||||
*
|
||||
* @return mixed[] Template data after active plugins render_picwall hook execution.
|
||||
*/
|
||||
protected function executeHooks(array $data): array
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'save_plugin_parameters',
|
||||
$data
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class ToolsController extends ShaarliAdminController
|
|||
'sslenabled' => is_https($this->container->environment),
|
||||
];
|
||||
|
||||
$data = $this->executeHooks($data);
|
||||
$this->executePageHooks('render_tools', $data, TemplatePage::TOOLS);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->assignView($key, $value);
|
||||
|
@ -32,19 +32,4 @@ class ToolsController extends ShaarliAdminController
|
|||
|
||||
return $response->write($this->render(TemplatePage::TOOLS));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Variables passed to the template engine
|
||||
*
|
||||
* @return mixed[] Template data after active plugins render_picwall hook execution.
|
||||
*/
|
||||
protected function executeHooks(array $data): array
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'render_tools',
|
||||
$data
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,7 +124,7 @@ class BookmarkListController extends ShaarliVisitorController
|
|||
|
||||
$data['pagetitle'] = ($data['pagetitle'] ?? '') . $this->container->conf->get('general.title', 'Shaarli');
|
||||
|
||||
$this->executeHooks($data);
|
||||
$this->executePageHooks('render_linklist', $data, TemplatePage::LINKLIST);
|
||||
$this->assignAllView($data);
|
||||
|
||||
return $response->write($this->render(TemplatePage::LINKLIST));
|
||||
|
@ -153,7 +153,7 @@ class BookmarkListController extends ShaarliVisitorController
|
|||
]
|
||||
);
|
||||
|
||||
$this->executeHooks($data);
|
||||
$this->executePageHooks('render_linklist', $data, TemplatePage::LINKLIST);
|
||||
$this->assignAllView($data);
|
||||
|
||||
return $response->write($this->render(TemplatePage::LINKLIST));
|
||||
|
@ -182,18 +182,6 @@ class BookmarkListController extends ShaarliVisitorController
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Template vars to process in plugins, passed as reference.
|
||||
*/
|
||||
protected function executeHooks(array &$data): void
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'render_linklist',
|
||||
$data,
|
||||
['loggedin' => $this->container->loginManager->isLoggedIn()]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] Default template variables without values.
|
||||
*/
|
||||
|
|
|
@ -72,13 +72,11 @@ class DailyController extends ShaarliVisitorController
|
|||
];
|
||||
|
||||
// Hooks are called before column construction so that plugins don't have to deal with columns.
|
||||
$data = $this->executeHooks($data);
|
||||
$this->executePageHooks('render_daily', $data, TemplatePage::DAILY);
|
||||
|
||||
$data['cols'] = $this->calculateColumns($data['linksToDisplay']);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->assignView($key, $value);
|
||||
}
|
||||
$this->assignAllView($data);
|
||||
|
||||
$mainTitle = $this->container->conf->get('general.title', 'Shaarli');
|
||||
$this->assignView(
|
||||
|
@ -190,20 +188,4 @@ class DailyController extends ShaarliVisitorController
|
|||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Variables passed to the template engine
|
||||
*
|
||||
* @return mixed[] Template data after active plugins render_picwall hook execution.
|
||||
*/
|
||||
protected function executeHooks(array $data): array
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'render_daily',
|
||||
$data,
|
||||
['loggedin' => $this->container->loginManager->isLoggedIn()]
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,7 +46,7 @@ class FeedController extends ShaarliVisitorController
|
|||
|
||||
$data = $this->container->feedBuilder->buildData($feedType, $request->getParams());
|
||||
|
||||
$data = $this->executeHooks($data, $feedType);
|
||||
$this->executePageHooks('render_feed', $data, $feedType);
|
||||
$this->assignAllView($data);
|
||||
|
||||
$content = $this->render('feed.'. $feedType);
|
||||
|
@ -55,23 +55,4 @@ class FeedController extends ShaarliVisitorController
|
|||
|
||||
return $response->write($content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Template data
|
||||
*
|
||||
* @return mixed[] Template data after active plugins hook execution.
|
||||
*/
|
||||
protected function executeHooks(array $data, string $feedType): array
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'render_feed',
|
||||
$data,
|
||||
[
|
||||
'loggedin' => $this->container->loginManager->isLoggedIn(),
|
||||
'target' => $feedType,
|
||||
]
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,30 +42,13 @@ class PictureWallController extends ShaarliVisitorController
|
|||
}
|
||||
}
|
||||
|
||||
$data = $this->executeHooks($linksToDisplay);
|
||||
$data = ['linksToDisplay' => $linksToDisplay];
|
||||
$this->executePageHooks('render_picwall', $data, TemplatePage::PICTURE_WALL);
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->assignView($key, $value);
|
||||
}
|
||||
|
||||
return $response->write($this->render(TemplatePage::PICTURE_WALL));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $linksToDisplay List of formatted bookmarks
|
||||
*
|
||||
* @return mixed[] Template data after active plugins render_picwall hook execution.
|
||||
*/
|
||||
protected function executeHooks(array $linksToDisplay): array
|
||||
{
|
||||
$data = [
|
||||
'linksToDisplay' => $linksToDisplay,
|
||||
];
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'render_picwall',
|
||||
$data,
|
||||
['loggedin' => $this->container->loginManager->isLoggedIn()]
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,22 +60,9 @@ abstract class ShaarliVisitorController
|
|||
$this->assignView('privateLinkcount', $this->container->bookmarkService->count(BookmarkFilter::$PRIVATE));
|
||||
$this->assignView('plugin_errors', $this->container->pluginManager->getErrors());
|
||||
|
||||
/*
|
||||
* Define base path (if Shaarli is installed in a domain's subfolder, e.g. `/shaarli`)
|
||||
* and the asset path (subfolder/tpl/default for default theme).
|
||||
* These MUST be used to create an internal link or to include an asset in templates.
|
||||
*/
|
||||
$this->assignView('base_path', $this->container->basePath);
|
||||
$this->assignView(
|
||||
'asset_path',
|
||||
$this->container->basePath . '/' .
|
||||
rtrim($this->container->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
|
||||
$this->container->conf->get('resource.theme', 'default')
|
||||
);
|
||||
|
||||
$this->executeDefaultHooks($template);
|
||||
|
||||
return $this->container->pageBuilder->render($template);
|
||||
return $this->container->pageBuilder->render($template, $this->container->basePath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -97,13 +84,29 @@ abstract class ShaarliVisitorController
|
|||
$pluginData,
|
||||
[
|
||||
'target' => $template,
|
||||
'loggedin' => $this->container->loginManager->isLoggedIn()
|
||||
'loggedin' => $this->container->loginManager->isLoggedIn(),
|
||||
'basePath' => $this->container->basePath,
|
||||
]
|
||||
);
|
||||
$this->assignView('plugins_' . $name, $pluginData);
|
||||
}
|
||||
}
|
||||
|
||||
protected function executePageHooks(string $hook, array &$data, string $template = null): void
|
||||
{
|
||||
$params = [
|
||||
'target' => $template,
|
||||
'loggedin' => $this->container->loginManager->isLoggedIn(),
|
||||
'basePath' => $this->container->basePath,
|
||||
];
|
||||
|
||||
$this->container->pluginManager->executeHooks(
|
||||
$hook,
|
||||
$data,
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple helper which prepend the base path to redirect path.
|
||||
*
|
||||
|
|
|
@ -71,10 +71,8 @@ class TagCloudController extends ShaarliVisitorController
|
|||
'search_tags' => $searchTags,
|
||||
'tags' => $tags,
|
||||
];
|
||||
$data = $this->executeHooks('tag' . $type, $data);
|
||||
foreach ($data as $key => $value) {
|
||||
$this->assignView($key, $value);
|
||||
}
|
||||
$this->executePageHooks('render_tag' . $type, $data, 'tag.' . $type);
|
||||
$this->assignAllView($data);
|
||||
|
||||
$searchTags = !empty($searchTags) ? $searchTags .' - ' : '';
|
||||
$this->assignView(
|
||||
|
@ -82,7 +80,7 @@ class TagCloudController extends ShaarliVisitorController
|
|||
$searchTags . t('Tag '. $type) .' - '. $this->container->conf->get('general.title', 'Shaarli')
|
||||
);
|
||||
|
||||
return $response->write($this->render('tag.'. $type));
|
||||
return $response->write($this->render('tag.' . $type));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -112,20 +110,4 @@ class TagCloudController extends ShaarliVisitorController
|
|||
|
||||
return $tagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed[] $data Template data
|
||||
*
|
||||
* @return mixed[] Template data after active plugins hook execution.
|
||||
*/
|
||||
protected function executeHooks(string $template, array $data): array
|
||||
{
|
||||
$this->container->pluginManager->executeHooks(
|
||||
'render_'. $template,
|
||||
$data,
|
||||
['loggedin' => $this->container->loginManager->isLoggedIn()]
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue