aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/configureController.php
blob: e61eb38728e411379391f642a5efaa16d9a0c2d1 (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
114
115
116
117
118
119
120
121
122
<?php

class configureController extends ActionController {
	public function categorizeAction () {
		$catDAO = new CategoryDAO ();
		
		if (Request::isPost ()) {
			$cats = Request::param ('categories', array ());
			$ids = Request::param ('ids', array ());
			$newCat = Request::param ('new_category');
			
			foreach ($cats as $key => $name) {
				if (strlen ($name) > 0) {
					$cat = new Category ($name);
					$values = array (
						'name' => $cat->name (),
						'color' => $cat->color ()
					);
					$catDAO->updateCategory ($ids[$key], $values);
				} else {
					$catDAO->deleteCategory ($ids[$key]);
				}
			}
			
			if ($newCat != false) {
				$cat = new Category ($newCat);
				$values = array (
					'id' => $cat->id (),
					'name' => $cat->name (),
					'color' => $cat->color ()
				);
				$catDAO->addCategory ($values);
			}
			
			$catDAO->save ();
			
		}
		
		$this->view->categories = $catDAO->listCategories ();
	}
	
	public function fluxAction () {
		$feedDAO = new FeedDAO ();
		$this->view->feeds = $feedDAO->listFeeds ();
		
		$id = Request::param ('id');
		
		$this->view->flux = false;
		if ($id != false) {
			$this->view->flux = $feedDAO->searchById ($id);
			
			$catDAO = new CategoryDAO ();
			$this->view->categories = $catDAO->listCategories ();
			
			if (Request::isPost () && $this->view->flux) {
				$cat = Request::param ('category');
				$values = array (
					'category' => $cat
				);
				$feedDAO->updateFeed ($id, $values);
				
				$this->view->flux->_category ($cat);
			}
		}
	}
	
	public function displayAction () {
		if (Request::isPost ()) {
			$nb = Request::param ('posts_per_page', 10);
			$view = Request::param ('default_view', 'all');
			$display = Request::param ('display_posts', 'no');
			$sort = Request::param ('sort_order', 'low_to_high');
		
			$this->view->conf->_postsPerPage (intval ($nb));
			$this->view->conf->_defaultView ($view);
			$this->view->conf->_displayPosts ($display);
			$this->view->conf->_sortOrder ($sort);
		
			$values = array (
				'posts_per_page' => $this->view->conf->postsPerPage (),
				'default_view' => $this->view->conf->defaultView (),
				'display_posts' => $this->view->conf->displayPosts (),
				'sort_order' => $this->view->conf->sortOrder ()
			);
		
			$confDAO = new RSSConfigurationDAO ();
			$confDAO->save ($values);
			Session::_param ('conf', $this->view->conf);
		}
	}
	
	public function importExportAction () {
		$this->view->req = Request::param ('q');
		
		if ($this->view->req == 'export') {
			View::_title ('feeds_opml.xml');
			
			$this->view->_useLayout (false);
			header('Content-type: text/xml');
			
			$feedDAO = new FeedDAO ();
			$catDAO = new CategoryDAO ();
			
			$list = array ();
			foreach ($catDAO->listCategories () as $key => $cat) {
				$list[$key]['name'] = $cat->name ();
				$list[$key]['feeds'] = $feedDAO->listByCategory ($cat->id ());
			}
			
			$this->view->categories = $list;
		} elseif ($this->view->req == 'import' && Request::isPost ()) {
			if ($_FILES['file']['error'] == 0) {
				$content = file_get_contents ($_FILES['file']['tmp_name']);
				$feeds = opml_import ($content);
				
				Request::_param ('q');
				Request::_param ('feeds', $feeds);
				Request::forward (array ('c' => 'feed', 'a' => 'massiveInsert'));
			}
		}
	}
}