Exemplo n.º 1
0
 function hookSaveEventFromPost($post_id)
 {
     global $fsCalendar;
     @session_start();
     // Check autosave
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // Store the postdata in the session, because all data gets lost on the
     // frontend, when a error occurs!
     $_SESSION['fse_postdata'] = $_POST;
     // Check nonce
     if (isset($_POST['eventid']) && $action != 'view') {
         $nonce = $_POST['_fseevent'];
         if (!wp_verify_nonce($nonce, 'event')) {
             $_SESSION['fse_error'] = __('Security check failed', fsCalendar::$plugin_textdom);
             return;
         }
     }
     $active = isset($_POST['fseventactive']) && $_POST['fseventactive'] == true;
     $sync = isset($_POST['fseventsync']) && $_POST['fseventsync'] == true;
     $synconce = isset($_POST['fseventupdate']) && $_POST['fseventupdate'] == true;
     // WP Calender event active?
     if (!$active) {
         return;
     }
     // Only use the main post (nut the revisions)
     if (wp_is_post_revision($post_id) !== false) {
         return;
     }
     // Check if an event exists
     $evt = new fsEvent(0, '', true, $post_id);
     // Neuer Event
     if (empty($evt->eventid)) {
         if (!$fsCalendar->userCanAddEvents()) {
             $_SESSION['fse_error'] = __('You do not have the permission to create events', fsCalendar::$plugin_textdom);
             return;
         }
     } else {
         // Check if needs to be updated!
         //if (!$sync && !$synconce)
         //	return;
         // Check authority to edit
         if (!$evt->userCanEditEvent()) {
             $_SESSION['fse_error'] = __('No permission to edit event', fsCalendar::$plugin_textdom);
             return;
         }
     }
     // Now add all the data
     $evt->postid = $post_id;
     $evt->updatedbypost = $sync;
     // Some date are only updated when requestet
     if ($sync || $synconce) {
         $post = get_post($post_id);
         $cats = wp_get_post_categories($post_id);
         $evt->subject = $post->post_title;
         $evt->description = $post->post_content;
         $evt->categories = array();
         foreach ($cats as $c) {
             $evt->categories[] = $c;
         }
     }
     $evt->allday = isset($_POST['event_allday']) ? true : false;
     $evt->date_admin_from = $_POST['event_from'];
     $evt->date_admin_to = $_POST['event_to'];
     $evt->time_admin_from = $_POST['event_tfrom'];
     $evt->time_admin_to = $_POST['event_tto'];
     $evt->location = $_POST['event_location'];
     if (($ret = $evt->saveToDataBase()) === true) {
         $_SESSION['fse_success'] = 'Successfully saved';
     } else {
         $_SESSION['fse_error'] = $ret;
     }
     return $post_id;
 }