/**
* Installing Magic fields
*
* This function create all the Magic Fields default values and
* his tables in the database
*
* @return void
*/
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);
//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'] = "";
$options['enable-editnplace'] = 1;
$options['eip-highlight-color'] = "#FFFFCC";
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("SHOW TABLES LIKE '" . 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/upgrade-functions.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
if (!$wpdb->get_var("SHOW TABLES LIKE '" . 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\t\t\t\tPRIMARY KEY (id) ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci";
$qst_tables[] = "CREATE TABLE " . MF_TABLE_CUSTOM_FIELD_TYPES . " (\n\t\t\t\tid tinyint(11) NOT NULL auto_increment,\n\t\t\t\tname varchar(255) NOT NULL,\n\t\t\t\tdescription varchar(100),\n\t\t\t\thas_options enum('true', 'false') NOT NULL,\n\t\t\t\thas_properties enum('true', 'false') NOT NULL,\n\t\t\t\tallow_multiple_values enum('true', 'false') NOT NULL,\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 int(11) 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\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/upgrade-functions.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);
}
}
// Insert standard fields definition
if ($not_installed) {
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (1, 'Textbox', NULL, 'false', 'true', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (2, 'Multiline Textbox', NULL, 'false', 'true', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (3, 'Checkbox', NULL, 'false', 'false', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (4, 'Checkbox List', NULL, 'true', 'false', 'true')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (5, 'Radiobutton List', NULL, 'true', 'false', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (6, 'Dropdown List', NULL, 'true', 'false', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (7, 'Listbox', NULL, 'true', 'true', 'true')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (8, 'File', NULL, 'false', 'false', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (9, 'Image', NULL, 'false', 'true', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (10, 'Date', NULL, 'false', 'true', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (11, 'Audio', NULL, 'false', 'false', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (12, 'Color Picker', NULL, 'false', 'false', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (13, 'Slider', NULL, 'false', 'true', 'false')";
$wpdb->query($sql6);
$sql6 = "INSERT IGNORE INTO " . MF_TABLE_CUSTOM_FIELD_TYPES . " VALUES (14, 'Related Type', NULL, 'false', 'true', 'false')";
$wpdb->query($sql6);
}
//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');
}
}
}