This repository has been archived by the owner on Apr 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
class.auto-translator-for-wpml-admin.php
139 lines (118 loc) · 5.05 KB
/
class.auto-translator-for-wpml-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
<?php
// Main url to sections
const WPMLAT_SETTINGS_URL = 'options-general.php?page=wpmlat_config';
const WPMLAT_EXECUTION_URL = 'admin.php?page=wpmlat_execution';
const WPML_REFERRAL_URL = 'https://wpml.org/?aid=188550&affiliate_key=ZNyQ9dyyFFii&dr=wpmlat-referral';
class WPMLAutoTranslatorAdmin {
private static $initiated = false;
public static function init() {
if (!self::$initiated) {
self::init_hooks();
}
if (isset($_POST['settings'])) {
self::enter_settings();
}
}
/**
* Instantiate all hooks for admin panel (wp-admin)
*/
public static function init_hooks() {
self::$initiated = true;
self::include_page_class();
add_action('admin_init', array('WPMLAutoTranslatorAdmin', 'admin_init'));
add_action('admin_menu', array('WPMLAutoTranslatorAdmin', 'admin_menu'), 40 );
add_action('admin_notices', array('WPMLAutoTranslatorAdmin', 'admin_notices'), 20 );
//add_filter('plugin_action_links_' . plugin_basename(plugin_dir_path(__FILE__) . 'akismet.php'), array('Akismet_Admin', 'admin_plugin_settings_link'));
}
public static function admin_notices () {
$use_translation_management = get_option( 'wpmlat_use_translation_management', false );
if ( ! WPMLAutoTranslator::wpml_available() ) {
self::print_admin_notices(
__('WPML dependencens missing for WPMLAT.', 'wpmlat'),
sprintf ( __( 'Please, install <b>WPML</b>, if you do not haven it yet, you <a href="%s" target="_blank">can obtain it here</a>.', 'wpmlat' ), WPML_REFERRAL_URL ),
'error'
);
}
if ( $use_translation_management && ! WPMLAutoTranslator::wpml_full_configured() ) {
self::print_admin_notices(
__('WPML dependencens missing for WPMLAT.', 'wpmlat'),
sprintf ( __( 'Please, install <b>WPML Translation Management</b> and <b>WPML String Translation</b> extension, you <a href="%s" target="_blank">can obtain it here</a> or disable it in <a href="%s">Settings</a>.', 'wpmlat' ), WPML_REFERRAL_URL, WPMLAT_SETTINGS_URL ),
'error'
);
}
}
/**
* Show a message box
* @param type $title
* @param type $message
* @param type $type
*/
public static function print_admin_notices ( $title, $message, $type = 'error' ) {
?>
<div class='error'>
<?php if ($title) { ?>
<p><strong><?php echo $title; ?></strong></p>
<?php }
if ($message) { ?>
<p><?php echo $message; ?></p>
<?php } ?>
</div>
<?php
}
/**
* Include all page admin class
* Is required load all for options/hooks things.
* This only will be loaded in admin panel. And yes, this is too much slow action...
*/
public static function include_page_class() {
// include all admin pages and initialize settings and hooks
$path = WPMLAT__PLUGIN_DIR . 'pages/admin/';
$dh = opendir($path);
while (($page = readdir($dh)) !== false) {
if ( $page === '.' or $page === '..' ) continue;
// Including php file
$full_path = $path . $page;
include_once $full_path;
// Checking class
$page = substr($page, 0, strpos($page, '.php'));
$class = 'WPMLAutoTranslatorAdmin'.$page.'Page';
if (!class_exists($class)) {
die ('Class ' . $class .' not exist. Check that file ' . $full_path . ' exist and contain this class.' );
}
// Prepare class initialization
add_action( 'admin_init', [ $class, 'initialize' ] );
}
}
/**
* Instantiate admin fields
*/
public static function admin_init() {
load_plugin_textdomain('wpmalt');
// add_meta_box('akismet-status', __('Comment History', 'akismet'), array('Akismet_Admin', 'comment_status_meta_box'), 'comment', 'normal');
}
/**
* Add menu in admin sidebar
*/
public static function admin_menu() {
add_options_page(
__('WPML Auto Translation', 'wpmlat'),
__('WMPL Auto Translator', 'wpmlat'),
'manage_options',
'wpmlat_config',
array( 'WPMLAutoTranslatorAdminConfigPage', 'show' )
);
$main_page = apply_filters( 'icl_menu_main_page', WPML_PLUGIN_FOLDER . '/menu/languages.php' );
// $main_page = null; // Hide from menu
// $main_page = 'tools.php'; // Put in tools submenu
add_submenu_page(
$main_page,
__( 'WPML Auto Translation', 'wpmlat' ),
__( 'Do auto translation', 'wmplat' ),
'manage_options',
'wpmlat_execution',
array( 'WPMLAutoTranslatorAdminExecutionPage', 'show' )
);
}
public static function enter_settings() {
}
}