Elgg  Version 2.2
/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.

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 = "") {
$CURRENT_SYSTEM_VIEWTYPE = $viewtype;
return true;
}
function elgg_get_viewtype() {
if (empty($CURRENT_SYSTEM_VIEWTYPE)) {
$CURRENT_SYSTEM_VIEWTYPE = _elgg_get_initial_viewtype();
}
}
$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) {
if (!isset($GLOBALS['_ELGG']->allowed_ajax_views)) {
$GLOBALS['_ELGG']->allowed_ajax_views = array();
}
$GLOBALS['_ELGG']->allowed_ajax_views[$view] = true;
if ($cacheable) {
_elgg_services()->views->registerCacheableView($view);
}
}
if (isset($GLOBALS['_ELGG']->allowed_ajax_views[$view])) {
unset($GLOBALS['_ELGG']->allowed_ajax_views[$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);
}
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()) {
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();
if (elgg_view_exists("navigation/menu/$name")) {
return elgg_view("navigation/menu/$name", $menu->getParams());
} else {
return elgg_view("navigation/menu/default", $menu->getParams());
}
}
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) {
if (elgg_view_exists($view)) {
$contents = elgg_view($view, $vars, $bypass, $debug);
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) {
if (elgg_view_exists($view)) {
$contents = elgg_view($view, $vars, $bypass, $debug);
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'] != 'list') {
return elgg_view('page/components/gallery', $vars);
} else {
return elgg_view('page/components/list', $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) {
if (elgg_view_exists($view)) {
break;
}
}
return $contents;
}
function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
$defaults = array(
'action' => $CONFIG->wwwroot . "action/$action",
'body' => elgg_view("forms/$action", $body_vars)
);
// append elgg-form class to any class options set
$form_vars['class'] = (array) elgg_extract('class', $form_vars, []);
$form_vars['class'][] = 'elgg-form-' . preg_replace('/[^a-z0-9]/i', '-', $action);
$form_vars = array_merge($defaults, $form_vars);
$form_vars['action_name'] = $action;
return elgg_view('input/form', $form_vars);
}
function elgg_view_input($input_type, array $vars = array()) {
if (!elgg_view_exists("input/$input_type")) {
return '';
}
if ($input_type == 'hidden') {
return elgg_view("input/$input_type", $vars);
}
if (!$id) {
$id = "elgg-field-" . base_convert(mt_rand(), 10, 36);
$vars['id'] = $id;
}
$vars['input_type'] = $input_type;
$label = elgg_view('elements/forms/label', $vars);
if ($input_type == 'checkbox') {
$vars['label'] = $label;
$vars['label_tag'] = 'div';
$label = false;
} else {
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,
));
}
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) {
return elgg_view_entity($item, $vars);
} else if ($item instanceof \ElggAnnotation) {
return elgg_view_annotation($item, $vars);
} else if ($item instanceof \ElggRiverItem) {
return elgg_view_river_item($item, $vars);
}
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() {
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 = (include $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 = $GLOBALS['_ELGG']->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);
}
}
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);
};