/** * @param bool $isPrint * * @return string */ function getFormatDialog($isPrint = false) { $data = new stdClass(); $data->SECTIONS = array(); $id = 0; $styleData = $isPrint ? $this->printStyleData : $this->styleData; /** * 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); $print = $isPrint ? 'true' : '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.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; /* * Display formatting JS is handled by enqueue scripts * The print page exits before enqueues get output so add the script manually now */ if ($isPrint && current_user_can("edit_theme_options")) { $html .= sprintf('<script type="text/javascript" src="%s/js/easyrecipe-format.js?version=%s"></script>', self::$EasyRecipePlusUrl, self::$pluginVersion); } return $html; }
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; }