-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpoly_blank_module.php
More file actions
202 lines (172 loc) · 9.45 KB
/
poly_blank_module.php
File metadata and controls
202 lines (172 loc) · 9.45 KB
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
197
198
199
200
201
202
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/*
Module Name: Poly Blank Module
Description: Sample module template with basic hooks, filters, classes, and methods for creating a module for PerfexCRM.
Version: 1.0.0
Requires at least: 3.0.0
Author: PolyXGO
Author URI: https://codecanyon.net/user/polyxgo
*/
define('POLY_BLANK_MODULE', 'poly_blank_module');
define('POLY_BLANK_MODULE_SETTINGS_TAB', 'settings_tab');
define('POLY_BLANK_MODULE_VERSION', '1.0.0');
define('POLY_BLANK_MODULE_NAME', 'Poly Blank Module');
class POLYBLANKMODULE
{
private $CI;
private $settings;
private $staff_id;
public function __construct()
{
$this->CI = &get_instance();
$this->staff_id = get_staff_user_id();
register_activation_hook(POLY_BLANK_MODULE, array($this, 'register_activation_hook'));
register_deactivation_hook(POLY_BLANK_MODULE, array($this, 'register_deactivation_hook'));
// Load the list of shared helper libraries.
$this->CI->load->helper(POLY_BLANK_MODULE . '/poly_blank_module_common');
// Register menu items and assign menu items permissions.
hooks()->add_action('admin_init', [$this, 'init_menu_items']);
/**
* Register language files, must be registered if the module is using languages
*/
register_language_files(POLY_BLANK_MODULE, [POLY_BLANK_MODULE]);
/**
* Admin | Customers | Both => scripts, styles.
*/
hooks()->add_action('app_admin_head', [$this, 'scripts_styles_admin_staff_head']); // Admin header
hooks()->add_action('app_admin_footer', [$this, 'scripts_styles_admin_staff_footer']); // Admin footer
hooks()->add_action('app_customers_head', [$this, 'scripts_styles_clients_customers_head']); // Clients header
hooks()->add_action('app_customers_footer', [$this, 'scripts_styles_clients_customers_footer']); // Clients footer
//Page login
hooks()->add_action('app_admin_authentication_head', [$this, 'admin_authentication_head']); // Admin, Staff header. Footer use `before_admin_login_form_close` & `clients_login_form_end`
hooks()->add_action('after_admin_login_form_start', [$this, 'admin_login_form_head']); // Admin login form header
hooks()->add_action('before_admin_login_form_close', [$this, 'admin_login_form_footer']); // Admin login form footer
hooks()->add_action('clients_login_form_start', [$this, 'clients_customers_login_form_header']); // Clients & Customers login form header
hooks()->add_action('clients_login_form_end', [$this, 'clients_customers_login_form_footer']); // Clients & Customers login form footer
}
public function admin_authentication_head()
{
echo $this->show_block_area("Login_Admin_Staff_HEAD", "hooks()->add_action('app_admin_authentication_head', [\$this, 'your_function_admin_authentication_head']);");
}
public function admin_login_form_head()
{
echo $this->show_block_area('Login_Admin_Staff_Form_HEAD', "hooks()->add_action('after_admin_login_form_start', [\$this, 'your_function_admin_login_form_head']);");
}
public function admin_login_form_footer()
{
echo $this->show_block_area('Login_Admin_Staff_FOOTER', "hooks()->add_action('before_admin_login_form_close', [\$this, 'your_function_admin_login_form_footer']);");
}
public function clients_customers_login_form_head()
{
echo $this->show_block_area('Login_Clients_Form_HEAD', "hooks()->add_action('clients_login_form_start', [\$this, 'your_function_clients_customers_login_form_head']);");
}
public function clients_customers_login_form_footer()
{
echo $this->show_block_area('Login_Clients_Form_FOOTER', "hooks()->add_action('clients_login_form_end', [\$this, 'your_function_clients_customers_login_form_footer']);");
}
//Login admin & staff
public function scripts_styles_admin_staff_head()
{
// Scripts & Styles
echo '<link rel="stylesheet" href="' . poly_blank_module_common_helper::get_assets('css/admin/style.css') . '"/>';
echo '<script src="' . poly_blank_module_common_helper::get_assets('js/public/common.js') . '"></script>';
echo $this->show_block_area('Logged_Amin_HEAD', "hooks()->add_action('app_admin_head', [\$this, 'your_function_scripts_styles_admin_staff_head']);");
}
public function scripts_styles_admin_staff_footer()
{
echo '<script src="' . poly_blank_module_common_helper::get_assets('js/admin/scripts.js') . '"></script>';
echo $this->show_block_area('Logged_Admin_FOOTER', "hooks()->add_action('app_admin_head', [\$this, 'your_function_scripts_styles_admin_staff_head']);");
}
//Login clients/ customers
public function scripts_styles_clients_customers_head()
{
echo $this->show_block_area('LoginLogged_Clients_Customer_HEAD', "hooks()->add_action('app_customers_head', [\$this, 'your_function_scripts_styles_clients_customers_head']);");
}
public function scripts_styles_clients_customers_footer()
{
echo $this->show_block_area('LoginLogged_Clients_Customer_FOOTER', "hooks()->add_action('app_customers_footer', [\$this, 'your_function_scripts_styles_clients_customers_footer']);");
}
public function show_block_area($content, $hook_function = '')
{
return '<div class="poly-hook-area" style="padding: 4px; color: yellow; display: flex; justify-content: center;"><div style="background:red; padding: 4px 8px; text-align: center">' . $content . ' by ' . POLY_BLANK_MODULE . ((!empty($hook_function) ? "<pre>{$hook_function}</pre>" : '')) . '</div></div>';
}
public function register_activation_hook()
{
require_once(__DIR__ . '/install.php');
// Register your module's custom routes into application/config/routes.php via my_routes.php (the file will be created automatically if it doesn't exist. Therefore, ensure write permissions for the application/config directory). Remove or comment out this code if the module does not register routes.
poly_blank_module_common_helper::require_in_file(APPPATH . 'config/my_routes.php', "FCPATH.'modules/" . POLY_BLANK_MODULE . "/config/my_routes.php'");
}
public function register_deactivation_hook()
{
// Unregister your module's custom routes from application/config/routes.php via my_routes.php (the file will be created automatically if it doesn't exist. Therefore, ensure write permissions for the application/config directory). Remove or comment out this code if the module does not register routes.
poly_blank_module_common_helper::unrequire_in_file(APPPATH . 'config/my_routes.php', "FCPATH.'modules/" . POLY_BLANK_MODULE . "/config/my_routes.php'");
}
/**
* Init api module menu items in setup in admin_init hook
* @return null
*/
public function init_menu_items()
{
/**
* If the logged in user is administrator, add custom menu in Setup
*/
if (is_admin()) {
$CI = &get_instance();
$CI->app_menu->add_sidebar_menu_item(POLY_BLANK_MODULE, [
'collapse' => true,
'name' => _l(POLY_BLANK_MODULE),
'position' => 2,
'icon' => 'fa fa-cogs',
]);
$CI->app_menu->add_sidebar_children_item(POLY_BLANK_MODULE, [
'slug' => 'item_test',
'name' => _l(POLY_BLANK_MODULE . '_item_test'),
'href' => admin_url(POLY_BLANK_MODULE . '/item_test'),
'position' => 5,
]);
$CI->app_menu->add_sidebar_children_item(POLY_BLANK_MODULE, [
'slug' => 'settings',
'name' => _l(POLY_BLANK_MODULE . '_settings'),
'href' => admin_url(POLY_BLANK_MODULE . '/settings'),
'position' => 10,
]);
$CI->app_menu->add_sidebar_children_item(POLY_BLANK_MODULE, [
'slug' => POLY_BLANK_MODULE_SETTINGS_TAB,
'name' => _l(POLY_BLANK_MODULE . '_settings_tab'),
'href' => admin_url(POLY_BLANK_MODULE . '/' . POLY_BLANK_MODULE_SETTINGS_TAB),
'position' => 15,
]);
$this->permissions();
}
}
/**
* Initialize module permissions during setup in the admin_init hook.
* @return void
*/
public function permissions()
{
$capabilities = [];
$capabilities['capabilities'] = [
'view' => _l('permission_view')
];
register_staff_capabilities(POLY_BLANK_MODULE, $capabilities, _l(POLY_BLANK_MODULE));
$capabilities = [];
$capabilities['capabilities'] = [
'view' => _l('permission_view'),
'create' => _l('permission_create'),
'edit' => _l('permission_edit'),
'delete' => _l('permission_delete'),
];
register_staff_capabilities(POLY_BLANK_MODULE . '_item_test', $capabilities, _l(POLY_BLANK_MODULE . '_item_test') . ' (' . _l(POLY_BLANK_MODULE) . ')');
$capabilities = [];
$capabilities['capabilities'] = [
'view' => _l('permission_view'),
'create' => _l('permission_create'),
'edit' => _l('permission_edit'),
'delete' => _l('permission_delete'),
];
register_staff_capabilities(POLY_BLANK_MODULE . '_settings', $capabilities, _l(POLY_BLANK_MODULE . '_settings') . ' (' . _l(POLY_BLANK_MODULE) . ')');
}
}
new POLYBLANKMODULE();