Elgg  Version 1.10
comments_block.php
Go to the documentation of this file.
1 <?php
12 $options = array(
13  'type' => 'object',
14  'subtype' => 'comment',
15  'limit' => elgg_extract('limit', $vars, 4),
16  'wheres' => array(),
17  'preload_owners' => true,
18  'distinct' => false,
19 );
20 
21 $owner_guid = elgg_extract('owner_guid', $vars);
22 $subtypes = elgg_extract('subtypes', $vars);
23 
24 if ($owner_guid || $subtypes) {
25  $db_prefix = elgg_get_config('dbprefix');
26 
27  // Join on the entities table to check container subtype and/or owner
28  $options['joins'] = array("JOIN {$db_prefix}entities ce ON e.container_guid = ce.guid");
29 }
30 
31 // If owner is defined, view only the comments that have
32 // been posted on objects owned by that user
33 if ($owner_guid) {
34  $owner_entity = get_entity($owner_guid);
35  if (!$owner_entity instanceof ElggUser) {
36  // Only supporting users so no need to continue
37  return true;
38  }
39 
40  $options['wheres'][] = "ce.owner_guid = $owner_guid";
41 }
42 
43 // If subtypes are defined, view only the comments that have been
44 // posted on objects that belong to any of those subtypes
45 if ($subtypes) {
46  if (is_array($subtypes)) {
47  $subtype_ids = array();
48  foreach ($subtypes as $subtype) {
49  $id = (int)get_subtype_id('object', $subtype);
50  if ($id) {
51  $subtype_ids[] = $id;
52  }
53  }
54  if ($subtype_ids) {
55  $subtype_string = implode(',', $subtype_ids);
56  $options['wheres'][] = "ce.subtype IN ($subtype_string)";
57  } else {
58  // subtype ids do not exist so cannot display comments
59  $options['wheres'][] = "1 = -1";
60  }
61  } else {
62  $subtype_id = (int)get_subtype_id('object', $subtypes);
63  $options['wheres'][] = "ce.subtype = $subtype_id";
64  }
65 }
66 
67 $title = elgg_echo('generic_comments:latest');
69 if ($comments) {
70  $body = elgg_view('page/components/list', array(
71  'items' => $comments,
72  'pagination' => false,
73  'list_class' => 'elgg-latest-comments',
74  'full_view' => false,
75  ));
76 } else {
77  $body = '<p>' . elgg_echo('generic_comment:none') . '</p>';
78 }
79 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
elgg_view_module($type, $title, $body, array $vars=array())
Wrapper function for the module display pattern.
Definition: views.php:1199
$comments
get_subtype_id($type, $subtype)
Return the id for a given subtype.
Definition: entities.php:157
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:1349
$owner_guid
if($owner_guid||$subtypes) if($owner_guid) if($subtypes) $title
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg echo
Translates a string.
Definition: languages.js:43
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:490
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
$options
Display the latest related comments.
$subtypes
$subtype
Definition: river.php:12
if(!$collection_name) $id
Definition: add.php:17
if(!$num_display) $db_prefix
Definition: content.php:12
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382
if(file_exists($welcome)) $vars
Definition: upgrade.php:93