#642: Image in events
[platal.git] / include / banana / forum.inc.php
CommitLineData
24cec3d8 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2007 Polytechnique.org *
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
22require_once 'banana/banana.inc.php';
23require_once 'banana/hooks.inc.php';
24
25function hook_checkcancel($_headers)
26{
27 return ($_headers['x-org-id'] == S::v('forlife') or S::has_perms());
28}
29
fa7d6c7b 30class ForumsBanana extends Banana
24cec3d8 31{
32 function __construct($params = null)
33 {
34 global $globals;
35 Banana::$msgedit_canattach = false;
580d1c7d 36 Banana::$spool_root = $globals->banana->spool_root;
24cec3d8 37 array_push(Banana::$msgparse_headers, 'x-org-id', 'x-org-mail');
38 Banana::$nntp_host = 'news://web_'.S::v('forlife')
39 . ":{$globals->banana->password}@{$globals->banana->server}:{$globals->banana->port}/";
1515e65a 40 if (S::has_perms()) {
41 Banana::$msgshow_mimeparts[] = 'source';
42 }
d3f26be9 43 Banana::$debug_nntp = ($globals->debug & 1);
6544d0e1 44 if (!S::v('core_rss_hash')) {
45 Banana::$feed_active = false;
46 }
24cec3d8 47 parent::__construct($params);
48 }
49
50 public function run()
51 {
52 global $platal, $globals;
53
54 // Update last unread time
55 $time = null;
56 if (!is_null($this->params) && isset($this->params['updateall'])) {
57 $time = intval($this->params['updateall']);
58 $_SESSION['banana_last'] = $time;
59 }
60
61 // Get user profile from SQL
62 $req = XDB::query("SELECT nom, mail, sig,
63 FIND_IN_SET('threads',flags), FIND_IN_SET('automaj',flags)
64 FROM {$globals->banana->table_prefix}profils
65 WHERE uid={?}", S::i('uid'));
66 if (!(list($nom,$mail,$sig,$disp,$maj) = $req->fetchOneRow())) {
67 $nom = S::v('prenom')." ".S::v('nom');
68 $mail = S::v('forlife')."@polytechnique.org";
69 $sig = $nom." (".S::v('promo').")";
70 $disp = 0;
71 $maj = 1;
72 }
73 if ($maj) {
74 $time = time();
75 }
76
77 // Build user profile
78 $req = XDB::query("
79 SELECT nom
80 FROM {$globals->banana->table_prefix}abos
81 LEFT JOIN {$globals->banana->table_prefix}list ON list.fid=abos.fid
82 WHERE uid={?}", S::i('uid'));
fa2056fe 83 Banana::$profile['headers']['From'] = "$nom <$mail>";
24cec3d8 84 Banana::$profile['headers']['Organization'] = 'Utilisateur de Polytechnique.org';
fa2056fe 85 Banana::$profile['signature'] = $sig;
24cec3d8 86 Banana::$profile['display'] = $disp;
87 Banana::$profile['autoup'] = $maj;
88 Banana::$profile['lastnews'] = S::v('banana_last');
89 Banana::$profile['subscribe'] = $req->fetchColumn();
90
91 // Update the "unread limit"
92 if (!is_null($time)) {
93 XDB::execute("UPDATE auth_user_quick
94 SET banana_last = FROM_UNIXTIME({?})
95 WHERE user_id={?}",
96 $time, S::i('uid'));
97 }
98
4f355064 99 if (!empty($GLOBALS['IS_XNET_SITE'])) {
100 Banana::$page->killPage('forums');
101 Banana::$page->killPage('subscribe');
102 Banana::$spool_boxlist = false;
103 } else {
104 // Register custom Banana links and tabs
105 if (!Banana::$profile['autoup']) {
106 Banana::$page->registerAction('<a href=\'javascript:dynpostkv("'
107 . $platal->path . '", "updateall", ' . time() . ')\'>'
108 . 'Marquer tous les messages comme lus'
109 . '</a>', array('forums', 'thread', 'message'));
110 }
111 Banana::$page->registerPage('profile', 'Préférences', null);
112 }
24cec3d8 113
114 // Run Banana
115 return parent::run();
116 }
117
118 protected function action_saveSubs($groups)
119 {
120 global $globals;
121 $uid = S::v('uid');
122
123 Banana::$profile['subscribe'] = array();
124 XDB::execute("DELETE FROM {$globals->banana->table_prefix}abos WHERE uid={?}", $uid);
125 if (!count($groups)) {
126 return true;
127 }
128
129 $req = XDB::iterRow("SELECT fid,nom FROM {$globals->banana->table_prefix}list");
130 $fids = array();
131 while (list($fid,$fnom) = $req->next()) {
132 $fids[$fnom] = $fid;
133 }
134
135 $diff = array_diff($groups, array_keys($fids));
136 foreach ($diff as $g) {
137 XDB::execute("INSERT INTO {$globals->banana->table_prefix}list (nom) VALUES ({?})", $g);
138 $fids[$g] = XDB::insertId();
139 }
140
141 foreach ($groups as $g) {
142 XDB::execute("INSERT INTO {$globals->banana->table_prefix}abos (fid,uid) VALUES ({?},{?})",
143 $fids[$g], $uid);
144 Banana::$profile['subscribe'][] = $g;
145 }
146 }
147}
148
a7de4ef7 149// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
24cec3d8 150?>