summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex AUVOLAT <alexis211@gmail.com>2012-06-21 16:34:27 +0200
committerAlex AUVOLAT <alexis211@gmail.com>2012-06-21 16:34:27 +0200
commit889e8eaf7c40817663dd602a21ac771062ccac3b (patch)
treeca8ac81ee202165333e5ffe16147d09e5cdaf2ab
parent5c4caed8560d5fded00525844dfa8386b97e7918 (diff)
downloadBits-889e8eaf7c40817663dd602a21ac771062ccac3b.tar.gz
Bits-889e8eaf7c40817663dd602a21ac771062ccac3b.zip
Big change, sir. Can now upload any kind of files.
-rw-r--r--.gitignore2
-rw-r--r--design/style.css3
-rw-r--r--lib/conf/apps.php2
-rw-r--r--lib/conf/file.php13
-rw-r--r--lib/conf/image.php7
-rw-r--r--lib/file/delete.php21
-rw-r--r--lib/file/delfld.php (renamed from lib/image/delfld.php)12
-rw-r--r--lib/file/editfld.php (renamed from lib/image/editfld.php)10
-rw-r--r--lib/file/editinfo.php (renamed from lib/image/editinfo.php)24
-rw-r--r--lib/file/folder.php43
-rw-r--r--lib/file/index.php44
-rw-r--r--lib/file/newfld.php (renamed from lib/image/newfld.php)4
-rw-r--r--lib/file/upload.php54
-rw-r--r--lib/image/delete.php21
-rw-r--r--lib/image/folder.php43
-rw-r--r--lib/image/index.php49
-rw-r--r--lib/image/upload.php63
-rw-r--r--schema.sql46
-rw-r--r--tpl/file/folder.php56
-rw-r--r--tpl/file/index.php61
-rw-r--r--tpl/file/upload-ok.php (renamed from tpl/image/upload-ok.php)8
-rw-r--r--tpl/file/upload.php (renamed from tpl/image/upload.php)8
-rw-r--r--tpl/general/top.php6
-rw-r--r--tpl/image/folder.php52
-rw-r--r--tpl/image/index.php55
25 files changed, 356 insertions, 351 deletions
diff --git a/.gitignore b/.gitignore
index 9b7ca5e..e775888 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,4 @@ lib/conf/sql.php
*.swp
nohup.out
_old
-images/*
+files/*
diff --git a/design/style.css b/design/style.css
index 2a537f6..613fed7 100644
--- a/design/style.css
+++ b/design/style.css
@@ -182,6 +182,9 @@ iframe, textarea {
.small_right, .tool_link {
font-size: 0.8em;
+}
+
+.small_right a, .tool_link {
font-style: italic;
}
diff --git a/lib/conf/apps.php b/lib/conf/apps.php
index 8afeb2d..8e755b1 100644
--- a/lib/conf/apps.php
+++ b/lib/conf/apps.php
@@ -5,7 +5,7 @@ $homepage = "blog";
$apps = array(
// Image upload application
- "image" => array(
+ "file" => array(
"index" => 1,
"delete" => 1,
"editinfo" => 1,
diff --git a/lib/conf/file.php b/lib/conf/file.php
new file mode 100644
index 0000000..4a8830e
--- /dev/null
+++ b/lib/conf/file.php
@@ -0,0 +1,13 @@
+<?php
+
+$baseurl = "http://localhost/alex.auvolat/files/";
+$savedir = getcwd() . "/files/";
+
+$img_mini_width = 127;
+
+function has_mini($ext) {
+ return $ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif";
+}
+
+//$quota = 128;; //ceil((time() - 1220000000) / (3600 * 24 * 20));
+//$min_priv_for_no_quota = 2;
diff --git a/lib/conf/image.php b/lib/conf/image.php
deleted file mode 100644
index 462300e..0000000
--- a/lib/conf/image.php
+++ /dev/null
@@ -1,7 +0,0 @@
-<?php
-
-$baseurl = "http://localhost/alex.auvolat/images/";
-$savedir = getcwd() . "/images/";
-$miniature_width = 127;
-//$quota = 128;; //ceil((time() - 1220000000) / (3600 * 24 * 20));
-//$min_priv_for_no_quota = 2;
diff --git a/lib/file/delete.php b/lib/file/delete.php
new file mode 100644
index 0000000..1a65058
--- /dev/null
+++ b/lib/file/delete.php
@@ -0,0 +1,21 @@
+<?php
+
+require("lib/conf/file.php");
+
+$title = "Delete a file";
+
+if (count($args) < 3) header("location: index.php");
+$id = intval($args[2]);
+
+$info = mysql_fetch_assoc(sql("SELECT * FROM files WHERE id = $id"));
+
+if ($info["owner"] == $user["id"]) {
+ token_validate("Do you really want to delete this file ?", "file");
+ if (has_mini($info["extension"])) unlink($savedir . $id . "-min." . $info["extension"]);
+ unlink($savedir . $id . "." . $info["extension"]);
+ sql("DELETE FROM files WHERE id = $id");
+ header("location: file");
+} else {
+ $error = "You cannot delete this file.";
+}
+require("tpl/general/empty.php");
diff --git a/lib/image/delfld.php b/lib/file/delfld.php
index a018b7a..c1cacf0 100644
--- a/lib/image/delfld.php
+++ b/lib/file/delfld.php
@@ -1,16 +1,16 @@
<?php
-assert_redir(count($args) >= 3, 'image');
+assert_redir(count($args) >= 3, 'file');
$fldid = intval($args[2]);
$fld = mysql_fetch_assoc(sql(
"SELECT id, name, comment, public, owner ".
- "FROM img_folders WHERE id = $fldid"
+ "FROM folders WHERE id = $fldid"
));
assert_error($fld && $fld['owner'] == $user['id'],
"This folder does not exist, or you are not allowed to edit it.");
-token_validate("Do you really want to delete this folder ?", "folder-image-$fldid");
-sql("DELETE FROM img_folders WHERE id = $fldid");
-sql("UPDATE images SET folder = 0 WHERE folder = $fldid");
-header("location: image");
+token_validate("Do you really want to delete this folder ?", "folder-file-$fldid");
+sql("DELETE FROM folders WHERE id = $fldid");
+sql("UPDATE files SET folder = 0 WHERE folder = $fldid");
+header("location: file");
diff --git a/lib/image/editfld.php b/lib/file/editfld.php
index a0bef1f..db5a304 100644
--- a/lib/image/editfld.php
+++ b/lib/file/editfld.php
@@ -2,12 +2,12 @@
require("lib/markdown.php");
-assert_redir(count($args) == 3, 'image');
+assert_redir(count($args) == 3, 'file');
$fldid = intval($args[2]);
$fld = mysql_fetch_assoc(sql(
"SELECT id, name, comment, public, owner ".
- "FROM img_folders WHERE id = $fldid"
+ "FROM folders WHERE id = $fldid"
));
assert_error($fld && $fld['owner'] == $user['id'],
"This folder does not exist, or you are not allowed to edit it.");
@@ -23,10 +23,10 @@ if (isset($_POST['name']) && isset($_POST['comment'])) {
if ($fld_name == "") {
$error = "You must enter a name for your folder.";
} else {
- sql("UPDATE img_folders SET name = '" . escs($fld_name) . "', comment = '" . escs($fld_comment) .
+ sql("UPDATE folders SET name = '" . escs($fld_name) . "', comment = '" . escs($fld_comment) .
"', comment_html = '" . escs($fld_comment_html) . "', public = " . ($fld_public?'1':'0') .
" WHERE id = $fldid");
- header("Location: folder-image-" . $fldid);
+ header("Location: folder-file-" . $fldid);
die();
}
@@ -34,7 +34,7 @@ if (isset($_POST['name']) && isset($_POST['comment'])) {
$title = "Edit folder";
$fields = array(
- array("label" => "Name : ", "name" => "name", "value" => $fld_name),
+ array("label" => "Folder name : ", "name" => "name", "value" => $fld_name),
array("label" => "Public ? ", "name" => "public", "type" => "checkbox", "checked" => $fld_public),
array("label" => "Comment : ", "name" => "comment", "type" => "textarea", "value" => $fld_comment),
);
diff --git a/lib/image/editinfo.php b/lib/file/editinfo.php
index 8223c18..eea9f35 100644
--- a/lib/image/editinfo.php
+++ b/lib/file/editinfo.php
@@ -2,20 +2,20 @@
require("lib/markdown.php");
-require("lib/conf/image.php");
+require("lib/conf/file.php");
-$title = "Rename an image";
+$title = "Rename a file";
if (count($args) < 3) header("location: index.php");
$id = intval($args[2]);
$info = mysql_fetch_assoc(sql(
- "SELECT images.owner AS owner, images.id AS id, images.name AS name, images.comment AS comment,
- img_folders.id AS folder_id, img_folders.name AS folder_name
- FROM images LEFT JOIN img_folders ON images.folder = img_folders.id WHERE images.id = $id"
+ "SELECT files.owner AS owner, files.id AS id, files.name AS name, files.comment AS comment,
+ folders.id AS folder_id, folders.name AS folder_name
+ FROM files LEFT JOIN folders ON files.folder = folders.id WHERE files.id = $id"
));
-assert_error($info["owner"] == $user["id"], "You cannot rename this image.");
+assert_error($info["owner"] == $user["id"], "You cannot rename this file.");
$name = $info['name'];
$comment = $info['comment'];
@@ -26,23 +26,23 @@ if (isset($_POST['name']) && isset($_POST['comment']) && isset($_POST['folder'])
$comment_html = Markdown($comment);
$folder = intval($_POST['folder']);
if ($name == "") {
- $error = "You must give a non-empty name to this image. Please.";
+ $error = "You must give a non-empty name to this file. Please.";
} else {
- sql("UPDATE images SET name = '" . escs($name) . "', comment='" . escs($comment). "',
+ sql("UPDATE files SET name = '" . escs($name) . "', comment='" . escs($comment). "',
comment_html = '" . escs($comment_html) . "', folder = $folder WHERE id = $id");
- header("Location: image");
+ header("Location: file");
die();
}
}
$folders = array(0 => "[no folder]");
-$r = sql("SELECT id, name FROM img_folders WHERE owner = " . $user['id'] . " ORDER BY name ASC");
+$r = sql("SELECT id, name FROM folders WHERE owner = " . $user['id'] . " ORDER BY name ASC");
while ($n = mysql_fetch_array($r))
$folders[$n['id']] = $n['name'];
-$title = "Edit image info : " . $info['name'];
+$title = "Edit file info : " . $info['name'];
$fields = array(
- array("label" => "Name : ", "name" => "name", "value" => $name),
+ array("label" => "File name : ", "name" => "name", "value" => $name),
array("label" => "Folder : ", "type" => "select", "name" => "folder", "choices" => $folders, "value" => $folder),
array("label" => "Comment : ", "name" => "comment", "value" => $comment, "type" => "textarea"),
);
diff --git a/lib/file/folder.php b/lib/file/folder.php
new file mode 100644
index 0000000..15e8625
--- /dev/null
+++ b/lib/file/folder.php
@@ -0,0 +1,43 @@
+<?php
+
+require("lib/conf/file.php");
+
+assert_redir(count($args) == 3, 'file');
+$fldid = intval($args[2]);
+
+$fld = mysql_fetch_assoc(sql(
+ "SELECT folders.id AS id, folders.name AS name, folders.comment_html AS comment_html, ".
+ "folders.public AS public, account.id AS owner, account.login AS ownername FROM folders ".
+ "LEFT JOIN account ON account.id = folders.owner ".
+ "WHERE folders.id = $fldid"
+));
+assert_error($fld && ($fld['public'] != 0 || $fld['owner'] == $user['id']),
+ "This folder does not exist, or you are not allowed to see it.");
+
+$can_edit = ($user['priv'] >= $apps['file']['editfld'] && $user['id'] == $fld['owner']);
+$is_owner = ($user['id'] == $fld['owner']);
+
+$filters = array (
+ "order" => array (
+ "name" => "title",
+ "upl_date" => "date uploaded",
+ ),
+ "way" => $ord_ways,
+);
+$fdefaults = array (
+ "order" => "name",
+ "way" => "ASC",
+);
+
+$title = $fld["name"];
+
+$files = array();
+$fileq = sql("SELECT files.id AS id, files.name AS name, files.extension AS extension, files.upl_date AS upl_date, ".
+ "files.comment_html AS comment_html FROM files WHERE files.folder = $fldid");
+while ($img = mysql_fetch_assoc($fileq)) $files[] = $img;
+
+$s = sql("SELECT id, name FROM folders WHERE owner = " . $fld['owner'] . ($fld['owner'] == $user['id'] ? '' : " AND public != 0"). " ORDER BY name ASC");
+$folers = array();
+while ($f = mysql_fetch_assoc($s)) $folders[] = $f;
+
+require("tpl/file/folder.php");
diff --git a/lib/file/index.php b/lib/file/index.php
new file mode 100644
index 0000000..34686c5
--- /dev/null
+++ b/lib/file/index.php
@@ -0,0 +1,44 @@
+<?php
+
+require("lib/conf/file.php");
+
+$filters = array (
+ "order" => array (
+ "name" => "title",
+ "upl_date" => "date uploaded",
+ "folder_name" => "folder",
+ ),
+ "way" => $ord_ways,
+);
+$fdefaults = array (
+ "order" => "upl_date",
+ "way" => "DESC",
+);
+
+$title = "Image upload";
+
+$files = array();
+$fileq = sql("SELECT files.id AS id, files.name AS name, files.extension AS extension, files.upl_date AS upl_date, ".
+ "files.comment_html AS comment_html, folders.id AS folder_id, folders.name AS folder_name ".
+ " FROM files LEFT JOIN folders ON folders.id = files.folder ".
+ "WHERE files.owner = " . $user['id'] .
+ " ORDER BY " . get_filter('order') . " " . get_filter('way'));
+while ($img = mysql_fetch_assoc($fileq)) $files[] = $img;
+
+if ($user['priv'] < $apps['file']['upload']) {
+ $error = "You don't have the rights to upload files.";
+ $can_upload = false;
+} else {
+ $can_upload = true;
+}
+
+$folders = array();
+$r = sql("SELECT id, name FROM folders WHERE owner = " . $user['id'] . " ORDER BY name ASC");
+while ($f = mysql_fetch_assoc($r)) {
+ $folders[] = $f;
+}
+
+$can_delete = ($user['priv'] >= $apps['file']['delete'] && $user['id'] != 0);
+$can_rename = ($user['priv'] >= $apps['file']['editinfo'] && $user['id'] != 0);
+
+require("tpl/file/index.php");
diff --git a/lib/image/newfld.php b/lib/file/newfld.php
index 63afd17..6b5ba1f 100644
--- a/lib/image/newfld.php
+++ b/lib/file/newfld.php
@@ -13,10 +13,10 @@ if (isset($_POST['name']) && isset($_POST['comment'])) {
if ($fld_name == "") {
$error = "You must enter a name for your folder.";
} else {
- sql("INSERT INTO img_folders(owner, name, comment, comment_html, public) ".
+ sql("INSERT INTO folders(owner, name, comment, comment_html, public) ".
"VALUES(" . $user['id'] . ", '" . escs($fld_name) . "', '" . escs($fld_comment) .
"', '" . escs($fld_comment_html) . "', " . ($fld_public ? '1' : '0') . ")");
- header("Location: folder-image-" . mysql_insert_id());
+ header("Location: folder-file-" . mysql_insert_id());
die();
}
}
diff --git a/lib/file/upload.php b/lib/file/upload.php
new file mode 100644
index 0000000..4b5299d
--- /dev/null
+++ b/lib/file/upload.php
@@ -0,0 +1,54 @@
+<?php
+
+$title = "Upload a file";
+
+require("lib/conf/file.php");
+
+
+if (isset($_FILES['file']) && isset($_POST['name'])) {
+ $name = esca($_POST['name']);
+ if ($name == "") $name = $_FILES['file']['name'];
+ if ($_FILES['file']['error'] != 0) {
+ $error = "Sorry, an error occurred while uploading your file. Try with a smaller one.";
+ require("tpl/file/upload.php");
+ }
+ $origname = strtolower(basename($_FILES['file']['name']));
+ $type = preg_replace("#^.+\.([a-z0-9]+)$#", "$1", $origname);
+
+ sql("INSERT INTO files(owner, extension, name, upl_date) VALUES(" . $user['id'] . ", '$type', '" . escs($name) . "', NOW())");
+ $id = mysql_insert_id();
+ $filen = $savedir . $id . "." . $type;
+ if (!copy($_FILES['file']['tmp_name'], $filen)) {
+ $error = "An internal error occurred. You might want to try again later.";
+ sql("DELETE FROM files WHERE id = $id");
+ require("tpl/file/upload.php");
+ }
+
+ if (has_mini($type)) {
+ $minin = $savedir . $id . "-min." . $type;
+ if ($type == "png")
+ $source = imagecreatefrompng($filen);
+ elseif ($type == "jpg" || $type == "jpeg")
+ $source = imagecreatefromjpeg($filen);
+ elseif ($type == "gif")
+ $source = imagecreatefromgif($filen);
+ $l = imagesx($source);
+ $h = imagesy($source);
+ $l2 = $img_mini_width;
+ $h2 = $l2 * $h / $l;
+ $mini = imagecreatetruecolor($l2, $h2);
+ imagecopyresampled($mini, $source, 0, 0, 0, 0, $l2, $h2, $l, $h);
+ if ($type == "png")
+ imagepng($mini, $minin);
+ elseif ($type == "jpg")
+ imagejpeg($mini, $minin);
+ elseif ($type == "gif")
+ imagegif($mini, $minin);
+ $message = "Your image has been uploaded successfully and a miniature has been created.";
+ } else {
+ $message = "Your file has been uploaded successfully.";
+ }
+ require("tpl/file/upload-ok.php");
+} else {
+ require("tpl/file/upload.php");
+}
diff --git a/lib/image/delete.php b/lib/image/delete.php
deleted file mode 100644
index e6716ec..0000000
--- a/lib/image/delete.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-require("lib/conf/image.php");
-
-$title = "Delete an image";
-
-if (count($args) < 3) header("location: index.php");
-$id = intval($args[2]);
-
-$info = mysql_fetch_assoc(sql("SELECT * FROM images WHERE id = $id"));
-
-if ($info["owner"] == $user["id"]) {
- token_validate("Do you really want to delete this image ?", "image");
- unlink($savedir . $id . "-min." . $info["extension"]);
- unlink($savedir . $id . "." . $info["extension"]);
- sql("DELETE FROM images WHERE id = $id");
- header("location: image");
-} else {
- $error = "You cannot delete this image.";
-}
-require("tpl/general/empty.php");
diff --git a/lib/image/folder.php b/lib/image/folder.php
deleted file mode 100644
index 574531c..0000000
--- a/lib/image/folder.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-require("lib/conf/image.php");
-
-assert_redir(count($args) == 3, 'image');
-$fldid = intval($args[2]);
-
-$fld = mysql_fetch_assoc(sql(
- "SELECT img_folders.id AS id, img_folders.name AS name, img_folders.comment_html AS comment_html, ".
- "img_folders.public AS public, account.id AS owner, account.login AS ownername FROM img_folders ".
- "LEFT JOIN account ON account.id = img_folders.owner ".
- "WHERE img_folders.id = $fldid"
-));
-assert_error($fld && ($fld['public'] != 0 || $fld['owner'] == $user['id']),
- "This folder does not exist, or you are not allowed to see it.");
-
-$can_edit = ($user['priv'] >= $apps['image']['editfld'] && $user['id'] == $fld['owner']);
-$is_owner = ($user['id'] == $fld['owner']);
-
-$filters = array (
- "order" => array (
- "name" => "title",
- "upl_date" => "date uploaded",
- ),
- "way" => $ord_ways,
-);
-$fdefaults = array (
- "order" => "name",
- "way" => "ASC",
-);
-
-$title = $fld["name"];
-
-$images = array();
-$files = sql("SELECT images.id AS id, images.name AS name, images.extension AS extension, images.upl_date AS upl_date, ".
- "images.comment_html AS comment_html FROM images WHERE images.folder = $fldid");
-while ($img = mysql_fetch_assoc($files)) $images[] = $img;
-
-$s = sql("SELECT id, name FROM img_folders WHERE owner = " . $fld['owner'] . ($fld['owner'] == $user['id'] ? '' : " AND public != 0"). " ORDER BY name ASC");
-$folers = array();
-while ($f = mysql_fetch_assoc($s)) $folders[] = $f;
-
-require("tpl/image/folder.php");
diff --git a/lib/image/index.php b/lib/image/index.php
deleted file mode 100644
index b9748dc..0000000
--- a/lib/image/index.php
+++ /dev/null
@@ -1,49 +0,0 @@
-<?php
-
-require("lib/conf/image.php");
-
-$filters = array (
- "order" => array (
- "name" => "title",
- "upl_date" => "date uploaded",
- "folder_name" => "folder",
- ),
- "way" => $ord_ways,
-);
-$fdefaults = array (
- "order" => "name",
- "way" => "ASC",
-);
-
-$title = "Image upload";
-
-$images = array();
-$files = sql("SELECT images.id AS id, images.name AS name, images.extension AS extension, images.upl_date AS upl_date, ".
- "images.comment_html AS comment_html, img_folders.id AS folder_id, img_folders.name AS folder_name ".
- " FROM images LEFT JOIN img_folders ON img_folders.id = images.folder ".
- "WHERE images.owner = " . $user['id'] .
- " ORDER BY " . get_filter('order') . " " . get_filter('way'));
-while ($img = mysql_fetch_assoc($files)) $images[] = $img;
-
-/*if (count($images) >= $quota && $user['priv'] < $min_priv_for_no_quota) {
- $error = "You have already exceeded your quota of $quota uploadable images.";
- $can_upload = false;
-} else */
-
-if ($user['priv'] < $apps['image']['upload']) {
- $error = "You don't have the rights to upload images.";
- $can_upload = false;
-} else {
- $can_upload = true;
-}
-
-$folders = array();
-$r = sql("SELECT id, name FROM img_folders WHERE owner = " . $user['id'] . " ORDER BY name ASC");
-while ($f = mysql_fetch_assoc($r)) {
- $folders[] = $f;
-}
-
-$can_delete = ($user['priv'] >= $apps['image']['delete'] && $user['id'] != 0);
-$can_rename = ($user['priv'] >= $apps['image']['editinfo'] && $user['id'] != 0);
-
-require("tpl/image/index.php");
diff --git a/lib/image/upload.php b/lib/image/upload.php
deleted file mode 100644
index 5176a3a..0000000
--- a/lib/image/upload.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-$title = "Upload an image";
-
-require("lib/conf/image.php");
-
-/*
-$number = mysql_fetch_assoc(sql("SELECT count(*) AS count FROM images WHERE owner = " . $user['id']));
-assert_error($number['count'] < $quota || $user['priv'] >= $min_priv_for_no_quota || $user['id'] == 0,
- "You have already exceeded your upload quota.");
-*/
-
-if (isset($_FILES['image']) && isset($_POST['name'])) {
- $name = esca($_POST['name']);
- if ($name == "") $name = $_FILES['image']['name'];
- if ($_FILES['image']['error'] != 0) {
- $error = "Sorry, an error occurred while uploading your file. Try with a smaller one.";
- require("tpl/image/upload.php");
- }
- $origname = strtolower(basename($_FILES['image']['name']));
- if (preg_match("#\.png$#",$origname)) {
- $type = "png";
- } elseif (preg_match("#\.gif$#",$origname)) {
- $type = "gif";
- } elseif (preg_match("#\.jpg$#",$origname) or preg_match("#\.jpeg$#",$origname)) {
- $type = "jpg";
- } else {
- $error = "Sorry, we only accept GIF, PNG and JPEG images.";
- require("tpl/image/upload.php");
- }
- sql("INSERT INTO images(owner, extension, name, upl_date) VALUES(" . $user['id'] . ", '$type', '" . escs($name) . "', NOW())");
- $id = mysql_insert_id();
- $filen = $savedir . $id . "." . $type;
- $minin = $savedir . $id . "-min." . $type;
- if (!copy($_FILES['image']['tmp_name'], $filen)) {
- $error = "An internal error occurred. You might want to try again later.";
- sql("DELETE FROM images WHERE id = $id");
- require("tpl/image/upload.php");
- }
-
- if ($type == "png")
- $source = imagecreatefrompng($filen);
- elseif ($type == "jpg")
- $source = imagecreatefromjpeg($filen);
- elseif ($type == "gif")
- $source = imagecreatefromgif($filen);
- $l = imagesx($source);
- $h = imagesy($source);
- $l2 = $miniature_width;
- $h2 = $l2 * $h / $l;
- $mini = imagecreatetruecolor($l2, $h2);
- imagecopyresampled($mini, $source, 0, 0, 0, 0, $l2, $h2, $l, $h);
- if ($type == "png")
- imagepng($mini, $minin);
- elseif ($type == "jpg")
- imagejpeg($mini, $minin);
- elseif ($type == "gif")
- imagegif($mini, $minin);
- $message = "Your image has been uploaded successfully.";
- require("tpl/image/upload-ok.php");
-} else {
- require("tpl/image/upload.php");
-}
diff --git a/schema.sql b/schema.sql
index 1c858f2..86bbfe6 100644
--- a/schema.sql
+++ b/schema.sql
@@ -1,11 +1,11 @@
-- phpMyAdmin SQL Dump
--- version 3.5.0
+-- version 3.5.1
-- http://www.phpmyadmin.net
--
-- Client: localhost
--- Généré le: Ven 13 Avril 2012 à 19:07
--- Version du serveur: 5.5.22-log
--- Version de PHP: 5.3.10
+-- Généré le: Jeu 21 Juin 2012 à 14:33
+-- Version du serveur: 5.5.25-log
+-- Version de PHP: 5.4.4
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
@@ -35,7 +35,7 @@ CREATE TABLE IF NOT EXISTS `account` (
`reg_date` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -53,7 +53,7 @@ CREATE TABLE IF NOT EXISTS `batches` (
PRIMARY KEY (`id`),
UNIQUE KEY `unique_name` (`list`,`name`),
KEY `list` (`list`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -71,7 +71,7 @@ CREATE TABLE IF NOT EXISTS `batch_review` (
PRIMARY KEY (`id`),
KEY `batch` (`batch`),
KEY `user_idx` (`user`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -87,7 +87,7 @@ CREATE TABLE IF NOT EXISTS `batch_study` (
PRIMARY KEY (`id`),
UNIQUE KEY `batch` (`batch`),
KEY `user_idx` (`user`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -105,7 +105,7 @@ CREATE TABLE IF NOT EXISTS `blog_comments` (
PRIMARY KEY (`id`),
KEY `post` (`post`),
KEY `owner` (`owner`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -124,7 +124,7 @@ CREATE TABLE IF NOT EXISTS `blog_posts` (
PRIMARY KEY (`id`),
KEY `poster` (`owner`),
KEY `draft` (`draft`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -155,7 +155,7 @@ CREATE TABLE IF NOT EXISTS `cards` (
UNIQUE KEY `unique_name` (`deck`,`name`),
UNIQUE KEY `unique_number` (`deck`,`number`),
KEY `deck_idx` (`deck`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -171,7 +171,7 @@ CREATE TABLE IF NOT EXISTS `card_study` (
`next_review` date NOT NULL,
PRIMARY KEY (`id`),
KEY `deck_study` (`deck_study`,`card`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=19 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -188,7 +188,7 @@ CREATE TABLE IF NOT EXISTS `decks` (
PRIMARY KEY (`id`),
UNIQUE KEY `unique_name` (`owner`,`name`),
KEY `owner_idx` (`owner`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -207,15 +207,15 @@ CREATE TABLE IF NOT EXISTS `deck_study` (
UNIQUE KEY `unique_user_deck` (`user`,`deck`),
KEY `user_idx` (`user`),
KEY `deck_idx` (`deck`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=10 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
--- Structure de la table `images`
+-- Structure de la table `files`
--
-CREATE TABLE IF NOT EXISTS `images` (
+CREATE TABLE IF NOT EXISTS `files` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner` int(11) NOT NULL,
`extension` varchar(5) NOT NULL,
@@ -227,15 +227,15 @@ CREATE TABLE IF NOT EXISTS `images` (
PRIMARY KEY (`id`),
KEY `owner` (`owner`),
KEY `folder` (`folder`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
--
--- Structure de la table `img_folders`
+-- Structure de la table `folders`
--
-CREATE TABLE IF NOT EXISTS `img_folders` (
+CREATE TABLE IF NOT EXISTS `folders` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
@@ -244,7 +244,7 @@ CREATE TABLE IF NOT EXISTS `img_folders` (
`public` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `owner` (`owner`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -261,7 +261,7 @@ CREATE TABLE IF NOT EXISTS `lists` (
PRIMARY KEY (`id`),
UNIQUE KEY `unique_name` (`owner`,`name`),
KEY `owner` (`owner`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -277,7 +277,7 @@ CREATE TABLE IF NOT EXISTS `list_study` (
UNIQUE KEY `unique_user_list` (`user`,`list`),
KEY `user` (`user`),
KEY `list_idx` (`list`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- --------------------------------------------------------
@@ -295,7 +295,7 @@ CREATE TABLE IF NOT EXISTS `notes` (
`public` tinyint(1) NOT NULL,
PRIMARY KEY (`id`),
KEY `owner` (`owner`,`parent`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=35 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
diff --git a/tpl/file/folder.php b/tpl/file/folder.php
new file mode 100644
index 0000000..d7ebd73
--- /dev/null
+++ b/tpl/file/folder.php
@@ -0,0 +1,56 @@
+<?php
+require("tpl/general/top.php");
+
+if ($can_edit) {
+ echo '<div class="small_right"><a href="editfld-file-' . $fldid . '">edit folder info</a> | ';
+ echo '<a href="delfld-file-' . $fldid . '">delete folder</a></div>';
+}
+
+echo $fld['comment_html'];
+
+if (count($files) == 0) {
+ echo '<div class="message">This folder has no files.</div>';
+} else {
+ echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+ echo '<table><tr><th width="' . ($img_mini_width) . 'px"></th><th>Info</th><th>Date</th></tr>';
+ foreach ($files as $fl) {
+ $min = $baseurl . $fl['id'] . "-min." . $fl['extension'];
+ $flf = $baseurl . $fl['id'] . "." . $fl['extension'];
+ echo '<tr><td style="text-align: center; vertical-align: middle"><a href="' . $flf . '">';
+ if (has_mini($fl['extension'])) {
+ echo '<img src="' . $min . '" />';
+ } else {
+ echo 'download';
+ }
+ echo '</a></td>';
+ echo '<td><strong>' . $fl['name'] . '</strong>';
+ echo '<br />' . $fl['comment_html'] . '<br />';
+ echo '</td>';
+ echo '<td>' . $fl['upl_date'] . '<br />';
+ if ($can_edit) echo '<br /><a href="delete-file-' . $fl['id'] . '">delete</a>';
+ if ($can_edit) echo '<br /><a href="editinfo-file-' . $fl['id'] . '">edit info</a>';
+ echo '</td></tr>';
+ }
+ echo '</table>';
+}
+
+echo '</div><div class="contents-left">';
+if ($is_owner) {
+ echo '<h1>Your folders</h1>';
+} else {
+ echo '<h1>' . $fld["ownername"] . "'s folders</h1>";
+}
+echo '<ul>';
+foreach ($folders as $f) {
+ if ($f['id'] == $fldid) {
+ echo '<li>' . $f['name'] . '</li>';
+ } else {
+ echo '<li><a href="folder-file-' . $f['id'] . '">' . $f['name'] . '</a></li>';
+ }
+}
+if ($is_owner) {
+ echo '<li><a class="tool_link" href="newfld-file">[+] New folder</a></li>';
+}
+echo '</ul>';
+
+require("tpl/general/bottom.php");
diff --git a/tpl/file/index.php b/tpl/file/index.php
new file mode 100644
index 0000000..dc8cb52
--- /dev/null
+++ b/tpl/file/index.php
@@ -0,0 +1,61 @@
+<?php
+require("tpl/general/top.php");
+
+if (count($files) == 0) {
+ echo '<div class="message">You have uploaded no files yet.</div>';
+} else {
+ echo '<p>You have uploaded ' . count($files) .' files.</p>';
+ echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+ echo '<table><tr><th width="' . ($img_mini_width) . 'px"></th><th>Info</th><th>Date</th></tr>';
+ foreach ($files as $fl) {
+ $min = $baseurl . $fl['id'] . "-min." . $fl['extension'];
+ $flf = $baseurl . $fl['id'] . "." . $fl['extension'];
+ echo '<tr><td style="text-align: center; vertical-align: middle"><a href="' . $flf . '">';
+ if (has_mini($fl['extension'])) {
+ echo '<img src="' . $min . '" />';
+ } else {
+ echo 'download';
+ }
+ echo '</a></td>';
+ echo '<td><strong>' . $fl['name'] . '</strong>';
+ if ($fl['folder_id'] != 0) {
+ echo ' (in folder: <a href="folder-file-' . $fl['folder_id'] . '">' . $fl['folder_name'] . '</a>)';
+ }
+ echo '<br /><strong>MD:</strong> <code>' . (has_mini($fl['extension']) ? '!' : '') . '['.$fl['name'].']('.$flf.')</code>';
+ echo '<br />' . $fl['comment_html'] . '<br />';
+ /*echo '<strong>Miniature:</strong> <a href="' . $min . '">' . $min . '</a><br />';
+ echo '<strong>Image:</strong> <a href="' . $flf . '">' . $flf . '</a><br />'; */
+ echo '</td>';
+ echo '<td>' . $fl['upl_date'] . '<br />';
+ if ($can_delete) echo '<br /><a href="delete-file-' . $fl['id'] . '">delete</a>';
+ if ($can_rename) echo '<br /><a href="editinfo-file-' . $fl['id'] . '">edit info</a>';
+ echo '</td></tr>';
+ }
+ echo '</table>';
+}
+
+if ($can_upload) {
+?>
+</div>
+<div class="contents-left">
+<h1>Upload a file</h1>
+<form method="POST" action="index.php?p=upload-file" enctype="multipart/form-data">
+If you upload an image, a <?php echo $img_mini_width; ?>px preview will be created.<br /><br />
+Title : <input type="text" name="name" style="width: 200px;" ><br />
+<input type="file" name="file" /><br />
+<input type="submit" value="Upload" /></form>
+
+<br /><br />
+<h1>Your folders</h1>
+<ul>
+<?php
+foreach ($folders as $f) {
+ echo '<li><a href="folder-file-' . $f['id'] . '">' . $f['name'] . '</a></li>';
+}
+?>
+<li><a class="tool_link" href="newfld-file">[+] New folder</a></li>
+</ul>
+<?php
+}
+
+require("tpl/general/bottom.php");
diff --git a/tpl/image/upload-ok.php b/tpl/file/upload-ok.php
index 6242d93..a0edee1 100644
--- a/tpl/image/upload-ok.php
+++ b/tpl/file/upload-ok.php
@@ -7,13 +7,13 @@ $imgurl = $baseurl . $id . "." . $type;
?>
<p>Preview : <a href="<?php echo $minurl; ?>"><?php echo $minurl; ?></a><br />
Image : <a href="<?php echo $imgurl; ?>"><?php echo $imgurl; ?></a><br />
- Markdown code : <code>![<?php echo $name; ?>](<?php echo $imgurl; ?>)</code></p>
+ Markdown code : <code><?php echo (has_mini($type) ? '!' : '') . '[' . $name; ?>](<?php echo $imgurl; ?>)</code></p>
<p>
<p>
- <a href="upload-image">Back to upload form</a>
+ <a href="upload-file">Back to upload form</a>
<?php
- if ($user['priv'] >= $apps['image']['index'])
- echo ' - <a href="index-image">back to list of uploaded images</a>';
+ if ($user['priv'] >= $apps['file']['index'])
+ echo ' - <a href="index-file">back to list of uploaded files</a>';
?>
</p>
<?php
diff --git a/tpl/image/upload.php b/tpl/file/upload.php
index 71283cf..31bdda7 100644
--- a/tpl/image/upload.php
+++ b/tpl/file/upload.php
@@ -1,12 +1,12 @@
<?php
-$title = "Upload an image";
+$title = "Upload a file";
-if ($user['id'] == 0) $message = "You should create an account so that you can track images you have uploaded.";
+if ($user['id'] == 0) $message = "You should create an account so that you can track files you have uploaded.";
-$form_message = "A $miniature_width"."px preview will be created.";
+$form_message = "If you upload an image, a $img_mini_width"."px preview will be created.";
$need_file = true;
$fields = array(
- array("label" => "Image file : ", "type" => "file", "name" => "image"),
+ array("label" => "Image file : ", "type" => "file", "name" => "file"),
array("label" => "Image title (optionnal) : ", "type" => "text", "name" => "name")
);
$validate = "Upload";
diff --git a/tpl/general/top.php b/tpl/general/top.php
index 08481fd..e2b168a 100644
--- a/tpl/general/top.php
+++ b/tpl/general/top.php
@@ -34,11 +34,11 @@ if ($user['id'] == 0) {
<?php
if ($user['id'] != 0) {
echo '<a href="study">My studies</a>';
- echo '<a href="image">Uploaded images</a>';
+ echo '<a href="file">Uploaded files</a>';
} else {
echo '<a href="study">Studies</a>';
- if ($user['priv'] >= $apps['image']['upload']) {
- echo '<a href="upload-image">Upload image</a>';
+ if ($user['priv'] >= $apps['file']['upload']) {
+ echo '<a href="upload-file">Upload file</a>';
}
}
?>
diff --git a/tpl/image/folder.php b/tpl/image/folder.php
deleted file mode 100644
index 5d5e57b..0000000
--- a/tpl/image/folder.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-require("tpl/general/top.php");
-
-if ($can_edit) {
- echo '<div class="small_right"><a href="editfld-image-' . $fldid . '">edit folder info</a> | ';
- echo '<a href="delfld-image-' . $fldid . '">delete folder</a></div>';
-}
-
-echo $fld['comment_html'];
-
-if (count($images) == 0) {
- echo '<div class="message">This folder has no images.</div>';
-} else {
- echo '<div class="ordering_links">' . filters_html_full() . '</div>';
- echo '<table><tr><th width="' . ($miniature_width) . 'px">Preview</th><th>Info</th><th>Date</th></tr>';
- foreach ($images as $img) {
- $min = $baseurl . $img['id'] . "-min." . $img['extension'];
- $imgf = $baseurl . $img['id'] . "." . $img['extension'];
- echo '<tr><td><a href="' . $imgf . '"><img src="' . $min . '" /></a></td>';
- echo '<td><strong>' . $img['name'] . '</strong>';
- echo '<br />' . $img['comment_html'] . '<br />';
- /*echo '<strong>Miniature:</strong> <a href="' . $min . '">' . $min . '</a><br />';
- echo '<strong>Image:</strong> <a href="' . $imgf . '">' . $imgf . '</a><br />'; */
- echo '</td>';
- echo '<td>' . $img['upl_date'] . '<br />';
- if ($can_edit) echo '<br /><a href="delete-image-' . $img['id'] . '">delete</a>';
- if ($can_edit) echo '<br /><a href="editinfo-image-' . $img['id'] . '">edit info</a>';
- echo '</td></tr>';
- }
- echo '</table>';
-}
-
-echo '</div><div class="contents-left">';
-if ($is_owner) {
- echo '<h1>Your folders</h1>';
-} else {
- echo '<h1>' . $fld["ownername"] . "'s folders</h1>";
-}
-echo '<ul>';
-foreach ($folders as $f) {
- if ($f['id'] == $fldid) {
- echo '<li>' . $f['name'] . '</li>';
- } else {
- echo '<li><a href="folder-image-' . $f['id'] . '">' . $f['name'] . '</a></li>';
- }
-}
-if ($is_owner) {
- echo '<li><a class="tool_link" href="newfld-image">[+] New folder</a></li>';
-}
-echo '</ul>';
-
-require("tpl/general/bottom.php");
diff --git a/tpl/image/index.php b/tpl/image/index.php
deleted file mode 100644
index a89d024..0000000
--- a/tpl/image/index.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-require("tpl/general/top.php");
-
-if (count($images) == 0) {
- echo '<div class="message">You have uploaded no images yet.</div>';
-} else {
- echo '<p>You have uploaded ' . count($images) .' images.</p>';
- echo '<div class="ordering_links">' . filters_html_full() . '</div>';
- echo '<table><tr><th width="' . ($miniature_width) . 'px">Preview</th><th>Info</th><th>Date</th></tr>';
- foreach ($images as $img) {
- $min = $baseurl . $img['id'] . "-min." . $img['extension'];
- $imgf = $baseurl . $img['id'] . "." . $img['extension'];
- echo '<tr><td><a href="' . $imgf . '"><img src="' . $min . '" /></a></td>';
- echo '<td><strong>' . $img['name'] . '</strong>';
- if ($img['folder_id'] != 0) {
- echo ' (in folder: <a href="folder-image-' . $img['folder_id'] . '">' . $img['folder_name'] . '</a>)';
- }
- echo '<br /><strong>MD:</strong> <code>!['.$img['name'].']('.$imgf.')</code>';
- echo '<br />' . $img['comment_html'] . '<br />';
- /*echo '<strong>Miniature:</strong> <a href="' . $min . '">' . $min . '</a><br />';
- echo '<strong>Image:</strong> <a href="' . $imgf . '">' . $imgf . '</a><br />'; */
- echo '</td>';
- echo '<td>' . $img['upl_date'] . '<br />';
- if ($can_delete) echo '<br /><a href="delete-image-' . $img['id'] . '">delete</a>';
- if ($can_rename) echo '<br /><a href="editinfo-image-' . $img['id'] . '">edit info</a>';
- echo '</td></tr>';
- }
- echo '</table>';
-}
-
-if ($can_upload) {
-?>
-</div>
-<div class="contents-left">
-<h1>Upload an image</h1>
-<form method="POST" action="index.php?p=upload-image" enctype="multipart/form-data">
-A <?php echo $miniature_width; ?>px preview will be created.<br /><br />
-Title : <input type="text" name="name" style="width: 200px;" ><br />
-<input type="file" name="image" /><br />
-<input type="submit" value="Upload" /></form>
-
-<br /><br />
-<h1>Your folders</h1>
-<ul>
-<?php
-foreach ($folders as $f) {
- echo '<li><a href="folder-image-' . $f['id'] . '">' . $f['name'] . '</a></li>';
-}
-?>
-<li><a class="tool_link" href="newfld-image">[+] New folder</a></li>
-</ul>
-<?php
-}
-
-require("tpl/general/bottom.php");