Ejemplo n.º 1
0
function atom_save($document)
{
    global $config, $javascript_msg;
    // Split up the post to get the title and content separately
    $div = strpos($document, "\n");
    $title = trim(substr($document, 0, $div));
    $content = substr($document, $div + 1);
    // Prep these elements for use in the Atom objects later
    $title = array('title' => htmlspecialchars($title), 'mode' => 'escaped', 'type' => 'text/html');
    $content = array('content' => htmlspecialchars($content), 'mode' => 'escaped', 'type' => 'text/html');
    // 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
    if (preg_match('/^\\[(https?)?.*@https?.*\\]$/Ui', $_SESSION['plugin_identifier'])) {
        $at = strpos($_SESSION['plugin_identifier'], '@');
        $entry_uri = substr($_SESSION['plugin_identifier'], 1, $at - 1);
        if (trim($entry_uri) == '') {
            $entry_uri = false;
        }
        $feed_uri = substr($_SESSION['plugin_identifier'], $at + 1, -1);
    } else {
        // Couldn't figure out where to save to
        $javascript_msg = '@Couldn\'t locate the blog to save this post to.';
        return $_SESSION['filename'];
    }
    // If we're updating an existing one, we need some details
    if ($entry_uri !== false) {
        // Create the new entry and get it as XML
        $ae = new AtomEntry($title, $content);
        $ae = $ae->to_xml('PUT');
        $ar = new AtomRequest('PUT', urldecode($entry_uri), $auth, $ae);
        $response = $ar->exec();
        if ($response == 200) {
            $javascript_msg = 'Post saved successfully.';
            return;
        } else {
            $javascript_msg = '@Saving your post failed, please try again. (' . $ar->get_response() . ')';
            return;
        }
    } else {
        // Make the entry, and get it in XML (for POSTing)
        $ae = new AtomEntry($title, $content);
        $ae = $ae->to_xml('POST');
        $ar = new AtomRequest('POST', urldecode($feed_uri), $auth, $ae);
        $response = $ar->exec();
        if ($response == 200 || $response == 201) {
            // Need to get the EditURI for this new post now
            $ae = new AtomEntry();
            $ae->from_xml($ar->get_response());
            $link = $ae->get_links('rel', 'service.edit');
            $javascript_msg = 'Post saved successfully.';
            $_SESSION['plugin_identifier'] = '[' . urlencode($link[0]['href']) . '@' . $feed_uri . ']';
            return;
        } else {
            $javascript_msg = '@Saving your post failed, please try again. (' . $ar->get_response() . ')';
            return;
        }
    }
}
Ejemplo n.º 2
0
<body onkeypress="if (event.keyCode==27) { window.close(); }">
<?php 
echo '<a href="../../locations/browse_plugin.php?t=' . $config['plugins'][$_REQUEST['p']]['type'] . '&p=' . $_REQUEST['p'] . '" title="Back to Blog List"><img src="../../images/files_up.gif" width="19" height="18" alt="" border="0" align="absmiddle" />�Back to Blog List</a>' . "\n";
// Create Auth Object
if ($config['plugins'][$_REQUEST['p']]['type'] == 'blogger') {
    require_once dirname(__FILE__) . '/class.basicauth.php';
    $auth = new BasicAuth($config['plugins'][$_REQUEST['p']]['username'], $config['plugins'][$_REQUEST['p']]['password']);
} else {
    require_once dirname(__FILE__) . '/class.wsse.php';
    $auth = new WSSE($config['plugins'][$_REQUEST['p']]['username'], $config['plugins'][$_REQUEST['p']]['password']);
}
// Handle request to delete an entry before we load them all
if (isset($_POST['delete_entry']) && strlen($_POST['delete_entry'])) {
    $del = $_POST['delete_entry'];
    $dr = new AtomRequest('DELETE', $del, $auth);
    $dr->exec();
    $code = $dr->get_httpcode();
    if ($code != 200 && $code != 204) {
        echo "<script language=\"JavaScript\" type=\"text/javascript\">\n";
        echo "<!--\n";
        echo "alert('Can\\'t delete that post - you might not have permission to do so.');\n";
        echo "// -->\n";
        echo "</script>\n";
    }
}
$af = new AtomFeed(urldecode($_REQUEST['f']), $auth);
$entries = $af->get_entries();
if (is_array($entries)) {
    foreach ($entries as $e => $entry) {
        $link = $entry->get_links('rel', 'service.edit');
Ejemplo n.º 3
0
 /**
  * @return TRUE/Int on error
  * @desc Initiates the AtomFeed object from a URI by loading the data, then parsing it as XML. Returns an HTTP response code on error, or TRUE if successful.
  */
 function init()
 {
     $ar = new AtomRequest('GET', $this->get_endpoint(), $this->get_auth());
     $code = $ar->exec();
     // Successfully retrieved feed, now process it out
     if ($code == 200) {
         $this->from_xml($ar->get_response());
         return true;
     } else {
         $this->err_no = ATOMAPI_FEED_INIT_FAILED;
         return $code;
     }
 }