/beacon/events/index.php
PHP | 105 lines | 92 code | 12 blank | 1 comment | 18 complexity | a20d57566e3ba97b2d75bfd7a1d0a02a MD5 | raw file
1<?php 2require_once(dirname(dirname(dirname(__FILE__))).'/global.php'); 3 4if (array_key_exists('title', $_GET) && $_GET['title'] != '' 5 && array_key_exists('url_prefix', $_GET) && filter_var($_GET['url_prefix'], FILTER_VALIDATE_URL) !== false 6 ) 7{ 8 $url = validateURL($_GET['url_prefix'], $outputerror); 9 10 $type = array_key_exists('type', $_GET) && $_GET['type'] != '' ? $_GET['type'] : FALSE; 11 $start = array_key_exists('start', $_GET) && $_GET['start'] != '' ? $_GET['start'] : FALSE; 12 $end = array_key_exists('end', $_GET) && $_GET['type'] != '' ? $_GET['end'] : FALSE; 13 $resource_url = filter_var($_GET['resource_url'], FILTER_VALIDATE_URL); 14 15 $query = sprintf('INSERT INTO event ( 16 url_prefix, 17 title, 18 start' 19 .($type !== FALSE ? ', type' : '') 20 .($end !== FALSE ? ', end' : '') 21 .($resource_url !== FALSE ? ', resource_url' : '') 22 .") VALUES ( 23 '%s', 24 '%s', 25 '%s'" 26 .($type !== FALSE ? ", '%s'" : '') 27 .($end !== FALSE ? ", '%s'" : '') 28 .($resource_url !== FALSE ? ", '%s'" : '') 29 .')', 30 mysql_real_escape_string($url), 31 mysql_real_escape_string($_GET['title']), 32 mysql_real_escape_string($start), 33 mysql_real_escape_string($type), 34 mysql_real_escape_string($end), 35 mysql_real_escape_string($resource_url) 36 ); 37 38 if (!mysql_query($query)) 39 { 40 beaconError(mysql_error()); 41 } 42 43 # updating last_event_update for the matching URLs 44 $query = sprintf("UPDATE urls SET last_event_update = NOW() WHERE INSTR(url, '%s') = 1", 45 mysql_real_escape_string($url) 46 ); 47 $result = mysql_query($query); 48 49 if (!$result) { 50 beaconError(mysql_error()); 51 } 52 53 if (array_key_exists('manual', $_GET)) 54 { 55 ?><html> 56<head> 57<title>Event added</title> 58</head> 59<body> 60<h1>Event added</h1> 61<p>Event successfully added.</p> 62<p>Add <a href="./">one more</a>.</p> 63</body></html> 64<?php 65 exit; 66 } 67 68} else { 69 header('HTTP/1.0 400 Bad Request'); 70 71 ?><html> 72<head> 73<title>Bad Request: Event beacon</title> 74<style> 75i { 76 color: red; 77} 78</style> 79</head> 80<body> 81<h1>Bad Request: Event beacon</h1> 82<p>This is an event beacon for ShowSlow.</p> 83<p>You can use automated script to publish events using GET call to this URL:</p> 84<b><pre><?php echo $showslow_base?>beacon/events/?type=<i>sometype</i>&url_prefix=<i>url_prefix</i>&title=<i>some+title</i>&start=<i><?php echo urlencode(date("Y-m-d"))?></i>&end=<i><?php echo urlencode(date("Y-m-d"))?></i>&resource_url=<i>link+to+page</i></pre></b> 85or use form below to manually enter events. 86 87<h2>Add an event</h2> 88<form action="" method="GET"> 89<table> 90<tr><td>Type:</td><td><input type="text" name="type" size="25"/> (25 characters max)</td></tr> 91<tr><td>URL prefix:</td><td><input type="text" name="url_prefix" value="http://www.example.com/" size="80"/></td></tr> 92<tr><td>Event title:</td><td><input type="text" name="title" size="80"/></td></tr> 93<tr valign="top"><td>Start time:</td><td><input type="text" name="start" value="<?php echo date("Y-m-d H:i:s");?>"/> (leave blank for current time)<br/>Time in MySQL <a href="http://dev.mysql.com/doc/refman/5.1/en/datetime.html">timestamp format</a></td></tr> 94<tr valign="top"><td>End time:</td><td><input type="text" name="end"/> (or blank for momentary event)<br/>Time in MySQL <a href="http://dev.mysql.com/doc/refman/5.1/en/datetime.html">timestamp format</a></td></tr> 95<tr><td>Resource URL:</td><td><input type="text" name="resource_url" size="80"/></td></tr> 96<tr><td></td><td><input type="submit" name="manual" value="add"/></td></tr> 97 98</table> 99</form> 100</body></html> 101<?php 102 exit; 103} 104 105header('HTTP/1.0 204 Data accepted');