Esempio n. 1
0
/**
 * Get some input from variables passed submitted through GET or POST.
 *
 * If using any data obtained from get_input() in a web page, please be aware that
 * it is a possible vector for a reflected XSS attack. If you are expecting an
 * integer, cast it to an int. If it is a string, escape quotes.
 *
 * Note: this function does not handle nested arrays (ex: form input of param[m][n])
 * because of the filtering done in htmlawed from the filter_tags call.
 * @todo Is this ^ still true?
 *
 * @param string $variable      The variable name we want.
 * @param mixed  $default       A default value for the variable if it is not found.
 * @param bool   $filter_result If true, then the result is filtered for bad tags.
 *
 * @return mixed
 */
function get_input($variable, $default = null, $filter_result = true)
{
    global $CONFIG;
    $result = $default;
    elgg_push_context('input');
    if (isset($CONFIG->input[$variable])) {
        // a plugin has already set this variable
        $result = $CONFIG->input[$variable];
        if ($filter_result) {
            $result = filter_tags($result);
        }
    } else {
        $request = _elgg_services()->request;
        $value = $request->get($variable);
        if ($value !== null) {
            $result = $value;
            if (is_string($result)) {
                // @todo why trim
                $result = trim($result);
            }
            if ($filter_result) {
                $result = filter_tags($result);
            }
        }
    }
    elgg_pop_context();
    return $result;
}
Esempio n. 2
0
 /**
  * Test anchor tags as input
  */
 public function testHtmlawedFilterTagsAnchorsInput()
 {
     $tests = array();
     // these should all work
     foreach ($this->validSchemes as $scheme) {
         $input = "<a href=\"{$scheme}://test\">Test</a>";
         $tests[$input] = "<a href=\"{$scheme}://test\">Test</a>";
     }
     $bad_schemes = array('javascript', 'itmss', 'magnet');
     // these should be denied
     foreach ($bad_schemes as $scheme) {
         $input = "<a href=\"{$scheme}://test\">Test</a>";
         $tests[$input] = "<a href=\"denied:{$scheme}://test\">Test</a>";
     }
     // set context to input to avoid adding nofollow
     elgg_push_context('input');
     foreach ($tests as $input => $expected) {
         $result = _elgg_htmlawed_filter_tags(null, null, $input);
         $this->assertEqual($expected, $result);
     }
     $weird_schemes = array('<a href="http://javascript:alert">Test</a>' => '<a href="http://javascript:alert">Test</a>', '<a href="javascript:https://">Test</a>' => '<a href="denied:javascript:https://">Test</a>', '<a href="ftp:\\/\\/">Test</a>' => '<a href="ftp:\\/\\/">Test</a>');
     foreach ($weird_schemes as $input => $expected) {
         $result = _elgg_htmlawed_filter_tags(null, null, $input);
         $this->assertEqual($expected, $result);
     }
     elgg_pop_context();
 }
Esempio n. 3
0
/**
 * Listen to the registration of a new user
 *
 * @param string $hook         the name of the hook
 * @param string $type         the type of the hook
 * @param bool   $return_value the current return value
 * @param array  $params       supplied params
 *
 * @return bool
 */
function uservalidationbyadmin_register_user_hook($hook, $type, $return_value, $params)
{
    if (empty($params) || !is_array($params)) {
        return $return_value;
    }
    $user = elgg_extract("user", $params);
    if (empty($user) || !elgg_instanceof($user, "user")) {
        return $return_value;
    }
    // make sure we can see everything
    $hidden = access_get_show_hidden_status();
    access_show_hidden_entities(true);
    // make sure we can save metadata
    elgg_push_context("uservalidationbyadmin_new_user");
    // this user needs validation
    $user->admin_validated = false;
    // check who to notify
    $notify_admins = uservalidationbyadmin_get_admin_notification_setting();
    if ($notify_admins == "direct") {
        uservalidationbyadmin_notify_admins();
    }
    // check if we need to disable the user
    if ($user->isEnabled()) {
        $user->disable();
    }
    // restore context
    elgg_pop_context();
    // restore access settings
    access_show_hidden_entities($hidden);
    return $return_value;
}
Esempio n. 4
0
 public static function prepareMenu($h, $t, $v, $p)
 {
     $default = new MenuList(elgg_extract('default', $v, []));
     $alt = new MenuList(elgg_extract('alt', $v, []));
     // dump alt items into default
     $default->appendList($alt);
     $avatar = $default->get('profile');
     $account = $default->get('account');
     if ($avatar && $account) {
         $user = elgg_get_logged_in_user_entity();
         // copy account children under avatar
         $children = new MenuList($account->getChildren());
         // copy admin out
         $admin = $children->remove('administration');
         $url = $avatar->getHref();
         $profile = new \ElggMenuItem('view-profile', elgg_echo('profile'), $url);
         $children->move($profile, 0);
         $avatar->setHref(null);
         elgg_push_context('mrclay_aalborg_topbar');
         $avatar->setText(elgg_view_entity_icon($user, 'tiny'));
         elgg_pop_context();
         $default->remove($account);
         $default->push($avatar);
         if ($admin) {
             $admin->setTooltip(elgg_echo('admin'));
             $admin->setText(elgg_view_icon('settings-alt'));
             $default->move($admin, 0);
         }
     }
     return ['default' => $default->getItems()];
 }
