Dotclear

source: plugins/myGmaps/map.php @ 2815

Revision 2815, 14.4 KB checked in by philippe, 13 years ago (diff)

myGmaps : fixed notice php 5.3 in map.php

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
13require_once DC_ROOT.'/inc/admin/prepend.php';
14
15dcPage::check('usage,contentadmin');
16
17$p_url    = 'plugin.php?p='.basename(dirname(__FILE__));
18$s =& $core->blog->settings->myGmaps;
19
20$myGmaps_center = $s->myGmaps_center;
21$myGmaps_zoom = $s->myGmaps_zoom;
22$myGmaps_type = $s->myGmaps_type;
23     
24$post_id = '';
25$cat_id = '';
26$post_dt = '';
27$post_type = 'map';
28$post_maps = 'none';
29$post_format = $core->auth->getOption('post_format');
30$post_password = '';
31$post_url = '';
32$post_lang = $core->auth->getInfo('user_lang');
33$post_title = '';
34$post_excerpt = '';
35$post_excerpt_xhtml = '';
36$post_content = '';
37$post_content_xhtml = '';
38$post_notes = '';
39$post_status = $core->auth->getInfo('user_post_status');
40$post_selected = false;
41$post_open_comment = '';
42$post_open_tb = '';
43
44$post_media = array();
45
46$page_title = __('New map element');
47
48$can_view_page = true;
49$can_edit_post = $core->auth->check('usage,contentadmin',$core->blog->id);
50$can_publish = $core->auth->check('publish,contentadmin',$core->blog->id);
51$can_delete = false;
52
53$post_headlink = '<link rel="%s" title="%s" href="map.php?id=%s" />';
54$post_link = '<a href="'.$p_url.'&amp;do=edit&amp;id=%s" title="%s">%s</a>';
55
56$next_link = $prev_link = $next_headlink = $prev_headlink = null;
57
58# If user can't publish
59if (!$can_publish) {
60     $post_status = -2;
61}
62
63# Getting categories
64$categories_combo = array('&nbsp;' => '');
65try {
66     $categories = $core->blog->getCategories(array('post_type'=>'post'));
67     while ($categories->fetch()) {
68          $categories_combo[] = new formSelectOption(
69               str_repeat('&nbsp;&nbsp;',$categories->level-1).'&bull; '.html::escapeHTML($categories->cat_title),
70               $categories->cat_id
71          );
72     }
73} catch (Exception $e) { }
74
75# Status combo
76$status_combo = array(
77     __('pending') => '-2',
78     __('online') => '1'
79);
80
81# Formaters combo
82foreach ($core->getFormaters() as $v) {
83     $formaters_combo[$v] = $v;
84}
85
86# Languages combo
87$rs = $core->blog->getLangs(array('order'=>'asc'));
88$all_langs = l10n::getISOcodes(0,1);
89$lang_combo = array('' => '', __('Most used') => array(), __('Available') => l10n::getISOcodes(1,1));
90while ($rs->fetch()) {
91     if (isset($all_langs[$rs->post_lang])) {
92          $lang_combo[__('Most used')][$all_langs[$rs->post_lang]] = $rs->post_lang;
93          unset($lang_combo[__('Available')][$all_langs[$rs->post_lang]]);
94     } else {
95          $lang_combo[__('Most used')][$rs->post_lang] = $rs->post_lang;
96     }
97}
98unset($all_langs);
99unset($rs);
100
101
102# Get entry informations
103if (!empty($_REQUEST['id']))
104{
105     $params['post_id'] = $_REQUEST['id'];
106     $params['post_type'] = 'map';
107     
108     $post = $core->blog->getPosts($params);
109     
110     if ($post->isEmpty())
111     {
112          $core->error->add(__('This map element does not exist.'));
113          $can_view_page = false;
114     }
115     else
116     {
117          $post_id = $post->post_id;
118          $cat_id = $post->cat_id;
119          $post_dt = date('Y-m-d H:i',strtotime($post->post_dt));
120          $post_type = $post->post_type;
121          $post_maps = $post->post_maps;
122          $post_format = $post->post_format;
123          $post_password = $post->post_password;
124          $post_url = $post->post_url;
125          $post_lang = $post->post_lang;
126          $post_title = $post->post_title;
127          $post_excerpt = $post->post_excerpt;
128          $post_excerpt_xhtml = $post->post_excerpt_xhtml;
129          $post_content = $post->post_content;
130          $post_content_xhtml = $post->post_content_xhtml;
131          $post_notes = $post->post_notes;
132          $post_status = $post->post_status;
133          $post_selected = (boolean) $post->post_selected;
134          $post_open_comment = (boolean) $post->post_open_comment;
135          $post_open_tb = (boolean) $post->post_open_tb;
136         
137          $page_title = __('Edit map element');
138         
139          $can_edit_post = $post->isEditable();
140          $can_delete= $post->isDeletable();
141         
142          $next_rs = $core->blog->getNextPost($post,1);
143          $prev_rs = $core->blog->getNextPost($post,-1);
144         
145          if ($next_rs !== null) {
146               $next_link = sprintf($post_link,$next_rs->post_id,
147                    html::escapeHTML($next_rs->post_title),__('next element').'&nbsp;&#187;');
148               $next_headlink = sprintf($post_headlink,'next',
149                    html::escapeHTML($next_rs->post_title),$next_rs->post_id);
150          }
151         
152          if ($prev_rs !== null) {
153               $prev_link = sprintf($post_link,$prev_rs->post_id,
154                    html::escapeHTML($prev_rs->post_title),'&#171;&nbsp;'.__('previous element'));
155               $prev_headlink = sprintf($post_headlink,'previous',
156                    html::escapeHTML($prev_rs->post_title),$prev_rs->post_id);
157          }
158         
159          try {
160               $core->media = new dcMedia($core);
161               $post_media = $core->media->getPostMedia($post_id);
162          } catch (Exception $e) {}
163     }
164}
165
166# Format excerpt and content
167if (!empty($_POST) && $can_edit_post)
168{
169     $post_format = $_POST['post_format'];
170     $post_excerpt = $_POST['post_excerpt'];
171     $post_content = $_POST['post_content'];
172     
173     $post_title = $_POST['post_title'];
174     
175     $cat_id = (integer) $_POST['cat_id'];
176     
177     if (isset($_POST['post_status'])) {
178          $post_status = (integer) $_POST['post_status'];
179     }
180     
181     if (empty($_POST['post_dt'])) {
182          $post_dt = '';
183     } else {
184          $post_dt = strtotime($_POST['post_dt']);
185          $post_dt = date('Y-m-d H:i',$post_dt);
186     }
187     
188     $post_open_comment = !empty($_POST['post_open_comment']);
189     $post_open_tb = !empty($_POST['post_open_tb']);
190     $post_selected = !empty($_POST['post_selected']);
191     $post_lang = $_POST['post_lang'];
192     $post_password = !empty($_POST['post_password']) ? $_POST['post_password'] : null;
193     
194     $post_notes = $_POST['post_notes'];
195     
196     if (isset($_POST['post_url'])) {
197          $post_url = $_POST['post_url'];
198     }
199     
200     $core->blog->setPostContent(
201          $post_id,$post_format,$post_lang,
202          $post_excerpt,$post_excerpt_xhtml,$post_content,$post_content_xhtml
203     );
204}
205
206# Create or update post
207if (!empty($_POST) && !empty($_POST['save']) && $can_edit_post)
208{
209     $cur = $core->con->openCursor($core->prefix.'post');
210     
211     $cur->post_title = $post_title;
212     $cur->cat_id = ($cat_id ? $cat_id : null);
213     $cur->post_dt = $post_dt ? date('Y-m-d H:i:00',strtotime($post_dt)) : '';
214     $cur->post_type = $post_type;
215     $cur->post_format = $post_format;
216     $cur->post_password = $post_password;
217     $cur->post_lang = $post_lang;
218     $cur->post_title = $post_title;
219     $cur->post_excerpt = $post_excerpt;
220     $cur->post_excerpt_xhtml = $post_excerpt_xhtml;
221     $cur->post_content = $post_content;
222     $cur->post_content_xhtml = $post_content_xhtml;
223     $cur->post_notes = $post_notes;
224     $cur->post_status = $post_status;
225     $cur->post_selected = (integer) $post_selected;
226     $cur->post_open_comment = (integer) $post_open_comment;
227     $cur->post_open_tb = (integer) $post_open_tb;
228     
229     if (isset($_POST['post_url'])) {
230          $cur->post_url = $post_url;
231     }
232     
233     
234     
235     # Update post
236     if ($post_id)
237     {
238         
239          try
240          {
241               # --BEHAVIOR-- adminBeforePostUpdate
242               $core->callBehavior('adminBeforePostUpdate',$cur,$post_id);
243               
244               $core->blog->updPost($post_id,$cur);
245               
246               # --BEHAVIOR-- adminAfterPostUpdate
247               $core->callBehavior('adminAfterPostUpdate',$cur,$post_id);
248               
249               if (isset($_POST['post_maps'])) {
250                    $tags = $_POST['post_maps'];
251                    $myGmaps_center = $_POST['myGmaps_center'];
252                    $myGmaps_zoom = $_POST['myGmaps_zoom'];
253                    $myGmaps_type = $_POST['myGmaps_type'];
254                    $meta =& $GLOBALS['core']->meta;
255                    $meta->delPostMeta($post_id,'map');
256                    $meta->delPostMeta($post_id,'map_options');
257                   
258                    foreach ($meta->splitMetaValues($tags) as $tag) {
259                         $meta->setPostMeta($post_id,'map',$tag);
260                    }
261                    $map_options = $myGmaps_center.','.$myGmaps_zoom.','.$myGmaps_type;
262                    $meta->setPostMeta($post_id,'map_options',$map_options);
263               }
264               http::redirect(''.$p_url.'&do=edit&id='.$post_id.'&upd=1');
265          }
266          catch (Exception $e)
267          {
268               $core->error->add($e->getMessage());
269          }
270     }
271     else
272     {
273          $cur->user_id = $core->auth->userID();
274         
275          try
276          {
277               # --BEHAVIOR-- adminBeforePostCreate
278               $core->callBehavior('adminBeforePostCreate',$cur);
279               
280               $return_id = $core->blog->addPost($cur);
281               
282               
283               
284               # --BEHAVIOR-- adminAfterPostCreate
285               $core->callBehavior('adminAfterPostCreate',$cur,$return_id);
286               
287               if (isset($_POST['post_maps'])) {
288                    $tags = $_POST['post_maps'];
289                    $myGmaps_center = $_POST['myGmaps_center'];
290                    $myGmaps_zoom = $_POST['myGmaps_zoom'];
291                    $myGmaps_type = $_POST['myGmaps_type'];
292                    $meta =& $GLOBALS['core']->meta;
293                   
294                    foreach ($meta->splitMetaValues($tags) as $tag) {
295                         $meta->setPostMeta($return_id,'map',$tag);
296                    }
297                    $map_options = $myGmaps_center.','.$myGmaps_zoom.','.$myGmaps_type;
298                    $meta->setPostMeta($return_id,'map_options',$map_options);
299               }
300               
301               http::redirect(''.$p_url.'&do=edit&id='.$return_id.'&crea=1');
302          }
303          catch (Exception $e)
304          {
305               $core->error->add($e->getMessage());
306          }
307     }
308}
309
310if (!empty($_POST['delete']) && $can_delete)
311{
312     try {
313          # --BEHAVIOR-- adminBeforePostDelete
314          $core->callBehavior('adminBeforePostDelete',$post_id);
315          $core->blog->delPost($post_id);
316          http::redirect($p_url.'&amp;do=edit');
317     } catch (Exception $e) {
318          $core->error->add($e->getMessage());
319     }
320}
321
322/* DISPLAY
323-------------------------------------------------------- */
324?>
325<html>
326     <head>
327          <title><?php echo $page_title; ?></title>
328          <?php
329          echo
330          dcPage::jsDatePicker().
331          dcPage::jsToolBar().
332          dcPage::jsModal().
333          dcPage::jsLoad(DC_ADMIN_URL.'?pf=myGmaps/js/_map.js').
334          dcPage::jsConfirmClose('entry-form').
335          dcPage::jsPageTabs($default_tab).
336          $next_headlink."\n".$prev_headlink
337          ?>
338    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
339    <style type="text/css">
340     #map_canvas{height:400px;padding:3px;border:1px solid #999999;margin:-10px 0 1px 0; }
341     textarea[name=post_excerpt] {display:none;}
342     .infowindow {margin-top:1em;}
343     </style>
344     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
345     <body>
346<?php
347
348$default_tab = 'edit-entry';
349if (!$can_edit_post) {
350     $default_tab = '';
351}
352
353if (!empty($_GET['upd'])) {
354          echo '<p class="message">'.__('Map element has been successfully updated.').'</p>';
355}
356elseif (!empty($_GET['crea'])) {
357          echo '<p class="message">'.__('Map element has been successfully created.').'</p>';
358}
359
360
361# XHTML conversion
362if (!empty($_GET['xconv']))
363{
364     $post_excerpt = $post_excerpt_xhtml;
365     $post_content = $post_content_xhtml;
366     $post_format = 'xhtml';
367     
368     echo '<p class="message">'.__('Don\'t forget to validate your XHTML conversion by saving your post.').'</p>';
369}
370
371echo '<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Google Maps').' &rsaquo; '.$page_title;
372
373
374echo '</h2>';
375
376if ($post_id)
377{
378     echo '<p>';
379     if ($prev_link) {
380          echo $prev_link.' - '.'<a href="'.$p_url.'&amp;do=list">'.__('elements list').'</a>';
381     } else {
382          echo '<a href="'.$p_url.'&amp;do=list">'.__('elements list').'</a>';
383     }
384     if ($next_link) {
385          echo ' - '.$next_link;
386     }
387     
388     # --BEHAVIOR-- adminPostNavLinks
389     $core->callBehavior('adminPostNavLinks',isset($post) ? $post : null);
390     
391     echo '</p>';
392}
393
394# Exit if we cannot view page
395if (!$can_view_page) {
396     dcPage::helpBlock('core_post');
397     dcPage::close();
398     exit;
399}
400
401/* Post form if we can edit post
402-------------------------------------------------------- */
403if ($can_edit_post)
404{
405     echo '<div class="multi-part" title="'.__('Edit map element').'" id="edit-entry">';
406     echo '<form action="'.$p_url.'&amp;do=edit" method="post" id="entry-form">';
407     echo '<div id="entry-sidebar">';
408     
409     echo
410     '<p><label>'.__('Category:').
411     form::combo('cat_id',$categories_combo,$cat_id,'maximal',3).
412     '</label></p>'.
413     
414     '<p><label>'.__('Map element status:').
415     form::combo('post_status',$status_combo,$post_status,'',3,!$can_publish).
416     '</label></p>'.
417     
418     '<p><label>'.__('Map element published on:').
419     form::field('post_dt',16,16,$post_dt,'',3).
420     '</label></p>'.
421     
422     '<p><label>'.__('Text formating:').
423     form::combo('post_format',$formaters_combo,$post_format,'',3).
424     '</label></p>';     
425     
426     
427     echo '</div>';      // End #entry-sidebar
428     
429     echo '<div id="entry-content"><fieldset class="constrained">';
430     
431     echo
432     '<p class="col"><label class="required" title="'.__('Required field').'">'.__('Title:').
433     form::field('post_title',20,255,html::escapeHTML($post_title),'maximal',2).
434     '</label></p>'.
435     
436     '<p class="maximal" style="margin-bottom:5px"><input id="delete_overlays" type="button" value="'.__('Initialize map').'"/>'.
437     '<span> </span><input id="use_kml_file" type="button" value="'.__('Include kml file').'"/>';
438     
439     
440     $meta =& $GLOBALS['core']->meta;
441     
442     if(isset($post)) {
443          echo form::hidden('post_maps',$meta->getMetaStr($post->post_meta,'map')).'</p>';
444     } else {
445          echo form::hidden('post_maps','').'</p>';
446     }
447     
448     echo
449     '<p class="area" id="excerpt-area"><label class="required" title="'.__('Required field').'" '.
450     'for="post_excerpt">'.__('Coordinates:').'</label> '.
451     form::textarea('post_excerpt',50,3,html::escapeHTML($post_excerpt),'',2).
452     '</p>'.
453
454     
455     
456     '<p class="area" id="map_canvas"></p>'.
457     
458     '<p class="area"><label class="required infowindow" title="'.__('Required field').'" '.
459     'for="post_content">'.__('Description:').'</label> '.
460     form::textarea('post_content',50,$core->auth->getOption('edit_size'),html::escapeHTML($post_content),'',2).
461     '</p>'.
462     
463     '<p class="area" id="notes-area"><label>'.__('Notes:').'</label>'.
464     form::textarea('post_notes',50,5,html::escapeHTML($post_notes),'',2).
465     '</p>';
466     
467     if(isset($post)) {
468          $meta_rs = $meta->getMetaStr($post->post_meta,'map_options');
469          if ($meta_rs) {
470               $map_options = explode(",",$meta_rs);
471               $myGmaps_center = $map_options[0].','.$map_options[1];
472               $myGmaps_zoom = $map_options[2];
473               $myGmaps_type = $map_options[3];
474          }
475     }
476     echo
477     '<p>'.
478     ($post_id ? form::hidden('id',$post_id) : '').
479     '<input type="submit" value="'.__('save').' (s)" tabindex="4" '.
480     'accesskey="s" name="save" /> '.
481     '<input type="hidden" name="myGmaps_center" id="myGmaps_center" value="'.$myGmaps_center.'" />'.
482     '<input type="hidden" name="myGmaps_zoom" id="myGmaps_zoom" value="'.$myGmaps_zoom.'" />'.
483     '<input type="hidden" name="myGmaps_type" id="myGmaps_type" value="'.$myGmaps_type.'" />'.
484     ($can_delete ? '<input type="submit" value="'.__('delete').'" name="delete" />' : '').
485     $core->formNonce().
486     '</p>';
487     
488     echo '</fieldset></div>';          // End #entry-content
489     echo '</form>';
490     echo '</div>';
491     
492}
493
494
495dcPage::helpBlock('myGmap','core_wiki');
496?>
497     </body>
498</html>
Note: See TracBrowser for help on using the repository browser.

Sites map