Compare commits
9 Commits
84f1eda2da
...
1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 32f74940ac | |||
| ddaa677dd1 | |||
| 5d89e6dcf4 | |||
| 8f19bd924f | |||
| 269d314758 | |||
| 1a5fe54439 | |||
| aeaed44fcd | |||
| e8c5e32768 | |||
| 525e5bfb64 |
19
blueprints/fields/dates.yml
Normal file
19
blueprints/fields/dates.yml
Normal 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
|
||||
24
blueprints/fields/link-location.yml
Normal file
24
blueprints/fields/link-location.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
type: fields
|
||||
|
||||
fields:
|
||||
linkLocation:
|
||||
label: Link Location
|
||||
type: select
|
||||
options:
|
||||
type: query
|
||||
query: site.linkLocations.toStructure
|
||||
text: "{{ item.description }}"
|
||||
value: "{{ item.location }}"
|
||||
linkIndex:
|
||||
label: Link Position
|
||||
type: number
|
||||
min: 1
|
||||
default: 10
|
||||
linkText:
|
||||
label: Link Text
|
||||
help: Custom link text to use instead of the title.
|
||||
type: text
|
||||
linkIcon:
|
||||
label: Link Icon
|
||||
help: Font Awesome icon that is used for the link text.
|
||||
type: text
|
||||
15
blueprints/fields/link-locations.yml
Normal file
15
blueprints/fields/link-locations.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
type: fields
|
||||
|
||||
fields:
|
||||
linkLocations:
|
||||
label: Link Locations
|
||||
type: structure
|
||||
fields:
|
||||
description:
|
||||
label: Location Description
|
||||
type: text
|
||||
help: A friendly description for selecting this location on pages.
|
||||
location:
|
||||
label: Location Key
|
||||
type: text
|
||||
help: This is what is used when finding links for this location.
|
||||
9
blueprints/fields/pinned.yml
Normal file
9
blueprints/fields/pinned.yml
Normal file
@@ -0,0 +1,9 @@
|
||||
type: fields
|
||||
|
||||
fields:
|
||||
pinned:
|
||||
label: Pinned
|
||||
type: toggle
|
||||
text:
|
||||
- "No"
|
||||
- "Yes"
|
||||
10
blueprints/fields/show-on-home.yml
Normal file
10
blueprints/fields/show-on-home.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
type: fields
|
||||
|
||||
fields:
|
||||
showOnHome:
|
||||
label: Show On Home
|
||||
type: toggle
|
||||
default: true
|
||||
text:
|
||||
- "No"
|
||||
- "Yes"
|
||||
149
index.php
149
index.php
@@ -21,6 +21,18 @@ Kirby::plugin(
|
||||
],
|
||||
],
|
||||
],
|
||||
"blueprints" => [
|
||||
"fields/link-locations" => __DIR__ . "/blueprints/fields/link-locations.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" => [
|
||||
"navbar/primary" => __DIR__ . "/snippets/navbar/primary.php",
|
||||
"collection/post" => __DIR__ . "/snippets/collection/post.php",
|
||||
"page/pagination" => __DIR__ . "/snippets/page/pagination.php",
|
||||
],
|
||||
"hooks" => [
|
||||
/**
|
||||
* To add this hook to a plugin, change the option() call to use the plugins name.
|
||||
@@ -39,6 +51,98 @@ Kirby::plugin(
|
||||
|
||||
return $files;
|
||||
},
|
||||
/**
|
||||
* To add this hook to a plugin, replace the foreach filter with any other method to generate the $newLinks[] array.
|
||||
*
|
||||
* @version 1.0
|
||||
*
|
||||
* Links in the array should have a minimum of the following options set:
|
||||
* $newLinks[] => [
|
||||
* "index" => The sort index of the link,
|
||||
* "url" => The URL of the link,
|
||||
* "text" => The text of the link,
|
||||
* "aria" => Accessible version of the link text,
|
||||
* "active" => True if this is the active link,
|
||||
* ];
|
||||
*
|
||||
* Optional supported options are:
|
||||
* $newLinks[] = [
|
||||
* "icon" => An optional Font Awesome icon,
|
||||
* "disabled" => True if this link should have the 'disabled' HTML attribute,
|
||||
* "target" => The value of the HTML link target attribute,
|
||||
* "dropdown" => [
|
||||
* [
|
||||
* "divider" => True to display a divider in the dropdown menu,
|
||||
* ],
|
||||
* [
|
||||
* A link, as defined above, that should be displayed in the dropdown menu.
|
||||
* These links will need to be sorted in the template. Index in this case
|
||||
* doesn't have any purpose unless you process it in the template.
|
||||
* ],
|
||||
* ],
|
||||
* ];
|
||||
*/
|
||||
"hobbyhome.getLinkList" => function ($links = [], $linkLocation = "primary") {
|
||||
$newLinks = [];
|
||||
|
||||
# ---------------------------------------------------------------------------------
|
||||
# Replace this section with any method of generating the $newLinks[] array.
|
||||
# ---------------------------------------------------------------------------------
|
||||
$pages = site()->index(true)->filterBy("linkLocation", $linkLocation);
|
||||
|
||||
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())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$newLinks[] = [
|
||||
"index" => $page->linkIndex()->toInt(),
|
||||
"url" => $page->url(),
|
||||
"icon" => ($page->linkIcon()->isNotEmpty()) ? kirbytag("fa", $page->linkIcon()) : "",
|
||||
"text" => ($page->linkText()->isNotEmpty()) ? $page->linkText() : $page->title(),
|
||||
"aria" => ($page->linkText()->isNotEmpty()) ? $page->linkText() : $page->title(),
|
||||
"active" => $page->isActive(),
|
||||
];
|
||||
}
|
||||
# ---------------------------------------------------------------------------------
|
||||
|
||||
foreach ($newLinks as $link) {
|
||||
$index = $link["index"];
|
||||
|
||||
# Make sure no other link exists with the current sort order index.
|
||||
while (isset($links[$index])) {
|
||||
$index++;
|
||||
}
|
||||
|
||||
$links[$index] = $link;
|
||||
}
|
||||
|
||||
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" => [
|
||||
/**
|
||||
@@ -62,6 +166,49 @@ Kirby::plugin(
|
||||
|
||||
return $files;
|
||||
},
|
||||
/**
|
||||
* Fetch and sort a list of links.
|
||||
*
|
||||
* @param string $linkLocation The identifier key for the list of links.
|
||||
*
|
||||
* @return Array of links, sorted by index.
|
||||
*/
|
||||
"getLinkList" => function ($linkLocation = "primary") {
|
||||
$links = kirby()->apply("hobbyhome.getLinkList", ["links" => [], "linkLocation" => $linkLocation], "links");
|
||||
ksort($links, SORT_NUMERIC);
|
||||
|
||||
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: [
|
||||
@@ -71,6 +218,6 @@ Kirby::plugin(
|
||||
"homepage" => "https://hobbyhome.net",
|
||||
]],
|
||||
"license" => "AGPL-3.0-only",
|
||||
"version" => "0.0.0",
|
||||
"version" => "1.0.0",
|
||||
],
|
||||
);
|
||||
|
||||
34
snippets/collection/post.php
Normal file
34
snippets/collection/post.php
Normal 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>
|
||||
77
snippets/navbar/primary.php
Normal file
77
snippets/navbar/primary.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<ul class="navbar-nav me-auto">
|
||||
<?php foreach ($site->getLinkList("primary") as $link) : ?>
|
||||
<?php if (isset($link["dropdown"])) : ?>
|
||||
<?php ksort($link["dropdown"], SORT_NUMERIC) ?>
|
||||
<li class="nav-item dropdown">
|
||||
<a
|
||||
class="nav-link dropdown-toggle<?= (isset($link["active"]) and $link["active"]) ? " active" : "" ?><?= (isset($link["disabled"]) and $link["disabled"]) ? " disabled" : "" ?>"
|
||||
href="#"
|
||||
data-bs-toggle="dropdown"
|
||||
title="<?= $link["aria"] ?>"
|
||||
aria-label="<?= $link["aria"] ?>"
|
||||
>
|
||||
<?php if ($link["icon"]) : ?>
|
||||
<?= $link["icon"] ?>
|
||||
|
||||
<span class="d-md-none">
|
||||
<?php else : ?>
|
||||
<span>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $link["text"] ?>
|
||||
</span>
|
||||
</a>
|
||||
|
||||
<ul class="dropdown-menu">
|
||||
<?php foreach ($link["dropdown"] as $link) : ?>
|
||||
<li>
|
||||
<?php if (isset($link["divider"])) : ?>
|
||||
<hr class="dropdown-divider">
|
||||
<?php else : ?>
|
||||
<a
|
||||
class="dropdown-item<?= (isset($link["active"]) and $link["active"]) ? " active" : "" ?><?= (isset($link["disabled"]) and $link["disabled"]) ? " disabled" : "" ?>"
|
||||
href="<?= $link["url"] ?>"
|
||||
<?= isset($link["target"]) ? " target=\"{$link["target"]}\"" : "" ?>
|
||||
title="<?= $link["aria"] ?>"
|
||||
aria-label="<?= $link["aria"] ?>"
|
||||
>
|
||||
<?php if ($link["icon"]) : ?>
|
||||
<?= $link["icon"] ?>
|
||||
|
||||
<span class="d-md-none">
|
||||
<?php else : ?>
|
||||
<span>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $link["text"] ?>
|
||||
</span>
|
||||
</a>
|
||||
<?php endif ?>
|
||||
</li>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</li>
|
||||
<?php else : ?>
|
||||
<li class="nav-item">
|
||||
<a
|
||||
class="nav-link<?= (isset($link["active"]) and $link["active"]) ? " active" : "" ?><?= (isset($link["disabled"]) and $link["disabled"]) ? " disabled" : "" ?>"
|
||||
href="<?= $link["url"] ?>"
|
||||
<?= isset($link["target"]) ? " target=\"{$link["target"]}\"" : "" ?>
|
||||
title="<?= $link["aria"] ?>"
|
||||
aria-label="<?= $link["aria"] ?>"
|
||||
>
|
||||
<?php if ($link["icon"]) : ?>
|
||||
<?= $link["icon"] ?>
|
||||
|
||||
<span class="d-md-none">
|
||||
<?php else : ?>
|
||||
<span>
|
||||
<?php endif ?>
|
||||
|
||||
<?= $link["text"] ?>
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
35
snippets/page/pagination.php
Normal file
35
snippets/page/pagination.php
Normal 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 ?>
|
||||
Reference in New Issue
Block a user