Esempio n. 5
0
/**
 * Disables a user upon registration.
 *
 * @param string $hook
 * @param string $type
 * @param bool   $value
 * @param array  $params
 * @return bool
 */
function uservalidationbyemail_disable_new_user($hook, $type, $value, $params)
{
    $user = elgg_extract('user', $params);
    // no clue what's going on, so don't react.
    if (!$user instanceof ElggUser) {
        return;
    }
    // another plugin is requesting that registration be terminated
    // no need for uservalidationbyemail
    if (!$value) {
        return $value;
    }
    // has the user already been validated?
    if (elgg_get_user_validation_status($user->guid) == true) {
        return $value;
    }
    // disable user to prevent showing up on the site
    // set context so our canEdit() override works
    elgg_push_context('uservalidationbyemail_new_user');
    $hidden_entities = access_get_show_hidden_status();
    access_show_hidden_entities(TRUE);
    // Don't do a recursive disable.  Any entities owned by the user at this point
    // are products of plugins that hook into create user and might need
    // access to the entities.
    // @todo That ^ sounds like a specific case...would be nice to track it down...
    $user->disable('uservalidationbyemail_new_user', FALSE);
    // set user as unvalidated and send out validation email
    elgg_set_user_validation_status($user->guid, FALSE);
    uservalidationbyemail_request_validation($user->guid);
    elgg_pop_context();
    access_show_hidden_entities($hidden_entities);
    return $value;
}
Esempio n. 6
0
function list_subgroups($group, $options = array())
{
    if ($group instanceof ElggGroup) {
        $defaults = array('full_view' => false, 'pagination' => true);
        $options = array_merge($defaults, $options);
        $options['type'] = 'group';
        $options['container_guid'] = $group->guid;
        elgg_push_context('subgroups');
        $list = elgg_list_entities($options);
        elgg_pop_context();
        return $list;
    } else {
        return "";
    }
}
Esempio n. 7
0
function list_relatedgroups($group, $options = array())
{
    if ($group instanceof ElggGroup) {
        $defaults = array('full_view' => false, 'pagination' => true);
        $options = array_merge($defaults, $options);
        $options['relationship'] = 'related';
        $options['relationship_guid'] = $group->guid;
        elgg_push_context('relatedgroups');
        $list = elgg_list_entities_from_relationship($options);
        elgg_pop_context();
        return $list;
    } else {
        return "";
    }
}
Esempio n. 8
0
 public function testContainsTellsYouIfAGivenContextIsInTheCurrentStack()
 {
     $context = new Context();
     $context->push('foo');
     $context->push('bar');
     $context->push('baz');
     $this->assertTrue($context->contains('foo'));
     $this->assertTrue($context->contains('bar'));
     $this->assertTrue($context->contains('baz'));
     $popped = $context->pop();
     $this->assertFalse($context->contains($popped));
     // TODO: remove once global state is fully deprecated (2.0)
     _elgg_services()->setValue('context', new Context());
     elgg_push_context('foo');
     elgg_push_context('bar');
     elgg_push_context('baz');
     $this->assertTrue(elgg_in_context('foo'));
     $this->assertTrue(elgg_in_context('bar'));
     $this->assertTrue(elgg_in_context('baz'));
     $popped = elgg_pop_context();
     $this->assertFalse(elgg_in_context($popped));
 }
Esempio n. 9
0
/**
 * Get some input from variables passed submitted through GET or POST.
 *
 * If using any data obtained from get_input() in a web page, please be aware that
 * it is a possible vector for a reflected XSS attack. If you are expecting an
 * integer, cast it to an int. If it is a string, escape quotes.
 *
 * Note: this function does not handle nested arrays (ex: form input of param[m][n])
 * because of the filtering done in htmlawed from the filter_tags call.
 * @todo Is this ^ still true?
 *
 * @param string $variable      The variable name we want.
 * @param mixed  $default       A default value for the variable if it is not found.
 * @param bool   $filter_result If true, then the result is filtered for bad tags.
 *
 * @return mixed
 */
function get_input($variable, $default = NULL, $filter_result = TRUE)
{
    global $CONFIG;
    $result = $default;
    elgg_push_context('input');
    if (isset($CONFIG->input[$variable])) {
        $result = $CONFIG->input[$variable];
        if ($filter_result) {
            $result = filter_tags($result);
        }
    } elseif (isset($_REQUEST[$variable])) {
        if (is_array($_REQUEST[$variable])) {
            $result = $_REQUEST[$variable];
        } else {
            $result = trim($_REQUEST[$variable]);
        }
        if ($filter_result) {
            $result = filter_tags($result);
        }
    }
    elgg_pop_context();
    return $result;
}
Esempio n. 10
0
function questions_page_handler($segments)
{
    //	elgg_push_breadcrumb(elgg_echo('questions'), "/questions/all");
    $pages = dirname(__FILE__) . "/pages/questions";
    switch ($segments[0]) {
        case "all":
            include "{$pages}/all.php";
            break;
        case "owner":
            include "{$pages}/owner.php";
            break;
            /*
            		case "friends":
            			gatekeeper();
            			include "$pages/friends.php";
            			break;
            */
        /*
        		case "friends":
        			gatekeeper();
        			include "$pages/friends.php";
        			break;
        */
        case "view":
            set_input('guid', $segments[1]);
            include "{$pages}/view.php";
            break;
        case "add":
            gatekeeper();
            set_input('guid', $segments[1]);
            include "{$pages}/add.php";
            break;
        case "edit":
            gatekeeper();
            set_input('guid', $segments[1]);
            include "{$pages}/edit.php";
            break;
        case 'group':
            //			group_gatekeeper();
            include "{$pages}/owner.php";
            break;
        default:
            return false;
    }
    elgg_pop_context();
    return true;
}
Esempio n. 11
0
/**
 * Dispatcher for bookmarks.
 *
 * URLs take the form of
 *  All bookmarks:        bookmarks/all
 *  User's bookmarks:     bookmarks/owner/<username>
 *  Friends' bookmarks:   bookmarks/friends/<username>
 *  View bookmark:        bookmarks/view/<guid>/<title>
 *  New bookmark:         bookmarks/add/<guid> (container: user, group, parent)
 *  Edit bookmark:        bookmarks/edit/<guid>
 *  Group bookmarks:      bookmarks/group/<guid>/all
 *  Bookmarklet:          bookmarks/bookmarklet/<guid> (user)
 *
 * Title is ignored
 *
 * @param array $page
 * @return bool
 */
