-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathunical_client.module
247 lines (211 loc) · 7.31 KB
/
unical_client.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
241
242
243
244
245
246
247
<?php
/**
* @file
* Implements various hooks and functions to run the unical_client module.
*/
/**
* Implements hook_help().
*/
function unical_client_help($path, $arg) {
switch ($path) {
case 'admin/help#unical_client':
$filepath = dirname(__FILE__) . '/README.md';
if (file_exists($filepath)) {
$readme = file_get_contents($filepath);
}
else {
$filepath = dirname(__FILE__) . '/README.txt';
if (file_exists($filepath)) {
$readme = file_get_contents($filepath);
}
}
if (!isset($readme)) {
return NULL;
}
if (module_exists('markdown')) {
$filters = module_invoke('markdown', 'filter_info');
$info = $filters['filter_markdown'];
if (function_exists($info['process callback'])) {
$output = $info['process callback']($readme, NULL);
}
else {
$output = '<pre>' . $readme . '</pre>';
}
}
else {
$output = '<pre>' . $readme . '</pre>';
}
return $output;
}
}
/**
* Implements hook_init().
*/
function unical_client_init() {
// Get API URL setting.
$site_url = variable_get('unical_client_settings_site_url');
$site_id = variable_get('unical_client_settings_site_id');
$addthis_id = variable_get('unical_client_settings_addevent_id');
// JS Variables.
$settings = array(
'site_url' => $site_url,
'site_id' => $site_id,
'addevent_id' => $addthis_id,
);
drupal_add_js(array('unical_client_variables' => $settings), 'setting');
// Fonts.
drupal_add_css('https://fonts.googleapis.com/css?family=Open+Sans:400,700', 'external');
drupal_add_css('https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', 'external');
// Unical server assets.
// If the site url is '/', the server is in the local Drupal docroot.
if ($site_url === '/') {
// Empty out the $site_url string so that the file paths are relative to
// the Drupal docroot and not the system root.
$site_url = '';
$type = 'file';
}
else {
$type = 'external';
}
// Unical API JS.
drupal_add_js($site_url . drupal_get_path('module', 'unical') .'/app/build/unical.js', array('type' => $type, 'weight' => -20, 'scope' => 'footer'));
// CSS.
// Add stock UniCal Styles if boolean is checked.
if(variable_get('unical_client_settings_use_stock')) {
drupal_add_css($site_url . drupal_get_path('module', 'unical') .'/assets/css/styles.css', $type);
}
// Add custom UniCal Styles if boolean is checked.
if(variable_get('unical_client_settings_use_custom')) {
drupal_add_css($site_url . drupal_get_path('module', 'unical_styles') .'/style.css', $type);
}
}
/**
* Implements hook_menu().
*/
function unical_client_menu() {
$items = array();
$items['calendar'] = array(
'title' => 'Calendar',
'page callback' => 'unical_client_get',
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/config/services/unical_client'] = array(
'title' => 'UniCal embed settings',
'description' => 'Configuration for UniCal embed',
'page callback' => 'drupal_get_form',
'page arguments' => array('unical_client_form'),
'access arguments' => array('administer blocks'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implements hook_form().
*/
function unical_client_form($form, &$form_state) {
$form['some_text'] = array(
'#markup' => '
<p>This page allows you to define the settings that will control your rendering of the <a href="http://unical.idfive.com">UniCal</a> custom Calendar. Your site administrator should provide you with the site URL of the mothership site, and your particular Site ID, which will do the work of pulling your custom configurations.</p>
<ul>
<li>Your calendar will now be viewable at <a href="/calendar">/calendar</a>.</li>
<li><a href="/admin/config/search/path/add">Add a local path alias</a> to change the default <a href="/calendar">/calendar</a> link, if you choose.</li>
</ul>
<p>Contact your site administrator (who gave you the Site ID) If further customizations are required.</p>
',
);
// General settings.
$form['unical_client_settings'] = array(
'#type' => 'fieldset',
'#title' => 'Settings'
);
// URL of the API.
$form['unical_client_settings']['unical_client_settings_site_url'] = array(
'#type' => 'textfield',
'#title' => t('Site URL'),
'#default_value' => variable_get('unical_client_settings_site_url', ''),
'#size' => 100,
'#maxlength' => 255,
'#description' => t('URL of main UniCal calendar website'),
'#required' => TRUE
);
// Site ID.
$form['unical_client_settings']['unical_client_settings_site_id'] = array(
'#type' => 'textfield',
'#title' => t('Site ID'),
'#default_value' => variable_get('unical_client_settings_site_id', ''),
'#size' => 5,
'#maxlength' => 10,
'#description' => t('ID of the site node'),
'#required' => TRUE
);
// addevent.com ID
$form['unical_client_settings']['unical_client_settings_addevent_id'] = array(
'#type' => 'textfield',
'#title' => t('addevent.com ID'),
'#default_value' => variable_get('unical_client_settings_addevent_id', ''),
'#size' => 50,
'#maxlength' => 100,
'#description' => t('ID for paid addevent.com plans')
);
// Style settings.
$form['unical_client_style_settings'] = array(
'#type' => 'fieldset',
'#title' => 'Styles',
);
// Add checkbox for using stock UniCal styles
$form['unical_client_style_settings']['unical_client_settings_use_stock'] = array(
'#type' => 'checkbox',
'#title' => t('Use Stock CSS'),
'#default_value' => variable_get('unical_client_settings_use_stock', 1),
'#description' => t('Use the stock UniCal calendar style. Leave this checked unless you know what you are doing.'),
);
// Add checkbox for using custom UniCal styles
$form['unical_client_style_settings']['unical_client_settings_use_custom'] = array(
'#type' => 'checkbox',
'#title' => t('Use Custom CSS'),
'#default_value' => variable_get('unical_client_settings_use_custom', 1),
'#description' => t('Use a custom UniCal calendar style, served from SITE ID/sites/all/modules/unical_styles/style.css'),
);
return system_settings_form($form);
}
/**
* Function for above hook_menu().
*/
function unical_client_theme() {
return array(
'unical_client_calendar' => array(
'template' => 'calendar',
),
);
}
/**
* Function for above hook_menu().
*/
function unical_client_get() {
// Add base href, so angular can run in html5 mode.
if (!path_is_admin(current_path())) {
if(drupal_is_front_page()) {
$baseUrl = base_path();
} else {
$baseUrl = base_path() . drupal_get_path_alias(current_path()) . '/';
//Replacement patterns
$patterns = array();
$patterns[0] = '/event\/([0-9]+)\/([a-z0-9-]+)*\/?/';
$patterns[1] = '/submit-event\/?/';
//Regular expression to remove any event URL params
$baseUrl = preg_replace($patterns, '', $baseUrl);
}
$meta_fragment = array(
'#type' => 'html_tag',
'#tag' => 'base',
'#attributes' => array(
'href' => $baseUrl
)
);
// Add header meta tag for IE to head
drupal_add_html_head($meta_fragment, 'meta_fragment');
}
// Load the template.
return theme('unical_client_calendar');
}