| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | |
|---|
| 5 | ___Canvas Plugin Form___________________________________________ |
|---|
| 6 | |
|---|
| 7 | Outputs the Lightbox form for plugins, building individual |
|---|
| 8 | form elements based upon the plugin definitions. |
|---|
| 9 | |
|---|
| 10 | ________________________________________________________________ |
|---|
| 11 | |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | require( dirname(__FILE__) . '/../../../wp-config.php' ); |
|---|
| 15 | if (!(is_user_logged_in() && current_user_can('edit_posts'))) |
|---|
| 16 | die("Athentication failed!"); |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | global $wpdb, $canvas; |
|---|
| 20 | |
|---|
| 21 | $zone = $_GET['zone']; |
|---|
| 22 | $position = $_GET['position']; |
|---|
| 23 | $block_id = $_GET['block_id']; |
|---|
| 24 | $counter = 0; |
|---|
| 25 | |
|---|
| 26 | // Get module info from database |
|---|
| 27 | $module_id= $wpdb->get_var("SELECT module_id FROM ".$canvas->main." WHERE block_id = $block_id"); |
|---|
| 28 | if ( $wpdb->get_var("SELECT zone FROM ".$canvas->main." WHERE block_id = $block_id") != "shelf"){ |
|---|
| 29 | $template_size = $wpdb->get_var("SELECT template_size FROM ".$canvas->main." WHERE block_id = $block_id"); |
|---|
| 30 | $template_name = $wpdb->get_var("SELECT template_name FROM ".$canvas->main." WHERE block_id = $block_id"); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | //if ('' == $template_name) $template_name = 'default'; |
|---|
| 34 | //if ('' == $template_size) $template_size = '-1'; |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | $module_template_size_div_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_size'; |
|---|
| 38 | $module_template_name_div_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_template_name'; |
|---|
| 39 | |
|---|
| 40 | // Get module name |
|---|
| 41 | include_once('RCCWP_CustomWriteModule.php'); |
|---|
| 42 | |
|---|
| 43 | $customWriteModule = RCCWP_CustomWriteModule::Get($module_id); |
|---|
| 44 | $module_name = $customWriteModule->name; |
|---|
| 45 | |
|---|
| 46 | // Get plugin sizes |
|---|
| 47 | $moduleTemplatesFolder = dirname(__FILE__)."/modules/".$module_name."/templates"; |
|---|
| 48 | $moduleTemplateFolder = dirname(__FILE__)."/modules/".$module_name."/templates/".$template_name; |
|---|
| 49 | |
|---|
| 50 | // Load module template sizes |
|---|
| 51 | $otherSizesStr = ""; |
|---|
| 52 | if ($handle = @opendir($moduleTemplateFolder)) { |
|---|
| 53 | while (false !== ($file = readdir($handle))) { |
|---|
| 54 | if (is_numeric($file)){ |
|---|
| 55 | if ($template_size == $file) |
|---|
| 56 | $otherSizesStr = $otherSizesStr."<option selected='selected' value='".$file."'>".$file."</option>"; |
|---|
| 57 | else |
|---|
| 58 | $otherSizesStr = $otherSizesStr."<option value='".$file."'>".$file."</option>"; |
|---|
| 59 | |
|---|
| 60 | } |
|---|
| 61 | else{ |
|---|
| 62 | $t_size_val = 0; |
|---|
| 63 | switch($file){ |
|---|
| 64 | case "small": |
|---|
| 65 | $t_size_val = -1; |
|---|
| 66 | break; |
|---|
| 67 | case "medium": |
|---|
| 68 | $t_size_val = -2; |
|---|
| 69 | break; |
|---|
| 70 | case "large": |
|---|
| 71 | $t_size_val = -3; |
|---|
| 72 | break; |
|---|
| 73 | case "full": |
|---|
| 74 | $t_size_val = -4; |
|---|
| 75 | break; |
|---|
| 76 | |
|---|
| 77 | } |
|---|
| 78 | if ($t_size_val<0){ |
|---|
| 79 | if ($template_size == $t_size_val) |
|---|
| 80 | $otherSizesStr = $otherSizesStr."<option selected='selected' value='".$t_size_val."'>".$file."</option>"; |
|---|
| 81 | else |
|---|
| 82 | $otherSizesStr = $otherSizesStr."<option value='".$t_size_val."'>".$file."</option>"; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | closedir($handle); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | // Load module template names |
|---|
| 92 | $templatesNamesStr = ""; |
|---|
| 93 | if ($handle = @opendir($moduleTemplatesFolder)) { |
|---|
| 94 | while (false !== ($file = readdir($handle))) { |
|---|
| 95 | if ($file!= "." && $file!="..") |
|---|
| 96 | if ($template_name == $file) |
|---|
| 97 | $templatesNamesStr = $templatesNamesStr."<option selected='selected' value='".$file."'>".$file."</option>"; |
|---|
| 98 | else |
|---|
| 99 | $templatesNamesStr = $templatesNamesStr."<option value='".$file."'>".$file."</option>"; |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | closedir($handle); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | ?> |
|---|
| 107 | <div class="lbContent"> |
|---|
| 108 | <?php |
|---|
| 109 | global $wpdb, $canvas; |
|---|
| 110 | $variables = $wpdb->get_results("SELECT * FROM ".$canvas->variables." WHERE parent = '$block_id' ORDER BY variable_id"); |
|---|
| 111 | $title = $wpdb->get_results("SELECT * FROM ".$canvas->main." WHERE block_id = '$block_id'"); |
|---|
| 112 | |
|---|
| 113 | // Get module name |
|---|
| 114 | include_once('RCCWP_CustomWriteModule.php'); |
|---|
| 115 | $customWriteModule = RCCWP_CustomWriteModule::Get($title[0]->module_id); |
|---|
| 116 | if ($title[0]->duplicate_id ==0 ) |
|---|
| 117 | $title[0]->module_title = $customWriteModule->name; |
|---|
| 118 | else |
|---|
| 119 | $title[0]->module_title = $wpdb->get_var("SELECT duplicate_name FROM ".$canvas->duplicates." WHERE duplicate_id = ".$title[0]->duplicate_id); |
|---|
| 120 | |
|---|
| 121 | $content = '<h3>'.$title[0]->module_title.''; |
|---|
| 122 | if($title[0]->author != '' && $title[0]->uri != '') |
|---|
| 123 | $content .= '<span>by <a target="new" href="'.$title[0]->uri.'">'.$title[0]->author.'</a></span>'; |
|---|
| 124 | if($title[0]->description != '') |
|---|
| 125 | $content .= '<p>'.$title[0]->description.'</p>'; |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | $F = "\$F"; |
|---|
| 129 | $module_template_name_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_template_name'; |
|---|
| 130 | |
|---|
| 131 | $ListboxAJAX = CANVASURI. "ajax/canvas-populate-listbox.php?mod_name=".$module_name."&template_name="; |
|---|
| 132 | |
|---|
| 133 | $content .= |
|---|
| 134 | <<<EOF |
|---|
| 135 | |
|---|
| 136 | <input type="hidden" id="updated_module_template_size_id" value="$module_template_size_div_id" /> |
|---|
| 137 | <input type="hidden" id="updated_module_template_name_id" value="$module_template_name_div_id" /> |
|---|
| 138 | |
|---|
| 139 | <script language="JavaScript" type="text/javascript" > |
|---|
| 140 | curr_module_size = $F('$module_template_size_div_id'); |
|---|
| 141 | curr_module_template_name = $F('$module_template_name_div_id'); |
|---|
| 142 | |
|---|
| 143 | function UpdateModuleBlock(){ |
|---|
| 144 | $('$module_template_size_div_id').value = $('template_name').value; |
|---|
| 145 | $('$module_template_name_div_id').value = $('template_size').value; |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | function dynamicallyLoadSizeList(){ |
|---|
| 149 | $('template_name').value = curr_module_template_name; |
|---|
| 150 | $("template_size").innerHTML = "<option>Loading ...</option>"; |
|---|
| 151 | |
|---|
| 152 | var myAjax = new Ajax.Request('$ListboxAJAX' + curr_module_template_name + "&template_size=" + curr_module_size, { method:'post', |
|---|
| 153 | onSuccess: function(transport){ |
|---|
| 154 | $("template_size").innerHTML = transport.responseText; |
|---|
| 155 | $("template_size").innerHTML = $("template_size").innerHTML + "<option>Hello</option>"; |
|---|
| 156 | } |
|---|
| 157 | }); |
|---|
| 158 | }; |
|---|
| 159 | |
|---|
| 160 | EOF; |
|---|
| 161 | |
|---|
| 162 | if ($template_name == ""){ //If the template name is not saved in the database, get the default template name stored in the module block |
|---|
| 163 | $content .= |
|---|
| 164 | <<<EOF |
|---|
| 165 | //Event.observe(window, |
|---|
| 166 | // 'load', |
|---|
| 167 | // dynamicallyLoadSizeList , |
|---|
| 168 | // false); |
|---|
| 169 | |
|---|
| 170 | dynamicallyLoadSizeList(); |
|---|
| 171 | |
|---|
| 172 | EOF; |
|---|
| 173 | } |
|---|
| 174 | $content .= |
|---|
| 175 | <<<EOF |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | function changeTemplateSize(){ |
|---|
| 179 | Event.observe($("template_name"), 'change', |
|---|
| 180 | function(){ |
|---|
| 181 | var d = new Date(); |
|---|
| 182 | var time = d.getTime(); |
|---|
| 183 | $("template_size").innerHTML = "<option>Loading ...</option>"; |
|---|
| 184 | var myAjax = new Ajax.Request('$ListboxAJAX' + $F("template_name") + '&time='+time, { method:'get', |
|---|
| 185 | onSuccess: function(transport){ |
|---|
| 186 | 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();">'; |
|---|
| 187 | newContent += transport.responseText +" </select>"; |
|---|
| 188 | $("wrap_template_size").innerHTML = newContent; |
|---|
| 189 | } |
|---|
| 190 | }); |
|---|
| 191 | |
|---|
| 192 | } |
|---|
| 193 | ); |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | //Event.observe(window, |
|---|
| 197 | // 'load', |
|---|
| 198 | // changeTemplateSize); |
|---|
| 199 | changeTemplateSize(); |
|---|
| 200 | |
|---|
| 201 | function saveAndReturn(){ |
|---|
| 202 | lightbox.prototype.deactivate(); |
|---|
| 203 | return false; |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | |
|---|
| 207 | </script> |
|---|
| 208 | |
|---|
| 209 | <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> |
|---|
| 210 | <a id="cancel" href="javascript:void(0)" class="lbAction" rel="cancel">Cancel</a></h3><div class="lbContent_inside"> |
|---|
| 211 | |
|---|
| 212 | <form name="lightbox_form" action="" id="lightbox_form" onsubmit="lightbox.prototype.deactivate();return false;"> |
|---|
| 213 | <label for="template_name">Template Name:</label> |
|---|
| 214 | <select name="template_name" id="template_name" style="width:100px;font-size:11px;" onchange="Canvas.changePublishImg();"> |
|---|
| 215 | $templatesNamesStr |
|---|
| 216 | </select> |
|---|
| 217 | <br /> |
|---|
| 218 | <div id="wrap_template_size"> |
|---|
| 219 | <label for="template_size">Template Size:</label> |
|---|
| 220 | <select name="template_size" id="template_size" style="margin-left:11px;width:100px;font-size:11px;" onchange="Canvas.changePublishImg();"> |
|---|
| 221 | $otherSizesStr |
|---|
| 222 | </select> |
|---|
| 223 | </div> |
|---|
| 224 | <br /> |
|---|
| 225 | <hr /> |
|---|
| 226 | <br /> |
|---|
| 227 | |
|---|
| 228 | |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | EOF; |
|---|
| 232 | $content .= '<input type="hidden" name="parent" value="'.$block_id.'">'."\n"; |
|---|
| 233 | |
|---|
| 234 | foreach($variables as $variable) { |
|---|
| 235 | if(strtolower($variable->type) == 'text') |
|---|
| 236 | $content .= '<label class="textbox">'.$variable->description.': <input type="text" class="text" name="'.$variable->variable_name.'" value="'.$variable->value.'" /></label>'."\n"; |
|---|
| 237 | elseif(strtolower($variable->type) == 'textarea') |
|---|
| 238 | $content .= '<label class="textbox">'.$variable->description.': <textarea rows="8" name="'.$variable->variable_name.'">'.htmlspecialchars($variable->value).'</textarea></label>'."\n"; |
|---|
| 239 | elseif(strtolower($variable->type) == 'integer') |
|---|
| 240 | $content .= '<label class="textbox">'.$variable->description.': <input type="text" size="3" name="'.$variable->variable_name.'" value="'.$variable->value.'" /></label>'."\n"; |
|---|
| 241 | elseif(strtolower($variable->type) == 'boolean') { |
|---|
| 242 | $content .= '<label class="boolean"><input type="checkbox" name="'.$variable->variable_name.'" value="1" '; |
|---|
| 243 | if($variable->value == 1) $content .= 'checked '; |
|---|
| 244 | $content .= '/> '.$variable->description.'</label>'."\n"; |
|---|
| 245 | } elseif(strtolower($variable->type) == 'radio') { |
|---|
| 246 | $content .= '<span><p>'.$variable->description.':</p>'; |
|---|
| 247 | |
|---|
| 248 | $options = $wpdb->get_results("SELECT * FROM ".$canvas->options." WHERE var_id = '$variable->variable_id'"); |
|---|
| 249 | |
|---|
| 250 | foreach($options as $option) { |
|---|
| 251 | // If is a Wordpress database variable... |
|---|
| 252 | if(preg_match('/(.*)\-\>(.*)\:(.*)/', $option->option_value, $matches)) { |
|---|
| 253 | $content .= canvas_database_plugin($matches, 'radio', $variable->value, $option->option_params); |
|---|
| 254 | } else { |
|---|
| 255 | $content .= '<label><input type="radio" name="'.$variable->variable_name.'" value="'.$option->option_value.'" '; |
|---|
| 256 | if ($option->option_value == $variable->value) $content .= ' checked="checked" '; |
|---|
| 257 | $content .= '/> '.$option->option_text.'</label>'; |
|---|
| 258 | } |
|---|
| 259 | } |
|---|
| 260 | $content .= '</span>'."\n"; |
|---|
| 261 | } elseif(strtolower($variable->type) == 'select') { |
|---|
| 262 | $content .= '<span><p>'.$variable->description.':</p>'; |
|---|
| 263 | |
|---|
| 264 | $options = $wpdb->get_results("SELECT * FROM ".$canvas->options." WHERE var_id = '$variable->variable_id'"); |
|---|
| 265 | |
|---|
| 266 | $content .= '<select name="'.$variable->variable_name.'" id="'.$variable->variable_name.'">'."\n"; |
|---|
| 267 | foreach($options as $option) { |
|---|
| 268 | // If is a Wordpress database variable... |
|---|
| 269 | if(preg_match('/(.*)\-\>(.*)\:(.*)/', $option->option_value, $matches)) { |
|---|
| 270 | $content .= canvas_database_plugin($matches, 'select', $variable->value, $option->option_params); |
|---|
| 271 | } else { |
|---|
| 272 | $content .= '<option value="'.$option->option_value.'" '; |
|---|
| 273 | if ($option->option_value == $variable->value) $content .= ' selected="selected" '; |
|---|
| 274 | $content .= '> '.$option->option_text."</option>\n"; |
|---|
| 275 | } |
|---|
| 276 | } |
|---|
| 277 | $content .= '</select>'."\n"; |
|---|
| 278 | $content .= '</span>'."\n"; |
|---|
| 279 | } elseif(strtolower($variable->type) == 'image') { |
|---|
| 280 | $options = $wpdb->get_results("SELECT * FROM ".$canvas->options." WHERE var_id = '$variable->variable_id'"); |
|---|
| 281 | $content .= '<p>'.$variable->description.':</p>'; |
|---|
| 282 | $content .= '<input type="hidden" id="directory" value="'.$options[0]->option_value.'">'; |
|---|
| 283 | $selected = '<input type="hidden" id="selected_image">'; |
|---|
| 284 | $content .= '<input type="hidden" id="path" name="'.$variable->variable_name.'" value="'.$variable->value.'">'; |
|---|
| 285 | $content .= '<div class="gallery">'; |
|---|
| 286 | $files = scandirectory(ABSPATH.$options[0]->option_value); |
|---|
| 287 | foreach($files as $file) { |
|---|
| 288 | $class = ''; |
|---|
| 289 | if(substr($file, -3) == 'jpg' || substr($file, -3) == 'gif' || substr($file, -3) == 'png') { |
|---|
| 290 | if($options[0]->option_value.$file == $variable->value) { |
|---|
| 291 | $class= 'class="selected_image"'; |
|---|
| 292 | $selected = '<input type="hidden" id="selected_image" value="'.$file.'">'; |
|---|
| 293 | } |
|---|
| 294 | list($width, $height) = @getimagesize(get_bloginfo('wpurl').'/'.$options[0]->option_value.$file); |
|---|
| 295 | if($width > 250) { $height = $height * 250 / $width; $width = 250; } |
|---|
| 296 | $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>'; |
|---|
| 297 | } |
|---|
| 298 | } |
|---|
| 299 | $content .= $selected; |
|---|
| 300 | $content .= '</div>'; |
|---|
| 301 | } elseif(strtolower($variable->type) == 'list') { |
|---|
| 302 | $listitems = explode('|', $variable->value); |
|---|
| 303 | $content .= '<label class="textbox">'.$variable->description.' <small>(Note | is an illegal character)</small></label>'."\n".'<span class="list" id="listlist">'."\n"; |
|---|
| 304 | foreach($listitems as $listitem) { |
|---|
| 305 | $content .= '<span id="'.$variable->variable_name.$counter.'"><input type="text" class="text" name="'.$counter.'canvaslist_'.$variable->variable_name.'" value="'.htmlspecialchars($listitem).'" />'."\n"; |
|---|
| 306 | $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>'; |
|---|
| 307 | $content .= '<a href="javascript:void(0)" onclick="Canvas.removeListItem(this)"><img src="'.CANVASURI.'images/list-delete.png" alt="Delete" title="Delete item"/></a>'; |
|---|
| 308 | $content .= '</span>'; |
|---|
| 309 | $counter++; |
|---|
| 310 | } |
|---|
| 311 | $content .= '</span>'."\n"; |
|---|
| 312 | } |
|---|
| 313 | elseif(strtolower($variable->type) == 'fileupload'){ |
|---|
| 314 | |
|---|
| 315 | $value = attribute_escape($variable->value); |
|---|
| 316 | $path = CANVASURI.'files_flutter/'; |
|---|
| 317 | $valueRelative = $value; |
|---|
| 318 | $value = $path.$value; |
|---|
| 319 | |
|---|
| 320 | $varName = $variable->variable_name; |
|---|
| 321 | $iframePath = CANVASURI."RCCWP_upload.php?input_name=".$varName; |
|---|
| 322 | $content .= '<label class="textbox">'.$variable->description.': </label>'."\n"; |
|---|
| 323 | if($valueRelative) |
|---|
| 324 | $content .= '(<a href="' . $value . '" target="_blank">View Current</a>)'; |
|---|
| 325 | |
|---|
| 326 | echo $content; |
|---|
| 327 | echo |
|---|
| 328 | <<<EOF |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | <input tabindex="3" |
|---|
| 333 | id="$varName" |
|---|
| 334 | name="$varName" |
|---|
| 335 | type="hidden" |
|---|
| 336 | size="46" |
|---|
| 337 | onchange="" |
|---|
| 338 | value="$valueRelative" |
|---|
| 339 | /> |
|---|
| 340 | <p id="upload_progress_$varName" style="visibility:hidden;height:0px"></p> |
|---|
| 341 | |
|---|
| 342 | EOF; |
|---|
| 343 | ?> |
|---|
| 344 | |
|---|
| 345 | <?php |
|---|
| 346 | include_once( "RCCWP_SWFUpload.php" ) ; |
|---|
| 347 | RCCWP_SWFUpload::Body($varName, 0, 1, 10) ; |
|---|
| 348 | $content = ""; |
|---|
| 349 | |
|---|
| 350 | } elseif(strtolower($variable->type) == 'gmodule') { |
|---|
| 351 | //$variable->value WILL THIS BE THE XML FILE? |
|---|
| 352 | $xmlfile = 'http://www.google.com/ig/modules/datetime.xml'; |
|---|
| 353 | $url = 'http://gmodules.com/ig/creator?synd=open&url='.$xmlfile; |
|---|
| 354 | echo '<object id="gmodule_content" data="'.$url.'" type="text/html"></object>'; |
|---|
| 355 | } elseif(strtolower($variable->type) == 'gmodule_script') { |
|---|
| 356 | echo '<input type="text" id="gmodule_script" value="'.$variable->value.'">'; |
|---|
| 357 | } |
|---|
| 358 | } |
|---|
| 359 | //if(count($variables) == 0) echo 'This plugin has no options (yes, it should be a block instead).'; |
|---|
| 360 | |
|---|
| 361 | $content .= '<input type="hidden" id="listcount" name="listcount" value="'.$counter.'">'."\n"; |
|---|
| 362 | $content .= '</form>'."\n"; |
|---|
| 363 | |
|---|
| 364 | echo $content; |
|---|
| 365 | |
|---|
| 366 | ?> |
|---|
| 367 | </div> |
|---|
| 368 | </div> |
|---|