function testStructuredBloggingParsing() { // make sure we can correctly parse SB XML $mic = new SBMicroContent(); $mic->set_mc_type("review/localservice"); $this->assertContains('/review/subject/location/@country', $mic->get_mc_editor()); // make sure all MCD files contain a title field foreach (glob(SB_MC_LOCATION . '/*.xml') as $mcd_fn) { $dom = new DOMDocument(); $this->assertTrue($dom->load($mcd_fn), "failed to load {$mcd_fn} into a DOM object - bad xml?"); // make sure it's valid xml $xp = new DOMXPath($dom); $mc_type = $xp->query("/micro-content/@type")->item(0)->nodeValue; $mc_type_guess = str_replace("-", "/", basename($mcd_fn, ".xml")); if (strpos($mc_type_guess, "/") === FALSE) { $mc_type_guess .= "/generic"; } $nodes = $xp->query("/micro-content/display[@media='meta/title']"); $this->assertEquals(1, $nodes->length, "{$mcd_fn} is missing a <display media=\"meta/title\"> element"); foreach ($xp->query("field/@content", $nodes->item(0)) as $field) { // echo " field: $field->nodeValue\n"; } // echo "guessed mc type: $mc_type_guess; parsed mc type: $mc_type; title field: $title_field\n"; $this->assertEquals($mc_type, $mc_type_guess, "microcontent types (real={$mc_type}, guess={$mc_type_guess}) do not agree"); } }
function getContent() { global $current_theme_path, $base_url; $mc = new SBMicroContent(); $mc->set_mc_type($this->sb_mc_type); $edit = $instance = null; // if we've clicked an 'edit' button, parse the existing // structured content and pre-fill the form. note that we don't // do this on POST, as in that case all the data we want is in // $_POST. if ($this->content_id && $_SERVER['REQUEST_METHOD'] == "GET") { $mc->load($this->content_id); $body = $mc->body; $edit = "edit"; $instance = $mc->parse_structured_content($body); } $editor = $mc->get_mc_editor($edit, $instance); return $editor; }
function getContent() { $mc = new SBMicroContent(); $mc->set_mc_type($this->sb_mc_type); $edit = $instance = null; // if we've clicked an 'edit' button, parse the existing // structured content and pre-fill the form. note that we don't // do this on POST, as in that case all the data we want is in // $_POST. if ($this->content_id && $_SERVER['REQUEST_METHOD'] == "GET") { $mc->load($this->content_id); $body = $mc->body; $edit = "edit"; $instance = $mc->parse_structured_content($body); if (!$instance) { throw new PAException(GENERAL_SOME_ERROR, "Failed to parse structured blogging content in content id {$this->content_id}"); } } $editor = $mc->get_mc_editor($edit, $instance); return $editor; }