1 | <?php |
---|
2 | # -- BEGIN LICENSE BLOCK ---------------------------------- |
---|
3 | # This file is part of myLocation, a plugin for Dotclear. |
---|
4 | # |
---|
5 | # Copyright (c) 2010 Tomtom and contributors |
---|
6 | # http://blog.zenstyle.fr/ |
---|
7 | # |
---|
8 | # Licensed under the GPL version 2.0 license. |
---|
9 | # A copy of this license is available in LICENSE file or at |
---|
10 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
11 | # -- END LICENSE BLOCK ------------------------------------ |
---|
12 | |
---|
13 | if (!defined('DC_RC_PATH')) { return; } |
---|
14 | |
---|
15 | $core->addBehavior('publicFooterContent',array('myLocationBehaviors','publicFooterContent')); |
---|
16 | $core->addBehavior('templateBeforeBlock',array('myLocationBehaviors','templateBeforeBlock')); |
---|
17 | $core->addBehavior('coreBeforeCommentCreate',array('myLocationBehaviors','coreBeforeCommentCreate')); |
---|
18 | $core->addBehavior('coreBlogGetComments',array('myLocationBehaviors','coreBlogGetComments')); |
---|
19 | |
---|
20 | if ($core->blog->settings->myLocation->position === 'afterContent') { |
---|
21 | $core->addBehavior('publicCommentAfterContent',array('myLocationBehaviors','publicCommentAfterContent')); |
---|
22 | } |
---|
23 | else { |
---|
24 | $core->addBehavior('templateAfterValue',array('myLocationBehaviors','templateAfterValue')); |
---|
25 | } |
---|
26 | |
---|
27 | class myLocationBehaviors |
---|
28 | { |
---|
29 | public static function publicFooterContent($core,$_ctx) |
---|
30 | { |
---|
31 | $js = $core->blog->getQMarkURL().'pf='.basename(dirname(__FILE__)).'/js/post.js'; |
---|
32 | $css = $core->blog->getQMarkURL().'pf='.basename(dirname(__FILE__)).'/style.css'; |
---|
33 | |
---|
34 | echo $core->blog->settings->myLocation->enable ? |
---|
35 | '<link rel="stylesheet" media="screen" type="text/css" href="'.$css.'" />'."\n". |
---|
36 | '<script type="text/javascript">'."\n". |
---|
37 | '//<![CDATA['."\n". |
---|
38 | 'var post_location_checkbox = "'.__('Add my location').'";'."\n". |
---|
39 | 'var post_location_search = "'.__('Searching...').'";'."\n". |
---|
40 | 'var post_location_error_denied = "'.__('Permission denied by your browser').'";'."\n". |
---|
41 | 'var post_location_error_unavailable = "'.__('You location is currently unavailable. Please, try later').'";'."\n". |
---|
42 | 'var post_location_error_accuracy = "'.__('You location is currently unavailable for the choosen accuracy').'";'."\n". |
---|
43 | 'var post_location_longitude = "'.(isset($_POST['c_location_longitude']) ? $_POST['c_location_longitude'] : '').'";'."\n". |
---|
44 | 'var post_location_latitude = "'.(isset($_POST['c_location_latitude']) ? $_POST['c_location_latitude'] : '').'";'."\n". |
---|
45 | 'var post_location_address = "'.(isset($_POST['c_location_address']) ? $_POST['c_location_address'] : '').'";'."\n". |
---|
46 | 'var post_location_accuracy = "'.$core->blog->settings->myLocation->accuracy.'";'."\n". |
---|
47 | '//]]>'."\n". |
---|
48 | '</script>'."\n". |
---|
49 | '<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>'."\n". |
---|
50 | '<script type="text/javascript" src="'.$js.'"></script>'."\n" : ''; |
---|
51 | } |
---|
52 | |
---|
53 | public static function templateBeforeBlock($core,$tag,$attr) |
---|
54 | { |
---|
55 | if ($tag === 'Comments') { |
---|
56 | return '<?php $params["columns"][] = "comment_location"; ?>'; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | public static function publicCommentAfterContent($core,$_ctx) |
---|
61 | { |
---|
62 | if ($_ctx->comments->hasLocation()) { |
---|
63 | echo '<p class="comment-location">'.$_ctx->comments->getLocation().'</p>'; |
---|
64 | } |
---|
65 | } |
---|
66 | |
---|
67 | public static function templateAfterValue($core,$tag,$attr) |
---|
68 | { |
---|
69 | $fit_tag = $core->blog->settings->myLocation->position; |
---|
70 | |
---|
71 | if ($tag === $fit_tag) { |
---|
72 | return |
---|
73 | "<?php\n". |
---|
74 | 'if ($_ctx->comments->hasLocation()) {'."\n". |
---|
75 | 'echo \' <span class="comment-location">\'.$_ctx->comments->getLocation().\'</span>\';'."\n". |
---|
76 | '}'."\n". |
---|
77 | "?>"; |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | public static function coreBeforeCommentCreate($blog,$cur) |
---|
82 | { |
---|
83 | $location = array( |
---|
84 | 'longitude' => $_POST['c_location_longitude'], |
---|
85 | 'latitude' => $_POST['c_location_latitude'], |
---|
86 | 'address' => $_POST['c_location_address'] |
---|
87 | ); |
---|
88 | $cur->comment_location = serialize($location); |
---|
89 | } |
---|
90 | |
---|
91 | public static function coreBlogGetComments($rs) |
---|
92 | { |
---|
93 | $rs->extend('rsExtCommentLocation'); |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | ?> |
---|