View source
<?php
function views_atom_views_api() {
return array(
'api' => 2.0,
'path' => drupal_get_path('module', 'views_atom') . '/views',
'template path' => drupal_get_path('module', 'views_atom') . '/theme',
);
}
function views_atom_theme() {
return array(
'views_atom_fields_item' => array(
'arguments' => array(
'content' => '',
'view' => NULL,
'item' => NULL,
),
'file' => 'views_atom.theme.inc',
'path' => drupal_get_path('module', 'views_atom') . '/theme',
'template' => 'views-atom-fields-item',
),
'views_rss_feed_icon' => array(
'arguments' => array(
'url',
'title',
'icon',
),
'file' => 'views_atom.theme.inc',
),
);
}
function views_atom_get_feed_displays() {
static $used_views = array();
if (empty($used_views)) {
views_include('cache');
$cache = views_cache_get("views_atom:feeds");
if (isset($cache->data)) {
$used_views = $cache->data;
}
else {
$views = views_get_all_views();
foreach ($views as $view) {
foreach ($view->display as $display_id => $display) {
if ($display->display_plugin == 'feed') {
$title = $view
->get_title();
if (!$title) {
$title = $view->name;
}
$used_views[] = array(
'name' => $view->name,
'display' => $display_id,
'title' => $title,
'display_title' => $display->display_title,
);
}
}
$view
->destroy();
}
views_cache_set("views_atom:feeds", $used_views);
}
}
return $used_views;
}
function views_atom_guid($entity_type, $entity_id, $options = array()) {
$guid = url("{$entity_type}/{$entity_id}", array(
'absolute' => TRUE,
'alias' => TRUE,
'purl' => array(
'disabled' => TRUE,
),
'language' => '',
));
if (!empty($options['use_existing_from_feed']) && $entity_type == 'node' && module_exists('feeds')) {
$temp_guid = db_result(db_query("SELECT guid FROM {feeds_node_item} WHERE nid = '%s'", $entity_id));
if ($temp_guid) {
$guid = $temp_guid;
}
}
return $guid;
}
function views_atom_sanitize($string) {
if (is_string($string)) {
module_load_include('inc', 'views_atom', 'misc/html_entities');
$replacements = views_atom_html_entities_to_numeric();
$search = array_keys($replacements);
$replace = array_values($replacements);
$string = str_replace($search, $replace, $string);
}
return $string;
}
function content_views_atom_render($node, $entity_xml) {
$result = db_query("SELECT field_name, type FROM {content_node_field}");
while ($record = db_fetch_object($result)) {
if (!empty($node->{$record->field_name})) {
$field = array_filter($node->{$record->field_name});
$field_xml = $entity_xml
->addChild('field');
$field_xml
->addAttribute('type', $record->type);
$field_xml
->addAttribute('name', $record->field_name);
foreach ($field as $instance) {
$field_instance_xml = $field_xml
->addChild('field-instance');
foreach ($instance as $column => $value) {
$serialize = FALSE;
if (is_array($value)) {
$value = serialize($value);
$serialize = TRUE;
}
$element_xml = $field_instance_xml
->addChild('column', views_atom_sanitize($value));
$element_xml
->addAttribute('name', $column);
if (!empty($serialize)) {
$element_xml
->addAttribute('serialize', $serialize);
}
}
}
module_invoke_all('views_atom_render_field', $field_xml, $field, $record->type);
}
}
}
function filefield_views_atom_render_field(SimpleXMLElement $field_xml, $field, $field_type) {
if ($field_type == 'filefield') {
$instances = $field_xml->{'field-instance'};
foreach ($field as $i => $instance) {
$url = file_create_url($instance['filepath']);
$new_column = $instances[$i]
->addChild('column', $url);
$new_column
->addAttribute('name', 'full_url');
}
}
}
function taxonomy_views_atom_render($node, $entity_xml) {
$taxonomy_xml = $entity_xml
->addChild('taxonomy');
foreach ($node->taxonomy as $tid => $term) {
global $base_url;
$term_path = url(taxonomy_term_path($term), array(
'absolute' => TRUE,
'alias' => TRUE,
));
$vocabulary = taxonomy_vocabulary_load($term->vid);
$term_xml = $taxonomy_xml
->addChild('term');
$term_xml
->addAttribute('name', $term->name);
$term_xml
->addChild('link', $term_path);
$term_xml
->addChild('label', $term->name);
$term_xml
->addChild('title', $term->name);
$term_xml
->addChild('subject', $term->name);
$term_xml
->addChild('description', views_atom_sanitize($term->description));
$term_xml
->addChild('vocabulary', $vocabulary->name);
}
}