Skip to content
This repository was archived by the owner on May 27, 2023. It is now read-only.

Commit 7b6ad9e

Browse files
committed
fixed avatar image path determination
1 parent eab3353 commit 7b6ad9e

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

Bridge/ProfileModuleBridge.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use InvalidArgumentException;
1717
use Symfony\Component\HttpFoundation\RequestStack;
1818
use Symfony\Component\Routing\RouterInterface;
19+
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
1920
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
2021
use Zikula\ProfileModule\Helper\GravatarHelper;
2122
use Zikula\ProfileModule\ProfileConstant;
@@ -27,6 +28,11 @@
2728

2829
class ProfileModuleBridge implements ProfileModuleInterface
2930
{
31+
/**
32+
* @var ZikulaHttpKernelInterface
33+
*/
34+
private $kernel;
35+
3036
/**
3137
* @var RouterInterface
3238
*/
@@ -63,6 +69,7 @@ class ProfileModuleBridge implements ProfileModuleInterface
6369
private $prefix;
6470

6571
public function __construct(
72+
ZikulaHttpKernelInterface $kernel,
6673
RouterInterface $router,
6774
RequestStack $requestStack,
6875
VariableApiInterface $variableApi,
@@ -71,6 +78,7 @@ public function __construct(
7178
GravatarHelper $gravatarHelper,
7279
$prefix
7380
) {
81+
$this->kernel = $kernel;
7482
$this->router = $router;
7583
$this->requestStack = $requestStack;
7684
$this->variableApi = $variableApi;
@@ -122,7 +130,7 @@ public function getAvatar($uid = null, array $parameters = []): string
122130

123131
$avatarUrl = '';
124132
if (!in_array($avatar, ['blank.gif', 'blank.jpg'], true)) {
125-
if (isset($avatar) && !empty($avatar) && $avatar !== $gravatarImage && file_exists($avatarPath . '/' . $avatar)) {
133+
if (isset($avatar) && !empty($avatar) && $avatar !== $gravatarImage && file_exists($this->kernel->getProjectDir() . '/' . $avatarPath . '/' . $avatar)) {
126134
$request = $this->requestStack->getCurrentRequest();
127135
if (null !== $request) {
128136
$avatarUrl = $request->getSchemeAndHttpHost() . $request->getBasePath() . '/' . $avatarPath . '/' . $avatar;

Controller/ConfigController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Component\HttpFoundation\Request;
1818
use Symfony\Component\Routing\Annotation\Route;
1919
use Zikula\Bundle\CoreBundle\Controller\AbstractController;
20+
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
2021
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
2122
use Zikula\PermissionsModule\Annotation\PermissionCheck;
2223
use Zikula\ProfileModule\Form\Type\ConfigType;
@@ -35,8 +36,11 @@ class ConfigController extends AbstractController
3536
* @Theme("admin")
3637
* @Template("@ZikulaProfileModule/Config/config.html.twig")
3738
*/
38-
public function configAction(Request $request, VariableApiInterface $variableApi): array
39-
{
39+
public function configAction(
40+
Request $request,
41+
ZikulaHttpKernelInterface $kernel,
42+
VariableApiInterface $variableApi
43+
): array {
4044
$modVars = $this->getVars();
4145

4246
$varsInUsersModule = [
@@ -72,8 +76,8 @@ public function configAction(Request $request, VariableApiInterface $variableApi
7276

7377
$pathWarning = '';
7478
if (true === $modVars['allowUploads']) {
75-
$path = $modVars[ProfileConstant::MODVAR_AVATAR_IMAGE_PATH];
76-
if (!(file_exists($path) && is_readable($path))) {
79+
$path = $kernel->getProjectDir() . '/' . $modVars[ProfileConstant::MODVAR_AVATAR_IMAGE_PATH];
80+
if (!file_exists($path) || !is_readable($path)) {
7781
$pathWarning = $this->trans('Warning! The avatar directory does not exist or is not readable for the webserver.');
7882
} elseif (!is_writable($path)) {
7983
$pathWarning = $this->trans('Warning! The webserver cannot write to the avatar directory.');

Form/Type/AvatarType.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
1919
use Symfony\Component\Form\Extension\Core\Type\FileType;
2020
use Symfony\Component\OptionsResolver\OptionsResolver;
21+
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
2122
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
2223
use Zikula\UsersModule\Constant as UsersConstant;
2324

@@ -33,10 +34,12 @@ class AvatarType extends AbstractType
3334
*/
3435
private $avatarPath;
3536

36-
public function __construct(VariableApiInterface $variableApi)
37-
{
37+
public function __construct(
38+
ZikulaHttpKernelInterface $kernel,
39+
VariableApiInterface $variableApi
40+
) {
3841
$this->modVars = $variableApi->getAll('ZikulaProfileModule');
39-
$this->avatarPath = $variableApi->get(UsersConstant::MODNAME, 'avatarpath', 'public/uploads/avatar');
42+
$this->avatarPath = $kernel->getProjectDir() . '/' . $variableApi->get(UsersConstant::MODNAME, 'avatarpath', 'public/uploads/avatar');
4043
}
4144

4245
public function configureOptions(OptionsResolver $resolver)

Menu/ExtensionMenu.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ private function getAdmin(): ?ItemInterface
102102
if ($this->permissionApi->hasPermission($this->getBundleName().'::', '::', ACCESS_ADD)) {
103103
$menu->addChild('Create new property', [
104104
'route' => 'zikulaprofilemodule_property_edit',
105-
])->setAttribute('icon', 'fas fa-plus')
106-
->setLinkAttribute('class', 'text-success');
105+
])->setAttribute('icon', 'fas fa-plus');
107106
}
108107
if ($this->permissionApi->hasPermission($this->getBundleName().'::', '::', ACCESS_ADMIN)) {
109108
$menu->addChild('Settings', [

0 commit comments

Comments
 (0)