-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweatherpic.module
173 lines (162 loc) · 5.14 KB
/
weatherpic.module
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* @file
* Show weather images of www.idokep.hu for Hungary in a block.
*
* This module provides an easy way to show the freely available
* weather images of the Hungarian www.idokep.hu website in a block.
* You can easily customize which of the 8 available images to show.
*/
/**
* Implements hook_block_info().
*/
function weatherpic_block_info() {
$block = array();
$block['weatherpic'] = array(
'info' => t('Weather Pic'),
'cache' => DRUPAL_NO_CACHE,
);
return $block;
}
/**
* Implements hook_help().
*/
function weatherpic_help($path, $arg) {
if ($path == 'admin/help#weatherpic') {
return '<p>' . t('This module provides an easy way to show the freely available weather images of the Hungarian
www.idokep.hu website in a block.') . '</p><p>' . t('On the <a href="@blocks">blocks
administration page</a> you can define the region where you would like to show the block.',
array('@blocks' => url('admin/structure/block'))) . '</p><p>' . t('At the <a href="@configure">
configuration page</a> you can choose which from the eight images want to show with checking the
corresponding checkbox(es).',
array('@configure' => url('admin/structure/block/manage/weatherpic/weatherpic/configure'))) . '</p>';
}
}
/**
* Implements hook_block_configure().
*/
function weatherpic_block_configure($delta) {
$form = array();
if ($delta == 'weatherpic') {
$options = array(
1 => t('Budapest smog map'),
2 => t('Clouds map'),
3 => t('Animated clouds map'),
4 => t('Heat map'),
5 => t('UV map'),
6 => t('Wind map'),
7 => t('Animated wind map'),
8 => t('Forecast bar'),
);
$form['weatherpics'] = array(
'#type' => 'checkboxes',
'#title' => t('Weather images'),
'#default_value' => variable_get('weatherpics', array()),
'#options' => $options,
'#description' => t('With these checkboxes you can customize which images to show in the block.'),
);
}
return $form;
}
/**
* Implements hook_block_save().
*/
function weatherpic_block_save($delta, $edit = array()) {
if($delta == 'weatherpic') {
variable_set('weatherpics', $edit['weatherpics']);
}
return;
}
/**
* Implements hook_block_view().
*/
function weatherpic_block_view($delta) {
if ($delta == 'weatherpic') {
$content = '';
$link = array();
$alt = array();
$weatherpics = variable_get('weatherpics');
foreach ($weatherpics as $tmp) {
if ($tmp != 0) {
switch ($tmp) {
case 1:
$link[] = 'http://terkep.idokep.hu/kis_bp_szenny.jpg';
$alt[] = t('Budapest smog map');
break;
case 2:
$link[] = 'http://terkep.idokep.hu/terkep/hu/wap_idokep.jpg';
$alt[] = t('Clouds map');
break;
case 3:
$link[] = 'http://terkep.idokep.hu/terkep/hu/i_anim.gif';
$alt[] = t('Animated clouds map');
break;
case 4:
$link[] = 'http://terkep.idokep.hu/terkep/hu/hom_kozepes.jpg';
$alt[] = t('Heat map');
break;
case 5:
$link[] = 'http://terkep.idokep.hu/terkep/hu_mini/uvfeny_small.jpg';
$alt[] = t('UV map');
break;
case 6:
$link[] = 'http://terkep.idokep.hu/terkep/hu/wap_szelterkep.jpg';
$alt[] = t('Wind map');
break;
case 7:
$link[] = 'http://terkep.idokep.hu/terkep/hu/s_anim.gif';
$alt[] = t('Animated wind map');
break;
case 8:
$link[] = 'http://www.idokep.hu/hosszutavu_elore.jpg';
$alt[] = t('Forecast bar');
break;
default:
$content = '';
break;
}
}
}
$content = theme('weatherpic_image', array( 'link' => $link, 'alt' => $alt));
$block = array(
'subject' => t('Weather Pic'),
'content' => $content,
);
return $block;
}
}
/**
* Implementation of hook_theme().
*/
function weatherpic_theme() {
return array(
'weatherpic_image' => array(
'arguments' => array(
'link' => NULL,
'alt' => NULL),
),
);
}
/**
* Theme function for theming weatherpic images.
*
* @param $arguments
* An array with the image links and alts
* @return
* An HTML themed string.
*/
function theme_weatherpic_image($arguments) {
$output = '';
$length = count($arguments['link']);
if ($length > 0) {
$module_path = drupal_get_path('module', 'weatherpic');
$full_path = $module_path .'/weatherpic.css';
drupal_add_css($full_path);
$output = '<ul id="weatherpic-list">';
for ($i = 0; $i < $length; $i++) {
$output .= '<li class="weatherpic-list-items">' . l('<img src="' . $arguments['link'][$i] . '" alt="' . $arguments['alt'][$i] . '">', 'http://www.idokep.hu', array('html' => TRUE)) . '</li>';
}
$output .= '<li id="weatherpic-source">' . t('source: ') . l(t('idokep.hu'), 'http://www.idokep.hu') . '</li></ul>';
}
return $output;
}