block.if_authorized.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 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  * Render content based on authorization.
15  *
16  * Example:
17  * @code
18  * {if_authorized resource="Category" action="delete"}
19  * ... content only visible
20  * for authorized users ...
21  * {/if_authorized}
22  * @endcode
23  *
24  * @note Works only for local files.
25  *
26  * @param $params Array with keys:
27  * - resource: The resource to authorize (e.g. class name of the Controller or OID)
28  * - context: The context in which the action takes place
29  * - action: The action to process
30  * - alternative_content: The content to display if not authorized
31  * @param $content
32  * @param $template Smarty_Internal_Template
33  * @param $repeat
34  * @return String
35  */
36 function smarty_block_if_authorized($params, $content, \Smarty_Internal_Template $template, &$repeat) {
37  if(!$repeat) {
38  $permissionManager = ObjectFactory::getInstance('permissionManager');
39  if ($permissionManager->authorize($params['resource'], $params['context'], $params['action'])) {
40  return $content;
41  }
42  else {
43  return $params['alternative_content'];
44  }
45  }
46 }
47 ?>
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...