Example #1
0
/**
 * 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:
 *  - ElggEntity 'entity' The entity being viewed
 *
 * Other common view $vars paramters:
 *  - bool 'full_view' Whether to show a full or condensed view. (Default: true)
 *
 * @tip This function can automatically appends annotations to entities if in full
 * view and a handler is registered for the entity:annotate.  See https://github.com/Elgg/Elgg/issues/964 and
 * {@link elgg_view_entity_annotations()}.
 *
 * @param ElggEntity $entity The entity to display
 * @param array      $vars   Array of variables to pass to the entity view.
 *                           In Elgg 1.7 and earlier it was the boolean $full_view
 * @param boolean    $bypass If true, will not pass to a custom template handler.
 *                           {@link set_template_handler()}
 * @param boolean    $debug  Complain if views are missing
 *
 * @return string HTML to display or false
 * @todo The annotation hook might be better as a generic plugin hook to append content.
 */
function elgg_view_entity(ElggEntity $entity, $vars = array(), $bypass = false, $debug = false)
{
    // No point continuing if entity is null
    if (!$entity || !$entity instanceof ElggEntity) {
        return false;
    }
    global $autofeed;
    $autofeed = true;
    $defaults = array('full_view' => true);
    if (is_array($vars)) {
        $vars = array_merge($defaults, $vars);
    } else {
        elgg_deprecated_notice("Update your use of elgg_view_entity()", 1.8);
        $vars = array('full_view' => $vars);
    }
    $vars['entity'] = $entity;
    // if this entity has a view defined, use it
    $view = $entity->view;
    if (is_string($view)) {
        return elgg_view($view, $vars, $bypass, $debug);
    }
    $entity_type = $entity->getType();
    $subtype = $entity->getSubtype();
    if (empty($subtype)) {
        $subtype = 'default';
    }
    $contents = '';
    if (elgg_view_exists("{$entity_type}/{$subtype}")) {
        $contents = elgg_view("{$entity_type}/{$subtype}", $vars, $bypass, $debug);
    } else {
        $contents = elgg_view("{$entity_type}/default", $vars, $bypass, $debug);
    }
    // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
    if ($vars['full_view']) {
        $annotations = elgg_view_entity_annotations($entity, $vars['full_view']);
        if ($annotations) {
            $contents .= $annotations;
        }
    }
    return $contents;
}
/**
 * When given an entity, views it intelligently.
 * 
 * Expects a view to exist called entity-type/subtype, or for the entity to have a parameter
 * 'view' which lists a different view to display.  In both cases, elgg_view will be called with
 * array('entity' => $entity) as its parameters, and therefore this is what the view should expect
 * to receive. 
 *
 * @param ElggEntity $entity The entity to display
 * @param boolean $full Determines whether or not to display the full version of an object, or a smaller version for use in aggregators etc
 * @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
 * @param boolean $debug If set to true, the viewer will complain if it can't find a view
 * @return string HTML (etc) to display
 */
