You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

273 lines
14 KiB
PHP

<?php
/* 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'], 'ORDER' => ['favorite' => "DESC"]]);
$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;
}
}
?>
<style nonce="<?php echo $SECURE_NONCE; ?>">
<?php
foreach ($notes as $note) {
echo "#notecard_" . $note->getID() . ", #notecard_" . $note->getID() . " .card-body a {\n"
. " background-color: #" . $note->getColor() . ";\n"
. " color: #" . $note->getTextColor() . ";\n"
. " border: 1px solid #" . $note->getColor() . ";\n"
. "}\n";
echo "#notecard_" . $note->getID() . " .card-footer a {\n"
. " color: #" . $note->getTextColor() . ";\n"
. "}\n";
echo "#notecard_" . $note->getID() . " .parsedown-task-list-close {\n"
. " color: #" . $note->getGrayColor() . ";\n"
. "}\n";
}
foreach (Colors::$colors as $c) {
echo ".bg_$c {\n"
. " background-color: #$c !important;\n"
. " border: 1px solid #$c !important;\n"
. "}\n";
}
?>
</style>
<div class="row justify-content-between px-4">
<div class="flex-fill btn-group mb-4">
<?php if ($notequotareached) { ?>
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#quotamodal">
<i class="fas fa-plus"></i> <?php $Strings->get("New note"); ?>
</button>
<?php } else { ?>
<a href="app.php?page=newnote" class="btn btn-success"><i class="fas fa-plus"></i> <?php $Strings->get("New note"); ?></a>
<?php } ?>
<a href="app.php?page=home" class="btn btn-light"><i class="fas fa-sync-alt"></i> <?php $Strings->get("Refresh"); ?></a>
</div>
<div class="flex-fill d-none yesscript">
<div class="input-group pl-4">
<input type="text" class="form-control" id="searchbox" placeholder="<?php $Strings->get("Search"); ?>" aria-label="<?php $Strings->get("Search"); ?>">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="button" id="searchbtn"><i class="fas fa-search"></i></button>
</div>
</div>
</div>
</div>
<div class="row" id="grid">
<?php
// Show ad card if enabled in settings
$count = 0;
$adshown = false;
foreach ($notes as $note) {
$count++;
if ($count >= 2 && !$adshown && $SETTINGS['ads_enabled'] && !(new User($_SESSION['uid']))->hasPermission($SETTINGS['noads_permission'])) {
$adshown = true;
?>
<style nonce="<?php echo $SECURE_NONCE; ?>"><?php echo $SETTINGS['ad_css']; ?></style>
<div class="grid__brick col-12 col-sm-6 col-md-6 col-lg-4 pb-4 pt-1">
<div class="card">
<?php echo $SETTINGS['ad_html']; ?>
<div class="card-body text-muted p-0 m-2">
<?php echo $SETTINGS['ad_footer']; ?>
</div>
</div>
</div>
<?php
}
?>
<div class="grid__brick col-12 col-sm-6 col-md-6 col-lg-4 pb-4 pt-1">
<div class="card notecard" data-color="<?php echo $note->getColor(); ?>" id="notecard_<?php echo $note->getID(); ?>" data-note="<?php echo $note->getID(); ?>">
<div class="card-body notecard-click2open">
<div class="float-right">
<a href="./action.php?action=favoritenote&noteid=<?php echo $note->getID(); ?>" class="favorite-btn pr-1" data-toggle="tooltip" title="<?php $Strings->get("Favorite"); ?>">
<?php
if ($note->getFavorite()) {
?>
<i class="fas fa-star fa-fw"></i>
<?php
} else {
?>
<i class="far fa-star fa-fw"></i>
<?php
}
?>
</a>
</div>
<div class="card-text note-text">
<?php echo $note->getHTML(); ?>
</div>
</div>
<div class="card-footer">
<div class="d-flex justify-content-around flex-wrap">
<div>
<a class="px-2 py-2" href="./app.php?page=editnote&note=<?php echo $note->getID(); ?>" data-toggle="tooltip" title="<?php $Strings->get('Edit'); ?>">
<i class="fas fa-edit"></i> <noscript><?php $Strings->get('Edit'); ?></noscript>
</a>
</div>
<div>
<a class="px-2 py-2" href="./action.php?action=maketodolist&noteid=<?php echo $note->getID(); ?>" data-toggle="tooltip" title="<?php $Strings->get("Make a List"); ?>" data-noteid="<?php echo $note->getID(); ?>">
<i class="fas fa-tasks"></i> <noscript><?php $Strings->get('Listify'); ?></noscript>
</a>
</div>
<div class="d-none yesscript">
<a class="px-2 py-2 color-btn" href="#" data-toggle="tooltip" title="<?php $Strings->get("Set color"); ?>" data-color="<?php echo $note->getColor(); ?>" data-noteid="<?php echo $note->getID(); ?>">
<i class="fas fa-palette"></i>
</a>
</div>
<noscript>
<div>
<a href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>" data-toggle="tooltip" title="<?php $Strings->get('Download (Text)'); ?>">
<i class="fas fa-download"></i> <?php $Strings->get('Download'); ?>
</a>
(<a href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=html" title="<?php $Strings->get('Download (HTML)'); ?>"><?php $Strings->get('HTML'); ?></a>
| <a href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=odt" title="<?php $Strings->get('Download (Office)'); ?>"><?php $Strings->get('ODT'); ?></a>)
</div>
</noscript>
<noscript>
<div>
<a class="px-2 py-2" href="./action.php?action=deletenote&noteid=<?php echo $note->getID(); ?>" data-toggle="tooltip" title="<?php $Strings->get('Delete'); ?>">
<i class="fas fa-trash"></i> <?php $Strings->get('Delete'); ?>
</a>
</div>
</noscript>
<div class="dropdown yesscript">
<span data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" data-offset="0,-70">
<a class="p-2" href="#" id="moreoptionsbtn_<?php echo $note->getID(); ?>" data-tooltip="tooltip" title="<?php $Strings->get('More'); ?>">
<i class="fas fa-ellipsis-v"></i>
</a>
</span>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="moreoptionsbtn_<?php echo $note->getID(); ?>">
<!--<h4 class="dropdown-header"><?php $Strings->get("More Options"); ?></h4>-->
<a class="dropdown-item" href="./action.php?action=deletenote&noteid=<?php echo $note->getID(); ?>">
<i class="fas fa-trash fa-fw"></i> <?php $Strings->get('Delete'); ?>
</a>
<div class="dropdown-divider"></div>
<h4 class="dropdown-header"><i class="fas fa-cloud-download-alt fa-fw"></i> <?php $Strings->get('Download'); ?></h4>
<div class="dropdown-item d-flex justify-content-between">
<a class="p-2" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=markdown">
<i class="fas fa-align-left"></i> <?php $Strings->get('Text'); ?>
</a>
<a class="p-2" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=html">
<i class="fab fa-html5"></i> <?php $Strings->get('HTML'); ?>
</a>
<?php
// Additional export formats
if ($SETTINGS['pandoc'] != "") {
?>
<a class="p-2" href="./action.php?action=downloadnote&noteid=<?php echo $note->getID(); ?>&type=odt">
<i class="fas fa-file-alt"></i> <?php $Strings->get('Office'); ?>
</a>
<?php
} else {
// Fillin' space
?>
<span class="px-4">&nbsp;</span>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>
<div class="col-1 sizer-element"></div>
</div>
<?php if ($notequotaset) { ?>
<div class="quotamsg" data-toggle="modal" data-target="#quotamodal">
<?php
if ($userunlimited) {
$Strings->get("Note quota: Unlimited");
} else {
$Strings->build("Note quota: {x} of {y} used.", ["x" => $usernotecount, "y" => $notequota]);
}
?>
</div>
<div class="modal fade" id="quotamodal" tabindex="-1" role="dialog" aria-labelledby="quotamodallabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="quotamodallabel"><i class="fas fa-tachometer-alt"></i> <?php $Strings->get("Note quota"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<?php
$quotamsg = str_replace(["{{notecount}}", "{{notelimit}}"], [$usernotecount, ($userunlimited ? $Strings->get("unlimited", false) : $notequota)], $SETTINGS['quota_msg_content']);
echo $quotamsg;
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php $Strings->get("Close"); ?></button>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="modal fade" tabindex="-1" role="dialog" id="colormodal">
<div class="modal-dialog" role="document">
<form class="modal-content" action="action.php" method="POST">
<input type="hidden" name="action" value="setcolor" />
<input type="hidden" name="source" value="home" />
<input type="hidden" name="noteid" value="" />
<input type="hidden" name="color" value="FFFFFF" />
<div class="modal-header">
<h5 class="modal-title"><i class="fas fa-palette"></i> <?php $Strings->get("Set color"); ?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div class="d-flex flex-wrap justify-content-center">
<?php
foreach (Colors::$colors as $c) {
?>
<button type="submit" name="color" value="<?php echo $c; ?>" class="btn bg_<?php echo $c; ?> m-1">
&nbsp;
</button>
<?php
}
?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><?php $Strings->get("Cancel"); ?></button>
</div>
</form>
</div>
</div>