public static function Install()
{
include_once 'RCCWP_Options.php';
global $wpdb;
// First time installation
if (get_option(RC_CWP_OPTION_KEY) === false) {
// Giving full rights to folders. thanks Akis Kesoglou
wp_mkdir_p(MF_UPLOAD_FILES_DIR);
wp_mkdir_p(MF_CACHE_DIR);
wp_mkdir_p(MF_GET_CACHE_DIR);
//Initialize options
$options['condense-menu'] = 0;
$options['hide-non-standart-content'] = 1;
$options['hide-write-post'] = 0;
$options['hide-write-page'] = 0;
$options['hide-visual-editor'] = 0;
$options['prompt-editing-post'] = 0;
$options['assign-to-role'] = 0;
$options['default-custom-write-panel'] = "";
RCCWP_Options::Update($options);
}
// Check blog database
if (get_option("RC_CWP_BLOG_DB_VERSION") == '') {
update_option("RC_CWP_BLOG_DB_VERSION", 0);
}
if (get_option("RC_CWP_BLOG_DB_VERSION") < RC_CWP_DB_VERSION) {
$BLOG_DBChanged = true;
} else {
$BLOG_DBChanged = false;
}
// Install blog tables
if (!$wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", MF_TABLE_POST_META)) == MF_TABLE_POST_META || $BLOG_DBChanged) {
$blog_tables[] = "CREATE TABLE " . MF_TABLE_POST_META . " (\n\t\t\t\tid integer NOT NULL,\n\t\t\t\tgroup_count integer NOT NULL,\n\t\t\t\tfield_count integer NOT NULL,\n\t\t\t\tpost_id integer NOT NULL,\n\t\t\t\tfield_name text NOT NULL,\n\t\t\t\torder_id integer NOT NULL,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
// try to get around
// these includes like http://trac.mu.wordpress.org/ticket/384
// and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
require_once ABSPATH . 'wp-includes/pluggable.php';
} else {
require_once ABSPATH . 'wp-includes/pluggable-functions.php';
}
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
foreach ($blog_tables as $blog_table) {
dbDelta($blog_table);
}
}
update_option('RC_CWP_BLOG_DB_VERSION', RC_CWP_DB_VERSION);
// Upgrade Blog
if ($BLOG_DBChanged) {
RCCWP_Application::UpgradeBlog();
}
if (RCCWP_Application::IsWordpressMu()) {
if (get_site_option("RC_CWP_DB_VERSION") == '') {
update_site_option("RC_CWP_DB_VERSION", 0);
}
if (get_site_option("RC_CWP_DB_VERSION") < RC_CWP_DB_VERSION) {
$DBChanged = true;
} else {
$DBChanged = false;
}
} else {
if (get_option("RC_CWP_DB_VERSION") == '') {
update_option("RC_CWP_DB_VERSION", 0);
}
if (get_option("RC_CWP_DB_VERSION") < RC_CWP_DB_VERSION) {
$DBChanged = true;
} else {
$DBChanged = false;
}
}
// -- Create Tables if they don't exist or the database changed
$not_installed = false;
if (!$wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", MF_TABLE_PANELS)) == MF_TABLE_PANELS) {
$not_installed = true;
}
if ($not_installed || $DBChanged) {
$qst_tables[] = "CREATE TABLE " . MF_TABLE_PANELS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tsingle tinyint(1) NOT NULL default 0,\n\t\t\t\tdescription varchar(255),\n\t\t\t\tdisplay_order int(11),\n\t\t\t\tcapability_name varchar(255) NOT NULL,\n\t\t\t\ttype varchar(255) NOT NULL,\n expanded tinyint NOT NULL DEFAULT 1,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_GROUP_FIELDS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tgroup_id int(11) NOT NULL,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tdescription varchar(255),\n\t\t\t\tdisplay_order int(11),\n\t\t\t\tdisplay_name enum('true', 'false') NOT NULL,\n\t\t\t\tdisplay_description enum('true', 'false') NOT NULL,\n\t\t\t\ttype tinyint NOT NULL,\n\t\t\t\tCSS varchar(100),\n\t\t\t\trequired_field tinyint,\n\t\t\t\tduplicate tinyint(1) NOT NULL,\n\t\t\t\thelp_text text,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_CUSTOM_FIELD_OPTIONS . " (\n\t\t\t\tcustom_field_id int(11) NOT NULL,\n\t\t\t\toptions text,\n\t\t\t\tdefault_option text,\n\t\t\t\tPRIMARY KEY (custom_field_id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_PANEL_CATEGORY . " (\n\t\t\t\tpanel_id int(11) NOT NULL,\n\t\t\t\tcat_id varchar(100) NOT NULL,\n\t\t\t\tPRIMARY KEY (panel_id, cat_id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_PANEL_STANDARD_FIELD . " (\n\t\t\t\tpanel_id int(11) NOT NULL,\n\t\t\t\tstandard_field_id int(11) NOT NULL,\n\t\t\t\tPRIMARY KEY (panel_id, standard_field_id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_CUSTOM_FIELD_PROPERTIES . " (\n\t\t\t\tcustom_field_id int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\tproperties TEXT,\n\t\t\t\tPRIMARY KEY (custom_field_id)\n\t\t\t\t) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_PANEL_GROUPS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tpanel_id int(11) NOT NULL,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tduplicate tinyint(1) NOT NULL,\n expanded tinyint,\n\t\t\t\tat_right tinyint(1) NOT NULL,\n\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
// try to get around
// these includes like http://trac.mu.wordpress.org/ticket/384
// and http://www.quirm.net/punbb/viewtopic.php?pid=832#p832
if (file_exists(ABSPATH . 'wp-includes/pluggable.php')) {
require_once ABSPATH . 'wp-includes/pluggable.php';
} else {
require_once ABSPATH . 'wp-includes/pluggable-functions.php';
}
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
foreach ($qst_tables as $qst_table) {
dbDelta($qst_table);
}
if (RCCWP_Application::IsWordpressMu()) {
update_site_option('RC_CWP_DB_VERSION', RC_CWP_DB_VERSION);
} else {
update_option('RC_CWP_DB_VERSION', RC_CWP_DB_VERSION);
}
}
//Import Default modules
if (RCCWP_Application::IsWordpressMu()) {
if (get_site_option('MAGIC_FIELDS_fist_time') == '') {
update_site_option('MAGIC_FIELDS_fist_time', '1');
}
} else {
if (get_option('MAGIC_FIELDS_fist_time') == '') {
update_option('MAGIC_FIELDS_fist_time', '1');
}
}
//Post types
if (is_wp30()) {
// require_once(MF_PATH.'/MF_PostTypesPage.php');
// MF_PostTypePages::CreatePostTypesTables();
}
RCCWP_Application::UpgradeBlog();
}