summaryrefslogtreecommitdiff
path: root/app/controllers/entryController.php
blob: c01139ba44cab1e3a31a1b3a1cd806233d322c62 (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
<?php

class entryController extends ActionController {
	public function firstAction () {
		if (login_is_conf ($this->view->conf) && !is_logged ()) {
			Error::error (
				403,
				array ('error' => array (Translate::t ('access_denied')))
			);
		}

		$this->params = array ();
		$this->redirect = false;
		$ajax = Request::param ('ajax');
		if ($ajax) {
			$this->view->_useLayout (false);
		}
	}
	public function lastAction () {
		$ajax = Request::param ('ajax');
		if (!$ajax && $this->redirect) {
			Request::forward (array (
				'c' => 'index',
				'a' => 'index',
				'params' => $this->params
			), true);
		} else {
			Request::_param ('ajax');
		}
	}

	public function readAction () {
		$this->redirect = true;

		$id = Request::param ('id');
		$is_read = Request::param ('is_read');
		$get = Request::param ('get');
		$nextGet = Request::param ('nextGet', $get); 
		$idMax = Request::param ('idMax', 0);

		$is_read = !!$is_read;

		$entryDAO = new EntryDAO ();
		if ($id == false) {
			if (!$get) {
				$entryDAO->markReadEntries ($idMax);
			} else {
				$typeGet = $get[0];
				$get = substr ($get, 2);
				switch ($typeGet) {
					case 'c':
						$entryDAO->markReadCat ($get, $idMax);
						break;
					case 'f':
						$entryDAO->markReadFeed ($get, $idMax);
						break;
					case 's':
						$entryDAO->markReadEntries ($idMax, true);
						break;
					case 'a':
						$entryDAO->markReadEntries ($idMax);
						break;
				}
				if ($nextGet !== 'a') {
					$this->params = array ('get' => $nextGet);
				}
			}

			$notif = array (
				'type' => 'good',
				'content' => Translate::t ('feeds_marked_read')
			);
			Session::_param ('notification', $notif);
		} else {
			$entryDAO->markRead ($id, $is_read);
		}
	}

	public function bookmarkAction () {
		$this->redirect = true;

		$id = Request::param ('id');
		if ($id) {
			$entryDAO = new EntryDAO ();
			$entryDAO->markFavorite ($id, Request::param ('is_favorite'));
		}
	}

	public function optimizeAction() {
		@set_time_limit(300);
		invalidateHttpCache();

		// La table des entrées a tendance à grossir énormément
		// Cette action permet d'optimiser cette table permettant de grapiller un peu de place
		// Cette fonctionnalité n'est à appeler qu'occasionnellement
		$entryDAO = new EntryDAO();
		$entryDAO->optimizeTable();

		invalidateHttpCache();

		$notif = array (
			'type' => 'good',
			'content' => Translate::t ('optimization_complete')
		);
		Session::_param ('notification', $notif);

		Request::forward(array(
			'c' => 'configure',
			'a' => 'display'
		), true);
	}
}