-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
232 lines (192 loc) · 7.07 KB
/
functions.php
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
<?php
function filter_contribution_description($components) {
$components['label'] = "Description";
$components['description'] = "Please include as much information as you can. For example: What was happening at this moment? Who is involved? What else do we need to know about this moment in time?";
return $components;
}
function filter_contribution_title($components) {
$components['description'] = "For example, “Police in downtown Charlottesville” or “What I witnessed from the Rotunda.”";
return $components;
}
function filter_contribution_text($components) {
$components['label'] = "Tell Your Story";
$components['description'] = "";
return $components;
}
function filter_contribution_date($components) {
$components['description'] = "When did this occur?";
return $components;
}
function filter_contribution_coverage($components) {
$components['description'] = "Where did this occur?";
return $components;
}
function filter_contribution_contributor($components) {
$components['description'] = '';
return $components;
}
function filter_contribution_abstract($components) {
$components['label'] = "What else do we need to know about this? ";
$components['description'] = "";
return $components;
}
function filter_contribution_creator($components) {
$components['label'] = "Your name (Required)";
$components['description'] = "";
return $components;
}
/**
* Checks if current view is the Contribution Form.
*/
function is_contribution_form() {
$request = Zend_Controller_Front::getInstance()->getRequest();
$module = $request->getModuleName();
$action = $request->getActionName();
if ($module == 'contribution' && $action == 'contribute') {
return true;
}
return false;
}
function filter_for_anonymity($text, $args) {
$record = $args['record'];
$contributedItem = get_db()->getTable('ContributionContributedItem')->findByItem($record);
if ($contributedItem->anonymous != 0) {
$text = 'Anonymous';
}
return $text;
}
/**
* Replicates Omeka's default item_citation output, but checks
* if the item was submitted under the condition of anonymity.
* If so, the creator name is replaced with 'Anonymous'. If not,
* the DC:Creator name is used instead of the submitter's
* username.
*/
function filter_item_citation($citation, $args) {
$citation = '';
$item = $args['item'];
$contribItem = get_db()->getTable('ContributionContributedItem')->findByItem($item);
if ($contribItem->anonymous) {
$creator = 'Anonymous';
} else {
$creators = metadata($item, array('Dublin Core', 'Creator'), array('all' => true));
// Strip formatting and remove empty creator elements.
$creators = array_filter(array_map('strip_formatting', $creators));
if ($creators) {
switch (count($creators)) {
case 1:
$creator = $creators[0];
break;
case 2:
/// Chicago-style item citation: two authors
$creator = __('%1$s and %2$s', $creators[0], $creators[1]);
break;
case 3:
/// Chicago-style item citation: three authors
$creator = __('%1$s, %2$s, and %3$s', $creators[0], $creators[1], $creators[2]);
break;
default:
/// Chicago-style item citation: more than three authors
$creator = __('%s et al.', $creators[0]);
}
}
}
$citation .= "$creator, ";
if ($title = metadata($item, 'display_title')) {
$citation .= "“$title,” ";
}
if ($siteTitle = option('site_title')) {
$citation .= "<em>$siteTitle</em>, ";
}
$accessed = format_date(time(), Zend_Date::DATE_LONG);
$url = '<span class="citation-url">'.html_escape(record_url($item, null, true)).'</span>';
/// Chicago-style item citation: access date and URL
$citation .= __('accessed %1$s, %2$s.', $accessed, $url);
return $citation;
}
// adjust brightness
// Adapted from a solution by Torkil Johnsen.
// @param string $color
// @param int $steps
// @link http://stackoverflow.com/questions/3512311/how-to-generate-lighter-darker-color-with-php
function adjustBrightness($hex, $steps) {
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max(-255, min(255, $steps));
// Normalize into a six character long hex string
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3) {
$hex = str_repeat(substr($hex,0,1), 2).str_repeat(substr($hex,1,1), 2).str_repeat(substr($hex,2,1), 2);
}
// Split into three parts: R, G and B
$color_parts = str_split($hex, 2);
$return = '#';
foreach ($color_parts as $color) {
$color = hexdec($color); // Convert to decimal
$color = max(0,min(255,$color + $steps)); // Adjust color
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
}
return $return;
}
/* Convert hexdec color string to rgb(a) string */
function hex2rgba($color, $opacity = false) {
$default = 'rgb(0,0,0)';
//Return default if no color provided
if(empty($color))
return $default;
//Sanitize $color if "#" is provided
if ($color[0] == '#' ) {
$color = substr( $color, 1 );
}
//Check if color has 6 or 3 characters and get values
if (strlen($color) == 6) {
$hex = array( $color[0] . $color[1], $color[2] . $color[3], $color[4] . $color[5] );
} elseif ( strlen( $color ) == 3 ) {
$hex = array( $color[0] . $color[0], $color[1] . $color[1], $color[2] . $color[2] );
} else {
return $default;
}
//Convert hexadec to rgb
$rgb = array_map('hexdec', $hex);
//Check if opacity is set(rgba or rgb)
if($opacity){
if(abs($opacity) > 1)
$opacity = 1.0;
$output = 'rgba('.implode(",",$rgb).','.$opacity.')';
} else {
$output = 'rgb('.implode(",",$rgb).')';
}
//Return rgb(a) color string
return $output;
}
/**
* Get the theme's logo image tag.
*
* @package Omeka\Function\View\Head
* @uses get_theme_option()
* @return string|null
*/
function cville_theme_logo()
{
$logo = get_theme_option('Logo');
if ($logo) {
$storage = Zend_Registry::get('storage');
$uri = $storage->getUri($storage->getPathByType($logo, 'theme_uploads'));
return '<img src="' . $uri . '" alt="' . get_theme_option('logo_alt') . '" class="logo" />';
}
}
/**
* Get the theme's shortcut icon tag.
*
* @package Omeka\Function\View\Head
* @uses get_theme_option()
* @return string|null
*/
function cville_theme_icon()
{
$icon = get_theme_option('shortcut_icon');
if ($icon) {
$storage = Zend_Registry::get('storage');
$uri = $storage->getUri($storage->getPathByType($icon, 'theme_uploads'));
return '<link rel="shortcut icon" sizes="32x32" href="' . $uri . '" />';
}
}