Dotclear

source: plugins/myGmaps/branches/map.php @ 2868

Revision 2868, 14.7 KB checked in by Tomtom33, 13 years ago (diff)

Watch out \#1

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

Sites map