/** * Converts Crayon tags found in WP to <pre> form. * XXX: This will alter blog content, so backup before calling. * XXX: Do NOT call this while updating posts or comments, it may cause an infinite loop or fail. * @param $encode Whether to detect missing "decode" attribute and encode html entities in the code. */ public static function convert_tags($encode = FALSE) { $crayon_posts = CrayonSettingsWP::load_legacy_posts(); if ($crayon_posts === NULL) { return; } self::init_legacy_tag_bits(); $args = array('callback' => 'CrayonWP::capture_replace_pre', 'callback_extra_args' => array('encode' => $encode), 'ignore' => FALSE, 'preserve_atts' => TRUE, 'flags' => self::$legacy_flags, 'skip_setting_check' => TRUE); foreach ($crayon_posts as $postID) { $post = get_post($postID); $post_content = $post->post_content; $post_captures = self::capture_crayons($postID, $post_content, array(), $args); if ($post_captures['has_captured'] === TRUE) { $post_obj = array(); $post_obj['ID'] = $postID; $post_obj['post_content'] = addslashes($post_captures['content']); wp_update_post($post_obj); CrayonLog::syslog("Converted Crayons in post ID {$postID} to pre tags", 'CONVERT'); } if (CrayonGlobalSettings::val(CrayonSettings::COMMENTS)) { $comments = get_comments(array('post_id' => $postID)); foreach ($comments as $comment) { $commentID = $comment->comment_ID; $comment_captures = self::capture_crayons($commentID, $comment->comment_content, array(CrayonSettings::DECODE => TRUE), $args); if ($comment_captures['has_captured'] === TRUE) { $comment_obj = array(); $comment_obj['comment_ID'] = $commentID; $comment_obj['comment_content'] = $comment_captures['content']; wp_update_comment($comment_obj); CrayonLog::syslog("Converted Crayons in post ID {$postID}, comment ID {$commentID} to pre tags", 'CONVERT'); } } } } self::refresh_posts(); }