Dotclear

source: plugins/myGmaps/_admin.php @ 2814

Revision 2814, 5.4 KB checked in by philippe, 13 years ago (diff)

plugin myGmaps created

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('adminPostForm',array('myGmapsPostBehaviors','adminPostForm'));
26$core->addBehavior('adminAfterPostUpdate',array('myGmapsPostBehaviors','adminAfterPostUpdate'));
27
28if (isset($_GET['remove']) && $_GET['remove'] == 'map') {
29     try {
30     $post_id = $_GET['id'];
31     $meta =& $GLOBALS['core']->meta;
32     $meta->delPostMeta($post_id,'map');
33     $meta->delPostMeta($post_id,'map_options');
34     
35     http::redirect(DC_ADMIN_URL.'post.php?id='.$post_id);
36     
37  } catch (Exception $e) {
38    $core->error->add($e->getMessage());
39  }
40} elseif (!empty($_GET['remove'])) {
41     try {
42     $post_id = $_GET['id'];
43     $meta =& $GLOBALS['core']->meta;
44     $meta->delPostMeta($post_id,'map',(integer) $_GET['remove']);
45     
46     http::redirect(DC_ADMIN_URL.'post.php?id='.$post_id);
47     
48  } catch (Exception $e) {
49    $core->error->add($e->getMessage());
50  }
51}
52
53class myGmapsPostBehaviors
54{
55     public static function postHeaders()
56     {
57          return
58          '<script type="text/javascript">'."\n".
59          '$(document).ready(function() {'."\n".
60               '$(\'a.map-remove\').click(function() {'."\n".
61               'msg = \''.__('Are you sure you want to remove this map?').'\';'."\n".
62               'if (!window.confirm(msg)) {'."\n".
63                    'return false;'."\n".
64               '}'."\n".
65               '});'."\n".
66               '$(\'a.element-remove\').click(function() {'."\n".
67               'msg = \''.__('Are you sure you want to remove this element?').'\';'."\n".
68               'if (!window.confirm(msg)) {'."\n".
69                    'return false;'."\n".
70               '}'."\n".
71               '});'."\n".
72          '});'."\n".
73          '</script>'.
74          '<style type="text/css">'."\n".
75               'a.element-remove {'."\n".
76                    'color : #999 !important;'."\n".
77                    'border: none;'."\n".
78               '}'."\n".
79                    'a.element-remove:hover, a.element-remove:focus {'."\n".
80                    'color : #06c !important;'."\n".
81          '}'."\n".
82          '</style>';
83         
84     }
85     public static function adminPostForm($post)
86     {
87          global $core;
88          $id = $post->post_id;
89          $meta =& $GLOBALS['core']->meta;
90          $meta_rs = $meta->getMetaStr($post->post_meta,'map');
91          if ($id) {
92               if (!$meta_rs) {
93                    echo 
94                         '<fieldset><legend>'.__('Google Map').'</legend>'.
95                         '<p><a href="plugin.php?p=myGmaps&amp;post_id='.$id.'">'.__('Add a map to entry').'</a></p>'.
96                         '</fieldset>';
97               } else {
98                   
99                    $meta =& $GLOBALS['core']->meta;
100                    $maps_array = explode(",",$meta->getMetaStr($post->post_meta,'map'));
101                    $maps_options = explode(",",$meta->getMetaStr($post->post_meta,'map_options'));
102                   
103                    echo '<fieldset><legend>'.__('Google Map').'</legend>'.
104                    '<h3>'.__('Map elements').'</h3>';
105                   
106                    echo
107                         '<table class="clear"><tr>'.
108                         '<th>'.__('Title').'</th>'.
109                         '<th>'.__('Date').'</th>'.
110                         '<th>'.__('Category').'</th>'.
111                         '<th>'.__('Author').'</th>'.
112                         '<th class="nowrap">'.__('Type').'</th>'.
113                         '<th>&nbsp;</th>'.
114                         '</tr>';
115                   
116                    $params['post_type'] = 'map';
117                    $params['no_content'] = true;
118                   
119                    $rsp = $core->blog->getPosts($params);
120                    while ($rsp->fetch()) {
121                         if (in_array($rsp->post_id,$maps_array)) {
122                              $meta_rs = $meta->getMetaStr($rsp->post_meta,'map');
123                              if ($core->auth->check('categories',$core->blog->id)) {
124                                   $cat_link = '<a href="category.php?id=%s">%s</a>';
125                              } else {
126                                   $cat_link = '%2$s';
127                              }
128                              if ($rsp->cat_title) {
129                                   $cat_title = sprintf($cat_link,$rsp->cat_id,
130                                   html::escapeHTML($rsp->cat_title));
131                              } else {
132                                   $cat_title = __('None');
133                              }
134                              echo
135                              '<tr>'.
136                              '<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>'.
137                              '<td class="nowrap">'.dt::dt2str(__('%Y-%m-%d %H:%M'),$rsp->post_dt).'</td>'.
138                              '<td class="nowrap">'.$cat_title.'</td>'.
139                              '<td class="nowrap">'.$rsp->user_id.'</td>'.
140                              '<td class="nowrap">'.__($meta_rs).'</td>'.
141                              '<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>'.
142                              '</tr>';
143                             
144                         }
145                    }
146
147                    echo '</table>'.
148                    '<div class="two-cols">'.
149                    '<p class="col"><a href="plugin.php?p=myGmaps&amp;post_id='.$id.'"><strong>'.__('Edit map').'</strong></a></p>'.
150                    '<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>'.
151                    '</div>'.
152                    '</fieldset>';
153                   
154               }
155          }
156     }
157     public static function adminAfterPostUpdate()
158     {
159          if ($_GET['remove'] == 'ok') {
160               echo '<p class="message">'.__('Map has been successfully deleted.').'</p>';
161          }
162     }
163}   
164?>
Note: See TracBrowser for help on using the repository browser.

Sites map