Michael Bommarito (g0thm0g) wrote in lj_nifty,
Michael Bommarito
g0thm0g
lj_nifty

  • Music:

Friends-only OPML without the password risk

AJAX OPML Generator

This is pretty much a ripoff of nikolasco's OPML-generating script. There is, however, one major difference: mine supports friends-only authentication for feeds. I've already used it to import my LJ list to my feed reader - and all my friends-only friends show up now too.

One word of caution - because this OPML feed will store your password, I don't suggest using it on a site designed to share OPML. In this case, you would be exposing your password to the world. Only use it for services that import OPML for private feed reading.

It's written in AJAX with a PHP backend to fetch your friends list. Why AJAX? Why is this any different? Well, because the OPML file is generated by JavaScript, your password never leaves the web page. As usual, source is included.

JavaScript in fdata.php
<script type="text/javascript" lang="javascript">	
var xmlhttp=false;

/**
	http://jibbering.com/2002/4/httprequest.html
**/
function initReq() {
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	// JScript gives us Conditional compilation, we can cope with old IE versions.
	// and security blocked creation of the objects.
	 try {
	  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	  try {
	   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (E) {
	   xmlhttp = false;
	  }
	 }
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	  xmlhttp = new XMLHttpRequest();
	}
}

function processFriends(str) {
	var friends = str.split(",");
	var user = document.forms['frmOpts'].ljUser.value;
	var pass = document.forms['frmOpts'].ljPass.value;
	var opmlOut = '';
	
	opmlOut = '<opml version="1.1">' + "\n";
	opmlOut += '<head><title>' + user + "\'s Friends</title></head>\n";
	opmlOut += '<body>';
	for(var i = 0; i < friends.length; i++) {
		opmlOut = opmlOut + '<outline text="' + friends[i] + 
    '" xmlUrl="http://' + user + ':' + pass 
    + '@www.livejournal.com/users/' + friends[i] 
    + '/data/rss?auth=digest"/>' + "\n";
	}
	opmlOut = opmlOut + "</body>\n" + "</opml>";
	
	document.forms['frmOpts'].opmlOut.value = opmlOut;
}

function generateOPML() {
	var user = document.forms['frmOpts'].ljUser.value;
	xmlhttp.open("GET", "fetchfdata.php?user=" + user, true);
	xmlhttp.onreadystatechange=function() {
			if (xmlhttp.readyState==4) {
				processFriends(xmlhttp.responseText)
			}
	}
	xmlhttp.send(null)
}

</script>




fetchfdata.php
<?php
	if(isset($_GET['user'])) {
		//readfile("http://www.livejournal.com/misc/fdata.bml?user=" . $_GET['user']);
		$friends = array_slice(file("http://www.livejournal.com/misc/fdata.bml?user=" . $_GET['user']), 1);
		foreach($friends as $friend) {
			if($friend[0] == ">") {
				$friend = explode(' ', $friend);
				$friend = rtrim(end($friend));
				$f[] = $friend;
			}
		}
		echo implode(',', $f);
	} else {
		echo 'Error';
	}
?>
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 16 comments