function bookmarks_page_handler($page)
{
    elgg_load_library('elgg:bookmarks');
    if (!isset($page[0])) {
        $page[0] = 'all';
    }
    elgg_push_breadcrumb(elgg_echo('bookmarks'), 'bookmarks/all');
    switch ($page[0]) {
        case "all":
            echo elgg_view_resource('bookmarks/all');
            break;
        case "owner":
            echo elgg_view_resource('bookmarks/owner');
            break;
        case "friends":
            echo elgg_view_resource('bookmarks/friends');
            break;
        case "view":
            set_input('guid', $page[1]);
            echo elgg_view_resource('bookmarks/view');
            break;
        case "add":
            echo elgg_view_resource('bookmarks/add');
            break;
        case "edit":
            set_input('guid', $page[1]);
            echo elgg_view_resource('bookmarks/edit');
            break;
        case 'group':
            echo elgg_view_resource('bookmarks/owner');
            break;
        case "bookmarklet":
            set_input('container_guid', $page[1]);
            echo elgg_view_resource('bookmarks/bookmarklet');
            break;
        default:
            return false;
    }
    elgg_pop_context();
    return true;
}
Esempio n. 12
0
<?php

$userId = elgg_get_page_owner_guid();
$offset = get_input('offset', 0);
$count = elgg_get_entities_from_relationship(array('type' => 'group', 'relationship' => 'member', 'relationship_guid' => $userId, 'inverse_relationship' => false, 'count' => true));
if (!$count) {
    echo elgg_echo('groups:none');
} else {
    $groups = elgg_get_entities_from_relationship(array('type' => 'group', 'relationship' => 'member', 'relationship_guid' => $userId, 'inverse_relationship' => false, "offset" => $offset, "limit" => ZHGROUPS_IN_PROFILE_LIMIT));
    echo '<div id="zhaohu_profile_joined_groups">';
    echo "<h3>" . elgg_echo("zhgroups:memberof", array($count)) . "</h3>";
    elgg_push_context('inprofile');
    $options = array("count" => $count, "offset" => $offset, "limit" => ZHGROUPS_IN_PROFILE_LIMIT, "full_view" => false, 'list_type' => 'gallery', "pagination" => true);
    //fordebug system_message("count ".$options["count"]);
    echo elgg_view_entity_list($groups, $options);
    echo '</div>';
    elgg_pop_context('inprofile');
}
Esempio n. 13
0
/**
 * Dispatcher for bookmarks.
 *
 * URLs take the form of
 *  All bookmarks:        bookmarks/all
 *  User's bookmarks:     bookmarks/owner/<username>
 *  Friends' bookmarks:   bookmarks/friends/<username>
 *  View bookmark:        bookmarks/view/<guid>/<title>
 *  New bookmark:         bookmarks/add/<guid> (container: user, group, parent)
 *  Edit bookmark:        bookmarks/edit/<guid>
 *  Group bookmarks:      bookmarks/group/<guid>/all
 *  Bookmarklet:          bookmarks/bookmarklet/<guid> (user)
 *
 * Title is ignored
 *
 * @param array $page
 */
function bookmarks_page_handler($page)
{
    elgg_load_library('elgg:bookmarks');
    elgg_push_breadcrumb(elgg_echo('bookmarks'), 'bookmarks/all');
    // old group usernames
    if (substr_count($page[0], 'group:')) {
        preg_match('/group\\:([0-9]+)/i', $page[0], $matches);
        $guid = $matches[1];
        if ($entity = get_entity($guid)) {
            bookmarks_url_forwarder($page);
        }
    }
    // user usernames
    $user = get_user_by_username($page[0]);
    if ($user) {
        bookmarks_url_forwarder($page);
    }
    $pages = dirname(__FILE__) . '/pages/bookmarks';
    switch ($page[0]) {
        case "all":
            include "{$pages}/all.php";
            break;
        case "owner":
            include "{$pages}/owner.php";
            break;
        case "friends":
            include "{$pages}/friends.php";
            break;
        case "read":
        case "view":
            set_input('guid', $page[1]);
            include "{$pages}/view.php";
            break;
        case "add":
            gatekeeper();
            include "{$pages}/add.php";
            break;
        case "edit":
            gatekeeper();
            set_input('guid', $page[1]);
            include "{$pages}/edit.php";
            break;
        case 'group':
            group_gatekeeper();
            include "{$pages}/owner.php";
            break;
        case "bookmarklet":
            set_input('container_guid', $page[1]);
            include "{$pages}/bookmarklet.php";
            break;
        default:
            return false;
    }
    elgg_pop_context();
    return true;
}
Esempio n. 14
0
/**
 * Insert user into elgg user table using info from ldap
 * Tries to insert, otherwise returns error
 *
 * @return user or error (false?)
 */
