root/afridex/plugins/Flutter/RCCWP_Menu.php @ 21

Revision 21, 16.3 kB (checked in by admin, 18 years ago)
RevLine 
[21]1<?php
2require_once ('RCCWP_Application.php');
3require_once ('RCCWP_ManagementPage.php');
4require_once ('RCCWP_CreateCustomWritePanelPage.php');
5require_once ('RCCWP_CreateCustomWriteModulePage.php');
6require_once ('RCCWP_CustomWriteModulePage.php');
7require_once ('RCCWP_CreateCustomGroupPage.php');
8require_once ('RCCWP_CreateCustomFieldPage.php');
9require_once ('RCCWP_CustomFieldPage.php');
10require_once ('RCCWP_CreatePanelModulePage.php');
11require_once ('RCCWP_ModuleDuplicate.php');
12require_once ('RCCWP_ModuleDuplicatePage.php');
13
14
15class RCCWP_Menu
16{
17        function PrepareModulesPanelsMenuItems()
18        {
19                $sub_menu_is_modules = false;
20               
21                $currentAction = $_REQUEST['flutter_action'];
22               
23                switch ($currentAction){
24                       
25                        // ------------ Custom Fields
26                        case 'create-custom-field':
27                                $page_group = 'RCCWP_CreateCustomFieldPage';
28                                $page_type = 'Main';
29                                break;
30
31                        case 'continue-create-custom-field':           
32                                if(isset($_REQUEST['custom-group-id']) && !empty($_REQUEST['custom-group-id']) )
33                                        $customGroupId = (int)$_REQUEST['custom-group-id'];
34                                $customGroup = RCCWP_CustomGroup::Get($customGroupId);
35       
36                                $current_field = RCCWP_CustomField::GetCustomFieldTypes((int)$_REQUEST['custom-field-type']);
37                                if ($current_field->has_options == "true" || $current_field->has_properties == "true")
38                                {
39                                        $page_group = 'RCCWP_CreateCustomFieldPage';
40                                        $page_type = 'SetOptions';
41                                }
42                                else if ($current_field->has_options == "false")
43                                {
44                                        RCCWP_CustomField::Create(
45                                                $_POST['custom-group-id'],
46                                                $_POST['custom-field-name'],
47                                                $_POST['custom-field-description'],
48                                                $_POST['custom-field-order'],
49                                                $_POST['custom-field-required'],
50                                                $_POST['custom-field-type'],
51                                                $_POST['custom-field-options'],
52                                                null,null,
53                                                $_POST['custom-field-duplicate']);
54       
55                                        $page_group = 'RCCWP_CustomWritePanelPage';
56                                        $page_type = 'View';
57                                        /*if ($customGroup->name=='__default'){
58                                                $page_group = 'RCCWP_CustomWritePanelPage';
59                                                $page_type = 'View';
60                                        }
61                                        else{
62                                                $page_group = 'RCCWP_CustomGroupPage';
63                                                $page_type = 'View';
64                                        }*/
65                                }
66                                break;
67               
68                        case 'delete-custom-field':
69                                $page_group = 'RCCWP_CustomWritePanelPage';
70                                $page_type = 'View';
71                                break;
72                                       
73                        case 'finish-create-custom-field':             
74                        case 'cancel-edit-custom-field':
75                        case 'cancel-create-custom-field':
76                        case 'submit-edit-custom-field':
77                        case 'copy-custom-field':
78                                /*$customGroupId = false;
79                                $customGroupId = (int)$_REQUEST['custom-group-id'];
80       
81                                $customGroup = RCCWP_CustomGroup::Get($customGroupId);
82                                if ($customGroup->name=='__default'){
83                                        $page_group = 'RCCWP_CustomWritePanelPage';
84                                        $page_type = 'View';
85                                }
86                                else{
87                                        $page_group = 'RCCWP_CustomGroupPage';
88                                        $page_type = 'View';
89                                }*/
90                                $page_group = 'RCCWP_CustomWritePanelPage';
91                                $page_type = 'View';
92                                break;
93                               
94                        case 'edit-custom-field':
95                                $page_group = 'RCCWP_CustomFieldPage';
96                                $page_type = 'Edit';
97                                break;
98               
99                        // ------------ Groups
100                       
101                        case 'create-custom-group':
102                                $page_group = 'RCCWP_CreateCustomGroupPage';
103                                $page_type = 'Main';
104                                break;
105                                       
106                        case 'view-custom-group':
107                                $page_group = 'RCCWP_CustomGroupPage';
108                                $page_type = 'View';
109                                break;
110
111                        case 'cancel-edit-custom-group':
112                        case 'cancel-create-custom-group':
113                        case 'delete-custom-group':
114                        case 'submit-edit-custom-group':
115                        case 'finish-create-custom-group':
116                                $page_group = 'RCCWP_CustomWritePanelPage';
117                                $page_type = 'View';
118                                break;
119                               
120                        case 'edit-custom-group':
121                                $page_group = 'RCCWP_CustomGroupPage';
122                                $page_type = 'Edit';
123                                break;
124                               
125                               
126
127                        // ------------ Custom Write Panels
128
129                        case 'view-custom-write-panel':
130                                $page_group = 'RCCWP_CustomWritePanelPage';
131                                $page_type = 'View';
132                                break;
133                               
134                        case 'create-custom-write-panel':
135                                $page_group = 'RCCWP_CreateCustomWritePanelPage';
136                                $page_type = 'Main';
137                                break;
138
139                        case 'finish-create-custom-write-panel':
140                                $page_group = 'RCCWP_CustomWritePanelPage';
141                                $page_type = 'View';
142                                break;
143                               
144                        case 'edit-custom-write-panel':
145                                $page_group = 'RCCWP_CustomWritePanelPage';
146                                $page_type = 'Edit';
147                                break;
148                               
149                        case 'cancel-edit-custom-write-panel':
150                                $page_group = 'RCCWP_CustomWritePanelPage';
151                                $page_type = 'View';
152                                break;
153                               
154                        case 'submit-edit-custom-write-panel':
155                                $page_group = 'RCCWP_CustomWritePanelPage';
156                                $page_type = 'View';
157                                break;
158                               
159                        case 'import-write-panel':
160                                $page_group = 'RCCWP_CustomWritePanelPage';
161                                $page_type = 'Import';
162                                break;
163                               
164
165                        // ------------ Modules
166                        case 'import-module':
167                                $page_group = 'RCCWP_CustomWriteModulePage';
168                                $page_type = 'Import';
169                                $sub_menu_is_modules = true;
170                                break;
171                               
172                        case 'create-custom-write-module':
173                                $page_group = 'RCCWP_CreateCustomWriteModulePage';
174                                $page_type = 'Main';
175                                $sub_menu_is_modules = true;
176                                break;
177                               
178                        case 'prepare-export-write-module':
179                                $page_group = 'RCCWP_CustomWriteModulePage';
180                                $page_type = 'PrepareExport';
181                                $sub_menu_is_modules = true;
182                                break;
183                                                                                               
184                        default:
185                               
186                               
187                               
188                                if (isset($_REQUEST['assign-custom-write-panel']))
189                                {
190                                        $page_group = 'RCCWP_ManagementPage';
191                                        $page_type = 'AssignCustomWritePanel';
192                                        $sub_menu_is_modules = false;
193                                }
194                                // ------- Groups
195                               
196                                else if (isset($_REQUEST['cancel-edit-custom-group']))
197                                {
198                                        $page_group = 'RCCWP_CustomGroupPage';
199                                        $page_type = 'View';
200                                }
201                               
202                                else if (isset($_REQUEST['view-groups']))
203                                {
204                                        $page_group = 'RCCWP_ManagementPage';
205                                        $page_type = 'ViewGroups';
206                                }
207                               
208                                // ------- Modules
209                               
210                                else if (isset($_REQUEST['edit-custom-write-module']))
211                                {
212                                        $page_group = 'RCCWP_CustomWriteModulePage';
213                                        $page_type = 'Edit';
214                                        $sub_menu_is_modules = true;
215                                }
216                                else if (isset($_REQUEST['cancel-edit-custom-write-module']))
217                                {
218                                        $page_group = 'RCCWP_CustomWriteModulePage';
219                                        $page_type = 'View';
220                                        $sub_menu_is_modules = true;
221                                }
222                                else if (isset($_REQUEST['submit-edit-custom-write-module']))
223                                {
224                                        $page_group = 'RCCWP_CustomWriteModulePage';
225                                        $page_type = 'View';
226                                        $sub_menu_is_modules = true;
227                                }
228                                else if (isset($_REQUEST['view-custom-write-module']))
229                                {
230                                        $page_group = 'RCCWP_CustomWriteModulePage';
231                                        $page_type = 'View';
232                                        $sub_menu_is_modules = true;
233                                }
234                                else if (isset($_REQUEST['view-modules']))
235                                {
236                                        $page_group = 'RCCWP_ManagementPage';
237                                        $page_type = 'ViewModules';
238                                        $sub_menu_is_modules = true;
239                                }
240                               
241                                // ------- Modules Duplicates
242                                else if (isset($_REQUEST['cancel-edit-module-duplicate']))
243                                {
244                                        $page_group = 'RCCWP_CustomWriteModulePage';
245                                        $page_type = 'View';
246                                        $sub_menu_is_modules = true;
247                                }
248                                else if (isset($_REQUEST['edit-module-duplicate']))
249                                {
250                                        $page_group = 'RCCWP_ModuleDuplicatePage';
251                                        $page_type = 'Edit';
252                                        $sub_menu_is_modules = true;
253                                }
254                                else if (isset($_REQUEST['submit-edit-module-duplicate']))
255                                {
256                                        $page_group = 'RCCWP_CustomWriteModulePage';
257                                        $page_type = 'View';
258                                        $sub_menu_is_modules = true;
259                                }
260                                // ------- Default behavior
261                                else{
262                                        $page_group = 'RCCWP_CustomWritePanelPage';
263                                        $page_type = 'ViewWritePanels';
264                                        $sub_menu_is_modules = false;
265                                }
266                               
267                }
268               
269               
270               
271               
272               
273                               
274
275
276                if ($sub_menu_is_modules){
277                        $result->panelsMenuFunction = array('RCCWP_CustomWritePanelPage', 'ViewWritePanels');
278                        $result->modulesMenuFunction = array($page_group, $page_type);
279                }
280                else{
281                        $result->panelsMenuFunction = array($page_group, $page_type);
282                        $result->modulesMenuFunction = array('RCCWP_ManagementPage', 'ViewModules');
283                }
284
285                return $result;
286
287
288        }
289
290       
291        function AttachFlutterMenus()
292        {
293                require_once ('canvas-admin.php');
294                require_once ('RCCWP_OptionsPage.php');
295
296                //$showPanelsModules = true;
297                //If we are Wordrpess mu and the user is not top admin, don't show panels and modules.
298                //if (function_exists('is_site_admin') && !is_site_admin()) $showPanelsModules = false;
299
300                if ((!current_user_can(FLUTTER_CAPABILITY_PANELS) && !current_user_can(FLUTTER_CAPABILITY_MODULES)) &&
301                    (!RCCWP_Options::Get('canvas_show') || !current_user_can(FLUTTER_CAPABILITY_LAYOUT)) &&
302                    (!RCCWP_Options::Get('ink_show') || !current_user_can(FLUTTER_CAPABILITY_STYLE)) )
303                        return;
304
305                       
306
307                //if ($showPanelsModules)
308                $panelsAndModulesFunctions = RCCWP_Menu::PrepareModulesPanelsMenuItems();
309
310                // Add top menu
311                add_menu_page(__('Flutter > Manage'), 'Flutter', FLUTTER_CAPABILITY_PANELS, __FILE__, $panelsAndModulesFunctions->panelsMenuFunction);
312
313                // Add Flutter submenus
314                //if ($showPanelsModules)
315                        add_submenu_page(__FILE__, __('Write Panels'), __('Write Panels'), FLUTTER_CAPABILITY_PANELS, __FILE__, $panelsAndModulesFunctions->panelsMenuFunction);
316               
317                //if ($showPanelsModules)
318                        add_submenu_page(__FILE__, __('Modules'), __('Modules'), FLUTTER_CAPABILITY_MODULES, 'FlutterManageModules', $panelsAndModulesFunctions->modulesMenuFunction);         
319               
320                if (RCCWP_Options::Get('canvas_show'))
321                        add_submenu_page(__FILE__, __('Layout'), __('Layout'), FLUTTER_CAPABILITY_LAYOUT, 'FlutterEditCanvas', 'canvas_admin');
322                if (RCCWP_Options::Get('ink_show'))
323                        add_submenu_page(__FILE__, __('Style'), __('Style'), FLUTTER_CAPABILITY_STYLE, 'FlutterInk', 'canvas_ink_admin');
324
325        }
326
327        function AttachOptionsMenuItem()
328        {
329
330                require_once ('RCCWP_OptionsPage.php');
331                add_options_page(__('Flutter Options'), __('Flutter'), 'manage_options', 'RCCWP_OptionsPage.php', array('RCCWP_OptionsPage', 'Main'));
332        }
333
334
335        function StartPage(){
336                return;
337/*              $showPanelsModules = true;
338                //If we are Wordrpess mu and the user is not top admin, don't show panels and modules.
339                if (function_exists('is_site_admin') && !is_site_admin()) $showPanelsModules = false;
340
341                $startPageContent.=
342<<<EOF
343        <h2> Flutter Manager </h2>
344        <p> Welcome to Flutter management pages. You can:</p>
345        <ul>
346EOF;
347
348                if ($showPanelsModules && current_user_can(FLUTTER_CAPABILITY_PANELS)) $startPageContent.= '<li><a href="">Manage Write Panels</a></li>';
349                if ($showPanelsModules && current_user_can(FLUTTER_CAPABILITY_MODULES)) $startPageContent.= '<li><a href="">Manage Modules</a></li>';
350                if (RCCWP_Options::Get('canvas_show') && current_user_can(FLUTTER_CAPABILITY_LAYOUT)) $startPageContent.= '<li><a href="">Change theme Layout</a></li>';
351                if (RCCWP_Options::Get('ink_show') && current_user_can(FLUTTER_CAPABILITY_STYLE)) $startPageContent.= '<li><a href="">Change theme style</a></li>';
352
353                $startPageContent.= "</ul>";
354                echo $startPageContent;
355*/
356        }
357
358
359
360       
361        function AttachCustomWritePanelMenuItems()
362        {
363                require_once ('RCCWP_Options.php');
364                $assignToRole = RCCWP_Options::Get('assign-to-role');
365                $requiredPostsCap = 'edit_posts';
366                $requiredPagesCap = 'edit_pages';
367
368
369                $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels();
370
371                foreach ($customWritePanels as $panel)
372                {
373                        if ($assignToRole == 1){
374                                $requiredPostsCap = $panel->capability_name;
375                                $requiredPagesCap = $panel->capability_name;
376                        }
377
378                        if ($panel->type == "post"){
379                                add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPostsCap, 'post-new.php?custom-write-panel-id=' . $panel->id);
380                                add_submenu_page('edit.php', __($panel->name), __($panel->name), $requiredPostsCap, 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
381                        }
382                        else {
383                                add_submenu_page('post-new.php', __($panel->name), __($panel->name), $requiredPagesCap, 'page-new.php?custom-write-panel-id=' . $panel->id);
384                                add_submenu_page('edit.php', __($panel->name), __($panel->name), $requiredPagesCap, 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . $panel->id);
385                        }
386                }
387               
388                RCCWP_Menu::SetCurrentCustomWritePanelMenuItem();
389               
390        }
391
392        function HighlightCustomPanel(){
393                global $wpdb, $submenu_file, $post; 
394               
395                $result = $wpdb->get_results( " SELECT meta_value
396                                                FROM $wpdb->postmeta
397                                                WHERE post_id = '".$post->ID."' and meta_key = '_rc_cwp_write_panel_id'", ARRAY_A );
398                $currPage = basename($_SERVER['SCRIPT_NAME']);
399                if (count($result) > 0 && $currPage =="post.php" ){
400                        $id = $result[0]['meta_value'];
401                        $submenu_file = "edit.php?filter-posts=1&custom-write-panel-id=$id";
402                }
403                elseif (count($result) > 0 && $currPage == "page.php" ){
404                        $id = $result[0]['meta_value'];
405                        $submenu_file = "edit-pages.php?filter-posts=1&custom-write-panel-id=$id";
406                }
407               
408               
409        }
410
411        function FilterPostsPagesList($where){
412                global $wpdb;
413                if (isset($_GET['filter-posts'])) {
414                        $panel_id = $_GET['custom-write-panel-id'];
415                        $where = $where . " AND 0 < (SELECT count($wpdb->postmeta.meta_value)
416                                        FROM $wpdb->postmeta
417                                        WHERE $wpdb->postmeta.post_id = $wpdb->posts.ID and $wpdb->postmeta.meta_key = '_rc_cwp_write_panel_id' and $wpdb->postmeta.meta_value = '$panel_id') ";
418                }
419                return $where;
420                /*$i = 0;
421                if (isset($_GET['filter-posts']) && (!empty($posts))) {
422                        $panel_id = $_GET['custom-write-panel-id'];
423                        foreach($posts as $my_post){
424                                $result = $wpdb->get_results( " SELECT meta_value
425                                        FROM $wpdb->postmeta
426                                        WHERE post_id = '$my_post->ID' and meta_key = '_rc_cwp_write_panel_id' and meta_value = '$panel_id'", ARRAY_A );
427                                if (count($result) == 0 )
428                                        array_splice($posts, $i ,1);
429                                else
430                                        $i++;
431                        }
432
433                }
434                return $posts;*/
435        }
436       
437        function DetachWpWritePanelMenuItems()
438        {
439                require_once ('RCCWP_Options.php');
440                global $submenu;
441
442                $options = RCCWP_Options::Get();
443               
444                if ($options['hide-write-post'] == '1')
445                        unset($submenu['post-new.php'][5]);
446               
447                if ($options['hide-write-page'] == '1')
448                        unset($submenu['post-new.php'][10]);   
449        }
450       
451        function SetCurrentCustomWritePanelMenuItem()
452        {
453               
454                global $submenu_file;
455                global $menu;
456               
457                require_once ('RCCWP_Options.php');
458                $options = RCCWP_Options::Get();
459               
460                if ($options['default-custom-write-panel'] != '')
461                {
462                        require_once ('RCCWP_CustomWritePanel.php');
463                       
464                        $customWritePanel = RCCWP_CustomWritePanel::Get((int)$options['default-custom-write-panel']);
465                       
466                        if ($customWritePanel->type == "post")
467                                $menu[5][2] = 'post-new.php?custom-write-panel-id=' . (int)$options['default-custom-write-panel'];
468                        else
469                                $menu[5][2] = 'page-new.php?custom-write-panel-id=' . (int)$options['default-custom-write-panel'];
470                       
471                }
472               
473                if ($_REQUEST['custom-write-panel-id'])
474                {
475                        $customWritePanel = RCCWP_CustomWritePanel::Get((int)$_REQUEST['custom-write-panel-id']);
476                        if ($_REQUEST['filter-posts']){
477                                if ($customWritePanel->type == "post")
478                                        $submenu_file = 'edit.php?filter-posts=1&custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id'];
479                                else
480                                        $submenu_file = 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id'];
481                        }
482                        else{
483                                if ($customWritePanel->type == "post")
484                                        $submenu_file = 'post-new.php?custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id'];
485                                else
486                                        $submenu_file = 'page-new.php?custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id'];
487                        }
488                }
489
490        }
491
492        function AddThickbox()
493        {
494                if ($_GET['page']=='FlutterManageModules') {
495                        // Overcome bug (http://wordpress.org/support/topic/196884)
496                        $thickBoxCSS = get_bloginfo('url').'/wp-includes/js/thickbox/thickbox.css';
497                        ?>
498                        <link rel='stylesheet' href='<?php echo $thickBoxCSS?>' type='text/css' />
499                        <?php
500                       
501                        wp_enqueue_script('prototype');
502                        wp_enqueue_script('thickbox');
503                }
504               
505        }
506       
507        function ShowPanel($panel){
508                return true;
509                require_once ('RCCWP_CustomWritePanel.php');
510                global $wpdb, $canvas;
511
512                if ($panel->always_show) return true;
513
514                $custom_panel_modules = RCCWP_CustomWritePanel::GetPanelCustomModules($panel->id);
515                foreach ($custom_panel_modules as $panel_module){
516                        //echo "SELECT * FROM ".$canvas->main." WHERE module_id = $panel_module->mod_id AND zone <> 'shelf'";
517                        if($wpdb->get_results("SELECT * FROM ".$canvas->main." WHERE module_id = $panel_module->mod_id AND zone <> 'shelf'"))
518                                return true;
519                }
520
521                if ( 0 < $wpdb->get_var("SELECT count($wpdb->postmeta.meta_value)
522                        FROM $wpdb->postmeta
523                        WHERE $wpdb->postmeta.meta_key = '_rc_cwp_write_panel_id' and $wpdb->postmeta.meta_value = '$panel->id'")){
524                                return true;
525                }
526
527                return false;
528        }
529}
530?>
Note: See TracBrowser for help on using the browser.