forked from LocalGood/Goteo
-
Notifications
You must be signed in to change notification settings - Fork 2
/
blog.php
89 lines (75 loc) · 2.77 KB
/
blog.php
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
<?php
/*
* Copyright (C) 2012 Platoniq y Fundación Fuentes Abiertas (see README for details)
* This file is part of Goteo.
*
* Goteo is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Goteo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Goteo. If not, see <http://www.gnu.org/licenses/agpl.txt>.
*
*/
namespace Goteo\Controller {
use Goteo\Core\View,
Goteo\Library\Text,
Goteo\Library\Message,
Goteo\Model;
class Blog extends \Goteo\Core\Controller {
public function index ($post = null) {
if (!empty($post)) {
$show = 'post';
// -- Mensaje azul molesto para usuarios no registrados
if (empty($_SESSION['user'])) {
$_SESSION['jumpto'] = '/blog/' . $post;
Message::Info(Text::html('user-login-required'));
}
} else {
$show = 'list';
}
// sacamos su blog
$blog = Model\Blog::get(\GOTEO_NODE, 'node');
$filters = array();
if (isset($_GET['tag'])) {
$tag = Model\Blog\Post\Tag::get($_GET['tag']);
if (!empty($tag->id)) {
$filters['tag'] = $tag->id;
}
} else {
$tag = null;
}
if (isset($_GET['author'])) {
$author = Model\User::getMini($_GET['author']);
if (!empty($author->id)) {
$filters['author'] = $author->id;
}
} else {
$author = null;
}
if (!empty($filters)) {
$blog->posts = Model\Blog\Post::getList($filters);
}
if (isset($post) && !isset($blog->posts[$post]) && $_GET['preview'] != $_SESSION['user']->id) {
throw new \Goteo\Core\Redirection('/blog');
}
// segun eso montamos la vista
return new View(
'view/blog/index.html.php',
array(
'blog' => $blog,
'show' => $show,
'filters' => $filters,
'post' => $post,
'owner' => \GOTEO_NODE
)
);
}
}
}