/**
 * Set taxonomies for post
 *
 * @custom code since 2.8.4 added by Dheer Gupta http://webdisect.com
 *
 * @param int $post_id Post ID.
 * @param array $fields Taxonomy Fields
 * Enter Values as array
 * array ( 'tags' => '', 'taxonomy' => '' )
 */
function set_new_taxonomy_tag($post_id, $fields)
{
    $post_id = (int) $post_id;
    foreach ((array) $fields as $tax) {
        if (isset($tax['id'])) {
            $tax['id'] = (int) $tax['id'];
            if (isset($tax['taxonomy'])) {
                nxt_set_post_terms($tax['id'], $tax['tags'], $tax['taxonomy']);
            }
        } elseif ($post_id != '') {
            if (isset($tax['taxonomy'])) {
                nxt_set_post_terms($post_id, $tax['tags'], $tax['taxonomy']);
            }
        }
    }
}
 /**
  * has_gradebook( $assignment_id = null, $force_creation = true )
  *
  * Checks if $assignment_id has a gradebook
  * 
  * @param String $assignment_id, is assignment identifier
  *  default is null which defaults to $this->current_assignment as $assignment_id
  * @param Bool $force_creation, to force the creation of a gradebook if none exists
  * @return Int the ID of the gradebook
  */
 function has_gradebook($assignment_id = null, $force_creation = true)
 {
     global $bp;
     $gradebook_id = null;
     if (!$assignment_id) {
         $assignment_id = $this->current_assignment;
     }
     $assignment = BPSP_Assignments::is_assignment($assignment_id);
     if ($assignment) {
         $gradebook = reset(get_children(array('post_parent' => $assignment->ID, 'post_type' => 'gradebook')));
         if (!empty($gradebook)) {
             $gradebook_id = $gradebook->ID;
         }
     } else {
         return null;
     }
     if (!$gradebook_id && $force_creation) {
         $gradebook_id = nxt_insert_post(array('post_title' => ' ', 'post_type' => 'gradebook', 'post_status' => 'publish', 'post_parent' => $assignment->ID, 'post_author' => $bp->groups->current_group->creator_id));
         if ($gradebook_id) {
             nxt_set_post_terms($gradebook_id, $bp->groups->current_group->id, 'group_id');
             nxt_set_post_terms($gradebook_id, $assignment->ID, 'assignment_id');
         }
     }
     return $gradebook_id;
 }
Exemple #3
0
/**
 * Set the tags for a post.
 *
 * @since 2.3.0
 * @uses nxt_set_object_terms() Sets the tags for the post.
 *
 * @param int $post_id Post ID.
 * @param string $tags The tags to set for the post, separated by commas.
 * @param bool $append If true, don't delete existing tags, just add on. If false, replace the tags with the new tags.
 * @return mixed Array of affected term IDs. nxt_Error or false on failure.
 */
