Dotclear

source: plugins/myGmaps/branches/_admin.php @ 2879

Revision 2879, 8.8 KB checked in by Tomtom33, 13 years ago (diff)

Watch out #5

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;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
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          dcPage::jsLoad('index.php?pf=myGmaps/js/_post.js');
67          /*'<script type="text/javascript">'."\n".
68          '$(document).ready(function() {'."\n".
69               '$(\'a.map-remove\').click(function() {'."\n".
70               'msg = \''.__('Are you sure you want to remove this map?').'\';'."\n".
71               'if (!window.confirm(msg)) {'."\n".
72                    'return false;'."\n".
73               '}'."\n".
74               '});'."\n".
75               '$(\'a.element-remove\').click(function() {'."\n".
76               'msg = \''.__('Are you sure you want to remove this element?').'\';'."\n".
77               'if (!window.confirm(msg)) {'."\n".
78                    'return false;'."\n".
79               '}'."\n".
80               '});'."\n".
81          '});'."\n".
82          '</script>'.
83          '<style type="text/css">'."\n".
84               'a.element-remove {'."\n".
85                    'color : #999 !important;'."\n".
86                    'border: none;'."\n".
87               '}'."\n".
88                    'a.element-remove:hover, a.element-remove:focus {'."\n".
89                    'color : #06c !important;'."\n".
90          '}'."\n".
91          '</style>';*/
92         
93     }
94     public static function adminPostForm($post)
95     {
96          global $core;
97          $id = $post->post_id;
98          $type = $post->post_type;
99          $meta =& $GLOBALS['core']->meta;
100          $meta_rs = $meta->getMetaStr($post->post_meta,'map_options');
101          if ($id) {
102               if (!$meta_rs) {
103                    echo 
104                         '<fieldset><legend>'.__('Google Map').'</legend>'.
105                         '<p><a class="add-maps" href="plugin.php?p=myGmaps&go=maps_popup&popup=1&post_id='.$id.'">'.__('Add a map to entry').'</a></p>'.
106                         '</fieldset>';
107               } else {
108                   
109                    $meta =& $GLOBALS['core']->meta;
110                    $maps_array = explode(",",$meta->getMetaStr($post->post_meta,'map'));
111                    $maps_options = explode(",",$meta->getMetaStr($post->post_meta,'map_options'));
112                   
113                    echo '<fieldset><legend>'.__('Google Map').'</legend>'.
114                    '<h3>'.__('Map elements').'</h3>';
115                    if ($meta->getMetaStr($post->post_meta,'map') != '') {
116                         echo
117                              '<table class="clear"><tr>'.
118                              '<th>'.__('Title').'</th>'.
119                              '<th>'.__('Date').'</th>'.
120                              '<th>'.__('Category').'</th>'.
121                              '<th>'.__('Author').'</th>'.
122                              '<th class="nowrap">'.__('Type').'</th>'.
123                              '<th>&nbsp;</th>'.
124                              '</tr>';
125                         
126                         $params['post_type'] = 'map';
127                         $params['no_content'] = true;
128                         
129                         $rsp = $core->blog->getPosts($params);
130                         while ($rsp->fetch()) {
131                              if (in_array($rsp->post_id,$maps_array)) {
132                                   $meta_rs = $meta->getMetaStr($rsp->post_meta,'map');
133                                   if ($core->auth->check('categories',$core->blog->id)) {
134                                        $cat_link = '<a href="category.php?id=%s">%s</a>';
135                                   } else {
136                                        $cat_link = '%2$s';
137                                   }
138                                   if ($rsp->cat_title) {
139                                        $cat_title = sprintf($cat_link,$rsp->cat_id,
140                                        html::escapeHTML($rsp->cat_title));
141                                   } else {
142                                        $cat_title = __('None');
143                                   }
144                                   echo
145                                   '<tr>'.
146                                   '<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>'.
147                                   '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rsp->post_dt).'</td>'.
148                                   '<td class="nowrap">'.$cat_title.'</td>'.
149                                   '<td class="nowrap">'.$rsp->user_id.'</td>'.
150                                   '<td class="nowrap">'.__($meta_rs).'</td>'.
151                                   '<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>'.
152                                   '</tr>';
153                                   
154                              }
155                         }
156     
157                         echo '</table>';
158                    } else {
159                         echo '<p>'.__('No element (empty map)').'</p>';
160                    }
161                    echo
162                    '<div class="two-cols">'.
163                    '<p class="col"><a href="plugin.php?p=myGmaps&amp;post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'.
164                    '<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>'.
165                    '</div>'.
166                    '</fieldset>';
167                   
168               }
169          }
170     }
171     public static function adminPageForm($post)
172     {
173          global $core;
174          $id = $post->post_id;
175          $type = $post->post_type;
176          $meta =& $GLOBALS['core']->meta;
177          $meta_rs = $meta->getMetaStr($post->post_meta,'map_options');
178          if ($id) {
179               if (!$meta_rs) {
180                    echo 
181                    '<fieldset><legend>'.__('Google Map').'</legend>'.
182                    '<p><a href="plugin.php?p=myGmaps&amp;post_type=page&amp;post_id='.$id.'">'.__('Add a map to page').'</a></p>'.
183                    '</fieldset>';
184               } else {
185                   
186                    $meta =& $GLOBALS['core']->meta;
187                    $maps_array = explode(",",$meta->getMetaStr($post->post_meta,'map'));
188                    $maps_options = explode(",",$meta->getMetaStr($post->post_meta,'map_options'));
189                   
190                    echo '<fieldset><legend>'.__('Google Map').'</legend>'.
191                    '<h3>'.__('Map elements').'</h3>';
192                    if ($meta->getMetaStr($post->post_meta,'map') != '') {
193                         echo
194                              '<table class="clear"><tr>'.
195                              '<th>'.__('Title').'</th>'.
196                              '<th>'.__('Date').'</th>'.
197                              '<th>'.__('Category').'</th>'.
198                              '<th>'.__('Author').'</th>'.
199                              '<th class="nowrap">'.__('Type').'</th>'.
200                              '<th>&nbsp;</th>'.
201                              '</tr>';
202                         
203                         $params['post_type'] = 'map';
204                         $params['no_content'] = true;
205                         
206                         $rsp = $core->blog->getPosts($params);
207                         while ($rsp->fetch()) {
208                              if (in_array($rsp->post_id,$maps_array)) {
209                                   $meta_rs = $meta->getMetaStr($rsp->post_meta,'map');
210                                   if ($core->auth->check('categories',$core->blog->id)) {
211                                        $cat_link = '<a href="category.php?id=%s">%s</a>';
212                                   } else {
213                                        $cat_link = '%2$s';
214                                   }
215                                   if ($rsp->cat_title) {
216                                        $cat_title = sprintf($cat_link,$rsp->cat_id,
217                                        html::escapeHTML($rsp->cat_title));
218                                   } else {
219                                        $cat_title = __('None');
220                                   }
221                                   echo
222                                   '<tr>'.
223                                   '<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>'.
224                                   '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rsp->post_dt).'</td>'.
225                                   '<td class="nowrap">'.$cat_title.'</td>'.
226                                   '<td class="nowrap">'.$rsp->user_id.'</td>'.
227                                   '<td class="nowrap">'.__($meta_rs).'</td>'.
228                                   '<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>'.
229                                   '</tr>';
230                                   
231                              }
232                         }
233     
234                         echo '</table>';
235                    } else {
236                         echo '<p>'.__('No element (empty map)').'</p>';
237                    }
238                    echo
239                    '<div class="two-cols">'.
240                    '<p class="col"><a href="plugin.php?p=myGmaps&amp;post_type=page&amp;post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'.
241                    '<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>'.
242                    '</div>'.
243                    '</fieldset>';
244               }
245          }
246     }
247}   
248?>
Note: See TracBrowser for help on using the repository browser.

Sites map