aboutsummaryrefslogtreecommitdiff
path: root/mod/messageboard/ajax_endpoint/load.php
blob: 4509c30ef13a90dab0c57d0d1eff22c2d86f9835 (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
<?php

/**
 * Elgg message board widget ajax logic page
 *
 * @package ElggMessageBoard
 */

// Load Elgg engine will not include plugins
require_once(dirname(dirname(dirname(dirname(__FILE__)))) . "/engine/start.php");

//get the required info

//the actual message
$message = get_input('messageboard_content');
//the number of messages to display
$numToDisplay = get_input('numToDisplay');    
//get the full page owner entity
$user = get_entity(get_input('pageOwner'));

//stage one - if a message was posted, add it as an annotation    
if ($message) {

	if (!messageboard_add(elgg_get_logged_in_user_entity(), $user, $message, $user->access_id)) {
		echo elgg_echo("messageboard:failure");
	}

} else {
	echo elgg_echo('messageboard:somethingwentwrong');
}


//step two - grab the latest messageboard contents, this will include the message above, unless an issue 
//has occurred.
$contents = $user->getAnnotations('messageboard', $numToDisplay, 0, 'desc'); 

//step three - display the latest results
if ($contents) {
	foreach ($contents as $content) {
		echo elgg_view("messageboard/messageboard_content", array('annotation' => $content));
	}
}