/** * 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; }
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; }
public function showPage() { /* @var $wp_rewrite WP_Rewrite */ global $wp_rewrite; /** @var $wpdb wpdb */ global $wpdb; global $wp_version; if (isset($_POST['action']) && $_POST['action'] == 'save') { $this->save($_POST["EasyRecipePlus"]); } $data = new stdClass(); foreach (self::$defaultSettings as $setting => $default) { $data->{$setting} = isset($this->{$setting}) ? $this->{$setting} : $default; } $data->settingsname = 'EasyRecipePlus'; $wpurl = get_bloginfo("wpurl"); $data->fdsite = preg_replace('%^(?:http://)(.*)$%i', '$1', $wpurl); $isWP39 = version_compare($wp_version, '3.9.dev', '>') > 0 ? 'true' : 'false'; $editURL = "{$wpurl}/wp-admin/edit.php"; $data->pluginversion = EasyRecipePlus::$pluginVersion; $license = $this->licenseKey; /** * Figure out what we need to display on the Fooderific tab * * If we had MBRB enabled but this is the first run, show the welcome (firstRun = true) and hide the "retrieving" splash * Otherwise, show the "retrieving" splash */ $data->fdFirstRun = false; $data->fdNotEnabled = false; $fdAPIKey = $this->fooderificAPIKey; if (!$this->enableFooderific) { $data->fdNotEnabled = true; $data->retrieveclass = 'FDDisplayNone'; $lastScan = 0; } else { if ($this->lastScanStarted == 0) { $data->fdFirstRun = true; $data->retrieveclass = 'FDDisplayNone'; $lastScan = 0; } else { $data->retrieveclass = ''; $tzOffet = get_option('gmt_offset'); $lastScan = date_i18n("j M y g:ia", $this->lastScanStarted + $tzOffet * 3600); } } $pluginVersion = EasyRecipePlus::$pluginVersion; $data->javascript = <<<EOD <script type="text/javascript"> //<![CDATA[ window.EASYRECIPE = window.EASYRECIPE || {}; EASYRECIPE.settingsName = 'EasyRecipePlus'; EASYRECIPE.editURL = '{$editURL}'; EASYRECIPE.pluginVersion = '{$pluginVersion}'; EASYRECIPE.wpurl = '{$wpurl}'; EASYRECIPE.slug = 'easyrecipeplus'; EASYRECIPE.license = '{$license}'; EASYRECIPE.lastScan = '{$lastScan}'; EASYRECIPE.fdAPIKey = '{$fdAPIKey}'; EASYRECIPE.isWP39 = {$isWP39}; //]]> </script> EOD; /** * If the site isn't using permalinks then just pass the print stuff as a qurerystring param */ $data->siteDiagnosticsURL = home_url(); if (!$wp_rewrite->using_permalinks()) { $data->siteDiagnosticsURL .= "?"; } $data->useFeaturedImageChecked = $this->useFeaturedImage ? 'checked="checked"' : ''; $data->displayPrintChecked = $this->displayPrint ? 'checked="checked"' : ''; $data->filterExcerptsChecked = $this->filterExcerpts ? 'checked="checked"' : ''; $data->displayZiplistChecked = $this->displayZiplist ? 'checked="checked"' : ''; $data->displayRecipeCardChecked = $this->displayRecipeCard ? 'checked="checked"' : ''; $data->displayRecipageChecked = $this->displayRecipage ? 'checked="checked"' : ''; $data->displayGMCChecked = $this->displayGMC ? 'checked="checked"' : ''; $data->displayUltimateRecipeChecked = $this->displayUltimateRecipe ? 'checked="checked"' : ''; $data->allowLinkChecked = $this->allowLink ? 'checked="checked"' : ''; $data->convertFractionsChecked = $this->convertFractions ? 'checked="checked"' : ''; $data->removeMFChecked = $this->removeMicroformat ? 'checked="checked"' : ''; $data->fdLinkChecked = $this->enableFooderific ? 'checked="checked"' : ''; $data->enableSwoopChecked = $this->enableSwoop ? 'checked="checked"' : ''; $data->swoopclass = $this->enableSwoop ? '' : 'ERSNoSwoop'; $data->forcejQueryChecked = $this->forcejQuery ? 'checked="checked"' : ''; $data->noHTMLWarnChecked = $this->noHTMLWarn ? 'checked="checked"' : ''; $data->genesisGridChecked = $this->genesisGrid ? 'checked="checked"' : ''; $data->saveButtonBigOvenChecked = $data->saveButtonZiplistChecked = $data->saveButtonSaltyFigChecked = $data->saveButtonNoneChecked = ''; $data->ziplistclass = $data->saltyfigclass = "ERSDisplayNone"; /** * Only show the Ziplist stuff if we are already using it and then only so it can be unselected */ $data->showZiplist = false; switch ($data->saveButton) { case 'BigOven': $data->saveButtonBigOvenChecked = 'checked="checked"'; break; case 'Ziplist': $data->saveButtonZiplistChecked = 'checked="checked"'; $data->ziplistclass = ''; $data->showZiplist = true; break; case 'SaltyFig': $data->saveButtonSaltyFigChecked = 'checked="checked"'; $data->saltyfigclass = ''; break; default: $data->saveButtonNoneChecked = 'checked="checked"'; break; } $data->ratingEasyRecipeChecked = $data->ratingSelfRatedChecked = $data->ratingDisabledChecked = ''; $ratingChecked = "rating" . $this->ratings . "Checked"; $data->{$ratingChecked} = 'checked="checked"'; $data->erSubscribeChecked = $this->erSubscribe ? 'checked="checked"' : ''; $data->subscribeclass = $this->erSubscribe ? '' : 'ERSNoSubscribe'; /* * Set up Swoop stuff */ if ($data->swoopSiteID != '') { $data->registerswoop = 'ERSDisplayNone'; $data->loginswoop = ''; } else { $data->registerswoop = ''; $data->loginswoop = 'ERSDisplayNone'; } /* * Set up the register data even if we're already registered in case we remove the current ID */ $swoopData = new stdClass(); $swoopData->email = get_bloginfo("admin_email"); $swoopData->blog_url = get_bloginfo("wpurl"); $swoopData->blog_title = get_bloginfo("description"); $swoopData->rss_url = get_bloginfo("rss_url"); $swoopData->tz = get_option('timezone_string'); /** @noinspection PhpParamsInspection */ $data->swoopqs = http_build_query($swoopData); $data->easyrecipeURL = EasyRecipePlus::$EasyRecipePlusUrl; $data->siteurl = get_site_url(); $data->erplus = 'Plus'; $data->isPlus = true; $data->author = $this->author; $data->cuisines = str_replace('|', "\n", $this->cuisines); $data->recipeTypes = str_replace('|', "\n", $this->recipeTypes); $data->plus = "EasyRecipePlus" == "easyrecipeplus" ? "Plus" : ""; $data->pluginName = "EasyRecipePlus"; $optionsHTML = "<input type='hidden' name='option_page' value='EROptionSettings' />"; $optionsHTML .= '<input type="hidden" name="action" value="update" />'; $optionsHTML .= wp_nonce_field("EROptionSettings-options", '_wpnonce', true, false); $optionsHTML .= wp_referer_field(false); $styles = EasyRecipePlusStyles::getStyles($this->customTemplates); // $styles = call_user_func(array ($this->stylesClass, 'getStyles'), $this->settings['customTemplates']); $data->styleDirectory = $this->style; $styleNum = 0; $styleTab = 1; $styleItem = false; $data->STYLETABS = array(); foreach ($styles as $style) { if ($styleNum % 3 == 0) { if ($styleItem !== false) { /** @noinspection PhpUndefinedFieldInspection */ $styleItem->styleTab = $styleTab++; $data->STYLETABS[] = $styleItem; } $styleItem = new stdClass(); $styleItem->STYLES = array(); } $style->selected = $data->style == $style->directory ? 'ERSStyleSelected' : ''; $styleItem->STYLES[] = $style; $styleNum++; } if ($styleItem) { $styleItem->styleTab = $styleTab; $data->STYLETABS[] = $styleItem; } $styles = EasyRecipePlusStyles::getStyles($this->customTemplates, EasyRecipePlusStyles::ISPRINT); //$styles = call_user_func(array ($this->stylesClass, 'getStyles'), $this->settings['customTemplates'], constant("$this->stylesClass::ISPRINT")); $data->printStyleDirectory = $this->printStyle; $styleNum = 0; $styleTab = 1; $styleItem = false; $data->PRINTSTYLETABS = array(); foreach ($styles as $style) { if ($styleNum % 3 == 0) { if ($styleItem !== false) { /** @noinspection PhpUndefinedFieldInspection */ $styleItem->styleTab = $styleTab++; $data->PRINTSTYLETABS[] = $styleItem; } $styleItem = new stdClass(); $styleItem->PRINTSTYLES = array(); } $style->selected = $data->printStyle == $style->directory ? 'ERSStyleSelected' : ''; $styleItem->PRINTSTYLES[] = $style; $styleNum++; } if ($styleItem) { $styleItem->styleTab = $styleTab; $data->PRINTSTYLETABS[] = $styleItem; } $data->optionsHTML = $optionsHTML; $data->customTemplates = $this->customTemplates; /** * The Guest Post template is separate simply because it's somewhat complex * and it's much easier to handle it in Dreamweaver separately */ $gpData = new stdClass(); $gpData->settingsname = "EasyRecipePlus"; $gpData->gpHideFooterChecked = $this->gpHideFooter ? 'checked="checked"' : ''; $gpData->gpCopyDetailsChecked = $this->gpCopyDetails ? 'checked="checked"' : ''; $gpData->lblGPName = $this->lblGPName; $gpData->lblGPEmail = $this->lblGPEmail; $gpData->lblGPWebsite = $this->lblGPWebsite; $gpData->lblGPContinue = $this->lblGPContinue; $gpData->lblGPPostTitle = $this->lblGPPostTitle; $gpData->lblGPHint = $this->lblGPHint; $gpData->lblGPMessage = $this->lblGPMessage; $gpData->lblGPSubmitPost = $this->lblGPSubmitPost; /** * Get users so we can select one for the nominal guest poster - restricted to non-subscribers * It seems some blogs have tens of thousands of spam subscribers and reading them all will crash WP (and make a drop down select useless obviously!) * Since there's no reliable, clean standard way of getting users who *don't* have some specific role, we have to do it ourselves * TODO - probably should check the number of non-subscribers too before we commit to reading them all * There is no efficient way to select by user role - we have to use a LIKE */ $q = "SELECT ID, user_login FROM {$wpdb->users} JOIN {$wpdb->usermeta} ON ID = user_id WHERE meta_key = 'wp_capabilities' AND meta_value NOT LIKE '%subscriber%'"; $users = $wpdb->get_results($q); // $users = get_users(); $pages = get_pages(array('post_status' => 'publish,draft,private')); $gpData->GPUSERS = array(); $item = new stdClass(); $item->userid = 0; $item->username = '******'; $gpData->GPUSERS[] = $item; foreach ($users as $user) { $item = new stdClass(); $item->userid = $user->ID; $item->username = $user->user_login; $item->selected = $user->ID == $this->gpUserID ? 'selected="selected"' : ''; $gpData->GPUSERS[] = $item; } $gpData->GPDETAILSPAGE = array(); $gpData->GPENTRYPAGE = array(); $gpData->GPTHANKSPAGE = array(); $item = new stdClass(); $item->pageid = 0; $item->pagename = 'Please select...'; $gpData->GPDETAILSPAGE[] = $item; $gpData->GPENTRYPAGE[] = $item; $gpData->GPTHANKSPAGE[] = $item; foreach ($pages as $page) { $item = new stdClass(); $item->pageid = $page->ID; $item->pagename = $page->post_title; $item->selected = $page->ID == $this->gpDetailsPage ? 'selected="selected"' : ''; $gpData->GPDETAILSPAGE[] = $item; $item = clone $item; $item->selected = $page->ID == $this->gpEntryPage ? 'selected="selected"' : ''; $gpData->GPENTRYPAGE[] = $item; $item = clone $item; $item->selected = $page->ID == $this->gpThanksPage ? 'selected="selected"' : ''; $gpData->GPTHANKSPAGE[] = $item; } $gpData->easyrecipeURL = EasyRecipePlus::$EasyRecipePlusUrl; $gpTemplate = new EasyRecipePlusTemplate(EasyRecipePlus::$EasyRecipePlusDir . "/templates/easyrecipe-guestpostsettings.html"); $data->guestpostsettings = $gpTemplate->replace($gpData); //$data->guestpostsettings="XXX"; /* * We need to preserve whitespace on this template because newlines in the the textareas are significant */ $template = new EasyRecipePlusTemplate(EasyRecipePlus::$EasyRecipePlusDir . "/templates/easyrecipe-settings.html"); $html = $template->replace($data, EasyRecipePlusTemplate::PRESERVEWHITESPACE); echo $html; }
/** * Returns an array of all the styles we know about * * @param string $customTemplates * The directory where custom styles are stored. This will be an emprty string if there are no custom styles * @param boolean $isPrint * Return print styles if TRUE * @return array An array of style data */ public static function getStyles($customTemplates, $isPrint = false) { $names = array(); $styles = array(); /* * Do we need to create the styles data? */ if (!$isPrint && !isset(self::$styles) || $isPrint && !isset(self::$printStyles)) { /* * Do we need to get custom templates? */ if ($customTemplates != '') { $directory = $isPrint ? "{$customTemplates}/printstyles" : "{$customTemplates}/styles"; $names = self::getStyleNames($directory, 1); } $directory = EasyRecipePlus::$EasyRecipePlusDir; $directory = $isPrint ? "{$directory}/printstyles" : "{$directory}/styles"; $names = array_merge($names, self::getStyleNames($directory)); sort($names); foreach ($names as $name) { $style = self::getStyleData($name, $customTemplates, $isPrint); $styles[] = $style; } } if ($isPrint) { self::$printStyles = $styles; } else { self::$styles = $styles; } return $isPrint ? self::$printStyles : self::$styles; }
/** * @param $styleData * @param bool $isPrint * @return string */ function getFormatDialog($styleData, $isPrint = false) { $data = new stdClass(); $data->SECTIONS = array(); $id = 0; /** * Get the formatting data for each formattable element * Add more specificity to each target in an attempt to override any specific theme CSS */ $formats = @json_decode($styleData->formatting); if ($formats) { foreach ($formats as $format) { $item = new stdClass(); if (stripos($format->target, ".easyrecipe") === 0) { $format->target = "html body div" . $format->target; } else { if (stripos($format->target, "div.easyrecipe") === 0) { $format->target = "html body " . $format->target; } else { if (stripos($format->target, "html body") === false) { $format->target = "html body " . $format->target; } } } $item->section = $format->section; $format->id = $item->id = $id++; $data->SECTIONS[] = $item; } } /** * Get all the styles we have */ $styles = EasyRecipePlusStyles::getStyles($this->settings->customTemplates, $isPrint); $data->STYLES = array(); $styleThumbs = array(); foreach ($styles as $style) { $item = new stdClass(); $item->directory = $style->directory; $item->selected = $item->directory == $this->styleName ? 'selected="selected"' : ''; $item->style = $style->style; $styleThumbs[$style->directory] = $style->thumbnail; $data->STYLES[] = $item; } $data->stylethumb = $styleData->thumbnail; $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-format.html"); $html = $template->replace($data); $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-fontchange.html"); $fontChangeHTML = $template->replace($data); $fontChangeHTML = str_replace("\r", "", $fontChangeHTML); $fontChangeHTML = str_replace("\n", " ", $fontChangeHTML); $fontChangeHTML = str_replace("'", '\\0x27', $fontChangeHTML); $fontChangeHTML = trim(preg_replace('/> \\s+</i', '> <', $fontChangeHTML)); $ajaxURL = admin_url('admin-ajax.php'); $cssType = $isPrint ? 'customPrintCSS' : 'customCSS'; /** * Fix extra slashes that may be hanging around from earlier versions * Then escape single quotes with a slash */ $customCSS = str_replace("'", "\\'", stripslashes_deep($this->settings->{$cssType})); if ($customCSS == '') { $customCSS = '{}'; } $formats = json_encode($formats); $formats = str_replace("'", '\'', $formats); if ($isPrint) { $minHeight = 550; $print = 'true'; } else { $minHeight = 638; $print = 'false'; } $thumbs = json_encode($styleThumbs); $url = self::$EasyRecipePlusUrl; $pluginVersion = self::$pluginVersion; $html .= <<<EOD <script type="text/javascript"> /* <![CDATA[ */ window.EASYRECIPE = window.EASYRECIPE || {}; EASYRECIPE.isPrint = {$print}; EASYRECIPE.minHeight = {$minHeight}; EASYRECIPE.formatting = '{$formats}'; EASYRECIPE.customCSS = '{$customCSS}'; EASYRECIPE.easyrecipeURL = '{$url}'; EASYRECIPE.wpVersion = '{$this->wpVersion}'; EASYRECIPE.version = '{$pluginVersion}'; EASYRECIPE.ajaxURL = '{$ajaxURL}'; EASYRECIPE.styleThumbs = '{$thumbs}'; EASYRECIPE.fontChangeHTML = '{$fontChangeHTML}'; /* ]]> */ </script> EOD; return $html; }