Last active
August 29, 2015 14:13
-
-
Save Da-Fecto/43b03e76b65dc2bfa59c to your computer and use it in GitHub Desktop.
Module to hide pages that are not editable by the logged in user.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This module is build by Adrian, tnx Adrian. | |
* | |
* | |
* Module to hide pages that are not editable by the logged in user. | |
* | |
* ProcessWire 2.x | |
* Copyright (C) 2010 by Ryan Cramer | |
* Licensed under GNU/GPL v2, see LICENSE.TXT | |
* | |
* http://www.processwire.com | |
* http://www.ryancramer.com | |
* | |
*/ | |
class HideUneditablePages extends WireData implements Module { | |
public static function getModuleInfo() { | |
return array( | |
'title' => 'HideUneditablePages', | |
'version' => 1, | |
'summary' => 'Module to hide pages that are not editable by the logged in user.', | |
'href' => '', | |
'singular' => true, | |
'autoload' => true | |
); | |
} | |
public function init() { | |
// only add hook only if the render parameter is set | |
// (as used by ProcessPageList) | |
// or if superuser, also exit | |
if(!isset($_GET['render']) || $this->user->isSuperuser()) return; | |
$this->addHookAfter('ProcessPageList::execute', $this, 'pageListHiddenPages'); | |
} | |
public function pageListHiddenPages(HookEvent $event){ | |
// make sure it's an ajax request | |
if($this->config->ajax){ | |
// manipulate the json returned and remove any pages found from array | |
$json = json_decode($event->return, true); | |
foreach($json['children'] as $key => $child){ | |
$c = $this->pages->get($child['id']); | |
$pagetemplate = $c->template; | |
$uroles = $this->user->roles->implode(',', 'id'); | |
$uroles = explode(',', $uroles); | |
if(is_array($pagetemplate->editRoles) || is_array($pagetemplate->addRoles)) { | |
if(!array_intersect($uroles, $pagetemplate->editRoles) && !array_intersect($uroles, $pagetemplate->addRoles)) unset($json['children'][$key]); | |
} | |
} | |
$json['children'] = array_values($json['children']); | |
$event->return = json_encode($json); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment