Revision e90899ac
Added by Andreas Kohlbecker about 8 years ago
modules/cdm_dataportal/cdm_api/cdm_api.module | ||
---|---|---|
163 | 163 |
); |
164 | 164 |
} |
165 | 165 |
|
166 |
// ===================== Tagged Text functions ================== // |
|
167 |
|
|
166 | 168 |
/** |
167 | 169 |
* Converts an array of TaggedText items into corresponding html tags. |
168 | 170 |
* |
... | ... | |
180 | 182 |
* @return string |
181 | 183 |
* A string with HTML. |
182 | 184 |
*/ |
183 |
function cdm_taggedtext2html(array $taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()) {
|
|
185 |
function cdm_tagged_text_to_markup(array $taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()) {
|
|
184 | 186 |
$out = ''; |
185 | 187 |
$i = 0; |
186 | 188 |
foreach ($taggedtxt as $tt) { |
... | ... | |
194 | 196 |
/** |
195 | 197 |
* Finds the text tagged with $tag_type in an array of taggedText instances. |
196 | 198 |
* |
197 |
* Comment @WA: this function seems unused.
|
|
199 |
* Note: This function is currently unused.
|
|
198 | 200 |
* |
199 | 201 |
* @param array $taggedtxt |
200 | 202 |
* Array with text items. |
... | ... | |
204 | 206 |
* @return array |
205 | 207 |
* An array with the texts mapped by $tag_type. |
206 | 208 |
*/ |
207 |
function cdm_taggedtext_values(array $taggedtxt, $tag_type) { |
|
209 |
function cdm_tagged_text_values(array $taggedtxt, $tag_type) {
|
|
208 | 210 |
$tokens = array(); |
209 | 211 |
if (!empty($taggedtxt)) { |
210 | 212 |
foreach ($taggedtxt as $tagtxt) { |
... | ... | |
216 | 218 |
return $tokens; |
217 | 219 |
} |
218 | 220 |
|
221 |
|
|
222 |
/** |
|
223 |
* Preprocess the taggedTitle arrays. |
|
224 |
* |
|
225 |
* Step 1: Turns 'newly' introduces tag types ("hybridSign") |
|
226 |
* into tag type "name" |
|
227 |
* |
|
228 |
* Step 2: Two taggedTexts which have the same type and which have |
|
229 |
* a separator between them are merged together. |
|
230 |
* |
|
231 |
* @param array $taggedTextList |
|
232 |
* An array of TaggedText objects |
|
233 |
*/ |
|
234 |
function normalize_tagged_text(&$taggedTextList) { |
|
235 |
|
|
236 |
if (is_array($taggedTextList)) { |
|
237 |
|
|
238 |
// First pass: rename. |
|
239 |
for ($i = 0; $i < count($taggedTextList); $i++) { |
|
240 |
|
|
241 |
if ($taggedTextList[$i]->type == "hybridSign") { |
|
242 |
$taggedTextList[$i]->type = "name"; |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
// Second pass: resolve separators. |
|
247 |
$taggedNameListNew = array(); |
|
248 |
for ($i = 0; $i < count($taggedTextList); $i++) { |
|
249 |
|
|
250 |
// elements of the same type concatenated by a separator should be merged together |
|
251 |
if (isset($taggedTextList[$i + 2]) && $taggedTextList[$i + 1]->type == "separator" && $taggedTextList[$i]->type == $taggedTextList[$i + 2]->type) { |
|
252 |
$taggedName = clone $taggedTextList[$i]; |
|
253 |
$taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text; |
|
254 |
$taggedNameListNew[] = $taggedName; |
|
255 |
++$i; |
|
256 |
++$i; |
|
257 |
continue; |
|
258 |
} |
|
259 |
// no special handling |
|
260 |
$taggedNameListNew[] = $taggedTextList[$i]; |
|
261 |
|
|
262 |
} |
|
263 |
$taggedTextList = $taggedNameListNew; |
|
264 |
} |
|
265 |
} |
|
266 |
|
|
267 |
function split_secref_from_tagged_text(&$taggedTextList) { |
|
268 |
|
|
269 |
$secref_tt = array(); |
|
270 |
if (is_array($taggedTextList)) { |
|
271 |
for ($i = 0; $i < count($taggedTextList) - 1; $i++) { |
|
272 |
if ($taggedTextList[$i + 1]->type == "secReference" && $taggedTextList[$i]->type == "separator"){ |
|
273 |
$secref_tt[0] = $taggedTextList[$i]; |
|
274 |
$secref_tt[1] = $taggedTextList[$i + 1]; |
|
275 |
unset($taggedTextList[$i]); |
|
276 |
unset($taggedTextList[$i + 1]); |
|
277 |
} |
|
278 |
break; |
|
279 |
} |
|
280 |
} |
|
281 |
return $secref_tt; |
|
282 |
} |
|
283 |
|
|
284 |
|
|
285 |
function split_nomstatus_from_tagged_text(&$taggedTextList) { |
|
286 |
|
|
287 |
$secref_tt = array(); |
|
288 |
if (is_array($taggedTextList)) { |
|
289 |
for ($i = 0; $i < count($taggedTextList) - 1; $i++) { |
|
290 |
if ($taggedTextList[$i]->type == "nomStatus"){ |
|
291 |
unset($taggedTextList[$i]); |
|
292 |
$secref_tt[0] = $taggedTextList[$i]; |
|
293 |
if($taggedTextList[$i +1 ]->type == "postSeparator"){ |
|
294 |
unset($taggedTextList[$i + 1]); |
|
295 |
$secref_tt[1] = $taggedTextList[$i + 1]; |
|
296 |
} |
|
297 |
} |
|
298 |
break; |
|
299 |
} |
|
300 |
} |
|
301 |
return $secref_tt; |
|
302 |
} |
|
303 |
|
|
304 |
function find_tagged_text_elements($taggedTextList, $type){ |
|
305 |
$matching_elements = array(); |
|
306 |
if (is_array($taggedTextList)) { |
|
307 |
for ($i = 0; $i < count($taggedTextList) - 1; $i++) { |
|
308 |
if($taggedTextList[$i]->type == $type){ |
|
309 |
$matching_elements[] = $taggedTextList[$i]; |
|
310 |
} |
|
311 |
} |
|
312 |
} |
|
313 |
return $matching_elements; |
|
314 |
} |
|
315 |
|
|
316 |
// ===================== END of Tagged Text functions ================== // |
|
317 |
|
|
219 | 318 |
/** |
220 | 319 |
* Returns the currently classification tree in use. |
221 | 320 |
*/ |
modules/cdm_dataportal/cdm_dataportal.module | ||
---|---|---|
1873 | 1873 |
} |
1874 | 1874 |
} |
1875 | 1875 |
|
1876 |
/** |
|
1877 |
* Preprocess the taggedTitle arrays. |
|
1878 |
* |
|
1879 |
* Step 1: Turns 'newly' introduces tag types ("hybridSign") |
|
1880 |
* into tag type "name" |
|
1881 |
* |
|
1882 |
* Step 2: Two taggedTexts which have the same type and which have |
|
1883 |
* a separator between them are merged together. |
|
1884 |
* |
|
1885 |
* @param array $taggedTextList |
|
1886 |
* An array of TaggedText objects |
|
1887 |
*/ |
|
1888 |
function normalize_tagged_title(&$taggedTextList) { |
|
1889 |
|
|
1890 |
if (is_array($taggedTextList)) { |
|
1891 | 1876 |
|
1892 |
// First pass: rename. |
|
1893 |
for ($i = 0; $i < count($taggedTextList); $i++) { |
|
1894 |
|
|
1895 |
if ($taggedTextList[$i]->type == "hybridSign") { |
|
1896 |
$taggedTextList[$i]->type = "name"; |
|
1897 |
} |
|
1898 |
} |
|
1899 |
|
|
1900 |
// Second pass: resolve separators. |
|
1901 |
$taggedNameListNew = array(); |
|
1902 |
for ($i = 0; $i < count($taggedTextList); $i++) { |
|
1903 |
|
|
1904 |
if ($i + 1 < count($taggedTextList) && $taggedTextList[$i + 1]->type == "separator") { |
|
1905 |
if ($taggedTextList[$i]->type == $taggedTextList[$i + 2]->type) { |
|
1906 |
$taggedName = clone $taggedTextList[$i]; |
|
1907 |
$taggedName->text = $taggedName->text . $taggedTextList[$i + 1]->text . $taggedTextList[$i + 2]->text; |
|
1908 |
$taggedNameListNew[] = $taggedName; |
|
1909 |
++$i; |
|
1910 |
++$i; |
|
1911 |
} |
|
1912 |
} |
|
1913 |
else { |
|
1914 |
$taggedNameListNew[] = $taggedTextList[$i]; |
|
1915 |
} |
|
1916 |
} |
|
1917 |
$taggedTextList = $taggedNameListNew; |
|
1918 |
} |
|
1919 |
} |
|
1920 |
|
|
1921 |
function split_secref_from_tagged_title(&$taggedTextList) { |
|
1922 |
|
|
1923 |
$secref_tt = array(); |
|
1924 |
if (is_array($taggedTextList)) { |
|
1925 |
for ($i = 0; $i < count($taggedTextList) - 1; $i++) { |
|
1926 |
if ($taggedTextList[$i + 1]->type == "secReference" && $taggedTextList[$i]->type == "separator"){ |
|
1927 |
$secref_tt[0] = $taggedTextList[$i]; |
|
1928 |
$secref_tt[1] = $taggedTextList[$i + 1]; |
|
1929 |
unset($taggedTextList[$i]); |
|
1930 |
unset($taggedTextList[$i + 1]); |
|
1931 |
} |
|
1932 |
} |
|
1933 |
} |
|
1934 |
return $secref_tt; |
|
1935 |
} |
|
1936 | 1877 |
/** |
1937 | 1878 |
* Creates a short taxonname. |
1938 | 1879 |
* |
1939 |
* The short name is created by using the taggename field of
|
|
1880 |
* The short name is created by using the taggedTitle field of
|
|
1940 | 1881 |
* NameSTO or NameTO instances. |
1941 |
* If the taggename if empty the fullname will be returned.
|
|
1882 |
* If the taggedTitle if empty the fullname will be returned.
|
|
1942 | 1883 |
* |
1943 | 1884 |
* @param unknown_type $name |
1944 | 1885 |
* Name or TreeNode. |
... | ... | |
1948 | 1889 |
function cdm_dataportal_shortname_of($name) { |
1949 | 1890 |
$nameStr = ''; |
1950 | 1891 |
|
1951 |
normalize_tagged_title($name->taggedTitle);
|
|
1892 |
normalize_tagged_text($name->taggedTitle);
|
|
1952 | 1893 |
|
1953 | 1894 |
// Get all tagged text tokens of the scientific name. |
1954 | 1895 |
foreach ($name->taggedTitle as $tagtxt) { |
modules/cdm_dataportal/includes/name.inc | ||
---|---|---|
296 | 296 |
} |
297 | 297 |
} |
298 | 298 |
|
299 |
$secref_tagged_text = split_secref_from_tagged_title($taggedTitle); |
|
300 |
normalize_tagged_title($taggedTitle); |
|
299 |
$secref_tagged_text = split_secref_from_tagged_text($taggedTitle); |
|
300 |
$nom_status_tagged_text = split_nomstatus_from_tagged_text($taggedTitle); |
|
301 |
normalize_tagged_text($taggedTitle); |
|
301 | 302 |
|
302 | 303 |
$firstEntryIsValidNamePart = |
303 | 304 |
isset($taggedTitle) |
... | ... | |
337 | 338 |
} |
338 | 339 |
} |
339 | 340 |
$taggedName = $taggedNameNew; |
341 |
unset($taggedNameNew); |
|
340 | 342 |
} |
341 |
$name = '<span class="' . $taxonName->class . '">' . cdm_taggedtext2html($taggedName, 'span', ' ', $skiptags) . '</span>';
|
|
343 |
$name = '<span class="' . $taxonName->class . '">' . cdm_tagged_text_to_markup($taggedName, 'span', ' ', $skiptags) . '</span>';
|
|
342 | 344 |
} |
343 | 345 |
else { |
344 | 346 |
$name = '<span class="' . $taxonName->class . '_titleCache">' . $taxonName->titleCache . '</span>'; |
... | ... | |
414 | 416 |
} |
415 | 417 |
} |
416 | 418 |
|
419 |
// Fill with status. |
|
420 |
$statusHtml = ''; |
|
421 |
if (isset($nom_status_tagged_text[0])) { |
|
422 |
if (array_setr('status', TRUE, $renderTemplate)) { |
|
423 |
array_setr('status', '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text) . '</span>', $renderTemplate); |
|
424 |
} |
|
425 |
} |
|
426 |
|
|
417 | 427 |
if (isset($renderTemplate['secReferencePart'])){ |
418 | 428 |
if(isset($secref_tagged_text[1])){ |
429 |
$post_separator_markup = $is_reference_year ? '.': ''; |
|
430 |
if(isset($nom_status_tagged_text[count($nom_status_tagged_text -1 )]) && $nom_status_tagged_text[count($nom_status_tagged_text -1 )]->type == 'postSeparator'){ |
|
431 |
$post_separator_markup = cdm_tagged_text_to_markup(array($nom_status_tagged_text[count($nom_status_tagged_text -1 )])); |
|
432 |
}; |
|
419 | 433 |
array_setr('secReference', |
420 |
$is_reference_year ? '.': ''
|
|
434 |
$post_separator_markup
|
|
421 | 435 |
. ' <span class="sec_reference">' |
422 | 436 |
. $secref_tagged_text[0]->text . $secref_tagged_text[1]->text |
423 | 437 |
. '</span>', $renderTemplate); |
424 | 438 |
} |
425 | 439 |
} |
426 | 440 |
|
427 |
// Fill with status. |
|
428 |
$statusHtml = ''; |
|
429 |
if (isset($taxonName->status) && is_array($taxonName->status)) { |
|
430 |
if (array_setr('status', TRUE, $renderTemplate)) { |
|
431 |
if (isset($taxonName->status[0])) { |
|
432 |
foreach ($taxonName->status as $status) { |
|
433 |
$statusHtml .= ', ' . $status->type->representation_L10n_abbreviatedLabel; |
|
434 |
} |
|
435 |
} |
|
436 |
array_setr('status', '<span class="nomenclatural_status">' . $statusHtml . '</span>', $renderTemplate); |
|
437 |
} |
|
438 |
} |
|
439 | 441 |
|
440 | 442 |
// Fill with protologues etc... |
441 | 443 |
$descriptionHtml = ''; |
Also available in: Unified diff
implementing separator between nomstatus and sec reference