aboutsummaryrefslogtreecommitdiff
path: root/mod/sitepages/sitepages_functions.php
blob: 39693a2c8a1bfd0f71a37397c1750ee3dd218b9f (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
 * Helper functions for Site Pages.
 *
 * @package SitePages
 */


/**
 * Returns a single object that holds information about
 * customizations for the $page_type site page.  The object guid
 * is stored as private data on the site entity.  This allows the pages
 * to still be searchable as standard entities.
 *
 * @param $type
 * @return mixed ElggSitePage on success, FALSE on fail
 */
function sitepages_get_sitepage_object($page_type) {
	global $CONFIG;

	$page_guid = get_private_setting($CONFIG->site->getGUID(), "sitepages:$page_type");
	$sitepage = get_entity($page_guid);

	if ($sitepage instanceof ElggSitePage || $sitepage->page_type == $page_type) {
		return $sitepage;
	}

	return FALSE;
}

/**
 * Creates a site page object.
 *
 * @param str $page_type
 * @return mixed ElggSitePage on success, FALSE on fail.
 */
function sitepages_create_sitepage_object($page_type) {
	global $CONFIG;

	$sitepage = new ElggSitePage();
	$sitepage->page_type = $page_type;
	$sitepage->access_id = ACCESS_PUBLIC;
	$sitepage->save();

	if ($sitepage->save() && set_private_setting($CONFIG->site->getGUID(), "sitepages:$page_type", $sitepage->getGUID())) {
		return $sitepage;
	}

	return FALSE;
}

/**
 * Assembles html for edit sections of site pages.
 *
 * @param str $section
 * @return str html
 */
function sitepages_get_edit_section_content($page_type, $entity=NULL) {
	$menu = elgg_view('sitepages/menu', array('page_type' => $page_type));

	switch ($page_type) {
		case 'front':
			$view = 'sitepages/forms/editfrontsimple';
			break;

		case 'seo':
			$view = 'sitepages/forms/editmeta';
			break;

		default:
			$view = 'sitepages/forms/edit';
			break;

	}

	$form .= elgg_view($view, array(
		'page_type' => $page_type,
		'entity' => $entity,
	));
	return $menu . $form;
}

/**
 * Assembles html for displaying site pages
 *
 * @param string $page_type
 * @return string Formatted html
 */
function sitepages_get_page_content($page_type) {
	$body = elgg_view_title(elgg_echo("sitepages:". strtolower($page_type)));

	$sitepage = sitepages_get_sitepage_object($page_type);

	if ($sitepage) {
		$body .= $sitepage->description;
	} else {
		$body .= elgg_echo('sitepages:notset');
	}

	$content = elgg_view_layout('one_column_with_sidebar', array('content' => $body));
	return $content;
}

/**
 * Utility object to store site page information.
 */
class ElggSitePage extends ElggObject {
	public function initializeAttributes() {
		parent::initializeAttributes();

		$this->attributes['subtype'] = 'sitepages_page';
	}
}