diff --git a/.gitignore b/.gitignore
index 07fe371..e1da2a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
vendor
settings.php
nbproject/private
-*.sync-conflict*
\ No newline at end of file
+*.sync-conflict*
+*.bak
\ No newline at end of file
diff --git a/app.php b/app.php
index 5cfcc36..c18fd0b 100644
--- a/app.php
+++ b/app.php
@@ -114,7 +114,7 @@ END;
// For mobile app
echo ""
?>
-
+
diff --git a/composer.json b/composer.json
index fb37c32..3542cee 100644
--- a/composer.json
+++ b/composer.json
@@ -1,10 +1,11 @@
{
- "name": "netsyms/business-app-template",
- "description": "Template for a webapp integrated with an AccountHub server.",
+ "name": "netsyms/notepost",
+ "description": "Note and list organizer.",
"type": "project",
"require": {
"catfan/medoo": "^1.5",
- "guzzlehttp/guzzle": "^6.2"
+ "guzzlehttp/guzzle": "^6.2",
+ "erusev/parsedown": "^1.7"
},
"license": "MPL-2.0",
"authors": [
diff --git a/composer.lock b/composer.lock
index 8d36028..b680b7d 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,8 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "hash": "5c7439c6e041764f2f6b0270a95ab3ae",
- "content-hash": "e4e700119f47d2f68b0ed82abaf8c5c6",
+ "content-hash": "1aea304797149ba2b5bccc0f6d82c060",
"packages": [
{
"name": "catfan/medoo",
@@ -64,7 +63,53 @@
"sql",
"sqlite"
],
- "time": "2018-06-14 18:59:08"
+ "time": "2018-06-14T18:59:08+00:00"
+ },
+ {
+ "name": "erusev/parsedown",
+ "version": "1.7.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/erusev/parsedown.git",
+ "reference": "92e9c27ba0e74b8b028b111d1b6f956a15c01fc1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/erusev/parsedown/zipball/92e9c27ba0e74b8b028b111d1b6f956a15c01fc1",
+ "reference": "92e9c27ba0e74b8b028b111d1b6f956a15c01fc1",
+ "shasum": ""
+ },
+ "require": {
+ "ext-mbstring": "*",
+ "php": ">=5.3.0"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^4.8.35"
+ },
+ "type": "library",
+ "autoload": {
+ "psr-0": {
+ "Parsedown": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Emanuil Rusev",
+ "email": "hello@erusev.com",
+ "homepage": "http://erusev.com"
+ }
+ ],
+ "description": "Parser for Markdown.",
+ "homepage": "http://parsedown.org",
+ "keywords": [
+ "markdown",
+ "parser"
+ ],
+ "time": "2018-03-08T01:11:30+00:00"
},
{
"name": "guzzlehttp/guzzle",
@@ -129,7 +174,7 @@
"rest",
"web service"
],
- "time": "2018-04-22 15:46:56"
+ "time": "2018-04-22T15:46:56+00:00"
},
{
"name": "guzzlehttp/promises",
@@ -180,7 +225,7 @@
"keywords": [
"promise"
],
- "time": "2016-12-20 10:07:11"
+ "time": "2016-12-20T10:07:11+00:00"
},
{
"name": "guzzlehttp/psr7",
@@ -245,7 +290,7 @@
"uri",
"url"
],
- "time": "2017-03-20 17:10:46"
+ "time": "2017-03-20T17:10:46+00:00"
},
{
"name": "psr/http-message",
@@ -295,7 +340,7 @@
"request",
"response"
],
- "time": "2016-08-06 14:39:51"
+ "time": "2016-08-06T14:39:51+00:00"
}
],
"packages-dev": [],
diff --git a/database.mwb b/database.mwb
new file mode 100644
index 0000000..62603e0
Binary files /dev/null and b/database.mwb differ
diff --git a/langs/en/notes.json b/langs/en/notes.json
new file mode 100644
index 0000000..37bf50d
--- /dev/null
+++ b/langs/en/notes.json
@@ -0,0 +1,5 @@
+{
+ "New": "New",
+ "Note": "Note",
+ "Edit": "Edit"
+}
diff --git a/langs/en/titles.json b/langs/en/titles.json
index 6fbf103..bc70416 100644
--- a/langs/en/titles.json
+++ b/langs/en/titles.json
@@ -1,4 +1,4 @@
{
"home": "Home",
- "test": "Test"
+ "Notes": "Notes"
}
diff --git a/lib/Exceptions.lib.php b/lib/Exceptions.lib.php
index baec83f..441beaa 100644
--- a/lib/Exceptions.lib.php
+++ b/lib/Exceptions.lib.php
@@ -10,4 +10,10 @@ class IncorrectPasswordException extends Exception {
public function __construct(string $message = "Incorrect password.", int $code = 0, \Throwable $previous = null) {
parent::__construct($message, $code, $previous);
}
+}
+
+class NoSuchNoteException extends Exception {
+ public function __construct(string $message = "Note ID does not exist.", int $code = 0, \Throwable $previous = null) {
+ parent::__construct($message, $code, $previous);
+ }
}
\ No newline at end of file
diff --git a/lib/Note.lib.php b/lib/Note.lib.php
new file mode 100644
index 0000000..6f943ee
--- /dev/null
+++ b/lib/Note.lib.php
@@ -0,0 +1,195 @@
+content = $content;
+ $this->color = $color;
+ $this->ownerid = $ownerid;
+ $this->noteid = $noteid;
+ }
+
+ /**
+ * Load a note from the database and return it.
+ * @global type $database
+ * @param int $noteid
+ * @return \Note
+ * @throws NoSuchNoteException When the note ID isn't found.
+ */
+ public static function loadNote(int $noteid): Note {
+ global $database;
+
+ if (!$database->has('notes', ['noteid' => $noteid])) {
+ throw new NoSuchNoteException();
+ }
+
+ $notedata = $database->get('notes', ['noteid', 'ownerid', 'color', 'content'], ['noteid' => $noteid]);
+
+ return new Note($notedata['content'], $notedata['color'], $notedata['ownerid'], $notedata['noteid']);
+ }
+
+ /**
+ * Save the note to the database.
+ * @global type $database
+ * @param bool $saveas If true, save the note under a new ID. Forced to
+ * true if the current note ID is missing or invalid.
+ * @return int The database ID of the saved note
+ * @throws Exception If there is no note owner set.
+ */
+ public function saveNote(bool $saveas = false): int {
+ global $database;
+
+ $data = [
+ 'ownerid' => $this->ownerid,
+ 'color' => $this->color,
+ 'content' => $this->content
+ ];
+
+ // We can't UPDATE the database, so use save as for INSERT
+ if (empty($this->noteid) || !$database->has('notes', ['noteid' => $this->noteid])) {
+ $saveas = true;
+ }
+
+ if (empty($this->ownerid)) {
+ throw new Exception("No owner set.");
+ }
+
+ if ($saveas) {
+ $database->insert('notes', $data);
+ return $database->id();
+ } else {
+ $database->update('notes', $data, ['noteid' => $this->noteid]);
+ return $this->noteid;
+ }
+ }
+
+ /**
+ * Get the Markdown content of the note.
+ * @return string
+ */
+ public function getText(): string {
+ return $this->content;
+ }
+
+ /**
+ * Get the HTML render of the note.
+ * @param bool $fragment Get just the HTML content, instead of a whole HTML5 file
+ * @return string
+ */
+ public function getHTML(bool $fragment = true): string {
+ $parsedown = new Parsedown;
+ $parsedown->setSafeMode(true);
+ return $parsedown->text($this->content);
+ }
+
+ /**
+ * Get the note ID.
+ * @return int
+ */
+ public function getID(): int {
+ return $this->noteid;
+ }
+
+ /**
+ * Get the note color as RRGGBB hex.
+ * @return string
+ */
+ public function getColor(): string {
+ return $this->color;
+ }
+
+ /**
+ * Get the owner UID
+ * @return int
+ */
+ public function getOwnerID(): int {
+ return $this->ownerid;
+ }
+
+ /**
+ * Get the owner as a User object
+ * @return \User
+ */
+ public function getOwner(): User {
+ return new User($this->ownerid);
+ }
+
+ /**
+ * Set the note content
+ * @param string $markdown
+ */
+ public function setText(string $markdown) {
+ $this->content = $markdown;
+ }
+
+ /**
+ * Set the note color to a hex string
+ * @param string $color "RRGGBB"
+ */
+ public function setColor(string $color) {
+ $this->color = $color;
+ }
+
+ /**
+ * Set the owner by UID
+ * @param int $uid
+ */
+ public function setOwnerID(int $uid) {
+ $this->ownerid = $uid;
+ }
+
+ /**
+ * Set the owner
+ * @param User $user
+ */
+ public function setOwner(User $owner) {
+ $this->ownerid = $owner->getUID();
+ }
+
+ /**
+ * Get this note as an array.
+ * @return string
+ */
+ public function toArray(): array {
+ $owner = new User($this->ownerid);
+ $arr = [
+ 'noteid' => $this->noteid,
+ 'color' => $this->color,
+ 'content' => $this->content,
+ 'owner' => [
+ 'uid' => $owner->getUID(),
+ 'username' => $owner->getUsername(),
+ 'name' => $owner->getName()
+ ]
+ ];
+
+ return $arr;
+ }
+
+ /**
+ * Read an array with the structure from toArray().
+ * @param array $arr
+ * @return \Note A Note constructed from the array data.
+ */
+ public static function fromArray(array $arr): Note {
+ return new Note($arr['content'], $arr['color'], $arr['owner']['uid'], $arr['noteid']);
+ }
+
+}
diff --git a/nbproject/project.xml b/nbproject/project.xml
index 3edeb05..e722681 100644
--- a/nbproject/project.xml
+++ b/nbproject/project.xml
@@ -3,7 +3,7 @@
org.netbeans.modules.php.project
- BusinessAppTemplate
+ NotePost
diff --git a/pages.php b/pages.php
index ad2a84f..a8a466a 100644
--- a/pages.php
+++ b/pages.php
@@ -7,9 +7,9 @@
// List of pages and metadata
define("PAGES", [
"home" => [
- "title" => "home",
+ "title" => "Notes",
"navbar" => true,
- "icon" => "fas fa-home"
+ "icon" => "far fa-sticky-note"
],
"404" => [
"title" => "404 error"
diff --git a/pages/home.php b/pages/home.php
index 1d44fbf..9d8cfcc 100644
--- a/pages/home.php
+++ b/pages/home.php
@@ -2,5 +2,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+$noteids = $database->select('notes', 'noteid', ['ownerid' => $_SESSION['uid']]);
+
+$notes = [];
+
+foreach ($noteids as $n) {
+ $notes[] = Note::loadNote($n);
+}
?>
-Hello World
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+ getHTML(); ?>
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/settings.template.php b/settings.template.php
index 2732b99..3ee374f 100644
--- a/settings.template.php
+++ b/settings.template.php
@@ -11,14 +11,14 @@ define("DEBUG", false);
// Database connection settings
// See http://medoo.in/api/new for info
define("DB_TYPE", "mysql");
-define("DB_NAME", "app");
+define("DB_NAME", "notepost");
define("DB_SERVER", "localhost");
-define("DB_USER", "app");
+define("DB_USER", "notepost");
define("DB_PASS", "");
define("DB_CHARSET", "utf8");
// Name of the app.
-define("SITE_TITLE", "Web App Template");
+define("SITE_TITLE", "NotePost");
// URL of the AccountHub API endpoint
diff --git a/static/img/logo.svg b/static/img/logo.svg
index 410fb09..3643eff 100644
--- a/static/img/logo.svg
+++ b/static/img/logo.svg
@@ -1,78 +1,2 @@
-
-
-
-
-
-
-
-
-
-
-
- image/svg+xml
-
-
-
-
-
-
-
-
-
-
+
+