Exemplo n.º 1
0
/**
 *
 * Processes page permissions from the role configuration array. This is called upon each "route" triggered hook.
 *
 * @param string $hook_name Equals "route"
 * @param string $type The triggered "register" hook's type
 * @param mixed $return_value
 * @param mixed $params An associative array of parameters provided by the hook trigger
 */
function roles_pages_permissions($hook_name, $type, $return_value, $params)
{
    $role = roles_get_role();
    if (elgg_instanceof($role, 'object', 'role')) {
        $role_perms = roles_get_role_permissions($role, 'pages');
        $page_path = $return_value['handler'] . '/' . implode('/', $return_value['segments']);
        if (is_array($role_perms) && !empty($role_perms)) {
            foreach ($role_perms as $page => $perm_details) {
                if (roles_path_match(roles_replace_dynamic_paths($page), $page_path)) {
                    switch ($perm_details['rule']) {
                        case 'deny':
                            register_error(elgg_echo('roles:page:denied'));
                            if (isset($perm_details['forward'])) {
                                forward($perm_details['forward']);
                            } else {
                                forward(REFERER);
                            }
                            break;
                        case 'redirect':
                            if (isset($perm_details['forward'])) {
                                forward($perm_details['forward']);
                            } else {
                                forward(REFERER);
                            }
                            break;
                        case 'allow':
                        default:
                            break;
                    }
                }
            }
        }
    }
}
Exemplo n.º 2
0
/**
 *
 * Substitutes dynamic parts of a menu's target URL
 *
 * @param array $vars An associative array holding the menu permissions
 *
 * @return The substituted menu permission array
 */
function roles_prepare_menu_vars($vars)
{
    $prepared_vars = $vars;
    if (isset($prepared_vars['href'])) {
        $prepared_vars['href'] = roles_replace_dynamic_paths($prepared_vars['href']);
    }
    return $prepared_vars;
}