/** * Update the group * * @param unknown_type $customWritePanelId * @param unknown_type $name group name * @param unknown_type $duplicate a boolean indicating whether the group can be duplicated * @param unknown_type $at_right a boolean indicating whether the group should be placed at right side. */ function Update($customGroupId, $name, $duplicate, $at_right) { require_once 'RC_Format.php'; global $wpdb; //$capabilityName = RCCWP_CustomWriteModule::GetCapabilityName($name); $sql = sprintf("UPDATE " . RC_CWP_TABLE_PANEL_GROUPS . " SET name = %s , duplicate = %d, at_right = %d" . " where id = %d", RC_Format::TextToSql($name), $duplicate, $at_right, $customGroupId); $wpdb->query($sql); }
/** * Updates the basic information of a module * * @param integer $customWriteModuleId the id of the module that will be updated * @param string $name new name * @param string $description new description * @return the id of the module or -1 if the module name already exist */ function Update($customWriteModuleId, $name, $description) { require_once 'RC_Format.php'; global $wpdb; //$capabilityName = RCCWP_CustomWriteModule::GetCapabilityName($name); $special_chars = array(' ', '`', '"', '\'', '\\', '/', " ", "#", "\$", "%", "^", "&", "*", "!", "~", "‘", "\"", "’", "'", "=", "?", "/", "[", "]", "(", ")", "|", "<", ">", ";", "\\", ","); $name = str_replace($special_chars, '', $name); //Make sure the module doesn't already exist $sql = "SELECT * FROM " . RC_CWP_TABLE_MODULES . " WHERE name = '" . $name . "' AND id <> {$customWriteModuleId}"; if ($wpdb->get_row($sql)) { return -1; } //Get old name $sql = "SELECT name FROM " . RC_CWP_TABLE_MODULES . " WHERE id = {$customWriteModuleId}"; $originalModName = $wpdb->get_var($sql); $oldModuleTemplateFolder = FLUTTER_MODULES_DIR . $originalModName; // Update name $sql = sprintf("UPDATE " . RC_CWP_TABLE_MODULES . " SET name = %s," . " description = %s" . " where id = %d", RC_Format::TextToSql($name), RC_Format::TextToSql($description), $customWriteModuleId); $wpdb->query($sql); //Rename module folder $newModuleTemplateFolder = FLUTTER_MODULES_DIR . $name; rename($oldModuleTemplateFolder, $newModuleTemplateFolder); return $customWriteModuleId; }
/** * Update the group * * @param unknown_type $customWritePanelId * @param unknown_type $name group name * @param unknown_type $duplicate a boolean indicating whether the group can be duplicated * @param unknown_type $at_right a boolean indicating whether the group should be placed at right side. */ function Update($customGroupId, $name, $duplicate, $expanded, $at_right) { require_once 'RC_Format.php'; global $wpdb; $sql = sprintf("UPDATE " . MF_TABLE_PANEL_GROUPS . " SET name = %s , duplicate = %d, expanded = %d, at_right = %d" . " where id = %d", RC_Format::TextToSql($name), $duplicate, $expanded, $at_right, $customGroupId); $wpdb->query($sql); }
/** * Updates the properties of a custom field. * * @param integer $customFieldId the id of the field to be updated * @param string $name the name of the field, the name is used to uniquely identify the field * when retrieving its value. * @param string $label the label of the field, the label is displayed beside the field * in Write tab. * @param integer $order the order of the field when it is displayed in * the Write tab. * @param integer $required_field whether this field is a required field. Required fields * doesn't allow users to save a post if they are null. * @param integer $type the type of the field. Use $FIELD_TYPES defined in RCCWP_Constant.php * @param array $options array of strings that represent the list of the field if * its type is list. * @param array $default_value array of strings that represent default value(s) of * of the field if its type is list. * @param array $properties an array containing extra properties of the field. */ function Update($customFieldId, $name, $label, $order = 1, $required_field = 0, $type, $options = null, $default_value = null, $properties = null, $duplicate) { global $wpdb; $oldCustomField = RCCWP_CustomField::Get($customFieldId); if ($oldCustomField->name != $name) { $sql = sprintf("UPDATE {$wpdb->postmeta}" . " SET meta_key = %s" . " WHERE meta_key = %s", RC_Format::TextToSql($name), RC_Format::TextToSql($oldCustomField->name)); $wpdb->query($sql); } $sql = sprintf("UPDATE " . RC_CWP_TABLE_GROUP_FIELDS . " SET name = %s" . " , description = %s" . " , display_order = %d" . " , required_field = %d" . " , type = %d" . " , CSS = '%s'" . " , duplicate = %d" . " WHERE id = %d", RC_Format::TextToSql($name), RC_Format::TextToSql($label), $order, $required_field, $type, $_POST['custom-field-css'], $duplicate, $customFieldId); $wpdb->query($sql); $field_type = RCCWP_CustomField::GetCustomFieldTypes($type); if ($field_type->has_options == "true") { if (!is_array($options)) { $options = stripslashes($options); $options = explode("\n", $options); } array_walk($options, array(RC_Format, TrimArrayValues)); $options = addslashes(serialize($options)); if (!is_array($default_value)) { $default_value = stripslashes($default_value); $default_value = explode("\n", $default_value); } array_walk($default_value, array(RC_Format, TrimArrayValues)); $default_value = addslashes(serialize($default_value)); $sql = sprintf("INSERT INTO " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS . " (custom_field_id, options, default_option) values (%d, %s, %s)" . " ON DUPLICATE KEY UPDATE options = %s, default_option = %s", $customFieldId, RC_Format::TextToSql($options), RC_Format::TextToSql($default_value), RC_Format::TextToSql($options), RC_Format::TextToSql($default_value)); $wpdb->query($sql); } else { $sql = sprintf("DELETE FROM " . RC_CWP_TABLE_CUSTOM_FIELD_OPTIONS . " WHERE custom_field_id = %d", $customFieldId); $wpdb->query($sql); } if ($field_type->has_properties == "true") { $sql = sprintf("INSERT INTO " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES . " (custom_field_id, properties) values (%d, %s)" . " ON DUPLICATE KEY UPDATE properties = %s", $customFieldId, RC_Format::TextToSql(serialize($properties)), RC_Format::TextToSql(serialize($properties))); $wpdb->query($sql); } else { $sql = sprintf("DELETE FROM " . RC_CWP_TABLE_CUSTOM_FIELD_PROPERTIES . " WHERE custom_field_id = %d", $customFieldId); $wpdb->query($sql); } }
/** * Updates the properties of a write panel * * @param integer $customWritePanelId panel id * @param string $name write panel name * @param string $description write panel description * @param array $standardFields a list of standard fields ids that are to be displayed in * in the panel. Use $STANDARD_FIELDS defined in RCCWP_Constant.php * @param array $categories array of category ids that are checked by default when the user * opens Write tab for that panel. * @param integer $display_order the order of the panel in Magic Fields > Write Panels tab * @param string $type 'post' or 'page' */ function Update($customWritePanelId, $name, $description = '', $standardFields = array(), $categories = array(), $display_order = 1, $type = FALSE, $createDefaultGroup = true, $single_post = 0, $default_theme_page = NULL, $default_parent_page = NULL) { include_once 'RC_Format.php'; global $wpdb; $capabilityName = RCCWP_CustomWritePanel::GetCapabilityName($name); $sql = sprintf("UPDATE " . MF_TABLE_PANELS . " SET name = %s" . " , description = %s" . " , display_order = %d" . " , capability_name = %s" . " , type = %s" . " , single = %s" . " where id = %d", RC_Format::TextToSql($name), RC_Format::TextToSql($description), $display_order, RC_Format::TextToSql($capabilityName), RC_Format::TextToSql($_POST['radPostPage']), $single_post, $customWritePanelId); $wpdb->query($sql); if (!isset($categories) || empty($categories)) { $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_CATEGORY . " WHERE panel_id = %d", $customWritePanelId); $wpdb->query($sql); } else { $currentCategoryIds = array(); $currentCategoryIds = RCCWP_CustomWritePanel::GetAssignedCategoryIds($customWritePanelId); $keepCategoryIds = array_intersect($currentCategoryIds, $categories); $deleteCategoryIds = array_diff($currentCategoryIds, $keepCategoryIds); $insertCategoryIds = array_diff($categories, $keepCategoryIds); foreach ($insertCategoryIds as $cat_id) { $sql = sprintf("INSERT INTO " . MF_TABLE_PANEL_CATEGORY . " (panel_id, cat_id)" . " values (%d, %d)", $customWritePanelId, $cat_id); $wpdb->query($sql); } if (!empty($deleteCategoryIds)) { $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_CATEGORY . " WHERE panel_id = %d" . " AND cat_id IN (%s)", $customWritePanelId, implode(',', $deleteCategoryIds)); $wpdb->query($sql); } } if (!isset($standardFields) || empty($standardFields)) { $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD . " WHERE panel_id = %d", $customWritePanelId); $wpdb->query($sql); } else { $currentStandardFieldIds = array(); $currentStandardFieldIds = RCCWP_CustomWritePanel::GetStandardFields($customWritePanelId); $keepStandardFieldIds = array_intersect($currentStandardFieldIds, $standardFields); $deleteStandardFieldIds = array_diff($currentStandardFieldIds, $keepStandardFieldIds); $insertStandardFieldIds = array_diff($standardFields, $keepStandardFieldIds); foreach ($insertStandardFieldIds as $standard_field_id) { $sql = sprintf("INSERT INTO " . MF_TABLE_PANEL_STANDARD_FIELD . " (panel_id, standard_field_id)" . " values (%d, %d)", $customWritePanelId, $standard_field_id); $wpdb->query($sql); } if (!empty($deleteStandardFieldIds)) { $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD . " WHERE panel_id = %d" . " AND standard_field_id IN (%s)", $customWritePanelId, implode(',', $deleteStandardFieldIds)); $wpdb->query($sql); } } if ($default_theme_page) { $theme_key = "t_" . $name; //check if exist template in postmeta $check_template = "SELECT meta_id FROM " . $wpdb->postmeta . " WHERE meta_key='" . $theme_key . "' "; $query_template = $wpdb->query($check_template); if ($query_template) { $sql = "UPDATE " . $wpdb->postmeta . " SET meta_value = '" . $default_theme_page . "' " . " WHERE meta_key = '" . $theme_key . "' AND post_id = '0' "; } else { $sql = "INSERT INTO " . $wpdb->postmeta . " (meta_key, meta_value) " . " VALUES ('" . $theme_key . "', '" . $default_theme_page . "')"; } $wpdb->query($sql); } if ($default_parent_page && $default_parent_page >= 0) { $parent_key = "p_" . $name; //check if exist parent in postmeta $check_parent = "SELECT meta_id FROM " . $wpdb->postmeta . " WHERE meta_key='" . $parent_key . "' "; $query_parent = $wpdb->query($check_parent); if ($query_parent) { $sql = "UPDATE " . $wpdb->postmeta . " SET meta_value = '" . $default_parent_page . "' " . " WHERE meta_key = '" . $parent_key . "' AND post_id = '0' "; } else { $sql = "INSERT INTO " . $wpdb->postmeta . " (meta_key, meta_value) " . " VALUES ('" . $parent_key . "', '" . $default_parent_page . "')"; } $wpdb->query($sql); } elseif ($default_parent_page == -1) { delete_post_meta(0, "p_" . $name, $value); } }