1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* This module provides block with a simple jQuery coundown
|
5
|
*
|
6
|
* Author: Marcin Pajdzik
|
7
|
*/
|
8
|
|
9
|
/**
|
10
|
* Implements hook_theme().
|
11
|
*/
|
12
|
function jquery_countdown_timer_theme() {
|
13
|
return array(
|
14
|
'jquery_countdown_timer_container' => array(
|
15
|
'variables' => array(),
|
16
|
)
|
17
|
);
|
18
|
}
|
19
|
|
20
|
/**
|
21
|
* Implements hook_block_info().
|
22
|
*/
|
23
|
function jquery_countdown_timer_block_info() {
|
24
|
$blocks = array();
|
25
|
$blocks['jquery_countdown_timer'] = array(
|
26
|
'info' => t('jQuery Countdown Timer'),
|
27
|
'cache' => DRUPAL_CACHE_GLOBAL
|
28
|
);
|
29
|
return $blocks;
|
30
|
}
|
31
|
|
32
|
/**
|
33
|
* Implements hook_block_configure().
|
34
|
*/
|
35
|
function jquery_countdown_timer_block_configure($delta) {
|
36
|
$form = array();
|
37
|
switch ($delta) {
|
38
|
case 'jquery_countdown_timer':
|
39
|
module_load_include('inc', 'date_api', 'date_api_elements');
|
40
|
$form['jquery_countdown_timer_font_size'] = array(
|
41
|
'#type' => 'textfield',
|
42
|
'#title' => t('Timer font size'),
|
43
|
'#default_value' => variable_get('jquery_countdown_timer_font_size', 28),
|
44
|
'#size' => 3,
|
45
|
'#maxlength' => 2,
|
46
|
);
|
47
|
$form['jquery_countdown_timer_date'] = array(
|
48
|
'#type' => 'date_select',
|
49
|
'#title' => t('Timer date'),
|
50
|
'#default_value' => variable_get('jquery_countdown_timer_date', date('Y-m-d G:i:s')),
|
51
|
'#date_format' => 'Y-m-d H:i',
|
52
|
);
|
53
|
break;
|
54
|
}
|
55
|
return $form;
|
56
|
}
|
57
|
|
58
|
|
59
|
/**
|
60
|
* Implements hook_block_save().
|
61
|
*/
|
62
|
function jquery_countdown_timer_block_save($delta = '', $edit = array()) {
|
63
|
switch ($delta) {
|
64
|
case 'jquery_countdown_timer':
|
65
|
variable_set('jquery_countdown_timer_date', $edit['jquery_countdown_timer_date']);
|
66
|
variable_set('jquery_countdown_timer_font_size', (int)$edit['jquery_countdown_timer_font_size']);
|
67
|
break;
|
68
|
}
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Implements hook_block_view().
|
73
|
*/
|
74
|
function jquery_countdown_timer_block_view($delta = '', $edit = array()) {
|
75
|
$block = '';
|
76
|
switch ($delta) {
|
77
|
case 'jquery_countdown_timer':
|
78
|
$block['subject'] = 'Countdown';
|
79
|
$block['content'] = array(
|
80
|
'#markup' => theme('jquery_countdown_timer_container', array()),
|
81
|
'#attached' => jquery_countdown_timer_attach(),
|
82
|
);
|
83
|
break;
|
84
|
}
|
85
|
return $block;
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* Adds timer to the page.
|
90
|
* @param mixed $context an optional value to provide context in calls
|
91
|
* @return array an array of items to attach to the current request
|
92
|
*/
|
93
|
function jquery_countdown_timer_attach($context = NULL) {
|
94
|
$attach = array();
|
95
|
$path = drupal_get_path('module', 'jquery_countdown_timer');
|
96
|
// add external js files
|
97
|
$attach['js'] = array(
|
98
|
$path . '/js/jquery_countdown_timer.js' => array (
|
99
|
'type' => 'file',
|
100
|
'scope' => 'footer',
|
101
|
),
|
102
|
$path . '/js/jquery_countdown_timer_init.js'=> array (
|
103
|
'type' => 'file',
|
104
|
'scope' => 'footer',
|
105
|
),
|
106
|
);
|
107
|
// set the default date and allow other projects to modify contextually
|
108
|
$date = variable_get('jquery_countdown_timer_date', date('Y-m-d G:i:s'));
|
109
|
drupal_alter('jquery_countdown_timer_date', $date, $context);
|
110
|
// add js settings
|
111
|
$settings = array(
|
112
|
'jquery_countdown_timer_date' => strtotime($date),
|
113
|
);
|
114
|
$attach['js'][] = array(
|
115
|
'data' => array('jquery_countdown_timer' => $settings),
|
116
|
'type' => 'setting',
|
117
|
);
|
118
|
//add css
|
119
|
$attach['css'] = array(
|
120
|
$path . '/css/jquery_countdown_timer.css',
|
121
|
);
|
122
|
//add inline css
|
123
|
$font_size = variable_get('jquery_countdown_timer_font_size', 28);
|
124
|
$attach['css'][] = array(
|
125
|
'data' => '.countdownHolder {font-size: ' . $font_size . 'px}',
|
126
|
'type' => 'inline',
|
127
|
);
|
128
|
return $attach;
|
129
|
}
|
130
|
|
131
|
/**
|
132
|
* Returns HTML for the timer container.
|
133
|
*
|
134
|
* @param type $variables
|
135
|
* @return string
|
136
|
*/
|
137
|
|
138
|
function theme_jquery_countdown_timer_container($variables) {
|
139
|
$output = '';
|
140
|
$output .= "<div id='jquery-countdown-timer'></div>";
|
141
|
$output .= "<div id='jquery-countdown-timer-note'></div>";
|
142
|
return $output;
|
143
|
}
|