diff --git a/api/actions/savenote.php b/api/actions/savenote.php index 6af10fe..0c2ca9b 100644 --- a/api/actions/savenote.php +++ b/api/actions/savenote.php @@ -12,11 +12,21 @@ $note = new Note("", "", getRequestUser()->getUID(), null); +$newnote = true; if (!empty($VARS['id'])) { try { $note = Note::loadNote($VARS['id']); + $newnote = false; } catch (Exception $ex) { // It's a new note I guess + $newnote = true; + } +} + +if ($newnote && $SETTINGS['note_limit'] !== false && !getRequestUser()->hasPermission($SETTINGS['unlimited_permission'])) { + $notecount = $database->count("notes", ['ownerid' => $_SESSION['uid']]); + if ($notecount >= $SETTINGS['note_limit']) { + sendJsonResp($Strings->get("You've reached your quota limit and can't make new notes.", false), "ERROR"); } } diff --git a/langs/en/quota.json b/langs/en/quota.json new file mode 100644 index 0000000..814df48 --- /dev/null +++ b/langs/en/quota.json @@ -0,0 +1,8 @@ +{ + "You've reached your quota limit and can't make new notes.": "You've reached your quota limit and can't make new notes.", + "Note quota reached": "Note quota reached", + "Note quota": "Note quota", + "Note quota: {x} of {y} used.": "Note quota: {x} of {y} used.", + "Note quota: Unlimited": "Note quota: Unlimited", + "unlimited": "unlimited" +} diff --git a/langs/messages.php b/langs/messages.php index 3b904e3..d0d9830 100644 --- a/langs/messages.php +++ b/langs/messages.php @@ -20,5 +20,9 @@ define("MESSAGES", [ "note_deleted" => [ "string" => "Note deleted", "type" => "success" + ], + "quota_reached" => [ + "string" => "You've reached your quota limit and can't make new notes.", + "type" => "danger" ] ]); diff --git a/pages/editnote.php b/pages/editnote.php index 19b29ec..cd7312e 100644 --- a/pages/editnote.php +++ b/pages/editnote.php @@ -5,13 +5,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +$newnote = true; $note = new Note("", "", $_SESSION['uid'], null); if (!empty($VARS['note'])) { try { $note = Note::loadNote($VARS['note']); + $newnote = false; } catch (Exception $ex) { // It's a new note I guess + $newnote = true; } } @@ -21,6 +24,13 @@ if ($note->getOwnerID() != $_SESSION['uid']) { die(); } +if ($newnote && $SETTINGS['note_limit'] !== false && !(new User($_SESSION['uid']))->hasPermission($SETTINGS['unlimited_permission'])) { + $notecount = $database->count("notes", ['ownerid' => $_SESSION['uid']]); + if ($notecount >= $SETTINGS['note_limit']) { + header("Location: app.php?msg=quota_reached"); + } +} + $note->saveNote(); ?> diff --git a/pages/home.php b/pages/home.php index 26354ca..e152d91 100644 --- a/pages/home.php +++ b/pages/home.php @@ -10,6 +10,23 @@ $notes = []; foreach ($noteids as $n) { $notes[] = Note::loadNote($n); } + +// Check note quota +$notequota = $SETTINGS['note_limit']; +$notequotaset = $SETTINGS['note_limit'] !== false; +$notequotareached = false; +$usernotecount = 0; +$userunlimited = false; +if ($notequotaset) { + $usernotecount = $database->count("notes", ['ownerid' => $_SESSION['uid']]); + $usernotelimit = $SETTINGS['note_limit']; + if ((new User($_SESSION['uid']))->hasPermission($SETTINGS['unlimited_permission'])) { + $userunlimited = true; + } + if (!$userunlimited && $usernotecount >= $usernotelimit) { + $notequotareached = true; + } +} ?>
- get("New note"); ?> + + + + get("New note"); ?> + get("Refresh"); ?>
@@ -185,6 +208,40 @@ foreach ($colors as $c) { + +
+ get("Note quota: Unlimited"); + } else { + $Strings->build("Note quota: {x} of {y} used.", ["x" => $usernotecount, "y" => $notequota]); + } + ?> +
+ + + +