Mercurial > hg > vamp-website
comparison forum/Sources/Notify.php @ 76:e3e11437ecea website
Add forum code
author | Chris Cannam |
---|---|
date | Sun, 07 Jul 2013 11:25:48 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
75:72f59aa7e503 | 76:e3e11437ecea |
---|---|
1 <?php | |
2 | |
3 /** | |
4 * Simple Machines Forum (SMF) | |
5 * | |
6 * @package SMF | |
7 * @author Simple Machines http://www.simplemachines.org | |
8 * @copyright 2011 Simple Machines | |
9 * @license http://www.simplemachines.org/about/smf/license.php BSD | |
10 * | |
11 * @version 2.0 | |
12 */ | |
13 | |
14 if (!defined('SMF')) | |
15 die('Hacking attempt...'); | |
16 | |
17 /* This file contains just the functions that turn on and off notifications to | |
18 topics or boards. The following two functions are included: | |
19 | |
20 void Notify() | |
21 - is called to turn off/on notification for a particular topic. | |
22 - must be called with a topic specified in the URL. | |
23 - uses the Notify template (main sub template.) when called with no sa. | |
24 - the sub action can be 'on', 'off', or nothing for what to do. | |
25 - requires the mark_any_notify permission. | |
26 - upon successful completion of action will direct user back to topic. | |
27 - is accessed via ?action=notify. | |
28 | |
29 void BoardNotify() | |
30 - is called to turn off/on notification for a particular board. | |
31 - must be called with a board specified in the URL. | |
32 - uses the Notify template. (notify_board sub template.) | |
33 - only uses the template if no sub action is used. (on/off) | |
34 - requires the mark_notify permission. | |
35 - redirects the user back to the board after it is done. | |
36 - is accessed via ?action=notifyboard. | |
37 */ | |
38 | |
39 // Turn on/off notifications... | |
40 function Notify() | |
41 { | |
42 global $scripturl, $txt, $topic, $user_info, $context, $smcFunc; | |
43 | |
44 // Make sure they aren't a guest or something - guests can't really receive notifications! | |
45 is_not_guest(); | |
46 isAllowedTo('mark_any_notify'); | |
47 | |
48 // Make sure the topic has been specified. | |
49 if (empty($topic)) | |
50 fatal_lang_error('not_a_topic', false); | |
51 | |
52 // What do we do? Better ask if they didn't say.. | |
53 if (empty($_GET['sa'])) | |
54 { | |
55 // Load the template, but only if it is needed. | |
56 loadTemplate('Notify'); | |
57 | |
58 // Find out if they have notification set for this topic already. | |
59 $request = $smcFunc['db_query']('', ' | |
60 SELECT id_member | |
61 FROM {db_prefix}log_notify | |
62 WHERE id_member = {int:current_member} | |
63 AND id_topic = {int:current_topic} | |
64 LIMIT 1', | |
65 array( | |
66 'current_member' => $user_info['id'], | |
67 'current_topic' => $topic, | |
68 ) | |
69 ); | |
70 $context['notification_set'] = $smcFunc['db_num_rows']($request) != 0; | |
71 $smcFunc['db_free_result']($request); | |
72 | |
73 // Set the template variables... | |
74 $context['topic_href'] = $scripturl . '?topic=' . $topic . '.' . $_REQUEST['start']; | |
75 $context['start'] = $_REQUEST['start']; | |
76 $context['page_title'] = $txt['notification']; | |
77 | |
78 return; | |
79 } | |
80 elseif ($_GET['sa'] == 'on') | |
81 { | |
82 checkSession('get'); | |
83 | |
84 // Attempt to turn notifications on. | |
85 $smcFunc['db_insert']('ignore', | |
86 '{db_prefix}log_notify', | |
87 array('id_member' => 'int', 'id_topic' => 'int'), | |
88 array($user_info['id'], $topic), | |
89 array('id_member', 'id_topic') | |
90 ); | |
91 } | |
92 else | |
93 { | |
94 checkSession('get'); | |
95 | |
96 // Just turn notifications off. | |
97 $smcFunc['db_query']('', ' | |
98 DELETE FROM {db_prefix}log_notify | |
99 WHERE id_member = {int:current_member} | |
100 AND id_topic = {int:current_topic}', | |
101 array( | |
102 'current_member' => $user_info['id'], | |
103 'current_topic' => $topic, | |
104 ) | |
105 ); | |
106 } | |
107 | |
108 // Send them back to the topic. | |
109 redirectexit('topic=' . $topic . '.' . $_REQUEST['start']); | |
110 } | |
111 | |
112 function BoardNotify() | |
113 { | |
114 global $scripturl, $txt, $board, $user_info, $context, $smcFunc; | |
115 | |
116 // Permissions are an important part of anything ;). | |
117 is_not_guest(); | |
118 isAllowedTo('mark_notify'); | |
119 | |
120 // You have to specify a board to turn notifications on! | |
121 if (empty($board)) | |
122 fatal_lang_error('no_board', false); | |
123 | |
124 // No subaction: find out what to do. | |
125 if (empty($_GET['sa'])) | |
126 { | |
127 // We're gonna need the notify template... | |
128 loadTemplate('Notify'); | |
129 | |
130 // Find out if they have notification set for this topic already. | |
131 $request = $smcFunc['db_query']('', ' | |
132 SELECT id_member | |
133 FROM {db_prefix}log_notify | |
134 WHERE id_member = {int:current_member} | |
135 AND id_board = {int:current_board} | |
136 LIMIT 1', | |
137 array( | |
138 'current_board' => $board, | |
139 'current_member' => $user_info['id'], | |
140 ) | |
141 ); | |
142 $context['notification_set'] = $smcFunc['db_num_rows']($request) != 0; | |
143 $smcFunc['db_free_result']($request); | |
144 | |
145 // Set the template variables... | |
146 $context['board_href'] = $scripturl . '?board=' . $board . '.' . $_REQUEST['start']; | |
147 $context['start'] = $_REQUEST['start']; | |
148 $context['page_title'] = $txt['notification']; | |
149 $context['sub_template'] = 'notify_board'; | |
150 | |
151 return; | |
152 } | |
153 // Turn the board level notification on.... | |
154 elseif ($_GET['sa'] == 'on') | |
155 { | |
156 checkSession('get'); | |
157 | |
158 // Turn notification on. (note this just blows smoke if it's already on.) | |
159 $smcFunc['db_insert']('ignore', | |
160 '{db_prefix}log_notify', | |
161 array('id_member' => 'int', 'id_board' => 'int'), | |
162 array($user_info['id'], $board), | |
163 array('id_member', 'id_board') | |
164 ); | |
165 } | |
166 // ...or off? | |
167 else | |
168 { | |
169 checkSession('get'); | |
170 | |
171 // Turn notification off for this board. | |
172 $smcFunc['db_query']('', ' | |
173 DELETE FROM {db_prefix}log_notify | |
174 WHERE id_member = {int:current_member} | |
175 AND id_board = {int:current_board}', | |
176 array( | |
177 'current_board' => $board, | |
178 'current_member' => $user_info['id'], | |
179 ) | |
180 ); | |
181 } | |
182 | |
183 // Back to the board! | |
184 redirectexit('board=' . $board . '.' . $_REQUEST['start']); | |
185 } | |
186 | |
187 ?> |