function upgrade() { //Alternate form in case we're upgrading. global $nxt_version; $nxtw_options = get_option('nxtw_options'); $test = get_posts('post_type=wiki'); if ($nxt_version >= 3.0 && empty($test)) { $old_wikis = get_pages('meta_key=_wiki_page&meta_value=1'); foreach ($old_wikis as $wiki) { $wiki->post_type = 'wiki'; $wiki->ID = null; if (nxt_insert_post($wiki) != false) { echo "<p>" . __('Wiki page') . " " . $wiki->post_title . " " . __('successfully upgraded to Wiki post type.') . "</p><br />"; nxt_delete_post($wiki->ID); } } } $this->upgrade_wiki_editor(); if (!isset($nxtw_options['number_of_revisions']) && get_option('numberOfRevisions') != false) { echo '<input type="hidden" name="nxtw_options[number_of_revisions]" value="' . get_option('numberOfRevisions') . '" />'; } elseif (empty($nxtw_options['number_of_revisions'])) { echo '<input type="hidden" name="nxtw_options[number_of_revisions]" value="5" />'; } delete_option('numberOfRevisions'); if (!isset($nxtw_options['email_admins']) && get_option('wiki_email_admins') != false) { echo '<input type="hidden" name="nxtw_options[email_admins]" value="' . get_option('wiki_email_admins') . '" />'; } elseif (empty($nxtw_options['email_admins'])) { echo '<input type="hidden" name="nxtw_options[email_admins]" value="0" />'; } delete_option('wiki_email_admins'); if (!isset($nxtw_options['show_toc_onfrontpage']) && get_option('wiki_show_toc_onfrontpage') != false) { echo '<input type="hidden" name="nxtw_options[show_toc_onfrontpage]" value="' . get_option('wiki_show_toc_onfrontpage') . '" />'; } elseif (empty($nxtw_options['show_toc_onfrontpage'])) { echo '<input type="hidden" name="nxtw_options[show_toc_onfrontpage]" value="0" />'; } delete_option('wiki_show_toc_onfrontpage'); if (!isset($nxtw_options['cron_email']) && get_option('wiki_cron_email') != false) { echo '<input type="hidden" name="nxtw_options[cron_email]" value="' . get_option('wiki_cron_email') . '" />'; } elseif (empty($nxtw_options['cron_email'])) { echo '<input type="hidden" name="nxtw_options[cron_email]" value="0" />'; } delete_option('wiki_cron_email'); echo '<input type="hidden" name="nxtw_options[nxtw_upgrade]" value="done_gone_and_upgraded" />'; echo ' <tr> <td><input class="button-primary" type="submit" value="' . __('Finish Upgrade') . '" /></td> </tr> '; }
/** * register_post_types() * * Static function to register the bibliography post types and capabilities. */ function register_post_types() { $bib_post_def = array('label' => __('Bibliography', 'bpsp'), 'singular_label' => __('Bibliography', 'bpsp'), 'description' => __('BuddyPress ScholarPress Courseware Bibliography', 'bpsp'), 'public' => BPSP_DEBUG, 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_ui' => BPSP_DEBUG, 'capability_type' => 'bib', 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array('title', 'custom-fields')); if (!register_post_type('bib', $bib_post_def)) { nxt_die(__('BuddyPress Courseware error while registering bibliography post type.', 'bpsp')); } /** * Dummy post definition for storing the bibs entries as custom-fields */ $bibdb_def = array('post_title' => 'BIBSDB', 'post_status' => 'draft', 'post_type' => 'bib'); if (!get_posts($bibdb_def)) { $bibs_id = nxt_insert_post($bibdb_def); if (!$bibs_id) { nxt_die('BuddyPress Courseware error while creating bibliography database.', 'bpsp'); } } }
/** * 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')); } }
if (function_exists('iconv') && !empty($charset)) { $content = iconv($charset, get_option('blog_charset'), $content); } // Captures any text in the body after $phone_delim as the body $content = explode($phone_delim, $content); $content = empty($content[1]) ? $content[0] : $content[1]; $content = trim($content); $post_content = apply_filters('phone_content', $content); $post_title = xmlrpc_getposttitle($content); if ($post_title == '') { $post_title = $subject; } $post_category = array(get_option('default_email_category')); $post_data = compact('post_content', 'post_title', 'post_date', 'post_date_gmt', 'post_author', 'post_category', 'post_status'); $post_data = add_magic_quotes($post_data); $post_ID = nxt_insert_post($post_data); if (is_nxt_error($post_ID)) { echo "\n" . $post_ID->get_error_message(); } // We couldn't post, for whatever reason. Better move forward to the next email. if (empty($post_ID)) { continue; } do_action('publish_phone', $post_ID); echo "\n<p>" . sprintf(__('<strong>Author:</strong> %s'), esc_html($post_author)) . '</p>'; echo "\n<p>" . sprintf(__('<strong>Posted title:</strong> %s'), esc_html($post_title)) . '</p>'; if (!$pop3->delete($i)) { echo '<p>' . sprintf(__('Oops: %s'), esc_html($pop3->ERROR)) . '</p>'; $pop3->reset(); exit; } else {
/** * Create a new post. * * The 'content_struct' argument must contain: * - title * - description * - mt_excerpt * - mt_text_more * - mt_keywords * - mt_tb_ping_urls * - categories * * Also, it can optionally contain: * - nxt_slug * - nxt_password * - nxt_page_parent_id * - nxt_page_order * - nxt_author_id * - post_status | page_status - can be 'draft', 'private', 'publish', or 'pending' * - mt_allow_comments - can be 'open' or 'closed' * - mt_allow_pings - can be 'open' or 'closed' * - date_created_gmt * - dateCreated * * @since 1.5.0 * * @param array $args Method parameters. Contains: * - blog_id * - username * - password * - content_struct * - publish * @return int */ function mw_nenxtost($args) { $this->escape($args); $blog_ID = (int) $args[0]; // we will support this in the near future $username = $args[1]; $password = $args[2]; $content_struct = $args[3]; $publish = isset($args[4]) ? $args[4] : 0; if (!($user = $this->login($username, $password))) { return $this->error; } do_action('xmlrpc_call', 'metaWeblog.nenxtost'); $page_template = ''; if (!empty($content_struct['post_type'])) { if ($content_struct['post_type'] == 'page') { if ($publish) { $cap = 'publish_pages'; } elseif ('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) { $cap = 'publish_posts'; } elseif ('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) { $cap = 'publish_posts'; } elseif ('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')); } } // Let NXTClass generate the post_name (slug) unless // one has been provided. $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 provided. if (isset($content_struct['nxt_page_parent_id'])) { $post_parent = $content_struct['nxt_page_parent_id']; } // Only set the menu_order if it was provided. if (isset($content_struct['nxt_page_order'])) { $menu_order = $content_struct['nxt_page_order']; } $post_author = $user->ID; // If an author id was provided then use it instead. 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 post as this user')); } break; case "page": if (!current_user_can('edit_others_pages')) { return new IXR_Error(401, __('You are not allowed to create pages as this user')); } break; default: return new IXR_Error(401, __('Invalid post type.')); break; } $post_author = $content_struct['nxt_author_id']; } $post_title = isset($content_struct['title']) ? $content_struct['title'] : null; $post_content = isset($content_struct['description']) ? $content_struct['description'] : 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; } } $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; $tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null; 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; } } } else { $comment_status = get_option('default_comment_status'); } 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; } } } else { $ping_status = get_option('default_ping_status'); } 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 = current_time('mysql'); $post_date_gmt = current_time('mysql', 1); } $post_category = array(); if (isset($content_struct['categories'])) { $catnames = $content_struct['categories']; logIO('O', 'Post cats: ' . var_export($catnames, true)); if (is_array($catnames)) { foreach ($catnames as $cat) { $post_category[] = get_cat_ID($cat); } } } $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template'); $post_ID = $postdata['ID'] = get_default_post_to_edit($post_type, true)->ID; // 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($post_ID, $post_content); // Handle post formats if assigned, value is validated 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'); } $post_ID = nxt_insert_post($postdata, true); if (is_nxt_error($post_ID)) { return new IXR_Error(500, $post_ID->get_error_message()); } if (!$post_ID) { return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); } logIO('O', "Posted ! ID: {$post_ID}"); return strval($post_ID); }
/** * new_response_screen( $vars ) * * Hooks into screen_handler * Adds a UI to add new responses. * * @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_response_screen($vars) { global $bp; $nonce_name = 'add_response'; $form_results = null; if (!$this->has_student_caps($bp->loggedin_user->id) && !is_super_admin() || !bp_group_is_member($bp->groups->current_group)) { $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to add a new response.', 'bpsp'); return $vars; } // Save new response if (isset($_POST['response']) && $this->current_assignment->ID == $_POST['response']['parent_id'] && isset($_POST['_nxtnonce'])) { $new_response = $_POST['response']; $new_response_quiz = !empty($_POST['frmb']) ? $_POST['frmb'] : null; $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name); $response = $this->has_response(); if (true != $is_nonce) { $vars['error'] = __('Nonce Error while adding a response.', 'bpsp'); } if (!empty($response)) { $vars['response'] = $response; $vars['error'] = __('You already sent your response.', 'bpsp'); $this->single_response_screen($vars); } else { if ($new_response_quiz) { $new_response['title'] = bp_core_get_username($bp->loggedin_user->id) . __(' on ', 'bpsp') . $this->current_assignment->post_title; $new_response['content'] = __('Your quiz results: ', 'bpsp'); $form_results = $this->check_quiz($new_response_quiz, $this->current_assignment->form_data); $new_response['content'] .= (isset($form_results['correct']) ? $form_results['correct'] : 0) . '/' . $form_results['total']; } if (isset($new_response['title']) && isset($new_response['content'])) { $new_response['title'] = strip_tags($new_response['title']); $new_response_id = nxt_insert_post(array('post_author' => $bp->loggedin_user->id, 'post_title' => $new_response['title'], 'post_content' => $new_response['content'], 'post_status' => 'publish', 'post_type' => 'response', 'post_parent' => $this->current_assignment->ID)); if ($new_response_id) { // Save author id in assignment post_meta so we don't have to query it all over add_post_meta($this->current_assignment->ID, 'responded_author', $bp->loggedin_user->id); add_post_meta($new_response_id, 'form_values', $form_results); $vars = $this->single_response_screen($vars); // Leave this for imediate results preview $vars['response']->form_values = $form_results; if ($this->group_responses_status()) { $vars['public'] = true; } do_action('courseware_response_added', $vars); $vars['message'] = __('New response was added.', 'bpsp'); return $vars; } else { $vars['error'] = __('New response could not be added (fill the title/content).', 'bpsp'); } } } } $vars['name'] = 'add_response'; $vars['parent_assignment'] = $this->current_assignment; $vars['user_id'] = $bp->loggedin_user->id; $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false); $vars['trail'] = array($this->current_assignment->lecture->post_title => $this->current_assignment->lecture->permalink, $this->current_assignment->post_title => $this->current_assignment->permalink, __('New Response', 'bpsp') => ''); return $vars; }
function woothemes_mlu_get_silentpost($_token) { global $nxtdb; $_id = 0; // Check if the token is valid against a whitelist. // $_whitelist = array( 'woo_logo', 'woo_custom_favicon', 'woo_body_img', 'woo_ad_top_image' ); // Sanitise the token. $_token = strtolower(str_replace(' ', '_', $_token)); // if ( in_array( $_token, $_whitelist ) ) { if ($_token) { // Tell the function what to look for in a post. $_args = array('post_parent' => '0', 'post_type' => 'wooframework', 'post_name' => 'woo-wf-' . $_token, 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed'); // Look in the database for a "silent" post that meets our criteria. $_posts = get_post($_args); // If we've got a post, loop through and get it's ID. if (count($_posts)) { $_id = $_posts->ID; } else { // If no post is present, insert one. // Prepare some additional data to go with the post insertion. $_words = explode('_', $_token); $_title = join(' ', $_words); $_title = ucwords($_title); $_post_data = array('post_title' => $_title); $_post_data = array_merge($_post_data, $_args); $_id = nxt_insert_post($_post_data); } // End IF Statement } return $_id; }
/** * 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; }
/** * new_assignment_screen( $vars ) * * Hooks into screen_handler * Adds a UI to add new assignments. * * @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_assignment_screen($vars) { global $bp; $nonce_name = 'new_assignment'; if (!$this->has_assignment_caps($bp->loggedin_user->id) && !is_super_admin()) { $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to add a new assignment.', 'bpsp'); return $vars; } // Save new assignment if (isset($_POST['assignment']) && $_POST['assignment']['object'] == 'group' && BPSP_Lectures::is_lecture($_POST['assignment']['lecture_id']) && isset($_POST['_nxtnonce'])) { $new_assignment = $_POST['assignment']; $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name); if (true != $is_nonce) { $vars['error'] = __('Nonce Error while adding an assignment.', 'bpsp'); } else { if (isset($new_assignment['title']) && isset($new_assignment['content']) && isset($new_assignment['group_id']) && is_numeric($new_assignment['course_id'])) { $new_assignment['title'] = strip_tags($new_assignment['title']); $new_assignment_id = nxt_insert_post(array('post_author' => $bp->loggedin_user->id, 'post_title' => $new_assignment['title'], 'post_content' => $new_assignment['content'], 'post_status' => 'publish', 'post_type' => 'assignment')); if ($new_assignment_id) { nxt_set_post_terms($new_assignment_id, $new_assignment['group_id'], 'group_id'); nxt_set_post_terms($new_assignment_id, $new_assignment['course_id'], 'course_id'); if (isset($new_assignment['lecture_id'])) { add_post_meta($new_assignment_id, 'lecture_id', $new_assignment['lecture_id']); } if (strtotime($new_assignment['due_date'])) { add_post_meta($new_assignment_id, 'due_date', $new_assignment['due_date']); } // Save the formbuilder if ($new_assignment['form']) { $this->frmb->load_serialized($new_assignment['form']); if ($this->frmb->get_data()) { add_post_meta($new_assignment_id, 'form_data', $this->frmb->get_data()); } } $vars['message'] = __('New assignment was added.', 'bpsp'); do_action('courseware_assignment_added', $this->is_assignment($new_assignment_id)); do_action('courseware_assignment_activity', $this->is_assignment($new_assignment_id), 'add'); return $this->list_assignments_screen($vars); } else { $vars['error'] = __('New assignment could not be added.', 'bpsp'); } } else { $vars['error'] = __('Please fill in all the fields.', 'bpsp'); } } } $vars['posted_data'] = $_POST['assignment']; $vars['lectures'] = BPSP_Lectures::has_lectures($bp->groups->current_group->id); $vars['name'] = 'new_assignment'; $vars['group_id'] = $bp->groups->current_group->id; $vars['course_id'] = $this->current_course->ID; $vars['user_id'] = $bp->loggedin_user->id; $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false); $vars['trail'] = array(__('New Assignment') => ''); if (count($vars['lectures']) == 0 && empty($vars['error'])) { $vars['error'] = __('No lectures were created. ', 'bpsp') . __('It is recommended to create lectures first and link assignments to those.', 'bpsp'); } return $vars; }
function optionsframework_mlu_get_silentpost($_token) { global $nxtdb; $_id = 0; // Check if the token is valid against a whitelist. // $_whitelist = array( 'of_logo', 'of_custom_favicon', 'of_ad_top_image' ); // Sanitise the token. $_token = strtolower(str_replace(' ', '_', $_token)); // if ( in_array( $_token, $_whitelist ) ) { if ($_token) { // Tell the function what to look for in a post. $_args = array('post_type' => 'optionsframework', 'post_name' => 'of-' . $_token, 'post_status' => 'draft', 'comment_status' => 'closed', 'ping_status' => 'closed'); // Look in the database for a "silent" post that meets our criteria. $query = 'SELECT ID FROM ' . $nxtdb->posts . ' WHERE post_parent = 0'; foreach ($_args as $k => $v) { $query .= ' AND ' . $k . ' = "' . $v . '"'; } // End FOREACH Loop $query .= ' LIMIT 1'; $_posts = $nxtdb->get_row($query); // If we've got a post, loop through and get it's ID. if (count($_posts)) { $_id = $_posts->ID; } else { // If no post is present, insert one. // Prepare some additional data to go with the post insertion. $_words = explode('_', $_token); $_title = join(' ', $_words); $_title = ucwords($_title); $_post_data = array('post_title' => $_title); $_post_data = array_merge($_post_data, $_args); $_id = nxt_insert_post($_post_data); } } return $_id; }
/** * Creates a page for the plugin with the given name on the root blog. * * This makes a new page for the plugin, and adds it to the list of plugin * pages, which is used to make the page visible but not shown automatically * in the list of pages on a site that appears at the top of manyt hemes. * * An optional existing page ID can be passed in. If this argument is given * and the page ID does not map to a valid page, the page is recreated. If * the page ID represents an extant and valid page, however, no action is * taken except for making sure that the page is registered in the list * of plugin-created pages. * * @param string $name the name of the page to create * @param string $content the desired content of the page * @param int $page_id the optional ID of an already created page * @return int the ID of the created page * * @access protected * @since 0.1 */ public static function create_plugin_page($name, $content = '', $page_id = null) { $conflicts = true; $counter = 0; $page_name = $name; // If a page with the given ID already exists, abort early if ($page_id && get_page($page_id)) { self::_register_plugin_page($page_id); return $page_id; } // Find a name for the new page that doesn't conflict with others while ($conflicts) { $page = get_page_by_title($page_name); if (isset($page)) { $counter++; $page_name = sprintf('%s %d', $name, $counter); } else { $conflicts = false; } } // Create the new page and store its ID $new_page = array('post_author' => ClassBlogs_Settings::get_admin_user_id(), 'post_content' => $content, 'post_status' => 'publish', 'post_title' => $page_name, 'post_type' => 'page'); $page_id = nxt_insert_post($new_page); self::_register_plugin_page($page_id); return $page_id; }
/** * Save the properties of a menu item or create a new one. * * @since 3.0.0 * * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item. * @param array $menu_item_data The menu item's data. * @return int The menu item's database ID or nxt_Error object on failure. */ function nxt_update_nav_menu_item($menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array()) { $menu_id = (int) $menu_id; $menu_item_db_id = (int) $menu_item_db_id; // make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects if (!empty($menu_item_db_id) && !is_nav_menu_item($menu_item_db_id)) { return new nxt_Error('update_nav_menu_item_failed', __('The given object ID is not that of a menu item.')); } $menu = nxt_get_nav_menu_object($menu_id); if (!$menu && 0 !== $menu_id || is_nxt_error($menu)) { return $menu; } $menu_items = 0 == $menu_id ? array() : (array) nxt_get_nav_menu_items($menu_id, array('post_status' => 'publish,draft')); $count = count($menu_items); $defaults = array('menu-item-db-id' => $menu_item_db_id, 'menu-item-object-id' => 0, 'menu-item-object' => '', 'menu-item-parent-id' => 0, 'menu-item-position' => 0, 'menu-item-type' => 'custom', 'menu-item-title' => '', 'menu-item-url' => '', 'menu-item-description' => '', 'menu-item-attr-title' => '', 'menu-item-target' => '', 'menu-item-classes' => '', 'menu-item-xfn' => '', 'menu-item-status' => ''); $args = nxt_parse_args($menu_item_data, $defaults); if (0 == $menu_id) { $args['menu-item-position'] = 1; } elseif (0 == (int) $args['menu-item-position']) { $last_item = array_pop($menu_items); $args['menu-item-position'] = $last_item && isset($last_item->menu_order) ? 1 + $last_item->menu_order : $count; } $original_parent = 0 < $menu_item_db_id ? get_post_field('post_parent', $menu_item_db_id) : 0; if ('custom' != $args['menu-item-type']) { /* if non-custom menu item, then: * use original object's URL * blank default title to sync with original object's */ $args['menu-item-url'] = ''; $original_title = ''; if ('taxonomy' == $args['menu-item-type']) { $original_parent = get_term_field('parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw'); $original_title = get_term_field('name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw'); } elseif ('post_type' == $args['menu-item-type']) { $original_object = get_post($args['menu-item-object-id']); $original_parent = (int) $original_object->post_parent; $original_title = $original_object->post_title; } if (empty($args['menu-item-title']) || $args['menu-item-title'] == $original_title) { $args['menu-item-title'] = ''; // hack to get nxt to create a post object when too many properties are empty if (empty($args['menu-item-description'])) { $args['menu-item-description'] = ' '; } } } // Populate the menu item object $post = array('menu_order' => $args['menu-item-position'], 'ping_status' => 0, 'post_content' => $args['menu-item-description'], 'post_excerpt' => $args['menu-item-attr-title'], 'post_parent' => $original_parent, 'post_title' => $args['menu-item-title'], 'post_type' => 'nav_menu_item'); if (0 != $menu_id) { $post['tax_input'] = array('nav_menu' => array(intval($menu->term_id))); } // New menu item. Default is draft status if (0 == $menu_item_db_id) { $post['ID'] = 0; $post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft'; $menu_item_db_id = nxt_insert_post($post); // Update existing menu item. Default is publish status } else { $post['ID'] = $menu_item_db_id; $post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish'; nxt_update_post($post); } if ('custom' == $args['menu-item-type']) { $args['menu-item-object-id'] = $menu_item_db_id; $args['menu-item-object'] = 'custom'; } if (!$menu_item_db_id || is_nxt_error($menu_item_db_id)) { return $menu_item_db_id; } $menu_item_db_id = (int) $menu_item_db_id; update_post_meta($menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type'])); update_post_meta($menu_item_db_id, '_menu_item_menu_item_parent', (int) $args['menu-item-parent-id']); update_post_meta($menu_item_db_id, '_menu_item_object_id', (int) $args['menu-item-object-id']); update_post_meta($menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object'])); update_post_meta($menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target'])); $args['menu-item-classes'] = array_map('sanitize_html_class', explode(' ', $args['menu-item-classes'])); $args['menu-item-xfn'] = implode(' ', array_map('sanitize_html_class', explode(' ', $args['menu-item-xfn']))); update_post_meta($menu_item_db_id, '_menu_item_classes', $args['menu-item-classes']); update_post_meta($menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn']); update_post_meta($menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url'])); if (0 == $menu_id) { update_post_meta($menu_item_db_id, '_menu_item_orphaned', time()); } else { delete_post_meta($menu_item_db_id, '_menu_item_orphaned'); } do_action('nxt_update_nav_menu_item', $menu_id, $menu_item_db_id, $args); return $menu_item_db_id; }
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(' '), 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; } }
/** * Creates a new post from the "Write Post" form using $_POST information. * * @since 2.1.0 * * @return unknown */ function nxt_write_post() { global $user_ID; if (isset($_POST['post_type'])) { $ptype = get_post_type_object($_POST['post_type']); } else { $ptype = get_post_type_object('post'); } if (!current_user_can($ptype->cap->edit_posts)) { if ('page' == $ptype->name) { return new nxt_Error('edit_pages', __('You are not allowed to create pages on this site.')); } else { return new nxt_Error('edit_posts', __('You are not allowed to create posts or drafts on this site.')); } } $_POST['post_mime_type'] = ''; // Clear out any data in internal vars. unset($_POST['filter']); // Edit don't write if we have a post id. if (isset($_POST['post_ID'])) { return edit_post(); } $translated = _nxt_translate_postdata(false); if (is_nxt_error($translated)) { return $translated; } if (isset($_POST['visibility'])) { switch ($_POST['visibility']) { case 'public': $_POST['post_password'] = ''; break; case 'password': unset($_POST['sticky']); break; case 'private': $_POST['post_status'] = 'private'; $_POST['post_password'] = ''; unset($_POST['sticky']); break; } } // Create the post. $post_ID = nxt_insert_post($_POST); if (is_nxt_error($post_ID)) { return $post_ID; } if (empty($post_ID)) { return 0; } add_meta($post_ID); add_post_meta($post_ID, '_edit_last', $GLOBALS['current_user']->ID); // Now that we have an ID we can fix any attachment anchor hrefs _fix_attachment_links($post_ID); nxt_set_post_lock($post_ID); return $post_ID; }
/** * new_schedule_screen( $vars ) * * Hooks into screen_handler * Adds a UI to add new schedules. * * @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_schedule_screen($vars) { global $bp; $nonce_name = 'new_schedule'; $repeats = null; if (!$this->has_schedule_caps($bp->loggedin_user->id) && !is_super_admin()) { $vars['die'] = __('BuddyPress Courseware Error while forbidden user tried to add a new course.', 'bpsp'); return $vars; } // Save new schedule if (isset($_POST['schedule']) && $_POST['schedule']['object'] == 'group' && isset($_POST['_nxtnonce'])) { if (empty($_POST['schedule']['title']) || empty($_POST['schedule']['desc']) || empty($_POST['schedule']['start_date'])) { $vars['error'] = __('New schedule could not be added. Missing description/title and/or start date.', 'bpsp'); $vars['schedule']->title = $_POST['schedule']['title']; $vars['schedule']->desc = $_POST['schedule']['desc']; $_POST = null; return $this->new_schedule_screen($vars); } $new_schedule = $_POST['schedule']; if (!empty($new_schedule['repetition']) && !empty($new_schedule['repetition_times'])) { $repeats = array('interval' => $new_schedule['repetition'], 'count' => $new_schedule['repetition_times']); } else { $repeats = null; } $valid_dates = $this->datecheck($new_schedule['start_date'], $new_schedule['end_date'], $repeats); $is_nonce = nxt_verify_nonce($_POST['_nxtnonce'], $nonce_name); if (true != $is_nonce) { $vars['die'] = __('Nonce Error while adding a schedule.', 'bpsp'); return $vars; } else { if (!empty($new_schedule['desc']) || !empty($new_schedule['group_id']) || !$valid_dates) { // create a template $first_schedule = array('post_author' => $bp->loggedin_user->id, 'post_title' => sanitize_text_field($new_schedule['title']), 'post_content' => sanitize_text_field($new_schedule['desc']), 'post_status' => 'publish', 'post_type' => 'schedule', 'cw_group_id' => $new_schedule['group_id'], 'cw_start_date' => $new_schedule['start_date'], 'cw_end_date' => $new_schedule['end_date'], 'cw_location' => sanitize_text_field($new_schedule['location'])); if (BPSP_Courses::is_course($new_schedule['course_id'])) { $first_schedule['cw_course_id'] = $new_schedule['course_id']; } if (BPSP_Lectures::is_lecture($new_schedule['lecture_id'])) { $first_schedule['cw_lecture_id'] = $new_schedule['lecture_id']; } // store first schedule $new_schedules[] = array_filter($first_schedule); // generate repeated events if (is_array($valid_dates)) { foreach ($valid_dates as $p) { $schedule_copy = reset($new_schedules); $schedule_copy['cw_start_date'] = $p['start_date']; $schedule_copy['cw_end_date'] = $p['end_date']; $new_schedules[] = $schedule_copy; } } // Add all schedules $counted_schedules = count($new_schedules); foreach ($new_schedules as $newschedule) { $newschedule_id = nxt_insert_post($newschedule); if ($newschedule_id) { nxt_set_post_terms($newschedule_id, $newschedule['cw_group_id'], 'group_id'); if ($newschedule['cw_course_id']) { nxt_set_post_terms($newschedule_id, $newschedule['cw_course_id'], 'course_id'); } add_post_meta($newschedule_id, 'lecture_id', $newschedule['cw_lecture_id']); add_post_meta($newschedule_id, 'start_date', $newschedule['cw_start_date']); add_post_meta($newschedule_id, 'end_date', $newschedule['cw_end_date']); if ($newschedule['cw_location']) { add_post_meta($newschedule_id, 'location', $newschedule['cw_location']); } } } $vars['message'] = __('New schedule was added.', 'bpsp'); do_action('courseware_schedule_activity', $counted_schedules); return $this->list_schedules_screen($vars); } else { $vars['error'] = __('New schedule could not be added.', 'bpsp'); } } } $vars['name'] = 'new_schedule'; $vars['group_id'] = $bp->groups->current_group->id; $vars['course_id'] = $this->current_course->ID; $vars['user_id'] = $bp->loggedin_user->id; $vars['lectures'] = BPSP_Lectures::has_lectures($bp->groups->current_group->id); $vars['nonce'] = nxt_nonce_field($nonce_name, '_nxtnonce', true, false); $vars['trail'] = array(__('New Schedule', 'bpsp') => ''); return $vars; }
function create_new_and_redirect() { //echo 'workin?'; if (isset($_GET['new_wiki_page']) && $_GET['new_wiki_page'] == 'true' && nxt_verify_nonce($_GET['nonce'], 'nxtw_new_page_nonce')) { global $nxt_version; global $nxtdb; $new_wiki = array(); $title = strip_tags($_GET['title']); $pieces = explode(':', $title, 2); if (count($pieces) == 2) { list($namespace, $topic) = $pieces; $namespace = strtolower(preg_replace('/[ -]+/', '-', $namespace)); $parent_id = $nxtdb->get_var('SELECT id FROM `' . $nxtdb->posts . '` WHERE post_name = "' . $namespace . '"'); if ($parent_id) { $new_wiki['post_parent'] = $parent_id; } } else { $namespace = ''; $topic = $title; } $topic = strtolower(preg_replace('/[ -]+/', '-', $topic)); $url = get_option('siteurl') . '/wiki/' . ($namespace ? $namespace . '/' : '') . $topic; $new_wiki['post_name'] = $topic; $new_wiki['post_title'] = $title; $new_wiki['post_content'] = 'Click the "Edit" tab to add content to this page.'; $new_wiki['guid'] = $url; $new_wiki['post_status'] = 'publish'; if ($nxt_version >= 3.0) { $new_wiki['post_type'] = 'wiki'; } $new_wiki_id = nxt_insert_post($new_wiki); if ($nxt_version <= 3.0) { update_post_meta($new_wiki_id, '_wiki_page', 1); } nxt_redirect($url); exit; } }
/** * 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; }
/** * Inserts post data into the posts table as a post revision. * * @package NXTClass * @subpackage Post_Revisions * @since 2.6.0 * * @uses nxt_insert_post() * * @param int|object|array $post Post ID, post object OR post array. * @param bool $autosave Optional. Is the revision an autosave? * @return mixed Null or 0 if error, new revision ID if success. */ function _nxt_put_post_revision($post = null, $autosave = false) { if (is_object($post)) { $post = get_object_vars($post); } elseif (!is_array($post)) { $post = get_post($post, ARRAY_A); } if (!$post || empty($post['ID'])) { return; } if (isset($post['post_type']) && 'revision' == $post['post_type']) { return new nxt_Error('post_type', __('Cannot create a revision of a revision')); } $post = _nxt_post_revision_fields($post, $autosave); $post = add_magic_quotes($post); //since data is from db $revision_id = nxt_insert_post($post); if (is_nxt_error($revision_id)) { return $revision_id; } if ($revision_id) { do_action('_nxt_put_post_revision', $revision_id); } return $revision_id; }
function bp_core_create_root_component_page() { global $bp; $new_page_ids = array(); foreach ((array) $bp->add_root as $slug) { $new_page_ids[$slug] = nxt_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords($slug), 'post_status' => 'publish', 'post_type' => 'page')); } $page_ids = array_merge((array) $new_page_ids, (array) bp_core_get_directory_page_ids()); bp_core_update_directory_page_ids($page_ids); }
function setup_pages($pages) { foreach ($pages as $key => $value) { if ('page' == $value) { // Check for the selected page if (!empty($_POST['bp-' . $key . '-page'])) { $bp_pages[$key] = (int) $_POST['bp-' . $key . '-page']; } else { $bp_pages[$key] = nxt_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords($key), 'post_status' => 'publish', 'post_type' => 'page')); } } else { // Create a new page $bp_pages[$key] = nxt_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_title' => ucwords($value), 'post_status' => 'publish', 'post_type' => 'page')); } } return $bp_pages; }
/** * 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 “%s”: 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 “%s” 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 “%s”', '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); }