Exemplo n.º 1
0
function atom_open()
{
    global $config, $javascript_msg;
    // Create Auth Object
    if ($config['plugins'][$_SESSION['plugin']]['type'] == 'blogger') {
        require_once dirname(__FILE__) . '/class.basicauth.php';
        $auth = new BasicAuth($config['plugins'][$_SESSION['plugin']]['username'], $config['plugins'][$_SESSION['plugin']]['password']);
    } else {
        require_once dirname(__FILE__) . '/class.wsse.php';
        $auth = new WSSE($config['plugins'][$_SESSION['plugin']]['username'], $config['plugins'][$_SESSION['plugin']]['password']);
    }
    // Break down the identifier details into its parts
    $at = strpos($_SESSION['plugin_identifier'], '@');
    $entry_uri = substr($_SESSION['plugin_identifier'], 1, $at - 1);
    $feed_uri = substr($_SESSION['plugin_identifier'], $at + 1, -1);
    // Get the feed as specified
    $ar = new AtomRequest('GET', urldecode($entry_uri), $auth);
    $response = $ar->exec();
    if ($response == 200) {
        $entry = new AtomEntry();
        $entry->from_xml($ar->get_response());
        // Pull out the existing title and content from this object
        $title = $entry->get_title('title');
        $content = $entry->get_content('content');
        // Strip out the default namespace tags
        $content = preg_replace(array('/^\\s*<div xmlns="http:\\/\\/www.w3.org\\/1999\\/xhtml">/s', '/<\\/div>\\s*$/s'), '', trim($content));
        return html_entity_decode($title) . "\n" . trim($content);
    } else {
        $javascript_msg = '@Couldn\'t open your blog post.';
        return false;
    }
}