FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View File

@@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

View File

@@ -0,0 +1,144 @@
<?php
/**
* @file
* Field formatters for Views RSS: Core Elements module.
*/
/**
* Implements hook_field_formatter_info().
*/
function views_rss_core_field_formatter_info() {
$formatters = array(
'enclosure' => array(
'label' => t('RSS <enclosure> element'),
'field types' => array('file', 'media', 'image', 'text', 'link_field'),
),
);
return $formatters;
}
/**
* Implements hook_field_formatter_settings_form().
*/
function views_rss_core_field_formatter_settings_form($field, $instance, $view_mode, $form, &$form_state) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$element = NULL;
if ($field['type'] == 'image') {
$image_styles = image_style_options(FALSE);
$element['image_style'] = array(
'#title' => t('Image style'),
'#type' => 'select',
'#default_value' => $settings['image_style'],
'#empty_option' => t('None (original image)'),
'#options' => $image_styles,
);
}
return $element;
}
/**
* Implements hook_field_formatter_settings_summary().
*/
function views_rss_core_field_formatter_settings_summary($field, $instance, $view_mode) {
$display = $instance['display'][$view_mode];
$settings = $display['settings'];
$summary = array();
if ($field['type'] == 'image') {
$image_styles = image_style_options(FALSE);
// Unset possible 'No defined styles' option.
unset($image_styles['']);
// Styles could be lost because of enabled/disabled modules that defines
// their styles in code.
if (isset($image_styles[$settings['image_style']])) {
$summary[] = t('Image style: @style', array('@style' => $image_styles[$settings['image_style']]));
}
else {
$summary[] = t('Original image');
}
}
return implode('<br />', $summary);
}
/**
* Implements hook_field_formatter_view().
*
* This is a dirty trick here. Essentially, we do not want to call a theme
* function from here, as it should be called from within a view (amongst
* other to have $view object in $variables). Therefore here we want to
* return value only, hence use of array('#markup' => $value). However,
* in some cases it won't be just a simple string value to return,
* sometimes we'd want to return an array (for example value with
* additional arguments) - hence the need to serialize it (plus add
* "serialized" string at the beginning so that our field preprocess
* function template_preprocess_views_view_views_rss_field() is able
* to recognize it as serialized array and treat accordingly.
*
* Any better ideas?
*/
function views_rss_core_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = NULL;
foreach ($items as $delta => $item) {
// Inside a view item may contain NULL data. In that case, just return.
if (
($field['type'] == 'file' || $field['type'] == 'image') && empty($item['fid'])
|| $field['type'] == 'media' && empty($item['file']->fid)
|| $field['type'] == 'text' && empty($item['safe_value'])
|| $field['type'] == 'link_field' && empty($item['url'])
) {
unset($items[$delta]);
continue;
}
// Get full image URL based on provided image style.
if ($field['type'] == 'image' && !empty($display['settings']['image_style']) && $image_style = image_style_load($display['settings']['image_style'])) {
$uri = image_style_url($display['settings']['image_style'], $item['uri']);
// Get file size of image preset file (if it has already been created,
// otherwise just create it first and then get file size).
$path = image_style_path($display['settings']['image_style'], $item['uri']);
$real_path = drupal_realpath($path);
if (file_exists($real_path) || image_style_create_derivative($image_style, $item['uri'], $path)) {
$item['filesize'] = filesize($real_path);
}
}
elseif ($field['type'] == 'media') {
$uri = file_create_url($item['file']->uri);
$item['filesize'] = $item['file']->filesize;
$item['filemime'] = $item['file']->filemime;
}
elseif ($field['type'] == 'text' || $field['type'] == 'link_field') {
$uri = ($field['type'] == 'text') ? $item['safe_value'] : $item['url'];
// Great idea to use get_headers() here by Dan Feidt,
// http://drupal.org/user/60005 Thanks Dan!
$headers = get_headers($uri, $format = 1);
$item['filesize'] = $headers['Content-Length'];
$item['filemime'] = $headers['Content-Type'];
}
else {
$uri = file_create_url($item['uri']);
}
// XML element array in format_xml_elements() format.
$rss_element = array(
'key' => 'enclosure',
'attributes' => array(
'url' => $uri,
'length' => $item['filesize'],
'type' => $item['filemime'],
),
);
$element[$delta] = array(
'#item' => $item,
'#markup' => format_xml_elements(array($rss_element)),
'#rss_element' => $rss_element,
);
}
return $element;
}

View File

@@ -0,0 +1,197 @@
<?php
/**
* @file
* Preprocess functions for Views RSS: Core Elements module.
*/
/**
* Preprocess function for channel <title> element.
*/
function views_rss_core_preprocess_channel_title(&$variables) {
$view_title = $variables['view']->get_title();
$variables['elements'][0]['value'] = ($view_title) ? $view_title : variable_get('site_name', t('Drupal'));
}
/**
* Preprocess function for channel <description> element.
*/
function views_rss_core_preprocess_channel_description(&$variables) {
if (empty($variables['elements'][0]['value'])) {
$variables['elements'][0]['value'] = variable_get('site_slogan', '');
}
}
/**
* Preprocess function for channel <link> element.
*/
function views_rss_core_preprocess_channel_link(&$variables) {
$variables['elements'][0]['value'] = url('<front>', array('absolute' => TRUE));
}
/**
* Preprocess function for channel <atom:link> element.
*/
function views_rss_core_preprocess_channel_atom_link(&$variables) {
$url_options = array('absolute' => TRUE);
$input = $variables['view']->get_exposed_input();
if ($input) {
$url_options['query'] = $input;
}
$url = url($variables['view']->get_url(), $url_options);
$variables['elements'][0]['attributes'] = array(
'rel' => 'self',
'href' => $url,
);
}
/**
* Preprocess function for channel <category> element.
*/
function views_rss_core_preprocess_channel_category(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$elements = array();
$categories = explode(',', $variables['elements'][0]['value']);
foreach ($categories as $category) {
$elements[] = array(
'key' => 'category',
'value' => trim($category),
);
}
$variables['elements'] = $elements;
}
/**
* Preprocess function for channel <image> element.
*/
function views_rss_core_preprocess_channel_image(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$path = $variables['elements'][0]['value'];
// Get value of channel <title> element from its preprocess function.
views_rss_core_preprocess_channel_title($variables);
$title = $variables['elements'][0]['value'];
// Get value of channel <title> element from its preprocess function.
views_rss_core_preprocess_channel_link($variables);
$link = $variables['elements'][0]['value'];
// Create subelements array.
$variables['elements'][0]['value'] = array(
'url' => file_create_url($path),
'title' => $title,
'link' => $link,
);
// Try to get image description from website's mission.
$site_slogan = variable_get('site_slogan', '');
if (!empty($site_slogan)) {
$variables['elements'][0]['value']['description'] = $site_slogan;
}
// Get image width and height.
$image = image_load($path);
if (!empty($image)) {
$variables['elements'][0]['value']['width'] = $image->info['width'];
$variables['elements'][0]['value']['height'] = $image->info['height'];
}
}
/**
* Preprocess function for channel <pubDate> and <lastBuildDate> elements.
*
* It will return values for date element providing that original Views query
* was modified appropriately by views_rss_core_views_query_alter() by adding
* new fields to SELECT clause retrieving object creation (for <pubDate>)
* or modification timestamp (for <lastBuildDate>).
*/
function views_rss_core_preprocess_channel_date(&$variables) {
if (count($variables['view']->result) > 0) {
$max_date = 0;
foreach ($variables['view']->result as $row) {
$key = strtolower($variables['elements'][0]['key']);
if (isset($row->$key) && $row->$key > $max_date) {
$max_date = $row->$key;
}
}
if ($max_date) {
$variables['elements'][0]['value'] = date('r', $max_date);
}
}
}
/**
* Preprocess function for channel <skipHours> and <skipDays> elements.
*/
function views_rss_core_preprocess_channel_skip(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$elements = array();
$skips = strip_tags($variables['elements'][0]['value']);
if (!empty($skips)) {
foreach (explode(',', $skips) as $skip_value) {
$elements[] = array(
'key' => ($variables['elements'][0]['key'] == 'skipHours') ? 'hour' : 'day',
'value' => trim($skip_value),
);
}
}
$variables['elements'][0]['value'] = $elements;
}
/**
* Preprocess function for channel <cloud> element.
*/
function views_rss_core_preprocess_channel_cloud(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
if ($url = parse_url($variables['elements'][0]['value'])) {
$variables['elements'][0]['value'] = NULL;
$variables['elements'][0]['attributes'] = array(
'domain' => $url['host'],
'port' => $url['port'],
'path' => $url['path'],
'registerProcedure' => $url['fragment'],
'protocol' => $url['scheme'],
);
}
}
/**
* Preprocess function for item <guid> element.
*/
function views_rss_core_preprocess_item_guid(&$variables) {
// No value = no preprocessing.
if (empty($variables['elements'][0]['value'])) {
return;
}
$is_permalink = 'false';
if (
(!isset($variables['item']['views_rss_core']['link']) || empty($variables['item']['views_rss_core']['link']))
&& valid_url($variables['elements'][0]['value'], TRUE)
) {
$is_permalink = 'true';
}
$variables['elements'][0]['attributes']['isPermaLink'] = $is_permalink;
}
/**
* Preprocess function for item <source> element.
*/
function views_rss_core_preprocess_item_source(&$variables) {
$url_options = array('absolute' => TRUE);
$input = $variables['view']->get_exposed_input();
if ($input) {
$url_options['query'] = $input;
}
$url = url($variables['view']->get_url(), $url_options);
$view_title = $variables['view']->get_title();
$variables['elements'][0]['value'] = (!empty($view_title)) ? $view_title : variable_get('site_name', t('Drupal'));
$variables['elements'][0]['attributes'] = array('url' => $url);
}

