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

Commit

Permalink
fixed avatar image path determination
Browse files Browse the repository at this point in the history
  • Loading branch information
Guite committed May 31, 2020
1 parent eab3353 commit 7b6ad9e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
10 changes: 9 additions & 1 deletion Bridge/ProfileModuleBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use InvalidArgumentException;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\RouterInterface;
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
use Zikula\ProfileModule\Helper\GravatarHelper;
use Zikula\ProfileModule\ProfileConstant;
Expand All @@ -27,6 +28,11 @@

class ProfileModuleBridge implements ProfileModuleInterface
{
/**
* @var ZikulaHttpKernelInterface
*/
private $kernel;

/**
* @var RouterInterface
*/
Expand Down Expand Up @@ -63,6 +69,7 @@ class ProfileModuleBridge implements ProfileModuleInterface
private $prefix;

public function __construct(
ZikulaHttpKernelInterface $kernel,

This comment has been minimized.

Copy link
@craigh

craigh May 31, 2020

Member

again - if the project_dir is all that is needed, inject only this.

This comment has been minimized.

Copy link
@Guite

Guite May 31, 2020

Author Member

changed in dfee228

RouterInterface $router,
RequestStack $requestStack,
VariableApiInterface $variableApi,
Expand All @@ -71,6 +78,7 @@ public function __construct(
GravatarHelper $gravatarHelper,
$prefix
) {
$this->kernel = $kernel;
$this->router = $router;
$this->requestStack = $requestStack;
$this->variableApi = $variableApi;
Expand Down Expand Up @@ -122,7 +130,7 @@ public function getAvatar($uid = null, array $parameters = []): string

$avatarUrl = '';
if (!in_array($avatar, ['blank.gif', 'blank.jpg'], true)) {
if (isset($avatar) && !empty($avatar) && $avatar !== $gravatarImage && file_exists($avatarPath . '/' . $avatar)) {
if (isset($avatar) && !empty($avatar) && $avatar !== $gravatarImage && file_exists($this->kernel->getProjectDir() . '/' . $avatarPath . '/' . $avatar)) {
$request = $this->requestStack->getCurrentRequest();
if (null !== $request) {
$avatarUrl = $request->getSchemeAndHttpHost() . $request->getBasePath() . '/' . $avatarPath . '/' . $avatar;
Expand Down
12 changes: 8 additions & 4 deletions Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Zikula\Bundle\CoreBundle\Controller\AbstractController;
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
use Zikula\PermissionsModule\Annotation\PermissionCheck;
use Zikula\ProfileModule\Form\Type\ConfigType;
Expand All @@ -35,8 +36,11 @@ class ConfigController extends AbstractController
* @Theme("admin")
* @Template("@ZikulaProfileModule/Config/config.html.twig")
*/
public function configAction(Request $request, VariableApiInterface $variableApi): array
{
public function configAction(
Request $request,
ZikulaHttpKernelInterface $kernel,
VariableApiInterface $variableApi
): array {
$modVars = $this->getVars();

$varsInUsersModule = [
Expand Down Expand Up @@ -72,8 +76,8 @@ public function configAction(Request $request, VariableApiInterface $variableApi

$pathWarning = '';
if (true === $modVars['allowUploads']) {
$path = $modVars[ProfileConstant::MODVAR_AVATAR_IMAGE_PATH];
if (!(file_exists($path) && is_readable($path))) {
$path = $kernel->getProjectDir() . '/' . $modVars[ProfileConstant::MODVAR_AVATAR_IMAGE_PATH];
if (!file_exists($path) || !is_readable($path)) {
$pathWarning = $this->trans('Warning! The avatar directory does not exist or is not readable for the webserver.');
} elseif (!is_writable($path)) {
$pathWarning = $this->trans('Warning! The webserver cannot write to the avatar directory.');
Expand Down
9 changes: 6 additions & 3 deletions Form/Type/AvatarType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Zikula\Bundle\CoreBundle\HttpKernel\ZikulaHttpKernelInterface;
use Zikula\ExtensionsModule\Api\ApiInterface\VariableApiInterface;
use Zikula\UsersModule\Constant as UsersConstant;

Expand All @@ -33,10 +34,12 @@ class AvatarType extends AbstractType
*/
private $avatarPath;

public function __construct(VariableApiInterface $variableApi)
{
public function __construct(
ZikulaHttpKernelInterface $kernel,
VariableApiInterface $variableApi
) {
$this->modVars = $variableApi->getAll('ZikulaProfileModule');
$this->avatarPath = $variableApi->get(UsersConstant::MODNAME, 'avatarpath', 'public/uploads/avatar');
$this->avatarPath = $kernel->getProjectDir() . '/' . $variableApi->get(UsersConstant::MODNAME, 'avatarpath', 'public/uploads/avatar');
}

public function configureOptions(OptionsResolver $resolver)
Expand Down
3 changes: 1 addition & 2 deletions Menu/ExtensionMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ private function getAdmin(): ?ItemInterface
if ($this->permissionApi->hasPermission($this->getBundleName().'::', '::', ACCESS_ADD)) {
$menu->addChild('Create new property', [
'route' => 'zikulaprofilemodule_property_edit',
])->setAttribute('icon', 'fas fa-plus')
->setLinkAttribute('class', 'text-success');
])->setAttribute('icon', 'fas fa-plus');
}
if ($this->permissionApi->hasPermission($this->getBundleName().'::', '::', ACCESS_ADMIN)) {
$menu->addChild('Settings', [
Expand Down

0 comments on commit 7b6ad9e

Please sign in to comment.