Daan is sweet to Kelley and delegates himself TestCMS code reflection
[ssproject1617.git] / testcms-final-anon / system / classes / metadata.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Metadata {
4
5 public static function update() {
6 $post = Input::post(array('sitename', 'description', 'theme', 'twitter', 'home_page', 'posts_page', 'auto_published_comments', 'posts_per_page'));
7 $errors = array();
8
9 if(empty($post['sitename'])) {
10 $errors[] = 'You need a site sitename';
11 }
12
13 if(empty($post['description'])) {
14 $errors[] = 'You need a site description';
15 }
16
17 if(empty($post['theme'])) {
18 $errors[] = 'You need a theme';
19 }
20
21 // auto publish comments
22 $post['auto_published_comments'] = $post['auto_published_comments'] ? 1 : 0;
23
24 // format posts per page, must be a whole number above 1 defaults to 10 if a invalid number is entered
25 $post['posts_per_page'] = ($posts_per_page = intval($post['posts_per_page'])) > 0 ? $posts_per_page : 10;
26
27 if(count($errors)) {
28 Notifications::set('error', $errors);
29 return false;
30 }
31
32 foreach($post as $key => $value) {
33 Db::update('meta', array('value' => $value), array('key' => $key));
34 }
35
36 Notifications::set('success', 'Your metadata has been updated');
37
38 return true;
39 }
40
41 }