root/afridex/plugins/Flutter/canvas-core.php @ 21

Revision 21, 23.6 kB (checked in by admin, 18 years ago)
Line 
1<?php
2
3/*
4
5___Canvas Core Functions________________________________________
6
7Core functions for generating the Canvas GUI
8and manipulating layout contents.
9
10________________________________________________________________
11
12*/
13
14
15
16require_once('canvas-globals.php');
17require_once('canvas-install.php');
18require_once('canvas-xml.php');
19require_once('canvas-import_functions.php');
20require_once('canvas-admin.php');
21require_once('Ink/ink.php');
22
23define(MODULE_TEMPLATE_SIZE_SMALL, -1);
24define(MODULE_TEMPLATE_SIZE_MEDIUM, -2);
25define(MODULE_TEMPLATE_SIZE_LARGE, -3);
26define(MODULE_TEMPLATE_SIZE_FULL, -4);
27
28
29
30function canvas_build_canvas($curr_page) {
31        global $current_zones, $wpdb, $canvas;
32        if(isset($_GET["template"])) $template = ABSPATH.'wp-content/themes/'.$_GET["template"];
33                else $template = TEMPLATEPATH;
34        if(file_exists($template . "/canvas.php")) {
35                       
36                        if(get_option('canvas_auto_publish') != 'true') echo '<div id="publish"><a href="javascript:void(0)"><img src="'.CANVASURI.'images/publish.gif" title="Publish Your Changes" alt="Publish Changes" id="publish_image" /></a></div>';
37                                else echo '<div id="publish" class="publish_nobutton"></div>';
38                        echo
39<<<EOF
40                        <a id="publish" href="?page=FlutterEditCanvas&defaultmods=1">Load all Default Modules</a>
41                        <a id="publish" href="?page=FlutterEditCanvas&resetmods=1" onclick="return confirmBeforeReset();">Reset Modules</a>
42                        <script type="text/javascript" language="javascript">
43                                function confirmBeforeReset()
44                                {
45                                        return confirm("You're about put all your modules back in the shelf. Are you sure you want to do this?");
46                                }
47                        </script>
48EOF;
49               
50                        include($template . "/canvas.php");
51
52                        //Put modules whose canvas no more exists back to the shelf
53                        $currDBModules = $wpdb->get_results("SELECT block_id, zone FROM ".$canvas->main." WHERE zone <> 'shelf' AND theme = '".get_option('template')."' AND page='$curr_page'"); 
54                        $updated = false;
55                        foreach ($currDBModules as $currDBModule){
56                                $found = false;
57                                foreach($current_zones as $current_zone){
58                                        if ($currDBModule->zone == $current_zone) $found = true;
59                                }
60                                if (!$found){
61                                        $updated = true;
62                                        $wpdb->query("UPDATE ".$canvas->main." SET zone = 'shelf' WHERE block_id = '".$currDBModule->block_id."'");
63                                }
64                        }
65                        if ($updated) {
66                                wp_redirect("?page=FlutterEditCanvas");
67                                return;
68                        }
69                       
70                        echo '<br />'; 
71                } else { canvas_no_theme(); }
72}
73
74function canvas_check_theme() {
75        global $wpdb, $canvas, $table_prefix;
76        $table = $table_prefix . 'ink';
77        $theme = get_option('template');
78
79        $filename = get_template_directory().'/canvas.php';
80
81        // Install Canvas
82        if(!$wpdb->get_results("SELECT block_id FROM ".$canvas->main." WHERE theme = '".get_option('template')."'")){ 
83                //canvas_install();
84                if(file_exists($filename)) {
85                        if(!get_option('canvas_first_install')) update_option('canvas_first_install', time());
86                        if($wpdb->get_results("SELECT block_id FROM ".$canvas->main." WHERE theme = '".get_option('template')."'") && !$wpdb->get_results("SELECT block_id FROM ".$canvas->main." WHERE zone != 'shelf' AND theme = '".get_option('template')."'")) {
87                                $xmlfile = get_template_directory().'/canvas.xml';
88                                if(file_exists($xmlfile)) canvas_import_layout($xmlfile);
89                        }
90                }
91        }
92
93        // Install Ink
94        if (!$wpdb->get_results("SELECT * FROM ".$table." WHERE theme = '$theme'")) {
95                if(file_exists($filename)) {
96                        $file_data = implode('', file($filename));
97                        if(preg_match("|Ink Elements:(.*)|i", $file_data, $ink_string)) $ink_string = trim($ink_string[1]);
98                        if(function_exists('ink_elements')) ink_elements($ink_string);
99                }
100        }
101
102}
103
104function canvas_create_draggable($block_id, $zone, $position, $module_name, $module_title, $content, $type, $group, $template_size, $template_name) {
105
106        // Get plugin sizes
107        $moduleTemplatesFolder = dirname(__FILE__)."/modules/".$module_name."/templates";
108        $moduleTemplateFolder = dirname(__FILE__)."/modules/".$module_name."/templates/default";
109
110        if ($zone=="shelf") $template_name="";
111
112
113        $module_title_min = $module_title;
114        if (strlen($module_title) > 10 ){       
115                $module_title_min = substr($module_title,0,10);//."...";
116        }
117
118        $class = 'container';
119        if($type == 'plugin') $class = 'container-plugin';
120        $class .= ' '.strtolower($group);
121        echo '<div class="'.$class.'" id="canvas_'.$zone.'_'.$position.'_'.$block_id.'" title="'.strip_tags($module_title." - ".$content).'">'."\n";
122        echo '<h6 class="handle"><span>'.$module_title_min.'</span></h6>'."\n";
123        $module_size_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_size';
124        $module_name_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_name';
125        $module_template_name_id = 'canvas_'.$zone.'_'.$position.'_'.$block_id.'_module_template_name';
126//echo($template_size);
127       
128
129        echo 
130<<<EOF
131        <!--<div id="module_size_select" class="module_size_select">
132       
133        <select name="$module_size_id" id="$module_size_id" style="height:18px;font-size:11px;" onchange="Canvas.changePublishImg();">
134                $otherSizesStr
135        </select>
136        <select name="$module_template_name_id" id="$module_template_name_id" style="height:18px;font-size:11px;"  onchange="Canvas.changePublishImg();">
137                $templatesNamesStr
138        </select>
139        </div>--->
140        <input type="hidden" name="$module_size_id" id="$module_size_id" value="$template_size" />
141        <input type="hidden" name="$module_template_name_id" id="$module_template_name_id" value="$template_name" />   
142        <input id="$module_name_id" type="hidden" value="$module_name"/>
143EOF;
144        echo canvas_create_plugin_form($zone, $position, $block_id, $type)."\n";
145        echo '<div class="content">'.$content."</div>\n";
146
147        echo '</div>'."\n";
148}
149
150function canvas_create_management_block($block,$style='',$delete_button='true') {
151        if ($block->is_original) $delete_button='false';
152
153        if($block->uri != '') $link = '<a href="'.$block->uri.'">'.$block->author.'</a>';
154                else $link = $block->author;
155        if($block->type == 'plugin') $class = ' class="plugin '.strtolower($block->block_group).'"';
156                else $class = ' class="'.strtolower($block->block_group).'"';
157        echo "\t".'<li id="block_'.$block->block_id.'"'.$class.$style.'>';
158        if($delete_button == 'true') echo '<a class="delete_block" id="'.$block->block_id.'" href="javascript:void(0)"><img src="'.CANVASURI.'images/delete.png" alt="Delete" title="Delete block"/></a>';
159        echo '<a class="duplicate_block" id="'.$block->block_id.'" href="javascript:void(0)"><img src="'.CANVASURI.'images/duplicate.png" alt="Duplicate" title="Duplicate block"/></a>';
160        echo '<a class="block_info" id="'.$block->block_id.'" href="javascript:void(0)"><img src="'.CANVASURI.'images/block_info.png" alt="Info" title="Block information"/></a>';
161        if ($block->is_original)
162                echo '<h3><span id="title_'.$block->block_id.'">'.$block->module_title.'</span> by '.$link.'.</h3><p>'.wptexturize($block->description).'</p>';
163        else
164                echo '<h3><span class="title" id="title_'.$block->block_id.'">'.$block->module_title.'</span> by '.$link.'.</h3><p>'.wptexturize($block->description).'</p>';
165        echo '<div class="info" id="info_'.$block->block_id.'" style="display: none;"><div>'.
166                        '<strong>Module Folder:</strong> modules/'.$block->module_name.
167                        '<br/><strong>Module ID:</strong> '.$block->block_id.
168                        '<br/><strong>Path:</strong> '.$block->path.
169                        '<br/><strong>Zone:</strong> '.$block->zone.
170                        '<br/><strong>Position:</strong> '.$block->position.
171                        '<br/><strong>Author URI:</strong> '.$block->uri.'</div></div>';
172        echo '</li>'."\n";
173}
174
175function canvas_create_plugin_form($zone,$position,$block_id,$block_type) {
176        if($block_type == 'plugin'){
177                echo '<a href="'.CANVASURI.'canvas-plugin_form.php?zone='.$zone.'&position='.$position.'&block_id='.$block_id.'" class="lbOn"><img class="lbLink" src="'.CANVASURI.'images/plugin_options.gif" title="Module Settings" alt="Module Settings"/></a>';
178                echo '<a href="'.CANVASURI.'canvas-plugin_info.php?block_id='.$block_id.'" class="lbOn"><img class="lbLinkInfo" src="'.CANVASURI.'images/block_info.png" title="Module Information" alt="Module Information"/></a>';
179        }
180}
181
182
183
184function canvas_database_plugin($matches, $type = 'select', $variable_value, $where_cond = '') {
185        global $wpdb, $canvas;
186        $ALLOW_TABLES = array("sitecategories");
187
188        $content = '';
189        if(!isset($matches[3])) $matches[3] = $matches[2];
190        if ($where_cond != '') {
191                $where_cond = str_replace('%prefix%', $wpdb->prefix, $where_cond);
192                $where_cond = " WHERE " . $where_cond;
193        }
194
195
196        // We need to find out whether the table name requires user prefix or global prefix
197        $req_table_prefix = $wpdb->prefix;
198        if (!$wpdb->get_var("SHOW TABLES LIKE '".$req_table_prefix.$matches[1]."'") == $req_table_prefix.$matches[1]){
199                if (in_array($matches[1], $ALLOW_TABLES))
200                        $req_table_prefix = (isset($wpdb->base_prefix)?$wpdb->base_prefix:$wpdb->prefix);
201        }
202       
203
204        if($wpdb->get_var("SHOW TABLES LIKE '".$req_table_prefix.$matches[1]."'") == $req_table_prefix.$matches[1]) {
205                //echo("<br/>SELECT ".$matches[2].", ".$matches[3]." FROM ".$req_table_prefix.$matches[1]."  TBL ".$where_cond);
206                if($data = $wpdb->get_results("SELECT ".$matches[2].", ".$matches[3]." FROM ".$req_table_prefix.$matches[1]."  TBL ".$where_cond)) {
207                        foreach($data as $row) {
208                                if($type == 'select') {
209                                        $content .= '<option value="'.$row->$matches[3].'" ';
210                                        if ($row->$matches[3] == $variable_value) $content .= ' selected="selected" ';
211                                        $content .= '>&nbsp;'.$row->$matches[2]."</option>\n";
212                                } elseif($type == 'radio') {
213                                        $content .= '<label><input type="radio" value="'.$row->$matches[3].'" ';
214                                        if ($row->$matches[3] == $variable_value) $content .= ' checked="checked" ';
215                                        $content .= '/>&nbsp;'.$row->$matches[2].'</label>';
216                                }
217                        }
218                }
219        }
220       
221        return $content;
222}
223
224
225/**
226*       
227*       @param $zone_name (String) The zone name
228*       @param $template_name (String) The name of the template to grab. The default value is "default".
229*       @param $template_size (Integer) Grabs the specified version of the template. The default value is MODULE_TEMPLATE_SIZE_SMALL. The value of $template_size could be
230*               - MODULE_TEMPLATE_SIZE_SMALL, MODULE_TEMPLATE_SIZE_MEDIUM, MODULE_TEMPLATE_SIZE_LARGE, or MODULE_TEMPLATE_SIZE_FULL.
231*               - The maximum width of the module that can be placed in this canvas.
232*       @param $allow_other_sizes (Boolean) If you tried to put a version of a module larger the zone version, and this value is set to True, it will just give a warning. Otherwise, it will give error. The default value is true.
233*       @param $default_module (String) This will bring up a certain module by default.
234*       @param $allow_other_modules (Boolean) If set to True, then the admin can put another module in the space. Otherwise, you shouldn’t be able to move the module. The default value is true.
235*       @param $styles (String) A string that will be printed in the style attribute of the canvas div. 
236**/
237
238function canvas_define_zone($zone_name, $template_name = "default", $template_size = MODULE_TEMPLATE_SIZE_SMALL, $allow_other_sizes = TRUE, $default_module = '', $allow_other_modules = TRUE, $styles='') {
239        $parent='';
240        global $zones, $parents, $current_zones;
241        $current_zones[] = $zone_name;
242        if($_GET["template"] != '') $theme = $_GET["template"];
243                else $theme = get_option('template');
244        $parents[] = $parent;
245        $zones[] = $zone_name;
246        echo '<div class="canvas_droppable_zone '.$zone_name.'" id="'.$zone_name.'"';
247        if($styles != '') echo ' style="'.$styles.'"';
248        echo '>'."\n";
249        get_canvas_draggables($zone_name, $theme);
250        echo '<input type="hidden" id="'.$zone_name.'_template_name" value="'.$template_name.'" />';
251        echo '<input type="hidden" id="'.$zone_name.'_template_size" value="'.$template_size.'" />';
252        echo '<input type="hidden" id="'.$zone_name.'_allow_other_sizes" value="'.$allow_other_sizes.'" />';
253        echo '<input type="hidden" id="'.$zone_name.'_allow_other_modules" value="'.$allow_other_modules.'" />';
254        echo '<input type="hidden" id="'.$zone_name.'_default_module" value="'.$default_module.'" />';
255        echo '</div>'."\n";
256}
257
258function canvas_execute_function($function_name, $block_id) {
259        global $wpdb, $canvas;
260        if($var_data = $wpdb->get_results("SELECT variable_name, value, type FROM ".$canvas->variables." WHERE parent = '$block_id'")) {
261                $url_string = '';
262                $vars = array();
263                if (!empty($var_data)) {
264                  foreach($var_data as $var) {
265                        $url_string .= '&'.$var->variable_name.'='.$var->value;
266                        //if ($function_name)
267                        //      $vars[str_replace($function_name.'_', '', $var->variable_name)] = $var->value;
268                        //else
269                        switch($var->type){
270                                case 'fileupload':
271                                        $vars[$var->variable_name] = FLUTTER_URI.'files_flutter/'.$var->value;
272                                        break;
273                                default:
274                                        $vars[$var->variable_name] = $var->value;
275                        }
276                  }
277               
278
279                  $url_string = str_replace($function_name.'_', '', $url_string);
280                  $url_string .= '&block_id='.$block_id;
281                }
282                $url_string = substr($url_string, 1);
283                if(is_callable($function_name)) $function_name($url_string, $vars);
284        }
285        return $vars;
286}
287
288function canvas_getNodeByAttr($attr, $nodeID, $xmldoc) {
289        if ($xmldoc->hasChildNodes()) {
290                $children = $xmldoc->childNodes;
291                foreach($children as $node) {
292                        if($node->hasAttributes()) {
293                                $attributes = $node->attributes;
294                                foreach ($attributes as $attribute) {
295                                        if(($attribute->name == $attr) && (stripos($attribute->value, $nodeID)) !== false) {
296                                                return $node;
297                                        } else {
298                                                if(canvas_getNodeByAttr($attr,$nodeID,$node))
299                                                        return canvas_getNodeByAttr($attr,$nodeID,$node);
300                                        }
301                                }
302                        } else {
303                                if(canvas_getNodeByAttr($attr,$nodeID,$node))
304                                        return canvas_getNodeByAttr($attr,$nodeID,$node);
305                        }
306                }
307        } else {
308                return null;
309        }
310}
311
312function canvas_head() {
313        global $installed, $canvas, $wpdb;
314        $load_default_modules = 0;
315
316        if($_GET["resetmods"]){
317                $wpdb->query("UPDATE ".$canvas->main." SET zone = 'shelf', template_name='', template_size=''");
318                $wpdb->query("UPDATE ".$canvas->variables." SET default_value = '__RESETDEFAULT__'");
319                echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=?page=FlutterEditCanvas&resetmodsmsg=1">';
320                //wp_redirect("?page=FlutterEditCanvas&resetmodsmsg=1");
321                die();
322        }
323
324        if ($wpdb->get_results("SELECT block_id FROM ".$canvas->main." WHERE theme = '".get_option('template')."' AND zone <>'shelf'")) {
325                $load_default_modules = 0;
326        }
327        else{
328                $load_default_modules = 1;
329        }
330        if(isset($_GET["defaultmods"])) $load_default_modules = 1; 
331
332        if($_GET["page"] == 'FlutterEditCanvas' || $_GET["page"] == 'FlutterInk') : 
333
334
335                                        ?>
336<link rel="stylesheet" href="<?php echo CANVASURI; ?>stylesheet.css" type="text/css" media="screen" />
337<link rel="stylesheet" href="<?php echo CANVASURI; ?>lightbox.css" type="text/css" media="screen" />
338                <?php if(!isset($_GET["template"])) : ?>
339<link rel="stylesheet" href="<?php bloginfo('stylesheet_directory') ?>/canvas.css" type="text/css" media="screen" />
340                <?php else : ?>
341<link rel="stylesheet" href="<?php echo get_bloginfo('wpurl').'/wp-content/themes/'.$_GET["template"]; ?>/canvas.css" type="text/css" media="screen" />
342                <?php endif; ?>
343<script language="JavaScript" type="text/javascript" > 
344        JS_CANVASURI="<?php echo CANVASURI; ?>";
345
346        // The following piece of code checks whether 'www' is included in teh original URL or not,
347        // The AJAX js must be called from exactl same URL, otherwise the browser will prevent it
348        // for security reason (calling a URL from another place).
349        var originalHost = location.host;
350        if (originalHost.substring(0,4) == "www."){
351                if (JS_CANVASURI.indexOf("://www.") == -1)
352                        alert("The registered URL in wordpress does not have a 'www', please remove 'www' from the URL.");
353        }
354        else {
355                if (JS_CANVASURI.indexOf("://www.") > -1)
356                        alert("The registered URL in wordpress has a 'www', please add 'www' to the URL.");
357        }
358
359
360        LOAD_DEFAULT_MODULES=<?php echo $load_default_modules; ?>;
361</script>
362<script language="JavaScript" type="text/javascript" src="<?php echo CANVASURI; ?>js/prototype.js"></script>
363<script language="JavaScript" type="text/javascript" src="<?php echo CANVASURI; ?>js/scriptaculous/scriptaculous.js"></script>
364<script language="JavaScript" type="text/javascript" src="<?php echo CANVASURI; ?>js/lightbox.js"></script>
365<script language="JavaScript" type="text/javascript" src="<?php echo CANVASURI; ?>js/canvas-ajax.js.php"></script>
366        <?php endif;
367        if($_GET["content"] == 'manage') : ?>
368<script language="JavaScript" type="text/javascript" src="<?php echo CANVASURI; ?>js/canvas-management.js"></script>
369        <?php endif;
370        if($_GET["content"] == 'options') : ?>
371<script language="JavaScript" type="text/javascript" src="<?php echo CANVASURI; ?>js/canvas-options.js"></script>
372        <?php endif;
373}
374
375function canvas_include_block($filename) {
376        include($filename);
377}
378
379function canvas_interrupt() {
380        if(file_exists(get_template_directory().'/canvas.php'))
381                ob_start();
382}
383
384function canvas_no_theme() {
385        $theme = current_theme_info();
386        echo '<div class="wrap"><h2>Theme Not Supported</h2><p>The theme you are currently using ('.$theme->title.' by '.$theme->author.') doesn\'t seem to support Canvas. At this point in the game, Canvas only supports themes that are built to run with the Canvas layout and styling system. To use Canvas, you\'ll have to either <a href="themes.php">select</a> a different theme from your collection.</p>';
387        $themes = get_themes();
388        $theme_names = array_keys($themes);
389        natcasesort($theme_names);
390        $canvas_themes = array();
391        foreach($theme_names as $index => $theme_name) {
392                $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
393                if(file_exists(ABSPATH . $stylesheet_dir . '/canvas.php')) {
394                        $canvas_themes[$index]['title'] = $themes[$theme_name]['Title'];
395                        $canvas_themes[$index]['template'] = $themes[$theme_name]['Template'];
396                        $canvas_themes[$index]['directory'] = $stylesheet_dir;
397                }
398        }
399        if(!empty($canvas_themes)) {
400                echo '<p>Although your current theme isn\'t compatible, you do have some Canvas compatible themes available. Select a theme from the listing below to edit an inactive theme.</p>'."\n";
401                foreach($canvas_themes as $theme) {
402                        $link = 'themes.php?page=Main.php&amp;template='.$theme['template'];
403                        echo '<h3><p><a href="'.$link.'">&raquo; '.$theme['title'].'</a></p></h3>'."\n";
404                }
405        }
406        echo '</div>'."\n";
407}
408
409function canvas_show_zone_options($zone, $theme) {
410        $content_position = canvas_zone_handler($zone);
411       
412        if(true) {return; $display = ' style="display: none;"'; $toggle_style = ' style="background-color: #cfcfcf;"'; }
413                else { $display = ''; $toggle_style = ''; }
414        $content = '<h8 id="togglezoneoption_'.$zone.'"'.$toggle_style.'></h8>'."\n";
415        $content .= '<span class="canvas_zone_options" id="options_'.$zone.'"'.$display.'>'."\n";
416        $content .= '<select class="zone_content_options" id="zoneoption_'.$zone.'" name="zoneoption_'.$zone.'">'."\n";
417        $content .= '<option value="before">Insert blocks before original content.'."\n";
418        $content .= '<option value="append">Insert blocks after original content.'."\n";
419        $content .= '<option value="replace">Replace original content.'."\n";
420        $content .= '</select>'."\n";
421        $content .= '<img src="'.CANVASURI.'images/replace_up.png" title="Replace original content" onclick="Canvas.zoneHandler(\''.$zone.'\', \'replace\')" />';
422        $content .= '<img src="'.CANVASURI.'images/append_up.png" title="Insert after original content" onclick="Canvas.zoneHandler(\''.$zone.'\', \'append\')" />';
423        $content .= '<img src="'.CANVASURI.'images/before_up.png" title="Insert before original content" onclick="Canvas.zoneHandler(\''.$zone.'\', \'before\')" />';
424        $content .= '</span>'."\n";
425        if($content_position != '') $content = str_replace($content_position.'_up', $content_position.'_down', $content);
426        $content = str_replace('value="'.$content_position.'"', 'value="'.$content_position.'" selected="selected"', $content);
427
428        echo $content;
429}
430
431function mod_var($var_name){
432        global $mod_vars; 
433        //return $mod_vars[$function_name][$var_name];
434        return $mod_vars[$var_name];
435}
436
437/**
438*       Used inside any theme file in order to display a canvas whenever this page is displayed.
439*       
440**/
441function canvas_zone($zone_name) {
442        global $wpdb, $canvas;
443        if($zone_data = $wpdb->get_results("SELECT module_id, block_id, path, type, position, zone, template_name, template_size FROM ".$canvas->main." WHERE zone = '$zone_name' AND theme = '".get_option('template')."' ORDER BY position")) {
444                foreach($zone_data as $zone) {
445
446                        // Get module name
447                        include_once('RCCWP_CustomWriteModule.php');
448                        $customWriteModule = RCCWP_CustomWriteModule::Get($zone->module_id);
449                        $zone->module_name = $customWriteModule->name;
450
451                        $dir = get_module_template_folder($zone->module_name, $zone->template_name, $zone->template_size);
452                        global $mod_vars;
453                        $mod_vars = canvas_execute_function($zone->path, $zone->block_id);
454                        if (!file_exists($dir.'default.php')) return;
455                        include($dir.'default.php');
456
457                }
458        }
459}
460
461
462/**
463*       Used inside any theme file in order to grab the specified module directly without the need to define it in the canvas.php.
464*       
465*       @param $module_name (String) The zone name
466*       @param $template_name (String) The name of the template to grab. The default value is "default".
467*       @param $template_size (Integer) Grabs the specified version of the template. The default value is "small".
468**/
469
470function get_module($module_name, $template_name = "default", $template_size = MODULE_TEMPLATE_SIZE_SMALL) {
471        global $wpdb, $canvas;
472       
473        // Load variables
474        global $mod_vars;
475        include_once("RCCWP_CustomWriteModule.php");
476        $mod = RCCWP_CustomWriteModule::GetByName($module_name);
477        $mod_vars = canvas_execute_function('', $mod->id);
478
479        // Load template file
480        $dir = get_module_template_folder($module_name, $template_name, $template_size)  ;
481        if (!file_exists($dir.'default.php')) return;
482        include($dir.'default.php');
483}
484
485
486function get_module_template_folder($module_name, $template_name, $template_size) {
487        switch($template_size){
488                case MODULE_TEMPLATE_SIZE_SMALL:
489                        $template_size = "small";
490                        break;
491                case MODULE_TEMPLATE_SIZE_MEDIUM:
492                        $template_size = "medium";
493                        break;
494                case MODULE_TEMPLATE_SIZE_LARGE:
495                        $template_size = "large";
496                        break;
497                case MODULE_TEMPLATE_SIZE_FULL:
498                        $template_size = "full";
499                        break;
500        }
501
502        if (empty($template_size))
503                $template_size = "small";
504
505        if (empty($template_name))
506                $template_name = "default";
507
508        return CANVASPATH.'/modules/'.$module_name.'/templates/'.$template_name.'/'.$template_size.'/'  ;
509}
510
511function canvas_zone_handler($zone) {
512        global $wpdb, $canvas;
513        $position = $wpdb->get_var("SELECT value FROM ".$canvas->zone_options." WHERE option_name = 'zone_handler' AND zone = '$zone' AND theme = '".get_option('template')."'");
514        if($position != '') return $position;
515                else return 'before';
516}
517
518function get_canvas_draggables($zone, $theme = '') {
519        include_once('RCCWP_Options.php');
520
521        if (isset($_GET['t_page'])) 
522                $curr_page = $_GET['t_page'];
523        else
524                $curr_page = 'home'; // Attempt to find the main page
525       
526        if(RCCWP_Options::Get('canvas_show_zone_name') && $zone != 'shelf') echo '<strong>'.$zone.'</strong>';
527        if($zone != 'shelf') canvas_show_zone_options($zone, $theme);
528        if($theme == '') $theme = get_option('template');
529        global $wpdb, $canvas; 
530        if($wpdb->get_var("SHOW TABLES LIKE '".$canvas->main."'") == $canvas->main)
531                $results = $wpdb->get_results("SELECT * FROM ".$canvas->main." WHERE theme = '$theme' AND page='$curr_page' AND zone LIKE '$zone' ORDER BY position");
532
533        if ($results) {
534                foreach($results as $result) {
535                        // Get module name
536                        include_once('RCCWP_CustomWriteModule.php');
537                        $customWriteModule = RCCWP_CustomWriteModule::Get($result->module_id);
538                        $result->module_name = $customWriteModule->name;
539                        $result->description = $customWriteModule->description;
540                        if ($result->duplicate_id ==0 )
541                                $result->module_title = $customWriteModule->name;
542                        else
543                                $result->module_title = $wpdb->get_var("SELECT duplicate_name FROM ".$canvas->duplicates." WHERE duplicate_id = ".$result->duplicate_id);
544                        canvas_create_draggable($result->block_id, $zone, $result->position, $result->module_name, $result->module_title, '<p>'.$result->description.'</p>', $result->type, $result->block_group, $result->template_size, $result->template_name);
545                }
546        }
547}
548
549
550if(!function_exists('htmlspecialchars_decode')) {
551        function htmlspecialchars_decode($str, $quote_style = ENT_COMPAT) {
552                return strtr($str, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
553        }
554}
555
556
557
558
559
560?>
Note: See TracBrowser for help on using the browser.