Skip to content

Commit

Permalink
Fix Recursive *.author Hook Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
taufik-nurrohman committed Feb 14, 2018
1 parent 749268b commit 494d5aa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions user/about.page
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: User
description: Rich user data.
author: Taufik Nurrohman
type: Markdown
version: 1.3.4
version: 1.4.0
...

### Without User Extension
Expand Down Expand Up @@ -42,8 +42,8 @@ The user file as `lot\user\ta-tau-taufik.page`:

~~~ .yaml
---
$: Taufik Nurrohman
link: http://example.com
author: Taufik Nurrohman
...

Page content.
Expand Down
8 changes: 3 additions & 5 deletions user/engine/kernel/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ class User extends Genome {

public function __construct($id, $lot = [], $NS = []) {
$input = File::exist(USER . DS . $id . '.page', null);
$this->lot = new Page($input, $lot, array_replace([
X, // TODO: re-enable the `*.key` hook
__c2f__(static::class, '_', '\\')
], $NS));
$this->lot = new Page($input, $lot, array_replace([1 => __c2f__(static::class, '_', '\\')], $NS));
$this->lot->url = $GLOBALS['URL']['$'] . '/' . Extend::state('user', 'path') . '/' . $id;
if (!$this->lot->key) {
$this->lot->key = $id;
}
Expand Down Expand Up @@ -45,7 +43,7 @@ public function __unset($key) {
}

public function __toString() {
return $this->lot->author('@' . $this->lot->key) . "";
return $this->lot->{'$'}('@' . $this->lot->key) . "";
}

}
4 changes: 3 additions & 1 deletion user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ function fn_user($author) {
return $author;
}

Hook::set('*.author', 'fn_user', 1);
Hook::set('*.author', 'fn_user', 1);

include __DIR__ . DS . 'lot' . DS . 'worker' . DS . 'route.php';
24 changes: 24 additions & 0 deletions user/lot/worker/route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

Route::lot('%*%', function($path) use($site) {
$s = explode('/', $path);
if (count($s) === 2 && $s[0] === Extend::state('user', 'path')) {
if (!$f = File::exist([
USER . DS . $s[1] . '.page',
USER . DS . $s[1] . '.archive'
])) {
Shield::abort();
}
$page = new Page($f);
if ($t = $page->{'$'}) {
$page->title = $t;
}
Config::set('page.title', new Anemon([$t . ' (@' . $s[1] . ')', $site->title], ' &#x00B7; '));
Lot::set([
'page' => $page,
'pages' => [],
'pager' => new Elevator([], 1, 0, true)
]);
Shield::attach('page/' . $path);
}
});

0 comments on commit 494d5aa

Please sign in to comment.