function nxt_set_post_tags($post_id = 0, $tags = '', $append = false)
{
    return nxt_set_post_terms($post_id, $tags, 'post_tag', $append);
}
 /**
  * edit_assignment_screen( $vars )
  *
  * Hooks into screen_handler
  * Edit assignment screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function edit_assignment_screen($vars)
 {
     global $bp;
     $nonce_name = 'edit_assignment';
     $updated_assignment_id = $this->current_assignment;
     $old_assignment = $this->is_assignment($this->current_assignment);
     if (!$this->has_assignment_caps($bp->loggedin_user->id) && !is_super_admin() || $bp->loggedin_user->id != $old_assignment->post_author) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to update the assignment.', 'bpsp');
         return $vars;
     }
     // Update assignment
     if (isset($_POST['assignment']) && $_POST['assignment']['object'] == 'group' && BPSP_Lectures::is_lecture($_POST['assignment']['lecture_id']) && isset($_POST['_nxtnonce'])) {
         $updated_assignment = $_POST['assignment'];
         $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name);
         if (true != $is_nonce) {
             $vars['error'] = __('Nonce Error while editing the assignment.', 'bpsp');
         } else {
             if (isset($updated_assignment['title']) && isset($updated_assignment['content']) && isset($updated_assignment['course_id']) && is_numeric($updated_assignment['group_id'])) {
                 $updated_assignment['title'] = strip_tags($updated_assignment['title']);
                 $updated_assignment_id = nxt_update_post(array('ID' => $old_assignment->ID, 'post_title' => $updated_assignment['title'], 'post_content' => $updated_assignment['content']));
                 if (is_object($updated_assignment_id) && isset($updated_assignment_id->ID)) {
                     $updated_assignment_id = $updated_assignment_id->ID;
                 }
                 if ($updated_assignment_id) {
                     nxt_set_post_terms($updated_assignment_id, $updated_assignment['course_id'], 'course_id');
                     if (strtotime($updated_assignment['due_date'])) {
                         update_post_meta($updated_assignment_id, 'due_date', $updated_assignment['due_date'], $old_assignment->due_date);
                     }
                     if (isset($updated_assignment['lecture_id'])) {
                         update_post_meta($updated_assignment_id, 'lecture_id', $updated_assignment['lecture_id']);
                     }
                     // Save the formbuilder
                     if (isset($updated_assignment['form']) && !empty($updated_assignment['form'])) {
                         $this->frmb->load_serialized($updated_assignment['form']);
                         if ($this->frmb->get_data()) {
                             update_post_meta($updated_assignment_id, 'form_data', $this->frmb->get_data(), $old_assignment->form_data);
                         }
                     }
                     $vars['message'] = __('Assignment was updated.', 'bpsp');
                     do_action('courseware_assignment_activity', $this->is_assignment($updated_assignment_id), 'update');
                 } else {
                     $vars['error'] = __('Assignment could not be updated.', 'bpsp');
                 }
             }
         }
     }
     $vars['name'] = 'edit_assignment';
     $vars['group_id'] = $bp->groups->current_group->id;
     $vars['user_id'] = $bp->loggedin_user->id;
     $vars['lecture_id'] = get_post_meta(isset($new_assignment_id) ? $new_assignment_id : $old_assignment->ID, 'lecture_id', true);
     $vars['lectures'] = BPSP_Lectures::has_lectures($bp->groups->current_group->id);
     $vars['assignment'] = $this->is_assignment($updated_assignment_id);
     $vars['assignment_edit_uri'] = $vars['current_uri'] . '/assignment/' . $this->current_assignment->post_name . '/edit/';
     $vars['assignment_delete_uri'] = $vars['current_uri'] . '/assignment/' . $this->current_assignment->post_name . '/delete/';
     $vars['assignment_permalink'] = $vars['current_uri'] . '/assignment/' . $this->current_assignment->post_name;
     $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     $vars['delete_nonce'] = add_query_arg('_nxtnonce', nxt_create_nonce('delete_assignment'), $vars['assignment_delete_uri']);
     $vars['trail'] = array($vars['assignment']->lecture->post_title => $vars['assignment']->lecture->permalink, __('Editing Assignment: ') . $vars['assignment']->post_title => $vars['assignment']->permalink);
     return $vars;
 }
 /**
  * init_course()
  * 
  * On initial group creation, assign a course to it
  * @param Int $group_id, the id of the created group
  */
 function init_course($group_id)
 {
     global $bp;
     $new_course_id = nxt_insert_post(array('post_author' => $bp->loggedin_user->id, 'post_title' => $bp->groups->current_group->name, 'post_content' => $bp->groups->current_group->description, 'post_status' => 'publish', 'post_type' => 'course'));
     if ($new_course_id) {
         nxt_set_post_terms($new_course_id, $bp->groups->current_group->id, 'group_id');
         $this->current_course = $new_course_id;
         do_action('courseware_course_added', $new_course_id);
         bp_core_add_message(__('New course was added.', 'bpsp'));
     } else {
         bp_core_add_message(__('New course could not be added.', 'bpsp'));
     }
 }
 /**
  * Edit a post.
  *
  * @since 1.5.0
  *
  * @param array $args Method parameters.
  * @return bool True on success.
  */
 function mw_editPost($args)
 {
     $this->escape($args);
     $post_ID = (int) $args[0];
     $username = $args[1];
     $password = $args[2];
     $content_struct = $args[3];
     $publish = $args[4];
     if (!($user = $this->login($username, $password))) {
         return $this->error;
     }
     do_action('xmlrpc_call', 'metaWeblog.editPost');
     $cap = $publish ? 'publish_posts' : 'edit_posts';
     $error_message = __('Sorry, you are not allowed to publish posts on this site.');
     $post_type = 'post';
     $page_template = '';
     if (!empty($content_struct['post_type'])) {
         if ($content_struct['post_type'] == 'page') {
             if ($publish || 'publish' == $content_struct['page_status']) {
                 $cap = 'publish_pages';
             } else {
                 $cap = 'edit_pages';
             }
             $error_message = __('Sorry, you are not allowed to publish pages on this site.');
             $post_type = 'page';
             if (!empty($content_struct['nxt_page_template'])) {
                 $page_template = $content_struct['nxt_page_template'];
             }
         } elseif ($content_struct['post_type'] == 'post') {
             if ($publish || 'publish' == $content_struct['post_status']) {
                 $cap = 'publish_posts';
             } else {
                 $cap = 'edit_posts';
             }
             $error_message = __('Sorry, you are not allowed to publish posts on this site.');
             $post_type = 'post';
         } else {
             // No other post_type values are allowed here
             return new IXR_Error(401, __('Invalid post type.'));
         }
     } else {
         if ($publish || 'publish' == $content_struct['post_status']) {
             $cap = 'publish_posts';
         } else {
             $cap = 'edit_posts';
         }
         $error_message = __('Sorry, you are not allowed to publish posts on this site.');
         $post_type = 'post';
     }
     if (!current_user_can($cap)) {
         return new IXR_Error(401, $error_message);
     }
     // Check for a valid post format if one was given
     if (isset($content_struct['nxt_post_format'])) {
         $content_struct['nxt_post_format'] = sanitize_key($content_struct['nxt_post_format']);
         if (!array_key_exists($content_struct['nxt_post_format'], get_post_format_strings())) {
             return new IXR_Error(404, __('Invalid post format'));
         }
     }
     $postdata = nxt_get_single_post($post_ID, ARRAY_A);
     // If there is no post data for the give post id, stop
     // now and return an error.  Other wise a new post will be
     // created (which was the old behavior).
     if (empty($postdata["ID"])) {
         return new IXR_Error(404, __('Invalid post ID.'));
     }
     $this->escape($postdata);
     extract($postdata, EXTR_SKIP);
     // Let NXTClass manage slug if none was provided.
     $post_name = "";
     $post_name = $postdata['post_name'];
     if (isset($content_struct['nxt_slug'])) {
         $post_name = $content_struct['nxt_slug'];
     }
     // Only use a password if one was given.
     if (isset($content_struct['nxt_password'])) {
         $post_password = $content_struct['nxt_password'];
     }
     // Only set a post parent if one was given.
     if (isset($content_struct['nxt_page_parent_id'])) {
         $post_parent = $content_struct['nxt_page_parent_id'];
     }
     // Only set the menu_order if it was given.
     if (isset($content_struct['nxt_page_order'])) {
         $menu_order = $content_struct['nxt_page_order'];
     }
     $post_author = $postdata['post_author'];
     // Only set the post_author if one is set.
     if (isset($content_struct['nxt_author_id']) && $user->ID != $content_struct['nxt_author_id']) {
         switch ($post_type) {
             case 'post':
                 if (!current_user_can('edit_others_posts')) {
                     return new IXR_Error(401, __('You are not allowed to change the post author as this user.'));
                 }
                 break;
             case 'page':
                 if (!current_user_can('edit_others_pages')) {
                     return new IXR_Error(401, __('You are not allowed to change the page author as this user.'));
                 }
                 break;
             default:
                 return new IXR_Error(401, __('Invalid post type.'));
                 break;
         }
         $post_author = $content_struct['nxt_author_id'];
     }
     if (isset($content_struct['mt_allow_comments'])) {
         if (!is_numeric($content_struct['mt_allow_comments'])) {
             switch ($content_struct['mt_allow_comments']) {
                 case 'closed':
                     $comment_status = 'closed';
                     break;
                 case 'open':
                     $comment_status = 'open';
                     break;
                 default:
                     $comment_status = get_option('default_comment_status');
                     break;
             }
         } else {
             switch ((int) $content_struct['mt_allow_comments']) {
                 case 0:
                 case 2:
                     $comment_status = 'closed';
                     break;
                 case 1:
                     $comment_status = 'open';
                     break;
                 default:
                     $comment_status = get_option('default_comment_status');
                     break;
             }
         }
     }
     if (isset($content_struct['mt_allow_pings'])) {
         if (!is_numeric($content_struct['mt_allow_pings'])) {
             switch ($content_struct['mt_allow_pings']) {
                 case 'closed':
                     $ping_status = 'closed';
                     break;
                 case 'open':
                     $ping_status = 'open';
                     break;
                 default:
                     $ping_status = get_option('default_ping_status');
                     break;
             }
         } else {
             switch ((int) $content_struct["mt_allow_pings"]) {
                 case 0:
                     $ping_status = 'closed';
                     break;
                 case 1:
                     $ping_status = 'open';
                     break;
                 default:
                     $ping_status = get_option('default_ping_status');
                     break;
             }
         }
     }
     $post_title = isset($content_struct['title']) ? $content_struct['title'] : null;
     $post_content = isset($content_struct['description']) ? $content_struct['description'] : null;
     $post_category = array();
     if (isset($content_struct['categories'])) {
         $catnames = $content_struct['categories'];
         if (is_array($catnames)) {
             foreach ($catnames as $cat) {
                 $post_category[] = get_cat_ID($cat);
             }
         }
     }
     $post_excerpt = isset($content_struct['mt_excerpt']) ? $content_struct['mt_excerpt'] : null;
     $post_more = isset($content_struct['mt_text_more']) ? $content_struct['mt_text_more'] : null;
     $post_status = $publish ? 'publish' : 'draft';
     if (isset($content_struct["{$post_type}_status"])) {
         switch ($content_struct["{$post_type}_status"]) {
             case 'draft':
             case 'pending':
             case 'private':
             case 'publish':
                 $post_status = $content_struct["{$post_type}_status"];
                 break;
             default:
                 $post_status = $publish ? 'publish' : 'draft';
                 break;
         }
     }
     $tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null;
     if ('publish' == $post_status) {
         if ('page' == $post_type && !current_user_can('publish_pages')) {
             return new IXR_Error(401, __('Sorry, you do not have the right to publish this page.'));
         } else {
             if (!current_user_can('publish_posts')) {
                 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.'));
             }
         }
     }
     if ($post_more) {
         $post_content = $post_content . "<!--more-->" . $post_more;
     }
     $to_ping = null;
     if (isset($content_struct['mt_tb_ping_urls'])) {
         $to_ping = $content_struct['mt_tb_ping_urls'];
         if (is_array($to_ping)) {
             $to_ping = implode(' ', $to_ping);
         }
     }
     // Do some timestamp voodoo
     if (!empty($content_struct['date_created_gmt'])) {
         $dateCreated = str_replace('Z', '', $content_struct['date_created_gmt']->getIso()) . 'Z';
     } elseif (!empty($content_struct['dateCreated'])) {
         $dateCreated = $content_struct['dateCreated']->getIso();
     }
     if (!empty($dateCreated)) {
         $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
         $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     } else {
         $post_date = $postdata['post_date'];
         $post_date_gmt = $postdata['post_date_gmt'];
     }
     // We've got all the data -- post it:
     $nenxtost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
     $result = nxt_update_post($nenxtost, true);
     if (is_nxt_error($result)) {
         return new IXR_Error(500, $result->get_error_message());
     }
     if (!$result) {
         return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.'));
     }
     // Only posts can be sticky
     if ($post_type == 'post' && isset($content_struct['sticky'])) {
         if ($content_struct['sticky'] == true) {
             stick_post($post_ID);
         } elseif ($content_struct['sticky'] == false) {
             unstick_post($post_ID);
         }
     }
     if (isset($content_struct['custom_fields'])) {
         $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
     }
     // Handle enclosures
     $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
     $this->add_enclosure_if_new($post_ID, $thisEnclosure);
     $this->attach_uploads($ID, $post_content);
     // Handle post formats if assigned, validation is handled
     // earlier in this function
     if (isset($content_struct['nxt_post_format'])) {
         nxt_set_post_terms($post_ID, array('post-format-' . $content_struct['nxt_post_format']), 'post_format');
     }
     logIO('O', "(MW) Edited ! ID: {$post_ID}");
     return true;
 }
 /**
  * new_lecture_screen( $vars )
  *
  * Hooks into screen_handler
  * Adds a UI to add new lectures.
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function new_lecture_screen($vars)
 {
     global $bp;
     $nonce_name = 'new_lecture';
     if (!$this->has_lecture_caps($bp->loggedin_user->id) && !is_super_admin()) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to add a new lecture.', 'bpsp');
         return $vars;
     }
     // Save new lecture
     $course = reset(BPSP_Courses::has_courses($bp->groups->current_group->id));
     if (isset($_POST['lecture']) && $_POST['lecture']['object'] == 'group' && isset($_POST['_nxtnonce'])) {
         $new_lecture = $_POST['lecture'];
         $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name);
         if (true != $is_nonce) {
             $vars['error'] = __('Nonce Error while adding a lecture.', 'bpsp');
         } else {
             if (isset($new_lecture['title']) && isset($new_lecture['content']) && isset($new_lecture['group_id'])) {
                 $new_lecture['title'] = strip_tags($new_lecture['title']);
                 $new_lecture_id = nxt_insert_post(array('post_author' => $bp->loggedin_user->id, 'post_title' => $new_lecture['title'], 'post_content' => $new_lecture['content'], 'post_parent' => isset($new_lecture['parent']) ? intval($new_lecture['parent']) : 0, 'menu_order' => isset($new_lecture['order']) ? intval($new_lecture['order']) : 0, 'post_status' => 'publish', 'post_type' => 'lecture'));
                 if ($new_lecture_id) {
                     nxt_set_post_terms($new_lecture_id, $new_lecture['group_id'], 'group_id');
                     nxt_set_post_terms($new_lecture_id, $course->ID, 'course_id');
                     $this->current_lecture = $this->is_lecture($new_lecture_id);
                     $vars['message'] = __('New lecture was added.', 'bpsp');
                     do_action('courseware_lecture_added', $this->current_lecture);
                     do_action('courseware_lecture_activity', $this->current_lecture, 'add');
                     return $this->single_lecture_screen($vars);
                 } else {
                     $vars['error'] = __('New lecture could not be added.', 'bpsp');
                 }
             } else {
                 $vars['error'] = __('Please fill in all the fields.', 'bpsp');
             }
         }
     }
     $vars['posted_data'] = isset($_POST['lecture']) ? $_POST['lecture'] : false;
     $vars['course'] = $course;
     $vars['lectures'] = $this->has_lectures($bp->groups->current_group->id);
     $vars['name'] = 'new_lecture';
     $vars['group_id'] = $bp->groups->current_group->id;
     $vars['user_id'] = $bp->loggedin_user->id;
     $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     $vars['trail'] = array($vars['course']->post_title => $vars['course']->permalink, __('New Lecture') => '');
     return $vars;
 }
 /**
  * edit_schedule_screen( $vars )
  *
  * Hooks into screen_handler
  * Edit schedule screen
  *
  * @param Array $vars a set of variables received for this screen template
  * @return Array $vars a set of variable passed to this screen template
  */
 function edit_schedule_screen($vars)
 {
     global $bp;
     $nonce_name = 'edit_schedule';
     $old_schedule = $this->is_schedule($this->current_schedule);
     $old_schedule->terms = nxt_get_object_terms($old_schedule->ID, 'group_id');
     if (!$this->has_schedule_caps($bp->loggedin_user->id) || !is_super_admin() && $bp->groups->current_group->id != $old_schedule->terms[0]->name) {
         $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to update the schedule.', 'bpsp');
         return $vars;
     }
     // Update schedule
     if (isset($_POST['schedule']) && $_POST['schedule']['object'] == 'group' && isset($_POST['_nxtnonce'])) {
         if (empty($_POST['schedule']['desc']) || empty($_POST['schedule']['start_date'])) {
             $vars['error'] = __('New schedule could not be added. Missing description and/or start date.', 'bpsp');
             $_POST = null;
             return $this->edit_schedule_screen($vars);
         }
         $updated_schedule = $_POST['schedule'];
         if (isset($updated_schedule['end_date']) && !empty($updated_schedule['end_date'])) {
             $valid_dates = $this->datecheck($updated_schedule['start_date'], $updated_schedule['end_date']);
         } else {
             $valid_dates = true;
         }
         $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name);
         if (true != $is_nonce) {
             $vars['error'] = __('Nonce Error while editing a schedule.', 'bpsp');
         } else {
             if (!empty($updated_schedule['group_id']) && $valid_dates) {
                 $updated_schedule_id = nxt_update_post(array('ID' => $old_schedule->ID, 'post_title' => sanitize_text_field($updated_schedule['title']), 'post_content' => sanitize_text_field($updated_schedule['desc'])));
                 if ($updated_schedule_id) {
                     if (!empty($updated_schedule['course_id']) && BPSP_Courses::is_course($updated_schedule['course_id'])) {
                         nxt_set_post_terms($updated_schedule_id, $updated_schedule['course_id'], 'course_id');
                     } elseif (empty($updated_schedule['course_id'])) {
                         nxt_set_post_terms($updated_schedule_id, '', 'course_id');
                     }
                     update_post_meta($updated_schedule_id, 'start_date', $updated_schedule['start_date'], $old_schedule->start_date);
                     update_post_meta($updated_schedule_id, 'end_date', $updated_schedule['end_date'], $old_schedule->end_date);
                     if (isset($updated_schedule['lecture_id'])) {
                         update_post_meta($updated_schedule_id, 'lecture_id', $updated_schedule['lecture_id']);
                     }
                     if (!empty($updated_schedule['location'])) {
                         if ($old_schedule->location) {
                             update_post_meta($updated_schedule_id, 'location', $updated_schedule['location'], $old_schedule->location);
                         } else {
                             add_post_meta($updated_schedule_id, 'location', $updated_schedule['location']);
                         }
                     }
                     $vars['message'] = __('Schedule was updated.', 'bpsp');
                 } else {
                     $vars['error'] = __('Schedule could not be updated.', 'bpsp');
                 }
             }
         }
     }
     $vars['name'] = 'edit_schedule';
     $vars['group_id'] = $bp->groups->current_group->id;
     $vars['course_id'] = $this->current_course->ID;
     $vars['lecture_id'] = get_post_meta($old_schedule->ID, 'lecture_id', true);
     $vars['user_id'] = $bp->loggedin_user->id;
     $vars['lectures'] = BPSP_Lectures::has_lectures($bp->groups->current_group->id);
     $vars['schedule'] = $this->is_schedule($old_schedule->ID);
     $vars['schedule_edit_uri'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule . '/edit';
     $vars['schedule_delete_uri'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule . '/delete';
     $vars['schedule_delete_title'] = __('Delete Course', 'bpsp');
     $vars['schedule_permalink'] = $vars['current_uri'] . '/schedule/' . $this->current_schedule;
     $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false);
     $vars['delete_nonce'] = add_query_arg('_nxtnonce', nxt_create_nonce('delete_schedule'), $vars['schedule_delete_uri']);
     $vars['trail'] = array($vars['schedule']->lecture->post_title => $vars['schedule']->lecture->permalink, __('Editing Schedule: ', 'bpsp') . $vars['schedule']->post_title => $vars['schedule']->permalink);
     return $vars;
 }
