private function printRecipe($postID, $recipeIX)
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     $post = get_post($postID);
     if (!$post) {
         return;
     }
     /**
      * Process the [br] shortcodes and remove the spurious <br>'s that wp_auto() inserts
      */
     $content = str_replace("[br]", "<br>", $post->post_content);
     $content = preg_replace('%</div>\\s*</p></div>%im', '</div></div>', $content);
     if ($this->settings->displayZiplist) {
         /**
          * Process recipes from other plugins
          * Most of these are handled by shortcodes which we replace with an EasyRecipe equivalent
          * Recipage is a little more involved. It is hrecipe formatted and we can't reliably extract the recipe code with a regex, so we need to use a DOMDocument
          */
         $content = preg_replace_callback('/\\[amd-(zlrecipe)-recipe:(\\d+)\\]/', array($this, 'doConvert'), $content);
     }
     if ($this->settings->displayRecipeCard) {
         $content = preg_replace_callback("/\\[(yumprint)-recipe id='(\\d+)'\\]/", array($this, 'doConvert'), $content);
     }
     if ($this->settings->displayGMC) {
         $content = preg_replace_callback('/\\[(gmc_recipe) (\\d+)\\]/', array($this, 'doConvert'), $content);
     }
     if ($this->settings->displayUltimateRecipe) {
         $content = preg_replace_callback('/\\[(ultimate-recipe) id=["\'](\\d+|random)["\']\\]/i', array($this, 'doConvert'), $content);
     }
     if ($this->settings->displayRecipage) {
         /**
          * Do a quick check before we go to the expense of instantiating a DOMDocument
          */
         if (strpos($content, 'hrecipe f') !== false) {
             $document = new EasyRecipePlusDOMDocument($content);
             if ($document->isValid()) {
                 /** @var DOMElement $hrecipe */
                 $hrecipe = $document->getElementByClassName('hrecipe');
                 if ($hrecipe) {
                     $matches = array();
                     $matches[1] = 'recipage';
                     $matches[2] = $postID;
                     $convertedRecipe = $this->doConvert($matches);
                     /** @var DOMDocumentFragment $fragment */
                     $fragment = $document->createDocumentFragment();
                     $fragment->appendXML($convertedRecipe);
                     $hrecipe->parentNode->replaceChild($fragment, $hrecipe);
                     $content = $document->saveHTML();
                 }
             }
         }
     }
     $postDOM = new EasyRecipePlusDocument($content);
     if (!$postDOM->isEasyRecipe) {
         return;
     }
     /**
      * If the post is formatted already then it came from the Object cache
      * If that's the case we need to re-read the original
      */
     if ($postDOM->isFormatted) {
         $post = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "posts WHERE ID = {$postID}");
         $postDOM = new EasyRecipePlusDocument($post->post_content);
         if (!$postDOM->isEasyRecipe) {
             return;
         }
     }
     $this->settings = EasyRecipePlusSettings::getInstance();
     if (isset($_GET['style'])) {
         $this->styleName = $_GET['style'];
     } else {
         $this->styleName = $this->settings->printStyle;
     }
     //        $this->printStyleData = call_user_func(array($this->stylesClass, 'getStyleData'), $this->styleName, $this->settings->get('customTemplates'), true);
     $this->printStyleData = EasyRecipePlusStyles::getStyleData($this->styleName, $this->settings->customTemplates, true);
     if (get_locale() != 'en_US') {
         EasyRecipePlusTemplate::setTranslate('easyrecipe');
     }
     /**
      * Fix possibly broken times in older posts
      * Fix the Cholesterol oops in early versions
      */
     if ($postDOM->recipeVersion < '3') {
         $postDOM->fixTimes("preptime");
         $postDOM->fixTimes("cooktime");
         $postDOM->fixTimes("duration");
         $postDOM->setParentValueByClassName("cholestrol", $this->settings->lblCholesterol, "Cholestrol");
     }
     $postDOM->setSettings($this->settings);
     $data = new stdClass();
     $data->hasRating = false;
     $data->convertFractions = $this->settings->convertFractions;
     $this->settings->getLabels($data);
     $data->hasLinkback = $this->settings->allowLink;
     $data->title = $post->post_title;
     $data->blogname = get_option("blogname");
     $data->recipeurl = get_permalink($post->ID);
     $data->customCSS = $this->getCSS('Print');
     $data->extraPrintHeader = $this->settings->extraPrintHeader;
     $data->easyrecipeURL = self::$EasyRecipePlusUrl;
     $recipe = $postDOM->getRecipe($recipeIX);
     $photoURL = $postDOM->findPhotoURL($recipe);
     $data->hasPhoto = !empty($photoURL);
     $data->jqueryjs = self::JQUERYJS;
     $data->jqueryuijs = self::JQUERYUIJS;
     $data->jqueryuicss = self::JQUERYUICSS;
     if (current_user_can('edit_posts')) {
         $data->isAdmin = true;
         $data->formatDialog = $this->getFormatDialog(true);
     } else {
         $data->formatDialog = '';
     }
     $data->style = $this->styleName;
     if ($data->style[0] == '_') {
         $style = substr($data->style, 1);
         $data->css = "/easyrecipe-printstyle";
         $templateFile = $this->settings->customTemplates . "/printstyles/{$style}/style.html";
     } else {
         $data->css = self::$EasyRecipePlusUrl . "/printstyles/{$data->style}";
         $templateFile = self::$EasyRecipePlusDir . "/printstyles/{$data->style}/style.html";
     }
     $data->css .= "/style.css?version=" . self::$pluginVersion . ".{$this->printStyleData->version}";
     $template = new EasyRecipePlusTemplate($templateFile);
     /**
      * Brain dead IE shows "friendly" error pages (i.e. it's non-compliant) so we need to force a 200
      */
     header("HTTP/1.1 200 OK");
     echo $postDOM->formatRecipe($recipe, $template, $data);
     exit;
 }
 /**
  * Get the post, extract the recipe and combine with the current style and output it
  *
  * @param integer $postID The post ID to print
  * @param integer $recipeIX The zero based index of the recipe in the post
  */
 public function printRecipe($postID, $recipeIX)
 {
     /** @var $wpdb wpdb */
     global $wpdb;
     $settings = EasyRecipePlusSettings::getInstance();
     /**
      * Be paranoid and force the ID to an integer
      */
     $postID = (int) $postID;
     $q = "SELECT * FROM {$wpdb->posts} WHERE ID = {$postID}";
     $post = $wpdb->get_row($q);
     if (!$post) {
         return;
     }
     /**
      * Process the [br] shortcodes and remove the spurious <br>'s that wp_auto() inserts
      */
     $content = str_replace("[br]", "<br>", $post->post_content);
     $content = preg_replace('%</div>\\s*</p></div>%im', '</div></div>', $content);
     $content = $this->plugin->possiblyConvert($postID, $post->post_type, $content);
     $postDOM = new EasyRecipePlusDocument($content);
     if (!$postDOM->isEasyRecipe) {
         return;
     }
     /**
      * If the post is formatted already then it came from the Object cache (?)
      * If that's the case we need to re-read the original
      */
     if ($postDOM->isFormatted) {
         $post = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "posts WHERE ID = {$postID}");
         $content = str_replace("[br]", "<br>", $post->post_content);
         $content = preg_replace('%</div>\\s*</p></div>%im', '</div></div>', $content);
         $content = $this->plugin->possiblyConvert($postID, '', $content);
         $postDOM = new EasyRecipePlusDocument($content);
         if (!$postDOM->isEasyRecipe) {
             return;
         }
     }
     if (isset($_GET['style'])) {
         $styleName = $_GET['style'];
     } else {
         $styleName = $settings->printStyle;
     }
     //        $printStyleData = call_user_func(array($this->stylesClass, 'getStyleData'), $styleName, $settings->get('customTemplates'), true);
     $printStyleData = EasyRecipePlusStyles::getStyleData($styleName, $settings->customTemplates, true);
     if (get_locale() != 'en_US') {
         EasyRecipePlusTemplate::setTranslate('easyrecipe');
     }
     /**
      * Fix possibly broken times in older posts
      * Fix the Cholesterol oops in early versions
      */
     if ($postDOM->recipeVersion < '3') {
         $postDOM->fixTimes("preptime");
         $postDOM->fixTimes("cooktime");
         $postDOM->fixTimes("duration");
         $postDOM->setParentValueByClassName("cholestrol", $settings->lblCholesterol, "Cholestrol");
     }
     $postDOM->setSettings($settings);
     $data = new stdClass();
     $data->hasRating = false;
     $data->convertFractions = $settings->convertFractions;
     $settings->getLabels($data);
     $data->hasLinkback = $settings->allowLink;
     $data->title = $post->post_title;
     $data->blogname = get_option("blogname");
     $data->recipeurl = get_permalink($post->ID);
     $data->customCSS = $this->plugin->getCSS('Print');
     $data->extraPrintHeader = $settings->extraPrintHeader;
     $data->easyrecipeURL = EasyRecipePlus::$EasyRecipePlusUrl;
     $recipe = $postDOM->getRecipe($recipeIX);
     $photoURL = $postDOM->findPhotoURL($recipe);
     $data->hasPhoto = !empty($photoURL);
     $data->jqueryjs = self::JQUERYJS;
     $data->jqueryuijs = self::JQUERYUIJS;
     $data->jqueryuicss = self::JQUERYUICSS;
     if (current_user_can('edit_posts')) {
         $data->isAdmin = true;
         $data->formatDialog = $this->plugin->getFormatDialog($printStyleData, true);
         $cssLink = '<link href="' . EasyRecipePlus::$EasyRecipePlusUrl . '/css/%s?version=' . EasyRecipePlus::$pluginVersion . '" rel="stylesheet" type="text/css"/>';
         $jsLink = '<script type="text/javascript" src="' . EasyRecipePlus::$EasyRecipePlusUrl . '/js/%s?version=' . EasyRecipePlus::$pluginVersion . '"></script>';
         $data->formatCSS = sprintf($cssLink, 'easyrecipe-format-min.css');
         $data->formatJS = sprintf($jsLink, 'easyrecipe-format-min.js');
     } else {
         $data->formatDialog = '';
         $data->printJS = '<script type="text/javascript" src="' . EasyRecipePlus::$EasyRecipePlusUrl . '/js/easyrecipe-print-min.js?version=' . EasyRecipePlus::$pluginVersion . '"></script>';
     }
     $data->style = $styleName;
     if ($data->style[0] == '_') {
         $style = substr($data->style, 1);
         $data->css = "/easyrecipe-printstyle";
         $templateFile = $settings->customTemplates . "/printstyles/{$style}/style.html";
     } else {
         $data->css = EasyRecipePlus::$EasyRecipePlusUrl . "/printstyles/{$data->style}";
         $templateFile = EasyRecipePlus::$EasyRecipePlusDir . "/printstyles/{$data->style}/style.html";
     }
     $data->css .= "/style.css?version=" . EasyRecipePlus::$pluginVersion . ".{$printStyleData->version}";
     $template = new EasyRecipePlusTemplate($templateFile);
     /**
      * Brain dead IE shows "friendly" error pages (i.e. it's non-compliant) so we need to force a 200
      */
     header("HTTP/1.1 200 OK");
     /**
      * Set the character encoding explicitly
      */
     $charset = get_bloginfo('charset');
     header("Content-Type:text/html; charset={$charset}");
     echo $postDOM->formatRecipe($recipe, $template, $data);
     flush();
     exit;
 }
 /**
  */
 function enqueueScripts()
 {
     /*
      * We only need our stuff if there's an EasyRecipe on the post/page
      */
     if (count($this->easyrecipes) == 0) {
         return;
     }
     /**
      * Hook into the comments stuff to add the rating widget, display rating on individual comments and save a rating
      * and ajax calls don't trigger the wp_enqueue_scripts action where this was done previously
      */
     if ($this->settings->ratings == 'EasyRecipe') {
         add_action('comment_form', array($this, 'commentForm'), 0);
         add_action('comment_post', array($this, 'ratingSave'));
         // TODO - get ratings from all comments in one DB read when the comments start to display
         // Otherwise we'll have heaps of single row accesses if there's loads of comments
         add_filter('get_comment_text', array($this, 'ratingDisplay'), 100);
     }
     /**
      * Set the translate switch if this isn't in the US
      */
     if (get_locale() != 'en_US') {
         EasyRecipePlusTemplate::setTranslate('easyrecipe');
     }
     if ($this->settings->removeMicroformat) {
         add_filter('post_class', array($this, 'postClass'), 100);
         ob_start(array($this, 'fixMicroformats'));
     }
     $this->styleData = EasyRecipePlusStyles::getStyleData($this->styleName, $this->settings->customTemplates);
     wp_enqueue_style('easyrecipestyle-reset', self::$EasyRecipePlusUrl . "/css/easyrecipe-style-reset-min.css", array(), self::$pluginVersion);
     wp_enqueue_style("easyrecipebuttonUI", self::$EasyRecipePlusUrl . "/ui/easyrecipe-buttonUI.css", array('easyrecipestyle-reset'), self::$pluginVersion);
     /**
      * If the style directory starts with an underscore, it's a custom style
      */
     if ($this->styleData->directory[0] == '_') {
         wp_enqueue_style("easyrecipestyle", "/easyrecipe-style/style.css", array('easyrecipestyle-reset'), self::$pluginVersion . ".{$this->styleData->version}");
     } else {
         wp_enqueue_style("easyrecipestyle", self::$EasyRecipePlusUrl . "/styles/{$this->styleName}/style.css", array('easyrecipestyle-reset'), self::$pluginVersion . ".{$this->styleData->version}");
     }
     if (file_exists(self::$EasyRecipePlusDir . "/styles/{$this->styleName}/style.js")) {
         wp_enqueue_script('easyrecipestyle', self::$EasyRecipePlusUrl . "/styles/{$this->styleName}/style.js", array($this->pluginName), self::$pluginVersion . ".{$this->styleData->version}", $this->loadJSInFooter);
     }
     wp_enqueue_script($this->pluginName, self::$EasyRecipePlusUrl . "/js/easyrecipe-min.js", array('jquery', 'jquery-ui-button'), self::$pluginVersion, $this->loadJSInFooter);
     /**
      * Load any fonts used by the style
      * TODO - the enqueue name should be unique
      */
     foreach ($this->styleData->fonts as $font) {
         switch ($font['provider']) {
             case 'google':
                 wp_enqueue_style("easyrecipefonts-" . $font['provider'], "http://fonts.googleapis.com/css?family=" . $font['fonts']);
                 break;
         }
     }
     /**
      * Load format dialogs and UI CSS if logged in as admin
      * Use our own version of an unobtrusive jQuery UI theme to prevent interference from themes and plugins that override standard stuff
      *
      * edit_theme_options is a better capability to check than edit_plugins (which is limited to super admins)
      *
      * Don't setup Live Formatting if the theme is being customized.
      *
      */
     if (current_user_can("edit_theme_options") && !class_exists('WP_Customize_Control', false)) {
         /*
          * Use an unobtrusive grey scheme for the formatting dialog so it doesn't visually overpower the recipe's styling
          */
         wp_enqueue_style("easyrecipe-FormatUI", self::$EasyRecipePlusUrl . "/formatui/easyrecipeFormatUI{$this->uiVersion}.css", array(), self::$pluginVersion);
         wp_enqueue_style("easyrecipeformat", self::$EasyRecipePlusUrl . "/css/easyrecipe-format-min.css", array('easyrecipe-FormatUI'), self::$pluginVersion);
         wp_enqueue_script('easyrecipeformat', self::$EasyRecipePlusUrl . "/js/easyrecipe-format-min.js", array('jquery', 'jquery-ui-slider', 'jquery-ui-autocomplete', 'jquery-ui-accordion', 'jquery-ui-dialog', 'jquery-ui-tabs', 'jquery-ui-button', 'json2'), self::$pluginVersion, $this->loadJSInFooter);
         add_action('wp_footer', array($this, 'addFormatDialog'), 0);
     }
     if ($this->settings->enableSwoop) {
         add_action('wp_footer', array($this, 'addSwoop'), 32767);
     }
     if ($this->settings->saveButton == 'BigOven') {
         add_action('wp_footer', array($this, 'addRecipeJSON'));
     }
 }