Elgg  Version 1.11
views.php
Go to the documentation of this file.
1 <?php
57 
70 function elgg_set_viewtype($viewtype = "") {
72 
73  $CURRENT_SYSTEM_VIEWTYPE = $viewtype;
74 
75  return true;
76 }
77 
91 function elgg_get_viewtype() {
93 
94  if ($CURRENT_SYSTEM_VIEWTYPE != "") {
96  }
97 
98  $viewtype = get_input('view', '', false);
100  return $viewtype;
101  }
102 
103  if (isset($CONFIG->view) && _elgg_is_valid_viewtype($CONFIG->view)) {
104  return $CONFIG->view;
105  }
106 
107  return 'default';
108 }
109 
117  global $CONFIG;
118 
119  if (!isset($CONFIG->view_types) || !is_array($CONFIG->view_types)) {
120  $CONFIG->view_types = array();
121  }
122 
123  if (!in_array($viewtype, $CONFIG->view_types)) {
124  $CONFIG->view_types[] = $viewtype;
125  }
126 
127  return true;
128 }
129 
139  global $CONFIG;
140 
141  if (!isset($CONFIG->view_types) || !is_array($CONFIG->view_types)) {
142  return false;
143  }
144 
145  return in_array($viewtype, $CONFIG->view_types);
146 }
147 
148 
159  if (!is_string($viewtype) || $viewtype === '') {
160  return false;
161  }
162 
163  if (preg_match('/\W/', $viewtype)) {
164  return false;
165  }
166 
167  return true;
168 }
169 
182  _elgg_services()->views->registerViewtypeFallback($viewtype);
183 }
184 
194  return _elgg_services()->views->doesViewtypeFallback($viewtype);
195 }
196 
210 }
211 
221 }
222 
231 function elgg_register_external_view($view, $cacheable = false) {
232  global $CONFIG;
233 
234  if (!isset($CONFIG->allowed_ajax_views)) {
235  $CONFIG->allowed_ajax_views = array();
236  }
237 
238  $CONFIG->allowed_ajax_views[$view] = true;
239 
240  if ($cacheable) {
241  _elgg_services()->views->registerCacheableView($view);
242  }
243 }
244 
254  return _elgg_services()->views->isCacheableView($view);
255 }
256 
265  global $CONFIG;
266 
267  if (isset($CONFIG->allowed_ajax_views[$view])) {
268  unset($CONFIG->allowed_ajax_views[$view]);
269  }
270 }
271 
284  return _elgg_services()->views->getViewLocation($view, $viewtype);
285 }
286 
303 function elgg_set_view_location($view, $location, $viewtype = '') {
304  _elgg_services()->views->setViewLocation($view, $location, $viewtype);
305 }
306 
318 function elgg_view_exists($view, $viewtype = '', $recurse = true) {
319  return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
320 }
321 
354 function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $viewtype = '') {
355  return _elgg_services()->views->renderView($view, $vars, $bypass, $viewtype);
356 }
357 
371 function elgg_view_deprecated($view, array $vars, $suggestion, $version) {
372  return _elgg_services()->views->renderDeprecatedView($view, $vars, $suggestion, $version);
373 }
374 
401 function elgg_extend_view($view, $view_extension, $priority = 501, $viewtype = '') {
402  _elgg_services()->views->extendView($view, $view_extension, $priority, $viewtype);
403 }
404 
414 function elgg_unextend_view($view, $view_extension) {
415  return _elgg_services()->views->unextendView($view, $view_extension);
416 }
417 
437 function elgg_view_page($title, $body, $page_shell = 'default', $vars = array()) {
438 
439  $params = array();
440  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
441  $params['segments'] = _elgg_services()->request->getUrlSegments();
442  array_shift($params['segments']);
443  $page_shell = elgg_trigger_plugin_hook('shell', 'page', $params, $page_shell);
444 
445  $system_messages = _elgg_services()->systemMessages;
446 
447  $messages = null;
448  if ($system_messages->count()) {
449  $messages = $system_messages->dumpRegister();
450 
451  if (isset($messages['error'])) {
452  // always make sure error is the first type
453  $errors = array(
454  'error' => $messages['error']
455  );
456 
457  unset($messages['error']);
458  $messages = array_merge($errors, $messages);
459  }
460  }
461 
462  $vars['title'] = $title;
463  $vars['body'] = $body;
464  $vars['sysmessages'] = $messages;
465 
466  // head has keys 'title', 'metas', 'links'
467  $head_params = _elgg_views_prepare_head($title);
468 
469  $vars['head'] = elgg_trigger_plugin_hook('head', 'page', $vars, $head_params);
470 
471  $vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars);
472 
473  // check for deprecated view
474  if ($page_shell == 'default' && elgg_view_exists('pageshells/pageshell')) {
475  elgg_deprecated_notice("pageshells/pageshell is deprecated by page/$page_shell", 1.8);
476  $output = elgg_view('pageshells/pageshell', $vars);
477  } else {
478  $output = elgg_view("page/$page_shell", $vars);
479  }
480 
481  $vars['page_shell'] = $page_shell;
482 
483  // Allow plugins to modify the output
484  return elgg_trigger_plugin_hook('output', 'page', $vars, $output);
485 }
486 
495  $params = array(
496  'links' => array(),
497  'metas' => array(),
498  );
499 
500  if (empty($title)) {
501  $params['title'] = elgg_get_config('sitename');
502  } else {
503  $params['title'] = $title . ' : ' . elgg_get_config('sitename');
504  }
505 
506  $params['metas']['content-type'] = array(
507  'http-equiv' => 'Content-Type',
508  'content' => 'text/html; charset=utf-8',
509  );
510 
511  $params['metas']['description'] = array(
512  'name' => 'description',
513  'content' => elgg_get_config('sitedescription')
514  );
515 
516  // https://developer.chrome.com/multidevice/android/installtohomescreen
517  $params['metas']['viewport'] = array(
518  'name' => 'viewport',
519  'content' => 'width=device-width',
520  );
521  $params['metas']['mobile-web-app-capable'] = array(
522  'name' => 'mobile-web-app-capable',
523  'content' => 'yes',
524  );
525  $params['metas']['apple-mobile-web-app-capable'] = array(
526  'name' => 'apple-mobile-web-app-capable',
527  'content' => 'yes',
528  );
529  $params['links']['apple-touch-icon'] = array(
530  'rel' => 'apple-touch-icon',
531  'href' => elgg_normalize_url('_graphics/favicon-128.png'),
532  );
533 
534  // favicons
535  $params['links']['icon-ico'] = array(
536  'rel' => 'icon',
537  'href' => elgg_normalize_url('_graphics/favicon.ico'),
538  );
539  $params['links']['icon-vector'] = array(
540  'rel' => 'icon',
541  'sizes' => '16x16 32x32 48x48 64x64 128x128',
542  'type' => 'image/svg+xml',
543  'href' => elgg_normalize_url('_graphics/favicon.svg'),
544  );
545  $params['links']['icon-16'] = array(
546  'rel' => 'icon',
547  'sizes' => '16x16',
548  'type' => 'image/png',
549  'href' => elgg_normalize_url('_graphics/favicon-16.png'),
550  );
551  $params['links']['icon-32'] = array(
552  'rel' => 'icon',
553  'sizes' => '32x32',
554  'type' => 'image/png',
555  'href' => elgg_normalize_url('_graphics/favicon-32.png'),
556  );
557  $params['links']['icon-64'] = array(
558  'rel' => 'icon',
559  'sizes' => '64x64',
560  'type' => 'image/png',
561  'href' => elgg_normalize_url('_graphics/favicon-64.png'),
562  );
563  $params['links']['icon-128'] = array(
564  'rel' => 'icon',
565  'sizes' => '128x128',
566  'type' => 'image/png',
567  'href' => elgg_normalize_url('_graphics/favicon-128.png'),
568  );
569 
570  // RSS feed link
571  global $autofeed;
572  if (isset($autofeed) && $autofeed == true) {
574  if (substr_count($url,'?')) {
575  $url .= "&view=rss";
576  } else {
577  $url .= "?view=rss";
578  }
579  $params['links']['rss'] = array(
580  'rel' => 'alternative',
581  'type' => 'application/rss+xml',
582  'title' => 'RSS',
583  'href' => elgg_format_url($url),
584  );
585  }
586 
587  return $params;
588 }
589 
622 function elgg_view_layout($layout_name, $vars = array()) {
623 
624  $params = array();
625  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
626  $params['segments'] = _elgg_services()->request->getUrlSegments();
627  array_shift($params['segments']);
628  $layout_name = elgg_trigger_plugin_hook('layout', 'page', $params, $layout_name);
629 
630  if (is_string($vars) || $vars === null) {
631  elgg_deprecated_notice("The use of unlimited optional string arguments in elgg_view_layout() was deprecated in favor of an options array", 1.8);
632  $arg = 1;
633  $param_array = array();
634  while ($arg < func_num_args()) {
635  $param_array['area' . $arg] = func_get_arg($arg);
636  $arg++;
637  }
638  } else {
639  $param_array = $vars;
640  }
641  $param_array['layout'] = $layout_name;
642 
643  $params = elgg_trigger_plugin_hook('output:before', 'layout', null, $param_array);
644 
645  // check deprecated location
646  if (elgg_view_exists("canvas/layouts/$layout_name")) {
647  elgg_deprecated_notice("canvas/layouts/$layout_name is deprecated by page/layouts/$layout_name", 1.8);
648  $output = elgg_view("canvas/layouts/$layout_name", $params);
649  } elseif (elgg_view_exists("page/layouts/$layout_name")) {
650  $output = elgg_view("page/layouts/$layout_name", $params);
651  } else {
652  $output = elgg_view("page/layouts/default", $params);
653  }
654 
655  return elgg_trigger_plugin_hook('output:after', 'layout', $params, $output);
656 }
657 
692 function elgg_view_menu($menu_name, array $vars = array()) {
693  global $CONFIG;
694 
695  $vars['name'] = $menu_name;
696 
697  $vars = elgg_trigger_plugin_hook('parameters', "menu:$menu_name", $vars, $vars);
698 
699  $sort_by = elgg_extract('sort_by', $vars, 'text');
700 
701  if (isset($CONFIG->menus[$menu_name])) {
702  $menu = $CONFIG->menus[$menu_name];
703  } else {
704  $menu = array();
705  }
706 
707  // Give plugins a chance to add menu items just before creation.
708  // This supports dynamic menus (example: user_hover).
709  $menu = elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, $menu);
710 
711  $builder = new \ElggMenuBuilder($menu);
712  $vars['menu'] = $builder->getMenu($sort_by);
713  $vars['selected_item'] = $builder->getSelected();
714 
715  // Let plugins modify the menu
716  $vars['menu'] = elgg_trigger_plugin_hook('prepare', "menu:$menu_name", $vars, $vars['menu']);
717 
718  if (elgg_view_exists("navigation/menu/$menu_name")) {
719  return elgg_view("navigation/menu/$menu_name", $vars);
720  } else {
721  return elgg_view("navigation/menu/default", $vars);
722  }
723 }
724 
733 function elgg_view_menu_item(\ElggMenuItem $item, array $vars = array()) {
734  if (!isset($vars['class'])) {
735  $vars['class'] = 'elgg-menu-content';
736  }
737 
738  $vars = array_merge($item->getValues(), $vars);
739 
740  if ($item->getLinkClass()) {
741  $vars['class'] .= ' ' . $item->getLinkClass();
742  }
743 
744  if ($item->getHref() === false || $item->getHref() === null) {
745  $text = $item->getText();
746 
747  // if contains elements, don't wrap
748  if (preg_match('~<[a-z]~', $text)) {
749  return $text;
750  } else {
751  return elgg_format_element('span', array('class' => 'elgg-non-link'), $text);
752  }
753  }
754 
755  if (!isset($vars['rel']) && !isset($vars['is_trusted'])) {
756  $vars['is_trusted'] = true;
757  }
758 
759  if ($item->getConfirmText()) {
760  $vars['confirm'] = $item->getConfirmText();
761  }
762 
763  return elgg_view('output/url', $vars);
764 }
765 
793 function elgg_view_entity(\ElggEntity $entity, $vars = array(), $bypass = false, $debug = false) {
794 
795  // No point continuing if entity is null
796  if (!$entity || !($entity instanceof \ElggEntity)) {
797  return false;
798  }
799 
800  global $autofeed;
801  $autofeed = true;
802 
803  $defaults = array(
804  'full_view' => true,
805  );
806 
807  if (is_array($vars)) {
808  $vars = array_merge($defaults, $vars);
809  } else {
810  elgg_deprecated_notice("Update your use of elgg_view_entity()", 1.8);
811  $vars = array(
812  'full_view' => $vars,
813  );
814  }
815 
816  $vars['entity'] = $entity;
817 
818  $entity_type = $entity->getType();
819  $entity_subtype = $entity->getSubtype();
820  if (empty($entity_subtype)) {
821  $entity_subtype = 'default';
822  }
823 
824  $entity_views = array(
825  elgg_extract('item_view', $vars, ''),
826  $entity->view,
827  "$entity_type/$entity_subtype",
828  "$entity_type/default",
829  );
830 
831  $contents = '';
832  foreach ($entity_views as $view) {
833  if (elgg_view_exists($view)) {
834  $contents = elgg_view($view, $vars, $bypass, $debug);
835  break;
836  }
837  }
838 
839  // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
840  if ($vars['full_view']) {
841  $annotations = elgg_view_entity_annotations($entity, $vars['full_view']);
842 
843  if ($annotations) {
845  }
846  }
847  return $contents;
848 }
849 
865 function elgg_view_entity_icon(\ElggEntity $entity, $size = 'medium', $vars = array()) {
866 
867  // No point continuing if entity is null
868  if (!$entity || !($entity instanceof \ElggEntity)) {
869  return false;
870  }
871 
872  $vars['entity'] = $entity;
873  $vars['size'] = $size;
874 
875  $entity_type = $entity->getType();
876 
877  $subtype = $entity->getSubtype();
878  if (empty($subtype)) {
879  $subtype = 'default';
880  }
881 
882  $contents = '';
883  if (elgg_view_exists("icon/$entity_type/$subtype")) {
884  $contents = elgg_view("icon/$entity_type/$subtype", $vars);
885  }
886  if (empty($contents)) {
887  $contents = elgg_view("icon/$entity_type/default", $vars);
888  }
889  if (empty($contents)) {
890  $contents = elgg_view("icon/default", $vars);
891  }
892 
893  return $contents;
894 }
895 
917 function elgg_view_annotation(\ElggAnnotation $annotation, array $vars = array(), $bypass = false, $debug = false) {
918  global $autofeed;
919  $autofeed = true;
920 
921  $defaults = array(
922  'full_view' => true,
923  );
924 
925  $vars = array_merge($defaults, $vars);
926  $vars['annotation'] = $annotation;
927 
928  // @todo setting the view on an annotation is not advertised anywhere
929  // do we want to keep this?
930  $view = $annotation->view;
931  if (is_string($view)) {
932  return elgg_view($view, $vars, $bypass, $debug);
933  }
934 
935  $name = $annotation->name;
936  if (empty($name)) {
937  return false;
938  }
939 
940  $annotation_views = array(
941  elgg_extract('item_view', $vars, ''),
942  "annotation/$name",
943  "annotation/default",
944  );
945 
946  $contents = '';
947  foreach ($annotation_views as $view) {
948  if (elgg_view_exists($view)) {
949  $contents = elgg_view($view, $vars, $bypass, $debug);
950  break;
951  }
952  }
953 
954  return $contents;
955 }
956 
984 function elgg_view_entity_list($entities, $vars = array(), $offset = 0, $limit = null, $full_view = true,
985 $list_type_toggle = true, $pagination = true) {
986 
987  if (!is_int($offset)) {
988  $offset = (int)get_input('offset', 0);
989  }
990 
991  // list type can be passed as request parameter
992  $list_type = get_input('list_type', 'list');
993  if (get_input('listtype')) {
994  elgg_deprecated_notice("'listtype' has been deprecated by 'list_type' for lists", 1.8);
995  $list_type = get_input('listtype');
996  }
997 
998  if (is_array($vars)) {
999  // new function
1000  $defaults = array(
1001  'items' => $entities,
1002  'list_class' => 'elgg-list-entity',
1003  'full_view' => true,
1004  'pagination' => true,
1005  'list_type' => $list_type,
1006  'list_type_toggle' => false,
1007  'offset' => $offset,
1008  'limit' => null,
1009  );
1010 
1011  $vars = array_merge($defaults, $vars);
1012 
1013  } else {
1014  // old function parameters
1015  elgg_deprecated_notice("Please update your use of elgg_view_entity_list()", 1.8);
1016 
1017  if ($limit === null) {
1018  $limit = elgg_get_config('default_limit');
1019  }
1020 
1021  $vars = array(
1022  'items' => $entities,
1023  'count' => (int) $vars, // the old count parameter
1024  'offset' => $offset,
1025  'limit' => (int) $limit,
1026  'full_view' => $full_view,
1027  'pagination' => $pagination,
1028  'list_type' => $list_type,
1029  'list_type_toggle' => $list_type_toggle,
1030  'list_class' => 'elgg-list-entity',
1031  );
1032  }
1033 
1034  if (!$vars["limit"] && !$vars["offset"]) {
1035  // no need for pagination if listing is unlimited
1036  $vars["pagination"] = false;
1037  }
1038 
1039  if ($vars['list_type'] != 'list') {
1040  return elgg_view('page/components/gallery', $vars);
1041  } else {
1042  return elgg_view('page/components/list', $vars);
1043  }
1044 }
1045 
1064 function elgg_view_annotation_list($annotations, array $vars = array()) {
1065  $defaults = array(
1066  'items' => $annotations,
1067  'offset' => null,
1068  'limit' => null,
1069  'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9
1070  'full_view' => true,
1071  'offset_key' => 'annoff',
1072  );
1073 
1074  $vars = array_merge($defaults, $vars);
1075 
1076  if (!$vars["limit"] && !$vars["offset"]) {
1077  // no need for pagination if listing is unlimited
1078  $vars["pagination"] = false;
1079  }
1080 
1081  return elgg_view('page/components/list', $vars);
1082 }
1083 
1099  if (!($entity instanceof \ElggEntity)) {
1100  return false;
1101  }
1102 
1103  $entity_type = $entity->getType();
1104 
1105  $annotations = elgg_trigger_plugin_hook('entity:annotate', $entity_type,
1106  array(
1107  'entity' => $entity,
1108  'full_view' => $full_view,
1109  )
1110  );
1111 
1112  return $annotations;
1113 }
1114 
1125 function elgg_view_title($title, $vars = array()) {
1126  if (!is_array($vars)) {
1127  elgg_deprecated_notice('setting $submenu in elgg_view_title() is deprecated', 1.8);
1128  $vars = array('submenu' => $vars);
1129  }
1130 
1131  $vars['title'] = $title;
1132 
1133  return elgg_view('page/elements/title', $vars);
1134 }
1135 
1146 function elgg_view_friendly_time($time) {
1147  return elgg_view('output/friendlytime', array('time' => $time));
1148 }
1149 
1150 
1164 function elgg_view_comments($entity, $add_comment = true, array $vars = array()) {
1165  if (!($entity instanceof \ElggEntity)) {
1166  return false;
1167  }
1168 
1169  $vars['entity'] = $entity;
1170  $vars['show_add_form'] = $add_comment;
1171  $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
1172 
1173  $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
1174  if ($output) {
1175  return $output;
1176  } else {
1177  return elgg_view('page/elements/comments', $vars);
1178  }
1179 }
1180 
1196 function elgg_view_image_block($image, $body, $vars = array()) {
1197  $vars['image'] = $image;
1198  $vars['body'] = $body;
1199  return elgg_view('page/components/image_block', $vars);
1200 }
1201 
1217 function elgg_view_module($type, $title, $body, array $vars = array()) {
1218  $vars['type'] = $type;
1219  $vars['class'] = elgg_extract('class', $vars, '');
1220  $vars['title'] = $title;
1221  $vars['body'] = $body;
1222  return elgg_view('page/components/module', $vars);
1223 }
1224 
1233 function elgg_view_river_item($item, array $vars = array()) {
1234  if (!($item instanceof \ElggRiverItem)) {
1235  return '';
1236  }
1237  // checking default viewtype since some viewtypes do not have unique views per item (rss)
1238  $view = $item->getView();
1239  if (!$view || !elgg_view_exists($view, 'default')) {
1240  return '';
1241  }
1242 
1243  $subject = $item->getSubjectEntity();
1244  $object = $item->getObjectEntity();
1245  if (!$subject || !$object) {
1246  // subject is disabled or subject/object deleted
1247  return '';
1248  }
1249 
1250  // @todo this needs to be cleaned up
1251  // Don't hide objects in closed groups that a user can see.
1252  // see https://github.com/elgg/elgg/issues/4789
1253  // else {
1254  // // hide based on object's container
1255  // $visibility = \Elgg\GroupItemVisibility::factory($object->container_guid);
1256  // if ($visibility->shouldHideItems) {
1257  // return '';
1258  // }
1259  // }
1260 
1261  $vars['item'] = $item;
1262 
1263  $river_views = array(
1264  elgg_extract('item_view', $vars, ''),
1265  "river/item",
1266  );
1267 
1268  $contents = '';
1269  foreach ($river_views as $view) {
1270  if (elgg_view_exists($view)) {
1271  $contents = elgg_view($view, $vars);
1272  break;
1273  }
1274  }
1275 
1276  return $contents;
1277 }
1278 
1313 function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
1314  global $CONFIG;
1315 
1316  $defaults = array(
1317  'action' => $CONFIG->wwwroot . "action/$action",
1318  'body' => elgg_view("forms/$action", $body_vars)
1319  );
1320 
1321  $form_class = 'elgg-form-' . preg_replace('/[^a-z0-9]/i', '-', $action);
1322 
1323  // append elgg-form class to any class options set
1324  if (isset($form_vars['class'])) {
1325  $form_vars['class'] = $form_vars['class'] . " $form_class";
1326  } else {
1327  $form_vars['class'] = $form_class;
1328  }
1329 
1330  $form_vars = array_merge($defaults, $form_vars);
1331  $form_vars['action_name'] = $action;
1332 
1333  return elgg_view('input/form', $form_vars);
1334 }
1335 
1350 function elgg_view_tagcloud(array $options = array()) {
1351 
1352  $type = $subtype = '';
1353  if (isset($options['type'])) {
1354  $type = $options['type'];
1355  }
1356  if (isset($options['subtype'])) {
1357  $subtype = $options['subtype'];
1358  }
1359 
1360  $tag_data = elgg_get_tags($options);
1361  return elgg_view("output/tagcloud", array(
1362  'value' => $tag_data,
1363  'type' => $type,
1364  'subtype' => $subtype,
1365  ));
1366 }
1367 
1378 function elgg_view_list_item($item, array $vars = array()) {
1379 
1380  if ($item instanceof \ElggEntity) {
1381  return elgg_view_entity($item, $vars);
1382  } else if ($item instanceof \ElggAnnotation) {
1383  return elgg_view_annotation($item, $vars);
1384  } else if ($item instanceof \ElggRiverItem) {
1385  return elgg_view_river_item($item, $vars);
1386  }
1387 
1388  return '';
1389 }
1390 
1403 function elgg_view_icon($name, $vars = array()) {
1404  if (empty($vars)) {
1405  $vars = array();
1406  }
1407 
1408  if ($vars === true) {
1409  elgg_deprecated_notice("Using a boolean to float the icon is deprecated. Use the class float.", 1.9);
1410  $vars = array('class' => 'float');
1411  }
1412 
1413  if (is_string($vars)) {
1414  $vars = array('class' => $vars);
1415  }
1416 
1417  if (!is_array($vars)) {
1418  throw new \InvalidArgumentException('$vars needs to be a string or an array');
1419  }
1420 
1421  if (!array_key_exists('class', $vars)) {
1422  $vars['class'] = array();
1423  }
1424 
1425  if (!is_array($vars['class'])) {
1426  $vars['class'] = array($vars['class']);
1427  }
1428 
1429  $vars['class'][] = "elgg-icon-$name";
1430 
1431  return elgg_view("output/icon", $vars);
1432 }
1433 
1444  if ($collections = get_user_access_collections($owner_guid)) {
1446  if ($user) {
1447  $entities = $user->getFriends(array('limit' => 0));
1448  } else {
1449  $entities = array();
1450  }
1451 
1452  foreach ($collections as $key => $collection) {
1453  $collections[$key]->members = get_members_of_access_collection($collection->id, true);
1454  $collections[$key]->entities = $entities;
1455  }
1456  }
1457 
1458  return elgg_view('core/friends/collections', array('collections' => $collections));
1459 }
1460 
1481 function set_template_handler($function_name) {
1482  global $CONFIG;
1483 
1484  if (is_callable($function_name)) {
1485  $CONFIG->template_handler = $function_name;
1486  return true;
1487  }
1488  return false;
1489 }
1490 
1508 function autoregister_views($view_base, $folder, $base_location_path, $viewtype) {
1509  return _elgg_services()->views->autoregisterViews($view_base, $folder, $base_location_path, $viewtype);
1510 }
1511 
1524  if (preg_match('~[\.-]min\.~', $params['view'])) {
1525  // bypass minification
1526  return;
1527  }
1528 
1529  if ($type == 'js') {
1530  if (elgg_get_config('simplecache_minify_js')) {
1531  return JSMin::minify($content);
1532  }
1533  } elseif ($type == 'css') {
1534  if (elgg_get_config('simplecache_minify_css')) {
1535  $cssmin = new CSSmin();
1536  return $cssmin->run($content);
1537  }
1538  }
1539 }
1540 
1541 
1554  $filter = new \Elgg\Amd\ViewFilter();
1555  return $filter->filter($params['view'], $content);
1556 }
1557 
1565  global $autofeed;
1566  if (isset($autofeed) && $autofeed == true) {
1567  $url = current_page_url();
1568  if (substr_count($url, '?')) {
1569  $url .= "&view=rss";
1570  } else {
1571  $url .= "?view=rss";
1572  }
1573 
1575  elgg_register_menu_item('extras', array(
1576  'name' => 'rss',
1577  'text' => elgg_view_icon('rss'),
1578  'href' => $url,
1579  'title' => elgg_echo('feed:rss'),
1580  ));
1581  }
1582 }
1583 
1590  header('X-Frame-Options: SAMEORIGIN');
1591 }
1592 
1599  $removed_views = array(
1600  "1.10" => array(
1601  'core/settings/tools',
1602  ),
1603  );
1604 
1605  $views_svc = _elgg_services()->views;
1606  foreach ($removed_views as $version => $names) {
1607  foreach ($names as $name) {
1608  if ($views_svc->viewExists($name)) {
1609  elgg_deprecated_notice("The view $name is no longer used and should not be provided or extended.", $version);
1610  }
1611  }
1612  }
1613 }
1614 
1622  $location = elgg_get_view_location('page_elements/contentwrapper');
1623  if ($location === "/var/www/views/") {
1624  elgg_extend_view('page_elements/contentwrapper', 'page/elements/wrapper');
1625  }
1626 }
1627 
1636 function elgg_views_boot() {
1637  global $CONFIG;
1638 
1640 
1641  elgg_register_simplecache_view('js/text.js');
1642 
1643  elgg_register_js('elgg.require_config', elgg_get_simplecache_url('js', 'elgg/require_config'), 'head');
1644  elgg_register_js('require', '/vendors/requirejs/require-2.1.10.min.js', 'head');
1645  elgg_register_js('jquery', '/vendors/jquery/jquery-1.11.0.min.js', 'head');
1646  elgg_register_js('jquery-migrate', '/vendors/jquery/jquery-migrate-1.2.1.min.js', 'head');
1647  elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.10.4.min.js', 'head');
1648 
1649  // this is the only lib that isn't required to be loaded sync in head
1650  elgg_define_js('jquery.form', array(
1651  'src' => '/vendors/jquery/jquery.form.min.js',
1652  'deps' => array('jquery'),
1653  'exports' => 'jQuery.fn.ajaxForm',
1654  ));
1655  elgg_define_js('jquery.ui', array(
1656  'src' => '/vendors/jquery/jquery-ui-1.10.4.min.js',
1657  'deps' => array('jquery'),
1658  ));
1659 
1660  $elgg_js_url = elgg_get_simplecache_url('js', 'elgg');
1661  elgg_register_js('elgg', $elgg_js_url, 'head');
1662 
1663  elgg_load_js('elgg.require_config');
1664  elgg_load_js('require');
1665  elgg_load_js('jquery');
1666  elgg_load_js('jquery-migrate');
1667  elgg_load_js('jquery-ui');
1668  elgg_load_js('elgg');
1669 
1670  $lightbox_js_url = elgg_get_simplecache_url('js', 'lightbox');
1671  elgg_register_js('lightbox', $lightbox_js_url);
1672 
1673  elgg_register_css('lightbox', 'vendors/jquery/colorbox/theme/colorbox.css');
1674 
1675  $elgg_css_url = elgg_get_simplecache_url('css', 'elgg');
1676  elgg_register_css('elgg', $elgg_css_url);
1677 
1678  elgg_load_css('elgg');
1679 
1680  elgg_register_ajax_view('js/languages');
1681 
1682  elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_amd');
1683  elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify');
1684  elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify');
1685 
1686  elgg_register_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link');
1687  elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options');
1688 
1689  // discover the core viewtypes
1690  // @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier
1691  $view_path = $CONFIG->viewpath;
1692  $viewtype_dirs = scandir($view_path);
1693  foreach ($viewtype_dirs as $viewtype) {
1694  if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) {
1695  elgg_register_viewtype($viewtype);
1696  }
1697  }
1698 
1699  // set default icon sizes - can be overridden in settings.php or with plugin
1700  if (!isset($CONFIG->icon_sizes)) {
1701  $icon_sizes = array(
1702  'topbar' => array('w' => 16, 'h' => 16, 'square' => true, 'upscale' => true),
1703  'tiny' => array('w' => 25, 'h' => 25, 'square' => true, 'upscale' => true),
1704  'small' => array('w' => 40, 'h' => 40, 'square' => true, 'upscale' => true),
1705  'medium' => array('w' => 100, 'h' => 100, 'square' => true, 'upscale' => true),
1706  'large' => array('w' => 200, 'h' => 200, 'square' => false, 'upscale' => false),
1707  'master' => array('w' => 550, 'h' => 550, 'square' => false, 'upscale' => false),
1708  );
1709  elgg_set_config('icon_sizes', $icon_sizes);
1710  }
1711 }
1712 
1713 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
1714  $events->registerHandler('boot', 'system', 'elgg_views_boot');
1715  $events->registerHandler('init', 'system', 'elgg_views_handle_deprecated_views');
1716  $events->registerHandler('ready', 'system', '_elgg_views_deprecate_removed_views');
1717 };
$messages
Definition: admin.php:27
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$view
Definition: crop.php:68
getSubtype()
Get the entity subtype.
elgg_is_registered_viewtype($viewtype)
Checks if $viewtype is registered.
Definition: views.php:138
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_get_tags(array $options=array())
Get popular tags and their frequencies.
Definition: tags.php:72
$subject
Definition: exceptions.php:25
_elgg_is_valid_viewtype($viewtype)
Checks if $viewtype is a string suitable for use as a viewtype name.
Definition: views.php:158
elgg_view_module($type, $title, $body, array $vars=array())
Wrapper function for the module display pattern.
Definition: views.php:1217
$annotation
Elgg default annotation view.
Definition: default.php:10
elgg_normalize_url($url)
Definition: output.php:311
elgg_view_icon($name, $vars=array())
View one of the elgg sprite icons.
Definition: views.php:1403
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
elgg_define_js($name, $config)
Defines a JS lib as an AMD module.
Definition: elgglib.php:152
if($footer) $contents
Definition: module.php:48
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:65
$size
Definition: view.php:10
set_template_handler($function_name)
Registers a function to handle templates.
Definition: views.php:1481
$object
Definition: upgrade.php:12
elgg_view_entity_annotations(\ElggEntity $entity, $full_view=true)
Display a plugin-specified rendered list of annotations for an entity.
Definition: views.php:1098
$defaults
elgg_view_tagcloud(array $options=array())
Create a tagcloud for viewing.
Definition: views.php:1350
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:98
$full_view
Elgg comment view.
Definition: comment.php:9
getLinkClass()
Get the anchor classes as text.
elgg_register_external_view($view, $cacheable=false)
Registers a view as being available externally (i.e.
Definition: views.php:231
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:318
elgg_register_css($name, $url, $priority=null)
Register a CSS file for inclusion in the HTML head.
Definition: elgglib.php:228
if(!$count) $offset
Definition: pagination.php:25
_elgg_views_amd($hook, $type, $content, $params)
Inserts module names into anonymous modules by handling the "simplecache:generate" hook...
Definition: views.php:1553
$pagination
Definition: gallery.php:22
elgg_view_annotation_list($annotations, array $vars=array())
Returns a rendered list of annotations, plus pagination.
Definition: views.php:1064
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:181
$collection
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1246
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:703
elgg_get_view_location($view, $viewtype= '')
Returns the file location for a view.
Definition: views.php:283
$url
Definition: exceptions.php:24
elgg_views_handle_deprecated_views()
Registers deprecated views to avoid making some pages from older plugins completely empty...
Definition: views.php:1621
elgg_unregister_external_view($view)
Unregister a view for ajax calls.
Definition: views.php:264
$title
Definition: save.php:24
$action
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:215
autoregister_views($view_base, $folder, $base_location_path, $viewtype)
Auto-registers views from a location.
Definition: views.php:1508
_elgg_views_deprecate_removed_views()
Checks for usage of core views that have been removed.
Definition: views.php:1598
$params
Definition: login.php:72
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1378
$options
Definition: index.php:14
$text
Definition: default.php:25
_elgg_views_minify($hook, $type, $content, $params)
Minifies simplecache CSS and JS views by handling the "simplecache:generate" hook.
Definition: views.php:1523
elgg_view_menu($menu_name, array $vars=array())
Render a menu.
Definition: views.php:692
$owner_guid
getConfirmText()
Get the confirm text.
get_user_access_collections($owner_guid, $site_guid=0)
Returns an array of database row objects of the access collections owned by $owner_guid.
Definition: access.php:405
elgg_unregister_ajax_view($view)
Unregister a view for ajax calls.
Definition: views.php:219
elgg_load_css($name)
Load a CSS file for this page.
Definition: elgglib.php:255
$limit
Definition: userpicker.php:31
elgg_register_js($name, $url, $location= 'head', $priority=null)
Register a JavaScript file for inclusion.
Definition: elgglib.php:127
elgg_set_viewtype($viewtype="")
Manually set the viewtype.
Definition: views.php:70
elgg_get_viewtype()
Return the current view type.
Definition: views.php:91
elgg_views_add_rss_link()
Add the rss link to the extras when if needed.
Definition: views.php:1564
elgg_view_annotation(\ElggAnnotation $annotation, array $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered annotation.
Definition: views.php:917
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_get_simplecache_url($type, $view)
Definition: cache.php:117
elgg_view_friendly_time($time)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:1146
$key
Definition: summary.php:34
get_user($guid)
Get a user object from a GUID.
Definition: users.php:87
elgg_set_view_location($view, $location, $viewtype= '')
Set an alternative base location for a view.
Definition: views.php:303
elgg_unextend_view($view, $view_extension)
Unextends a view.
Definition: views.php:414
get_members_of_access_collection($collection, $idonly=false)
Get all of members of an access collection.
Definition: access.php:418
elgg_view_image_block($image, $body, $vars=array())
Wrapper function for the image block display pattern.
Definition: views.php:1196
elgg_set_config($name, $value)
Set an Elgg configuration value.
_elgg_services()
Definition: autoloader.php:14
$item
Definition: item.php:12
global $CURRENT_SYSTEM_VIEWTYPE
The viewtype override.
Definition: views.php:55
elgg_does_viewtype_fallback($viewtype)
Checks if a viewtype falls back to default.
Definition: views.php:193
global $CONFIG
_elgg_is_view_cacheable($view)
Check whether a view is registered as cacheable.
Definition: views.php:253
if(!file_exists($filename)) $icon_sizes
Definition: crop.php:31
elgg_view_deprecated($view, array $vars, $suggestion, $version)
Display a view with a deprecation notice.
Definition: views.php:371
if(!$vars['title']&&$vars['title']!==false) if(isset($vars['filter_override'])) if(!isset($vars['filter'])&&elgg_is_logged_in()&&$context) $filter
Definition: content.php:62
elgg_extend_view($view, $view_extension, $priority=501, $viewtype= '')
Extends a view with another view.
Definition: views.php:401
$user
Definition: ban.php:13
$body_vars
$annotations
Definition: entity.php:20
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:775
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Log a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1006
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
elgg_register_menu_item($menu_name, $menu_item)
Register an item for an Elgg menu.
Definition: navigation.php:92
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
if(!elgg_instanceof($comment, 'object', 'comment')||!$comment->canEdit()) $form_vars
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:622
$builder
Definition: save.php:12
getText()
Get the display text of the menu item.
_elgg_views_send_header_x_frame_options()
Sends X-Frame-Options header on page requests.
Definition: views.php:1589
_elgg_views_prepare_head($title)
Prepare the variables for the html head.
Definition: views.php:494
elgg_view_menu_item(\ElggMenuItem $item, array $vars=array())
Render a menu item (usually as a link)
Definition: views.php:733
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:189
elgg_view_title($title, $vars=array())
Renders a title.
Definition: views.php:1125
getType()
Returns the entity type.
elgg_register_ajax_view($view)
Register a view to be available for ajax calls.
Definition: views.php:208
$content
Set robots.txt action.
Definition: set_robots.php:6
elgg_view_comments($entity, $add_comment=true, array $vars=array())
Returns rendered comments and a comment form for an entity.
Definition: views.php:1164
elgg_view_entity(\ElggEntity $entity, $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:793
elgg_format_url($url)
Handles formatting of ampersands in urls.
Definition: output.php:105
elgg_view_access_collections($owner_guid)
Displays a user&#39;s access collections, using the core/friends/collections view.
Definition: views.php:1443
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
Definition: views.php:437
$menu
Definition: default.php:19
clearfix elgg elgg elgg elgg page header
Definition: admin.php:127
$output
Definition: item.php:10
$entity
Definition: delete.php:10
elgg_view_entity_list($entities, $vars=array(), $offset=0, $limit=null, $full_view=true, $list_type_toggle=true, $pagination=true)
Returns a rendered list of entities with pagination.
Definition: views.php:984
$subtype
Definition: river.php:12
elgg_view_entity_icon(\ElggEntity $entity, $size= 'medium', $vars=array())
View the icon of an entity.
Definition: views.php:865
$version
Definition: version.php:14
elgg_view_form($action, $form_vars=array(), $body_vars=array())
Definition: views.php:1313
$viewtype
Definition: start.php:76
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades...
Definition: views.php:1636
$priority
getValues()
Get all the values for this menu item.
getHref()
Get the URL of the menu item.
if(file_exists($welcome)) $vars
Definition: upgrade.php:93
$image
Definition: upload.php:37
elgg_view_river_item($item, array $vars=array())
Renders a human-readable representation of a river item.
Definition: views.php:1233
elgg_register_viewtype($viewtype)
Register a viewtype.
Definition: views.php:116