PHP

Stuff about PHP scripting

Publishing Echo recorded lectures in Moodle

Update: I wouldn’t recommend using this method now. The EchoCenter works just fine, and has the added benefit of displaying analytics to instructors.


WTH?

EchoSystem, the lecture recording service we are running at LSE, provides various methods for publishing links to recorded lectures in Moodle, our VLE (LMS).

The “Moodle Publisher” places the links in the course calendar, with each recording listed as a separate “event”.  This is useful, but it is not immediately apparent to our students that they should look there for the links.

If configured to do so, EchoSystem will generate RSS feeds for each course’s “section” or “module”.  This is also useful, because RSS feeds can be used in a number of contexts, including Moodle’s Remote RSS feeds block.  But there’s a problem: unless you have given your presenters the ability to edit their recordings (we haven’t), or you have the time to edit them yourself (we don’t), all the recordings from a particular section end up with the same title.

November 26th, 2010|Images, Audio & Video, Tools & Technologies|Comments Off on Publishing Echo recorded lectures in Moodle|

A Regular Expression to match any URL

Update: see my most recent comment. WordPress has a pretty good regex for matching URLs.


A bold claim, but I think I’ve got one:

|([A-Za-z]{3,9})://([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((/[-\+~%/\.\w]+)?\??([-\+=&;%@\.\w]+)?#?([\w]+)?)?|

An online events booking system I developed doesn’t allow HTML in the event description field, primarily to protect against annoying scripting attacks. But what if you want to provide a link in the description? I need to detect plain text URLs stored in the database, and turn them into hyperlinks when displayed in the browser. The regular expression above allows me to do that quite easily in PHP:

$pattern = |([A-Za-z]{3,9})://([-;:&=+$,w]+@{1})?([-A-Za-z0-9.]+)+:?(d+)?((/[-+~%/.w]+)???([-+=&;%@.w]+)?#?([w]+)?)?|;
$html = preg_replace($pattern, '<a href="$0">$0</a>', $text);

But the regular expression has several submatches. They provide a means to break down the URL into its constituent parts, including protocol, user info, server name, REQUEST_URI, query string and anchor.

Here’s a PHP class I wrote that uses this Regular Expression to analyse a string, detect URLs, populate an array with the constituent parts of the URL, and replace URLs with hyperlinks. Here’s an example of usage:

$text  = 'Please visit http://www.example.com/cgi-bin/';
$text .= 'script.cgi?variable=value&variable2=some';
$text .= '+url+encoded+text#section-1 to find out more';

$urlf = new URLFinder();
$html = $urlf->make_links($text);
echo $html;

If you print_r($urlf), you can see how the URL is broken down.

I haven’t managed to find any exceptions to the expression, but if you do, please post an example.