/** * If there's an EasyRecipe in the content, load the HTML and pre-process, else just return * * @param $content * @param bool $load */ public function __construct($content, $load = true) { /** * If there's no EasyRecipe, just return */ if (!@preg_match(self::regexEasyRecipe, $content)) { return; } /** * Load the html - make sure we could parse it */ parent::__construct($content, $load); if (!$this->isValid()) { return; } /** * Find the easyrecipe(s) */ $this->easyrecipes = $this->getElementsByClassName('easyrecipe'); /** * Sanity check - make sure we could actually find at least one */ if (count($this->easyrecipes) == 0) { // echo "<!-- ER COUNT = 0 -->\n"; return; } /** * This is a valid easyrecipe post * Find a version number - the version will be the same for every recipe in a multi recipe post so just get the first */ $this->isEasyRecipe = true; /* @var $node DOMElement */ $node = $this->getElementByClassName("endeasyrecipe", "div", $this->easyrecipes[0], false); $this->recipeVersion = $node->nodeValue; /* * See if this post has already been formatted. * Wordpress replaces the parent post_content with the autosave post content (as already formatted by us) on a preview. * so we need to know if this post has already been formatted. This is a pretty icky way of doing it since it relies * on the style template having a specific title attribute on the endeasyrecipe div - need to make this more robust */ $this->isFormatted = $node !== null && $node->hasAttribute('title'); }