Elgg  Version master
views.php
Go to the documentation of this file.
1 <?php
48 use Elgg\Menu\Menu;
50 
63 function elgg_set_viewtype(string $viewtype = ''): bool {
64  return _elgg_services()->views->setViewtype($viewtype);
65 }
66 
76 function elgg_get_viewtype(): string {
77  return _elgg_services()->views->getViewtype();
78 }
79 
92  _elgg_services()->views->registerViewtypeFallback($viewtype);
93 }
94 
107 function elgg_register_ajax_view(string $view): void {
108  _elgg_services()->ajax->registerView($view);
109 }
110 
120  _elgg_services()->ajax->unregisterView($view);
121 }
122 
137 function elgg_set_view_location(string $view, string $location, string $viewtype = ''): void {
138  _elgg_services()->views->setViewDir($view, $location, $viewtype);
139 }
140 
152 function elgg_view_exists(string $view, string $viewtype = '', bool $recurse = true): bool {
153  return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
154 }
155 
177 function elgg_view(string $view, array $vars = [], string $viewtype = ''): string {
178  return _elgg_services()->views->renderView($view, $vars, $viewtype);
179 }
180 
204 function elgg_extend_view(string $view, string $view_extension, int $priority = 501): void {
205  _elgg_services()->views->extendView($view, $view_extension, $priority);
206 }
207 
217 function elgg_unextend_view(string $view, string $view_extension): bool {
218  return _elgg_services()->views->unextendView($view, $view_extension);
219 }
220 
231 function elgg_get_view_extensions(string $view): array {
232  $list = _elgg_services()->views->getViewList($view);
233  unset($list[500]);
234  return $list;
235 }
236 
256 function elgg_view_page(string $title, string|array $body, string $page_shell = 'default', array $vars = []): string {
257 
258  if (elgg_is_xhr() && get_input('_elgg_ajax_list')) {
259  // requested by ajaxed pagination
260  return is_array($body) ? (string) elgg_extract('content', $body) : $body;
261  }
262 
263  if (is_array($body)) {
264  $vars['entity'] = elgg_extract('entity', $body, elgg_extract('entity', $vars));
265 
266  $body['title'] = elgg_extract('title', $body, $title);
267  $body = elgg_view_layout('default', $body);
268  }
269 
270  $timer = _elgg_services()->timer;
271  if (!$timer->hasEnded(['build page'])) {
272  $timer->end(['build page']);
273  }
274 
275  $timer->begin([__FUNCTION__]);
276 
277  $params = [];
278  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
279  $params['segments'] = _elgg_services()->request->getUrlSegments();
280  array_shift($params['segments']);
281  $page_shell = elgg_trigger_event_results('shell', 'page', $params, $page_shell);
282 
283  $system_messages = _elgg_services()->system_messages;
284 
285  $messages = null;
286  if ($system_messages->count()) {
287  $messages = $system_messages->dumpRegister();
288 
289  if (isset($messages['error'])) {
290  // always make sure error is the first type
291  $errors = [
292  'error' => $messages['error']
293  ];
294 
295  unset($messages['error']);
296  $messages = array_merge($errors, $messages);
297  }
298  }
299 
300  $vars['title'] = $title;
301  $vars['body'] = $body;
302  $vars['sysmessages'] = $messages;
303  $vars['page_shell'] = $page_shell;
304 
305  $vars['head'] = elgg_trigger_event_results('head', 'page', $vars, ['metas' => [], 'links' => []]);
306 
307  $vars = elgg_trigger_event_results('output:before', 'page', [], $vars);
308 
309  $output = elgg_view("page/{$page_shell}", $vars);
310 
311  // Allow plugins to modify the output
312  $output = elgg_trigger_event_results('output', 'page', $vars, $output);
313 
314  $timer->end([__FUNCTION__]);
315  return $output;
316 }
317 
328 function elgg_view_resource(string $name, array $vars = []): string {
329  $view = "resources/{$name}";
330 
331  if (elgg_view_exists($view)) {
332  return _elgg_services()->views->renderView($view, $vars);
333  }
334 
335  if (elgg_get_viewtype() !== 'default' && elgg_view_exists($view, 'default')) {
336  return _elgg_services()->views->renderView($view, $vars, 'default');
337  }
338 
339  _elgg_services()->logger->error("The view {$view} is missing.");
340 
341  // only works for default viewtype
342  throw new PageNotFoundException();
343 }
344 
373 function elgg_view_layout(string $layout_name, array $vars = []): string {
374  $timer = _elgg_services()->timer;
375  if (!$timer->hasEnded(['build page'])) {
376  $timer->end(['build page']);
377  }
378 
379  $timer->begin([__FUNCTION__]);
380 
381  $vars['identifier'] = _elgg_services()->request->getFirstUrlSegment();
382  $vars['segments'] = _elgg_services()->request->getUrlSegments();
383  array_shift($vars['segments']);
384 
385  $layout_name = elgg_trigger_event_results('layout', 'page', $vars, $layout_name);
386 
387  $vars['layout'] = $layout_name;
388 
389  $layout_views = [
390  "page/layouts/{$layout_name}",
391  'page/layouts/default',
392  ];
393 
394  $output = '';
395  foreach ($layout_views as $layout_view) {
396  if (elgg_view_exists($layout_view)) {
397  $output = elgg_view($layout_view, $vars);
398  break;
399  }
400  }
401 
402  $timer->end([__FUNCTION__]);
403  return $output;
404 }
405 
462 function elgg_view_menu($menu, array $vars = []): string {
463 
464  $menu_view = (string) elgg_extract('menu_view', $vars);
465  unset($vars['menu_view']);
466 
467  if (is_string($menu)) {
468  $menu = _elgg_services()->menus->getMenu($menu, $vars);
469  } elseif ($menu instanceof UnpreparedMenu) {
470  $menu = _elgg_services()->menus->prepareMenu($menu);
471  }
472 
473  if (!$menu instanceof Menu) {
474  throw new ElggInvalidArgumentException('$menu must be a menu name, a Menu, or UnpreparedMenu');
475  }
476 
477  $name = $menu->getName();
478  $params = $menu->getParams();
479 
480  $views = [
481  $menu_view,
482  "navigation/menu/{$name}",
483  'navigation/menu/default',
484  ];
485 
486  foreach ($views as $view) {
487  if (elgg_view_exists($view)) {
488  return elgg_view($view, $params);
489  }
490  }
491 
492  return '';
493 }
494 
514 function elgg_view_entity(\ElggEntity $entity, array $vars = []): string {
515 
516  $defaults = [
517  'full_view' => true,
518  ];
519 
520  $vars = array_merge($defaults, $vars);
521 
522  if (elgg_extract('register_rss_link', $vars, elgg_extract('full_view', $vars))) {
524  }
525 
526  $vars['entity'] = $entity;
527 
528  $entity_type = $entity->getType();
529  $entity_subtype = $entity->getSubtype();
530 
531  $entity_views = [
532  (string) elgg_extract('item_view', $vars, ''),
533  "{$entity_type}/{$entity_subtype}",
534  "{$entity_type}/default",
535  ];
536 
537  $contents = '';
538  foreach ($entity_views as $view) {
539  if (elgg_view_exists($view)) {
540  $contents = elgg_view($view, $vars);
541  break;
542  }
543  }
544 
545  return $contents;
546 }
547 
563 function elgg_view_entity_icon(\ElggEntity $entity, string $size = 'medium', array $vars = []): string {
564 
565  $vars['entity'] = $entity;
566  $vars['size'] = $size;
567 
568  $entity_type = $entity->getType();
569 
570  $subtype = $entity->getSubtype();
571 
572  $contents = '';
573  if (elgg_view_exists("icon/{$entity_type}/{$subtype}")) {
574  $contents = elgg_view("icon/{$entity_type}/{$subtype}", $vars);
575  }
576 
577  if (empty($contents) && elgg_view_exists("icon/{$entity_type}/default")) {
578  $contents = elgg_view("icon/{$entity_type}/default", $vars);
579  }
580 
581  if (empty($contents)) {
582  $contents = elgg_view('icon/default', $vars);
583  }
584 
585  return $contents;
586 }
587 
604 function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = []): string {
605  $defaults = [
606  'full_view' => true,
607  ];
608 
609  $vars = array_merge($defaults, $vars);
610  $vars['annotation'] = $annotation;
611 
612  $name = $annotation->name;
613  if (empty($name)) {
614  return '';
615  }
616 
617  $annotation_views = [
618  (string) elgg_extract('item_view', $vars, ''),
619  "annotation/{$name}",
620  'annotation/default',
621  ];
622 
623  foreach ($annotation_views as $view) {
624  if (elgg_view_exists($view)) {
625  return elgg_view($view, $vars);
626  }
627  }
628 
629  return '';
630 }
631 
657 function elgg_view_entity_list(array $entities, array $vars = []): string {
658  $offset = (int) get_input('offset', 0);
659 
660  // list type can be passed as request parameter
661  $list_type = get_input('list_type', 'list');
662 
663  $defaults = [
664  'items' => $entities,
665  'list_class' => 'elgg-list-entity',
666  'full_view' => true,
667  'pagination' => true,
668  'list_type' => $list_type,
669  'offset' => $offset,
670  'limit' => null,
671  ];
672 
673  $vars = array_merge($defaults, $vars);
674 
675  if (!$vars['limit'] && !$vars['offset']) {
676  // no need for pagination if listing is unlimited
677  $vars['pagination'] = false;
678  }
679 
680  $view = "page/components/{$vars['list_type']}";
681  if (!elgg_view_exists($view)) {
682  $view = 'page/components/list';
683  }
684 
685  return elgg_view($view, $vars);
686 }
687 
706 function elgg_view_annotation_list(array $annotations, array $vars = []): string {
707  // list type can be passed as request parameter
708  $list_type = get_input('list_type', 'list');
709 
710  $defaults = [
711  'items' => $annotations,
712  'offset' => null,
713  'limit' => null,
714  'list_class' => 'elgg-list-annotation',
715  'full_view' => true,
716  'list_type' => $list_type,
717  'offset_key' => 'annoff',
718  ];
719 
720  $vars = array_merge($defaults, $vars);
721 
722  if (!$vars['limit'] && !$vars['offset']) {
723  // no need for pagination if listing is unlimited
724  $vars['pagination'] = false;
725  }
726 
727  $view = "page/components/{$vars['list_type']}";
728  if (!elgg_view_exists($view)) {
729  $view = 'page/components/list';
730  }
731 
732  return elgg_view($view, $vars);
733 }
734 
753 function elgg_view_relationship_list(array $relationships, array $vars = []): string {
754  // list type can be passed as request parameter
755  $list_type = get_input('list_type', 'list');
756 
757  $defaults = [
758  'items' => $relationships,
759  'offset' => null,
760  'limit' => null,
761  'list_class' => 'elgg-list-relationship',
762  'full_view' => false,
763  'list_type' => $list_type,
764  'offset_key' => 'reloff',
765  ];
766 
767  $vars = array_merge($defaults, $vars);
768 
769  if (!$vars['limit'] && !$vars['offset']) {
770  // no need for pagination if listing is unlimited
771  $vars['pagination'] = false;
772  }
773 
774  $view = "page/components/{$vars['list_type']}";
775  if (!elgg_view_exists($view)) {
776  $view = 'page/components/list';
777  }
778 
779  return elgg_view($view, $vars);
780 }
781 
799  $defaults = [
800  'full_view' => true,
801  ];
802 
803  $vars = array_merge($defaults, $vars);
804  $vars['relationship'] = $relationship;
805 
806  $name = $relationship->relationship;
807  if (empty($name)) {
808  return '';
809  }
810 
811  $relationship_views = [
812  (string) elgg_extract('item_view', $vars, ''),
813  "relationship/{$name}",
814  'relationship/default',
815  ];
816 
817  foreach ($relationship_views as $view) {
818  if (elgg_view_exists($view)) {
819  return elgg_view($view, $vars);
820  }
821  }
822 
823  return '';
824 }
825 
836 function elgg_view_title(string $title, array $vars = []): string {
837  $vars['title'] = $title;
838 
839  return elgg_view('page/elements/title', $vars);
840 }
841 
853 function elgg_view_friendly_time($time, $time_updated = null): string {
854  $view = 'output/friendlytime';
855  $vars = [
856  'time' => $time,
857  'time_updated' => $time_updated,
858  ];
859  $viewtype = elgg_view_exists($view) ? '' : 'default';
860 
862 }
863 
877 function elgg_view_comments(\ElggEntity $entity, bool $add_comment = true, array $vars = []): string {
878  if (!$entity->hasCapability('commentable')) {
879  return '';
880  }
881 
882  $vars['entity'] = $entity;
883  $vars['show_add_form'] = $add_comment;
884  $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
885 
886  $default_id = 'comments';
887  if ($entity instanceof \ElggComment) {
888  $default_id .= "-{$entity->guid}";
889  }
890 
891  $vars['id'] = elgg_extract('id', $vars, $default_id);
892 
893  $output = elgg_trigger_event_results('comments', $entity->getType(), $vars, false);
894  if (is_string($output)) {
895  return $output;
896  }
897 
898  return elgg_view('page/elements/comments', $vars);
899 }
900 
919 function elgg_view_image_block(string $image, string $body, array $vars = []): string {
920  $vars['image'] = $image;
921  $vars['body'] = $body;
922  return elgg_view('page/components/image_block', $vars);
923 }
924 
940 function elgg_view_module(string $type, string $title, string $body, array $vars = []): string {
941  $vars['type'] = $type;
942  $vars['title'] = $title;
943  $vars['body'] = $body;
944  return elgg_view('page/components/module', $vars);
945 }
946 
961 function elgg_view_message(string $type, string $body, array $vars = []): string {
962  $vars['type'] = $type;
963  $vars['body'] = $body;
964  return elgg_view('page/components/message', $vars);
965 }
966 
976 function elgg_view_river_item(\ElggRiverItem $item, array $vars = []): string {
977 
978  // checking default viewtype since some viewtypes do not have unique views per item (rss)
979  $view = $item->getView();
980 
981  $subject = $item->getSubjectEntity();
982  $object = $item->getObjectEntity();
983  if (!$subject || !$object) {
984  // subject is disabled or subject/object deleted
985  return '';
986  }
987 
988  if (elgg_extract('register_rss_link', $vars)) {
990  }
991 
992  $vars['item'] = $item;
993 
994  // create river view logic
995  $type = $object->getType();
996  $subtype = $object->getSubtype();
997  $action = $item->action_type;
998 
999  $river_views = [
1000  elgg_extract('item_view', $vars, ''),
1001  'river/item', // important for other viewtypes, e.g. "rss"
1002  $view,
1003  "river/{$type}/{$subtype}/{$action}",
1004  "river/{$type}/{$subtype}/default",
1005  "river/{$type}/{$action}",
1006  "river/{$type}/default",
1007  'river/elements/layout',
1008  ];
1009 
1010  foreach ($river_views as $view) {
1011  if (elgg_view_exists($view)) {
1012  return elgg_view($view, $vars);
1013  }
1014  }
1015 
1016  return '';
1017 }
1018 
1054 function elgg_view_form(string $action, array $form_vars = [], array $body_vars = []): string {
1055  return _elgg_services()->forms->render($action, $form_vars, $body_vars);
1056 }
1057 
1067 function elgg_set_form_footer(string $footer = ''): void {
1068  _elgg_services()->forms->setFooter($footer);
1069 }
1070 
1075 function elgg_get_form_footer(): string {
1076  return _elgg_services()->forms->getFooter();
1077 }
1078 
1090 function _elgg_split_vars(array $vars = [], array $prefixes = null): array {
1091 
1092  if (!isset($prefixes)) {
1093  $prefixes = ['#'];
1094  }
1095 
1096  $return = [];
1097  $default_section = ''; // something weird with PHP 8.1 compatibility
1098 
1099  foreach ($vars as $key => $value) {
1100  foreach ($prefixes as $prefix) {
1101  if (substr($key, 0, 1) === $prefix) {
1102  $key = substr($key, 1);
1103  $return[$prefix][$key] = $value;
1104  break;
1105  } else {
1106  $return[$default_section][$key] = $value;
1107  }
1108  }
1109  }
1110 
1111  return $return;
1112 }
1113 
1133 function elgg_view_field(array $params = []): string {
1134 
1135  if (!empty($params['#html'])) {
1136  return $params['#html'];
1137  }
1138 
1139  if (empty($params['#type'])) {
1140  _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.');
1141  return '';
1142  }
1143 
1144  $input_type = $params['#type'];
1145  if (!elgg_view_exists("input/$input_type")) {
1146  return '';
1147  }
1148 
1149  $hidden_types = ['hidden', 'securitytoken'];
1150  if (in_array($input_type, $hidden_types)) {
1152  return elgg_view("input/{$input_type}", $params['']);
1153  }
1154 
1155  if (empty($params['id'])) {
1156  $params['id'] = 'elgg-field-' . base_convert(mt_rand(), 10, 36);
1157  }
1158 
1159  $make_special_checkbox_label = false;
1160  if ($input_type == 'checkbox' && (isset($params['label']) || isset($params['#label']))) {
1161  if (isset($params['#label']) && isset($params['label'])) {
1162  $params['label_tag'] = 'div';
1163  } else {
1164  $label = elgg_extract('label', $params);
1165  $label = elgg_extract('#label', $params, $label);
1166 
1167  $params['#label'] = $label;
1168  unset($params['label']);
1169 
1170  // Single checkbox input view gets special treatment
1171  // We don't want the field label to appear a checkbox without a label
1172  $make_special_checkbox_label = true;
1173  }
1174  }
1175 
1176  // Need to set defaults to prevent input keys with same name ending up in element vars if not provided
1177  $defaults = [
1178  '#class' => ELGG_ENTITIES_ANY_VALUE,
1179  '#help' => ELGG_ENTITIES_ANY_VALUE,
1180  '#label' => ELGG_ENTITIES_ANY_VALUE,
1181  '#view' => ELGG_ENTITIES_ANY_VALUE,
1182  ];
1183  $params = array_merge($defaults, $params);
1184 
1185  // first pass non-hash keys into both
1186  $split_params = _elgg_split_vars($params);
1187 
1188  // $vars passed to input/$input_name
1189  $input_vars = $split_params[''];
1190 
1191  // $vars passed to label, help and field wrapper views
1192  $element_vars = array_merge($split_params[''], $split_params['#']);
1193 
1194  // field input view needs this
1195  $input_vars['input_type'] = $input_type;
1196 
1197  // field views get more data
1198  $element_vars['input_type'] = $input_type;
1199 
1200  // correct the label vars
1201  $label_vars = $element_vars;
1202  if (in_array($input_type, ['checkboxes', 'radio'])) {
1203  // the field label shouldn't point to the wrapping <ul> as that isn't a valid target for a <label>
1204  unset($label_vars['id']);
1205  }
1206 
1207  $element_vars['label'] = elgg_view('elements/forms/label', $label_vars);
1208 
1209  // wrap if present
1210  $element_vars['help'] = elgg_view('elements/forms/help', $element_vars);
1211 
1212  if ($make_special_checkbox_label) {
1213  $input_vars['label'] = $element_vars['label'];
1214  $input_vars['label_tag'] = 'div';
1215  unset($element_vars['label']);
1216  }
1217 
1218  $element_vars['input'] = elgg_view('elements/forms/input', $input_vars);
1219 
1220  return elgg_view('elements/forms/field', $element_vars);
1221 }
1222 
1235 function elgg_view_tagcloud(array $options = []): string {
1236  return elgg_view('output/tagcloud', [
1237  'value' => elgg_get_tags($options),
1238  'type' => elgg_extract('type', $options, ''),
1239  'subtype' => elgg_extract('subtype', $options, ''),
1240  ]);
1241 }
1242 
1253 function elgg_view_list_item($item, array $vars = []): string {
1254 
1255  if ($item instanceof \ElggEntity) {
1256  return elgg_view_entity($item, $vars);
1257  } else if ($item instanceof \ElggAnnotation) {
1258  return elgg_view_annotation($item, $vars);
1259  } else if ($item instanceof \ElggRiverItem) {
1260  return elgg_view_river_item($item, $vars);
1261  } else if ($item instanceof ElggRelationship) {
1263  }
1264 
1265  $view = (string) elgg_extract('item_view', $vars);
1266  if ($view && elgg_view_exists($view)) {
1267  $vars['item'] = $item;
1268  return elgg_view($view, $vars);
1269  }
1270 
1271  return '';
1272 }
1273 
1282 function elgg_view_icon(string $name, array $vars = []): string {
1283  $vars['class'] = elgg_extract_class($vars, "elgg-icon-{$name}");
1284 
1285  return elgg_view('output/icon', $vars);
1286 }
1287 
1294  _elgg_services()->config->_elgg_autofeed = true;
1295 }
1296 
1303  _elgg_services()->config->_elgg_autofeed = false;
1304 }
1305 
1312 function _elgg_has_rss_link(): bool {
1313  if (_elgg_services()->config->disable_rss) {
1314  return false;
1315  }
1316 
1317  return (bool) _elgg_services()->config->_elgg_autofeed;
1318 }
1319 
1327 function elgg_views_boot(): void {
1328  _elgg_services()->viewCacher->registerCoreViews();
1329 
1330  // jQuery and UI must come before require. See #9024
1331  elgg_register_external_file('js', 'jquery', elgg_get_simplecache_url('jquery.js'));
1332  elgg_load_external_file('js', 'jquery');
1333 
1334  elgg_extend_view('require.js', 'elgg/require_config.js', 100);
1335 
1336  elgg_register_external_file('js', 'require', elgg_get_simplecache_url('require.js'));
1337  elgg_load_external_file('js', 'require');
1338 
1339  elgg_register_external_file('js', 'elgg', elgg_get_simplecache_url('elgg.js'));
1340  elgg_load_external_file('js', 'elgg');
1341 
1342  elgg_register_external_file('css', 'font-awesome', elgg_get_simplecache_url('font-awesome/css/all.min.css'));
1343  elgg_load_external_file('css', 'font-awesome');
1344 
1345  elgg_define_js('cropperjs', [
1346  'src' => elgg_get_simplecache_url('cropperjs/cropper.min.js'),
1347  ]);
1348  elgg_define_js('jquery-cropper/jquery-cropper', [
1349  'src' => elgg_get_simplecache_url('jquery-cropper/jquery-cropper.min.js'),
1350  ]);
1351 
1352  elgg_require_css('elgg');
1353 
1354  elgg_extend_view('initialize_elgg.js', 'elgg/prevent_clicks.js', 1);
1355 
1356  elgg_extend_view('elgg.css', 'lightbox/elgg-colorbox-theme/colorbox.css');
1357  elgg_extend_view('elgg.css', 'entity/edit/icon/crop.css');
1358 
1359  elgg_define_js('jquery.ui.autocomplete.html', [
1360  'deps' => ['jquery-ui/widgets/autocomplete'],
1361  ]);
1362 
1363  elgg_register_simplecache_view('elgg/touch_punch.js');
1364  elgg_define_js('jquery-ui/widgets/sortable', [
1365  'deps' => ['elgg/touch_punch'],
1366  ]);
1367 
1368  elgg_register_ajax_view('languages.js');
1369 }
1370 
1379 function _elgg_get_js_site_data(): array {
1380 
1381  $message_delay = (int) elgg_get_config('message_delay');
1382  if ($message_delay < 1) {
1383  $message_delay = 6;
1384  }
1385 
1386  return [
1387  'elgg.data' => (object) elgg_trigger_event_results('elgg.data', 'site', [], []),
1388  'elgg.release' => elgg_get_release(),
1389  'elgg.config.wwwroot' => elgg_get_site_url(),
1390  'elgg.config.message_delay' => $message_delay * 1000,
1391 
1392  // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
1393  'elgg.security.interval' => (int) _elgg_services()->csrf->getActionTokenTimeout() * 333,
1394  'elgg.config.language' => _elgg_services()->config->language ?: 'en',
1395  ];
1396 }
1397 
1406 function _elgg_get_js_page_data(array $params = []): array {
1407  $data = elgg_trigger_event_results('elgg.data', 'page', $params, []);
1408  if (!is_array($data)) {
1409  elgg_log('"elgg.data" Event handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR');
1410  $data = [];
1411  }
1412 
1413  $elgg = [
1414  'config' => [
1415  'lastcache' => (int) _elgg_services()->config->lastcache,
1416  'viewtype' => elgg_get_viewtype(),
1417  'simplecache_enabled' => (int) elgg_is_simplecache_enabled(),
1418  'current_language' => elgg_get_current_language(),
1419  ],
1420  'security' => [
1421  'token' => [
1422  '__elgg_ts' => $ts = _elgg_services()->csrf->getCurrentTime()->getTimestamp(),
1423  '__elgg_token' => _elgg_services()->csrf->generateActionToken($ts),
1424  ],
1425  ],
1426  'session' => [
1427  'user' => null,
1428  'token' => _elgg_services()->session->get('__elgg_session'),
1429  ],
1430  '_data' => (object) $data,
1431  ];
1432 
1434  if ($user instanceof ElggUser) {
1435  $user_object = $user->toObject();
1436  $user_object->admin = $user->isAdmin();
1437 
1438  $elgg['user'] = (array) $user_object;
1439  }
1440 
1441  return $elgg;
1442 }
1443 
1455 function _elgg_view_under_viewtype(string $view, array $vars, string $viewtype): string {
1456  $current_view_type = null;
1457  if ($viewtype) {
1458  $current_view_type = elgg_get_viewtype();
1459  elgg_set_viewtype($viewtype);
1460  }
1461 
1462  $ret = elgg_view($view, $vars);
1463 
1464  if (isset($current_view_type)) {
1465  elgg_set_viewtype($current_view_type);
1466  }
1467 
1468  return $ret;
1469 }
1470 
1481 function elgg_view_url(string $href, string $text = null, array $options = []): string {
1482  $options['is_trusted'] = elgg_extract('is_trusted', $options, true);
1483  $options['href'] = $href;
1484  $options['text'] = $text;
1485 
1486  return elgg_view('output/url', $options);
1487 }
1488 
1498 function elgg_view_entity_url(\ElggEntity $entity, array $options = []): string {
1499  return elgg_view_url($entity->getURL(), $entity->getDisplayName(), $options);
1500 }
1501 
1514 function elgg_view_deprecated(string $view, array $vars, string $suggestion, string $version): string {
1515  return _elgg_services()->views->renderDeprecatedView($view, $vars, $suggestion, $version);
1516 }
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:940
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades...
Definition: views.php:1327
getSubtype()
Get the entity subtype.
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:91
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:976
elgg_view_layout(string $layout_name, array $vars=[])
Displays a layout with optional parameters.
Definition: views.php:373
elgg_view_form(string $action, array $form_vars=[], array $body_vars=[])
Definition: views.php:1054
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:1133
elgg_define_js(string $name, array $config)
Helper functions for external files like css/js.
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:919
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
if($vars['name']&&$vars['default']!==false) $input_vars
Definition: checkboxes.php:90
$menu
Admin sidebar – just outputs the page menus.
Definition: sidebar.php:6
$time_updated
Definition: time.php:21
$type
Definition: delete.php:22
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:1235
elgg_register_ajax_view(string $view)
Register a view to be available for ajax calls.
Definition: views.php:107
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:1379
elgg_extract_class(array $array, $existing=[], $extract_key= 'class')
Extract class names from an array, optionally merging into a preexisting set.
Definition: elgglib.php:276
elgg_view_title(string $title, array $vars=[])
Renders a title.
Definition: views.php:836
elgg_view_resource(string $name, array $vars=[])
Render a resource view.
Definition: views.php:328
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
Definition: item.php:48
$options
Elgg admin footer.
Definition: footer.php:6
$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:76
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:254
_elgg_has_rss_link()
Should the RSS view of this URL be linked to?
Definition: views.php:1312
if(!$entity instanceof\ElggUser) $data
Definition: attributes.php:13
elgg_view_menu($menu, array $vars=[])
Render a menu.
Definition: views.php:462
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:177
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:706
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:1067
elgg_view_entity_icon(\ElggEntity $entity, string $size= 'medium', array $vars=[])
View the icon of an entity.
Definition: views.php:563
$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:1253
$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:256
elgg_get_view_extensions(string $view)
Get the views (and priorities) that extend a view.
Definition: views.php:231
elgg_log($message, $level=\Psr\Log\LogLevel::NOTICE)
Log a message.
Definition: elgglib.php:86
elgg_view_relationship(\ElggRelationship $relationship, array $vars=[])
Returns a string of a rendered relationship.
Definition: views.php:798
elgg_view_entity(\ElggEntity $entity, array $vars=[])
Returns a string of a rendered entity.
Definition: views.php:514
$user
Definition: ban.php:7
$body_vars
$image
Definition: image_block.php:25
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:63
$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.
$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:1282
elgg_view_friendly_time($time, $time_updated=null)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:853
elgg_unregister_ajax_view(string $view)
Unregister a view for ajax calls.
Definition: views.php:119
elgg_set_view_location(string $view, string $location, string $viewtype= '')
Set an alternative base location for a view.
Definition: views.php:137
elgg_view_deprecated(string $view, array $vars, string $suggestion, string $version)
Display a view with a deprecation notice.
Definition: views.php:1514
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:657
$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:1481
elgg_view_message(string $type, string $body, array $vars=[])
Wrapper function for the message display pattern.
Definition: views.php:961
elgg_is_simplecache_enabled()
Is simple cache enabled.
Definition: cache.php:149
getType()
Returns the entity type.
$subtype
Definition: delete.php:23
getView()
Get the view used to display this river item.
_elgg_services()
Get the global service provider.
Definition: elgglib.php:346
elgg_register_simplecache_view(string $view_name)
Registers a view to simple cache.
Definition: cache.php:111
$vars['head']
Definition: html.php:24
elgg_view_relationship_list(array $relationships, array $vars=[])
Returns a rendered list of relationships, plus pagination.
Definition: views.php:753
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:604
elgg_unregister_rss_link()
Remove the RSS icon link and link element from the head.
Definition: views.php:1302
_elgg_view_under_viewtype(string $view, array $vars, string $viewtype)
Render a view while the global viewtype is temporarily changed.
Definition: views.php:1455
elgg_get_simplecache_url(string $view, string $subview= '')
Get the URL for the cached view.
Definition: cache.php:139
$text
Definition: button.php:32
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:204
elgg_view_comments(\ElggEntity $entity, bool $add_comment=true, array $vars=[])
Returns rendered comments and a comment form for an entity.
Definition: views.php:877
$output
Definition: download.php:9
elgg_unextend_view(string $view, string $view_extension)
Unextends a view.
Definition: views.php:217
elgg_view_exists(string $view, string $viewtype= '', bool $recurse=true)
Returns whether the specified view exists.
Definition: views.php:152
_elgg_get_js_page_data(array $params=[])
Get the initial contents of "elgg" client side.
Definition: views.php:1406
_elgg_split_vars(array $vars=[], array $prefixes=null)
Split array of vars into subarrays based on property prefixes.
Definition: views.php:1090
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:54
$priority
elgg_view_entity_url(\ElggEntity $entity, array $options=[])
Helper function for outputting a link to an entity.
Definition: views.php:1498
$views
Definition: item.php:17
getDisplayName()
Get the entity&#39;s display name.
Definition: ElggEntity.php:312
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:1075
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1293
getObjectEntity()
Get the object of this river item.