function cas_insertUser($username, $ldap_attributes, $config)
{
    // name is 'cn' in ldap
    $name = $ldap_attributes['cn'];
    // remove periods from ldap username
    // ex. anthony.hopkins -> anthonyhopkins
    $uname = !empty($ldap_attributes['textUid']) ? $ldap_attributes['textUid'] : str_replace(".", "", $username);
    $email = $ldap_attributes['mail'];
    $user = new ElggUser();
    $user->username = $uname;
    $user->email = $email;
    $user->name = $name;
    $user->access_id = 2;
    $user->salt = generate_random_cleartext_password();
    // Note salt generated before password!
    // cas users don't need password stored locally
    // so create an invalid password
    // a real password can be saved at a later time if they become a local user
    $user->password = md5(time());
    //generate_user_password($user, $password);
    // returns guid or false
    $guid = $user->save();
    if (!$guid) {
        return false;
    }
    $obj = get_entity($guid);
    if (isset($config->casadminuser) && $config->casadminuser == $uname) {
        if ($obj instanceof \ElggUser) {
            //set context for permissions check
            elgg_push_context('au_cas_auth_make_admin');
            if (make_user_admin($guid)) {
                system_message(elgg_echo('admin:user:makeadmin:yes'));
            } else {
                register_error(elgg_echo('admin:user:makeadmin:no'));
            }
            // set context back
            elgg_pop_context();
        } else {
            register_error(elgg_echo('admin:user:makeadmin:no'));
        }
    }
    return $user;
}
Esempio n. 15
0
 /**
  * Pre 1.9 notificatins
  *
  * Listen to the 'publish','object' event and send out notifications
  * to interested users, as well as anyone tagged
  *
  * @param string      $event       Equals 'publish'
  * @param string      $entity_type Equals 'object'
  * @param ElggEntity $entity      Published entity
  * @return boolean
  */
 public function sendLegacy($event, $entity_type, $entity)
 {
     if (!$entity instanceof Post || $entity->origin != 'wall') {
         return true;
     }
     $poster = $entity->getOwnerEntity();
     $container = $entity->getContainerEntity();
     $message = $entity->formatMessage(true);
     $sent = array(elgg_get_logged_in_user_guid(), $poster->guid, $container->guid);
     // Notify wall owner
     if ($poster->guid !== $container->guid && $container instanceof ElggUser) {
         $to = $container->guid;
         $from = $poster->guid;
         $target = elgg_echo("wall:target:{$entity->getSubtype()}");
         $ownership = elgg_echo('wall:ownership:your', array($target));
         $subject = elgg_echo('wall:new:notification:subject', array($poster->name, $ownership));
         $body = elgg_echo('wall:new:notification:message', array($poster->name, $ownership, $message, $entity->getURL()));
         notify_user($to, $from, $subject, $body);
     }
     // Notify tagged users
     $tagged_friends = $entity->getTaggedFriends();
     foreach ($tagged_friends as $tagged_friend) {
         // user tagged herself or the wall owner
         if ($tagged_friend->guid == $poster->guid || $tagged_friend->guid == $container->guid || in_array($tagged_friend->guid, $sent)) {
             continue;
         }
         $sent[] = $tagged_friend->guid;
         $to = $tagged_friend->guid;
         $from = $poster->guid;
         $subject = elgg_echo('wall:tagged:notification:subject', array($poster->name));
         $body = elgg_echo('wall:tagged:notification:message', array($poster->name, $message, $entity->getURL()));
         notify_user($to, $from, $subject, $body);
     }
     elgg_push_context('widgets');
     $default_msg_body = elgg_view_entity($entity, array('full_view' => false));
     elgg_pop_context();
     global $NOTIFICATION_HANDLERS;
     // Get users interested in content from this person and notify them
     // (Person defined by container_guid so we can also subscribe to groups if we want)
     foreach ($NOTIFICATION_HANDLERS as $method => $foo) {
         $interested_users = ElggBatch('elgg_get_entities_from_relationship', array('site_guids' => ELGG_ENTITIES_ANY_VALUE, 'relationship' => 'notify' . $method, 'relationship_guid' => $entity->container_guid, 'inverse_relationship' => true, 'type' => 'user', 'limit' => false));
         foreach ($interested_users as $user) {
             if ($user instanceof ElggUser && !$user->isBanned() && !in_array($user->guid, $sent)) {
                 if (has_access_to_entity($entity, $user) && $entity->access_id != ACCESS_PRIVATE) {
                     $body = elgg_trigger_plugin_hook('notify:entity:message', 'object', array('entity' => $entity, 'to_entity' => $user, 'method' => $method), $default_msg_body);
                     if ($body !== false) {
                         notify_user($user->guid, $entity->container_guid, $subject, $body, null, array($method));
                     }
                 }
             }
         }
     }
     return true;
 }
