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

Revision 21, 5.4 kB (checked in by admin, 18 years ago)
RevLine 
[21]1<?php
2
3/*
4
5___Canvas Installation Scripts__________________________________
6
7Creates the necessary SQL tables for a clean Canvas install.
8
9________________________________________________________________
10
11*/
12
13
14function canvas_clean_install() {
15    global $wpdb, $canvas;
16        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->main."");
17        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->variables."");
18        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->options."");
19        canvas_install();
20        return true;
21}
22
23function canvas_clean_deactivate() {
24        global $wpdb, $canvas;
25        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->main."");
26        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->duplicates."");
27        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->variables."");
28        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->options."");
29        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->zone_options."");
30        $wpdb->query("DROP TABLE IF EXISTS ".$canvas->ink."");
31
32        return true;
33}
34
35
36
37function canvas_create_db() {
38        global $wpdb, $canvas;
39
40        ${$canvas->main} = "CREATE TABLE ".$canvas->main." (
41                block_id INT NOT NULL AUTO_INCREMENT,
42                PRIMARY KEY(block_id),
43                        module_id INT NOT NULL,
44                        type tinytext NOT NULL,
45                        zone tinytext NOT NULL,
46                        position int(6) NOT NULL,
47                        author tinytext NOT NULL,
48                        description text NOT NULL,
49                        block_group tinytext NOT NULL,
50                        uri text NOT NULL,
51                        path text NOT NULL,
52                        theme tinytext NOT NULL,
53                        ubi text NOT NULL,
54                        template_name text NOT NULL,
55                        template_size text NOT NULL,
56                        duplicate_id INT NOT NULL,
57                        page text NOT NULL
58                        );";
59
60        ${$canvas->duplicates} = "CREATE TABLE ".$canvas->duplicates." (
61                duplicate_id INT NOT NULL AUTO_INCREMENT,
62                PRIMARY KEY(duplicate_id),
63                        module_id INT NOT NULL,
64                        duplicate_name text NOT NULL
65                        );";
66
67
68        ${$canvas->variables} = "CREATE TABLE ".$canvas->variables." (
69                        variable_id INT NOT NULL AUTO_INCREMENT,
70                        PRIMARY KEY(variable_id),
71                        variable_name text NOT NULL,
72                        parent INT NOT NULL,
73                        type text NOT NULL,
74                        value text NOT NULL,
75                        default_value text NOT NULL,
76                        description text NOT NULL
77                        );";
78
79        ${$canvas->options} = "CREATE TABLE ".$canvas->options." (
80                        option_id INT NOT NULL AUTO_INCREMENT,
81                        PRIMARY KEY(option_id),
82                        var_id INT NOT NULL,
83                        option_text text NOT NULL,
84                        option_value text NOT NULL,
85                        option_params text NOT NULL
86                        );";
87
88        ${$canvas->zone_options} = "CREATE TABLE ".$canvas->zone_options." (
89                        option_id INT NOT NULL AUTO_INCREMENT,
90                        PRIMARY KEY(option_id),
91                        zone text NOT NULL,
92                        option_name text NOT NULL,
93                        value text NOT NULL,
94                        theme text NOT NULL
95                        );";
96
97        ${$canvas->ink} = "CREATE TABLE ".$canvas->ink." (
98                element_id INT NOT NULL AUTO_INCREMENT,
99                PRIMARY KEY(element_id),
100                        element text NOT NULL,
101                        theme text NOT NULL,
102                        color text NOT NULL,
103                        background text NOT NULL,
104                        border text NOT NULL,
105                        font_family text NOT NULL,
106                        font_size text NOT NULL,
107                        font_style text NOT NULL,
108                        other text NOT NULL
109                        );";
110
111        // try to get around
112        // these includes like http://trac.mu.wordpress.org/ticket/384
113        // and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
114
115        if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
116                require_once(ABSPATH . 'wp-includes/pluggable.php');
117        } else {
118                require_once(ABSPATH . 'wp-includes/pluggable-functions.php');
119        }
120        require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
121       
122        foreach($canvas as $table)
123                dbDelta(${$table});
124       
125        return;
126}
127
128function canvas_install($DBChanged=false) {
129        global $wpdb, $canvas; //, $installed, $canvas_external_plugins;
130       
131        if(!$wpdb->get_var("SHOW TABLES LIKE '".$canvas->main."'") == $canvas->main ||
132                        $DBChanged) {
133                canvas_create_db();
134                update_option('RC_CWP_BLOG_DB_VERSION', RC_CWP_DB_VERSION);
135                ink_clean_install();
136                //canvas_check_theme();
137               
138               
139                update_option('canvas_auto_publish','false'); // for future releases
140
141                /*if(file_exists(get_template_directory().'/canvas.php') && !$wpdb->get_results("SELECT block_id FROM ".$canvas->main." WHERE theme = '".get_option('template')."'")) {
142                        $position = 1;
143                        $canvas_dir = CANVASPATH.'/modules/';
144                        list($plugins, $position) = canvas_import_plugins($position, $canvas_dir);
145                } elseif(file_exists(get_template_directory().'/canvas.php')) {
146                        canvas_reload();
147                }*/
148
149               
150
151        }
152       
153        return true;
154}
155
156
157function canvas_reload() {
158        global $wpdb, $canvas, $canvas_external_plugins;
159        $current_blocks = $wpdb->get_results("SELECT block_id, path FROM ".$canvas->main." WHERE theme = '".get_option('template')."' AND type = 'block'");
160        $current_plugins = $wpdb->get_results("SELECT block_id, path FROM ".$canvas->main." WHERE theme = '".get_option('template')."' AND type = 'plugin'");
161        $positions = $wpdb->get_var("SELECT MAX(position) FROM ".$canvas->main." WHERE theme = '".get_option('template')."' AND zone = 'shelf'");
162        if($positions) $position = $positions->position;
163                else $position = 1;
164        $block_count = 0; $plugin_count = 0;
165        foreach($current_blocks as $block) {
166                $current_block_paths[] = $block->path;
167        }
168        foreach($current_plugins as $plugin) {
169                $current_plugin_paths[] = $plugin->path;
170        }
171
172        // Search for modules
173        $dir = CANVASPATH.'/modules/';
174        canvas_import_plugins($position, $dir);
175               
176
177        if($block_count > 0 || $plugin_count > 0) $message = '<p>Installed '.$block_count.' blocks and '.$plugin_count.' plugins.</p>';
178                else $message = '<p>No new blocks or plugins found.</p>';
179
180        return $message;
181}
182
183?>
Note: See TracBrowser for help on using the browser.