forked from rabisg/Event
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.module
More file actions
170 lines (148 loc) · 5.74 KB
/
Copy pathevent.module
File metadata and controls
170 lines (148 loc) · 5.74 KB
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
<?php
/**
* @file
* Code for the Event feature.
*/
include_once 'event.features.inc';
/**
* Implements hook_theme_registry_alter()
*/
function event_theme_registry_alter(&$theme_registry) {
$mod_path = drupal_get_path('module', 'event') . '/theme';
$theme_registry_copy = $theme_registry; // munge on a copy
_theme_process_registry($theme_registry_copy, 'phptemplate', 'theme_engine', 'pow', $mod_path);
$theme_registry += array_diff_key($theme_registry_copy, $theme_registry);
$hooks = array('node');
foreach ($hooks as $h) {
_event_insert_after_first_element($theme_registry[$h]['theme paths'], $mod_path);
}
}
/**
* Helper function for re-ordering arrays (needed by theme_registry_alter)
*/
function _event_insert_after_first_element(&$a, $element) {
if (is_array($a)) {
$first_element = array_shift($a);
array_unshift($a, $first_element, $element);
}
}
/**
* Implements hook_node_view
* Add Signup link to Teaser if Signup is allowed
* Converts URL in Trac Ticket and Resources into links
* Hides Venue and Time fields if current time is greater than
* the event end time
*/
function event_node_view($node, $view_mode, $langcode) {
if ($node->type != 'event')
return;
//Converts url in Trac Ticket fields into links
if (isset($node->content['field_trac_ticket'][0]['#markup'])) {
$node->content['field_trac_ticket'][0]['#markup'] = make_clickable($node->content['field_trac_ticket'][0]['#markup']);
}
//Converts url in Resources field to links
$i = 0;
while (isset($node->content['field_resources'][$i])) {
$node->content['field_resources'][$i]['#markup'] = make_clickable($node->content['field_resources'][$i]['#markup']);
$i++;
}
//Hides Trac Ticket, Time and Venue fields
$time = strtotime($node->field_start_time['und'][0]['value2']);
if (REQUEST_TIME > $time) {
unset($node->content['field_trac_ticket']);
unset($node->content['field_start_time']);
unset($node->content['field_venue']);
}
//Adds a display_image variable which is the Display Image field
$node->display_image = theme('image', array('path' => $node->field_event_dp['und'][0]['uri'], 'alt' => $node->title, 'title' => 'Event', 'attributes' => array('class' => 'thumb', 'width' => '50px', 'height' => '50px')));
//Adds a signup link on teasers
if($view_mode != 'teaser' || _event_signup_access($node, 'signup') == FALSE)
return;
$node->content['links']['event'] = array(
'#links' => array(
array(
'title' => 'Signup',
'href' => url('node/'. $node->nid, array('absolute' => TRUE, 'fragment' => 'signup')),
),
),
);
}
/**
* Helper function to determine whether
* Signup link should be displayed on this event node
*/
function _event_signup_access($node) {
// If the node isn't signup enabled, immediately return failure.
if (empty($node->signup) || !$node->signup_status) {
return FALSE;
}
// See if this user can signup and if the node has signup output.
return user_access('sign up for content');
}
/*
* Implements hook_contextual_links_view_alter().
* Add contextual links for Twitter hashtags, Trac Ticket etc.
*/
function event_contextual_links_view_alter(&$element, $items) {
// Check if we have a node link to process
if (isset($element['#element']['#node']->nid)) {
$node = $element['#element']['#node'];
// Content Type Event
if ($node->type == 'event') {
$links = &$element['#links'];
if(!empty($node->field_trac_ticket['und'][0]['value'])) {
$links['trac-ticket'] = array(
'title' => t('Trac Ticket'),
'href' => $node->field_trac_ticket['und'][0]['value'],
);
}
//Add the Twitter Trends Link if there is a hashtag associated with this Event
if (isset($node->field_hashtag['und'][0]['value']) && strlen($node->field_hashtag['und'][0]['value']) > 1 && $node->field_hashtag['und'][0]['value'][0] == '#') {
$links['twitter-trend'] = array(
'title' => t('Twitter Trend'),
'href' => url('http://twitter.com/#!/search?q=%23' . substr($node->field_hashtag['und'][0]['value'], 1)),
);
}
}
}
}
function _make_url_clickable_cb($matches) {
$ret = '';
$url = $matches[2];
if ( empty($url) )
return $matches[0];
// removed trailing [.,;:] from URL
if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {
$ret = substr($url, -1);
$url = substr($url, 0, strlen($url)-1);
}
return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $ret;
}
function _make_web_ftp_clickable_cb($matches) {
$ret = '';
$dest = $matches[2];
$dest = 'http://' . $dest;
if ( empty($dest) )
return $matches[0];
// removed trailing [,;:] from URL
if ( in_array(substr($dest, -1), array('.', ',', ';', ':')) === true ) {
$ret = substr($dest, -1);
$dest = substr($dest, 0, strlen($dest)-1);
}
return $matches[1] . "<a href=\"$dest\" rel=\"nofollow\">$dest</a>" . $ret;
}
function _make_email_clickable_cb($matches) {
$email = $matches[2] . '@' . $matches[3];
return $matches[1] . "<a href=\"mailto:$email\">$email</a>";
}
function make_clickable($ret) {
$ret = ' ' . $ret;
// in testing, using arrays here was found to be faster
$ret = preg_replace_callback('#([\s>])([\w]+?://[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_url_clickable_cb', $ret);
$ret = preg_replace_callback('#([\s>])((www|ftp)\.[\w\\x80-\\xff\#$%&~/.\-;:=,?@\[\]+]*)#is', '_make_web_ftp_clickable_cb', $ret);
$ret = preg_replace_callback('#([\s>])([.0-9a-z_+-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,})#i', '_make_email_clickable_cb', $ret);
// this one is not in an array because we need it to run last, for cleanup of accidental links within links
$ret = preg_replace("#(<a( [^>]+?>|>))<a [^>]+?>([^>]+?)</a></a>#i", "$1$3</a>", $ret);
$ret = trim($ret);
return $ret;
}