View File

@@ -0,0 +1,12 @@
name = "Views RSS: Core Elements"
description = "Provides core XML channel and item elements for Views RSS."
package = Views
dependencies[] = views_rss
core = "7.x"
; Information added by drupal.org packaging script on 2013-09-11
version = "7.x-2.0-rc3+4-dev"
core = "7.x"
project = "views_rss"
datestamp = "1378900636"

View File

@@ -0,0 +1,57 @@
<?php
/**
* @file
* (Un)installation functions for Views RSS: Core Elements module.
*/
/**
* Implements hook_install().
*/
function views_rss_core_install() {
cache_clear_all('views_rss:', 'cache_views', TRUE);
}
/**
* Implements hook_uninstall().
*/
function views_rss_core_uninstall() {
if (db_table_exists('cache_views')) {
cache_clear_all('views_rss:', 'cache_views', TRUE);
}
}
/**
* Rename all old "enclosure_file" and "enclosure_image" field formatters
* for any field in any view to new "enclosure".
*/
function views_rss_core_update_7201() {
$sql = "SELECT vd.*, vv.name FROM {views_display} vd JOIN {views_view} vv USING(vid)";
$result = db_query($sql);
foreach ($result as $record) {
$updated = 0;
if (isset($record->display_options)) {
$display_options = unserialize($record->display_options);
if (isset($display_options['fields']) && is_array($display_options['fields'])) {
foreach ($display_options['fields'] as $field_key => $field) {
if (isset($field['type']) && ($field['type'] == 'enclosure_image' || $field['type'] == 'enclosure_file')) {
$display_options['fields'][$field_key]['type'] = 'enclosure';
$updated++;
}
}
}
}
if ($updated) {
db_update('views_display')
->fields(array('display_options' => serialize($display_options)))
->condition('vid', $record->vid)
->condition('id', $record->id)
->execute();
drupal_set_message(t('Enclosure formatter has been updated for %count fields in %display display in %view_name.', array(
'%count' => $updated,
'%display' => $record->display_title,
'%view_name' => $record->name,
)));
}
}
}

View File

