source: branches/1.4/install/install_tables.php @ 2000

Revision 2000, 30.0 KB checked in by shibuya246, 3 years ago (diff)

[Branch 1.4] change post_title column from navchar to text

Line 
1<?php
2/**
3 * Install database tables for Hotaru CMS.
4 *
5 * Steps through the set-up process, creating database tables and registering
6 * the Admin user. Note: You must delete this file after installation as it
7 * poses a serious security risk if left.
8 *
9 * PHP version 5
10 *
11 * LICENSE: Hotaru CMS is free software: you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, either version 3 of
14 * the License, or (at your option) any later version.
15 *
16 * Hotaru CMS is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with Hotaru CMS. If not, see http://www.gnu.org/licenses/.
22 *
23 * @category  Content Management System
24 * @package   HotaruCMS
25 * @author    Nick Ramsay <admin@hotarucms.org>
26 * @copyright Copyright (c) 2010, Hotaru CMS
27 * @license   http://www.gnu.org/copyleft/gpl.html GNU General Public License
28 * @link      http://www.hotarucms.org/
29 */
30
31/**
32 * Create database tables
33 *
34 * @param string $table_name
35 *
36 * Note: Deletes the table if it already exists, then makes it again
37 */
38function create_table($table_name)
39{
40        global $db, $lang, $h;
41       
42        $sql = 'DROP TABLE IF EXISTS `' . DB_PREFIX . $table_name . '`;';
43        $db->query($sql);
44
45        // BLOCKED TABLE - blocked IPs, users, email types, etc...
46       
47        if ($table_name == "blocked") {
48                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
49                        `blocked_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
50                        `blocked_type` varchar(64) NULL,
51                        `blocked_value` text NULL,
52                        `blocked_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
53                        `blocked_updateby` int(20) NOT NULL DEFAULT 0,
54                        `blocked_siteid` int(20) NOT NULL DEFAULT 1,
55                        INDEX (`blocked_siteid`),
56                        INDEX  (`blocked_type`)
57                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Blocked IPs, users, emails, etc';";
58                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
59                $db->query($sql);
60
61        }
62       
63       
64        // CATEGORIES TABLE - categories
65       
66        if ($table_name == "categories") {
67                //echo "table doesn't exist. Stopping before creation."; exit;
68                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
69                        `category_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
70                        `category_parent` int(11) NOT NULL DEFAULT '1',
71                        `category_name` varchar(64) NOT NULL DEFAULT '',
72                        `category_safe_name` varchar(64) NOT NULL DEFAULT '',
73                        `rgt` int(11) NOT NULL DEFAULT '0',
74                        `lft` int(11) NOT NULL DEFAULT '0',
75                        `category_order` int(11) NOT NULL DEFAULT '0',
76                        `category_desc` text NULL,
77                        `category_keywords` varchar(255) NOT NULL,
78                        `category_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
79                        `category_updateby` int(20) NOT NULL DEFAULT 0,
80                        `category_siteid` int(20) NOT NULL DEFAULT 1,
81                        INDEX (`category_siteid`),
82                        UNIQUE KEY `key` (`category_name`, `category_siteid`)
83                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Categories';";
84                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
85                $db->query($sql);
86               
87                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (category_name, category_safe_name) VALUES (%s, %s)";
88                $db->query($db->prepare($sql, urlencode('All'), urlencode('all')));
89        }
90
91
92        // COMMENTS TABLE - comments
93       
94        if ($table_name == "comments") {
95                //echo "table doesn't exist. Stopping before creation."; exit;
96                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
97                        `comment_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
98                        `comment_archived` enum('Y','N') NOT NULL DEFAULT 'N',
99                        `comment_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
100                        `comment_post_id` int(20) NOT NULL DEFAULT '0',
101                        `comment_user_id` int(20) NOT NULL DEFAULT '0',
102                        `comment_parent` int(20) DEFAULT '0',
103                        `comment_date` timestamp NOT NULL,
104                        `comment_status` varchar(32) NOT NULL DEFAULT 'approved',
105                        `comment_content` text NOT NULL,
106                        `comment_votes_up` smallint(11) NOT NULL DEFAULT '0',
107                        `comment_votes_down` smallint(11) NOT NULL DEFAULT '0',
108                        `comment_subscribe` tinyint(1) NOT NULL DEFAULT '0',
109                        `comment_updateby` int(20) NOT NULL DEFAULT 0,
110                        `comment_siteid` int(20) NOT NULL DEFAULT 1,
111                        INDEX (`comment_siteid`),
112                        FULLTEXT (`comment_content`),
113                        INDEX  (`comment_archived`),
114                        INDEX  (`comment_post_id`),
115                        INDEX  (`comment_status`)
116                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Post Comments';";
117                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
118                $db->query($sql);
119        }
120       
121       
122        // COMMENT VOTES TABLE - comment votes
123       
124        if ($table_name == "commentvotes") {
125                //echo "table doesn't exist. Stopping before creation."; exit;
126                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
127                        `cvote_archived` enum('Y','N') NOT NULL DEFAULT 'N',
128                        `cvote_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
129                        `cvote_post_id` int(11) NOT NULL DEFAULT '0',
130                        `cvote_comment_id` int(11) NOT NULL DEFAULT '0',
131                        `cvote_user_id` int(11) NOT NULL DEFAULT '0',
132                        `cvote_user_ip` varchar(32) NOT NULL DEFAULT '0',
133                        `cvote_date` timestamp NOT NULL,
134                        `cvote_rating` smallint(11) NOT NULL DEFAULT '0',
135                        `cvote_reason` tinyint(3) NOT NULL DEFAULT 0,
136                        `cvote_updateby` int(20) NOT NULL DEFAULT 0
137                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Comment Votes';";
138                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
139                $db->query($sql);
140        }
141       
142       
143        // FRIENDS TABLE
144       
145                if ($table_name == "friends") {
146                //echo "table doesn't exist. Stopping before creation."; exit;
147                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
148                        `follower_user_id` int(20) NOT NULL default '0',
149                        `following_user_id` int(20) NOT NULL default '0',
150                        `friends_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
151                        PRIMARY KEY (follower_user_id, following_user_id)
152                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Friends';";
153                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
154                $db->query($sql);
155                }
156               
157               
158        // MESSAGING TABLE
159       
160                if ($table_name == "messaging") {
161                //echo "table doesn't exist. Stopping before creation."; exit;
162                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
163                        `message_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
164                        `message_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
165                        `message_archived` enum('Y','N') NOT NULL DEFAULT 'N',
166                        `message_from` int(20) NOT NULL DEFAULT 0,
167                        `message_to` int(20) NOT NULL DEFAULT 0,
168                        `message_date` timestamp NOT NULL,
169                        `message_subject` varchar(255) NOT NULL DEFAULT '',
170                        `message_content` text NULL,
171                        `message_read` tinyint(1) NOT NULL DEFAULT '0',
172                        `message_inbox` tinyint(1) NOT NULL DEFAULT '1',
173                        `message_outbox` tinyint(1) NOT NULL DEFAULT '1',
174                        `message_updateby` int(20) NOT NULL DEFAULT 0,
175                        INDEX  (`message_archived`)
176                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Messaging';";
177                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
178                $db->query($sql);
179                }
180
181
182        // MISCDATA TABLE - for storing default permissions, etc.
183       
184        if ($table_name == "miscdata") {
185                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
186                        `miscdata_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
187                        `miscdata_key` varchar(64) NOT NULL,
188                        `miscdata_value` text NOT NULL DEFAULT '',
189                        `miscdata_default` text NOT NULL DEFAULT '',
190                        `miscdata_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
191                        `miscdata_updateby` int(20) NOT NULL DEFAULT 0,
192                        `miscdata_siteid` int(20) NOT NULL DEFAULT 1,
193                        INDEX (`miscdata_siteid`)
194                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Miscellaneous Data';";
195                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
196                $db->query($sql);
197               
198                // Add Hotaru version number to the database (referred to when upgrading)
199                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (miscdata_key, miscdata_value, miscdata_default) VALUES (%s, %s, %s)";
200                $db->query($db->prepare($sql, 'hotaru_version', $h->version, $h->version));
201               
202                // Default permissions
203                $perms['options']['can_access_admin'] = array('yes', 'no');
204                $perms['can_access_admin']['admin'] = 'yes';
205                $perms['can_access_admin']['supermod'] = 'yes';
206                $perms['can_access_admin']['default'] = 'no';
207                $perms = serialize($perms);
208               
209                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (miscdata_key, miscdata_value, miscdata_default) VALUES (%s, %s, %s)";
210                $db->query($db->prepare($sql, 'permissions', $perms, $perms));
211               
212                // default settings
213                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (miscdata_key, miscdata_value, miscdata_default) VALUES (%s, %s, %s)";
214                $db->query($db->prepare($sql, 'user_settings', '', ''));
215               
216                // site announcement
217                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (miscdata_key, miscdata_value, miscdata_default) VALUES (%s, %s, %s)";
218                $db->query($db->prepare($sql, 'site_announcement', '', ''));
219        }
220       
221       
222        // PLUGINS TABLE
223        // @TODO Move plugin_enabled and plugin_order to PLUGIN_SETTINGS TABLE
224
225        if ($table_name == "plugins") {
226                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
227                        `plugin_id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
228                        `plugin_enabled` tinyint(1) NOT NULL DEFAULT '0',
229                        `plugin_name` varchar(64) NOT NULL DEFAULT '',
230                        `plugin_folder` varchar(64) NOT NULL DEFAULT '',
231                        `plugin_class` varchar(64) NOT NULL DEFAULT '',
232                        `plugin_extends` varchar(64) NOT NULL DEFAULT '',
233                        `plugin_type` varchar(32) NOT NULL DEFAULT '',
234                        `plugin_desc` varchar(255) NOT NULL DEFAULT '',
235                        `plugin_requires` varchar(255) NOT NULL DEFAULT '',
236                        `plugin_version` varchar(32) NOT NULL DEFAULT '0.0',
237                        `plugin_order` int(11) NOT NULL DEFAULT 0,
238                        `plugin_author` varchar(32) NOT NULL DEFAULT '',
239                        `plugin_authorurl` varchar(128) NOT NULL DEFAULT '',
240                        `plugin_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
241                        `plugin_updateby` int(20) NOT NULL DEFAULT 0,
242                        `plugin_latestversion` varchar(8) NOT NULL DEFAULT '0.0',
243                        `plugin_siteid` int(20) NOT NULL DEFAULT 1,
244                        INDEX (`plugin_siteid`),
245                        UNIQUE KEY `key` (`plugin_folder`, `plugin_siteid`)
246                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Application Plugins';";
247                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
248                $db->query($sql);
249        }
250       
251        // PLUGIN HOOKS TABLE
252       
253        if ($table_name == "pluginhooks") {
254                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
255                        `phook_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
256                        `plugin_folder` varchar(64) NOT NULL DEFAULT '',
257                        `plugin_hook` varchar(128) NOT NULL DEFAULT '',
258                        `plugin_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
259                        `plugin_updateby` int(20) NOT NULL DEFAULT 0,
260                        `pluginhooks_siteid` int(20) NOT NULL DEFAULT 1,
261                        INDEX  (`plugin_folder`),
262                        INDEX (`pluginhooks_siteid`)
263                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Plugins Hooks';";
264                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
265                $db->query($sql);
266        }
267       
268        // PLUGIN SETTINGS TABLE
269       
270        if ($table_name == "pluginsettings") {
271                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
272                        `psetting_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
273                        `plugin_folder` varchar(64) NOT NULL,
274                        `plugin_setting` varchar(64) NULL,
275                        `plugin_value` text NULL,
276                        `plugin_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
277                        `plugin_updateby` int(20) NOT NULL DEFAULT 0,
278                        `plugin_siteid` int(20) NOT NULL DEFAULT 1,
279                        INDEX (`plugin_siteid`),
280                        INDEX  (`plugin_folder`)
281                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Plugins Settings';";
282                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
283                $db->query($sql);
284        }
285       
286       
287        // POSTS TABLE - stories/news
288       
289        if ($table_name == "posts") {
290                //echo "table doesn't exist. Stopping before creation."; exit;
291                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
292                        `post_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
293                        `post_archived` enum('Y','N') NOT NULL DEFAULT 'N',
294                        `post_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
295                        `post_author` int(20) NOT NULL DEFAULT 0,
296                        `post_date` timestamp NOT NULL,
297                        `post_pub_date` timestamp NOT NULL,
298                        `post_status` varchar(32) NOT NULL DEFAULT 'processing',
299                        `post_type` varchar(32) NULL,
300                        `post_category` int(20) NOT NULL DEFAULT 1,
301                        `post_tags` text NULL,
302                        `post_title` text NULL,
303                        `post_orig_url` varchar(255) NULL,
304                        `post_domain` varchar(255) NULL,
305                        `post_url` varchar(255) NULL,
306                        `post_content` text NULL,
307                        `post_votes_up` smallint(11) NOT NULL DEFAULT '0',
308                        `post_votes_down` smallint(11) NOT NULL DEFAULT '0',
309                        `post_comments` enum('open', 'closed') NOT NULL DEFAULT 'open',
310                        `post_subscribe` tinyint(1) NOT NULL DEFAULT '0',
311                        `post_updateby` int(20) NOT NULL DEFAULT 0,
312                        `post_siteid` int(20) NOT NULL DEFAULT 1,
313                        INDEX (`post_siteid`),
314                        FULLTEXT (`post_title`, `post_domain`, `post_url`, `post_content`, `post_tags`),
315                        INDEX  (`post_archived`),
316                        INDEX  (`post_status`),
317                        INDEX  (`post_type`)
318                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Story Posts';";
319                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
320                $db->query($sql);
321        }
322       
323       
324        // POSTMETA TABLE - extra information for posts
325       
326        if ($table_name == "postmeta") {
327                //echo "table doesn't exist. Stopping before creation."; exit;
328                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
329                        `postmeta_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
330                        `postmeta_archived` enum('Y','N') NOT NULL DEFAULT 'N',
331                        `postmeta_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
332                        `postmeta_postid` int(20) NOT NULL DEFAULT 0,
333                        `postmeta_key` varchar(255) NULL,
334                        `postmeta_value` text NULL,
335                        `postmeta_updateby` int(20) NOT NULL DEFAULT 0,
336                        INDEX  (`postmeta_postid`)
337                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Post Meta';";
338                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
339                $db->query($sql);
340        }
341       
342       
343        // POSTVOTES TABLE - votes
344       
345        if ($table_name == "postvotes") {
346                //echo "table doesn't exist. Stopping before creation."; exit;
347                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
348                        `vote_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
349                        `vote_archived` enum('Y','N') NOT NULL DEFAULT 'N',
350                        `vote_post_id` int(11) NOT NULL DEFAULT '0',
351                        `vote_user_id` int(11) NOT NULL DEFAULT '0',
352                        `vote_user_ip` varchar(32) NOT NULL DEFAULT '0',
353                        `vote_date` timestamp NOT NULL,
354                        `vote_type` varchar(32) NULL,
355                        `vote_rating` smallint(11) NOT NULL DEFAULT '0',
356                        `vote_reason` tinyint(3) NOT NULL DEFAULT 0,
357                        `vote_updateby` int(20) NOT NULL DEFAULT 0,
358                        INDEX  (`vote_post_id`)
359                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Post Votes';";
360                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
361                $db->query($sql);
362        }
363
364
365        // RELATES TABLE
366
367                if ($table_name == "relates") {
368                //echo "table doesn't exist. Stopping before creation."; exit;
369                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
370                        `relates_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
371                        `relates_user_id` int(20) NOT NULL default '0',
372                        `relates_post_id` int(20) NOT NULL default '0',
373                        `relates_type` varchar(64) default '',
374                        `relates_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
375                        INDEX  (`relates_user_id`),
376                        INDEX  (`relates_post_id`),
377                        INDEX  (`relates_type`)
378                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Relates';";
379                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
380                $db->query($sql);
381                }
382
383
384       
385        // SETTINGS TABLE
386       
387        if ($table_name == "settings") {
388                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
389                        `settings_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
390                        `settings_name` varchar(64) NOT NULL,
391                        `settings_value` text NOT NULL DEFAULT '',
392                        `settings_default` text NOT NULL DEFAULT '',
393                        `settings_note` text NOT NULL DEFAULT '',
394                        `settings_show` enum('Y','N') NOT NULL DEFAULT 'Y',
395                        `settings_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
396                        `settings_updateby` int(20) NOT NULL DEFAULT 0,
397                        `settings_siteid` int(20) NOT NULL DEFAULT 1,
398                        UNIQUE KEY `key` (`settings_name`, `settings_siteid`),
399                        INDEX (`settings_siteid`)
400                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Application Settings';";
401                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
402                $db->query($sql);
403               
404                // Default settings:
405               
406                // Site open
407                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
408                $db->query($db->prepare($sql, 'SITE_OPEN', 'true', 'true', ''));
409               
410                // Site name
411                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
412                $db->query($db->prepare($sql, 'SITE_NAME', 'Hotaru CMS', 'Hotaru CMS', ''));
413               
414                // Main theme
415                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
416                $db->query($db->prepare($sql, 'THEME', 'default/', 'default/', 'You need the "\/"'));
417               
418                // Admin theme
419                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
420                $db->query($db->prepare($sql, 'ADMIN_THEME', 'admin_default/', 'admin_default/', 'You need the "\/"'));
421               
422                // Debug
423                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
424                $db->query($db->prepare($sql, 'DEBUG', 'true', 'true', ''));
425               
426                // Friendly urls
427                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
428                $db->query($db->prepare($sql, 'FRIENDLY_URLS', 'false', 'false', ''));
429               
430                // Database cache
431                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
432                $db->query($db->prepare($sql, 'DB_CACHE', 'false', 'false', ''));
433               
434                // Database cache duration (hours)
435                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note, settings_show) VALUES (%s, %d, %d, %s, %s)";
436                $db->query($db->prepare($sql, 'DB_CACHE_DURATION', 12, 12, 'Hours', 'N')); // 'N' means Not shown on Admin Settings page
437               
438                // CSS/JavaScript cache
439                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
440                $db->query($db->prepare($sql, 'CSS_JS_CACHE', 'true', 'true', ''));
441               
442                // HTML cache
443                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
444                $db->query($db->prepare($sql, 'HTML_CACHE', 'true', 'true', ''));
445               
446                // Language cache
447                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
448                $db->query($db->prepare($sql, 'LANG_CACHE', 'true', 'true', ''));
449               
450                // RSS cache
451                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
452                $db->query($db->prepare($sql, 'RSS_CACHE', 'true', 'true', ''));
453               
454                // RSS cache duration (hours)
455                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note, settings_show) VALUES (%s, %d, %d, %s, %s)";
456                $db->query($db->prepare($sql, 'RSS_CACHE_DURATION', 60, 60, 'Minutes', 'N')); // 'N' means Not shown on Admin Settings page
457               
458                // Site email
459                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
460                $db->query($db->prepare($sql, 'SITE_EMAIL', 'email@example.com', 'email@example.com', 'Must be changed'));
461               
462                // SMTP on
463                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
464                $db->query($db->prepare($sql, 'SMTP', 'false', 'false', 'Email auth'));
465               
466                // SMTP host
467                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
468                $db->query($db->prepare($sql, 'SMTP_HOST', 'mail.example.com', 'mail.example.com', ''));
469               
470                // SMTP port
471                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
472                $db->query($db->prepare($sql, 'SMTP_PORT', '25', '25', ''));
473               
474                // SMTP username
475                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
476                $db->query($db->prepare($sql, 'SMTP_USERNAME', '', '', ''));
477               
478                // SMTP password
479                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
480                $db->query($db->prepare($sql, 'SMTP_PASSWORD', '', '', ''));
481               
482                // Sys Feedback
483                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
484                $db->query($db->prepare($sql, 'SYS_UPDATES', 'true', 'true', 'Hotaru updates'));
485
486                // Multiple Sites
487                $sql = "INSERT INTO " . DB_PREFIX . $table_name . " (settings_name, settings_value, settings_default, settings_note) VALUES (%s, %s, %s, %s)";
488                $db->query($db->prepare($sql, 'MULTI_SITE', 'false', 'false', 'Multiple sites'));
489
490                echo $lang['install_step2_adding_data'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
491
492        }
493       
494       
495        // SITE TABLE - for multiple sites
496
497        if ($table_name == "site") {
498                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
499                        `site_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
500                        `site_adminuser_id` varchar(64) NULL,
501                        `site_url` varchar(128) NOT NULL DEFAULT '',
502                        `site_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
503                        `site_updateby` int(20) NOT NULL DEFAULT 0
504                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Site Table';";
505                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
506                $db->query($sql);
507        }
508       
509       
510        // TAGS TABLE - tags
511       
512        if ($table_name == "tags") {
513                //echo "table doesn't exist. Stopping before creation."; exit;
514                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
515                        `tags_post_id` int(11) NOT NULL DEFAULT '0',
516                        `tags_archived` enum('Y','N') NOT NULL DEFAULT 'N',
517                        `tags_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
518                        `tags_date` timestamp NOT NULL,
519                        `tags_word` varchar(64) NOT NULL DEFAULT '',
520                        `tags_updateby` int(20) NOT NULL DEFAULT 0,
521                        `tags_siteid` int(20) NOT NULL DEFAULT 1,
522                        INDEX (`tags_siteid`),
523                        UNIQUE KEY `tags_post_id` (`tags_post_id`,`tags_word`,`tags_siteid`),
524                        INDEX  (`tags_archived`)
525                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Post Tags';";
526                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
527                $db->query($sql);
528        }
529       
530       
531        // TEMPDATA TABLE - temporary data
532       
533        if ($table_name == "tempdata") {
534                //echo "table doesn't exist. Stopping before creation."; exit;
535                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
536                        `tempdata_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
537                        `tempdata_key` varchar(255) NULL,
538                        `tempdata_value` text NULL,
539                        `tempdata_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
540                        `tempdata_updateby` int(20) NOT NULL DEFAULT 0
541                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Temporary Data';";
542                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
543                $db->query($sql);
544        }
545       
546       
547        // TOKENS TABLE - used to prevent against CSRF attacks
548       
549        if ($table_name == "tokens") {
550                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
551                        `token_id` INT(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
552                        `token_sid` varchar(32) NOT NULL,
553                        `token_key` CHAR(32) NOT NULL,
554                        `token_stamp` INT(11) NOT NULL default '0',
555                        `token_action` varchar(64),
556                        INDEX  (`token_key`)
557                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Tokens for CSRF protection';";
558                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
559                $db->query($sql);
560        }
561       
562       
563        // USERS TABLE
564       
565        if ($table_name == "users") {   
566                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
567                        `user_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
568                        `user_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
569                        `user_username` varchar(32) NOT NULL,
570                        `user_role` varchar(32) NOT NULL DEFAULT 'member',
571                        `user_date` timestamp NOT NULL,
572                        `user_password` varchar(64) NOT NULL DEFAULT '',
573                        `user_password_conf` varchar(128) NULL,
574                        `user_email` varchar(128) NOT NULL DEFAULT '',
575                        `user_email_valid` tinyint(3) NOT NULL DEFAULT 0,
576                        `user_email_conf` varchar(128) NULL,
577                        `user_permissions` text NOT NULL DEFAULT '',
578                        `user_ip` varchar(32) NOT NULL DEFAULT '0',
579                        `user_lastlogin` timestamp NULL,
580                        `user_lastvisit` timestamp NULL,
581                        `user_updateby` int(20) NOT NULL DEFAULT 0,
582                        `user_siteid` int(20) NOT NULL DEFAULT 1,
583                        INDEX (`user_siteid`),
584                        UNIQUE KEY `key` (`user_username`, `user_siteid`),
585                        KEY `user_email` (`user_email`)                 
586                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Users and Roles';";
587                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
588                $db->query($sql);
589        }
590       
591       
592        // USERMETA TABLE - extra information for posts
593       
594        if ($table_name == "usermeta") {
595                //echo "table doesn't exist. Stopping before creation."; exit;
596                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
597                        `usermeta_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
598                        `usermeta_userid` int(20) NOT NULL DEFAULT 0,
599                        `usermeta_key` varchar(255) NULL,
600                        `usermeta_value` text NULL,
601                        `usermeta_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
602                        `usermeta_updateby` int(20) NOT NULL DEFAULT 0,
603                        INDEX  (`usermeta_userid`),
604                        INDEX  (`usermeta_key`)
605                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='User Meta';";
606                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
607                $db->query($sql);
608        }
609       
610       
611        // USERACTIVITY TABLE - record user activity
612       
613        if ($table_name == "useractivity") {
614                //echo "table doesn't exist. Stopping before creation."; exit;
615                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
616                        `useract_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
617                        `useract_archived` enum('Y','N') NOT NULL DEFAULT 'N',
618                        `useract_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
619                        `useract_userid` int(20) NOT NULL DEFAULT 0,
620                        `useract_status` varchar(32) NOT NULL DEFAULT 'show',
621                        `useract_key` varchar(255) NULL,
622                        `useract_value` text NULL,
623                        `useract_key2` varchar(255) NULL,
624                        `useract_value2` text NULL,
625                        `useract_date` timestamp NOT NULL,
626                        `useract_updateby` int(20) NOT NULL DEFAULT 0,
627                        INDEX  (`useract_userid`)
628                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='User Activity';";
629                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
630                $db->query($sql);
631        }
632       
633       
634        // WIDGETS TABLE - widgets
635       
636        if ($table_name == "widgets") {
637                //echo "table doesn't exist. Stopping before creation."; exit;
638                $sql = "CREATE TABLE `" . DB_PREFIX . $table_name . "` (
639                        `widget_id` int(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
640                        `widget_updatedts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
641                        `widget_plugin` varchar(32) NOT NULL DEFAULT '',
642                        `widget_function` varchar(255) NULL,
643                        `widget_args` varchar(255) NULL,
644                        `widget_updateby` int(20) NOT NULL DEFAULT 0,
645                        `widget_siteid` int(20) NOT NULL DEFAULT 1,
646                        INDEX (`widget_siteid`)
647                ) ENGINE=" . DB_ENGINE . " DEFAULT CHARSET=" . DB_CHARSET . " COLLATE=" . DB_COLLATE . " COMMENT='Widgets';";
648                echo $lang['install_step2_creating_table'] . ": '" . DB_PREFIX . $table_name . "'...<br />\n";
649                $db->query($sql);
650        }
651
652}
653?>
Note: See TracBrowser for help on using the repository browser.