$res .= "<imgurl>" .
($feature->imgpath ?
- full_url_from_filename ($feature->imgpath)
+ full_url_from_imgpath ($feature->imgpath)
: "") .
"</imgurl>";
$description = unquote ($_POST ["description"]);
try {
- $new_feature = new feature ($id, $lon, $lat, $imgpath, $title, $description);
+ $new_feature = new feature ($id, $lon, $lat, $imgpath, $title, $description, 0);
} catch (Exception $e) {
request_error ();
}
$title = unquote ($_POST ["title"]);
$description = unquote ($_POST ["description"]);
try {
- $feature = new feature (null, $lon, $lat, $imgpath, $title, $description);
+ $feature = new feature (null, $lon, $lat, $imgpath, $title, $description, 0);
} catch (Exception $e) {
request_error ();
}
cp -RLp inc/ $DESTDIR/
# other php files
-cp -p admin.*php index.*php wizard.*php api.php items.php logout.php $DESTDIR/
+cp -p admin.*php index.*php wizard.*php news.php api.php items.php logout.php $DESTDIR/
# media
cp -RLp media/ $DESTDIR/
private $imgpath = null;
private $title = null;
private $description = null;
+ private $date = 0;
const err_lonlat_invalid = 1;
- function __construct ($id, $lon, $lat, $imgpath, $title, $description) {
+ function __construct ($id, $lon, $lat, $imgpath, $title, $description, $date) {
$this->imgpath = $imgpath;
// id
// description
$this->description = $description;
+ // date
+ $this->date = $date;
+
// longitude
if (!isset ($lon) || !is_numeric ($lon) ||
($lon < -180) || ($lon > 180)) {
*/
public function listfeatures();
+ /*
+ * returns the most recent features sorted by date. If $num_features is not
+ * defined or is null, returns all features sorted by date.
+ */
+ public function mostrecentfeatures($num_features);
+
/*
* returns true if a feature with imgpath exists
*/
$id = mysql_insert_id ();
return new feature ($id, $feature->lon, $feature->lat,
$feature->imgpath, $feature->title,
- $feature->description);
+ $feature->description, $feature->date);
}
}
public function getfeature ($id) {
$query = sprintf ("SELECT id, imgpath, title, description, AsText(location)
- AS location FROM %sitems WHERE id = '%s';",
+ AS location, UNIX_TIMESTAMP(date) AS date FROM %sitems
+ WHERE id = '%s';",
$this->dbprefix, mysql_real_escape_string ($id));
$row = mysql_fetch_assoc ($this->_execute_query ($query));
if ($row === false) {
public function listfeatures () {
$query = sprintf ("SELECT id, imgpath, title, description, AsText(location)
- AS location FROM %sitems;",
+ AS location, UNIX_TIMESTAMP(date) AS date FROM %sitems;",
$this->dbprefix);
$features = array ();
return $features;
}
+ public function mostrecentfeatures ($num_features) {
+ $query = sprintf ("SELECT id, imgpath, title, description,
+ AsText(location) AS location, UNIX_TIMESTAMP(date)
+ AS date FROM %sitems ORDER BY date DESC",
+ $this->dbprefix);
+ if ($num_features) {
+ $query .= sprintf (" LIMIT %d", $num_features);
+ }
+ $features = array ();
+ $res = $this->_execute_query ($query);
+ while ($row = mysql_fetch_assoc ($res)) {
+ $feature = $this->_feature_frow_row ($row);
+ if (isset ($feature)) {
+ $features[] = $feature;
+ }
+ }
+ return $features;
+ }
+
public function imgpath_exists ($imgpath) {
$query = sprintf ("SELECT COUNT(*) FROM %sitems WHERE imgpath LIKE '%s';",
$this->dbprefix, mysql_real_escape_string ($imgpath));
$lat = $matches [2];
try {
$feature = new feature ($row ["id"], $lon, $lat, $row ["imgpath"],
- $row ["title"], $row ["description"]);
+ $row ["title"], $row ["description"],
+ $row ["date"]);
} catch (Exception $e) {
return null;
}
// title of your website
define ("SITETITLE", "SYP");
+// email contact for webmaster.
+define ("WEBMASTERMAIL", "");
+
// url of images directory. If empty, syp will try to guess it from syp admin
// location and UPLOADDIR. So, you need to set that variable if host is
// different between syp admin and images directory. Or if protocol is
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<title><?php echo defined ("SITETITLE") ? SITETITLE : "SYP"?></title>
+ <link rel="alternate" type="application/atom+xml" title="Atom 1.0" href="news.php">
<link rel="stylesheet" href="./openlayers/theme/default/style.css" type="text/css">
<link rel="stylesheet" href="./media/syp.css" type="text/css">
require_once ("inc/settings.php");
+function gethost() {
+ $host = $_SERVER ["HTTP_HOST"];
+ $colpos = strpos ($host, ':');
+ // some web clients add port informations in Host header
+ if ($colpos !== false) {
+ $host = substr ($host, 0, $colpos);
+ }
+ return $host;
+}
+
function unquote($gpc_str) {
if (!isset ($gpc_str)) {
return $gpc_str;
}
}
-function full_url_from_filename ($filename) {
+function full_url_from_imgpath ($filename) {
if (defined ("IMGSDIRURL") && (strlen (IMGSDIRURL) != 0)) {
return rtrim (IMGSDIRURL, '/') . "/" . rawurlencode ($filename);
}
$rel_path = UPLOADDIR . "/" . rawurlencode ($filename);
+ return full_url_from_path (UPLOADDIR . "/" . rawurlencode ($filename));
+}
+
+function full_url_from_path ($path) {
+ $rel_path = $path;
+
while (substr($rel_path, 0, 2) == "./") { // strips ./
$rel_path = substr ($rel_path, 2);
}
$path = "$script_dir/$rel_path";
}
- $host = $_SERVER ["HTTP_HOST"];
+ $host = gethost();
$port = $_SERVER ["SERVER_PORT"];
if ($_SERVER ["HTTPS"] == "on") {
$proto = "https";
return "$proto://$host$port$path";
}
-
?>
$title = htmlspecialchars ($feature->title, ENT_QUOTES);
$description = htmlspecialchars ($feature->description, ENT_QUOTES);
$imgurl = ($feature->imgpath ?
- full_url_from_filename ($feature->imgpath)
+ full_url_from_imgpath ($feature->imgpath)
: "");
$lon = $feature->lon;
$lat = $feature->lat;
--- /dev/null
+<?php
+/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
+ license. */
+
+require_once ("./inc/settings.php");
+require_once ("./inc/db/mysql.php");
+require_once ("./inc/utils.php");
+
+header ("Content-type: application/atom+xml; charset=UTF-8");
+header("Cache-control: no-cache");
+
+function date3339 ($feature) {
+ $date = date ('Y-m-d\TH:i:s', $feature->date);
+
+ $matches = array();
+ if (preg_match ('/^([\-+])(\d{2})(\d{2})$/',
+ date ('O', $feature->date), $matches)) {
+ $date .= $matches [1] . $matches [2] . ':' . $matches [3];
+ } else {
+ $date .= 'Z';
+ }
+ return $date;
+}
+
+function unique_id_from_feature ($feature) {
+ // method from http://diveintomark.org/archives/2004/05/28/howto-atom-id#other
+ $date = date('Y-m-d', $feature->date);
+ $res = sprintf("tag:%s,%s:%d", gethost(), $date, $feature->id);
+ return $res;
+}
+
+function unique_id_from_site () {
+ $id = md5 (full_url_from_path (""));
+ $res = sprintf("tag:%s,1970-01-01:%d", gethost, $id);
+ return $res;
+}
+
+function main ($features) {
+ print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
+<feed xmlns=\"http://www.w3.org/2005/Atom\"
+ xmlns:georss=\"http://www.georss.org/georss\">\n";
+
+ printf(" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n",
+ full_url_from_path (""));
+ printf(" <link rel=\"self\" href=\"%s\" type=\"application/atom+xml\"/>\n",
+ full_url_from_path (basename ($_SERVER ["PHP_SELF"])));
+ printf(" <id>%s</id>\n", unique_id_from_site());
+
+ if (count ($features) > 0) {
+ printf(" <updated>%s</updated>\n", date3339 ($features[0]));
+ }
+
+ if (SITETITLE) {
+ printf (" <title>%s</title>\n", SITETITLE);
+ }
+
+ if (WEBMASTERMAIL) {
+ printf (" <author>\n");
+ printf (" <email>%s</email>\n", WEBMASTERMAIL);
+ printf(" </author>\n");
+ }
+
+ print "\n";
+
+ foreach ($features as $feature) {
+ print (" <entry>\n");
+
+ if ($feature->title) {
+ $title = htmlspecialchars ($feature->title, ENT_QUOTES);
+ } else {
+ $title = $feature->id;
+ }
+ printf (" <title>%s</title>\n", $title);
+
+ $rel_url = sprintf ("index.php?lat=%.18F&lon=%.18F&zoom=12",
+ $feature->lat, $feature->lon);
+ $link = htmlspecialchars (full_url_from_path ($rel_url), ENT_QUOTES);
+ printf (" <link rel=\"alternate\" type=\"text/html\" href=\"%s\"/>\n", $link);
+
+ printf (" <id>%s</id>\n", unique_id_from_feature ($feature));
+
+ printf (" <updated>%s</updated>\n", date3339 ($feature));
+
+ if ($feature->description) {
+ $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->description, ENT_QUOTES));
+ } else {
+ $contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
+ }
+
+ if (strlen ($contentHTML) != 0) {
+ printf(" <content type=\"html\">
+ %s
+ </content>\n", htmlspecialchars ($contentHTML));
+ }
+
+ printf(" <georss:point>%.18F %.18F</georss:point>\n",
+ $feature->lat, $feature->lon);
+
+ printf(" </entry>\n\n");
+ }
+ print '</feed>';
+}
+
+try {
+ $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
+ $features = $connection->mostrecentfeatures (10);
+} catch (Exception $e) {
+ exit ("server error");
+}
+main ($features);
+?>