Skip to content

Instantly share code, notes, and snippets.

function pubDateToTimestamp(pubDate) {
if (typeof pubDate === "number") {
return pubDate;
}
var date = new Date(pubDate);
var pubDateParsed = Math.round(date.getTime() / 1000);
if (isNaN(pubDateParsed)) {
return 0;
@daveajones
daveajones / jsonfeed2rss.php
Last active August 15, 2023 21:06
Convert JSONFeed to RSS
<?php
//Convert JSONfeed to RSS in a single function as a drop-in to make adding JSONfeed
//support to an aggregator easier
function convert_jsonfeed_to_rss($content = NULL, $max = NULL)
{
//Test if the content is actual JSON
json_decode($content);
if( json_last_error() !== JSON_ERROR_NONE) return FALSE;
@daveajones
daveajones / get_final_url
Created July 21, 2016 14:56
A php function to follow all redirects and return the final destination url.
//Follow redirects to get to the final, good url
function get_final_url($url, $timeout = 5, $count = 0)
{
$count++;
$url = clean_url($url);
$ua = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0';
$cookie = tempnam("/tmp", "CURLCOOKIE");
$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, $ua);