PageAccessReleasetime by Sebi

Enables you to set a start- and end-time for the release of pages. Prevents unreleased pages from being displayed.

PageAccessReleasetime

Enables you to set a start- and end-time for the release of pages. Prevents unreleased pages from being displayed.

ProcessWire-Module: http://processwire.com/modules/page-access-releasetime/

Support-Forum: https://processwire.com/talk/topic/20852-module-page-access-releasetime/

Github-Repo: 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

After that, you will find checkboxes for activating the releasetime-fields at the settings-tab of each page. You don't need to add the fields to your templates manually.

Check e.g. the checkbox "Activate Releasetime from?" and fill in a date in the future. The page will not be accessable for your users until the given date is reached.

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 and Page::listable to prevent users to access unreleased pages:

public function hookPageViewable($event) {
	$page = $event->object;
	$viewable = $event->return;

	if($viewable){
		// If the page would be viewable, additionally check Releasetime and User-Permission
		$viewable = $this->canUserSee($page);
	}
	$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.

public function hookPageIsPublic($e) {
	$page = $e->object;
	if($e->return && $this->isReleaseTimeSet($page)) {
		$e->return = false;
	}
}

The check wether a not-public file should be accessable happens in ProcessPageView::sendFile. We throw an 404 Exception if the current user must not see the file.

public function hookProcessPageViewSendFile($e) {
	$page = $e->arguments[0];
	if(!$this->canUserSee($page)) {
		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() 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:

$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!

Versioning


We use SemVer for versioning. For the versions available, see the tags on this repository.

License


This project is licensed under the Mozilla Public License Version 2.0 - see the LICENSE.md file for details.

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Latest news

  • ProcessWire Weekly #514
    In the 514th issue of ProcessWire Weekly we'll check out the latest blog post from Ryan, introduce two new third party modules — Page List Versions Counter and Fieldtype Fieldset Panel — and more. Read on!
    Weekly.pw / 16 March 2024
  • Invoices Site Profile
    The new invoices site profile is a free invoicing application developed in ProcessWire. It enables you to create invoices, record payments to them, email invoices to clients, print invoices, and more. This post covers all the details.
    Blog / 15 March 2024
  • Subscribe to weekly ProcessWire news

“I am currently managing a ProcessWire site with 2 million+ pages. It’s admirably fast, and much, much faster than any other CMS we tested.” —Nickie, Web developer