Tag Archives: php

Futzing and Displaying Unruly RSS Feeds

I am currently working on a Web site for my latest and absolutely greatest adventure of competing in the 2010 Montgomery Country Agricultural Fair‘s demolition derby. I want this Web site to provide multimedia content, descriptions and plans, as well as nicely displayed RSS feeds of my blog and SMS systems relevant to my demolition derby effort. Probably because of my own ignorance and lack of knowledge (remember, I’m a political/economic analyst, not a developer) but possibly because of a(nother) bug with StatusNet, I had difficulty using PHP to repost posts that contain a certain hashtag. After trying to do it the “correct” way for an hour or two, I decided to do it the easy hacky way and did so in five minutes. Here’s the deal in case you come across a similar problem:

For my homepage, I swiped Matt Thommes’ PHP to display RSS/ATOM feeds in another page. It took some tweaking (and learning), but I used his structure/framework to get my blog and sms sites to load. This works well, is clear, and allows for a good degree of flexibility.

For the demolition derby Web site, I want to post notices from my sms site that contain the #demoderby hashtag. That way, I can continue to use whatever information delivery methods I prefer (e.g., blog or sms) with it all being delivered to one place for people who want to follow the destruction. At first, I played with the various badges (for StatusNet systems) that exist out there, but I could not get the first two I tried to work and none of them seemed well configured for limiting posts to certain hashtags. The next step was to use Thommes’ PHP structure to use the RSS feed a StatusNet install provides for a given hashtag. This, however, wouldn’t work because–I think–of the URL StatusNet uses for hashtags’ RSS feeds.

After about two hours of total hunting and searching (starting from the badge search), I gave up and decided to add a tweak to Thommes’ code. I essentially include a line that checks to see if a given notice contains the hashtag. If it doesn’t, do nothing and move on to the next notice. If it does, then display the tag. It took me five minutes to do, and should have been how I started. Oh well.

Here’s the tweaked code:

# INSTANTIATE CURL.
$curl = curl_init();

# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL, "http://sms.jasonkoepke.com/api/statuses/user_timeline/1.atom");
Curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# GRAB THE XML FILE.
$xmlSMSFeed = curl_exec($curl);

curl_close($curl);

# SET UP XML OBJECT.
$xmlObjSMSFeed = simplexml_load_string($xmlSMSFeed);

$tempCounter = 0;

#Specify the hash you care about
$hashofconcern = "#demoderby";

foreach ($xmlObjSMSFeed->entry as $smsitem)
{
# DISPLAY ONLY 3 ITEMS.
if ( $tempCounter < 3 )
{
$pos = strpos($smsitem->title, $hashofconcern);
if ($pos === false)
{
#We don't want to display non-hashtagged posts, so this if statment has nothing.
}
else
{
echo " id."">".$smsitem -> published.": ".$smsitem -> title."

";
}
}

$tempCounter += 1;
}

Hope that helps someone, or someone comments the obvious and easier way of doing all this.

Parse Error when Installing StatusNet

I successfully installed StatusNet (nee: Laconica) this morning to my Web server, but in doing so I came across an issue that appears undocumented.

The StatusNet install is simple and straightforward. You UL the relevant files to your server and then visit the install path in your browser. StatusNet asks you to fill in several basic fields, including MySQL db info, admin info, and basic about-type info. Once you click Save, StatusNet installs the software, structures your previously created, blank MySQL db, and creates the config.php file using the information you entered on the install page.

After I had filled in the information, I clicked Save and, instead of being greeted by a success page, I saw an error along these lines:
install config.php parse error unexpected T_STRING.

I searched the config.php file for something that might be problematic, but couldn’t find anything. In addition, I did several searches, but again nothing. After about an hour, I tried removing an apostrophe I had put in my StatusNet install name (“Jsn’s”). That did the trick (although I had to delete and recreate the MySQL db and config.php files).

Hope that helps.

Update (Tech, not Life)

I have made slow progress on evolving my site, but the results are now becoming visible so a post is appropriate. The jasonkoepke.com part of the site has been PHP-ified, allowing me more flexibility and fun. This was a setup to display RSS feeds on the home page, which will give that page some content and protect my search rankings from encroaching Jason Koepkes. I also added a micro-blogging service at sms.jasonkoepke.com for learning purposes; at some point in the near term, I will add (1) add a link to the site on the main site’s navigation bar and (2) add the RSS feed on the main site’s home page. These changes provide a more robust foundation on which to develop and play, as well as improve my PHP skills for some other projects.