-
Notifications
You must be signed in to change notification settings - Fork 1
/
block_simple_map.php
127 lines (106 loc) · 4.56 KB
/
block_simple_map.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
class block_simple_map extends block_base {
/** @var int */
public static $navcount;
/** @var string */
public $blockname = null;
/** @var bool */
protected $contentgenerated = false;
/** @var bool|null */
protected $docked = null;
public function init() {
global $CFG;
$this->blockname = get_class($this);
$this->title = get_string('pluginname', 'block_simple_map');
}
public function has_config() {
return true;
}
public function instance_allow_multiple() {
return false;
}
function specialization() {
$this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(
get_string('pluginname', 'block_simple_map'));
if ($this->title == '') {
$this->title = format_string(get_string('pluginname', 'block_simple_map'));
}
}
public function get_content() {
global $CFG, $COURSE, $OUTPUT;
require_once ($CFG->libdir . '/pagelib.php');
if ($this->content !== null) {
return $this->content;
}
$googleAPIkey = get_config('block_simple_map', 'googleapikey');
if (!empty($this->config->category_of_places)) {
$category_of_places = $this->config->category_of_places;
} else {
$category_of_places = get_string('places', 'block_simple_map');
}
if (!empty($this->config->limit_search)) {
$limit_search = $this->config->limit_search;
} else {
$limit_search = '';
}
$data = '<script type="text/javascript" src="' . $CFG->wwwroot .
'/blocks/simple_map/javascript/jquery.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="' .
$CFG->wwwroot .
'/blocks/simple_map/javascript/gmap3.min.js"></script>
<script type="text/javascript" src="' .
$CFG->wwwroot .
'/blocks/simple_map/javascript/jquery-autocomplete.min.js"></script>
<script type="text/javascript" src="' .
$CFG->wwwroot . '/blocks/simple_map/javascript/custom.js"></script>
<noscript><p>JavaScript must be enabled in order for you to use Google Maps.
However, it seems JavaScript is either disabled or not supported by your browser.
To view Google Maps, enable JavaScript by changing your browser options, and then
try again.</p>
</noscript>
<div id="googleapikey" style="display: none;">' . $googleAPIkey . '</div>
<div id="simplemapsesskey" style="display: none;">' . sesskey() . '</div>
<div id="simplemaplimitsearch" style="display: none;">' . $limit_search . '</div>
<div id="simplemapwwwroot" style="display: none;">' . $CFG->wwwroot .
'</div>
<div id="s_map">
<form action="">
<p>' .
str_replace("SMap_Places", $category_of_places,
get_string('find_places_near_you', 'block_simple_map')) . '</p>
<p>' .
get_string('enter_address', 'block_simple_map') . '</p>
<div><input type="text" id="address" size="18" style="width: auto;" /></div>
<p>' .
get_string('set_distance', 'block_simple_map') . '</p>
<div><select id="distance">
<option value="1000">1km</option>
<option value="5000">5km</option>
<option value="10000" selected="selected">10km</option>
<option value="20000">20km</option>
</select></div>
</form>
<div id="simple_map" class="gmap3"></div>
</div>';
// check Capabilities
$context = context_course::instance($COURSE->id);
$this->content = new stdClass();
if (has_capability('moodle/site:manageblocks', $context)) {
$this->content->text = '';
$this->content->text = $data;
if (empty($googleAPIkey)) {
$this->content->text .= html_writer::div('Google API key must be specified in the admin settings for the plugin',"alert alert-error");
}
$this->content->text .= '<a title="configuration" href="' . $CFG->wwwroot .
'/blocks/simple_map/edit_upload_form.php">' .
get_string('upload_form', 'block_simple_map') . '</a>';
$this->content->footer = '';
} else {
$this->content->text = $data;
$this->content->footer = '';
}
return $this->content;
}
}
?>