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 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
14 | |
---|
15 | $_menu['Blog']->addItem( |
---|
16 | |
---|
17 | __('Google Maps'), |
---|
18 | 'plugin.php?p=myGmaps&go=maps','index.php?pf=myGmaps/icon.png', |
---|
19 | preg_match('/plugin.php\?p=myGmaps(&.*)?$/',$_SERVER['REQUEST_URI']), |
---|
20 | $core->auth->check('usage,contentadmin',$core->blog->id)); |
---|
21 | |
---|
22 | $p_url = 'plugin.php?p='.basename(dirname(__FILE__)); |
---|
23 | |
---|
24 | $core->addBehavior('adminPostHeaders',array('myGmapsPostBehaviors','postHeaders')); |
---|
25 | $core->addBehavior('adminPageHeaders',array('myGmapsPostBehaviors','postHeaders')); |
---|
26 | $core->addBehavior('adminPostForm',array('myGmapsPostBehaviors','adminPostForm')); |
---|
27 | $core->addBehavior('adminPageForm',array('myGmapsPostBehaviors','adminPageForm')); |
---|
28 | |
---|
29 | if (isset($_GET['remove']) && $_GET['remove'] == 'map') { |
---|
30 | try { |
---|
31 | $post_id = $_GET['id']; |
---|
32 | $meta =& $GLOBALS['core']->meta; |
---|
33 | $meta->delPostMeta($post_id,'map'); |
---|
34 | $meta->delPostMeta($post_id,'map_options'); |
---|
35 | if ($_GET['post_type'] == 'page') { |
---|
36 | http::redirect('plugin.php?p=pages&act=page&id='.$post_id); |
---|
37 | } else { |
---|
38 | http::redirect(DC_ADMIN_URL.'post.php?id='.$post_id); |
---|
39 | } |
---|
40 | |
---|
41 | } catch (Exception $e) { |
---|
42 | $core->error->add($e->getMessage()); |
---|
43 | } |
---|
44 | } elseif (!empty($_GET['remove']) && is_numeric($_GET['remove'])) { |
---|
45 | try { |
---|
46 | $post_id = $_GET['id']; |
---|
47 | $meta =& $GLOBALS['core']->meta; |
---|
48 | $meta->delPostMeta($post_id,'map',(integer) $_GET['remove']); |
---|
49 | |
---|
50 | if ($_GET['post_type'] == 'page') { |
---|
51 | http::redirect('plugin.php?p=pages&act=page&id='.$post_id); |
---|
52 | } else { |
---|
53 | http::redirect(DC_ADMIN_URL.'post.php?id='.$post_id); |
---|
54 | } |
---|
55 | |
---|
56 | } catch (Exception $e) { |
---|
57 | $core->error->add($e->getMessage()); |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | class myGmapsPostBehaviors |
---|
62 | { |
---|
63 | public static function postHeaders() |
---|
64 | { |
---|
65 | return |
---|
66 | '<script type="text/javascript">'."\n". |
---|
67 | '$(document).ready(function() {'."\n". |
---|
68 | '$(\'a.map-remove\').click(function() {'."\n". |
---|
69 | 'msg = \''.__('Are you sure you want to remove this map?').'\';'."\n". |
---|
70 | 'if (!window.confirm(msg)) {'."\n". |
---|
71 | 'return false;'."\n". |
---|
72 | '}'."\n". |
---|
73 | '});'."\n". |
---|
74 | '$(\'a.element-remove\').click(function() {'."\n". |
---|
75 | 'msg = \''.__('Are you sure you want to remove this element?').'\';'."\n". |
---|
76 | 'if (!window.confirm(msg)) {'."\n". |
---|
77 | 'return false;'."\n". |
---|
78 | '}'."\n". |
---|
79 | '});'."\n". |
---|
80 | '});'."\n". |
---|
81 | '</script>'. |
---|
82 | '<style type="text/css">'."\n". |
---|
83 | 'a.element-remove {'."\n". |
---|
84 | 'color : #999 !important;'."\n". |
---|
85 | 'border: none;'."\n". |
---|
86 | '}'."\n". |
---|
87 | 'a.element-remove:hover, a.element-remove:focus {'."\n". |
---|
88 | 'color : #06c !important;'."\n". |
---|
89 | '}'."\n". |
---|
90 | '</style>'; |
---|
91 | |
---|
92 | } |
---|
93 | public static function adminPostForm($post) |
---|
94 | { |
---|
95 | global $core; |
---|
96 | $id = $post->post_id; |
---|
97 | $type = $post->post_type; |
---|
98 | $meta =& $GLOBALS['core']->meta; |
---|
99 | $meta_rs = $meta->getMetaStr($post->post_meta,'map_options'); |
---|
100 | if ($id) { |
---|
101 | if (!$meta_rs) { |
---|
102 | echo |
---|
103 | '<fieldset><legend>'.__('Google Map').'</legend>'. |
---|
104 | '<p><a href="plugin.php?p=myGmaps&post_id='.$id.'">'.__('Add a map to entry').'</a></p>'. |
---|
105 | '</fieldset>'; |
---|
106 | } else { |
---|
107 | |
---|
108 | $meta =& $GLOBALS['core']->meta; |
---|
109 | $maps_array = explode(",",$meta->getMetaStr($post->post_meta,'map')); |
---|
110 | $maps_options = explode(",",$meta->getMetaStr($post->post_meta,'map_options')); |
---|
111 | |
---|
112 | echo '<fieldset><legend>'.__('Google Map').'</legend>'. |
---|
113 | '<h3>'.__('Map elements').'</h3>'; |
---|
114 | if ($meta->getMetaStr($post->post_meta,'map') != '') { |
---|
115 | echo |
---|
116 | '<table class="clear"><tr>'. |
---|
117 | '<th>'.__('Title').'</th>'. |
---|
118 | '<th>'.__('Date').'</th>'. |
---|
119 | '<th>'.__('Category').'</th>'. |
---|
120 | '<th>'.__('Author').'</th>'. |
---|
121 | '<th class="nowrap">'.__('Type').'</th>'. |
---|
122 | '<th> </th>'. |
---|
123 | '</tr>'; |
---|
124 | |
---|
125 | $params['post_type'] = 'map'; |
---|
126 | $params['no_content'] = true; |
---|
127 | |
---|
128 | $rsp = $core->blog->getPosts($params); |
---|
129 | while ($rsp->fetch()) { |
---|
130 | if (in_array($rsp->post_id,$maps_array)) { |
---|
131 | $meta_rs = $meta->getMetaStr($rsp->post_meta,'map'); |
---|
132 | if ($core->auth->check('categories',$core->blog->id)) { |
---|
133 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
134 | } else { |
---|
135 | $cat_link = '%2$s'; |
---|
136 | } |
---|
137 | if ($rsp->cat_title) { |
---|
138 | $cat_title = sprintf($cat_link,$rsp->cat_id, |
---|
139 | html::escapeHTML($rsp->cat_title)); |
---|
140 | } else { |
---|
141 | $cat_title = __('None'); |
---|
142 | } |
---|
143 | echo |
---|
144 | '<tr>'. |
---|
145 | '<td class="maximal"><a href="plugin.php?p=myGmaps&do=edit&id='.$rsp->post_id.'" title="'.__('Edit map element').' : '.html::escapeHTML($rsp->post_title).'">'.html::escapeHTML($rsp->post_title).'</a></td>'. |
---|
146 | '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rsp->post_dt).'</td>'. |
---|
147 | '<td class="nowrap">'.$cat_title.'</td>'. |
---|
148 | '<td class="nowrap">'.$rsp->user_id.'</td>'. |
---|
149 | '<td class="nowrap">'.__($meta_rs).'</td>'. |
---|
150 | '<td class="nowrap"><a class="element-remove" href="'.DC_ADMIN_URL.'post.php?id='.$id.'&remove='.$rsp->post_id.'" title="'.__('Remove map element').' : '.html::escapeHTML($rsp->post_title).'">[x]</a></td>'. |
---|
151 | '</tr>'; |
---|
152 | |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | echo '</table>'; |
---|
157 | } else { |
---|
158 | echo '<p>'.__('No element (empty map)').'</p>'; |
---|
159 | } |
---|
160 | echo |
---|
161 | '<div class="two-cols">'. |
---|
162 | '<p class="col"><a href="plugin.php?p=myGmaps&post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'. |
---|
163 | '<p class="col right"><a class="map-remove" href="'.DC_ADMIN_URL.'post.php?id='.$id.'&remove=map"><strong>'.__('Remove map').'</strong></a></p>'. |
---|
164 | '</div>'. |
---|
165 | '</fieldset>'; |
---|
166 | |
---|
167 | } |
---|
168 | } |
---|
169 | } |
---|
170 | public static function adminPageForm($post) |
---|
171 | { |
---|
172 | global $core; |
---|
173 | $id = $post->post_id; |
---|
174 | $type = $post->post_type; |
---|
175 | $meta =& $GLOBALS['core']->meta; |
---|
176 | $meta_rs = $meta->getMetaStr($post->post_meta,'map_options'); |
---|
177 | if ($id) { |
---|
178 | if (!$meta_rs) { |
---|
179 | echo |
---|
180 | '<fieldset><legend>'.__('Google Map').'</legend>'. |
---|
181 | '<p><a href="plugin.php?p=myGmaps&post_type=page&post_id='.$id.'">'.__('Add a map to page').'</a></p>'. |
---|
182 | '</fieldset>'; |
---|
183 | } else { |
---|
184 | |
---|
185 | $meta =& $GLOBALS['core']->meta; |
---|
186 | $maps_array = explode(",",$meta->getMetaStr($post->post_meta,'map')); |
---|
187 | $maps_options = explode(",",$meta->getMetaStr($post->post_meta,'map_options')); |
---|
188 | |
---|
189 | echo '<fieldset><legend>'.__('Google Map').'</legend>'. |
---|
190 | '<h3>'.__('Map elements').'</h3>'; |
---|
191 | if ($meta->getMetaStr($post->post_meta,'map') != '') { |
---|
192 | echo |
---|
193 | '<table class="clear"><tr>'. |
---|
194 | '<th>'.__('Title').'</th>'. |
---|
195 | '<th>'.__('Date').'</th>'. |
---|
196 | '<th>'.__('Category').'</th>'. |
---|
197 | '<th>'.__('Author').'</th>'. |
---|
198 | '<th class="nowrap">'.__('Type').'</th>'. |
---|
199 | '<th> </th>'. |
---|
200 | '</tr>'; |
---|
201 | |
---|
202 | $params['post_type'] = 'map'; |
---|
203 | $params['no_content'] = true; |
---|
204 | |
---|
205 | $rsp = $core->blog->getPosts($params); |
---|
206 | while ($rsp->fetch()) { |
---|
207 | if (in_array($rsp->post_id,$maps_array)) { |
---|
208 | $meta_rs = $meta->getMetaStr($rsp->post_meta,'map'); |
---|
209 | if ($core->auth->check('categories',$core->blog->id)) { |
---|
210 | $cat_link = '<a href="category.php?id=%s">%s</a>'; |
---|
211 | } else { |
---|
212 | $cat_link = '%2$s'; |
---|
213 | } |
---|
214 | if ($rsp->cat_title) { |
---|
215 | $cat_title = sprintf($cat_link,$rsp->cat_id, |
---|
216 | html::escapeHTML($rsp->cat_title)); |
---|
217 | } else { |
---|
218 | $cat_title = __('None'); |
---|
219 | } |
---|
220 | echo |
---|
221 | '<tr>'. |
---|
222 | '<td class="maximal"><a href="plugin.php?p=myGmaps&do=edit&id='.$rsp->post_id.'" title="'.__('Edit map element').' : '.html::escapeHTML($rsp->post_title).'">'.html::escapeHTML($rsp->post_title).'</a></td>'. |
---|
223 | '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rsp->post_dt).'</td>'. |
---|
224 | '<td class="nowrap">'.$cat_title.'</td>'. |
---|
225 | '<td class="nowrap">'.$rsp->user_id.'</td>'. |
---|
226 | '<td class="nowrap">'.__($meta_rs).'</td>'. |
---|
227 | '<td class="nowrap"><a class="element-remove" href="plugin.php?p=pages&post_type=page&id='.$id.'&remove='.$rsp->post_id.'" title="'.__('Remove map element').' : '.html::escapeHTML($rsp->post_title).'">[x]</a></td>'. |
---|
228 | '</tr>'; |
---|
229 | |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | echo '</table>'; |
---|
234 | } else { |
---|
235 | echo '<p>'.__('No element (empty map)').'</p>'; |
---|
236 | } |
---|
237 | echo |
---|
238 | '<div class="two-cols">'. |
---|
239 | '<p class="col"><a href="plugin.php?p=myGmaps&post_type=page&post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'. |
---|
240 | '<p class="col right"><a class="map-remove" href="plugin.php?p=pages&post_type=page&id='.$id.'&remove=map"><strong>'.__('Remove map').'</strong></a></p>'. |
---|
241 | '</div>'. |
---|
242 | '</fieldset>'; |
---|
243 | } |
---|
244 | } |
---|
245 | } |
---|
246 | } |
---|
247 | ?> |
---|