Esempio n. 16
0
/**
 * Updates the fixed widgets for a given context and user
 *
 * @param string $context   context of the widgets
 * @param int    $user_guid owner of the new widgets
 *
 * @return void
 */
function widget_manager_update_fixed_widgets($context, $user_guid)
{
    // need to be able to access everything
    $old_ia = elgg_set_ignore_access(true);
    elgg_push_context('create_default_widgets');
    $options = ['type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name_value_pairs' => ['context' => $context, 'fixed' => 1.0], 'limit' => false];
    // see if there are configured fixed widgets
    $configured_fixed_widgets = elgg_get_entities_from_private_settings($options);
    widget_manager_sort_widgets_guid($configured_fixed_widgets);
    // fetch all currently configured widgets fixed AND not fixed
    $options['private_setting_name_value_pairs'] = ['context' => $context];
    $options['owner_guid'] = $user_guid;
    $user_widgets = elgg_get_entities_from_private_settings($options);
    widget_manager_sort_widgets_guid($user_widgets);
    $default_widget_guids = [];
    // update current widgets
    if ($user_widgets) {
        foreach ($user_widgets as $guid => $widget) {
            $widget_fixed = $widget->fixed;
            $default_widget_guid = $widget->fixed_parent_guid;
            $default_widget_guids[] = $default_widget_guid;
            if (empty($default_widget_guid)) {
                continue;
            }
            if ($widget_fixed && !array_key_exists($default_widget_guid, $configured_fixed_widgets)) {
                // remove fixed status
                $widget->fixed = false;
            } elseif (!$widget_fixed && array_key_exists($default_widget_guid, $configured_fixed_widgets)) {
                // add fixed status
                $widget->fixed = true;
            }
            // need to recheck the fixed status as it could have been changed
            if ($widget->fixed && array_key_exists($default_widget_guid, $configured_fixed_widgets)) {
                // update settings for currently configured widgets
                // pull in settings
                $settings = get_all_private_settings($configured_fixed_widgets[$default_widget_guid]->guid);
                foreach ($settings as $name => $value) {
                    $widget->{$name} = $value;
                }
                // access is no setting, but could also be controlled from the default widget
                $widget->access = $configured_fixed_widgets[$default_widget_guid]->access;
                // save the widget (needed for access update)
                $widget->save();
            }
        }
    }
    // add new fixed widgets
    if ($configured_fixed_widgets) {
        foreach ($configured_fixed_widgets as $guid => $widget) {
            if (in_array($guid, $default_widget_guids)) {
                continue;
            }
            // if no widget is found which is already linked to this default widget, clone the widget to the user
            $new_widget = clone $widget;
            $new_widget->container_guid = $user_guid;
            $new_widget->owner_guid = $user_guid;
            // pull in settings
            $settings = get_all_private_settings($guid);
            foreach ($settings as $name => $value) {
                $new_widget->{$name} = $value;
            }
            $new_widget->save();
        }
    }
    // fixing order on all columns for this context, fixed widgets should always stay on top of other 'free' widgets
    foreach ([1, 2, 3] as $column) {
        // reuse previous declared options with a minor adjustment
        $options['private_setting_name_value_pairs'] = ['context' => $context, 'column' => $column];
        $column_widgets = elgg_get_entities_from_private_settings($options);
        $free_widgets = [];
        $max_fixed_order = 0;
        if ($column_widgets) {
            foreach ($column_widgets as $widget) {
                if ($widget->fixed) {
                    if ($widget->order > $max_fixed_order) {
                        $max_fixed_order = $widget->order;
                    }
                } else {
                    $free_widgets[] = $widget;
                }
            }
            if (!empty($max_fixed_order) && !empty($free_widgets)) {
                foreach ($free_widgets as $widget) {
                    $widget->order += $max_fixed_order;
                }
            }
        }
    }
    // revert access
    elgg_set_ignore_access($old_ia);
    elgg_pop_context();
    // set the user timestamp
    elgg_set_plugin_user_setting($context . '_fixed_ts', time(), $user_guid, 'widget_manager');
}
Esempio n. 17
0
<?php

// generate a div which includes all the recommended groups
$search_options = array('type' => 'group', 'subtype' => 0, 'offset' => 0, 'limit' => 5, 'joins' => array(), 'wheres' => array());
$search_options['metadata_name_value_pairs'][] = array('name' => 'featured_group', 'value' => 'yes');
$search_options['count'] = false;
$recommended_groups = elgg_get_entities_from_metadata($search_options);
$display_options = array("count" => ZHAOHU_RECOMMENDED_SHOW_LIMIT, "offset" => 0, "limit" => ZHAOHU_RECOMMENDED_SHOW_LIMIT, "full_view" => false, "pagination" => false);
$header_title = elgg_echo("zhaohu:recommended_groups");
$content = "<div id='zhaohu_homepage_recommended_groups' class='zhaohu-homepage-right-sidebar-div'>";
$content .= "<div id='zhaohu_homepage_recommended_groups_header' class='zhaohu-homepage-right-sidebar-div-header'>{$header_title}</div>";
$content .= "<div id='zhaohu_homepage_recommended_groups_content' class='zhaohu-homepage-right-sidebar-div-content'>";
elgg_push_context("recommended_groups");
$list = elgg_view_entity_list($recommended_groups, $display_options);
elgg_pop_context("recommended_groups");
if (!empty($list)) {
    $content .= $list;
} else {
    $content .= elgg_echo('zhaohu:noresults');
}
$content .= "</div>";
$content .= "</div>";
echo $content;
Esempio n. 18
0
/**
 * Dispatcher for bookmarks.
 *
 * URLs take the form of
 *  All bookmarks:        bookmarks/all
 *  User's bookmarks:     bookmarks/owner/<username>
 *  Friends' bookmarks:   bookmarks/friends/<username>
 *  View bookmark:        bookmarks/view/<guid>/<title>
 *  New bookmark:         bookmarks/add/<guid> (container: user, group, parent)
 *  Edit bookmark:        bookmarks/edit/<guid>
 *  Group bookmarks:      bookmarks/group/<guid>/all
 *  Bookmarklet:          bookmarks/bookmarklet/<guid> (user)
 *
 * Title is ignored
 *
 * @param array $page
 * @return bool
 */
function bookmarks_page_handler($page)
{
    elgg_load_library('elgg:bookmarks');
    if (!isset($page[0])) {
        $page[0] = 'all';
    }
    elgg_push_breadcrumb(elgg_echo('bookmarks'), 'bookmarks/all');
    $pages = dirname(__FILE__) . '/pages/bookmarks';
    switch ($page[0]) {
        case "all":
            include "{$pages}/all.php";
            break;
        case "owner":
            include "{$pages}/owner.php";
            break;
        case "friends":
            include "{$pages}/friends.php";
            break;
        case "view":
            set_input('guid', $page[1]);
            include "{$pages}/view.php";
            break;
        case "add":
            elgg_gatekeeper();
            include "{$pages}/add.php";
            break;
        case "edit":
            elgg_gatekeeper();
            set_input('guid', $page[1]);
            include "{$pages}/edit.php";
            break;
        case 'group':
            elgg_group_gatekeeper();
            include "{$pages}/owner.php";
            break;
        case "bookmarklet":
            set_input('container_guid', $page[1]);
            include "{$pages}/bookmarklet.php";
            break;
        default:
            return false;
    }
    elgg_pop_context();
    return true;
}
 /**
  * Render a uniform view for embedded entities
  * Use 'output:entity', 'embed' hook to override the output
  * @return string
  */
 private function getEntityView($params = array())
 {
     $entity = $this->entity;
     if ($entity instanceof ElggFile) {
         $size = $entity->simpletype == 'image' ? 'large' : 'small';
         $output = elgg_view_entity_icon($entity, $size);
     } else {
         elgg_push_context('widgets');
         if (!isset($params['full_view'])) {
             $params['full_view'] = false;
         }
         $output = elgg_view_entity($entity, $params);
         elgg_pop_context();
     }
     $params['entity'] = $this->entity;
     $params['src'] = $this->url;
     return elgg_trigger_plugin_hook('output:entity', 'embed', $params, $output);
 }
Esempio n. 20
0
 /**
  * Returns the program data for a user
  *
  * @param string $user_guid     guid of the entity
  * @param bool   $participate   show the participation
  * @param string $register_type type of the registration
  *
  * @return boolean|string
  */
 public function getProgramData($user_guid = null, $participate = false, $register_type = "register")
 {
     if ($user_guid === null) {
         $user_guid = elgg_get_logged_in_user_guid();
     }
     if (!$this->hasEventDays()) {
         return false;
     }
     if (!$participate) {
         elgg_push_context('programmailview');
         $result = elgg_view('event_manager/program/view', ['entity' => $this, 'member' => $user_guid]);
         elgg_pop_context();
     } else {
         $result = elgg_view('event_manager/program/edit', ['entity' => $this, 'register_type' => $register_type, 'member' => $user_guid]);
     }
     return elgg_view_module('main', '', $result);
 }
Esempio n. 21
0
/**
 * Creates default widgets
 *
 * This plugin hook handler is registered for events based on what kinds of
 * default widgets have been registered. See elgg_default_widgets_init() for
 * information on registering new default widget contexts.
 *
 * @param string $event  The event
 * @param string $type   The type of object
 * @param \ElggEntity $entity The entity being created
 * @return void
 * @access private
 */
function _elgg_create_default_widgets($event, $type, $entity)
{
    $default_widget_info = elgg_get_config('default_widget_info');
    if (!$default_widget_info || !$entity) {
        return;
    }
    $type = $entity->getType();
    $subtype = $entity->getSubtype();
    // event is already guaranteed by the hook registration.
    // need to check subtype and type.
    foreach ($default_widget_info as $info) {
        if ($info['entity_type'] == $type) {
            if ($info['entity_subtype'] == ELGG_ENTITIES_ANY_VALUE || $info['entity_subtype'] == $subtype) {
                // need to be able to access everything
                $old_ia = elgg_set_ignore_access(true);
                elgg_push_context('create_default_widgets');
                // pull in by widget context with widget owners as the site
                // not using elgg_get_widgets() because it sorts by columns and we don't care right now.
                $options = array('type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name' => 'context', 'private_setting_value' => $info['widget_context'], 'limit' => 0);
                $widgets = elgg_get_entities_from_private_settings($options);
                /* @var \ElggWidget[] $widgets */
                foreach ($widgets as $widget) {
                    // change the container and owner
                    $new_widget = clone $widget;
                    $new_widget->container_guid = $entity->guid;
                    $new_widget->owner_guid = $entity->guid;
                    // pull in settings
                    $settings = get_all_private_settings($widget->guid);
                    foreach ($settings as $name => $value) {
                        $new_widget->{$name} = $value;
                    }
                    $new_widget->save();
                }
                elgg_set_ignore_access($old_ia);
                elgg_pop_context();
            }
        }
    }
}
Esempio n. 22
0
<?php

