/** * Insert the easyrecipe dialogs and template HTML at the end of the * page - they're display:none by default */ function addDialogHTML() { global $post; if (!$this->isGuest && !isset($post)) { return; } $data = new stdClass(); $data->isSelfRated = $this->settings->ratings == 'SelfRated'; $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-entry.html"); echo $template->replace($data); $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-select.html"); echo $template->replace(); $data = new stdClass(); $data->easyrecipeURL = self::$EasyRecipePlusUrl; $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-convert.html"); echo $template->replace($data); $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-htmlwarning.html"); echo $template->getTemplateHTML(); /** * Get the basic data template * We need to preserve comments here because the template is processed by the javascript template engine and it needs the INCLUDEIF/REPEATS */ $template = new EasyRecipePlusTemplate(self::$EasyRecipePlusDir . "/templates/easyrecipe-template.html"); $html = $template->getTemplateHTML(EasyRecipePlusTemplate::PRESERVECOMMENTS); $html = preg_replace('/\\n */', ' ', $html); $html = trim(str_replace("'", "\"", $html)); /* * Unless this is a guest post, get the URL we can test at Google (as long as it's published) */ if (!$this->isGuest) { $testURL = $post->post_status == 'publish' ? urlencode(get_permalink($post->ID)) : ''; } else { $testURL = ''; } if ($this->isGuest) { /** @var $guestAuthor WP_User */ $guestAuthor = get_user_by('id', $this->settings->gpUserID); /** @noinspection PhpUndefinedFieldInspection */ $author = str_replace("'", '\\x27', json_encode(str_replace('"', '\\"', $guestAuthor->data->display_name))); } else { $author = str_replace("'", '\\x27', json_encode(str_replace('"', '\\"', $this->settings->author))); } $cuisines = str_replace("'", '\\x27', json_encode(explode('|', str_replace('"', '\\"', $this->settings->cuisines)))); $recipeTypes = str_replace("'", '\\x27', json_encode(explode('|', str_replace('"', '\\"', $this->settings->recipeTypes)))); $ingredients = str_replace("'", '\\x27', json_encode(str_replace('"', '\\"', $this->settings->lblIngredients))); $instructions = str_replace("'", '\\x27', json_encode(str_replace('"', '\\"', $this->settings->lblInstructions))); $notes = str_replace("'", '\\x27', json_encode(str_replace('"', '\\"', $this->settings->lblNotes))); if (!function_exists('get_upload_iframe_src')) { require_once ABSPATH . 'wp-admin/includes/media.php'; } // $upIframeSrc = get_upload_iframe_src(); $guestPost = $this->isGuest ? 'true' : 'false'; $noWarn = $this->settings->noHTMLWarn ? 'true' : 'false'; $wpurl = get_bloginfo('wpurl'); $url = self::$EasyRecipePlusUrl; $pluginVersion = self::$pluginVersion; echo <<<EOD <script type="text/javascript"> /* <![CDATA[ */ window.EASYRECIPE = window.EASYRECIPE || {}; EASYRECIPE.ingredients ='{$ingredients}'; EASYRECIPE.instructions ='{$instructions}'; EASYRECIPE.notes ='{$notes}'; EASYRECIPE.version = '{$pluginVersion}'; EASYRECIPE.easyrecipeURL = '{$url}'; EASYRECIPE.recipeTemplate = '{$html}'; EASYRECIPE.testURL = '{$testURL}'; EASYRECIPE.author = '{$author}'; EASYRECIPE.recipeTypes = '{$recipeTypes}'; EASYRECIPE.cuisines = '{$cuisines}'; EASYRECIPE.isGuest = {$guestPost}; EASYRECIPE.wpurl = '{$wpurl}'; EASYRECIPE.wpVersion = '{$this->wpVersion}'; EASYRECIPE.postID = {$post->ID}; EASYRECIPE.noHTMLWarn = {$noWarn}; /* ]]> */ </script> EOD; }
function guestPostEntry() { $this->plugin->isGuest = true; add_filter('tiny_mce_before_init', array($this->plugin, 'mcePreInitialise')); add_filter('mce_external_plugins', array($this->plugin, 'mcePlugins')); add_filter('mce_buttons', array($this->plugin, 'mceButtons')); $data = new stdClass(); $nonce = isset($_POST['nonce']) ? $_POST['nonce'] : ''; $postData = isset($_POST['ERGuestPost']) ? $_POST['ERGuestPost'] : ''; if (!wp_verify_nonce($nonce, 'guestpostdetails') || $postData == '' || !isset($postData['egpname']) || !isset($postData['egpemail']) || !isset($postData['egpurl'])) { wp_redirect(get_permalink($this->settings->gpDetailsPage)); exit; } $postData = $_POST['ERGuestPost']; $data->name = $postData['egpname']; $data->email = $postData['egpemail']; $data->url = $postData['egpurl']; // add_filter('tiny_mce_before_init', array($this, 'mcePreInitialise')); // add_filter('mce_external_plugins', array($this, 'mcePlugins')); // add_filter('mce_buttons', array($this, 'mceButtons')); ob_flush(); // fixme - check to see if there IS a buffer ob_start(); wp_editor('', 'guestpost'); $data->editor = ob_get_clean(); $data->postID = 0; $data->gpHideFooter = $this->settings->gpHideFooter; $data->lblGPPostTitle = $this->settings->lblGPPostTitle; $data->lblGPHint = $this->settings->lblGPHint; $data->lblGPMessage = $this->settings->lblGPMessage; $data->lblGPSubmitPost = $this->settings->lblGPSubmitPost; $data->nonce = wp_create_nonce('guestpostentry'); $data->next = $data->next = get_permalink($this->settings->gpThanksPage); $template = new EasyRecipePlusTemplate(EasyRecipePlus::$EasyRecipePlusDir . "/templates/easyrecipe-upload.html"); $data->uploadDialog = $template->getTemplateHTML(); $template = new EasyRecipePlusTemplate(EasyRecipePlus::$EasyRecipePlusDir . "/templates/easyrecipe-links.html"); $data->linksDialog = $template->getTemplateHTML(); $template = new EasyRecipePlusTemplate(EasyRecipePlus::$EasyRecipePlusDir . "/templates/easyrecipe-guestpost.html"); return $template->replace($data); }