public static function the_posts($posts) { CrayonLog::debug('the_posts'); // Whether to enqueue syles/scripts CrayonSettingsWP::load_settings(TRUE); // We will eventually need more than the settings self::init_tags_regex(); $crayon_posts = CrayonSettingsWP::load_posts(); // Loads posts containing crayons // Search for shortcode in posts foreach ($posts as $post) { $wp_id = $post->ID; $is_page = $post->post_type == 'page'; if (!in_array($wp_id, $crayon_posts)) { // If we get query for a page, then that page might have a template and load more posts containing Crayons // By this state, we would be unable to enqueue anything (header already written). if (CrayonGlobalSettings::val(CrayonSettings::SAFE_ENQUEUE) && $is_page) { CrayonGlobalSettings::set(CrayonSettings::ENQUEUE_THEMES, false); CrayonGlobalSettings::set(CrayonSettings::ENQUEUE_FONTS, false); } // Only include crayon posts continue; } $id_str = strval($wp_id); if (wp_is_post_revision($wp_id)) { // Ignore post revisions, use the parent, which has the updated post content continue; } if (isset(self::$post_captures[$id_str])) { // Don't capture twice // XXX post->post_content is reset each loop, replace content // Doing this might cause content changed by other plugins between the last loop // to fail, so be cautious $post->post_content = self::$post_captures[$id_str]; continue; } // Capture post Crayons $captures = self::capture_crayons(intval($post->ID), $post->post_content); // XXX Careful not to undo changes by other plugins // XXX Must replace to remove $ for ignored Crayons $post->post_content = $captures['content']; self::$post_captures[$id_str] = $captures['content']; if ($captures['has_captured'] === TRUE) { self::$post_queue[$id_str] = array(); foreach ($captures['capture'] as $capture_id => $capture_content) { self::$post_queue[$id_str][$capture_id] = $capture_content; } } // Search for shortcode in comments if (CrayonGlobalSettings::val(CrayonSettings::COMMENTS)) { $comments = get_comments(array('post_id' => $post->ID)); foreach ($comments as $comment) { $id_str = strval($comment->comment_ID); if (isset(self::$comment_queue[$id_str])) { // Don't capture twice continue; } // Capture comment Crayons, decode their contents if decode not specified $content = apply_filters('get_comment_text', $comment->comment_content, $comment); $captures = self::capture_crayons($comment->comment_ID, $content, array(CrayonSettings::DECODE => TRUE)); self::$comment_captures[$id_str] = $captures['content']; if ($captures['has_captured'] === TRUE) { self::$comment_queue[$id_str] = array(); foreach ($captures['capture'] as $capture_id => $capture_content) { self::$comment_queue[$id_str][$capture_id] = $capture_content; } } } } } return $posts; }
public static function the_posts($posts) { CrayonLog::debug('the_posts'); // Whether to enqueue syles/scripts $enqueue = FALSE; CrayonSettingsWP::load_settings(TRUE); // Load just the settings from db, for now self::init_tags_regex(); $crayon_posts = CrayonSettingsWP::load_posts(); // Loads posts containing crayons // Search for shortcode in posts foreach ($posts as $post) { $wp_id = $post->ID; if (!in_array($wp_id, $crayon_posts)) { // If we get query for a page, then that page might have a template and load more posts containing Crayons // By this state, we would be unable to enqueue anything (header already written). if (CrayonGlobalSettings::val(CrayonSettings::SAFE_ENQUEUE) && is_page($wp_id)) { CrayonGlobalSettings::set(CrayonSettings::ENQUEUE_THEMES, false); CrayonGlobalSettings::set(CrayonSettings::ENQUEUE_FONTS, false); } else { // Only include crayon posts continue; } } $id_str = strval($wp_id); if (isset(self::$post_captures[$id_str])) { // Don't capture twice // XXX post->post_content is reset each loop, replace content // Doing this might cause content changed by other plugins between the last loop // to fail, so be cautious $post->post_content = self::$post_captures[$id_str]; continue; } // Capture post Crayons $captures = self::capture_crayons($post->ID, $post->post_content); // XXX Careful not to undo changes by other plugins // XXX Must replace to remove $ for ignored Crayons $post->post_content = $captures['content']; self::$post_captures[$id_str] = $captures['content']; if ($captures['has_captured'] === TRUE) { $enqueue = TRUE; self::$post_queue[$id_str] = array(); foreach ($captures['capture'] as $capture_id => $capture_content) { self::$post_queue[$id_str][$capture_id] = $capture_content; } } // Search for shortcode in comments if (CrayonGlobalSettings::val(CrayonSettings::COMMENTS)) { $comments = get_comments(array('post_id' => $post->ID)); foreach ($comments as $comment) { $id_str = strval($comment->comment_ID); if (isset(self::$comment_queue[$id_str])) { // Don't capture twice continue; } // Capture comment Crayons, decode their contents if decode not specified $captures = self::capture_crayons($comment->comment_ID, $comment->comment_content, array(CrayonSettings::DECODE => TRUE)); self::$comment_captures[$id_str] = $captures['content']; if ($captures['has_captured'] === TRUE) { $enqueue = TRUE; self::$comment_queue[$id_str] = array(); foreach ($captures['capture'] as $capture_id => $capture_content) { self::$comment_queue[$id_str][$capture_id] = $capture_content; } } } } } if (!is_admin() && $enqueue && !self::$enqueued) { // Crayons have been found and we enqueue efficiently self::enqueue_resources(); } return $posts; }