From a1fe27d396790ca9a33c54d05c231cd6b7e191b4 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 08:47:34 -0500 Subject: [PATCH 1/7] update ExceptionListener for FC --- .../Bundle/CoreBundle/Console/Application.php | 1 + .../Doctrine1ConnectorListener.php | 1 + .../EventListener/ExceptionListener.php | 45 ++++++++++++++++++- .../CoreBundle/Resources/config/core.yml | 25 +++++++++-- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/Console/Application.php b/src/lib/Zikula/Bundle/CoreBundle/Console/Application.php index 3dc6af87f7..7d3d66dcfa 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Console/Application.php +++ b/src/lib/Zikula/Bundle/CoreBundle/Console/Application.php @@ -64,6 +64,7 @@ protected function registerCommands() /** * Grants admin access for console commands (#1908). * This avoids subsequent permission problems from any components used. + * @deprecated remove at Core-2.0 */ protected function loginAsAdministrator() { diff --git a/src/lib/Zikula/Bundle/CoreBundle/EventListener/Doctrine1ConnectorListener.php b/src/lib/Zikula/Bundle/CoreBundle/EventListener/Doctrine1ConnectorListener.php index 9110079350..9a0553fda9 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/EventListener/Doctrine1ConnectorListener.php +++ b/src/lib/Zikula/Bundle/CoreBundle/EventListener/Doctrine1ConnectorListener.php @@ -23,6 +23,7 @@ /** * Doctrine listeners. + * @deprecated remove at Core-2.0 */ class Doctrine1ConnectorListener implements EventSubscriberInterface { diff --git a/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php b/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php index 7d5a46b8ff..250b9e24fb 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php +++ b/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php @@ -22,6 +22,7 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException; use Zikula\Bundle\CoreBundle\CacheClearer; use Zikula\Core\Exception\ExtensionNotAvailableException; +use Zikula\PermissionsModule\Api\PermissionApi; use Zikula\UsersModule\Api\CurrentUserApi; /** @@ -29,19 +30,58 @@ */ class ExceptionListener implements EventSubscriberInterface { + /** + * @var LoggerInterface + */ private $logger; + + /** + * @var RouterInterface + */ private $router; + + /** + * @var EventDispatcherInterface + */ private $dispatcher; + + /** + * @var CacheClearer + */ private $cacheClearer; + + /** + * @var CurrentUserApi + */ private $currentUserApi; + + /** + * @var PermissionApi + */ + private $permissionApi; + + /** + * @var bool + */ private $installed; + /** + * ExceptionListener constructor. + * @param LoggerInterface|null $logger + * @param RouterInterface|null $router + * @param EventDispatcherInterface|null $dispatcher + * @param CacheClearer $cacheClearer + * @param CurrentUserApi $currentUserApi + * @param PermissionApi $permissionApi + * @param bool $installed + */ public function __construct( LoggerInterface $logger = null, RouterInterface $router = null, EventDispatcherInterface $dispatcher = null, CacheClearer $cacheClearer, CurrentUserApi $currentUserApi, + PermissionApi $permissionApi, $installed ) { $this->logger = $logger; @@ -49,6 +89,7 @@ public function __construct( $this->dispatcher = $dispatcher; $this->cacheClearer = $cacheClearer; $this->currentUserApi = $currentUserApi; + $this->permissionApi = $permissionApi; $this->installed = $installed; } @@ -131,9 +172,9 @@ private function handleRouteNotFoundException(GetResponseForExceptionEvent $even { $message = $event->getException()->getMessage(); $event->getRequest()->getSession()->getFlashBag()->add('error', $message); - if ($userLoggedIn && \SecurityUtil::checkPermission('ZikulaRoutesModule::', '::', ACCESS_ADMIN)) { + if ($userLoggedIn && $this->permissionApi->hasPermission('ZikulaRoutesModule::', '::', ACCESS_ADMIN)) { try { - $url = $this->router->generate('zikularoutesmodule_route_reload', ['lct' => 'admin'], RouterInterface::ABSOLUTE_URL); + $url = $this->router->generate('zikularoutesmodule_route_adminreload', [], RouterInterface::ABSOLUTE_URL); $link = '' . __('re-loading the routes') . ''; $event->getRequest()->getSession()->getFlashBag()->add('error', __f('You might try %s for the extension in question.', $link)); } catch (RouteNotFoundException $e) { diff --git a/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml b/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml index 1a89f7123b..5fb26da811 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml +++ b/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml @@ -59,7 +59,12 @@ services: zikula_core.common.csrf_token_handler: class: %zikula_core.common.csrf_token_handler.class% - arguments: ["@zikula_core.internal.token.generator", "@zikula_core.internal.token.validator", "@request_stack", "@zikula_extensions_module.api.variable", "@session"] + arguments: + - "@zikula_core.internal.token.generator" + - "@zikula_core.internal.token.validator" + - "@request_stack" + - "@zikula_extensions_module.api.variable" + - "@session" zikula_core.internal.clickjack_protection_listener: class: %zikula_core.internal.clickjack_protection_listener.class% @@ -69,7 +74,14 @@ services: zikula_core.internal.site_off_listener: class: %zikula_core.internal.site_off_listener.class% - arguments: ["@zikula_extensions_module.api.variable", "@zikula_permissions_module.api.permission", "@zikula_users_module.current_user", "@templating", "@form.factory", "@router", "%installed%"] + arguments: + - "@zikula_extensions_module.api.variable" + - "@zikula_permissions_module.api.permission" + - "@zikula_users_module.current_user" + - "@templating" + - "@form.factory" + - "@router" + - "%installed%" tags: - { name: kernel.event_subscriber } @@ -81,7 +93,14 @@ services: zikula_core.internal.exception_listener: class: %zikula_core.internal.exception_listener.class% - arguments: ["@?logger", "@router", "@event_dispatcher", "@zikula.cache_clearer", "@zikula_users_module.current_user", "%installed%"] + arguments: + - "@?logger" + - "@router" + - "@event_dispatcher" + - "@zikula.cache_clearer" + - "@zikula_users_module.current_user" + - "@zikula_permissions_module.api.permission" + - "%installed%" tags: - { name: kernel.event_subscriber } - { name: monolog.logger, channel: request } From 672e585504818caf8b25d5af9e37ace109956055 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 10:05:05 -0500 Subject: [PATCH 2/7] replace DataUtil usage and setup ProfileLink functions for later use by ProfileInterface --- .../Twig/Extension/CoreExtension.php | 116 +++++++++--------- .../Zikula/Bundle/CoreBundle/YamlDumper.php | 13 +- 2 files changed, 60 insertions(+), 69 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php index 9bf6f4ebc3..0c02316021 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php +++ b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php @@ -15,6 +15,7 @@ use Zikula\Bundle\CoreBundle\Twig; use Zikula\Bundle\CoreBundle\Twig\Extension\SimpleFunction\DefaultPathSimpleFunction; use Zikula\Bundle\CoreBundle\Twig\Extension\SimpleFunction\DispatchEventSimpleFunction; +use Zikula\Common\Translator\TranslatorInterface; use Zikula\ThemeModule\Engine\AssetBag; class CoreExtension extends \Twig_Extension @@ -24,9 +25,15 @@ class CoreExtension extends \Twig_Extension */ private $container; + /** + * @var TranslatorInterface + */ + private $translator; + public function __construct(ContainerInterface $container = null) { $this->container = $container; + $this->translator = $container->get('translator.default'); } /** @@ -212,9 +219,7 @@ public function yesNo($string) return $string; } - $translator = $this->container->get('translator.default'); - - return (bool)$string ? $translator->__('Yes') : $translator->__('No'); + return (bool)$string ? $this->translator->__('Yes') : $this->translator->__('No'); } /** @@ -277,10 +282,7 @@ public function profileLinkByUserId($userId, $class = '', $image = '', $maxLengt return $userId; } - $userId = (int)$userId; - $userName = \UserUtil::getVar('uname', $userId); - - return $this->determineProfileLink($userId, $userName, $class, $image, $maxLength); + return $this->determineProfileLink((int)$userId, null, $class, $image, $maxLength); } /** @@ -307,9 +309,7 @@ public function profileLinkByUserName($userName, $class = '', $image = '', $maxL return $userName; } - $userId = \UserUtil::getIdFromName($userName); - - return $this->determineProfileLink($userId, $userName, $class, $image, $maxLength); + return $this->determineProfileLink(null, $userName, $class, $image, $maxLength); } /** @@ -318,45 +318,47 @@ public function profileLinkByUserName($userName, $class = '', $image = '', $maxL * @param integer $userId The users uid * @param string $userName The users name * @param string $class The class name for the link (optional) - * @param string $image Path to the image to show instead of the username (optional) + * @param string $imagePath Path to the image to show instead of the username (optional) * @param integer $maxLength If set then user names are truncated to x chars * @return string The output */ - private function determineProfileLink($userId, $userName, $class = '', $image = '', $maxLength = 0) + private function determineProfileLink($userId = null, $userName = null, $class = '', $imagePath = '', $maxLength = 0) { - $profileLink = ''; - - $profileModule = \System::getVar('profilemodule', ''); - - if ($userId && $userId > 1 && !empty($profileModule) && \ModUtil::available($profileModule)) { - $userDisplayName = \ModUtil::apiFunc($profileModule, 'user', 'getUserDisplayName', ['uid' => $userId]); - if (empty($userDisplayName)) { - $userDisplayName = $userName; - } - - if (!empty($class)) { - $class = ' class="' . \DataUtil::formatForDisplay($class) . '"'; - } + if (!isset($userId) && !isset($userName)) { + throw new \InvalidArgumentException(); + } + if ($userId) { + $user = $this->container->get('zikula_users_module.user_repository')->find($userId); + } else { + $user = $this->container->get('zikula_users_module.user_repository')->findBy(['uname' => $userName]); + } - if (!empty($image)) { - $show = '' . \DataUtil::formatForDisplay($userDisplayName) . ''; - } elseif ($maxLength > 0) { - // truncate the user name to $maxLength chars - $length = strlen($userDisplayName); - $truncEnd = ($maxLength > $length) ? $length : $maxLength; - $show = \DataUtil::formatForDisplay(substr($userDisplayName, 0, $truncEnd)); - } else { - $show = \DataUtil::formatForDisplay($userDisplayName); - } + $profileModule = $this->container->get('zikula_extensions_module.api.variable')->getSystemVar('profilemodule', ''); + if (empty($profileModule) || !$this->container->get('kernel')->isBundle($profileModule)) { + return $user->getUname(); + } - $profileLink = '' . $show . ''; - } elseif (!empty($image)) { - $profileLink = ''; // image for anonymous user should be "empty" + // @todo replace with ProfileInterface usage + $userDisplayName = \ModUtil::apiFunc($profileModule, 'user', 'getUserDisplayName', ['uid' => $user->getUid()]); + if (empty($userDisplayName)) { + $userDisplayName = $user->getUname(); + } + $class = !empty($class) ? ' class="' . htmlspecialchars($class, ENT_QUOTES) . '"': ''; + + if (!empty($imagePath)) { + $show = '' . htmlspecialchars($userDisplayName, ENT_QUOTES) . ''; + } elseif ($maxLength > 0) { + // truncate the user name to $maxLength chars + $length = strlen($userDisplayName); + $truncEnd = ($maxLength > $length) ? $length : $maxLength; + $show = htmlspecialchars(substr($userDisplayName, 0, $truncEnd), ENT_QUOTES); } else { - $profileLink = \DataUtil::formatForDisplay($userName); + $show = htmlspecialchars($userDisplayName, ENT_QUOTES); } + // @todo replace with ProfileInterface usage + $href = htmlspecialchars(\ModUtil::url($profileModule, 'user', 'view', ['uid' => $userId], null, null, true)); - return $profileLink; + return '' . $show . ''; } /** @@ -369,8 +371,7 @@ private function determineProfileLink($userId, $userName, $class = '', $image = public function pageSetVar($name, $value) { if (empty($name) || empty($value)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } $this->container->get('zikula_core.common.theme.pagevars')->set($name, $value); @@ -408,12 +409,10 @@ public function pageAddVar($name, $value) public function pageAddAsset($type, $value, $weight = AssetBag::WEIGHT_DEFAULT) { if (empty($type) || empty($value)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } if (!in_array($type, ['stylesheet', 'javascript', 'header', 'footer']) || !is_numeric($weight)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } // ensure proper variable types @@ -448,8 +447,7 @@ public function pageAddAsset($type, $value, $weight = AssetBag::WEIGHT_DEFAULT) public function pageGetVar($name, $default = null) { if (empty($name)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } return $this->container->get('zikula_core.common.theme.pagevars')->get($name, $default); @@ -464,8 +462,7 @@ public function pageGetVar($name, $default = null) public function getModVar($module, $name, $default = null) { if (empty($module) || empty($name)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } return $this->container->get('zikula_extensions_module.api.variable')->get($module, $name, $default); @@ -479,8 +476,7 @@ public function getModVar($module, $name, $default = null) public function getSystemVar($name, $default = null) { if (empty($name)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } return $this->container->get('zikula_extensions_module.api.variable')->getSystemVar($name, $default); @@ -493,16 +489,16 @@ public function getSystemVar($name, $default = null) public function setMetaTag($name, $value) { if (empty($name) || empty($value)) { - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Empty argument at') . ':' . __FILE__ . '::' . __LINE__); } $metaTags = $this->container->hasParameter('zikula_view.metatags') ? $this->container->getParameter('zikula_view.metatags') : []; - $metaTags[$name] = \DataUtil::formatForDisplay($value); + $metaTags[$name] = htmlspecialchars($value, ENT_QUOTES); $this->container->setParameter('zikula_view.metatags', $metaTags); } /** + * @deprecated remove at Core-2.0 * @param string $modname * @param bool $force * @return bool @@ -516,17 +512,15 @@ public function modAvailable($modname, $force = false) /** * Call a php callable with parameters. - * @param array|string $callable + * @param callable $callable * @param array $params * @return mixed */ - public function callFunc($callable, array $params = []) + public function callFunc(callable $callable, array $params = []) { - if (function_exists($callable) && is_callable($callable)) { + if (function_exists($callable)) { return call_user_func_array($callable, $params); } - - $translator = $this->container->get('translator.default'); - throw new \InvalidArgumentException($translator->__('Function does not exist or is not callable.') . ':' . __FILE__ . '::' . __LINE__); + throw new \InvalidArgumentException($this->translator->__('Function does not exist or is not callable.') . ':' . __FILE__ . '::' . __LINE__); } } diff --git a/src/lib/Zikula/Bundle/CoreBundle/YamlDumper.php b/src/lib/Zikula/Bundle/CoreBundle/YamlDumper.php index ec1175d478..5eb31f9a9e 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/YamlDumper.php +++ b/src/lib/Zikula/Bundle/CoreBundle/YamlDumper.php @@ -157,15 +157,12 @@ public function delConfiguration($name) /** * Returns configuration in html format. * - * @param string $name The requested configuration's name - * @param bool $fetchDefault Whether or not to return the values specified in the dynamic_config_default.yml file - * if no configuration is set in the dynamic_config.yml file - * + * @param string $name The requested configuration's name * @return string */ - public function getConfigurationForHtml($name, $fetchDefault = true) + public function getConfigurationForHtml($name) { - $config = $this->getConfiguration($name, $fetchDefault); + $config = $this->getConfiguration($name); $html = $this->formatValue($config); return $html; @@ -187,11 +184,11 @@ protected function formatValue($value) $html = ''; foreach ($value as $key => $val) { - $html .= '
  • ' . \DataUtil::formatForDisplay($key) . ':'; + $html .= '
  • ' . htmlspecialchars($key, ENT_QUOTES) . ':'; if (is_array($val)) { $html .= $this->formatValue($val) . "
  • \n"; } else { - $val = !empty($val) ? \DataUtil::formatForDisplay($val) : 'null'; + $val = !empty($val) ? htmlspecialchars($val, ENT_QUOTES) : 'null'; $html .= " " . $val . "\n"; } } From e8d0d2980dde357becda996e689d4401768099bd Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 10:06:43 -0500 Subject: [PATCH 3/7] ci --- .../Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php index 0c02316021..2d53eea072 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php +++ b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php @@ -343,7 +343,7 @@ private function determineProfileLink($userId = null, $userName = null, $class = if (empty($userDisplayName)) { $userDisplayName = $user->getUname(); } - $class = !empty($class) ? ' class="' . htmlspecialchars($class, ENT_QUOTES) . '"': ''; + $class = !empty($class) ? ' class="' . htmlspecialchars($class, ENT_QUOTES) . '"' : ''; if (!empty($imagePath)) { $show = '' . htmlspecialchars($userDisplayName, ENT_QUOTES) . ''; From 51bddfcf8a5ca3acf33ff73c184c449267d70ca0 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 10:48:23 -0500 Subject: [PATCH 4/7] update Pager to remove deprecated calls --- .../Twig/Extension/PagerExtension.php | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/PagerExtension.php b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/PagerExtension.php index ca082fe9f8..7e4b7fb9b6 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/PagerExtension.php +++ b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/PagerExtension.php @@ -13,6 +13,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Zikula\ExtensionsModule\Api\VariableApi; class PagerExtension extends \Twig_Extension { @@ -91,6 +92,7 @@ public function pager($params) $templateName = (isset($params['template'])) ? $params['template'] : 'CoreBundle:Pager:pagercss.html.twig'; $processDetailLinks = isset($params['processDetailLinks']) ? (bool)$params['processDetailLinks'] : ($templateName != 'CoreBundle:Pager:pagerimage.html.twig'); $anchorText = isset($params['anchorText']) ? '#' . $params['anchorText'] : ''; + $systemVars = $this->container->get('zikula_extensions_module.api.variable')->getAll(VariableApi::CONFIG); $routeParams = []; if ($request->attributes->has('_route_params')) { @@ -135,7 +137,7 @@ public function pager($params) } break; case 'lang': - $addcurrentlang2url = \System::getVar('languageurl'); + $addcurrentlang2url = $systemVars['languageurl']; if ($addcurrentlang2url == 0) { $pager['args'][$k] = $v; } @@ -171,21 +173,21 @@ public function pager($params) } } - $pagerUrl = function ($pager) use ($routeName) { - if (!$routeName) { - // only case where this should be true is if this is the homepage - $startargs = explode(',', \System::getVar('startargs')); - foreach ($startargs as $arg) { - if (!empty($arg)) { - $argument = explode('=', $arg); - $pager['args'][$argument[0]] = $argument[1]; - } - } + $pagerUrl = function ($pager) use ($routeName, $systemVars) { + if ($routeName) { + return $this->container->get('router')->generate($routeName, $pager['args']); + } + // only case where this should be true is if this is the homepage + parse_str($systemVars['startargs'], $pager['args']); + if ($systemVars['startController']) { + $route = strtolower(str_replace(':', '_', $systemVars['startController'])); - return \ModUtil::url(\System::getVar('startpage'), \System::getVar('starttype'), \System::getVar('startfunc'), $pager['args']); + return $this->container->get('router')->generate($route, $pager['args']); } - return $this->container->get('router')->generate($routeName, $pager['args']); + // @todo @deprecated remove at Core-2.0 + // replace with `return $this->container->get('router')->generate('home', $pager['args'])` + return \ModUtil::url($systemVars['startpage'], $systemVars['starttype'], $systemVars['startfunc'], $pager['args']); }; // build links to items / pages @@ -230,14 +232,14 @@ public function pager($params) $pager['pages'][$currItem]['pagenr'] = $currItem; $pager['pages'][$currItem]['isCurrentPage'] = ($pager['pages'][$currItem]['pagenr'] == $pager['currentPage']); $pager['pages'][$currItem]['isVisible'] = $currItemVisible; - $pager['pages'][$currItem]['url'] = \DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText); + $pager['pages'][$currItem]['url'] = $pagerUrl($pager) . $anchorText; } unset($pager['args'][$pager['posvar']]); } // link to first & prev page $pager['args'][$pager['posvar']] = $pager['first'] = '1'; - $pager['firstUrl'] = \DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText); + $pager['firstUrl'] = $pagerUrl($pager) . $anchorText; if ($displayType == 'page') { $pager['prev'] = ($pager['currentPage'] - 1); @@ -245,7 +247,7 @@ public function pager($params) $pager['prev'] = ($leftMargin - 1) * $pager['perpage'] - $pager['perpage'] + $pager['first']; } $pager['args'][$pager['posvar']] = ($pager['prev'] > 1) ? $pager['prev'] : 1; - $pager['prevUrl'] = \DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText); + $pager['prevUrl'] = $pagerUrl($pager) . $anchorText; // link to next & last page if ($displayType == 'page') { @@ -254,7 +256,7 @@ public function pager($params) $pager['next'] = $rightMargin * $pager['perpage'] + 1; } $pager['args'][$pager['posvar']] = ($pager['next'] < $pager['total']) ? $pager['next'] : $pager['next'] - $pager['perpage']; - $pager['nextUrl'] = \DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText); + $pager['nextUrl'] = $pagerUrl($pager) . $anchorText; if ($displayType == 'page') { $pager['last'] = $pager['countPages']; @@ -262,7 +264,7 @@ public function pager($params) $pager['last'] = $pager['countPages'] * $pager['perpage'] - $pager['perpage'] + 1; } $pager['args'][$pager['posvar']] = $pager['last']; - $pager['lastUrl'] = \DataUtil::formatForDisplay($pagerUrl($pager) . $anchorText); + $pager['lastUrl'] = $pagerUrl($pager) . $anchorText; $pager['itemStart'] = ($pager['currentPage'] * $pager['perpage']) - $pager['perpage'] + 1; $pager['itemEnd'] = $pager['itemStart'] + $pager['perpage'] - 1; From 3aedaf308012930c15314bac2fffae2114756a9e Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 11:33:00 -0500 Subject: [PATCH 5/7] update HookBundle to remove deprecated calls --- .../HookBundle/Controller/HookController.php | 9 +++- .../Storage/Doctrine/DoctrineStorage.php | 49 ++++++++++--------- .../HookBundle/Resources/config/services.yml | 2 +- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/lib/Zikula/Bundle/HookBundle/Controller/HookController.php b/src/lib/Zikula/Bundle/HookBundle/Controller/HookController.php index e771639d94..256cbfa887 100644 --- a/src/lib/Zikula/Bundle/HookBundle/Controller/HookController.php +++ b/src/lib/Zikula/Bundle/HookBundle/Controller/HookController.php @@ -56,6 +56,7 @@ public function editAction($moduleName) // create an instance of the module's version // we will use it to get the bundles + // @todo @deprecated in Core-2.0 use `$bundle->getMetaData()` and assume instance of MetaData $moduleVersionObj = ExtensionsUtil::getVersionMeta($moduleName); if ($moduleVersionObj instanceof MetaData) { // Core-2.0 Spec module @@ -133,6 +134,7 @@ public function editAction($moduleName) } // create an instance of the subscriber's version + // @todo @deprecated in Core-2.0 use `$bundle->getMetaData()` and assume instance of MetaData $hooksubscriberVersionObj = ExtensionsUtil::getVersionMeta($hooksubscribers[$i]['name']); if ($hooksubscriberVersionObj instanceof MetaData) { // Core-2.0 Spec module @@ -160,7 +162,7 @@ public function editAction($moduleName) $hooksubscribers[$i]['areasToCategories'] = $hooksubscriberAreasToCategories; } $templateParameters['hooksubscribers'] = $hooksubscribers; - $templateParameters['total_available_subscriber_areas'] = $$amountOfAvailableSubscriberAreas; + $templateParameters['total_available_subscriber_areas'] = $amountOfAvailableSubscriberAreas; } else { $templateParameters['total_available_subscriber_areas'] = 0; } @@ -194,6 +196,7 @@ public function editAction($moduleName) $sbaProviderModule = $this->get('hook_dispatcher')->getOwnerByArea($areaname); // create an instance of the provider's version + // @todo @deprecated in Core-2.0 use `$bundle->getMetaData()` and assume instance of MetaData $sbaProviderModuleVersionObj = ExtensionsUtil::getVersionMeta($sbaProviderModule); if ($sbaProviderModuleVersionObj instanceof MetaData) { // Core-2.0 Spec module @@ -229,6 +232,7 @@ public function editAction($moduleName) } // create an instance of the provider's version + // @todo @deprecated in Core-2.0 use `$bundle->getMetaData()` and assume instance of MetaData $hookproviderVersionObj = ExtensionsUtil::getVersionMeta($hookproviders[$i]['name']); if ($hookproviderVersionObj instanceof MetaData) { // Core-2.0 Spec module @@ -308,6 +312,7 @@ public function toggleSubscribeAreaStatusAction(Request $request) if (empty($subscriber)) { throw new \InvalidArgumentException($this->get('translator.default')->__f('Module "%s" is not a valid subscriber.', $subscriber)); } + // @todo @deprecated in Core-2.0 use `$this->get('kernel')->isBundle($subscriber)` if (!\ModUtil::available($subscriber)) { throw new \RuntimeException($this->get('translator.default')->__f('Subscriber module "%s" is not available.', $subscriber)); } @@ -326,6 +331,7 @@ public function toggleSubscribeAreaStatusAction(Request $request) if (empty($provider)) { throw new \InvalidArgumentException($this->get('translator.default')->__f('Module "%s" is not a valid provider.', $provider)); } + // @todo @deprecated in Core-2.0 use `$this->get('kernel')->isBundle($provider)` if (!\ModUtil::available($provider)) { throw new \RuntimeException($this->get('translator.default')->__f('Provider module "%s" is not available.', $provider)); } @@ -388,6 +394,7 @@ public function changeProviderAreaOrderAction(Request $request) if (empty($subscriber)) { throw new \InvalidArgumentException($this->get('translator.default')->__f('Module "%s" is not a valid subscriber.', $subscriber)); } + // @todo @deprecated in Core-2.0 use `$this->get('kernel')->isBundle($subscriber)` if (!\ModUtil::available($subscriber)) { throw new \RuntimeException($this->get('translator.default')->__f('Subscriber module "%s" is not available.', $subscriber)); } diff --git a/src/lib/Zikula/Bundle/HookBundle/Dispatcher/Storage/Doctrine/DoctrineStorage.php b/src/lib/Zikula/Bundle/HookBundle/Dispatcher/Storage/Doctrine/DoctrineStorage.php index 9562b2c027..0d4c73f59f 100644 --- a/src/lib/Zikula/Bundle/HookBundle/Dispatcher/Storage/Doctrine/DoctrineStorage.php +++ b/src/lib/Zikula/Bundle/HookBundle/Dispatcher/Storage/Doctrine/DoctrineStorage.php @@ -11,18 +11,20 @@ namespace Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine; -use DataUtil; use Doctrine\ORM\EntityManager; -use LogUtil; -use System; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Zikula\Bundle\HookBundle\Dispatcher\Exception\InvalidArgumentException; use Zikula\Bundle\HookBundle\Dispatcher\StorageInterface; +use Zikula\Common\Translator\TranslatorInterface; +use Zikula\Common\Translator\TranslatorTrait; /** * Doctrine class. */ class DoctrineStorage implements StorageInterface { + use TranslatorTrait; + const PROVIDER = 'p'; const SUBSCRIBER = 's'; @@ -33,9 +35,21 @@ class DoctrineStorage implements StorageInterface */ private $em; - public function __construct(EntityManager $em) + /** + * @var SessionInterface + */ + private $session; + + public function __construct(EntityManager $em, SessionInterface $session, TranslatorInterface $translator) { $this->em = $em; + $this->session = $session; + $this->setTranslator($translator); + } + + public function setTranslator($translator) + { + $this->translator = $translator; } public function registerSubscriber($owner, $subOwner, $areaName, $areaType, $category, $eventName) @@ -45,15 +59,10 @@ public function registerSubscriber($owner, $subOwner, $areaName, $areaType, $cat // Now we have an areaId we can register a subscriber, but first test if the subscriber is already registered. $existingSubscriber = $this->getSubscriberByEventName($eventName); if (!empty($existingSubscriber)) { - if (System::isDevelopmentMode()) { - LogUtil::registerWarning(__f('The hook subscriber "%1$s" could not be registered for "%2$s" because it is registered already.', [$eventName, $owner])); - } else { - $warns = LogUtil::getWarningMessages(false); - $msg = __f('Hook subscribers could not be registered for "%1$s" because they are registered already.', [$owner]); - if (!in_array(DataUtil::formatForDisplayHTML($msg), $warns)) { - LogUtil::registerWarning($msg); - } - } + $this->session->getFlashBag()->add('warning', $this->__f('The hook subscriber "%sub" could not be registered for "%own" because it is registered already.', [ + '%sub' => $eventName, + '%own' => $owner + ])); return; } @@ -116,15 +125,11 @@ public function registerProvider($owner, $subOwner, $areaName, $hookType, $categ $existingProvider = $this->getProviderByAreaAndType($pareaId, $hookType); if (!empty($existingProvider)) { - if (System::isDevelopmentMode()) { - LogUtil::registerWarning(__f('The hook provider for area "%1$s" of type "%2$s" could not be registered for "%3$s" because it already exists.', [$pareaId, $hookType, $owner])); - } else { - $warns = LogUtil::getWarningMessages(false); - $msg = __f('Hook providers could not be registered for "%1$s" because they already exist.', [$owner]); - if (!in_array(DataUtil::formatForDisplayHTML($msg), $warns)) { - LogUtil::registerWarning($msg); - } - } + $this->session->getFlashBag()->add('warning', $this->__f('The hook provider for area "%parea" of type "%type" could not be registered for "%own" because it already exists.', [ + '%parea' => $pareaId, + '%type' => $hookType, + '%own' => $owner + ])); return; } diff --git a/src/lib/Zikula/Bundle/HookBundle/Resources/config/services.yml b/src/lib/Zikula/Bundle/HookBundle/Resources/config/services.yml index eba7651cc4..1727262e0d 100644 --- a/src/lib/Zikula/Bundle/HookBundle/Resources/config/services.yml +++ b/src/lib/Zikula/Bundle/HookBundle/Resources/config/services.yml @@ -23,7 +23,7 @@ services: hook_dispatcher.storage: class: Zikula\Bundle\HookBundle\Dispatcher\Storage\Doctrine\DoctrineStorage - arguments: ["@doctrine.orm.default_entity_manager"] + arguments: ["@doctrine.orm.default_entity_manager", "@session", "@translator.default"] hook_dispatcher.servicefactory: class: Zikula\Bundle\HookBundle\Dispatcher\ServiceFactory From a298b6bd3c03ec59668c29f8ee68ffe99141d654 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 11:39:24 -0500 Subject: [PATCH 6/7] remove use of wrong route --- .../Resources/views/plugins/function.adminheader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/system/AdminModule/Resources/views/plugins/function.adminheader.php b/src/system/AdminModule/Resources/views/plugins/function.adminheader.php index aa3d21af2b..20670181c2 100644 --- a/src/system/AdminModule/Resources/views/plugins/function.adminheader.php +++ b/src/system/AdminModule/Resources/views/plugins/function.adminheader.php @@ -27,7 +27,7 @@ function smarty_function_adminheader($params, $view) try { $router->generate('zikulaadminmodule_admininterface_header'); } catch (\Symfony\Component\Routing\Exception\RouteNotFoundException $e) { - $url = $view->getContainer()->get('router')->generate('zikularoutesmodule_route_reload', ['lct' => 'admin', 'confirm' => 1]); + $url = $view->getContainer()->get('router')->generate('zikularoutesmodule_route_adminreload', ['confirm' => 1]); return '
    ' . __f('Routes must be reloaded. Click %s to reload all routes.', '' . __('here') . '') . '
    '; } From 0802fae7fdbc3dabf33d59496562ef922fd3b6ba Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 28 Dec 2016 11:52:55 -0500 Subject: [PATCH 7/7] correct args on ExceptionListener --- .../EventListener/ExceptionListener.php | 17 ++++------------- .../Bundle/CoreBundle/Resources/config/core.yml | 1 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php b/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php index 250b9e24fb..4fc221db13 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php +++ b/src/lib/Zikula/Bundle/CoreBundle/EventListener/ExceptionListener.php @@ -11,7 +11,6 @@ namespace Zikula\Bundle\CoreBundle\EventListener; -use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -30,11 +29,6 @@ */ class ExceptionListener implements EventSubscriberInterface { - /** - * @var LoggerInterface - */ - private $logger; - /** * @var RouterInterface */ @@ -67,24 +61,21 @@ class ExceptionListener implements EventSubscriberInterface /** * ExceptionListener constructor. - * @param LoggerInterface|null $logger - * @param RouterInterface|null $router - * @param EventDispatcherInterface|null $dispatcher + * @param RouterInterface $router + * @param EventDispatcherInterface $dispatcher * @param CacheClearer $cacheClearer * @param CurrentUserApi $currentUserApi * @param PermissionApi $permissionApi * @param bool $installed */ public function __construct( - LoggerInterface $logger = null, - RouterInterface $router = null, - EventDispatcherInterface $dispatcher = null, + RouterInterface $router, + EventDispatcherInterface $dispatcher, CacheClearer $cacheClearer, CurrentUserApi $currentUserApi, PermissionApi $permissionApi, $installed ) { - $this->logger = $logger; $this->router = $router; $this->dispatcher = $dispatcher; $this->cacheClearer = $cacheClearer; diff --git a/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml b/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml index 5fb26da811..4e0bf1ca5a 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml +++ b/src/lib/Zikula/Bundle/CoreBundle/Resources/config/core.yml @@ -94,7 +94,6 @@ services: zikula_core.internal.exception_listener: class: %zikula_core.internal.exception_listener.class% arguments: - - "@?logger" - "@router" - "@event_dispatcher" - "@zikula.cache_clearer"