-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact_class.php
196 lines (156 loc) · 5.01 KB
/
contact_class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/*
* e107 website system
*
* Copyright (C) 2008-2025 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* #######################################
* # e107 contact plugin #
* # by Jimako #
* # https://www.e107sk.com #
* #######################################
*/
class econtact
{
/**
* Plugin Preferences
* contact::prefs['xy'];
*/
private static $contactPrefs = [];
/**
* Class construcotr
*/
function __construct()
{
$this->setProperties();
}
/**
* Define the required plugin properties
*
* @return void
*/
public function setProperties()
{
$contactPrefs = e107::pref('econtact');
if (empty($contactPrefs))
{
$user = e107::getUser();
// Kontrola, či je používateľ prihlásený ako hlavný administrátor alebo admin pluginu
if ($user->isAdmin() || $user->checkAdminPerms('econtact'))
{
// Zobrazenie chybovej správy, ak ide o hlavného admina alebo plugin admina
e107::getMessage()->addError("Správa pre administrátor: skontrolujte nastavenie pluginu");
echo e107::getMessage()->render(); // Zobrazí správu na stránke
$contactPrefs['contact_pages']['activate']['contact'] = 1;
$contactPrefs['contact_pages']['activate']['report'] = 1;
$contactPrefs['contact_pages']['contactform']['contact'] = 0;
$contactPrefs['contact_pages']['contactform']['report'] = 0;
$contactPrefs['contact_pages']['contactinfo']['contact'] = 1;
$contactPrefs['contact_pages']['contactinfo']['report'] = 1;
}
else
{
// Presmerovanie na úvodnú stránku, ak nie je prihlásený admin
e107::redirect(e107::url('home', ''));
}
}
else
{
$contactPrefs['contact_pages'] = e107::unserialize($contactPrefs['contact_pages']);
}
self::$contactPrefs = $contactPrefs;
}
public function setContactLayouts($page = "contact")
{
// Check if the specified page layout exists and is greater than zero
$layoutId = self::$contactPrefs['contact_pages']['themelayout'][$page] ?? null;
if (!empty($layoutId))
{
// Define the layout constant if a valid layout ID is found
define('THEME_LAYOUT', $layoutId);
}
var_dump(THEME_LAYOUT);
}
public function setRedirection($page = "contact")
{
// Check if the specified page key exists
if (
!array_key_exists($page, self::$contactPrefs['contact_pages']['activate'])
|| self::$contactPrefs['contact_pages']['activate'][$page] <= 0
)
{
// Redirect to the homepage if the page is not activated or doesn't exist
e107::redirect(); // homepage
}
}
public function renderContactForm($page = "contact")
{
// check if form is allowed to render, don't display form without owner control
if (!array_key_exists($page, self::$contactPrefs['contact_pages']['contactform']))
{
return '';
}
$active = self::$contactPrefs['contact_pages']['contactform'][$page];
if (!check_class($active))
{
if ($active == e_UC_MEMBER)
{
//render message
return $this->renderSignupRequired();
}
}
else
{
$CONTACT_FORM = e107::getTemplate('econtact', $page, 'form');
$contact_shortcodes = e107::getScBatch('form', 'econtact', false);
$contact_shortcodes->wrapper($page . '/form');
$text = e107::getParser()->parseTemplate($CONTACT_FORM, true, $contact_shortcodes);
if (trim($text) !== '')
{
return e107::getRender()->tablerender(LAN_CONTACT_02, $text, "contact-form", true);
}
}
}
public function renderContactInfo($page = "contact")
{
// check if form is allowed to render, don't display form without owner control
if (!array_key_exists($page, self::$contactPrefs['contact_pages']['contactinfo']))
{
return '';
}
$active = self::$contactPrefs['contact_pages']['contactform'][$page];
if (!check_class($active))
{
if ($active == e_UC_MEMBER)
{
//render message
return $this->renderSignupRequired();
}
}
else
{
$CONTACT_INFO = e107::getTemplate('econtact', 'contact', 'info');
$contact_shortcodes = e107::getScBatch('form', 'econtact', false);
$contact_shortcodes->wrapper('contact/info');
$text = e107::getParser()->parseTemplate($CONTACT_INFO, true, $contact_shortcodes);
return e107::getRender()->tablerender(LAN_CONTACT_01, $text, "contact-info", true);
}
}
public function renderSignupRequired()
{
$srch = array("[", "]");
$repl = array("<a class='alert-link' href='" . e_SIGNUP . "'>", "</a>");
$message = LAN_CONTACT_16; // "You must be [registered] and signed-in to use this form.";
$text = e107::getRender()->tablerender(LAN_CONTACT_02, "<div class='alert alert-info'>" . str_replace($srch, $repl, $message) . "</div>", "contact", true);
return $text;
}
public function getPageLayout($page = "contact")
{
$LAYOUT = '{---CONTACT-INFO---} {---CONTACT-FORM---} ';
$layout_key = self::$contactPrefs['contact_pages']['contactlayout'][$page];
$LAYOUT = e107::getTemplate('econtact', 'contact_layout', $layout_key);
return $LAYOUT;
}
}