-
Notifications
You must be signed in to change notification settings - Fork 0
/
nameday.module
128 lines (116 loc) · 2.94 KB
/
nameday.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
<?php
/**
* @file
* Show a block with actual date, name day and holiday if exists
*/
/**
* Implements hook_menu().
*/
function nameday_menu() {
$items = array();
$items['admin/config/regional/nameday'] = array(
'title' => 'Nameday',
'page callback' => 'drupal_get_form',
'page arguments' => array('nameday_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'nameday.admin.inc'
);
return $items;
}
/**
* Implements hook_block_info().
*/
function nameday_block_info() {
$blocks['nameday'] = array(
'info' => t("Name day"),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function nameday_block_view($delta = '') {
$nameday = _nameday_get_row();
if (!count($nameday)) {
return FALSE;
}
switch ($delta) {
case 'nameday':
$block['subject'] = t('Name day');
$block['content'] = theme('nameday', _nameday_get_row());
return $block;
break;
}
}
/**
* Implements hook_theme().
*/
function nameday_theme() {
return array(
'nameday' => array(
'arguments' => array('nameday' => NULL ),
'template' => 'nameday',
)
);
}
function nameday_preprocess_nameday(&$variables, $hook) {
if (array_key_exists(0, $variables)) {
$variables['name'] = $variables[0]->name;
if (variable_get('nameday_show_date', TRUE)) {
$variables['date'] = format_date(REQUEST_TIME, variable_get('nameday_date_format', 'small'), variable_get('nameday_date_format_custom', ''));
}
else {
$variables['date'] = FALSE;
}
if (variable_get('nameday_show_holiday', TRUE) && $variables[0]->holiday != '') {
$variables['holiday'] = $variables[0]->holiday;
}
else {
$variables['holiday'] = FALSE;
}
}
}
/**
* return the current day database row-array
*/
function _nameday_get_row() {
global $language;
//static $result = NULL;
//if (!$result) {
//setting the current timestamp with timezone
$time = format_date(REQUEST_TIME, 'custom', 'U');
$date = getdate($time);
$select = db_select('nameday', 'n');
$select->addField('n', 'name');
$select->addField('n', 'holiday');
$select->condition('n.month', $date["mon"]);
$select->condition('n.day', $date["mday"]);
$select->condition('n.language', $language->language);
try {
$entries = $select->execute()->fetchAll();
} catch (Exception $e) {
drupal_set_message( $e->getMessage());
}
//}
return $entries;
}
/**
*
* Token support is early alpha.
*
* Implements hook_token_values().
*/
function nameday_token_values($type, $object = NULL, $options = array()) {
$result = _nameday_get_row();
$tokens['nameday'] = $result['name'];
$tokens['holiday'] = $result['holiday'];
return $tokens;
}
/**
* Implements hook_token_list().
*/
function nameday_token_list($type = 'all') {
$tokens[$type]['nameday'] = "Current nameday";
$tokens[$type]['holiday'] = "Current holiday if any";
return $tokens;
}