summaryrefslogtreecommitdiff
path: root/lib/image
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 /lib/image
parent5c4caed8560d5fded00525844dfa8386b97e7918 (diff)
downloadBits-889e8eaf7c40817663dd602a21ac771062ccac3b.tar.gz
Bits-889e8eaf7c40817663dd602a21ac771062ccac3b.zip
Big change, sir. Can now upload any kind of files.
Diffstat (limited to 'lib/image')
-rw-r--r--lib/image/delete.php21
-rw-r--r--lib/image/delfld.php16
-rw-r--r--lib/image/editfld.php44
-rw-r--r--lib/image/editinfo.php51
-rw-r--r--lib/image/folder.php43
-rw-r--r--lib/image/index.php49
-rw-r--r--lib/image/newfld.php32
-rw-r--r--lib/image/upload.php63
8 files changed, 0 insertions, 319 deletions
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/delfld.php b/lib/image/delfld.php
deleted file mode 100644
index a018b7a..0000000
--- a/lib/image/delfld.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-assert_redir(count($args) >= 3, 'image');
-$fldid = intval($args[2]);
-
-$fld = mysql_fetch_assoc(sql(
- "SELECT id, name, comment, public, owner ".
- "FROM img_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");
diff --git a/lib/image/editfld.php b/lib/image/editfld.php
deleted file mode 100644
index a0bef1f..0000000
--- a/lib/image/editfld.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-require("lib/markdown.php");
-
-assert_redir(count($args) == 3, 'image');
-$fldid = intval($args[2]);
-
-$fld = mysql_fetch_assoc(sql(
- "SELECT id, name, comment, public, owner ".
- "FROM img_folders WHERE id = $fldid"
- ));
-assert_error($fld && $fld['owner'] == $user['id'],
- "This folder does not exist, or you are not allowed to edit it.");
-
-$fld_name = $fld['name'];
-$fld_comment = $fld['comment'];
-$fld_public = $fld['public'];
-if (isset($_POST['name']) && isset($_POST['comment'])) {
- $fld_public = isset($_POST['public']);
- $fld_name = esca($_POST['name']);
- $fld_comment = esca($_POST['comment']);
- $fld_comment_html = Markdown($fld_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) .
- "', comment_html = '" . escs($fld_comment_html) . "', public = " . ($fld_public?'1':'0') .
- " WHERE id = $fldid");
- header("Location: folder-image-" . $fldid);
- die();
- }
-
-}
-
-$title = "Edit folder";
-$fields = array(
- array("label" => "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),
- );
-$validate = "Save";
-
-require("tpl/general/form.php");
-
diff --git a/lib/image/editinfo.php b/lib/image/editinfo.php
deleted file mode 100644
index 8223c18..0000000
--- a/lib/image/editinfo.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-
-require("lib/markdown.php");
-
-require("lib/conf/image.php");
-
-$title = "Rename an image";
-
-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"
-));
-
-assert_error($info["owner"] == $user["id"], "You cannot rename this image.");
-
-$name = $info['name'];
-$comment = $info['comment'];
-$folder = $info['folder_id'];
-if (isset($_POST['name']) && isset($_POST['comment']) && isset($_POST['folder'])) {
- $name = esca($_POST['name']);
- $comment = esca($_POST['comment']);
- $comment_html = Markdown($comment);
- $folder = intval($_POST['folder']);
- if ($name == "") {
- $error = "You must give a non-empty name to this image. Please.";
- } else {
- sql("UPDATE images SET name = '" . escs($name) . "', comment='" . escs($comment). "',
- comment_html = '" . escs($comment_html) . "', folder = $folder WHERE id = $id");
- header("Location: image");
- die();
- }
-}
-
-$folders = array(0 => "[no folder]");
-$r = sql("SELECT id, name FROM img_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'];
-$fields = array(
- array("label" => "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"),
-);
-$validate = "Save";
-
-require("tpl/general/form.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/newfld.php b/lib/image/newfld.php
deleted file mode 100644
index 63afd17..0000000
--- a/lib/image/newfld.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?php
-
-require("lib/markdown.php");
-
-$fld_name = "";
-$fld_comment = "";
-$fld_public = true;
-if (isset($_POST['name']) && isset($_POST['comment'])) {
- $fld_public = isset($_POST['public']);
- $fld_name = esca($_POST['name']);
- $fld_comment = esca($_POST['comment']);
- $fld_comment_html = Markdown($fld_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) ".
- "VALUES(" . $user['id'] . ", '" . escs($fld_name) . "', '" . escs($fld_comment) .
- "', '" . escs($fld_comment_html) . "', " . ($fld_public ? '1' : '0') . ")");
- header("Location: folder-image-" . mysql_insert_id());
- die();
- }
-}
-
-$title = "New folder";
-$fields = array(
- array("label" => "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),
- );
-$validate = "Create folder";
-
-require("tpl/general/form.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");
-}