Elgg  Version 2.3
/root/Elgg/engine/lib/views.php

Convenience function for generating a form from a view in a standard location.This function assumes that the body of the form is located at "forms/$action" and sets the action by default to "action/$action". Automatically wraps the forms/$action view with a <form> tag and inserts the anti-csrf security tokens.

@tip This automatically appends elgg-form-action-name to the form's class. It replaces any slashes with dashes (blog/save becomes elgg-form-blog-save)

echo elgg_view_form('login');

This would assume a "login" form body to be at "forms/login" and would set the action of the form to "http://yoursite.com/action/login".

If elgg_view('forms/login') is: <input type="text" name="username" > <input type="password" name="password" >

Then elgg_view_form('login') generates: <form action="http://yoursite.com/action/login" method="post"> ...security tokens... <input type="text" name="username" > <input type="password" name="password" > </form>

Parameters
string$actionThe name of the action. An action name does not include the leading "action/". For example, "login" is an action name.
array$form_vars$vars environment passed to the "input/form" view
array$body_vars$vars environment passed to the "forms/$action" view
Returns
string The complete form
<?php
function elgg_set_viewtype($viewtype = "") {
return true;
}
function elgg_get_viewtype() {
}
}
global $CONFIG;
$viewtype = get_input('view', '', false);
if (_elgg_is_valid_viewtype($viewtype)) {
return $viewtype;
}
if (isset($CONFIG->view) && _elgg_is_valid_viewtype($CONFIG->view)) {
return $CONFIG->view;
}
return 'default';
}
function elgg_register_viewtype($viewtype) {
if (!isset($GLOBALS['_ELGG']->view_types) || !is_array($GLOBALS['_ELGG']->view_types)) {
$GLOBALS['_ELGG']->view_types = array();
}
if (!in_array($viewtype, $GLOBALS['_ELGG']->view_types)) {
$GLOBALS['_ELGG']->view_types[] = $viewtype;
}
return true;
}
function elgg_is_registered_viewtype($viewtype) {
if (!isset($GLOBALS['_ELGG']->view_types) || !is_array($GLOBALS['_ELGG']->view_types)) {
return false;
}
return in_array($viewtype, $GLOBALS['_ELGG']->view_types);
}
function _elgg_is_valid_viewtype($viewtype) {
if (!is_string($viewtype) || $viewtype === '') {
return false;
}
if (preg_match('/\W/', $viewtype)) {
return false;
}
return true;
}
function elgg_register_viewtype_fallback($viewtype) {
_elgg_services()->views->registerViewtypeFallback($viewtype);
}
function elgg_does_viewtype_fallback($viewtype) {
return _elgg_services()->views->doesViewtypeFallback($viewtype);
}
}
}
function elgg_register_external_view($view, $cacheable = false) {
_elgg_services()->ajax->registerView($view);
if ($cacheable) {
_elgg_services()->views->registerCacheableView($view);
}
}
_elgg_services()->ajax->unregisterView($view);
}
function elgg_set_view_location($view, $location, $viewtype = '') {
_elgg_services()->views->setViewDir($view, $location, $viewtype);
}
function elgg_view_exists($view, $viewtype = '', $recurse = true) {
return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
}
function elgg_list_views($viewtype = 'default') {
return _elgg_services()->views->listViews($viewtype);
}
function elgg_view($view, $vars = array(), $ignore1 = false, $ignore2 = false, $viewtype = '') {
return _elgg_services()->views->renderView($view, $vars, $ignore1, $viewtype);
}
function elgg_view_deprecated($view, array $vars, $suggestion, $version) {
return _elgg_services()->views->renderDeprecatedView($view, $vars, $suggestion, $version);
}
function elgg_extend_view($view, $view_extension, $priority = 501) {
_elgg_services()->views->extendView($view, $view_extension, $priority);
}
function elgg_unextend_view($view, $view_extension) {
return _elgg_services()->views->unextendView($view, $view_extension);
}
$list = _elgg_services()->views->getViewList($view);
unset($list[500]);
return $list;
}
return Minify_CSS_UriRewriter::prepend($css, $path);
}
function elgg_view_page($title, $body, $page_shell = 'default', $vars = array()) {
$timer = _elgg_services()->timer;
if (!$timer->hasEnded(['build page'])) {
$timer->end(['build page']);
}
$timer->begin([__FUNCTION__]);
$params = array();
$params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
$params['segments'] = _elgg_services()->request->getUrlSegments();
array_shift($params['segments']);
$page_shell = elgg_trigger_plugin_hook('shell', 'page', $params, $page_shell);
$system_messages = _elgg_services()->systemMessages;
$messages = null;
if ($system_messages->count()) {
$messages = $system_messages->dumpRegister();
if (isset($messages['error'])) {
// always make sure error is the first type
$errors = array(
'error' => $messages['error']
);
unset($messages['error']);
$messages = array_merge($errors, $messages);
}
}
$vars['title'] = $title;
$vars['body'] = $body;
$vars['sysmessages'] = $messages;
// head has keys 'title', 'metas', 'links'
$vars['head'] = elgg_trigger_plugin_hook('head', 'page', $vars, $head_params);
$vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars);
$output = elgg_view("page/$page_shell", $vars);
$vars['page_shell'] = $page_shell;
// Allow plugins to modify the output
$timer->end([__FUNCTION__]);
return $output;
}
function elgg_view_resource($name, array $vars = []) {
$view = "resources/$name";
return _elgg_services()->views->renderView($view, $vars);
}
if (elgg_get_viewtype() !== 'default' && elgg_view_exists($view, 'default')) {
return _elgg_services()->views->renderView($view, $vars, false, 'default');
}
_elgg_services()->logger->error("The view $view is missing.");
if (elgg_get_viewtype() === 'default') {
// only works for default viewtype
forward('', '404');
} else {
register_error(elgg_echo('error:404:content'));
forward('');
}
}
$params = array(
'links' => array(),
'metas' => array(),
);
if (empty($title)) {
$params['title'] = elgg_get_config('sitename');
} else {
$params['title'] = $title . ' : ' . elgg_get_config('sitename');
}
$params['metas']['content-type'] = array(
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=utf-8',
);
$params['metas']['description'] = array(
'name' => 'description',
'content' => elgg_get_config('sitedescription')
);
// https://developer.chrome.com/multidevice/android/installtohomescreen
$params['metas']['viewport'] = array(
'name' => 'viewport',
'content' => 'width=device-width',
);
$params['metas']['mobile-web-app-capable'] = array(
'name' => 'mobile-web-app-capable',
'content' => 'yes',
);
$params['metas']['apple-mobile-web-app-capable'] = array(
'name' => 'apple-mobile-web-app-capable',
'content' => 'yes',
);
// RSS feed link
if (substr_count($url,'?')) {
$url .= "&view=rss";
} else {
$url .= "?view=rss";
}
$params['links']['rss'] = array(
'rel' => 'alternative',
'type' => 'application/rss+xml',
'title' => 'RSS',
'href' => elgg_format_url($url),
);
}
return $params;
}
function _elgg_views_prepare_favicon_links($hook, $type, $head_params, $params) {
$head_params['links']['apple-touch-icon'] = array(
'rel' => 'apple-touch-icon',
'href' => elgg_get_simplecache_url('favicon-128.png'),
);
// favicons
$head_params['links']['icon-ico'] = array(
'rel' => 'icon',
'href' => elgg_get_simplecache_url('favicon.ico'),
);
$head_params['links']['icon-vector'] = array(
'rel' => 'icon',
'sizes' => '16x16 32x32 48x48 64x64 128x128',
'type' => 'image/svg+xml',
'href' => elgg_get_simplecache_url('favicon.svg'),
);
$head_params['links']['icon-16'] = array(
'rel' => 'icon',
'sizes' => '16x16',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-16.png'),
);
$head_params['links']['icon-32'] = array(
'rel' => 'icon',
'sizes' => '32x32',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-32.png'),
);
$head_params['links']['icon-64'] = array(
'rel' => 'icon',
'sizes' => '64x64',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-64.png'),
);
$head_params['links']['icon-128'] = array(
'rel' => 'icon',
'sizes' => '128x128',
'type' => 'image/png',
'href' => elgg_get_simplecache_url('favicon-128.png'),
);
return $head_params;
}
function elgg_view_layout($layout_name, $vars = array()) {
$timer = _elgg_services()->timer;
if (!$timer->hasEnded(['build page'])) {
$timer->end(['build page']);
}
$timer->begin([__FUNCTION__]);
$params = array();
$params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
$params['segments'] = _elgg_services()->request->getUrlSegments();
array_shift($params['segments']);
$layout_name = elgg_trigger_plugin_hook('layout', 'page', $params, $layout_name);
$param_array = $vars;
$param_array['layout'] = $layout_name;
$params = elgg_trigger_plugin_hook('output:before', 'layout', null, $param_array);
if (elgg_view_exists("page/layouts/$layout_name")) {
$output = elgg_view("page/layouts/$layout_name", $params);
} else {
$output = elgg_view("page/layouts/default", $params);
}
$output = elgg_trigger_plugin_hook('output:after', 'layout', $params, $output);
$timer->end([__FUNCTION__]);
return $output;
}
function elgg_view_menu($menu, array $vars = array()) {
$menu_view = elgg_extract('menu_view', $vars);
unset($vars['menu_view']);
if (is_string($menu)) {
$menu = _elgg_services()->menus->getMenu($menu, $vars);
} elseif ($menu instanceof UnpreparedMenu) {
$menu = _elgg_services()->menus->prepareMenu($menu);
}
if (!$menu instanceof Menu) {
throw new \InvalidArgumentException('$menu must be a menu name, a Menu, or UnpreparedMenu');
}
$name = $menu->getName();
$params = $menu->getParams();
$views = [
$menu_view,
"navigation/menu/$name",
'navigation/menu/default',
];
foreach ($views as $view) {
}
}
}
function elgg_view_menu_item(\ElggMenuItem $item, array $vars = array()) {
if (!isset($vars['class'])) {
$vars['class'] = 'elgg-menu-content';
}
$vars = array_merge($item->getValues(), $vars);
if ($item->getLinkClass()) {
$vars['class'] .= ' ' . $item->getLinkClass();
}
if ($item->getHref() === false || $item->getHref() === null) {
$text = $item->getText();
// if contains elements, don't wrap
if (preg_match('~<[a-z]~', $text)) {
return $text;
} else {
return elgg_format_element('span', array('class' => 'elgg-non-link'), $text);
}
}
if (!isset($vars['rel']) && !isset($vars['is_trusted'])) {
$vars['is_trusted'] = true;
}
if ($item->getConfirmText()) {
$vars['confirm'] = $item->getConfirmText();
}
return elgg_view('output/url', $vars);
}
function elgg_view_entity(\ElggEntity $entity, array $vars = array(), $bypass = false, $debug = false) {
// No point continuing if entity is null
if (!$entity || !($entity instanceof \ElggEntity)) {
return false;
}
$defaults = array(
'full_view' => true,
);
$vars = array_merge($defaults, $vars);
$vars['entity'] = $entity;
$entity_type = $entity->getType();
$entity_subtype = $entity->getSubtype();
if (empty($entity_subtype)) {
$entity_subtype = 'default';
}
$entity_views = array(
elgg_extract('item_view', $vars, ''),
"$entity_type/$entity_subtype",
"$entity_type/default",
);
$contents = '';
foreach ($entity_views as $view) {
break;
}
}
// Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
if ($vars['full_view']) {
if ($annotations) {
}
}
return $contents;
}
function elgg_view_entity_icon(\ElggEntity $entity, $size = 'medium', $vars = array()) {
// No point continuing if entity is null
if (!$entity || !($entity instanceof \ElggEntity)) {
return false;
}
$vars['entity'] = $entity;
$vars['size'] = $size;
$entity_type = $entity->getType();
$subtype = $entity->getSubtype();
if (empty($subtype)) {
$subtype = 'default';
}
$contents = '';
if (elgg_view_exists("icon/$entity_type/$subtype")) {
$contents = elgg_view("icon/$entity_type/$subtype", $vars);
}
if (empty($contents)) {
$contents = elgg_view("icon/$entity_type/default", $vars);
}
if (empty($contents)) {
$contents = elgg_view("icon/default", $vars);
}
return $contents;
}
function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = array(), $bypass = false, $debug = false) {
$defaults = array(
'full_view' => true,
);
$vars = array_merge($defaults, $vars);
$vars['annotation'] = $annotation;
$name = $annotation->name;
if (empty($name)) {
return false;
}
$annotation_views = array(
elgg_extract('item_view', $vars, ''),
"annotation/$name",
"annotation/default",
);
$contents = '';
foreach ($annotation_views as $view) {
break;
}
}
return $contents;
}
function elgg_view_entity_list($entities, array $vars = array()) {
$offset = (int)get_input('offset', 0);
// list type can be passed as request parameter
$list_type = get_input('list_type', 'list');
$defaults = array(
'items' => $entities,
'list_class' => 'elgg-list-entity',
'full_view' => true,
'pagination' => true,
'list_type' => $list_type,
'list_type_toggle' => false,
'offset' => $offset,
'limit' => null,
);
$vars = array_merge($defaults, $vars);
if (!$vars["limit"] && !$vars["offset"]) {
// no need for pagination if listing is unlimited
$vars["pagination"] = false;
}
if ($vars['list_type'] == 'table') {
return elgg_view('page/components/table', $vars);
} elseif ($vars['list_type'] == 'list') {
return elgg_view('page/components/list', $vars);
} else {
return elgg_view('page/components/gallery', $vars);
}
}
function elgg_view_annotation_list($annotations, array $vars = array()) {
$defaults = array(
'items' => $annotations,
'offset' => null,
'limit' => null,
'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9
'full_view' => true,
'offset_key' => 'annoff',
);
$vars = array_merge($defaults, $vars);
if (!$vars["limit"] && !$vars["offset"]) {
// no need for pagination if listing is unlimited
$vars["pagination"] = false;
}
return elgg_view('page/components/list', $vars);
}
if (!($entity instanceof \ElggEntity)) {
return false;
}
$entity_type = $entity->getType();
$annotations = elgg_trigger_plugin_hook('entity:annotate', $entity_type,
array(
'entity' => $entity,
'full_view' => $full_view,
)
);
return $annotations;
}
function elgg_view_title($title, array $vars = array()) {
$vars['title'] = $title;
return elgg_view('page/elements/title', $vars);
}
function elgg_view_friendly_time($time) {
$view = 'output/friendlytime';
$vars = ['time' => $time];
$viewtype = elgg_view_exists($view) ? '' : 'default';
return _elgg_view_under_viewtype($view, $vars, $viewtype);
}
function elgg_view_comments($entity, $add_comment = true, array $vars = array()) {
if (!($entity instanceof \ElggEntity)) {
return false;
}
$vars['entity'] = $entity;
$vars['show_add_form'] = $add_comment;
$vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
$output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
if ($output !== false) {
return $output;
} else {
return elgg_view('page/elements/comments', $vars);
}
}
function elgg_view_image_block($image, $body, $vars = array()) {
$vars['image'] = $image;
$vars['body'] = $body;
return elgg_view('page/components/image_block', $vars);
}
function elgg_view_module($type, $title, $body, array $vars = array()) {
$vars['type'] = $type;
$vars['title'] = $title;
$vars['body'] = $body;
return elgg_view('page/components/module', $vars);
}
function elgg_view_river_item($item, array $vars = array()) {
if (!($item instanceof \ElggRiverItem)) {
return '';
}
// checking default viewtype since some viewtypes do not have unique views per item (rss)
$view = $item->getView();
if (!$view || !elgg_view_exists($view, 'default')) {
return '';
}
$subject = $item->getSubjectEntity();
$object = $item->getObjectEntity();
if (!$subject || !$object) {
// subject is disabled or subject/object deleted
return '';
}
// @todo this needs to be cleaned up
// Don't hide objects in closed groups that a user can see.
// see https://github.com/elgg/elgg/issues/4789
// else {
// // hide based on object's container
// $visibility = \Elgg\GroupItemVisibility::factory($object->container_guid);
// if ($visibility->shouldHideItems) {
// return '';
// }
// }
$vars['item'] = $item;
$river_views = array(
elgg_extract('item_view', $vars, ''),
"river/item",
);
$contents = '';
foreach ($river_views as $view) {
break;
}
}
return $contents;
}
function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
return _elgg_services()->forms->render($action, $form_vars, $body_vars);
}
function elgg_set_form_footer($footer = '') {
return _elgg_services()->forms->setFooter($footer);
}
return _elgg_services()->forms->getFooter();
}
function elgg_view_input($input_type, array $vars = array()) {
elgg_deprecated_notice(__FUNCTION__ . '() is deprecated. Use elgg_view_field()', '2.3');
$vars['#type'] = $input_type;
if (isset($vars['label']) && $input_type !== 'checkbox') {
$vars['#label'] = $vars['label'];
unset($vars['label']);
}
if (isset($vars['help'])) {
$vars['#help'] = $vars['help'];
unset($vars['help']);
}
if (isset($vars['field_class'])) {
$vars['#class'] = $vars['field_class'];
unset($vars['field_class']);
}
}
function elgg_view_field(array $params = []) {
if (empty($params['#type'])) {
_elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.');
return '';
}
$input_type = $params['#type'];
if (!elgg_view_exists("input/$input_type")) {
return '';
}
$hidden_types = ['hidden', 'securitytoken'];
if (in_array($input_type, $hidden_types)) {
unset($params['#type']);
unset($params['#label']);
unset($params['#help']);
unset($params['#class']);
return elgg_view("input/$input_type", $params);
}
if (!$id) {
$id = "elgg-field-" . base_convert(mt_rand(), 10, 36);
$params['id'] = $id;
}
// $vars passed to label, help and field wrapper views
$element_vars = [];
// $vars passed to input/$input_name
$make_special_checkbox_label = false;
if ($input_type == 'checkbox' && (isset($params['label']) || isset($params['#label']))) {
if (isset($params['#label']) && isset($params['label'])) {
$params['label_tag'] = 'div';
} else {
$params['#label'] = $label;
unset($params['label']);
// Single checkbox input view gets special treatment
// We don't want the field label to appear a checkbox without a label
$make_special_checkbox_label = true;
}
}
// first pass non-hash keys into both
foreach ($params as $key => $value) {
if ($key[0] !== '#') {
$element_vars[$key] = $value;
}
}
// field input view needs this
$input_vars['input_type'] = $input_type;
// field views get more data
$element_vars['input_type'] = $input_type;
unset($element_vars['class']);
if (isset($params['#class'])) {
$element_vars['class'] = $params['#class'];
}
unset($element_vars['help']);
if (isset($params['#help'])) {
$element_vars['help'] = $params['#help'];
}
unset($element_vars['label']);
if (isset($params['#label'])) {
$element_vars['label'] = $params['#label'];
}
// wrap if present
$element_vars['label'] = elgg_view('elements/forms/label', $element_vars);
$element_vars['help'] = elgg_view('elements/forms/help', $element_vars);
if ($make_special_checkbox_label) {
$input_vars['label'] = $element_vars['label'];
$input_vars['label_tag'] = 'div';
unset($element_vars['label']);
}
$element_vars['input'] = elgg_view("elements/forms/input", $input_vars);
return elgg_view('elements/forms/field', $element_vars);
}
function elgg_view_tagcloud(array $options = array()) {
$type = $subtype = '';
if (isset($options['type'])) {
$type = $options['type'];
}
if (isset($options['subtype'])) {
$subtype = $options['subtype'];
}
$tag_data = elgg_get_tags($options);
return elgg_view("output/tagcloud", array(
'value' => $tag_data,
'type' => $type,
'subtype' => $subtype,
));
}
function elgg_view_list_item($item, array $vars = array()) {
if ($item instanceof \ElggEntity) {
} else if ($item instanceof \ElggAnnotation) {
} else if ($item instanceof \ElggRiverItem) {
}
return '';
}
function elgg_view_icon($name, $vars = array()) {
if (empty($vars)) {
$vars = array();
}
if ($vars === true) {
elgg_deprecated_notice("Using a boolean to float the icon is deprecated. Use the class float.", 1.9);
$vars = array('class' => 'float');
}
if (is_string($vars)) {
$vars = array('class' => $vars);
}
if (!is_array($vars)) {
throw new \InvalidArgumentException('$vars needs to be a string or an array');
}
if (!array_key_exists('class', $vars)) {
$vars['class'] = array();
}
if (!is_array($vars['class'])) {
$vars['class'] = array($vars['class']);
}
$vars['class'][] = "elgg-icon-$name";
return elgg_view("output/icon", $vars);
}
_elgg_services()->config->set('_elgg_autofeed', true);
}
_elgg_services()->config->set('_elgg_autofeed', false);
}
function _elgg_has_rss_link() {
if (isset($GLOBALS['autofeed']) && is_bool($GLOBALS['autofeed'])) {
elgg_deprecated_notice('Do not set the global $autofeed. Use elgg_register_rss_link()', '2.1');
return $GLOBALS['autofeed'];
}
return (bool)_elgg_services()->config->getVolatile('_elgg_autofeed');
}
if ($user) {
$entities = $user->getFriends(array('limit' => 0));
} else {
$entities = array();
}
foreach ($collections as $key => $collection) {
$collections[$key]->members = get_members_of_access_collection($collection->id, true);
$collections[$key]->entities = $entities;
}
}
return elgg_view('core/friends/collections', array('collections' => $collections));
}
function autoregister_views($view_base, $folder, $ignored, $viewtype) {
return _elgg_services()->views->autoregisterViews($view_base, $folder, $viewtype);
}
if (preg_match('~[\.-]min\.~', $params['view'])) {
// bypass minification
return;
}
if ($type == 'js') {
if (elgg_get_config('simplecache_minify_js')) {
return JSMin::minify($content);
}
} elseif ($type == 'css') {
if (elgg_get_config('simplecache_minify_css')) {
$cssmin = new CSSmin();
return $cssmin->run($content);
}
}
}
function _elgg_views_amd($hook, $type, $content, $params) {
$filter = new \Elgg\Amd\ViewFilter();
return $filter->filter($params['view'], $content);
}
if (substr_count($url, '?')) {
$url .= "&view=rss";
} else {
$url .= "?view=rss";
}
elgg_register_menu_item('extras', array(
'name' => 'rss',
'text' => elgg_view_icon('rss'),
'href' => $url,
'title' => elgg_echo('feed:rss'),
));
}
}
header('X-Frame-Options: SAMEORIGIN');
}
$views = _elgg_services()->views;
if ($views->viewIsExtended($view) || $views->viewHasHookHandlers($view)) {
return true;
}
$viewtype = elgg_get_viewtype();
// check location
if (0 === strpos($path, '/') || preg_match('~^([A-Za-z]\:)?\\\\~', $path)) {
// absolute path
$expected_path = $path;
} else {
// relative path
$root = dirname(dirname(__DIR__));
$expected_path = "$root/views/$viewtype/" . ltrim($path, '/\\');
}
$view_path = $views->findViewFile($view, $viewtype);
return realpath($view_path) !== realpath($expected_path);
}
function elgg_views_boot() {
global $CONFIG;
if (!elgg_get_config('system_cache_loaded')) {
// Core view files in /views
_elgg_services()->views->registerPluginViews(realpath(__DIR__ . '/../../'));
// Core view definitions in /engine/views.php
$file = dirname(__DIR__) . '/views.php';
if (is_file($file)) {
$spec = Includer::includeFile($file);
if (is_array($spec)) {
_elgg_services()->views->mergeViewsSpec($spec);
}
}
}
// on every page
// jQuery and UI must come before require. See #9024
elgg_register_js('jquery', elgg_get_simplecache_url('jquery.js'), 'head');
elgg_load_js('jquery');
elgg_register_js('jquery-ui', elgg_get_simplecache_url('jquery-ui.js'), 'head');
elgg_load_js('jquery-ui');
elgg_register_js('elgg.require_config', elgg_get_simplecache_url('elgg/require_config.js'), 'head');
elgg_load_js('elgg.require_config');
elgg_register_js('require', elgg_get_simplecache_url('require.js'), 'head');
elgg_load_js('require');
elgg_register_js('elgg', elgg_get_simplecache_url('elgg.js'), 'head');
elgg_load_js('elgg');
elgg_register_css('font-awesome', elgg_get_simplecache_url('font-awesome/css/font-awesome.css'));
elgg_load_css('font-awesome');
elgg_load_css('elgg');
elgg_register_css('lightbox', elgg_get_simplecache_url('lightbox/elgg-colorbox-theme/colorbox.css'));
elgg_load_css('lightbox');
// provide warning to use elgg/lightbox AMD
elgg_register_js('lightbox', elgg_get_simplecache_url('lightbox.js'));
// just provides warning to use elgg/autocomplete AMD
elgg_register_js('elgg.autocomplete', elgg_normalize_url('js/lib/ui.autocomplete.js'));
elgg_define_js('jquery.ui.autocomplete.html', [
'deps' => ['jquery-ui'],
]);
elgg_register_js('elgg.friendspicker', elgg_get_simplecache_url('elgg/ui.friends_picker.js'));
elgg_register_js('elgg.avatar_cropper', elgg_get_simplecache_url('elgg/ui.avatar_cropper.js'));
// @deprecated 2.2
elgg_register_js('elgg.ui.river', elgg_get_simplecache_url('elgg/ui.river.js'));
elgg_register_js('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.js'));
elgg_register_css('jquery.imgareaselect', elgg_get_simplecache_url('jquery.imgareaselect.css'));
elgg_register_ajax_view('languages.js');
elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_amd');
elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify');
elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify');
elgg_register_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link');
elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options');
// registered with high priority for BC
// prior to 2.2 registration used to take place in _elgg_views_prepare_head() before the hook was triggered
elgg_register_plugin_hook_handler('head', 'page', '_elgg_views_prepare_favicon_links', 1);
// @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier
$view_path = _elgg_services()->views->view_path;
$viewtype_dirs = scandir($view_path);
foreach ($viewtype_dirs as $viewtype) {
if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) {
}
}
// set default icon sizes - can be overridden in settings.php or with plugin
if (!isset($CONFIG->icon_sizes)) {
$icon_sizes = array(
'topbar' => array('w' => 16, 'h' => 16, 'square' => true, 'upscale' => true),
'tiny' => array('w' => 25, 'h' => 25, 'square' => true, 'upscale' => true),
'small' => array('w' => 40, 'h' => 40, 'square' => true, 'upscale' => true),
'medium' => array('w' => 100, 'h' => 100, 'square' => true, 'upscale' => true),
'large' => array('w' => 200, 'h' => 200, 'square' => false, 'upscale' => false),
'master' => array('w' => 550, 'h' => 550, 'square' => false, 'upscale' => false),
);
elgg_set_config('icon_sizes', $icon_sizes);
}
// Patches and features that were included between major releases
// sometimes require additional styling, but adding them to core CSS files
// is not always feasible, because those can be replaced by themes.
// @todo Remove in 3.0
elgg_extend_view('elgg.css', 'elements/pathces.css');
elgg_extend_view('admin.css', 'elements/pathces.css');
}
global $CONFIG;
static $allow_delay_pagesetup = true;
if (isset($GLOBALS['_ELGG']->pagesetupdone) || empty($CONFIG->boot_complete)) {
return;
}
// only first rendering gets an opportunity to delay
$allow_delay = $allow_delay_pagesetup;
$allow_delay_pagesetup = false;
if ($allow_delay && (0 === strpos($view, 'resources/'))) {
return;
}
$GLOBALS['_ELGG']->pagesetupdone = true;
// don't call this anymore
_elgg_services()->hooks->unregisterHandler('view_vars', 'all', '_elgg_manage_pagesetup');
_elgg_services()->events->trigger('pagesetup', 'system');
}
$language = elgg_get_config('language');
if (!$language) {
$language = 'en';
}
return [
'elgg.data' => (object)elgg_trigger_plugin_hook('elgg.data', 'site', null, []),
'elgg.version' => elgg_get_version(),
'elgg.release' => elgg_get_version(true),
'elgg.config.wwwroot' => elgg_get_site_url(),
// refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
'elgg.security.interval' => (int)_elgg_services()->actions->getActionTokenTimeout() * 333,
'elgg.config.language' => $language,
];
}
$data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []);
if (!is_array($data)) {
elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR');
$data = [];
}
$elgg = array(
'config' => array(
'lastcache' => (int) elgg_get_config('lastcache'),
'viewtype' => elgg_get_viewtype(),
'simplecache_enabled' => (int) elgg_is_simplecache_enabled(),
),
'security' => array(
'token' => array(
'__elgg_ts' => $ts = time(),
'__elgg_token' => generate_action_token($ts),
),
),
'session' => array(
'user' => null,
'token' => _elgg_services()->session->get('__elgg_session'),
),
'_data' => (object) $data,
);
if (elgg_get_config('elgg_load_sync_code')) {
$elgg['config']['load_sync_code'] = true;
}
if ($page_owner instanceof ElggEntity) {
$elgg['page_owner'] = $page_owner->toObject();
}
if ($user instanceof ElggUser) {
$user_object = $user->toObject();
$user_object->admin = $user->isAdmin();
$elgg['session']['user'] = $user_object;
}
return $elgg;
}
function _elgg_view_under_viewtype($view, $vars, $viewtype) {
if ($viewtype) {
elgg_set_viewtype($viewtype);
}
$ret = elgg_view($view, $vars);
if ($viewtype) {
}
return $ret;
}
return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
$events->registerHandler('boot', 'system', 'elgg_views_boot');
$hooks->registerHandler('view_vars', 'all', '_elgg_manage_pagesetup', 1000);
};
$content
Set robots.txt action.
Definition: set_robots.php:6
$view
Definition: crop.php:34
if(! $collection_name) $id
Definition: add.php:17
$params
Definition: login.php:72
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
$language
Definition: useradd.php:20
$page_owner
Definition: add.php:25
$title
Definition: save.php:22
generate_action_token($timestamp)
Generate an action token.
Definition: actions.php:177
$options
Elgg admin footer.
Definition: footer.php:6
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
clearfix elgg elgg elgg elgg page header
Definition: admin.css.php:131
$defaults
$user
Definition: ban.php:13
elgg_is_simplecache_enabled()
Is simple cache enabled.
Definition: cache.php:146
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:108
elgg_get_simplecache_url($view, $subview='')
Get the URL for the cached view.
Definition: cache.php:136
$version
Allow executing scripts without $this context or local vars.
Definition: Includer.php:9
A complete menu, sorted, filtered by the "prepare" hook, and split into sections.
Definition: Menu.php:11
Linear set of menu items collected from configuration and the "register" hook.
$full_view
Elgg comment view.
Definition: comment.php:9
$owner_guid
$_ELGG view_types
A list of valid view types as discovered.
Definition: config.php:353
elgg_set_config($name, $value)
Set an Elgg configuration value.
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$menu
Definition: default.php:19
$annotation
Elgg default annotation view.
Definition: default.php:10
$text
Definition: default.php:25
$annotations
Definition: entity.php:20
$icon_sizes
Definition: default.php:18
$size
Definition: default.php:20
$path
Definition: details.php:88
$body_vars
if(!elgg_instanceof($comment, 'object', 'comment')||! $comment->canEdit()) $form_vars
$footer
Wrap form footer @uses $vars['footer'] Form footer @uses $vars['action_name'] Action name.
Definition: footer.php:8
register_error($error)
Display an error on next page load.
Definition: elgglib.php:464
elgg_define_js($name, $config)
Defines a JS lib as an AMD module.
Definition: elgglib.php:183
elgg_log($message, $level='NOTICE')
Display or log a message.
Definition: elgglib.php:1028
elgg_register_css($name, $url, $priority=null)
Register a CSS file for inclusion in the HTML head.
Definition: elgglib.php:271
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1375
elgg_load_css($name)
Load a CSS file for this page.
Definition: elgglib.php:298
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:740
elgg_register_js($name, $url, $location='head', $priority=null)
Register a JavaScript file for inclusion.
Definition: elgglib.php:155
elgg_get_version($human_readable=false)
Get the current Elgg version information.
Definition: elgglib.php:1071
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:826
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1098
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:220
forward($location="", $reason='system')
Forward to $location.
Definition: elgglib.php:94
get_members_of_access_collection($collection_id, $guids_only=false)
Get all of members of an access collection.
Definition: access.php:416
get_user_access_collections($owner_guid, $site_guid=0)
Returns an array of database row objects of the access collections owned by $owner_guid.
Definition: access.php:403
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
current_page_url()
Returns the current page's complete URL.
Definition: input.php:65
elgg_get_tags(array $options=array())
Get popular tags and their frequencies.
Definition: tags.php:78
$subtype
Definition: delete.php:28
$entity
Definition: delete.php:7
if(! $display_name) $type
Definition: delete.php:27
$object
These two snippets demonstrates triggering an event and how to register for that event.
Definition: trigger.php:7
$url
Definition: exceptions.php:24
$subject
Definition: exceptions.php:25
$input_vars
Definition: checkboxes.php:61
$value
Definition: longtext.php:42
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_view_resource($name, array $vars=[])
Render a resource view.
Definition: views.php:510
elgg_set_form_footer($footer='')
Sets form footer and defers its rendering until the form view and extensions have been rendered.
Definition: views.php:1358
elgg_view_friendly_time($time)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:1176
elgg_view_comments($entity, $add_comment=true, array $vars=array())
Returns rendered comments and a comment form for an entity.
Definition: views.php:1197
elgg_view_annotation_list($annotations, array $vars=array())
Returns a rendered list of annotations, plus pagination.
Definition: views.php:1099
elgg_get_viewtype()
Return the current view type.
Definition: views.php:95
elgg_register_viewtype_fallback($viewtype)
Register a viewtype to fall back to a default view if a view isn't found for that viewtype.
Definition: views.php:194
elgg_is_registered_viewtype($viewtype)
Checks if $viewtype is registered.
Definition: views.php:153
elgg_view_input($input_type, array $vars=array())
Renders a form field.
Definition: views.php:1385
_elgg_get_js_page_data()
Get the initial contents of "elgg" client side.
Definition: views.php:2014
_elgg_has_rss_link()
Should the RSS view of this URL be linked to?
Definition: views.php:1637
elgg_view_menu_item(\ElggMenuItem $item, array $vars=array())
Render a menu item (usually as a link)
Definition: views.php:815
elgg_list_views($viewtype='default')
List all views in a viewtype.
Definition: views.php:306
elgg_does_viewtype_fallback($viewtype)
Checks if a viewtype falls back to default.
Definition: views.php:206
elgg_unregister_ajax_view($view)
Unregister a view for ajax calls.
Definition: views.php:232
elgg_unregister_rss_link()
Remove the RSS icon link and link element from the head.
Definition: views.php:1627
elgg_register_viewtype($viewtype)
Register a viewtype.
Definition: views.php:133
elgg_view_title($title, array $vars=array())
Renders a title.
Definition: views.php:1160
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:689
_elgg_manage_pagesetup($hook, $view, $value, $params)
Handle triggering the pagesetup event at the right time.
Definition: views.php:1957
_elgg_views_amd($hook, $type, $content, $params)
Inserts module names into anonymous modules by handling the "simplecache:generate" hook.
Definition: views.php:1734
elgg_unextend_view($view, $view_extension)
Unextends a view.
Definition: views.php:393
_elgg_views_send_header_x_frame_options()
Sends X-Frame-Options header on page requests.
Definition: views.php:1769
_elgg_views_minify($hook, $type, $content, $params)
Minifies simplecache CSS and JS views by handling the "simplecache:generate" hook.
Definition: views.php:1704
elgg_set_view_location($view, $location, $viewtype='')
Set an alternative base location for a view.
Definition: views.php:278
_elgg_get_initial_viewtype()
Get the initial viewtype.
Definition: views.php:112
elgg_view_river_item($item, array $vars=array())
Renders a human-readable representation of a river item.
Definition: views.php:1265
_elgg_view_under_viewtype($view, $vars, $viewtype)
Render a view while the global viewtype is temporarily changed.
Definition: views.php:2070
elgg_view_entity_icon(\ElggEntity $entity, $size='medium', $vars=array())
View the icon of an entity.
Definition: views.php:936
elgg_view_access_collections($owner_guid)
Displays a user's access collections, using the core/friends/collections view.
Definition: views.php:1654
elgg_views_add_rss_link()
Add the RSS link to the extras when if needed.
Definition: views.php:1745
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1557
elgg_view_image_block($image, $body, $vars=array())
Wrapper function for the image block display pattern.
Definition: views.php:1229
elgg_unregister_external_view($view)
Unregister a view for ajax calls.
Definition: views.php:260
_elgg_views_prepare_favicon_links($hook, $type, $head_params, $params)
Add favicon link tags to HTML head.
Definition: views.php:611
elgg_register_ajax_view($view)
Register a view to be available for ajax calls.
Definition: views.php:221
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1424
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades.
Definition: views.php:1832
elgg_view_page($title, $body, $page_shell='default', $vars=array())
Assembles and outputs a full page.
Definition: views.php:447
elgg_view_annotation(\ElggAnnotation $annotation, array $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered annotation.
Definition: views.php:987
elgg_view_form($action, $form_vars=array(), $body_vars=array())
Definition: views.php:1345
elgg_view_entity(\ElggEntity $entity, array $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:873
elgg_get_form_footer()
Returns currently set footer, or false if not in the form rendering stack.
Definition: views.php:1366
autoregister_views($view_base, $folder, $ignored, $viewtype)
Auto-registers views from a location.
Definition: views.php:1689
_elgg_get_js_site_data()
Get the site data to be merged into "elgg" in elgg.js.
Definition: views.php:1990
global $CURRENT_SYSTEM_VIEWTYPE
The viewtype override.
Definition: views.php:59
elgg_view_icon($name, $vars=array())
View one of the icons.
Definition: views.php:1582
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype='')
Return a parsed view.
Definition: views.php:336
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:74
elgg_extend_view($view, $view_extension, $priority=501)
Extends a view with another view.
Definition: views.php:380
elgg_view_deprecated($view, array $vars, $suggestion, $version)
Display a view with a deprecation notice.
Definition: views.php:353
elgg_view_entity_annotations(\ElggEntity $entity, $full_view=true)
Display a plugin-specified rendered list of annotations for an entity.
Definition: views.php:1133
elgg_view_entity_list($entities, array $vars=array())
Returns a rendered list of entities with pagination.
Definition: views.php:1048
_elgg_is_valid_viewtype($viewtype)
Checks if $viewtype is a string suitable for use as a viewtype name.
Definition: views.php:171
elgg_prepend_css_urls($css, $path)
In CSS content, prepend a path to relative URLs.
Definition: views.php:424
_elgg_view_may_be_altered($view, $path)
Is there a chance a plugin is altering this view?
Definition: views.php:1800
elgg_view_module($type, $title, $body, array $vars=array())
Wrapper function for the module display pattern.
Definition: views.php:1250
elgg_view_exists($view, $viewtype='', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:293
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1618
elgg_get_view_extensions($view)
Get the views (and priorities) that extend a view.
Definition: views.php:407
_elgg_views_prepare_head($title)
Prepare the variables for the html head.
Definition: views.php:539
elgg_view_menu($menu, array $vars=array())
Render a menu.
Definition: views.php:775
elgg_register_external_view($view, $cacheable=false)
Registers a view as being available externally (i.e.
Definition: views.php:244
elgg_view_tagcloud(array $options=array())
Create a tagcloud for viewing.
Definition: views.php:1529
if($footer) $contents
Definition: module.php:43
elgg_register_menu_item($menu_name, $menu_item)
Register an item for an Elgg menu.
Definition: navigation.php:97
$data
Definition: opendd.php:13
elgg_format_url($url)
Handles formatting of ampersands in urls.
Definition: output.php:81
elgg_format_element($tag_name, array $attributes=array(), $text='', array $options=array())
Format an HTML element.
Definition: output.php:208
elgg_normalize_url($url)
Definition: output.php:280
if(! $vars['title'] && $vars['title'] !==false) if(isset($vars['filter_override'])) if(!isset($vars['filter']) &&elgg_is_logged_in() && $context) $filter
Definition: content.php:62
$css
Definition: maintenance.php:16
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:56
if(! $count) $offset
Definition: pagination.php:26
$collection
$action
Definition: full.php:133
$vars['entity']
if(!array_key_exists($filename, $text_files)) $file
if(! $items) $item
Definition: delete.php:17
$key
Definition: summary.php:34
$output
Definition: item.php:10
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:32
$priority
global $CONFIG
elgg subtext time
get_user($guid)
Get a user object from a GUID.
Definition: users.php:87
$image
Definition: upload.php:37
$input_type
Helper view that can be used to filter vars for all input views.
Definition: input.php:6
$messages
Definition: admin.php:27