db = &EL_Db::get_instance(); $this->options = &EL_Options::get_instance(); $this->categories = &EL_Categories::get_instance(); $this->is_new = !(isset($_GET['action']) && ('edit' === $_GET['action'] || 'added' === $_GET['action'] || 'modified' === $_GET['action'])); $this->is_duplicate = $this->is_new && isset($_GET['id']) && is_numeric($_GET['id']); } public function show_new() { if(!current_user_can('edit_posts')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $out = '

'.__('Add New Event','event-list').'

'; if($this->is_duplicate) { $out .= '('.sprintf(__('Duplicate of event id:%d','event-list'), $_GET['id']).')'; } $out .= $this->edit_event(); $out .= '
'; echo $out; } public function embed_new_scripts() { wp_enqueue_script('jquery-ui-datepicker'); wp_enqueue_script('link'); wp_enqueue_script('eventlist_admin_new_js', EL_URL.'admin/js/admin_new.js'); wp_enqueue_style('eventlist_admin_new', EL_URL.'admin/css/admin_new.css'); } public function edit_event() { $dateformat = $this->get_event_dateformat(); if($this->is_new && !$this->is_duplicate) { // set next day as date $start_date = current_time('timestamp')+86400; // next day (86400 seconds = 1*24*60*60 = 1 day); $end_date = $start_date; } else { // set event data and existing date $event = $this->db->get_event($_GET['id']); $start_date = strtotime($event->start_date); $end_date = strtotime($event->end_date); } // Add required data for javascript in a hidden field $json = json_encode(array('el_url' => EL_URL, 'el_date_format' => $this->datepicker_format($dateformat))); $out = '
'; $out .= " "; // single quote required for value due to json layout // TODO: saving changed metabox status and order is not working yet $out .= wp_nonce_field('autosavenonce', 'autosavenonce', false, false); $out .= wp_nonce_field('closedpostboxesnonce', 'closedpostboxesnonce', false, false); $out .= wp_nonce_field('meta-box-order-nonce', 'meta-box-order-nonce', false, false); $out .= '
'; if($this->is_new) { $out .= ' '; } else { $out .= ' '; } $out .= '
title) ? $event->title : '').'" />
-
time) ? $event->time : '').'" />
location) ? $event->location : '').'" />
'; $editor_settings = array('drag_drop_upload' => true, 'textarea_rows' => 20); ob_start(); wp_editor(isset($event->details) ? $event->details : '', 'details', $editor_settings); $out .= ob_get_contents(); ob_end_clean(); $out .= '

NOTE: In the text editor, use RETURN to start a new paragraph - use SHIFT-RETURN to start a new line.

'; $out .= '
'; add_meta_box('event-publish', __('Publish','event-list'), array(&$this, 'render_publish_metabox'), 'event-list'); $metabox_args = isset($event->categories) ? array('event_cats' => $event->categories) : null; add_meta_box('event-categories', __('Categories','event-list'), array(&$this, 'render_category_metabox'), 'event-list', 'advanced', 'default', $metabox_args); ob_start(); do_meta_boxes('event-list', 'advanced', null); $out .= ob_get_contents(); ob_end_clean(); $out .= '
'; return $out; } public function render_publish_metabox() { $button_text = $this->is_new ? __('Publish','event-list') : __('Update','event-list'); $out = '
'.__('Cancel','event-list').'
'; echo $out; } public function render_category_metabox($post, $metabox) { $out = '
'; $cat_array = $this->categories->get_cat_array('name', 'asc'); if(empty($cat_array)) { $out .= __('No categories available.','event-list'); } else { $out .= ' '; } $out .= '
'; // TODO: Adding new categories in edit event form /*

'.__('+ Add New Category','event-list').'

*/ $out .= '
'.__('Goto Category Settings','event-list').'
'; echo $out; } private function get_event_dateformat() { if('' == $this->options->get('el_edit_dateformat')) { return __('Y/m/d'); } else { return $this->options->get('el_edit_dateformat'); } } /** * Convert a date format to a jQuery UI DatePicker format * * @param string $format a date format * @return string */ private function datepicker_format($format) { $chars = array( // Day 'd' => 'dd', 'j' => 'd', 'l' => 'DD', 'D' => 'D', // Month 'm' => 'mm', 'n' => 'm', 'F' => 'MM', 'M' => 'M', // Year 'Y' => 'yy', 'y' => 'y', ); return strtr((string)$format, $chars); } } ?>