Skip to content

Commit 00d601d

Browse files
author
Sonja Broda
committed
Some code refactoring
1 parent 0c19075 commit 00d601d

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ foreach($relatedImages as $image) {
6464
6565
```
6666

67+
### Config options
68+
69+
You can set the cache to true or false using the `texnixe.related.cache` option.
70+
71+
```
72+
return [
73+
'texnixe.related.cache' => true
74+
];
75+
```
76+
77+
6778
### Options
6879

6980
You can pass an array of options:
@@ -79,6 +90,7 @@ $relatedPages = $page->related(array(
7990
));
8091
?>
8192
```
93+
8294
#### searchCollection
8395

8496
The pages collection to search in.
@@ -104,9 +116,14 @@ Default: 1
104116
Filter related items by language in a multi-language installation.
105117
Default: false
106118

119+
## Disclaimer
120+
121+
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you encounter any problem, please [create an issue](https://github.com/texnixe/kirby3-codepen/issues/new).
107122

108123
## License
109124

110-
Kirby 3 Related is open-sourced software licensed under the MIT license.
125+
[MIT](https://opensource.org/licenses/MIT)
126+
127+
128+
It is discouraged to use this plugin in any project that promotes racism, sexism, homophobia, animal abuse, violence or any other form of hate speech.
111129

112-
Copyright © 2019 Sonja Broda info@texniq.de https://sonjabroda.com

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "texnixe/related",
33
"description": "Fetch related pages or files based on the values of a given field ",
4-
"version": "0.9.2",
4+
"version": "1.0.0",
55
"type": "kirby-plugin",
66
"license": "MIT",
77
"authors": [

hooks.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace texnixe\Related;
4+
5+
return [
6+
'page.update:after' => function() {
7+
Related::flush();
8+
},
9+
'page.create:after' => function() {
10+
Related::flush();
11+
},
12+
'file.create:after' => function() {
13+
Related::flush();
14+
},
15+
'page.update:after' => function() {
16+
Related::flush();
17+
}
18+
];

index.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?php
2+
3+
namespace texnixe\Related;
4+
25
/**
36
* Kirby 3 Related Pages Plugin
47
*
5-
* @version 0.9.2
8+
* @version 1.0.0
69
* @author Sonja Broda <info@texniq.de>
710
* @copyright Sonja Broda <info@texniq.de>
811
* @link https://github.com/texnixe/kirby-related
@@ -13,9 +16,9 @@
1316
'texnixe\\related\\related' => 'src/Related.php'
1417
], __DIR__);
1518

16-
Kirby::plugin('texnixe/related', [
19+
\Kirby::plugin('texnixe/related', [
1720
'options' => [
18-
'cache' => true,
21+
'cache' => option('texnixe.related.cache', true),
1922
'expires' => (60*24*7), // minutes
2023
'defaults' => [
2124
'searchField' => 'tags',
@@ -26,28 +29,15 @@
2629
],
2730
'pageMethods' => [
2831
'related' => function (array $options = []) {
29-
return Texnixe\Related\Related::getRelated($this, $options);
32+
return Related::getRelated($this, $options);
3033
}
3134
],
3235
'fileMethods' => [
3336
'related' => function (array $options = []) {
34-
return Texnixe\Related\Related::getRelated($this, $options);
37+
return Related::getRelated($this, $options);
3538
}
3639
],
37-
'hooks' => [
38-
'page.update:after' => function() {
39-
Texnixe\Related\Related::flush();
40-
},
41-
'page.create:after' => function() {
42-
Texnixe\Related\Related::flush();
43-
},
44-
'file.create:after' => function() {
45-
Texnixe\Related\Related::flush();
46-
},
47-
'page.update:after' => function() {
48-
Texnixe\Related\Related::flush();
49-
}
50-
]
40+
'hooks' => require __DIR__ . '/hooks.php'
5141
]);
5242

5343

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "Kirby Related plugin",
44
"author": "Sonja Broda <sonja@texniq.de>",
55
"license": "MIT",
6-
"version": "0.9.2",
6+
"version": "1.0.0",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/texnixe/kirby-related"

src/Related.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Texnixe\Related;
3+
namespace texnixe\Related;
44

55

66
class Related
@@ -47,7 +47,7 @@ public static function data($basis, $options = [])
4747
$languageFilter = $options['languageFilter'];
4848

4949
// get search items from active basis
50-
$searchItems = $basis->{$searchField}()->split(',');
50+
$searchItems = $basis->{$searchField}()->split($delimiter);
5151
$noOfSearchItems = count($searchItems);
5252

5353
if($noOfSearchItems > 0) {
@@ -76,10 +76,10 @@ public static function data($basis, $options = [])
7676

7777
public static function getClassName($basis, $items = '')
7878
{
79-
if(is_a($basis, 'Kirby\Cms\Page')) {
79+
if(is_a($basis, '\Kirby\Cms\Page')) {
8080
return pages($items);
8181
}
82-
if(is_a($basis, 'Kirby\Cms\File')) {
82+
if(is_a($basis, '\Kirby\Cms\File')) {
8383
return new \Kirby\Cms\Files($items);
8484
}
8585
}

0 commit comments

Comments
 (0)