Exemple #1
0
 /**
  * Check if the user is an admin
  *
  * @param ElggUser $user User
  * @return boolean
  */
 public function isAdminUser($user)
 {
     if (!elgg_instanceof($user, 'user')) {
         return false;
     }
     return elgg_is_admin_user($user->guid);
 }
Exemple #2
0
/**
 * Set the user language to site language at login time to take into account the currently selected site language
 */
function monolingual_set_user_language($event, $object_type, $object)
{
    if ($event == 'login:after' && $object_type == 'user' && $object instanceof ElggUser) {
        if (!elgg_is_admin_user($object->guid)) {
            if (elgg_get_config('language')) {
                $object->language = elgg_get_config('language');
                $object->save();
            }
        }
    }
    return true;
}
Exemple #3
0
/**
 * Overrides the access system if appropriate.
 *
 * Allows admin users and calls after {@link elgg_set_ignore_access} to
 * bypass the access system.
 *
 * Registered for the 'permissions_check', 'all' and the 
 * 'container_permissions_check', 'all' plugin hooks.
 *
 * Returns true to override the access system or null if no change is needed.
 *
 * @return true|null
 * @access private
 */
function elgg_override_permissions($hook, $type, $value, $params)
{
    $user = elgg_extract('user', $params);
    if ($user) {
        $user_guid = $user->getGUID();
    } else {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // don't do this so ignore access still works with no one logged in
    //if (!$user instanceof ElggUser) {
    //	return false;
    //}
    // check for admin
    if ($user_guid && elgg_is_admin_user($user_guid)) {
        return true;
    }
    // check access overrides
    if (elgg_check_access_overrides($user_guid)) {
        return true;
    }
    // consult other hooks
    return NULL;
}
/**
 * Get access query for Solr search
 *
 * @param int $user_guid GUID of the user accessing content
 * @return string
 */
function elgg_solr_get_access_query($user_guid = null)
{
    if (elgg_get_ignore_access()) {
        return '';
    }
    if (!isset($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (elgg_is_admin_user($user_guid)) {
        return '';
    }
    $access_public = elgg_solr_escape_special_chars(ACCESS_PUBLIC);
    $access_friends = elgg_solr_escape_special_chars(ACCESS_FRIENDS);
    $user_guid = elgg_solr_escape_special_chars($user_guid);
    $queries = [];
    if ($user_guid) {
        $queries['ors']['collections'] = "access_id:{!join from=access_list_is to=access_id}id:{$user_guid}";
        $queries['ors']['is_owner'] = "owner_guid:{$user_guid}";
        $queries['ors']['is_friend'] = "access_id:{$access_friends} AND owner_guid:{!join from=friends_of_is to=owner_guid}id:{$user_guid}";
    } else {
        $queries['ors']['collections'] = "access_id:{$access_public}";
    }
    $params = ['user_guid' => $user_guid];
    $queries = elgg_trigger_plugin_hook('elgg_solr:access', 'entities', $params, $queries);
    if (!empty($queries['ors'])) {
        $ors = [];
        foreach ($queries['ors'] as $or) {
            $ors[] = "({$or})";
        }
        $queries['ands'][] = implode(' OR ', $ors);
    }
    $query_str = '';
    if (!empty($queries['ands'])) {
        $ands = [];
        foreach ($queries['ands'] as $and) {
            $ands[] = "({$and})";
        }
        $query_str = '(' . implode(' AND ', $ands) . ')';
    }
    return $query_str;
}
Exemple #5
0
<?php

$page_type = elgg_extract('page_type', $vars);
$guid = elgg_extract('guid', $vars);
elgg_entity_gatekeeper($guid, 'object', 'blog');
elgg_group_gatekeeper();
$blog = get_entity($guid);
if (!elgg_is_admin_user($blog->owner_guid)) {
    forward('', '404');
}
elgg_set_page_owner_guid($blog->container_guid);
// no header or tabs for viewing an individual blog
$params = ['filter' => '', 'title' => $blog->title];
$container = $blog->getContainerEntity();
$crumbs_title = $container->name;
if (elgg_instanceof($container, 'group')) {
    elgg_push_breadcrumb($crumbs_title, "blog/group/{$container->guid}/all");
} else {
    elgg_push_breadcrumb($crumbs_title, "blog/owner/{$container->username}");
}
elgg_push_breadcrumb($blog->title);
$params['content'] = elgg_view_entity($blog, array('full_view' => true));
// check to see if we should allow comments
if ($blog->comments_on != 'Off' && $blog->status == 'published') {
    $params['content'] .= elgg_view_comments($blog);
}
$params['sidebar'] = elgg_view('blog/sidebar', array('page' => $page_type));
$body = elgg_view_layout('content', $params);
echo elgg_view_page($params['title'], $body);
Exemple #6
0
/**
 * Check if the user is an admin
 * @param ElggUser $user
 * @return boolean
 */
function hj_inbox_is_admin_user($user)
{
    if (!elgg_instanceof($user, 'user')) {
        return false;
    }
    return elgg_is_admin_user($user->guid);
}
/**
 * Check if the provided user is a translation editor
 *
 * @param int $user_guid the user to check (defaults to current user)
 *
 * @return bool
 */
function translation_editor_is_translation_editor($user_guid = 0)
{
    static $editors_cache;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return false;
    }
    if (elgg_is_admin_user($user_guid)) {
        return true;
    }
    // preload all editors
    if (!isset($editors_cache)) {
        $editors_cache = array();
        $translation_editor_id = elgg_get_metastring_id('translation_editor');
        $true_id = elgg_get_metastring_id(true);
        $options = array('type' => 'user', 'limit' => false, 'joins' => array('JOIN ' . elgg_get_config('dbprefix') . 'metadata md ON e.guid = md.entity_guid'), 'wheres' => array("(md.name_id = {$translation_editor_id} AND md.value_id = {$true_id})"), 'callback' => 'translation_editor_guid_only');
        $guids = elgg_get_entities($options);
        if (!empty($guids)) {
            $editors_cache = $guids;
        }
    }
    // is the user an editor or an admin
    return in_array($user_guid, $editors_cache);
}
Exemple #8
0
<?php

$page_type = elgg_extract('page_type', $vars);
$username = elgg_extract('username', $vars);
$user = get_user_by_username($username);
if (!$user || !elgg_is_admin_user($user->guid)) {
    forward('', '404');
}
$params = blog_get_page_content_list($user->guid);
$params['sidebar'] = elgg_view('blog/sidebar', ['page' => $page_type]);
$body = elgg_view_layout('content', $params);
echo elgg_view_page($params['title'], $body);
Exemple #9
0
/**
 * Build a wall to block non-experts. Forward non-experts off the page.
 * User is considered an expert when he has the expert role on the site or in a group.
 * 
 * @return bool true if the user is an expert, false otherwise
 */
function questions_expert_gatekeeper()
{
    if (!questions_is_expert() && !elgg_is_admin_user()) {
        register_error(elgg_echo('questions:workflow:noaccess'));
        forward();
    }
}
Exemple #10
0
function event_calendar_can_add($group_guid = 0, $user_guid = 0)
{
    if (!$user_guid) {
        if (elgg_is_logged_in()) {
            $user_guid = elgg_get_logged_in_user_guid();
        } else {
            return FALSE;
        }
    }
    if ($group_guid) {
        if (!event_calendar_activated_for_group($group_guid)) {
            return FALSE;
        }
        $group = get_entity($group_guid);
        if (elgg_instanceof($group, 'group')) {
            $group_calendar = elgg_get_plugin_setting('group_calendar', 'event_calendar');
            if (!$group_calendar || $group_calendar == 'members') {
                return $group->canWriteToContainer($user_guid);
            } else {
                if ($group_calendar == 'admin') {
                    if ($group->canEdit($user_guid)) {
                        return TRUE;
                    } else {
                        return FALSE;
                    }
                }
            }
        } else {
            return FALSE;
        }
    } else {
        $site_calendar = elgg_get_plugin_setting('site_calendar', 'event_calendar');
        if (!$site_calendar || $site_calendar == 'admin') {
            // only admins can post directly to the site-wide calendar
            return elgg_is_admin_user($user_guid);
        } else {
            if ($site_calendar == 'loggedin') {
                // any logged-in user can post to the site calendar
                return TRUE;
            }
        }
    }
    return FALSE;
}
Exemple #11
0
     $monitorGroupGuids = '';
 }
 $monitorGroupGuidsArr = array_map('trim', explode(",", $monitorGroupGuids));
 $tutorUserGuids = get_plugin_setting('tutorUserGuids', 'activityAndPerformanceDashboard');
 if (!$tutorUserGuids) {
     $tutorUserGuids = '';
 }
 $tutorUserGuidsArr = array_map('trim', explode(",", $tutorUserGuids));
 $excludedUserGuids = get_plugin_setting('excludedUserGuids', 'activityAndPerformanceDashboard');
 if (!$excludedUserGuids) {
     $excludedUserGuids = '';
 }
 $excludedUserGuidsArr = array_map('trim', explode(",", $excludedUserGuids));
 $excludedFromDashboardUserGuids = '';
 //determine if current user is admin, tutor, user or excluded user
 $userIsAdmin = elgg_is_admin_user(get_loggedin_user()->guid);
 $userIsTutor = false;
 foreach ($tutorUserGuidsArr as $tutorUserGuid) {
     if ($tutorUserGuid > 0) {
         if (get_loggedin_user()->guid == $tutorUserGuid) {
             $userIsTutor = true;
         }
         if ($excludedFromDashboardUserGuids != '') {
             $excludedFromDashboardUserGuids .= ",";
         }
         $excludedFromDashboardUserGuids .= $tutorUserGuid;
     }
 }
 $userIsExcluded = false;
 foreach ($excludedUserGuidsArr as $excludedUserGuid) {
     if ($excludedUserGuid > 0) {
Exemple #12
0
/**
 * Check if the access system should be overridden.
 *
 * Allows admin users and calls after {@link elgg_set_ignore_access} to
 * by pass the access system.
 *
 * @return true|null
 * @since 1.7.0
 * @elgg_event_handler permissions_check all
 */
function elgg_override_permissions_hook()
{
    $user_guid = elgg_get_logged_in_user_guid();
    // check for admin
    if ($user_guid && elgg_is_admin_user($user_guid)) {
        return true;
    }
    // check access overrides
    if (elgg_check_access_overrides($user_guid)) {
        return true;
    }
    // consult other hooks
    return NULL;
}
/**
 * Override permissions system
 *
 * @return true|null
 */
function elgg_override_permissions_hook($hook, $type, $returnval, $params)
{
    $user_guid = get_loggedin_userid();
    // check for admin
    if ($user_guid && elgg_is_admin_user($user_guid)) {
        return true;
    }
    // check access overrides
    if (elgg_check_access_overrides($user_guid)) {
        return true;
    }
    // consult other hooks
    return NULL;
}
Exemple #14
0
<?php

/**
 * Provide a way of setting your language prefs
 *
 * @package Elgg
 * @subpackage Core
 *
 * Removing language selection in user settings for non-admins by overwriting core view
 *
 * (c) iionly 2012
 *
 */
$user = elgg_get_page_owner_entity();
if ($user && elgg_is_admin_user($user->guid)) {
    $title = elgg_echo('user:set:language');
    $content = elgg_echo('user:language:label') . ': ';
    $content .= elgg_view("input/select", array('name' => 'language', 'value' => $user->language, 'options_values' => get_installed_translations()));
    echo elgg_view_module('info', $title, $content);
} elseif ($user && elgg_get_config('language')) {
    echo elgg_view('input/hidden', array('name' => 'language', 'value' => elgg_get_config('language')));
}
use Exception;
$guids = get_input('user_guids');
if ($guids) {
    $count = count($guids);
    $error_nouser = $error_canedit = $error = $success = 0;
    foreach ($guids as $guid) {
        $user = get_entity($guid);
        if (!elgg_instanceof($user, 'user')) {
            $error_nouser++;
            continue;
        }
        if (!$user->canEdit()) {
            $error_canedit++;
            continue;
        }
        if ($user->guid == elgg_get_logged_in_user_guid() || elgg_is_admin_user($user->guid)) {
            $error++;
            continue;
        }
        $email = $user->email;
        $subject = elgg_echo("db_explorer:delete:email:subject");
        $body = elgg_view('framework/db_explorer/notifications/delete', array('entity' => $user, 'setter' => elgg_get_logged_in_user_entity(), 'note' => get_input('notify_users_message')));
        if ($user->delete(true)) {
            if (get_input('notify_users', false)) {
                try {
                    elgg_send_email(elgg_get_site_entity()->email, $email, $subject, $body);
                } catch (Exception $e) {
                    register_error($e->getMessage());
                }
            }
            $success++;