PageRenderTime 84ms CodeModel.GetById 39ms RepoModel.GetById 7ms app.codeStats 0ms

/engine/lib/views.php

https://github.com/fragilbert/Elgg
PHP | 1461 lines | 566 code | 156 blank | 739 comment | 114 complexity | 540b2c0e6324e2c97cb536dcc64771a0 MD5 | raw file
Possible License(s): MIT, BSD-3-Clause, LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * Elgg's view system.
  4. *
  5. * The view system is the primary templating engine in Elgg and renders
  6. * all output. Views are short, parameterised PHP scripts for displaying
  7. * output that can be regsitered, overridden, or extended. The view type
  8. * determines the output format and location of the files that renders the view.
  9. *
  10. * Elgg uses a two step process to render full output: first
  11. * content-specific elements are rendered, then the resulting
  12. * content is inserted into a layout and displayed. This makes it
  13. * easy to maintain a consistent look on all pages.
  14. *
  15. * A view corresponds to a single file on the filesystem and the views
  16. * name is its directory structure. A file in
  17. * <code>mod/plugins/views/default/myplugin/example.php</code>
  18. * is called by saying (with the default viewtype):
  19. * <code>echo elgg_view('myplugin/example');</code>
  20. *
  21. * View names that are registered later override those that are
  22. * registered earlier. For plugins this corresponds directly
  23. * to their load order: views in plugins lower in the list override
  24. * those higher in the list.
  25. *
  26. * Plugin views belong in the views/ directory under an appropriate
  27. * viewtype. Views are automatically registered.
  28. *
  29. * Views can be embedded-you can call a view from within a view.
  30. * Views can also be prepended or extended by any other view.
  31. *
  32. * Any view can extend any other view if registered with
  33. * {@link elgg_extend_view()}.
  34. *
  35. * Viewtypes are set by passing $_REQUEST['view']. The viewtype
  36. * 'default' is a standard HTML view. Types can be defined on the fly
  37. * and you can get the current viewtype with {@link elgg_get_viewtype()}.
  38. *
  39. * @internal Plugin views are autoregistered before their init functions
  40. * are called, so the init order doesn't affect views.
  41. *
  42. * @internal The file that determines the output of the view is the last
  43. * registered by {@link elgg_set_view_location()}.
  44. *
  45. * @package Elgg.Core
  46. * @subpackage Views
  47. * @link http://docs.elgg.org/Views
  48. */
  49. /**
  50. * The viewtype override.
  51. *
  52. * @global string $CURRENT_SYSTEM_VIEWTYPE
  53. * @see elgg_set_viewtype()
  54. */
  55. global $CURRENT_SYSTEM_VIEWTYPE;
  56. $CURRENT_SYSTEM_VIEWTYPE = "";
  57. /**
  58. * Manually set the viewtype.
  59. *
  60. * View types are detected automatically. This function allows
  61. * you to force subsequent views to use a different viewtype.
  62. *
  63. * @tip Call elgg_set_viewtype() with no parameter to reset.
  64. *
  65. * @param string $viewtype The view type, e.g. 'rss', or 'default'.
  66. *
  67. * @return bool
  68. * @link http://docs.elgg.org/Views/Viewtype
  69. * @example views/viewtype.php
  70. */
  71. function elgg_set_viewtype($viewtype = "") {
  72. global $CURRENT_SYSTEM_VIEWTYPE;
  73. $CURRENT_SYSTEM_VIEWTYPE = $viewtype;
  74. return true;
  75. }
  76. /**
  77. * Return the current view type.
  78. *
  79. * Viewtypes are automatically detected and can be set with $_REQUEST['view']
  80. * or {@link elgg_set_viewtype()}.
  81. *
  82. * @internal Viewtype is determined in this order:
  83. * - $CURRENT_SYSTEM_VIEWTYPE Any overrides by {@link elgg_set_viewtype()}
  84. * - $CONFIG->view The default view as saved in the DB.
  85. *
  86. * @return string The view.
  87. * @see elgg_set_viewtype()
  88. * @link http://docs.elgg.org/Views
  89. */
  90. function elgg_get_viewtype() {
  91. global $CURRENT_SYSTEM_VIEWTYPE, $CONFIG;
  92. if ($CURRENT_SYSTEM_VIEWTYPE != "") {
  93. return $CURRENT_SYSTEM_VIEWTYPE;
  94. }
  95. $viewtype = get_input('view', '', false);
  96. if (_elgg_is_valid_viewtype($viewtype)) {
  97. return $viewtype;
  98. }
  99. if (isset($CONFIG->view) && _elgg_is_valid_viewtype($CONFIG->view)) {
  100. return $CONFIG->view;
  101. }
  102. return 'default';
  103. }
  104. /**
  105. * Register a viewtype.
  106. *
  107. * @param string $viewtype The view type to register
  108. * @return bool
  109. */
  110. function elgg_register_viewtype($viewtype) {
  111. global $CONFIG;
  112. if (!isset($CONFIG->view_types) || !is_array($CONFIG->view_types)) {
  113. $CONFIG->view_types = array();
  114. }
  115. if (!in_array($viewtype, $CONFIG->view_types)) {
  116. $CONFIG->view_types[] = $viewtype;
  117. }
  118. return true;
  119. }
  120. /**
  121. * Checks if $viewtype is registered.
  122. *
  123. * @param string $viewtype The viewtype name
  124. *
  125. * @return bool
  126. * @since 1.9.0
  127. */
  128. function elgg_is_registered_viewtype($viewtype) {
  129. global $CONFIG;
  130. if (!isset($CONFIG->view_types) || !is_array($CONFIG->view_types)) {
  131. return FALSE;
  132. }
  133. return in_array($viewtype, $CONFIG->view_types);
  134. }
  135. /**
  136. * Checks if $viewtype is a string suitable for use as a viewtype name
  137. *
  138. * @param string $viewtype Potential viewtype name. Alphanumeric chars plus _ allowed.
  139. *
  140. * @return bool
  141. * @access private
  142. * @since 1.9
  143. */
  144. function _elgg_is_valid_viewtype($viewtype) {
  145. if (!is_string($viewtype) || $viewtype === '') {
  146. return false;
  147. }
  148. if (preg_match('/\W/', $viewtype)) {
  149. return false;
  150. }
  151. return true;
  152. }
  153. /**
  154. * Register a viewtype to fall back to a default view if a view isn't
  155. * found for that viewtype.
  156. *
  157. * @tip This is useful for alternate html viewtypes (such as for mobile devices).
  158. *
  159. * @param string $viewtype The viewtype to register
  160. *
  161. * @return void
  162. * @since 1.7.2
  163. * @example views/viewtype_fallback.php Fallback from mobile to default.
  164. */
  165. function elgg_register_viewtype_fallback($viewtype) {
  166. _elgg_services()->views->registerViewtypeFallback($viewtype);
  167. }
  168. /**
  169. * Checks if a viewtype falls back to default.
  170. *
  171. * @param string $viewtype Viewtype
  172. *
  173. * @return boolean
  174. * @since 1.7.2
  175. */
  176. function elgg_does_viewtype_fallback($viewtype) {
  177. return _elgg_services()->views->doesViewtypeFallback($viewtype);
  178. }
  179. /**
  180. * Register a view to be available for ajax calls
  181. *
  182. * @param string $view The view name
  183. * @return void
  184. * @since 1.8.3
  185. */
  186. function elgg_register_ajax_view($view) {
  187. elgg_register_external_view($view, false);
  188. }
  189. /**
  190. * Unregister a view for ajax calls
  191. *
  192. * @param string $view The view name
  193. * @return void
  194. * @since 1.8.3
  195. */
  196. function elgg_unregister_ajax_view($view) {
  197. elgg_unregister_external_view($view);
  198. }
  199. /**
  200. * Registers a view as being available externally (i.e. via URL).
  201. *
  202. * @param string $view The name of the view.
  203. * @param boolean $cacheable Whether this view can be cached.
  204. * @since 1.9.0
  205. */
  206. function elgg_register_external_view($view, $cacheable = false) {
  207. global $CONFIG;
  208. if (!isset($CONFIG->allowed_ajax_views)) {
  209. $CONFIG->allowed_ajax_views = array();
  210. }
  211. $CONFIG->allowed_ajax_views[$view] = true;
  212. if ($cacheable) {
  213. _elgg_services()->views->registerCacheableView($view);
  214. }
  215. }
  216. /**
  217. * Check whether a view is registered as cacheable.
  218. *
  219. * @param string $view The name of the view.
  220. * @return boolean
  221. * @access private
  222. * @since 1.9.0
  223. */
  224. function _elgg_is_view_cacheable($view) {
  225. return _elgg_services()->views->isCacheableView($view);
  226. }
  227. /**
  228. * Unregister a view for accessibility via URLs.
  229. *
  230. * @param string $view The view name
  231. * @return void
  232. * @since 1.9.0
  233. */
  234. function elgg_unregister_external_view($view) {
  235. global $CONFIG;
  236. if (isset($CONFIG->allowed_ajax_views[$view])) {
  237. unset($CONFIG->allowed_ajax_views[$view]);
  238. }
  239. }
  240. /**
  241. * Returns the file location for a view.
  242. *
  243. * @warning This doesn't check if the file exists, but only
  244. * constructs (or extracts) the path and returns it.
  245. *
  246. * @param string $view The view.
  247. * @param string $viewtype The viewtype
  248. *
  249. * @return string
  250. */
  251. function elgg_get_view_location($view, $viewtype = '') {
  252. return _elgg_services()->views->getViewLocation($view, $viewtype);
  253. }
  254. /**
  255. * Set an alternative base location for a view.
  256. *
  257. * Views are expected to be in plugin_name/views/. This function can
  258. * be used to change that location.
  259. *
  260. * @internal Core view locations are stored in $CONFIG->viewpath.
  261. *
  262. * @tip This is useful to optionally register views in a plugin.
  263. *
  264. * @param string $view The name of the view
  265. * @param string $location The base location path
  266. * @param string $viewtype The view type
  267. *
  268. * @return void
  269. */
  270. function elgg_set_view_location($view, $location, $viewtype = '') {
  271. _elgg_services()->views->setViewLocation($view, $location, $viewtype);
  272. }
  273. /**
  274. * Returns whether the specified view exists
  275. *
  276. * @note If $recurse is true, also checks if a view exists only as an extension.
  277. *
  278. * @param string $view The view name
  279. * @param string $viewtype If set, forces the viewtype
  280. * @param bool $recurse If false, do not check extensions
  281. *
  282. * @return bool
  283. */
  284. function elgg_view_exists($view, $viewtype = '', $recurse = true) {
  285. return _elgg_services()->views->viewExists($view, $viewtype, $recurse);
  286. }
  287. /**
  288. * Return a parsed view.
  289. *
  290. * Views are rendered by a template handler and returned as strings.
  291. *
  292. * Views are called with a special $vars variable set,
  293. * which includes any variables passed as the second parameter.
  294. * For backward compatbility, the following variables are also set but we
  295. * recommend that you do not use them:
  296. * - $vars['config'] The $CONFIG global. (Use {@link elgg_get_config()} instead).
  297. * - $vars['url'] The site URL. (use {@link elgg_get_site_url()} instead).
  298. * - $vars['user'] The logged in user. (use {@link elgg_get_logged_in_user_entity()} instead).
  299. *
  300. * Custom template handlers can be set with {@link set_template_handler()}.
  301. *
  302. * The output of views can be intercepted by registering for the
  303. * view, $view_name plugin hook.
  304. *
  305. * @warning Any variables in $_SESSION will override passed vars
  306. * upon name collision. See {@trac #2124}.
  307. *
  308. * @param string $view The name and location of the view to use
  309. * @param array $vars Variables to pass to the view.
  310. * @param boolean $bypass If set to true, elgg_view will bypass any specified
  311. * alternative template handler; by default, it will
  312. * hand off to this if requested (see set_template_handler)
  313. * @param boolean $ignored This argument is ignored and will be removed eventually
  314. * @param string $viewtype If set, forces the viewtype for the elgg_view call to be
  315. * this value (default: standard detection)
  316. *
  317. * @return string The parsed view
  318. * @see set_template_handler()
  319. * @example views/elgg_view.php
  320. * @link http://docs.elgg.org/View
  321. */
  322. function elgg_view($view, $vars = array(), $bypass = false, $ignored = false, $viewtype = '') {
  323. return _elgg_services()->views->renderView($view, $vars, $bypass, $viewtype);
  324. }
  325. /**
  326. * Extends a view with another view.
  327. *
  328. * The output of any view can be prepended or appended to any other view.
  329. *
  330. * The default action is to append a view. If the priority is less than 500,
  331. * the output of the extended view will be appended to the original view.
  332. *
  333. * Priority can be specified and affects the order in which extensions
  334. * are appended or prepended.
  335. *
  336. * @internal View extensions are stored in
  337. * $CONFIG->views->extensions[$view][$priority] = $view_extension
  338. *
  339. * @param string $view The view to extend.
  340. * @param string $view_extension This view is added to $view
  341. * @param int $priority The priority, from 0 to 1000,
  342. * to add at (lowest numbers displayed first)
  343. *
  344. * @return void
  345. * @since 1.7.0
  346. * @link http://docs.elgg.org/Views/Extend
  347. * @example views/extend.php
  348. */
  349. function elgg_extend_view($view, $view_extension, $priority = 501, $viewtype = '') {
  350. _elgg_services()->views->extendView($view, $view_extension, $priority, $viewtype);
  351. }
  352. /**
  353. * Unextends a view.
  354. *
  355. * @param string $view The view that was extended.
  356. * @param string $view_extension This view that was added to $view
  357. *
  358. * @return bool
  359. * @since 1.7.2
  360. */
  361. function elgg_unextend_view($view, $view_extension) {
  362. return _elgg_services()->views->unextendView($view, $view_extension);
  363. }
  364. /**
  365. * Assembles and outputs a full page.
  366. *
  367. * A "page" in Elgg is determined by the current view type and
  368. * can be HTML for a browser, RSS for a feed reader, or
  369. * Javascript, PHP and a number of other formats.
  370. *
  371. * @param string $title Title
  372. * @param string $body Body
  373. * @param string $page_shell Optional page shell to use. See page/shells view directory
  374. * @param array $vars Optional vars array to pass to the page
  375. * shell. Automatically adds title, body, and sysmessages
  376. *
  377. * @return string The contents of the page
  378. * @since 1.8
  379. */
  380. function elgg_view_page($title, $body, $page_shell = 'default', $vars = array()) {
  381. $messages = null;
  382. if (count_messages()) {
  383. // get messages - try for errors first
  384. $messages = system_messages(NULL, "error");
  385. if (count($messages["error"]) == 0) {
  386. // no errors so grab rest of messages
  387. $messages = system_messages(null, "");
  388. } else {
  389. // we have errors - clear out remaining messages
  390. system_messages(null, "");
  391. }
  392. }
  393. $vars['title'] = $title;
  394. $vars['body'] = $body;
  395. $vars['sysmessages'] = $messages;
  396. $vars = elgg_trigger_plugin_hook('output:before', 'page', null, $vars);
  397. // check for deprecated view
  398. if ($page_shell == 'default' && elgg_view_exists('pageshells/pageshell')) {
  399. elgg_deprecated_notice("pageshells/pageshell is deprecated by page/$page_shell", 1.8);
  400. $output = elgg_view('pageshells/pageshell', $vars);
  401. } else {
  402. $output = elgg_view("page/$page_shell", $vars);
  403. }
  404. $vars['page_shell'] = $page_shell;
  405. // Allow plugins to mod output
  406. return elgg_trigger_plugin_hook('output', 'page', $vars, $output);
  407. }
  408. /**
  409. * Displays a layout with optional parameters.
  410. *
  411. * Layouts provide consistent organization of pages and other blocks of content.
  412. * There are a few default layouts in core:
  413. * - admin A special layout for the admin area.
  414. * - one_column A single content column.
  415. * - one_sidebar A content column with sidebar.
  416. * - two_sidebar A content column with two sidebars.
  417. * - widgets A widget canvas.
  418. *
  419. * The layout views take the form page/layouts/$layout_name
  420. * See the individual layouts for what options are supported. The three most
  421. * common layouts have these parameters:
  422. * one_column
  423. * content => string
  424. * one_sidebar
  425. * content => string
  426. * sidebar => string (optional)
  427. * content
  428. * content => string
  429. * sidebar => string (optional)
  430. * buttons => string (override the default add button)
  431. * title => string (override the default title)
  432. * filter_context => string (selected content filter)
  433. * See the content layout view for more parameters
  434. *
  435. * @param string $layout_name The name of the view in page/layouts/.
  436. * @param array $vars Associative array of parameters for the layout view
  437. *
  438. * @return string The layout
  439. */
  440. function elgg_view_layout($layout_name, $vars = array()) {
  441. if (is_string($vars) || $vars === null) {
  442. elgg_deprecated_notice("The use of unlimited optional string arguments in elgg_view_layout() was deprecated in favor of an options array", 1.8);
  443. $arg = 1;
  444. $param_array = array();
  445. while ($arg < func_num_args()) {
  446. $param_array['area' . $arg] = func_get_arg($arg);
  447. $arg++;
  448. }
  449. } else {
  450. $param_array = $vars;
  451. }
  452. $params = elgg_trigger_plugin_hook('output:before', 'layout', null, $param_array);
  453. // check deprecated location
  454. if (elgg_view_exists("canvas/layouts/$layout_name")) {
  455. elgg_deprecated_notice("canvas/layouts/$layout_name is deprecated by page/layouts/$layout_name", 1.8);
  456. $output = elgg_view("canvas/layouts/$layout_name", $params);
  457. } elseif (elgg_view_exists("page/layouts/$layout_name")) {
  458. $output = elgg_view("page/layouts/$layout_name", $params);
  459. } else {
  460. $output = elgg_view("page/layouts/default", $params);
  461. }
  462. return elgg_trigger_plugin_hook('output:after', 'layout', $params, $output);
  463. }
  464. /**
  465. * Render a menu
  466. *
  467. * @see elgg_register_menu_item() for documentation on adding menu items and
  468. * navigation.php for information on the different menus available.
  469. *
  470. * This function triggers a 'register', 'menu:<menu name>' plugin hook that enables
  471. * plugins to add menu items just before a menu is rendered. This is used by
  472. * dynamic menus (menus that change based on some input such as the user hover
  473. * menu). Using elgg_register_menu_item() in response to the hook can cause
  474. * incorrect links to show up. See the blog plugin's blog_owner_block_menu()
  475. * for an example of using this plugin hook.
  476. *
  477. * An additional hook is the 'prepare', 'menu:<menu name>' which enables plugins
  478. * to modify the structure of the menu (sort it, remove items, set variables on
  479. * the menu items).
  480. *
  481. * elgg_view_menu() uses views in navigation/menu
  482. *
  483. * @param string $menu_name The name of the menu
  484. * @param array $vars An associative array of display options for the menu.
  485. * Options include:
  486. * sort_by => string or php callback
  487. * string options: 'name', 'priority', 'title' (default),
  488. * 'register' (registration order) or a
  489. * php callback (a compare function for usort)
  490. * handler: string the page handler to build action URLs
  491. * entity: ElggEntity to use to build action URLs
  492. * class: string the class for the entire menu.
  493. * show_section_headers: bool show headers before menu sections.
  494. *
  495. * @return string
  496. * @since 1.8.0
  497. */
  498. function elgg_view_menu($menu_name, array $vars = array()) {
  499. global $CONFIG;
  500. $vars['name'] = $menu_name;
  501. $sort_by = elgg_extract('sort_by', $vars, 'text');
  502. if (isset($CONFIG->menus[$menu_name])) {
  503. $menu = $CONFIG->menus[$menu_name];
  504. } else {
  505. $menu = array();
  506. }
  507. // Give plugins a chance to add menu items just before creation.
  508. // This supports dynamic menus (example: user_hover).
  509. $menu = elgg_trigger_plugin_hook('register', "menu:$menu_name", $vars, $menu);
  510. $builder = new ElggMenuBuilder($menu);
  511. $vars['menu'] = $builder->getMenu($sort_by);
  512. $vars['selected_item'] = $builder->getSelected();
  513. // Let plugins modify the menu
  514. $vars['menu'] = elgg_trigger_plugin_hook('prepare', "menu:$menu_name", $vars, $vars['menu']);
  515. if (elgg_view_exists("navigation/menu/$menu_name")) {
  516. return elgg_view("navigation/menu/$menu_name", $vars);
  517. } else {
  518. return elgg_view("navigation/menu/default", $vars);
  519. }
  520. }
  521. /**
  522. * Returns a string of a rendered entity.
  523. *
  524. * Entity views are either determined by setting the view property on the entity
  525. * or by having a view named after the entity $type/$subtype. Entities that have
  526. * neither a view property nor a defined $type/$subtype view will fall back to
  527. * using the $type/default view.
  528. *
  529. * The entity view is called with the following in $vars:
  530. * - ElggEntity 'entity' The entity being viewed
  531. *
  532. * Other common view $vars paramters:
  533. * - bool 'full_view' Whether to show a full or condensed view.
  534. *
  535. * @tip This function can automatically appends annotations to entities if in full
  536. * view and a handler is registered for the entity:annotate. See {@trac 964} and
  537. * {@link elgg_view_entity_annotations()}.
  538. *
  539. * @param ElggEntity $entity The entity to display
  540. * @param array $vars Array of variables to pass to the entity view.
  541. * In Elgg 1.7 and earlier it was the boolean $full_view
  542. * @param boolean $bypass If true, will not pass to a custom template handler.
  543. * {@see set_template_handler()}
  544. * @param boolean $debug Complain if views are missing
  545. *
  546. * @return string HTML to display or false
  547. * @link http://docs.elgg.org/Views/Entity
  548. * @link http://docs.elgg.org/Entities
  549. * @todo The annotation hook might be better as a generic plugin hook to append content.
  550. */
  551. function elgg_view_entity(ElggEntity $entity, $vars = array(), $bypass = false, $debug = false) {
  552. // No point continuing if entity is null
  553. if (!$entity || !($entity instanceof ElggEntity)) {
  554. return false;
  555. }
  556. global $autofeed;
  557. $autofeed = true;
  558. $defaults = array(
  559. 'full_view' => false,
  560. );
  561. if (is_array($vars)) {
  562. $vars = array_merge($defaults, $vars);
  563. } else {
  564. elgg_deprecated_notice("Update your use of elgg_view_entity()", 1.8);
  565. $vars = array(
  566. 'full_view' => $vars,
  567. );
  568. }
  569. $vars['entity'] = $entity;
  570. // if this entity has a view defined, use it
  571. $view = $entity->view;
  572. if (is_string($view)) {
  573. return elgg_view($view, $vars, $bypass, $debug);
  574. }
  575. $entity_type = $entity->getType();
  576. $subtype = $entity->getSubtype();
  577. if (empty($subtype)) {
  578. $subtype = 'default';
  579. }
  580. $contents = '';
  581. if (elgg_view_exists("$entity_type/$subtype")) {
  582. $contents = elgg_view("$entity_type/$subtype", $vars, $bypass, $debug);
  583. } else {
  584. $contents = elgg_view("$entity_type/default", $vars, $bypass, $debug);
  585. }
  586. // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
  587. if ($vars['full_view']) {
  588. $annotations = elgg_view_entity_annotations($entity, $vars['full_view']);
  589. if ($annotations) {
  590. $contents .= $annotations;
  591. }
  592. }
  593. return $contents;
  594. }
  595. /**
  596. * View the icon of an entity
  597. *
  598. * Entity views are determined by having a view named after the entity $type/$subtype.
  599. * Entities that do not have a defined icon/$type/$subtype view will fall back to using
  600. * the icon/$type/default view.
  601. *
  602. * @param ElggEntity $entity The entity to display
  603. * @param string $size The size: tiny, small, medium, large
  604. * @param array $vars An array of variables to pass to the view. Some possible
  605. * variables are img_class and link_class. See the
  606. * specific icon view for more parameters.
  607. *
  608. * @return string HTML to display or false
  609. */
  610. function elgg_view_entity_icon(ElggEntity $entity, $size = 'medium', $vars = array()) {
  611. // No point continuing if entity is null
  612. if (!$entity || !($entity instanceof ElggEntity)) {
  613. return false;
  614. }
  615. $vars['entity'] = $entity;
  616. $vars['size'] = $size;
  617. $entity_type = $entity->getType();
  618. $subtype = $entity->getSubtype();
  619. if (empty($subtype)) {
  620. $subtype = 'default';
  621. }
  622. $contents = '';
  623. if (elgg_view_exists("icon/$entity_type/$subtype")) {
  624. $contents = elgg_view("icon/$entity_type/$subtype", $vars);
  625. }
  626. if (empty($contents)) {
  627. $contents = elgg_view("icon/$entity_type/default", $vars);
  628. }
  629. if (empty($contents)) {
  630. $contents = elgg_view("icon/default", $vars);
  631. }
  632. return $contents;
  633. }
  634. /**
  635. * Returns a string of a rendered annotation.
  636. *
  637. * Annotation views are expected to be in annotation/$annotation_name.
  638. * If a view is not found for $annotation_name, the default annotation/default
  639. * will be used.
  640. *
  641. * @warning annotation/default is not currently defined in core.
  642. *
  643. * The annotation view is called with the following in $vars:
  644. * - ElggEntity 'annotation' The annotation being viewed.
  645. *
  646. * @param ElggAnnotation $annotation The annotation to display
  647. * @param array $vars Variable array for view.
  648. * @param bool $bypass If true, will not pass to a custom
  649. * template handler. {@see set_template_handler()}
  650. * @param bool $debug Complain if views are missing
  651. *
  652. * @return string/false Rendered annotation
  653. */
  654. function elgg_view_annotation(ElggAnnotation $annotation, array $vars = array(), $bypass = false, $debug = false) {
  655. global $autofeed;
  656. $autofeed = true;
  657. $defaults = array(
  658. 'full_view' => true,
  659. );
  660. $vars = array_merge($defaults, $vars);
  661. $vars['annotation'] = $annotation;
  662. // @todo setting the view on an annotation is not advertised anywhere
  663. // do we want to keep this?
  664. $view = $annotation->view;
  665. if (is_string($view)) {
  666. return elgg_view($view, $vars, $bypass, $debug);
  667. }
  668. $name = $annotation->name;
  669. if (empty($name)) {
  670. return false;
  671. }
  672. if (elgg_view_exists("annotation/$name")) {
  673. return elgg_view("annotation/$name", $vars, $bypass, $debug);
  674. } else {
  675. return elgg_view("annotation/default", $vars, $bypass, $debug);
  676. }
  677. }
  678. /**
  679. * Returns a rendered list of entities with pagination. This function should be
  680. * called by wrapper functions.
  681. *
  682. * @see elgg_list_entities()
  683. * @see list_user_friends_objects()
  684. * @see elgg_list_entities_from_metadata()
  685. * @see elgg_list_entities_from_relationships()
  686. * @see elgg_list_entities_from_annotations()
  687. *
  688. * @param array $entities Array of entities
  689. * @param array $vars Display variables
  690. * 'count' The total number of entities across all pages
  691. * 'offset' The current indexing offset
  692. * 'limit' The number of entities to display per page
  693. * 'full_view' Display the full view of the entities?
  694. * 'list_class' CSS class applied to the list
  695. * 'item_class' CSS class applied to the list items
  696. * 'pagination' Display pagination?
  697. * 'list_type' List type: 'list' (default), 'gallery'
  698. * 'list_type_toggle' Display the list type toggle?
  699. *
  700. * @return string The rendered list of entities
  701. * @access private
  702. */
  703. function elgg_view_entity_list($entities, $vars = array(), $offset = 0, $limit = 10, $full_view = true,
  704. $list_type_toggle = true, $pagination = true) {
  705. if (!is_int($offset)) {
  706. $offset = (int)get_input('offset', 0);
  707. }
  708. // list type can be passed as request parameter
  709. $list_type = get_input('list_type', 'list');
  710. if (get_input('listtype')) {
  711. elgg_deprecated_notice("'listtype' has been deprecated by 'list_type' for lists", 1.8);
  712. $list_type = get_input('listtype');
  713. }
  714. if (is_array($vars)) {
  715. // new function
  716. $defaults = array(
  717. 'items' => $entities,
  718. 'list_class' => 'elgg-list-entity',
  719. 'full_view' => true,
  720. 'pagination' => true,
  721. 'list_type' => $list_type,
  722. 'list_type_toggle' => false,
  723. 'offset' => $offset,
  724. );
  725. $vars = array_merge($defaults, $vars);
  726. } else {
  727. // old function parameters
  728. elgg_deprecated_notice("Please update your use of elgg_view_entity_list()", 1.8);
  729. $vars = array(
  730. 'items' => $entities,
  731. 'count' => (int) $vars, // the old count parameter
  732. 'offset' => $offset,
  733. 'limit' => (int) $limit,
  734. 'full_view' => $full_view,
  735. 'pagination' => $pagination,
  736. 'list_type' => $list_type,
  737. 'list_type_toggle' => $list_type_toggle,
  738. 'list_class' => 'elgg-list-entity',
  739. );
  740. }
  741. if ($vars['list_type'] != 'list') {
  742. return elgg_view('page/components/gallery', $vars);
  743. } else {
  744. return elgg_view('page/components/list', $vars);
  745. }
  746. }
  747. /**
  748. * Returns a rendered list of annotations, plus pagination. This function
  749. * should be called by wrapper functions.
  750. *
  751. * @param array $annotations Array of annotations
  752. * @param array $vars Display variables
  753. * 'count' The total number of annotations across all pages
  754. * 'offset' The current indexing offset
  755. * 'limit' The number of annotations to display per page
  756. * 'full_view' Display the full view of the annotation?
  757. * 'list_class' CSS Class applied to the list
  758. * 'offset_key' The url parameter key used for offset
  759. *
  760. * @return string The list of annotations
  761. * @access private
  762. */
  763. function elgg_view_annotation_list($annotations, array $vars = array()) {
  764. $defaults = array(
  765. 'items' => $annotations,
  766. 'list_class' => 'elgg-list-annotation elgg-annotation-list', // @todo remove elgg-annotation-list in Elgg 1.9
  767. 'full_view' => true,
  768. 'offset_key' => 'annoff',
  769. );
  770. $vars = array_merge($defaults, $vars);
  771. return elgg_view('page/components/list', $vars);
  772. }
  773. /**
  774. * Display a plugin-specified rendered list of annotations for an entity.
  775. *
  776. * This displays the output of functions registered to the entity:annotation,
  777. * $entity_type plugin hook.
  778. *
  779. * This is called automatically by the framework from {@link elgg_view_entity()}
  780. *
  781. * @param ElggEntity $entity Entity
  782. * @param bool $full_view Display full view?
  783. *
  784. * @return mixed string or false on failure
  785. * @todo Change the hook name.
  786. */
  787. function elgg_view_entity_annotations(ElggEntity $entity, $full_view = true) {
  788. if (!($entity instanceof ElggEntity)) {
  789. return false;
  790. }
  791. $entity_type = $entity->getType();
  792. $annotations = elgg_trigger_plugin_hook('entity:annotate', $entity_type,
  793. array(
  794. 'entity' => $entity,
  795. 'full_view' => $full_view,
  796. )
  797. );
  798. return $annotations;
  799. }
  800. /**
  801. * Renders a title.
  802. *
  803. * This is a shortcut for {@elgg_view page/elements/title}.
  804. *
  805. * @param string $title The page title
  806. * @param array $vars View variables (was submenu be displayed? (deprecated))
  807. *
  808. * @return string The HTML (etc)
  809. */
  810. function elgg_view_title($title, $vars = array()) {
  811. if (!is_array($vars)) {
  812. elgg_deprecated_notice('setting $submenu in elgg_view_title() is deprecated', 1.8);
  813. $vars = array('submenu' => $vars);
  814. }
  815. $vars['title'] = $title;
  816. return elgg_view('page/elements/title', $vars);
  817. }
  818. /**
  819. * Displays a UNIX timestamp in a friendly way
  820. *
  821. * @see elgg_get_friendly_time()
  822. *
  823. * @param int $time A UNIX epoch timestamp
  824. *
  825. * @return string The friendly time HTML
  826. * @since 1.7.2
  827. */
  828. function elgg_view_friendly_time($time) {
  829. return elgg_view('output/friendlytime', array('time' => $time));
  830. }
  831. /**
  832. * Returns rendered comments and a comment form for an entity.
  833. *
  834. * @tip Plugins can override the output by registering a handler
  835. * for the comments, $entity_type hook. The handler is responsible
  836. * for formatting the comments and the add comment form.
  837. *
  838. * @param ElggEntity $entity The entity to view comments of
  839. * @param bool $add_comment Include a form to add comments?
  840. * @param array $vars Variables to pass to comment view
  841. *
  842. * @return string|false Rendered comments or false on failure
  843. * @link http://docs.elgg.org/Entities/Comments
  844. * @link http://docs.elgg.org/Annotations/Comments
  845. */
  846. function elgg_view_comments($entity, $add_comment = true, array $vars = array()) {
  847. if (!($entity instanceof ElggEntity)) {
  848. return false;
  849. }
  850. $vars['entity'] = $entity;
  851. $vars['show_add_form'] = $add_comment;
  852. $vars['class'] = elgg_extract('class', $vars, "{$entity->getSubtype()}-comments");
  853. $output = elgg_trigger_plugin_hook('comments', $entity->getType(), $vars, false);
  854. if ($output) {
  855. return $output;
  856. } else {
  857. return elgg_view('page/elements/comments', $vars);
  858. }
  859. }
  860. /**
  861. * Wrapper function for the image block display pattern.
  862. *
  863. * Fixed width media on the side (image, icon, flash, etc.).
  864. * Descriptive content filling the rest of the column.
  865. *
  866. * This is a shortcut for {@elgg_view page/components/image_block}.
  867. *
  868. * @param string $image The icon and other information
  869. * @param string $body Description content
  870. * @param array $vars Additional parameters for the view
  871. *
  872. * @return string
  873. * @since 1.8.0
  874. */
  875. function elgg_view_image_block($image, $body, $vars = array()) {
  876. $vars['image'] = $image;
  877. $vars['body'] = $body;
  878. return elgg_view('page/components/image_block', $vars);
  879. }
  880. /**
  881. * Wrapper function for the module display pattern.
  882. *
  883. * Box with header, body, footer
  884. *
  885. * This is a shortcut for {@elgg_view page/components/module}.
  886. *
  887. * @param string $type The type of module (main, info, popup, aside, etc.)
  888. * @param string $title A title to put in the header
  889. * @param string $body Content of the module
  890. * @param array $vars Additional parameters for the module
  891. *
  892. * @return string
  893. * @since 1.8.0
  894. */
  895. function elgg_view_module($type, $title, $body, array $vars = array()) {
  896. $vars['type'] = $type;
  897. $vars['class'] = elgg_extract('class', $vars, '') . " elgg-module-$type";
  898. $vars['title'] = $title;
  899. $vars['body'] = $body;
  900. return elgg_view('page/components/module', $vars);
  901. }
  902. /**
  903. * Renders a human-readable representation of a river item
  904. *
  905. * @param ElggRiverItem $item A river item object
  906. * @param array $vars An array of variables for the view
  907. *
  908. * @return string returns empty string if could not be rendered
  909. */
  910. function elgg_view_river_item($item, array $vars = array()) {
  911. if (!($item instanceof ElggRiverItem)) {
  912. return '';
  913. }
  914. // checking default viewtype since some viewtypes do not have unique views per item (rss)
  915. $view = $item->getView();
  916. if (!$view || !elgg_view_exists($view, 'default')) {
  917. return '';
  918. }
  919. $subject = $item->getSubjectEntity();
  920. $object = $item->getObjectEntity();
  921. if (!$subject || !$object) {
  922. // subject is disabled or subject/object deleted
  923. return '';
  924. }
  925. // Don't hide objects in closed groups that a user can see.
  926. // see http://trac.elgg.org/ticket/4789
  927. // else {
  928. // // hide based on object's container
  929. // $visibility = ElggGroupItemVisibility::factory($object->container_guid);
  930. // if ($visibility->shouldHideItems) {
  931. // return '';
  932. // }
  933. // }
  934. $vars['item'] = $item;
  935. return elgg_view('river/item', $vars);
  936. }
  937. /**
  938. * Convenience function for generating a form from a view in a standard location.
  939. *
  940. * This function assumes that the body of the form is located at "forms/$action" and
  941. * sets the action by default to "action/$action". Automatically wraps the forms/$action
  942. * view with a <form> tag and inserts the anti-csrf security tokens.
  943. *
  944. * @tip This automatically appends elgg-form-action-name to the form's class. It replaces any
  945. * slashes with dashes (blog/save becomes elgg-form-blog-save)
  946. *
  947. * @example
  948. * <code>echo elgg_view_form('login');</code>
  949. *
  950. * This would assume a "login" form body to be at "forms/login" and would set the action
  951. * of the form to "http://yoursite.com/action/login".
  952. *
  953. * If elgg_view('forms/login') is:
  954. * <input type="text" name="username" />
  955. * <input type="password" name="password" />
  956. *
  957. * Then elgg_view_form('login') generates:
  958. * <form action="http://yoursite.com/action/login" method="post">
  959. * ...security tokens...
  960. * <input type="text" name="username" />
  961. * <input type="password" name="password" />
  962. * </form>
  963. *
  964. * @param string $action The name of the action. An action name does not include
  965. * the leading "action/". For example, "login" is an action name.
  966. * @param array $form_vars $vars environment passed to the "input/form" view
  967. * @param array $body_vars $vars environment passed to the "forms/$action" view
  968. *
  969. * @return string The complete form
  970. */
  971. function elgg_view_form($action, $form_vars = array(), $body_vars = array()) {
  972. global $CONFIG;
  973. $defaults = array(
  974. 'action' => $CONFIG->wwwroot . "action/$action",
  975. 'body' => elgg_view("forms/$action", $body_vars)
  976. );
  977. $form_class = 'elgg-form-' . preg_replace('/[^a-z0-9]/i', '-', $action);
  978. // append elgg-form class to any class options set
  979. if (isset($form_vars['class'])) {
  980. $form_vars['class'] = $form_vars['class'] . " $form_class";
  981. } else {
  982. $form_vars['class'] = $form_class;
  983. }
  984. return elgg_view('input/form', array_merge($defaults, $form_vars));
  985. }
  986. /**
  987. * View an item in a list
  988. *
  989. * @param ElggEntity|ElggAnnotation $item
  990. * @param array $vars Additional parameters for the rendering
  991. *
  992. * @return string
  993. * @since 1.8.0
  994. * @access private
  995. */
  996. function elgg_view_list_item($item, array $vars = array()) {
  997. global $CONFIG;
  998. $type = $item->getType();
  999. if (in_array($type, $CONFIG->entity_types)) {
  1000. return elgg_view_entity($item, $vars);
  1001. } else if ($type == 'annotation') {
  1002. return elgg_view_annotation($item, $vars);
  1003. } else if ($type == 'river') {
  1004. return elgg_view_river_item($item, $vars);
  1005. }
  1006. return '';
  1007. }
  1008. /**
  1009. * View one of the elgg sprite icons
  1010. *
  1011. * Shorthand for <span class="elgg-icon elgg-icon-$name"></span>
  1012. *
  1013. * @param string $name The specific icon to display
  1014. * @param string $class Additional class: float, float-alt, or custom class
  1015. *
  1016. * @return string The html for displaying an icon
  1017. */
  1018. function elgg_view_icon($name, $class = '') {
  1019. // @todo deprecate boolean in Elgg 1.9
  1020. if ($class === true) {
  1021. $class = 'float';
  1022. }
  1023. return "<span class=\"elgg-icon elgg-icon-$name $class\"></span>";
  1024. }
  1025. /**
  1026. * Displays a user's access collections, using the core/friends/collections view
  1027. *
  1028. * @param int $owner_guid The GUID of the owning user
  1029. *
  1030. * @return string A formatted rendition of the collections
  1031. * @todo Move to the friends/collection.php page.
  1032. * @access private
  1033. */
  1034. function elgg_view_access_collections($owner_guid) {
  1035. if ($collections = get_user_access_collections($owner_guid)) {
  1036. foreach ($collections as $key => $collection) {
  1037. $collections[$key]->members = get_members_of_access_collection($collection->id, true);
  1038. $collections[$key]->entities = get_user_friends($owner_guid, "", 9999);
  1039. }
  1040. }
  1041. return elgg_view('core/friends/collections', array('collections' => $collections));
  1042. }
  1043. /**
  1044. * Registers a function to handle templates.
  1045. *
  1046. * Alternative template handlers can be registered to handle
  1047. * all output functions. By default, {@link elgg_view()} will
  1048. * simply include the view file. If an alternate template handler
  1049. * is registered, the view name and passed $vars will be passed to the
  1050. * registered function, which is then responsible for generating and returning
  1051. * output.
  1052. *
  1053. * Template handlers need to accept two arguments: string $view_name and array
  1054. * $vars.
  1055. *
  1056. * @warning This is experimental.
  1057. *
  1058. * @param string $function_name The name of the function to pass to.
  1059. *
  1060. * @return bool
  1061. * @see elgg_view()
  1062. * @link http://docs.elgg.org/Views/TemplateHandlers
  1063. */
  1064. function set_template_handler($function_name) {
  1065. global $CONFIG;
  1066. if (is_callable($function_name)) {
  1067. $CONFIG->template_handler = $function_name;
  1068. return true;
  1069. }
  1070. return false;
  1071. }
  1072. /**
  1073. * Returns the name of views for in a directory.
  1074. *
  1075. * Use this to get all namespaced views under the first element.
  1076. *
  1077. * @param string $dir The main directory that holds the views. (mod/profile/views/)
  1078. * @param string $base The root name of the view to use, without the viewtype. (profile)
  1079. *
  1080. * @return array
  1081. * @since 1.7.0
  1082. * @todo Why isn't this used anywhere else but in elgg_view_tree()?
  1083. * Seems like a useful function for autodiscovery.
  1084. * @access private
  1085. */
  1086. function elgg_get_views($dir, $base) {
  1087. $return = array();
  1088. if (file_exists($dir) && is_dir($dir)) {
  1089. if ($handle = opendir($dir)) {
  1090. while ($view = readdir($handle)) {
  1091. if (!in_array($view, array('.', '..', '.svn', 'CVS'))) {
  1092. if (is_dir($dir . '/' . $view)) {
  1093. if ($val = elgg_get_views($dir . '/' . $view, $base . '/' . $view)) {
  1094. $return = array_merge($return, $val);
  1095. }
  1096. } else {
  1097. $view = str_replace('.php', '', $view);
  1098. $return[] = $base . '/' . $view;
  1099. }
  1100. }
  1101. }
  1102. }
  1103. }
  1104. return $return;
  1105. }
  1106. /**
  1107. * Returns all views below a partial view.
  1108. *
  1109. * Settings $view_root = 'profile' will show all available views under
  1110. * the "profile" namespace.
  1111. *
  1112. * @param string $view_root The root view
  1113. * @param string $viewtype Optionally specify a view type
  1114. * other than the current one.
  1115. *
  1116. * @return array A list of view names underneath that root view
  1117. * @todo This is used once in the deprecated get_activity_stream_data() function.
  1118. * @access private
  1119. */
  1120. function elgg_view_tree($view_root, $viewtype = "") {
  1121. global $CONFIG;
  1122. static $treecache = array();
  1123. // Get viewtype
  1124. if (!$viewtype) {
  1125. $viewtype = elgg_get_viewtype();
  1126. }
  1127. // A little light internal caching
  1128. if (!empty($treecache[$view_root])) {
  1129. return $treecache[$view_root];
  1130. }
  1131. // Examine $CONFIG->views->locations
  1132. if (isset($CONFIG->views->locations[$viewtype])) {
  1133. foreach ($CONFIG->views->locations[$viewtype] as $view => $path) {
  1134. $pos = strpos($view, $view_root);
  1135. if ($pos === 0) {
  1136. $treecache[$view_root][] = $view;
  1137. }
  1138. }
  1139. }
  1140. // Now examine core
  1141. $location = $CONFIG->viewpath;
  1142. $viewtype = elgg_get_viewtype();
  1143. $root = $location . $viewtype . '/' . $view_root;
  1144. if (file_exists($root) && is_dir($root)) {
  1145. $val = elgg_get_views($root, $view_root);
  1146. if (!is_array($treecache[$view_root])) {
  1147. $treecache[$view_root] = array();
  1148. }
  1149. $treecache[$view_root] = array_merge($treecache[$view_root], $val);
  1150. }
  1151. return $treecache[$view_root];
  1152. }
  1153. /**
  1154. * Auto-registers views from a location.
  1155. *
  1156. * @note Views in plugin/views/ are automatically registered for active plugins.
  1157. * Plugin authors would only need to call this if optionally including
  1158. * an entire views structure.
  1159. *
  1160. * @param string $view_base Optional The base of the view name without the view type.
  1161. * @param string $folder Required The folder to begin looking in
  1162. * @param string $base_location_path The base views directory to use with elgg_set_view_location()
  1163. * @param string $viewtype The type of view we're looking at (default, rss, etc)
  1164. *
  1165. * @return bool returns false if folder can't be read
  1166. * @since 1.7.0
  1167. * @see elgg_set_view_location()
  1168. * @access private
  1169. */
  1170. function autoregister_views($view_base, $folder, $base_location_path, $viewtype) {
  1171. return _elgg_services()->views->autoregisterViews($view_base, $folder, $base_location_path, $viewtype);
  1172. }
  1173. /**
  1174. * Minifies simplecache CSS and JS views by handling the "simplecache:generate" hook
  1175. *
  1176. * @param string $hook The name of the hook
  1177. * @param string $type View type (css, js, or unknown)
  1178. * @param string $content Content of the view
  1179. * @param array $params Array of parameters
  1180. *
  1181. * @return string|null View content minified (if css/js type)
  1182. * @access private
  1183. */
  1184. function _elgg_views_minify($hook, $type, $content, $params) {
  1185. static $autoload_registered;
  1186. if (!$autoload_registered) {
  1187. $path = elgg_get_root_path() . 'vendors/minify/lib';
  1188. elgg_get_class_loader()->addFallback($path);
  1189. $autoload_registered = true;
  1190. }
  1191. if ($type == 'js') {
  1192. if (elgg_get_config('simplecache_minify_js')) {
  1193. return JSMin::minify($content);
  1194. }
  1195. } elseif ($type == 'css') {
  1196. if (elgg_get_config('simplecache_minify_css')) {
  1197. $cssmin = new CSSMin();
  1198. return $cssmin->run($content);
  1199. }
  1200. }
  1201. }
  1202. /**
  1203. * Add the rss link to the extras when if needed
  1204. *
  1205. * @return void
  1206. * @access private
  1207. */
  1208. function elgg_views_add_rss_link() {
  1209. global $autofeed;
  1210. if (isset($autofeed) && $autofeed == true) {
  1211. $url = full_url();
  1212. if (substr_count($url, '?')) {
  1213. $url .= "&view=rss";
  1214. } else {
  1215. $url .= "?view=rss";
  1216. }
  1217. $url = elgg_format_url($url);
  1218. elgg_register_menu_item('extras', array(
  1219. 'name' => 'rss',
  1220. 'text' => elgg_view_icon('rss'),
  1221. 'href' => $url,
  1222. 'title' => elgg_echo('feed:rss'),
  1223. ));
  1224. }
  1225. }
  1226. /**
  1227. * Registers deprecated views to avoid making some pages from older plugins
  1228. * completely empty.
  1229. *
  1230. * @access private
  1231. */
  1232. function elgg_views_handle_deprecated_views() {
  1233. $location = elgg_get_view_location('page_elements/contentwrapper');
  1234. if ($location === "/var/www/views/") {
  1235. elgg_extend_view('page_elements/contentwrapper', 'page/elements/wrapper');
  1236. }
  1237. }
  1238. /**
  1239. * Initialize viewtypes on system boot event
  1240. * This ensures simplecache is cleared during upgrades. See #2252
  1241. *
  1242. * @return void
  1243. * @access private
  1244. * @elgg_event_handler boot system
  1245. */
  1246. function elgg_views_boot() {
  1247. global $CONFIG;
  1248. elgg_register_simplecache_view('css/ie');
  1249. elgg_register_simplecache_view('css/ie7');
  1250. elgg_register_simplecache_view('css/ie8');
  1251. elgg_register_simplecache_view('js/text.js');
  1252. elgg_register_js('require', '/vendors/requirejs/require-2.1.4.min.js', 'head');
  1253. elgg_register_js('jquery', '/vendors/jquery/jquery-1.7.2.min.js', 'head');
  1254. elgg_register_js('jquery-ui', '/vendors/jquery/jquery-ui-1.8.21.min.js', 'head');
  1255. elgg_register_js('jquery.form', array(
  1256. 'src' => '/vendors/jquery/jquery.form.js',
  1257. 'location' => 'head',
  1258. 'deps' => array('jquery'),
  1259. 'exports' => 'jQuery.fn.ajaxForm',
  1260. ));
  1261. elgg_register_simplecache_view('js/elgg');
  1262. $elgg_js_url = elgg_get_simplecache_url('js', 'elgg');
  1263. elgg_register_js('elgg', $elgg_js_url, 'head');
  1264. elgg_load_js('require');
  1265. elgg_load_js('jquery');
  1266. elgg_load_js('jquery-ui');
  1267. elgg_load_js('elgg');
  1268. elgg_register_simplecache_view('js/lightbox');
  1269. $lightbox_js_url = elgg_get_simplecache_url('js', 'lightbox');
  1270. elgg_register_js('lightbox', $lightbox_js_url);
  1271. elgg_register_simplecache_view('css/lightbox');
  1272. $lightbox_css_url = elgg_get_simplecache_url('css', 'lightbox');
  1273. elgg_register_css('lightbox', $lightbox_css_url);
  1274. elgg_register_simplecache_view('css/elgg');
  1275. $elgg_css_url = elgg_get_simplecache_url('css', 'elgg');
  1276. elgg_register_css('elgg', $elgg_css_url);
  1277. elgg_load_css('elgg');
  1278. elgg_register_ajax_view('js/languages');
  1279. elgg_register_plugin_hook_handler('simplecache:generate', 'css', '_elgg_views_minify');
  1280. elgg_register_plugin_hook_handler('simplecache:generate', 'js', '_elgg_views_minify');
  1281. elgg_register_plugin_hook_handler('output:before', 'layout', 'elgg_views_add_rss_link');
  1282. // discover the core viewtypes
  1283. // @todo the cache is loaded in load_plugins() but we need to know viewtypes earlier
  1284. $view_path = $CONFIG->viewpath;
  1285. $viewtype_dirs = scandir($view_path);
  1286. foreach ($viewtype_dirs as $viewtype) {
  1287. if (_elgg_is_valid_viewtype($viewtype) && is_dir($view_path . $viewtype)) {
  1288. elgg_register_viewtype($viewtype);
  1289. }
  1290. }
  1291. // set default icon sizes - can be overridden in settings.php or with plugin
  1292. if (!$CONFIG->icon_sizes) {
  1293. $icon_sizes = array(
  1294. 'topbar' => array('w' => 16, 'h' => 16, 'square' => TRUE, 'upscale' => TRUE),
  1295. 'tiny' => array('w' => 25, 'h' => 25, 'square' => TRUE, 'upscale' => TRUE),
  1296. 'small' => array('w' => 40, 'h' => 40, 'square' => TRUE, 'upscale' => TRUE),
  1297. 'medium' => array('w' => 100, 'h' => 100, 'square' => TRUE, 'upscale' => TRUE),
  1298. 'large' => array('w' => 200, 'h' => 200, 'square' => FALSE, 'upscale' => FALSE),
  1299. 'master' => array('w' => 550, 'h' => 550, 'square' => FALSE, 'upscale' => FALSE),
  1300. );
  1301. elgg_set_config('icon_sizes', $icon_sizes);
  1302. }
  1303. }
  1304. elgg_register_event_handler('boot', 'system', 'elgg_views_boot');
  1305. elgg_register_event_handler('init', 'system', 'elgg_views_handle_deprecated_views');