Script: Creating a small portal site (PHP)

This is the code that powers the syndication of, the portal site for my group of friends. For some time, we were using a standard RSS-and-Perl solution, but we had a good deal of problems with it.Problem 1: Non-ASCII characters
I tend to use many non-ASCII characters, including emdashes and accented letters, in my posts. While I have my posting system (currently greymatter, but soon to change of a database system of my own writing) set to replace those with their escaped HTML equivalents, they didn't play nicely with XML.

Problem 2: Lag time before syndication
We're obsessive. We wanted posts to syndicate immediately. We'd originally thought that syndicating every thirty minutes would be enough, but most of us discovered that we hated the thirty minutes of lag time between the creation of a post and its display on wondergeeks. Therefore, our new solution needed to be dynamic, so that the syndication files were called whenever someone loaded

Problem 3: Number of sites syndicated
We were syndicating 15 sites on wondergeeks. It was becoming more and more difficult to just look at the portal page and figure out which entries were actually new, and which sites hadn't updated in weeks (or, in one case, months). We wanted something that would feature only the newly-updated sites, and relegate the more stale posts to the background.

Our best option seemed to be to move away from a standard RSS/Perl implementation and move toward PHP. I wrote this code with an eye toward releasing it. I realized that we were able to do our previous portal because Heather was comfortable creating (and had permission to create) cronjobs that would periodically download all our syndication files, parse them appropriately, and use them in the creation of the newest page. Not everyone has those permissions or that comfort level with unix, so I thought I'd write something that would be a little easier to implement and maintain.

Heather normally maintains wondergeeks (our portal) and I maintain, our group weblog/discussion site. I told Heather that if she was willing to swap jobs for a while, I'd write this code for wondergeeks if she'd create a third skin for geek-chick. She agreed, and I got started writing.

The end result is the code that's available in this (5K) file.

What does it do?
In short, it pulls in all the files that you tell it to, and drops the information into an array. It sorts the information it's received by date, and displays the first N posts in order of the time they were posted (the very newest entry is at the top). The N newest posts have their site name, post title, and first X words displayed. All sites that don't qualify as being one of the N newest are then re-sorted alphabetically (by the name of their site) and then displayed (name of site only) in two columns.

In other words, you feature the sites that are newest and freshest, but everyone gets linked.

How do I make it work?
This code actually works immediately with no customization. I've included links to some of the syndication files we use on wondergeeks, just so you can see it working immediately. There are copious comments in the code, detailing what you need to add to the script to add a site.

What files are included?
There are three files: server.php,, and Server.php is the code that generates the portal page. Keep in mind that you can rename this file anything you want, and you can include plenty of other PHP and HTML in this page to make it fit in with your site. Your syndicatees will need either the file or the file, depending on whether they are running Greymatter or Movable Type.

What do my GM syndicatees need to do?

  1. Take the file, and edit the code to suit their site. Directions are included in the file.
  2. Upload the file to their server, and chmod it to 644 (or 666 if you absolutely must).
  3. Log into Greymatter, go to the Configuration menu, and add this file to the Connected Files box. Make sure that "Rebuild files when new entries are posted?" is checked.
  4. Save changes, then go to "Rebuild Files" and choose "Rebuild Connected Files."
  5. Contact you and provide you with the URL to the file, as well as how many hours they are ahead or behind of GMT.

What do my MT syndicatees need to do?

  1. Create a new index template and paste the code (from in there.
  2. Edit the code to suit their site. The Name: field can be whatever's easiest for them. The Output file: field should be what you want the syndicated file to be named (say,
  3. Contact you and provide you with the URL to the file, as well as how many hours they are ahead or behind of GMT.

(Thanks to Lynda for this information.)

Why .inc? Why not .php?
You're going to be pulling information across a HTTP connection. If your syndicatees named these files with a .php extension, and their servers support PHP, that .php file would be parsed by the server. Since these are just variables, with no screen output, their server would present you with a blank page. You need the variables, not blankness—so by naming the files with a three-letter extension that PHP doesn't parse, you don't have to worry about this problem occurring. Your syndicatees don't even need to be able to use PHP—just you.

So what do I do to get started?
Chances are, you've got a group of people who want to have a portal. Do your part first—take the server.php file, dress it up like the rest of your site, and rename it to whatever you need it to be. Send your friends the appropriate syndication files, and give them the directions they need to set up syndication. As they get back in touch with you, add the information about their sites to your portal page. That should be it!

How much does this cost?
It's donationware. In other words, it's free—technically. I ask that a link to my codebits page or the front page of receive a text link somewhere on your page. If you find the script useful, consider wandering over to my Amazon wishlist and throwing a donation my way. You'll have my gratitude, and it'll encourage me to keep writing scripts and making them available.

The code is available in this (5K) file. Good luck, and enjoy!

all tags: 


*S* well. I'm not sure I understood half of what you said. but the other half that I ~did~ understand, makes this sound Very Interesting! (I downloaded the file anyway) hopefully, in a few months, I ~Will~ understand Exactly what you said :) (as i keep trying to learn more and more :) THANK YOU!

All that, and nary a comment on how much a pain in the ass my site structure can be in making things work all happy. I am impressed, Amy! :) And yes, I'm going to be using this code on Sooner, rather than later, actually.

I'm still puzzled by some aspects of the script. As a non english speaker some things are unclear. I'm trying to display N lines of ((newsentries)), but it just displays 1 entry per website. How can I influence this? Otherwise the fastest and easiest working script I've come across!! Keep up the good work!

What you're asking for would require a bit of a rewrite. The script is intended to pull only one entry from each site, and put it into a list. The script takes the N newest entries from THAT list.

I should also note that I've got to make this script a bit more robust. I forgot to add in a bit of error-handling in case one of your syndicatees is unreachable...a fact I discovered when one of OURS went dark for a little while. I've got an idea of how to fix it...just gotta test it out.

Hola, Amy. I had a quick question about this script. Does it only handle the feeds generated from those using the .inc files, or can it handle any rss feed? Forgive me if I sound ignorant (because I am). I'm very new to PHP (though I'm learning how to install fairly well).

I can answer that: it will only process the included .inc file. This is not an RSS feed, really.

Darn. Thanks!

what do you use to create the site this is damn cool. J

I was wondering if this works in PHP 4.0.0 becuase I got this error: Fatal error: Call to undefined function: str_pad() in /home/ on line 110

Still learning... tough stuff.