Example #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;
        }
    }
}
Example #2
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;
     }
 }