forked from idfive/UniCal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunical.module
193 lines (170 loc) · 6.64 KB
/
unical.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
<?php
/**
* @file
* This file implements various hooks and functions.
*/
/**
* Implements hook_help().
*/
function unical_help($path, $arg) {
switch ($path) {
case 'admin/help#unical':
$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_ctools_plugin_directory().
*/
function unical_ctools_plugin_directory($module, $plugin) {
if ($module == 'restful') {
return 'plugins/' . $plugin;
}
}
/**
* Implements hook_theme().
*/
function unical_theme($existing, $type, $theme, $path) {
return array(
'node__site' => array(
'render element' => 'content',
'base hook' => 'node',
'template' => 'node--site',
'path' => drupal_get_path('module', 'unical') . '/templates/node',
),
);
}
/**
* Implements hook_menu().
*/
function unical_menu() {
$items = array();
$items['node/%node/calendar-site-settings-embed'] = array(
'title' => 'Embed/Install Instructions',
'page callback' => '_unical_client',
'page arguments' => array(1),
'access callback' => '_unical_check_tab_permission',
'access arguments' => array(1),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
return $items;
}
/**
* Function for the hook_menu() above. Create a tab to show embed info/etc.
*/
function _unical_client() {
// Define site URL.
$url = $GLOBALS['base_url'];
// Get nid from url, as we dont have access to $node.
$node_path = explode('/', $_SERVER["REQUEST_URI"]);
$nid = $node_path[2];
$embed_code = htmlspecialchars('<link rel="stylesheet" href="' . $url . '/sites/all/modules/unical/assets/css/styles.css"><link rel="stylesheet" href="' . $url . '/sites/all/modules/unical_styles/style.css"><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css"><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<div ng-app="calendar" class="unical-calendar"><h1>Calendar of Events</h1><div ng-view></div></div><script>var site_url = "' . $url . '/api/";
var site_id =' . $nid . ';</script><script src="' . $url . '/sites/all/modules/unical/app/build/unical.js"></script>');
$embed_text = "
<h1>Embed/Install Instructions</h1>
<p>In addition to the individual site calendars being available on this site, they are also available for embedding either through the unical_client module for drupal sites, or by simply adding the code snippet at the bottom of the page.</p>
<h3>Drupal Module:</h3>
<p>Add the following to the modules settings page:</p>
<ul>
<li><strong>Site URL</strong>: " . $url . "/</li>
<li><strong>Site ID</strong>: " . $nid . "</li>
</ul>
<h3>Manual Embed Code:</h3>
<p>For manual embed, you will need to add code in two places:</p>
<ul>
<li>Add the <base href='/'> tag into the <head> of the document. (needed to let the angular app run in html5mode)</li>
<li>The embed code below where you wish the calendar to appear</li>
</ul>
<p>A NOTE ON SEO: If SEO/sharing is a priority, the .htaccess (or equivelant) will need to be modified on the client site. See help page for the UniCal module for more information/examples.</p>
<p>The following can be embedded on any relevant HTML page, regardless of the CMS/etc. This can be modified and separated into more optimized areas of the site (head/footer/etc) if desired.</p>
<p>The main components needed are:</p>
<ul>
<li>Stock styles.css for the calendar.</li>
<li>Custom style.css for the calendar. (remove this if not using unical_styles module on MASTER)</li>
<li>Font awesome css (4.4)(eliminate if site is already using).</li>
<li>jquery > 1.10.2 (eliminate if site is already using).</li>
<li>Divs that will render the app.</li>
<li>JS variables to tell the calendar which site to use.</li>
<li>The main app JS.</li>
</ul>
<code> " . $embed_code . "</code>";
return $embed_text;
}
/**
* Check whether to display "Settings/Embed" tab.
*/
function _unical_check_tab_permission($node) {
global $user;
if ($node->type == 'site' && in_array('administrator', $user->roles)) {
return TRUE;
}
else {
return FALSE;
}
}
/**
* Expires dates in repeating events, so sort works on next date in series
*
* This work around is needed in order to properly sort events within the api. If
* this is not done, previously occuring events in the series will throw off the
* ordering of events, because it looks at all events in the series, ie, the date
* the first event in the series. Currently, this is set to run on CRON.
*/
function _unical_expire_repeating_events() {
// field_date_value2 is the end date of the event, field_date_rrule indicates if it's a repeater.
$result = db_query(
'UPDATE {field_data_field_date} SET deleted = :deleted WHERE field_date_value2 < :datenow AND field_date_rrule != :rrule', array(
':datenow' => date('Y-m-d H:i:s'),
':rrule' => 'null',
':deleted' => 1
)
);
watchdog('unical', $result->rowCount() . ' previously occurring repeating event dates were set to expired in the database by UniCal.', array(), WATCHDOG_NOTICE);
}
/**
* Implements hook_cron().
*
*/
function unical_cron() {
_unical_expire_repeating_events();
}
/**
* Implements hook_date_combo_validate_date_end_alter().
*
* This hook lets us set a custom end time (23:59:00) rather than the 00:00:00
* stock one that drupal date_all_day module does. See https://www.drupal.org/node/874322
* for more info on current "All Day" date setup stuff.
*/
function unical_date_combo_validate_date_end_alter(&$date, &$form_state, $context) {
// If this is an 'All day' value, set the end time to 11:59.
if (!empty($context['element']['#date_is_all_day'])) {
$date->setTime(23, 59, 0);
}
}