Installation
------------
+upload syp to your webserver
edit inc/settings.php
-open http://yoururl.com/wizard.php
+open http://yoururl.com/wizard.php with your web browser
follow instructions
+Upgrade
+------------
+- make a copy of inc/settings.php
+- delete old version of syp from your server
+- upload now version
+- edit inc/settings.php again (copy old version of file may not be enough
+ because new settings may have appeared)
+- open http://yoururl.com/upgrade.php with your web browser
+
server API
----------
The way server side communicates with client side is described at
$res .= "<imgurl>" .
($feature->imgpath ?
- full_url_from_imgpath ($feature->imgpath)
+ image_url_from_imgpath ($feature->imgpath)
: "") .
"</imgurl>";
(!move_uploaded_file ($file ["tmp_name"], $dest))) {
server_error ();
}
+ $mini_dest = getthumbsdir () . "/mini_" . basename_safe ($dest);
+
+ try {
+ $thumbnail_ok = create_thumbnail ($dest, $mini_dest);
+ } catch (Exception $e) {
+ $thumbnail_ok = false;
+ }
+ if (!$thumbnail_ok) {
+ if (!copy ($dest, $mini_dest)) {
+ server_error ();
+ }
+ }
+
}
return basename_safe ($dest);
}
return;
}
if ($con->imgpath_exists ($imgpath)) {
- return false;
+ return;
}
+
$path = UPLOADDIR . "/" . $imgpath;
- if (file_exists($path)) {
+ if (file_exists ($path)) {
unlink ($path);
- return true;
- } else {
- return false;
+ }
+
+ $thumb_path = getthumbsdir () . "/mini_" . $imgpath;
+ if (file_exists ($thumb_path)) {
+ unlink ($thumb_path);
}
}
cp -RLp inc/ $DESTDIR/
# other php files
-cp -p admin.*php index.*php wizard.*php news.php api.php items.php logout.php $DESTDIR/
+cp -p admin.*php index.*php upgrade.*php wizard.*php news.php api.php items.php logout.php $DESTDIR/
# media
cp -RLp media/ $DESTDIR/
cp -p license.txt README.txt COPYING.txt $DESTDIR/
# creates upload directory
-mkdir $DESTDIR/upload
-chmod a+wx $DESTDIR/upload
+mkdir -p $DESTDIR/upload/_thumbs
+chmod -R a+wx $DESTDIR/upload
# generate sources
cd $BUILDDIR
"SYP wizard"
=> "",
+ "exist but is not a directory"
+ => "",
+
+ "could not create directory"
+ => "",
+
+ "directory created"
+ => "",
+
+ "could not write in directory"
+ => "",
+
"You need at least PHP version 5"
=> "",
"Data table created."
=> "",
- "exist but is not a directory"
+ "It looks like GD extension is not installed."
=> "",
- "could not create directory"
+ "SYP is installed. You can now go to <a href=\"admin.en.php\">admin area</a>"
=> "",
- "directory created"
+ "SYP upgrade"
=> "",
- "could not write in directory"
+ "Thumbnails successfully created."
=> "",
- "SYP is installed. You can now go to <a href=\"admin.en.php\">admin area</a>"
+ "Error when creating thumbnails."
+ => "",
+
+ "SYP upgrade went smoothly. You can now go to <a href=\"admin.en.php\">admin area</a>"
=> "",
"SYP needs javascript. Please activate scripts in your browser."
"Assistant d'installation de SYP"
,
+ "exist but is not a directory"
+ =>
+ "existe mais n'est pas un répertoire"
+ ,
+
+ "could not create directory"
+ =>
+ "Impossible de créer le répertoire"
+ ,
+
+ "directory created"
+ =>
+ "Répertoire créé"
+ ,
+
+ "could not write in directory"
+ =>
+ "Impossible d'écrire dans le répertoire"
+ ,
+
"You need at least PHP version 5"
=>
"Vous devez utiliser une version de PHP au moins égale à la version 5"
"Table des données créée."
,
- "exist but is not a directory"
+ "It looks like GD extension is not installed."
=>
- "existe mais n'est pas un répertoire"
+ "L'extension GD ne semble pas être installée."
,
- "could not create directory"
+ "SYP is installed. You can now go to <a href=\"admin.en.php\">admin area</a>"
=>
- "Impossible de créer le répertoire"
+ "SYP est installé. Vous pouvez maintenant vous rendre dans <a href=\"admin.fr.php\">la partie administration.</a>"
,
- "directory created"
+ "SYP upgrade"
=>
- "Répertoire créé"
+ "mise à jour de SYP"
,
- "could not write in directory"
+ "Thumbnails successfully created."
=>
- "Impossible d'écrire dans le répertoire"
+ "Miniatures crées avec succès."
,
- "SYP is installed. You can now go to <a href=\"admin.en.php\">admin area</a>"
+ "Error when creating thumbnails."
=>
- "SYP est installé. Vous pouvez maintenant vous rendre dans <a href=\"admin.fr.php\">la partie administration.</a>"
+ "Erreur lors de la création des miniatures."
+ ,
+
+ "SYP upgrade went smoothly. You can now go to <a href=\"admin.en.php\">admin area</a>"
+ =>
+ "La mise à jour de SYP s'est déroulée avec succès. Vous pouvez maintenant vous rendre dans <a href=\"admin.fr.php\">la partie administration.</a>"
,
"SYP needs javascript. Please activate scripts in your browser."
,
)
-?>
+?>
\ No newline at end of file
$ROOTDIR = "../../";
// scripts in rootdir we need to link to
-$SCRIPTS = array ("admin", "index", "wizard");
+$SCRIPTS = array ("admin", "index", "upgrade", "wizard");
function usage() {
global $argv;
// to be writeable by SYP.
define ("UPLOADDIR", "upload");
+// directory where generated thumbnails are stored. That directory needs to be
+// writeable by SYP.
+define ("THUMBSDIR", "upload/_thumbs");
+
// title of your website
define ("SITETITLE", "SYP");
// different between syp admin and images directory. Or if protocol is
// different (for example, if syp admin is https and images directory is http)
define ("IMGSDIRURL", "");
+
+// url of tumbnails directory. If empty, syp will try to guess it from syp
+// location and THUMBSDIR. So, you need to set that variable if host is
+// different between syp admin and images directory. Or if protocol is
+// different (for example, if syp admin is https and images directory is http)
+define ("THUMBSDIRURL", "");
+
+// max size (either width or height) of thumbnails. If one dimension of
+// uploaded image is bigger, images will be resized.
+define ("THUMBSMAXSIZE", 400);
?>
}
$bbox = $connection->mbr ();
+if (defined ("THUMBSMAXSIZE") && (THUMBSMAXSIZE > 0)) {
+ $thumbsmaxsize = THUMBSMAXSIZE;
+} else {
+ $thumbsmaxsize = 400; // default value;
+}
?>
<html>
<head>
<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">
+ <style type="text/css">
+ .olPopup p {
+ <?php printf("width: %dpx;\n", $thumbsmaxsize)?>
+ }
+ .olPopup img {
+ <?php printf("max-height: %dpx;\n", $thumbsmaxsize)?>
+ <?php printf("max-width: %dpx;\n", $thumbsmaxsize)?>
+
+ /* for IE (does not understand max-heigth max-width) */
+ <?php printf("_height: expression((this.scrollHeight>this.scrollWidth) ?
+ Math.min(parseInt(this.scrollHeight), %d ) + 'px' : 'auto');\n", $thumbsmaxsize)?>
+ <?php printf("_width: expression((this.scrollWidth>this.scrollHeight) ?
+ Math.min(parseInt(this.scrollWidth), %d ) + 'px' : 'auto');\n", $thumbsmaxsize)?>
+ }
+ </style>
<script type="text/javascript">
var SypStrings = {
--- /dev/null
+<?php
+/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
+ license. */
+?>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
+ "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
+ <link rel="stylesheet" href="./media/common.css" type="text/css" />
+ <title><?php ptrans ('SYP upgrade')?></title>
+</head>
+<body>
+<?php
+ function create_all_thumbs($con) {
+ $features = $con->listfeatures ();
+ foreach ($features as $feature) {
+ if ($feature->imgpath) {
+ $imgfilename = UPLOADDIR . "/" . $feature->imgpath;
+ $thumbfilename = getthumbsdir () . "/mini_" . $feature->imgpath;
+ if ((file_exists ($imgfilename)) &&
+ (!(file_exists ($thumbfilename)))) {
+ try {
+ create_thumbnail ($imgfilename, $thumbfilename);
+ } catch (Exception $e) {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ require_once ("./inc/settings.php");
+ require_once ("./inc/db/mysql.php");
+ require_once ("./inc/utils.php");
+
+ $error = false;
+ try {
+ $connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
+ $usrtblexists = $connection->users_table_exists ();
+ $itemstblexists = $connection->items_table_exists ();
+ } catch (Exception $e) {
+ $error = true;
+ }
+ if (!$usrtblexists || !$itemstblexists) {
+ $error = true;
+ }
+ if ($error) {
+ die(sprintf('<p class="error center">%s</p>', trans('SYP is not correctly installed. Please follow README.txt instructions
+ and go to <a href="wizard.en.php">wizard</a>.')));
+ }
+
+ safe_create_writable_dir (getthumbsdir ());
+ if (create_all_thumbs ($connection)) {
+ par_success (trans('Thumbnails successfully created.'));
+ } else {
+ par_error (trans('Error when creating thumbnails.'));
+ }
+
+ par_success (trans ('SYP upgrade went smoothly. You can now go to <a href="admin.en.php">admin area</a>'));
+
+?>
+</body>
+</html>
<body onload="init()">
<?php
- function leave () {
- exit ("\n</body></html>");
- }
- function wiz_success ($message) {
- printf ("<p class=\"success center\">%s</p>", $message);
- }
- function wiz_error ($message) {
- printf ("<p class=\"error center\">%s</p>", $message);
- leave ();
- }
- function wiz_warn ($message) {
- printf ("<p class=\"warn center\">%s</p>", $message);
- }
if (version_compare (PHP_VERSION, '5.0.0', '<')) {
- wiz_error (trans ("You need at least PHP version 5"));
+ par_error (trans ("You need at least PHP version 5"));
}
require_once ("./inc/settings.php");
require_once ("./inc/db/mysql.php");
+ require_once ("./inc/utils.php");
try {
$connection->connect (DBHOST, DBUSER, DBPWD, DBNAME, DBPREFIX);
} catch (Exception $e) {
switch ($e->getMessage ()) {
case anydbConnection::err_driver_unavailable:
- wiz_error ($connection->getdbname() . ': ' . trans ('not supported'));
+ par_error ($connection->getdbname() . ': ' . trans ('not supported'));
case anydbConnection::err_connection:
- wiz_error (trans ('Could not connect to database.'));
+ par_error (trans ('Could not connect to database.'));
case anydbConnection::err_unknown_database:
- wiz_error (trans ('Database does not exist.'));
+ par_error (trans ('Database does not exist.'));
default:
- wiz_error (trans ('Unknown error when connecting to database.'));
+ par_error (trans ('Unknown error when connecting to database.'));
}
}
try {
$users_table_exists = $connection->users_table_exists ();
} catch(Exception $e) {
- wiz_error (trans ('Unknown error when checking user table.'));
+ par_error (trans ('Unknown error when checking user table.'));
}
if ($users_table_exists) {
- wiz_success (trans ('Found user table.'));
+ par_success (trans ('Found user table.'));
} else {
if (isset($_POST ["password"])) {
try {
$connection->create_users_table (true);
} catch (Exception $e) {
- wiz_error (trans ('Error when creating user table.'));
+ par_error (trans ('Error when creating user table.'));
}
- wiz_success (trans ('User table created.'));
+ par_success (trans ('User table created.'));
try {
$connection->setpwd ("admin", $_POST ["password"]);
} catch (Exception $e) {
- wiz_error (trans ('Error when initializing password.'));
+ par_error (trans ('Error when initializing password.'));
}
- wiz_success (trans ('Admin password initialized.'));
+ par_success (trans ('Admin password initialized.'));
} else {
print ('<form class="center" method="post" action="">
try {
$items_table_exists = $connection->items_table_exists ();
} catch (Exception $e) {
- wiz_error (trans ('Unknown error when checking data table.'));
+ par_error (trans ('Unknown error when checking data table.'));
}
if ($items_table_exists) {
- wiz_success (trans ('Found data table.'));
+ par_success (trans ('Found data table.'));
} else {
try {
$connection->create_items_table (true);
} catch (Exception $e) {
- wiz_error (trans ('Error when creating data table.'));
+ par_error (trans ('Error when creating data table.'));
}
- wiz_success (trans ('Data table created.'));
+ par_success (trans ('Data table created.'));
}
- if (!is_dir (UPLOADDIR)) {
- if (file_exists (UPLOADDIR)) {
- wiz_error (UPLOADDIR . ": " . trans ('exist but is not a directory'));
- }
- if (!mkdir (UPLOADDIR)) {
- wiz_error (UPLOADDIR . ": " . trans ('could not create directory'));
- } else {
- wiz_success (UPLOADDIR . ": " . trans ('directory created'));
- }
- }
- if (!is_writeable (UPLOADDIR) || !is_executable (UPLOADDIR)) {
- wiz_error (UPLOADDIR . ": " . trans ('could not write in directory'));
+
+ safe_create_writable_dir (UPLOADDIR);
+ safe_create_writable_dir (getthumbsdir ());
+
+ if (!function_exists ("gd_info")) {
+ par_warn (trans ('It looks like GD extension is not installed.'));
}
- wiz_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));
+
+ par_success (trans ('SYP is installed. You can now go to <a href="admin.en.php">admin area</a>'));
?>
</body>
require_once ("inc/settings.php");
-function gethost() {
+function getthumbsdir () {
+ if (THUMBSDIR) {
+ return rtrim (THUMBSDIR, "/");
+ } else {
+ $uploaddir = rtrim (UPLOADDIR, "/");
+ return $uploaddir . "/" . "_thumbs";
+ }
+}
+
+function gethost () {
$host = $_SERVER ["HTTP_HOST"];
$colpos = strpos ($host, ':');
// some web clients add port informations in Host header
return $host;
}
+function ext_safe ($path) {
+ $basename = basename_safe ($path);
+ return end (explode (".", $basename));
+}
+
function basename_safe ($path) {
return end (explode ("/", $path));
}
}
}
-function full_url_from_imgpath ($filename) {
+function thumb_url_from_imgpath ($filename) {
+ if (defined ("THUMBSDIRURL") && (strlen (THUMBSDIRURL) != 0)) {
+ return rtrim (THUMBSDIRURL, '/') . "/_mini" . rawurlencode ($filename);
+ }
+ return full_url_from_path (getthumbsdir () . "/mini_" . rawurlencode ($filename));
+}
+
+function image_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));
}
return "$proto://$host$port$path";
}
+
+function create_thumbnail ($filename, $destfile) {
+ $ext = strtolower (ext_safe ($filename));
+ if ($ext == "jpg" || $ext == "jpeg") {
+ $image = imagecreatefromjpeg ($filename);
+ } else if ($ext == "png") {
+ $image = imagecreatefrompng ($filename);
+ } else {
+ return false;
+ }
+
+ if ($image === false) {
+ return false;
+ }
+
+ if (defined (THUMBSMAXSIZE) && (THUMBSMAXSIZE > 0)) {
+ $thumbsmaxsize = THUMBSMAXSIZE;
+ } else {
+ $thumbsmaxsize = 400; // default value;
+ }
+
+ $width = imageSX ($image);
+ $height = imageSY ($image);
+ if (($width <= $thumbsmaxsize) || ($height <= $thumbsmaxsize)) {
+ return false;
+ }
+
+ if ($width > $height) {
+ $thumb_width = $thumbsmaxsize;
+ $thumb_height = $height * ($thumbsmaxsize / $width);
+ } else if ($width < $height) {
+ $thumb_width = $width * ($thumbsmaxsize / $height);
+ $thumb_height = $thumbsmaxsize;
+ } else if ($width == $height) {
+ $thumb_width = $thumbsmaxsize;
+ $thumb_height = $thumbsmaxsize;
+ }
+
+ $thumb_image = ImageCreateTrueColor ($thumb_width, $thumb_height);
+ if ($thumb_image === false) {
+ return false;
+ }
+ if (!imagecopyresampled ($thumb_image, $image, 0, 0, 0, 0,
+ $thumb_width, $thumb_height, $width, $height)) {
+ return false;
+ }
+
+ if ($ext == "jpg" || $ext == "jpeg") {
+ if (!imagejpeg ($thumb_image, $destfile, 100)) {
+ return false;
+ }
+ } else if ($ext == "png") {
+ if (!imagepng ($thumb_image, $destfile)) {
+ return false;
+ }
+ }
+
+ imagedestroy ($image);
+ imagedestroy ($thumb_image);
+
+ return true;
+}
+
+function safe_create_dir ($dirname) {
+ if (is_dir ($dirname)) {
+ return;
+ }
+ if (file_exists ($dirname)) {
+ par_error ($dirname . ": " . trans ('exist but is not a directory'));
+ }
+ if (!mkdir ($dirname)) {
+ par_error ($dirname . ": " . trans ('could not create directory'));
+ } else {
+ par_success ($dirname . ": " . trans ('directory created'));
+ }
+}
+
+function safe_create_writable_dir ($dirname) {
+ safe_create_dir ($dirname);
+ if (!is_writeable ($dirname) || !is_executable ($dirname)) {
+ par_error ($dirname . ": " . trans ('could not write in directory'));
+ }
+}
+
+function leave () {
+ exit ("\n</body></html>");
+}
+function par_success ($message) {
+ printf ("<p class=\"success center\">%s</p>", $message);
+}
+function par_error ($message) {
+ printf ("<p class=\"error center\">%s</p>", $message);
+ leave ();
+}
+function par_warn ($message) {
+ printf ("<p class=\"warn center\">%s</p>", $message);
+}
?>
$title = htmlspecialchars ($feature->title, ENT_QUOTES);
$description = htmlspecialchars ($feature->description, ENT_QUOTES);
$imgurl = ($feature->imgpath ?
- full_url_from_imgpath ($feature->imgpath)
+ image_url_from_imgpath ($feature->imgpath)
+ : "");
+ $thumburl = ($feature->imgpath ?
+ thumb_url_from_imgpath ($feature->imgpath)
: "");
$lon = $feature->lon;
$lat = $feature->lat;
$title;
if ($imgurl) {
- $imgurlHTML = sprintf ('<img alt="%s" src="%s">', $alt, $imgurl);
+ $imgurlHTML = sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
} else {
$imgurlHTML = "";
}
width: 50%;
}
-.olPopup p {
- width: 400px;
-}
-.olPopup img {
- margin: 20px;
- max-height: 400px;
- max-width: 400px;
-
- /* for IE (does not understand max-heigth max-width) */
- _height: expression((this.offsetHeight>this.offsetWidth) ?
- Math.min(parseInt(this.offsetHeight), 400 ) : true);
- _width: expression((this.offsetWidth>=this.offsetHeight) ?
- Math.min(parseInt(this.offsetWidth), 400 ) : true);
-}
.olPopup {
text-align: center;
border: 3px double black;
background-color: white;
}
+.olPopup img {
+ margin: 20px;
+}
+
/* for IE (does not understand double borders */
#popup_contentDiv {
_border: 2px solid black;
$contentHTML = sprintf ("<p>%s</p>", htmlspecialchars ($feature->title, ENT_QUOTES));
}
+ // FIXME: we consider thumbnail are correctly sized if gd library is
+ // installed. That may not always be true. For example if gd was installed
+ // after images were initially uploaded.
+ if (function_exists ("imagecreatefromjpeg")) {
+ if ($feature->imgpath) {
+ $imgurl = image_url_from_imgpath ($feature->imgpath);
+ $thumburl = thumb_url_from_imgpath ($feature->imgpath);
+ $contentHTML .= sprintf ('<a href="%s"><img alt="%s" src="%s"></a>', $imgurl, $alt, $thumburl);
+ }
+ }
+
if (strlen ($contentHTML) != 0) {
printf (" <content type=\"html\">
%s
--- /dev/null
+upgrade.php
\ No newline at end of file
--- /dev/null
+upgrade.php
\ No newline at end of file
--- /dev/null
+<?php
+/* Copyright (c) 2009 Arnaud Renevier, Inc, published under the modified BSD
+ license. */
+
+ require ('inc/langutils.php');
+ require ('inc/templates_upgrade.php');
+?>