summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2012-03-18 14:08:31 +0100
committerNicolas BERNSTEIN <alexis211@gmail.com>2012-03-18 14:08:31 +0100
commitccff9ce8d8a2818699ce4e20a310986fc95ea022 (patch)
treec585ead91c894c621c73b63bc84012709e795151
parent24547ccec6526fcef3cccb34bc35fb81f31236b3 (diff)
downloadBits-ccff9ce8d8a2818699ce4e20a310986fc95ea022.tar.gz
Bits-ccff9ce8d8a2818699ce4e20a310986fc95ea022.zip
Added a way of classifying images in folders.
-rw-r--r--design/style.css5
-rw-r--r--lib/conf/apps.php6
-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.php14
-rw-r--r--lib/image/newfld.php32
-rw-r--r--lib/image/rename.php32
-rw-r--r--schema.sql29
-rw-r--r--tpl/general/inc_form.php8
-rw-r--r--tpl/image/folder.php52
-rw-r--r--tpl/image/index.php26
13 files changed, 314 insertions, 44 deletions
diff --git a/design/style.css b/design/style.css
index dbb3e91..c3a5314 100644
--- a/design/style.css
+++ b/design/style.css
@@ -124,6 +124,11 @@ iframe, textarea {
width: 300px;
}
+ select {
+ width: 200px;
+ margin-left: 4px;
+ }
+
iframe, textarea {
border: 1px solid #CCC;
width: 98%;
diff --git a/lib/conf/apps.php b/lib/conf/apps.php
index 26de50c..b7f3c9d 100644
--- a/lib/conf/apps.php
+++ b/lib/conf/apps.php
@@ -8,8 +8,12 @@ $apps = array(
"image" => array(
"index" => 1,
"delete" => 1,
- "rename" => 1,
+ "editinfo" => 1,
"upload" => 0,
+ "folder" => 0,
+ "newfld" => 1,
+ "editfld" => 1,
+ "delfld" => 1,
),
// Account application
diff --git a/lib/image/delfld.php b/lib/image/delfld.php
new file mode 100644
index 0000000..a018b7a
--- /dev/null
+++ b/lib/image/delfld.php
@@ -0,0 +1,16 @@
+<?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
new file mode 100644
index 0000000..a0bef1f
--- /dev/null
+++ b/lib/image/editfld.php
@@ -0,0 +1,44 @@
+<?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
new file mode 100644
index 0000000..8223c18
--- /dev/null
+++ b/lib/image/editinfo.php
@@ -0,0 +1,51 @@
+<?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
new file mode 100644
index 0000000..56166d8
--- /dev/null
+++ b/lib/image/folder.php
@@ -0,0 +1,43 @@
+<?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
index 59a304d..b9748dc 100644
--- a/lib/image/index.php
+++ b/lib/image/index.php
@@ -6,6 +6,7 @@ $filters = array (
"order" => array (
"name" => "title",
"upl_date" => "date uploaded",
+ "folder_name" => "folder",
),
"way" => $ord_ways,
);
@@ -17,7 +18,10 @@ $fdefaults = array (
$title = "Image upload";
$images = array();
-$files = sql("SELECT * FROM images WHERE owner = " . $user['id'] .
+$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;
@@ -33,7 +37,13 @@ if ($user['priv'] < $apps['image']['upload']) {
$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']['rename'] && $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
new file mode 100644
index 0000000..63afd17
--- /dev/null
+++ b/lib/image/newfld.php
@@ -0,0 +1,32 @@
+<?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/rename.php b/lib/image/rename.php
deleted file mode 100644
index 0fbc442..0000000
--- a/lib/image/rename.php
+++ /dev/null
@@ -1,32 +0,0 @@
-<?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 * FROM images WHERE id = $id"));
-
-assert_error($info["owner"] == $user["id"], "You cannot rename this image.");
-
-$name = $info['name'];
-if (isset($_POST['name'])) {
- $name = esca($_POST['name']);
- if ($name == "") {
- $error = "You must give a non-empty name to this image. Please.";
- } else {
- sql("UPDATE images SET name = '" . escs($name) . "' WHERE id = $id");
- header("Location: image");
- die();
- }
-}
-
-$title = "Rename : " . $info['name'];
-$fields = array(
- array("label" => "New name : ", "name" => "name", "value" => $name),
-);
-$validate = "Rename";
-
-require("tpl/general/form.php");
diff --git a/schema.sql b/schema.sql
index 7bc67b6..f91acb2 100644
--- a/schema.sql
+++ b/schema.sql
@@ -1,10 +1,10 @@
-- phpMyAdmin SQL Dump
--- version 3.4.9
+-- version 3.4.10.1
-- http://www.phpmyadmin.net
--
-- Client: localhost
--- Généré le : Dim 12 Février 2012 à 19:40
--- Version du serveur: 5.5.20
+-- Généré le : Dim 18 Mars 2012 à 13:58
+-- Version du serveur: 5.5.21
-- Version de PHP: 5.3.10
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
@@ -203,13 +203,34 @@ CREATE TABLE IF NOT EXISTS `images` (
`extension` varchar(5) NOT NULL,
`name` varchar(255) NOT NULL,
`upl_date` date NOT NULL,
+ `folder` int(11) NOT NULL,
+ `comment` text NOT NULL,
+ `comment_html` text NOT NULL,
PRIMARY KEY (`id`),
- KEY `owner` (`owner`)
+ KEY `owner` (`owner`),
+ KEY `folder` (`folder`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
-- --------------------------------------------------------
--
+-- Structure de la table `img_folders`
+--
+
+CREATE TABLE IF NOT EXISTS `img_folders` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `owner` int(11) NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `comment` text NOT NULL,
+ `comment_html` text NOT NULL,
+ `public` tinyint(1) NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `owner` (`owner`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
+
+-- --------------------------------------------------------
+
+--
-- Structure de la table `lists`
--
diff --git a/tpl/general/inc_form.php b/tpl/general/inc_form.php
index 8cd2ad5..24e4a49 100644
--- a/tpl/general/inc_form.php
+++ b/tpl/general/inc_form.php
@@ -13,6 +13,14 @@ foreach($fields as $f) {
if (isset($f['type']) && $f['type'] == 'textarea') {
echo '<label>' . $f['label'] . '</label><br />';
echo '<textarea name="' . $f['name'] . '">' . $f['value'] . '</textarea><br />';
+ } else if (isset($f['type']) && $f['type'] == 'select') {
+ echo '<label>' . $f['label'] . '</label>';
+ echo '<select name="' . $f['name'] . '">';
+ foreach ($f['choices'] as $id => $text) {
+ echo '<option value="' . $id . '"'. ($id == $f['value'] ? ' selected="selected"' : '') .
+ '>' . $text . '</option>';
+ }
+ echo '</select><br />';
} else {
?>
<label for="ff_<?php echo $f['name']; ?>"><?php echo $f['label']; ?></label>
diff --git a/tpl/image/folder.php b/tpl/image/folder.php
new file mode 100644
index 0000000..5d5e57b
--- /dev/null
+++ b/tpl/image/folder.php
@@ -0,0 +1,52 @@
+<?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
index 4f9db8e..a89d024 100644
--- a/tpl/image/index.php
+++ b/tpl/image/index.php
@@ -11,13 +11,18 @@ if (count($images) == 0) {
$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><br /><br />';
- echo '<strong>Miniature:</strong> <a href="' . $min . '">' . $min . '</a><br />';
- echo '<strong>Image:</strong> <a href="' . $imgf . '">' . $imgf . '</a><br />';
- echo '<strong>Markdown:</strong> <code>!['.$img['name'].']('.$imgf.')</code></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="rename-image-' . $img['id'] . '">rename</a>';
+ if ($can_rename) echo '<br /><a href="editinfo-image-' . $img['id'] . '">edit info</a>';
echo '</td></tr>';
}
echo '</table>';
@@ -33,6 +38,17 @@ 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
}