-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplugin.php
executable file
·129 lines (110 loc) · 3.81 KB
/
plugin.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
<?php
/**
* Vvveb
*
* Copyright (C) 2023 Ziadin Givan
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
/*
Name: Contact form
Slug: contact-form
Category: email
Url: https://www.vvveb.com
Description: Create contact forms that sends email or saves data in the database
Thumb: contact-form.svg
Author: givanz
Version: 0.1
Author url: https://www.vvveb.com
Settings: /admin/index.php?module=plugins/contact-form/messages
*/
use function Vvveb\__;
use function Vvveb\arrayInsertArrayAfter;
use function Vvveb\model;
use Vvveb\Plugins\ContactForm\Install;
use Vvveb\System\Core\View;
use Vvveb\System\Event;
if (! defined('V_VERSION')) {
die('Invalid request!');
}
#[\AllowDynamicProperties]
class ContactFormPlugin {
function admin() {
// add admin menu item
$admin_path = \Vvveb\adminPath();
// add menu event
Event::on('Vvveb\Controller\Base', 'init-menu', __CLASS__, function ($menu) use ($admin_path) {
// get number of unread messages
$message = model('Plugins\ContactForm\Message');
$status = $message->getStatusCount(['status' => 0]);
$unread = $status['count'] ?? 0;
// add menu entry under plugins submenu
$menu['plugins']['items']['contact-form'] = [
'name' => __('Contact form'),
'url' => $admin_path . 'index.php?module=plugins/contact-form/messages',
'icon-img' => PUBLIC_PATH . 'plugins/contact-form/contact-form.svg',
'module' => 'plugins/contact-form/messages',
'action' => 'index',
];
// add shortcut to messages page to top level menu
$menuEntry = [
'name' => __('Messages'),
'url' => $admin_path . 'index.php?module=plugins/contact-form/messages',
'icon' => $unread ? 'icon-mail-unread-outline' : 'icon-mail-outline',
'module' => 'plugins/contact-form/messages',
'action' => 'index',
];
// if unread messages add notification with number of messages to the menu entry
if ($unread) {
$menuEntry['badge'] = $unread;
$menuEntry['badge-class'] = 'badge bg-success-subtle text-body mx-2';
}
$menu = arrayInsertArrayAfter('users', $menu, ['messages' => $menuEntry]);
return [$menu];
});
// include plugin component when the page builder loads
Event::on('Vvveb\Controller\Editor\Editor', 'loadThemeAssets', __CLASS__, function ($inputs, $components, $blocks, $sections) {
$components['contact-form'] = '../../plugins/contact-form/editor/components.js';
return [$inputs, $components, $blocks, $sections];
});
// when plugin is installed first time run install and create tables if not created
Event::on('Vvveb\System\Extensions\Plugins', 'setup', __CLASS__, function ($pluginName, $siteId) {
if ($pluginName == 'contact-form') {
$this->install();
}
return [$pluginName, $siteId];
});
}
function install() {
$install = new Install();
$install->run();
}
function app() {
// include code contact forms to preserve input values on form submit
$this->view = View::getInstance();
$template = $this->view->getTemplateEngineInstance();
$template->loadTemplateFile(__DIR__ . '/app/template/contact-form.tpl');
}
function __construct() {
if (APP == 'admin') {
$this->admin();
} else {
if (APP == 'app') {
$this->app();
}
}
}
}
$contactFormPlugin = new ContactFormPlugin();