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 | $entries = isset($_POST['entries']) ? $_POST['entries'] : array(); |
---|
14 | $action = isset($_POST['action']) ? $_POST['action'] : ''; |
---|
15 | $redir = isset($_POST['redir']) ? $_POST['redir'] : $p_url; |
---|
16 | |
---|
17 | foreach ($entries as $k => $v) { |
---|
18 | $entries[$k] = (integer) $v; |
---|
19 | } |
---|
20 | |
---|
21 | $params['sql'] = 'AND P.post_id IN('.implode(',',$entries).') '; |
---|
22 | $params['post_type'] = 'map'; |
---|
23 | $params['no_content'] = true; |
---|
24 | |
---|
25 | $posts = $core->blog->getPosts($params); |
---|
26 | |
---|
27 | foreach ($filters as $k) { |
---|
28 | if (array_key_exists($k,$_POST)) { |
---|
29 | $redir .= sprintf('&%s=%s',$k,$_POST[$k]); |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | /* Actions |
---|
34 | -------------------------------------------------------- */ |
---|
35 | if (!empty($action) && count(entries) > 0) |
---|
36 | { |
---|
37 | try { |
---|
38 | $act = null; |
---|
39 | # Change map posts status |
---|
40 | if ($action === 'published' || $action === 'pending' || $action === 'unpublished') { |
---|
41 | foreach ($entries as $id) { |
---|
42 | switch ($action) { |
---|
43 | case 'published' : $status = 1; break; |
---|
44 | case 'pending' : $status = -2; break; |
---|
45 | case 'unpublished' : $status = 0; break; |
---|
46 | default : $status = 1; break; |
---|
47 | } |
---|
48 | $core->blog->updPostStatus($id,$status); |
---|
49 | } |
---|
50 | $act = 1; |
---|
51 | } |
---|
52 | # Change map posts category |
---|
53 | if ($action == 'category' && isset($_POST['new_cat_id'])) |
---|
54 | { |
---|
55 | while ($posts->fetch()) { |
---|
56 | $new_cat_id = (integer) $_POST['new_cat_id']; |
---|
57 | $core->blog->updPostCategory($posts->post_id,$new_cat_id); |
---|
58 | } |
---|
59 | $act = 2; |
---|
60 | } |
---|
61 | # Change map posts authors |
---|
62 | if ($action == 'author' && isset($_POST['new_auth_id']) |
---|
63 | && $core->auth->check('admin',$core->blog->id)) |
---|
64 | { |
---|
65 | $new_user_id = $_POST['new_auth_id']; |
---|
66 | |
---|
67 | if ($core->getUser($new_user_id)->isEmpty()) { |
---|
68 | throw new Exception(__('This user does not exist')); |
---|
69 | } |
---|
70 | |
---|
71 | while ($posts->fetch()) |
---|
72 | { |
---|
73 | $cur = $core->con->openCursor($core->prefix.'post'); |
---|
74 | $cur->user_id = $new_user_id; |
---|
75 | $cur->update('WHERE post_id = '.(integer) $posts->post_id); |
---|
76 | } |
---|
77 | $act = 3; |
---|
78 | } |
---|
79 | # Delete map posts |
---|
80 | if ($action === 'delete') { |
---|
81 | foreach ($entries as $id) { |
---|
82 | # --BEHAVIOR-- adminBeforePostDelete |
---|
83 | $core->callBehavior('adminBeforePostDelete',$id); |
---|
84 | $core->blog->delPost($id); |
---|
85 | } |
---|
86 | $act = 4; |
---|
87 | } |
---|
88 | |
---|
89 | if (!is_null($act)) { |
---|
90 | http::redirect($redir.'&act='.$act); |
---|
91 | } |
---|
92 | } catch (Exception $e) { |
---|
93 | $core->error->add($e->getMessage()); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | # --BEHAVIOR-- adminPostsActions |
---|
98 | $core->callBehavior('adminPostsActions',$core,$posts,$action,$p_url); |
---|
99 | |
---|
100 | /* DISPLAY |
---|
101 | -------------------------------------------------------- */ |
---|
102 | |
---|
103 | echo |
---|
104 | '<html>'. |
---|
105 | '<head>'. |
---|
106 | '<title>'.__('Google Maps').'</title>'. |
---|
107 | dcPage::jsMetaEditor(); |
---|
108 | # --BEHAVIOR-- adminBeforePostDelete |
---|
109 | $core->callBehavior('adminPostsActionsHeaders'); |
---|
110 | echo |
---|
111 | '</head>'. |
---|
112 | '<body>'; |
---|
113 | |
---|
114 | $hidden_fields = form::hidden('redir',$redir); |
---|
115 | while ($posts->fetch()) { |
---|
116 | $hidden_fields .= form::hidden(array('entries[]'),$posts->post_id); |
---|
117 | } |
---|
118 | |
---|
119 | # --BEHAVIOR-- adminPostsActionsContent |
---|
120 | $core->callBehavior('adminPostsActionsContent',$core,$action,$hidden_fields); |
---|
121 | |
---|
122 | if ($action === 'category') |
---|
123 | { |
---|
124 | echo |
---|
125 | '<h2>'. |
---|
126 | html::escapeHTML($core->blog->name).' › '. |
---|
127 | '<a href="'.$p_url.'">'.__('Google Maps').'</a> › '. |
---|
128 | __('Change category for map elements'). |
---|
129 | '</h2>'; |
---|
130 | |
---|
131 | # categories list |
---|
132 | # Getting categories |
---|
133 | $categories_combo = array(' ' => ''); |
---|
134 | try { |
---|
135 | $categories = $core->blog->getCategories(array('post_type'=>'post')); |
---|
136 | while ($categories->fetch()) { |
---|
137 | $categories_combo[] = new formSelectOption( |
---|
138 | str_repeat(' ',$categories->level-1).'• '.html::escapeHTML($categories->cat_title), |
---|
139 | $categories->cat_id |
---|
140 | ); |
---|
141 | } |
---|
142 | } catch (Exception $e) { } |
---|
143 | |
---|
144 | echo |
---|
145 | '<form action="'.$p_url.'&go=maps_actions" method="post">'. |
---|
146 | '<p><label class="classic">'.__('Category:').' '. |
---|
147 | form::combo('new_cat_id',$categories_combo,''). |
---|
148 | '</label> '; |
---|
149 | |
---|
150 | echo |
---|
151 | $hidden_fields. |
---|
152 | $core->formNonce(). |
---|
153 | form::hidden(array('action'),'category'). |
---|
154 | '<input type="submit" value="'.__('save').'" /></p>'. |
---|
155 | '</form>'; |
---|
156 | } |
---|
157 | elseif ($action === 'author' && $core->auth->check('admin',$core->blog->id)) |
---|
158 | { |
---|
159 | echo |
---|
160 | '<h2>'. |
---|
161 | html::escapeHTML($core->blog->name).' › '. |
---|
162 | '<a href="'.$p_url.'">'.__('Google Maps').'</a> › '. |
---|
163 | __('Change author for map elements'). |
---|
164 | '</h2>'; |
---|
165 | |
---|
166 | echo |
---|
167 | '<form action="'.$p_url.'&go=maps_actions" method="post">'. |
---|
168 | '<p><label class="classic">'.__('Author ID:').' '. |
---|
169 | form::field('new_auth_id',20,255). |
---|
170 | '</label> '; |
---|
171 | |
---|
172 | echo |
---|
173 | $hidden_fields. |
---|
174 | $core->formNonce(). |
---|
175 | form::hidden(array('action'),'author'). |
---|
176 | '<input type="submit" value="'.__('save').'" /></p>'. |
---|
177 | '</form>'; |
---|
178 | } |
---|
179 | |
---|
180 | $posts_list = ''; |
---|
181 | |
---|
182 | while ($posts->fetch()) { |
---|
183 | $link = sprintf('<a href="%s">%s</a>',$p_url.'&go=map&id='.$posts->post_id,$posts->post_title); |
---|
184 | $posts_list .= sprintf('<li>#%s - %s</li>',$posts->post_id,$link); |
---|
185 | } |
---|
186 | |
---|
187 | if ($posts_list !== '') { |
---|
188 | echo sprintf('<p><ul>%s</ul></p>',$posts_list); |
---|
189 | } |
---|
190 | |
---|
191 | echo |
---|
192 | '<p><a class="back" href="'.html::escapeURL($p_url).'">'.__('back').'</a></p>'. |
---|
193 | '</body>'. |
---|
194 | '</html>'; |
---|
195 | |
---|
196 | ?> |
---|