Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // v1.0.0
- // params
- $force = array_key_exists('force', $_GET) ? true : false;
- $prog = $_GET['prog'];
- $savefile = "config.$prog.json";
- if(!file_exists($savefile)) die("unknown prog '{$prog}'");
- $data = json_decode(file_get_contents($savefile), true) or die('failed reading data file');
- // not from feedburner
- if(!$force
- && (!array_key_exists('HTTP_USER_AGENT', $_SERVER) || strpos($_SERVER['HTTP_USER_AGENT'], 'FeedBurner') === FALSE)
- && (array_key_exists('Feed', $data))
- ) {
- header("Status: 301 Moved Permanently", false, 301);
- header("Location: {$data['Feed']}");
- die();
- }
- $last_generation_time = filemtime($savefile) or die('failed reading data file age');
- // file older than 6 hours ?
- if ($force || ((time() - $last_generation_time) > 21600)) {
- $url = $data['Page'];
- $fetched = file_get_contents($url) or die('failed fetching feed');
- $reg = '#<li id="video_(?<vid>\\d+)"#ims'; //#<li id="video_(?<vid>\d+)"#ims
- if(preg_match_all($reg, $fetched, $matches, PREG_SET_ORDER)) {
- $items = array();
- foreach($matches as $match) {
- $vid = (int)$match['vid'];
- $title = sprintf("%s %s", $data['Title'], $vid);
- $url = sprintf("%s?vid=%s", $data['Page'], $vid);
- if(strlen($title) == 0 || strpos($title, '<img') !== FALSE)
- continue;
- $items[$vid] = array(
- 'VID' => $vid,
- 'TITLE' => $title,
- 'URL' => $url
- );
- }
- krsort($items);
- }
- if (count($items) > 0) {
- $data['Items'] = array_values($items);
- file_put_contents($savefile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) or die('failed saving data file');
- }
- $last_generation_time = time();
- }
- header('Content-Type: application/rss+xml; charset=utf-8');
- echo '<'.'?'.'xml version="1.0" encoding="utf-8"'.'?'.'>';
- ?>
- <rss version="2.0">
- <channel>
- <title><?=htmlspecialchars($data['Title'])?></title>
- <description><?=htmlspecialchars($data['Title'])?></description>
- <lastBuildDate><?=date('r', $last_generation_time)?></lastBuildDate>
- <link>http://www.canalplus.fr/</link>
- <?php foreach($data['Items'] as $item): ?>
- <item>
- <title><?=htmlspecialchars($item['TITLE'])?></title>
- <link><?=htmlspecialchars($item['URL'])?></link>
- </item>
- <?php endforeach; ?>
- </channel>
- </rss>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement