Ejemplo n.º 1
0
/**
 * Stripe related pages
 *
 * @param array $page
 * @param string $handler
 * @return boolean
 */
function stripe_page_handler($page, $handler)
{
    gatekeeper();
    $username = elgg_extract(0, $page, false);
    if ($username) {
        $user = get_user_by_username($username);
    }
    if (!elgg_instanceof($user) || !$user->canEdit()) {
        $user = elgg_get_logged_in_user_entity();
        forward("{$handler}/{$user->username}");
    }
    elgg_set_context('settings');
    elgg_set_page_owner_guid($user->guid);
    elgg_push_breadcrumb(elgg_echo('stripe:billing'), 'billing');
    $context = elgg_extract(1, $page, 'cards');
    $action = elgg_extract(2, $page, 'all');
    $view = "stripe/pages/{$context}/{$action}";
    if (elgg_view_exists($view)) {
        $params = array('entity' => $user, 'id' => elgg_extract(3, $page, false), 'context' => $page);
        $title = elgg_echo("stripe:{$context}:{$action}");
        $content = elgg_view($view, $params);
        $sidebar = elgg_view('stripe/sidebar', $params);
        $filter = elgg_view("stripe/filters/{$context}/{$action}", $params);
    }
    if ($content) {
        if (elgg_is_xhr()) {
            echo $content;
        } else {
            $layout = elgg_view_layout('content', array('title' => $title, 'content' => $content, 'sidebar' => $sidebar, 'filter' => $filter));
            echo elgg_view_page($title, $layout);
        }
        return true;
    }
    return false;
}
Ejemplo n.º 2
0
 /**
  * Renders a form field
  *
  * @param string $input_type Input type, used to generate an input view ("input/$input_type")
  * @param array  $vars       Fields and input vars.
  *                           Field vars contain both field and input params. 'label', 'help',
  *                           and 'field_class' params will not be passed on to the input view.
  *                           Others, including 'required' and 'id', will be available to the
  *                           input view. Both 'label' and 'help' params accept HTML, and
  *                           will be printed unescaped within their wrapper element.
  * @return string
  */
 function elgg_view_input($input_type, array $vars = array())
 {
     static $id_num;
     if (!elgg_view_exists("input/{$input_type}")) {
         return '';
     }
     if ($input_type == 'hidden') {
         return elgg_view("input/{$input_type}", $vars);
     }
     $id = elgg_extract('id', $vars);
     if (!$id) {
         $id_num++;
         $id = "elgg-field-{$id_num}";
         $vars['id'] = $id;
     }
     $vars['input_type'] = $input_type;
     $label = elgg_view('elements/forms/label', $vars);
     unset($vars['label']);
     $help = elgg_view('elements/forms/help', $vars);
     unset($vars['help']);
     $required = elgg_extract('required', $vars);
     $field_class = (array) elgg_extract('field_class', $vars, array());
     unset($vars['field_class']);
     $input = elgg_view("elements/forms/input", $vars);
     return elgg_view('elements/forms/field', array('label' => $label, 'help' => $help, 'required' => $required, 'id' => $id, 'input' => $input, 'class' => $field_class, 'input_type' => $input_type));
 }
Ejemplo n.º 3
0
/**
 * List crud objects in a group
 *
 * @param CrudTemplate $crud Crud template object
 * @param int $guid Group entity GUID
 */
function crud_handle_list_page($crud, $guid)
{
    elgg_set_page_owner_guid($guid);
    $crud_type = $crud->crud_type;
    $parent = get_entity($guid);
    if ($parent instanceof ElggGroup) {
        $group = $parent;
        $parent = NULL;
    } else {
        $group = get_entity($parent->container_guid);
    }
    if (!$group) {
        register_error(elgg_echo('groups:notfound'));
        forward();
    }
    group_gatekeeper();
    elgg_push_breadcrumb($group->name);
    elgg_register_title_button();
    if (elgg_view_exists("forms/{$crud->module}/{$crud_type}_general")) {
        elgg_register_title_button($crud->crud_type, 'edit_general');
    }
    $title = elgg_echo("item:object:{$crud_type}");
    $params = array('title' => $title, 'content' => $crud->getListTabContent(), 'footer' => elgg_view("{$crud->module}/{$crud_type}_general", array('entity' => $group)), 'filter' => $crud->getListTabFilter());
    $params['sidebar'] .= elgg_view('crud/tagcloud_block', array('subtypes' => $crud->crud_type, 'owner_guid' => elgg_get_page_owner_guid()));
    $body = elgg_view_layout('content', $params);
    echo elgg_view_page($title, $body);
}
Ejemplo n.º 4
0
Archivo: output.php Proyecto: elgg/elgg
/**
 * Returns an excerpt.
 * Will return up to n chars stopping at the nearest space.
 * If no spaces are found (like in Japanese) will crop off at the
 * n char mark. Adds ... if any text was chopped.
 *
 * @param string $text      The full text to excerpt
 * @param int    $num_chars Return a string up to $num_chars long
 *
 * @return string
 * @since 1.7.2
 */
function elgg_get_excerpt($text, $num_chars = 250)
{
    $view = 'output/excerpt';
    $vars = ['text' => $text, 'num_chars' => $num_chars];
    $viewtype = elgg_view_exists($view) ? '' : 'default';
    return _elgg_view_under_viewtype($view, $vars, $viewtype);
}
Ejemplo n.º 5
0
/**
 * Registes all custom field types
 */
function register_custom_field_types()
{
    // registering profile field types
    $profile_options = array("show_on_register" => true, "mandatory" => true, "user_editable" => true, "output_as_tags" => true, "admin_only" => true, "count_for_completeness" => true);
    $location_options = $profile_options;
    unset($location_options["output_as_tags"]);
    $pm_datepicker_options = $profile_options;
    unset($pm_datepicker_options["output_as_tags"]);
    $pulldown_options = $profile_options;
    $pulldown_options["blank_available"] = true;
    $radio_options = $profile_options;
    $radio_options["blank_available"] = true;
    $file_options = array("user_editable" => true, "admin_only" => true);
    $pm_rating_options = $profile_options;
    unset($pm_rating_options["output_as_tags"]);
    add_custom_field_type("custom_profile_field_types", 'text', elgg_echo('profile:field:text'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'longtext', elgg_echo('profile:field:longtext'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'tags', elgg_echo('profile:field:tags'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'location', elgg_echo('profile:field:location'), $location_options);
    add_custom_field_type("custom_profile_field_types", 'url', elgg_echo('profile:field:url'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'email', elgg_echo('profile:field:email'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'date', elgg_echo('profile:field:date'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'calendar', elgg_echo('calendar'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'pm_datepicker', elgg_echo('profile_manager:admin:options:pm_datepicker'), $pm_datepicker_options);
    add_custom_field_type("custom_profile_field_types", 'dropdown', elgg_echo('profile_manager:admin:options:pulldown'), $pulldown_options);
    add_custom_field_type("custom_profile_field_types", 'radio', elgg_echo('profile_manager:admin:options:radio'), $radio_options);
    add_custom_field_type("custom_profile_field_types", 'multiselect', elgg_echo('profile_manager:admin:options:multiselect'), $profile_options);
    add_custom_field_type("custom_profile_field_types", 'pm_rating', elgg_echo('profile_manager:admin:options:pm_rating'), $pm_rating_options);
    //add_custom_field_type("custom_profile_field_types", 'pm_file', elgg_echo('profile_manager:admin:options:file'), $file_options);
    if (elgg_view_exists("output/datepicker") && elgg_view_exists("input/datepicker")) {
        $datepicker_options = $profile_options;
        unset($datepicker_options["output_as_tags"]);
        add_custom_field_type("custom_profile_field_types", 'datepicker', elgg_echo('profile_manager:admin:options:datepicker'), $datepicker_options);
    } else {
        elgg_register_plugin_hook_handler('display', 'view', 'profile_manager_display_view_hook');
    }
    // registering group field types
    $group_options = array("output_as_tags" => true, "admin_only" => true);
    $datepicker_options = $group_options;
    unset($datepicker_options["output_as_tags"]);
    $pulldown_options = $group_options;
    $pulldown_options["blank_available"] = true;
    $radio_options = $group_options;
    $radio_options["blank_available"] = true;
    add_custom_field_type("custom_group_field_types", 'text', elgg_echo('profile:field:text'), $group_options);
    add_custom_field_type("custom_group_field_types", 'longtext', elgg_echo('profile:field:longtext'), $group_options);
    add_custom_field_type("custom_group_field_types", 'tags', elgg_echo('profile:field:tags'), $group_options);
    add_custom_field_type("custom_group_field_types", 'url', elgg_echo('profile:field:url'), $group_options);
    add_custom_field_type("custom_group_field_types", 'email', elgg_echo('profile:field:email'), $group_options);
    add_custom_field_type("custom_group_field_types", 'date', elgg_echo('profile:field:date'), $group_options);
    add_custom_field_type("custom_group_field_types", 'calendar', elgg_echo('calendar'), $group_options);
    add_custom_field_type("custom_group_field_types", 'datepicker', elgg_echo('profile_manager:admin:options:datepicker'), $datepicker_options);
    add_custom_field_type("custom_group_field_types", 'dropdown', elgg_echo('profile_manager:admin:options:pulldown'), $pulldown_options);
    add_custom_field_type("custom_group_field_types", 'radio', elgg_echo('profile_manager:admin:options:radio'), $radio_options);
    add_custom_field_type("custom_group_field_types", 'multiselect', elgg_echo('profile_manager:admin:options:multiselect'), $group_options);
}
Ejemplo n.º 6
0
/**
 * Adds an item to the river.
 *
 * @param string $view          The view that will handle the river item (must exist)
 * @param string $action_type   An arbitrary string to define the action (eg 'comment', 'create')
 * @param int    $subject_guid  The GUID of the entity doing the action
 * @param int    $object_guid   The GUID of the entity being acted upon
 * @param int    $access_id     The access ID of the river item (default: same as the object)
 * @param int    $posted        The UNIX epoch timestamp of the river item (default: now)
 * @param int    $annotation_id The annotation ID associated with this river entry
 *
 * @return int/bool River ID or false on failure
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    global $CONFIG;
    // use default viewtype for when called from web services api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $view = sanitise_string($view);
    $action_type = sanitise_string($action_type);
    $subject_guid = sanitise_int($subject_guid);
    $object_guid = sanitise_int($object_guid);
    $access_id = sanitise_int($access_id);
    $posted = sanitise_int($posted);
    $annotation_id = sanitise_int($annotation_id);
    $values = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($values);
    // Attempt to save river item; return success status
    $id = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    // update the entities which had the action carried out on it
    // @todo shouldn't this be down elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($object_guid, $posted);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Ejemplo n.º 7
0
/**
 * Page handler for embeds
 * 
 * @param array $page
 */
function embed_page_handler($page)
{
    $params = array('output' => '', 'status' => 0, 'system_messages' => array('error' => array(), 'success' => array()));
    $container_guid = get_input('container_guid');
    if ($container_guid && get_entity($container_guid)) {
        elgg_set_page_owner_guid($container_guid);
    }
    switch ($page[0]) {
        default:
        case 'tab':
            $default_tab = elgg_is_active_plugin('file') ? 'file' : 'content_items';
            $embed_tab = elgg_extract(1, $page, $default_tab);
            $title = elgg_echo("embed:embed");
            $filter = elgg_view('embed/filter', array('filter_context' => $embed_tab));
            $view = "embed/tab/{$embed_tab}";
            if (elgg_view_exists($view)) {
                $content = elgg_view($view);
            } else {
                $embed_tab = elgg_get_config('embed_tab');
                if ($embed_tab instanceof \ElggMenuItem) {
                    $view = $embed_tab->getData('view');
                    $options = $embed_tab->getData('options');
                    if ($view) {
                        $content = elgg_view($view);
                    } else {
                        if ($options) {
                            $content = elgg_view('embed/get_list', array('options' => $options));
                        }
                    }
                }
            }
            if (empty($content)) {
                $content = elgg_autop(elgg_echo('embed:section:invalid'));
            }
            $params['output'] = elgg_view_layout('one_column', array('title' => $title, 'content' => $filter . $content, 'class' => 'embed-wrapper'));
            break;
    }
    $system_messages = system_messages(NULL, "");
    if (isset($system_messages['success'])) {
        $params['system_messages']['success'] = $system_messages['success'];
    }
    if (isset($system_messages['error'])) {
        $params['system_messages']['error'] = $system_messages['error'];
        $params['status'] = -1;
    }
    // We do not want to serve this page via non-xhr requests
    if (!elgg_is_xhr()) {
        register_error(elgg_echo('embed:error:non_xhr_request'));
        return false;
    }
    echo json_encode($params);
    exit;
}
Ejemplo n.º 8
0
/**
 * This function allows you to handle various visualizations of entities very easily.
 *
 * For example, `evan_view_entity('link', $blog)` will look for views in the following order: 
 * <ol>
 * <li>object/blog/link
 * <li>object/default/link
 * <li>entity/link
 * </ol>
 * 
 * This allows you to avoid filling your views with so many if/else statements like this:
 *
 * https://github.com/Elgg/Elgg/blob/f122c12ab35f26d5b77a18cc263fc199eb2a7b01/mod/blog/views/default/object/blog.php
 *
 * @param string $view     The subview to use to visualize this this entity.
 * @param Entity $entity   The entity to visualize.
 * @param array  $vars     Extra variables to pass to the view.
 * @param string $viewtype Set this to force the viewtype.
 *
 * @return string The generated view.
 */
function evan_view_entity($view, Entity $entity, array $vars = array(), $viewtype = 'default')
{
    $type = $entity->getType();
    $subtype = $entity->getSubtype();
    $vars['entity'] = $entity;
    if (elgg_view_exists("{$type}/{$subtype}/{$view}")) {
        return elgg_view("{$type}/{$subtype}/{$view}", $vars, $viewtype);
    } elseif (elgg_view_exists("{$type}/default/{$view}")) {
        return elgg_view("{$type}/default/{$view}", $vars, $viewtype);
    } else {
        return elgg_view("entity/{$view}", $vars, $viewtype);
    }
}
Ejemplo n.º 9
0
function elasticsearch_get_view($object)
{
    if ($object->type == "annotation") {
        $subtype = $object->name;
    } else {
        $subtype = get_subtype_from_id($object->subtype);
    }
    if (elgg_view_exists('search/' . $object->type . '/' . $subtype)) {
        return 'search/' . $object->type . '/' . $subtype;
    } else {
        if (elgg_view_exists('search/' . $object->type)) {
            return 'search/' . $object->type;
        }
    }
    return 'search/entity';
}
Ejemplo n.º 10
0
Archivo: river.php Proyecto: rasul/Elgg
/**
 * Adds an item to the river.
 *
 * @param string $view          The view that will handle the river item (must exist)
 * @param string $action_type   An arbitrary string to define the action (eg 'comment', 'create')
 * @param int    $subject_guid  The GUID of the entity doing the action
 * @param int    $object_guid   The GUID of the entity being acted upon
 * @param int    $access_id     The access ID of the river item (default: same as the object)
 * @param int    $posted        The UNIX epoch timestamp of the river item (default: now)
 * @param int    $annotation_id The annotation ID associated with this river entry
 *
 * @return bool Depending on success
 */
function add_to_river($view, $action_type, $subject_guid, $object_guid, $access_id = "", $posted = 0, $annotation_id = 0)
{
    // use default viewtype for when called from REST api
    if (!elgg_view_exists($view, 'default')) {
        return false;
    }
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    if (empty($action_type)) {
        return false;
    }
    if ($posted == 0) {
        $posted = time();
    }
    if ($access_id === "") {
        $access_id = $object->access_id;
    }
    $annotation_id = (int) $annotation_id;
    $type = $object->getType();
    $subtype = $object->getSubtype();
    $action_type = sanitise_string($action_type);
    $params = array('type' => $type, 'subtype' => $subtype, 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    // return false to stop insert
    $params = elgg_trigger_plugin_hook('add', 'river', null, $params);
    if ($params == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    extract($params);
    // Load config
    global $CONFIG;
    // Attempt to save river item; return success status
    $insert_data = insert_data("insert into {$CONFIG->dbprefix}river " . " set type = '{$type}', " . " subtype = '{$subtype}', " . " action_type = '{$action_type}', " . " access_id = {$access_id}, " . " view = '{$view}', " . " subject_guid = {$subject_guid}, " . " object_guid = {$object_guid}, " . " annotation_id = {$annotation_id}, " . " posted = {$posted}");
    //update the entities which had the action carried out on it
    if ($insert_data) {
        update_entity_last_action($object_guid, $posted);
        return $insert_data;
    }
}
Ejemplo n.º 11
0
function hj_framework_view_list($list_id, $getter_options = array(), $list_options = array(), $viewer_options = array(), $getter = 'elgg_get_entities')
{
    $default_list_options = array('list_type' => 'list', 'list_class' => null, 'item_class' => null, 'base_url' => current_page_url(), 'num_pages' => 5, 'pagination' => true, 'limit_key' => "__lim_{$list_id}", 'offset_key' => "__off_{$list_id}", 'order_by_key' => "__ord_{$list_id}", 'direction_key' => "__dir_{$list_id}", 'reverse_list' => false);
    $list_options = array_merge($default_list_options, $list_options);
    if (!isset($getter_options['limit'])) {
        $getter_options['limit'] = get_input($list_options['limit_key'], 10);
    }
    if (!isset($getter_options['offset'])) {
        $getter_options['offset'] = get_input($list_options['offset_key'], 0);
    }
    $porder_by = get_input($list_options['order_by_key'], '');
    $pdirection = get_input($list_options['direction_key'], 'DESC');
    $getter_options = hj_framework_get_order_by_clause($porder_by, $pdirection, $getter_options);
    if (isset($list_options['filter_callback']) && is_callable($list_options['filter_callback'])) {
        $getter_options = call_user_func_array($list_options['filter_callback'], array($list_id, $getter_options));
    }
    $getter_options = elgg_trigger_plugin_hook('custom_sql_clause', 'framework:lists', array('list_id' => $list_id, 'list_options' => $list_options, 'viewer_options' => $viewer_options), $getter_options);
    $getter_options['count'] = true;
    $count = $getter($getter_options);
    //error_log(print_r($getter_options, true));
    $getter_options['count'] = false;
    $entities = $getter($getter_options);
    if ($list_options['reverse_list']) {
        $entities = array_reverse($entities);
    }
    $params = array('list_id' => $list_id, 'entities' => $entities, 'count' => $count, 'list_options' => $list_options, 'getter_options' => $getter_options, 'viewer_options' => $viewer_options, 'getter' => $getter);
    if (elgg_view_exists("page/components/grids/{$list_options['list_type']}")) {
        $list = elgg_view("page/components/grids/{$list_options['list_type']}", $params, false, false, 'default');
    } else {
        $list = elgg_view("page/components/grids/list", $params, false, false, 'default');
    }
    if (elgg_is_xhr() && get_input('view') == 'xhr') {
        if (elgg_view_exists("page/components/grids/{$list_options['list_type']}")) {
            $json_list = elgg_view("page/components/grids/{$list_options['list_type']}", $params, false, false, 'xhr');
        } else {
            $json_list = elgg_view("page/components/grids/list", $params, false, false, 'xhr');
        }
        global $XHR_GLOBAL;
        $XHR_GLOBAL['lists'][$list_id] = $json_list;
    }
    return elgg_view('page/components/grids/wrapper', array('body' => $list));
}
Ejemplo n.º 12
0
/**
 * Route groups membership pages
 *
 * @param string $hook   "route"
 * @param string $type   "groups"
 * @param array  $return Identifier and segments
 * @param array  $params Hook params
 * @return array
 */
function group_membership_router($hook, $type, $return, $params)
{
    if (!is_array($return)) {
        return;
    }
    // Initial page identifier might be different from /groups
    // i.e. subtype specific handler e.g. /schools
    $initial_identifier = elgg_extract('identifier', $params);
    $identifier = elgg_extract('identifier', $return);
    $segments = elgg_extract('segments', $return);
    if ($identifier !== 'groups') {
        return;
    }
    $page = array_shift($segments);
    if (!$page) {
        $page = 'all';
    }
    // we want to pass the original identifier to the resource view
    // doing this via route hook in order to keep the page handler intact
    $resource_params = array('identifier' => $initial_identifier ?: 'groups', 'segments' => $segments);
    switch ($page) {
        case 'members':
            $guid = array_shift($segments);
            $sort = array_shift($segments);
            $resource_params['guid'] = $guid;
            $resource_params['sort'] = $sort;
            if (!elgg_is_active_plugin('user_sort') && elgg_view_exists("resources/groups/members/{$sort}")) {
                echo elgg_view_resource("groups/members/{$sort}", $resource_params);
            } else {
                echo elgg_view_resource('groups/members', $resource_params);
            }
            return false;
        case 'requests':
        case 'invited':
        case 'invite':
            $guid = array_shift($segments);
            $resource_params['guid'] = $guid;
            echo elgg_view_resource("groups/{$page}", $resource_params);
            return false;
    }
}
Ejemplo n.º 13
0
/**
 * Replaces file type icons
 *
 * @param string $hook   "entity:icon:url"
 * @param string $type   "object"
 * @param string $return Icon URL
 * @param array  $params Hook params
 * @return string
 */
function ui_icons_files_set_icon_url($hook, $type, $return, $params)
{
    $entity = elgg_extract('entity', $params);
    $size = elgg_extract('size', $params);
    if (!$entity instanceof \ElggFile || $entity->getSubtype() != 'file') {
        return;
    }
    $mimetype = $entity->mimetype ?: $entity->detectMimeType();
    if (!$mimetype) {
        $mimetype = 'application/otcet-stream';
    }
    if (0 === strpos($mimetype, 'image/') && $entity->icontime && $return) {
        return $return;
    }
    $extension = pathinfo($entity->getFilenameOnFilestore(), PATHINFO_EXTENSION);
    $filetype = ui_icons_files_map_type($mimetype, $extension);
    $view = "icon/object/file/{$filetype}.svg";
    if (!elgg_view_exists($view)) {
        $view = "icon/default.svg";
    }
    return elgg_get_simplecache_url($view);
}
Ejemplo n.º 14
0
/**
 * Get exportable metadata values
 *
 * @param ElggMetadata $metadata
 * @return array
 */
function elgg_tokeninput_export_metadata($metadata)
{
    if ($metadata instanceof ElggMetadata) {
        $type = $metadata->getType();
        $subtype = $metadata->getSubtype();
        $tag = $metadata->value;
        $id = $metadata->id;
    } else {
        if (is_string($metadata)) {
            $type = 'tag';
            $subtype = null;
            $tag = $metadata;
            $id = null;
        } else {
            return array();
        }
    }
    $export = array('label' => $tag, 'value' => $tag, 'type' => $type, 'subtype' => $subtype, 'html_result' => elgg_view_exists("tokeninput/{$type}/{$subtype}") ? elgg_view("tokeninput/{$type}/{$subtype}", array('tag' => $tag, 'metadata_id' => $id, 'for' => 'result')) : null, 'html_token' => elgg_view_exists("tokeninput/{$type}/{$subtype}") ? elgg_view("tokeninput/{$type}/{$subtype}", array('tag' => $tag, 'metadata_id' => $id, 'for' => 'token')) : null);
    $export = elgg_trigger_plugin_hook('tokeninput:entity:export', $type, array('tag' => $tag, 'metadata_id' => $id), $export);
    array_walk_recursive($export, function (&$value) {
        $value = is_string($value) ? html_entity_decode($value, ENT_QUOTES, 'UTF-8') : $value;
    });
    return $export;
}
Ejemplo n.º 15
0
/**
 * Display conten in the correct layout for embedding in Newsletter
 *
 * @param ElggEntity $entity the entity to embed
 * @param array      $vars   optional variables to pass to the embed view
 *
 * @return bool|string
 */
function newsletter_view_embed_content(ElggEntity $entity, $vars = array())
{
    if (empty($entity) || !elgg_instanceof($entity)) {
        return false;
    }
    if (!is_array($vars)) {
        $vars = array();
    }
    $vars["entity"] = $entity;
    $type = $entity->getType();
    $subtype = $entity->getSubtype();
    if (!empty($subtype) && elgg_view_exists("newsletter/embed/" . $type . "/" . $subtype)) {
        return elgg_view("newsletter/embed/" . $type . "/" . $subtype, $vars);
    } elseif (elgg_view_exists("newsletter/embed/" . $type . "/default")) {
        return elgg_view("newsletter/embed/" . $type . "/default", $vars);
    } elseif (elgg_view_exists("newsletter/embed/default")) {
        return elgg_view("newsletter/embed/default", $vars);
    }
    return false;
}
Ejemplo n.º 16
0
/**
 * Set up the menu for user settings
 *
 * @return void
 * @access private
 */
function _elgg_user_settings_menu_setup()
{
    $user = elgg_get_page_owner_entity();
    if (!$user) {
        return;
    }
    if (!elgg_in_context("settings")) {
        return;
    }
    $params = array('name' => '1_account', 'text' => elgg_echo('usersettings:user:opt:linktext'), 'href' => "settings/user/{$user->username}", 'section' => 'configure');
    elgg_register_menu_item('page', $params);
    $params = array('name' => '1_plugins', 'text' => elgg_echo('usersettings:plugins:opt:linktext'), 'href' => '#', 'section' => 'configure');
    elgg_register_menu_item('page', $params);
    $params = array('name' => '1_statistics', 'text' => elgg_echo('usersettings:statistics:opt:linktext'), 'href' => "settings/statistics/{$user->username}", 'section' => 'configure');
    elgg_register_menu_item('page', $params);
    // register plugin user settings menu items
    $active_plugins = elgg_get_plugins();
    foreach ($active_plugins as $plugin) {
        $plugin_id = $plugin->getID();
        if (elgg_view_exists("usersettings/{$plugin_id}/edit") || elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
            $params = array('name' => $plugin_id, 'text' => $plugin->getFriendlyName(), 'href' => "settings/plugins/{$user->username}/{$plugin_id}", 'parent_name' => '1_plugins', 'section' => 'configure');
            elgg_register_menu_item('page', $params);
        }
    }
    elgg_register_plugin_hook_handler("prepare", "menu:page", "_elgg_user_settings_menu_prepare");
}
Ejemplo n.º 17
0
    if (!empty($categories)) {
        ?>
		<div class="filerepo_categories">
			<?php 
        echo $categories;
        ?>
		</div>
<?php 
    }
    ?>
				</div>
		<?php 
    if (elgg_view_exists('file/specialcontent/' . $mime)) {
        echo "<div class=\"filerepo_specialcontent\">" . elgg_view('file/specialcontent/' . $mime, $vars) . "</div>";
    } else {
        if (elgg_view_exists("file/specialcontent/" . substr($mime, 0, strpos($mime, '/')) . "/default")) {
            echo "<div class=\"filerepo_specialcontent\">" . elgg_view("file/specialcontent/" . substr($mime, 0, strpos($mime, '/')) . "/default", $vars) . "</div>";
        }
    }
    ?>
		
		<div class="filerepo_download"><p><a href="<?php 
    echo $vars['url'];
    ?>
action/file/download?file_guid=<?php 
    echo $file_guid;
    ?>
"><?php 
    echo elgg_echo("file:download");
    ?>
</a></p></div>
Ejemplo n.º 18
0
Archivo: elgglib.php Proyecto: n8b/VMN
/**
 * Serves a JS or CSS view with headers for caching.
 *
 * /<css||js>/name/of/view.<last_cache>.<css||js>
 *
 * @param array  $page The page array
 * @param string $type The type: js or css
 *
 * @return bool
 * @access private
 */
function _elgg_cacheable_view_page_handler($page, $type)
{
    switch ($type) {
        case 'js':
            $content_type = 'text/javascript';
            break;
        case 'css':
            $content_type = 'text/css';
            break;
        default:
            return false;
            break;
    }
    if ($page) {
        // the view file names can have multiple dots
        // eg: views/default/js/calendars/jquery.fullcalendar.min.php
        // translates to the url /js/<ts>/calendars/jquery.fullcalendar.min.js
        // and the view js/calendars/jquery.fullcalendar.min
        // we ignore the last two dots for the ts and the ext.
        // Additionally, the timestamp is optional.
        $page = implode('/', $page);
        $regex = '|(.+?)\\.\\w+$|';
        if (!preg_match($regex, $page, $matches)) {
            return false;
        }
        $view = "{$type}/{$matches[1]}";
        if (!elgg_view_exists($view)) {
            return false;
        }
        $return = elgg_view($view);
        header("Content-type: {$content_type}");
        // @todo should js be cached when simple cache turned off
        //header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
        //header("Pragma: public");
        //header("Cache-Control: public");
        //header("Content-Length: " . strlen($return));
        echo $return;
        return true;
    }
    return false;
}
Ejemplo n.º 19
0
/**
 * Adds support for plugins that extends embed/custom_insert_js deprecated views
 *
 * @param {String} hook
 * @param {String} type
 * @param {Object} params
 * @param {String|Boolean} value
 * @returns {String|Boolean}
 * @private
 */
elgg.embed._deprecated_custom_insert_js = function(hook, type, params, value) {
	var textAreaId = params.textAreaId;
	var content = params.content;
	var event = params.event;
<?php 
if (elgg_view_exists('embed/custom_insert_js')) {
    elgg_deprecated_notice("The view embed/custom_insert_js has been replaced by the js hook 'embed', 'editor'.", 1.9);
    echo elgg_view('embed/custom_insert_js');
}
?>
};

/**
 * Inserts data attached to an embed list item in textarea
 *
 * @param {Object} event
 * @return void
 */
elgg.embed.insert = function(event) {
	var textAreaId = elgg.embed.textAreaId;
	var textArea = $('#' + textAreaId);
Ejemplo n.º 20
0
            if (isset($field['class'])) {
                $field['class'] = "{$field['class']} elgg-input-validated";
            } else {
                $field['class'] = 'elgg-input-validated';
            }
            $wrapper_class = 'elgg-input-wrapper-validated';
        }
    }
    $validation_message = elgg_extract('msg', $validation_status, null);
    if ($validation_message) {
        $validation_message = elgg_view('framework/bootstrap/form/elements/validation_message', array('msg' => $validation_message));
    }
}
if ($sticky_value) {
    $field['value'] = $sticky_value;
}
$view = "input/{$input_type}";
if (isset($field['override_view'])) {
    if (elgg_view_exists($field['override_view'])) {
        $view = $field['override_view'];
    }
    unset($field['override_view']);
} else {
    if (!elgg_view_exists($view)) {
        $view = 'input/text';
    }
}
unset($field['form_name']);
$input = elgg_view($view, $field);
$wrapper_params = array('label' => $label, 'hint' => $hint, 'input' => $input, 'validation_message' => $validation_message, 'class' => $wrapper_class, 'field' => $field_source);
echo elgg_view('framework/bootstrap/form/elements/wrapper', $wrapper_params);
Ejemplo n.º 21
0
/**
 * Displays an internal layout for the use of a plugin canvas.
 * Takes a variable number of parameters, which are made available
 * in the views as $vars['area1'] .. $vars['areaN'].
 *
 * @param string $layout The name of the views in canvas/layouts/.
 * @return string The layout
 */
function sw_elgg_view_layout($layout)
{
    $arg = 1;
    $param_array = array();
    while ($arg < func_num_args() - 2) {
        $param_array['area' . $arg] = func_get_arg($arg);
        $arg++;
    }
    $param_array['swType'] = func_get_arg($arg++);
    //	$param_array['swWhere'] = func_get_arg($arg);
    if (elgg_view_exists("canvas/layouts/{$layout}")) {
        return elgg_view("canvas/layouts/{$layout}", $param_array);
    } else {
        return elgg_view("canvas/default", $param_array);
    }
}
Ejemplo n.º 22
0
/**
 * Adds an item to the river.
 *
 * @tip Read the item like "Lisa (subject) posted (action)
 * a comment (object) on John's blog (target)".
 *
 * @param array $options Array in format:
 *
 * 	view => STR The view that will handle the river item (must exist)
 *
 * 	action_type => STR An arbitrary string to define the action (eg 'comment', 'create')
 *
 *  subject_guid => INT The GUID of the entity doing the action
 *
 *  object_guid => INT The GUID of the entity being acted upon
 *
 *  target_guid => INT The GUID of the the object entity's container
 *
 *  access_id => INT The access ID of the river item (default: same as the object)
 *
 *  posted => INT The UNIX epoch timestamp of the river item (default: now)
 *
 *  annotation_id INT The annotation ID associated with this river entry
 *
 * @return int|bool River ID or false on failure
 * @since 1.9
 */
function elgg_create_river_item(array $options = array())
{
    $view = elgg_extract('view', $options);
    // use default viewtype for when called from web services api
    if (empty($view) || !elgg_view_exists($view, 'default')) {
        return false;
    }
    $action_type = elgg_extract('action_type', $options);
    if (empty($action_type)) {
        return false;
    }
    $subject_guid = elgg_extract('subject_guid', $options, 0);
    if (!($subject = get_entity($subject_guid))) {
        return false;
    }
    $object_guid = elgg_extract('object_guid', $options, 0);
    if (!($object = get_entity($object_guid))) {
        return false;
    }
    $target_guid = elgg_extract('target_guid', $options, 0);
    if ($target_guid) {
        // target_guid is not a required parameter so check
        // it only if it is included in the parameters
        if (!($target = get_entity($target_guid))) {
            return false;
        }
    }
    $access_id = elgg_extract('access_id', $options, $object->access_id);
    $posted = elgg_extract('posted', $options, time());
    $annotation_id = elgg_extract('annotation_id', $options, 0);
    if ($annotation_id) {
        if (!elgg_get_annotation_from_id($annotation_id)) {
            return false;
        }
    }
    $values = array('type' => $object->getType(), 'subtype' => $object->getSubtype(), 'action_type' => $action_type, 'access_id' => $access_id, 'view' => $view, 'subject_guid' => $subject_guid, 'object_guid' => $object_guid, 'target_guid' => $target_guid, 'annotation_id' => $annotation_id, 'posted' => $posted);
    $col_types = array('type' => 'string', 'subtype' => 'string', 'action_type' => 'string', 'access_id' => 'int', 'view' => 'string', 'subject_guid' => 'int', 'object_guid' => 'int', 'target_guid' => 'int', 'annotation_id' => 'int', 'posted' => 'int');
    // return false to stop insert
    $values = elgg_trigger_plugin_hook('creating', 'river', null, $values);
    if ($values == false) {
        // inserting did not fail - it was just prevented
        return true;
    }
    $dbprefix = elgg_get_config('dbprefix');
    // escape values array and build INSERT assignments
    $assignments = array();
    foreach ($col_types as $name => $type) {
        $values[$name] = $type === 'int' ? (int) $values[$name] : sanitize_string($values[$name]);
        $assignments[] = "{$name} = '{$values[$name]}'";
    }
    $id = insert_data("INSERT INTO {$dbprefix}river SET " . implode(',', $assignments));
    // update the entities which had the action carried out on it
    // @todo shouldn't this be done elsewhere? Like when an annotation is saved?
    if ($id) {
        update_entity_last_action($values['object_guid'], $values['posted']);
        $river_items = elgg_get_river(array('id' => $id));
        if ($river_items) {
            elgg_trigger_event('created', 'river', $river_items[0]);
        }
        return $id;
    } else {
        return false;
    }
}
Ejemplo n.º 23
0
}
if ($page > $total_pages) {
    $page = $total_pages;
}
$offset = $limit * $page - $limit;
$offset = $offset < 0 ? 0 : $offset;
$row_data = get_data("SELECT * FROM {$dbprefix}entities e\n\t\t\t\t\t\tWHERE e.owner_guid = {$guid}\n\t\t\t\t\t\tORDER BY {$sidx} {$sord}\n\t\t\t\t\t\tLIMIT {$limit}\n\t\t\t\t\t\tOFFSET {$offset}");
if (!empty($row_data)) {
    $i = 0;
    $ordered_cols = array('checkbox', 'guid', 'type', 'subtype', 'owner_guid', 'site_guid', 'container_guid', 'access_id', 'time_created', 'time_updated', 'last_action', 'enabled');
    foreach ($row_data as $r) {
        $results['rows'][$i]['id'] = $r->id;
        $r_vars = get_object_vars($r);
        foreach ($ordered_cols as $col) {
            $value = $r_vars[$col];
            if (elgg_view_exists("framework/db_explorer/db_column/{$col}")) {
                $results['rows'][$i]['cell'][] = elgg_view("framework/db_explorer/db_column/{$col}", array('data' => $r));
            } else {
                $results['rows'][$i]['cell'][] = $value;
            }
        }
        $i++;
    }
}
$results['page'] = $page;
$results['total'] = $total_pages;
$results['records'] = $count;
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header('Cache-Control: no-cache, must-revalidate');
header("Pragma: no-cache");
Ejemplo n.º 24
0
$show_access = elgg_extract('show_access', $vars, true);
// @todo catch for disabled plugins
$widget_types = elgg_get_widget_types('all');
$handler = $widget->handler;
$title = $widget->getTitle();
$edit_area = '';
$can_edit = $widget->canEdit();
if ($can_edit) {
    $edit_area = elgg_view('object/widget/elements/settings', array('widget' => $widget, 'show_access' => $show_access));
}
$controls = elgg_view('object/widget/elements/controls', array('widget' => $widget, 'show_edit' => $edit_area != ''));
// don't show content for default widgets
if (elgg_in_context('default_widgets')) {
    $content = '';
} else {
    if (elgg_view_exists("widgets/{$handler}/content")) {
        $content = elgg_view("widgets/{$handler}/content", $vars);
    } else {
        elgg_deprecated_notice("widgets use content as the display view", 1.8);
        $content = elgg_view("widgets/{$handler}/view", $vars);
    }
}
$widget_id = "elgg-widget-{$widget->guid}";
$widget_instance = "elgg-widget-instance-{$handler}";
$widget_class = "elgg-module elgg-module-widget";
if ($can_edit) {
    $widget_class .= " elgg-state-draggable {$widget_instance}";
} else {
    $widget_class .= " elgg-state-fixed {$widget_instance}";
}
$widget_header = <<<HEADER
Ejemplo n.º 25
0
echo elgg_view('input/longtext', $description);
?>
</div>
<div>
	<label for='question_tags'><?php 
echo elgg_echo('tags');
?>
</label>
	<?php 
echo elgg_view('input/tags', $tags);
?>
</div>

<?php 
// categories support
if (elgg_view_exists('input/categories')) {
    echo elgg_view('input/categories', $vars);
}
// comments
$comments = elgg_format_element('label', ['for' => 'questions-comments'], elgg_echo('comments'));
$comments .= elgg_view('input/select', $comment_options);
echo elgg_format_element('div', [], $comments);
// access options
if ($show_access_options) {
    $access = elgg_format_element('label', ['for' => 'question_access_id'], elgg_echo('access'));
    $access .= '<br />';
    $access .= elgg_view('input/access', $access_id);
    echo elgg_format_element('div', [], $access);
} else {
    echo elgg_view('input/hidden', ['name' => 'access_id', 'value' => $access_setting]);
}
Ejemplo n.º 26
0
            if (elgg_view_exists($enttype . '/' . $entsubtype . '/embed')) {
                $content = elgg_view($enttype . '/' . $entsubtype . '/embed', array('entity' => $entity, 'full' => true));
            } else {
                $content = elgg_view($enttype . '/default/embed', array('entity' => $entity, 'full' => true));
            }
            $content = str_replace("\n", "", $content);
            $content = str_replace("\r", "", $content);
            //$content = htmlentities($content,null,'utf-8');
            $content = htmlentities($content, ENT_COMPAT, "UTF-8");
            $link = "javascript:elggUpdateContent('{$content}','{$vars['internalname']}');";
            if ($entity instanceof ElggObject) {
                $title = $entity->title;
                $mime = $entity->mimetype;
            } else {
                $title = $entity->name;
                $mime = '';
            }
            set_context('search');
            if (elgg_view_exists("{$enttype}/{$entsubtype}/embedlist")) {
                $entview = elgg_view("{$enttype}/{$entsubtype}/embedlist", array('entity' => $entity));
            } else {
                $entview = elgg_view_entity($entity);
            }
            $entview = str_replace($entity->getURL(), $link, $entview);
            echo $entview;
            set_context($context);
        }
    }
}
?>
</div>
Ejemplo n.º 27
0
/**
 * Groups page handler
 *
 * URLs take the form of
 *  All groups:           groups/all
 *  User's owned groups:  groups/owner/<username>
 *  User's member groups: groups/member/<username>
 *  Group profile:        groups/profile/<guid>/<title>
 *  New group:            groups/add/<guid>
 *  Edit group:           groups/edit/<guid>
 *  Group invitations:    groups/invitations/<username>
 *  Invite to group:      groups/invite/<guid>
 *  Membership requests:  groups/requests/<guid>
 *  Group activity:       groups/activity/<guid>
 *  Group members:        groups/members/<guid>
 *
 * @param array $page Array of url segments for routing
 * @return bool
 */
function groups_page_handler($page)
{
    elgg_load_library('elgg:groups');
    if (!isset($page[0])) {
        $page[0] = 'all';
    }
    elgg_push_breadcrumb(elgg_echo('groups'), "groups/all");
    $vars = [];
    switch ($page[0]) {
        case 'add':
        case 'all':
        case 'owner':
        case 'search':
            echo elgg_view_resource("groups/{$page[0]}");
            break;
        case 'invitations':
        case 'member':
            echo elgg_view_resource("groups/{$page[0]}", ['username' => $page[1]]);
            break;
        case 'members':
            $vars['sort'] = elgg_extract('2', $page, 'alpha');
            $vars['guid'] = elgg_extract('1', $page);
            if (elgg_view_exists("resources/groups/members/{$vars['sort']}")) {
                echo elgg_view_resource("groups/members/{$vars['sort']}", $vars);
            } else {
                echo elgg_view_resource('groups/members', $vars);
            }
            break;
        case 'profile':
            // Page owner and context need to be set before elgg_view() is
            // called so they'll be available in the [pagesetup, system] event
            // that is used for registering items for the sidebar menu.
            // @see groups_setup_sidebar_menus()
            elgg_push_context('group_profile');
            elgg_set_page_owner_guid($page[1]);
        case 'activity':
        case 'edit':
        case 'invite':
        case 'requests':
            echo elgg_view_resource("groups/{$page[0]}", ['guid' => $page[1]]);
            break;
        default:
            return false;
    }
    return true;
}
Ejemplo n.º 28
0
/**
 * Register menu items for the user settings page menu
 *
 * @param string $hook
 * @param string $type
 * @param array  $return
 * @param array  $params
 * @return array
 *
 * @access private
 *
 * @since 3.0
 */
function _elgg_user_settings_menu_register($hook, $type, $return, $params)
{
    $user = elgg_get_page_owner_entity();
    if (!$user) {
        return;
    }
    if (!elgg_in_context('settings')) {
        return;
    }
    $return[] = \ElggMenuItem::factory(['name' => '1_account', 'text' => elgg_echo('usersettings:user:opt:linktext'), 'href' => "settings/user/{$user->username}", 'section' => 'configure']);
    $return[] = \ElggMenuItem::factory(['name' => '1_plugins', 'text' => elgg_echo('usersettings:plugins:opt:linktext'), 'href' => '#', 'section' => 'configure']);
    $return[] = \ElggMenuItem::factory(['name' => '1_statistics', 'text' => elgg_echo('usersettings:statistics:opt:linktext'), 'href' => "settings/statistics/{$user->username}", 'section' => 'configure']);
    // register plugin user settings menu items
    $active_plugins = elgg_get_plugins();
    foreach ($active_plugins as $plugin) {
        $plugin_id = $plugin->getID();
        if (!elgg_view_exists("usersettings/{$plugin_id}/edit") && !elgg_view_exists("plugins/{$plugin_id}/usersettings")) {
            continue;
        }
        if (elgg_language_key_exists($plugin_id . ':usersettings:title')) {
            $title = elgg_echo($plugin_id . ':usersettings:title');
        } else {
            $title = $plugin->getFriendlyName();
        }
        $return[] = \ElggMenuItem::factory(['name' => $plugin_id, 'text' => $title, 'href' => "settings/plugins/{$user->username}/{$plugin_id}", 'parent_name' => '1_plugins', 'section' => 'configure']);
    }
    return $return;
}
Ejemplo n.º 29
0
Archivo: content.php Proyecto: n8b/VMN
// owner_guids
if (!empty($widget->owner_guids)) {
    if (!is_array($widget->owner_guids)) {
        $owner_guids = string_to_tag_array($widget->owner_guids);
    } else {
        $owner_guids = $widget->owner_guids;
    }
    if (!empty($owner_guids)) {
        $options["owner_guids"] = $owner_guids;
    }
}
if ($widget->context == "groups") {
    if ($widget->group_only !== "no") {
        $options["container_guids"] = array($widget->getContainerGUID());
    }
} elseif (elgg_view_exists("input/grouppicker")) {
    $container_guids = $widget->container_guids;
    if (!empty($container_guids)) {
        $options["container_guids"] = $container_guids;
    }
}
elgg_push_context("search");
$display_option = $widget->display_option;
if (in_array($display_option, array("slim", "simple"))) {
    if ($entities = elgg_get_entities($options)) {
        $num_highlighted = (int) $widget->highlight_first;
        $result .= "<ul class='elgg-list'>";
        $show_avatar = true;
        if ($widget->show_avatar == "no") {
            $show_avatar = false;
        }
Ejemplo n.º 30
0
} else {
    $categories[] = "inactive";
}
$categories_html = '';
if ($categories) {
    foreach ($categories as $category) {
        $css_class = preg_replace('/[^a-z0-9-]/i', '-', $category);
        $classes[] = "elgg-plugin-category-{$css_class}";
    }
}
// metadata
$description = elgg_view('output/longtext', array('value' => $plugin->getManifest()->getDescription()));
$settings_view_old = 'settings/' . $plugin->getID() . '/edit';
$settings_view_new = 'plugins/' . $plugin->getID() . '/settings';
$settings_link = '';
if (elgg_view_exists($settings_view_old) || elgg_view_exists($settings_view_new)) {
    $link = elgg_get_site_url() . "admin/plugin_settings/" . $plugin->getID();
    $settings_link = "<a class='elgg-plugin-settings' href='{$link}' title='" . elgg_echo('settings') . "'>" . elgg_view_icon("settings-alt") . "</a>";
}
$attrs = ['class' => $classes, 'id' => $css_id, 'data-guid' => $plugin->guid];
?>
<div <?php 
echo elgg_format_attributes($attrs);
?>
>
	<div class="elgg-image-block">
		<div class="elgg-image">
			<div>
				<?php 
echo $action_button;
?>