-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhotels_misc.module
240 lines (201 loc) · 7.5 KB
/
hotels_misc.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php
/**
* @file
* Displays the time in a block.
*/
/**
* Implements hook_block_info().
* This hook declares what blocks are provided by the module.
*/
function hotels_misc_block_info() {
$blocks['hotels_header_top'] = array(
'info' => t('Current time, temperature and language'),
'status' => TRUE,
'region' => 'header',
'cache' => DRUPAL_CACHE_GLOBAL,
);
$blocks['hotels_booking'] = array(
'info' => t('Booking'),
'status' => TRUE,
'region' => 'sidebar_second',
'cache' => DRUPAL_CACHE_GLOBAL,
);
return $blocks;
}
/**
* Implements hook_block_view().
* This hook generates the contents of the blocks themselves.
*/
function hotels_misc_block_view($delta = '') {
switch ($delta) {
case 'hotels_header_top':
$block['subject'] = '';
$block['content'] = array(
'#markup' => hotels_misc_clock_temp(),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'hotels_misc') . '/js/clock_temperature.js',
),
),
);
break;
case 'hotels_booking':
$block['subject'] = '';
$block['content'] = array(
'#markup' => theme('hotels_booking'),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'hotels_misc') . '/booking/fbfulltrack.js',
drupal_get_path('module', 'hotels_misc') . '/booking/fblib.js',
//drupal_get_path('module', 'hotels_misc') . '/booking/fbparam.js',
),
),
);
break;
}
return $block;
}
/**
* Implements hook_theme().
* Defines the theming capabilities provided by this module.
*/
function hotels_misc_theme() {
return array(
'header_top_theme' => array(
'path' => drupal_get_path('module', 'hotels_misc') . '/theme',
'template' => 'header-top',
'variables' => array('vars' => NULL),
),
'hotels_booking' => array(
'path' => drupal_get_path('module', 'hotels_misc') . '/theme',
'template' => 'hotels-booking',
'variables' => array(),
),
);
}
function hotels_misc_clock_temp() {
$lybe = file_get_contents('http://weather.noaa.gov/pub/data/observations/metar/decoded/LYBE.TXT');
$tmp = explode("\n", $lybe);
preg_match_all('/\d+/', $tmp[4], $matches);
return theme('header_top_theme', array('vars' => $matches));
}
/**
* Function to build the select widget form.
*/
function lang_dropdown_form($form, &$form_state, $languages, $type) {
$settings = _lang_dropdown_get_settings();
$module_path = drupal_get_path('module', 'hotels_misc');
$options = $js_settings = $hidden_elements = array();
$selected_option_language_icon = '';
$hidden_elements['lang_dropdown_type'] = array(
'#type' => 'hidden',
'#default_value' => check_plain($type),
);
$language_names = locale_language_list('native');
// Now we iterate on $languages to build the needed options for the select element.
foreach ($languages->links as $lang_code => $lang_options) {
// language icons module add language when negotiation is session so be careful
// we need to get rid of that language icons bug by checking for native property
$language_object = isset($lang_options['language']) && isset($lang_options['language']->native) ? $lang_options['language'] : NULL;
// The language is not enabled on this domain
if ($domain_locale_exists && !array_key_exists($lang_code, $domain_languages)) continue;
// There is no translation for this language and not all languages are shown
if (!isset($lang_options['href']) && (!$settings['showall'])) continue;
// Build the options in an assosiative array, so it will be ready for #options in select form element.
$options += array($lang_code => $language_names[$lang_code]);
// Set the selected option to be ready for #default_value in select form element.
if (isset($lang_options['href']) && ($lang_options['href'] == $_GET['q'] || ($lang_options['href'] == '<front>' && drupal_is_front_page())) && ($lang_code == $GLOBALS[$type]->language)) {
$selected_option = $lang_code;
}
// Now we build our hidden form inputs to handle the redirections.
$href = isset($lang_options['href']) ? $lang_options['href'] : '<front>';
$hidden_elements[$lang_code] = array(
'#type' => 'hidden',
'#default_value' => check_plain(url($href, array(
'language' => $language_object,
'query' => isset($lang_options['query']) ? $lang_options['query'] : '',
))),
);
}
// Add required files and settings for JS widget.
if ($settings['js_widget']) {
drupal_add_js($module_path . '/js/jquery.dd.js');
$js_settings += array(
'visibleRows' => $settings['js_widget_settings']['visible_rows'],
'rowHeight' => $settings['js_widget_settings']['row_height'],
'animStyle' => $settings['js_widget_settings']['animation'],
);
drupal_add_css($module_path . '/css/dd.css');
$js_settings += array(
'mainCSS' => 'dd',
);
drupal_add_js(array('lang_dropdown' => array('jsWidget' => $js_settings)), 'setting');
}
// Now we build the $form array.
$form['lang_dropdown_select'] = array(
'#type' => 'select',
'#default_value' => isset($selected_option) ? $selected_option : key($options),
'#options' => $options,
'#attributes' => array(
'style' => 'width:' . $settings['js_widget_settings']['width'] . 'px',
'class' => array('lang-dropdown-select-element'),
),
'#attached' => array(
'js' => array($module_path . '/js/lang_dropdown.js'),
'css' => array($module_path . '/css/lang_dropdown.css'),
),
);
if (empty($hidden_elements)) return array();
$form += $hidden_elements;
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Go'),
// The below prefix & suffix for gracefull fallback if JavaScript was disabled
'#prefix' => "<noscript><div>\n",
'#suffix' => "\n</div></noscript>",
);
//var_dump($form);die('ok');
return $form;
}
/**
* Handles graceful degrade when JS is disabled.
*/
function lang_dropdown_form_submit($form, &$form_state) {
$language_code = check_plain($form_state['values']['lang_dropdown_select']);
$type = check_plain($form_state['values']['lang_dropdown_type']);
$language_codes = locale_language_list('language');
if (!in_array($language_code, $language_codes)) return;
$types = language_types_configurable(FALSE);
if (!in_array($type, $types)) $type = 'language';
$path = drupal_is_front_page() ? '<front>' : $_GET['q'];
$languages = language_negotiation_get_switch_links($type, $path);
$language = $languages->links[$language_code];
$newpath = isset($language['href']) ? $language['href'] : '<front>';
// language icons module add language when negotiation is session so be careful
// we need to get rid of that language icons bug by checking for native property
$language_object = isset($language['language']) && isset($language['language']->native) ? $language['language'] : NULL;
drupal_goto($newpath, array(
'language' => $language_object,
'query' => isset($language['query']) ? $language['query'] : '',
));
}
/**
* Helper function to get Language switcher dropdown settings
*/
function _lang_dropdown_get_settings() {
return array(
'showall' => 0,
'js_widget' => 1,
'js_widget_settings' => array(
'visible_rows' => 2,
'row_height' => 17,
'width' => 90,
'animation' => 'slideDown',
),
);
}
function hotels_misc_form_alter(&$form, &$form_state, $form_id) {
if($form_id == 'simplenews_block_form_1') {
unset($form['mail']['#title']);
}
}