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  $default_id = 'comments';
898  if ($entity instanceof \ElggComment) {
899  $default_id .= "-{$entity->guid}";
900  }
901  $vars['id'] = elgg_extract('id', $vars, $default_id);
902 
903  $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
904  if ($output !== false) {
905  return $output;
906  }
907 
908  return elgg_view('page/elements/comments', $vars);
909 }
910 
930  $vars['image'] = $image;
931  $vars['body'] = $body;
932  return elgg_view('page/components/image_block', $vars);
933 }
934 
950 function elgg_view_module($type, $title, $body, array $vars = []) {
951  $vars['type'] = $type;
952  $vars['title'] = $title;
953  $vars['body'] = $body;
954  return elgg_view('page/components/module', $vars);
955 }
956 
971 function elgg_view_message($type, $body, array $vars = []) {
972  $vars['type'] = $type;
973  $vars['body'] = $body;
974  return elgg_view('page/components/message', $vars);
975 }
976 
986 function elgg_view_river_item($item, array $vars = []) {
987 
988  if (!($item instanceof \ElggRiverItem)) {
989  return '';
990  }
991 
992  // checking default viewtype since some viewtypes do not have unique views per item (rss)
993  $view = $item->getView();
994 
995  $subject = $item->getSubjectEntity();
996  $object = $item->getObjectEntity();
997  if (!$subject || !$object) {
998  // subject is disabled or subject/object deleted
999  return '';
1000  }
1001 
1002  if (elgg_extract('register_rss_link', $vars)) {
1004  }
1005 
1006  $vars['item'] = $item;
1007 
1008  // create river view logic
1009  $type = $object->getType();
1010  $subtype = $object->getSubtype();
1011  $action = $item->action_type;
1012 
1013  $river_views = [
1014  elgg_extract('item_view', $vars, ''),
1015  'river/item', // important for other viewtypes, e.g. "rss"
1016  $view,
1017  "river/{$type}/{$subtype}/{$action}",
1018  "river/{$type}/{$subtype}/default",
1019  "river/{$type}/{$action}",
1020  "river/{$type}/default",
1021  'river/elements/layout',
1022  ];
1023 
1024  $contents = '';
1025  foreach ($river_views as $view) {
1026  if (elgg_view_exists($view)) {
1027  $contents = elgg_view($view, $vars);
1028  break;
1029  }
1030  }
1031 
1032  return $contents;
1033 }
1034 
1071  return _elgg_services()->forms->render($action, $form_vars, $body_vars);
1072 }
1073 
1084  return _elgg_services()->forms->setFooter($footer);
1085 }
1086 
1092  return _elgg_services()->forms->getFooter();
1093 }
1094 
1106 function _elgg_split_vars(array $vars = [], array $prefixes = null) {
1107 
1108  if (!isset($prefixes)) {
1109  $prefixes = ['#'];
1110  }
1111 
1112  $return = [];
1113  $default_section = ''; // something weird with PHP 8.1 compatibility
1114 
1115  foreach ($vars as $key => $value) {
1116  foreach ($prefixes as $prefix) {
1117  if (substr($key, 0, 1) === $prefix) {
1118  $key = substr($key, 1);
1119  $return[$prefix][$key] = $value;
1120  break;
1121  } else {
1122  $return[$default_section][$key] = $value;
1123  }
1124  }
1125  }
1126 
1127  return $return;
1128 }
1129 
1149 function elgg_view_field(array $params = []) {
1150 
1151  if (!empty($params['#html'])) {
1152  return $params['#html'];
1153  }
1154 
1155  if (empty($params['#type'])) {
1156  _elgg_services()->logger->error(__FUNCTION__ . '(): $params["#type"] is required.');
1157  return '';
1158  }
1159 
1160  $input_type = $params['#type'];
1161  if (!elgg_view_exists("input/$input_type")) {
1162  return '';
1163  }
1164 
1165  $hidden_types = ['hidden', 'securitytoken'];
1166  if (in_array($input_type, $hidden_types)) {
1168  return elgg_view("input/$input_type", $params['']);
1169  }
1170 
1171  $id = elgg_extract('id', $params);
1172  if (!$id) {
1173  $id = "elgg-field-" . base_convert(mt_rand(), 10, 36);
1174  $params['id'] = $id;
1175  }
1176 
1177  $make_special_checkbox_label = false;
1178  if ($input_type == 'checkbox' && (isset($params['label']) || isset($params['#label']))) {
1179  if (isset($params['#label']) && isset($params['label'])) {
1180  $params['label_tag'] = 'div';
1181  } else {
1182  $label = elgg_extract('label', $params);
1183  $label = elgg_extract('#label', $params, $label);
1184 
1185  $params['#label'] = $label;
1186  unset($params['label']);
1187 
1188  // Single checkbox input view gets special treatment
1189  // We don't want the field label to appear a checkbox without a label
1190  $make_special_checkbox_label = true;
1191  }
1192  }
1193 
1194  // Need to set defaults to prevent input keys with same name ending up in element vars if not provided
1195  $defaults = [
1196  '#class' => ELGG_ENTITIES_ANY_VALUE,
1197  '#help' => ELGG_ENTITIES_ANY_VALUE,
1198  '#label' => ELGG_ENTITIES_ANY_VALUE,
1199  '#view' => ELGG_ENTITIES_ANY_VALUE,
1200  ];
1201  $params = array_merge($defaults, $params);
1202 
1203  // first pass non-hash keys into both
1204  $split_params = _elgg_split_vars($params);
1205 
1206  // $vars passed to input/$input_name
1207  $input_vars = $split_params[''];
1208 
1209  // $vars passed to label, help and field wrapper views
1210  $element_vars = array_merge($split_params[''], $split_params['#']);
1211 
1212  // field input view needs this
1213  $input_vars['input_type'] = $input_type;
1214 
1215  // field views get more data
1216  $element_vars['input_type'] = $input_type;
1217 
1218  // wrap if present
1219  $element_vars['label'] = elgg_view('elements/forms/label', $element_vars);
1220  $element_vars['help'] = elgg_view('elements/forms/help', $element_vars);
1221 
1222  if ($make_special_checkbox_label) {
1223  $input_vars['label'] = $element_vars['label'];
1224  $input_vars['label_tag'] = 'div';
1225  unset($element_vars['label']);
1226  }
1227  $element_vars['input'] = elgg_view("elements/forms/input", $input_vars);
1228 
1229  return elgg_view('elements/forms/field', $element_vars);
1230 }
1231 
1244 function elgg_view_tagcloud(array $options = []) {
1245 
1246  $type = $subtype = '';
1247  if (isset($options['type'])) {
1248  $type = $options['type'];
1249  }
1250  if (isset($options['subtype'])) {
1251  $subtype = $options['subtype'];
1252  }
1253 
1254  $tag_data = elgg_get_tags($options);
1255  return elgg_view("output/tagcloud", [
1256  'value' => $tag_data,
1257  'type' => $type,
1258  'subtype' => $subtype,
1259  ]);
1260 }
1261 
1272 function elgg_view_list_item($item, array $vars = []) {
1273 
1274  if ($item instanceof \ElggEntity) {
1275  return elgg_view_entity($item, $vars);
1276  } else if ($item instanceof \ElggAnnotation) {
1277  return elgg_view_annotation($item, $vars);
1278  } else if ($item instanceof \ElggRiverItem) {
1279  return elgg_view_river_item($item, $vars);
1280  } else if ($item instanceof ElggRelationship) {
1282  }
1283 
1284  $view = elgg_extract('item_view', $vars);
1285  if ($view && elgg_view_exists($view)) {
1286  $vars['item'] = $item;
1287  return elgg_view($view, $vars);
1288  }
1289 
1290  return '';
1291 }
1292 
1303 function elgg_view_icon($name, $vars = []) {
1304  if (empty($vars)) {
1305  $vars = [];
1306  }
1307 
1308  if (is_string($vars)) {
1309  $vars = ['class' => $vars];
1310  }
1311 
1312  if (!is_array($vars)) {
1313  throw new ElggInvalidArgumentException('$vars needs to be a string or an array');
1314  }
1315 
1316  $vars['class'] = elgg_extract_class($vars, "elgg-icon-$name");
1317 
1318  return elgg_view('output/icon', $vars);
1319 }
1320 
1327  _elgg_services()->config->_elgg_autofeed = true;
1328 }
1329 
1336  _elgg_services()->config->_elgg_autofeed = false;
1337 }
1338 
1346  if (_elgg_services()->config->disable_rss) {
1347  return false;
1348  }
1349 
1350  return (bool) _elgg_services()->config->_elgg_autofeed;
1351 }
1352 
1361 function elgg_views_boot() {
1362  _elgg_services()->viewCacher->registerCoreViews();
1363 
1364  // jQuery and UI must come before require. See #9024
1365  elgg_register_external_file('js', 'jquery', elgg_get_simplecache_url('jquery.js'));
1366  elgg_load_external_file('js', 'jquery');
1367 
1368  elgg_extend_view('require.js', 'elgg/require_config.js', 100);
1369 
1370  elgg_register_external_file('js', 'require', elgg_get_simplecache_url('require.js'));
1371  elgg_load_external_file('js', 'require');
1372 
1373  elgg_register_external_file('js', 'elgg', elgg_get_simplecache_url('elgg.js'));
1374  elgg_load_external_file('js', 'elgg');
1375 
1376  elgg_register_external_file('css', 'font-awesome', elgg_get_simplecache_url('font-awesome/css/all.min.css'));
1377  elgg_load_external_file('css', 'font-awesome');
1378 
1379  elgg_define_js('cropperjs', [
1380  'src' => elgg_get_simplecache_url('cropperjs/cropper.min.js'),
1381  ]);
1382  elgg_define_js('jquery-cropper/jquery-cropper', [
1383  'src' => elgg_get_simplecache_url('jquery-cropper/jquery-cropper.min.js'),
1384  ]);
1385 
1386  elgg_require_css('elgg');
1387 
1388  elgg_extend_view('initialize_elgg.js', 'elgg/prevent_clicks.js', 1);
1389 
1390  elgg_extend_view('elgg.css', 'lightbox/elgg-colorbox-theme/colorbox.css');
1391  elgg_extend_view('elgg.css', 'entity/edit/icon/crop.css');
1392 
1393  elgg_define_js('jquery.ui.autocomplete.html', [
1394  'deps' => ['jquery-ui/widgets/autocomplete'],
1395  ]);
1396 
1397  elgg_register_simplecache_view('elgg/touch_punch.js');
1398  elgg_define_js('jquery-ui/widgets/sortable', [
1399  'deps' => ['elgg/touch_punch'],
1400  ]);
1401 
1402  elgg_register_ajax_view('languages.js');
1403 }
1404 
1414 
1415  $message_delay = (int) elgg_get_config('message_delay');
1416  if ($message_delay < 1) {
1417  $message_delay = 6;
1418  }
1419 
1420  return [
1421  'elgg.data' => (object) elgg_trigger_plugin_hook('elgg.data', 'site', null, []),
1422  'elgg.release' => elgg_get_release(),
1423  'elgg.config.wwwroot' => elgg_get_site_url(),
1424  'elgg.config.message_delay' => $message_delay * 1000,
1425 
1426  // refresh token 3 times during its lifetime (in microseconds 1000 * 1/3)
1427  'elgg.security.interval' => (int) _elgg_services()->csrf->getActionTokenTimeout() * 333,
1428  'elgg.config.language' => _elgg_services()->config->language ?: 'en',
1429  ];
1430 }
1431 
1439  $data = elgg_trigger_plugin_hook('elgg.data', 'page', null, []);
1440  if (!is_array($data)) {
1441  elgg_log('"elgg.data" plugin hook handlers must return an array. Returned ' . gettype($data) . '.', 'ERROR');
1442  $data = [];
1443  }
1444 
1445  $elgg = [
1446  'config' => [
1447  'lastcache' => (int) _elgg_services()->config->lastcache,
1448  'viewtype' => elgg_get_viewtype(),
1449  'simplecache_enabled' => (int) elgg_is_simplecache_enabled(),
1450  'current_language' => elgg_get_current_language(),
1451  ],
1452  'security' => [
1453  'token' => [
1454  '__elgg_ts' => $ts = _elgg_services()->csrf->getCurrentTime()->getTimestamp(),
1455  '__elgg_token' => _elgg_services()->csrf->generateActionToken($ts),
1456  ],
1457  ],
1458  'session' => [
1459  'user' => null,
1460  'token' => _elgg_services()->session->get('__elgg_session'),
1461  ],
1462  '_data' => (object) $data,
1463  ];
1464 
1466  if ($page_owner instanceof ElggEntity) {
1467  $elgg['page_owner'] = $page_owner->toObject(); // @todo remove in Elgg 5.0
1468  }
1469 
1471  if ($user instanceof ElggUser) {
1472  $user_object = $user->toObject();
1473  $user_object->admin = $user->isAdmin();
1474  $elgg['session']['user'] = $user_object; // @todo remove in Elgg 5.0
1475 
1476  $elgg['user'] = (array) $user_object;
1477  }
1478 
1479  return $elgg;
1480 }
1481 
1494  $current_view_type = null;
1495  if ($viewtype) {
1496  $current_view_type = elgg_get_viewtype();
1498  }
1499 
1500  $ret = elgg_view($view, $vars);
1501 
1502  if (isset($current_view_type)) {
1503  elgg_set_viewtype($current_view_type);
1504  }
1505 
1506  return $ret;
1507 }
1508 
1519 function elgg_view_url(string $href, string $text = null, array $options = []): string {
1520  $options['is_trusted'] = elgg_extract('is_trusted', $options, true);
1521  $options['href'] = $href;
1522  $options['text'] = $text;
1523 
1524  return elgg_view('output/url', $options);
1525 }
1526 
1536 function elgg_view_entity_url(\ElggEntity $entity, array $options = []): string {
1537  return elgg_view_url($entity->getURL(), $entity->getDisplayName(), $options);
1538 }
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:1361
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:1149
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:1244
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:1413
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:1083
$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:929
_elgg_has_rss_link()
Should the RSS view of this URL be linked to?
Definition: views.php:1345
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:1438
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:971
elgg_view_list_item($item, array $vars=[])
View an item in a list.
Definition: views.php:1272
$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:986
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:1070
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:950
$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:1519
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:1303
_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:1335
_elgg_view_under_viewtype($view, $vars, $viewtype)
Render a view while the global viewtype is temporarily changed.
Definition: views.php:1493
$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:1106
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:1536
$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:1091
elgg_register_rss_link()
Include the RSS icon link and link element in the head.
Definition: views.php:1326
elgg_unextend_view($view, $view_extension)
Unextends a view.
Definition: views.php:223