diff --git a/PageAccessReleasetime.module.php b/PageAccessReleasetime.module.php index 22c2d26..297d40c 100755 --- a/PageAccessReleasetime.module.php +++ b/PageAccessReleasetime.module.php @@ -14,7 +14,7 @@ public static function getModuleInfo() { return array( 'title' => __('Page Access Releasetime'), 'author' => 'Sebastian Schendel', - 'version' => '1.0.3', + 'version' => '1.0.4', 'summary' => __('Enables you to set a start- and end-time for the release of pages. Prevents unreleased pages from being displayed.'), 'singular' => true, 'autoload' => true, @@ -134,13 +134,14 @@ public static function getModuleConfigInputfields(array $data) { foreach(wire('templates') as $template) { // Exclude system templates: if($template->flags & Template::flagSystem) continue; - $f->addOption($template->id, $template->getLabel()); + $f->addOption($template->id, $template->getLabel() . ' (' . $template->name . ')'); // Check, if the template already has all releasetime-fields: $allFieldsExistFlag = true; foreach(self::fieldnames as $fieldname){ if(!$template->hasField($fieldname)){ $allFieldsExistFlag = false; + break; } } @@ -166,6 +167,9 @@ public function init() { // Prevent unreleased pagse from being viewed $this->addHook('Page::viewable', $this, 'hookPageViewable'); + // Unreleased pages cannot be listed: + $this->addHook('Page::listable', $this, 'hookPageListable'); + // Manage access to files ($config->pagefileSecure has to be true) $this->addHookAfter('Page::isPublic', $this, 'hookPageIsPublic'); $this->addHookBefore('ProcessPageView::sendFile', $this, 'hookProcessPageViewSendFile'); @@ -196,6 +200,17 @@ public function hookPageViewable(HookEvent $event) { $event->return = $viewable; } + public function hookPageListable(HookEvent $event) { + $page = $event->object; + $listable = $event->return; + + if($listable){ + // If the page would be listable, additionally check Releasetime and User-Permission + $listable = $this->canUserSee($page); + } + $event->return = $listable; + } + /** * if Page::isPublic() returns false a prefix (-) will be added to the name of the assets directory * the directory is not accessible directly anymore diff --git a/README.md b/README.md index 9dea6be..16852e8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # PageAccessReleasetime Enables you to set a start- and end-time for the release of pages. Prevents unreleased pages from being displayed. +ProcessWire-Module: [http://modules.processwire.com/modules/page-access-releasetime/](http://modules.processwire.com/modules/page-access-releasetime/) +Support-Forum: [https://processwire.com/talk/topic/20852-module-page-access-releasetime/](https://processwire.com/talk/topic/20852-module-page-access-releasetime/) +Github-Repo: [https://github.com/Sebiworld/PageAccessReleasetime](https://github.com/Sebiworld/PageAccessReleasetime) + ## Usage PageAccessReleasetime can be installed like every other module in ProcessWire. Check the following guide for detailed information: [How-To Install or Uninstall Modules](http://modules.processwire.com/install-uninstall/) @@ -11,7 +15,7 @@ Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the f If you have `$config->pagefileSecure = true`, the module will protect files of unreleased pages as well. ## How it works -This module hooks into `Page::viewable` to prevent users to access unreleased pages: +This module hooks into `Page::viewable` and `Page::listable` to prevent users to access unreleased pages: ```php public function hookPageViewable($event) { @@ -24,12 +28,23 @@ public function hookPageViewable($event) { } $event->return = $viewable; } - + +public function hookPageListable($event) { + $page = $event->object; + $listable = $event->return; + + if($listable){ + // If the page would be listable, additionally check Releasetime and User-Permission + $listable = $this->canUserSee($page); + } + $event->return = $listable; +} + ``` To prevent access to the files of unreleased pages, we hook into `Page::isPublic` and `ProcessPageView::sendFile`. -The site/assets/files/ directory of pages, which `isPublic()` returns false, will get a '-' as prefix. This indicates ProcessWire (with activated `$config->pagefileSecure`) to check the file's permissions via PHP before delivering it to the client. +The site/assets/files/ directory of pages, which `isPublic()` returns false, will get a '-' as prefix. This indicates ProcessWire (with activated `$config->pagefileSecure`) to check the file's permissions via PHP before delivering it to the client. ```php public function hookPageIsPublic($e) { @@ -49,12 +64,12 @@ public function hookProcessPageViewSendFile($e) { throw new Wire404Exception('File not found'); } } - + ``` Additionally we hook into `ProcessPageEdit::buildForm` to add the PageAccessReleasetime fields to each page and move them to the settings tab. ## Limitations -In the current version, releasetime-protected pages will appear in `wire('pages')->find()` queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with `$page->viewable()` wether the page can be accessed. `$page->viewable()` returns false, if the page is not released yet. +In the current version, releasetime-protected pages will appear in `wire('pages')->find()` queries. If you want to display a list of pages, where pages could be releasetime-protected, you should double-check with `$page->viewable()` or `$page->listable()` (for lists) wether the page can be accessed. `$page->viewable()` returns false, if the page is not released yet. To filter unreleased pages, add the `PageAccessReleasetime::selector` to your selector: @@ -62,10 +77,10 @@ To filter unreleased pages, add the `PageAccessReleasetime::selector` to your se $onlyReleasedPages = wire('pages')->find('template.name=news, ' . PageAccessReleasetime::selector); ``` -If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request! +If you have an idea how unreleased pages can be filtered out of ProcessWire selector queries, feel free to write an issue, comment or make a pull request! ## Versioning -We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/Sebiworld/PageAccessReleasetime/tags). +We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/Sebiworld/PageAccessReleasetime/tags). ## License This project is licensed under the Mozilla Public License Version 2.0 - see the [LICENSE.md](LICENSE.md) file for details.