1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # |
---|
4 | # This file is part of myGmaps, a plugin for Dotclear 2. |
---|
5 | # |
---|
6 | # Copyright (c) 2010 Philippe aka amalgame |
---|
7 | # Licensed under the GPL version 2.0 license. |
---|
8 | # See LICENSE file or |
---|
9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
10 | # |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | require_once DC_ROOT.'/inc/admin/prepend.php'; |
---|
14 | |
---|
15 | dcPage::check('usage,contentadmin'); |
---|
16 | |
---|
17 | $params = array(); |
---|
18 | |
---|
19 | $p_url = 'plugin.php?p='.basename(dirname(__FILE__)); |
---|
20 | |
---|
21 | /* Actions |
---|
22 | -------------------------------------------------------- */ |
---|
23 | if (!empty($_POST['action']) && !empty($_POST['entries'])) |
---|
24 | { |
---|
25 | $entries = $_POST['entries']; |
---|
26 | $action = $_POST['action']; |
---|
27 | |
---|
28 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
29 | { |
---|
30 | $redir = $_POST['redir']; |
---|
31 | } |
---|
32 | else |
---|
33 | { |
---|
34 | $redir = |
---|
35 | 'plugin.php?p=myGmaps&do=list'. |
---|
36 | '&user_id='.$_POST['user_id']. |
---|
37 | '&cat_id='.$_POST['cat_id']. |
---|
38 | '&status='.$_POST['status']. |
---|
39 | '&selected='.$_POST['selected']. |
---|
40 | '&month='.$_POST['month']. |
---|
41 | '&lang='.$_POST['lang']. |
---|
42 | '&sortby='.$_POST['sortby']. |
---|
43 | '&order='.$_POST['order']. |
---|
44 | '&page='.$_POST['page']. |
---|
45 | '&nb='.$_POST['nb']; |
---|
46 | } |
---|
47 | |
---|
48 | foreach ($entries as $k => $v) { |
---|
49 | $entries[$k] = (integer) $v; |
---|
50 | } |
---|
51 | |
---|
52 | $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') '; |
---|
53 | |
---|
54 | if (!isset($_POST['full_content']) || empty($_POST['full_content'])) { |
---|
55 | $params['no_content'] = true; |
---|
56 | } |
---|
57 | |
---|
58 | $params['post_type'] = 'map'; |
---|
59 | |
---|
60 | |
---|
61 | $posts = $core->blog->getPosts($params); |
---|
62 | |
---|
63 | # --BEHAVIOR-- adminPostsActions |
---|
64 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$redir); |
---|
65 | |
---|
66 | if (preg_match('/^(publish|unpublish|schedule|pending)$/',$action)) |
---|
67 | { |
---|
68 | switch ($action) { |
---|
69 | case 'unpublish' : $status = 0; break; |
---|
70 | case 'schedule' : $status = -1; break; |
---|
71 | case 'pending' : $status = -2; break; |
---|
72 | default : $status = 1; break; |
---|
73 | } |
---|
74 | |
---|
75 | try |
---|
76 | { |
---|
77 | while ($posts->fetch()) { |
---|
78 | $core->blog->updPostStatus($posts->post_id,$status); |
---|
79 | } |
---|
80 | |
---|
81 | http::redirect($redir); |
---|
82 | } |
---|
83 | catch (Exception $e) |
---|
84 | { |
---|
85 | $core->error->add($e->getMessage()); |
---|
86 | } |
---|
87 | } |
---|
88 | elseif ($action == 'selected' || $action == 'unselected') |
---|
89 | { |
---|
90 | try |
---|
91 | { |
---|
92 | while ($posts->fetch()) { |
---|
93 | $core->blog->updPostSelected($posts->post_id,$action == 'selected'); |
---|
94 | } |
---|
95 | |
---|
96 | http::redirect($redir); |
---|
97 | } |
---|
98 | catch (Exception $e) |
---|
99 | { |
---|
100 | $core->error->add($e->getMessage()); |
---|
101 | } |
---|
102 | } |
---|
103 | elseif ($action == 'delete') |
---|
104 | { |
---|
105 | try |
---|
106 | { |
---|
107 | while ($posts->fetch()) { |
---|
108 | # --BEHAVIOR-- adminBeforePostDelete |
---|
109 | $core->callBehavior('adminBeforePostDelete',$posts->post_id); |
---|
110 | $core->blog->delPost($posts->post_id); |
---|
111 | } |
---|
112 | |
---|
113 | http::redirect($redir); |
---|
114 | } |
---|
115 | catch (Exception $e) |
---|
116 | { |
---|
117 | $core->error->add($e->getMessage()); |
---|
118 | } |
---|
119 | |
---|
120 | } |
---|
121 | elseif ($action == 'category' && isset($_POST['new_cat_id'])) |
---|
122 | { |
---|
123 | try |
---|
124 | { |
---|
125 | while ($posts->fetch()) |
---|
126 | { |
---|
127 | $new_cat_id = (integer) $_POST['new_cat_id']; |
---|
128 | $core->blog->updPostCategory($posts->post_id,$new_cat_id); |
---|
129 | } |
---|
130 | http::redirect($redir); |
---|
131 | } |
---|
132 | catch (Exception $e) |
---|
133 | { |
---|
134 | $core->error->add($e->getMessage()); |
---|
135 | } |
---|
136 | } |
---|
137 | elseif ($action == 'author' && isset($_POST['new_auth_id']) |
---|
138 | && $core->auth->check('admin',$core->blog->id)) |
---|
139 | { |
---|
140 | $new_user_id = $_POST['new_auth_id']; |
---|
141 | |
---|
142 | try |
---|
143 | { |
---|
144 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
145 | throw new Exception(__('This user does not exist')); |
---|
146 | } |
---|
147 | |
---|
148 | while ($posts->fetch()) |
---|
149 | { |
---|
150 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
151 | $cur->user_id = $new_user_id; |
---|
152 | $cur->update('WHERE post_id = '.(integer) $posts->post_id); |
---|
153 | } |
---|
154 | |
---|
155 | http::redirect($redir); |
---|
156 | } |
---|
157 | catch (Exception $e) |
---|
158 | { |
---|
159 | $core->error->add($e->getMessage()); |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | /* DISPLAY |
---|
165 | -------------------------------------------------------- */ |
---|
166 | ?> |
---|
167 | <html> |
---|
168 | <head> |
---|
169 | <title><?php echo __('Google Maps'); ?></title> |
---|
170 | <?php |
---|
171 | echo |
---|
172 | dcPage::jsMetaEditor(). |
---|
173 | # --BEHAVIOR-- adminBeforePostDelete |
---|
174 | $core->callBehavior('adminPostsActionsHeaders') |
---|
175 | ?> |
---|
176 | </head> |
---|
177 | <body> |
---|
178 | <?php |
---|
179 | |
---|
180 | if (!isset($action)) { |
---|
181 | //dcPage::close(); |
---|
182 | exit; |
---|
183 | } |
---|
184 | |
---|
185 | $hidden_fields = ''; |
---|
186 | while ($posts->fetch()) { |
---|
187 | $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id); |
---|
188 | } |
---|
189 | |
---|
190 | if (isset($_POST['redir']) && strpos($_POST['redir'],'://') === false) |
---|
191 | { |
---|
192 | $hidden_fields .= form::hidden(array('redir'),html::escapeURL($_POST['redir'])); |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | $hidden_fields .= |
---|
197 | form::hidden(array('user_id'),$_POST['user_id']). |
---|
198 | form::hidden(array('cat_id'),$_POST['cat_id']). |
---|
199 | form::hidden(array('status'),$_POST['status']). |
---|
200 | form::hidden(array('selected'),$_POST['selected']). |
---|
201 | form::hidden(array('month'),$_POST['month']). |
---|
202 | form::hidden(array('lang'),$_POST['lang']). |
---|
203 | form::hidden(array('sortby'),$_POST['sortby']). |
---|
204 | form::hidden(array('order'),$_POST['order']). |
---|
205 | form::hidden(array('page'),$_POST['page']). |
---|
206 | form::hidden(array('nb'),$_POST['nb']); |
---|
207 | } |
---|
208 | |
---|
209 | if (isset($_POST['post_type'])) { |
---|
210 | $hidden_fields .= form::hidden(array('post_type'),$_POST['post_type']); |
---|
211 | } |
---|
212 | |
---|
213 | # --BEHAVIOR-- adminPostsActionsContent |
---|
214 | $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); |
---|
215 | |
---|
216 | if ($action == 'category') |
---|
217 | { |
---|
218 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Google Maps').' › '.__('Change category for map elements').'</h2>'; |
---|
219 | |
---|
220 | # categories list |
---|
221 | # Getting categories |
---|
222 | $categories_combo = array(' ' => ''); |
---|
223 | try { |
---|
224 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
225 | while ($categories->fetch()) { |
---|
226 | $categories_combo[] = new formSelectOption( |
---|
227 | str_repeat(' ',$categories->level-1).'• '.html::escapeHTML($categories->cat_title), |
---|
228 | $categories->cat_id |
---|
229 | ); |
---|
230 | } |
---|
231 | } catch (Exception $e) { } |
---|
232 | |
---|
233 | echo |
---|
234 | '<form action="'.$p_url.'" method="post">'. |
---|
235 | '<p><label class="classic">'.__('Category:').' '. |
---|
236 | form::combo('new_cat_id',$categories_combo,''). |
---|
237 | '</label> '; |
---|
238 | |
---|
239 | echo |
---|
240 | $hidden_fields. |
---|
241 | $core->formNonce(). |
---|
242 | form::hidden(array('action'),'category'). |
---|
243 | '<input type="submit" value="'.__('save').'" /></p>'. |
---|
244 | '</form>'; |
---|
245 | } |
---|
246 | elseif ($action == 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
247 | { |
---|
248 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.__('Google Maps').' › '.__('Change author for map elements').'</h2>'; |
---|
249 | |
---|
250 | echo |
---|
251 | '<form action="'.$p_url.'" method="post">'. |
---|
252 | '<p><label class="classic">'.__('Author ID:').' '. |
---|
253 | form::field('new_auth_id',20,255). |
---|
254 | '</label> '; |
---|
255 | |
---|
256 | echo |
---|
257 | $hidden_fields. |
---|
258 | $core->formNonce(). |
---|
259 | form::hidden(array('action'),'author'). |
---|
260 | '<input type="submit" value="'.__('save').'" /></p>'. |
---|
261 | '</form>'; |
---|
262 | } |
---|
263 | |
---|
264 | echo '<p><a class="back" href="'.html::escapeURL($redir).'">'.__('back').'</a></p>'; |
---|
265 | |
---|
266 | ?> |
---|
267 | </body> |
---|
268 | </html> |
---|