forked from ding2/ting_relation
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathting_relation.theme.inc
More file actions
219 lines (187 loc) · 5.92 KB
/
ting_relation.theme.inc
File metadata and controls
219 lines (187 loc) · 5.92 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
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
<?php
/**
* @file
* Theming functions for ting_relation.
*/
/**
* Preprocess variables for ting_relation.tpl.php.
*/
function template_preprocess_ting_relation(&$variables) {
$all_relations = $variables['elements']['#relations'];
foreach( $all_relations as $ns => $relations ) {
switch( $ns ) {
case 'dbcaddi:hasReview' :
$variables['content'][$ns] = ting_relation_reviews( $relations );
break;
case 'dbcaddi:hasSubjectDescription':
$variables['content'][$ns] = ting_relation_subjects( $relations );
break;
case 'dbcaddi:hasCreatorDescription':
$variables['content'][$ns] = ting_relation_creator_description( $relations );
break;
case 'dbcaddi:hasOnlineAccess':
$cont = ting_relation_online( $relations );
if( !empty($cont) ) {
$variables['content'][$ns] = $cont;
}
break;
default:
break;
}
}
}
/**
* two variants(sofar) Ebrary and filmstriben
*/
function ting_relation_online( $relations ) {
$ret = array();
foreach( $relations as $relation ) {
if( $relation['#ac_source'] == 'Ebrary' ) {
$ret[] = ting_relation_online_ebrary( $relation );
}
elseif( $relation['#ac_source'] == 'Filmstriben (fjernlån)' ) {
$ret[] = ting_relation_online_filmstriben( $relation );
}
}
return $ret;
}
/**
* a variant(Ebrary) of 'hasOnlineAccess'
*/
function ting_relation_online_ebrary( $relation ){
$ebrary_url = variable_get('ting_ebrary_url');
if( !isset($ebrary_url) ) {
return;
}
$rel = $relation['#relation'];
// simply set a button
$url = str_replace('[URL]',$ebrary_url,$rel->uri);
$content['online_url'] = array('#markup' => l($relation['#ac_source'], $url, array('attributes' => array('target'=>'_blank'))));
return $content;
}
/**
* a variant(filmstriben) of 'hasOnlineAccess'
*/
function ting_relation_online_filmstriben( $relation ) {
$rel = $relation['#relation'];
$content['type'] = $relation['#title'];
// simply set a button
$url = $rel->uri;
$content['online_url'] = array('#markup' => l($relation['#ac_source'], $url, array('attributes' => array('target'=>'_blank'))));
return $content;
}
function ting_relation_creator_description( $relations ) {
foreach( $relations as $relation ) {
$content = array();
$ting = $relation['#object'];
$rel = $relation['#relation'];
$content['type'] = $relation['#title'];
$content['title'] = $rel->object->title;
if ( $ting->creators ) {
$variables['content']['byline'] = ting_relation_array2names($ting->creators);
}
$content['abstract'] = filter_xss_admin($ting->abstract);
// TODO online_url
if( $url = $rel->object->online_url ) {
$content['online_url'] = array('#markup' => l($rel->object->ac_source, $url, array('attributes' => array('target'=>'_blank'))));
}
$ret[] = $content;
}
return $ret;
}
function ting_relation_subjects( $relations ) {
foreach( $relations as $relation ) {
$content = array();
$ting = $relation['#object'];
$rel = $relation['#relation'];
$content['type'] = $relation['#title'];
$content['title'] = $rel->object->title;
if( $ting->creators ) {
$content['byline'] = t('by @author', array('@author' => ting_relation_array2names($ting->creators)));
}
$content['abstract'] = filter_xss_admin($ting->abstract);
$content['text'] = filter_xss_admin($ting->description);
if( $url = $rel->object->online_url ) {
$content['online_url'] = array('#markup' => l($rel->object->ac_source, $url, array('attributes' => array('target'=>'_blank'))));
}
$ret[] = $content;
}
return $ret;
}
/**
* two variants sofar - review(ac:source=Anmeldelser) and all the others (sofar only ac:source=bibliotekets materialer)
*/
function ting_relation_reviews( $relations ) {
foreach( $relations as $relation ) {
$ac_source = $relation['#relation']->object->ac_source;
if( $ac_source == 'Anmeldelser' ) {
$ret[] = ting_relation_review_other( $relation );
}
else {
$ret[] = ting_relation_review( $relation );
}
}
return $ret;
}
/**
* a variant of a review (ac:source = 'bibliotekets materialer'
*/
function ting_relation_review_other( $relation ) {
$ting = $relation['#object'];
$rel = $relation['#relation'];
//type title
$content['type'] = $relation['#title'];
//title
$content['title'] = $rel->object->title;
//creators
if ($names = ting_relation_array2names($rel->object->creators)) {
$content['byline'] = t('by @author', array('@author' => $names));
}
//ispartof
if ($partOf = ting_relation_array2names($rel->object->isPartOf)) {
$extent = $rel->object->extent;
$content['isPartOf'] = filter_xss_admin($partOf . ', ' . $extent);
}
// TODO online_url
if( $url = $rel->object->online_url ) {
$content['online_url'] = array('#markup' => l($rel->object->ac_source, $url, array('attributes' => array('target'=>'_blank'))));
}
return $content;
}
/**
* a variant of a review (ac:source = 'Anmeldelser'
*/
function ting_relation_review( $relation ) {
$ting = $relation['#object'];
$rel = $relation['#relation'];
//type title ; generel
$content['type'] = $relation['#title'];
//title ; generel
$content['title'] = $rel->object->title;
//year
$content['year'] = $rel->object->date;
//creator
$content['creator'] = ting_relation_array2names($ting->creators);
//text
$content['text'] = isset($ting->reply->record['dc:description'][''][0]) ? $ting->reply->record['dc:description'][''][0] : FALSE;
if( $url = $rel->object->online_url ) {
$content['online_url'] = array('#markup' => l($rel->object->ac_source, $url, array('attributes' => array('target'=>'_blank'))));
}
return $content;
}
/**
* helper function
*/
function ting_relation_array2names($array) {
if ( !isset($array) || empty($array)) {
return false;
}
$ret = '';
foreach($array as $key => $name) {
if (strlen($ret) > 0) {
$ret .= ', ';
}
$ret .= $name;
}
return $ret;
}