Projet

Général

Profil

Paste
Télécharger (3,49 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / jquery_countdown_timer / jquery_countdown_timer.module @ 87dbc3bf

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 javascript to the block.
90
 */
91
function jquery_countdown_timer_attach() {
92
  $attach = array();
93
  $path = drupal_get_path('module', 'jquery_countdown_timer');
94
  // add external js files
95
  $attach['js'] = array(
96
    $path . '/js/jquery_countdown_timer.js' => array (
97
      'type' => 'file',
98
      'scope' => 'footer',
99
    ),
100
    $path . '/js/jquery_countdown_timer_init.js'=> array (
101
      'type' => 'file',
102
      'scope' => 'footer',
103
    ),
104
  );
105
  // add js settings
106
  $settings = array(
107
    'jquery_countdown_timer_date' => strtotime(variable_get('jquery_countdown_timer_date', date('Y-m-d G:i:s'))),
108
  );
109
   $attach['js'][] = array(
110
     'data' =>  array('jquery_countdown_timer' => $settings),
111
     'type' => 'setting',
112
   );
113
   //add css
114
   $attach['css'] = array(
115
     $path . '/css/jquery_countdown_timer.css',
116
   );
117
   //add inline css
118
   $font_size = variable_get('jquery_countdown_timer_font_size', 28);
119
   $attach['css'][] = array(
120
     'data' => '.countdownHolder {font-size: ' . $font_size . 'px}',
121
     'type' => 'inline',
122
   );
123
  return $attach;
124
}
125

    
126
/**
127
 * Returns HTML for the timer container.
128
 *
129
 * @param type $variables
130
 * @return string
131
 */
132

    
133
function theme_jquery_countdown_timer_container($variables) {
134
  $output = '';
135
  $output .= "<div id='jquery-countdown-timer'></div>";
136
  $output .= "<div id='jquery-countdown-timer-note'></div>";
137
  return $output;
138
}