@@ -0,0 +1,284 @@
<?php
/**
* @file
* Provides core <channel> and <item> elements for Views RSS module.
*/
/**
* Module installation path.
*/
define('VIEWS_RSS_CORE_PATH', drupal_get_path('module', 'views_rss_core'));
/**
* Include file with field formatters.
*/
include_once VIEWS_RSS_CORE_PATH .'/views_rss_core.field.inc';
/**
* Include file with all preprocess functions.
*/
include_once VIEWS_RSS_CORE_PATH . '/views_rss_core.inc';
/**
* Implementation of hook_views_rss_namespaces().
*/
function views_rss_core_views_rss_namespaces() {
$namespaces['atom'] = array(
'prefix' => 'xmlns',
'uri' => 'http://www.w3.org/2005/Atom',
);
return $namespaces;
}
/**
* Implements hook_views_rss_channel_elements().
*/
function views_rss_core_views_rss_channel_elements() {
$elements['title'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_title'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-title',
);
$elements['description'] = array(
'description' => t('Description for this feed. If left blank, the default site mission will be used.'),
'settings form' => array('#type' => 'textarea', '#rows' => 3),
'preprocess functions' => array(
'views_rss_core_preprocess_channel_description',
'views_rss_rewrite_relative_paths',
),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-description',
);
$elements['link'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_link'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-link',
);
$elements['atom:link'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_atom_link'),
'help' => 'http://www.rssboard.org/rss-profile#namespace-elements-atom-link',
);
$elements['language'] = array(
'description' => t('The language the channel is written in. This allows aggregators to group all Italian language sites, for example, on a single page. See list of <a href="@w3c_url">allowable values</a> for this element defined by the W3C.', array(
'@w3c_url' => url('http://www.w3.org/TR/REC-html40/struct/dirlang.html', array('fragment' => 'langcodes')),
)),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-language',
);
$elements['category'] = array(
'description' => t('Specify one or more categories that the channel belongs to. Separate multiple items with comma.'),
'preprocess functions' => array('views_rss_core_preprocess_channel_category'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-category',
);
$elements['image'] = array(
'description' => t('Path to the image to be used as the artwork for your feed, for example <em>sites/default/files/AllAboutEverything.jpg</em>. Allowed image formats are GIF, JPEG or PNG. Maximum image width is 144 pixels, maximum height 400 pixels.'),
'preprocess functions' => array('views_rss_core_preprocess_channel_image'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-image',
);
$elements['copyright'] = array(
'description' => t('Copyright notice for content in the channel.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-copyright',
);
$elements['managingEditor'] = array(
'description' => t('Email address for person responsible for editorial content.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-managingeditor',
);
$elements['webMaster'] = array(
'description' => t('Email address for person responsible for technical issues relating to channel.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-webmaster',
);
$elements['generator'] = array(
'description' => t('A string indicating the program used to generate the channel.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-generator',
);
$elements['docs'] = array(
'description' => t("A URL that points to the documentation for the format used in the RSS file. It's for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is."),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-docs',
);
$elements['cloud'] = array(
'description' => t("Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. Example: <em>soap://rpc.sys.com:80/RPC2#pingMe</em>"),
'preprocess functions' => array('views_rss_core_preprocess_channel_cloud'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-cloud',
);
$elements['ttl'] = array(
'description' => t("ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source."),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-ttl',
);
$elements['skipHours'] = array(
'description' => t('A hint for aggregators telling them which hours they can skip. The hours must be expressed as an integer representing the number of hours since 00:00:00 GMT. Values from 0 to 23 are permitted, with 0 representing midnight. An hour must not be duplicated.'),
'preprocess functions' => array('views_rss_core_preprocess_channel_skip'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-skiphours',
);
$elements['skipDays'] = array(
'description' => t('A hint for aggregators telling them which days of the week they can skip (up to seven days).'),
'preprocess functions' => array('views_rss_core_preprocess_channel_skip'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-skipdays',
);
$elements['pubDate'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_date'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-pubdate',
);
$elements['lastBuildDate'] = array(
'configurable' => FALSE,
'preprocess functions' => array('views_rss_core_preprocess_channel_date'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-lastbuilddate',
);
return $elements;
}
/**
* Implements hook_views_rss_item_elements().
*/
function views_rss_core_views_rss_item_elements() {
$elements['title'] = array(
'description' => t('The title of the item. Required by RSS specification.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-title',
);
$elements['link'] = array(
'description' => t('The URL of the item. Required by RSS specification.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-link',
);
$elements['description'] = array(
'description' => t('The item synopsis. Required by RSS specification.'),
'preprocess functions' => array('views_rss_rewrite_relative_paths'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-description',
);
$elements['author'] = array(
'description' => t('Email address of the author of the item. A feed published by an individual should omit this element and use the &lt;managingEditor&gt; or &lt;webMaster&gt; channel elements to provide contact information.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-author',
);
$elements['category'] = array(
'description' => t('Includes the item in one or more categories.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-category',
);
$elements['comments'] = array(
'description' => t('URL of a page for comments relating to the item.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-comments',
);
$elements['enclosure'] = array(
'description' => t('Describes a media object that is attached to the item.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-enclosure',
);
$elements['guid'] = array(
'description' => t('A string that uniquely identifies the item.'),
'preprocess functions' => array('views_rss_core_preprocess_item_guid'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-guid',
);
$elements['pubDate'] = array(
'description' => t('Indicates when the item was published.'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-pubdate',
);
$elements['source'] = array(
'configurable' => FALSE,
'description' => t('The RSS channel that the item came from.'),
'preprocess functions' => array('views_rss_core_preprocess_item_source'),
'help' => 'http://www.rssboard.org/rss-profile#element-channel-item-source',
);
return $elements;
}
/**
* Implements hook_views_rss_date_sources().
*/
function views_rss_core_views_rss_date_sources() {
$sources['node'] = array(
'pubDate' => array(
'table' => 'node',
'field' => 'created',
),
'lastBuildDate' => array(
'table' => 'node',
'field' => 'changed',
),
);
$sources['node_revisions'] = array(
'pubDate' => array(
'table' => 'node_revisions',
'field' => 'timestamp',
),
);
$sources['comments'] = array(
'lastBuildDate' => array(
'table' => 'comments',
'field' => 'timestamp',
),
);
$sources['files'] = array(
'pubDate' => array(
'table' => 'files',
'field' => 'timestamp',
),
);
$sources['users'] = array(
'pubDate' => array(
'table' => 'users',
'field' => 'created',
),
);
return $sources;
}
/**
* Implements hook_views_query_alter().
*/
function views_rss_core_views_query_alter(&$view, &$query) {
if ($view->style_plugin->definition['handler'] == 'views_rss_plugin_style_fields') {
$date_sources = views_rss_get('date_sources');
foreach (array_keys($date_sources) as $module) {
if (isset($date_sources[$module][$view->base_table])) {
// Select the most recent node creation date for <pubDate> element.
if (isset($date_sources[$module][$view->base_table]['pubDate'])) {
$query->fields['pubDate'] = $date_sources[$module][$view->base_table]['pubDate'];
}
// Select the most recent node update date for <lastBuildDate> element.
if (isset($date_sources[$module][$view->base_table]['lastBuildDate'])) {
$query->fields['lastBuildDate'] = $date_sources[$module][$view->base_table]['lastBuildDate'];
}
}
}
}
}
/**
* Implements hook_views_rss_options_form_validate().
*/
function views_rss_core_views_rss_options_form_validate($form, &$form_state) {
// Validate channel <image> element.
if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'])) {
// Do not validate absolute URLs, as this could mean external image.
if (!valid_url($form_state['values']['style_options']['channel']['core']['views_rss_core']['image'], TRUE)) {
// Check that image exists and is in acceptable format.
$image = image_load($form_state['values']['style_options']['channel']['core']['views_rss_core']['image']);
if (empty($image)) {
form_set_error('style_options][channel][core][views_rss_core][image', t('Unable to find %image or incorrect image format.', array(
'%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
)));
}
else {
// Check image width.
if ($image->info['width'] > 144) {
form_set_error('style_options][channel][core][views_rss_core][image', t("Maximum allowed width of an image for feed channel's &lt;image&gt; element is 144 pixels. Specified %image is !width pixels wide.", array(
'%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
'!width' => $image->info['width'],
)));
}
// Check image height.
if ($image->info['height'] > 400) {
form_set_error('style_options][channel][core][views_rss_core][image', t("Maximum allowed height of an image for feed channel's &lt;image&gt; element is 400 pixels. Specified %image is !height pixels high.", array(
'%image' => $form_state['values']['style_options']['channel']['core']['views_rss_core']['image'],
'!height' => $image->info['height'],
)));
}
}
}
}
// Validate channel <docs> element.
if (!empty($form_state['values']['style_options']['channel']['core']['views_rss_core']['docs'])) {
if (!valid_url($form_state['values']['style_options']['channel']['core']['views_rss_core']['docs'], TRUE)) {
form_set_error('style_options][channel][core][views_rss_core][docs', t("Not a valid URL."));
}
}
}

View File

@@ -0,0 +1,12 @@
name = "Views RSS: DC Elements"
description = "Provides Dublin Core Metadata element set for Views RSS"
package = Views
dependencies[] = views_rss
core = "7.x"
; Information added by drupal.org packaging script on 2013-09-11
version = "7.x-2.0-rc3+4-dev"
core = "7.x"
project = "views_rss"
datestamp = "1378900636"

View File

@@ -0,0 +1,22 @@
<?php
/**
* @file
* (Un)installation functions for Views RSS: DC Elements module.
*/
/**
* Implements hook_install().
*/
function views_rss_dc_install() {
cache_clear_all('views_rss:', 'cache_views', TRUE);
}
/**
* Implements hook_uninstall().
*/
function views_rss_dc_uninstall() {
if (db_table_exists('cache_views')) {
cache_clear_all('views_rss:', 'cache_views', TRUE);
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* @file
* Provides Dublin Core namespace and <item> elements for Views RSS module.
*/
/**
* Implements hook_views_rss_namespaces().
*/
function views_rss_dc_views_rss_namespaces() {
$namespaces['dc'] = array(
'prefix' => 'xmlns',
'uri' => 'http://purl.org/dc/elements/1.1/',
);
return $namespaces;
}
/**
* Implements hook_views_rss_item_elements().
*/
function views_rss_dc_views_rss_item_elements() {
$elements['dc:title'] = array(
'description' => t('A name given to the resource. Typically, a Title will be a name by which the resource is formally known.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#title',
);
$elements['dc:creator'] = array(
'description' => t('An entity primarily responsible for making the content of the resource. Examples of a Creator include a person, an organisation, or a service. Typically, the name of a Creator should be used to indicate the entity.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#creator',
);
$elements['dc:subject'] = array(
'description' => t('The topic of the content of the resource. Typically, a Subject will be expressed as keywords, key phrases or classification codes that describe a topic of the resource. Recommended best practice is to select a value from a controlled vocabulary or formal classification scheme.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#subject',
);
$elements['dc:description'] = array(
'description' => t('An account of the content of the resource. Description may include but is not limited to: an abstract, table of contents, reference to a graphical representation of content or a free-text account of the content.'),
'preprocess functions' => array('views_rss_rewrite_relative_paths'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#description',
);
$elements['dc:publisher'] = array(
'description' => t('An entity responsible for making the resource available. Examples of a Publisher include a person, an organisation, or a service. Typically, the name of a Publisher should be used to indicate the entity.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#publisher',
);
$elements['dc:contributor'] = array(
'description' => t('An entity responsible for making contributions to the content of the resource. Examples of a Contributor include a person, an organisation, or a service. Typically, the name of a Contributor should be used to indicate the entity.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#contributor',
);
$elements['dc:date'] = array(
'description' => t('A date associated with an event in the life cycle of the resource. Typically, Date will be associated with the creation or availability of the resource. Recommended best practice for encoding the date value is defined in a profile of <a href="@formats_url">ISO 8601</a> and follows the YYYY-MM-DD format.', array(
'@formats_url' => url('http://www.w3.org/TR/NOTE-datetime'),
)),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#date',
);
$elements['dc:type'] = array(
'description' => t('The nature or genre of the content of the resource. Type includes terms describing general categories, functions, genres, or aggregation levels for content. Recommended best practice is to select a value from a controlled vocabulary (for example, the working draft list of <a href="@core_types_url">Dublin Core Types</a>). To describe the physical or digital manifestation of the resource, use the FORMAT element.', array(
'@core_types_url' => url('http://dublincore.org/documents/dcmi-type-vocabulary/'),
)),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#type',
);
$elements['dc:format'] = array(
'description' => t('The physical or digital manifestation of the resource. Typically, Format may include the media-type or dimensions of the resource. Format may be used to determine the software, hardware or other equipment needed to display or operate the resource. Examples of dimensions include size and duration. Recommended best practice is to select a value from a controlled vocabulary (for example, the list of <a href="@types_url">Internet Media Types</a> defining computer media formats).', array(
'@types_url' => url('http://www.isi.edu/in-notes/iana/assignments/media-types/media-types'),
)),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#format',
);
$elements['dc:identifier'] = array(
'description' => t('An unambiguous reference to the resource within a given context. Recommended best practice is to identify the resource by means of a string or number conforming to a formal identification system. Example formal identification systems include the Uniform Resource Identifier (URI) (including the Uniform Resource Locator (URL)), the Digital Object Identifier (DOI) and the International Standard Book Number (ISBN).'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#identifier',
);
$elements['dc:source'] = array(
'description' => t('A Reference to a resource from which the present resource is derived. The present resource may be derived from the Source resource in whole or in part. Recommended best practice is to reference the resource by means of a string or number conforming to a formal identification system.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#source',
);
$elements['dc:language'] = array(
'description' => t("A language of the intellectual content of the resource. Recommended best practice for the values of the Language element is defined by <a href='@RFC1766_url'>RFC 1766</a> which includes a two-letter Language Code (taken from the <a href='@ISO639_url'>ISO 639 standard</a>), followed optionally, by a two-letter Country Code (taken from the <a href='@ISO3166_url'>ISO 3166 standard</a>). For example, 'en' for English, 'fr' for French, or 'en-uk' for English used in the United Kingdom.", array(
'@RFC1766_url' => url('http://www.ietf.org/rfc/rfc1766.txt'),
'@ISO639_url' => url('http://www.oasis-open.org/cover/iso639a.html'),
'@ISO3166_url' => url('http://www.oasis-open.org/cover/iso639a.html'),
)),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#language',
);
$elements['dc:relation'] = array(
'description' => t('A reference to a related resource. Recommended best practice is to reference the resource by means of a string or number conforming to a formal identification system.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#relation',
);
$elements['dc:coverage'] = array(
'description' => t('The extent or scope of the content of the resource. Coverage will typically include spatial location (a place name or geographic coordinates), temporal period (a period label, date, or date range) or jurisdiction (such as a named administrative entity). Recommended best practice is to select a value from a controlled vocabulary (for example, the Thesaurus of Geographic Names) and that, where appropriate, named places or time periods be used in preference to numeric identifiers such as sets of coordinates or date ranges.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#coverage',
);
$elements['dc:rights'] = array(
'description' => t('Information about rights held in and over the resource. Typically, a Rights element will contain a rights management statement for the resource, or reference a service providing such information. Rights information often encompasses Intellectual Property Rights (IPR), Copyright, and various Property Rights. If the Rights element is absent, no assumptions can be made about the status of these and other rights with respect to the resource.'),
'help' => 'http://dublincore.org/documents/1999/07/02/dces/#rights',
);
return $elements;
}

View File

@@ -0,0 +1,224 @@
<?php
/**
* @file
* Theme functions for Views RSS module.
*/
/**
* Template preprocessor for views-view-views-rss.tpl.php.
*/
function template_preprocess_views_view_views_rss(&$variables) {
$view = $variables['view'];
// Start building the feed array compatible with format_xml_elements().
$rss_feed = array(
'key' => 'rss',
'attributes' => array(
'version' => '2.0',
),
'value' => array(),
);
// Prepare namespaces and add them to feed array.
// xml:base cannot be defined by hook_views_rss_namespaces() implementation,
// as we don't want its value to be cached, it needs to be dynamic.
$rss_feed['attributes']['xml:base'] = url('<front>', array('absolute' => TRUE));
// All other namespaces are taken from hook_views_rss_namespaces() implementations.
foreach (views_rss_get('namespaces') as $module => $module_namespaces) {
foreach ($module_namespaces as $namespace => $definition) {
// Check if definition provided through modules hooks
// should be overwritten by module configuration.
if (
isset($view->style_plugin->options['namespaces'][$module][$namespace])
&& !empty($view->style_plugin->options['namespaces'][$module][$namespace])
) {
$definition['uri'] = $view->style_plugin->options['namespaces'][$module][$namespace];
}
// Add namespace to feed array.
if (isset($definition['uri']) && !empty($definition['uri'])) {
// Namespaces with prefix, for example xml:base="" or xmlns:dc=""
if (isset($definition['prefix']) && !empty($definition['prefix'])) {
$namespace_key = $definition['prefix'] . ':' . $namespace;
$rss_feed['attributes'][$namespace_key] = $definition['uri'];
}
// Namespaces without prefix, for example: content="" or foaf=""
else {
$rss_feed['attributes'][$namespace] = $definition['uri'];
}
}
}
}
// Prepare <channel> elements and add them to feed array.
$rss_channel = array();
foreach (views_rss_get('channel_elements') as $module => $module_channel_elements) {
foreach ($module_channel_elements as $element => $definition) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
// Try to fetch namespace value from view configuration.
if (isset($view->style_plugin->options['channel'][$namespace][$module][$element_name])) {
$value = $view->style_plugin->options['channel'][$namespace][$module][$element_name];
}
// Otherwise check if it was provided by element definition.
elseif (isset($definition['default_value'])) {
$value = $definition['default_value'];
}
else {
$value = NULL;
}
// Start building XML channel element array compatible with format_xml_elements().
$rss_elements = array(
array(
'key' => $element,
'value' => $value,
),
);
// Preprocess element value.
if (isset($definition['preprocess functions']) && is_array($definition['preprocess functions'])) {
foreach ($definition['preprocess functions'] as $preprocess_function) {
if (function_exists($preprocess_function)) {
$item_variables = array(
'elements' => &$rss_elements,
'item' => $view->style_plugin->options['channel'],
'view' => $view,
);
$preprocess_function($item_variables);
}
}
}
// If there is no value and no attributes (in case of self-closing elements)
// already set for the element at this stage, it is not going to be set
// at any point further, so the element should not be added to the feed.
foreach ($rss_elements as $key => $rss_element) {
if (empty($rss_element['value']) && empty($rss_element['attributes'])) {
unset($rss_elements[$key]);
}
}
if (empty($rss_elements)) continue;
// Add XML element(s) to the channel array.
$rss_channel = array_merge($rss_channel, $rss_elements);
}
}
// Channel array should not be added to the feed array yet, as first
// it needs to get populated with all <item> elements.
// Prepare <item> elements and add them to the channel array.
$item_elements = views_rss_get('item_elements');
$items = $view->style_plugin->map_rows($variables['rows']);
foreach ($items as $item_key => $item) {
// Start building XML item element array compatible with format_xml_elements().
$rss_item = array(
'key' => 'item',
'value' => array(),
);
// Preprocess whole item array before preprocessing separate elements.
foreach (module_implements('views_rss_preprocess_item') as $module) {
$preprocess_function = $module . '_views_rss_preprocess_item';
$item_variables = array(
'item' => &$item,
'view' => $view,
);
// Add raw row if generated based on raw item values provided by field formatter.
if (!empty($view->views_rss['raw_items'][$item_key])) {
$item_variables['raw'] = $view->views_rss['raw_items'][$item_key];
}
$preprocess_function($item_variables);
}
// Process each element separately.
foreach ($item as $module => $module_item_elements) {
foreach ($module_item_elements as $element => $value) {
// Start building XML element array compatible with format_xml_elements().
$rss_elements = array(
array(
'key' => $element,
'value' => $value,
),
);
// Preprocess element initial value if required.
if (isset($item_elements[$module][$element]['preprocess functions']) && is_array($item_elements[$module][$element]['preprocess functions'])) {
foreach ($item_elements[$module][$element]['preprocess functions'] as $preprocess_function) {
if (function_exists($preprocess_function)) {
$item_variables = array(
'elements' => &$rss_elements,
'item' => $item,
'view' => $view,
);
// Add raw item if provided by field formatter.
if (!empty($view->views_rss['raw_items'][$item_key][$module][$element])) {
$item_variables['raw'] = $view->views_rss['raw_items'][$item_key][$module][$element];
}
$preprocess_function($item_variables);
}
}
}
// If no preprocess function was defined, and we have received
// #rss_element value (XML element array) from the formatter, it should
// be added to the feed array without any further modifications.
elseif (
!empty($view->views_rss['raw_items'][$item_key][$module][$element])
&& is_array($view->views_rss['raw_items'][$item_key][$module][$element])
) {
// At this point we don't know yet if we got #rss_elements in raw
// values, so do not overwrite and empty main $rss_elements yet, just
// start working with new $formatter_rss_elements - it could be
// overwritten once we are sure we have all required values.
$formatter_rss_elements = array();
foreach ($view->views_rss['raw_items'][$item_key][$module][$element] as $raw_item) {
if (!empty($raw_item['rendered']['#rss_element'])) {
$formatter_rss_elements[] = $raw_item['rendered']['#rss_element'];
}
}
// Now we can overwrite main $rss_elements.
if (!empty($formatter_rss_elements)) {
$rss_elements = $formatter_rss_elements;
}
}
// If there is no value and no attributes (in case of self-closing elements)
// already set for the element at this stage, it is not going to be set
// at any point further, so the element should not be added to the feed.
foreach ($rss_elements as $key => $rss_element) {
if (empty($rss_element['value']) && empty($rss_element['attributes'])) {
unset($rss_elements[$key]);
}
}
if (empty($rss_elements)) continue;
// Add XML element(s) to the item array.
$rss_item['value'] = array_merge($rss_item['value'], $rss_elements);
}
}
// Add XML item element to the channe; array.
$rss_channel[] = $rss_item;
}
// Finally, let's put together the whole feed array.
$rss_feed['value'][] = array(
'key' => 'channel',
'value' => $rss_channel,
);
// Allow for altering it before final render and passing it to the template.
drupal_alter('views_rss_feed', $rss_feed);
// Assign rendered feed to the template variables.
$variables['rss_feed'] = format_xml_elements(array($rss_feed));
// Set XML header.
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
}

View File

@@ -0,0 +1,8 @@
<?php
/**
* @file views-view-views-rss.tpl.php
* Default template for feed displays that use the RSS Fields style.
*/
?>
<?php print "<?xml"; ?> version="1.0" encoding="utf-8" <?php print "?>"; ?>
<?php print $rss_feed; ?>

View File

@@ -0,0 +1,58 @@
<?php
/**
* @file
* Views plugins, handlers and hooks definition for Views RSS module.
*/
/**
* Implements hook_views_style_plugins().
* Adds view types to views UI interface.
*/
function views_rss_views_plugins() {
return array(
'style' => array(
'rss_fields' => array(
'type' => 'feed',
'title' => t('RSS Feed - Fields'),
'help' => t('Outputs a RSS formatted feed'),
'handler' => 'views_rss_plugin_style_fields',
'path' => VIEWS_RSS_PATH . '/views',
'theme' => 'views_view_views_rss',
'theme file' => 'theme.inc',
'theme path' => VIEWS_RSS_PATH . '/theme',
'uses row plugin' => FALSE,
'uses fields' => TRUE,
'uses options' => TRUE,
'uses grouping' => FALSE,
),
),
);
}
/**
* Implements hook_views_handlers().
*/
function views_rss_views_handlers() {
return array(
'info' => array(
'path' => VIEWS_RSS_PATH . '/views',
),
'handlers' => array(
'views_rss_handler_field_user_mail' => array(
'parent' => 'views_handler_field_user_mail',
),
'views_rss_handler_field_term_node_tid' => array(
'parent' => 'views_handler_field_term_node_tid',
),
),
);
}
/**
* Implements hook_views_data_alter().
*/
function views_rss_views_data_alter(&$data) {
$data['users']['mail']['field']['handler'] = 'views_rss_handler_field_user_mail';
$data['node']['term_node_tid']['field']['handler'] = 'views_rss_handler_field_term_node_tid';
}

View File

@@ -0,0 +1,163 @@
<?php
/**
* @file
* Field handler to provide additional control for the All Taxonomy Terms field.
*/
class views_rss_handler_field_term_node_tid extends views_handler_field_term_node_tid {
function option_definition() {
$options = parent::option_definition();
$options['rss_domain'] = array('default' => 'none');
$options['rss_include_parents'] = array('default' => 0);
$options['rss_include_vocabulary'] = array('default' => 0);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
// New display type: "RSS <category> element".
$form['type']['#weight'] = 2;
$form['separator']['#weight'] = 3;
$form['type']['#options']['rss_category'] = t('RSS &lt;category&gt; element');
// Additional options for "domain" attribute.
$form['rss_domain'] = array(
'#type' => 'select',
'#title' => t('<em>Domain</em> attribute'),
'#description' => t("<em>domain</em> attribute identifies the category's taxonomy.") . ' ' . l('[?]', 'http://www.rssboard.org/rss-profile#element-channel-item-category', array('attributes' => array('title' => t('Need more information?')))),
'#options' => array(
'none' => t('None'),
'path' => t('Path'),
'alias' => t('URL alias'),
),
'#default_value' => $this->options['rss_domain'],
'#dependency' => array('radio:options[type]' => array('rss_category')),
'#weight' => 3,
);
// Output terms with their parents.
// Example: parent2/parent1/term
$form['rss_include_parents'] = array(
'#type' => 'checkbox',
'#title' => t('Include term parents'),
'#description' => t('Output terms from hierarchical vocabularies together with their parents (slash-delimited).'),
'#default_value' => $this->options['rss_include_parents'],
'#dependency' => array('radio:options[type]' => array('rss_category')),
'#weight' => 4,
);
// Output terms with their parents and vocabulary.
// Example: vocabulary/parent2/parent1/term
$form['rss_include_vocabulary'] = array(
'#type' => 'checkbox',
'#title' => t('Include term vocabulary'),
'#description' => t('Add vocabulary name before term parents.'),
'#default_value' => $this->options['rss_include_vocabulary'],
'#process' => array('ctools_dependent_process'),
'#dependency_count' => 2,
'#dependency' => array(
'radio:options[type]' => array('rss_category'),
'edit-options-rss-include-parents' => array(1),
),
'#weight' => 5,
);
// Hide "Link this field to its term page" checkbox
// if "RSS <category> element" is selected as "Display type".
$form['link_to_taxonomy']['#weight'] = 4;
$form['link_to_taxonomy']['#states'] = array(
'visible' => array(
':input[name="options[type]"]' => array('!value' => 'rss_category'),
),
);
}
function pre_render(&$values) {
parent::pre_render($values);
// For "RSS <category> element" display type make sure
// that field value will never be rendered as link.
if ($this->options['type'] == 'rss_category') {
foreach ($this->items as $node_nid => $terms) {
foreach ($terms as $term_tid => $term) {
if (isset($term['make_link'])) {
$this->items[$node_nid][$term_tid]['make_link'] = FALSE;
}
if ($this->options['rss_domain'] != 'none' && empty($this->options['link_to_taxonomy'])) {
$this->items[$node_nid][$term_tid]['path'] = 'taxonomy/term/' . $term_tid;
}
if ($this->options['rss_include_parents']) {
$this->items[$node_nid][$term_tid]['parents'] = taxonomy_get_parents_all($term_tid);
}
if ($this->options['rss_include_vocabulary']) {
$this->items[$node_nid][$term_tid]['vocabulary'] = $term['vocabulary'];
}
}
}
}
}
function render_items($items) {
if (!empty($items)) {
if ($this->options['type'] == 'rss_category') {
return implode('', $items);
}
// Default render_items().
return parent::render_items($items);
}
}
function render_item($count, $item) {
if ($this->options['type'] == 'rss_category') {
// Basic XML element details.
$rss_element = array(
'key' => 'category',
'value' => $item['name'],
);
// Slash-delimited list of all parents with the term at the end.
// $item['parents'] array contains the current term as well.
if ($this->options['rss_include_parents'] && isset($item['parents'])) {
$parents = array();
// Add vocabulary if required.
if ($this->options['rss_include_vocabulary'] && isset($item['vocabulary'])) {
$parents[] = $item['vocabulary'];
}
// Add all terms (parent and current one).
foreach (array_reverse($item['parents']) as $parent) {
$parents[] = $parent->name;
}
if (count($parents)) {
$rss_element['value'] = implode('/', $parents);
}
}
// Add "domain" attribute if required.
if ($this->options['rss_domain'] == 'path') {
$rss_element['attributes']['domain'] = url('<front>', array('absolute' => TRUE)) . $item['path'];
}
elseif ($this->options['rss_domain'] == 'alias') {
$rss_element['attributes']['domain'] = url($item['path'], array('absolute' => TRUE));
}
// Prepare raw-rendered values to store in view results.
$rendered = array(
'#item' => $item,
'#markup' => format_xml_elements(array($rss_element)),
'#rss_element' => $rss_element,
'#settings' => $this->options,
);
// Store raw-rendered values in view results, the same way
// as values from standard field formatters are added.
$row_index = $this->view->row_index;
$field_name = 'field_' . $this->field;
$this->view->result[$row_index]->{$field_name}[$count] = array(
'rendered' => $rendered,
'raw' => $item,
);
// Return formatted XML element.
return format_xml_elements(array($rss_element));
}
// Standard Views render_item().
return parent::render_item($count, $item);
}
}

View File

@@ -0,0 +1,72 @@
<?php
/**
* @file
* Field handler to provide additional control for the email field.
*/
class views_rss_handler_field_user_mail extends views_handler_field_user_mail {
function option_definition() {
$options = parent::option_definition();
$options['rss_format'] = array('default' => 'default');
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['rss_format'] = array(
'#title' => t('Display type'),
'#type' => 'select',
'#options' => array(
'default' => t('Generic email'),
'with_name' => t('RSS <author> element (with user name)'),
),
'#default_value' => isset($this->options['rss_format']) ? $this->options['rss_format'] : 'default',
'#weight' => 0,
);
// Hide "Link this field" radios if "RSS <author> element"
// is selected as "Display type".
$form['link_to_user']['#states'] = array(
'visible' => array(
':input[name="options[rss_format]"]' => array('!value' => 'with_name'),
),
);
}
function render_link($data, $values) {
if ($this->options['rss_format'] == 'with_name') {
// Try to load full user object based on email address.
$value = $data;
if ($account = user_load_by_mail($data)) {
$value = $account->mail . ' (' . $account->name . ')';
}
// Basic XML element details.
$rss_element = array(
'key' => 'author',
'value' => $value,
);
// Prepare and store raw-rendered values in view results,
// the same way as values from standard field formatters are added.
$rendered = array(
'#item' => $data,
'#markup' => format_xml_elements(array($rss_element)),
'#rss_element' => $rss_element,
'#settings' => $this->options,
);
// Store raw-rendered values in view results, the same way
// as values from standard field formatters are added.
$row_index = $this->view->row_index;
$field_name = 'field_' . $this->field;
$this->view->result[$row_index]->{$field_name}[0] = array(
'rendered' => $rendered,
'raw' => $data,
);
// Return formatted XML element.
return format_xml_elements(array($rss_element));
}
// Standard Views render_link().
return parent::render_link($data, $values);
}
}

View File

@@ -0,0 +1,409 @@
<?php
/**
* @file
* Extends the view_plugin_style class to provide new RSS view style.
*/
class views_rss_plugin_style_fields extends views_plugin_style {
/**
* Attach this view to another display as a feed.
*/
function attach_to($display_id, $path, $title) {
$display = $this->view->display[$display_id]->handler;
$url_options = array('absolute' => TRUE);
$input = $this->view->get_exposed_input();
if ($input) {
$url_options['query'] = $input;
}
$url = url($this->view->get_url(NULL, $path), $url_options);
if ($display->has_path() && !$this->options['feed_settings']['feed_in_links']) {
if (empty($this->preview)) {
drupal_add_feed($url, $title);
}
}
else {
if (empty($this->view->feed_icon)) {
$this->view->feed_icon = '';
}
$this->view->feed_icon .= theme('feed_icon', array('url' => $url, 'title' => $title));
drupal_add_html_head_link(array(
'rel' => 'alternate',
'type' => 'application/rss+xml',
'title' => $title,
'href' => $url,
));
}
}
function option_definition() {
$options = parent::option_definition();
// Namespace defaults.
$namespaces = views_rss_get('namespaces');
if (count($namespaces)) {
foreach ($namespaces as $module => $module_namespaces) {
foreach (array_keys($module_namespaces) as $namespace) {
$options['namespaces'][$module][$namespace] = array('default' => NULL);
}
}
}
// Channel element defaults.
$channel_elements = views_rss_get('channel_elements');
if (count($channel_elements)) {
foreach ($channel_elements as $module => $module_channel_elements) {
foreach (array_keys($module_channel_elements) as $element) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
$options['channel'][$namespace][$module][$element_name] = array('default' => NULL);
}
}
}
// Item element defaults.
$item_elements = views_rss_get('item_elements');
if (count($item_elements)) {
foreach ($item_elements as $module => $module_item_elements) {
foreach (array_keys($module_item_elements) as $element) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
$options['item'][$namespace][$module][$element_name] = array('default' => NULL);
}
}
}
// Other feed settings defaults.
$options['feed_settings']['feed_in_links'] = array('default' => 0);
return $options;
}
/**
* Provide a form for setting options.
*
* @param array $form
* @param array $form_state
*/
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$handlers = $this->display->handler->get_handlers('field');
if (empty($handlers)) {
drupal_set_message(t('You need at least one field before you can configure your field settings.'), 'error');
}
else {
// Field chooser.
$field_names = array('' => '--');
foreach ($handlers as $field => $handler) {
if ($label = $handler->label()) {
$field_names[$field] = $label;
}
else {
$field_names[$field] = $handler->ui_name();
}
}
// Element groups could be used both in channel and item settings.
$element_groups = views_rss_get('element_groups');
// Channel elements settings.
$channel_elements = views_rss_get('channel_elements');
if (count($channel_elements)) {
foreach ($channel_elements as $module => $module_channel_elements) {
foreach ($module_channel_elements as $element => $definition) {
if (!isset($definition['configurable']) || $definition['configurable']) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
// Add fieldset for namespace if not yet added.
if (!isset($form['channel'][$namespace])) {
$form['channel'][$namespace] = array(
'#type' => 'fieldset',
'#title' => t('Channel elements : @namespace', array('@namespace' => $namespace)),
'#description' => t('Provide values for &lt;channel&gt; elements in "@namespace" namespace. See <a href="@guide_url">Views RSS documentation</a> for more information.', array(
'@namespace' => $namespace,
'@guide_url' => url('http://drupal.org/node/1344136'),
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
// Prepare form element.
$default_value = NULL;
if (!empty($this->options['channel'][$namespace][$module][$element_name])) {
$default_value = $this->options['channel'][$namespace][$module][$element_name];
}
$form_item = array(
'#type' => 'textfield',
'#title' => filter_xss(isset($definition['title']) ? $definition['title'] : $element_name),
'#description' => filter_xss(isset($definition['description']) ? $definition['description'] : NULL),
'#default_value' => $default_value,
);
// Allow to overwrite default form element.
if (!empty($definition['settings form'])) {
$form_item = array_merge($form_item, $definition['settings form']);
// Make sure that #options is an associative array.
if (!empty($definition['settings form']['#options'])) {
$form_item['#options'] = views_rss_map_assoc($definition['settings form']['#options']);
}
}
if (!empty($definition['settings form options callback'])) {
$function = $definition['settings form options callback'];
$form_item['#options'] = views_rss_map_assoc($function());
}
// Add help link if provided.
if (!empty($definition['help'])) {
$form_item['#description'] .= ' ' . l('[?]', $definition['help'], array('attributes' => array('title' => t('Need more information?'))));
}
// Check if element should be displayed in a subgroup.
if (!empty($definition['group'])) {
// Add a subgroup to the form if it not yet added.
if (!isset($form['channel'][$namespace][$module][$definition['group']])) {
// Does module provide the group definition?
$group_title = !empty($element_groups[$module][$definition['group']]['title']) ? $element_groups[$module][$definition['group']]['title'] : $definition['group'];
$group_description = !empty($element_groups[$module][$definition['group']]['description']) ? $element_groups[$module][$definition['group']]['description'] : NULL;
$form['channel'][$namespace][$module][$definition['group']] = array(
'#type' => 'fieldset',
'#title' => filter_xss($group_title),
'#description' => filter_xss($group_description),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
$form['channel'][$namespace][$module][$definition['group']][$element_name] = $form_item;
}
// Display element normally (not within a subgroup).
else {
$form['channel'][$namespace][$module][$element_name] = $form_item;
}
}
}
}
}
// Item elements settings.
$item_elements = views_rss_get('item_elements');
if (count($item_elements)) {
foreach ($item_elements as $module => $module_item_elements) {
foreach ($module_item_elements as $element => $definition) {
if (!isset($definition['configurable']) || $definition['configurable']) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
// Add fieldset for namespace if not yet added.
if (!isset($form['item'][$namespace])) {
$form['item'][$namespace] = array(
'#type' => 'fieldset',
'#title' => t('Item elements : @namespace', array('@namespace' => $namespace)),
'#description' => t('Select fields containing relevant values for &lt;item&gt; elements in "@namespace" namespace. See <a href="@guide_url">Views RSS documentation</a> for more information.', array(
'@namespace' => $namespace,
'@guide_url' => url('http://drupal.org/node/1344136'),
)),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
// Prepare form element.
$default_value = NULL;
if (!empty($this->options['item'][$namespace][$module][$element_name])) {
$default_value = $this->options['item'][$namespace][$module][$element_name];
}
$form_item = array(
'#type' => 'select',
'#title' => filter_xss(isset($definition['title']) ? $definition['title'] : $element_name),
'#description' => filter_xss(isset($definition['description']) ? $definition['description'] : NULL),
'#options' => $field_names,
'#default_value' => $default_value,
);
// Allow to overwrite default form element.
if (!empty($definition['settings form'])) {
$form_item = array_merge($form_item, $definition['settings form']);
// Make sure that #options is an associative array.
if (!empty($definition['settings form']['#options'])) {
$form_item['#options'] = views_rss_map_assoc($definition['settings form']['#options']);
}
}
// Add help link if provided.
if (isset($definition['help']) && $definition['help']) {
$form_item['#description'] .= ' ' . l('[?]', $definition['help'], array('attributes' => array('title' => t('Need more information?'))));
}
// Check if element should be displayed in a subgroup.
if (isset($definition['group']) && $definition['group']) {
// Add a subgroup to the form if it not yet added.
if (!isset($form['item'][$namespace][$module][$definition['group']])) {
// Does module provide the group definition?
$group_title = !empty($element_groups[$module][$definition['group']]['title']) ? $element_groups[$module][$definition['group']]['title'] : $definition['group'];
$group_description = !empty($element_groups[$module][$definition['group']]['description']) ? $element_groups[$module][$definition['group']]['description'] : NULL;
$form['item'][$namespace][$module][$definition['group']] = array(
'#type' => 'fieldset',
'#title' => filter_xss($group_title),
'#description' => filter_xss($group_description),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
$form['item'][$namespace][$module][$definition['group']][$element_name] = $form_item;
}
// Display element normally (not within a subgroup).
else {
$form['item'][$namespace][$module][$element_name] = $form_item;
}
}
}
}
}
// Undefined namespaces derived from <channel> and/or <item>
// elements defined by extension modules.
$namespaces = views_rss_get('namespaces');
if (count($namespaces)) {
foreach ($namespaces as $module => $module_namespaces) {
foreach ($module_namespaces as $namespace => $definition) {
if (empty($definition['uri'])) {
// Add fieldset for namespace if not yet added.
if (!isset($form['namespaces'])) {
$form['namespaces'] = array(
'#type' => 'fieldset',
'#title' => t('Namespaces'),
'#description' => t('Enter missing URLs for namespaces derived from &lt;channel&gt; and/or &lt;item&gt; elements defined by extension modules.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
}
if (!empty($this->options['namespaces'][$module][$namespace])) {
$default_value = $this->options['namespaces'][$module][$namespace];
}
else {
$default_value = NULL;
}
$form['namespaces'][$module][$namespace] = array(
'#type' => 'textfield',
'#title' => check_plain($namespace),
'#default_value' => $default_value,
);
}
}
}
}
// Other feed settings.
$form['feed_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Other feed settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['feed_settings']['absolute_paths'] = array(
'#type' => 'checkbox',
'#title' => t("Replace relative paths with absolute URLs"),
'#description' => t('Enabling this option will replace all relative paths (like <em>/node/1</em>) with absolute URLs (<em>!absolute_url</em>) in all feed elements configured to use this feature (for example &lt;description&gt; element).', array(
'!absolute_url' => trim($GLOBALS['base_url'], '/') . '/node/1',
)),
'#default_value' => !empty($this->options['feed_settings']['absolute_paths']) || !isset($this->options['feed_settings']['absolute_paths']),
'#weight' => 1,
);
$form['feed_settings']['feed_in_links'] = array(
'#type' => 'checkbox',
'#title' => t('Display feed icon in the links attached to the view'),
'#default_value' => !empty($this->options['feed_settings']['feed_in_links']),
'#weight' => 3,
);
}
}
/**
* Allow other modules to validate options form values prior to submit.
*/
function options_validate(&$form, &$form_state) {
foreach (module_implements('views_rss_options_form_validate') as $module) {
$function = $module . '_views_rss_options_form_validate';
$function($form, $form_state);
}
}
/**
* Allow other modules to perform any necessary changes
* to options form values prior to storage.
*/
function options_submit(&$form, &$form_state) {
foreach (module_implements('views_rss_options_form_submit') as $module) {
$function = $module . '_views_rss_options_form_submit';
$function($form, $form_state);
}
}
/**
* Make sure the display and all associated handlers are valid.
*/
function validate() {
parent::validate();
$errors = array();
$channel_elements = views_rss_get('channel_elements');
$item_elements = views_rss_get('item_elements');
if (empty($channel_elements) && empty($item_elements)) {
$errors[] = t('You have not enabled any modules providing feed elements. Please enable at least <a href="@modules_url">Views RSS: Core Elements</a> module.', array(
'@modules_url' => url('admin/modules', array('fragment' => 'edit-modules-views')),
));
}
return $errors;
}
/**
* Map views row result to an RSS item.
*/
function map_rows($rows) {
// Fields must be pre-rendered starting from version 2.3 of Views module.
$rendered = $raw = array();
$keys = array_keys($this->view->field);
foreach ($rows as $count => $row) {
$this->view->row_index = $count;
foreach ($keys as $id) {
$rendered[$count][$id] = $this->view->field[$id]->theme($row);
// Also let's keep raw value for further processing.
$field_name = 'field_' . $id;
if (!empty($row->$field_name)) {
$raw[$count][$id] = $row->$field_name;
}
}
}
// Rewrite view rows to XML item rows.
$items = $raw_items = array();
$item_elements = views_rss_get('item_elements');
foreach ($rendered as $id => $row) {
$item = $raw_item = array();
foreach ($item_elements as $module => $module_item_elements) {
foreach (array_keys($module_item_elements) as $element) {
list($namespace, $element_name) = views_rss_extract_element_names($element, 'core');
// Assign values for all elements, not only those defined in view settings.
// If element value is not defined in view settings, let's just assign NULL.
// It will not be passed to final theme function anyway during processing
// taking place in template_preprocess_views_view_views_rss().
if (
isset($this->options['item'][$namespace][$module][$element_name])
&& isset($row[$this->options['item'][$namespace][$module][$element_name]])
) {
$item[$module][$element] = $row[$this->options['item'][$namespace][$module][$element_name]];
}
else {
$item[$module][$element] = NULL;
}
// Keep raw values too.
if (
!empty($this->options['item'][$namespace][$module][$element_name])
&& !empty($raw[$id][$this->options['item'][$namespace][$module][$element_name]])
) {
$raw_item[$module][$element] = $raw[$id][$this->options['item'][$namespace][$module][$element_name]];
}
}
}
$items[$id] = $item;
$raw_items[$id] = $raw_item;
}
$this->view->views_rss['raw_items'] = $raw_items;
return $items;
}
}

View File

@@ -0,0 +1,15 @@
name = "Views RSS"
description = "Provides a views plugin that allows fields to be included in RSS feeds created using the Views module."
package = Views
dependencies[] = views
core = 7.x
files[] = views/views_rss_plugin_style_fields.inc
files[] = views/views_rss_handler_field_user_mail.inc
files[] = views/views_rss_handler_field_term_node_tid.inc
; Information added by drupal.org packaging script on 2013-09-11
version = "7.x-2.0-rc3+4-dev"
core = "7.x"
project = "views_rss"
datestamp = "1378900636"

View File

@@ -0,0 +1,171 @@
<?php
/**
* @file
* Module providing fields-based views style plugin for RSS feed generation.
*/
/**
* Module build version.
*/
define('VIEWS_RSS_BUILD', '7.x-2.x-dev-20120416');
/**
* Module installation path.
*/
define('VIEWS_RSS_PATH', drupal_get_path('module', 'views_rss'));
/**
* In theory, theme.inc should be automatically loaded from hook_views_plugins()
* implementation in views_rss.views.inc - which usually is the case, apart from
* when "Rescan template files" in view configuration is used, when new template
* files are being detected, but theme.inc for some reason is not loaded, so
* template_preprocess_views_view_views_rss() is not available, and we're getting
* "Array" instead of proper feed data as a result.
*/
include_once VIEWS_RSS_PATH . '/theme/theme.inc';
/**
* Implements hook_views_api().
*/
function views_rss_views_api() {
return array(
'api' => 3,
'path' => VIEWS_RSS_PATH . '/views',
);
}
/**
* Returns an array of item elements defined by other modules
* with hook_views_rss_item_elements() and optionally altered with
* hook_views_rss_item_elements_alter() implementations.
*/
function views_rss_get($key, $rebuild = FALSE) {
static $data = array();
if (!isset($data[$key]) || empty($data[$key]) || $rebuild === TRUE) {
$cid = 'views_rss:' . $key;
$cached = cache_get($cid, 'cache_views');
if (is_object($cached) && isset($cached->data) && $rebuild === FALSE) {
$data[$key] = $cached->data;
}
else {
// Fetch item elements provided by other modules. We need to manually call
// each module so that we can know which module a given item came from.
$data[$key] = array();
$hook_name = 'views_rss_' . $key;
foreach (module_implements($hook_name) as $module) {
$module_data = call_user_func($module . '_' . $hook_name);
if (isset($module_data) && is_array($module_data)) {
$data[$key][$module] = $module_data;
}
}
// Add namespaces not defined by any hook_views_rss_namespaces(),
// but used in any of defined <channel> or <item> elements.
// Let's also add "xmlns" prefix by default to such namespaces.
$function = '_views_rss_process_' . $key;
if (function_exists($function)) {
$data[$key] = $function($data[$key]);
}
// Allow other modules to alter obtained item elements.
drupal_alter($hook_name, $data[$key]);
// Store it infinitely in cache (rebuild only on cache clear).
cache_set($cid, $data[$key], 'cache_views');
}
}
return $data[$key];
}
/**
* Add namespaces not defined by any hook_views_rss_namespaces(),
* but used in any of defined <channel> or <item> elements.
* Let's also add "xmlns" prefix by default to such namespaces.
*/
function _views_rss_process_namespaces($namespaces) {
foreach (views_rss_get('channel_elements') as $module => $elements) {
foreach (array_keys($elements) as $element) {
list($namespace, $element_name) = views_rss_extract_element_names($element);
if ($namespace && !isset($namespaces[$module][$namespace])) {
$namespaces[$module][$namespace] = array('prefix' => 'xmlns', 'uri' => NULL);
}
}
}
foreach (views_rss_get('item_elements') as $module => $elements) {
foreach (array_keys($elements) as $element) {
list($namespace, $element_name) = views_rss_extract_element_names($element);
if ($namespace && !isset($namespaces[$module][$namespace])) {
$namespaces[$module][$namespace] = array('prefix' => 'xmlns', 'uri' => NULL);
}
}
}
return $namespaces;
}
/**
* Add table aliases for additional fields used for altering view query.
*/
function _views_rss_process_date_sources($date_sources) {
foreach ($date_sources as $module => $module_date_sources) {
foreach ($module_date_sources as $base_table => $elements) {
foreach ($elements as $element_name => $definition) {
if (!isset($definition['alias'])) {
$date_sources[$module][$base_table][$element_name]['alias'] = $element_name;
}
}
}
}
return $date_sources;
}
/**
* Extracts and returns an array containing element namespace and name.
*/
function views_rss_extract_element_names($element, $core_namespace = '') {
if (!strstr($element, ':')) {
$element = $core_namespace . ':' . $element;
}
return explode(':', $element);
}
/**
* Preprocess callback.
* Replaces relative paths in element values with absolute URLs.
* Based on preg_match from rel_to_abs module by lourenzo,
* with added patch from issue #1335734 by joelstein.
* @see http://drupal.org/project/rel_to_abs
* @see http://drupal.org/node/1335734
*/
function views_rss_rewrite_relative_paths(&$variables) {
// Rewriting relative paths should be enabled by default,
// so rewrite relative paths even if option value is not set.
if (
!isset($variables['view']->style_plugin->options['feed_settings']['absolute_paths'])
|| !empty($variables['view']->style_plugin->options['feed_settings']['absolute_paths'])
) {
global $base_path;
foreach ($variables['elements'] as $delta => $element) {
if (isset($element['value'])) {
// Value is an array, so this is a set of subelements.
if (is_array($element['value'])) {
views_rss_rewrite_relative_paths($variables['elements'][$delta]['value']);
}
// Value is a string, so just process it.
else {
$pattern = '/(src|href)=(\'|")[^\/]' . preg_quote($base_path, '/') . '/';
$replacement = '$1=$2' . url('<front>', array('absolute' => TRUE));
$variables['elements'][$delta]['value'] = preg_replace($pattern, $replacement, $element['value']);
}
}
}
}
}
/**
* Forms associative array from linear array,
* or returns original array if already associative.
*/
function views_rss_map_assoc($array) {
if (!(array_keys($array) !== range(0, count($array) - 1))) {
$array = drupal_map_assoc($array);
}
return $array;
}