[Beeframework-svn] SF.net SVN: beeframework:[87] trunk/framework
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2013-09-16 20:10:48
|
Revision: 87
http://sourceforge.net/p/beeframework/code/87
Author: m_plomer
Date: 2013-09-16 20:10:46 +0000 (Mon, 16 Sep 2013)
Log Message:
-----------
- smarty block function for Auth::hasRole
Added Paths:
-----------
trunk/framework/resources/
trunk/framework/resources/smarty/
trunk/framework/resources/smarty/block.bee_auth_has_role.php
Added: trunk/framework/resources/smarty/block.bee_auth_has_role.php
===================================================================
--- trunk/framework/resources/smarty/block.bee_auth_has_role.php (rev 0)
+++ trunk/framework/resources/smarty/block.bee_auth_has_role.php 2013-09-16 20:10:46 UTC (rev 87)
@@ -0,0 +1,53 @@
+<?php
+/*
+ * Copyright 2008-2013 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Smarty
+ *
+ */
+/**
+ * Smarty block displayed if the currently authenticated user has a given role.
+ * Parameters:
+ * - all (string) - comma-separated list of roles the user is required to have
+ * - any (string) - comma-separated list of roles the user may have
+ * - none (string) - comma-separated list of roles the user must not have
+ * @param $params
+ * @param $content
+ * @param $smarty
+ * @param $repeat
+ * @return mixed
+ */
+function smarty_block_bee_auth_has_role ($params, $content, &$smarty, &$repeat) {
+ if($repeat) {
+ $roles = Bee_Security_Helper::getRoles();
+
+ $requiredRoles = array_map('trim', explode(',', $params['all']));
+ $possibleRoles = array_map('trim', explode(',', $params['any']));
+ $forbiddenRoles = array_map('trim', explode(',', $params['none']));
+
+ // check if all required roles present
+ $repeat = array_intersect($roles, $requiredRoles) === $requiredRoles;
+
+ // check if any of the possible roles are present
+ $repeat = $repeat && count($possibleRoles) > 0 ? count(array_intersect($roles, $possibleRoles)) > 0 : true;
+
+ // check that none of the forbidden roles are present
+ $repeat = $repeat && count(array_intersect($roles, $forbiddenRoles)) === 0;
+ }
+ return $content;
+}
+
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|