engine/lib/views.php File Reference

Go to the source code of this file.

Functions

 elgg_set_viewtype ($viewtype="")
 elgg_get_viewtype ()
 Return the current view type.
 elgg_register_viewtype ($view_type)
 Register a view type as valid.
 elgg_is_valid_view_type ($view_type)
 Checks if $view_type is valid on this installation.
 elgg_register_viewtype_fallback ($viewtype)
 elgg_does_viewtype_fallback ($viewtype)
 Checks if a viewtype falls back to default.
 elgg_register_ajax_view ($view)
 Register a view to be available for ajax calls.
 elgg_unregister_ajax_view ($view)
 Unregister a view for ajax calls.
 elgg_get_view_location ($view, $viewtype= '')
 Returns the file location for a view.
 elgg_set_view_location ($view, $location, $viewtype= '')
 Set an alternative base location for a view.
 elgg_view_exists ($view, $viewtype= '', $recurse=true)
 Returns whether the specified view exists.
 elgg_view ($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
 elgg_extend_view ($view, $view_extension, $priority=501)
 Extends a view with another view.
 elgg_unextend_view ($view, $view_extension)
 Unextends a view.
 elgg_view_page ($title, $body, $page_shell= 'default', $vars=array())
 Assembles and outputs a full page.
 elgg_view_layout ($layout_name, $vars=array())
 Displays a layout with optional parameters.
 elgg_view_menu ($menu_name, array $vars=array())
 Render a menu.
 elgg_view_entity (ElggEntity $entity, $vars=array(), $bypass=true, $debug=false)
 Returns a string of a rendered entity.
 elgg_view_entity_icon (ElggEntity $entity, $size= 'medium', $vars=array())
 View the icon of an entity.
 elgg_view_annotation (ElggAnnotation $annotation, array $vars=array(), $bypass=true, $debug=false)
 Returns a string of a rendered annotation.
 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.
 elgg_view_annotation_list ($annotations, array $vars=array())
 Returns a rendered list of annotations, plus pagination.
 elgg_view_entity_annotations (ElggEntity $entity, $full_view=true)
 Display a plugin-specified rendered list of annotations for an entity.
 elgg_view_title ($title, $vars=array())
 Renders a title.
 elgg_view_friendly_time ($time)
 Displays a UNIX timestamp in a friendly way.
 elgg_view_comments ($entity, $add_comment=true, array $vars=array())
 Returns rendered comments and a comment form for an entity.
 elgg_view_image_block ($image, $body, $vars=array())
 Wrapper function for the image block display pattern.
 elgg_view_module ($type, $title, $body, array $vars=array())
 Wrapper function for the module display pattern.
 elgg_view_river_item ($item, array $vars=array())
 Renders a human-readable representation of a river item.
 elgg_view_form ($action, $form_vars=array(), $body_vars=array())
 elgg_view_list_item ($item, array $vars=array())
 View an item in a list.
 elgg_view_icon ($name, $class= '')
 View one of the elgg sprite icons.
 elgg_view_access_collections ($owner_guid)
 Displays a user's access collections, using the core/friends/collections view.
 set_template_handler ($function_name)
 Registers a function to handle templates.
 elgg_get_views ($dir, $base)
 Returns the name of views for in a directory.
 elgg_view_tree ($view_root, $viewtype="")
 Returns all views below a partial view.
 autoregister_views ($view_base, $folder, $base_location_path, $viewtype)
 Auto-registers views from a location.
 elgg_views_add_rss_link ()
 Add the rss link to the extras when if needed.
 elgg_views_handle_deprecated_views ()
 Registers deprecated views to avoid making some pages from older plugins completely empty.
 elgg_views_boot ()
 Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades.

Variables

global $CURRENT_SYSTEM_VIEWTYPE = ""
 Elgg's view system.

Function Documentation

autoregister_views ( view_base,
folder,
base_location_path,
viewtype 
)

Auto-registers views from a location.

Note:
Views in plugin/views/ are automatically registered for active plugins. Plugin authors would only need to call this if optionally including an entire views structure.
Parameters:
string $view_base Optional The base of the view name without the view type.
string $folder Required The folder to begin looking in
string $base_location_path The base views directory to use with elgg_set_view_location()
string $viewtype The type of view we're looking at (default, rss, etc)
Returns:
bool returns false if folder can't be read
Since:
1.7.0
See also:
elgg_set_view_location()

Definition at line 1512 of file views.php.

elgg_does_viewtype_fallback ( viewtype  ) 

Checks if a viewtype falls back to default.

Parameters:
string $viewtype Viewtype
Returns:
boolean
Since:
1.7.2

Definition at line 192 of file views.php.

elgg_extend_view ( view,
view_extension,
priority = 501 
)

Extends a view with another view.

The output of any view can be prepended or appended to any other view.

The default action is to append a view. If the priority is less than 500, the output of the extended view will be appended to the original view.

Priority can be specified and affects the order in which extensions are appended or prepended.

Definition at line 557 of file views.php.

elgg_get_view_location ( view,
viewtype = '' 
)

Returns the file location for a view.

Warning:
This doesn't check if the file exists, but only constructs (or extracts) the path and returns it.
Parameters:
string $view The view.
string $viewtype The viewtype
Returns:
string

Definition at line 245 of file views.php.

elgg_get_views ( dir,
base 
)

Returns the name of views for in a directory.

Use this to get all namespaced views under the first element.

Parameters:
string $dir The main directory that holds the views. (mod/profile/views/)
string $base The root name of the view to use, without the viewtype. (profile)
Returns:
array
Since:
1.7.0

Definition at line 1418 of file views.php.

elgg_get_viewtype (  ) 

Return the current view type.

View types are automatically detected and can be set with $_REQUEST['view'] or elgg_set_viewtype().

Definition at line 97 of file views.php.

elgg_is_valid_view_type ( view_type  ) 

Checks if $view_type is valid on this installation.

Parameters:
string $view_type View type
Returns:
bool
Since:
1.7.2 private

Definition at line 148 of file views.php.

elgg_register_ajax_view ( view  ) 

Register a view to be available for ajax calls.

Parameters:
string $view The view name
Returns:
void
Since:
1.8.3

Definition at line 209 of file views.php.

elgg_register_viewtype ( view_type  ) 

Register a view type as valid.

Parameters:
string $view_type The view type to register
Returns:
bool

Definition at line 125 of file views.php.

elgg_register_viewtype_fallback ( viewtype  ) 

Definition at line 170 of file views.php.

elgg_set_view_location ( view,
location,
viewtype = '' 
)

Set an alternative base location for a view.

Views are expected to be in plugin_name/views/. This function can be used to change that location.

Definition at line 279 of file views.php.

elgg_set_viewtype ( viewtype = ""  ) 

Definition at line 73 of file views.php.

elgg_unextend_view ( view,
view_extension 
)

Unextends a view.

Parameters:
string $view The view that was extended.
string $view_extension This view that was added to $view
Returns:
bool
Since:
1.7.2

Definition at line 589 of file views.php.

elgg_unregister_ajax_view ( view  ) 

Unregister a view for ajax calls.

Parameters:
string $view The view name
Returns:
void
Since:
1.8.3

Definition at line 226 of file views.php.

elgg_view ( view,
vars = array(),
bypass = false,
ignored = false,
viewtype = '' 
)

Definition at line 388 of file views.php.

elgg_view_access_collections ( owner_guid  ) 

Displays a user's access collections, using the core/friends/collections view.

Parameters:
int $owner_guid The GUID of the owning user
Returns:
string A formatted rendition of the collections

Definition at line 1362 of file views.php.

elgg_view_annotation ( ElggAnnotation annotation,
array $  vars = array(),
bypass = true,
debug = false 
)

Returns a string of a rendered annotation.

Annotation views are expected to be in annotation/$annotation_name. If a view is not found for $annotation_name, the default annotation/default will be used.

Warning:
annotation/default is not currently defined in core.

The annotation view is called with the following in $vars:

  • ElggEntity 'annotation' The annotation being viewed.
Parameters:
ElggAnnotation $annotation The annotation to display
array $vars Variable array for view.
bool $bypass If false, will not pass to a custom template handler. {
See also:
set_template_handler()}
Parameters:
bool $debug Complain if views are missing
Returns:
string/false Rendered annotation

Definition at line 937 of file views.php.

elgg_view_annotation_list ( annotations,
array $  vars = array() 
)

Returns a rendered list of annotations, plus pagination.

This function should be called by wrapper functions.

Parameters:
array $annotations Array of annotations
array $vars Display variables 'count' The total number of annotations across all pages 'offset' The current indexing offset 'limit' The number of annotations to display per page 'full_view' Display the full view of the annotation? 'list_class' CSS Class applied to the list 'offset_key' The url parameter key used for offset
Returns:
string The list of annotations private

Definition at line 1060 of file views.php.

elgg_view_comments ( entity,
add_comment = true,
array $  vars = array() 
)

Returns rendered comments and a comment form for an entity.

Plugins can override the output by registering a handler for the comments, $entity_type hook. The handler is responsible for formatting the comments and the add comment form.

Parameters:
ElggEntity $entity The entity to view comments of
bool $add_comment Include a form to add comments?
array $vars Variables to pass to comment view
Returns:
string|false Rendered comments or false on failure http://docs.elgg.org/Annotations/Comments

Definition at line 1155 of file views.php.

elgg_view_entity ( ElggEntity entity,
vars = array(),
bypass = true,
debug = false 
)

Returns a string of a rendered entity.

Entity views are either determined by setting the view property on the entity or by having a view named after the entity $type/$subtype. Entities that have neither a view property nor a defined $type/$subtype view will fall back to using the $type/default view.

The entity view is called with the following in $vars:

Other common view $vars paramters:

  • bool 'full_view' Whether to show a full or condensed view.

This function can automatically appends annotations to entities if in full view and a handler is registered for the entity:annotate. See { 964} and elgg_view_entity_annotations().

Parameters:
ElggEntity $entity The entity to display
array $vars Array of variables to pass to the entity view. In Elgg 1.7 and earlier it was the boolean $full_view
boolean $bypass If false, will not pass to a custom template handler. {
See also:
set_template_handler()}
Parameters:
boolean $debug Complain if views are missing
Returns:
string HTML to display or false http://docs.elgg.org/Entities todo 78.

Definition at line 813 of file views.php.

elgg_view_entity_annotations ( ElggEntity entity,
full_view = true 
)

Display a plugin-specified rendered list of annotations for an entity.

This displays the output of functions registered to the entity:annotation, $entity_type plugin hook.

This is called automatically by the framework from elgg_view_entity()

Parameters:
ElggEntity $entity Entity
bool $full_view Display full view?
Returns:
mixed string or false on failure

Definition at line 1087 of file views.php.

elgg_view_entity_icon ( ElggEntity entity,
size = 'medium',
vars = array() 
)

View the icon of an entity.

Entity views are determined by having a view named after the entity $type/$subtype. Entities that do not have a defined icon/$type/$subtype view will fall back to using the icon/$type/default view.

Parameters:
ElggEntity $entity The entity to display
string $size The size: tiny, small, medium, large
array $vars An array of variables to pass to the view. Some possible variables are img_class and link_class. See the specific icon view for more parameters.
Returns:
string HTML to display or false

Definition at line 886 of file views.php.

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.

This function should be called by wrapper functions.

See also:
elgg_list_entities()
list_user_friends_objects()
elgg_list_entities_from_metadata()
elgg_list_entities_from_relationships()
elgg_list_entities_from_annotations()
Parameters:
array $entities Array of entities
array $vars Display variables 'count' The total number of entities across all pages 'offset' The current indexing offset 'limit' The number of entities to display per page 'full_view' Display the full view of the entities? 'list_class' CSS class applied to the list 'item_class' CSS class applied to the list items 'pagination' Display pagination? 'list_type' List type: 'list' (default), 'gallery' 'list_type_toggle' Display the list type toggle?
Returns:
string The rendered list of entities private

Definition at line 992 of file views.php.

elgg_view_exists ( view,
viewtype = '',
recurse = true 
)

Returns whether the specified view exists.

Note:
If $recurse is true, also checks if a view exists only as an extension.
Parameters:
string $view The view name
string $viewtype If set, forces the viewtype
bool $recurse If false, do not check extensions
Returns:
bool

Definition at line 312 of file views.php.

elgg_view_form ( action,
form_vars = array(),
body_vars = array() 
)

Definition at line 1290 of file views.php.

elgg_view_friendly_time ( time  ) 

Displays a UNIX timestamp in a friendly way.

See also:
elgg_get_friendly_time()
Parameters:
int $time A UNIX epoch timestamp
Returns:
string The friendly time HTML
Since:
1.7.2

Definition at line 1135 of file views.php.

elgg_view_icon ( name,
class = '' 
)

View one of the elgg sprite icons.

Shorthand for

Parameters:
string $name The specific icon to display
string $class Additional class: float, float-alt, or custom class
Returns:
string The html for displaying an icon

Definition at line 1345 of file views.php.

elgg_view_image_block ( image,
body,
vars = array() 
)

Wrapper function for the image block display pattern.

Fixed width media on the side (image, icon, flash, etc.). Descriptive content filling the rest of the column.

This is a shortcut for { page/components/image_block}.

Parameters:
string $image The icon and other information
string $body Description content
array $vars Additional parameters for the view
Returns:
string
Since:
1.8.0

Definition at line 1187 of file views.php.

elgg_view_layout ( layout_name,
vars = array() 
)

Displays a layout with optional parameters.

Layouts provide consistent organization of pages and other blocks of content. There are a few default layouts in core:

  • admin A special layout for the admin area.
  • one_column A single content column.
  • one_sidebar A content column with sidebar.
  • two_sidebar A content column with two sidebars.
  • widgets A widget canvas.

The layout views take the form page/layouts/$layout_name See the individual layouts for what options are supported. The three most common layouts have these parameters: one_column content => string one_sidebar content => string sidebar => string (optional) content content => string sidebar => string (optional) buttons => string (override the default add button) title => string (override the default title) filter_context => string (selected content filter) See the content layout view for more parameters

Parameters:
string $layout_name The name of the view in page/layouts/.
array $vars Associative array of parameters for the layout view
Returns:
string The layout

Definition at line 689 of file views.php.

elgg_view_list_item ( item,
array $  vars = array() 
)

View an item in a list.

Parameters:
ElggEntity|ElggAnnotation $item
array $vars Additional parameters for the rendering
Returns:
string
Since:
1.8.0 private

Definition at line 1320 of file views.php.

elgg_view_menu ( menu_name,
array $  vars = array() 
)

Render a menu.

See also:
elgg_register_menu_item() for documentation on adding menu items and navigation.php for information on the different menus available.

This function triggers a 'register', 'menu:<menu name>="">' plugin hook that enables plugins to add menu items just before a menu is rendered. This is used by dynamic menus (menus that change based on some input such as the user hover menu). Using elgg_register_menu_item() in response to the hook can cause incorrect links to show up. See the blog plugin's blog_owner_block_menu() for an example of using this plugin hook.

An additional hook is the 'prepare', 'menu:<menu name>="">' which enables plugins to modify the structure of the menu (sort it, remove items, set variables on the menu items).

elgg_view_menu() uses views in navigation/menu

Parameters:
string $menu_name The name of the menu
array $vars An associative array of display options for the menu. Options include: sort_by => string or php callback string options: 'name', 'priority', 'title' (default), 'register' (registration order) or a php callback (a compare function for usort) handler: string the page handler to build action URLs entity: ElggEntity to use to build action URLs class: string the class for the entire menu. show_section_headers: bool show headers before menu sections.
Returns:
string
Since:
1.8.0

Definition at line 752 of file views.php.

elgg_view_module ( type,
title,
body,
array $  vars = array() 
)

Wrapper function for the module display pattern.

Box with header, body, footer

This is a shortcut for { page/components/module}.

Parameters:
string $type The type of module (main, info, popup, aside, etc.)
string $title A title to put in the header
string $body Content of the module
array $vars Additional parameters for the module
Returns:
string
Since:
1.8.0

Definition at line 1208 of file views.php.

elgg_view_page ( title,
body,
page_shell = 'default',
vars = array() 
)

Assembles and outputs a full page.

A "page" in Elgg is determined by the current view type and can be HTML for a browser, RSS for a feed reader, or Javascript, PHP and a number of other formats.

Parameters:
string $title Title
string $body Body
string $page_shell Optional page shell to use. See page/shells view directory
array $vars Optional vars array to pass to the page shell. Automatically adds title, body, and sysmessages
Returns:
string The contents of the page
Since:
1.8

Definition at line 622 of file views.php.

elgg_view_river_item ( item,
array $  vars = array() 
)

Renders a human-readable representation of a river item.

Parameters:
ElggRiverItem $item A river item object
array $vars An array of variables for the view
Returns:
string returns empty string if could not be rendered

Definition at line 1223 of file views.php.

elgg_view_title ( title,
vars = array() 
)

Renders a title.

This is a shortcut for { page/elements/title}.

Parameters:
string $title The page title
array $vars View variables (was submenu be displayed? (deprecated))
Returns:
string The HTML (etc)

Definition at line 1114 of file views.php.

elgg_view_tree ( view_root,
viewtype = "" 
)

Returns all views below a partial view.

Settings $view_root = 'profile' will show all available views under the "profile" namespace.

Parameters:
string $view_root The root view
string $viewtype Optionally specify a view type other than the current one.
Returns:
array A list of view names underneath that root view

Definition at line 1454 of file views.php.

elgg_views_add_rss_link (  ) 

Add the rss link to the extras when if needed.

Returns:
void private

Definition at line 1550 of file views.php.

elgg_views_boot (  ) 

Initialize viewtypes on system boot event This ensures simplecache is cleared during upgrades.

See #2252

Returns:
void private boot system

Definition at line 1591 of file views.php.

elgg_views_handle_deprecated_views (  ) 

Registers deprecated views to avoid making some pages from older plugins completely empty.

private

Definition at line 1576 of file views.php.

set_template_handler ( function_name  ) 

Registers a function to handle templates.

Alternative template handlers can be registered to handle all output functions. By default, elgg_view() will simply include the view file. If an alternate template handler is registered, the view name and passed $vars will be passed to the registered function, which is then responsible for generating and returning output.

Template handlers need to accept two arguments: string $view_name and array $vars.

Warning:
This is experimental.
Parameters:
string $function_name The name of the function to pass to.
Returns:
bool
See also:
elgg_view() http://docs.elgg.org/Views/TemplateHandlers

Definition at line 1394 of file views.php.


Variable Documentation

$CURRENT_SYSTEM_VIEWTYPE = ""

Elgg's view system.

The view system is the primary templating engine in Elgg and renders all output. Views are short, parameterised PHP scripts for displaying output that can be regsitered, overridden, or extended. The view type determines the output format and location of the files that renders the view.

Elgg uses a two step process to render full output: first content-specific elements are rendered, then the resulting content is inserted into a layout and displayed. This makes it easy to maintain a consistent look on all pages.

A view corresponds to a single file on the filesystem and the views name is its directory structure. A file in mod/plugins/views/default/myplugin/example.php is called by saying (with the default viewtype): echo elgg_view('myplugin/example');

View names that are registered later override those that are registered earlier. For plugins this corresponds directly to their load order: views in plugins lower in the list override those higher in the list.

Plugin views belong in the views/ directory under an appropriate viewtype. Views are automatically registered.

Views can be embedded-you can call a view from within a view. Views can also be prepended or extended by any other view.

Any view can extend any other view if registered with elgg_extend_view().

View types are set by passing $_REQUEST['view']. The view type 'default' is a standard HTML view. Types can be defined on the fly and you can get the current view type with get_current_view(). The view type override.

string $CURRENT_SYSTEM_VIEWTYPE

See also:
elgg_set_viewtype()

Definition at line 56 of file views.php.

 All Classes Namespaces Files Functions Variables Enumerations
Generated on Thu May 23 00:01:25 2013 for Elgg by  doxygen 1.6.3