Posts tagged PHP (PHP: Hypertext Preprocessor)
PHP Script to Add Time Zones to iCalendar/vCal Feeds
1This is really just a quick hack: all it does is insert the correct timezone description in the header of an iCalendar feed. But if the server that is generating the iCalendar feed doesn’t do it, someone has to. The script generates a URL that can then be subscribed to by your Calendar reader of choice. (I’m running this on my server and using it daily to good effect, but decline to share bandwidth with the world for this one):
$filename = "calendar";
if (isset($_GET["url"]))
{
$url = $_GET["url"];
if (!isset($_GET["show_url"]))
{
preg_match("|.+\/([^?]+)\??|", $url, $matches);
if (isset ($matches[1]))
{
$filename = $matches[1];
}
$calendar = file_get_contents ($url);
if ($calendar)
{
//$output = preg_replace_callback ("/(DATE-TIME:)(\d{4,4})(\d{2,2})(\d{2,2})T(\d{2,2})(\d{2,2})(\d{2,2})[^Z]/", "adjustTimeZone", $calendar);
$timezone = "X-WR-TIMEZONE:America/Los_Angeles\n" .
"CALSCALE:GREGORIAN\n" .
"BEGIN:VTIMEZONE\n" .
"TZID:America/Los_Angeles\n" .
"BEGIN:DAYLIGHT\n" .
"TZOFFSETFROM:-0800\n" .
"RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\n" .
"DTSTART:20070311T020000\n" .
"TZNAME:PDT\n" .
"TZOFFSETTO:-0700\n" .
"END:DAYLIGHT\n" .
"BEGIN:STANDARD\n" .
"TZOFFSETFROM:-0700\n" .
"RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\n" .
"DTSTART:20071104T020000\n" .
"TZNAME:PST\n" .
"TZOFFSETTO:-0800\n" .
"END:STANDARD\n" .
"END:VTIMEZONE\n";
$loc = strpos($calendar, "BEGIN:VEVENT");
$output = substr($calendar, 0, $loc) . $timezone . substr($calendar, $loc, strlen($calendar));
header("Content-Type: text/calendar");
header("Content-Disposition: inline; filename=$filename-pacific-timezone.ics");
echo $output;
exit;
}
}
} |
<h1>vCalendar Time Zone timezone</h1> <p>This is quick script to "de-float" calendars in the vCalendar format which do not specify time zones for their events. This script will automatically add the Pacific time zone information to the calendar at the URL entered below. Copy-and-paste the resulting URL below into your calendar reader of choice. <a href="http://battis.net/link/timezonescript">The source of this script is freely available.</a></p> <form action="<?= $_SERVER["PHP_SELF"] ?>" method="get"> <input type="hidden" name="show_url" value="" /> <p>Calendar URL <input name="url" type="text" value="<?= $url ?/>" /></p> < ?php $newUrl = "http://" . $_SERVER["SERVER_NAME"] . $_SERVER["PHP_SELF"] . "?url=" . urlencode($url); echo "<p><a href=\"$newUrl\">$newUrl</a>"; ?> <p><input type="submit" value="Generate"/></p> </form> |
WordPress µ Testing Setup
0A few days ago (well, maybe a couple weeks ago), I was chatting with one of my colleagues about how I go about testing out new plugins and themes for WordPress µ before loading them on our school blog server. It seems like documenting my process might be generally helpful, so…
To start with, I decided (after ten years of mucking out Apache config files and PHP extensions and custom MySQL installs — thank you so, so much Marc Liyange for your timely and helpful installers!), that I was a grown-up and could spend $60 on a tool that makes my life easier: I run MAMP Pro on my MacBook. This means that I have a generic Apache/PHP/MySQL stack that supports commonly-used PHP extensions, Apache configurations, etc. I have redirected the document root of my install to my regular user’s Sites directory in OS X (~/Sites) so that I have ready access to the backend files of for my test installs. The net result: WordPress’ famous “Five Minute Install” is now true of almost any LAMP-based web application — I had a five-minute install of Drupal, Moodle, Joomla… you name it.
I’ve also settled into using Coda ($99) to edit HTML/PHP source code, since I particularly like the built-in terminal and publishing management features.
With WordPress µ installed (which, I guess, is now calling itself WPMU or WordPress MU or even WordPress 3 in betas), I now do the following:
- I install create a new blog for each new theme or plugin that I want to test out. I follow a pretty intuitive naming scheme: the URL for the blog is the URL for the plugin or theme, and the name of the blog is the name of the plugin or theme (so WordPress Hashcash is at …/wp-hashcash and named WordPress Hashcash).
- As I create each new blog, I create a new user to be that blog’s administrator. I almost never use this login, but it means that I have one user who is matched to each blog. In doing this, I make heavy use of Gmail’s + modifiers, so new user emails look like mygmailaddress+talyn+wpmu+blogurl@gmail.com — this lets me catch and filter relevant emails easily on the other end. (I developed this system when I was testing plugins that sent email notifications). For the curious, Talyn is the name of my laptop (so I know which server is sending me email) and WPMU is the keyword to distinguish these emails from, say, Drupal notifications.
- I also have six generic users that I add to most (not all — I add them as needed) blogs, each with their own standard privileges:
- Anna “Annie” Administrator
- Edward “Eddie” Editor
- Allison “Allie” Author
- Christine “Chrissy” Contributor
- Samuel “Sammy” Subscriber
- Nathan “Nate” No Privileges
I actually included nicknames so that I could control for how different themes displayed usernames (since I’m thinking about FERPA and how it may apply to our students on our school blogserver).
- I have one blog on which I never activate themes or plugins, which I lyrically call “Is this blog in the blast radius?” This is based on my experience installing Digress.it on WordPress µ at the start of the year (it hosed every blog on the server, rather than just the one where it was activated). I check this before I deem any test complete.
- One tricky thing that I did was that I set up MAMP to run Apache and MySQL as my local user account on my MacBook, and I have set permissions on my Sites directory so that my local user has all privileges, as does the www group, and other users have read/execute privileges (
chown -R seth ~/Sites; chgrp -R www ~/Sites; chmod -R 775 ~/Sites). This means that I usually don’t run into problems with web apps that want to move or create files. This is also, of course, totally insecure. Que sera, sera. - I have an extra blog set up on my WordPress µ install that runs Feed WordPress, and it republishes the feeds for all of the other blogs on the server tagged Note. This means that I can post something tagged Note to any blog that I’m working on and then have all my notes together in one place. Adding the subscriptions to the Feed WordPress blog is a manual step, but not prohibitively difficult. And it really does mean that I have one place for all of my notes on how things went (or didn’t went) in my WordPress µ testing. I have the feeds categorized as Plugins, Themes, Configuration and Hacks, since those are generally what I’m testing (and mostly Plugins, at that).
- One hitch in my system is that I have opted to keep my system entirely up-to-date (I’m running WordPress µ 2.9.2 with the most recent versions of all my plugins), while our school blog server is still at 2.8.4a. Generally speaking, this hasn’t been much of a problem, but when I’m particularly concerned, I will sometimes check things out on a lingering 2.8.4a install before loading it.
This looks promising…
0The second semester started a few weeks ago here at the school where I teach. One of the real frustrations for me has been watching the enrollment in my second semester classes bottom out — conversations with students suggest that they are making this decision based largely on graduation requirements (they don’t need my courses to graduate). I had one particularly poignant conversation with a student this afternoon who asked, “why would someone sign up for the second semester? What do they get out of it? Are they just taking the class because they like it?”
In any event, sad though this is at a macro level, it has provided me with an opportunity to do what I enjoy most: build a project with my students. The few students remaining in my computer animation class and I are going to write, produce and animate a short film this spring. This is a project with more than a few steps, and no small amount of complexity. I’m keeping my fingers crossed that the students can do this, and I’m expecting to have to step in to pull my own weight in this project as well. And I’m kind of looking forward to that. (I’m certainly teaching this class because I like it!)
In doing this, I started to map out the steps of the project in a variety of different tools. I experimented with a bunch of online options (BaseCamp, 5pm, LiquidPlanner, Tom’s Planner) and have ended up with a tool that Adam Seldow introduced me to back when we were working on EdTags: dotProject. It’s a quirky little open source project planner, that has a fairly extensive collection of community-produced add-ons. It runs on a standard PHP/MySQL installation. It lets me map out milestones, tasks (with dependencies on other tasks), and have my students log their work (and progress) in the tool.
…and it generates Gantt charts of the project. Which turned out, to my surprise, to be a shockingly effective visualization for my students this afternoon. They haven’t exactly been coming out swinging — they’ve only been working on this project in class, while I’m there to crack the whip. But when they saw a) the complexity of the project and b) that their progress bars were behind where today’s date line was on the chart and c) that now our projected date of completion is two weeks after our last class. And they got religion.
As I worked with dotProject some more this afternoon, I’m beginning to think that the logging feature are going to provide me with some really spectacular qualitative data for assessing these students, as well as allowing them to visualize their progress in an immediate and understandable way. I’m totally excited about this: it’s authentic learning, with assessment, with intrinsic motivation! Woo hoo!
Let’s hope that this high lasts….