/** * Enable the Real-Time Editor for LivePress. * * Fetch the content of the user's current textarea and return: * - Original post content, split into regions with distinct IDs * - Processed content, again split into regions * - User's POSTed content, split into regions with same IDs as original post * - Processed POSTed content, split into regions */ public function start_editor() { // Globalize $post so we can modify it a bit before using it global $post; // Set up the $post object $post_id = absint($_POST['post_id']); $post = get_post($post_id); $post->no_update_tag = true; if (isset($_POST['content'])) { $user_content = wp_kses_post(stripslashes($_POST['content'])); } else { $user_content = ''; } $this->assemble_pieces($post); // If the post content is not empty, and there are no child posts, the post has // just been made live. Insert the content as a live update if (0 == count($this->pieces)) { if ('' !== $user_content) { // Add a live update with the current content if (array_key_exists('update_meta', $_POST)) { $update_meta = $_POST['update_meta']; } $update_meta['draft'] = false; // TODO: set to match the post state $title = get_the_title($post_id); $update_header = !empty($title) && 'Auto Draft' !== $title ? 'update_header="' . $title . '"' : ''; $user = wp_get_current_user(); $user_text = ' authors="' . $user->display_name . '" ' . $update_header; $user_content = str_replace('authors=""', $user_text, $user_content); $admin_settings = new LivePress_Admin_Settings(); $settings = $admin_settings->get_settings(); if (in_array('AUTHOR', $settings->show)) { $avartar_html = $this->avatar_html($post) . '<div class="livepress-update-inner-wrapper lp_avatar_shown">'; $user_content = str_replace('<div class="livepress-update-inner-wrapper lp_avatar_hidden">', $avartar_html, $user_content); } $this->add_update($post, $user_content, '', $update_meta); $this->assemble_pieces($post); } } $original = $this->pieces; if ($post->post_content == $user_content) { $user = null; } else { // Proceed user-supplied post content. $user = $this->pieces; } $ans = array('orig' => $original, 'user' => $user, 'edit_uuid' => $this->near_uuid, 'editStartup' => Collaboration::return_live_edition_data()); header('Content-type: application/javascript'); echo json_encode($ans); die; }
/** * Enable the Real-Time Editor for LivePress. * * Fetch the content of the user's current textarea and return: * - Original post content, split into regions with distinct IDs * - Processed content, again split into regions * - User's POSTed content, split into regions with same IDs as original post * - Processed POSTed content, split into regions */ public function start_editor() { // Globalize $post so we can modify it a bit before using it global $post; // Set up the $post object $post_id = (int) $_POST['post_id']; $post = get_post($post_id); $post->no_update_tag = true; if (isset($_POST['content'])) { $user_content = wp_kses_post(stripslashes($_POST['content'])); } else { $user_content = ''; } $this->assemble_pieces($post); // If the post content is not empty, and there are no child posts, the post has // just been made live. Insert the content as a live update if (0 == count($this->pieces)) { if ('' !== $user_content) { // Add a live update with the current content $this->add_update($post, $user_content, ''); $this->assemble_pieces($post); } } $original = $this->pieces; if ($post->post_content == $user_content) { $user = null; } else { // Proceed user-supplied post content. $user = $this->pieces; } $ans = array('orig' => $original, 'user' => $user, 'edit_uuid' => $this->near_uuid, 'editStartup' => Collaboration::return_live_edition_data()); header("Content-type: application/javascript"); echo json_encode($ans); die; }