-
Notifications
You must be signed in to change notification settings - Fork 1
/
IEEEStyleForBibtexbrowser.php
319 lines (284 loc) · 11 KB
/
IEEEStyleForBibtexbrowser.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
// This is version 2013-01-22
/*
This file is part of IEEEStyleForBibtexbrowser.
IEEEStyleForBibtexbrowser is free software: you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
IEEEStyleForBibtexbrowser is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with IEEEStyleForBibtexbrowser. If not, see <http://www.gnu.org/licenses/>.
You can always find the latest version at https://github.com/KaiBi/IEEEStyleForBibtexbrowser
*/
/* See the included README.md for documentation */
function IEEEStyle(&$bibentry) {
if (!defined('IEEEStyle_SkipVersionCheck'))
define('IEEEStyle_SkipVersionCheck', false);
if (!defined('IEEEStyle_FullAuthorList'))
define('IEEEStyle_FullAuthorList', false);
if (!defined('IEEEStyle_FullEditorList'))
define('IEEEStyle_FullEditorList', false);
// check for supported bibtexbrowser-version
// if (BIBTEXBROWSER !== 'v20121205' and IEEEStyleSkipVersionCheck !== true) {
// die('This version of IEEEStyleForBibtexbrowser has not been tested with bibtexbrowser ' . BIBTEXBROWSER . '. You may add the following line to your bibtexbrowser-configuration to ignore this warning: ' . "\n" . '@define(\'IEEEStyle_SkipVersionCheck\', true);');
// }
/*
IEEEStyleForBibtexbrowser uses $entryType for the bibtex entry type and $type for
the field within an entry.
*/
$entryType = strtolower($bibentry->getField(Q_INNER_TYPE));
$type = false;
if ($bibentry->hasField(Q_TYPE))
$type = $bibentry->getField(Q_INNER_TYPE);
$author = false;
if ($bibentry->hasField(Q_AUTHOR)) {
// abbreviate author names
$authors = $bibentry->getRawAuthors();
for ($i = 0; $i < count($authors); $i++) {
$a = $authors[$i];
// check author format; "Firstname Lastname" or "Lastname, Firstname"
if (strpos($a, ',') === false) {
$parts = explode(' ', $a);
$lastname = trim(array_pop($parts));
$firstnames = $parts;
} else {
$parts = explode(',', $a);
$lastname = trim($parts[0]);
$firstnames = explode(' ', trim($parts[1]));
}
$name = array();
foreach ($firstnames as $fn)
$name[] = substr(trim($fn), 0, 1) . '.';
// do not forget the author links if available
if (BIBTEXBROWSER_AUTHOR_LINKS=='homepage') {
$authors[$i] = $bibentry->addHomepageLink(implode(' ', $name) . ' ' . $lastname);
}
if (BIBTEXBROWSER_AUTHOR_LINKS=='resultpage') {
$authors[$i] = $bibentry->addAuthorPageLink(implode(' ', $name) . ' ' . $lastname);
}
}
// special formatting depending on the number of contributing authors
if (IEEEStyle_FullAuthorList === true and count($authors) > 3)
$author = implode(', ', $authors);
else
if (count($authors) > 3)
$author = $authors[0] . ' et al.';
else if (count($authors) > 2)
$author = $authors[0] . ', ' . $authors[1] . ' and ' . $authors[2];
else if (count($authors) > 1)
$author = $authors[0] . ', ' . $authors[1];
else
$author = $authors[0];
}
$title = false;
if ($bibentry->hasField(TITLE)) {
$title = $bibentry->getTitle();
$title = '<span class="bibtitle">' . $title . '</span>';
}
if ($title && $bibentry->hasField('url'))
$title = '<a class="bibtitlelink"' . (BIBTEXBROWSER_BIB_IN_NEW_WINDOW? ' target="_blank" ' : '') . ' href="' . $bibentry->getField("url") . '">' . $title . '</a>';
$publisher = false;
if ($bibentry->hasField('publisher'))
// we do not want the 'special' logic from the 'getPublisher'-method
$publisher = $bibentry->getField('publisher');
$address = false;
if ($bibentry->hasField('address'))
$address = $bibentry->getField('address');
$editor = false;
if ($bibentry->hasField(EDITOR)) {
$editors = $bibentry->getEditors();
for ($i = 0; $i < count($editors); $i++) {
$a = $editors[$i];
// check author format; "Firstname Lastname" or "Lastname, Firstname"
if (strpos($a, ',') === false) {
$parts = explode(' ', $a);
$lastname = trim(array_pop($parts));
$firstnames = $parts;
} else {
$parts = explode(',', $a);
$lastname = trim($parts[0]);
$firstnames = explode(' ', trim($parts[1]));
}
$name = array();
foreach ($firstnames as $fn)
$name[] = substr(trim($fn), 0, 1) . '.';
// do not forget the author links if available
if (BIBTEXBROWSER_AUTHOR_LINKS=='homepage') {
$editors[$i] = $bibentry->addHomepageLink(implode(' ', $name) . ' ' . $lastname);
}
if (BIBTEXBROWSER_AUTHOR_LINKS=='resultpage') {
$editors[$i] = $bibentry->addAuthorPageLink(implode(' ', $name) . ' ' . $lastname);
}
}
// special formatting depending on the number of authors
if (IEEEStyle_FullEditorList === true and count($editors) > 3)
$editor = implode(', ', $editors) . ', Eds.';
else
if (count($editors) > 3)
$editor = $editors[0] . ' et al., Eds.';
else if (count($editors) > 1)
$editor = implode(', ', $editors) . ', Eds.';
else
$editor = $editors[0] . ', Ed.';
}
$booktitle = false;
if ($bibentry->hasField(BOOKTITLE))
$booktitle = $bibentry->getField(BOOKTITLE);
$school = false;
if ($bibentry->hasField(SCHOOL))
$school = $bibentry->getField(SCHOOL);
$year = false;
if ($bibentry->hasField(YEAR))
$year = $bibentry->getField(YEAR);
$edition = false;
$editionShort = false;
if ($bibentry->hasField('edition')) {
$edition = $bibentry->getField('edition');
// extend this if you need hihgher edition numbers
$editionToShort = array (
'first' => '1st',
'second' => '2nd',
'third' => '3rd',
'fourth' => '4th',
'fifth' => '5th'
);
// convert textual edition ordinals to numeric
if (array_key_exists(strtolower($edition), $editionToShort))
$editionShort = $editionToShort[strtolower($edition)];
}
$comment = false;
if ($bibentry->hasField('comment'))
$comment = $bibentry->getField('comment');
$pages = false;
if ($bibentry->hasField('pages'))
$pages = 'pp. ' . str_replace('--', '-', $bibentry->getField('pages'));
$journal = false;
if ($bibentry->hasField('journal'))
$journal = $bibentry->getField('journal');
$volume = false;
if ($bibentry->hasField('volume'))
$volume = $bibentry->getField('volume');
$number = false;
if ($bibentry->hasField('number'))
$number = $bibentry->getField('number');
$month = false;
if ($bibentry->hasField('month'))
$month = $bibentry->getField('month');
$chapter = false;
if ($bibentry->hasField('chapter'))
$chapter = 'ch. ' . $bibentry->getField('chapter');
$institution = false;
if ($bibentry->hasField('institution'))
$institution = $bibentry->getField('institution');
$entry = array();
$result = '';
// redundancies are left on purpose to improve changeability
switch ($entryType) {
case 'article':
if ($author) $entry[] = $author;
if ($title) $entry[] = '"' . $title . '"';
if ($journal) $entry[] = '<em>' . $journal . '</em>';
if ($volume) $entry[] = 'vol. ' . $volume;
if ($number) $entry[] = 'no. ' . $number;
if ($month && $year) $entry[] = $month . ' ' . $year;
else if ($year) $entry[] = $year;
if ($pages) $entry[] = $pages;
break;
case 'book':
if ($author) $entry[] = $author;
if ($title) $entry[] = '<em>' . $title . '</em>';
if ($address && $publisher) $publisher = $address . ': ' . $publisher;
if ($edition && $publisher) $entry[] = ($editionShort? $editionShort : $edition) . ' ed. ' . $publisher;
else if ($publisher) $entry[] = $publisher;
if ($year) $entry[] = $year;
break;
case 'booklet':
break;
case 'conference':
break;
case 'inbook':
if ($author) $entry[] = $author;
if ($title) $entry[] = '<em>' . $title . '</em>';
if ($address && $publisher) $publisher = $address . ': ' . $publisher;
if ($edition && $publisher) $entry[] = ($editionShort? $editionShort : $edition) . ' ed. ' . $publisher;
else if ($publisher) $entry[] = $publisher;
if ($year) $entry[] = $year;
if ($chapter) $entry[] = 'ch. ' . $chapter;
if ($pages) $entry[] = $pages;
break;
case 'incollection':
if ($author) $entry[] = $author;
if ($title) $entry[] = '"' . $title . '"';
if ($booktitle) $entry[] = 'in <em>' . $booktitle . '</em>';
if ($edition && $editor) $entry[] = ($editionShort? $editionShort : $edition) . ' ed. ' . $editor;
else if ($editor) $entry[] = $editor;
if ($address && $publisher) $entry[] = $address . ': ' . $publisher;
else if ($publisher) $entry[] = $publisher;
if ($year) $entry[] = $year;
if ($pages) $entry[] = $pages;
break;
case 'inproceedings':
if ($author) $entry[] = $author;
if ($title) $entry[] = '"' . $title . '"';
if ($booktitle) $entry[] = 'in <em>' . $booktitle . '</em>';
if ($editor) $entry[] = $editor;
if ($address && $publisher) $entry[] = $address . ': ' . $publisher;
else if ($publisher) $entry[] = $publisher;
// the year is omitted if it is already part of the booktitle
if ($year && !preg_match('/' . $year . '|' . '\'' . substr($year, 2) . '/', $booktitle)) $entry[] = $year;
if ($pages) $entry[] = $pages;
break;
case 'manual':
break;
case 'mastersthesis':
if ($author) $entry[] = $author;
if ($title) $entry[] = '"' . $title . '"';
if ($type) $entry[] = $type;
else $entry[] = 'Master\'s thesis';
if ($school) $entry[] = $school;
if ($address) $entry[] = $address;
if ($year) $entry[] = $year;
break;
case 'misc':
break;
case 'phdthesis':
if ($author) $entry[] = $author;
if ($title) $entry[] = '"' . $title . '"';
if ($type) $entry[] = $type;
else $entry[] = 'Ph.D. dissertation';
if ($school) $entry[] = $school;
if ($address) $entry[] = $address;
if ($year) $entry[] = $year;
break;
case 'proceedings':
if ($editor) $entry[] = $editor;
if ($title) $entry[] = '<em>' . $title . '</em>';
if ($address && $publisher) $publisher = $address . ': ' . $publisher;
else if ($publisher) $entry[] = $publisher;
// the year is omitted if it is already part of the title
if ($year && !preg_match('/' . $year . '|' . '\'' . substr($year, 2) . '/', $title)) $entry[] = $year;
break;
case 'techreport':
if ($author) $entry[] = $author;
if ($title) $entry[] = '"' . $title . '"';
if ($address && $institution) $entry[] = $institution . ': ' . $address;
else if ($institution) $entry[] = $institution;
if ($number) $entry[] = 'Rep. ' . $number;
// the year is omitted if it is already part of the report number
if ($year && (!$number || !preg_match('/' . $year . '|' . '\'' . substr($year, 2) . '/', $number))) $entry[] = $year;
break;
case 'unpublished':
break;
default:
break;
}
$result = implode(', ', $entry);
if ($comment) $result .= ' (' . $comment .')';
$result .= '.';
return $result . "\n" . $bibentry->toCoins();
}
?>