function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $debug = false)
{
    global $autofeed;
    $autofeed = true;
    // No point continuing if entity is null.
    if (!$entity) {
        return '';
    }
    $view = $entity->view;
    if (is_string($view)) {
        return elgg_view($view, array('entity' => $entity), $bypass, $debug);
    }
    $classes = array('ElggUser' => 'user', 'ElggObject' => 'object', 'ElggSite' => 'site', 'ElggGroup' => 'group');
    $entity_class = get_class($entity);
    if (isset($classes[$entity_class])) {
        $entity_type = $classes[$entity_class];
    } else {
        foreach ($classes as $class => $type) {
            if ($entity instanceof $class) {
                $entity_type = $type;
                break;
            }
        }
    }
    if (!isset($entity_class)) {
        return false;
    }
    $subtype = $entity->getSubtype();
    if (empty($subtype)) {
        $subtype = $entity_type;
    }
    $contents = '';
    if (elgg_view_exists("{$entity_type}/{$subtype}")) {
        $contents = elgg_view("{$entity_type}/{$subtype}", array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    if (empty($contents)) {
        $contents = elgg_view("{$entity_type}/default", array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    if ($full) {
        $annotations = elgg_view_entity_annotations($entity, $full);
        if ($annotations) {
            $contents .= $annotations;
        }
    }
    return $contents;
}
Example #3
0
/**
 * 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:
 *  - \ElggEntity 'entity' The entity being viewed
 *
 * @tip This function can automatically appends annotations to entities if in full
 * view and a handler is registered for the entity:annotate.  See https://github.com/Elgg/Elgg/issues/964 and
 * {@link elgg_view_entity_annotations()}.
 *
 * @param \ElggEntity $entity The entity to display
 * @param array       $vars   Array of variables to pass to the entity view.
 *      'full_view'        Whether to show a full or condensed view. (Default: true)
 *      'item_view'        Alternative view used to render this entity
 * @param boolean     $bypass Ignored and will be removed eventually
 * @param boolean     $debug  Complain if views are missing
 *
 * @return string HTML to display or false
 * @todo The annotation hook might be better as a generic plugin hook to append content.
 */
function elgg_view_entity(\ElggEntity $entity, array $vars = array(), $bypass = false, $debug = false)
{
    // No point continuing if entity is null
    if (!$entity || !$entity instanceof \ElggEntity) {
        return false;
    }
    global $autofeed;
    $autofeed = true;
    $defaults = array('full_view' => true);
    $vars = array_merge($defaults, $vars);
    $vars['entity'] = $entity;
    $entity_type = $entity->getType();
    $entity_subtype = $entity->getSubtype();
    if (empty($entity_subtype)) {
        $entity_subtype = 'default';
    }
    $entity_views = array(elgg_extract('item_view', $vars, ''), "{$entity_type}/{$entity_subtype}", "{$entity_type}/default");
    $contents = '';
    foreach ($entity_views as $view) {
        if (elgg_view_exists($view)) {
            $contents = elgg_view($view, $vars, $bypass, $debug);
            break;
        }
    }
    // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
    if ($vars['full_view']) {
        $annotations = elgg_view_entity_annotations($entity, $vars['full_view']);
        if ($annotations) {
            $contents .= $annotations;
        }
    }
    return $contents;
}
Example #4
0
/**
 * When given an entity, views it intelligently.
 *
 * Expects a view to exist called entity-type/subtype, or for the entity to have a parameter
 * 'view' which lists a different view to display.  In both cases, elgg_view will be called with
 * array('entity' => $entity, 'full' => $full) as its parameters, and therefore this is what
 * the view should expect to receive.
 *
 * @param ElggEntity $entity The entity to display
 * @param boolean $full Determines whether or not to display the full version of an object, or a smaller version for use in aggregators etc
 * @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
 * @param boolean $debug If set to true, the viewer will complain if it can't find a view
 * @return string HTML to display or false
 */
function elgg_view_entity(ElggEntity $entity, $full = false, $bypass = true, $debug = false)
{
    global $autofeed;
    $autofeed = true;
    // No point continuing if entity is null
    if (!$entity) {
        return '';
    }
    if (!$entity instanceof ElggEntity) {
        return false;
    }
    // if this entity has a view defined, use it
    $view = $entity->view;
    if (is_string($view)) {
        return elgg_view($view, array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    $entity_type = $entity->getType();
    $subtype = $entity->getSubtype();
    if (empty($subtype)) {
        $subtype = $entity_type;
    }
    $contents = '';
    if (elgg_view_exists("{$entity_type}/{$subtype}")) {
        $contents = elgg_view("{$entity_type}/{$subtype}", array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    if (empty($contents)) {
        $contents = elgg_view("{$entity_type}/default", array('entity' => $entity, 'full' => $full), $bypass, $debug);
    }
    // Marcus Povey 20090616 : Speculative and low impact approach for fixing #964
    if ($full) {
        $annotations = elgg_view_entity_annotations($entity, $full);
        if ($annotations) {
            $contents .= $annotations;
        }
    }
    return $contents;
}