Elgg  Version 6.1
views.php
Go to the documentation of this file.
1 <?php
45 use Elgg\Menu\Menu;
47 
60 function elgg_set_viewtype(string $viewtype = ''): bool {
61  return _elgg_services()->views->setViewtype($viewtype);
62 }
63 
73 function elgg_get_viewtype(): string {
74  return _elgg_services()->views->getViewtype();
75 }
76 
89  _elgg_services()->views->registerViewtypeFallback($viewtype);
90 }
91 
104 function elgg_register_ajax_view(string $view): void {
105  _elgg_services()->ajax->registerView($view);
106 }
107 
117  _elgg_services()->ajax->unregisterView($view);
118 }
119 
131 function elgg_view_exists(string $view, string $viewtype = '', bool $recurse = true): bool {
132  return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
133 }
134 
156 function elgg_view(string $view, array $vars = [], string $viewtype = ''): string {
157  return _elgg_services()->views->renderView($view, $vars, $viewtype);
158 }
159 
183 function elgg_extend_view(string $view, string $view_extension, int $priority = 501): void {
184  _elgg_services()->views->extendView($view, $view_extension, $priority);
185 }
186 
196 function elgg_unextend_view(string $view, string $view_extension): bool {
197  return _elgg_services()->views->unextendView($view, $view_extension);
198 }
199 
210 function elgg_get_view_extensions(string $view): array {
211  $list = _elgg_services()->views->getViewList($view);
212  unset($list[500]);
213  return $list;
214 }
215 
235 function elgg_view_page(string $title, string|array $body, string $page_shell = 'default', array $vars = []): string {
236 
237  if (elgg_is_xhr() && get_input('_elgg_ajax_list')) {
238  // requested by ajaxed pagination
239  return is_array($body) ? (string) elgg_extract('content', $body) : $body;
240  }
241 
242  if (is_array($body)) {
243  $vars['entity'] = elgg_extract('entity', $body, elgg_extract('entity', $vars));
244 
245  $body['title'] = elgg_extract('title', $body, $title);
246  $body = elgg_view_layout('default', $body);
247  }
248 
249  $timer = _elgg_services()->timer;
250  if (!$timer->hasEnded(['build page'])) {
251  $timer->end(['build page']);
252  }
253 
254  $timer->begin([__FUNCTION__]);
255 
256  $params = [];
257  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
258  $params['segments'] = _elgg_services()->request->getUrlSegments();
259  array_shift($params['segments']);
260  $page_shell = elgg_trigger_event_results('shell', 'page', $params, $page_shell);
261 
262  $system_messages = _elgg_services()->system_messages;
263 
264  $messages = null;
265  if ($system_messages->count()) {
266  $messages = $system_messages->dumpRegister();
267 
268  if (isset($messages['error'])) {
269  // always make sure error is the first type
270  $errors = [
271  'error' => $messages['error']
272  ];
273 
274  unset($messages['error']);
275  $messages = array_merge($errors, $messages);
276  }
277  }
278 
279  $vars['title'] = $title;
280  $vars['body'] = $body;
281  $vars['sysmessages'] = $messages;
282  $vars['page_shell'] = $page_shell;
283 
284  $vars['head'] = elgg_trigger_event_results('head', 'page', $vars, ['metas' => [], 'links' => []]);
285 
286  $vars = elgg_trigger_event_results('output:before', 'page', [], $vars);
287 
288  $output = elgg_view("page/{$page_shell}", $vars);
289 
290  // Allow plugins to modify the output
291  $output = elgg_trigger_event_results('output', 'page', $vars, $output);
292 
293  $timer->end([__FUNCTION__]);
294  return $output;
295 }
296 
307 function elgg_view_resource(string $name, array $vars = []): string {
308  $view = "resources/{$name}";
309 
310  if (elgg_view_exists($view)) {
311  return _elgg_services()->views->renderView($view, $vars);
312  }
313 
314  if (elgg_get_viewtype() !== 'default' && elgg_view_exists($view, 'default')) {
315  return _elgg_services()->views->renderView($view, $vars, 'default');
316  }
317 
318  _elgg_services()->logger->error("The view {$view} is missing.");
319 
320  // only works for default viewtype
321  throw new PageNotFoundException();
322 }
323 
352 function elgg_view_layout(string $layout_name, array $vars = []): string {
353  $timer = _elgg_services()->timer;
354  if (!$timer->hasEnded(['build page'])) {
355  $timer->end(['build page']);
356  }
357 
358  $timer->begin([__FUNCTION__]);
359 
360  $vars['identifier'] = _elgg_services()->request->getFirstUrlSegment();
361  $vars['segments'] = _elgg_services()->request->getUrlSegments();
362  array_shift($vars['segments']);
363 
364  $layout_name = elgg_trigger_event_results('layout', 'page', $vars, $layout_name);
365 
366  $vars['layout'] = $layout_name;
367 
368  $layout_views = [
369  "page/layouts/{$layout_name}",
370  'page/layouts/default',
371  ];
372 
373  $output = '';
374  foreach ($layout_views as $layout_view) {
375  if (elgg_view_exists($layout_view)) {
376  $output = elgg_view($layout_view, $vars);
377  break;
378  }
379  }
380 
381  $timer->end([__FUNCTION__]);
382  return $output;
383 }
384 
441 function elgg_view_menu($menu, array $vars = []): string {
442 
443  $menu_view = (string) elgg_extract('menu_view', $vars);
444  unset($vars['menu_view']);
445 
446  if (is_string($menu)) {
447  $menu = _elgg_services()->menus->getMenu($menu, $vars);
448  } elseif ($menu instanceof UnpreparedMenu) {
449  $menu = _elgg_services()->menus->prepareMenu($menu);
450  }
451 
452  if (!$menu instanceof Menu) {
453  throw new ElggInvalidArgumentException('$menu must be a menu name, a Menu, or UnpreparedMenu');
454  }
455 
456  $name = $menu->getName();
457  $params = $menu->getParams();
458 
459  $views = [
460  $menu_view,
461  "navigation/menu/{$name}",
462  'navigation/menu/default',
463  ];
464 
465  foreach ($views as $view) {
466  if (elgg_view_exists($view)) {
467  return elgg_view($view, $params);
468  }
469  }
470 
471  return '';
472 }
473 
493 function elgg_view_entity(\ElggEntity $entity, array $vars = []): string {
494 
495  $defaults = [
496  'full_view' => true,
497  ];
498 
499  $vars = array_merge($defaults, $vars);
500 
501  if (elgg_extract('register_rss_link', $vars, elgg_extract('full_view', $vars))) {
503  }
504 
505  $vars['entity'] = $entity;
506 
507  $entity_type = $entity->getType();
508  $entity_subtype = $entity->getSubtype();
509 
510  $entity_views = [
511  (string) elgg_extract('item_view', $vars, ''),
512  "{$entity_type}/{$entity_subtype}",
513  "{$entity_type}/default",
514  ];
515 
516  $contents = '';
517  foreach ($entity_views as $view) {
518  if (elgg_view_exists($view)) {
519  $contents = elgg_view($view, $vars);
520  break;
521  }
522  }
523 
524  return $contents;
525 }
526 
542 function elgg_view_entity_icon(\ElggEntity $entity, string $size = 'medium', array $vars = []): string {
543 
544  $vars['entity'] = $entity;
545  $vars['size'] = $size;
546 
547  $entity_type = $entity->getType();
548 
549  $subtype = $entity->getSubtype();
550 
551  $contents = '';
552  if (elgg_view_exists("icon/{$entity_type}/{$subtype}")) {
553  $contents = elgg_view("icon/{$entity_type}/{$subtype}", $vars);
554  }
555 
556  if (empty($contents) && elgg_view_exists("icon/{$entity_type}/default")) {
557  $contents = elgg_view("icon/{$entity_type}/default", $vars);
558  }
559 
560  if (empty($contents)) {
561  $contents = elgg_view('icon/default', $vars);
562  }
563 
564  return $contents;
565 }
566 
583 function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = []): string {
584  $defaults = [
585  'full_view' => true,
586  ];
587 
588  $vars = array_merge($defaults, $vars);
589  $vars['annotation'] = $annotation;
590 
591  $name = $annotation->name;
592  if (empty($name)) {
593  return '';
594  }
595 
596  $annotation_views = [
597  (string) elgg_extract('item_view', $vars, ''),
598  "annotation/{$name}",
599  'annotation/default',
600  ];
601 
602  foreach ($annotation_views as $view) {
603  if (elgg_view_exists($view)) {
604  return elgg_view($view, $vars);
605  }
606  }
607 
608  return '';
609 }
610 
636 function elgg_view_entity_list(array $entities, array $vars = []): string {
637  $offset = (int) get_input('offset', 0);
638 
639  // list type can be passed as request parameter
640  $list_type = get_input('list_type', 'list');
641 
642  $defaults = [
643  'items' => $entities,
644  'list_class' => 'elgg-list-entity',
645  'full_view' => true,
646  'pagination' => true,
647  'list_type' => $list_type,
648  'offset' => $offset,
649  'limit' => null,
650  ];
651 
652  $vars = array_merge($defaults, $vars);
653 
654  if (!$vars['limit'] && !$vars['offset']) {
655  // no need for pagination if listing is unlimited
656  $vars['pagination'] = false;
657  }
658 
659  $view = "page/components/{$vars['list_type']}";
660  if (!elgg_view_exists($view)) {
661  $view = 'page/components/list';
662  }
663 
664  return elgg_view($view, $vars);
665 }
666 
685 function elgg_view_annotation_list(array $annotations, array $vars = []): string {
686  // list type can be passed as request parameter
687  $list_type = get_input('list_type', 'list');
688 
689  $defaults = [
690  'items' => $annotations,
691  'offset' => null,
692  'limit' => null,
693  'list_class' => 'elgg-list-annotation',
694  'full_view' => true,
695  'list_type' => $list_type,
696  'offset_key' => 'annoff',
697  ];
698 
699  $vars = array_merge($defaults, $vars);
700 
701  if (!$vars['limit'] && !$vars['offset']) {
702  // no need for pagination if listing is unlimited
703  $vars['pagination'] = false;
704  }
705 
706  $view = "page/components/{$vars['list_type']}";
707  if (!elgg_view_exists($view)) {
708  $view = 'page/components/list';
709  }
710 
711  return elgg_view($view, $vars);
712 }
713 
732 function elgg_view_relationship_list(array $relationships, array $vars = []): string {
733  // list type can be passed as request parameter
734  $list_type = get_input('list_type', 'list');
735 
736  $defaults = [
737  'items' => $relationships,
738  'offset' => null,
739  'limit' => null,
740  'list_class' => 'elgg-list-relationship',
741  'full_view' => false,
742  'list_type' => $list_type,
743  'offset_key' => 'reloff',
744  ];
745 
746  $vars = array_merge($defaults, $vars);
747 
748  if (!$vars['limit'] && !$vars['offset']) {
749  // no need for pagination if listing is unlimited
750  $vars['pagination'] = false;
751  }
752 
753  $view = "page/components/{$vars['list_type']}";
754  if (!elgg_view_exists($view)) {
755  $view = 'page/components/list';
756  }
757 
758  return elgg_view($view, $vars);
759 }
760 
778  $defaults = [
779  'full_view' => true,
780  ];
781 
782  $vars = array_merge($defaults, $vars);
783  $vars['relationship'] = $relationship;
784 
785  $name = $relationship->relationship;
786  if (empty($name)) {
787  return '';
788  }
789 
790  $relationship_views = [
791  (string) elgg_extract('item_view', $vars, ''),
792  "relationship/{$name}",
793  'relationship/default',
794  ];
795 
796  foreach ($relationship_views as $view) {
797  if (elgg_view_exists($view)) {
798  return elgg_view($view, $vars);
799  }
800  }
801 
802  return '';
803 }
804 
815 function elgg_view_title(string $title, array $vars = []): string {
816  $vars['title'] = $title;
817 
818  return elgg_view('page/elements/title', $vars);
819 }
820 
832 function elgg_view_friendly_time($time, $time_updated = null): string {
833  $view = 'output/friendlytime';
834  $vars = [
835  'time' => $time,
836  'time_updated' => $time_updated,
837  ];
838  $viewtype = elgg_view_exists($view) ? '' : 'default';
839 
841 }
842 
856 function elgg_view_comments(\ElggEntity $entity, bool $add_comment = true, array $vars = []): string {
857  if (!$entity->hasCapability('commentable')) {
858  return '';
859  }
860 
861  $vars['entity'] = $entity;
862  $vars['show_add_form'] = $add_comment;
863  $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
864 
865  $default_id = 'comments';
866  if ($entity instanceof \ElggComment) {
867  $default_id .= "-{$entity->guid}";
868  }
869 
870  $vars['id'] = elgg_extract('id', $vars, $default_id);
871 
872  $output = elgg_trigger_event_results('comments', $entity->getType(), $vars, false);
873  if (is_string($output)) {
874  return $output;
875  }
876 
877  return elgg_view('page/elements/comments', $vars);
878 }
879 
898 function elgg_view_image_block(string $image, string $body, array $vars = []): string {
899  $vars['image'] = $image;
900  $vars['body'] = $body;
901  return elgg_view('page/components/image_block', $vars);
902 }
903 
919 function elgg_view_module(string $type, string $title, string $body, array $vars = []): string {
920  $vars['type'] = $type;
921  $vars['title'] = $title;
922  $vars['body'] = $body;
923  return elgg_view('page/components/module', $vars);
924 }
925 
940 function elgg_view_message(string $type, string $body, array $vars = []): string {
941  $vars['type'] = $type;
942  $vars['body'] = $body;
943  return elgg_view('page/components/message', $vars);
944 }
945 
955 function elgg_view_river_item(\ElggRiverItem $item, array $vars = []): string {
956 
957  // checking default viewtype since some viewtypes do not have unique views per item (rss)
958  $view = $item->getView();
959 
960  $subject = $item->getSubjectEntity();
961  $object = $item->getObjectEntity();
962  if (!$subject || !$object) {
963  // subject is disabled or subject/object deleted
964  return '';
965  }
966 
967  if (elgg_extract('register_rss_link', $vars)) {
969  }
970 
971  $vars['item'] = $item;
972 
973  // create river view logic
974  $type = $object->getType();
975  $subtype = $object->getSubtype();
976  $action = $item->action_type;
977 
978  $river_views = [
979  elgg_extract('item_view', $vars, ''),
980  'river/item', // important for other viewtypes, e.g. "rss"
981  $view,
982  "river/{$type}/{$subtype}/{$action}",
983  "river/{$type}/{$subtype}/default",
984  "river/{$type}/{$action}",
985  "river/{$type}/default",
986  'river/elements/layout',
987  ];
988 
989  foreach ($river_views as $view) {
990  if (elgg_view_exists($view)) {
991  return elgg_view($view, $vars);
992  }
993  }
994 
995  return '';
996 }
997 
1033 function elgg_view_form(string $action, array $form_vars = [], array $body_vars = []): string {
1034  return _elgg_services()->forms->render($action, $form_vars, $body_vars);
1035 }
1036 
1046 function elgg_set_form_footer(string $footer = ''): void {
1047  _elgg_services()->forms->setFooter($footer);
1048 }
1049 
1054 function elgg_get_form_footer(): string {
1055  return _elgg_services()->forms->getFooter();
1056 }
1057 
1069 function _elgg_split_vars(array $vars = [], array $prefixes = null): array {
1070 
1071  if (!isset($prefixes)) {
1072  $prefixes = ['#'];
1073  }
1074 
1075  $return = [];
1076  $default_section = ''; // something weird with PHP 8.1 compatibility
1077 
1078  foreach ($vars as $key => $value) {
1079  foreach ($prefixes as $prefix) {
1080  if (substr($key, 0, 1) === $prefix) {
1081  $key = substr($key, 1);
1082  $return[$prefix][$key] = $value;
1083  break;
1084  } else {
1085  $return[$default_section][$key] = $value;
1086  }
1087  }
1088  }
1089 
1090  return $return;
1091 }
1092 
1112 function elgg_view_field(array $params = []): string {
1113 
1114  if (isset($params['#html'])) {
1115  return (string) $params['#html'];
1116  }
1117 
1118  if (empty($params['#type'])) {
1119  _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.');
1120  return '';
1121  }
1122 
1123  $input_type = $params['#type'];
1124  if (!elgg_view_exists("input/$input_type")) {
1125  return '';
1126  }
1127 
1128  $hidden_types = ['hidden', 'securitytoken'];
1129  if (in_array($input_type, $hidden_types)) {
1131  return elgg_view("input/{$input_type}", $params['']);
1132  }
1133 
1134  if (empty($params['id'])) {
1135  $params['id'] = 'elgg-field-' . base_convert(mt_rand(), 10, 36);
1136  }
1137 
1138  $make_special_checkbox_label = false;
1139  if (in_array($input_type, ['checkbox', 'switch']) && (isset($params['label']) || isset($params['#label']))) {
1140  if (isset($params['#label']) && isset($params['label'])) {
1141  $params['label_tag'] = 'div';
1142  } else {
1143  $label = elgg_extract('label', $params);
1144  $label = elgg_extract('#label', $params, $label);
1145 
1146  $params['#label'] = $label;
1147  unset($params['label']);
1148 
1149  // Single checkbox input view gets special treatment
1150  // We don't want the field label to appear a checkbox without a label
1151  $make_special_checkbox_label = true;
1152  }
1153  }
1154 
1155  // Need to set defaults to prevent input keys with same name ending up in element vars if not provided
1156  $defaults = [
1157  '#class' => ELGG_ENTITIES_ANY_VALUE,
1158  '#help' => ELGG_ENTITIES_ANY_VALUE,
1159  '#label' => ELGG_ENTITIES_ANY_VALUE,
1160  '#view' => ELGG_ENTITIES_ANY_VALUE,
1161  ];
1162  $params = array_merge($defaults, $params);
1163 
1164  // first pass non-hash keys into both
1165  $split_params = _elgg_split_vars($params);
1166 
1167  // $vars passed to input/$input_name
1168  $input_vars = $split_params[''];
1169 
1170  // $vars passed to label, help and field wrapper views
1171  $element_vars = array_merge($split_params[''], $split_params['#']);
1172 
1173  // field input view needs this
1174  $input_vars['input_type'] = $input_type;
1175 
1176  // field views get more data
1177  $element_vars['input_type'] = $input_type;
1178 
1179  // correct the label vars
1180  $label_vars = $element_vars;
1181  if (in_array($input_type, ['checkboxes', 'radio'])) {
1182  // the field label shouldn't point to the wrapping <ul> as that isn't a valid target for a <label>
1183  unset($label_vars['id']);
1184  }
1185 
1186  $element_vars['label'] = elgg_view('elements/forms/label', $label_vars);
1187 
1188  // wrap if present
1189  $element_vars['help'] = elgg_view('elements/forms/help', $element_vars);
1190 
1191  if ($make_special_checkbox_label) {
1192  $input_vars['label'] = $element_vars['label'];
1193  $input_vars['label_tag'] = 'div';
1194  unset($element_vars['label']);
1195  }
1196 
1197  $element_vars['input'] = elgg_view('elements/forms/input', $input_vars);
1198 
1199  return elgg_view('elements/forms/field', $element_vars);
1200 }
1201 
1214 function elgg_view_tagcloud(array $options = []): string {
1215  return elgg_view('output/tagcloud', [
1216  'value' => elgg_get_tags($options),
1217  'type' => elgg_extract('type', $options, ''),
1218  'subtype' => elgg_extract('subtype', $options, ''),
1219  ]);
1220 }
1221 
1232 function elgg_view_list_item($item, array $vars = []): string {
1233 
1234  if ($item instanceof \ElggEntity) {
1235  return elgg_view_entity($item, $vars);
1236  } else if ($item instanceof \ElggAnnotation) {
1237  return elgg_view_annotation($item, $vars);
1238  } else if ($item instanceof \ElggRiverItem) {
1239  return elgg_view_river_item($item, $vars);
1240  } else if ($item instanceof ElggRelationship) {
1242  }
1243 
1244  $view = (string) elgg_extract('item_view', $vars);
1245  if ($view && elgg_view_exists($view)) {
1246  $vars['item'] = $item;
1247  return elgg_view($view, $vars);
1248  }
1249 
1250  return '';
1251 }
1252 
1261 function elgg_view_icon(string $name, array $vars = []): string {
1262  $vars['class'] = elgg_extract_class($vars, "elgg-icon-{$name}");
1263 
1264  return elgg_view('output/icon', $vars);
1265 }
1266 
1273  _elgg_services()->config->_elgg_autofeed = true;
1274 }
1275 
1282  _elgg_services()->config->_elgg_autofeed = false;
1283 }
1284 
1291 function _elgg_has_rss_link(): bool {
1292  if (_elgg_services()->config->disable_rss) {
1293  return false;
1294  }
1295 
1296  return (bool) _elgg_services()->config->_elgg_autofeed;
1297 }
1298 
1306 function elgg_views_boot(): void {
1307  _elgg_services()->views->registerCoreViews();
1308 
1309  elgg_register_external_file('css', 'font-awesome', elgg_get_simplecache_url('font-awesome/css/all.min.css'));
1310  elgg_load_external_file('css', 'font-awesome');
1311 
1312  elgg_extend_view('elgg.css', 'lightbox/elgg-colorbox-theme/colorbox.css');
1313  elgg_extend_view('elgg.css', 'entity/edit/icon/crop.css');
1314 
1315  elgg_require_css('elgg');
1316 
1317  elgg_register_esm('cropperjs', elgg_get_simplecache_url('cropperjs/cropper.esm.js'));
1318  elgg_register_esm('jquery', elgg_get_simplecache_url('elgg/jquery.mjs'));
1319  elgg_register_esm('jquery-ui', elgg_get_simplecache_url('jquery-ui.js'));
1320  elgg_register_esm('jquery-cropper/jquery-cropper', elgg_get_simplecache_url('jquery-cropper/jquery-cropper.esm.js'));
1321 
1322  elgg_import_esm('elgg');
1323  elgg_import_esm('elgg/lightbox');
1324  elgg_import_esm('elgg/security');
1325 
1326  elgg_extend_view('jquery-ui.js', 'jquery.ui.touch-punch.js');
1327  elgg_extend_view('initialize_elgg.js', 'elgg/prevent_clicks.js', 1);
1328 
1329  elgg_register_ajax_view('languages.js');
1330 }
1331 
1340 function _elgg_get_js_page_data(array $params = []): array {
1341  $data = elgg_trigger_event_results('elgg.data', 'page', $params, []);
1342  if (!is_array($data)) {
1343  _elgg_services()->logger->error('"elgg.data" Event handlers must return an array. Returned ' . gettype($data) . '.');
1344  $data = [];
1345  }
1346 
1347  $message_delay = (int) elgg_get_config('message_delay');
1348  if ($message_delay < 1) {
1349  $message_delay = 6;
1350  }
1351 
1352  $elgg = [
1353  'config' => [
1354  'lastcache' => (int) _elgg_services()->config->lastcache,
1355  'viewtype' => elgg_get_viewtype(),
1356  'simplecache_enabled' => (int) _elgg_services()->simpleCache->isEnabled(),
1357  'current_language' => elgg_get_current_language(),
1358  'language' => _elgg_services()->config->language ?: 'en',
1359  'wwwroot' => elgg_get_site_url(),
1360  'message_delay' => $message_delay * 1000,
1361  ],
1362  'release' => elgg_get_release(),
1363  'security' => [
1364  // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
1365  'interval' => (int) _elgg_services()->csrf->getActionTokenTimeout() * 333,
1366 
1367  'token' => [
1368  '__elgg_ts' => $ts = _elgg_services()->csrf->getCurrentTime()->getTimestamp(),
1369  '__elgg_token' => _elgg_services()->csrf->generateActionToken($ts),
1370  ],
1371  ],
1372  'session' => [
1373  'user' => null,
1374  'token' => _elgg_services()->session->get('__elgg_session'),
1375  ],
1376  'data' => $data,
1377  ];
1378 
1380  if ($user instanceof ElggUser) {
1381  $user_object = $user->toObject();
1382  $user_object->admin = $user->isAdmin();
1383 
1384  $elgg['user'] = (array) $user_object;
1385  }
1386 
1387  return $elgg;
1388 }
1389 
1401 function _elgg_view_under_viewtype(string $view, array $vars, string $viewtype): string {
1402  $current_view_type = null;
1403  if ($viewtype) {
1404  $current_view_type = elgg_get_viewtype();
1405  elgg_set_viewtype($viewtype);
1406  }
1407 
1408  $ret = elgg_view($view, $vars);
1409 
1410  if (isset($current_view_type)) {
1411  elgg_set_viewtype($current_view_type);
1412  }
1413 
1414  return $ret;
1415 }
1416 
1427 function elgg_view_url(string $href, string $text = null, array $options = []): string {
1428  $options['is_trusted'] = elgg_extract('is_trusted', $options, true);
1429  $options['href'] = $href;
1430  $options['text'] = $text;
1431 
1432  return elgg_view('output/url', $options);
1433 }
1434 
1444 function elgg_view_entity_url(\ElggEntity $entity, array $options = []): string {
1445  return elgg_view_url($entity->getURL(), $entity->getDisplayName(), $options);
1446 }
1447 
1460 function elgg_view_deprecated(string $view, array $vars, string $suggestion, string $version): string {
1461  return _elgg_services()->views->renderDeprecatedView($view, $vars, $suggestion, $version);
1462 }
elgg_get_current_language()
Get the current system/user language or &#39;en&#39;.
Definition: languages.php:27
if(!$items) $item
Definition: delete.php:13
$messages
Definition: admin.php:12
if(!elgg_view_exists("plugins/{$plugin_id}/settings")) $form_vars
elgg_view_module(string $type, string $title, string $body, array $vars=[])
Wrapper function for the module display pattern.
Definition: views.php:919
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades...
Definition: views.php:1306
getSubtype()
Get the entity subtype.
Definition: ElggEntity.php:504
elgg_get_release()
Get the current Elgg release.
elgg_register_viewtype_fallback(string $viewtype)
Register a viewtype to fall back to a default view if a view isn&#39;t found for that viewtype...
Definition: views.php:88
if(empty($plugins)) $errors
if($view &&elgg_view_exists($view)) $label
Definition: field.php:26
elgg_view_river_item(\ElggRiverItem $item, array $vars=[])
Renders a human-readable representation of a river item.
Definition: views.php:955
elgg_view_layout(string $layout_name, array $vars=[])
Displays a layout with optional parameters.
Definition: views.php:352
elgg_view_form(string $action, array $form_vars=[], array $body_vars=[])
Definition: views.php:1033
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:1112
elgg_get_config(string $name, $default=null)
Get an Elgg configuration value.
$footer
Wrap form footer.
Definition: footer.php:11
if($id< 1) $annotation
Definition: delete.php:11
$defaults
Generic entity header upload helper.
Definition: header.php:6
elgg_view_image_block(string $image, string $body, array $vars=[])
Wrapper function for the image block display pattern.
Definition: views.php:898
if(!$user||!$user->canDelete()) $name
Definition: delete.php:22
getSubjectEntity()
Get the subject of this river item.
$title
Definition: generic.php:50
$version
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
if(empty($count)) $offset
Definition: pagination.php:26
$relationship
Elgg default relationship view.
Definition: default.php:10
if(!$annotation instanceof ElggAnnotation) $time
Definition: time.php:20
Entity Annotation.
if($vars['name']&&$vars['default']!==false) $input_vars
Definition: checkboxes.php:89
$time_updated
Definition: time.php:21
$type
Definition: delete.php:21
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
elgg_view_tagcloud(array $options=[])
Create a tagcloud for viewing.
Definition: views.php:1214
elgg_register_ajax_view(string $view)
Register a view to be available for ajax calls.
Definition: views.php:104
elgg_register_external_file(string $type, string $name, string $url, string $location= '')
Core registration function for external files.
elgg_view_title(string $title, array $vars=[])
Renders a title.
Definition: views.php:815
elgg_view_resource(string $name, array $vars=[])
Render a resource view.
Definition: views.php:307
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
$value
Definition: generic.php:51
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_get_viewtype()
Return the current view type.
Definition: views.php:73
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:256
_elgg_has_rss_link()
Should the RSS view of this URL be linked to?
Definition: views.php:1291
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
Definition: language.php:20
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
elgg_view_menu($menu, array $vars=[])
Render a menu.
Definition: views.php:441
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
Linear set of menu items collected from configuration and the "register" event.
Thrown when page is not accessible.
elgg_view_annotation_list(array $annotations, array $vars=[])
Returns a rendered list of annotations, plus pagination.
Definition: views.php:685
elgg_set_form_footer(string $footer= '')
Sets form footer and defers its rendering until the form view and extensions have been rendered...
Definition: views.php:1046
elgg_view_entity_icon(\ElggEntity $entity, string $size= 'medium', array $vars=[])
View the icon of an entity.
Definition: views.php:542
$input_type
Helper view that can be used to filter vars for all input views.
Definition: input.php:6
elgg_view_list_item($item, array $vars=[])
View an item in a list.
Definition: views.php:1232
$entity
Definition: reset.php:8
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_page(string $title, string|array $body, string $page_shell= 'default', array $vars=[])
Assembles and outputs a full page.
Definition: views.php:235
elgg_get_view_extensions(string $view)
Get the views (and priorities) that extend a view.
Definition: views.php:210
elgg_import_esm(string $name)
Helper functions for external files like css/js.
elgg_view_relationship(\ElggRelationship $relationship, array $vars=[])
Returns a string of a rendered relationship.
Definition: views.php:777
elgg_view_entity(\ElggEntity $entity, array $vars=[])
Returns a string of a rendered entity.
Definition: views.php:493
$user
Definition: ban.php:7
elgg_register_esm(string $name, string $href)
Registers an ES module to the import map.
$body_vars
$image
Definition: image_block.php:26
elgg_load_external_file(string $type, string $name)
Load an external resource for use on this page.
elgg_set_viewtype(string $viewtype= '')
Manually set the viewtype.
Definition: views.php:60
$viewtype
Definition: default.php:11
$timer
Definition: pending.php:28
const ELGG_ENTITIES_ANY_VALUE
Constant to request the value of a parameter be ignored in elgg_get_*() functions.
Definition: constants.php:21
elgg_get_site_url()
Get the URL for the current (or specified) site, ending with "/".
$body
Definition: useradd.php:55
hasCapability(string $capability)
Checks a specific capability is enabled for the entity type/subtype.
$menu
Form body for setting up site menu.
Definition: save.php:7
$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_icon(string $name, array $vars=[])
View an icon glyph.
Definition: views.php:1261
elgg_view_friendly_time($time, $time_updated=null)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:832
elgg_unregister_ajax_view(string $view)
Unregister a view for ajax calls.
Definition: views.php:116
elgg_view_deprecated(string $view, array $vars, string $suggestion, string $version)
Display a view with a deprecation notice.
Definition: views.php:1460
elgg_get_tags(array $options=[])
Get popular tags and their frequencies.
Definition: metadata.php:68
if($email instanceof\Elgg\Email) $object
Definition: body.php:24
elgg_view_entity_list(array $entities, array $vars=[])
Returns a rendered list of entities with pagination.
Definition: views.php:636
$ts
CSRF security token view for use with secure forms.
$vars
Definition: theme.php:5
elgg_view_url(string $href, string $text=null, array $options=[])
Helper function for outputting urls.
Definition: views.php:1427
elgg_view_message(string $type, string $body, array $vars=[])
Wrapper function for the message display pattern.
Definition: views.php:940
getType()
Returns the entity type.
Definition: ElggEntity.php:478
$subtype
Definition: delete.php:22
getView()
Get the view used to display this river item.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:353
elgg_view_relationship_list(array $relationships, array $vars=[])
Returns a rendered list of relationships, plus pagination.
Definition: views.php:732
elgg_extract_class(array $array, array|string $existing=[], string $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:279
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:583
elgg_get_simplecache_url(string $view)
Get the URL for the cached view.
Definition: cache.php:78
elgg_unregister_rss_link()
Remove the RSS icon link and link element from the head.
Definition: views.php:1281
_elgg_view_under_viewtype(string $view, array $vars, string $viewtype)
Render a view while the global viewtype is temporarily changed.
Definition: views.php:1401
$text
Definition: button.php:33
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:78
elgg_extend_view(string $view, string $view_extension, int $priority=501)
Extends a view with another view.
Definition: views.php:183
elgg_view_comments(\ElggEntity $entity, bool $add_comment=true, array $vars=[])
Returns rendered comments and a comment form for an entity.
Definition: views.php:856
$output
Definition: download.php:9
elgg_unextend_view(string $view, string $view_extension)
Unextends a view.
Definition: views.php:196
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
Definition: views.php:131
_elgg_get_js_page_data(array $params=[])
Get the initial contents of "elgg" client side.
Definition: views.php:1340
_elgg_split_vars(array $vars=[], array $prefixes=null)
Split array of vars into subarrays based on property prefixes.
Definition: views.php:1069
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.
Definition: ElggEntity.php:573
$menu_view
Definition: default.php:31
$subject
Definition: useradd.php:54
$priority
elgg_view_entity_url(\ElggEntity $entity, array $options=[])
Helper function for outputting a link to an entity.
Definition: views.php:1444
$views
Definition: item.php:17
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:306
A complete menu, sorted, filtered by the "prepare" event, and split into sections.
Definition: Menu.php:10
elgg_get_form_footer()
Returns currently set footer, or false if not in the form rendering stack.
Definition: views.php:1054
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1272
getObjectEntity()
Get the object of this river item.