function woo_tumblog_publish($type, $data)
{
    global $current_user;
    //Gets the current user's info
    get_currentuserinfo();
    $content_method = get_option('woo_tumblog_content_method');
    //Set custom fields
    $tumblog_custom_fields = array('video-embed' => 'video-embed', 'quote-copy' => 'quote-copy', 'quote-author' => 'quote-author', 'quote-url' => 'quote-url', 'link-url' => 'link-url', 'image-url' => 'image', 'audio-url' => 'audio');
    //get term ids
    $tumblog_items = array('articles' => get_option('woo_articles_term_id'), 'images' => get_option('woo_images_term_id'), 'audio' => get_option('woo_audio_term_id'), 'video' => get_option('woo_video_term_id'), 'quotes' => get_option('woo_quotes_term_id'), 'links' => get_option('woo_links_term_id'));
    //Set date formatting
    $php_formatting = "Y-m-d H:i:s";
    //default post settings
    $tumbl_note = array();
    $tumbl_note['post_status'] = 'publish';
    $browser = $_SERVER['HTTP_USER_AGENT'] . "\n\n";
    $safari_check = substr_count(strtolower($browser), strtolower('safari'));
    if ($safari_check > 0) {
        $data['tumblog-content'] = str_ireplace(array('<div>', '</div>'), array('', '<br>'), $data['tumblog-content']);
        $data['tumblog-content'] = str_ireplace(array('<br><br><br>'), array('<br><br>'), $data['tumblog-content']);
        $data['tumblog-content'] = str_ireplace(array('&nbsp;'), array(' '), $data['tumblog-content']);
    }
    //Handle Tumblog Types
    switch ($type) {
        case 'note':
            //Create post object
            $tumbl_note['post_title'] = $data['note-title'];
            $tumbl_note['post_content'] = $data['tumblog-content'];
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($data['tumblog-status'] != '') {
                $tumbl_note['post_status'] = $data['tumblog-status'];
            }
            //Hours and Mins
            $original_hours = (int) $data['original-tumblog-hours'];
            $original_mins = (int) $data['original-tumblog-mins'];
            $original_date = strtotime($data['original-tumblog-date']);
            $posted_date = strtotime($data['tumblog-date']);
            $note_hours = (int) $data['tumblog-hours'];
            if ($note_hours == 0) {
                $note_hours = 12;
            } elseif ($note_hours >= 24) {
                $note_hours = 0;
            }
            $note_mins = (int) $data['tumblog-mins'];
            if ($note_mins == 0) {
                $note_mins = 0;
            } elseif ($note_mins >= 60) {
                $note_mins = 0;
            }
            //Convert to Y-m-d H:i:s
            //if everything is unchanged
            if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
                $time_now_hours = date_i18n("H");
                $time_now_mins = date_i18n("i");
                $date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
            } else {
                $date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
            }
            $date_formatted = date($php_formatting, strtotime($date_raw));
            $tumbl_note['post_date'] = $date_formatted;
            // DEPRECATED
            // }
            $tumbl_note['post_author'] = $current_user->ID;
            $tumbl_note['tags_input'] = $data['tumblog-tags'];
            // DEPRECATED
            // Get Category from Theme Options
            /*
            if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
            	$category_id = get_cat_ID( get_option( 'woo_articles_category') );
            	$categories = array($category_id);
            } else {
            	$categories = array();
            }
            */
            $categories = array();
            $post_cat_array = $data['post_category'];
            if (empty($post_cat_array)) {
                //Do nothing
            } else {
                $N = count($post_cat_array);
                for ($i = 0; $i < $N; $i++) {
                    array_push($categories, $post_cat_array[$i]);
                }
            }
            $tumbl_note['post_category'] = $categories;
            //Insert the note into the database
            $post_id = nxt_insert_post($tumbl_note);
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($content_method == 'post_format') {
                set_post_format($post_id, 'aside');
            } else {
                //update posts taxonomies
                $taxonomy_data = $data['tax_input'];
                if (!empty($taxonomy_data)) {
                    foreach ($taxonomy_data as $taxonomy => $tags) {
                        $taxonomy_obj = get_taxonomy($taxonomy);
                        if (is_array($tags)) {
                            // array = hierarchical, string = non-hierarchical.
                            $tags = array_filter($tags);
                        }
                        if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                            array_push($tags, $tumblog_items['articles']);
                        }
                    }
                } else {
                    $tags[0] = $tumblog_items['articles'];
                }
                nxt_set_post_terms($post_id, $tags, 'tumblog');
            }
            // DEPRECATED
            // }
            break;
        case 'video':
            //Create post object
            $tumbl_note['post_title'] = $data['video-title'];
            $tumbl_note['post_content'] = $data['tumblog-content'];
            // DEPRECATED
            //if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($data['tumblog-status'] != '') {
                $tumbl_note['post_status'] = $data['tumblog-status'];
            }
            //Hours and Mins
            $original_hours = (int) $data['original-tumblog-hours'];
            $original_mins = (int) $data['original-tumblog-mins'];
            $original_date = strtotime($data['original-tumblog-date']);
            $posted_date = strtotime($data['tumblog-date']);
            $note_hours = (int) $data['tumblog-hours'];
            if ($note_hours == 0) {
                $note_hours = 12;
            } elseif ($note_hours >= 24) {
                $note_hours = 0;
            }
            $note_mins = (int) $data['tumblog-mins'];
            if ($note_mins == 0) {
                $note_mins = 0;
            } elseif ($note_mins >= 60) {
                $note_mins = 0;
            }
            //Convert to Y-m-d H:i:s
            //if everything is unchanged
            if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
                $time_now_hours = date_i18n("H");
                $time_now_mins = date_i18n("i");
                $date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
            } else {
                $date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
            }
            $date_formatted = date($php_formatting, strtotime($date_raw));
            $tumbl_note['post_date'] = $date_formatted;
            // DEPRECATED
            // }
            $tumbl_note['post_author'] = $current_user->ID;
            $tumbl_note['tags_input'] = $data['tumblog-tags'];
            // DEPRECATED
            //Get Category from Theme Options
            /*
            if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
            	$category_id = get_cat_ID( get_option( 'woo_videos_category') );
            	$categories = array($category_id);
            } else {
            	$categories = array();
            }
            */
            $categories = array();
            $post_cat_array = $data['post_category'];
            if (empty($post_cat_array)) {
                //Do nothing
            } else {
                $N = count($post_cat_array);
                for ($i = 0; $i < $N; $i++) {
                    array_push($categories, $post_cat_array[$i]);
                }
            }
            $tumbl_note['post_category'] = $categories;
            //Insert the note into the database
            $post_id = nxt_insert_post($tumbl_note);
            //Add Custom Field Data to the Post
            add_post_meta($post_id, $tumblog_custom_fields['video-embed'], $data['video-embed'], true);
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($content_method == 'post_format') {
                set_post_format($post_id, 'video');
            } else {
                //update posts taxonomies
                $taxonomy_data = $data['tax_input'];
                if (!empty($taxonomy_data)) {
                    foreach ($taxonomy_data as $taxonomy => $tags) {
                        $taxonomy_obj = get_taxonomy($taxonomy);
                        if (is_array($tags)) {
                            // array = hierarchical, string = non-hierarchical.
                            $tags = array_filter($tags);
                        }
                        if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                            array_push($tags, $tumblog_items['video']);
                        }
                    }
                } else {
                    $tags[0] = $tumblog_items['video'];
                }
                nxt_set_post_terms($post_id, $tags, 'tumblog');
            }
            // DEPRECATED
            // }
            break;
        case 'image':
            //Create post object
            $tumbl_note['post_title'] = $data['image-title'];
            $tumbl_note['post_content'] = $data['tumblog-content'];
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($data['tumblog-status'] != '') {
                $tumbl_note['post_status'] = $data['tumblog-status'];
            }
            //Hours and Mins
            $original_hours = (int) $data['original-tumblog-hours'];
            $original_mins = (int) $data['original-tumblog-mins'];
            $original_date = strtotime($data['original-tumblog-date']);
            $posted_date = strtotime($data['tumblog-date']);
            $note_hours = (int) $data['tumblog-hours'];
            if ($note_hours == 0) {
                $note_hours = 12;
            } elseif ($note_hours >= 24) {
                $note_hours = 0;
            }
            $note_mins = (int) $data['tumblog-mins'];
            if ($note_mins == 0) {
                $note_mins = 0;
            } elseif ($note_mins >= 60) {
                $note_mins = 0;
            }
            //Convert to Y-m-d H:i:s
            //if everything is unchanged
            if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
                $time_now_hours = date_i18n("H");
                $time_now_mins = date_i18n("i");
                $date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
            } else {
                $date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
            }
            $date_formatted = date($php_formatting, strtotime($date_raw));
            $tumbl_note['post_date'] = $date_formatted;
            // DEPRECATED
            // }
            $tumbl_note['post_author'] = $current_user->ID;
            $tumbl_note['tags_input'] = $data['tumblog-tags'];
            // DEPRECATED
            //Get Category from Theme Options
            /*
            if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
            	$category_id = get_cat_ID( get_option( 'woo_images_category') );
            	$categories = array($category_id);
            } else {
            	$categories = array();
            }
            */
            $categories = array();
            $post_cat_array = $data['post_category'];
            if (empty($post_cat_array)) {
                //Do nothing
            } else {
                $N = count($post_cat_array);
                for ($i = 0; $i < $N; $i++) {
                    array_push($categories, $post_cat_array[$i]);
                }
            }
            $tumbl_note['post_category'] = $categories;
            //Insert the note into the database
            $post_id = nxt_insert_post($tumbl_note);
            //Add Custom Field Data to the Post
            if ($data['image-id'] > 0) {
                $my_post = array();
                $my_post['ID'] = $data['image-id'];
                $my_post['post_parent'] = $post_id;
                //Update the post into the database
                nxt_update_post($my_post);
                add_post_meta($post_id, $tumblog_custom_fields['image-url'], $data['image-upload'], true);
            } else {
                add_post_meta($post_id, $tumblog_custom_fields['image-url'], $data['image-url'], true);
            }
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($content_method == 'post_format') {
                set_post_format($post_id, 'image');
            } else {
                //update posts taxonomies
                $taxonomy_data = $data['tax_input'];
                if (!empty($taxonomy_data)) {
                    foreach ($taxonomy_data as $taxonomy => $tags) {
                        $taxonomy_obj = get_taxonomy($taxonomy);
                        if (is_array($tags)) {
                            // array = hierarchical, string = non-hierarchical.
                            $tags = array_filter($tags);
                        }
                        if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                            array_push($tags, $tumblog_items['images']);
                        }
                    }
                } else {
                    $tags[0] = $tumblog_items['images'];
                }
                nxt_set_post_terms($post_id, $tags, 'tumblog');
            }
            // DEPRECATED
            // }
            break;
        case 'link':
            //Create post object
            $tumbl_note['post_title'] = $data['link-title'];
            $tumbl_note['post_content'] = $data['tumblog-content'];
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($data['tumblog-status'] != '') {
                $tumbl_note['post_status'] = $data['tumblog-status'];
            }
            //Hours and Mins
            $original_hours = (int) $data['original-tumblog-hours'];
            $original_mins = (int) $data['original-tumblog-mins'];
            $original_date = strtotime($data['original-tumblog-date']);
            $posted_date = strtotime($data['tumblog-date']);
            $note_hours = (int) $data['tumblog-hours'];
            if ($note_hours == 0) {
                $note_hours = 12;
            } elseif ($note_hours >= 24) {
                $note_hours = 0;
            }
            $note_mins = (int) $data['tumblog-mins'];
            if ($note_mins == 0) {
                $note_mins = 0;
            } elseif ($note_mins >= 60) {
                $note_mins = 0;
            }
            //Convert to Y-m-d H:i:s
            //if everything is unchanged
            if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
                $time_now_hours = date_i18n("H");
                $time_now_mins = date_i18n("i");
                $date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
            } else {
                $date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
            }
            $date_formatted = date($php_formatting, strtotime($date_raw));
            $tumbl_note['post_date'] = $date_formatted;
            // DEPRECATED
            // }
            $tumbl_note['post_author'] = $current_user->ID;
            $tumbl_note['tags_input'] = $data['tumblog-tags'];
            // DEPRECATED
            //Get Category from Theme Options
            /*
            if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
            	$category_id = get_cat_ID( get_option( 'woo_links_category') );
            	$categories = array($category_id);
            } else {
            	$categories = array();
            }
            */
            $categories = array();
            $post_cat_array = $data['post_category'];
            if (empty($post_cat_array)) {
                //Do nothing
            } else {
                $N = count($post_cat_array);
                for ($i = 0; $i < $N; $i++) {
                    array_push($categories, $post_cat_array[$i]);
                }
            }
            $tumbl_note['post_category'] = $categories;
            //Insert the note into the database
            $post_id = nxt_insert_post($tumbl_note);
            //Add Custom Field Data to the Post
            add_post_meta($post_id, $tumblog_custom_fields['link-url'], $data['link-url'], true);
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($content_method == 'post_format') {
                set_post_format($post_id, 'link');
            } else {
                //update posts taxonomies
                $taxonomy_data = $data['tax_input'];
                if (!empty($taxonomy_data)) {
                    foreach ($taxonomy_data as $taxonomy => $tags) {
                        $taxonomy_obj = get_taxonomy($taxonomy);
                        if (is_array($tags)) {
                            // array = hierarchical, string = non-hierarchical.
                            $tags = array_filter($tags);
                        }
                        if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                            array_push($tags, $tumblog_items['links']);
                        }
                    }
                } else {
                    $tags[0] = $tumblog_items['links'];
                }
                nxt_set_post_terms($post_id, $tags, 'tumblog');
            }
            // DEPRECATED
            // }
            break;
        case 'quote':
            //Create post object
            $tumbl_note['post_title'] = $data['quote-title'];
            $tumbl_note['post_content'] = $data['tumblog-content'];
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($data['tumblog-status'] != '') {
                $tumbl_note['post_status'] = $data['tumblog-status'];
            }
            //Hours and Mins
            $original_hours = (int) $data['original-tumblog-hours'];
            $original_mins = (int) $data['original-tumblog-mins'];
            $original_date = strtotime($data['original-tumblog-date']);
            $posted_date = strtotime($data['tumblog-date']);
            $note_hours = (int) $data['tumblog-hours'];
            if ($note_hours == 0) {
                $note_hours = 12;
            } elseif ($note_hours >= 24) {
                $note_hours = 0;
            }
            $note_mins = (int) $data['tumblog-mins'];
            if ($note_mins == 0) {
                $note_mins = 0;
            } elseif ($note_mins >= 60) {
                $note_mins = 0;
            }
            //Convert to Y-m-d H:i:s
            //if everything is unchanged
            if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
                $time_now_hours = date_i18n("H");
                $time_now_mins = date_i18n("i");
                $date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
            } else {
                $date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
            }
            $date_formatted = date($php_formatting, strtotime($date_raw));
            $tumbl_note['post_date'] = $date_formatted;
            // DEPRECATED
            // }
            $tumbl_note['post_author'] = $current_user->ID;
            $tumbl_note['tags_input'] = $data['tumblog-tags'];
            // DEPRECATED
            //Get Category from Theme Options
            /*
            if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
            	$category_id = get_cat_ID( get_option( 'woo_quotes_category') );
            	$categories = array($category_id);
            } else {
            	$categories = array();
            }
            */
            $categories = array();
            $post_cat_array = $data['post_category'];
            if (empty($post_cat_array)) {
                //Do nothing
            } else {
                $N = count($post_cat_array);
                for ($i = 0; $i < $N; $i++) {
                    array_push($categories, $post_cat_array[$i]);
                }
            }
            $tumbl_note['post_category'] = $categories;
            //Insert the note into the database
            $post_id = nxt_insert_post($tumbl_note);
            //Add Custom Field Data to the Post
            add_post_meta($post_id, $tumblog_custom_fields['quote-copy'], $data['quote-copy'], true);
            add_post_meta($post_id, $tumblog_custom_fields['quote-author'], $data['quote-author'], true);
            add_post_meta($post_id, $tumblog_custom_fields['quote-url'], $data['quote-url'], true);
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($content_method == 'post_format') {
                set_post_format($post_id, 'quote');
            } else {
                //update posts taxonomies
                $taxonomy_data = $data['tax_input'];
                if (!empty($taxonomy_data)) {
                    foreach ($taxonomy_data as $taxonomy => $tags) {
                        $taxonomy_obj = get_taxonomy($taxonomy);
                        if (is_array($tags)) {
                            // array = hierarchical, string = non-hierarchical.
                            $tags = array_filter($tags);
                        }
                        if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                            array_push($tags, $tumblog_items['quotes']);
                        }
                    }
                } else {
                    $tags[0] = $tumblog_items['quotes'];
                }
                nxt_set_post_terms($post_id, $tags, 'tumblog');
            }
            // DEPRECATED
            // }
            break;
        case 'audio':
            //Create post object
            $tumbl_note['post_title'] = $data['audio-title'];
            $tumbl_note['post_content'] = $data['tumblog-content'];
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($data['tumblog-status'] != '') {
                $tumbl_note['post_status'] = $data['tumblog-status'];
            }
            //Hours and Mins
            $original_hours = (int) $data['original-tumblog-hours'];
            $original_mins = (int) $data['original-tumblog-mins'];
            $original_date = strtotime($data['original-tumblog-date']);
            $posted_date = strtotime($data['tumblog-date']);
            $note_hours = (int) $data['tumblog-hours'];
            if ($note_hours == 0) {
                $note_hours = 12;
            } elseif ($note_hours >= 24) {
                $note_hours = 0;
            }
            $note_mins = (int) $data['tumblog-mins'];
            if ($note_mins == 0) {
                $note_mins = 0;
            } elseif ($note_mins >= 60) {
                $note_mins = 0;
            }
            //Convert to Y-m-d H:i:s
            //if everything is unchanged
            if ($note_hours == $original_hours && $note_mins == $original_mins && $posted_date == $original_date) {
                $time_now_hours = date_i18n("H");
                $time_now_mins = date_i18n("i");
                $date_raw = date("Y") . '-' . date("m") . '-' . date("d") . ' ' . $time_now_hours . ':' . $time_now_mins . ':00';
            } else {
                $date_raw = date("Y", strtotime($data['tumblog-date'])) . '-' . date("m", strtotime($data['tumblog-date'])) . '-' . date("d", strtotime($data['tumblog-date'])) . ' ' . $note_hours . ':' . $note_mins . ':00';
            }
            $date_formatted = date($php_formatting, strtotime($date_raw));
            $tumbl_note['post_date'] = $date_formatted;
            // DEPRECATED
            // }
            $tumbl_note['post_author'] = $current_user->ID;
            $tumbl_note['tags_input'] = $data['tumblog-tags'];
            // DEPRECATED
            //Get Category from Theme Options
            /*
            if (get_option( 'tumblog_woo_tumblog_upgraded') != 'true') {
            	$category_id = get_cat_ID( get_option( 'woo_audio_category') );
            	$categories = array($category_id);
            } else {
            	$categories = array();
            }
            */
            $categories = array();
            $post_cat_array = $data['post_category'];
            if (empty($post_cat_array)) {
                //Do nothing
            } else {
                $N = count($post_cat_array);
                for ($i = 0; $i < $N; $i++) {
                    array_push($categories, $post_cat_array[$i]);
                }
            }
            $tumbl_note['post_category'] = $categories;
            //Insert the note into the database
            $post_id = nxt_insert_post($tumbl_note);
            //Add Custom Field Data to the Post
            if ($data['audio-id'] > 0) {
                $my_post = array();
                $my_post['ID'] = $data['audio-id'];
                $my_post['post_parent'] = $post_id;
                //Update the post into the database
                nxt_update_post($my_post);
                add_post_meta($post_id, $tumblog_custom_fields['audio-url'], $data['audio-upload'], true);
            } else {
                add_post_meta($post_id, $tumblog_custom_fields['audio-url'], $data['audio-url'], true);
            }
            // DEPRECATED
            // if (get_option( 'tumblog_woo_tumblog_upgraded') == 'true') {
            if ($content_method == 'post_format') {
                set_post_format($post_id, 'audio');
            } else {
                //update posts taxonomies
                $taxonomy_data = $data['tax_input'];
                if (!empty($taxonomy_data)) {
                    foreach ($taxonomy_data as $taxonomy => $tags) {
                        $taxonomy_obj = get_taxonomy($taxonomy);
                        if (is_array($tags)) {
                            // array = hierarchical, string = non-hierarchical.
                            $tags = array_filter($tags);
                        }
                        if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                            array_push($tags, $tumblog_items['audio']);
                        }
                    }
                } else {
                    $tags[0] = $tumblog_items['audio'];
                }
                nxt_set_post_terms($post_id, $tags, 'tumblog');
            }
            // DEPRECATED
            // }
            break;
        default:
            break;
    }
}
 /**
  * Create new posts based on import information
  *
  * Posts marked as having a parent which doesn't exist will become top level items.
  * Doesn't create a new post if: the post type doesn't exist, the given post ID
  * is already noted as imported or a post with the same title and date already exists.
  * Note that new/updated terms, comments and meta are imported for the last of the above.
  */
 function process_posts()
 {
     foreach ($this->posts as $post) {
         if (!post_type_exists($post['post_type'])) {
             printf(__('Failed to import &#8220;%s&#8221;: Invalid post type %s', 'nxtclass-importer'), esc_html($post['post_title']), esc_html($post['post_type']));
             echo '<br />';
             continue;
         }
         if (isset($this->processed_posts[$post['post_id']]) && !empty($post['post_id'])) {
             continue;
         }
         if ($post['status'] == 'auto-draft') {
             continue;
         }
         if ('nav_menu_item' == $post['post_type']) {
             $this->process_menu_item($post);
             continue;
         }
         $post_type_object = get_post_type_object($post['post_type']);
         $post_exists = post_exists($post['post_title'], '', $post['post_date']);
         if ($post_exists) {
             printf(__('%s &#8220;%s&#8221; already exists.', 'nxtclass-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
             echo '<br />';
             $comment_post_ID = $post_id = $post_exists;
         } else {
             $post_parent = (int) $post['post_parent'];
             if ($post_parent) {
                 // if we already know the parent, map it to the new local ID
                 if (isset($this->processed_posts[$post_parent])) {
                     $post_parent = $this->processed_posts[$post_parent];
                     // otherwise record the parent for later
                 } else {
                     $this->post_orphans[intval($post['post_id'])] = $post_parent;
                     $post_parent = 0;
                 }
             }
             // map the post author
             $author = sanitize_user($post['post_author'], true);
             if (isset($this->author_mapping[$author])) {
                 $author = $this->author_mapping[$author];
             } else {
                 $author = (int) get_current_user_id();
             }
             $postdata = array('import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'], 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'], 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'], 'post_status' => $post['status'], 'post_name' => $post['post_name'], 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'], 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'], 'post_type' => $post['post_type'], 'post_password' => $post['post_password']);
             if ('attachment' == $postdata['post_type']) {
                 $remote_url = !empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
                 // try to use _nxt_attached file for upload folder placement to ensure the same location as the export site
                 // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
                 $postdata['upload_date'] = $post['post_date'];
                 if (isset($post['postmeta'])) {
                     foreach ($post['postmeta'] as $meta) {
                         if ($meta['key'] == '_nxt_attached_file') {
                             if (preg_match('%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches)) {
                                 $postdata['upload_date'] = $matches[0];
                             }
                             break;
                         }
                     }
                 }
                 $comment_post_ID = $post_id = $this->process_attachment($postdata, $remote_url);
             } else {
                 $comment_post_ID = $post_id = nxt_insert_post($postdata, true);
             }
             if (is_nxt_error($post_id)) {
                 printf(__('Failed to import %s &#8220;%s&#8221;', 'nxtclass-importer'), $post_type_object->labels->singular_name, esc_html($post['post_title']));
                 if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                     echo ': ' . $post_id->get_error_message();
                 }
                 echo '<br />';
                 continue;
             }
             if ($post['is_sticky'] == 1) {
                 stick_post($post_id);
             }
         }
         // map pre-import ID to local ID
         $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
         // add categories, tags and other terms
         if (!empty($post['terms'])) {
             $terms_to_set = array();
             foreach ($post['terms'] as $term) {
                 // back compat with WXR 1.0 map 'tag' to 'post_tag'
                 $taxonomy = 'tag' == $term['domain'] ? 'post_tag' : $term['domain'];
                 $term_exists = term_exists($term['slug'], $taxonomy);
                 $term_id = is_array($term_exists) ? $term_exists['term_id'] : $term_exists;
                 if (!$term_id) {
                     $t = nxt_insert_term($term['name'], $taxonomy, array('slug' => $term['slug']));
                     if (!is_nxt_error($t)) {
                         $term_id = $t['term_id'];
                     } else {
                         printf(__('Failed to import %s %s', 'nxtclass-importer'), esc_html($taxonomy), esc_html($term['name']));
                         if (defined('IMPORT_DEBUG') && IMPORT_DEBUG) {
                             echo ': ' . $t->get_error_message();
                         }
                         echo '<br />';
                         continue;
                     }
                 }
                 $terms_to_set[$taxonomy][] = intval($term_id);
             }
             foreach ($terms_to_set as $tax => $ids) {
                 $tt_ids = nxt_set_post_terms($post_id, $ids, $tax);
             }
             unset($post['terms'], $terms_to_set);
         }
         // add/update comments
         if (!empty($post['comments'])) {
             $num_comments = 0;
             $inserted_comments = array();
             foreach ($post['comments'] as $comment) {
                 $comment_id = $comment['comment_id'];
                 $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
                 $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
                 $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
                 $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
                 $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
                 $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
                 $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
                 $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
                 $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
                 $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
                 $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
                 $newcomments[$comment_id]['commentmeta'] = isset($comment['commentmeta']) ? $comment['commentmeta'] : array();
                 if (isset($this->processed_authors[$comment['comment_user_id']])) {
                     $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
                 }
             }
             ksort($newcomments);
             foreach ($newcomments as $key => $comment) {
                 // if this is a new post we can skip the comment_exists() check
                 if (!$post_exists || !comment_exists($comment['comment_author'], $comment['comment_date'])) {
                     if (isset($inserted_comments[$comment['comment_parent']])) {
                         $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
                     }
                     $comment = nxt_filter_comment($comment);
                     $inserted_comments[$key] = nxt_insert_comment($comment);
                     foreach ($comment['commentmeta'] as $meta) {
                         $value = maybe_unserialize($meta['value']);
                         add_comment_meta($inserted_comments[$key], $meta['key'], $value);
                     }
                     $num_comments++;
                 }
             }
             unset($newcomments, $inserted_comments, $post['comments']);
         }
         // add/update post meta
         if (isset($post['postmeta'])) {
             foreach ($post['postmeta'] as $meta) {
                 $key = apply_filters('import_post_meta_key', $meta['key']);
                 $value = false;
                 if ('_edit_last' == $key) {
                     if (isset($this->processed_authors[intval($meta['value'])])) {
                         $value = $this->processed_authors[intval($meta['value'])];
                     } else {
                         $key = false;
                     }
                 }
                 if ($key) {
                     // export gets meta straight from the DB so could have a serialized string
                     if (!$value) {
                         $value = maybe_unserialize($meta['value']);
                     }
                     add_post_meta($post_id, $key, $value);
                     do_action('import_post_meta', $post_id, $key, $value);
                     // if the post has a featured image, take note of this in case of remap
                     if ('_thumbnail_id' == $key) {
                         $this->featured_images[$post_id] = (int) $value;
                     }
                 }
             }
         }
     }
     unset($this->posts);
 }