public function showPage() { /* @var $wp_rewrite WP_Rewrite */ global $wp_rewrite; global $wp_version; if (isset($_POST['action']) && $_POST['action'] == 'save') { $this->save($_POST["EasyRecipe"]); } $data = new stdClass(); foreach (self::$defaultSettings as $setting => $default) { $data->{$setting} = isset($this->{$setting}) ? $this->{$setting} : $default; } $data->settingsname = 'EasyRecipe'; $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 = EasyRecipe::$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 = EasyRecipe::$pluginVersion; $data->javascript = <<<EOD <script type="text/javascript"> //<![CDATA[ window.EASYRECIPE = window.EASYRECIPE || {}; EASYRECIPE.settingsName = 'EasyRecipe'; EASYRECIPE.editURL = '{$editURL}'; EASYRECIPE.pluginVersion = '{$pluginVersion}'; EASYRECIPE.wpurl = '{$wpurl}'; 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->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->saveButtonZiplistChecked = $data->saveButtonSaltyFigChecked = $data->saveButtonNoneChecked = ''; $data->ziplistclass = $data->saltyfigclass = "ERSDisplayNone"; switch ($data->saveButton) { case 'Ziplist': $data->saveButtonZiplistChecked = 'checked="checked"'; $data->ziplistclass = ''; 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 = EasyRecipe::$EasyRecipeURL; $data->siteurl = get_site_url(); $data->erplus = ''; $data->author = $this->author; $data->cuisines = str_replace('|', "\n", $this->cuisines); $data->recipeTypes = str_replace('|', "\n", $this->recipeTypes); $data->plus = "EasyRecipe" == "easyrecipeplus" ? "Plus" : ""; $data->pluginName = "EasyRecipe"; $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 = EasyRecipeStyles::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 = EasyRecipeStyles::getStyles($this->customTemplates, EasyRecipeStyles::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; /* * We need to preserve whitespace on this template because newlines in the the textareas are significant */ $template = new EasyRecipeTemplate(EasyRecipe::$EasyRecipeDir . "/templates/easyrecipe-settings.html"); $html = $template->replace($data, EasyRecipeTemplate::PRESERVEWHITESPACE); echo $html; $data = new stdClass(); $data->easyrecipeURL = EasyRecipe::$EasyRecipeURL; $template = new EasyRecipeTemplate(EasyRecipe::$EasyRecipeDir . "/templates/easyrecipe-upgrade.html"); echo $template->replace($data); }
/** * 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)) { $directory = EasyRecipe::$EasyRecipeDir; $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; }
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); $postDOM = new EasyRecipeDocument($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 EasyRecipeDocument($post->post_content); if (!$postDOM->isEasyRecipe) { return; } } $this->settings = EasyRecipeSettings::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 = EasyRecipeStyles::getStyleData($this->styleName, $this->settings->customTemplates, true); if (get_locale() != 'en_US') { EasyRecipeTemplate::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::$EasyRecipeURL; $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] == '_') { } else { $data->css = self::$EasyRecipeURL . "/printstyles/{$data->style}"; $templateFile = self::$EasyRecipeDir . "/printstyles/{$data->style}/style.html"; } $data->css .= "/style.css?version=" . self::$pluginVersion . ".{$this->printStyleData->version}"; $template = new EasyRecipeTemplate($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; }