| [21] | 1 | <?php |
|---|
| 2 | include_once('RCCWP_ManagementPage.php'); |
|---|
| 3 | include_once('RCCWP_CreateCustomWritePanelPage.php'); |
|---|
| 4 | include_once('RCCWP_CreateCustomFieldPage.php'); |
|---|
| 5 | include_once('RCCWP_CustomFieldPage.php'); |
|---|
| 6 | |
|---|
| 7 | class RCCWP_Menu |
|---|
| 8 | { |
|---|
| 9 | function AttachManagementMenuItem() |
|---|
| 10 | { |
|---|
| 11 | $page_group = 'RCCWP_ManagementPage'; |
|---|
| 12 | $page_type = 'View'; |
|---|
| 13 | |
|---|
| 14 | if (isset($_REQUEST['create-custom-write-panel'])) |
|---|
| 15 | { |
|---|
| 16 | $page_group = 'RCCWP_CreateCustomWritePanelPage'; |
|---|
| 17 | $page_type = 'Main'; |
|---|
| 18 | } |
|---|
| 19 | else if (isset($_REQUEST['create-custom-field'])) |
|---|
| 20 | { |
|---|
| 21 | $page_group = 'RCCWP_CreateCustomFieldPage'; |
|---|
| 22 | $page_type = 'Main'; |
|---|
| 23 | } |
|---|
| 24 | else if (isset($_REQUEST['continue-create-custom-field'])) |
|---|
| 25 | { |
|---|
| 26 | $current_field = RCCWP_CustomField::GetCustomFieldTypes((int)$_REQUEST['custom-field-type']); |
|---|
| 27 | if ($current_field->has_options == "true" || $current_field->has_properties == "true") |
|---|
| 28 | { |
|---|
| 29 | $page_group = 'RCCWP_CreateCustomFieldPage'; |
|---|
| 30 | $page_type = 'SetOptions'; |
|---|
| 31 | } |
|---|
| 32 | else if ($current_field->has_options == "false") |
|---|
| 33 | { |
|---|
| 34 | RCCWP_CustomField::Create( |
|---|
| 35 | $_POST['custom-write-panel-id'], |
|---|
| 36 | $_POST['custom-field-name'], |
|---|
| 37 | $_POST['custom-field-description'], |
|---|
| 38 | $_POST['custom-field-order'], |
|---|
| 39 | $_POST['custom-field-type'], |
|---|
| 40 | $_POST['custom-field-options']); |
|---|
| 41 | |
|---|
| 42 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 43 | $page_type = 'View'; |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | else if (isset($_REQUEST['finish-create-custom-field'])) |
|---|
| 47 | { |
|---|
| 48 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 49 | $page_type = 'View'; |
|---|
| 50 | } |
|---|
| 51 | else if (isset($_REQUEST['finish-create-custom-write-panel'])) |
|---|
| 52 | { |
|---|
| 53 | $page_group = 'RCCWP_ManagementPage'; |
|---|
| 54 | $page_type = 'View'; |
|---|
| 55 | } |
|---|
| 56 | else if (isset($_REQUEST['edit-custom-write-panel'])) |
|---|
| 57 | { |
|---|
| 58 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 59 | $page_type = 'Edit'; |
|---|
| 60 | } |
|---|
| 61 | else if (isset($_REQUEST['cancel-edit-custom-write-panel'])) |
|---|
| 62 | { |
|---|
| 63 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 64 | $page_type = 'View'; |
|---|
| 65 | } |
|---|
| 66 | else if (isset($_REQUEST['submit-edit-custom-write-panel'])) |
|---|
| 67 | { |
|---|
| 68 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 69 | $page_type = 'View'; |
|---|
| 70 | } |
|---|
| 71 | else if (isset($_REQUEST['cancel-edit-custom-field'])) |
|---|
| 72 | { |
|---|
| 73 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 74 | $page_type = 'View'; |
|---|
| 75 | } |
|---|
| 76 | else if (isset($_REQUEST['submit-edit-custom-field'])) |
|---|
| 77 | { |
|---|
| 78 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 79 | $page_type = 'View'; |
|---|
| 80 | } |
|---|
| 81 | else if (isset($_REQUEST['edit-custom-field'])) |
|---|
| 82 | { |
|---|
| 83 | $page_group = 'RCCWP_CustomFieldPage'; |
|---|
| 84 | $page_type = 'Edit'; |
|---|
| 85 | } |
|---|
| 86 | else if (isset($_REQUEST['view-custom-write-panel'])) |
|---|
| 87 | { |
|---|
| 88 | $page_group = 'RCCWP_CustomWritePanelPage'; |
|---|
| 89 | $page_type = 'View'; |
|---|
| 90 | } |
|---|
| 91 | else if (isset($_REQUEST['assign-custom-write-panel'])) |
|---|
| 92 | { |
|---|
| 93 | $page_group = 'RCCWP_ManagementPage'; |
|---|
| 94 | $page_type = 'AssignCustomWritePanel'; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | add_management_page(__('Custom Write Panel'), __('Write Panels'), 'manage_options', __FILE__, array($page_group, $page_type)); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | function AttachOptionsMenuItem() |
|---|
| 101 | { |
|---|
| 102 | include_once('RCCWP_OptionsPage.php'); |
|---|
| 103 | add_options_page(__('Fresh Post Options'), __('Fresh Post'), 'manage_options', 'RCCWP_OptionsPage.php', array('RCCWP_OptionsPage', 'Main')); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | function AttachCustomWritePanelMenuItems() |
|---|
| 107 | { |
|---|
| 108 | include_once('RCCWP_Options.php'); |
|---|
| 109 | $assignToRole = RCCWP_Options::Get('assign-to-role'); |
|---|
| 110 | |
|---|
| 111 | $customWritePanels = RCCWP_Application::GetCustomWritePanels(); |
|---|
| 112 | |
|---|
| 113 | foreach ($customWritePanels as $panel) |
|---|
| 114 | { |
|---|
| 115 | if ($assignToRole <> 1 || current_user_can($panel->capability_name)) |
|---|
| 116 | { |
|---|
| 117 | if ($panel->type == "post"){ |
|---|
| 118 | add_submenu_page('edit.php', __($panel->name), __($panel->name), 'publish_posts', 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id); |
|---|
| 119 | } |
|---|
| 120 | else { |
|---|
| 121 | add_submenu_page('edit.php', __($panel->name), __($panel->name), 'publish_posts', 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . $panel->id); |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | if (isset($_REQUEST['post'])) |
|---|
| 128 | { |
|---|
| 129 | global $submenu; |
|---|
| 130 | //print_r($submenu); |
|---|
| 131 | global $CUSTOM_WRITE_PANEL; |
|---|
| 132 | /*if (isset($CUSTOM_WRITE_PANEL)) |
|---|
| 133 | if ($CUSTOM_WRITE_PANEL->type == "post") |
|---|
| 134 | $submenu['edit.php'][5] = array(__($CUSTOM_WRITE_PANEL->name), 'edit_posts', 'edit.php'); |
|---|
| 135 | else |
|---|
| 136 | $submenu['edit.php'][10] = array(__($CUSTOM_WRITE_PANEL->name), 'edit_pages', 'edit-pages.php'); |
|---|
| 137 | */ |
|---|
| 138 | } |
|---|
| 139 | else |
|---|
| 140 | { |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | foreach ($customWritePanels as $panel) |
|---|
| 144 | { |
|---|
| 145 | if ($assignToRole <> 1 || current_user_can($panel->capability_name)) |
|---|
| 146 | { |
|---|
| 147 | if ($panel->type == "post"){ |
|---|
| 148 | add_submenu_page('post-new.php', __($panel->name), __($panel->name), 'publish_posts', 'post-new.php?custom-write-panel-id=' . $panel->id); |
|---|
| 149 | //add_submenu_page('edit.php', __($panel->name), __($panel->name), 'publish_posts', 'edit.php?filter-posts=1&custom-write-panel-id=' . $panel->id); |
|---|
| 150 | } |
|---|
| 151 | else { |
|---|
| 152 | add_submenu_page('post-new.php', __($panel->name), __($panel->name), 'publish_posts', 'page-new.php?custom-write-panel-id=' . $panel->id); |
|---|
| 153 | //add_submenu_page('edit.php', __($panel->name), __($panel->name), 'publish_posts', 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . $panel->id); |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | RCCWP_Menu::SetCurrentCustomWritePanelMenuItem(); |
|---|
| 161 | |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | function HighlightCustomPanel(){ |
|---|
| 165 | global $wpdb, $submenu_file, $post; |
|---|
| 166 | |
|---|
| 167 | $result = $wpdb->get_results( " SELECT meta_value |
|---|
| 168 | FROM $wpdb->postmeta |
|---|
| 169 | WHERE post_id = '".$post->ID."' and meta_key = '_rc_cwp_write_panel_id'", ARRAY_A ); |
|---|
| 170 | $currPage = basename($_SERVER['SCRIPT_NAME']); |
|---|
| 171 | if (count($result) > 0 && $currPage =="post.php" ){ |
|---|
| 172 | $id = $result[0]['meta_value']; |
|---|
| 173 | $submenu_file = "edit.php?filter-posts=1&custom-write-panel-id=$id"; |
|---|
| 174 | } |
|---|
| 175 | elseif (count($result) > 0 && $currPage == "page.php" ){ |
|---|
| 176 | $id = $result[0]['meta_value']; |
|---|
| 177 | $submenu_file = "edit-pages.php?filter-posts=1&custom-write-panel-id=$id"; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | function FilterPostsPagesList($where){ |
|---|
| 184 | global $wpdb; |
|---|
| 185 | if (isset($_GET['filter-posts'])) { |
|---|
| 186 | $panel_id = $_GET['custom-write-panel-id']; |
|---|
| 187 | $where = $where . " AND 0 < (SELECT count($wpdb->postmeta.meta_value) |
|---|
| 188 | FROM $wpdb->postmeta |
|---|
| 189 | 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') "; |
|---|
| 190 | } |
|---|
| 191 | return $where; |
|---|
| 192 | /*$i = 0; |
|---|
| 193 | if (isset($_GET['filter-posts']) && (!empty($posts))) { |
|---|
| 194 | $panel_id = $_GET['custom-write-panel-id']; |
|---|
| 195 | foreach($posts as $my_post){ |
|---|
| 196 | $result = $wpdb->get_results( " SELECT meta_value |
|---|
| 197 | FROM $wpdb->postmeta |
|---|
| 198 | WHERE post_id = '$my_post->ID' and meta_key = '_rc_cwp_write_panel_id' and meta_value = '$panel_id'", ARRAY_A ); |
|---|
| 199 | if (count($result) == 0 ) |
|---|
| 200 | array_splice($posts, $i ,1); |
|---|
| 201 | else |
|---|
| 202 | $i++; |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | } |
|---|
| 206 | return $posts;*/ |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | function DetachWpWritePanelMenuItems() |
|---|
| 210 | { |
|---|
| 211 | include_once('RCCWP_Options.php'); |
|---|
| 212 | global $submenu; |
|---|
| 213 | |
|---|
| 214 | $options = RCCWP_Options::Get(); |
|---|
| 215 | |
|---|
| 216 | if ($options['hide-write-post'] == '1') |
|---|
| 217 | unset($submenu['post-new.php'][5]); |
|---|
| 218 | |
|---|
| 219 | if ($options['hide-write-page'] == '1') |
|---|
| 220 | unset($submenu['post-new.php'][10]); |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | function SetCurrentCustomWritePanelMenuItem() |
|---|
| 224 | { |
|---|
| 225 | // wp-admin/menu.php |
|---|
| 226 | global $submenu_file; |
|---|
| 227 | global $menu; |
|---|
| 228 | |
|---|
| 229 | include_once('RCCWP_Options.php'); |
|---|
| 230 | $options = RCCWP_Options::Get(); |
|---|
| 231 | |
|---|
| 232 | if ($options['default-custom-write-panel'] != '') |
|---|
| 233 | { |
|---|
| 234 | include_once('RCCWP_CustomWritePanel.php'); |
|---|
| 235 | |
|---|
| 236 | $customWritePanel = RCCWP_CustomWritePanel::Get((int)$options['default-custom-write-panel']); |
|---|
| 237 | if ($options['assign-to-role'] <> 1 || current_user_can($customWritePanel->capability_name)) |
|---|
| 238 | { |
|---|
| 239 | if ($customWritePanel->type == "post") |
|---|
| 240 | $menu[5][2] = 'post-new.php?custom-write-panel-id=' . (int)$options['default-custom-write-panel']; |
|---|
| 241 | else |
|---|
| 242 | $menu[5][2] = 'page-new.php?custom-write-panel-id=' . (int)$options['default-custom-write-panel']; |
|---|
| 243 | } |
|---|
| 244 | } |
|---|
| 245 | |
|---|
| 246 | if ($_REQUEST['custom-write-panel-id']) |
|---|
| 247 | { |
|---|
| 248 | $customWritePanel = RCCWP_CustomWritePanel::Get((int)$_REQUEST['custom-write-panel-id']); |
|---|
| 249 | if ($_REQUEST['filter-posts']){ |
|---|
| 250 | if ($customWritePanel->type == "post") |
|---|
| 251 | $submenu_file = 'edit.php?filter-posts=1&custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id']; |
|---|
| 252 | else |
|---|
| 253 | $submenu_file = 'edit-pages.php?filter-posts=1&custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id']; |
|---|
| 254 | } |
|---|
| 255 | else{ |
|---|
| 256 | if ($customWritePanel->type == "post") |
|---|
| 257 | $submenu_file = 'post-new.php?custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id']; |
|---|
| 258 | else |
|---|
| 259 | $submenu_file = 'page-new.php?custom-write-panel-id=' . (int)$_REQUEST['custom-write-panel-id']; |
|---|
| 260 | } |
|---|
| 261 | } |
|---|
| 262 | else if (isset($_REQUEST['post'])) |
|---|
| 263 | { |
|---|
| 264 | } |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | ?> |
|---|