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; } } }