Commit | Line | Data |
---|---|---|
92e80560 VZ |
1 | <?php |
2 | /*************************************************************************** | |
12262f13 | 3 | * Copyright (C) 2003-2011 Polytechnique.org * |
92e80560 VZ |
4 | * http://opensource.polytechnique.org/ * |
5 | * * | |
6 | * This program is free software; you can redistribute it and/or modify * | |
7 | * it under the terms of the GNU General Public License as published by * | |
8 | * the Free Software Foundation; either version 2 of the License, or * | |
9 | * (at your option) any later version. * | |
10 | * * | |
11 | * This program is distributed in the hope that it will be useful, * | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 | * GNU General Public License for more details. * | |
15 | * * | |
16 | * You should have received a copy of the GNU General Public License * | |
17 | * along with this program; if not, write to the Free Software * | |
18 | * Foundation, Inc., * | |
19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | |
20 | ***************************************************************************/ | |
21 | ||
22 | class GadgetsModule extends PLModule | |
23 | { | |
24 | function handlers() | |
25 | { | |
26 | return array( | |
27 | 'gadgets/ig-events.xml' => $this->make_hook('ig_events_xml', AUTH_PUBLIC, 'user', NO_HTTPS), | |
eb5a266d | 28 | 'gadgets/ig-events' => $this->make_hook('ig_events', AUTH_PUBLIC), |
92e80560 | 29 | 'gadgets/ig-search.xml' => $this->make_hook('ig_search_xml', AUTH_PUBLIC, 'user', NO_HTTPS), |
eb5a266d | 30 | 'gadgets/ig-search' => $this->make_hook('ig_search', AUTH_PUBLIC), |
92e80560 VZ |
31 | ); |
32 | } | |
33 | ||
a0b45322 FB |
34 | function handler_ig_events_xml(&$page) |
35 | { | |
92e80560 VZ |
36 | require_once 'gadgets/gadgets.inc.php'; |
37 | init_igoogle_xml('gadgets/ig-events.xml.tpl'); | |
38 | } | |
39 | ||
a0b45322 FB |
40 | function handler_ig_events(&$page) |
41 | { | |
92e80560 VZ |
42 | require_once 'gadgets/gadgets.inc.php'; |
43 | init_igoogle_html('gadgets/ig-events.tpl', AUTH_COOKIE); | |
44 | ||
1bf36cd1 | 45 | $events = XDB::iterator("SELECT SQL_CALC_FOUND_ROWS |
a0b45322 | 46 | e.id, e.titre, UNIX_TIMESTAMP(e.creation_date) AS creation_date, |
1bf36cd1 SJ |
47 | ev.uid IS NULL AS nonlu, e.uid |
48 | FROM announces AS e | |
f280f651 | 49 | LEFT JOIN announce_read AS ev ON (e.id = ev.evt_id AND ev.uid = {?}) |
1bf36cd1 SJ |
50 | WHERE FIND_IN_SET('valide', e.flags) AND expiration >= NOW() |
51 | ORDER BY e.creation_date DESC", S::i('uid')); | |
92e80560 | 52 | $page->assign('event_count', XDB::query("SELECT FOUND_ROWS()")->fetchOneCell()); |
a0b45322 FB |
53 | |
54 | Platal::load('events', 'feed.inc.php'); | |
55 | $user = S::user(); | |
56 | $data = array(); | |
57 | while ($e = PlFeed::nextEvent($events, $user)) { | |
58 | $data[] = $e; | |
59 | if (count($data) == 5) { | |
60 | break; | |
61 | } | |
62 | } | |
63 | $page->assign('events', $data); | |
92e80560 VZ |
64 | } |
65 | ||
66 | function handler_ig_search_xml(&$page) { | |
67 | require_once 'gadgets/gadgets.inc.php'; | |
68 | init_igoogle_xml('gadgets/ig-search.xml.tpl'); | |
69 | } | |
70 | ||
71 | function handler_ig_search(&$page) | |
72 | { | |
73 | if (Env::has('quick') && Env::s('quick') != '') { | |
d667c548 | 74 | global $globals; |
92e80560 | 75 | require_once 'userset.inc.php'; |
d667c548 | 76 | |
78a47eb4 | 77 | $view = new QuickSearchSet(); |
92e80560 VZ |
78 | $view->addMod('gadget', 'Gadget', true); |
79 | $view->apply(null, $page); | |
80 | ||
81 | $nb_tot = $view->count(); | |
82 | $page->assign('result_count', $nb_tot); | |
83 | ||
84 | if (!S::logged() && $nb_tot > $globals->search->public_max) { | |
85 | $page->assign('error', 'Votre recherche a généré trop de résultats pour un affichage public.'); | |
86 | } elseif ($nb_tot > $globals->search->private_max) { | |
87 | $page->assign('error', 'Recherche trop générale.'); | |
88 | } elseif (empty($nb_tot)) { | |
89 | $page->assign('error', 'Il n\'existe personne correspondant à ces critères dans la base !'); | |
d667c548 SJ |
90 | } else { |
91 | $page->assign('error', false); | |
92e80560 VZ |
92 | } |
93 | } | |
94 | ||
95 | require_once 'gadgets/gadgets.inc.php'; | |
96 | init_igoogle_html('gadgets/ig-search.tpl', AUTH_PUBLIC); | |
97 | } | |
98 | } | |
99 | ||
100 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: | |
101 | ?> |