-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasy-tinyMCE-content.class.php
More file actions
273 lines (234 loc) · 8.54 KB
/
Easy-tinyMCE-content.class.php
File metadata and controls
273 lines (234 loc) · 8.54 KB
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
<?php
class Easy_TinyMCE_Class_content{
public $id;
public $shortcode;
public $content;
public $options;
/*******************************************************
Create the Template ID
*******************************************************/
function template_id(){
return $this->id.'_template';
}
/*******************************************************
Create the Template ID
*******************************************************/
function default_field_options(){
return array(
'id' => '',
'field' => '',
'title' => '',
'std' => '',
'type' => '',
'des' => '',
'option' => array(),
'post_type' => 'post',
'taxonomy' => 'category',
'multiple' => false,
'content' => false
);
}
/*******************************************************
Output the full HTML
*******************************************************/
function html(){
?>
<script type="text/javascript">
function <?php echo $this->id; ?>_insertTemplate() {
<?php $this->shortcode_ja_vars(); ?>
/** Send shortcode to editor */
<?php if($this->content == true): ?>
window.send_to_editor('[<?php echo $this->shortcode; ?> <?php echo $this->shortcode_arguments(); ?>]<?php $this->field_content(); ?>[/<?php echo $this->shortcode; ?>]');
<?php else: ?>
window.send_to_editor('[<?php echo $this->shortcode; ?> <?php echo $this->shortcode_arguments(); ?> /]');
<?php endif; ?>
}
</script>
<div id="<?php echo $this->template_id(); ?>" class="zookit-shortcode-editor">
<div class="wrap">
<?php echo $this->form(); ?>
<input type="button" id="<?php echo $this->id; ?>-insert-template" class="button-primary" value="<?php echo __( 'Insert Shortcode', 'zoohub_taxdomain' ); ?>" onclick="<?php echo $this->id; ?>_insertTemplate();" />
<a id="<?php echo $this->id; ?>-cancel-template" class="button-secondary" onclick="tb_remove();" title="<?php echo __( 'Cancel', 'zoohub_taxdomain' ); ?>" style="float:right;"><?php echo __( 'Cancel', 'zoohub_taxdomain' ); ?></a>
</div>
</div>
<?php
}
function shortcode_arguments(){
$options = $this->options;
if(is_array($options)){
foreach($options as $option){
$default = $this->default_field_options();
$option = array_merge($default, $option);
if($option['content'] == false){
echo "".$option['id']."=\"'+".$this->id."_".$option['id']."+'\" ";
}
}
}
}
function shortcode_ja_vars(){
$options = $this->options;
if(is_array($options)){
foreach($options as $option){
echo "var ".$this->id."_".$option['id']." = jQuery( '#".$this->id."_".$option['id']."' ).val(); ";
}
}
}
function field_content(){
$options = $this->options;
if(is_array($options)){
foreach($options as $option){
$default = $this->default_field_options();
$option = array_merge($default, $option);
if( $option['content'] == true ){ echo "'+".$this->id."_".$option['id']."+'"; }
}
}
}
function form(){
$options = $this->options;
if(is_array($options)){
echo '<table width="100%">';
foreach($options as $option){
if($option['field'] == 'text'){
$this->field_text($option);
}
elseif($option['field'] == 'textarea'){
$this->field_textarea($option);
}
elseif($option['field'] == 'select'){
$this->field_select($option);
}
elseif($option['field'] == 'post-select'){
$this->field_post_select($option);
}
elseif($option['field'] == 'tax-select'){
$this->field_tax_select($option);
}
elseif($option['field'] == 'color'){
$this->field_color($option);
}
}
echo '</table>';
}
}
function field_text($data){
$default = $this->default_field_options();
$data = array_merge($default, $data);
$uid = $this->id.'_'.$data['id'];
?>
<tr>
<td>
<label for="<?php echo $uid; ?>"><strong><?php echo $data['title']; ?></strong></label><br />
<input type="text" name="<?php echo $uid; ?>" value="<?php echo $data['std']; ?>" id="<?php echo $uid; ?>" style="width:100%; margin-top:3px;"/>
<p style="margin-top:0; color:#999; font-style:italic;"><?php echo $data['des']; ?></p>
</td>
</tr>
<?php
}
function field_color($data){
$default = $this->default_field_options();
$data = array_merge($default, $data);
$uid = $this->id.'_'.$data['id'];
?>
<tr>
<td>
<label for="<?php echo $uid; ?>" style="margin-bottom:3px;"><strong><?php echo $data['title']; ?></strong></label><br />
<input class="shortcode-editor-ColorPicker" type="text" name="<?php echo $uid; ?>" value="<?php echo $data['std']; ?>" id="<?php echo $uid; ?>""/>
<p style="margin-top:0; color:#999; font-style:italic;"><?php echo $data['des']; ?></p>
</td>
</tr>
<?php
}
function field_textarea($data){
$default = $this->default_field_options();
$data = array_merge($default, $data);
$uid = $this->id.'_'.$data['id'];
?>
<tr>
<td>
<label for="<?php echo $uid; ?>"><strong><?php echo $data['title']; ?></strong></label><br />
<textarea name="<?php echo $uid; ?>" id="<?php echo $uid; ?>" rows="4" style="width:100%; margin-top:3px;"><?php echo $data['std']; ?></textarea>
<p style="margin-top:0; color:#999; font-style:italic;"><?php echo $data['des']; ?></p>
</td>
</tr>
<?php
}
function field_select($data){
$default = $this->default_field_options();
$data = array_merge($default, $data);
$uid = $this->id.'_'.$data['id'];
?>
<tr>
<td>
<label for="<?php echo $uid; ?>"><strong><?php echo $data['title']; ?></strong></label><br />
<select name="<?php echo $uid; ?>" id="<?php echo $uid; ?>" <?php if($data['multiple'] == true){ echo 'multiple="true"'; } ?> style="width:100%; margin-top:3px;">
<?php
if(is_array($data['option'])){
foreach($data['option'] as $option){
echo '<option value="'.$option.'" '.selected( $data['std'], $option, false).'>'.$option.'</option>';
}
}
?>
</select>
<p style="margin-top:0; color:#999; font-style:italic;"><?php echo $data['des']; ?></p>
</td>
</tr>
<?php
}
function field_post_select($data){
$default = $this->default_field_options();
$data = array_merge($default, $data);
$uid = $this->id.'_'.$data['id'];
?>
<tr>
<td>
<label for="<?php echo $uid; ?>"><strong><?php echo $data['title']; ?></strong></label><br />
<select name="<?php echo $uid; ?>" id="<?php echo $uid; ?>" <?php if($data['multiple'] == true){ echo 'multiple="true"'; } ?> style="width:100%; margin-top:3px;">
<option value="" selected="selected"></option>
<?php
global $post;
$args = array(
'post_type' =>$data['post_type'],
'numberposts' => '-1'
);
$ids = get_posts($args);
$count=0;
foreach($ids as $post) : setup_postdata($post);
$count++;
?>
<option value="<?php echo $post->ID; ?>"><?php the_title(); ?></option>
<?php
endforeach; wp_reset_postdata();
?>
</select>
<p style="margin-top:0; color:#999; font-style:italic;"><?php echo $data['des']; ?></p>
</td>
</tr>
<?php
}
function field_tax_select($data){
$default = $this->default_field_options();
$data = array_merge($default, $data);
$uid = $this->id.'_'.$data['id'];
?>
<tr>
<td>
<label for="<?php echo $uid; ?>"><strong><?php echo $data['title']; ?></strong></label><br />
<select name="<?php echo $uid; ?>" id="<?php echo $uid; ?>" <?php if($data['multiple'] == true){ echo 'multiple="true"'; } ?> style="width:100%; margin-top:3px;">
<option value="" selected="selected"></option>
<?php
$terms = get_terms($data['taxonomy'], 'orderby=count&hide_empty=0');
$terms_count = count($terms);
$cat_name = '';
if ( $terms_count > 0 ){
foreach ( $terms as $term ) {
echo '<option value="'.$term->slug.'">'.$term->name.'</option>';
}
}
?>
</select>
<p style="margin-top:0; color:#999; font-style:italic;"><?php echo $data['des']; ?></p>
</td>
</tr>
<?php
}
}