-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto_translator.php
331 lines (303 loc) · 7.77 KB
/
auto_translator.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/*
Plugin Name: AutoTranslate
Plugin URI: #
Description: Connect to Bing Translate, Google Translate or Yandex translate and automatically translate your site.
Author: WPSatchel
Version: 1.0 (Beta)
Author URI: #
*/
class Auto_Translator {
/**
* URL to this plugin's directory.
*
* @type string
*/
public $plugin_url = '';
/**
* Path to this plugin's directory.
*
* @type string
*/
public $plugin_path = '';
/**
* @var string
* The google place api for using to queury info
*/
public $prefix = '';
/**
* @var string
*/
public $domain = '';
/**
* @var array
*/
public $global = array();
public function __construct() {
$this->init();
//load domain
add_action( 'plugins_loaded', array( &$this, 'localization' ) );
//autoload
spl_autoload_register( array( &$this, 'autoload' ) );
//assets
add_action( 'admin_enqueue_scripts', array( &$this, 'admin_script' ) );
add_action( 'wp_enqueue_scripts', array( &$this, 'script' ) );
}
public function script() {
wp_register_style( $this->prefix . 'style', $this->plugin_url . 'assets/style.css' );
}
public function admin_script() {
wp_enqueue_style( $this->prefix . 'admin_style', $this->plugin_url . '/assets/admin.css' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
}
function get_languages() {
return array(
'en' => 'English',
'aa' => 'Afar',
'ab' => 'Abkhazian',
'af' => 'Afrikaans',
'am' => 'Amharic',
'ar' => 'Arabic',
'as' => 'Assamese',
'ay' => 'Aymara',
'az' => 'Azerbaijani',
'ba' => 'Bashkir',
'be' => 'Byelorussian',
'bg' => 'Bulgarian',
'bh' => 'Bihari',
'bi' => 'Bislama',
'bn' => 'Bengali/Bangla',
'bo' => 'Tibetan',
'br' => 'Breton',
'ca' => 'Catalan',
'co' => 'Corsican',
'cs' => 'Czech',
'cy' => 'Welsh',
'da' => 'Danish',
'de' => 'German',
'dz' => 'Bhutani',
'el' => 'Greek',
'eo' => 'Esperanto',
'es' => 'Spanish',
'et' => 'Estonian',
'eu' => 'Basque',
'fa' => 'Persian',
'fi' => 'Finnish',
'fj' => 'Fiji',
'fo' => 'Faeroese',
'fr' => 'French',
'fy' => 'Frisian',
'ga' => 'Irish',
'gd' => 'Scots/Gaelic',
'gl' => 'Galician',
'gn' => 'Guarani',
'gu' => 'Gujarati',
'ha' => 'Hausa',
'hi' => 'Hindi',
'hr' => 'Croatian',
'hu' => 'Hungarian',
'hy' => 'Armenian',
'ia' => 'Interlingua',
'ie' => 'Interlingue',
'ik' => 'Inupiak',
'in' => 'Indonesian',
'is' => 'Icelandic',
'it' => 'Italian',
'iw' => 'Hebrew',
'ja' => 'Japanese',
'ji' => 'Yiddish',
'jw' => 'Javanese',
'ka' => 'Georgian',
'kk' => 'Kazakh',
'kl' => 'Greenlandic',
'km' => 'Cambodian',
'kn' => 'Kannada',
'ko' => 'Korean',
'ks' => 'Kashmiri',
'ku' => 'Kurdish',
'ky' => 'Kirghiz',
'la' => 'Latin',
'ln' => 'Lingala',
'lo' => 'Laothian',
'lt' => 'Lithuanian',
'lv' => 'Latvian/Lettish',
'mg' => 'Malagasy',
'mi' => 'Maori',
'mk' => 'Macedonian',
'ml' => 'Malayalam',
'mn' => 'Mongolian',
'mo' => 'Moldavian',
'mr' => 'Marathi',
'ms' => 'Malay',
'mt' => 'Maltese',
'my' => 'Burmese',
'na' => 'Nauru',
'ne' => 'Nepali',
'nl' => 'Dutch',
'no' => 'Norwegian',
'oc' => 'Occitan',
'om' => '(Afan)/Oromoor/Oriya',
'pa' => 'Punjabi',
'pl' => 'Polish',
'ps' => 'Pashto/Pushto',
'pt' => 'Portuguese',
'qu' => 'Quechua',
'rm' => 'Rhaeto-Romance',
'rn' => 'Kirundi',
'ro' => 'Romanian',
'ru' => 'Russian',
'rw' => 'Kinyarwanda',
'sa' => 'Sanskrit',
'sd' => 'Sindhi',
'sg' => 'Sangro',
'sh' => 'Serbo-Croatian',
'si' => 'Singhalese',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'sm' => 'Samoan',
'sn' => 'Shona',
'so' => 'Somali',
'sq' => 'Albanian',
'sr' => 'Serbian',
'ss' => 'Siswati',
'st' => 'Sesotho',
'su' => 'Sundanese',
'sv' => 'Swedish',
'sw' => 'Swahili',
'ta' => 'Tamil',
'te' => 'Tegulu',
'tg' => 'Tajik',
'th' => 'Thai',
'ti' => 'Tigrinya',
'tk' => 'Turkmen',
'tl' => 'Tagalog',
'tn' => 'Setswana',
'to' => 'Tonga',
'tr' => 'Turkish',
'ts' => 'Tsonga',
'tt' => 'Tatar',
'tw' => 'Twi',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
'vi' => 'Vietnamese',
'vo' => 'Volapuk',
'wo' => 'Wolof',
'xh' => 'Xhosa',
'yo' => 'Yoruba',
'zh' => 'Chinese',
'zu' => 'Zulu',
);;
}
public function load_controllers() {
$path = $this->plugin_path . 'app/controllers';
$files = glob( $path . '/*.php' );
foreach ( $files as $file ) {
if ( file_exists( $file ) ) {
include_once $file;
}
}
}
public function load_components() {
$path = $this->plugin_path . 'app/components';
$files = glob( $path . '/*.php' );
foreach ( $files as $file ) {
if ( file_exists( $file ) ) {
include_once $file;
}
}
}
public function load_engine() {
if ( ! is_admin() || ( defined( 'DOING_AJAX' ) && DOING_AJAX == true ) ) {
$engine = pct_setting()->engine;
if ( ! empty( $engine ) ) {
new $engine;
}
} elseif ( is_admin() ) {
$engines = apply_filters( 'pct_translate_engine', array() );
foreach ( $engines as $key => $e ) {
new $key;
}
}
}
//----------------------------------------------------------------------------------------------------------------------------//
public function init() {
//some defined
$this->plugin_url = plugins_url( '/', __FILE__ );
$this->plugin_path = plugin_dir_path( __FILE__ );
$this->prefix = 'pct_';
$this->domain = 'pct_comment_translator';
require_once $this->plugin_path . 'app/components/pct_Translate_Widget.php';
}
public function localization() {
load_plugin_textdomain( $this->domain, false, '/phpapp_comment_translator/languages/' );
}
public function autoload( $classname ) {
$path = '';
//$core_path = dirname(plugin_dir_path(__FILE__)).'/phpapp_core';
$core_path = $this->plugin_path;
$vendors = array(
'phpapp_Form' => $core_path . 'vendors/form/phpapp_Form.php',
'phpapp_Active_Form' => $core_path . 'vendors/form/phpapp_Active_Form.php',
'phpapp_Model' => $core_path . 'vendors/phpapp_Model.php',
'phpapp_Option_Model' => $core_path . 'vendors/phpapp_Option_Model.php',
'phpapp_Controller' => $core_path . 'vendors/phpapp_Controller.php'
);
if ( isset( $vendors[ $classname ] ) ) {
$path = $vendors[ $classname ];
if ( file_exists( $path ) ) {
include $path;
return;
}
}
$lower = strtolower( $classname );
//first we need to check the prefix to prevent conflict
if ( strpos( $lower, $this->prefix ) === 0 ) {
if ( stristr( $lower, 'controller' ) ) {
$path = $this->plugin_path . 'app/controllers/' . $classname . '.php';
} elseif ( stristr( $lower, 'model' ) || stristr( $lower, 'table' ) ) {
$path = $this->plugin_path . 'app/models/' . $classname . '.php';
}
}
if ( file_exists( $path ) ) {
include $path;
}
}
public function render_view( $view, $args = array(), $return = false ) {
$path = $this->plugin_path . 'app/views/' . $view . '.php';
if ( file_exists( $path ) ) {
ob_start();
extract( $args );
include $path;
$content = ob_get_contents();
ob_end_clean();
if ( ! empty( $this->layout ) ) {
$layout_path = $this->plugin_path . 'app/views/layouts/' . $this->layout . '.php';
if ( file_exists( $layout_path ) ) {
ob_start();
include $layout_path;
ob_end_flush();
} else {
throw new Exception( 'Layout not found!' );
}
}
if ( $return == false ) {
echo $content;
}
return $content;
}
}
}
global $auto_translator;
$auto_translator = new Auto_Translator();
function pct_instance() {
global $auto_translator;
return $auto_translator;
}
function pct_setting() {
$setting = new pct_Setting_Model();
return $setting;
}
$auto_translator->load_controllers();
$auto_translator->load_components();
$auto_translator->load_engine();