PluginProbe
Leyka / 3.5
Leyka v3.5
3.32.3 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.6.1 2.3.7 2.3.8 2.3.9 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1 3.10 3.11 3.11.1 3.12 3.13 3.14 3.15 3.16 3.17 All 89 releases
leyka / inc / leyka-admin.php

leyka-admin.php in Leyka 3.5, at inc/leyka-admin.php

774 lines 31.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if( !defined('WPINC') ) die;
2
3 /**
4 * Leyka Admin setup
5 **/
6
7 class Leyka_Admin_Setup extends Leyka_Singleton {
8
9 protected static $_instance = null;
10
11 /** @var WP_List_Table */
12 protected $_donors_list_table = null;
13
14 protected function __construct() {
15
16 require_once LEYKA_PLUGIN_DIR.'/inc/leyka-admin-functions.php';
17
18 add_action('admin_menu', array($this, 'admin_menu_setup'), 9);
19
20 if(leyka_options()->opt('donor_management_available')) { // Save Donors pages custom options
21 add_filter('set-screen-option', function($status, $option, $value) {
22
23 if($option === 'donors_per_page' && (int)$value > 0) {
24 update_user_option(get_current_user_id(), 'donors_per_page', $value);
25 }
26
27 return $value;
28
29 }, 10, 3);
30 }
31
32 add_action('admin_enqueue_scripts', array($this, 'load_frontend_scripts'));
33
34 add_action('admin_init', array($this, 'pre_admin_actions'));
35
36 add_action('wp_ajax_leyka_send_feedback', array($this, 'ajax_send_feedback'));
37
38 add_filter('plugin_row_meta', array($this, 'set_plugin_meta'), 10, 2);
39
40 add_filter('plugin_action_links_'.LEYKA_PLUGIN_INNER_SHORT_NAME, array($this, 'add_plugins_list_links'));
41
42 // Metaboxes support where it is needed:
43 add_action('leyka_pre_donor_info_actions', array($this, 'full_metaboxes_support'));
44
45 add_action('leyka_post_admin_actions', array($this, 'show_footer'));
46
47 // Donors' tags on the user profile page:
48 add_action('show_user_profile', array($this, 'show_user_profile_donor_fields'));
49 add_action('edit_user_profile', array($this, 'show_user_profile_donor_fields'));
50
51 add_action('personal_options_update', array($this, 'save_user_profile_donor_fields'));
52 add_action('edit_user_profile_update', array($this, 'save_user_profile_donor_fields'));
53
54 // Portlet controller API:
55 require_once LEYKA_PLUGIN_DIR.'/inc/leyka-class-portlet-controller.php';
56
57 }
58
59 public function set_plugin_meta($links, $file) {
60
61 if($file == LEYKA_PLUGIN_INNER_SHORT_NAME) {
62 $links[] = '<a href="https://github.com/Teplitsa/Leyka/">GitHub</a>';
63 }
64
65 return $links;
66
67 }
68
69 protected function _show_admin_template($template_id) {
70
71 if( !$template_id ) {
72 return;
73 }
74
75 $template_file = LEYKA_PLUGIN_DIR.'/inc/admin-templates/leyka-admin-'.$template_id.'.php';
76 if(file_exists($template_file)) {
77 require $template_file;
78 }
79
80 }
81
82 // Support the full abilities of the metaboxes on any plugin's page:
83 public function full_metaboxes_support($current_stage = false) {?>
84
85 <form style="display:none;" method="get" action="#">
86 <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
87 <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
88 </form>
89
90 <?php }
91
92 public function pre_admin_actions() {
93
94 function leyka_admin_title($admin_title) {
95
96 if(isset($_GET['page']) && $_GET['page'] === 'leyka_settings_new' && isset($_GET['screen'])) {
97
98 $screen_full_id = explode('-', $_GET['screen']);
99
100 // $screen_full_id[0] - view type (e.g. 'wizard' or 'control_panel')
101 // $screen_full_id[1] - settings area given (e.g. 'init').
102
103 require_once(LEYKA_PLUGIN_DIR.'inc/settings/leyka-class-settings-factory.php');
104
105 $admin_title = get_bloginfo('name')
106 .' &#8212; '
107 .Leyka_Settings_Factory::get_instance()->get_controller($screen_full_id[1])->title;
108
109 } else if(isset($_GET['page']) && $_GET['page'] === 'leyka_donor_info' && !empty($_GET['donor'])) {
110
111 try {
112 $donor = new Leyka_Donor(absint($_GET['donor']));
113 } catch(Exception $e) {
114 return $admin_title;
115 }
116
117 $admin_title = sprintf(__('Leyka: Donor %s'), $donor->name).' &lsaquo; '.get_bloginfo('name');
118
119 }
120
121 return $admin_title;
122
123 }
124 add_filter('admin_title', 'leyka_admin_title');
125
126 // Leyka admin notices:
127 if(isset($_GET['leyka_reset_msg'])) {
128 update_option('leyka_admin_notice_'.$_GET['leyka_reset_msg'], 0);
129 }
130
131 if(isset($_GET['leyka-hide-notice']) && isset($_GET['_leyka_notice_nonce'])) {
132
133 if( !wp_verify_nonce($_GET['_leyka_notice_nonce'], 'leyka_hide_notice_nonce') ) {
134 wp_die(__('Action failed. Please refresh the page and retry.', 'leyka'));
135 }
136
137 if( !current_user_can('manage_options') ) {
138 wp_die(__('Action failed: insufficient permissions.', 'leyka'));
139 }
140
141 update_option('leyka_admin_notice_'.sanitize_text_field($_GET['leyka-hide-notice']), 1);
142
143 }
144
145 add_filter('leyka_admin_portlet_title', function($portlet_title, $portlet_id){
146 return $portlet_id === 'donations-dynamics' ? $portlet_title.',&nbsp;'.leyka_get_currency_label() : $portlet_title;
147 }, 10, 2);
148
149 if(isset($_GET['page']) && $_GET['page'] === 'leyka_donor_info' && !empty($_GET['donor'])) {
150
151 // Add all metaboxes:
152 add_meta_box('leyka_donor_info', __("Donor's data", 'leyka'), array($this, 'donor_data_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
153 add_meta_box('leyka_donor_admin_comments', __('Comments', 'leyka'), array($this, 'donor_comments_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
154 add_meta_box('leyka_donor_tags', __('Tags'), array($this, 'donor_tags_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
155 add_meta_box('leyka_donor_donations', __('Donations', 'leyka'), array($this, 'donor_donations_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
156
157 }
158
159 }
160
161 public function admin_menu_setup() {
162
163 // Leyka menu root:
164 add_menu_page(__('Leyka Dashboard', 'leyka'), __('Leyka', 'leyka'), 'leyka_manage_donations', 'leyka', array($this, 'dashboard_screen'));
165
166 add_submenu_page('leyka', __('Leyka Dashboard', 'leyka'), __('Dashboard', 'leyka'), 'leyka_manage_donations', 'leyka', array($this, 'dashboard_screen'));
167
168 add_submenu_page('leyka', __('Donations', 'leyka'), __('Donations', 'leyka'), 'leyka_manage_donations', 'edit.php?post_type='.Leyka_Donation_Management::$post_type);
169
170 add_submenu_page('leyka', __('New correctional donation', 'leyka'), _x('Add new', 'donation', 'leyka'), 'leyka_manage_donations', 'post-new.php?post_type='.Leyka_Donation_Management::$post_type);
171
172 add_submenu_page('leyka', __('Campaigns', 'leyka'), __('Campaigns', 'leyka'), 'leyka_manage_donations', 'edit.php?post_type='.Leyka_Campaign_Management::$post_type);
173
174 add_submenu_page('leyka', __('New campaign', 'leyka'), _x('Add new', 'campaign', 'leyka'), 'leyka_manage_donations', 'post-new.php?post_type='.Leyka_Campaign_Management::$post_type);
175
176 // Donors' tags taxonomy:
177 if(leyka()->opt('donor_management_available')) {
178
179 // Donors list page:
180 $hook = add_submenu_page('leyka', __('Donors', 'leyka'), __('Donors', 'leyka'), 'leyka_manage_donations', 'leyka_donors', array($this, 'donors_list_screen'));
181 add_action("load-$hook", array($this, 'donors_list_screen_options'));
182
183 // Donors tags page:
184 $taxonomy = get_taxonomy(Leyka_Donor::DONORS_TAGS_TAXONOMY_NAME);
185
186 add_submenu_page('leyka', esc_attr($taxonomy->labels->menu_name), esc_attr($taxonomy->labels->menu_name), $taxonomy->cap->manage_terms, 'edit-tags.php?taxonomy='.$taxonomy->name);
187
188 add_filter('submenu_file', function($submenu_file) { // Fix for parent menu
189
190 global $parent_file;
191 if($submenu_file == 'edit-tags.php?taxonomy='.Leyka_Donor::DONORS_TAGS_TAXONOMY_NAME) {
192 $parent_file = 'leyka';
193 }
194 return $submenu_file;
195
196 });
197
198 }
199
200 add_submenu_page('leyka', __('Leyka Settings', 'leyka'), __('Settings', 'leyka'), 'leyka_manage_options', 'leyka_settings', array($this, 'settings_screen'));
201
202 add_submenu_page('leyka', __('Contact us', 'leyka'), __('Feedback', 'leyka'), 'leyka_manage_donations', 'leyka_feedback', array($this, 'feedback_screen'));
203
204 // Fake pages:
205 add_submenu_page(NULL, 'Leyka Wizard', 'Leyka Wizard', 'leyka_manage_options', 'leyka_settings_new', array($this, 'settings_new_screen'));
206
207 add_submenu_page(NULL, "Donor's info", "Donor's info", 'leyka_manage_options', 'leyka_donor_info', array($this, 'donor_info_screen'));
208 // Fake pages - END
209
210 do_action('leyka_admin_menu_setup');
211
212 global $submenu;
213
214 if( !empty($submenu['leyka']) ) {
215 $submenu['leyka'] = apply_filters('leyka_admin_menu_order', $submenu['leyka']);
216 }
217
218 }
219
220 /**
221 * Settings link in plugin list table.
222 *
223 * @param $links array
224 * @return array
225 */
226 public function add_plugins_list_links($links) {
227
228 $links[] = '<a href="'.admin_url('admin.php?page=leyka_settings').'">'.__( 'Settings', 'leyka').'</a>';
229 return $links;
230
231 }
232
233 public function dashboard_screen() {
234
235 if( !current_user_can('leyka_manage_donations') ) {
236 wp_die(__('Sorry, but you do not have permissions to access this page.', 'leyka'));
237 }
238
239 do_action('leyka_pre_dashboard_actions');
240
241 $this->_show_admin_template('dashboard-page');
242
243 do_action('leyka_post_dashboard_actions');
244 do_action('leyka_post_admin_actions');
245
246 }
247
248 public function show_admin_portlet($portlet_id, array $params = array()) {
249
250 $portlet_file = LEYKA_PLUGIN_DIR.'/inc/portlets/leyka-'.$portlet_id.'.php';
251 if( !file_exists($portlet_file) ) {
252 return;
253 }
254
255 $controller_file = LEYKA_PLUGIN_DIR.'/inc/portlets/'.$portlet_id.'/leyka-class-'.$portlet_id.'-portlet-controller.php';
256 if(file_exists($controller_file)) {
257 require_once $controller_file;
258 }
259
260 $portlet_data = get_file_data($portlet_file, array(
261 'name' => 'Leyka Portlet',
262 'description' => 'Description',
263 'title' => 'Title',
264 'thumbnail' => 'Thumbnail',
265 ));?>
266
267 <div class="leyka-admin-portlet portlet-<?php echo esc_attr($portlet_id);?>">
268
269 <div class="portlet-header">
270 <img src="<?php echo esc_url(LEYKA_PLUGIN_BASE_URL.trim($portlet_data['thumbnail'], '/'));?>" alt="">
271 <?php echo apply_filters('leyka_admin_portlet_title', esc_attr__($portlet_data['title'], 'leyka'), $portlet_id);?>
272 </div>
273
274 <div class="portlet-content"><?php require_once($portlet_file);?></div>
275
276 </div>
277
278 <?php
279 }
280
281 public function has_banners($page = false, $location = false) {
282 return !get_user_meta(get_current_user_id(), 'leyka_dashboard_banner_closed', true);
283 }
284
285 public function show_banner($page = false, $location = false) {?>
286
287 <div class="banner-wrapper">
288 <div class="banner-inner">
289 <a href="<?php echo admin_url('/admin.php?page=leyka_settings_new&screen=wizard-init');?>" class="banner">
290 <img src="<?php echo LEYKA_PLUGIN_BASE_URL;?>img/dashboard/banner-run-wizard.svg" alt="">
291 </a>
292 <a class="close" href="#" title="<?php esc_html_e('Close permanently', 'leyka');?>"> </a>
293 </div>
294 </div>
295
296 <?php
297 }
298
299 /**
300 * Display Donor related fields on the User profile admin page.
301 *
302 * @param $donor_user WP_User
303 */
304 public function show_user_profile_donor_fields(WP_User $donor_user) {
305
306 if( !current_user_can('administrator') ) {
307 return;
308 }?>
309
310 <table class="form-table">
311 <tr>
312 <th>
313 <label for="leyka-donors-tags-field"><?php _e('Donor tags', 'leyka');?></label>
314 </th>
315 <td>
316 <?php $all_donors_tags = get_terms(array(
317 'taxonomy' => Leyka_Donor::DONORS_TAGS_TAXONOMY_NAME,
318 'hide_empty' => false,
319 ));
320
321 $donor_user_tags = wp_get_object_terms(
322 $donor_user->ID,
323 Leyka_Donor::DONORS_TAGS_TAXONOMY_NAME,
324 array('fields' => 'ids')
325 );?>
326
327 <select id="leyka-donors-tags-field" multiple="multiple" name="leyka_donor_tags[]">
328 <?php foreach($all_donors_tags as $donor_tag) {?>
329 <option value="<?php echo esc_attr($donor_tag->term_id);?>" <?php echo in_array($donor_tag->term_id, $donor_user_tags) ? 'selected="selected"' : '';?>>
330 <?php echo esc_html($donor_tag->name);?>
331 </option>
332 <?php }?>
333 </select>
334 </td>
335 </tr>
336 </table>
337 <?php
338
339 }
340
341 /**
342 * Handle Donor related fields for the User profile admin page.
343 *
344 * @param $donor_user_id integer
345 * @return boolean True if fields values are saved, false otherwise.
346 */
347 public function save_user_profile_donor_fields($donor_user_id) {
348
349 if( !current_user_can('administrator') ) {
350 return false;
351 }
352
353 array_walk($_POST['leyka_donor_tags'], function( &$value ){
354 $value = (int)$value;
355 });
356
357 return !is_wp_error(wp_set_object_terms($donor_user_id, $_POST['leyka_donor_tags'], Leyka_Donor::DONORS_TAGS_TAXONOMY_NAME));
358
359 }
360
361 public function is_separate_forms_stage($stage) {
362 return in_array($stage, array('email', 'beneficiary', 'technical', 'view', 'additional'));
363 }
364
365 public function donors_list_screen_options() {
366
367 add_screen_option('per_page', array(
368 'label' => __('Donors per page', 'leyka'),
369 'default' => 20,
370 'option' => 'donors_per_page',
371 ));
372
373 require_once(LEYKA_PLUGIN_DIR.'inc/admin-lists/leyka-class-donors-list-table.php');
374
375 $this->_donors_list_table = new Leyka_Admin_Donors_List_Table();
376
377 }
378
379 public function donors_list_screen() {
380
381 if( !current_user_can('leyka_manage_options') ) {
382 wp_die(__('You do not have permissions to access this page.', 'leyka'));
383 }
384
385 do_action('leyka_pre_donors_list_actions');
386
387 $this->_show_admin_template('donors-list-page');
388
389 do_action('leyka_post_donors_list_actions');
390 do_action('leyka_post_admin_actions');
391
392 }
393
394 public function settings_screen() {
395
396 if( !current_user_can('leyka_manage_options') ) {
397 wp_die(__('You do not have permissions to access this page.', 'leyka'));
398 }
399
400 $current_stage = $this->get_current_settings_tab();
401
402 require_once(LEYKA_PLUGIN_DIR.'inc/settings/leyka-class-settings-factory.php'); // Basic Controller class
403 require_once(LEYKA_PLUGIN_DIR.'inc/settings-pages/leyka-settings-common.php');
404 require_once(LEYKA_PLUGIN_DIR.'inc/settings/leyka-admin-template-tags.php');
405
406 do_action('leyka_pre_settings_actions', $current_stage);
407
408 if( // Process settings change
409 (
410 !empty($_POST["leyka_settings_{$current_stage}_submit"])
411 || !empty($_POST["leyka_settings_stage-{$current_stage}_submit"])
412 )
413 /** @todo Find what's wrong with the nonce check below: */
414 // && wp_verify_nonce('_leyka_nonce', "leyka_settings_{$current_stage}")
415 ) {
416
417 do_action('leyka_settings_submit', $current_stage);
418 do_action("leyka_settings_{$current_stage}_submit");
419
420 }
421
422 $this->_show_admin_template('settings-page');?>
423
424 <?php do_action('leyka_post_settings_actions');
425 do_action('leyka_post_admin_actions');
426
427 }
428
429 /** Settings factory-controlled display (ATM, Wizards only) */
430 public function settings_new_screen() {
431
432 if(empty($_GET['screen']) || count(explode('-', $_GET['screen'])) < 2) {
433
434 $this->settings_screen();
435 return;
436
437 }
438
439 $screen_full_id = explode('-', $_GET['screen']);
440
441 // Normally, we'd constuct settings view based on
442 // - view type ([0], e.g. 'wizard' or 'control_panel')
443 // - settings area given ([1], e.g. 'init').
444
445 require_once(LEYKA_PLUGIN_DIR.'inc/settings/leyka-class-settings-factory.php');
446
447 try {
448
449 Leyka_Settings_Factory::get_instance()->get_render($screen_full_id[0])
450 ->set_controller(Leyka_Settings_Factory::get_instance()->get_controller($screen_full_id[1]))
451 ->render_page();
452
453 } catch(Exception $ex) {
454 echo '<pre>'.print_r('Settings page error (code '.$ex->getCode().'): '.$ex->getMessage(), 1).'</pre>';
455 }
456
457 do_action('leyka_post_admin_actions');
458
459 }
460
461 public function get_default_settings_tab() {
462 return apply_filters('leyka_default_settings_tab', 'payment');
463 }
464
465 public function get_current_settings_tab() {
466 return empty($_GET['stage']) ? $this->get_default_settings_tab() : trim($_GET['stage']);
467 }
468
469 public function settings_tabs_menu() {
470
471 $base_url = 'admin.php?page=leyka_settings';
472
473 $out = '';
474 foreach(Leyka_Options_Allocator::get_instance()->get_tabs() as $tab_id => $tab_label) {
475 $out .= '<a href="'
476 .($this->get_default_settings_tab() === $tab_id ? $base_url : add_query_arg('stage', $tab_id, $base_url))
477 .'" class="'.($this->get_current_settings_tab() === $tab_id ? 'nav-tab nav-tab-active' : 'nav-tab').'">'
478 .$tab_label.'</a>';
479 }
480
481 $out .= '<a href="'.admin_url('/admin.php?page=leyka_settings_new&screen=wizard-init').'" class="init-wizard-tab"></a>';
482
483 return $out;
484
485 }
486
487 public function donor_info_screen() {
488
489 do_action('leyka_pre_donor_info_actions'); // Add collapsible to metaboxes
490
491 // // Add all metaboxes:
492 // add_meta_box('leyka_donor_info', __("Donor's data", 'leyka'), array($this, 'donor_data_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
493 // add_meta_box('leyka_donor_admin_comments', __('Comments', 'leyka'), array($this, 'donor_comments_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
494 // add_meta_box('leyka_donor_tags', __('Tags'), array($this, 'donor_tags_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
495 // add_meta_box('leyka_donor_donations', __('Donations', 'leyka'), array($this, 'donor_donations_metabox'), 'dashboard_page_leyka_donor_info', 'normal');
496
497 $this->_show_admin_template('donor-info-page');
498
499 do_action('leyka_post_donor_info_actions');
500 do_action('leyka_post_admin_actions');
501
502 }
503
504 public function donor_data_metabox() {
505 $this->_show_admin_template('metabox-donor-data');
506 }
507 public function donor_comments_metabox() {
508 $this->_show_admin_template('metabox-donor-comments');
509 }
510 public function donor_tags_metabox() {
511 $this->_show_admin_template('metabox-donor-tags');
512 }
513 public function donor_donations_metabox() {
514 $this->_show_admin_template('metabox-donor-donations');
515 }
516
517 /** Displaying feedback **/
518 public function feedback_screen() {
519
520 if( !current_user_can('leyka_manage_donations') ) {
521 wp_die(__('You do not have permissions to access this page.', 'leyka'));
522 }
523
524 do_action('leyka_pre_feedback_actions');
525
526 $this->_show_admin_template('feedback-page');
527
528 do_action('leyka_post_feedback_actions');
529 do_action('leyka_post_admin_actions');
530
531 }
532
533 /** Feedback page processing */
534 public function ajax_send_feedback() {
535
536 if( !wp_verify_nonce($_POST['nonce'], 'leyka_feedback_sending') ) {
537 die('1');
538 }
539
540 $_POST['topic'] = htmlentities(trim($_POST['topic']), ENT_COMPAT, 'UTF-8');
541 $_POST['name'] = htmlentities(trim($_POST['name']), ENT_COMPAT, 'UTF-8');
542 $_POST['email'] = htmlentities(trim($_POST['email']), ENT_COMPAT, 'UTF-8');
543 $_POST['text'] = htmlentities(trim($_POST['text']), ENT_COMPAT, 'UTF-8');
544
545 if( !$_POST['name'] || !$_POST['email'] || !$_POST['text'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
546 die('2');
547 }
548
549 add_filter('wp_mail_content_type', 'leyka_set_html_content_type');
550
551 $res = true;
552 $site_env = format_debug_data(humanaize_debug_data(leyka_get_env_and_options()));
553
554 foreach((array)explode(',', LEYKA_SUPPORT_EMAIL) as $email) {
555
556 $email = trim($email);
557 if( !$email || !is_email($email) ) {
558 continue;
559 }
560
561 $res &= wp_mail(
562 $email, __('Leyka: new feedback incoming', 'leyka'),
563 sprintf(
564 "Добрый день!<br><br>
565 Поступила новая обратная связь от пользователя Лейки.<br><br>
566 <strong>Тема:</strong> %s<br>
567 <strong>Имя пользователя:</strong> %s<br>
568 <strong>Почта пользователя:</strong> %s<br>
569 <strong>Текст сообщения:</strong><br>%s<br><br>
570 ---------------- Те�
571 нические данные сайта пользователя --------------<br><br>
572 <strong>Cайт пользователя:</strong> <a href='%s'>%s</a> (IP: %s)<br>
573 <strong>Версия WP:</strong> %s<br>
574 <strong>Версия Лейки:</strong> %s<br>
575 <strong>Параметр admin_email:</strong> %s<br>
576 <strong>Язык:</strong> %s (кодировка: %s)<br>
577 <strong>ПО веб-сервера:</strong> %s<br>
578 <strong>Браузер пользователя:</strong> %s<br>
579 ---------------------------------------------------------------------<br>
580 <pre>%s</pre>",
581 $_POST['topic'], $_POST['name'], $_POST['email'], nl2br($_POST['text']),
582 home_url(), get_bloginfo('name'), $_SERVER['SERVER_ADDR'],
583 get_bloginfo('version'), LEYKA_VERSION, get_bloginfo('admin_email'),
584 get_bloginfo('language'), get_bloginfo('charset'),
585 $_SERVER['SERVER_SOFTWARE'], $_SERVER['HTTP_USER_AGENT'],
586 $site_env
587 ),
588 array('From: '.get_bloginfo('name').' <no_reply@leyka.te-st.ru>',)
589 );
590 }
591
592 // Reset content-type to avoid conflicts (http://core.trac.wordpress.org/ticket/23578):
593 remove_filter('wp_mail_content_type', 'leyka_set_html_content_type');
594
595 die($res ? '0' : '3');
596
597 }
598
599 public function show_footer() {
600 leyka_show_admin_footer();
601 }
602
603 protected function _load_data_tables() {
604
605 wp_enqueue_style('jquery-dataTables', LEYKA_PLUGIN_BASE_URL.'css/jquery.dataTables.css');
606 wp_enqueue_script('jquery-dataTables', LEYKA_PLUGIN_BASE_URL.'js/jquery.dataTables.min.js', array('jquery'), false, true);
607
608 wp_localize_script('jquery-dataTables', 'leyka_dt', array(
609 'processing' => __('Processing...', 'leyka'),
610 'search' => __('Search:', 'leyka'),
611 'lengthMenu' => __('Show _MENU_ entries', 'leyka'),
612 'info' => __('Showing _START_ to _END_ of _TOTAL_ entries', 'leyka'),
613 'infoEmpty' => __('Showing 0 to 0 of 0 entries', 'leyka'),
614 'infoFiltered' => __('(filtered from _MAX_ total entries)', 'leyka'),
615 'infoThousands' => __(',', 'leyka'),
616 'loadingRecords' => __('Loading...', 'leyka'),
617 'infoPostFix' => '',
618 'zeroRecords' => __('No matching records found', 'leyka'),
619 'emptyTable' => __('No data available in table', 'leyka'),
620 'paginate_first' => __('First', 'leyka'),
621 'paginate_previous' => __('Previous', 'leyka'),
622 'paginate_next' => __('Next', 'leyka'),
623 'paginate_last' => __('Last', 'leyka'),
624 'aria_sortAsc' => __(': activate to sort column ascending', 'leyka'),
625 'aria_sortDesc' => __(': activate to sort column descending', 'leyka'),
626 ));
627
628 return 'jquery-dataTables';
629
630 }
631
632 public function load_frontend_scripts() {
633
634 wp_enqueue_style('leyka-icon', LEYKA_PLUGIN_BASE_URL.'css/admin-icon.css', array(), LEYKA_VERSION);
635
636 wp_enqueue_style('leyka-admin-common', LEYKA_PLUGIN_BASE_URL.'assets/css/admin-common.css', array(), LEYKA_VERSION);
637
638 $screen = get_current_screen();
639 if(false === stripos($screen->base, 'leyka') && false === stripos($screen->id, 'leyka')) {
640 return;
641 }
642
643 // Base admin area js/css:
644 $leyka_admin_new = (isset($_GET['screen']) && count(explode('-', $_GET['screen'])) >= 2) // New settings pages (from v3.0)
645 || (isset($_GET['page']) && $_GET['page'] === 'leyka_settings' /*&& empty($_GET['stage'])*/)
646 || ($screen->post_type === Leyka_Campaign_Management::$post_type && $screen->base === 'post')
647 || (isset($_GET['page']) && ($_GET['page'] === 'leyka' || $_GET['page'] === 'leyka_donors'))
648 || (isset($_GET['page']) && $_GET['page'] === 'leyka_donor_info' && !empty($_GET['donor']));
649
650 $current_screen = get_current_screen();
651 $dependencies = array('jquery',);
652
653 if($leyka_admin_new) {
654 wp_enqueue_style('leyka-settings', LEYKA_PLUGIN_BASE_URL.'assets/css/admin.css', array(), LEYKA_VERSION);
655 } else { // Old admin pages (before v3.0)
656 wp_enqueue_style('leyka-admin', LEYKA_PLUGIN_BASE_URL.'css/admin.css', array(), LEYKA_VERSION);
657 }
658
659 // WP admin metaboxes support:
660 if($current_screen->id === 'dashboard_page_leyka_donor_info') {
661
662 $dependencies[] = 'postbox';
663 $dependencies[] = 'jquery-ui-accordion';
664 $dependencies[] = 'jquery-ui-sortable';
665 $dependencies[] = 'tags-box';
666
667 $dependencies[] = $this->_load_data_tables();
668
669 }
670 // Metaboxes support - END
671
672 // Settings pages:
673 if(stristr($current_screen->id, '_page_leyka_settings') !== false) {
674
675 // $dependencies[] = 'jquery-ui-accordion';
676 $dependencies[] = 'jquery-ui-sortable';
677
678 wp_enqueue_script('leyka-sticky', LEYKA_PLUGIN_BASE_URL.'js/jquery.sticky.js', $dependencies, LEYKA_VERSION, true);
679 $dependencies[] = 'leyka-sticky';
680 }
681
682 if(isset($_GET['page']) && ($_GET['page'] === 'leyka' || $_GET['page'] === 'leyka_donors')) {
683 wp_enqueue_style('jqueryui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css', false, null );
684 $dependencies[] = 'jquery-ui-selectmenu';
685 }
686
687 if($current_screen->post_type === Leyka_Donation_Management::$post_type) {
688
689 $dependencies[] = 'jquery-ui-autocomplete';
690 $dependencies[] = 'jquery-ui-tooltip';
691
692 }
693
694 $js_data = apply_filters('leyka_admin_js_localized_strings', array(
695 'ajaxurl' => admin_url('admin-ajax.php'),
696 'ajax_loader_url' => LEYKA_PLUGIN_BASE_URL.'img/ajax-loader.gif',
697 'field_required' => __('This field is required to be filled', 'leyka'),
698 'email_invalid_msg' => __('You have entered an invalid email', 'leyka'),
699 'common_error_message' => esc_html__('Error while saving the data', 'leyka'),
700 'error_message' => esc_html__('Error!', 'leyka'),
701 'default_image_message' => esc_html__('Default', 'leyka'),
702 'disconnect_stats' => esc_html__('Disconnect statistics', 'leyka'),
703 'confirm_delete_comment' => esc_html__('Delete comment?', 'leyka'),
704 'first_donation_date_incomplete_message' => esc_html__('To correctly search for "First Payment Date", select the range of their two dates.', 'leyka'),
705 'last_donation_date_incomplete_message' => esc_html__('To correctly search for "Last Payment Date", select the range of their two dates.', 'leyka'),
706 ));
707
708 if(isset($_GET['page']) && $_GET['page'] === 'leyka') {
709
710 wp_enqueue_script('jquery-ui-dialog');
711 wp_enqueue_style('wp-jquery-ui-dialog');
712 wp_enqueue_script('leyka-admin', LEYKA_PLUGIN_BASE_URL.'assets/js/Chart.v2.8.0.min.js', $dependencies, LEYKA_VERSION, true);
713
714 }
715
716 leyka_localize_rich_html_text_tags();
717
718 // Campaign editing page:
719 if($screen->post_type === Leyka_Campaign_Management::$post_type && $screen->base === 'post' && (!$screen->action || $screen->action === 'add')) {
720
721 $dependencies[] = $this->_load_data_tables();
722
723 if(function_exists('wp_enqueue_code_editor')) { // The function is available in WP v4.9.0+
724 wp_enqueue_code_editor(array('type' => 'text/css')); // Add the code editor lib
725 }
726
727 }
728
729 $locale = get_locale();
730 if($locale !== 'en_US') {
731 wp_enqueue_script(
732 'jquery-ui-datepicker-locale',
733 LEYKA_PLUGIN_BASE_URL."js/jq-datepicker-locales/$locale.js",
734 array('jquery-ui-datepicker'), LEYKA_VERSION, true
735 );
736 }
737
738 // Donation editing page:
739 if($screen->post_type === Leyka_Donation_Management::$post_type && $screen->base === 'post') {
740
741 wp_enqueue_script(
742 'leyka-admin-add-edit-donation',
743 LEYKA_PLUGIN_BASE_URL.'js/admin-add-edit-donation.js',
744 array('jquery-ui-datepicker-locale', 'jquery-ui-autocomplete'), LEYKA_VERSION, true
745 );
746 wp_localize_script('leyka-admin-add-edit-donation', 'leyka', $js_data + array(
747 'add_donation_button_text' => __('Add the donation', 'leyka'),
748 'field_required' => __('This field is required to be filled', 'leyka'),
749 'campaign_required' => __('Selecting a campaign is required', 'leyka'),
750 'email_invalid_msg' => __('You have entered an invalid email', 'leyka'),
751 'amount_incorrect_msg' => __('The amount must be filled with non-zero, non-negative number', 'leyka'),
752 'donation_source_required' => __('Please, set one of a payment methods or just type a few words to describe a source for this donation', 'leyka'),
753 ));
754
755 return; /** @todo Only for now. Need to transfer the code from /js/admin-add-edit-donation.js to the separate /src/js/admin/ script. */
756
757 }
758
759
760 $dependencies[] = 'jquery-ui-autocomplete';
761
762 wp_enqueue_script('leyka-easy-modal', LEYKA_PLUGIN_BASE_URL . 'js/jquery.easyModal.min.js', array(), false, true);
763 wp_enqueue_script(
764 'leyka-settings',
765 LEYKA_PLUGIN_BASE_URL.'assets/js/admin.js',
766 $dependencies,
767 LEYKA_VERSION,
768 true
769 );
770 wp_localize_script('leyka-settings', 'leyka', $js_data);
771
772 }
773
774 }