Update() public static method

@params array $options is a array with the options of Magic Fields
public static Update ( $options )
Esempio n. 1
0
 /**
  *  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');
         }
     }
 }
Esempio n. 2
0
 function Main()
 {
     require_once 'RC_Format.php';
     global $CUSTOM_WRITE_PANEL;
     wp_enqueue_script('jquery-ui-sortable');
     if (isset($_POST['edit-with-no-custom-write-panel'])) {
         $type = RCCWP_Post::GetCustomWritePanel();
         if (is_object($type)) {
             $ptype = $type->type;
         } else {
             $ptype = strpos($_SERVER['REQUEST_URI'], 'page.php') !== FALSE ? 'page' : 'post';
         }
         wp_redirect($ptype . '.php?action=edit&post=' . $_POST['post-id'] . '&no-custom-write-panel');
     } else {
         if (isset($_POST['edit-with-custom-write-panel']) && isset($_POST['custom-write-panel-id']) && (int) $_POST['custom-write-panel-id'] > 0) {
             $type = RCCWP_Post::GetCustomWritePanel();
             if (is_object($type)) {
                 $ptype = $type->type;
             } else {
                 $ptype = strpos($_SERVER['REQUEST_URI'], 'page.php') !== FALSE ? 'page' : 'post';
             }
             wp_redirect($type->type . '.php?action=edit&post=' . $_POST['post-id'] . '&custom-write-panel-id=' . $_POST['custom-write-panel-id']);
         }
     }
     if (empty($_REQUEST['mf_action'])) {
         $currentAction = "";
     } else {
         $currentAction = $_REQUEST['mf_action'];
     }
     switch ($currentAction) {
         // ------------ Write Panels
         case 'finish-create-custom-write-panel':
             include_once 'RCCWP_CustomWritePanel.php';
             $default_theme_page = NULL;
             if ($_POST['radPostPage'] == 'page') {
                 $default_theme_page = $_POST['page_template'];
             }
             $customWritePanelId = RCCWP_CustomWritePanel::Create($_POST['custom-write-panel-name'], $_POST['custom-write-panel-description'], $_POST['custom-write-panel-standard-fields'], $_POST['custom-write-panel-categories'], $_POST['custom-write-panel-order'], FALSE, true, $_POST['single'], $default_theme_page);
             wp_redirect(RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $customWritePanelId));
             break;
         case 'submit-edit-custom-write-panel':
             include_once 'RCCWP_CustomWritePanel.php';
             $default_theme_page = NULL;
             if ($_POST['radPostPage'] == 'page') {
                 $default_theme_page = $_POST['page_template'];
             }
             RCCWP_CustomWritePanel::Update($_POST['custom-write-panel-id'], $_POST['custom-write-panel-name'], $_POST['custom-write-panel-description'], $_POST['custom-write-panel-standard-fields'], $_POST['custom-write-panel-categories'], $_POST['custom-write-panel-order'], FALSE, true, $_POST['single'], $default_theme_page);
             RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator');
             break;
         case 'export-custom-write-panel':
             require_once 'RCCWP_CustomWritePanel.php';
             $panelID = $_REQUEST['custom-write-panel-id'];
             $writePanel = RCCWP_CustomWritePanel::Get($panelID);
             $exportedFilename = $tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $writePanel->name . '.pnl';
             RCCWP_CustomWritePanel::Export($panelID, $exportedFilename);
             // send file in header
             header('Content-type: binary');
             header('Content-Disposition: attachment; filename="' . $writePanel->name . '.pnl"');
             readfile($exportedFilename);
             unlink($exportedFilename);
             exit;
             break;
         case 'delete-custom-write-panel':
             include_once 'RCCWP_CustomWritePanel.php';
             RCCWP_CustomWritePanel::Delete($_GET['custom-write-panel-id']);
             break;
             // ------------ Groups
         // ------------ Groups
         case 'finish-create-custom-group':
             include_once 'RCCWP_CustomGroup.php';
             $customGroupId = RCCWP_CustomGroup::Create($_POST['custom-write-panel-id'], $_POST['custom-group-name'], $_POST['custom-group-duplicate'], $_POST['custom-group-at_right']);
             break;
         case 'delete-custom-group':
             include_once 'RCCWP_CustomGroup.php';
             $customGroup = RCCWP_CustomGroup::Get((int) $_REQUEST['custom-group-id']);
             RCCWP_CustomGroup::Delete($_GET['custom-group-id']);
             break;
         case 'submit-edit-custom-group':
             include_once 'RCCWP_CustomGroup.php';
             RCCWP_CustomGroup::Update($_REQUEST['custom-group-id'], $_POST['custom-group-name'], $_POST['custom-group-duplicate'], $_POST['custom-group-at_right']);
             break;
             // ------------ Fields
         // ------------ Fields
         case 'copy-custom-field':
             include_once 'RCCWP_CustomField.php';
             $fieldToCopy = RCCWP_CustomField::Get($_REQUEST['custom-field-id']);
             if (RCCWP_Processor::CheckFieldName($fieldToCopy->name, $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             RCCWP_CustomField::Create($_REQUEST['custom-group-id'], $fieldToCopy->name, $fieldToCopy->description, $fieldToCopy->display_order, $fieldToCopy->required_field, $fieldToCopy->type_id, $fieldToCopy->options, $fieldToCopy->default_value, $fieldToCopy->properties, $fieldToCopy->duplicate, $fieldToCopy->helptext);
         case 'continue-create-custom-field':
             if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             break;
         case 'finish-create-custom-field':
             include_once 'RCCWP_CustomField.php';
             if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             $current_field = RCCWP_CustomField::GetCustomFieldTypes((int) $_REQUEST['custom-field-type']);
             if ($current_field->has_properties) {
                 $custom_field_properties = array();
                 if (in_array($current_field->name, array('Textbox', 'Listbox'))) {
                     $custom_field_properties['size'] = $_POST['custom-field-size'];
                 } else {
                     if (in_array($current_field->name, array('Multiline Textbox'))) {
                         $custom_field_properties['height'] = $_POST['custom-field-height'];
                         $custom_field_properties['width'] = $_POST['custom-field-width'];
                     } else {
                         if (in_array($current_field->name, array('Date'))) {
                             $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                         } else {
                             if (in_array($current_field->name, array('Image'))) {
                                 $params = '';
                                 if ($_POST['custom-field-photo-height'] != '' && is_numeric($_POST['custom-field-photo-height'])) {
                                     $params .= '&h=' . $_POST['custom-field-photo-height'];
                                 }
                                 if ($_POST['custom-field-photo-width'] != '' && is_numeric($_POST['custom-field-photo-width'])) {
                                     $params .= '&w=' . $_POST['custom-field-photo-width'];
                                 }
                                 if ($_POST['custom-field-custom-params'] != '') {
                                     $params .= '&' . $_POST['custom-field-custom-params'];
                                 }
                                 if ($params) {
                                     $custom_field_properties['params'] = $params;
                                 }
                             } else {
                                 if (in_array($current_field->name, array('Date'))) {
                                     $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                                 } else {
                                     if (in_array($current_field->name, array('Slider'))) {
                                         $custom_field_properties['max'] = $_POST['custom-field-slider-max'];
                                         $custom_field_properties['min'] = $_POST['custom-field-slider-min'];
                                         $custom_field_properties['step'] = $_POST['custom-field-slider-step'];
                                     } else {
                                         if (in_array($current_field->name, array('Related Type'))) {
                                             $custom_field_properties['panel_id'] = $_POST['custom-field-related-type-panel-id'];
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             RCCWP_CustomField::Create($_POST['custom-group-id'], $_POST['custom-field-name'], $_POST['custom-field-description'], $_POST['custom-field-order'], $_POST['custom-field-required'], $_POST['custom-field-type'], $_POST['custom-field-options'], $_POST['custom-field-default-value'], $custom_field_properties, $_POST['custom-field-duplicate'], $_POST['custom-field-helptext']);
             break;
         case 'submit-edit-custom-field':
             include_once 'RCCWP_CustomField.php';
             $current_field_obj = RCCWP_CustomField::Get($_POST['custom-field-id']);
             if ($_POST['custom-field-name'] != $current_field_obj->name && RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-field') . '&custom-field-id=' . $_POST['custom-field-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             $current_field = RCCWP_CustomField::GetCustomFieldTypes((int) $_POST['custom-field-type']);
             if ($current_field->has_properties) {
                 $custom_field_properties = array();
                 if (in_array($current_field->name, array('Textbox', 'Listbox'))) {
                     $custom_field_properties['size'] = $_POST['custom-field-size'];
                 } else {
                     if (in_array($current_field->name, array('Multiline Textbox'))) {
                         $custom_field_properties['height'] = $_POST['custom-field-height'];
                         $custom_field_properties['width'] = $_POST['custom-field-width'];
                     } else {
                         if (in_array($current_field->name, array('Image'))) {
                             $params = '';
                             if ($_POST['custom-field-photo-height'] != '' && is_numeric($_POST['custom-field-photo-height'])) {
                                 $params = '&h=' . $_POST['custom-field-photo-height'];
                             }
                             if ($_POST['custom-field-photo-width'] != '' && is_numeric($_POST['custom-field-photo-width'])) {
                                 $params .= '&w=' . $_POST['custom-field-photo-width'];
                             }
                             if ($_POST['custom-field-custom-params'] != '') {
                                 $params .= '&' . $_POST['custom-field-custom-params'];
                             }
                             if ($params) {
                                 $custom_field_properties['params'] = $params;
                             }
                         } else {
                             if (in_array($current_field->name, array('Date'))) {
                                 $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                             } else {
                                 if (in_array($current_field->name, array('Slider'))) {
                                     $custom_field_properties['max'] = $_POST['custom-field-slider-max'];
                                     $custom_field_properties['min'] = $_POST['custom-field-slider-min'];
                                     $custom_field_properties['step'] = $_POST['custom-field-slider-step'];
                                 } else {
                                     if (in_array($current_field->name, array('Related Type'))) {
                                         $custom_field_properties['panel_id'] = $_POST['custom-field-related-type-panel-id'];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             RCCWP_CustomField::Update($_POST['custom-field-id'], $_POST['custom-field-name'], $_POST['custom-field-description'], $_POST['custom-field-order'], $_POST['custom-field-required'], $_POST['custom-field-type'], $_POST['custom-field-options'], $_POST['custom-field-default-value'], $custom_field_properties, $_POST['custom-field-duplicate'], $_POST['custom-field-helptext']);
             break;
         case 'delete-custom-field':
             include_once 'RCCWP_CustomField.php';
             if (isset($_REQUEST['custom-group-id']) && !empty($_REQUEST['custom-group-id'])) {
                 $customGroupId = (int) $_REQUEST['custom-group-id'];
             }
             $customGroup = RCCWP_CustomGroup::Get($customGroupId);
             RCCWP_CustomField::Delete($_REQUEST['custom-field-id']);
             break;
         default:
             if (RCCWP_Application::InWritePostPanel()) {
                 include_once 'RCCWP_Menu.php';
                 include_once 'RCCWP_WritePostPage.php';
                 $CUSTOM_WRITE_PANEL = RCCWP_Post::GetCustomWritePanel();
                 if (isset($CUSTOM_WRITE_PANEL) && $CUSTOM_WRITE_PANEL > 0) {
                     ob_start(array('RCCWP_WritePostPage', 'ApplyCustomWritePanelAssignedCategories'));
                     add_action('admin_head', array('RCCWP_WritePostPage', 'CustomFieldsCSS'));
                     //adding javascripts files for the custom fields
                     add_action('admin_print_scripts', array('RCCWP_WritePostPage', 'CustomFieldsJavascript'));
                     add_action('admin_head', array('RCCWP_WritePostPage', 'ApplyCustomWritePanelHeader'));
                     add_action('admin_menu', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'));
                 } else {
                     if (!isset($_REQUEST['no-custom-write-panel']) && isset($_REQUEST['post'])) {
                         include_once 'RCCWP_Options.php';
                         $promptEditingPost = RCCWP_Options::Get('prompt-editing-post');
                         if ($promptEditingPost == 1) {
                             wp_redirect('?page=' . urlencode(MF_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&assign-custom-write-panel=' . (int) $_GET['post']);
                         }
                     }
                 }
             } else {
                 if (isset($_POST['update-custom-write-panel-options'])) {
                     if ($_POST['uninstall-custom-write-panel'] == 'uninstall') {
                         RCCWP_Application::Uninstall();
                         wp_redirect('options-general.php');
                     } else {
                         include_once 'RCCWP_Options.php';
                         $options['hide-write-post'] = $_POST['hide-write-post'];
                         $options['hide-write-page'] = $_POST['hide-write-page'];
                         $options['hide-visual-editor'] = $_POST['hide-visual-editor'];
                         $options['prompt-editing-post'] = $_POST['prompt-editing-post'];
                         $options['assign-to-role'] = $_POST['assign-to-role'];
                         $options['use-snipshot'] = $_POST['use-snipshot'];
                         $options['enable-editnplace'] = $_POST['enable-editnplace'];
                         $options['eip-highlight-color'] = $_POST['eip-highlight-color'];
                         $options['enable-swfupload'] = $_POST['enable-swfupload'];
                         $options['enable-browserupload'] = $_POST['enable-browserupload'];
                         $options['default-custom-write-panel'] = $_POST['default-custom-write-panel'];
                         $options['enable-HTMLPurifier'] = $_POST['enable-HTMLPurifier'];
                         $options['tidy-level'] = $_POST['tidy-level'];
                         $options['canvas_show_instructions'] = $_POST['canvas_show_instructions'];
                         $options['canvas_show_zone_name'] = $_POST['canvas_show_zone_name'];
                         $options['canvas_show'] = $_POST['canvas_show'];
                         $options['ink_show'] = $_POST['ink_show'];
                         $options['hide-non-standart-content'] = $_POST['hide-non-standart-content'];
                         $options['condense-menu'] = $_POST['condense-menu'];
                         RCCWP_Options::Update($options);
                         $EnP = RCCWP_Application::create_EditnPlace_css(TRUE);
                     }
                 }
             }
     }
 }
Esempio n. 3
0
 function Set($key, $val)
 {
     $options = RCCWP_Options::Get();
     $options[$key] = $val;
     RCCWP_Options::Update($options);
 }
Esempio n. 4
0
    /**
     *  This function is executed every time to something related with the Magic Fields happen
     *  this function update,delete,create a customfield,writepanel,group.
     */
    function Main()
    {
        require_once 'RC_Format.php';
        global $CUSTOM_WRITE_PANEL, $wp_version;
        if (isset($_POST['edit-with-no-custom-write-panel'])) {
            $type = RCCWP_Post::GetCustomWritePanel();
            if (is_object($type)) {
                $ptype = $type->type;
            } else {
                $ptype = strpos($_SERVER['REQUEST_URI'], 'page.php') !== FALSE ? 'page' : 'post';
            }
            wp_redirect($ptype . '.php?action=edit&post=' . $_POST['post-id'] . '&no-custom-write-panel');
        } else {
            if (isset($_POST['edit-with-custom-write-panel']) && isset($_POST['custom-write-panel-id']) && (int) $_POST['custom-write-panel-id'] > 0) {
                if (substr($wp_version, 0, 3) >= 3.0) {
                    $ptype = 'post';
                } else {
                    $type = RCCWP_Post::GetCustomWritePanel();
                    if (is_object($type)) {
                        $ptype = $type->type;
                    } else {
                        $ptype = strpos($_SERVER['REQUEST_URI'], 'page.php') !== FALSE ? 'page' : 'post';
                    }
                }
                wp_redirect($ptype . '.php?action=edit&post=' . $_POST['post-id'] . '&custom-write-panel-id=' . $_POST['custom-write-panel-id']);
            }
        }
        if (empty($_REQUEST['mf_action'])) {
            $currentAction = "";
        } else {
            $currentAction = $_REQUEST['mf_action'];
        }
        switch ($currentAction) {
            // ------------ Write Panels
            case 'finish-create-custom-write-panel':
                include_once 'RCCWP_CustomWritePanel.php';
                $default_theme_page = NULL;
                if ($_POST['radPostPage'] == 'page') {
                    $default_theme_page = $_POST['page_template'];
                    $default_parent_page = $_POST['parent_id'];
                }
                $customWritePanelId = RCCWP_CustomWritePanel::Create($_POST['custom-write-panel-name'], $_POST['custom-write-panel-description'], $_POST['custom-write-panel-standard-fields'], $_POST['custom-write-panel-categories'], $_POST['custom-write-panel-order'], FALSE, true, $_POST['single'], $default_theme_page, $default_parent_page, $_POST['custom-write-panel-expanded']);
                wp_redirect(RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $customWritePanelId));
                break;
            case 'submit-edit-custom-write-panel':
                include_once 'RCCWP_CustomWritePanel.php';
                $default_theme_page = $default_parent_page = NULL;
                if ($_POST['radPostPage'] == 'page') {
                    $default_theme_page = $_POST['page_template'];
                    $default_parent_page = $_POST['parent_id'];
                }
                $default = array('custom-write-panel-id' => '', 'custom-write-panel-name' => '', 'custom-write-panel-standard-fields' => '', 'custom-write-panel-categories' => '', 'custom-write-panel-order' => '', 'single' => '', 'theme_page' => '', 'parent_page' => '', 'expanded' => '');
                $_POST['theme_page'] = $default_theme_page;
                $_POST['parent_page'] = $default_parent_page;
                $save = array_merge($default, $_POST);
                RCCWP_CustomWritePanel::Update($save['custom-write-panel-id'], $save['custom-write-panel-name'], NULL, $save['custom-write-panel-standard-fields'], $save['custom-write-panel-categories'], $save['custom-write-panel-order'], FALSE, true, $save['single'], $save['theme_page'], $save['parent_page'], $save['custom-write-panel-expanded']);
                RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator');
                break;
            case 'export-custom-write-panel':
                require_once 'RCCWP_CustomWritePanel.php';
                $panelID = $_REQUEST['custom-write-panel-id'];
                $writePanel = RCCWP_CustomWritePanel::Get($panelID);
                // send file in header
                header('Content-type: binary');
                header('Content-Disposition: attachment; filename="' . $writePanel->name . '.pnl"');
                print RCCWP_CustomWritePanel::Export($panelID);
                exit;
                break;
            case 'delete-custom-write-panel':
                include_once 'RCCWP_CustomWritePanel.php';
                RCCWP_CustomWritePanel::Delete($_GET['custom-write-panel-id']);
                break;
                // ------------ Groups
            // ------------ Groups
            case 'finish-create-custom-group':
                include_once 'RCCWP_CustomGroup.php';
                $default = array('custom-write-panel-id' => '', 'custom-group-name' => '', 'custom-group-duplicate' => '', 'custom-group-expanded' => '');
                $values = array_merge($default, $_POST);
                $customGroupId = RCCWP_CustomGroup::Create($values['custom-write-panel-id'], $values['custom-group-name'], $values['custom-group-duplicate'], $values['custom-group-expanded'], NULL);
                break;
            case 'delete-custom-group':
                include_once 'RCCWP_CustomGroup.php';
                $customGroup = RCCWP_CustomGroup::Get((int) $_REQUEST['custom-group-id']);
                RCCWP_CustomGroup::Delete($_GET['custom-group-id']);
                break;
            case 'unlink-write-panel':
                global $wpdb;
                $postId = (int) preg_replace('/post-/', '', $_REQUEST['post-id']);
                $dashboard = $_REQUEST['dashboard'];
                if ($postId) {
                    //only delete images and postmeta fields with write panels
                    if (count(get_post_meta($postId, RC_CWP_POST_WRITE_PANEL_ID_META_KEY))) {
                        $query = sprintf('SELECT wp_pm.meta_value 
						FROM %s mf_pm, %s mf_cf, %s wp_pm
						WHERE mf_pm.field_name = mf_cf.name AND mf_cf.type = 9 AND mf_pm.post_id = %d AND wp_pm.meta_id = mf_pm.id', MF_TABLE_POST_META, MF_TABLE_GROUP_FIELDS, $wpdb->postmeta, $postId);
                        $images = $wpdb->get_results($query);
                        foreach ($images as $image) {
                            if ($image->meta_value != '') {
                                $tmp = sprintf('%s%s', MF_FILES_PATH, $image->meta_value);
                                @unlink($tmp);
                            }
                        }
                        //delete all data of postmeta (WP and MF)
                        $query = sprintf('DELETE a,b from %s a INNER JOIN %s b WHERE a.meta_id = b.id AND a.post_id = %d', $wpdb->postmeta, MF_TABLE_POST_META, $postId);
                        $wpdb->query($query);
                    }
                    delete_post_meta($postId, RC_CWP_POST_WRITE_PANEL_ID_META_KEY);
                    wp_redirect($dashboard);
                    exit;
                }
                break;
            case 'submit-edit-custom-group':
                include_once 'RCCWP_CustomGroup.php';
                $default = array('custom-write-panel-id' => '', 'custom-group-name' => '', 'custom-group-duplicate' => '', 'custom-group-expanded' => '');
                $all = $_POST;
                $all['custom-group-id'] = $_REQUEST['custom-group-id'];
                $values = array_merge($default, $all);
                RCCWP_CustomGroup::Update($values['custom-group-id'], $values['custom-group-name'], $values['custom-group-duplicate'], $values['custom-group-expanded'], NULL);
                break;
                // ------------ Fields
            // ------------ Fields
            case 'copy-custom-field':
                include_once 'RCCWP_CustomField.php';
                $fieldToCopy = RCCWP_CustomField::Get($_REQUEST['custom-field-id']);
                if (RCCWP_Processor::CheckFieldName($fieldToCopy->name, $_REQUEST['custom-write-panel-id'])) {
                    $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                    wp_redirect($newURL);
                    exit;
                }
                RCCWP_CustomField::Create($_REQUEST['custom-group-id'], $fieldToCopy->name, $fieldToCopy->description, $fieldToCopy->display_order, $fieldToCopy->required_field, $fieldToCopy->type_id, $fieldToCopy->options, $fieldToCopy->default_value, $fieldToCopy->properties, $fieldToCopy->duplicate, $fieldToCopy->helptext);
            case 'continue-create-custom-field':
                if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                    $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                    wp_redirect($newURL);
                    exit;
                }
                break;
            case 'finish-create-custom-field':
                include_once 'RCCWP_CustomField.php';
                if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                    $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                    wp_redirect($newURL);
                    exit;
                }
                $current_field = RCCWP_CustomField::GetCustomFieldTypes((int) $_REQUEST['custom-field-type']);
                if ($current_field->has_properties) {
                    $custom_field_properties = array();
                    if (in_array($current_field->name, array('Textbox', 'Listbox'))) {
                        $custom_field_properties['size'] = $_POST['custom-field-size'];
                        if (isset($_POST['strict-max-length'])) {
                            $custom_field_properties['strict-max-length'] = $_POST['strict-max-length'];
                            if (empty($custom_field_properties['size'])) {
                                $custom_field_properties['size'] = 10;
                            }
                        }
                    } else {
                        if (in_array($current_field->name, array('Multiline Textbox'))) {
                            $custom_field_properties['height'] = $_POST['custom-field-height'];
                            $custom_field_properties['width'] = $_POST['custom-field-width'];
                            if (isset($_POST['hide-visual-editor'])) {
                                $custom_field_properties['hide-visual-editor'] = 1;
                            }
                            if (isset($_POST['strict-max-length'])) {
                                $custom_field_properties['hide-visual-editor'] = 1;
                                $custom_field_properties['strict-max-length'] = $_POST['strict-max-length'];
                                if (empty($custom_field_properties['height'])) {
                                    $custom_field_properties['height'] = 4;
                                }
                                if (empty($custom_field_properties['width'])) {
                                    $custom_field_properties['width'] = 64;
                                }
                            }
                        } else {
                            if (in_array($current_field->name, array('Date'))) {
                                $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                            } else {
                                if (in_array($current_field->name, array('Image', 'Image (Upload Media)'))) {
                                    $params = '';
                                    if ($_POST['custom-field-photo-height'] != '' && is_numeric($_POST['custom-field-photo-height'])) {
                                        $params .= '&h=' . $_POST['custom-field-photo-height'];
                                    }
                                    if ($_POST['custom-field-photo-width'] != '' && is_numeric($_POST['custom-field-photo-width'])) {
                                        $params .= '&w=' . $_POST['custom-field-photo-width'];
                                    }
                                    if ($_POST['custom-field-custom-params'] != '') {
                                        $params .= '&' . $_POST['custom-field-custom-params'];
                                    }
                                    if ($params) {
                                        $custom_field_properties['params'] = $params;
                                    }
                                } else {
                                    if (in_array($current_field->name, array('Date'))) {
                                        $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                                    } else {
                                        if (in_array($current_field->name, array('Slider'))) {
                                            $custom_field_properties['max'] = $_POST['custom-field-slider-max'];
                                            $custom_field_properties['min'] = $_POST['custom-field-slider-min'];
                                            $custom_field_properties['step'] = $_POST['custom-field-slider-step'];
                                        } else {
                                            if (in_array($current_field->name, array('Related Type'))) {
                                                $custom_field_properties['panel_id'] = $_POST['custom-field-related-type-panel-id'];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $default = array('custom-group-id' => '', 'custom-field-name' => '', 'custom-field-description' => '', 'custom-field-order' => '', 'custom-field-required' => '', 'custom-field-type' => '', 'custom-field-options' => '', 'custom-field-default-value' => '', 'prop' => '', 'custom-field-duplicate' => '', 'custom-field-helptext' => '');
                $_POST['prop'] = $custom_field_properties;
                $save = array_merge($default, $_POST);
                RCCWP_CustomField::Create($save['custom-group-id'], $save['custom-field-name'], $save['custom-field-description'], $save['custom-field-order'], $save['custom-field-required'], $save['custom-field-type'], $save['custom-field-options'], $save['custom-field-default-value'], $save['prop'], $save['custom-field-duplicate'], $save['custom-field-helptext']);
                break;
            case 'submit-edit-custom-field':
                include_once 'RCCWP_CustomField.php';
                $current_field_obj = RCCWP_CustomField::Get($_POST['custom-field-id']);
                if ($_POST['custom-field-name'] != $current_field_obj->name && RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                    $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-field') . '&custom-field-id=' . $_POST['custom-field-id'] . '&err_msg=-1';
                    wp_redirect($newURL);
                    exit;
                }
                $current_field = RCCWP_CustomField::GetCustomFieldTypes((int) $_POST['custom-field-type']);
                if ($current_field->has_properties) {
                    $custom_field_properties = array();
                    if (in_array($current_field->name, array('Textbox', 'Listbox'))) {
                        $custom_field_properties['size'] = $_POST['custom-field-size'];
                        if (isset($_POST['strict-max-length'])) {
                            $custom_field_properties['strict-max-length'] = $_POST['strict-max-length'];
                            if (empty($custom_field_properties['size'])) {
                                $custom_field_properties['size'] = 10;
                            }
                        }
                    } else {
                        if (in_array($current_field->name, array('Multiline Textbox'))) {
                            $custom_field_properties['height'] = $_POST['custom-field-height'];
                            $custom_field_properties['width'] = $_POST['custom-field-width'];
                            if (isset($_POST['hide-visual-editor'])) {
                                $custom_field_properties['hide-visual-editor'] = 1;
                            }
                            if (isset($_POST['strict-max-length'])) {
                                $custom_field_properties['hide-visual-editor'] = 1;
                                $custom_field_properties['strict-max-length'] = $_POST['strict-max-length'];
                                if (empty($custom_field_properties['height'])) {
                                    $custom_field_properties['height'] = 4;
                                }
                                if (empty($custom_field_properties['width'])) {
                                    $custom_field_properties['width'] = 64;
                                }
                            }
                        } else {
                            if (in_array($current_field->name, array('Image', 'Image (Upload Media)'))) {
                                $params = '';
                                if ($_POST['custom-field-photo-height'] != '' && is_numeric($_POST['custom-field-photo-height'])) {
                                    $params = '&h=' . $_POST['custom-field-photo-height'];
                                }
                                if ($_POST['custom-field-photo-width'] != '' && is_numeric($_POST['custom-field-photo-width'])) {
                                    $params .= '&w=' . $_POST['custom-field-photo-width'];
                                }
                                if ($_POST['custom-field-custom-params'] != '') {
                                    $params .= '&' . $_POST['custom-field-custom-params'];
                                }
                                if ($params) {
                                    $custom_field_properties['params'] = $params;
                                }
                            } else {
                                if (in_array($current_field->name, array('Date'))) {
                                    $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                                } else {
                                    if (in_array($current_field->name, array('Slider'))) {
                                        $custom_field_properties['max'] = $_POST['custom-field-slider-max'];
                                        $custom_field_properties['min'] = $_POST['custom-field-slider-min'];
                                        $custom_field_properties['step'] = $_POST['custom-field-slider-step'];
                                    } else {
                                        if (in_array($current_field->name, array('Related Type'))) {
                                            $custom_field_properties['panel_id'] = $_POST['custom-field-related-type-panel-id'];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                $default = array('custom-group-id' => '', 'custom-field-name' => '', 'custom-field-description' => '', 'custom-field-order' => '', 'custom-field-required' => '', 'custom-field-type' => '', 'custom-field-options' => '', 'custom-field-default-value' => '', 'prop' => '', 'custom-field-duplicate' => '', 'custom-field-helptext' => '');
                $_POST['prop'] = $custom_field_properties;
                $save = array_merge($default, $_POST);
                RCCWP_CustomField::Update($save['custom-field-id'], $save['custom-field-name'], $save['custom-field-description'], $save['custom-field-order'], $save['custom-field-required'], $save['custom-field-type'], $save['custom-field-options'], $save['custom-field-default-value'], $save['prop'], $save['custom-field-duplicate'], $save['custom-field-helptext']);
                break;
            case 'delete-custom-field':
                include_once 'RCCWP_CustomField.php';
                if (isset($_REQUEST['custom-field-id']) && !empty($_REQUEST['custom-field-id'])) {
                    RCCWP_CustomField::Delete($_REQUEST['custom-field-id']);
                }
                break;
            case 'save-fields-order':
                RCCWP_CustomWritePanelPage::save_order_fields();
            default:
                if (RCCWP_Application::InWritePostPanel()) {
                    include_once 'RCCWP_Menu.php';
                    include_once 'RCCWP_WritePostPage.php';
                    $CUSTOM_WRITE_PANEL = RCCWP_Post::GetCustomWritePanel();
                    if (isset($CUSTOM_WRITE_PANEL) && !empty($CUSTOM_WRITE_PANEL)) {
                        add_action('admin_head', array('RCCWP_WritePostPage', 'CustomFieldsCSS'));
                        //adding javascripts files for the custom fields
                        add_action('admin_print_scripts', array('RCCWP_WritePostPage', 'CustomFieldsJavascript'));
                        add_action('admin_print_scripts', array('RCCWP_WritePostPage', 'ApplyWritePanelAssignedCategoriesOrTemplate'));
                        add_action('admin_head', array('RCCWP_WritePostPage', 'ApplyCustomWritePanelHeader'));
                        add_action('admin_menu', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'));
                    } else {
                        if (!isset($_REQUEST['no-custom-write-panel']) && isset($_REQUEST['post'])) {
                            include_once 'RCCWP_Options.php';
                            $promptEditingPost = RCCWP_Options::Get('prompt-editing-post');
                            if ($promptEditingPost == 1) {
                                wp_redirect('?page=' . urlencode(MF_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&assign-custom-write-panel=' . (int) $_GET['post']);
                            }
                        }
                    }
                } else {
                    if (isset($_POST['update-custom-write-panel-options'])) {
                        if ($_POST['uninstall-custom-write-panel'] == 'uninstall') {
                            RCCWP_Application::Uninstall();
                            wp_redirect('options-general.php');
                        } else {
                            if (isset($_POST['clear-cache-image-mf'])) {
                                $dir = MF_CACHE_DIR;
                                if (is_dir($dir)) {
                                    if ($dh = opendir($dir)) {
                                        while (($file = readdir($dh)) !== false) {
                                            if (!is_dir($file)) {
                                                @unlink(MF_CACHE_DIR . $file);
                                            }
                                        }
                                        closedir($dh);
                                    }
                                }
                            }
                            include_once 'RCCWP_Options.php';
                            $default = array('condense-menu' => 0, 'hide-non-standart-content' => 0, 'hide-write-post' => 0, 'hide-write-page' => 0, 'hide-visual-editor' => 0, 'dont-remove-tmce' => 0, 'prompt-editing-post' => 0, 'assign-to-role' => 0, 'default-custom-write-panel' => 0);
                            $save_options = $_POST;
                            unset($save_options['uninstall-custom-write-panel']);
                            unset($save_options['update-custom-write-panel-options']);
                            $save = array_merge($default, $save_options);
                            RCCWP_Options::Update($save);
                        }
                    }
                }
                if (isset($_REQUEST['post'])) {
                    // traversal addition to change write panel
                    add_action('admin_menu', array('RCCWP_WritePostPage', 'CreateAttributesBox'));
                }
        }
    }
Esempio n. 5
0
 /** 
  *
  *
  */
 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.
         @chmod(FLUTTER_UPLOAD_FILES_DIR, 777);
         @chmod(FLUTTER_IMAGES_CACHE_DIR, 777);
         @chmod(FLUTTER_MODULES_DIR, 777);
         //Initialize options
         $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['use-snipshot'] = 0;
         $options['enable-editnplace'] = 1;
         $options['eip-highlight-color'] = "#FFFFCC";
         $options['enable-swfupload'] = 1;
         $options['default-custom-write-panel'] = "";
         if (version_compare(PHP_VERSION, '5.0.0') === 1) {
             $options['enable-HTMLPurifier'] = 0;
         } else {
             $options['enable-HTMLPurifier'] = 0;
         }
         $options['tidy-level'] = "medium";
         $options['canvas_show_instructions'] = 1;
         $options['canvas_show_zone_name'] = 0;
         $options['canvas_show'] = 1;
         $options['ink_show'] = 0;
         $options['enable-broserupload'] = 0;
         RCCWP_Options::Update($options);
     }
     //for  backward compatibility
     if ($options['enable-swfupload'] == 1) {
         $options['enable-browserupload'] = 0;
     } else {
         $options['enable-broserupload'] = 1;
     }
     RCCWP_Options::Update($options);
     //comment sniptshot  preference
     $checking_options = RCCWP_Options::Get();
     $checking_options['use-snipshot'] = 0;
     RCCWP_Options::Update($checking_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 '" . RC_CWP_TABLE_POST_META . "'") == RC_CWP_TABLE_POST_META || $BLOG_DBChanged) {
         $blog_tables[] = "CREATE TABLE " . RC_CWP_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                order_id integer NOT NULL,\n\t\t\t\tPRIMARY KEY (id) )";
         $blog_tables[] = "CREATE TABLE " . FLUTTER_TABLE_LAYOUT_MODULES . " (\n\t\t        block_id INT NOT NULL AUTO_INCREMENT,\n\t   \t\t\tmodule_id INT NOT NULL,\n\t\t\t\ttheme tinytext NOT NULL,\n\t\t\t\tpage text NOT NULL,\n\t\t\t\tposition tinytext NOT NULL,\n\t\t\t\ttemplate_name text NOT NULL,\n\t\t\t\ttemplate_size text NOT NULL,\n\t\t\t\tduplicate_id INT NOT NULL,\n\t\t\t\tPRIMARY KEY (block_id)\n\t\t\t\t);";
         $blog_tables[] = "CREATE TABLE " . FLUTTER_TABLE_LAYOUT_VARIABLES . " (\n\t   \t\t\tvariable_id INT NOT NULL AUTO_INCREMENT,\n\t   \t\t\tvariable_name text NOT NULL,\n\t   \t\t\tparent INT NOT NULL,\n\t   \t\t\ttype text NOT NULL,\n\t   \t\t\tvalue text NOT NULL,\n\t   \t\t\tdefault_value text NOT NULL,\n\t   \t\t\tdescription text NOT NULL,\n\t   \t\t\toptions text NOT NULL,\n\t   \t\t\tPRIMARY KEY (variable_id)\n\t\t\t\t);";
         $blog_tables[] = "CREATE TABLE " . FLUTTER_TABLE_LAYOUT_SETTINGS . " (\n\t\t        settings_id INT NOT NULL AUTO_INCREMENT,\n\t\t\t\ttheme tinytext NOT NULL,\n\t\t\t\tpage text NOT NULL,\n\t\t\t\tsettings text NOT NULL,\n\t\t\t\tPRIMARY KEY (settings_id)\n\t\t\t\t);";
         // 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);
     //canvas_install($BLOG_DBChanged);
     // 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 '" . RC_CWP_TABLE_PANELS . "'") == RC_CWP_TABLE_PANELS) {
         $not_installed = true;
     }
     if ($not_installed || $DBChanged) {
         $qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_PANELS . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tname varchar(50) NOT NULL,\n                single tinyint(1) NOT NULL default 0,\n\t\t\t\tdescription varchar(255),\n\t\t\t\tdisplay_order tinyint,\n\t\t\t\tcapability_name varchar(50) NOT NULL,\n\t\t\t\ttype varchar(50) NOT NULL,\n\t\t\t\tPRIMARY KEY (id) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " (\n\t\t\t\tid tinyint(11) NOT NULL auto_increment,\n\t\t\t\tname varchar(50) 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) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_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(50) NOT NULL,\n\t\t\t\tdescription varchar(255),\n\t\t\t\tdisplay_order tinyint,\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\tPRIMARY KEY (id) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_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) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_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) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_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) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_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);";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_TABLE_MODULES . " (\n\t\t\t\tid int(11) NOT NULL auto_increment,\n\t\t\t\tname varchar(50) NOT NULL,\n\t\t\t\tdescription text,\n\t\t\t\tPRIMARY KEY (id) )";
         $qst_tables[] = "CREATE TABLE " . RC_CWP_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(50) 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) )";
         $qst_tables[] = "CREATE TABLE " . FLUTTER_TABLE_MODULES_DUPLICATES . " (\n\t\t        duplicate_id INT NOT NULL AUTO_INCREMENT,\n\t   \t\t\tmodule_id INT NOT NULL,\n\t\t\t\tduplicate_name text NOT NULL,\n\t\t\t\tPRIMARY KEY(duplicate_id)\n\t\t\t\t);";
         // 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 " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (1, 'Textbox', NULL, 'false', 'true', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (2, 'Multiline Textbox', NULL, 'false', 'true', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (3, 'Checkbox', NULL, 'false', 'false', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (4, 'Checkbox List', NULL, 'true', 'false', 'true')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (5, 'Radiobutton List', NULL, 'true', 'false', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (6, 'Dropdown List', NULL, 'true', 'false', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (7, 'Listbox', NULL, 'true', 'true', 'true')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (8, 'File', NULL, 'false', 'false', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (9, 'Image', NULL, 'false', 'true', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (10, 'Date', NULL, 'false', 'true', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (11, 'Audio', NULL, 'false', 'false', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (12, 'Color Picker', NULL, 'false', 'false', 'false')";
         $wpdb->query($sql6);
         $sql6 = "INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (13, 'Slider', NULL, 'false', 'true', 'false')";
         $wpdb->query($sql6);
     }
     // Upgrade Blog site
     if ($DBChanged) {
         RCCWP_Application::UpgradeBlogSite();
     }
     if (RC_CWP_DB_VERSION >= 36) {
         $wpdb->query("INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (12, 'Color Picker', NULL, 'false', 'false', 'false')");
     }
     if (RC_CWP_DB_VERSION >= 36) {
         $wpdb->query("INSERT IGNORE INTO " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " VALUES (13, 'Slider', NULL, 'false', 'true', 'false')");
     }
     if (RC_CWP_DB_VERSION >= 40) {
         $wpdb->query("ALTER TABLE " . RC_CWP_TABLE_PANELS . " MODIFY name varchar(255) NOT NULL");
         $wpdb->query("ALTER TABLE " . RC_CWP_TABLE_PANELS . " MODIFY capability_name varchar(255) NOT NULL");
         $wpdb->query("ALTER TABLE " . RC_CWP_TABLE_CUSTOM_FIELD_TYPES . " MODIFY name varchar(255) NOT NULL");
         $wpdb->query("ALTER TABLE " . RC_CWP_TABLE_GROUP_FIELDS . " MODIFY name varchar(255) NOT NULL");
         $wpdb->query("ALTER TABLE " . RC_CWP_TABLE_MODULES . " MODIFY name varchar(255) NOT NULL");
         $wpdb->query("ALTER TABLE " . RC_CWP_TABLE_PANEL_GROUPS . " MODIFY name varchar(255) NOT NULL");
         //$wpdb->query('update '.RC_CWP_TABLE_POST_META.' ps, '.RC_CWP_TABLE_GROUP_FIELDS.' cf, '.RC_CWP_TABLE_PANEL_GROUPS.' mg set ps.order_id=-1 where mg.name="__default" and mg.id=cf.group_id AND cf.name=ps.field_name');
     }
     //Import Default modules
     if (RCCWP_Application::IsWordpressMu()) {
         if (get_site_option('FLUTTER_fist_time') == '') {
             RCCWP_Application::import_default_modules();
             update_site_option('FLUTTER_fist_time', '1');
         }
     } else {
         if (get_option('FLUTTER_fist_time') == '') {
             RCCWP_Application::import_default_modules();
             update_option('FLUTTER_fist_time', '1');
         }
     }
 }
Esempio n. 6
0
 function Main()
 {
     require_once 'RC_Format.php';
     global $CUSTOM_WRITE_PANEL;
     wp_enqueue_script('jquery-ui-sortable');
     if (isset($_POST['edit-with-no-custom-write-panel'])) {
         wp_redirect('post.php?action=edit&post=' . $_POST['post-id'] . '&no-custom-write-panel=' . $_POST['custom-write-panel-id']);
     } else {
         if (isset($_POST['edit-with-custom-write-panel'])) {
             wp_redirect('post.php?action=edit&post=' . $_POST['post-id'] . '&custom-write-panel-id=' . $_POST['custom-write-panel-id']);
         }
     }
     if (empty($_REQUEST['flutter_action'])) {
         $currentAction = "";
     } else {
         $currentAction = $_REQUEST['flutter_action'];
     }
     switch ($currentAction) {
         // ------------ Write Panels
         case 'finish-create-custom-write-panel':
             include_once 'RCCWP_CustomWritePanel.php';
             $default_theme_page = NULL;
             if ($_POST['radPostPage'] == 'page') {
                 $default_theme_page = $_POST['page_template'];
             }
             $customWritePanelId = RCCWP_CustomWritePanel::Create($_POST['custom-write-panel-name'], $_POST['custom-write-panel-description'], $_POST['custom-write-panel-standard-fields'], $_POST['custom-write-panel-categories'], $_POST['custom-write-panel-order'], FALSE, true, $_POST['single'], $default_theme_page);
             wp_redirect(RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $customWritePanelId));
             break;
         case 'submit-edit-custom-write-panel':
             include_once 'RCCWP_CustomWritePanel.php';
             $default_theme_page = NULL;
             if ($_POST['radPostPage'] == 'page') {
                 $default_theme_page = $_POST['page_template'];
             }
             RCCWP_CustomWritePanel::Update($_POST['custom-write-panel-id'], $_POST['custom-write-panel-name'], $_POST['custom-write-panel-description'], $_POST['custom-write-panel-standard-fields'], $_POST['custom-write-panel-categories'], $_POST['custom-write-panel-order'], FALSE, true, $_POST['single'], $default_theme_page);
             RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator');
             break;
         case 'export-custom-write-panel':
             require_once 'RCCWP_CustomWritePanel.php';
             $panelID = $_REQUEST['custom-write-panel-id'];
             $writePanel = RCCWP_CustomWritePanel::Get($panelID);
             $exportedFilename = $tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $writePanel->name . '.pnl';
             RCCWP_CustomWritePanel::Export($panelID, $exportedFilename);
             // send file in header
             header('Content-type: binary');
             header('Content-Disposition: attachment; filename="' . $writePanel->name . '.pnl"');
             readfile($exportedFilename);
             unlink($exportedFilename);
             exit;
             break;
         case 'delete-custom-write-panel':
             include_once 'RCCWP_CustomWritePanel.php';
             RCCWP_CustomWritePanel::Delete($_GET['custom-write-panel-id']);
             //wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php'));
             break;
             // ------------ Modules
             // ------------ Groups
         // ------------ Modules
         // ------------ Groups
         case 'finish-create-custom-group':
             include_once 'RCCWP_CustomGroup.php';
             $customGroupId = RCCWP_CustomGroup::Create($_POST['custom-write-panel-id'], $_POST['custom-group-name'], $_POST['custom-group-duplicate'], $_POST['custom-group-at_right']);
             break;
         case 'delete-custom-group':
             include_once 'RCCWP_CustomGroup.php';
             $customGroup = RCCWP_CustomGroup::Get((int) $_REQUEST['custom-group-id']);
             RCCWP_CustomGroup::Delete($_GET['custom-group-id']);
             break;
         case 'submit-edit-custom-group':
             include_once 'RCCWP_CustomGroup.php';
             RCCWP_CustomGroup::Update($_REQUEST['custom-group-id'], $_POST['custom-group-name'], $_POST['custom-group-duplicate'], $_POST['custom-group-at_right']);
             break;
             // ------------ Fields
         // ------------ Fields
         case 'copy-custom-field':
             include_once 'RCCWP_CustomField.php';
             $fieldToCopy = RCCWP_CustomField::Get($_REQUEST['custom-field-id']);
             if (RCCWP_Processor::CheckFieldName($fieldToCopy->name, $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             RCCWP_CustomField::Create($_REQUEST['custom-group-id'], $fieldToCopy->name, $fieldToCopy->description, $fieldToCopy->display_order, $fieldToCopy->required_field, $fieldToCopy->type_id, $fieldToCopy->options, $fieldToCopy->default_value, $fieldToCopy->properties, $fieldToCopy->duplicate);
         case 'continue-create-custom-field':
             if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             break;
         case 'finish-create-custom-field':
             include_once 'RCCWP_CustomField.php';
             if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . '&custom-group-id=' . $_REQUEST['custom-group-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             $current_field = RCCWP_CustomField::GetCustomFieldTypes((int) $_REQUEST['custom-field-type']);
             if ($current_field->has_properties) {
                 $custom_field_properties = array();
                 if (in_array($current_field->name, array('Textbox', 'Listbox'))) {
                     $custom_field_properties['size'] = $_POST['custom-field-size'];
                 } else {
                     if (in_array($current_field->name, array('Multiline Textbox'))) {
                         $custom_field_properties['height'] = $_POST['custom-field-height'];
                         $custom_field_properties['width'] = $_POST['custom-field-width'];
                     } else {
                         if (in_array($current_field->name, array('Date'))) {
                             $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                         } else {
                             if (in_array($current_field->name, array('Image'))) {
                                 $params = '';
                                 if ($_POST['custom-field-photo-height'] != '' && is_numeric($_POST['custom-field-photo-height'])) {
                                     $params .= '&h=' . $_POST['custom-field-photo-height'];
                                 }
                                 if ($_POST['custom-field-photo-width'] != '' && is_numeric($_POST['custom-field-photo-width'])) {
                                     $params .= '&w=' . $_POST['custom-field-photo-width'];
                                 }
                                 if ($_POST['custom-field-custom-params'] != '') {
                                     $params .= '&' . $_POST['custom-field-custom-params'];
                                 }
                                 if ($params) {
                                     $custom_field_properties['params'] = $params;
                                 }
                             } else {
                                 if (in_array($current_field->name, array('Date'))) {
                                     $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                                 } else {
                                     if (in_array($current_field->name, array('Slider'))) {
                                         $custom_field_properties['max'] = $_POST['custom-field-slider-max'];
                                         $custom_field_properties['min'] = $_POST['custom-field-slider-min'];
                                         $custom_field_properties['step'] = $_POST['custom-field-slider-step'];
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             RCCWP_CustomField::Create($_POST['custom-group-id'], $_POST['custom-field-name'], $_POST['custom-field-description'], $_POST['custom-field-order'], $_POST['custom-field-required'], $_POST['custom-field-type'], $_POST['custom-field-options'], $_POST['custom-field-default-value'], $custom_field_properties, $_POST['custom-field-duplicate']);
             break;
         case 'submit-edit-custom-field':
             include_once 'RCCWP_CustomField.php';
             $current_field_obj = RCCWP_CustomField::Get($_POST['custom-field-id']);
             if ($_POST['custom-field-name'] != $current_field_obj->name && RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])) {
                 $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-field') . '&custom-field-id=' . $_POST['custom-field-id'] . '&err_msg=-1';
                 wp_redirect($newURL);
                 exit;
             }
             $current_field = RCCWP_CustomField::GetCustomFieldTypes((int) $_POST['custom-field-type']);
             if ($current_field->has_properties) {
                 $custom_field_properties = array();
                 if (in_array($current_field->name, array('Textbox', 'Listbox'))) {
                     $custom_field_properties['size'] = $_POST['custom-field-size'];
                 } else {
                     if (in_array($current_field->name, array('Multiline Textbox'))) {
                         $custom_field_properties['height'] = $_POST['custom-field-height'];
                         $custom_field_properties['width'] = $_POST['custom-field-width'];
                     } else {
                         if (in_array($current_field->name, array('Image'))) {
                             $params = '';
                             if ($_POST['custom-field-photo-height'] != '' && is_numeric($_POST['custom-field-photo-height'])) {
                                 $params = '&h=' . $_POST['custom-field-photo-height'];
                             }
                             if ($_POST['custom-field-photo-width'] != '' && is_numeric($_POST['custom-field-photo-width'])) {
                                 $params .= '&w=' . $_POST['custom-field-photo-width'];
                             }
                             if ($_POST['custom-field-custom-params'] != '') {
                                 $params .= '&' . $_POST['custom-field-custom-params'];
                             }
                             if ($params) {
                                 $custom_field_properties['params'] = $params;
                             }
                         } else {
                             if (in_array($current_field->name, array('Date'))) {
                                 $custom_field_properties['format'] = $_POST['custom-field-date-format'];
                             } else {
                                 if (in_array($current_field->name, array('Slider'))) {
                                     $custom_field_properties['max'] = $_POST['custom-field-slider-max'];
                                     $custom_field_properties['min'] = $_POST['custom-field-slider-min'];
                                     $custom_field_properties['step'] = $_POST['custom-field-slider-step'];
                                 }
                             }
                         }
                     }
                 }
             }
             RCCWP_CustomField::Update($_POST['custom-field-id'], $_POST['custom-field-name'], $_POST['custom-field-description'], $_POST['custom-field-order'], $_POST['custom-field-required'], $_POST['custom-field-type'], $_POST['custom-field-options'], $_POST['custom-field-default-value'], $custom_field_properties, $_POST['custom-field-duplicate']);
             break;
         case 'delete-custom-field':
             include_once 'RCCWP_CustomField.php';
             if (isset($_REQUEST['custom-group-id']) && !empty($_REQUEST['custom-group-id'])) {
                 $customGroupId = (int) $_REQUEST['custom-group-id'];
             }
             $customGroup = RCCWP_CustomGroup::Get($customGroupId);
             RCCWP_CustomField::Delete($_REQUEST['custom-field-id']);
             break;
         case 'delete-theme-settings':
             include_once 'RCCWP_ThemeSettingsPage.php';
             $settings = new RCCWP_ThemeSettingsPage();
             $settings->remove_layout_setting();
             break;
         case 'create-layout-setting':
             include_once 'RCCWP_ThemeSettingsPage.php';
             if (!empty($_POST['variable_name'])) {
                 RCCWP_ThemeSettingsPage::finish_create_layout_element();
                 break;
             }
         default:
             if (RCCWP_Application::InWritePostPanel()) {
                 include_once 'RCCWP_Menu.php';
                 include_once 'RCCWP_WritePostPage.php';
                 $CUSTOM_WRITE_PANEL = RCCWP_Post::GetCustomWritePanel();
                 if (isset($CUSTOM_WRITE_PANEL) && $CUSTOM_WRITE_PANEL > 0) {
                     ob_start(array('RCCWP_WritePostPage', 'ApplyCustomWritePanelAssignedCategories'));
                     add_action('admin_head', array('RCCWP_WritePostPage', 'ApplyCustomWritePanelHeader'));
                     // Allows fields to be added to right
                     //	commented to test		add_action('submitpost_box', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterfaceRight'), 5);
                     //						add_action('submitpage_box', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterfaceRight'), 5);
                     // commented to test
                     add_action('add_meta_box', 'post', 'side', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterfaceRight'));
                     // Allows fields to be added to the post edit body
                     add_action('simple_edit_form', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'), 5);
                     add_action('edit_form_advanced', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'), 5);
                     add_action('edit_page_form', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'), 5);
                 } else {
                     if (!isset($_REQUEST['no-custom-write-panel']) && isset($_REQUEST['post'])) {
                         include_once 'RCCWP_Options.php';
                         $promptEditingPost = RCCWP_Options::Get('prompt-editing-post');
                         if ($promptEditingPost == 1) {
                             wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&assign-custom-write-panel=' . (int) $_GET['post']);
                         }
                     }
                 }
             } else {
                 if (isset($_POST['finish-create-custom-write-module'])) {
                     include_once 'RCCWP_CustomWriteModule.php';
                     $customWriteModuleId = RCCWP_CustomWriteModule::Create($_POST['custom-write-module-name'], $_POST['custom-write-module-description']);
                     //RCCWP_CustomWritePanel::AssignToRole($customWritePanelId, 'administrator');
                     if ($customWriteModuleId == -1) {
                         //$_POST['create-custom-write-module'] = 1;
                         $modulesURL = '?page=' . 'FlutterManageModules' . '&view-modules=1&create-custom-write-module=1&err_msg=-1';
                         wp_redirect($modulesURL);
                     } else {
                         wp_redirect(RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($customWriteModuleId));
                     }
                 } else {
                     if (isset($_POST['submit-edit-custom-write-module'])) {
                         include_once 'RCCWP_CustomWriteModule.php';
                         $customWriteModuleId = RCCWP_CustomWriteModule::Update($_REQUEST['custom-write-module-id'], $_REQUEST['custom-write-module-name'], $_REQUEST['custom-write-module-description']);
                         if ($customWriteModuleId == -1) {
                             $customWriteModuleId = $_REQUEST['custom-write-module-id'];
                             $modulesURL = '?page=' . 'FlutterManageModules' . "&edit-custom-write-module=1&view-custom-write-module={$customWriteModuleId}&custom-write-module-id={$customWriteModuleId}&err_msg=-1";
                             wp_redirect($modulesURL);
                         }
                         //RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator');
                     } else {
                         if (isset($_POST['update-custom-write-panel-options'])) {
                             if ($_POST['uninstall-custom-write-panel'] == 'uninstall') {
                                 RCCWP_Application::Uninstall();
                                 wp_redirect('options-general.php');
                             } else {
                                 include_once 'RCCWP_Options.php';
                                 $options['hide-write-post'] = $_POST['hide-write-post'];
                                 $options['hide-write-page'] = $_POST['hide-write-page'];
                                 $options['hide-visual-editor'] = $_POST['hide-visual-editor'];
                                 $options['prompt-editing-post'] = $_POST['prompt-editing-post'];
                                 $options['assign-to-role'] = $_POST['assign-to-role'];
                                 $options['use-snipshot'] = $_POST['use-snipshot'];
                                 $options['enable-editnplace'] = $_POST['enable-editnplace'];
                                 $options['eip-highlight-color'] = $_POST['eip-highlight-color'];
                                 $options['enable-swfupload'] = $_POST['enable-swfupload'];
                                 $options['enable-browserupload'] = $_POST['enable-browserupload'];
                                 $options['default-custom-write-panel'] = $_POST['default-custom-write-panel'];
                                 $options['enable-HTMLPurifier'] = $_POST['enable-HTMLPurifier'];
                                 $options['tidy-level'] = $_POST['tidy-level'];
                                 $options['canvas_show_instructions'] = $_POST['canvas_show_instructions'];
                                 $options['canvas_show_zone_name'] = $_POST['canvas_show_zone_name'];
                                 $options['canvas_show'] = $_POST['canvas_show'];
                                 $options['ink_show'] = $_POST['ink_show'];
                                 RCCWP_Options::Update($options);
                             }
                         } else {
                             if (isset($_REQUEST['create-module-duplicate'])) {
                                 include_once 'RCCWP_ModuleDuplicate.php';
                                 $moduleID = $_REQUEST['custom-write-module-id'];
                                 RCCWP_ModuleDuplicate::Create($moduleID);
                                 wp_redirect(RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($moduleID));
                             } else {
                                 if (isset($_POST['submit-edit-module-duplicate'])) {
                                     include_once 'RCCWP_ModuleDuplicate.php';
                                     $moduleID = $_REQUEST['custom-write-module-id'];
                                     RCCWP_ModuleDuplicate::Update($_REQUEST['module-duplicate-id'], $_REQUEST['module-duplicate-name']);
                                     wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&view-custom-write-module=' . $moduleID . '&custom-write-module-id=' . $moduleID);
                                 } else {
                                     if (isset($_REQUEST['delete-module-duplicate'])) {
                                         include_once 'RCCWP_ModuleDuplicate.php';
                                         $moduleID = $_REQUEST['custom-write-module-id'];
                                         RCCWP_ModuleDuplicate::Delete($_REQUEST['module-duplicate-id']);
                                         wp_redirect(RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($moduleID));
                                     } else {
                                         if (isset($_POST['delete-custom-write-module'])) {
                                             include_once 'RCCWP_CustomWriteModule.php';
                                             $moduleID = $_REQUEST['custom-write-module-id'];
                                             RCCWP_CustomWriteModule::Delete($moduleID);
                                             wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&view-modules=1');
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
     }
 }
Esempio n. 7
0
 /**
  *  Installing Magic fields
  * 
  *  This function create all the Magic Fields default values and
  *  his  tables in the database 
  * 
  *  @return void
  */
 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();
 }