Compare commits

...

7 Commits

6 changed files with 167 additions and 1 deletions

View File

@@ -0,0 +1,19 @@
type: fields
fields:
created:
label: Created
type: date
default: now
required: true
time:
notation: 12
step: 1
updated:
label: Updated
type: date
default: now
required: true
time:
notation: 12
step: 1

View File

@@ -0,0 +1,9 @@
type: fields
fields:
pinned:
label: Pinned
type: toggle
text:
- "No"
- "Yes"

View File

@@ -0,0 +1,10 @@
type: fields
fields:
showOnHome:
label: Show On Home
type: toggle
default: true
text:
- "No"
- "Yes"

View File

@@ -24,9 +24,14 @@ Kirby::plugin(
"blueprints" => [ "blueprints" => [
"fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml", "fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.yml",
"fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml", "fields/link-location" => __DIR__ . "/blueprints/fields/link-location.yml",
"fields/dates" => __DIR__ . "/blueprints/fields/dates.yml",
"fields/pinned" => __DIR__ . "/blueprints/fields/pinned.yml",
"fields/show-on-home" => __DIR__ . "/blueprints/fields/show-on-home.yml",
], ],
"snippets" => [ "snippets" => [
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php", "navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
"collection/post" => __DIR__ . "/snippets/collection/post.php",
"page/pagination" => __DIR__ . "/snippets/page/pagination.php",
], ],
"hooks" => [ "hooks" => [
/** /**
@@ -86,6 +91,22 @@ Kirby::plugin(
$pages = site()->index(true)->filterBy("linkLocation", $linkLocation); $pages = site()->index(true)->filterBy("linkLocation", $linkLocation);
foreach ($pages as $page) { foreach ($pages as $page) {
if (kirby()->plugin("hobbyhome/permissions")) {
// Hacky way of allowing us to run a hook multiple times from within another hook.
$events = kirby()->events;
call_user_func(
\Closure::bind(
function () use ($events) {
unset($events->processed["permissions.page:check"]);
}, null, $events
)
);
if (!$page->hasPerm()) {
continue;
}
}
if ($page->isDraft() && !($user = kirby()->user() and $user->role()->isAdmin())) { if ($page->isDraft() && !($user = kirby()->user() and $user->role()->isAdmin())) {
continue; continue;
} }
@@ -114,6 +135,14 @@ Kirby::plugin(
return $links; return $links;
}, },
"page.update:after" => function ($newPage, $oldPage) {
if ($newPage->updated()->exists()) {
# Set the last updated time to now.
$newPage->update([
"updated" => date("Y-m-d H:i"),
]);
}
},
], ],
"siteMethods" => [ "siteMethods" => [
/** /**
@@ -150,6 +179,36 @@ Kirby::plugin(
return $links; return $links;
}, },
/**
* Make a Json request to a URL using cURL.
*
* This isn't an entirely generic function and may not work as expected. It was created to service the Kirby Deluge plugin.
*
* If the `$method` is `get`, the request is executed and decoded with no further processing.
*
* @param CurlHandle $curl The instance of the cURL object.
* @param int $reqId A request ID. Usually incremented for each request.
* @param string $method The method to use for the request.
* @param mixed $params If method is not `get`, this is an array of parameters to set in the Json request as `params`.
*
* @return Array of decoded Json data.
*/
"makeRequest" => function ($curl, $reqId, $method, $params = []) {
if ($method != "get") {
$postData = Data::encode(["id" => $reqId, "method" => $method, "params" => $params], "json");
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
}
$response = curl_exec($curl);
if ($method == "get") {
return Data::decode($response, "json");
} else {
list($responseHeader, $responseBody) = explode("\r\n\r\n", $response, 2);
return Data::decode($responseBody, "json");
}
},
], ],
], ],
info: [ info: [
@@ -159,6 +218,6 @@ Kirby::plugin(
"homepage" => "https://hobbyhome.net", "homepage" => "https://hobbyhome.net",
]], ]],
"license" => "AGPL-3.0-only", "license" => "AGPL-3.0-only",
"version" => "0.0.0", "version" => "1.0.0",
], ],
); );

View File

@@ -0,0 +1,34 @@
<div class="card mb-3<?= r($post->pinned()->isTrue(), " border-light") ?><?= r($post->isDraft(), " text-secondary") ?>">
<div class="card-body py-1">
<h3 class="card-title mb-0">
<a href="<?= $post->url() ?>" class="text-reset text-decoration-none"><?= $post->title() ?></a>
<?php if ($post->pinned()->isTrue() || $post->isDraft()) : ?>
<div class="float-end">
<?= r($post->pinned()->isTrue(), kirbytag("fa", "thumbtack", ["class" => "fa-xs"])) ?>
<?= r($post->isDraft(), kirbytag("fa", "pencil-ruler", ["class" => "fa-xs"])) ?>
</div>
<?php endif ?>
</h3>
<small class="d-inline-block text-body-secondary pb-2">
<?= kirbytag("fa", "calendar-days") ?>
<?php if (date_diff(date_create($post->created()->toDate("Y-m-d")), date_create($post->updated()->toDate("Y-m-d")))->format("%a") > 0) : ?>
Updated on <span title="Originally posted on <?= $post->created()->toDate('l \t\h\e\ jS \of F Y') ?>"><?= $post->updated()->toDate('l \t\h\e jS \of F Y') ?></span>
<?php else : ?>
Posted on <?= $post->created()->toDate('l \t\h\e jS \of F Y') ?>
<?php endif ?>
</small>
<hr class="mt-0">
<?= $post->text()->textExcerpt(600, false) ?>
</div>
<div class="card-footer">
<small>
<div class="float-end">
<a href="<?= $post->url() ?>"><?= kirbytag("fa", "angle-double-right") ?> Read The Rest</a>
</div>
<?php if (($user = kirby()->user()) and $user->role()->isAdmin()) : ?>
<a href="<?= $post->panel()->url() ?>" target="_blank"><?= kirbytag("fa", "edit") ?></a>
<?php endif ?>
</small>
</div>
</div>

View File

@@ -0,0 +1,35 @@
<?php if (isset($pagination) and $pagination->hasPages()) : ?>
<div class="row mb-3">
<nav>
<ul class="pagination justify-content-center mb-0">
<li class="page-item<?= r(!$pagination->hasPrevPage(), " disabled") ?>">
<a class="page-link" href="<?= $pagination->firstPageUrl() ?>" title="First Page">
<?= kirbytag("fa", "angle-double-left") ?>
</a>
</li>
<li class="page-item<?= r(!$pagination->hasPrevPage(), " disabled") ?>">
<a class="page-link" href="<?= $pagination->prevPageUrl() ?>" title="Previous Page">
<?= kirbytag("fa", "angle-left") ?>
</a>
</li>
<?php foreach ($pagination->range(10) as $r) : ?>
<li class="page-item<?= r($pagination->page() === $r, " active") ?>">
<a class="page-link" href="<?= $pagination->pageUrl($r) ?>">
<?= $r ?>
</a>
</li>
<?php endforeach ?>
<li class="page-item<?= r(!$pagination->hasNextPage(), " disabled") ?>">
<a class="page-link" href="<?= $pagination->nextPageUrl() ?>" title="Next Page">
<?= kirbytag("fa", "angle-right") ?>
</a>
</li>
<li class="page-item<?= r(!$pagination->hasNextPage(), " disabled") ?>">
<a class="page-link" href="<?= $pagination->lastPageUrl() ?>" title="Last Page">
<?= kirbytag("fa", "angle-double-right") ?>
</a>
</li>
</ul>
</nav>
</div>
<?php endif ?>