1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,135 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-declare(strict_types=1); |
|
4 |
- |
|
5 |
-/* |
|
6 |
- * This file is part of Oveleon ContaoMemberExtension Bundle. |
|
7 |
- * |
|
8 |
- * @package contao-member-extension-bundle |
|
9 |
- * @license MIT |
|
10 |
- * @author Daniele Sciannimanica <https://github.com/doishub> |
|
11 |
- * @author Fabian Ekert <https://github.com/eki89> |
|
12 |
- * @author Sebastian Zoglowek <https://github.com/zoglo> |
|
13 |
- * @copyright Oveleon <https://www.oveleon.de/> |
|
14 |
- */ |
|
15 |
- |
|
16 |
-namespace Oveleon\ContaoMemberExtensionBundle; |
|
17 |
- |
|
18 |
-use Contao\BackendTemplate; |
|
19 |
-use Contao\Config; |
|
20 |
-use Contao\FrontendUser; |
|
21 |
-use Contao\Input; |
|
22 |
-use Contao\MemberModel; |
|
23 |
-use Contao\Module; |
|
24 |
-use Contao\StringUtil; |
|
25 |
-use Contao\System; |
|
26 |
- |
|
27 |
-/** |
|
28 |
- * Class ModuleDeleteAvatar |
|
29 |
- * |
|
30 |
- * @author Sebastian Zoglowek <https://github.com/zoglo> |
|
31 |
- */ |
|
32 |
-class ModuleDeleteAvatar extends Module |
|
33 |
-{ |
|
34 |
- /** |
|
35 |
- * Template. |
|
36 |
- * |
|
37 |
- * @var string |
|
38 |
- */ |
|
39 |
- protected $strTemplate = 'memberExtension_deleteAvatar'; |
|
40 |
- |
|
41 |
- /** |
|
42 |
- * Return a wildcard in the back end |
|
43 |
- * |
|
44 |
- * @return string |
|
45 |
- */ |
|
46 |
- public function generate() |
|
47 |
- { |
|
48 |
- $container = System::getContainer(); |
|
49 |
- |
|
50 |
- $request = System::getContainer()->get('request_stack')->getCurrentRequest(); |
|
51 |
- |
|
52 |
- if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request)) |
|
53 |
- { |
|
54 |
- $objTemplate = new BackendTemplate('be_wildcard'); |
|
55 |
- $objTemplate->wildcard = '### ' . mb_strtoupper($GLOBALS['TL_LANG']['FMD']['deleteAvatar'][0] ?? '', 'UTF-8') . ' ###'; |
|
56 |
- $objTemplate->title = $this->headline; |
|
57 |
- $objTemplate->id = $this->id; |
|
58 |
- $objTemplate->link = $this->name; |
|
59 |
- $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; |
|
60 |
- |
|
61 |
- return $objTemplate->parse(); |
|
62 |
- } |
|
63 |
- |
|
64 |
- // Set the item from the auto_item parameter |
|
65 |
- if (!isset($_GET['items']) && isset($_GET['auto_item']) && Config::get('useAutoItem')) |
|
66 |
- { |
|
67 |
- Input::setGet('items', Input::get('auto_item')); |
|
68 |
- } |
|
69 |
- |
|
70 |
- // Return if there is no logged-in user |
|
71 |
- if (!$container->get('contao.security.token_checker')->hasFrontendUser()) |
|
72 |
- { |
|
73 |
- return ''; |
|
74 |
- } |
|
75 |
- |
|
76 |
- $this->import(FrontendUser::class, 'User'); |
|
77 |
- $objMember = MemberModel::findByPk($this->User->id); |
|
78 |
- |
|
79 |
- if(null === $objMember) |
|
80 |
- { |
|
81 |
- return ''; |
|
82 |
- } |
|
83 |
- |
|
84 |
- // Confirmation message |
|
85 |
- $session = System::getContainer()->get('session'); |
|
86 |
- $flashBag = $session->getFlashBag(); |
|
87 |
- |
|
88 |
- // Return if there is no flashbag message or an avatar |
|
89 |
- if (!($session->isStarted() && $flashBag->has('mod_avatar_deleted')) && !$objMember->avatar) |
|
90 |
- { |
|
91 |
- return ''; |
|
92 |
- } |
|
93 |
- |
|
94 |
- return parent::generate(); |
|
95 |
- } |
|
96 |
- |
|
97 |
- /** |
|
98 |
- * Generate the module |
|
99 |
- */ |
|
100 |
- protected function compile() |
|
101 |
- { |
|
102 |
- $strFormId = 'deleteAvatar_' . $this->id; |
|
103 |
- $session = System::getContainer()->get('session'); |
|
104 |
- $flashBag = $session->getFlashBag(); |
|
105 |
- |
|
106 |
- // Get form submit |
|
107 |
- if (Input::post('FORM_SUBMIT') == $strFormId) |
|
108 |
- { |
|
109 |
- $this->import(FrontendUser::class, 'User'); |
|
110 |
- $objMember = MemberModel::findByPk($this->User->id); |
|
111 |
- |
|
112 |
- // Delete avatar if it exists |
|
113 |
- if(!!$objMember->avatar) |
|
114 |
- { |
|
115 |
- Member::deleteAvatar($objMember); |
|
116 |
- // Unset avatar |
|
117 |
- $objMember->avatar = null; |
|
118 |
- $objMember->save(); |
|
119 |
- |
|
120 |
- // Set message for deletion feedback |
|
121 |
- $flashBag->set('mod_avatar_deleted', $GLOBALS['TL_LANG']['MSC']['avatarDeleted']); |
|
122 |
- $this->reload(); |
|
123 |
- } |
|
124 |
- } |
|
125 |
- |
|
126 |
- // Confirmation message |
|
127 |
- if($session->isStarted() && $flashBag->has('mod_avatar_deleted')) { |
|
128 |
- $arrMessages = $flashBag->get('mod_avatar_deleted'); |
|
129 |
- $this->Template->message = $arrMessages[0]; |
|
130 |
- } |
|
131 |
- |
|
132 |
- $this->Template->formId = $strFormId; |
|
133 |
- $this->Template->slabel = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['deleteAvatar']); |
|
134 |
- } |
|
135 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,135 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+declare(strict_types=1); |
|
4 |
+ |
|
5 |
+/* |
|
6 |
+ * This file is part of Oveleon ContaoMemberExtension Bundle. |
|
7 |
+ * |
|
8 |
+ * @package contao-member-extension-bundle |
|
9 |
+ * @license MIT |
|
10 |
+ * @author Daniele Sciannimanica <https://github.com/doishub> |
|
11 |
+ * @author Fabian Ekert <https://github.com/eki89> |
|
12 |
+ * @author Sebastian Zoglowek <https://github.com/zoglo> |
|
13 |
+ * @copyright Oveleon <https://www.oveleon.de/> |
|
14 |
+ */ |
|
15 |
+ |
|
16 |
+namespace Oveleon\ContaoMemberExtensionBundle; |
|
17 |
+ |
|
18 |
+use Contao\BackendTemplate; |
|
19 |
+use Contao\Config; |
|
20 |
+use Contao\FrontendUser; |
|
21 |
+use Contao\Input; |
|
22 |
+use Contao\MemberModel; |
|
23 |
+use Contao\Module; |
|
24 |
+use Contao\StringUtil; |
|
25 |
+use Contao\System; |
|
26 |
+ |
|
27 |
+/** |
|
28 |
+ * Class ModuleDeleteAvatar |
|
29 |
+ * |
|
30 |
+ * @author Sebastian Zoglowek <https://github.com/zoglo> |
|
31 |
+ */ |
|
32 |
+class ModuleDeleteAvatar extends Module |
|
33 |
+{ |
|
34 |
+ /** |
|
35 |
+ * Template. |
|
36 |
+ * |
|
37 |
+ * @var string |
|
38 |
+ */ |
|
39 |
+ protected $strTemplate = 'memberExtension_deleteAvatar'; |
|
40 |
+ |
|
41 |
+ /** |
|
42 |
+ * Return a wildcard in the back end |
|
43 |
+ * |
|
44 |
+ * @return string |
|
45 |
+ */ |
|
46 |
+ public function generate() |
|
47 |
+ { |
|
48 |
+ $container = System::getContainer(); |
|
49 |
+ |
|
50 |
+ $request = System::getContainer()->get('request_stack')->getCurrentRequest(); |
|
51 |
+ |
|
52 |
+ if ($request && System::getContainer()->get('contao.routing.scope_matcher')->isBackendRequest($request)) |
|
53 |
+ { |
|
54 |
+ $objTemplate = new BackendTemplate('be_wildcard'); |
|
55 |
+ $objTemplate->wildcard = '### ' . mb_strtoupper($GLOBALS['TL_LANG']['FMD']['deleteAvatar'][0] ?? '', 'UTF-8') . ' ###'; |
|
56 |
+ $objTemplate->title = $this->headline; |
|
57 |
+ $objTemplate->id = $this->id; |
|
58 |
+ $objTemplate->link = $this->name; |
|
59 |
+ $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; |
|
60 |
+ |
|
61 |
+ return $objTemplate->parse(); |
|
62 |
+ } |
|
63 |
+ |
|
64 |
+ // Set the item from the auto_item parameter |
|
65 |
+ if (!isset($_GET['items']) && isset($_GET['auto_item']) && Config::get('useAutoItem')) |
|
66 |
+ { |
|
67 |
+ Input::setGet('items', Input::get('auto_item')); |
|
68 |
+ } |
|
69 |
+ |
|
70 |
+ // Return if there is no logged-in user |
|
71 |
+ if (!$container->get('contao.security.token_checker')->hasFrontendUser()) |
|
72 |
+ { |
|
73 |
+ return ''; |
|
74 |
+ } |
|
75 |
+ |
|
76 |
+ $this->import(FrontendUser::class, 'User'); |
|
77 |
+ $objMember = MemberModel::findByPk($this->User->id); |
|
78 |
+ |
|
79 |
+ if(null === $objMember) |
|
80 |
+ { |
|
81 |
+ return ''; |
|
82 |
+ } |
|
83 |
+ |
|
84 |
+ // Confirmation message |
|
85 |
+ $session = System::getContainer()->get('session'); |
|
86 |
+ $flashBag = $session->getFlashBag(); |
|
87 |
+ |
|
88 |
+ // Return if there is no flashbag message or an avatar |
|
89 |
+ if (!($session->isStarted() && $flashBag->has('mod_avatar_deleted')) && !$objMember->avatar) |
|
90 |
+ { |
|
91 |
+ return ''; |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ return parent::generate(); |
|
95 |
+ } |
|
96 |
+ |
|
97 |
+ /** |
|
98 |
+ * Generate the module |
|
99 |
+ */ |
|
100 |
+ protected function compile() |
|
101 |
+ { |
|
102 |
+ $strFormId = 'deleteAvatar_' . $this->id; |
|
103 |
+ $session = System::getContainer()->get('session'); |
|
104 |
+ $flashBag = $session->getFlashBag(); |
|
105 |
+ |
|
106 |
+ // Get form submit |
|
107 |
+ if (Input::post('FORM_SUBMIT') == $strFormId) |
|
108 |
+ { |
|
109 |
+ $this->import(FrontendUser::class, 'User'); |
|
110 |
+ $objMember = MemberModel::findByPk($this->User->id); |
|
111 |
+ |
|
112 |
+ // Delete avatar if it exists |
|
113 |
+ if(!!$objMember->avatar) |
|
114 |
+ { |
|
115 |
+ Member::deleteAvatar($objMember); |
|
116 |
+ // Unset avatar |
|
117 |
+ $objMember->avatar = null; |
|
118 |
+ $objMember->save(); |
|
119 |
+ |
|
120 |
+ // Set message for deletion feedback |
|
121 |
+ $flashBag->set('mod_avatar_deleted', $GLOBALS['TL_LANG']['MSC']['avatarDeleted']); |
|
122 |
+ $this->reload(); |
|
123 |
+ } |
|
124 |
+ } |
|
125 |
+ |
|
126 |
+ // Confirmation message |
|
127 |
+ if($session->isStarted() && $flashBag->has('mod_avatar_deleted')) { |
|
128 |
+ $arrMessages = $flashBag->get('mod_avatar_deleted'); |
|
129 |
+ $this->Template->message = $arrMessages[0]; |
|
130 |
+ } |
|
131 |
+ |
|
132 |
+ $this->Template->formId = $strFormId; |
|
133 |
+ $this->Template->slabel = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['deleteAvatar']); |
|
134 |
+ } |
|
135 |
+} |