Dotclear

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

Revision 2870, 13.3 KB checked in by Tomtom33, 13 years ago (diff)

Watch out #3

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

Sites map