aboutsummaryrefslogtreecommitdiff
path: root/mod/sitepages/actions/add.php
blob: bc38d80679f3664da499d2a0bed6285237781322 (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
<?php
/**
 * Site pages save/edit
 *
 * @package SitePages
 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
 * @author Curverider Ltd <info@elgg.com>
 * @copyright Curverider Ltd 2008-2010
 * @link http://elgg.com/
 *
 */

// Make sure we're logged as admin
admin_gatekeeper();

// Get input data
$content = get_input('sitepages_content', '', FALSE);
$page_type = get_input('page_type');
$tags = get_input('sitepages_tags');
$tag_array = string_to_tag_array($tags);

// Cache to the session for sticky forms
// @todo make these work.
$_SESSION['sitepages_content'] = $content;
$_SESSION['sitepages_type'] = $type;
$_SESSION['sitepages_tags'] = $tags;

if (!$sitepage = sitepages_get_sitepage_object($page_type)) {
	$sitepage = sitepages_create_sitepage_object($page_type);
}

if (empty($content)) {
	register_error(elgg_echo('sitepages:blank'));
} else {
	$sitepage->title = $type;
	$sitepage->description = $content;
	$sitepage->tags = $tag_array;

	if (!$sitepage->save()) {
		register_error(elgg_echo('sitepages:error'));
	} else {
		system_message(elgg_echo('sitepages:posted'));
		// @todo this needs to be accurate for create or update.
		add_to_river('river/sitepages/create', 'create', $_SESSION['user']->guid, $sitepages->guid);
	}

	// @todo Good intensions...
	unset($_SESSION['sitepages_content']);
	unset($_SESSION['sitepagestitle']);
	unset($_SESSION['sitepagestags']);
}

forward($_SERVER['HTTP_REFERER']);