forked from cyberwolf/cnapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cnapi.module
166 lines (148 loc) · 6.27 KB
/
cnapi.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
<?php
require_once 'cnapi.helpers.inc';
require_once 'cnapi.parsers.inc';
require_once 'cnapi.request.inc';
require_once 'cnapi.cache.inc';
require_once 'cnapi.api.inc';
require_once 'cnapi.values.inc';
define('CNAPI_API_LOCATION', 'http://build.uitdatabank.be/');
define('CNAPI_HTTP_REQUEST_TIMEOUT', 15);
define('CNAPI_LIST_SUMMARY', 'list_summary');
define('CNAPI_LIST_DETAIL', 'list_detail');
define('CNAPI_LIST_ID', 'list_id');
define('CNAPI_LIST_IGNORE', FALSE);
define('CNAPI_DEFAULT_PAGELENGTH', 10);
define('CNAPI_DEFAULT_SORT', 'date ASC');
define('CNAPI_CACHE_DISABLED', 0);
define('CNAPI_CACHE_ENABLED', 1);
define('CNAPI_LOCATIONS_DIMENSION_PROVINCE', 1);
define('CNAPI_LOCATIONS_DIMENSION_ADMINISTRATIVE', 2);
define('CNAPI_LOCATIONS_DIMENSION_TOURIST', 3);
define('CNAPI_LOCATIONS_DIMENSION_MUNICIPALITY', 4);
define('CNAPI_DIMENSION_EVENTTYPE', 1);
define('CNAPI_DIMENSION_THEME', 2);
define('CNAPI_DIMENSION_TARGETAUDIENCE', 3);
define('CNAPI_DIMENSION_FACILITY', 4);
define('CNAPI_DIMENSION_PUBLICSCOPE', 7);
define('CNAPI_DIMENSION_ACTORTYPE', 9);
define('CNAPI_DIMENSION_MUNICIPAL', 12);
define('CNAPI_DIMENSION_IPE', 13);
define('CNAPI_DIMENSION_MISC', 14);
define('CNAPI_OPTION_NONE', '_none');
/**
* Implements hook_menu().
*/
function cnapi_menu() {
$items['admin/config/services/cnapi'] = array(
'title' => 'CultuurNet API',
'description' => 'Change CultuurNet API setting like API key, location, ...',
'page callback' => 'drupal_get_form',
'page arguments' => array('cnapi_admin_settings'),
'access arguments' => array('administer site configuration'),
'file' => 'cnapi.admin.inc',
);
$items['admin/config/services/cnapi/settings'] = array(
'title' => 'Settings',
'description' => 'Select and configure your theme',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -1,
'file' => 'cnapi.admin.inc',
);
$items['admin/config/services/cnapi/defaults'] = array(
'title' => 'Defaults',
'description' => 'Change site name, e-mail address, slogan, default front page, and number of posts per page, error pages.',
'page callback' => 'drupal_get_form',
'page arguments' => array('cnapi_admin_defaults'),
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
'weight' => 0,
'file' => 'cnapi.admin.inc',
);
$items['cnapi/autocomplete/location'] = array(
'title' => 'Locations autocomplete',
'page callback' => 'cnapi_location_autocomplete',
'page arguments' => array(FALSE),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['cnapi/autocomplete/location/onlyzip'] = array(
'title' => 'Locations autocomplete',
'page callback' => 'cnapi_location_autocomplete',
'page arguments' => array(TRUE),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
$items['cnapi/autocomplete/actor'] = array(
'title' => 'Actors autocomplete',
'page callback' => 'cnapi_actor_autocomplete',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Implements hook_cron().
*/
function cnapi_cron() {
cache_clear_all(NULL, 'cache_cnapi');
cache_clear_all(NULL, 'cache_cnapi_detail');
}
/**
* Implements hook_form_alter().
*/
function cnapi_form_system_performance_settings_alter(&$form, $form_state) {
// We want our stuff before the clear cache fieldset and button.
$form['buttons']['#weight'] = 3;
$form['clear_cache']['#weight'] = 2;
// Adding API cache settings to the performance settings form.
$form['cnapi_cache'] = array(
'#type' => 'fieldset',
'#title' => t('CultuurNet API cache'),
'#weight' => 1,
'#description' => t('Enabling the CultuurNet API cache will cache all parsed results of requests to the CultuurNet API. This will reduce the number of requests made directly to the API service.'),
);
$form['cnapi_cache']['cnapi_cache_status'] = array(
'#type' => 'checkbox',
'#title' => t('Cache API requests'),
'#default_value' => variable_get('cnapi_cache_status', CNAPI_CACHE_ENABLED),
);
$period = array(0 => '<' . t('none') . '>') + drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400), 'format_interval');
$form['cnapi_cache']['cnapi_cache_lifetime'] = array(
'#type' => 'select',
'#title' => t('Minimum cache lifetime'),
'#default_value' => variable_get('cnapi_cache_lifetime', 0),
'#options' => $period,
'#description' => t('The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated'),
'#states' => array(
'invisible' => array(
'input[name="cnapi_cache_status"]' => array('checked' => FALSE),
),
),
);
$period = array(0 => '<' . t('none') . '>') + drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400, 86400 * 2, 86400 * 5, 86400 * 7, 86400 * 14, 86400 * 28), 'format_interval');
$form['cnapi_cache']['cnapi_cache_lifetime_detail'] = array(
'#type' => 'select',
'#title' => t('Minimum cache lifetime for details'),
'#default_value' => variable_get('cnapi_cache_lifetime_detail', 0),
'#options' => $period,
'#description' => t('The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated for actor and event details'),
'#states' => array(
'invisible' => array(
'input[name="cnapi_cache_status"]' => array('checked' => FALSE),
),
),
);
$period = array(0 => '<' . t('none') . '>') + drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400, 86400 * 2, 86400 * 5, 86400 * 7, 86400 * 14, 86400 * 28), 'format_interval');
$form['cnapi_cache']['cnapi_cache_lifetime_production'] = array(
'#type' => 'select',
'#title' => t('Minimum cache lifetime for productions'),
'#default_value' => variable_get('cnapi_cache_lifetime_production', 0),
'#options' => $period,
'#description' => t('The minimum cache lifetime is the minimum amount of time that will elapse before the cache is emptied and recreated for production details'),
'#states' => array(
'invisible' => array(
'input[name="cnapi_cache_status"]' => array('checked' => FALSE),
),
),
);
}