root/afridex/plugins/Flutter/RCCWP_Processor.php @ 22

Revision 21, 16.5 kB (checked in by admin, 18 years ago)
Line 
1<?php
2class RCCWP_Processor
3{
4        function Main()
5        {
6                require_once('RC_Format.php');
7                global $CUSTOM_WRITE_PANEL;
8               
9               
10               
11                if (isset($_POST['edit-with-no-custom-write-panel']))
12                {
13                       
14                        wp_redirect('post.php?action=edit&post=' . $_POST['post-id'] . '&no-custom-write-panel=' . $_POST['custom-write-panel-id']);
15                }
16                else if (isset($_POST['edit-with-custom-write-panel']))
17                {
18                       
19                        wp_redirect('post.php?action=edit&post=' . $_POST['post-id'] . '&custom-write-panel-id=' . $_POST['custom-write-panel-id']);
20                }
21               
22                $currentAction = $_REQUEST['flutter_action'];
23                switch ($currentAction){
24                       
25                        // ------------ Write Panels
26                        case 'finish-create-custom-write-panel':
27                                include_once('RCCWP_CustomWritePanel.php');
28                                       
29                                $customWritePanelId = RCCWP_CustomWritePanel::Create(
30                                        $_POST['custom-write-panel-name'],
31                                        $_POST['custom-write-panel-description'],
32                                        $_POST['custom-write-panel-standard-fields'],
33                                        $_POST['custom-write-panel-categories'],
34                                        $_POST['custom-write-panel-order']);
35
36                                wp_redirect(RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('view-custom-write-panel', $customWritePanelId));
37                                break;
38                               
39                        case 'submit-edit-custom-write-panel':
40                                include_once('RCCWP_CustomWritePanel.php');
41
42                                RCCWP_CustomWritePanel::Update(
43                                        $_POST['custom-write-panel-id'],
44                                        $_POST['custom-write-panel-name'],
45                                        $_POST['custom-write-panel-description'],
46                                        $_POST['custom-write-panel-standard-fields'],
47                                        $_POST['custom-write-panel-categories'],
48                                        $_POST['custom-write-panel-order']);
49                               
50                                RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator');
51                                break;
52                               
53                               
54                        case 'export-custom-write-panel':                               
55                                require_once('RCCWP_CustomWritePanel.php');     
56                                $panelID = $_REQUEST['custom-write-panel-id'];
57                                $writePanel = RCCWP_CustomWritePanel::Get($panelID);
58                                $exportedFilename = $tmpPath = sys_get_temp_dir().DIRECTORY_SEPARATOR. $writePanel->name . '.pnl';
59                               
60                                RCCWP_CustomWritePanel::Export($panelID, $exportedFilename);
61       
62                                // send file in header
63                                header('Content-type: binary');
64                                header('Content-Disposition: attachment; filename="'.$writePanel->name.'.pnl"');
65                                readfile($exportedFilename);
66                                unlink($exportedFilename);
67                                exit(); 
68                                break;
69                               
70                        case 'delete-custom-write-panel':
71                                include_once('RCCWP_CustomWritePanel.php');
72                                RCCWP_CustomWritePanel::Delete($_GET['custom-write-panel-id']);
73                                //wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php'));
74                                break;
75
76                               
77                        // ------------ Modules
78                       
79                        // ------------ Groups
80                        case 'finish-create-custom-group':
81                                include_once('RCCWP_CustomGroup.php');
82                                $customGroupId = RCCWP_CustomGroup::Create(
83                                                $_POST['custom-write-panel-id'], $_POST['custom-group-name'], $_POST['custom-group-duplicate'], $_POST['custom-group-at_right']);
84                                break;
85                               
86                        case 'delete-custom-group':
87                                include_once('RCCWP_CustomGroup.php');
88                                $customGroup = RCCWP_CustomGroup::Get((int)$_REQUEST['custom-group-id']);
89                                RCCWP_CustomGroup::Delete($_GET['custom-group-id']);
90                                break;
91
92                        case 'submit-edit-custom-group':                               
93                                include_once('RCCWP_CustomGroup.php');
94                                RCCWP_CustomGroup::Update(
95                                        $_REQUEST['custom-group-id'],
96                                        $_POST['custom-group-name'],
97                                        $_POST['custom-group-duplicate'],
98                                        $_POST['custom-group-at_right']);
99                                break;
100                                                                               
101                        // ------------ Fields
102                        case 'copy-custom-field':
103                                include_once('RCCWP_CustomField.php');
104                                $fieldToCopy = RCCWP_CustomField::Get($_REQUEST['custom-field-id']);
105                               
106                                if (RCCWP_Processor::CheckFieldName($fieldToCopy->name, $_REQUEST['custom-write-panel-id'])){
107                                        $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field').'&custom-group-id='.$_REQUEST['custom-group-id'].'&err_msg=-1';
108                                        wp_redirect($newURL);
109                                        exit;
110                                }
111                                                               
112                                RCCWP_CustomField::Create(
113                                        $_REQUEST['custom-group-id'],
114                                        $fieldToCopy->name,
115                                        $fieldToCopy->description,
116                                        $fieldToCopy->display_order,
117                                        $fieldToCopy->required_field,
118                                        $fieldToCopy->type_id,
119                                        $fieldToCopy->options,
120                                        $fieldToCopy->default_value,
121                                        $fieldToCopy->properties,
122                                        $fieldToCopy->duplicate
123                                        );
124                               
125                        case 'continue-create-custom-field':
126                                if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])){
127                                        $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field').'&custom-group-id='.$_REQUEST['custom-group-id'].'&err_msg=-1';
128                                        wp_redirect($newURL);
129                                        exit;
130                                }
131                                break;
132                               
133                        case 'finish-create-custom-field':
134                                include_once('RCCWP_CustomField.php');
135                               
136                                if (RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])){
137                                        $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field').'&custom-group-id='.$_REQUEST['custom-group-id'].'&err_msg=-1';
138                                        wp_redirect($newURL);
139                                        exit;
140                                }
141                                       
142                                $current_field = RCCWP_CustomField::GetCustomFieldTypes((int)$_REQUEST['custom-field-type']);
143                               
144                                if ($current_field->has_properties)
145                                {
146                                        $custom_field_properties = array();
147                                        if (in_array($current_field->name, array('Textbox', 'Listbox')))
148                                        {
149                                                $custom_field_properties['size'] = $_POST['custom-field-size'];
150                                        }
151                                        else if (in_array($current_field->name, array('Multiline Textbox')))
152                                        {
153                                                $custom_field_properties['height'] = $_POST['custom-field-height'];
154                                                $custom_field_properties['width'] = $_POST['custom-field-width'];
155                                        }
156                                        else if (in_array($current_field->name, array('Date')))
157                                        {
158                                                $custom_field_properties['format'] = $_POST['custom-field-date-format'];
159                                        }
160                                        else if( in_array( $current_field->name, array('Image') ) )
161                                        {
162                                                $params = '';
163                                                if( $_POST['custom-field-photo-height'] != '' && is_numeric( $_POST['custom-field-photo-height']) )
164                                                {
165                                                        $params .= '&h=' . $_POST['custom-field-photo-height'];
166                                                }
167       
168                                                if( $_POST['custom-field-photo-width'] != '' && is_numeric( $_POST['custom-field-photo-width']) )
169                                                {
170                                                        $params .= '&w=' . $_POST['custom-field-photo-width'];
171                                                }
172                                               
173                                                if( $_POST['custom-field-custom-params'] != '' )
174                                                {
175                                                        $params .= '&' . $_POST['custom-field-custom-params'];
176                                                }
177       
178                                                if( $params )
179                                                {
180                                                        $custom_field_properties['params'] = $params;
181                                                }
182                                        }
183                                        else if (in_array($current_field->name, array('Date')))
184                                        {
185                                                $custom_field_properties['format'] = $_POST['custom-field-date-format'];
186                                        }
187                                }
188                               
189                                RCCWP_CustomField::Create(
190                                        $_POST['custom-group-id'],
191                                        $_POST['custom-field-name'],
192                                        $_POST['custom-field-description'],
193                                        $_POST['custom-field-order'],
194                                        $_POST['custom-field-required'],
195                                        $_POST['custom-field-type'],
196                                        $_POST['custom-field-options'],
197                                        $_POST['custom-field-default-value'],
198                                        $custom_field_properties,
199                                        $_POST['custom-field-duplicate']
200                                        );
201                                break;
202                               
203                        case 'submit-edit-custom-field':
204                               
205                                include_once('RCCWP_CustomField.php');
206                               
207                               
208                                $current_field_obj = RCCWP_CustomField::Get($_POST['custom-field-id']);
209                                if ($_POST['custom-field-name']!=$current_field_obj->name && RCCWP_Processor::CheckFieldName($_POST['custom-field-name'], $_REQUEST['custom-write-panel-id'])){
210                                        $newURL = RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-field').'&custom-field-id='.$_POST['custom-field-id'].'&err_msg=-1';
211                                        wp_redirect($newURL);
212                                        exit;
213                                }
214                               
215                                $current_field = RCCWP_CustomField::GetCustomFieldTypes((int)$_POST['custom-field-type']);
216                               
217                                if ($current_field->has_properties)
218                                {
219                                        $custom_field_properties = array();
220                                        if (in_array($current_field->name, array('Textbox', 'Listbox')))
221                                        {
222                                                $custom_field_properties['size'] = $_POST['custom-field-size'];
223                                        }
224                                        else if (in_array($current_field->name, array('Multiline Textbox')))
225                                        {
226                                                $custom_field_properties['height'] = $_POST['custom-field-height'];
227                                                $custom_field_properties['width'] = $_POST['custom-field-width'];
228                                        }
229                                        else if( in_array( $current_field->name, array('Image') ) )
230                                        { 
231                                                $params = '';
232                                               
233                                                if( $_POST['custom-field-photo-height'] != '' && is_numeric( $_POST['custom-field-photo-height']) )
234                                                {
235                                                        $params = '&h=' . $_POST['custom-field-photo-height'];
236                                                }
237       
238                                                if( $_POST['custom-field-photo-width'] != '' && is_numeric( $_POST['custom-field-photo-width']) )
239                                                {
240                                                        $params .= '&w=' . $_POST['custom-field-photo-width'];
241                                                }
242                                               
243                                                if( $_POST['custom-field-custom-params'] != '' )
244                                                {
245                                                        $params .= '&' . $_POST['custom-field-custom-params'];
246                                                }
247       
248                                                if( $params )
249                                                {
250                                                        $custom_field_properties['params'] = $params;
251                                                }
252                                        }
253                                        else if (in_array($current_field->name, array('Date')))
254                                        {
255                                                $custom_field_properties['format'] = $_POST['custom-field-date-format'];
256                                        }
257                                }
258                               
259                                RCCWP_CustomField::Update(
260                                        $_POST['custom-field-id'],
261                                        $_POST['custom-field-name'],
262                                        $_POST['custom-field-description'],
263                                        $_POST['custom-field-order'],
264                                        $_POST['custom-field-required'],
265                                        $_POST['custom-field-type'],
266                                        $_POST['custom-field-options'],
267                                        $_POST['custom-field-default-value'],
268                                        $custom_field_properties,
269                                        $_POST['custom-field-duplicate']
270                                        );
271                                       
272                                break;
273                               
274                        case 'delete-custom-field':
275                               
276                                include_once('RCCWP_CustomField.php');
277                               
278                                if(isset($_REQUEST['custom-group-id']) && !empty($_REQUEST['custom-group-id']) )
279                                        $customGroupId = (int)$_REQUEST['custom-group-id'];
280       
281                                $customGroup = RCCWP_CustomGroup::Get($customGroupId);
282       
283                                RCCWP_CustomField::Delete($_REQUEST['custom-field-id']);
284       
285                                break;
286
287                        default:
288                                                               
289                                if (RCCWP_Application::InWritePostPanel())
290                                {
291                                        include_once('RCCWP_Menu.php');
292                                        include_once('RCCWP_WritePostPage.php');
293                                       
294                                        $CUSTOM_WRITE_PANEL = RCCWP_Post::GetCustomWritePanel();
295                                       
296                                       
297                                        if (isset($CUSTOM_WRITE_PANEL))
298                                        {
299                                                               
300                                                ob_start(array('RCCWP_WritePostPage', 'ApplyCustomWritePanelAssignedCategories'));
301                                                                                                       
302                                                add_action('admin_head', array('RCCWP_WritePostPage', 'ApplyCustomWritePanelHeader'));
303                                               
304                                                // Allows fields to be added to right
305                                                add_action('submitpost_box', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterfaceRight'), 5); 
306                                                add_action('submitpage_box', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterfaceRight'), 5);
307                                               
308                                                // Allows fields to be added to the post edit body
309                                                add_action('simple_edit_form', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'), 5);
310                                                add_action('edit_form_advanced', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'), 5);
311                                                add_action('edit_page_form', array('RCCWP_WritePostPage', 'CustomFieldCollectionInterface'), 5);
312
313                                        }
314                                        else if (!isset($_REQUEST['no-custom-write-panel']) && isset($_REQUEST['post']))
315                                        {
316                                                include_once('RCCWP_Options.php');
317                                                $promptEditingPost = RCCWP_Options::Get('prompt-editing-post');
318                                                if ($promptEditingPost == 1)
319                                                {
320                                                        wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&assign-custom-write-panel=' . (int)$_GET['post']);
321                                                }
322                                        }
323                                }
324                               
325                               
326                                else if (isset($_POST['finish-create-custom-write-module']))
327                                {
328                                        include_once('RCCWP_CustomWriteModule.php');
329                                        $customWriteModuleId = RCCWP_CustomWriteModule::Create(
330                                                        $_POST['custom-write-module-name'], $_POST['custom-write-module-description']);
331               
332                                        //RCCWP_CustomWritePanel::AssignToRole($customWritePanelId, 'administrator');
333                                        if ($customWriteModuleId == -1){
334                                                //$_POST['create-custom-write-module'] = 1;
335                                                $modulesURL = '?page=' . 'FlutterManageModules' . '&view-modules=1&create-custom-write-module=1&err_msg=-1';
336                                                wp_redirect($modulesURL);
337                                               
338                                        }
339                                        else
340                                                wp_redirect(RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($customWriteModuleId));
341                                }
342                               
343                                else if (isset($_POST['submit-edit-custom-write-module']))
344                                {
345                                                include_once('RCCWP_CustomWriteModule.php');
346                                               
347                                                $customWriteModuleId = RCCWP_CustomWriteModule::Update(
348                                                        $_REQUEST['custom-write-module-id'],
349                                                        $_REQUEST['custom-write-module-name'],
350                                                        $_REQUEST['custom-write-module-description']);
351               
352                                                if ($customWriteModuleId == -1){
353                                                        $customWriteModuleId = $_REQUEST['custom-write-module-id'];
354                                                        $modulesURL = '?page=' . 'FlutterManageModules' . "&edit-custom-write-module=1&view-custom-write-module=$customWriteModuleId&custom-write-module-id=$customWriteModuleId&err_msg=-1";
355                                                        wp_redirect($modulesURL);
356                                                       
357                                                }
358                                               
359                                                       
360                                                //RCCWP_CustomWritePanel::AssignToRole($_POST['custom-write-panel-id'], 'administrator');
361                                }
362                               
363               
364                               
365                               
366                                else if (isset($_POST['update-custom-write-panel-options']))
367                                {
368                                        if ($_POST['uninstall-custom-write-panel'] == 'uninstall')
369                                        {
370                                                RCCWP_Application::Uninstall();
371                                                wp_redirect('options-general.php');
372                                        }
373                                        else
374                                        {
375                                                include_once('RCCWP_Options.php');
376                                               
377                                                $options['hide-write-post'] = $_POST['hide-write-post'];
378                                                $options['hide-write-page'] = $_POST['hide-write-page'];
379                                                $options['prompt-editing-post'] = $_POST['prompt-editing-post'];
380                                                $options['assign-to-role'] = $_POST['assign-to-role'];
381                                                $options['use-snipshot'] = $_POST['use-snipshot'];
382                                                $options['enable-editnplace'] = $_POST['enable-editnplace'];
383                                                $options['enable-swfupload'] = $_POST['enable-swfupload'] ;
384                                                $options['default-custom-write-panel'] = $_POST['default-custom-write-panel'];
385                                                $options['enable-HTMLPurifier'] = $_POST['enable-HTMLPurifier'];
386                                                $options['tidy-level'] = $_POST['tidy-level'];
387                                                $options['canvas_show_instructions'] = $_POST['canvas_show_instructions'];
388                                                $options['canvas_show_zone_name'] = $_POST['canvas_show_zone_name'];
389                                                $options['canvas_show'] = $_POST['canvas_show'];
390                                                $options['ink_show'] = $_POST['ink_show'];
391               
392                                               
393                                                RCCWP_Options::Update($options);
394                                        }
395                                }
396                                else if (isset($_REQUEST['create-module-duplicate']))
397                                {
398                                        include_once('RCCWP_ModuleDuplicate.php');
399                                        $moduleID = $_REQUEST['custom-write-module-id'];
400                                        RCCWP_ModuleDuplicate::Create($moduleID);
401                                        wp_redirect(RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($moduleID));
402                                }
403                                else if (isset($_POST['submit-edit-module-duplicate']))
404                                {
405                                        include_once('RCCWP_ModuleDuplicate.php');
406                                        $moduleID = $_REQUEST['custom-write-module-id'];
407                                        RCCWP_ModuleDuplicate::Update(
408                                                $_REQUEST['module-duplicate-id'],
409                                                $_REQUEST['module-duplicate-name']);
410                                        wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php') . '&view-custom-write-module=' . $moduleID . '&custom-write-module-id=' . $moduleID);
411                                }
412                                else if (isset($_REQUEST['delete-module-duplicate']))
413                                {
414                                        include_once('RCCWP_ModuleDuplicate.php');
415                                        $moduleID = $_REQUEST['custom-write-module-id'];
416                                        RCCWP_ModuleDuplicate::Delete($_REQUEST['module-duplicate-id']);
417                                        wp_redirect(RCCWP_ManagementPage::GetCustomWriteModuleEditUrl($moduleID));
418                                }
419                               
420                                else if (isset($_POST['delete-custom-write-module']))
421                                {
422                                        include_once('RCCWP_CustomWriteModule.php');
423                                        $moduleID = $_REQUEST['custom-write-module-id'];
424                                        RCCWP_CustomWriteModule::Delete($moduleID);
425                                        wp_redirect('?page=' . urlencode(FLUTTER_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'RCCWP_Menu.php'). '&view-modules=1');
426                                }
427               
428                }
429               
430        }
431       
432       
433       
434        function FlushAllOutputBuffer() 
435        { 
436               
437                while (@ob_end_flush()); 
438               
439        } 
440       
441        function Redirect($location)
442        {
443                global $post_ID;
444                global $page_ID;
445
446               
447                if (!empty($_REQUEST['rc-cwp-custom-write-panel-id']))
448                {
449                        if (strstr($location, 'post-new.php?posted=') || strstr($location, 'page-new.php?posted='))
450                        {
451                                $id = ($post_ID=="")?$page_ID:$post_ID;
452                                $location = $_REQUEST['_wp_http_referer'] . '&posted=' . $id;
453                        }
454                }
455                return $location;
456        }
457       
458        function CheckFieldName($fieldName, $panelID){
459                global $wpdb;
460               
461                $sql = "SELECT id, group_id FROM " . RC_CWP_TABLE_GROUP_FIELDS .
462                                " WHERE name='$fieldName' ";
463                $results =$wpdb->get_results($sql);
464       
465                foreach($results as $result){
466                        $fieldGroup = RCCWP_CustomGroup::Get($result->group_id);
467                        if ($panelID == $fieldGroup->panel_id){
468                                return true;
469                        }
470                }
471                return false;
472        }
473
474}
475?>
Note: See TracBrowser for help on using the browser.