/**
 * List all suggested groups
 */
elgg_push_context('zhg_members');
$options = array("count" => elgg_extract("count", $vars), "offset" => elgg_extract("offset", $vars), "limit" => ZHAOHU_GROUPS_MEMBER_LIMIT, "full_view" => false, "pagination" => true);
//fordebug system_message("count ".$options["count"]);
$list = elgg_view_entity_list($vars["entities"], $options);
elgg_pop_context('zhg_members');
$result .= "<div id='zhaohu_manager_member_listing'>";
if (!empty($list)) {
    $result .= $list;
} else {
    $result .= elgg_echo('zhaohu_manager:list:noresults');
}
$result .= "</div>";
echo elgg_view_module("main", "", $result);
Esempio n. 23
0
/**
 * Handle static pages
 *
 * @param string $hook         the name of the hook
 * @param string $type         the type of the hook
 * @param array  $return_value current return value
 * @param mixed  $params       supplied params
 */
function theme_haarlem_intranet_route_static_handler($hook, $type, $return_value, $params)
{
    if (empty($return_value) || !is_array($return_value)) {
        return $return_value;
    }
    $handler = elgg_extract('handler', $return_value);
    if ($handler !== 'static') {
        return $return_value;
    }
    $segments = elgg_extract('segments', $return_value);
    if (empty($segments) || !is_array($segments)) {
        return $return_value;
    }
    switch ($segments[0]) {
        case 'view':
            set_input('guid', $segments[1]);
            elgg_push_context('static');
            include dirname(dirname(__FILE__)) . '/pages/static/view.php';
            elgg_pop_context();
            $return_value = false;
            break;
    }
    return $return_value;
}
/**
 * Checks sent passed validation code and user guids and validates the user.
 *
 * @param array $page
 * @return bool
 */
function uservalidationbyadmin_page_handler($page)
{
    if (isset($page[0]) && $page[0] == 'confirm') {
        $code = sanitise_string(get_input('c', FALSE));
        $user_guid = get_input('u', FALSE);
        // new users are not enabled by default.
        $access_status = access_get_show_hidden_status();
        access_show_hidden_entities(true);
        $user = get_entity($user_guid);
        if ($code && $user) {
            if (uservalidationbyadmin_validate_email($user_guid, $code)) {
                elgg_push_context('uservalidationbyadmin_validate_user');
                system_message(elgg_echo('email:confirm:success'));
                $user = get_entity($user_guid);
                $user->enable();
                elgg_pop_context();
                $site = elgg_get_site_entity();
                $subject = elgg_echo('user:validate:subject', array($user->name));
                $body = elgg_echo('user:validate:body', array($user->name, $site->name, $user->username, $site->name, $site->url));
                $result = notify_user($user->guid, $site->guid, $subject, $body, NULL, 'email');
                //	login($user);
            } else {
                register_error(elgg_echo('email:confirm:fail'));
            }
        } else {
            register_error(elgg_echo('email:confirm:fail'));
        }
        access_show_hidden_entities($access_status);
    } else {
        register_error(elgg_echo('email:confirm:fail'));
    }
    // forward to front page
    forward('');
}
Esempio n. 25
0
<?php

/**
 * List all suggested groups
 */
elgg_push_context('zhg_contact');
$options = array("count" => elgg_extract("count", $vars), "limit" => false, "full_view" => false, "pagination" => false);
$list = elgg_view_entity_list($vars["entities"], $options);
elgg_pop_context('zhg_contact');
$result .= "<div id='zhaohu_manager_member_listing'>";
if (!empty($list)) {
    $result .= $list;
} else {
    $result .= elgg_echo('zhaohu_manager:list:noresults');
}
$result .= "</div>";
echo elgg_view_module("main", "", $result);
Esempio n. 26
0
 /**
  * Returns the program data for a user
  *
  * @param string $user_guid     guid of the entity
  * @param bool   $participate   show the participation
  * @param string $register_type type of the registration
  *
  * @return boolean|string
  */
 public function getProgramData($user_guid = null, $participate = false, $register_type = "register")
 {
     if ($user_guid === null) {
         $user_guid = elgg_get_logged_in_user_guid();
     }
     if (!$this->getEventDays()) {
         return false;
     }
     $result = "";
     if (!$participate) {
         elgg_push_context("programmailview");
         $result .= elgg_view("event_manager/program/view", array("entity" => $this, "member" => $user_guid));
         elgg_pop_context();
     } else {
         $result .= elgg_view("event_manager/program/edit", array("entity" => $this, "register_type" => $register_type, "member" => $user_guid));
     }
     $result = elgg_view_module("main", "", $result);
     return $result;
 }
 /**
  * elgg_admin_sort_page_menu() should not expect that the supplied menu has a certain hierarchy
  *
  * https://github.com/Elgg/Elgg/issues/6379
  */
 function test_admin_sort_page_menu()
 {
     elgg_push_context('admin');
     elgg_register_plugin_hook_handler('prepare', 'menu:page', 'elgg_admin_sort_page_menu');
     $result = elgg_trigger_plugin_hook('prepare', 'menu:page', array(), array());
     $this->assertTrue(is_array($result), "Admin page menu fails to prepare for viewing");
     elgg_pop_context();
 }
