/** * Switcheroo! Raw XML content gets switched with HTML formatted content. * Save the raw XML to the post_content_formatted column * Save the formatted HTML to the post_content column */ function anno_insert_post_data($data, $postarr) { // This is the quick edit action, we don't want to mess around with the content. if (isset($_POST['action']) && $_POST['action'] == 'inline-save') { return $data; } $is_article_type = false; // Both published and drafts (before article ever saved) get caught here if ($postarr['post_type'] == 'article') { $is_article_type = true; } // If we're a revision, we need to do one more check to ensure our parent is an article if ($postarr['post_type'] == 'revision') { if (!empty($data['post_parent']) && get_post_type($data['post_parent']) == 'article') { $is_article_type = true; } } if ($is_article_type) { // Get our XML content for the revision $content = stripslashes($data['post_content']); // Remove non-ascii gremlins $content = preg_replace('/(\\xa0|\\xc2)/', '', $content); $content = str_replace(array("\r", "\r\n", "\n"), '', $content); // Set XML as backup content. Filter markup and strip out tags not on whitelist. $xml = anno_validate_xml_content_on_save($content); $data['post_content_filtered'] = addslashes($xml); // Set formatted HTML as the_content $data['post_content'] = addslashes(anno_xml_to_html($xml)); } return $data; }
/** * Switcheroo! Raw XML content gets switched with HTML formatted content. * Save the raw XML to the post_content_formatted column * Save the formatted HTML to the post_content column */ function anno_insert_post_data($data, $postarr) { // This is the quick edit action, we don't want to mess around with the content. if (isset($_POST['action']) && $_POST['action'] == 'inline-save') { return $data; } if ($postarr['post_type'] == 'article' || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE && get_post_type($postarr['post_parent']) == 'article') { // Get our XML content for the revision $content = stripslashes($data['post_content']); // Remove non-ascii gremlins $content = preg_replace('/(\\xc2\\xa0)/', ' ', $content); $content = str_replace(array("\r", "\r\n", "\n"), '', $content); // Set XML as backup content. Filter markup and strip out tags not on whitelist. $xml = anno_validate_xml_content_on_save($content); $data['post_content_filtered'] = addslashes($xml); // Set formatted HTML as the_content $data['post_content'] = addslashes(anno_xml_to_html($xml)); $data['post_excerpt'] = addslashes(anno_validate_xml_content_on_save(stripslashes($data['post_excerpt']))); } return $data; }
/** * Save post meta related to an article */ function anno_article_save_post($post_id, $post) { if ($post->post_type == 'article') { $anno_meta = array('anno_subtitle', 'anno_funding', 'anno_acknowledgements', 'anno_featured'); foreach ($anno_meta as $key) { if (isset($_POST[$key]) || $key == 'anno_featured') { switch ($key) { case 'anno_featured': if (isset($_POST['anno_featured']) && $_POST['anno_featured'] == 'on') { $value = 'on'; } else { $value = 'off'; } // Reset the transient if this is a published article if ($post->post_status == 'publish') { delete_transient('anno_featured'); } break; case 'anno_subtitle': case 'anno_funding': case 'anno_acknowledgements': default: if (isset($_POST[$key])) { $value = force_balance_tags($_POST[$key]); } else { $value = ''; } break; } update_post_meta($post_id, '_' . $key, $value); } } $appendices = array(); if (isset($_POST['anno_appendix']) && is_array($_POST['anno_appendix'])) { foreach ($_POST['anno_appendix'] as $appendix) { if (!anno_is_appendix_empty($appendix)) { $appendices[] = addslashes(anno_validate_xml_content_on_save(stripslashes($appendix))); } } update_post_meta($post_id, '_anno_appendices', $appendices); } } }