Skip to content
This repository has been archived by the owner on Aug 21, 2019. It is now read-only.

Commit

Permalink
added access to page models
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Meilick <b@bnomei.com>
  • Loading branch information
bnomei committed Apr 7, 2017
1 parent 6333194 commit 738107e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
24 changes: 22 additions & 2 deletions fields/opener/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$fileurl = c::get('plugin.opener.json.fileurl', 'fileurl');
$delay = c::get('plugin.opener.reset-delay', 5000); // ms
$popup = c::get('plugin.opener.popup-window', false);
$pagemodels = c::get('plugin.opener.allow-pagemodels', false);

if(strlen(trim($field->value)) > 0):
// locked
Expand All @@ -15,8 +16,20 @@

// vars for placeholders
// NOTE: page($page->id()); would be panel page
$page = $page;
$page = $page;
$pageModel = $pagemodels ? null : $page;
$site = $page->site();
if($pagemodels) {
//https://forum.getkirby.com/t/page-model-doesnt-working-inside-file-hook/2994/4
$kirby = kirby();
if(count(Page::$models) == 0) {
$kirby->models();
}
$cname = str::lower($page->template().'Page');
if(a::get(Page::$models, $page->template()) == $cname) {
$pageModel = new $cname($page->parent(), $page->dirname());
}
}
$pages = $site->pages();

$settings = c::get('plugin.opener.placeholder', array());
Expand Down Expand Up @@ -66,9 +79,16 @@
for($c = 1; $c < count($chain); $c++) {
if(isset($obj)) {
$method = str_replace('()', '', $chain[$c]);

if(is_callable([$obj, $method])) {
$obj = $obj->{$method}();

if($obj == $pageModel && method_exists($obj,$method)) {
$obj = $obj->{$method}();
} else {
$obj = $obj->{$method}();
}
}

}
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kirby-opener",
"description": "Kirby Opener is a Kirby CMS Panel Field button that allows you to use placeholders to create dynamic urls which are called with and without ajax response or start downloads.",
"version": "0.5.2",
"version": "0.6.0",
"author": "Bruno Meilick",
"type": "kirby-plugin",
"license": "Commercial"
Expand Down
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ You can set these in your `site/config/config.php`.
- default: 'open:yes'
- command part to tell the plugin js script to trigger a new window/tab with command as url. There will be no ajax call.

### plugins.opener.allow-pagemodels
- default: false
- if enabled you can use `$pageModel` in your placeholders to access functions defined in your [Kirby Page Models](https://getkirby.com/docs/developer-guide/advanced/models).

### plugins.opener.allow-eval
- default: false
- commands only allow you to chain `$page` or `$site` and their methods but without parameters. If you enabled `allow-eval` you can go crazy with your placeholders up to 100 chars and a single statement. But since `eval()` is dangerous this setting is disabled by default. Please be aware of the risks of you enable this setting.
Expand Down

0 comments on commit 738107e

Please sign in to comment.