/**
 * Formats notifications that have defined template
 * 
 * @param string                           $hook         "format"
 * @param string                           $type         "notification"
 * @param \Elgg\Notifications\Notification $notification Notification
 * @param array                            $params       Hook params
 * @return \Elgg\Notifications\Notification
 */
function notifications_editor_format_notification($hook, $type, $notification, $params)
{
    $language = $notification->language;
    if (empty($notification->params['template'])) {
        return;
    }
    $template = notifications_editor_get_template_entity($notification->params['template'], $language);
    if (!$template) {
        return;
    }
    $event = elgg_extract('event', $params);
    if ($event instanceof \Elgg\Notifications\Event) {
        $action = $event->getAction();
        $actor = $event->getActor();
        $object = $event->getObject();
        if ($object instanceof ElggEntity) {
            $target = $object->getContainerEntity();
        } else {
            if ($object instanceof ElggRelationship) {
                $target = array('subject' => get_entity($object->guid_one), 'object' => get_entity($object->guid_two));
            } else {
                if ($object instanceof ElggAnnotation) {
                    $target = $object->getEntity();
                }
            }
        }
    }
    $template_params = array('action' => $action, 'actor' => $actor, 'object' => $object, 'target' => $target, 'recipient' => $notification->getRecipient(), 'sender' => $notification->getSender(), 'language' => $language, 'site' => elgg_get_site_entity(), 'params' => $notification->params);
    elgg_push_context('widgets');
    if ($template->subject) {
        $notification->subject = mustache()->render($template->subject, $template_params);
    }
    if ($template->body) {
        $notification->body = mustache()->render($template->body, $template_params);
    }
    if ($template->summary) {
        $notification->summary = mustache()->render($template->summary, $template_params);
    }
    elgg_pop_context();
    return $notification;
}
Esempio n. 29
0
File: content.php Progetto: n8b/VMN
                if ($show_timestamp) {
                    $text .= " <span class='elgg-quiet'>" . elgg_view_friendly_time($entity->time_created) . "</span>";
                }
                $result .= elgg_view_image_block($icon, $text);
            }
            $result .= "</li>";
        }
        $result .= "</ul>";
    }
} else {
    $result = elgg_list_entities($options);
}
if (empty($result)) {
    $result = elgg_echo("notfound");
} elseif ($widget->show_search_link == "yes" && !empty($widget->tags) && elgg_is_active_plugin("search")) {
    $tags = $widget->tags;
    if (elgg_is_active_plugin("search_advanced")) {
        $tags_text = $tags;
    } else {
        $tags = string_to_tag_array($tags);
        $tags_text = $tags[0];
    }
    $search_postfix = "";
    if (count($content_type) == 1) {
        $search_postfix = "&entity_subtype=" . $content_type[0] . "&entity_type=object&search_type=entities";
    }
    $result .= "<div class='elgg-widget-more'>" . elgg_view("output/url", array("text" => elgg_echo("searchtitle", array($tags_text)), "href" => "search?q=" . $tags_text . $search_postfix)) . "</div>";
}
echo $result;
elgg_pop_context();
Esempio n. 30
0
 /**
  * Display an html list of the entities
  * @param string $class		CSS class to attach to the table
  * @return string
  */
 public function viewList()
 {
     $context = isset($this->options['list_type']) ? $this->options['list_type'] : 'list';
     elgg_push_context($context);
     $items = $this->getItems();
     $options = $this->getOptions();
     $count = $this->getCount();
     $offset = elgg_extract('offset', $options);
     $limit = elgg_extract('limit', $options);
     $base_url = elgg_extract('base_url', $options, '');
     $pagination = elgg_extract('pagination', $options, true);
     $offset_key = elgg_extract('offset_key', $options, 'offset');
     $position = elgg_extract('position', $options, 'after');
     if ($pagination && $count) {
         $nav = elgg_view('navigation/pagination', array('base_url' => $base_url, 'offset' => $offset, 'count' => $count, 'limit' => $limit, 'offset_key' => $offset_key));
     }
     $html .= '<div class="elgg-list-container">';
     if ($position == 'before' || $position == 'both') {
         $html .= $nav;
     }
     $list_attrs = elgg_format_attributes($this->getListAttributes());
     $html .= "<ul {$list_attrs}>";
     foreach ($items as $item) {
         $view = elgg_view_list_item($item, $options);
         if (!$view) {
             continue;
         }
         $has_items = true;
         $item_attrs = elgg_format_attributes($this->getItemAttributes($item));
         $html .= "<li {$item_attrs}>{$view}</li>";
     }
     if (!$has_items) {
         $html .= '<li class="elgg-list-placeholder">' . elgg_echo('list:empty') . '</li>';
     }
     $html .= '</ul>';
     if ($position == 'after' || $position == 'both') {
         $html .= $nav;
     }
     $html .= '</div>';
     elgg_pop_context();
     return $html;
 }