Add favorite note feature, fix setModified when passing UNIX timestamp
This commit is contained in:
parent
91636b15d2
commit
9742b70e71
14
action.php
14
action.php
@ -57,6 +57,7 @@ switch ($VARS['action']) {
|
||||
}
|
||||
$note->deleteNote();
|
||||
returnToSender("note_deleted");
|
||||
break;
|
||||
case "downloadnote":
|
||||
if (empty($VARS['noteid'])) {
|
||||
die($Strings->get("invalid parameters", false));
|
||||
@ -68,4 +69,17 @@ switch ($VARS['action']) {
|
||||
header("Content-Type: text/markdown; charset=UTF-8");
|
||||
header("Content-disposition: attachment; filename=\"" . $note->getCleanTitle() . "_" . $note->getModified() . ".md\"");
|
||||
echo $note->getText();
|
||||
break;
|
||||
case "favoritenote":
|
||||
if (empty($VARS['noteid'])) {
|
||||
die($Strings->get("invalid parameters"));
|
||||
}
|
||||
$note = Note::loadNote($VARS['noteid']);
|
||||
if (!$note->hasWriteAccess(new User($_SESSION['uid']))) {
|
||||
die($Strings->get("invalid parameters"));
|
||||
}
|
||||
$note->setFavorite(!$note->getFavorite());
|
||||
$note->saveNote();
|
||||
returnToSender("");
|
||||
break;
|
||||
}
|
BIN
database.mwb
BIN
database.mwb
Binary file not shown.
@ -14,6 +14,7 @@ class Note {
|
||||
private $title = "";
|
||||
private $modified = "";
|
||||
private $color = "FFFFFF";
|
||||
private $favorite = false;
|
||||
|
||||
/**
|
||||
* Create a new Note object.
|
||||
@ -42,11 +43,12 @@ class Note {
|
||||
throw new NoSuchNoteException();
|
||||
}
|
||||
|
||||
$notedata = $database->get('notes', ['noteid', 'ownerid', 'color', 'content', 'title', 'modified'], ['noteid' => $noteid]);
|
||||
$notedata = $database->get('notes', ['noteid', 'ownerid', 'color', 'content', 'title', 'modified', 'favorite'], ['noteid' => $noteid]);
|
||||
|
||||
$note = new Note($notedata['content'], $notedata['color'], $notedata['ownerid'], $notedata['noteid']);
|
||||
$note->setTitle(is_null($notedata['title']) ? "" : $notedata['title']);
|
||||
$note->setModified(is_null($notedata['modified']) ? date("Y-m-d H:i:s") : $notedata['modified']);
|
||||
$note->setFavorite($notedata['favorite'] == true);
|
||||
|
||||
return $note;
|
||||
}
|
||||
@ -67,7 +69,8 @@ class Note {
|
||||
'color' => $this->getColor(),
|
||||
'content' => $this->getText(),
|
||||
'title' => $this->getTitle(),
|
||||
'modified' => $this->getModified()
|
||||
'modified' => $this->getModified(),
|
||||
'favorite' => $this->getFavorite() ? 1 : 0
|
||||
];
|
||||
|
||||
// We can't UPDATE the database, so use save as for INSERT
|
||||
@ -167,6 +170,10 @@ class Note {
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the note title stripped of Markdown and trimmed
|
||||
* @return string
|
||||
*/
|
||||
public function getCleanTitle(): string {
|
||||
$title = $this->getTitle();
|
||||
$title = str_replace("*", "", $title);
|
||||
@ -187,6 +194,14 @@ class Note {
|
||||
return date("Y-m-d H:i:s", strtotime($this->modified));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if the note is favorited (starred).
|
||||
* @return bool
|
||||
*/
|
||||
public function getFavorite(): bool {
|
||||
return $this->favorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the note content
|
||||
* @param string $markdown
|
||||
@ -232,9 +247,21 @@ class Note {
|
||||
* @param string $datetime
|
||||
*/
|
||||
public function setModified(string $datetime) {
|
||||
if (is_numeric($datetime)) {
|
||||
$this->modified = date("Y-m-d H:i:s", $datetime);
|
||||
return;
|
||||
}
|
||||
$this->modified = date("Y-m-d H:i:s", strtotime($datetime));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the note as favorite or not
|
||||
* @param bool $favorite
|
||||
*/
|
||||
public function setFavorite(bool $favorite) {
|
||||
$this->favorite = $favorite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this note as an array.
|
||||
* @return string
|
||||
@ -247,6 +274,7 @@ class Note {
|
||||
'content' => $this->getText(),
|
||||
'title' => $this->getTitle(),
|
||||
'modified' => $this->getModified(),
|
||||
'favorite' => $this->getFavorite(),
|
||||
'owner' => [
|
||||
'uid' => $owner->getUID(),
|
||||
'username' => $owner->getUsername(),
|
||||
@ -269,7 +297,7 @@ class Note {
|
||||
"title" => $this->getTitle(),
|
||||
"category" => null,
|
||||
"content" => $this->getText(),
|
||||
"favorite" => false
|
||||
"favorite" => $this->getFavorite()
|
||||
];
|
||||
}
|
||||
|
||||
@ -304,6 +332,7 @@ class Note {
|
||||
$note = new Note($arr['content'], $arr['color'], $arr['owner']['uid'], $arr['noteid']);
|
||||
$note->setTitle($arr['title']);
|
||||
$note->setModified($arr['modified']);
|
||||
$note->setFavorite($arr['favorite']);
|
||||
return $note;
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ if (json_last_error() == JSON_ERROR_NONE) {
|
||||
$requestdata = array_merge($requestdata, $requestjson);
|
||||
}
|
||||
|
||||
file_put_contents("/var/www/html/debug.log", var_export($requestdata, true));
|
||||
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case "GET":
|
||||
if (count($route) == 1) {
|
||||
@ -67,6 +69,10 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||
$note->setModified($requestdata['modified']);
|
||||
}
|
||||
|
||||
if (!empty($requestdata['favorite']) && $requestdata['favorite'] == true) {
|
||||
$note->setFavorite(true);
|
||||
}
|
||||
|
||||
$note->setOwner($user);
|
||||
|
||||
$note->saveNote();
|
||||
@ -84,6 +90,11 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||
} else {
|
||||
$note->setModified($requestdata['modified']);
|
||||
}
|
||||
if (!empty($requestdata['favorite']) && $requestdata['favorite'] == true) {
|
||||
$note->setFavorite(true);
|
||||
} else {
|
||||
$note->setFavorite(false);
|
||||
}
|
||||
$note->saveNote();
|
||||
exit(json_encode($note->toNextcloud()));
|
||||
} else {
|
||||
|
@ -35,7 +35,14 @@ foreach ($notes as $note) {
|
||||
<div class="col-12 col-sm-6 col-md-6 col-lg-4">
|
||||
<div class="card mb-3" data-color="<?php echo $note->getColor(); ?>" id="notecard_<?php echo $note->getID(); ?>">
|
||||
<div class="card-body">
|
||||
<?php echo $note->getHTML(); ?>
|
||||
<div class="float-right">
|
||||
<a href="./action.php?action=favoritenote¬eid=<?php echo $note->getID(); ?>" class="text-<?php echo $note->getFavorite() ? "warning" : "body"; ?>">
|
||||
<i class="fa<?php echo $note->getFavorite() ? "s" : "r"; ?> fa-star"></i>
|
||||
</a>
|
||||
</div>
|
||||
<div class="card-text">
|
||||
<?php echo $note->getHTML(); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-footer">
|
||||
|
Loading…
x
Reference in New Issue
Block a user