Elgg  Version 1.9
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 );
18 
19 $owner_guid = elgg_extract('owner_guid', $vars);
20 $subtypes = elgg_extract('subtypes', $vars);
21 
22 if ($owner_guid || $subtypes) {
23  $db_prefix = elgg_get_config('dbprefix');
24 
25  // Join on the entities table to check container subtype and/or owner
26  $options['joins'] = array("JOIN {$db_prefix}entities ce ON e.container_guid = ce.guid");
27 }
28 
29 // If owner is defined, view only the comments that have
30 // been posted on objects owned by that user
31 if ($owner_guid) {
33  if (!$owner_entity instanceof ElggUser) {
34  // Only supporting users so no need to continue
35  return true;
36  }
37 
38  $options['wheres'][] = "ce.owner_guid = $owner_guid";
39 }
40 
41 // If subtypes are defined, view only the comments that have been
42 // posted on objects that belong to any of those subtypes
43 if ($subtypes) {
44  if (is_array($subtypes)) {
45  $subtype_ids = array();
46  foreach ($subtypes as $subtype) {
47  $id = (int)get_subtype_id('object', $subtype);
48  if ($id) {
49  $subtype_ids[] = $id;
50  }
51  }
52  if ($subtype_ids) {
53  $subtype_string = implode(',', $subtype_ids);
54  $options['wheres'][] = "ce.subtype IN ($subtype_string)";
55  } else {
56  // subtype ids do not exist so cannot display comments
57  $options['wheres'][] = "1 = -1";
58  }
59  } else {
60  $subtype_id = (int)get_subtype_id('object', $subtypes);
61  $options['wheres'][] = "ce.subtype = $subtype_id";
62  }
63 }
64 
65 $title = elgg_echo('generic_comments:latest');
67 if ($comments) {
68  $body = elgg_view('page/components/list', array(
69  'items' => $comments,
70  'pagination' => false,
71  'list_class' => 'elgg-latest-comments',
72  'full_view' => false,
73  ));
74 } else {
75  $body = '<p>' . elgg_echo('generic_comment:none') . '</p>';
76 }
77 
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:1197
$comments
get_subtype_id($type, $subtype)
Return the id for a given subtype.
Definition: entities.php:166
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
$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
if(!$owner_guid) $owner_entity
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:777
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:10
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:604
if(file_exists($welcome)) $vars
Definition: upgrade.php:93