Dotclear

source: plugins/myGmaps/_admin.php @ 2824

Revision 2824, 8.4 KB checked in by philippe, 13 years ago (diff)

myGmaps : now works with pages

Line 
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
13if (!defined('DC_CONTEXT_ADMIN')) { return; }
14
15$_menu['Blog']->addItem(
16
17     __('Google Maps'),
18     'plugin.php?p=myGmaps&amp;do=list','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
29if (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
61class 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');
100          if ($id) {
101               if (!$meta_rs) {
102                    echo 
103                         '<fieldset><legend>'.__('Google Map').'</legend>'.
104                         '<p><a href="plugin.php?p=myGmaps&amp;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                   
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>&nbsp;</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&amp;do=edit&amp;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.'&amp;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                    '<div class="two-cols">'.
158                    '<p class="col"><a href="plugin.php?p=myGmaps&amp;post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'.
159                    '<p class="col right"><a class="map-remove" href="'.DC_ADMIN_URL.'post.php?id='.$id.'&amp;remove=map"><strong>'.__('Remove map').'</strong></a></p>'.
160                    '</div>'.
161                    '</fieldset>';
162                   
163               }
164          }
165     }
166     public static function adminPageForm($post)
167     {
168          global $core;
169          $id = $post->post_id;
170          $type = $post->post_type;
171          $meta =& $GLOBALS['core']->meta;
172          $meta_rs = $meta->getMetaStr($post->post_meta,'map');
173          if ($id) {
174               if (!$meta_rs) {
175                    echo 
176                         '<fieldset><legend>'.__('Google Map').'</legend>'.
177                         '<p><a href="plugin.php?p=myGmaps&amp;post_type=page&amp;post_id='.$id.'">'.__('Add a map to page').'</a></p>'.
178                         '</fieldset>';
179               } else {
180                   
181                    $meta =& $GLOBALS['core']->meta;
182                    $maps_array = explode(",",$meta->getMetaStr($post->post_meta,'map'));
183                    $maps_options = explode(",",$meta->getMetaStr($post->post_meta,'map_options'));
184                   
185                    echo '<fieldset><legend>'.__('Google Map').'</legend>'.
186                    '<h3>'.__('Map elements').'</h3>';
187                   
188                    echo
189                         '<table class="clear"><tr>'.
190                         '<th>'.__('Title').'</th>'.
191                         '<th>'.__('Date').'</th>'.
192                         '<th>'.__('Category').'</th>'.
193                         '<th>'.__('Author').'</th>'.
194                         '<th class="nowrap">'.__('Type').'</th>'.
195                         '<th>&nbsp;</th>'.
196                         '</tr>';
197                   
198                    $params['post_type'] = 'map';
199                    $params['no_content'] = true;
200                   
201                    $rsp = $core->blog->getPosts($params);
202                    while ($rsp->fetch()) {
203                         if (in_array($rsp->post_id,$maps_array)) {
204                              $meta_rs = $meta->getMetaStr($rsp->post_meta,'map');
205                              if ($core->auth->check('categories',$core->blog->id)) {
206                                   $cat_link = '<a href="category.php?id=%s">%s</a>';
207                              } else {
208                                   $cat_link = '%2$s';
209                              }
210                              if ($rsp->cat_title) {
211                                   $cat_title = sprintf($cat_link,$rsp->cat_id,
212                                   html::escapeHTML($rsp->cat_title));
213                              } else {
214                                   $cat_title = __('None');
215                              }
216                              echo
217                              '<tr>'.
218                              '<td class="maximal"><a href="plugin.php?p=myGmaps&amp;do=edit&amp;id='.$rsp->post_id.'" title="'.__('Edit map element').' : '.html::escapeHTML($rsp->post_title).'">'.html::escapeHTML($rsp->post_title).'</a></td>'.
219                              '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rsp->post_dt).'</td>'.
220                              '<td class="nowrap">'.$cat_title.'</td>'.
221                              '<td class="nowrap">'.$rsp->user_id.'</td>'.
222                              '<td class="nowrap">'.__($meta_rs).'</td>'.
223                              '<td class="nowrap"><a class="element-remove" href="plugin.php?p=pages&amp;post_type=page&amp;id='.$id.'&amp;remove='.$rsp->post_id.'" title="'.__('Remove map element').' : '.html::escapeHTML($rsp->post_title).'">[x]</a></td>'.
224                              '</tr>';
225                             
226                         }
227                    }
228
229                    echo '</table>'.
230                    '<div class="two-cols">'.
231                    '<p class="col"><a href="plugin.php?p=myGmaps&amp;post_type=page&amp;post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'.
232                    '<p class="col right"><a class="map-remove" href="plugin.php?p=pages&amp;post_type=page&amp;id='.$id.'&amp;remove=map"><strong>'.__('Remove map').'</strong></a></p>'.
233                    '</div>'.
234                    '</fieldset>';
235                   
236               }
237          }
238     }
239}   
240?>
Note: See TracBrowser for help on using the repository browser.

Sites map