20 Jun
Along with the changed template you can see on this site, I also added a miniblog on the sidebar, using Ryan Poe’s Miniblog plugin, which he’s unfortunately abandoned, but none the less is still a good plugin. However I was having a problem with the RSS generator for it. The script was outputing the XML page, and then trying to output it again so I’d have the whole thing duplicated. I dug around in the code for a while but I couldn’t find what the heck was causing it, so I pulled the rss generation code out into a new file, and added RSS2.0 support (it was originally on 0.92). You can see the results by clicking on the RSS link next to the Short String heading on the sidebar, or alternatively just use this link. It allows for switching back to the 0.92 version of RSS by adding &v=0.92 to the end of the URL.
If anyone’s using the miniblog plugin and wants to use this, here be the code:
<?php
/*
Modifed RSS generation code for the Miniblog plugin writen by Ryan Poe (http://www.nmyworld.com/)
Modifications done by Glenn Slaven 2005-06-20
*/
$wordpress_dir = dirname(dirname(dirname(__FILE__)));
require_once($wordpress_dir . '/wp-config.php');
/* Get the blog name and description (stupid stupid WordPress making me do this) */
ob_start();
bloginfo('name');
$blog_name = ob_get_contents();
ob_end_clean();
ob_start();
bloginfo('description');
$blog_description = ob_get_contents();
ob_end_clean();
/* Return to sanity */
$number = $_GET['n'];
$offset = $_GET['o'];
$blog_term = htmlspecialchars(urldecode($_GET['q']));
$sort_by = htmlspecialchars(urldecode($_GET['s']));
$title = htmlspecialchars(urldecode($_GET['t']));
$description = htmlspecialchars(urldecode($_GET['d']));
/* Parse custom tags */
$title = str_replace('%site_name%', $blog_name, $title);
$description = str_replace('%site_name%', $blog_name, $description);
$title = str_replace('%site_description%', $blog_description, $title);
$description = str_replace('%site_description%', $blog_description, $description);
/* Clean the variables */
$varstoclean = array(&$number, &$offset, &$blog_term, &$sort_by, &$title, &$description);
foreach($varstoclean as $varname) {
$varname = miniblog_clean_var($varname);
}
/* Render the RSS */
header('Content-type: text/xml; charset=' . get_settings('blog_charset'), true);
echo "<?xml version=\"1.0\" encoding=\"" . get_settings('blog_charset') . "\"?>\n";
switch ($_GET['v']) {
case '0.92':
echo "<rss version=\"0.92\">\n";
echo "\t<channel>\n";
echo "\t\t<title>" . miniblog_clean_var($title) . "</title>\n";
echo "\t\t<link>";
bloginfo('url');
echo "</link>\n";
echo "\t\t<description>" . miniblog_clean_var($descriptions) . "</description>\n";
echo "\t\t<docs>http://backend.userland.com/rss092</docs>\n";
$entries = miniblog_return_entries($number, $offset, $blog_term, $sort_by, FALSE);
foreach($entries as $entry) {
echo "\t\t<item>\n";
echo "\t\t\t<title>" . miniblog_clean_var($entry->title) . "</title>\n";
echo "\t\t\t<description>" . miniblog_clean_var($entry->text) . "</description>\n";
echo "\t\t\t<link><![CDATA[" . miniblog_clean_var($entry->url) . "]]></link>\n";
echo "\t\t</item>\n";
}
echo "\t</channel>\n";
print "</rss>";
break;
default:
echo "<rss version=\"2.0\">\n";
echo "\t<channel>\n";
echo "\t\t<title>" . miniblog_clean_var($title) . "</title>\n";
echo "\t\t<link>";
bloginfo('url');
echo "</link>\n";
echo "\t\t<description>" . miniblog_clean_var($descriptions) . "</description>\n";
echo "\t\t<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
$entries = miniblog_return_entries($number, $offset, $blog_term, $sort_by, FALSE);
foreach($entries as $entry) {
echo "\t\t<item>\n";
echo "\t\t\t<title>" . miniblog_clean_var($entry->title) . "</title>\n";
echo "\t\t\t<description>" . miniblog_clean_var($entry->text) . "</description>\n";
echo "\t\t\t<pubDate>".mysql2date('D, d M Y H:i:s O', $entry->date, false)."</pubDate>\n";
echo "\t\t\t<link><![CDATA[" . miniblog_clean_var($entry->url) . "]]></link>\n";
echo "\t\t</item>\n";
}
echo "\t</channel>\n";
print "</rss>";
}
?>
Also, I wanted to be able to post from a bookmarklet, so I hacked the WP bookmarklet code, and it now works for the miniblog post page too. For it to work you need to add a few lines of code to the miniblog.php file in the plugins folder. At around line 135 (after if(!$post_blog) $post_blog = 'default';) add
/*Added to allow use as a bookmarklet */
if (!empty($_REQUEST['popuptitle'])) { $post_title = stripslashes(wp_specialchars($_REQUEST['popuptitle'])); }
if (!empty($_REQUEST['text'])) { $post_text = wp_specialchars($_REQUEST['text']); }
if (!empty($_REQUEST['popupurl'])) { $post_url = wp_specialchars($_REQUEST['popupurl']); }
/* END Added */
It puts in the title & url of the page you’re on into the form, and puts any selected text into the comment field. It doesn’t, however, do what the original popup does in puting an anchor tag in the comment field because it’s not needed with the url field.
The slightly adjusted link you’ll need for this bookmarklet is
javascript:if(navigator.userAgent.indexOf('Safari') >= 0){Q=getSelection();}else{Q=document.selection?document.selection.createRange().text:document.getSelection();}void(window.open('http://blog.slaven.net.au/wp-admin/post.php?page=miniblog.php&text='+escape(Q)+'&popupurl='+escape(location.href)+'&popuptitle='+escape(document.title),'WordPress bookmarklet','scrollbars=yes,width=1224,height=860,left=100,top=150,status=yes'));
Obviously, put your url in place of http://blog.slaven.net.au/. Also, I’ve set the width of the popup to 1224, which means that I don’t need to scroll down for anything, but if your screen resolution is smaller that that, you’ll probably want to drop it down a bit.
8 Responses for "Hacking the miniblog"
In a post by the original author of Miniblog there was a request for someone to take over the project. I volunteered. I’ll be hosting the code, fixing bugs, making improvements and answering questions on my blog: http://mediumbagel.org/?page_id=16.
In a post by the original author of Miniblog there was a request for someone to take over the project. I volunteered. I’ll be hosting the code, fixing bugs, making improvements and answering questions on my blog: http://mediumbagel.org/?page_id=16.
I tried following your directions exactly to create a miniblog bookmarklet, but instead I got a parse error: parse error, unexpected ‘?’, expecting ‘]’ in /wp-content/plugins/miniblog.php on line 135. I can’t figure out which ‘?’ it’s talking about.
I tried following your directions exactly to create a miniblog bookmarklet, but instead I got a parse error: parse error, unexpected ‘?’, expecting ‘]’ in /wp-content/plugins/miniblog.php on line 135. I can’t figure out which ‘?’ it’s talking about.
NG, you’re better off following the link the the 1st comment over to Thomas’ site, he’s now maintaining the code for this plugin
NG, you’re better off following the link the the 1st comment over to Thomas’ site, he’s now maintaining the code for this plugin
Hi,
I’m the new developer, Thomas did not want to continue development. That code does not work anymore. Unless you modify the new version. I have not added it to Miniblog 1.0, but I will probably add it soon. Sorry…
Hi,
I’m the new developer, Thomas did not want to continue development. That code does not work anymore. Unless you modify the new version. I have not added it to Miniblog 1.0, but I will probably add it soon. Sorry…
Leave a reply