| [21] | 1 | <?php |
|---|
| 2 | class RCCWP_Processor |
|---|
| 3 | { |
|---|
| 4 | function Main() |
|---|
| 5 | { |
|---|
| 6 | global $CUSTOM_WRITE_PANEL; |
|---|
| 7 | |
|---|
| 8 | if (isset($_POST['edit-with-no-custom-write-panel'])) |
|---|
| 9 | { |
|---|
| 10 | |
|---|
| 11 | wp_redirect('post.php?action=edit&post=' . $_POST['post-id'] . '&no-custom-write-panel=' . $_POST['custom-write-panel-id']); |
|---|
| 12 | } |
|---|
| 13 | else if (isset($_POST['edit-with-custom-write-panel'])) |
|---|
| 14 | { |
|---|
| 15 | |
|---|
| 16 | wp_redirect('post.php?action=edit&post=' . $_POST['post-id'] . '&custom-write-panel-id=' . $_POST['custom-write-panel-id']); |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | if (RCCWP_Application::InWritePostPanel()) |
|---|
| 20 | { |
|---|
| 21 | include_once('RCCWP_Menu.php'); |
|---|
| 22 | include_once('RCCWP_WritePostPage.php'); |
|---|
| 23 | |
|---|
| 24 | $CUSTOM_WRITE_PANEL = RCCWP_Post::GetCustomWritePanel(); |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | if (isset($CUSTOM_WRITE_PANEL)) |
|---|
| 28 | { |
|---|
| 29 | include_once('RCCWP_Options.php'); |
|---|
| 30 | $assignToRole = RCCWP_Options::Get('assign-to-role'); |
|---|
| 31 | |
|---|
| 32 | if ($assignToRole <> 1 || current_user_can($CUSTOM_WRITE_PANEL->capability_name)) |
|---|
| 33 | { |
|---|
| 34 | |
|---|
| 35 | ob_start(array('RCCWP_WritePostPage', 'ApplyCustomWritePanelAssignedCategories')); |
|---|
| 36 | ob_start(array('RCCWP_WritePostPage', 'RelocateWpSubmitButtons')); |
|---|
| 37 | |
|---|
| 38 | add_action('admin_head', array('RCCWP_WritePostPage', 'ApplyCustomWritePanelStandardFields')); |
|---|
| 39 | add_action('admin_head', array('RCCWP_WritePostPage', 'HideCustomWritePanelExternalFields')); |
|---|
| 40 | |
|---|
| 41 | add_action('simple_edit_form', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface')); |
|---|
| 42 | add_action('edit_form_advanced', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface')); |
|---|
| 43 | add_action('edit_page_form', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface')); |
|---|
| 44 | |
|---|
| 45 | } |
|---|
| 46 | } |
|---|
| 47 | else if (!isset($_REQUEST['no-custom-write-panel']) && isset($_REQUEST['post'])) |
|---|
| 48 | { |
|---|
| 49 | include_once('RCCWP_Options.php'); |
|---|
| 50 | $promptEditingPost = RCCWP_Options::Get('prompt-editing-post'); |
|---|
| 51 | if ($promptEditingPost == 1) |
|---|
| 52 | { |
|---|
| 53 | wp_redirect('edit.php?page=' . urlencode(RC_CWP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&assign-custom-write-panel=' . (int)$_GET['post']); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | if (isset($_POST['finish-create-custom-write-panel'])) |
|---|
| 59 | { |
|---|
| 60 | include_once('RCCWP_CustomWritePanel.php'); |
|---|
| 61 | $hiddenExtFields = $_POST['custom-write-panel-ext-fields']; |
|---|
| 62 | // $hiddenExtFields = explode("\n", $_POST['custom-write-panel-ext-fields']); |
|---|
| 63 | if(!empty($hiddenExtFields)) |
|---|
| 64 | array_walk($hiddenExtFields, array(RC_Format, TrimArrayValues)); |
|---|
| 65 | |
|---|
| 66 | $customWritePanelId = RCCWP_CustomWritePanel::Create( |
|---|
| 67 | $_POST['custom-write-panel-name'], |
|---|
| 68 | $_POST['custom-write-panel-description'], |
|---|
| 69 | $_POST['custom-write-panel-standard-fields'], |
|---|
| 70 | $hiddenExtFields, |
|---|
| 71 | $_POST['custom-write-panel-categories'], |
|---|
| 72 | $_POST['custom-write-panel-order']); |
|---|
| 73 | |
|---|
| 74 | RCCWP_CustomWritePanel::AssignToRole($customWritePanelId, 'administrator'); |
|---|
| 75 | wp_redirect('edit.php' . RCCWP_ManagementPage::GetCustomWritePanelEditUrl($customWritePanelId)); |
|---|
| 76 | } |
|---|
| 77 | else if (isset($_POST['submit-edit-custom-write-panel'])) |
|---|
| 78 | { |
|---|
| 79 | include_once('RCCWP_CustomWritePanel.php'); |
|---|
| 80 | |
|---|
| 81 | // $hiddenExtFields = explode("\n", $_POST['custom-write-panel-ext-fields']); |
|---|
| 82 | $hiddenExtFields = $_POST['custom-write-panel-ext-fields']; |
|---|
| 83 | if(!empty($hiddenExtFields)) |
|---|
| 84 | array_walk($hiddenExtFields, array(RC_Format, TrimArrayValues)); |
|---|
| 85 | |
|---|
| 86 | RCCWP_CustomWritePanel::Update( |
|---|
| 87 | $_POST['custom-write-panel-id'], |
|---|
| 88 | $_POST['custom-write-panel-name'], |
|---|
| 89 | $_POST['custom-write-panel-description'], |
|---|
| 90 | $_POST['custom-write-panel-standard-fields'], |
|---|
| 91 | $hiddenExtFields, |
|---|
| 92 | $_POST['custom-write-panel-categories'], |
|---|
| 93 | $_POST['custom-write-panel-order']); |
|---|
| 94 | |
|---|
| 95 | RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator'); |
|---|
| 96 | } |
|---|
| 97 | else if (isset($_POST['finish-create-custom-field'])) |
|---|
| 98 | { |
|---|
| 99 | include_once('RCCWP_CustomField.php'); |
|---|
| 100 | |
|---|
| 101 | $current_field = RCCWP_CustomField::GetCustomFieldTypes((int)$_REQUEST['custom-field-type']); |
|---|
| 102 | |
|---|
| 103 | if ($current_field->has_properties) |
|---|
| 104 | { |
|---|
| 105 | $custom_field_properties = array(); |
|---|
| 106 | if (in_array($current_field->name, array('Textbox', 'Listbox'))) |
|---|
| 107 | { |
|---|
| 108 | $custom_field_properties['size'] = $_POST['custom-field-size']; |
|---|
| 109 | } |
|---|
| 110 | else if (in_array($current_field->name, array('Multiline Textbox'))) |
|---|
| 111 | { |
|---|
| 112 | $custom_field_properties['height'] = $_POST['custom-field-height']; |
|---|
| 113 | $custom_field_properties['width'] = $_POST['custom-field-width']; |
|---|
| 114 | } |
|---|
| 115 | else if( in_array( $current_field->name, array('Image') ) ) |
|---|
| 116 | { |
|---|
| 117 | $params = ''; |
|---|
| 118 | if( $_POST['custom-field-photo-height'] != '' && is_numeric( $_POST['custom-field-photo-height']) ) |
|---|
| 119 | { |
|---|
| 120 | $params .= '&h=' . $_POST['custom-field-photo-height']; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | if( $_POST['custom-field-photo-width'] != '' && is_numeric( $_POST['custom-field-photo-height']) ) |
|---|
| 124 | { |
|---|
| 125 | $params .= '&w=' . $_POST['custom-field-photo-width']; |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | if( $_POST['custom-field-custom-params'] != '' ) |
|---|
| 129 | { |
|---|
| 130 | $params .= '&' . $_POST['custom-field-custom-params']; |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | if( $params ) |
|---|
| 134 | { |
|---|
| 135 | $custom_field_properties['params'] = $params; |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | else if (in_array($current_field->name, array('Date'))) |
|---|
| 139 | { |
|---|
| 140 | $custom_field_properties['format'] = $_POST['custom-field-date-format']; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | RCCWP_CustomField::Create( |
|---|
| 145 | $_POST['custom-write-panel-id'], |
|---|
| 146 | $_POST['custom-field-name'], |
|---|
| 147 | $_POST['custom-field-description'], |
|---|
| 148 | $_POST['custom-field-order'], |
|---|
| 149 | $_POST['custom-field-type'], |
|---|
| 150 | $_POST['custom-field-options'], |
|---|
| 151 | $_POST['custom-field-default-value'], |
|---|
| 152 | $custom_field_properties |
|---|
| 153 | ); |
|---|
| 154 | } |
|---|
| 155 | else if (isset($_POST['submit-edit-custom-field'])) |
|---|
| 156 | { |
|---|
| 157 | include_once('RCCWP_CustomField.php'); |
|---|
| 158 | |
|---|
| 159 | $current_field = RCCWP_CustomField::GetCustomFieldTypes((int)$_POST['custom-field-type']); |
|---|
| 160 | |
|---|
| 161 | if ($current_field->has_properties) |
|---|
| 162 | { |
|---|
| 163 | $custom_field_properties = array(); |
|---|
| 164 | if (in_array($current_field->name, array('Textbox', 'Listbox'))) |
|---|
| 165 | { |
|---|
| 166 | $custom_field_properties['size'] = $_POST['custom-field-size']; |
|---|
| 167 | } |
|---|
| 168 | else if (in_array($current_field->name, array('Multiline Textbox'))) |
|---|
| 169 | { |
|---|
| 170 | $custom_field_properties['height'] = $_POST['custom-field-height']; |
|---|
| 171 | $custom_field_properties['width'] = $_POST['custom-field-width']; |
|---|
| 172 | } |
|---|
| 173 | else if( in_array( $current_field->name, array('Image') ) ) |
|---|
| 174 | { |
|---|
| 175 | $params = ''; |
|---|
| 176 | |
|---|
| 177 | if( $_POST['custom-field-photo-height'] != '' && is_numeric( $_POST['custom-field-photo-height']) ) |
|---|
| 178 | { |
|---|
| 179 | $params = '&h=' . $_POST['custom-field-photo-height']; |
|---|
| 180 | } |
|---|
| 181 | |
|---|
| 182 | if( $_POST['custom-field-photo-width'] != '' && is_numeric( $_POST['custom-field-photo-height']) ) |
|---|
| 183 | { |
|---|
| 184 | $params .= '&w=' . $_POST['custom-field-photo-width']; |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | if( $_POST['custom-field-custom-params'] != '' ) |
|---|
| 188 | { |
|---|
| 189 | $params .= '&' . $_POST['custom-field-custom-params']; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | if( $params ) |
|---|
| 193 | { |
|---|
| 194 | $custom_field_properties['params'] = '?' . $params; |
|---|
| 195 | } |
|---|
| 196 | } |
|---|
| 197 | else if (in_array($current_field->name, array('Date'))) |
|---|
| 198 | { |
|---|
| 199 | $custom_field_properties['format'] = $_POST['custom-field-date-format']; |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | RCCWP_CustomField::Update( |
|---|
| 204 | $_POST['custom-field-id'], |
|---|
| 205 | $_POST['custom-field-name'], |
|---|
| 206 | $_POST['custom-field-description'], |
|---|
| 207 | $_POST['custom-field-order'], |
|---|
| 208 | $_POST['custom-field-type'], |
|---|
| 209 | $_POST['custom-field-options'], |
|---|
| 210 | $_POST['custom-field-default-value'], |
|---|
| 211 | $custom_field_properties |
|---|
| 212 | ); |
|---|
| 213 | } |
|---|
| 214 | else if (isset($_POST['update-custom-write-panel-options'])) |
|---|
| 215 | { |
|---|
| 216 | if ($_POST['uninstall-custom-write-panel'] == 'uninstall') |
|---|
| 217 | { |
|---|
| 218 | RCCWP_Application::Uninstall(); |
|---|
| 219 | wp_redirect('options-general.php'); |
|---|
| 220 | } |
|---|
| 221 | else |
|---|
| 222 | { |
|---|
| 223 | include_once('RCCWP_Options.php'); |
|---|
| 224 | RCCWP_Options::Update( |
|---|
| 225 | $_POST['hide-write-post'], |
|---|
| 226 | $_POST['hide-write-page'], |
|---|
| 227 | $_POST['prompt-editing-post'], |
|---|
| 228 | $_POST['assign-to-role'], |
|---|
| 229 | $_POST['use-snipshot'], |
|---|
| 230 | $_POST['default-custom-write-panel']); |
|---|
| 231 | } |
|---|
| 232 | } |
|---|
| 233 | else if (isset($_GET['delete-custom-write-panel'])) |
|---|
| 234 | { |
|---|
| 235 | include_once('RCCWP_CustomWritePanel.php'); |
|---|
| 236 | RCCWP_CustomWritePanel::Delete($_GET['delete-custom-write-panel']); |
|---|
| 237 | wp_redirect('edit.php?page=' . urlencode(RC_CWP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php')); |
|---|
| 238 | } |
|---|
| 239 | else if (isset($_GET['delete-custom-field'])) |
|---|
| 240 | { |
|---|
| 241 | include_once('RCCWP_CustomField.php'); |
|---|
| 242 | RCCWP_CustomField::Delete($_REQUEST['delete-custom-field']); |
|---|
| 243 | wp_redirect('edit.php?page=' . urlencode(RC_CWP_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&view-custom-write-panel=' . $_REQUEST['custom-write-panel-id'] . '&custom-write-panel-id=' . $_REQUEST['custom-write-panel-id']); |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | function FlushAllOutputBuffer() |
|---|
| 249 | { |
|---|
| 250 | |
|---|
| 251 | while (@ob_end_flush()); |
|---|
| 252 | |
|---|
| 253 | } |
|---|
| 254 | |
|---|
| 255 | function Redirect($location) |
|---|
| 256 | { |
|---|
| 257 | global $post_ID; |
|---|
| 258 | global $page_ID; |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | if (!empty($_REQUEST['rc-cwp-custom-write-panel-id'])) |
|---|
| 262 | { |
|---|
| 263 | if (strstr($location, 'post-new.php?posted=') || strstr($location, 'page-new.php?posted=')) |
|---|
| 264 | { |
|---|
| 265 | $id = ($post_ID=="")?$page_ID:$post_ID; |
|---|
| 266 | $location = $_REQUEST['_wp_http_referer'] . '&posted=' . $id; |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | return $location; |
|---|
| 270 | } |
|---|
| 271 | } |
|---|
| 272 | ?> |
|---|