Exemple #1
0
/**
 *
 * Processes event permissions from the role configuration array. Triggered by the 'ready', 'system' event.
 * This is to make sure that all plugins' init functions have been executed, and all event handlers have already been initialized
 *
 * @param string $event Equals 'ready'
 * @param string $event_type Equals 'system'
 * @param mixed $object Not in use for this specific listener
 * @return boolean
 */
function roles_events_permissions($event, $type, $object)
{
    $role = roles_get_role();
    if (elgg_instanceof($role, 'object', 'role')) {
        $role_perms = roles_get_role_permissions($role, 'events');
        if (is_array($role_perms) && !empty($role_perms)) {
            foreach ($role_perms as $event => $perm_details) {
                list($event_name, $type) = explode('::', $event);
                if (!$type) {
                    $type = 'all';
                }
                switch ($perm_details['rule']) {
                    case 'deny':
                        $params = $perm_details['event'];
                        if (is_array($params)) {
                            $handler = $params['handler'];
                            elgg_unregister_event_handler($event_name, $type, $handler);
                        } else {
                            global $CONFIG;
                            unset($CONFIG->events[$event_name][$type]);
                        }
                        break;
                    case 'extend':
                        $params = $perm_details['event'];
                        $handler = $params['handler'];
                        $priority = isset($params['priority']) ? $params['priority'] : 500;
                        elgg_register_event_handler($event_name, $type, $handler, $priority);
                        break;
                    case 'replace':
                        $params = $perm_details['hook'];
                        $old_handler = $params['old_handler'];
                        $new_handler = $params['new_handler'];
                        $priority = isset($params['priority']) ? $params['priority'] : 500;
                        elgg_unregister_event_handler($event_name, $type, $old_handler);
                        elgg_register_event_handler($event_name, $type, $new_handler, $priority);
                        break;
                    case 'allow':
                    default:
                        break;
                }
            }
        }
    }
    return true;
}
Exemple #2
0
<?php

namespace Elgg\Roles\UI;

$role = elgg_extract('entity', $vars);
elgg_extend_view('js/initialize_elgg', 'js/roles/ui/config');
elgg_load_js('roles.ui.admin');
elgg_load_css('roles.ui.admin');
$permission_types = array('actions', 'events', 'hooks', 'menus', 'views', 'pages');
$perms = isset($role->permissions) ? unserialize($role->permissions) : array();
echo '<ul class="roles-ui-permissions">';
foreach ($permission_types as $ptype) {
    $aggregated_perms = roles_get_role_permissions($role, $ptype);
    if (is_array($aggregated_perms)) {
        foreach ($aggregated_perms as $pname => $pdetails) {
            if (!$pdetails) {
                continue;
            }
            echo '<li>' . elgg_view("forms/roles/permissions/{$ptype}", array('name' => $pname, 'details' => $pdetails, 'actionable' => is_array($perms[$ptype]) && array_key_exists($pname, $perms[$ptype]))) . '</li>';
        }
    }
}
echo '</ul>';
echo '<div class="roles-ui-forms">';
foreach ($permission_types as $ptype) {
    echo elgg_view("forms/roles/templates/{$ptype}");
}
echo '</div>';
echo '<div class="elgg-foot">';
echo elgg_view('input/hidden', array('name' => 'guid', 'value' => $role->guid));
echo '<div class="roles-ui-buttonbank clearfix">';