/** * @return String * @param String $str * @param String $username * @param String $password * @param String $host * @param String $path * @param String $type * @desc Saves the string passed in according to the details in the session. */ function mt_save($str, $user, $pass, $host, $path, $type) { global $javascript_msg; // Split up the post to get the title and content separately $div = strpos($str, "\n"); $title = trim(substr($str, 0, $div)); $content = substr($str, $div + 1); // Construct the new post and update session details $the_post = '<title>' . $title . "</title>\n" . $content; $_SESSION['filename'] = $title; $_SESSION['display_filename'] = $title; // Break down the identifier details into its parts if (preg_match('/^\\[[^@]*@[^\\]]*\\]$/Ui', $_SESSION['plugin_identifier'])) { $at = strpos($_SESSION['plugin_identifier'], '@'); $entry_id = urldecode(substr($_SESSION['plugin_identifier'], 1, $at - 1)); if (trim($entry_id) == '') { $entry_id = false; } $feed_id = urldecode(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 ($type == 'livejournal') { $mt = new bloggerclient($user, $pass, $host, $path); } else { $mt = new mtclient($user, $pass, $host, $path); } // Updating an existing post (editPost) if ($entry_id !== false) { if ($type == 'livejournal') { $done = $mt->editPost($entry_id, $the_post, true); } else { $done = $mt->editPost($entry_id, $content, $title, true); } if ($done) { $javascript_msg = 'Entry updated successfully.'; } else { $javascript_msg = '@Couldn\'t update your entry.'; } return $_SESSION['filename']; } else { if ($type == 'livejournal') { $done = $mt->newPost($feed_id, $the_post, true); } else { $done = $mt->newPost($feed_id, $content, $title, true); } if ($done) { $_SESSION['plugin_identifier'] = '[' . urlencode($done) . '@' . urlencode($feed_id) . ']'; $javascript_msg = 'New entry posted successfully.'; } else { $javascript_msg = '@Couldn\'t post your entry to your blog.'; } return $_SESSION['filename']; } }