-
Notifications
You must be signed in to change notification settings - Fork 7
/
canvas-plugin_form.php
executable file
·368 lines (298 loc) · 14.2 KB
/
canvas-plugin_form.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
<?php
/*
___Canvas Plugin Form___________________________________________
Outputs the Lightbox form for plugins, building individual
form elements based upon the plugin definitions.
________________________________________________________________
*/
require( dirname(__FILE__) . '/../../../wp-config.php' );
if (!(is_user_logged_in() && current_user_can('edit_posts')))
die("Athentication failed!");
global $wpdb, $canvas;
$zone = $_GET['zone'];
$position = $_GET['position'];
$block_id = $_GET['block_id'];
$counter = 0;
// Get module info from database
$module_id= $wpdb->get_var("SELECT module_id FROM ".$canvas->main." WHERE block_id = $block_id");
if ( $wpdb->get_var("SELECT zone FROM ".$canvas->main." WHERE block_id = $block_id") != "shelf"){
$template_size = $wpdb->get_var("SELECT template_size FROM ".$canvas->main." WHERE block_id = $block_id");
$template_name = $wpdb->get_var("SELECT template_name FROM ".$canvas->main." WHERE block_id = $block_id");
}
//if ('' == $template_name) $template_name = 'default';
//if ('' == $template_size) $template_size = '-1';
$module_template_size_div_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_size';
$module_template_name_div_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_template_name';
// Get module name
include_once('RCCWP_CustomWriteModule.php');
$customWriteModule = RCCWP_CustomWriteModule::Get($module_id);
$module_name = $customWriteModule->name;
// Get plugin sizes
$moduleTemplatesFolder = dirname(__FILE__)."/modules/".$module_name."/templates";
$moduleTemplateFolder = dirname(__FILE__)."/modules/".$module_name."/templates/".$template_name;
// Load module template sizes
$otherSizesStr = "";
if ($handle = @opendir($moduleTemplateFolder)) {
while (false !== ($file = readdir($handle))) {
if (is_numeric($file)){
if ($template_size == $file)
$otherSizesStr = $otherSizesStr."<option selected='selected' value='".$file."'>".$file."</option>";
else
$otherSizesStr = $otherSizesStr."<option value='".$file."'>".$file."</option>";
}
else{
$t_size_val = 0;
switch($file){
case "small":
$t_size_val = -1;
break;
case "medium":
$t_size_val = -2;
break;
case "large":
$t_size_val = -3;
break;
case "full":
$t_size_val = -4;
break;
}
if ($t_size_val<0){
if ($template_size == $t_size_val)
$otherSizesStr = $otherSizesStr."<option selected='selected' value='".$t_size_val."'>".$file."</option>";
else
$otherSizesStr = $otherSizesStr."<option value='".$t_size_val."'>".$file."</option>";
}
}
}
closedir($handle);
}
// Load module template names
$templatesNamesStr = "";
if ($handle = @opendir($moduleTemplatesFolder)) {
while (false !== ($file = readdir($handle))) {
if ($file!= "." && $file!="..")
if ($template_name == $file)
$templatesNamesStr = $templatesNamesStr."<option selected='selected' value='".$file."'>".$file."</option>";
else
$templatesNamesStr = $templatesNamesStr."<option value='".$file."'>".$file."</option>";
}
closedir($handle);
}
?>
<div class="lbContent">
<?php
global $wpdb, $canvas;
$variables = $wpdb->get_results("SELECT * FROM ".$canvas->variables." WHERE parent = '$block_id' ORDER BY variable_id");
$title = $wpdb->get_results("SELECT * FROM ".$canvas->main." WHERE block_id = '$block_id'");
// Get module name
include_once('RCCWP_CustomWriteModule.php');
$customWriteModule = RCCWP_CustomWriteModule::Get($title[0]->module_id);
if ($title[0]->duplicate_id ==0 )
$title[0]->module_title = $customWriteModule->name;
else
$title[0]->module_title = $wpdb->get_var("SELECT duplicate_name FROM ".$canvas->duplicates." WHERE duplicate_id = ".$title[0]->duplicate_id);
$content = '<h3>'.$title[0]->module_title.'';
if($title[0]->author != '' && $title[0]->uri != '')
$content .= '<span>by <a target="new" href="'.$title[0]->uri.'">'.$title[0]->author.'</a></span>';
if($title[0]->description != '')
$content .= '<p>'.$title[0]->description.'</p>';
$F = "\$F";
$module_template_name_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_template_name';
$ListboxAJAX = CANVASURI. "ajax/canvas-populate-listbox.php?mod_name=".$module_name."&template_name=";
$content .=
<<<EOF
<input type="hidden" id="updated_module_template_size_id" value="$module_template_size_div_id" />
<input type="hidden" id="updated_module_template_name_id" value="$module_template_name_div_id" />
<script language="JavaScript" type="text/javascript" >
curr_module_size = $F('$module_template_size_div_id');
curr_module_template_name = $F('$module_template_name_div_id');
function UpdateModuleBlock(){
$('$module_template_size_div_id').value = $('template_name').value;
$('$module_template_name_div_id').value = $('template_size').value;
}
function dynamicallyLoadSizeList(){
$('template_name').value = curr_module_template_name;
$("template_size").innerHTML = "<option>Loading ...</option>";
var myAjax = new Ajax.Request('$ListboxAJAX' + curr_module_template_name + "&template_size=" + curr_module_size, { method:'post',
onSuccess: function(transport){
$("template_size").innerHTML = transport.responseText;
$("template_size").innerHTML = $("template_size").innerHTML + "<option>Hello</option>";
}
});
};
EOF;
if ($template_name == ""){ //If the template name is not saved in the database, get the default template name stored in the module block
$content .=
<<<EOF
//Event.observe(window,
// 'load',
// dynamicallyLoadSizeList ,
// false);
dynamicallyLoadSizeList();
EOF;
}
$content .=
<<<EOF
function changeTemplateSize(){
Event.observe($("template_name"), 'change',
function(){
var d = new Date();
var time = d.getTime();
$("template_size").innerHTML = "<option>Loading ...</option>";
var myAjax = new Ajax.Request('$ListboxAJAX' + $F("template_name") + '&time='+time, { method:'get',
onSuccess: function(transport){
var newContent = '<label for="template_size">Template Size:</label> <select name="template_size" id="template_size" style="margin-left:11px;width:100px;font-size:11px;" onchange="Canvas.changePublishImg();">';
newContent += transport.responseText +" </select>";
$("wrap_template_size").innerHTML = newContent;
}
});
}
);
}
//Event.observe(window,
// 'load',
// changeTemplateSize);
changeTemplateSize();
function saveAndReturn(){
lightbox.prototype.deactivate();
return false;
}
</script>
<a id="confirm" href="javascript:void(0)" class="lbAction" rel="deactivate" onclick="$('$module_size_div_id').value = $('template_name').value;$('$module_name_div_id').value = $('template_size').value;">Save and Return</a>
<a id="cancel" href="javascript:void(0)" class="lbAction" rel="cancel">Cancel</a></h3><div class="lbContent_inside">
<form name="lightbox_form" action="" id="lightbox_form" onsubmit="lightbox.prototype.deactivate();return false;">
<label for="template_name">Template Name:</label>
<select name="template_name" id="template_name" style="width:100px;font-size:11px;" onchange="Canvas.changePublishImg();">
$templatesNamesStr
</select>
<br />
<div id="wrap_template_size">
<label for="template_size">Template Size:</label>
<select name="template_size" id="template_size" style="margin-left:11px;width:100px;font-size:11px;" onchange="Canvas.changePublishImg();">
$otherSizesStr
</select>
</div>
<br />
<hr />
<br />
EOF;
$content .= '<input type="hidden" name="parent" value="'.$block_id.'">'."\n";
foreach($variables as $variable) {
if(strtolower($variable->type) == 'text')
$content .= '<label class="textbox">'.$variable->description.': <input type="text" class="text" name="'.$variable->variable_name.'" value="'.$variable->value.'" /></label>'."\n";
elseif(strtolower($variable->type) == 'textarea')
$content .= '<label class="textbox">'.$variable->description.': <textarea rows="8" name="'.$variable->variable_name.'">'.htmlspecialchars($variable->value).'</textarea></label>'."\n";
elseif(strtolower($variable->type) == 'integer')
$content .= '<label class="textbox">'.$variable->description.': <input type="text" size="3" name="'.$variable->variable_name.'" value="'.$variable->value.'" /></label>'."\n";
elseif(strtolower($variable->type) == 'boolean') {
$content .= '<label class="boolean"><input type="checkbox" name="'.$variable->variable_name.'" value="1" ';
if($variable->value == 1) $content .= 'checked ';
$content .= '/> '.$variable->description.'</label>'."\n";
} elseif(strtolower($variable->type) == 'radio') {
$content .= '<span><p>'.$variable->description.':</p>';
$options = $wpdb->get_results("SELECT * FROM ".$canvas->options." WHERE var_id = '$variable->variable_id'");
foreach($options as $option) {
// If is a Wordpress database variable...
if(preg_match('/(.*)\-\>(.*)\:(.*)/', $option->option_value, $matches)) {
$content .= canvas_database_plugin($matches, 'radio', $variable->value, $option->option_params);
} else {
$content .= '<label><input type="radio" name="'.$variable->variable_name.'" value="'.$option->option_value.'" ';
if ($option->option_value == $variable->value) $content .= ' checked="checked" ';
$content .= '/> '.$option->option_text.'</label>';
}
}
$content .= '</span>'."\n";
} elseif(strtolower($variable->type) == 'select') {
$content .= '<span><p>'.$variable->description.':</p>';
$options = $wpdb->get_results("SELECT * FROM ".$canvas->options." WHERE var_id = '$variable->variable_id'");
$content .= '<select name="'.$variable->variable_name.'" id="'.$variable->variable_name.'">'."\n";
foreach($options as $option) {
// If is a Wordpress database variable...
if(preg_match('/(.*)\-\>(.*)\:(.*)/', $option->option_value, $matches)) {
$content .= canvas_database_plugin($matches, 'select', $variable->value, $option->option_params);
} else {
$content .= '<option value="'.$option->option_value.'" ';
if ($option->option_value == $variable->value) $content .= ' selected="selected" ';
$content .= '> '.$option->option_text."</option>\n";
}
}
$content .= '</select>'."\n";
$content .= '</span>'."\n";
} elseif(strtolower($variable->type) == 'image') {
$options = $wpdb->get_results("SELECT * FROM ".$canvas->options." WHERE var_id = '$variable->variable_id'");
$content .= '<p>'.$variable->description.':</p>';
$content .= '<input type="hidden" id="directory" value="'.$options[0]->option_value.'">';
$selected = '<input type="hidden" id="selected_image">';
$content .= '<input type="hidden" id="path" name="'.$variable->variable_name.'" value="'.$variable->value.'">';
$content .= '<div class="gallery">';
$files = scandirectory(ABSPATH.$options[0]->option_value);
foreach($files as $file) {
$class = '';
if(substr($file, -3) == 'jpg' || substr($file, -3) == 'gif' || substr($file, -3) == 'png') {
if($options[0]->option_value.$file == $variable->value) {
$class= 'class="selected_image"';
$selected = '<input type="hidden" id="selected_image" value="'.$file.'">';
}
list($width, $height) = @getimagesize(get_bloginfo('wpurl').'/'.$options[0]->option_value.$file);
if($width > 250) { $height = $height * 250 / $width; $width = 250; }
$content .= '<a href="javascript:void(0)" onclick="Canvas.gallerySwitch(\''.$file.'\')"><img '.$class.' id="'.$file.'" src="'.get_bloginfo('wpurl').'/'.$options[0]->option_value.$file.'" title="'.$file.'" alt="'.$file.'" style="height: '.$height.'px; width: '.$width.'px;" /></a>';
}
}
$content .= $selected;
$content .= '</div>';
} elseif(strtolower($variable->type) == 'list') {
$listitems = explode('|', $variable->value);
$content .= '<label class="textbox">'.$variable->description.' <small>(Note | is an illegal character)</small></label>'."\n".'<span class="list" id="listlist">'."\n";
foreach($listitems as $listitem) {
$content .= '<span id="'.$variable->variable_name.$counter.'"><input type="text" class="text" name="'.$counter.'canvaslist_'.$variable->variable_name.'" value="'.htmlspecialchars($listitem).'" />'."\n";
$content .= '<a href="javascript:void(0)" onclick="Canvas.addListItem(this, \''.$variable->variable_name.'\')"><img src="'.CANVASURI.'images/list-duplicate.png" alt="Duplicate" title="Duplicate item"/></a>';
$content .= '<a href="javascript:void(0)" onclick="Canvas.removeListItem(this)"><img src="'.CANVASURI.'images/list-delete.png" alt="Delete" title="Delete item"/></a>';
$content .= '</span>';
$counter++;
}
$content .= '</span>'."\n";
}
elseif(strtolower($variable->type) == 'fileupload'){
$value = attribute_escape($variable->value);
$path = CANVASURI.'files_flutter/';
$valueRelative = $value;
$value = $path.$value;
$varName = $variable->variable_name;
$iframePath = CANVASURI."RCCWP_upload.php?input_name=".$varName;
$content .= '<label class="textbox">'.$variable->description.': </label>'."\n";
if($valueRelative)
$content .= '(<a href="' . $value . '" target="_blank">View Current</a>)';
echo $content;
echo
<<<EOF
<input tabindex="3"
id="$varName"
name="$varName"
type="hidden"
size="46"
onchange=""
value="$valueRelative"
/>
<p id="upload_progress_$varName" style="visibility:hidden;height:0px"></p>
EOF;
?>
<?php
include_once( "RCCWP_SWFUpload.php" ) ;
RCCWP_SWFUpload::Body($varName, 0, 1, 10) ;
$content = "";
} elseif(strtolower($variable->type) == 'gmodule') {
//$variable->value WILL THIS BE THE XML FILE?
$xmlfile = 'http://www.google.com/ig/modules/datetime.xml';
$url = 'http://gmodules.com/ig/creator?synd=open&url='.$xmlfile;
echo '<object id="gmodule_content" data="'.$url.'" type="text/html"></object>';
} elseif(strtolower($variable->type) == 'gmodule_script') {
echo '<input type="text" id="gmodule_script" value="'.$variable->value.'">';
}
}
//if(count($variables) == 0) echo 'This plugin has no options (yes, it should be a block instead).';
$content .= '<input type="hidden" id="listcount" name="listcount" value="'.$counter.'">'."\n";
$content .= '</form>'."\n";
echo $content;
?>
</div>
</div>