Subversion Repository Public Repository

Nextrek

@ 58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
require_once 'database.php';
$data = array();

if (sql_connect())
{
	$query = 'SELECT timestamp, canale, programma as `titolo`, tipo, durata FROM `palinsesto`';
	if (array_key_exists('channels',$_REQUEST))
	{
		$canali = explode(',',$_REQUEST['channels']);
		if (count($canali)>0)
		{
			$where = array();
			foreach($canali as &$canale)
			{
				if (strtolower($canale)=='live_streaming')
				{
					$where[] = '(canale IN (SELECT nome FROM `canali` WHERE streaming_url<>\'\'))';
				} else {
					if (strpos($canale,'%') !== false) {
						$where[] = 'canale LIKE '.sql_quote($canale);
					} else {
						$where[] = 'canale='.sql_quote($canale);
					}
				}
			}
			$query .= ' WHERE ('.implode(' OR ',$where).')';
		}
	}
	$query .= ' ORDER BY canale, timestamp';

	// debug
	//error_log($query);

	$cursor = sql_cursor_open($query);
	while ($row = sql_fetch_row($cursor))
	{
		$canale = $row['canale'];

		if (!array_key_exists($canale, $data))
		{
			$data[$canale] = array();
		}

		unset($row['canale']);

		$data[$canale][] = $row;
	}
	sql_cursor_close($cursor);
	sql_disconnect();
}

ob_start();
echo json_encode($data);
header('Content-Length: ' . ob_get_length());
header('Content-type: application/json');
header('Cache-Control: must-revalidate');

// calc an offset of 12 hours
 $offset = 3600 * 12;
 // calc the string in GMT not localtime and add the offset
 $expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
 //output the HTTP header
 Header($expire);

 $gmt_mtime = gmdate('D, d M Y H:i:s', time() ) . ' GMT';
 header("Last-Modified: " . $gmt_mtime );

/*
 * USARE QUESTO PER NON FAR CACHERE I DATI AL BROWSER
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
*/
ob_end_flush();
exit;
?>

Commits for Nextrek/Web/epg/get_epg.php

Diff revisions: vs.
Revision Author Commited Message
9 DRuega picture DRuega Mon 06 May, 2013 21:54:02 +0000

Ripristinato EPG