136
|
1 |
<?php |
|
2 |
|
|
3 |
require_once(dirname(__FILE__).'/const.php'); |
|
4 |
require_once(dirname(__FILE__).'/l10n.php'); |
|
5 |
|
|
6 |
// ----------------------------------------------------------------------------- |
|
7 |
// the ExecPhp_Script class displays the Exec-PHP javascript if necessary |
|
8 |
// ----------------------------------------------------------------------------- |
|
9 |
|
|
10 |
if (!class_exists('ExecPhp_Script')) : |
|
11 |
|
|
12 |
class ExecPhp_Script |
|
13 |
{ |
|
14 |
var $m_id = NULL; |
|
15 |
var $tab_name = NULL; |
|
16 |
var $m_l10n_tab = NULL; |
|
17 |
var $m_path = NULL; |
|
18 |
var $m_dependency = NULL; |
|
19 |
|
|
20 |
function ExecPhp_Script($id, $tab_name, $l10n_tab, $path, $dependency) |
|
21 |
{ |
|
22 |
$this->m_id =& $id; |
|
23 |
$this->m_tab_name = $tab_name; |
|
24 |
$this->m_l10n_tab = $l10n_tab; |
|
25 |
$this->m_path = $path; |
|
26 |
$this->m_dependency = $dependency; |
|
27 |
|
|
28 |
if (function_exists('wp_enqueue_script')) |
|
29 |
wp_enqueue_script($this->m_id, ExecPhp_HOME_URL. $this->m_path, $this->m_dependency); |
|
30 |
else |
|
31 |
// WP < 2.1 |
|
32 |
add_action('admin_head', array(&$this, 'action_admin_head_script')); |
|
33 |
|
|
34 |
if (!$this->m_l10n_tab) |
|
35 |
return; |
|
36 |
|
|
37 |
global $wp_version; |
|
38 |
|
|
39 |
if (version_compare($wp_version, '2.1.dev') >= 0) |
|
40 |
add_action('wp_print_scripts', array(&$this, 'action_wp_print_scripts')); |
|
41 |
else |
|
42 |
add_action('admin_head', array(&$this, 'action_admin_head_tab')); |
|
43 |
} |
|
44 |
|
|
45 |
// --------------------------------------------------------------------------- |
|
46 |
// hooks |
|
47 |
// --------------------------------------------------------------------------- |
|
48 |
|
|
49 |
function action_wp_print_scripts() |
|
50 |
{ |
|
51 |
if (function_exists('wp_localize_script')) |
|
52 |
{ |
|
53 |
$this->m_l10n_tab['l10n_print_after'] = 'try{convertEntities('. $this->m_tab_name. ');}catch(e){};'; |
|
54 |
wp_localize_script($this->m_id, $this->m_tab_name, $this->m_l10n_tab); |
|
55 |
} |
|
56 |
else |
|
57 |
// WP < 2.2 |
|
58 |
add_action('admin_head', array(&$this, 'action_admin_head_tab')); |
|
59 |
} |
|
60 |
|
|
61 |
function action_admin_head_script() |
|
62 |
{ |
|
63 |
?> |
|
64 |
<script type='text/javascript' src='<?php echo ExecPhp_HOME_URL. $this->m_path; ?>'></script> |
|
65 |
<?php |
|
66 |
} |
|
67 |
|
|
68 |
function action_admin_head_tab() |
|
69 |
{ |
|
70 |
?> |
|
71 |
<script type='text/javascript'> |
|
72 |
/* <![CDATA[ */ |
|
73 |
<?php echo $this->m_tab_name; ?> = { |
|
74 |
<?php |
|
75 |
foreach ($this->m_l10n_tab as $item => $value) |
|
76 |
{ |
|
77 |
echo "\t\t$item: \"$value\",\n"; |
|
78 |
} |
|
79 |
echo "\t\tlast: \"last\"\n\t}\n"; |
|
80 |
?> |
|
81 |
try{convertEntities(<?php echo $this->m_tab_name; ?>);}catch(e){}; |
|
82 |
/* ]]> */ |
|
83 |
</script> |
|
84 |
<?php |
|
85 |
} |
|
86 |
|
|
87 |
// --------------------------------------------------------------------------- |
|
88 |
// tools |
|
89 |
// --------------------------------------------------------------------------- |
|
90 |
|
|
91 |
function print_message($heading, $text) |
|
92 |
{ |
|
93 |
$heading = escape_dquote($heading); |
|
94 |
$text = escape_dquote($text); |
|
95 |
?> |
|
96 |
<script type="text/javascript"> |
|
97 |
//<![CDATA[ |
|
98 |
ExecPhp_setMessage("<?php echo $heading; ?>", "<?php echo $text; ?>"); |
|
99 |
//]]> |
|
100 |
</script> |
|
101 |
<?php |
|
102 |
} |
|
103 |
} |
|
104 |
endif; |
|
105 |
|
|
106 |
?> |