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");
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
function save_post($cid = NULL, $ccid = NULL, $is_album = FALSE, $display_on = 1)
{
    global $user, $network_info;
    $extra = unserialize($network_info->extra);
    $micro_content_post = new SBMicroContent();
    $micro_content_post->set_mc_type($_REQUEST['sb_mc_type']);
    $content = $micro_content_post->format_structured_content();
    $micro_content_post->body = $content;
    $micro_content_post->author_id = $_SESSION['user']['id'];
    $micro_content_post->allow_comments = 1;
    $micro_content_post->trackbacks = $_REQUEST['trackback'];
    $micro_content_post->is_active = 1;
    if ($cid) {
        $micro_content_post->content_id = $cid;
        $condition = array('content_id' => $cid);
        $is_active = ACTIVE;
        if ($extra['network_content_moderation'] == NET_YES) {
            $content = Content::load_all_content_for_moderation(NULL, $condition);
            if (!empty($content)) {
                $is_active = $content[0]['is_active'];
            }
        }
        $micro_content_post->is_active = $is_active;
    }
    if (!$ccid) {
        //independent post which is not part of any contentcollection
        $ccid = -1;
    }
    $micro_content_post->parent_collection_id = $ccid;
    $micro_content_post->display_on = $display_on;
    $sb_content = array();
    $sb_content = SBMicroContent::get_sbtype_id($_REQUEST['sb_mc_type'], $with_name = true);
    $micro_content_post->sbtype_id = $sb_content["sbtype_id"];
    $micro_content_post->title = $_POST[$sb_content["titlefield"]];
    //echo '<pre>';print_r($content);
    $micro_content_post->save();
    $return_array = array('title' => $_POST[$sb_content["titlefield"]], 'body' => $content, 'content_id' => $micro_content_post->content_id);
    if ($ccid != -1 && !$is_album) {
        // Code for checking groups with moderated content.
        //fix me change it for using ContentCollection::get_collection_type()
        $collection = ContentCollection::load_collection($micro_content_post->parent_collection_id, $micro_content_post->author_id);
        //$collection->assert_user_access($_SESSION['user']['id']);
        if ($collection->is_moderated) {
            $Group = new Group();
            $Group->collection_id = $micro_content_post->parent_collection_id;
            $Group->moderate_content($micro_content_post->content_id);
            $return_array['is_moderated'] = 1;
        }
    }
    $permalink_cid = $micro_content_post->content_id;
    $content_author_image = uihelper_resize_mk_user_img($user->picture, 80, 80, 'alt="' . $user->first_name . '" align="left" style="padding: 0px 12px 12px 0px;"');
    $params['cid'] = $permalink_cid;
    $params['first_name'] = $user->first_name;
    $params['user_id'] = $user->user_id;
    $params['user_image'] = $content_author_image;
    $params['content_title'] = $micro_content_post->title;
    $params['network_name'] = $network_info->name;
    auto_email_notification('content_posted', $params);
    if ($_POST['route_to_pa_home'] == 1) {
        auto_email_notification('content_posted_to_comm_blog', $params);
    }
    if ($extra['network_content_moderation'] == NET_YES && $network_info->owner_id != $user->user_id) {
        Network::moderate_network_content(-1, $permalink_cid);
        // -1 for contents; not a part of any collection
        $return_array['msg'] = 1004;
    }
    return $return_array;
}
 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;
 }