Elgg  Version 1.9
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  $messages = null;
446  if (count_messages()) {
447  // get messages - try for errors first
448  $messages = system_messages(null, "error");
449  if (count($messages["error"]) == 0) {
450  // no errors so grab rest of messages
451  $messages = system_messages(null, "");
452  } else {
453  // we have errors - clear out remaining messages
454  system_messages(null, "");
455  }
456  }
457 
458  $vars['title'] = $title;
459  $vars['body'] = $body;
460  $vars['sysmessages'] = $messages;
461 
462  // head has keys 'title', 'metas', 'links'
463  $head_params = _elgg_views_prepare_head($title);
464  $vars['head'] = elgg_trigger_plugin_hook('head', 'page', $vars, $head_params);
465 
466  $vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars);
467 
468  // check for deprecated view
469  if ($page_shell == 'default' && elgg_view_exists('pageshells/pageshell')) {
470  elgg_deprecated_notice("pageshells/pageshell is deprecated by page/$page_shell", 1.8);
471  $output = elgg_view('pageshells/pageshell', $vars);
472  } else {
473  $output = elgg_view("page/$page_shell", $vars);
474  }
475 
476  $vars['page_shell'] = $page_shell;
477 
478  // Allow plugins to modify the output
479  return elgg_trigger_plugin_hook('output', 'page', $vars, $output);
480 }
481 
490  $params = array(
491  'links' => array(),
492  'metas' => array(),
493  );
494 
495  if (empty($title)) {
496  $params['title'] = elgg_get_config('sitename');
497  } else {
498  $params['title'] = $title . ' : ' . elgg_get_config('sitename');
499  }
500 
501  $params['metas'][] = array(
502  'http-equiv' => 'Content-Type',
503  'content' => 'text/html; charset=utf-8',
504  );
505 
506  $params['metas'][] = array(
507  'name' => 'description',
508  'content' => elgg_get_config('sitedescription')
509  );
510 
511  // https://developer.chrome.com/multidevice/android/installtohomescreen
512  $data['metas'][] = array(
513  'name' => 'viewport',
514  'content' => 'width=device-width',
515  );
516  $data['metas'][] = array(
517  'name' => 'mobile-web-app-capable',
518  'content' => 'yes',
519  );
520  $data['metas'][] = array(
521  'name' => 'apple-mobile-web-app-capable',
522  'content' => 'yes',
523  );
524  $data['links'][] = array(
525  'rel' => 'apple-touch-icon',
526  'href' => elgg_normalize_url('_graphics/favicon-128.png'),
527  );
528 
529  // favicons
530  $params['links'][] = array(
531  'rel' => 'icon',
532  'href' => elgg_normalize_url('_graphics/favicon.ico'),
533  );
534  $params['links'][] = array(
535  'rel' => 'icon',
536  'sizes' => '16x16 32x32 48x48 64x64 128x128',
537  'type' => 'image/svg+xml',
538  'href' => elgg_normalize_url('_graphics/favicon.svg'),
539  );
540  $params['links'][] = array(
541  'rel' => 'icon',
542  'sizes' => '16x16',
543  'type' => 'image/png',
544  'href' => elgg_normalize_url('_graphics/favicon-16.png'),
545  );
546  $params['links'][] = array(
547  'rel' => 'icon',
548  'sizes' => '32x32',
549  'type' => 'image/png',
550  'href' => elgg_normalize_url('_graphics/favicon-32.png'),
551  );
552  $params['links'][] = array(
553  'rel' => 'icon',
554  'sizes' => '64x64',
555  'type' => 'image/png',
556  'href' => elgg_normalize_url('_graphics/favicon-64.png'),
557  );
558  $params['links'][] = array(
559  'rel' => 'icon',
560  'sizes' => '128x128',
561  'type' => 'image/png',
562  'href' => elgg_normalize_url('_graphics/favicon-128.png'),
563  );
564 
565  // RSS feed link
566  global $autofeed;
567  if (isset($autofeed) && $autofeed == true) {
569  if (substr_count($url,'?')) {
570  $url .= "&view=rss";
571  } else {
572  $url .= "?view=rss";
573  }
574  $params['links'][] = array(
575  'rel' => 'alternative',
576  'type' => 'application/rss+xml',
577  'title' => 'RSS',
578  'href' => elgg_format_url($url),
579  );
580  }
581 
582  return $params;
583 }
584 
617 function elgg_view_layout($layout_name, $vars = array()) {
618 
619  $params = array();
620  $params['identifier'] = _elgg_services()->request->getFirstUrlSegment();
621  $params['segments'] = _elgg_services()->request->getUrlSegments();
622  array_shift($params['segments']);
623  $layout_name = elgg_trigger_plugin_hook('layout', 'page', $params, $layout_name);
624 
625  if (is_string($vars) || $vars === null) {
626  elgg_deprecated_notice("The use of unlimited optional string arguments in elgg_view_layout() was deprecated in favor of an options array", 1.8);
627  $arg = 1;
628  $param_array = array();
629  while ($arg < func_num_args()) {
630  $param_array['area' . $arg] = func_get_arg($arg);
631  $arg++;
632  }
633  } else {
634  $param_array = $vars;
635  }
636  $param_array['layout'] = $layout_name;
637 
638  $params = elgg_trigger_plugin_hook('output:before', 'layout', null, $param_array);
639 
640  // check deprecated location
641  if (elgg_view_exists("canvas/layouts/$layout_name")) {
642  elgg_deprecated_notice("canvas/layouts/$layout_name is deprecated by page/layouts/$layout_name", 1.8);
643  $output = elgg_view("canvas/layouts/$layout_name", $params);
644  } elseif (elgg_view_exists("page/layouts/$layout_name")) {
645  $output = elgg_view("page/layouts/$layout_name", $params);
646  } else {
647  $output = elgg_view("page/layouts/default", $params);
648  }
649 
650  return elgg_trigger_plugin_hook('output:after', 'layout', $params, $output);
651 }
652 
687 function elgg_view_menu($menu_name, array $vars = array()) {
688  global $CONFIG;
689 
690  $vars['name'] = $menu_name;
691 
692  $sort_by = elgg_extract('sort_by', $vars, 'text');
693 
694  if (isset($CONFIG->menus[$menu_name])) {
695  $menu = $CONFIG->menus[$menu_name];
696  } else {
697  $menu = array();
698  }
699 
700  // Give plugins a chance to add menu items just before creation.
701  // This supports dynamic menus (example: user_hover).
702  $menu = elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, $menu);
703 
705  $vars['menu'] = $builder->getMenu($sort_by);
706  $vars['selected_item'] = $builder->getSelected();
707 
708  // Let plugins modify the menu
709  $vars['menu'] = elgg_trigger_plugin_hook('prepare', "menu:$menu_name", $vars, $vars['menu']);
710 
711  if (elgg_view_exists("navigation/menu/$menu_name")) {
712  return elgg_view("navigation/menu/$menu_name", $vars);
713  } else {
714  return elgg_view("navigation/menu/default", $vars);
715  }
716 }
717 
726 function elgg_view_menu_item(ElggMenuItem $item, array $vars = array()) {
727  if (!isset($vars['class'])) {
728  $vars['class'] = 'elgg-menu-content';
729  }
730 
731  $vars = array_merge($item->getValues(), $vars);
732 
733  if ($item->getLinkClass()) {
734  $vars['class'] .= ' ' . $item->getLinkClass();
735  }
736 
737  if ($item->getHref() === false) {
738  $text = $item->getText();
739 
740  // if contains elements, don't wrap
741  if (preg_match('~<[a-z]~', $text)) {
742  return $text;
743  } else {
744  return elgg_format_element('span', array('class' => 'elgg-non-link'), $text);
745  }
746  }
747 
748  if (!isset($vars['rel']) && !isset($vars['is_trusted'])) {
749  $vars['is_trusted'] = true;
750  }
751 
752  if ($item->getConfirmText()) {
753  $vars['confirm'] = $item->getConfirmText();
754  return elgg_view('output/confirmlink', $vars);
755  } else {
756  unset($vars['confirm']);
757  }
758 
759  return elgg_view('output/url', $vars);
760 }
761 
790 function elgg_view_entity(ElggEntity $entity, $vars = array(), $bypass = false, $debug = false) {
791 
792  // No point continuing if entity is null
793  if (!$entity || !($entity instanceof ElggEntity)) {
794  return false;
795  }
796 
797  global $autofeed;
798  $autofeed = true;
799 
800  $defaults = array(
801  'full_view' => true,
802  );
803 
804  if (is_array($vars)) {
805  $vars = array_merge($defaults, $vars);
806  } else {
807  elgg_deprecated_notice("Update your use of elgg_view_entity()", 1.8);
808  $vars = array(
809  'full_view' => $vars,
810  );
811  }
812 
813  $vars['entity'] = $entity;
814 
815 
816  // if this entity has a view defined, use it
817  $view = $entity->view;
818  if (is_string($view)) {
819  return elgg_view($view, $vars, $bypass, $debug);
820  }
821 
822  $entity_type = $entity->getType();
823 
824  $subtype = $entity->getSubtype();
825  if (empty($subtype)) {
826  $subtype = 'default';
827  }
828 
829  $contents = '';
830  if (elgg_view_exists("$entity_type/$subtype")) {
831  $contents = elgg_view("$entity_type/$subtype", $vars, $bypass, $debug);
832  } else {
833  $contents = elgg_view("$entity_type/default", $vars, $bypass, $debug);
834  }
835 
836  // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
837  if ($vars['full_view']) {
838  $annotations = elgg_view_entity_annotations($entity, $vars['full_view']);
839 
840  if ($annotations) {
842  }
843  }
844  return $contents;
845 }
846 
862 function elgg_view_entity_icon(ElggEntity $entity, $size = 'medium', $vars = array()) {
863 
864  // No point continuing if entity is null
865  if (!$entity || !($entity instanceof ElggEntity)) {
866  return false;
867  }
868 
869  $vars['entity'] = $entity;
870  $vars['size'] = $size;
871 
872  $entity_type = $entity->getType();
873 
874  $subtype = $entity->getSubtype();
875  if (empty($subtype)) {
876  $subtype = 'default';
877  }
878 
879  $contents = '';
880  if (elgg_view_exists("icon/$entity_type/$subtype")) {
881  $contents = elgg_view("icon/$entity_type/$subtype", $vars);
882  }
883  if (empty($contents)) {
884  $contents = elgg_view("icon/$entity_type/default", $vars);
885  }
886  if (empty($contents)) {
887  $contents = elgg_view("icon/default", $vars);
888  }
889 
890  return $contents;
891 }
892 
913 function elgg_view_annotation(ElggAnnotation $annotation, array $vars = array(), $bypass = false, $debug = false) {
914  global $autofeed;
915  $autofeed = true;
916 
917  $defaults = array(
918  'full_view' => true,
919  );
920 
921  $vars = array_merge($defaults, $vars);
922  $vars['annotation'] = $annotation;
923 
924  // @todo setting the view on an annotation is not advertised anywhere
925  // do we want to keep this?
926  $view = $annotation->view;
927  if (is_string($view)) {
928  return elgg_view($view, $vars, $bypass, $debug);
929  }
930 
931  $name = $annotation->name;
932  if (empty($name)) {
933  return false;
934  }
935 
936  if (elgg_view_exists("annotation/$name")) {
937  return elgg_view("annotation/$name", $vars, $bypass, $debug);
938  } else {
939  return elgg_view("annotation/default", $vars, $bypass, $debug);
940  }
941 }
942 
969 function elgg_view_entity_list($entities, $vars = array(), $offset = 0, $limit = 10, $full_view = true,
970 $list_type_toggle = true, $pagination = true) {
971 
972  if (!is_int($offset)) {
973  $offset = (int)get_input('offset', 0);
974  }
975 
976  // list type can be passed as request parameter
977  $list_type = get_input('list_type', 'list');
978  if (get_input('listtype')) {
979  elgg_deprecated_notice("'listtype' has been deprecated by 'list_type' for lists", 1.8);
980  $list_type = get_input('listtype');
981  }
982 
983  if (is_array($vars)) {
984  // new function
985  $defaults = array(
986  'items' => $entities,
987  'list_class' => 'elgg-list-entity',
988  'full_view' => true,
989  'pagination' => true,
990  'list_type' => $list_type,
991  'list_type_toggle' => false,
992  'offset' => $offset,
993  'limit' => null,
994  );
995 
996  $vars = array_merge($defaults, $vars);
997 
998  } else {
999  // old function parameters
1000  elgg_deprecated_notice("Please update your use of elgg_view_entity_list()", 1.8);
1001 
1002  $vars = array(
1003  'items' => $entities,
1004  'count' => (int) $vars, // the old count parameter
1005  'offset' => $offset,
1006  'limit' => (int) $limit,
1007  'full_view' => $full_view,
1008  'pagination' => $pagination,
1009  'list_type' => $list_type,
1010  'list_type_toggle' => $list_type_toggle,
1011  'list_class' => 'elgg-list-entity',
1012  );
1013  }
1014 
1015  if (!$vars["limit"] && !$vars["offset"]) {
1016  // no need for pagination if listing is unlimited
1017  $vars["pagination"] = false;
1018  }
1019 
1020  if ($vars['list_type'] != 'list') {
1021  return elgg_view('page/components/gallery', $vars);
1022  } else {
1023  return elgg_view('page/components/list', $vars);
1024  }
1025 }
1026 
1044 function elgg_view_annotation_list($annotations, array $vars = array()) {
1045  $defaults = array(
1046  'items' => $annotations,
1047  'offset' => null,
1048  'limit' => null,
1049  'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9
1050  'full_view' => true,
1051  'offset_key' => 'annoff',
1052  );
1053 
1054  $vars = array_merge($defaults, $vars);
1055 
1056  if (!$vars["limit"] && !$vars["offset"]) {
1057  // no need for pagination if listing is unlimited
1058  $vars["pagination"] = false;
1059  }
1060 
1061  return elgg_view('page/components/list', $vars);
1062 }
1063 
1079  if (!($entity instanceof ElggEntity)) {
1080  return false;
1081  }
1082 
1083  $entity_type = $entity->getType();
1084 
1085  $annotations = elgg_trigger_plugin_hook('entity:annotate', $entity_type,
1086  array(
1087  'entity' => $entity,
1088  'full_view' => $full_view,
1089  )
1090  );
1091 
1092  return $annotations;
1093 }
1094 
1105 function elgg_view_title($title, $vars = array()) {
1106  if (!is_array($vars)) {
1107  elgg_deprecated_notice('setting $submenu in elgg_view_title() is deprecated', 1.8);
1108  $vars = array('submenu' => $vars);
1109  }
1110 
1111  $vars['title'] = $title;
1112 
1113  return elgg_view('page/elements/title', $vars);
1114 }
1115 
1126 function elgg_view_friendly_time($time) {
1127  return elgg_view('output/friendlytime', array('time' => $time));
1128 }
1129 
1130 
1144 function elgg_view_comments($entity, $add_comment = true, array $vars = array()) {
1145  if (!($entity instanceof ElggEntity)) {
1146  return false;
1147  }
1148 
1149  $vars['entity'] = $entity;
1150  $vars['show_add_form'] = $add_comment;
1151  $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
1152 
1153  $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
1154  if ($output) {
1155  return $output;
1156  } else {
1157  return elgg_view('page/elements/comments', $vars);
1158  }
1159 }
1160 
1176 function elgg_view_image_block($image, $body, $vars = array()) {
1177  $vars['image'] = $image;
1178  $vars['body'] = $body;
1179  return elgg_view('page/components/image_block', $vars);
1180 }
1181 
1197 function elgg_view_module($type, $title, $body, array $vars = array()) {
1198  $vars['type'] = $type;
1199  $vars['class'] = elgg_extract('class', $vars, '');
1200  $vars['title'] = $title;
1201  $vars['body'] = $body;
1202  return elgg_view('page/components/module', $vars);
1203 }
1204 
1213 function elgg_view_river_item($item, array $vars = array()) {
1214  if (!($item instanceof ElggRiverItem)) {
1215  return '';
1216  }
1217  // checking default viewtype since some viewtypes do not have unique views per item (rss)
1218  $view = $item->getView();
1219  if (!$view || !elgg_view_exists($view, 'default')) {
1220  return '';
1221  }
1222 
1223  $subject = $item->getSubjectEntity();
1224  $object = $item->getObjectEntity();
1225  if (!$subject || !$object) {
1226  // subject is disabled or subject/object deleted
1227  return '';
1228  }
1229 
1230  // @todo this needs to be cleaned up
1231  // Don't hide objects in closed groups that a user can see.
1232  // see https://github.com/elgg/elgg/issues/4789
1233  // else {
1234  // // hide based on object's container
1235  // $visibility = Elgg_GroupItemVisibility::factory($object->container_guid);
1236  // if ($visibility->shouldHideItems) {
1237  // return '';
1238  // }
1239  // }
1240 
1241  $vars['item'] = $item;
1242 
1243  return elgg_view('river/item', $vars);
1244 }
1245 
1280 function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
1281  global $CONFIG;
1282 
1283  $defaults = array(
1284  'action' => $CONFIG->wwwroot . "action/$action",
1285  'body' => elgg_view("forms/$action", $body_vars)
1286  );
1287 
1288  $form_class = 'elgg-form-' . preg_replace('/[^a-z0-9]/i', '-', $action);
1289 
1290  // append elgg-form class to any class options set
1291  if (isset($form_vars['class'])) {
1292  $form_vars['class'] = $form_vars['class'] . " $form_class";
1293  } else {
1294  $form_vars['class'] = $form_class;
1295  }
1296 
1297  $form_vars = array_merge($defaults, $form_vars);
1298  $form_vars['action_name'] = $action;
1299 
1300  return elgg_view('input/form', $form_vars);
1301 }
1302 
1317 function elgg_view_tagcloud(array $options = array()) {
1318 
1319  $type = $subtype = '';
1320  if (isset($options['type'])) {
1321  $type = $options['type'];
1322  }
1323  if (isset($options['subtype'])) {
1324  $subtype = $options['subtype'];
1325  }
1326 
1327  $tag_data = elgg_get_tags($options);
1328  return elgg_view("output/tagcloud", array(
1329  'value' => $tag_data,
1330  'type' => $type,
1331  'subtype' => $subtype,
1332  ));
1333 }
1334 
1345 function elgg_view_list_item($item, array $vars = array()) {
1346  global $CONFIG;
1347 
1348  $type = $item->getType();
1349  if (in_array($type, $CONFIG->entity_types)) {
1350  return elgg_view_entity($item, $vars);
1351  } else if ($type == 'annotation') {
1352  return elgg_view_annotation($item, $vars);
1353  } else if ($type == 'river') {
1354  return elgg_view_river_item($item, $vars);
1355  }
1356 
1357  return '';
1358 }
1359 
1370 function elgg_view_icon($name, $class = '') {
1371  if ($class === true) {
1372  elgg_deprecated_notice("Using a boolean to float the icon is deprecated. Use the class float.", 1.9);
1373  $class = 'float';
1374  }
1375 
1376  $icon_class = array("elgg-icon-$name" , $class);
1377 
1378  return elgg_view("output/icon", array("class" => $icon_class));
1379 }
1380 
1391  if ($collections = get_user_access_collections($owner_guid)) {
1393  if ($user) {
1394  $entities = $user->getFriends(array('limit' => 0));
1395  } else {
1396  $entities = array();
1397  }
1398 
1399  foreach ($collections as $key => $collection) {
1400  $collections[$key]->members = get_members_of_access_collection($collection->id, true);
1401  $collections[$key]->entities = $entities;
1402  }
1403  }
1404 
1405  return elgg_view('core/friends/collections', array('collections' => $collections));
1406 }
1407 
1428 function set_template_handler($function_name) {
1429  global $CONFIG;
1430 
1431  if (is_callable($function_name)) {
1432  $CONFIG->template_handler = $function_name;
1433  return true;
1434  }
1435  return false;
1436 }
1437 
1455 function autoregister_views($view_base, $folder, $base_location_path, $viewtype) {
1456  return _elgg_services()->views->autoregisterViews($view_base, $folder, $base_location_path, $viewtype);
1457 }
1458 
1471  static $autoload_registered;
1472  if (!$autoload_registered) {
1473  $path = elgg_get_root_path() . 'vendors/minify/lib';
1474  elgg_get_class_loader()->addFallback($path);
1475  $autoload_registered = true;
1476  }
1477 
1478  if (preg_match('~[\.-]min\.~', $params['view'])) {
1479  // bypass minification
1480  return;
1481  }
1482 
1483  if ($type == 'js') {
1484  if (elgg_get_config('simplecache_minify_js')) {
1485  return JSMin::minify($content);
1486  }
1487  } elseif ($type == 'css') {
1488  if (elgg_get_config('simplecache_minify_css')) {
1489  $cssmin = new CSSMin();
1490  return $cssmin->run($content);
1491  }
1492  }
1493 }
1494 
1495 
1508  $filter = new Elgg_Amd_ViewFilter();
1509  return $filter->filter($params['view'], $content);
1510 }
1511 
1519  global $autofeed;
1520  if (isset($autofeed) && $autofeed == true) {
1521  $url = current_page_url();
1522  if (substr_count($url, '?')) {
1523  $url .= "&view=rss";
1524  } else {
1525  $url .= "?view=rss";
1526  }
1527 
1529  elgg_register_menu_item('extras', array(
1530  'name' => 'rss',
1531  'text' => elgg_view_icon('rss'),
1532  'href' => $url,
1533  'title' => elgg_echo('feed:rss'),
1534  ));
1535  }
1536 }
1537 
1544  header('X-Frame-Options: SAMEORIGIN');
1545 }
1546 
1554  $location = elgg_get_view_location('page_elements/contentwrapper');
1555  if ($location === "/var/www/views/") {
1556  elgg_extend_view('page_elements/contentwrapper', 'page/elements/wrapper');
1557  }
1558 }
1559 
1568 function elgg_views_boot() {
1569  global $CONFIG;
1570 
1572  elgg_register_simplecache_view('css/ie7');
1573  elgg_register_simplecache_view('css/ie8');
1574 
1575  elgg_register_simplecache_view('js/text.js');
1576 
1577  elgg_register_js('elgg.require_config', elgg_get_simplecache_url('js', 'elgg/require_config'), 'head');
1578  elgg_register_js('require', '/vendors/requirejs/require-2.1.10.min.js', 'head');
1579  elgg_register_js('jquery', '/vendors/jquery/jquery-1.11.0.min.js', 'head');
1580  elgg_register_js('jquery-migrate', '/vendors/jquery/jquery-migrate-1.2.1.min.js', 'head');
1581  elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.10.4.min.js', 'head');
1582 
1583  // this is the only lib that isn't required to be loaded sync in head
1584  elgg_define_js('jquery.form', array(
1585  'src' => '/vendors/jquery/jquery.form.min.js',
1586  'deps' => array('jquery'),
1587  'exports' => 'jQuery.fn.ajaxForm',
1588  ));
1589 
1590  $elgg_js_url = elgg_get_simplecache_url('js', 'elgg');
1591  elgg_register_js('elgg', $elgg_js_url, 'head');
1592 
1593  elgg_load_js('elgg.require_config');
1594  elgg_load_js('require');
1595  elgg_load_js('jquery');
1596  elgg_load_js('jquery-migrate');
1597  elgg_load_js('jquery-ui');
1598  elgg_load_js('elgg');
1599 
1600  $lightbox_js_url = elgg_get_simplecache_url('js', 'lightbox');
1601  elgg_register_js('lightbox', $lightbox_js_url);
1602 
1603  elgg_register_css('lightbox', 'vendors/jquery/colorbox/theme/colorbox.css');
1604 
1605  $elgg_css_url = elgg_get_simplecache_url('css', 'elgg');
1606  elgg_register_css('elgg', $elgg_css_url);
1607 
1608  elgg_load_css('elgg');
1609 
1610  elgg_register_ajax_view('js/languages');
1611 
1612  elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_amd');
1613  elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify');
1614  elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify');
1615 
1616  elgg_register_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link');
1617  elgg_register_plugin_hook_handler('output:before', 'page', '_elgg_views_send_header_x_frame_options');
1618 
1619  // discover the core viewtypes
1620  // @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier
1621  $view_path = $CONFIG->viewpath;
1622  $viewtype_dirs = scandir($view_path);
1623  foreach ($viewtype_dirs as $viewtype) {
1624  if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) {
1625  elgg_register_viewtype($viewtype);
1626  }
1627  }
1628 
1629  // set default icon sizes - can be overridden in settings.php or with plugin
1630  if (!isset($CONFIG->icon_sizes)) {
1631  $icon_sizes = array(
1632  'topbar' => array('w' => 16, 'h' => 16, 'square' => true, 'upscale' => true),
1633  'tiny' => array('w' => 25, 'h' => 25, 'square' => true, 'upscale' => true),
1634  'small' => array('w' => 40, 'h' => 40, 'square' => true, 'upscale' => true),
1635  'medium' => array('w' => 100, 'h' => 100, 'square' => true, 'upscale' => true),
1636  'large' => array('w' => 200, 'h' => 200, 'square' => false, 'upscale' => false),
1637  'master' => array('w' => 550, 'h' => 550, 'square' => false, 'upscale' => false),
1638  );
1639  elgg_set_config('icon_sizes', $icon_sizes);
1640  }
1641 }
1642 
1643 elgg_register_event_handler('boot', 'system', 'elgg_views_boot');
1644 elgg_register_event_handler('init', 'system', 'elgg_views_handle_deprecated_views');
$messages
Definition: admin.php:27
elgg_get_class_loader()
Get Elgg&#39;s class loader.
Definition: autoloader.php:93
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$view
Definition: crop.php:68
getSubtype()
Get the entity subtype.
elgg_view_entity_annotations(ElggEntity $entity, $full_view=true)
Display a plugin-specified rendered list of annotations for an entity.
Definition: views.php:1078
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_view_icon($name, $class= '')
View one of the elgg sprite icons.
Definition: views.php:1370
elgg_view_entity(ElggEntity $entity, $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered entity.
Definition: views.php:790
elgg_get_tags(array $options=array())
Get popular tags and their frequencies.
Definition: tags.php:71
$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:1197
$annotation
Elgg default annotation view.
Definition: default.php:10
elgg_normalize_url($url)
Definition: output.php:290
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:153
if($footer) $contents
Definition: module.php:48
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:106
$size
Definition: view.php:10
set_template_handler($function_name)
Registers a function to handle templates.
Definition: views.php:1428
$object
Definition: upgrade.php:12
elgg_view_tagcloud(array $options=array())
Create a tagcloud for viewing.
Definition: views.php:1317
elgg_view_entity_list($entities, $vars=array(), $offset=0, $limit=10, $full_view=true, $list_type_toggle=true, $pagination=true)
Returns a rendered list of entities with pagination.
Definition: views.php:969
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:136
elgg_view_menu_item(ElggMenuItem $item, array $vars=array())
Render a menu item (usually as a link)
Definition: views.php:726
$data
Definition: opendd.php:13
$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 Annotations.
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:229
_elgg_views_amd($hook, $type, $content, $params)
Inserts module names into anonymous modules by handling the "simplecache:generate" hook...
Definition: views.php:1507
$pagination
Definition: gallery.php:23
elgg_view_annotation_list($annotations, array $vars=array())
Returns a rendered list of annotations, plus pagination.
Definition: views.php:1044
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:1464
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
elgg_get_view_location($view, $viewtype= '')
Returns the file location for a view.
Definition: views.php:283
if(isset($vars['id'])) $class
Definition: ajax_loader.php:19
$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:1553
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:194
autoregister_views($view_base, $folder, $base_location_path, $viewtype)
Auto-registers views from a location.
Definition: views.php:1455
$params
Definition: login.php:72
elgg_view_list_item($item, array $vars=array())
View an item in a list.
Definition: views.php:1345
$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:1470
elgg_view_menu($menu_name, array $vars=array())
Render a menu.
Definition: views.php:687
$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:823
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:256
$limit
Definition: userpicker.php:33
elgg_register_js($name, $url, $location= 'head', $priority=null)
Register a JavaScript file for inclusion.
Definition: elgglib.php:128
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_view_entity_icon(ElggEntity $entity, $size= 'medium', $vars=array())
View the icon of an entity.
Definition: views.php:862
elgg_views_add_rss_link()
Add the rss link to the extras when if needed.
Definition: views.php:1518
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:155
elgg_view_friendly_time($time)
Displays a UNIX timestamp in a friendly way.
Definition: views.php:1126
$key
Definition: summary.php:34
get_user($guid)
Get a user object from a GUID.
Definition: users.php:222
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:851
elgg_view_image_block($image, $body, $vars=array())
Wrapper function for the image block display pattern.
Definition: views.php:1176
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
Elgg&#39;s view system.
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
elgg_get_root_path()
Get the root directory path for this installation.
$body_vars
$annotations
Definition: entity.php:20
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
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:73
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
system_messages($message=null, $register="success", $count=false)
Queues a message to be displayed.
Definition: elgglib.php:532
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:617
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
$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:1543
_elgg_views_prepare_head($title)
Prepare the variables for the html head.
Definition: views.php:489
elgg_load_js($name)
Load a JavaScript resource on this page.
Definition: elgglib.php:190
elgg_view_title($title, $vars=array())
Renders a title.
Definition: views.php:1105
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:1144
elgg_format_url($url)
Handles formatting of ampersands in urls.
Definition: output.php:105
if(isset($vars['item_class'])) $icon_class
Definition: tags.php:43
elgg_view_access_collections($owner_guid)
Displays a user&#39;s access collections, using the core/friends/collections view.
Definition: views.php:1390
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
$defaults
Definition: access.php:19
$entity
Definition: delete.php:10
elgg_view_annotation(ElggAnnotation $annotation, array $vars=array(), $bypass=false, $debug=false)
Returns a string of a rendered annotation.
Definition: views.php:913
$subtype
Definition: river.php:10
$version
Definition: version.php:14
$path
Definition: invalid.php:17
elgg_view_form($action, $form_vars=array(), $body_vars=array())
Definition: views.php:1280
$viewtype
Definition: start.php:132
elgg_views_boot()
Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades...
Definition: views.php:1568
$priority
getValues()
Get all the values for this menu item.
count_messages($register="")
Counts the number of messages, either globally or in a particular register.
Definition: elgglib.php:579
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:1213
elgg_register_viewtype($viewtype)
Register a viewtype.
Definition: views.php:116