function _linkchecker_parse_fields in Link checker 7
Parse the urls from entity.
This function parse all fields from the entity and returns an array of filtered field items.
Parameters
string $entity_type: The type of entity; e.g., 'node', 'comment'.
string $bundle_name: The name of the bundle aka node type, e.g., 'article', 'page'.
object $entity: The entity to parse, a $node or a $comment object.
bool $return_field_names: If set to TRUE, the returned array will contain the content as keys, and each element will be an array containing all field names in which the content is found. Otherwise, a simple array with content will be returned.
Return value
array Array of field items with filters applied.
2 calls to _linkchecker_parse_fields()
- _linkchecker_add_comment_links in ./
linkchecker.module - Add comment links to database.
- _linkchecker_extract_node_links in ./
linkchecker.module - Extracts links from a node.
File
- ./
linkchecker.module, line 1720 - This module periodically check links in given node types, blocks etc.
Code
function _linkchecker_parse_fields($entity_type, $bundle_name, $entity, $return_field_names = FALSE) {
$text_items = array();
$text_items_by_field = array();
// Create settings for _filter_url() function.
$filter = new stdClass();
$filter->settings['filter_url_length'] = 72;
// Collect the fields from this entity_type and bundle.
foreach (field_info_instances($entity_type, $bundle_name) as $field_name => $instance) {
$field = field_info_field($field_name);
// #1923328: field_name array may be missing in $entity.
$entity_field = isset($entity->{$field['field_name']}) ? $entity->{$field['field_name']} : array();
switch ($field['type']) {
// Core fields.
case 'text_with_summary':
foreach ($entity_field as $language) {
foreach ($language as $item) {
$item += array(
'format' => NULL,
'summary' => '',
'value' => '',
);
$text_items[] = $text_items_by_field[$field['field_name']][] = _linkchecker_check_markup($item['value'], $item['format'], linkchecker_entity_language($entity_type, $entity), TRUE);
$text_items[] = $text_items_by_field[$field['field_name']][] = _linkchecker_check_markup($item['summary'], $item['format'], linkchecker_entity_language($entity_type, $entity), TRUE);
}
}
break;
// Core fields.
case 'text_long':
case 'text':
foreach ($entity_field as $language) {
foreach ($language as $item) {
$item += array(
'format' => NULL,
'value' => '',
);
$text_items[] = $text_items_by_field[$field['field_name']][] = _linkchecker_check_markup($item['value'], $item['format'], linkchecker_entity_language($entity_type, $entity), TRUE);
}
}
break;
// Link module field, https://drupal.org/project/link.
case 'link_field':
foreach ($entity_field as $language) {
foreach ($language as $item) {
$item += array(
'title' => '',
);
$options = drupal_parse_url(link_cleanup_url($item['url']));
$text_items[] = $text_items_by_field[$field['field_name']][] = l($item['title'], $options['path'], $options);
$text_items[] = $text_items_by_field[$field['field_name']][] = _linkchecker_check_markup($item['title'], NULL, linkchecker_entity_language($entity_type, $entity), TRUE);
}
}
break;
}
}
return $return_field_names ? $text_items_by_field : $text_items;
}