summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas BERNSTEIN <alexis211@gmail.com>2012-02-12 19:50:55 +0100
committerNicolas BERNSTEIN <alexis211@gmail.com>2012-02-12 19:50:55 +0100
commit24547ccec6526fcef3cccb34bc35fb81f31236b3 (patch)
treefc908fb06a6b8b4d4131c7303c4fb3b7d348f9bf
parentcd76af42463bd80539db8c9671a427a9f0fe5d69 (diff)
downloadBits-24547ccec6526fcef3cccb34bc35fb81f31236b3.tar.gz
Bits-24547ccec6526fcef3cccb34bc35fb81f31236b3.zip
A lot of changes : blogging system essentially.
-rw-r--r--design/style.css28
-rw-r--r--lib/account/list.php23
-rw-r--r--lib/account/new.php10
-rw-r--r--lib/blog/delete.php13
-rw-r--r--lib/blog/drafts.php19
-rw-r--r--lib/blog/edit.php61
-rw-r--r--lib/blog/index.php72
-rw-r--r--lib/blog/post.php44
-rw-r--r--lib/blog/publish.php13
-rw-r--r--lib/conf/apps.php18
-rw-r--r--lib/conf/image.php4
-rw-r--r--lib/image/index.php22
-rw-r--r--lib/image/rename.php32
-rw-r--r--lib/image/upload.php8
-rw-r--r--lib/notes/index.php21
-rw-r--r--lib/study/index.php4
-rw-r--r--schema.sql47
-rw-r--r--tpl/account/list.php21
-rw-r--r--tpl/blog/drafts.php41
-rw-r--r--tpl/blog/index.php53
-rw-r--r--tpl/general/top.php9
-rw-r--r--tpl/image/index.php23
-rw-r--r--tpl/image/upload-ok.php11
-rw-r--r--tpl/image/upload.php3
-rw-r--r--tpl/notes/index.php13
-rw-r--r--tpl/study/index.php4
26 files changed, 549 insertions, 68 deletions
diff --git a/design/style.css b/design/style.css
index 2d41f57..dbb3e91 100644
--- a/design/style.css
+++ b/design/style.css
@@ -171,6 +171,7 @@ iframe, textarea {
}
.small_right {
+ clear: right;
float: right;
}
@@ -262,3 +263,30 @@ hr {
border-left: 1px solid #0000FF;
border-bottom: 1px solid #0000FF;
}
+
+
+/* blog */
+
+.blog_post {
+ margin: 4px;
+ margin-top: 16px;
+ border-left: 1px solid #ccc;
+ border-bottom: 1px dashed #ccc;
+ padding: 8px;
+ padding-top: 16px;
+}
+
+.blog_post .inside {
+ /*clear: right;
+ padding-top: 1px;*/
+}
+.blog_post .small_right {
+ margin-left: 100px;
+}
+
+.blog_post h2 {
+ margin: 0px;
+ padding: 0px;
+ margin-left: 16px;
+ font-size: 1.2em;
+}
diff --git a/lib/account/list.php b/lib/account/list.php
new file mode 100644
index 0000000..dcb6575
--- /dev/null
+++ b/lib/account/list.php
@@ -0,0 +1,23 @@
+<?php
+
+$filters = array (
+ "order" => array (
+ "name" => "username",
+ "reg_date" => "date registered",
+ "nbNotes" => "number of notes",
+ ),
+ "way" => $ord_ways,
+);
+$fdefaults = array (
+ "order" => "name",
+ "way" => "ASC",
+);
+
+$users = array();
+$n = sql("SELECT account.id AS id, login AS name, nc.count AS nbNotes, pc.count AS nbPosts ".
+ "FROM account ".
+ "LEFT JOIN (SELECT notes.owner AS owner, COUNT(notes.id) AS count FROM notes WHERE notes.public != 0 GROUP BY notes.owner) nc ON nc.owner = account.id ".
+ "LEFT JOIN (SELECT blog_posts.owner AS owner, COUNT(blog_posts.id) AS count FROM blog_posts GROUP BY blog_posts.owner) pc ON pc.owner = account.id ".
+ "ORDER BY " . get_filter("order") . " " . get_filter("way"));
+while ($nn = mysql_fetch_assoc($n)) $users[] = $nn;
+require("tpl/account/list.php");
diff --git a/lib/account/new.php b/lib/account/new.php
index c06083e..2366fbb 100644
--- a/lib/account/new.php
+++ b/lib/account/new.php
@@ -3,18 +3,23 @@
$title = "Register";
$login = "";
+$email = "";
if (isset($_POST['login']) && isset($_POST['pw1']) && isset($_POST['pw2'])) {
$login = esca($_POST["login"]);
+ $email = esca($_POST["email"]);
$pw1 = esc($_POST["pw1"]);
$pw2 = esc($_POST["pw2"]);
if ($login == "") {
$error = "You must enter a username.";
+ } else if (!preg_match('#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$#', $email)) {
+ $error = "You must enter a valid email address.";
} else if ($pw1 != $pw2) {
$error = "You must enter twice the same password.";
} else if ($pw1 == "") {
$error = "You must enter a password";
} else {
- sql("INSERT INTO account(login, password) VALUES('" . escs($login) . "', PASSWORD('$pw1'))");
+ sql("INSERT INTO account(login, password, email, reg_date) ".
+ "VALUES('" . escs($login) . "', PASSWORD('$pw1'), '" . escs($email) . "', NOW())");
$message = "Your account has been created. Please log in now.";
$url = $homepage;
require("tpl/account/login.php");
@@ -25,7 +30,8 @@ $form_message = "Please fill in the following form to create an account :";
$fields = array(
array("label" => "Username : ", "name" => "login", "value" => $login),
array("label" => "Password : ", "name" => "pw1", "type" => "password"),
- array("label" => "Confirm password : ", "name" => "pw2", "type" => "password")
+ array("label" => "Confirm password : ", "name" => "pw2", "type" => "password"),
+ array("label" => "Email address : ", "name" => "email", "value" => $email)
);
$validate = "Create an account";
diff --git a/lib/blog/delete.php b/lib/blog/delete.php
new file mode 100644
index 0000000..a57b5ac
--- /dev/null
+++ b/lib/blog/delete.php
@@ -0,0 +1,13 @@
+<?php
+
+assert_redir(count($args) >= 3, 'blog');
+$postid = intval($args[2]);
+
+$post = mysql_fetch_assoc(sql("SELECT owner FROM blog_posts WHERE id = $postid"));
+assert_error($post && $post['owner'] == $user['id'],
+ "This note does not exist, or you are not allowed to delete it.");
+
+token_validate("Do you really want to delete this post ?", "blog");
+sql("DELETE FROM blog_posts WHERE id = $postid");
+sql("DELETE FROM blog_tags WHERE post = $postid");
+header("Location: drafts-blog");
diff --git a/lib/blog/drafts.php b/lib/blog/drafts.php
new file mode 100644
index 0000000..735b039
--- /dev/null
+++ b/lib/blog/drafts.php
@@ -0,0 +1,19 @@
+<?php
+
+$title = "My posts";
+
+$drafts = array();
+$pub = array();
+
+$r = sql(
+ "SELECT id, title, text_html, draft FROM blog_posts WHERE owner = " . $user['id'] . " ORDER BY date DESC"
+ );
+while ($pp = mysql_fetch_assoc($r)) {
+ if ($pp['draft']) {
+ $drafts[] = $pp;
+ } else {
+ $pub[] = $pp;
+ }
+}
+
+require("tpl/blog/drafts.php");
diff --git a/lib/blog/edit.php b/lib/blog/edit.php
new file mode 100644
index 0000000..854c94f
--- /dev/null
+++ b/lib/blog/edit.php
@@ -0,0 +1,61 @@
+<?php
+
+require("lib/markdown.php");
+
+assert_redir(count($args) == 3, 'blog');
+$postid = intval($args[2]);
+
+$post = mysql_fetch_assoc(sql(
+ "SELECT blog_posts.title AS title, blog_posts.text AS text, blog_posts.owner AS owner, blog_posts.draft AS draft, ".
+ "GROUP_CONCAT(blog_tags.tag SEPARATOR ' ') AS tags ".
+ "FROM blog_posts LEFT JOIN blog_tags ON blog_tags.post = blog_posts.id ".
+ "WHERE id = $postid"
+));
+assert_error($post && $post['owner'] == $user['id'],
+ "This post does not exist, or you are not allowed to edit it.");
+
+$post_title = $post['title'];
+$post_tags = $post['tags'];
+$post_text = $post['text'];
+if (isset($_POST['title']) && isset($_POST['tags']) && isset($_POST['text'])) {
+ $post_title = esca($_POST['title']);
+ $post_text = esca($_POST['text']);
+ $post_html = Markdown($post_text);
+ $post_tags = esca($_POST['tags']);
+ if ($post_title == "") {
+ $error = "You must give a title to your post.";
+ } else {
+ sql("UPDATE blog_posts SET title = '" . escs($post_title) . "', text = '" . escs($post_text) .
+ "', text_html = '" . escs($post_html) . "'" . ($post['draft'] ? ', date = NOW()' : '') .
+ " WHERE id = $postid");
+ sql("DELETE FROM blog_tags WHERE post = $postid");
+ $tags = explode(' ', $post_tags);
+ if (count($tags) == 1 && $tags[0] == "") {
+ //do nothing lol
+ } else if (count($tags) >= 1) {
+ $v = array();
+ foreach ($tags as $tag) {
+ $v[] = "($postid, '" . escs($tag) . "')";
+ }
+ sql("INSERT INTO blog_tags(post, tag) VALUES " . implode(',', $v));
+ }
+ if ($post['draft']) {
+ header("Location: drafts-blog");
+ } else {
+ header("Location: blog");
+ }
+ die();
+ }
+}
+
+$title = "Edit : " . $post['title'];
+$fields = array(
+ array("label" => "Title : ", "name" => "title", "value" => $post_title),
+ array("label" => "Tags : ", "name" => "tags", "type" => "text", "value" => $post_tags),
+ array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $post_text),
+ );
+$validate = "Edit post";
+
+require("tpl/general/form.php");
+
+
diff --git a/lib/blog/index.php b/lib/blog/index.php
new file mode 100644
index 0000000..aaeb969
--- /dev/null
+++ b/lib/blog/index.php
@@ -0,0 +1,72 @@
+<?php
+
+$title = "What people write";
+
+$filters = array (
+ "order" => array (
+ "title" => "title",
+ "owner" => "author name",
+ "date" => "date published",
+ ),
+ "way" => $ord_ways,
+);
+$fdefaults = array (
+ "order" => "date",
+ "way" => "DESC",
+);
+
+$posts = array();
+
+$fa = array (
+ "author" => array(),
+ "date" => array(),
+ "tag" => array(),
+);
+$fvalues = array();
+for ($i = 2; $i < count($args); $i += 2) {
+ if (isset($args[$i+1])) {
+ $fvalues[$args[$i]] = urldecode($args[$i+1]);
+ }
+}
+function count_in($fat, $v, $d) {
+ global $fa;
+ if (isset($fa[$fat][$v])) {
+ $fa[$fat][$v]['count']++;
+ } else {
+ $fa[$fat][$v] = array('name' => $d, 'count' => 1);
+ }
+}
+
+$q =
+ "SELECT blog_posts.id AS id, blog_posts.title AS title, blog_posts.date AS date, ".
+ "DATE_FORMAT(blog_posts.date, '%Y-%m') AS month, ".
+ "blog_posts.text_html AS text_html, GROUP_CONCAT(ba.tag SEPARATOR ', ') AS tags, ".
+ "account.login AS owner, account.id AS owner_id ".
+ "FROM blog_posts LEFT JOIN account ON blog_posts.owner = account.id ".
+ "LEFT JOIN blog_tags ba ON ba.post = blog_posts.id ".
+ (isset($fvalues['tag']) ? "LEFT JOIN blog_tags bb ON bb.post = blog_posts.id AND bb.tag = '" . escs($fvalues['tag'])."' " : "").
+ "WHERE blog_posts.draft = 0 ".
+ (isset($fvalues['author']) ? 'AND blog_posts.owner = ' . intval($fvalues['author']) .' ' : '').
+ (isset($fvalues['date']) ? "AND blog_posts.date >= '" . escs(str_replace('.', '-', $fvalues['date'])) ."-01 00:00:00' " .
+ "AND blog_posts.date <= '" . escs(str_replace('.', '-', $fvalues['date'])) . "-31 23:59:59'" : '').
+ (isset($fvalues['tag']) ? " AND bb.post != 0 " : "").
+ "GROUP BY blog_posts.id ".
+ "ORDER BY " . get_filter('order') . " " . get_filter('way');
+$n = sql($q);
+
+
+while ($pp = mysql_fetch_assoc($n)) {
+ $posts[] = $pp;
+ count_in('author', $pp['owner_id'], $pp['owner']);
+ $tags = explode(', ', $pp['tags']);
+ foreach ($tags as $tag) {
+ count_in('tag', $tag, $tag);
+ }
+ count_in('date', str_replace('-', '.', $pp['month']), $pp['month']);
+}
+
+$can_post = ($user['priv'] >= $apps['blog']['drafts'] && $user['id'] != 0);
+$can_edit = ($user['priv'] >= $apps['blog']['edit'] && $user['id'] != 0);
+$can_delete = ($user['priv'] >= $apps['blog']['delete'] && $user['id'] != 0);
+
+require("tpl/blog/index.php");
diff --git a/lib/blog/post.php b/lib/blog/post.php
new file mode 100644
index 0000000..1f1525a
--- /dev/null
+++ b/lib/blog/post.php
@@ -0,0 +1,44 @@
+<?php
+
+require("lib/markdown.php");
+
+$post_title = "";
+$post_tags = "";
+$post_text = "";
+if (isset($_POST['title']) && isset($_POST['text'])) {
+ $post_title = esca($_POST['title']);
+ $post_text = esca($_POST['text']);
+ $post_tags = esca($_POST['tags']);
+ $post_html = Markdown($post_text);
+
+ if ($post_title == "") {
+ $error = "You must give a title to your post.";
+ } else {
+ sql("INSERT INTO blog_posts(owner, title, text, text_html, date, draft) ".
+ "VALUE(" . $user['id'] . ", '" . escs($post_title) . "', '" . escs($post_text) . "', '" . escs($post_html) .
+ "', NOW(), 1)");
+ $id = mysql_insert_id();
+ $tags = explode(' ', $post_tags);
+ if (count($tags) == 1 && $tags[0] == "") {
+ //do nothing lol
+ } else if (count($tags) >= 1) {
+ $v = array();
+ foreach ($tags as $tag) {
+ $v[] = "($id, '" . escs($tag) . "')";
+ }
+ sql("INSERT INTO blog_tags(post, tag) VALUES " . implode(',', $v));
+ }
+ header("Location: drafts-blog");
+ die();
+ }
+}
+
+$title = "Post to blog";
+$fields = array(
+ array("label" => "Title : ", "name" => "title", "value" => $post_title),
+ array("label" => "Tags ", "name" => "tags", "type" => "text", "value" => $post_tags),
+ array("label" => "Text : ", "name" => "text", "type" => "textarea", "value" => $post_text),
+ );
+$validate = "Post entry";
+
+require("tpl/general/form.php");
diff --git a/lib/blog/publish.php b/lib/blog/publish.php
new file mode 100644
index 0000000..1674911
--- /dev/null
+++ b/lib/blog/publish.php
@@ -0,0 +1,13 @@
+<?php
+
+assert_redir(count($args) >= 3, 'blog');
+$postid = intval($args[2]);
+
+$post = mysql_fetch_assoc(sql("SELECT owner, draft FROM blog_posts WHERE id = $postid"));
+assert_error($post && $post['owner'] == $user['id'],
+ "This note does not exist, or you are not allowed to delete it.");
+assert_error($post['draft'] == 1, "This post is already published.");
+
+token_validate("Are you sure this post is ready to be published ?", "blog");
+sql("UPDATE blog_posts SET draft = 0, date = NOW() WHERE id = $postid");
+header("Location: blog");
diff --git a/lib/conf/apps.php b/lib/conf/apps.php
index d8cb1c2..26de50c 100644
--- a/lib/conf/apps.php
+++ b/lib/conf/apps.php
@@ -1,6 +1,6 @@
<?php
-$homepage = "notes";
+$homepage = "blog";
$apps = array(
@@ -8,17 +8,19 @@ $apps = array(
"image" => array(
"index" => 1,
"delete" => 1,
+ "rename" => 1,
"upload" => 0,
),
// Account application
"account" => array(
"new" => 0,
+ "list" => 0,
),
// Notebook application
"notes" => array(
- "index" => 0,
+ //"index" => 0,
"user" => 0,
"view" => 0,
"new" => 1,
@@ -28,6 +30,16 @@ $apps = array(
"source" => 0,
),
+ // Blogging application
+ "blog" => array(
+ "index" => 0,
+ "drafts" => 1,
+ "publish" => 1,
+ "post" => 1,
+ "edit" => 1,
+ "delete" => 1,
+ ),
+
// Studies application
"deck" => array(
"index" => 0,
@@ -52,7 +64,7 @@ $apps = array(
),
"study" => array (
- "index" => 1,
+ "index" => 0,
"deckadd" => 1,
"deck" => 1,
"deckrm" => 1,
diff --git a/lib/conf/image.php b/lib/conf/image.php
index 8fd48ec..462300e 100644
--- a/lib/conf/image.php
+++ b/lib/conf/image.php
@@ -3,5 +3,5 @@
$baseurl = "http://localhost/alex.auvolat/images/";
$savedir = getcwd() . "/images/";
$miniature_width = 127;
-$quota = ceil((time() - 1220000000) / (3600 * 24 * 20));
-$min_priv_for_no_quota = 2;
+//$quota = 128;; //ceil((time() - 1220000000) / (3600 * 24 * 20));
+//$min_priv_for_no_quota = 2;
diff --git a/lib/image/index.php b/lib/image/index.php
index 01c0928..59a304d 100644
--- a/lib/image/index.php
+++ b/lib/image/index.php
@@ -2,16 +2,31 @@
require("lib/conf/image.php");
+$filters = array (
+ "order" => array (
+ "name" => "title",
+ "upl_date" => "date uploaded",
+ ),
+ "way" => $ord_ways,
+);
+$fdefaults = array (
+ "order" => "name",
+ "way" => "ASC",
+);
+
$title = "Image upload";
$images = array();
-$files = sql("SELECT * FROM images WHERE owner = " . $user['id']);
+$files = sql("SELECT * FROM images WHERE 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) {
+/*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']) {
+} else */
+
+if ($user['priv'] < $apps['image']['upload']) {
$error = "You don't have the rights to upload images.";
$can_upload = false;
} else {
@@ -19,5 +34,6 @@ if (count($images) >= $quota && $user['priv'] < $min_priv_for_no_quota) {
}
$can_delete = ($user['priv'] >= $apps['image']['delete'] && $user['id'] != 0);
+$can_rename = ($user['priv'] >= $apps['image']['rename'] && $user['id'] != 0);
require("tpl/image/index.php");
diff --git a/lib/image/rename.php b/lib/image/rename.php
new file mode 100644
index 0000000..0fbc442
--- /dev/null
+++ b/lib/image/rename.php
@@ -0,0 +1,32 @@
+<?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/lib/image/upload.php b/lib/image/upload.php
index 812295f..5176a3a 100644
--- a/lib/image/upload.php
+++ b/lib/image/upload.php
@@ -4,11 +4,15 @@ $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'])) {
+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");
@@ -24,7 +28,7 @@ if (isset($_FILES['image'])) {
$error = "Sorry, we only accept GIF, PNG and JPEG images.";
require("tpl/image/upload.php");
}
- sql("INSERT INTO images(owner, extension) VALUES(" . $user['id'] . ", '$type')");
+ 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;
diff --git a/lib/notes/index.php b/lib/notes/index.php
deleted file mode 100644
index 3089605..0000000
--- a/lib/notes/index.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-$filters = array (
- "order" => array (
- "nbNotes" => "number of notes",
- "name" => "username",
- ),
- "way" => $ord_ways,
-);
-$fdefaults = array (
- "order" => "nbNotes",
- "way" => "DESC",
-);
-
-$users = array();
-$n = sql("SELECT account.id AS id, login AS name, COUNT(notes.id) AS nbNotes FROM account ".
- "LEFT JOIN notes ON notes.owner = account.id ".
- "WHERE notes.public != 0 AND notes.id != 0 ".
- "GROUP BY account.id ORDER BY " . get_filter("order") . " " . get_filter("way"));
-while ($nn = mysql_fetch_assoc($n)) $users[] = $nn;
-require("tpl/notes/index.php");
diff --git a/lib/study/index.php b/lib/study/index.php
index e6cec20..6b43d53 100644
--- a/lib/study/index.php
+++ b/lib/study/index.php
@@ -1,3 +1,7 @@
<?php
+if ($user['id'] == 0) {
+ $message = "You must create an account to use this study program.";
+}
+
require("tpl/study/index.php");
diff --git a/schema.sql b/schema.sql
index 1c4f0c2..7bc67b6 100644
--- a/schema.sql
+++ b/schema.sql
@@ -1,11 +1,11 @@
-- phpMyAdmin SQL Dump
--- version 3.4.7.1
+-- version 3.4.9
-- http://www.phpmyadmin.net
--
-- Client: localhost
--- Généré le : Dim 20 Novembre 2011 à 13:31
--- Version du serveur: 5.5.17
--- Version de PHP: 5.3.8
+-- Généré le : Dim 12 Février 2012 à 19:40
+-- Version du serveur: 5.5.20
+-- Version de PHP: 5.3.10
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
@@ -31,6 +31,8 @@ CREATE TABLE IF NOT EXISTS `account` (
`login` varchar(255) NOT NULL,
`password` varchar(100) NOT NULL,
`priv` int(11) NOT NULL DEFAULT '1',
+ `email` varchar(255) NOT NULL,
+ `reg_date` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `login` (`login`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
@@ -90,6 +92,37 @@ CREATE TABLE IF NOT EXISTS `batch_study` (
-- --------------------------------------------------------
--
+-- Structure de la table `blog_posts`
+--
+
+CREATE TABLE IF NOT EXISTS `blog_posts` (
+ `id` int(11) NOT NULL AUTO_INCREMENT,
+ `title` varchar(255) NOT NULL,
+ `owner` int(11) NOT NULL,
+ `text` text NOT NULL,
+ `text_html` text NOT NULL,
+ `date` datetime NOT NULL,
+ `draft` tinyint(4) NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `poster` (`owner`),
+ KEY `draft` (`draft`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=5 ;
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `blog_tags`
+--
+
+CREATE TABLE IF NOT EXISTS `blog_tags` (
+ `post` int(11) NOT NULL,
+ `tag` varchar(255) NOT NULL,
+ KEY `post` (`post`,`tag`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- --------------------------------------------------------
+
+--
-- Structure de la table `cards`
--
@@ -168,9 +201,11 @@ CREATE TABLE IF NOT EXISTS `images` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`owner` int(11) NOT NULL,
`extension` varchar(5) NOT NULL,
+ `name` varchar(255) NOT NULL,
+ `upl_date` date NOT NULL,
PRIMARY KEY (`id`),
KEY `owner` (`owner`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=9 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ;
-- --------------------------------------------------------
@@ -221,7 +256,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=34 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=35 ;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
diff --git a/tpl/account/list.php b/tpl/account/list.php
new file mode 100644
index 0000000..398ac99
--- /dev/null
+++ b/tpl/account/list.php
@@ -0,0 +1,21 @@
+<?php
+$title = "People";
+require("tpl/general/top.php");
+
+echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+
+echo "<table>";
+echo "<tr><th>Username</th><th>Notebook</th><th>Blog</th></tr>";
+foreach($users as $u) {
+ echo '<tr><td>' . $u['name'] . '</td>';
+ echo '<td><a href="user-notes-' . $u['id'] . '">' . $u['nbNotes'] . ' notes</a></td>';
+ if ($u['nbPosts'] > 0) {
+ echo '<td><a href="index-blog-author-'.$u['id'].'">' . $u['nbPosts'] . ' posts</a></td>';
+ } else {
+ echo '<td>no posts</td>';
+ }
+ echo '</tr>';
+}
+echo "</table>";
+
+require("tpl/general/bottom.php");
diff --git a/tpl/blog/drafts.php b/tpl/blog/drafts.php
new file mode 100644
index 0000000..5440cbc
--- /dev/null
+++ b/tpl/blog/drafts.php
@@ -0,0 +1,41 @@
+<?php
+
+require("tpl/general/top.php");
+
+echo '<div class="small_right">';
+echo '<a href="post-blog">post a message</a></div>';
+
+echo '<h2>My drafts</h2>';
+
+if (count($drafts) > 0) {
+ foreach ($drafts as $post) {
+ echo '<div class="blog_post">';
+ echo '<div class="small_right">';
+ echo '<a href="edit-blog-' . $post['id'] . '">edit</a>';
+ echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a>';
+ echo ' | <a href="publish-blog-' . $post['id'] . '">publish</a>';
+ echo '</div>';
+ echo '<h2>' . $post['title'] . '</h2>';
+ echo $post['text_html'];
+ echo '</div>';
+ }
+} else {
+ echo '<p>No drafts</p>';
+}
+
+echo '<h2>My published posts</h2>';
+
+if (count($pub) > 0) {
+ echo '<table><tr><th>Title</th><th>Actions</th></tr>';
+ foreach ($pub as $post) {
+ echo '<tr><td>' . $post['title'] . '</td>';
+ echo '<td><a href="edit-blog-' . $post['id'] . '">edit</a>';
+ echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a></td></tr>';
+ }
+ echo '</table>';
+} else {
+ echo '<p>No published posts</p>';
+}
+
+
+require("tpl/general/bottom.php");
diff --git a/tpl/blog/index.php b/tpl/blog/index.php
new file mode 100644
index 0000000..07e3388
--- /dev/null
+++ b/tpl/blog/index.php
@@ -0,0 +1,53 @@
+<?php
+require("tpl/general/top.php");
+
+if ($can_post) {
+ echo '<div class="small_right">';
+ echo '<a href="post-blog">post a message</a>';
+ echo ' | <a href="drafts-blog">my drafts</a>';
+ echo '</div>';
+}
+
+echo '<div class="ordering_links">' . filters_html_full() . '</div>';
+
+foreach ($posts as $post) {
+ echo '<div class="blog_post">';
+ echo '<div class="small_right">Written by ' . $post['owner'];
+ if ($can_edit && $post['owner_id'] == $user['id'])
+ echo ' | <a href="edit-blog-' . $post['id'] . '">edit</a>';
+ if ($can_delete && $post['owner_id'] == $user['id'])
+ echo ' | <a href="delete-blog-' . $post['id'] . '">delete</a>';
+ echo '</div>';
+ echo '<div class="small_right">published ' . $post['date'] . '</div>';
+ if ($post['tags'] != '') {
+ echo '<div class="small_right">tags: ' . $post['tags'] . '</div>';
+ }
+ echo '<h2>' . $post['title'] . '</h2>';
+ echo '<div class="inside">' . $post['text_html'] . '</div>';
+ echo '</div>';
+}
+
+echo '</div><div class="contents-left">';
+
+foreach ($fa as $kname => $kdata) {
+ echo '<h1>Filter by ' . $kname . '</h1>';
+ if (isset($fvalues[$kname])) {
+ echo '<p>Filtering ' . $kname . ' : ' . $kdata[$fvalues[$kname]]['name'] . '.<br />';
+ $n = array();
+ foreach ($fvalues as $k => $v) {
+ if ($k != $kname) $n[] = "$k-$v";
+ }
+ echo '<a href="index-blog-' . implode('-', $n) . '">remove filtering</a></p>';
+ } else {
+ echo '<ul>';
+ foreach ($kdata as $vid => $vdata) {
+ $n = array();
+ foreach ($fvalues as $k => $v) $n[] = "$k-$v";
+ $n[] = "$kname-$vid";
+ echo '<li><a href="index-blog-' . implode('-', $n) . '">' . $vdata['name'] . ' (' . $vdata['count'] . ')</a></li>';
+ }
+ echo '</ul>';
+ }
+}
+
+require("tpl/general/bottom.php");
diff --git a/tpl/general/top.php b/tpl/general/top.php
index 2ddc84e..08481fd 100644
--- a/tpl/general/top.php
+++ b/tpl/general/top.php
@@ -29,16 +29,17 @@ if ($user['id'] == 0) {
?>
</div>
<div class="left">
- <a href="notes">Notebooks</a>
+ <a href="blog">Home</a>
+ <a href="list-account">People</a>
<?php
if ($user['id'] != 0) {
- echo '<a href="image">Uploaded images</a><a href="study">My studies</a>';
+ echo '<a href="study">My studies</a>';
+ echo '<a href="image">Uploaded images</a>';
} else {
+ echo '<a href="study">Studies</a>';
if ($user['priv'] >= $apps['image']['upload']) {
echo '<a href="upload-image">Upload image</a>';
}
- echo '<a href="deck">Study decks</a>';
- echo '<a href="list">Study lists</a>';
}
?>
</div>
diff --git a/tpl/image/index.php b/tpl/image/index.php
index 0f76abe..4f9db8e 100644
--- a/tpl/image/index.php
+++ b/tpl/image/index.php
@@ -1,20 +1,24 @@
<?php
require("tpl/general/top.php");
-echo '<h2>Images you have uploaded</h2>';
-
if (count($images) == 0) {
echo '<div class="message">You have uploaded no images yet.</div>';
} else {
-echo '<table><tr><th width="' . ($miniature_width) . 'px">Preview</th><th>Files</th></tr>';
+ 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><img src="' . $min . '" /></td>';
- echo '<td><strong>Miniature:</strong> <a href="' . $min . '">' . $min . '</a><br />';
- echo '<strong>Image:</strong> <a href="' . $imgf . '">' . $imgf . '</a>';
- if ($can_delete) echo '<br /><a href="delete-image-' . $img['id'] . '">Delete this image</a>';
- echo '</td>';
+ 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>' . $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>';
+ echo '</td></tr>';
}
echo '</table>';
}
@@ -25,7 +29,8 @@ if ($can_upload) {
<div class="contents-left">
<h1>Upload an image</h1>
<form method="POST" action="index.php?p=upload-image" enctype="multipart/form-data">
-<strong>A <?php echo $miniature_width; ?>px preview will be created.</strong><br /><br />
+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>
<?php
diff --git a/tpl/image/upload-ok.php b/tpl/image/upload-ok.php
index 1cd588c..6242d93 100644
--- a/tpl/image/upload-ok.php
+++ b/tpl/image/upload-ok.php
@@ -5,8 +5,17 @@ $minurl = $baseurl . $id . "-min." . $type;
$imgurl = $baseurl . $id . "." . $type;
?>
- Preview : <a href="<?php echo $minurl; ?>"><?php echo $minurl; ?></a><br />
+ <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>
+ <p>
+ <p>
+ <a href="upload-image">Back to upload form</a>
+ <?php
+ if ($user['priv'] >= $apps['image']['index'])
+ echo ' - <a href="index-image">back to list of uploaded images</a>';
+ ?>
+ </p>
<?php
require("tpl/general/bottom.php");
diff --git a/tpl/image/upload.php b/tpl/image/upload.php
index 6e9ee55..71283cf 100644
--- a/tpl/image/upload.php
+++ b/tpl/image/upload.php
@@ -6,7 +6,8 @@ if ($user['id'] == 0) $message = "You should create an account so that you can t
$form_message = "A $miniature_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" => "image"),
+ array("label" => "Image title (optionnal) : ", "type" => "text", "name" => "name")
);
$validate = "Upload";
diff --git a/tpl/notes/index.php b/tpl/notes/index.php
deleted file mode 100644
index 6c0eb99..0000000
--- a/tpl/notes/index.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-$title = "User's notebooks";
-require("tpl/general/top.php");
-
-echo '<div class="ordering_links">' . filters_html_full() . '</div>';
-
-echo "<ul>";
-foreach($users as $u) {
- echo '<li><a href="user-notes-' . $u['id'] . '">' . $u['name'] . '</a> (' . $u['nbNotes'] . ' notes)</li>';
-}
-echo "</ul>";
-
-require("tpl/general/bottom.php");
diff --git a/tpl/study/index.php b/tpl/study/index.php
index 82178df..287be11 100644
--- a/tpl/study/index.php
+++ b/tpl/study/index.php
@@ -11,7 +11,7 @@ require("tpl/general/top.php");
<p>The first method is based on
decks of cards, keeping track of your progress and everything.</p>
-<p>Please take a look in the <a href="deck">List of decks</a> and start learning whatever you want to learn.</p>
+<p>Please take a look at the <a href="deck">list of decks</a> and start learning whatever you want to learn.</p>
<p>The cards you are studying are classified in the following <em>boxes</em> :</p>
<ul>
@@ -34,6 +34,8 @@ Cards you are supposed to study or review today appear with a bold title : that
for a given list). You will study one batch at a time, and take a test for one batch at a time. All your test results
are kept in storage and are used to display your progress.</p>
+<p>Please take a look at the <a href="list">list of lists</a> and start learning whatever you want to learn.</p>
+
<?php
require ("lib_sidebar.php");