-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.ao_admin.php
308 lines (224 loc) · 10.7 KB
/
class.ao_admin.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
<?php
class AOAdmin {
public static $default_categories = [
'ao-gallery' => 'AO Gallery',
'ao-document' => 'AO Document',
'ao-media' => 'AO Media',
'ao-image' => 'AO Image',
'ao-audio' => 'AO Audio',
'ao-video' => 'AO Video',
'ao-headshot' => 'AO Headshot',
];
public static $response;
public static function init ( ) {
self::setupZendDB();
# Add Action Hooks #
add_action( 'admin_menu', [ 'AOAdmin', 'ao_admin_menu' ] );
add_action( 'admin_enqueue_scripts', [ 'AOAdmin', 'register_ao_plugin_scripts' ] );
add_action( 'admin_enqueue_scripts', [ 'AOAdmin', 'load_ao_plugin_scripts' ] );
# Ajax-specific Action Hooks #
add_action( 'wp_ajax_ao_api', [ 'AOAdmin', 'ao_api' ]);
# Add Filter Hooks #
add_filter( 'admin_body_class', [ 'AOAdmin', 'ao_admin_body_classes' ] );
register_taxonomy_for_object_type( 'category', 'attachment' );
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
public static function plugin_activation ( ) {
self::createDefaultAOCategories();
if ( is_admin() ) {
new AOPluginUpdate( __FILE__, 'myGitHubUsername', 'Repo-Name' );
}
}
public static function createDefaultAOCategories ( ) {
/** Returns an array of WP_Term objects. */
$existingCategories = wp_get_post_categories();
/**
object (WP_Term) (11) {
["term_id"]=> // int
["name"]=> // string
["slug"]=> // string
["term_group"]=> // int
["term_taxonomy_id"]=> // int
["taxonomy"]=> // string
["description"]=> // string
["parent"]=> // int
["count"]=> // int
["filter"] = // string
["meta"] = [] // an array of meta fields.
}
*/
foreach ( self::$default_categories as $slug => $name ) {
if ( ! get_category_by_slug( $slug ) ) {
$response = wp_insert_category([
'taxonomy' => 'category',
'cat_name' => $name,
'category_nicename' => $slug,
'category_description' => 'Do not remove. This is a 3AO category used by the 3AO themes and plugins.',
'category_parent' => '',
], true );
if ( is_wp_error( $response ) ) {
pr( $response->get_error_messages() );
}
}
}
}
public static function plugin_deactivation ( ) {
}
public static function setupZendDB ( ) {
# Sets the Zend_Db_Adapter so we can use Zend_Db_Table for DB calls. #
$db = Zend_Db::factory('Pdo_Mysql', [
'host' => DB_HOST,
'username' => DB_USER,
'password' => DB_PASSWORD,
'dbname' => DB_NAME,
// 'adapterNamespace' => 'Zend_Db'
]);
Zend_Registry::set('db', $db);
/**
try{
$tableModel = new AOModelUserMeta([
'db' => 'db',
'name'=> $GLOBALS['wpdb']->prefix . '_usermeta',
'primary' => 'umeta_id'
]);
$tableModel->getAdapter()->getConnection();
}
catch ( Exception | Error $e ) {
pr( $e->getMessage() );
}
*/
}
public static function view ( $name, array $args = [] ) {
$args = apply_filters( 'ao_admin_view_arguments', $args, $name );
foreach ( $args AS $key => $val ) {
$$key = $val;
}
load_plugin_textdomain( 'ao-admin' );
$file = AO_ADMIN_PLUGIN_DIR . 'views/'. $name . '.phtml';
include( $file );
}
public static function ajaxResponse () {
// print( json_encode( self::$response, JSON_HEX_QUOT ) );
header('Content-Type: application/json; charset=utf-8');
echo str_replace( 'u0022', '\u0022', json_encode( self::$response ) );
die();
}
public static function ao_admin_menu() {
add_menu_page(
__( 'Dashboard', 'ao-textdomain' ),
__( '3AO Dashboard', 'ao-textdomain' ),
'manage_options',
'3ao-dashboard',
['AOAdmin', 'ao_admin_page_contents'],
'dashicons-schedule',
1
);
}
public static function ao_admin_page_contents() {
AOAdmin::view('admin', [ 'test' => 'Welcome to the 3AO Dashboard.'] );
}
public static function register_ao_plugin_scripts() {
# Add Bootstrap 5.2.x #
wp_register_style( 'ao-bootstrap-css', plugins_url( 'ao-admin/assets/vendor/bootstrap/css/bootstrap.min.css' ) );
# Template Styles #
wp_register_style( 'ao-google-font-poppins-css','https://fonts.googleapis.com/css?family=Lato:300,400,400i,700|Poppins:300,400,500,600,700|PT+Serif:400,400i&display=swap' );
wp_register_style( 'ao-style-css', plugins_url( 'ao-admin/assets/css/style.css' ) );
wp_register_style( 'ao-dark-css', plugins_url( 'ao-admin/assets/css/dark.css' ) );
wp_register_style( 'ao-font-icons-css', plugins_url( 'ao-admin/assets/css/font-icons.css' ) );
wp_register_style( 'ao-animate-css', plugins_url( 'ao-admin/assets/css/animate.css' ) );
wp_register_style( 'ao-magnific-popup-css', plugins_url( 'ao-admin/assets/css/magnific-popup.css' ) );
wp_register_style( 'ao-summernote-css', plugins_url( 'ao-admin/assets/vendor/summernote/summernote.css' ) );
wp_register_style( 'ao-pretty-photo-css', plugins_url( 'ao-admin/assets/vendor/prettyPhoto/css/prettyPhoto.css' ) );
wp_register_style( 'ao-dropzone-css', plugins_url( 'ao-admin/assets/vendor/dropzone/dropzone.min.css' ) );
# Scripts #
wp_register_script( 'ao-bootstrap-js', plugins_url( 'ao-admin/assets/vendor/bootstrap/js/bootstrap.bundle.min.js' ) );
wp_register_script( 'ao-plugins-js', plugins_url( 'ao-admin/assets/js/plugins.js' ) );
wp_register_script( 'ao-functions-js', plugins_url( 'ao-admin/assets/js/functions.js' ) );
wp_register_script( 'ao-cookie-js', plugins_url( 'ao-admin/assets/vendor/js-cookie/js-cookie.min.js' ) );
wp_register_script( 'ao-color-picker-js', plugins_url( 'ao-admin/assets/js/js.colorpicker.min.js' ) );
wp_register_script( 'ao-tigerDOM-js', plugins_url( 'ao-admin/assets/js/tigerDOM.js' ) );
wp_register_script( 'ao-summernote-js', plugins_url( 'ao-admin/assets/vendor/summernote/summernote.js' ) );
wp_register_script( 'ao-pretty-photo-js', plugins_url( 'ao-admin/assets/vendor/prettyPhoto/js/jquery.prettyPhoto.js' ) );
wp_register_script( 'ao-clipboard-js', plugins_url( 'ao-admin/assets/js/clipboard.min.js' ) );
wp_register_script( 'ao-moment-js', plugins_url( 'ao-admin/assets/js/moment.min.js' ) );
wp_register_script( 'ao-dropzone-js', plugins_url( 'ao-admin/assets/vendor/dropzone/dropzone.min.js' ) );
wp_register_script( 'ao-media-admin-gallery-js', plugins_url( 'ao-admin/assets/js/mediaAdminGallery.js' ) );
wp_register_script( 'ao-media-admin-documents-js', plugins_url( 'ao-admin/assets/js/mediaAdminDocuments.js' ) );
wp_register_script( 'ao-media-admin-media-js', plugins_url( 'ao-admin/assets/js/mediaAdminMedia.js' ) );
# Add 3AO Custom CSS
wp_register_style( 'ao-colors-css', plugins_url( 'ao-admin/assets/css/colors.css' ) );
wp_register_style( 'ao-admin-css', plugins_url( 'ao-admin/assets/css/admin.css' ) );
# Add 3AO Custom JS
wp_register_script( 'ao-admin-js', plugins_url( 'ao-admin/assets/js/admin.js' ) );
}
public static function load_ao_plugin_scripts( $hook ) {
// Load only on ?page=3ao-dashboard
if( $hook !== 'toplevel_page_3ao-dashboard' ) {
return;
}
# Load Styles #
wp_enqueue_style( 'ao-bootstrap-css' );
wp_enqueue_style( 'ao-google-font-poppins-css' );
wp_enqueue_style( 'ao-style-css' );
wp_enqueue_style( 'ao-dark-css' );
wp_enqueue_style( 'ao-font-icons-css' );
wp_enqueue_style( 'ao-animate-css' );
wp_enqueue_style( 'ao-magnific-popup-css' );
wp_enqueue_style( 'ao-summernote-css' );
wp_enqueue_style( 'ao-pretty-photo-css' );
wp_enqueue_style( 'ao-dropzone-css' );
# 3AO Custom Admin #
wp_enqueue_style( 'ao-colors-css' );
wp_enqueue_style( 'ao-admin-css' );
# Load Scripts #
wp_enqueue_script( 'ao-bootstrap-js' );
wp_enqueue_script( 'ao-plugins-js' );
wp_enqueue_script( 'ao-functions-js' );
wp_enqueue_script( 'ao-cookie-js' );
wp_enqueue_script( 'ao-color-picker-js' );
wp_enqueue_script( 'ao-tigerDOM-js' );
wp_enqueue_script( 'ao-summernote-js' );
wp_enqueue_script( 'ao-pretty-photo-js' );
wp_enqueue_script( 'ao-clipboard-js' );
wp_enqueue_script( 'ao-moment-js' );
wp_enqueue_script( 'ao-dropzone-js' );
wp_enqueue_script( 'ao-media-admin-gallery-js' );
wp_enqueue_script( 'ao-media-admin-documents-js' );
wp_enqueue_script( 'ao-media-admin-media-js' );
wp_enqueue_script( 'ao-admin-js' );
// add_action('wp_head', 'ao_meta_tags');
}
public static function ao_meta_tags() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1" />';
}
public static function ao_admin_body_classes ( $classes ) {
$classes .= ' stretched invisible';
if ( ! empty( $_SESSION['themeStyle'] ) ) {
$classes .= ' ' . $_SESSION['themeStyle'];
}
return $classes;
}
public static function get_current_admin_url() {
return admin_url ( sprintf ( basename( $_SERVER['REQUEST_URI'] ) ) );
}
public static function get_admin_page_url( $page ) {
// https://3ao-beaudev.com/wp-admin/admin.php?page=3ao-dashboard
return admin_url() . 'admin.php?page=' . $page;
}
public static function ao_api ( ) {
/** Route the request to the right service class and method. */
if (
! empty( $_REQUEST['service'] ) &&
! empty( $_REQUEST['method'] ) &&
class_exists( $_REQUEST['service'] ) &&
method_exists( $_REQUEST['service'], $_REQUEST['method'] )
) {
$service = new $_REQUEST['service']( $_REQUEST );
self::$response = $service->getResponse();
self::ajaxResponse();
}
exit();
}
public static function ao_upload() {
}
}