| 1 |
<?php
|
| 2 |
|
| 3 |
/**
|
| 4 |
* Scan currently defined node types, and their
|
| 5 |
* fields, and update the regexes that will
|
| 6 |
* match requests for image fields. These regexes,
|
| 7 |
* plus the list of imagefields available for each
|
| 8 |
* type, are returned in a structured array that defines
|
| 9 |
* the "domain" over which imagepath will operate. The
|
| 10 |
* domain is also stored in a variable for caching.
|
| 11 |
*/
|
| 12 |
function _imagepath_update_domain() {
|
| 13 |
$domain = array();
|
| 14 |
foreach (content_types() as $type) {
|
| 15 |
$type_added = FALSE;
|
| 16 |
$imagefield_count = 0;
|
| 17 |
foreach ($type['fields'] as $field) {
|
| 18 |
if ($field['type'] == 'image') {
|
| 19 |
$imagefield_count++;
|
| 20 |
if (!$type_added) {
|
| 21 |
$type = $type['type'];
|
| 22 |
}
|
| 23 |
$field_name = substr($field['field_name'], 6);
|
| 24 |
$domain[$type]['fields'][] = $field_name;
|
| 25 |
$type_added = TRUE;
|
| 26 |
}
|
| 27 |
}
|
| 28 |
if ($type_added) {
|
| 29 |
$regex .= '))';
|
| 30 |
// Allow field name to be omitted if type has only one imagefield.
|
| 31 |
if ($imagefield_count == 1) {
|
| 32 |
$regex .= '?';
|
| 33 |
$domain[$type]['default_field'] = $field_name;
|
| 34 |
}
|
| 35 |
}
|
| 36 |
}
|
| 37 |
variable_set('imagepath_domain', $domain);
|
| 38 |
return $domain;
|
| 39 |
}
|