aboutsummaryrefslogtreecommitdiff
path: root/mod/riverdashboard/endpoint/ping.php
blob: 2a87da746537db5efc0777d30e9506c96d66556a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
 * Check for new activity.
 * Outputs # of new activity items since $_GET['last_checked'] time
 */

// Load Elgg engine will not include plugins
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php");
     
// check for last checked time
if (!$seconds_passed = get_input('seconds_passed', 0)) {
  	echo '';
   	exit;
}

$last_reload = time() - $seconds_passed;

//grab any new annotations
$annotations = count_annotations('', '', '', '', '', '', '', $last_reload);
if(!$annotations)
	$annotations = 0;
//grab all new objects created	
$entity_creation = elgg_get_entities(array(
	'count' => TRUE, 
	'created_time_lower' => $last_reload,
	'wheres' => array('e.type != \'user\'')
));
if(!$entity_creation)
	$entity_creation = 0;
//grab any entities updated
$entity_update = elgg_get_entities(array(
	'count' => TRUE, 
	'modified_time_lower' => $last_reload,
	'wheres' => array('e.type != \'user\'')
));
if(!$entity_update)
	$entity_update = 0;
//get any relationships, such as friending - this is not working quite right yet
//$relationship_action = elgg_get_entities_from_relationship(array('count' => TRUE));
//if(!$relationship_action)
//	$relationship_action = 0;

//sum all totals
$all_activity = $annotations + $entity_creation + $entity_update;

if ($all_activity > 0) {
  	$s = ($all_activity == 1) ? '' : 's';
  	echo "<a href=\"\" onClick=\"window.location.reload();\" class=\"update_wire\" style='margin-top:9px;'>$all_activity update$s!</a>";
  	//echo "<script type=\"text/javascript\">$(document).ready(function() { document.title = \"[{$all_activity}] new item{$s}!\"; }); </script>";
?>
	<script type="text/javascript">
		$(document).ready(function(){
		  
			var pageTitleSubstring;
			var stringStartPosition = document.title.indexOf("]");
			
			if (stringStartPosition == -1) { // we haven't already altered page title
				pageTitleSubstring = document.title; 
			} else { // we previously prepended to page title, need to remove it first
				pageTitleSubstring = document.title.substring( (stringStartPosition+2) );
			}
			
			document.title = "[<?php echo $all_activity; ?> update<?php echo $s; ?>] "+pageTitleSubstring;
		});
	</script>

<?php  	
} else {
  	echo '';
   	exit;
}