block.if_authorized.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
12 
13 /*
14 * Smarty plugin
15 * -------------------------------------------------------------
16 * File: block.if_authorized.php
17 * Type: block
18 * Name: if_authorized
19 * Purpose: render content based on authorization
20 * Parameters: resource The resource to authorize (e.g. class name of the Controller or OID).
21 * context The context in which the action takes place.
22 * action The action to process.
23 * alternative_content The content to display if not authorized
24 * Usage: {if_authorized resource="Category" action="delete"}
25 * ... content only visible
26 * for authorized users ...
27 * {/if_authorized}
28 *
29 * Author: Ingo Herwig <ingo@wemove.com>
30 * -------------------------------------------------------------
31 */
32 function smarty_block_if_authorized($params, $content, \Smarty_Internal_Template $template, &$repeat) {
33  if(!$repeat) {
34  $permissionManager = ObjectFactory::getInstance('permissionManager');
35  if ($permissionManager->authorize($params['resource'], $params['context'], $params['action'])) {
36  return $content;
37  }
38  else {
39  return $params['alternative_content'];
40  }
41  }
42 }
43 ?>