Skip to content

Commit

Permalink
Merge pull request #13 from oveleon/develop
Browse files Browse the repository at this point in the history
Drop 4.9 Support and other changes
  • Loading branch information
zoglo authored Jan 15, 2023
2 parents 0060055 + d8dfda1 commit d96aaaf
Show file tree
Hide file tree
Showing 39 changed files with 345 additions and 394 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

---

> Working with **Contao 4.9** and up to **Contao 4.13** (PHP ^7.4 and PHP 8)
> Working with **Contao 4.13** (PHP ^8.0)
---

Expand All @@ -20,7 +20,7 @@ Additionally, you can display members with their details in a reader page.

+ [Features](#features)
+ [Installation](#installation)
+ [Upgrading](#upgrading-to-version-12)
+ [Upgrading (v.1.1 to >=v.1.2)](#upgrading-to-version--12)
+ [Composer](#via-composer)
+ [Contao Manager](#via-contao-manager)
+ [Initial Setup](#initial-setup)
Expand All @@ -36,7 +36,7 @@ Additionally, you can display members with their details in a reader page.

## Features

- Compatible with Contao 4.9 and higher versions (PHP 8 Support)
- Compatible with Contao 4.13 (PHP ^8.0)
- Extends members with avatars
- Paginated member lists
- Member detail pages
Expand All @@ -46,8 +46,8 @@ Additionally, you can display members with their details in a reader page.

## Installation

#### Upgrading to version 1.2
> After upgrading from version 1.1 to version 1.2, make sure to edit your modules (memberlist, memberreader and avatar/profile picture) and set up the new templates.
#### Upgrading to version >=1.2
> After upgrading from version 1.1 to version >=1.2, make sure to edit your modules (memberlist, memberreader and avatar/profile picture) and set up the new templates.
#### Via composer
```
Expand All @@ -72,7 +72,7 @@ detail pages.
![Admin View: Member overview](https://www.oveleon.de/share/github-assets/contao-member-extension-bundle/default_avatar.jpg)
![Admin View: Member settings](https://www.oveleon.de/share/github-assets/contao-member-extension-bundle/default_avatar_setup.jpg)

2. To display your members, you need to setup a memberlist
2. To display your members, you need to set up a memberlist
1. Create the front end module *memberlist*
2. Choose the member groups and the member fields that should be displayed
3. Optionally you can set up a redirect page to your memberreader
Expand Down
48 changes: 19 additions & 29 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
"name": "oveleon/contao-member-extension-bundle",
"type": "contao-bundle",
"description": "Member feature extension for Contao.",
"license": "MIT",
"keywords": ["contao","member-extension-bundle"],
"homepage": "https://oveleon.de/",
"license": "MIT",
"authors": [
{
"name": "Oveleon",
"homepage": "https://oveleon.de/",
"name": "Sebastian Zoglowek",
"homepage": "https://github.com/zoglo",
"role": "Developer"
},
{
Expand All @@ -20,16 +20,11 @@
"name": "Fabian Ekert",
"homepage": "https://github.com/eki89",
"role": "Developer"
},
{
"name": "Sebastian Zoglowek",
"homepage": "https://github.com/zoglo",
"role": "Developer"
}
],
"require": {
"php": "^7.4 || ^8.0",
"contao/core-bundle":"^4.9"
"php": "^8.0",
"contao/core-bundle": "^4.13"
},
"require-dev": {
"contao/manager-plugin": "^2.3.1"
Expand All @@ -38,33 +33,28 @@
"contao/core": "*",
"contao/manager-plugin": "<2.0 || >=3.0"
},
"extra": {
"branch-alias": {
"dev-master": "1.3.x-dev"
},
"contao-manager-plugin": "Oveleon\\ContaoMemberExtensionBundle\\ContaoManager\\Plugin"
},
"autoload": {
"psr-4": {
"Oveleon\\ContaoMemberExtensionBundle\\": "src/"
},
"classmap": [
"src/Resources/contao/"
"contao/"
],
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
"contao/config/",
"contao/dca/",
"contao/languages/",
"contao/templates/"
]
},
"extra": {
"branch-alias": {
"dev-master": "1.2.x-dev"
},
"contao-manager-plugin": "Oveleon\\ContaoMemberExtensionBundle\\ContaoManager\\Plugin"
},
"config": {
"allow-plugins": {
"contao-components/installer": true,
"contao/manager-plugin": true
}
},
"support": {
"issues": "https://github.com/oveleon/contao-member-extension-bundle/issues"
"issues": "https://github.com/oveleon/contao-member-extension-bundle/issues",
"source": "https://github.com/oveleon/contao-member-extension-bundle"
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
*
* @package contao-member-extension-bundle
* @license MIT
* @author Daniele Sciannimanica <https://github.com/doishub>
* @author Fabian Ekert <https://github.com/eki89>
* @author Sebastian Zoglowek <https://github.com/zoglo>
* @copyright Oveleon <https://www.oveleon.de/>
* @author Sebastian Zoglowek <https://github.com/zoglo>
* @author Daniele Sciannimanica <https://github.com/doishub>
* @author Fabian Ekert <https://github.com/eki89>
* @copyright Oveleon <https://www.oveleon.de/>
*/

namespace Oveleon\ContaoMemberExtensionBundle;
Expand All @@ -29,7 +29,6 @@
use Contao\Validator;
use Psr\Log\LogLevel;


/**
* Class Member
*
Expand All @@ -41,18 +40,11 @@ class Member extends Frontend

/**
* MemberAvatar file name
*
* @var string
*/
protected $avatarName = 'memberAvatar';
protected string $avatarName = 'memberAvatar';

/**
* Create avatar for a member | Registration
*
* @param int $userId
* @param array $arrData
*
* @return void
*/
public function createAvatar(int $userId, array $arrData): void
{
Expand All @@ -62,25 +54,15 @@ public function createAvatar(int $userId, array $arrData): void

/**
* Update avatar of a member | Login
*
* @param FrontendUser $objUser
* @param array $arrData
*
* @return void
*/
public function updateAvatar(FrontendUser $objUser, $arrData): void
public function updateAvatar(FrontendUser $objUser, array $arrData): void
{
$objMember = MemberModel::findById($objUser->id);
$this->processAvatar($objMember, $arrData);
}

/**
* Process avatar upload for a member
*
* @param MemberModel $objMember
* @param array $arrData
*
* @return void
*/
protected function processAvatar(MemberModel $objMember, ?array $arrData): void
{
Expand All @@ -91,6 +73,7 @@ protected function processAvatar(MemberModel $objMember, ?array $arrData): void
return;
}

// ToDo: remove $_SESSION when contao 4.13 support ends (Contao ^5.* is not possible with Contao 4.* support)
$file = $_SESSION['FILES']['avatar'];
$maxlength_kb = $this->getMaximumUploadSize();
$maxlength_kb_readable = $this->getReadableSize($maxlength_kb);
Expand Down Expand Up @@ -136,7 +119,7 @@ protected function processAvatar(MemberModel $objMember, ?array $arrData): void
}

$objFile = new File($file['name']);
$uploadTypes = StringUtil::trimsplit(',', \Config::get('validImageTypes'));
$uploadTypes = StringUtil::trimsplit(',', Config::get('validImageTypes'));

// File type is not allowed
if (!\in_array($objFile->extension, $uploadTypes))
Expand Down Expand Up @@ -173,6 +156,7 @@ protected function processAvatar(MemberModel $objMember, ?array $arrData): void
// Upload valid file type with no width and height -> svg

// Don't upload if no homedir is assigned
// ToDo: Create homedir?
if (!$objMember->assignDir || !$objMember->homeDir)
{
// ToDo: add error message for no homedir
Expand All @@ -186,7 +170,7 @@ protected function processAvatar(MemberModel $objMember, ?array $arrData): void
// The upload folder could not be found
if ($objUploadFolder === null)
{
throw new \Exception("Invalid upload folder ID $intUploadFolder");
throw new Exception("Invalid upload folder ID $intUploadFolder");
}

$strUploadFolder = $objUploadFolder->path;
Expand Down Expand Up @@ -246,16 +230,14 @@ protected function processAvatar(MemberModel $objMember, ?array $arrData): void

// Add a log entry
$logger = System::getContainer()->get('monolog.logger.contao');
$logger->log(LogLevel::INFO, 'File "' . $strUploadFolder . '/' . $file['name'] . '" has been uploaded', array('contao' => new ContaoContext(__METHOD__, TL_FILES)));
$logger->log(LogLevel::INFO, 'File "' . $strUploadFolder . '/' . $file['name'] . '" has been uploaded', ['contao' => new ContaoContext(__METHOD__, TL_FILES)]);
}

unset($_SESSION['FILES']['avatar']);
}

/**
* Return the maximum upload file size in bytes
*
* @return string
*/
protected function getMaximumUploadSize()
{
Expand All @@ -269,13 +251,8 @@ protected function getMaximumUploadSize()

/**
* Parses an avatar to the template
*
* @param MemberModel|null $objMember
* @param $objTemplate
* @param $strImgSize
* @return void
*/
public static function parseMemberAvatar(?MemberModel $objMember, &$objTemplate, $strImgSize)
public static function parseMemberAvatar(?MemberModel $objMember, &$objTemplate, ?string $imgSize): void
{
$objTemplate->addImage= true;

Expand All @@ -285,7 +262,7 @@ public static function parseMemberAvatar(?MemberModel $objMember, &$objTemplate,
$projectDir = System::getContainer()->getParameter('kernel.project_dir');

// Check if member avatar exists
if(null === $objMember || null === $objMember->avatar || null === ($objFile = FilesModel::findByUuid($objMember->avatar)) || !\is_file($projectDir.'/'.$objFile->path))
if (null === $objMember || null === $objMember->avatar || null === ($objFile = FilesModel::findByUuid($objMember->avatar)) || !\is_file($projectDir.'/'. $objFile->path))
{
$objFile = !!($uuidDefault = Config::get('defaultAvatar')) ? FilesModel::findByUuid($uuidDefault) : null;
}
Expand All @@ -297,24 +274,30 @@ public static function parseMemberAvatar(?MemberModel $objMember, &$objTemplate,
}

$objTemplate->addFallbackImage = false;
$arrData = ['singleSRC'=>$objFile->path, 'size'=>$strImgSize];
$imgSize = $imgSize ?? null;

$figureBuilder = System::getContainer()
->get('contao.image.studio')
->createFigureBuilder()
->from($objFile->path)
->setSize($imgSize)
;

//ToDo: Change to FigureBuilder in the future
$objTemplate->addImageToTemplate($objTemplate, $arrData, null, null, $objFile);
if (null !== ($figure = $figureBuilder->buildIfResourceExists()))
{
$figure->applyLegacyTemplateData($objTemplate);
}
}

/**
* Gets the url for a member avatar
*
* @param MemberModel|null $objMember
* @return string
*/
public static function getMemberAvatarURL(?MemberModel $objMember): string
{
// ToDo: Merge logic with parseMemberAvatar
$projectDir = System::getContainer()->getParameter('kernel.project_dir');

if(null === $objMember || null === $objMember->avatar || null === ($objFile = FilesModel::findByUuid($objMember->avatar)) || !\is_file($projectDir.'/'. $objFile->path))
if (null === $objMember || null === $objMember->avatar || null === ($objFile = FilesModel::findByUuid($objMember->avatar)) || !\is_file($projectDir.'/'. $objFile->path))
{
$objFile = !!($uuidDefault = Config::get('defaultAvatar')) ? FilesModel::findByUuid($uuidDefault) : null;
}
Expand All @@ -329,13 +312,11 @@ public static function getMemberAvatarURL(?MemberModel $objMember): string
}

/**
* @param MemberModel $objMember
*
* @return void
* Deletes an avatar
*/
public static function deleteAvatar(MemberModel $objMember): void
{
if(!!$objMember->avatar)
if (!!$objMember->avatar)
{
$objFile = FilesModel::findByUuid($objMember->avatar) ?: '';
$projectDir = System::getContainer()->getParameter('kernel.project_dir');
Expand Down
34 changes: 34 additions & 0 deletions contao/config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

/*
* This file is part of Oveleon ContaoMemberExtension Bundle.
*
* @package contao-member-extension-bundle
* @license MIT
* @author Sebastian Zoglowek <https://github.com/zoglo>
* @author Daniele Sciannimanica <https://github.com/doishub>
* @author Fabian Ekert <https://github.com/eki89>
* @copyright Oveleon <https://www.oveleon.de/>
*/

// Back end modules
use Contao\ArrayUtil;

$GLOBALS['BE_MOD']['system']['member_settings'] = [
'tables' => ['tl_member_settings'],
'hideInNavigation' => true,
];

// Front end modules
ArrayUtil::arrayInsert($GLOBALS['FE_MOD']['user'], -1, [
'avatar' => 'Oveleon\ContaoMemberExtensionBundle\ModuleAvatar',
'deleteAvatar' => 'Oveleon\ContaoMemberExtensionBundle\ModuleDeleteAvatar',
'memberList' => 'Oveleon\ContaoMemberExtensionBundle\ModuleMemberList',
'memberReader' => 'Oveleon\ContaoMemberExtensionBundle\ModuleMemberReader'
]);

// Register hooks
$GLOBALS['TL_HOOKS']['createNewUser'][] = ['Oveleon\ContaoMemberExtensionBundle\Member', 'createAvatar'];
$GLOBALS['TL_HOOKS']['updatePersonalData'][] = ['Oveleon\ContaoMemberExtensionBundle\Member', 'updateAvatar'];
Loading

0 comments on commit d96aaaf

Please sign in to comment.