Elgg  Version 4.3
views.php
Go to the documentation of this file.
1 <?php
48 use Elgg\Menu\Menu;
50 
63 function elgg_set_viewtype($viewtype = '') {
64  return _elgg_services()->views->setViewtype($viewtype);
65 }
66 
76 function elgg_get_viewtype() {
77  return _elgg_services()->views->getViewtype();
78 }
79 
92  _elgg_services()->views->registerViewtypeFallback($viewtype);
93 }
94 
108  _elgg_services()->ajax->registerView($view);
109 }
110 
120  _elgg_services()->ajax->unregisterView($view);
121 }
122 
138  _elgg_services()->views->setViewDir($view, $location, $viewtype);
139 }
140 
152 function elgg_view_exists($view, $viewtype = '', $recurse = true) {
153  return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
154 }
155 
179 function elgg_view($view, $vars = [], $viewtype = '') {
180  if (func_num_args() == 5) {
181  elgg_log(__FUNCTION__ . ' now has only 3 arguments. Update your usage.', 'ERROR');
182  $viewtype = func_get_arg(4);
183  }
184  return _elgg_services()->views->renderView($view, $vars, $viewtype);
185 }
186 
210 function elgg_extend_view($view, $view_extension, $priority = 501) {
211  _elgg_services()->views->extendView($view, $view_extension, $priority);
212 }
213 
223 function elgg_unextend_view($view, $view_extension) {
224  return _elgg_services()->views->unextendView($view, $view_extension);
225 }
226 
238  $list = _elgg_services()->views->getViewList($view);
239  unset($list[500]);
240  return $list;
241 }
242 
262 function elgg_view_page($title, $body, $page_shell = 'default', $vars = []) {
263 
264  if (elgg_is_xhr() && get_input('_elgg_ajax_list')) {
265  // requested by ajaxed pagination
266  return is_array($body) ? elgg_extract('content', $body) : $body;
267  }
268 
269  if (is_array($body)) {
270  $vars['entity'] = elgg_extract('entity', $body, elgg_extract('entity', $vars));
271 
272  $body['title'] = elgg_extract('title', $body, $title);
273  $body = elgg_view_layout('default', $body);
274  }
275 
276  $timer = _elgg_services()->timer;
277  if (!$timer->hasEnded(['build page'])) {
278  $timer->end(['build page']);
279  }
280  $timer->begin([__FUNCTION__]);
281 
282  $params = [];
283  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
284  $params['segments'] = _elgg_services()->request->getUrlSegments();
285  array_shift($params['segments']);
286  $page_shell = elgg_trigger_plugin_hook('shell', 'page', $params, $page_shell);
287 
288 
289  $system_messages = _elgg_services()->system_messages;
290 
291  $messages = null;
292  if ($system_messages->count()) {
293  $messages = $system_messages->dumpRegister();
294 
295  if (isset($messages['error'])) {
296  // always make sure error is the first type
297  $errors = [
298  'error' => $messages['error']
299  ];
300 
301  unset($messages['error']);
302  $messages = array_merge($errors, $messages);
303  }
304  }
305 
306  $vars['title'] = $title;
307  $vars['body'] = $body;
308  $vars['sysmessages'] = $messages;
309  $vars['page_shell'] = $page_shell;
310 
311  $vars['head'] = elgg_trigger_plugin_hook('head', 'page', $vars, ['metas' => [], 'links' => []]);
312 
313  $vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars);
314 
315  $output = elgg_view("page/$page_shell", $vars);
316 
317 
318  // Allow plugins to modify the output
319  $output = elgg_trigger_plugin_hook('output', 'page', $vars, $output);
320 
321  $timer->end([__FUNCTION__]);
322  return $output;
323 }
324 
335 function elgg_view_resource($name, array $vars = []) {
336  $view = "resources/$name";
337 
338  if (elgg_view_exists($view)) {
339  return _elgg_services()->views->renderView($view, $vars);
340  }
341 
342  if (elgg_get_viewtype() !== 'default' && elgg_view_exists($view, 'default')) {
343  return _elgg_services()->views->renderView($view, $vars, 'default');
344  }
345 
346  _elgg_services()->logger->error("The view $view is missing.");
347 
348  // only works for default viewtype
349  throw new PageNotFoundException();
350 }
351 
380 function elgg_view_layout($layout_name, $vars = []) {
381  $timer = _elgg_services()->timer;
382  if (!$timer->hasEnded(['build page'])) {
383  $timer->end(['build page']);
384  }
385  $timer->begin([__FUNCTION__]);
386 
387  $vars['identifier'] = _elgg_services()->request->getFirstUrlSegment();
388  $vars['segments'] = _elgg_services()->request->getUrlSegments();
389  array_shift($vars['segments']);
390 
391  $layout_name = elgg_trigger_plugin_hook('layout', 'page', $vars, $layout_name);
392 
393  $vars['layout'] = $layout_name;
394 
395  $layout_views = [
396  "page/layouts/$layout_name",
397  "page/layouts/default",
398  ];
399 
400  $output = '';
401  foreach ($layout_views as $layout_view) {
402  if (elgg_view_exists($layout_view)) {
403  $output = elgg_view($layout_view, $vars);
404  break;
405  }
406  }
407 
408  $timer->end([__FUNCTION__]);
409  return $output;
410 }
411 
468 function elgg_view_menu($menu, array $vars = []) {
469 
470  $menu_view = elgg_extract('menu_view', $vars);
471  unset($vars['menu_view']);
472 
473  if (is_string($menu)) {
474  $menu = _elgg_services()->menus->getMenu($menu, $vars);
475  } elseif ($menu instanceof UnpreparedMenu) {
476  $menu = _elgg_services()->menus->prepareMenu($menu);
477  }
478 
479  if (!$menu instanceof Menu) {
480  throw new ElggInvalidArgumentException('$menu must be a menu name, a Menu, or UnpreparedMenu');
481  }
482 
483  $name = $menu->getName();
484  $params = $menu->getParams();
485 
486  $views = [
487  $menu_view,
488  "navigation/menu/$name",
489  'navigation/menu/default',
490  ];
491 
492  foreach ($views as $view) {
493  if (elgg_view_exists($view)) {
494  return elgg_view($view, $params);
495  }
496  }
497 }
498 
518 function elgg_view_entity(\ElggEntity $entity, array $vars = []) {
519 
520  $defaults = [
521  'full_view' => true,
522  ];
523 
524  $vars = array_merge($defaults, $vars);
525 
526  if (elgg_extract('register_rss_link', $vars, elgg_extract('full_view', $vars))) {
528  }
529 
530  $vars['entity'] = $entity;
531 
532  $entity_type = $entity->getType();
533  $entity_subtype = $entity->getSubtype();
534 
535  $entity_views = [
536  elgg_extract('item_view', $vars, ''),
537  "$entity_type/$entity_subtype",
538  "$entity_type/default",
539  ];
540 
541  $contents = '';
542  foreach ($entity_views as $view) {
543  if (elgg_view_exists($view)) {
544  $contents = elgg_view($view, $vars);
545  break;
546  }
547  }
548 
549  return $contents;
550 }
551 
567 function elgg_view_entity_icon(\ElggEntity $entity, $size = 'medium', $vars = []) {
568 
569  $vars['entity'] = $entity;
570  $vars['size'] = $size;
571 
572  $entity_type = $entity->getType();
573 
574  $subtype = $entity->getSubtype();
575 
576  $contents = '';
577  if (elgg_view_exists("icon/$entity_type/$subtype")) {
578  $contents = elgg_view("icon/$entity_type/$subtype", $vars);
579  }
580  if (empty($contents) && elgg_view_exists("icon/$entity_type/default")) {
581  $contents = elgg_view("icon/$entity_type/default", $vars);
582  }
583  if (empty($contents)) {
584  $contents = elgg_view("icon/default", $vars);
585  }
586 
587  return $contents;
588 }
589 
607  $defaults = [
608  'full_view' => true,
609  ];
610 
611  $vars = array_merge($defaults, $vars);
612  $vars['annotation'] = $annotation;
613 
614  $name = $annotation->name;
615  if (empty($name)) {
616  return false;
617  }
618 
619  $annotation_views = [
620  elgg_extract('item_view', $vars, ''),
621  "annotation/$name",
622  "annotation/default",
623  ];
624 
625  $contents = '';
626  foreach ($annotation_views as $view) {
627  if (elgg_view_exists($view)) {
628  $contents = elgg_view($view, $vars);
629  break;
630  }
631  }
632 
633  return $contents;
634 }
635 
661 function elgg_view_entity_list($entities, array $vars = []) {
662  $offset = (int) get_input('offset', 0);
663 
664  // list type can be passed as request parameter
665  $list_type = get_input('list_type', 'list');
666 
667  $defaults = [
668  'items' => $entities,
669  'list_class' => 'elgg-list-entity',
670  'full_view' => true,
671  'pagination' => true,
672  'list_type' => $list_type,
673  'offset' => $offset,
674  'limit' => null,
675  ];
676 
677  $vars = array_merge($defaults, $vars);
678 
679  if (!$vars["limit"] && !$vars["offset"]) {
680  // no need for pagination if listing is unlimited
681  $vars["pagination"] = false;
682  }
683 
684  $view = "page/components/{$vars['list_type']}";
685  if (!elgg_view_exists($view)) {
686  $view = 'page/components/list';
687  }
688 
689  return elgg_view($view, $vars);
690 }
691 
710 function elgg_view_annotation_list($annotations, array $vars = []) {
711  // list type can be passed as request parameter
712  $list_type = get_input('list_type', 'list');
713 
714  $defaults = [
715  'items' => $annotations,
716  'offset' => null,
717  'limit' => null,
718  'list_class' => 'elgg-list-annotation',
719  'full_view' => true,
720  'list_type' => $list_type,
721  'offset_key' => 'annoff',
722  ];
723 
724  $vars = array_merge($defaults, $vars);
725 
726  if (!$vars["limit"] && !$vars["offset"]) {
727  // no need for pagination if listing is unlimited
728  $vars["pagination"] = false;
729  }
730 
731  $view = "page/components/{$vars['list_type']}";
732  if (!elgg_view_exists($view)) {
733  $view = 'page/components/list';
734  }
735 
736  return elgg_view($view, $vars);
737 }
738 
757 function elgg_view_relationship_list($relationships, array $vars = []) {
758  // list type can be passed as request parameter
759  $list_type = get_input('list_type', 'list');
760 
761  $defaults = [
762  'items' => $relationships,
763  'offset' => null,
764  'limit' => null,
765  'list_class' => 'elgg-list-relationship',
766  'full_view' => false,
767  'list_type' => $list_type,
768  'offset_key' => 'reloff',
769  ];
770 
771  $vars = array_merge($defaults, $vars);
772 
773  if (!$vars['limit'] && !$vars['offset']) {
774  // no need for pagination if listing is unlimited
775  $vars['pagination'] = false;
776  }
777 
778  $view = "page/components/{$vars['list_type']}";
779  if (!elgg_view_exists($view)) {
780  $view = 'page/components/list';
781  }
782 
783  return elgg_view($view, $vars);
784 }
785 
803  $defaults = [
804  'full_view' => true,
805  ];
806 
807  $vars = array_merge($defaults, $vars);
808  $vars['relationship'] = $relationship;
809 
810  $name = $relationship->relationship;
811  if (empty($name)) {
812  return false;
813  }
814 
815  $relationship_views = [
816  elgg_extract('item_view', $vars, ''),
817  "relationship/$name",
818  "relationship/default",
819  ];
820 
821  $contents = '';
822  foreach ($relationship_views as $view) {
823  if (elgg_view_exists($view)) {
824  $contents = elgg_view($view, $vars);
825  break;
826  }
827  }
828 
829  return $contents;
830 }
831 
842 function elgg_view_title($title, array $vars = []) {
843  $vars['title'] = $title;
844 
845  return elgg_view('page/elements/title', $vars);
846 }
847 
860  $view = 'output/friendlytime';
861  $vars = [
862  'time' => $time,
863  'time_updated' => $time_updated,
864  ];
865  $viewtype = elgg_view_exists($view) ? '' : 'default';
866 
868 }
869 
883 function elgg_view_comments($entity, $add_comment = true, array $vars = []) {
884 
885  if (!$entity instanceof \ElggEntity) {
886  return false;
887  }
888 
889  if (!$entity->hasCapability('commentable')) {
890  return false;
891  }
892 
893  $vars['entity'] = $entity;
894  $vars['show_add_form'] = $add_comment;
895  $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
896 
897  $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
898  if ($output !== false) {
899  return $output;
900  }
901 
902  return elgg_view('page/elements/comments', $vars);
903 }
904 
924  $vars['image'] = $image;
925  $vars['body'] = $body;
926  return elgg_view('page/components/image_block', $vars);
927 }
928 
944 function elgg_view_module($type, $title, $body, array $vars = []) {
945  $vars['type'] = $type;
946  $vars['title'] = $title;
947  $vars['body'] = $body;
948  return elgg_view('page/components/module', $vars);
949 }
950 
965 function elgg_view_message($type, $body, array $vars = []) {
966  $vars['type'] = $type;
967  $vars['body'] = $body;
968  return elgg_view('page/components/message', $vars);
969 }
970 
980 function elgg_view_river_item($item, array $vars = []) {
981 
982  if (!($item instanceof \ElggRiverItem)) {
983  return '';
984  }
985 
986  // checking default viewtype since some viewtypes do not have unique views per item (rss)
987  $view = $item->getView();
988 
989  $subject = $item->getSubjectEntity();
990  $object = $item->getObjectEntity();
991  if (!$subject || !$object) {
992  // subject is disabled or subject/object deleted
993  return '';
994  }
995 
996  if (elgg_extract('register_rss_link', $vars)) {
998  }
999 
1000  $vars['item'] = $item;
1001 
1002  // create river view logic
1003  $type = $object->getType();
1004  $subtype = $object->getSubtype();
1005  $action = $item->action_type;
1006 
1007  $river_views = [
1008  elgg_extract('item_view', $vars, ''),
1009  'river/item', // important for other viewtypes, e.g. "rss"
1010  $view,
1011  "river/{$type}/{$subtype}/{$action}",
1012  "river/{$type}/{$subtype}/default",
1013  "river/{$type}/{$action}",
1014  "river/{$type}/default",
1015  'river/elements/layout',
1016  ];
1017 
1018  $contents = '';
1019  foreach ($river_views as $view) {
1020  if (elgg_view_exists($view)) {
1021  $contents = elgg_view($view, $vars);
1022  break;
1023  }
1024  }
1025 
1026  return $contents;
1027 }
1028 
1065  return _elgg_services()->forms->render($action, $form_vars, $body_vars);
1066 }
1067 
1078  return _elgg_services()->forms->setFooter($footer);
1079 }
1080 
1086  return _elgg_services()->forms->getFooter();
1087 }
1088 
1100 function _elgg_split_vars(array $vars = [], array $prefixes = null) {
1101 
1102  if (!isset($prefixes)) {
1103  $prefixes = ['#'];
1104  }
1105 
1106  $return = [];
1107  $default_section = ''; // something weird with PHP 8.1 compatibility
1108 
1109  foreach ($vars as $key => $value) {
1110  foreach ($prefixes as $prefix) {
1111  if (substr($key, 0, 1) === $prefix) {
1112  $key = substr($key, 1);
1113  $return[$prefix][$key] = $value;
1114  break;
1115  } else {
1116  $return[$default_section][$key] = $value;
1117  }
1118  }
1119  }
1120 
1121  return $return;
1122 }
1123 
1143 function elgg_view_field(array $params = []) {
1144 
1145  if (!empty($params['#html'])) {
1146  return $params['#html'];
1147  }
1148 
1149  if (empty($params['#type'])) {
1150  _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.');
1151  return '';
1152  }
1153 
1154  $input_type = $params['#type'];
1155  if (!elgg_view_exists("input/$input_type")) {
1156  return '';
1157  }
1158 
1159  $hidden_types = ['hidden', 'securitytoken'];
1160  if (in_array($input_type, $hidden_types)) {
1162  return elgg_view("input/$input_type", $params['']);
1163  }
1164 
1165  $id = elgg_extract('id', $params);
1166  if (!$id) {
1167  $id = "elgg-field-" . base_convert(mt_rand(), 10, 36);
1168  $params['id'] = $id;
1169  }
1170 
1171  $make_special_checkbox_label = false;
1172  if ($input_type == 'checkbox' && (isset($params['label']) || isset($params['#label']))) {
1173  if (isset($params['#label']) && isset($params['label'])) {
1174  $params['label_tag'] = 'div';
1175  } else {
1176  $label = elgg_extract('label', $params);
1177  $label = elgg_extract('#label', $params, $label);
1178 
1179  $params['#label'] = $label;
1180  unset($params['label']);
1181 
1182  // Single checkbox input view gets special treatment
1183  // We don't want the field label to appear a checkbox without a label
1184  $make_special_checkbox_label = true;
1185  }
1186  }
1187 
1188  // Need to set defaults to prevent input keys with same name ending up in element vars if not provided
1189  $defaults = [
1190  '#class' => ELGG_ENTITIES_ANY_VALUE,
1191  '#help' => ELGG_ENTITIES_ANY_VALUE,
1192  '#label' => ELGG_ENTITIES_ANY_VALUE,
1193  '#view' => ELGG_ENTITIES_ANY_VALUE,
1194  ];
1195  $params = array_merge($defaults, $params);
1196 
1197  // first pass non-hash keys into both
1198  $split_params = _elgg_split_vars($params);
1199 
1200  // $vars passed to input/$input_name
1201  $input_vars = $split_params[''];
1202 
1203  // $vars passed to label, help and field wrapper views
1204  $element_vars = array_merge($split_params[''], $split_params['#']);
1205 
1206  // field input view needs this
1207  $input_vars['input_type'] = $input_type;
1208 
1209  // field views get more data
1210  $element_vars['input_type'] = $input_type;
1211 
1212  // wrap if present
1213  $element_vars['label'] = elgg_view('elements/forms/label', $element_vars);
1214  $element_vars['help'] = elgg_view('elements/forms/help', $element_vars);
1215 
1216  if ($make_special_checkbox_label) {
1217  $input_vars['label'] = $element_vars['label'];
1218  $input_vars['label_tag'] = 'div';
1219  unset($element_vars['label']);
1220  }
1221  $element_vars['input'] = elgg_view("elements/forms/input", $input_vars);
1222 
1223  return elgg_view('elements/forms/field', $element_vars);
1224 }
1225 
1238 function elgg_view_tagcloud(array $options = []) {
1239 
1240  $type = $subtype = '';
1241  if (isset($options['type'])) {
1242  $type = $options['type'];
1243  }
1244  if (isset($options['subtype'])) {
1245  $subtype = $options['subtype'];
1246  }
1247 
1248  $tag_data = elgg_get_tags($options);
1249  return elgg_view("output/tagcloud", [
1250  'value' => $tag_data,
1251  'type' => $type,
1252  'subtype' => $subtype,
1253  ]);
1254 }
1255 
1266 function elgg_view_list_item($item, array $vars = []) {
1267 
1268  if ($item instanceof \ElggEntity) {
1269  return elgg_view_entity($item, $vars);
1270  } else if ($item instanceof \ElggAnnotation) {
1271  return elgg_view_annotation($item, $vars);
1272  } else if ($item instanceof \ElggRiverItem) {
1273  return elgg_view_river_item($item, $vars);
1274  } else if ($item instanceof ElggRelationship) {
1276  }
1277 
1278  $view = elgg_extract('item_view', $vars);
1279  if ($view && elgg_view_exists($view)) {
1280  $vars['item'] = $item;
1281  return elgg_view($view, $vars);
1282  }
1283 
1284  return '';
1285 }
1286 
1297 function elgg_view_icon($name, $vars = []) {
1298  if (empty($vars)) {
1299  $vars = [];
1300  }
1301 
1302  if (is_string($vars)) {
1303  $vars = ['class' => $vars];
1304  }
1305 
1306  if (!is_array($vars)) {
1307  throw new ElggInvalidArgumentException('$vars needs to be a string or an array');
1308  }
1309 
1310  $vars['class'] = elgg_extract_class($vars, "elgg-icon-$name");
1311 
1312  return elgg_view('output/icon', $vars);
1313 }
1314 
1321  _elgg_services()->config->_elgg_autofeed = true;
1322 }
1323 
1330  _elgg_services()->config->_elgg_autofeed = false;
1331 }
1332 
1340  if (_elgg_services()->config->disable_rss) {
1341  return false;
1342  }
1343 
1344  return (bool) _elgg_services()->config->_elgg_autofeed;
1345 }
1346 
1355 function elgg_views_boot() {
1356  _elgg_services()->viewCacher->registerCoreViews();
1357 
1358  // jQuery and UI must come before require. See #9024
1359  elgg_register_external_file('js', 'jquery', elgg_get_simplecache_url('jquery.js'));
1360  elgg_load_external_file('js', 'jquery');
1361 
1362  elgg_extend_view('require.js', 'elgg/require_config.js', 100);
1363 
1364  elgg_register_external_file('js', 'require', elgg_get_simplecache_url('require.js'));
1365  elgg_load_external_file('js', 'require');
1366 
1367  elgg_register_external_file('js', 'elgg', elgg_get_simplecache_url('elgg.js'));
1368  elgg_load_external_file('js', 'elgg');
1369 
1370  elgg_register_external_file('css', 'font-awesome', elgg_get_simplecache_url('font-awesome/css/all.min.css'));
1371  elgg_load_external_file('css', 'font-awesome');
1372 
1373  elgg_define_js('cropperjs', [
1374  'src' => elgg_get_simplecache_url('cropperjs/cropper.min.js'),
1375  ]);
1376  elgg_define_js('jquery-cropper/jquery-cropper', [
1377  'src' => elgg_get_simplecache_url('jquery-cropper/jquery-cropper.min.js'),
1378  ]);
1379 
1380  elgg_require_css('elgg');
1381 
1382  elgg_extend_view('initialize_elgg.js', 'elgg/prevent_clicks.js', 1);
1383 
1384  elgg_extend_view('elgg.css', 'lightbox/elgg-colorbox-theme/colorbox.css');
1385  elgg_extend_view('elgg.css', 'entity/edit/icon/crop.css');
1386 
1387  elgg_define_js('jquery.ui.autocomplete.html', [
1388  'deps' => ['jquery-ui/widgets/autocomplete'],
1389  ]);
1390 
1391  elgg_register_simplecache_view('elgg/touch_punch.js');
1392  elgg_define_js('jquery-ui/widgets/sortable', [
1393  'deps' => ['elgg/touch_punch'],
1394  ]);
1395 
1396  elgg_register_ajax_view('languages.js');
1397 }
1398 
1408 
1409  $message_delay = (int) elgg_get_config('message_delay');
1410  if ($message_delay < 1) {
1411  $message_delay = 6;
1412  }
1413 
1414  return [
1415  'elgg.data' => (object) elgg_trigger_plugin_hook('elgg.data', 'site', null, []),
1416  'elgg.release' => elgg_get_release(),
1417  'elgg.config.wwwroot' => elgg_get_site_url(),
1418  'elgg.config.message_delay' => $message_delay * 1000,
1419 
1420  // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
1421  'elgg.security.interval' => (int) _elgg_services()->csrf->getActionTokenTimeout() * 333,
1422  'elgg.config.language' => _elgg_services()->config->language ?: 'en',
1423  ];
1424 }
1425 
1433  $data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []);
1434  if (!is_array($data)) {
1435  elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR');
1436  $data = [];
1437  }
1438 
1439  $elgg = [
1440  'config' => [
1441  'lastcache' => (int) _elgg_services()->config->lastcache,
1442  'viewtype' => elgg_get_viewtype(),
1443  'simplecache_enabled' => (int) elgg_is_simplecache_enabled(),
1444  'current_language' => elgg_get_current_language(),
1445  ],
1446  'security' => [
1447  'token' => [
1448  '__elgg_ts' => $ts = _elgg_services()->csrf->getCurrentTime()->getTimestamp(),
1449  '__elgg_token' => _elgg_services()->csrf->generateActionToken($ts),
1450  ],
1451  ],
1452  'session' => [
1453  'user' => null,
1454  'token' => _elgg_services()->session->get('__elgg_session'),
1455  ],
1456  '_data' => (object) $data,
1457  ];
1458 
1460  if ($page_owner instanceof ElggEntity) {
1461  $elgg['page_owner'] = $page_owner->toObject(); // @todo remove in Elgg 5.0
1462  }
1463 
1465  if ($user instanceof ElggUser) {
1466  $user_object = $user->toObject();
1467  $user_object->admin = $user->isAdmin();
1468  $elgg['session']['user'] = $user_object; // @todo remove in Elgg 5.0
1469 
1470  $elgg['user'] = (array) $user_object;
1471  }
1472 
1473  return $elgg;
1474 }
1475 
1488  $current_view_type = null;
1489  if ($viewtype) {
1490  $current_view_type = elgg_get_viewtype();
1492  }
1493 
1494  $ret = elgg_view($view, $vars);
1495 
1496  if (isset($current_view_type)) {
1497  elgg_set_viewtype($current_view_type);
1498  }
1499 
1500  return $ret;
1501 }
1502 
1513 function elgg_view_url(string $href, string $text = null, array $options = []): string {
1514  $options['is_trusted'] = elgg_extract('is_trusted', $options, true);
1515  $options['href'] = $href;
1516  $options['text'] = $text;
1517 
1518  return elgg_view('output/url', $options);
1519 }
1520 
1530 function elgg_view_entity_url(\ElggEntity $entity, array $options = []): string {
1531  return elgg_view_url($entity->getURL(), $entity->getDisplayName(), $options);
1532 }
elgg_get_current_language()
Get the current system/user language or "en".
Definition: languages.php:29
if(!$items) $item
Definition: delete.php:13
$messages
Definition: admin.php:12
if(!elgg_view_exists("plugins/{$plugin_id}/settings")) $form_vars
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:152
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades...
Definition: views.php:1355
getSubtype()
Get the entity subtype.
elgg_get_release()
Get the current Elgg release.
elgg_get_view_extensions($view)
Get the views (and priorities) that extend a view.
Definition: views.php:237
if(empty($plugins)) $errors
elgg_unregister_ajax_view($view)
Unregister a view for ajax calls.
Definition: views.php:119
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
elgg_require_css(string $view)
Register a CSS view name to be included in the HTML head.
$params
Saves global plugin settings.
Definition: save.php:13
elgg_view_field(array $params=[])
Renders a form field, usually with a wrapper element, a label, help text, etc.
Definition: views.php:1143
elgg_view_entity_list($entities, array $vars=[])
Returns a rendered list of entities with pagination.
Definition: views.php:661
$footer
Wrap form footer.
Definition: footer.php:11
if($id< 1) $annotation
Definition: delete.php:11
elgg_view_resource($name, array $vars=[])
Render a resource view.
Definition: views.php:335
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
$defaults
$title
Definition: generic.php:50
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:111
elgg_get_simplecache_url($view, $subview= '')
Get the URL for the cached view.
Definition: cache.php:139
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
Definition: LICENSE.txt:215
elgg_view_relationship_list($relationships, array $vars=[])
Returns a rendered list of relationships, plus pagination.
Definition: views.php:757
$relationship
Elgg default relationship view.
Definition: default.php:10
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
if(elgg_trigger_plugin_hook('usersettings:save', 'user', $hooks_params, true)) foreach($request->validation() ->all() as $item) $data
Definition: save.php:53
if($vars['name']&&$vars['default']!==false) $input_vars
Definition: checkboxes.php:89
if(!$count) $offset
Definition: pagination.php:26
$menu
Admin sidebar – just outputs the page menus.
Definition: sidebar.php:6
$time_updated
Definition: time.php:21
$type
Definition: delete.php:21
elgg_view_tagcloud(array $options=[])
Create a tagcloud for viewing.
Definition: views.php:1238
elgg_register_viewtype_fallback($viewtype)
Register a viewtype to fall back to a default view if a view isn&#39;t found for that viewtype...
Definition: views.php:91
elgg_register_external_file(string $type, string $name, string $url, string $location= '')
Core registration function for external files.
_elgg_get_js_site_data()
Get the site data to be merged into "elgg" in elgg.js.
Definition: views.php:1407
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:569
elgg_set_form_footer($footer= '')
Sets form footer and defers its rendering until the form view and extensions have been rendered...
Definition: views.php:1077
$options
Elgg admin footer.
Definition: footer.php:6
elgg_view_entity_icon(\ElggEntity $entity, $size= 'medium', $vars=[])
View the icon of an entity.
Definition: views.php:567
elgg_view_page($title, $body, $page_shell= 'default', $vars=[])
Assembles and outputs a full page.
Definition: views.php:262
$value
Definition: generic.php:51
elgg_get_viewtype()
Return the current view type.
Definition: views.php:76
elgg_view_image_block($image, $body, $vars=[])
Wrapper function for the image block display pattern.
Definition: views.php:923
_elgg_has_rss_link()
Should the RSS view of this URL be linked to?
Definition: views.php:1339
elgg_view_menu($menu, array $vars=[])
Render a menu.
Definition: views.php:468
Linear set of menu items collected from configuration and the "register" hook.
_elgg_get_js_page_data()
Get the initial contents of "elgg" client side.
Definition: views.php:1432
Thrown when page is not accessible.
$input_type
Helper view that can be used to filter vars for all input views.
Definition: input.php:6
elgg_view_message($type, $body, array $vars=[])
Wrapper function for the message display pattern.
Definition: views.php:965
elgg_view_list_item($item, array $vars=[])
View an item in a list.
Definition: views.php:1266
$entity
Definition: reset.php:8
elgg_set_view_location($view, $location, $viewtype= '')
Set an alternative base location for a view.
Definition: views.php:137
elgg_view_river_item($item, array $vars=[])
Renders a human-readable representation of a river item.
Definition: views.php:980
if(!empty($avatar)&&!$avatar->isValid()) elseif(empty($avatar)) if(!$owner->saveIconFromUploadedFile('avatar')) if(!elgg_trigger_event('profileiconupdate', $owner->type, $owner)) $view
Definition: upload.php:39
elgg_view_form($action, $form_vars=[], $body_vars=[])
Definition: views.php:1064
get_input($variable, $default=null, $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:399
elgg_view_relationship(\ElggRelationship $relationship, array $vars=[])
Returns a string of a rendered relationship.
Definition: views.php:802
elgg_view_entity(\ElggEntity $entity, array $vars=[])
Returns a string of a rendered entity.
Definition: views.php:518
elgg_view_module($type, $title, $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:944
$user
Definition: ban.php:7
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:380
$image
Definition: image_block.php:25
elgg_load_external_file(string $type, string $name)
Load an external resource for use on this page.
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:23
$viewtype
Definition: default.php:11
$timer
Definition: pending.php:29
elgg_register_ajax_view($view)
Register a view to be available for ajax calls.
Definition: views.php:107
const ELGG_ENTITIES_ANY_VALUE
Definition: constants.php:24
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
$body
Definition: useradd.php:59
$page_owner
Definition: add.php:15
elgg_extend_view($view, $view_extension, $priority=501)
Extends a view with another view.
Definition: views.php:210
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:547
$size
Definition: thumb.php:23
$action
Definition: subscribe.php:11
if($container instanceof ElggGroup &&$container->guid!=elgg_get_page_owner_guid()) $key
Definition: summary.php:44
elgg_view_friendly_time($time, $time_updated=null)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:859
elgg_view_annotation_list($annotations, array $vars=[])
Returns a rendered list of annotations, plus pagination.
Definition: views.php:710
elgg_get_tags(array $options=[])
Get popular tags and their frequencies.
Definition: metadata.php:66
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
$ts
CSRF security token view for use with secure forms.
$location
Definition: member.php:29
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
Definition: views.php:1513
elgg_view_layout($layout_name, $vars=[])
Displays a layout with optional parameters.
Definition: views.php:380
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
elgg_is_simplecache_enabled()
Is simple cache enabled.
Definition: cache.php:149
getType()
Returns the entity type.
$subtype
Definition: delete.php:22
elgg_view_icon($name, $vars=[])
View an icon glyph.
Definition: views.php:1297
_elgg_services()
Get the global service provider.
Definition: elgglib.php:638
elgg_set_viewtype($viewtype= '')
Manually set the viewtype.
Definition: views.php:63
$vars['head']
Definition: html.php:24
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
Definition: sessions.php:24
elgg_view_annotation(\ElggAnnotation $annotation, array $vars=[])
Returns a string of a rendered annotation.
Definition: views.php:606
elgg_unregister_rss_link()
Remove the RSS icon link and link element from the head.
Definition: views.php:1329
_elgg_view_under_viewtype($view, $vars, $viewtype)
Render a view while the global viewtype is temporarily changed.
Definition: views.php:1487
$text
Definition: button.php:32
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:76
if(!($comment instanceof ElggComment)||!$comment->canEdit()) $body_vars
$id
Generic annotation delete action.
Definition: delete.php:6
$output
Definition: download.php:9
elgg_view($view, $vars=[], $viewtype= '')
Return a parsed view.
Definition: views.php:179
_elgg_split_vars(array $vars=[], array $prefixes=null)
Split array of vars into subarrays based on property prefixes.
Definition: views.php:1100
if(!empty($title)&&!empty($icon_name)) if(!empty($title)) if(!empty($menu)) if(!empty($header)) if(!empty($body)) $contents
Definition: message.php:73
getURL()
Gets the URL for this entity.
$menu_view
Definition: default.php:31
$subject
Definition: useradd.php:58
elgg_define_js($name, $config)
Helper functions for external files like css/js.
elgg_view_title($title, array $vars=[])
Renders a title.
Definition: views.php:842
$priority
elgg_view_entity_url(\ElggEntity $entity, array $options=[])
Helper function for outputting a link to an entity.
Definition: views.php:1530
$views
Definition: item.php:17
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:318
elgg_get_config($name, $default=null)
Get an Elgg configuration value.
A complete menu, sorted, filtered by the "prepare" hook, and split into sections. ...
Definition: Menu.php:10
elgg_view_comments($entity, $add_comment=true, array $vars=[])
Returns rendered comments and a comment form for an entity.
Definition: views.php:883
elgg_get_form_footer()
Returns currently set footer, or false if not in the form rendering stack.
Definition: views.php:1085
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1320
elgg_unextend_view($view, $view_extension)
Unextends a view.
Definition: views.php:223