FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -372,7 +372,7 @@ class views_handler_field extends views_handler {
|
||||
* Optional name of the field where the value is stored.
|
||||
*/
|
||||
function get_value($values, $field = NULL) {
|
||||
$alias = isset($field) && isset($this->aliases[$field]) ? $this->aliases[$field] : $this->field_alias;
|
||||
$alias = isset($field) ? $this->aliases[$field] : $this->field_alias;
|
||||
if (isset($values->{$alias})) {
|
||||
return $values->{$alias};
|
||||
}
|
||||
|
@@ -255,10 +255,11 @@ Drupal.behaviors.viewsUiRenderAddViewButton.attach = function (context, settings
|
||||
// away from the item. We use mouseleave instead of mouseout because
|
||||
// the user is going to trigger mouseout when she moves from the trigger
|
||||
// link to the sub menu items.
|
||||
// We use the live binder because the open class on this item will be
|
||||
//
|
||||
// We use the 'li.add' selector because the open class on this item will be
|
||||
// toggled on and off and we want the handler to take effect in the cases
|
||||
// that the class is present, but not when it isn't.
|
||||
$('li.add', $menu).live('mouseleave', function (event) {
|
||||
$menu.delegate('li.add', 'mouseleave', function (event) {
|
||||
var $this = $(this);
|
||||
var $trigger = $this.children('a[href="#"]');
|
||||
if ($this.children('.action-list').is(':visible')) {
|
||||
|
@@ -96,7 +96,6 @@ class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument
|
||||
$query = db_select('taxonomy_term_data', 'td');
|
||||
$query->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
|
||||
$query->fields('td');
|
||||
$query->fields('tv', array('machine_name'));
|
||||
$query->condition('td.tid', $argument);
|
||||
$query->addTag('term_access');
|
||||
$term = $query->execute()->fetchObject();
|
||||
@@ -105,7 +104,7 @@ class views_plugin_argument_validate_taxonomy_term extends views_plugin_argument
|
||||
}
|
||||
$term = taxonomy_term_load($term->tid);
|
||||
$this->argument->validated_title = check_plain(entity_label('taxonomy_term', $term));
|
||||
return empty($vocabularies) || !empty($vocabularies[$term->machine_name]);
|
||||
return empty($vocabularies) || !empty($vocabularies[$term->vocabulary_machine_name]);
|
||||
|
||||
case 'tids':
|
||||
// An empty argument is not a term so doesn't pass.
|
||||
|
@@ -30,6 +30,7 @@ class views_plugin_display_page extends views_plugin_display {
|
||||
'weight' => array('default' => 0),
|
||||
'name' => array('default' => variable_get('menu_default_node_menu', 'navigation')),
|
||||
'context' => array('default' => ''),
|
||||
'context_only_inline' => array('default' => FALSE),
|
||||
),
|
||||
);
|
||||
$options['tab_options'] = array(
|
||||
@@ -153,7 +154,7 @@ class views_plugin_display_page extends views_plugin_display {
|
||||
// Add context for contextual links.
|
||||
// @see menu_contextual_links()
|
||||
if (!empty($menu['context'])) {
|
||||
$items[$path]['context'] = MENU_CONTEXT_INLINE;
|
||||
$items[$path]['context'] = !empty($menu['context_only_inline']) ? MENU_CONTEXT_INLINE : (MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE);
|
||||
}
|
||||
|
||||
// If this is a 'default' tab, check to see if we have to create teh
|
||||
@@ -386,12 +387,23 @@ class views_plugin_display_page extends views_plugin_display {
|
||||
);
|
||||
$form['menu']['context'] = array(
|
||||
'#title' => t('Context'),
|
||||
'#suffix' => '</div>',
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($menu['context']),
|
||||
'#description' => t('Displays the link in contextual links'),
|
||||
'#dependency' => array('radio:menu[type]' => array('tab')),
|
||||
);
|
||||
$form['menu']['context_only_inline'] = array(
|
||||
'#title' => t('Hide menu tab'),
|
||||
'#suffix' => '</div>',
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($menu['context_only_inline']),
|
||||
'#description' => t('Only display menu item entry in contextual links. Menu tab should not be displayed.'),
|
||||
'#dependency' => array(
|
||||
'radio:menu[type]' => array('tab'),
|
||||
'edit-menu-context' => array(1),
|
||||
),
|
||||
'#dependency_count' => 2,
|
||||
);
|
||||
break;
|
||||
case 'tab_options':
|
||||
$form['#title'] .= t('Default tab options');
|
||||
|
@@ -5,9 +5,9 @@ core = 7.x
|
||||
dependencies[] = views
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-03-20
|
||||
version = "7.x-3.6"
|
||||
; Information added by drupal.org packaging script on 2013-04-09
|
||||
version = "7.x-3.7"
|
||||
core = "7.x"
|
||||
project = "views"
|
||||
datestamp = "1363810217"
|
||||
datestamp = "1365499236"
|
||||
|
||||
|
@@ -482,13 +482,15 @@ function hook_views_data_alter(&$data) {
|
||||
$data['users']['example_field'] = array(
|
||||
'title' => t('Example field'),
|
||||
'help' => t('Some example content that references a user'),
|
||||
'handler' => 'hook_handlers_field_example_field',
|
||||
'field' => array(
|
||||
'handler' => 'modulename_handler_field_example_field',
|
||||
),
|
||||
);
|
||||
|
||||
// This example changes the handler of the node title field.
|
||||
// In this handler you could do stuff, like preview of the node when clicking
|
||||
// the node title.
|
||||
$data['node']['title']['handler'] = 'modulename_handlers_field_node_title';
|
||||
$data['node']['title']['field']['handler'] = 'modulename_handler_field_node_title';
|
||||
|
||||
// This example adds a relationship to table {foo}, so that 'foo' views can
|
||||
// add this table using a relationship. Because we don't want to write over
|
||||
|
@@ -312,9 +312,9 @@ files[] = tests/views_cache.test
|
||||
files[] = tests/views_view.test
|
||||
files[] = tests/views_ui.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-03-20
|
||||
version = "7.x-3.6"
|
||||
; Information added by drupal.org packaging script on 2013-04-09
|
||||
version = "7.x-3.7"
|
||||
core = "7.x"
|
||||
project = "views"
|
||||
datestamp = "1363810217"
|
||||
datestamp = "1365499236"
|
||||
|
||||
|
@@ -7,9 +7,9 @@ dependencies[] = views
|
||||
files[] = views_ui.module
|
||||
files[] = plugins/views_wizard/views_ui_base_views_wizard.class.php
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-03-20
|
||||
version = "7.x-3.6"
|
||||
; Information added by drupal.org packaging script on 2013-04-09
|
||||
version = "7.x-3.7"
|
||||
core = "7.x"
|
||||
project = "views"
|
||||
datestamp = "1363810217"
|
||||
datestamp = "1365499236"
|
||||
|
||||
|
@@ -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.
|
@@ -0,0 +1,13 @@
|
||||
Views Bulk Operations augments Views by allowing bulk operations
|
||||
(provided by Drupal core or Rules) to be executed on the displayed rows.
|
||||
It does so by showing a checkbox in front of each displayed row, and adding a
|
||||
select box on top of the View containing operations that can be applied.
|
||||
|
||||
Getting started
|
||||
-----------------
|
||||
1. Create a View.
|
||||
2. Add a "Bulk operations" field, available to all entity types.
|
||||
3. Configure the field by selecting at least one operation.
|
||||
4. Go to the View page. VBO functionality should be present.
|
||||
|
||||
Read the full documentation at http://drupal.org/node/1591342.
|
@@ -0,0 +1,192 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides an action for creating a zip archive of selected files.
|
||||
* An entry in the {file_managed} table is created for the newly created archive,
|
||||
* and it is marked as permanent or temporary based on the operation settings.
|
||||
*/
|
||||
|
||||
function views_bulk_operations_archive_action_info() {
|
||||
$actions = array();
|
||||
if (function_exists('zip_open')) {
|
||||
$actions['views_bulk_operations_archive_action'] = array(
|
||||
'type' => 'file',
|
||||
'label' => t('Create an archive of selected files'),
|
||||
// This action only works when invoked through VBO. That's why it's
|
||||
// declared as non-configurable to prevent it from being shown in the
|
||||
// "Create an advanced action" dropdown on admin/config/system/actions.
|
||||
'configurable' => FALSE,
|
||||
'vbo_configurable' => TRUE,
|
||||
'triggers' => array('any'),
|
||||
);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since Drupal's Archiver doesn't abstract properly the archivers it implements
|
||||
* (Archive_Tar and ZipArchive), it can't be used here.
|
||||
*/
|
||||
function views_bulk_operations_archive_action($file, $context) {
|
||||
global $user;
|
||||
static $archive_contents = array();
|
||||
|
||||
// Adding a non-existent file to the archive crashes ZipArchive on close().
|
||||
if (file_exists($file->uri)) {
|
||||
$destination = $context['destination'];
|
||||
$zip = new ZipArchive();
|
||||
// If the archive already exists, open it. If not, create it.
|
||||
if (file_exists($destination)) {
|
||||
$opened = $zip->open(drupal_realpath($destination));
|
||||
}
|
||||
else {
|
||||
$opened = $zip->open(drupal_realpath($destination), ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
|
||||
}
|
||||
|
||||
if ($opened) {
|
||||
// Create a list of all files in the archive. Used for duplicate checking.
|
||||
if (empty($archive_contents)) {
|
||||
for ($i = 0; $i < $zip->numFiles; $i++) {
|
||||
$archive_contents[] = $zip->getNameIndex($i);
|
||||
}
|
||||
}
|
||||
// Make sure that the target filename is unique.
|
||||
$filename = _views_bulk_operations_archive_action_create_filename(basename($file->uri), $archive_contents);
|
||||
// Note that the actual addition happens on close(), hence the need
|
||||
// to open / close the archive each time the action runs.
|
||||
$zip->addFile(drupal_realpath($file->uri), $filename);
|
||||
$zip->close();
|
||||
$archive_contents[] = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
// The operation is complete, create a file entity and provide a download
|
||||
// link to the user.
|
||||
if ($context['progress']['current'] == $context['progress']['total']) {
|
||||
$archive_file = new stdClass();
|
||||
$archive_file->uri = $destination;
|
||||
$archive_file->filename = basename($destination);
|
||||
$archive_file->filemime = file_get_mimetype($destination);
|
||||
$archive_file->uid = $user->uid;
|
||||
$archive_file->status = $context['settings']['temporary'] ? FALSE : FILE_STATUS_PERMANENT;
|
||||
file_save($archive_file);
|
||||
|
||||
$url = file_create_url($archive_file->uri);
|
||||
$url = l($url, $url, array('absolute' => TRUE));
|
||||
_views_bulk_operations_log(t('An archive has been created and can be downloaded from: !url', array('!url' => $url)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration form shown to the user before the action gets executed.
|
||||
*/
|
||||
function views_bulk_operations_archive_action_form($context) {
|
||||
// Pass the scheme as a value, so that the submit callback can access it.
|
||||
$form['scheme'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => $context['settings']['scheme'],
|
||||
);
|
||||
|
||||
$form['filename'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Filename'),
|
||||
'#default_value' => 'vbo_archive_' . date('Ymd'),
|
||||
'#field_suffix' => '.zip',
|
||||
'#description' => t('The name of the archive file.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles a sanitized and unique URI for the archive, and returns it for
|
||||
* usage by the action callback (views_bulk_operations_archive_action).
|
||||
*/
|
||||
function views_bulk_operations_archive_action_submit($form, $form_state) {
|
||||
// Validate the scheme, fallback to public if it's somehow invalid.
|
||||
$scheme = $form_state['values']['scheme'];
|
||||
if (!file_stream_wrapper_valid_scheme($scheme)) {
|
||||
$scheme = 'public';
|
||||
}
|
||||
$destination = $scheme . '://' . basename($form_state['values']['filename']) . '.zip';
|
||||
// If the chosen filename already exists, file_destination() will append
|
||||
// an integer to it in order to make it unique.
|
||||
$destination = file_destination($destination, FILE_EXISTS_RENAME);
|
||||
|
||||
return array(
|
||||
'destination' => $destination,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form (embedded into the VBO field settings in the Views UI).
|
||||
*/
|
||||
function views_bulk_operations_archive_action_views_bulk_operations_form($options) {
|
||||
$scheme_options = array();
|
||||
foreach (file_get_stream_wrappers(STREAM_WRAPPERS_LOCAL_NORMAL) as $scheme => $stream_wrapper) {
|
||||
$scheme_options[$scheme] = $stream_wrapper['name'];
|
||||
}
|
||||
if (count($scheme_options) > 1) {
|
||||
$form['scheme'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Storage'),
|
||||
'#options' => $scheme_options,
|
||||
'#default_value' => !empty($options['scheme']) ? $options['scheme'] : variable_get('file_default_scheme', 'public'),
|
||||
'#description' => t('Select where the archive should be stored. Private file storage has significantly more overhead than public files, but allows restricted access.'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$scheme_option_keys = array_keys($scheme_options);
|
||||
$form['scheme'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => reset($scheme_option_keys),
|
||||
);
|
||||
}
|
||||
|
||||
$form['temporary'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Temporary'),
|
||||
'#default_value' => isset($options['temporary']) ? $options['temporary'] : TRUE,
|
||||
'#description' => t('Temporary files older than 6 hours are removed when cron runs.'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a sanitized and unique version of the provided filename.
|
||||
*
|
||||
* @param $filename
|
||||
* String filename
|
||||
*
|
||||
* @return
|
||||
* The new filename.
|
||||
*/
|
||||
function _views_bulk_operations_archive_action_create_filename($filename, $archive_list) {
|
||||
// Strip control characters (ASCII value < 32). Though these are allowed in
|
||||
// some filesystems, not many applications handle them well.
|
||||
$filename = preg_replace('/[\x00-\x1F]/u', '_', $filename);
|
||||
if (substr(PHP_OS, 0, 3) == 'WIN') {
|
||||
// These characters are not allowed in Windows filenames
|
||||
$filename = str_replace(array(':', '*', '?', '"', '<', '>', '|'), '_', $filename);
|
||||
}
|
||||
|
||||
if (in_array($filename, $archive_list)) {
|
||||
// Destination file already exists, generate an alternative.
|
||||
$pos = strrpos($filename, '.');
|
||||
if ($pos !== FALSE) {
|
||||
$name = substr($filename, 0, $pos);
|
||||
$ext = substr($filename, $pos);
|
||||
}
|
||||
else {
|
||||
$name = $filename;
|
||||
$ext = '';
|
||||
}
|
||||
|
||||
$counter = 0;
|
||||
do {
|
||||
$filename = $name . '_' . $counter++ . $ext;
|
||||
} while (in_array($filename, $archive_list));
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Passes selected ids as arguments to a page.
|
||||
* The ids might be entity ids or revision ids, depending on the type of the
|
||||
* VBO field.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_action_info().
|
||||
*/
|
||||
function views_bulk_operations_argument_selector_action_info() {
|
||||
return array(
|
||||
'views_bulk_operations_argument_selector_action' => array(
|
||||
'label' => t('Pass ids as arguments to a page'),
|
||||
'type' => 'entity',
|
||||
'aggregate' => TRUE,
|
||||
'configurable' => FALSE,
|
||||
'hooks' => array(),
|
||||
'triggers' => array('any'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of a Drupal action.
|
||||
* Passes selected ids as arguments to a view.
|
||||
*/
|
||||
function views_bulk_operations_argument_selector_action($entities, $context = array()) {
|
||||
$base_url = $context['settings']['url'];
|
||||
$arguments = implode(',', array_keys($entities));
|
||||
// Add a trailing slash if missing.
|
||||
if (substr($base_url, -1, 1) != '/') {
|
||||
$base_url .= '/';
|
||||
}
|
||||
drupal_goto($base_url . $arguments);
|
||||
}
|
||||
|
||||
function views_bulk_operations_argument_selector_action_views_bulk_operations_form($options) {
|
||||
$form['url'] = array(
|
||||
'#title' => t('URL'),
|
||||
'#type' => 'textfield',
|
||||
'#description' => t('Enter a URL that the user will be sent to. A comma-separated list of selected ids will be appended.'),
|
||||
'#default_value' => isset($options['url']) ? $options['url'] : '',
|
||||
'#field_prefix' => url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='),
|
||||
);
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Implements a generic entity delete action. Uses Entity API if available.
|
||||
*/
|
||||
|
||||
function views_bulk_operations_delete_action_info() {
|
||||
return array(
|
||||
'views_bulk_operations_delete_item' => array(
|
||||
'type' => 'entity',
|
||||
'label' => t('Delete item'),
|
||||
'configurable' => FALSE,
|
||||
'behavior' => array('deletes_property'),
|
||||
'triggers' => array('any'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function views_bulk_operations_delete_item($entity, $context) {
|
||||
$info = entity_get_info($context['entity_type']);
|
||||
$entity_id = $entity->{$info['entity keys']['id']};
|
||||
|
||||
entity_delete($context['entity_type'], $entity_id);
|
||||
}
|
@@ -0,0 +1,580 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file VBO action to modify entity values (properties and fields).
|
||||
*/
|
||||
|
||||
// Specifies that all available values should be shown to the user for editing.
|
||||
define('VBO_MODIFY_ACTION_ALL', '_all_');
|
||||
|
||||
function views_bulk_operations_modify_action_info() {
|
||||
return array('views_bulk_operations_modify_action' => array(
|
||||
'type' => 'entity',
|
||||
'label' => t('Modify entity values'),
|
||||
'behavior' => array('changes_property'),
|
||||
// This action only works when invoked through VBO. That's why it's
|
||||
// declared as non-configurable to prevent it from being shown in the
|
||||
// "Create an advanced action" dropdown on admin/config/system/actions.
|
||||
'configurable' => FALSE,
|
||||
'vbo_configurable' => TRUE,
|
||||
'triggers' => array('any'),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Action function.
|
||||
*
|
||||
* Goes through new values and uses them to modify the passed entity by either
|
||||
* replacing the existing values, or appending to them (based on user input).
|
||||
*/
|
||||
function views_bulk_operations_modify_action($entity, $context) {
|
||||
list(,,$bundle_name) = entity_extract_ids($context['entity_type'], $entity);
|
||||
|
||||
// Handle Field API fields.
|
||||
if (!empty($context['selected']['bundle_' . $bundle_name])) {
|
||||
// The pseudo entity is cloned so that changes to it don't get carried
|
||||
// over to the next execution.
|
||||
$pseudo_entity = clone $context['entities'][$bundle_name];
|
||||
foreach ($context['selected']['bundle_' . $bundle_name] as $key) {
|
||||
// Replace any tokens that might exist in the field columns.
|
||||
foreach ($pseudo_entity->{$key}[LANGUAGE_NONE] as $delta => &$item) {
|
||||
foreach ($item as $column => $value) {
|
||||
if (is_string($value)) {
|
||||
$item[$column] = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($key, $context['append']['bundle_' . $bundle_name]) && !empty($entity->$key)) {
|
||||
$entity->{$key}[LANGUAGE_NONE] = array_merge($entity->{$key}[LANGUAGE_NONE], $pseudo_entity->{$key}[LANGUAGE_NONE]);
|
||||
|
||||
// Check if we breached cardinality, and notify the user.
|
||||
$field_info = field_info_field($key);
|
||||
$field_count = count($entity->{$key}[LANGUAGE_NONE]);
|
||||
if ($field_info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $field_count > $field_info['cardinality']) {
|
||||
$entity_label = entity_label($context['entity_type'], $entity);
|
||||
$warning = t('Tried to set !field_count values for field !field_name that supports a maximum of !cardinality.',
|
||||
array('!field_count' => $field_count,
|
||||
'!field_name' => $field_info['field_name'],
|
||||
'!cardinality' => $field_info['cardinality']));
|
||||
drupal_set_message($warning, 'warning', FALSE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$entity->$key = $pseudo_entity->$key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle properties.
|
||||
if (!empty($context['selected']['properties'])) {
|
||||
// Use the wrapper to set property values, since some properties need
|
||||
// additional massaging by their setter callbacks.
|
||||
// The wrapper will automatically modify $entity itself.
|
||||
$wrapper = entity_metadata_wrapper($context['entity_type'], $entity);
|
||||
foreach ($context['selected']['properties'] as $key) {
|
||||
if (in_array($key, $context['append']['properties'])) {
|
||||
$old_values = $wrapper->$key->value();
|
||||
$wrapper->$key->set($context['properties'][$key]);
|
||||
$new_values = $wrapper->{$key}->value();
|
||||
$all_values = array_merge($old_values, $new_values);
|
||||
$wrapper->$key->set($all_values);
|
||||
}
|
||||
else {
|
||||
$value = $context['properties'][$key];
|
||||
if (is_string($value)) {
|
||||
$value = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
|
||||
}
|
||||
$wrapper->$key->set($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action form function.
|
||||
*
|
||||
* Displays form elements for properties acquired through Entity Metadata
|
||||
* (hook_entity_property_info()), as well as field widgets for each
|
||||
* entity bundle, as provided by field_attach_form().
|
||||
*/
|
||||
function views_bulk_operations_modify_action_form($context, &$form_state) {
|
||||
// This action form uses admin-provided settings. If they were not set, pull the defaults now.
|
||||
if (!isset($context['settings'])) {
|
||||
$context['settings'] = views_bulk_operations_modify_action_views_bulk_operations_form_options();
|
||||
}
|
||||
|
||||
$form_state['entity_type'] = $entity_type = $context['entity_type'];
|
||||
// For Field API integration to work, a pseudo-entity is constructed for each
|
||||
// bundle that has fields available for editing.
|
||||
// The entities then get passed to Field API functions
|
||||
// (field_attach_form(), field_attach_form_validate(), field_attach_submit()),
|
||||
// and filled with form data.
|
||||
// After submit, the pseudo-entities get passed to the actual action
|
||||
// (views_bulk_operations_modify_action()) which copies the data from the
|
||||
// relevant pseudo-entity constructed here to the actual entity being modified.
|
||||
$form_state['entities'] = array();
|
||||
|
||||
$info = entity_get_info($entity_type);
|
||||
$properties = _views_bulk_operations_modify_action_get_properties($entity_type, $context['settings']['display_values']);
|
||||
$bundles = _views_bulk_operations_modify_action_get_bundles($entity_type, $context);
|
||||
|
||||
$form['#attached']['css'][] = drupal_get_path('module', 'views_bulk_operations') . '/css/modify.action.css';
|
||||
$form['#tree'] = TRUE;
|
||||
|
||||
if (!empty($properties)) {
|
||||
$form['properties'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Properties',
|
||||
);
|
||||
$form['properties']['show_value'] = array(
|
||||
'#suffix' => '<div class="clearfix"></div>',
|
||||
);
|
||||
|
||||
foreach ($properties as $key => $property) {
|
||||
$form['properties']['show_value'][$key] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $property['label'],
|
||||
);
|
||||
|
||||
$determined_type = ($property['type'] == 'boolean') ? 'checkbox' : 'textfield';
|
||||
$form['properties'][$key] = array(
|
||||
'#type' => $determined_type,
|
||||
'#title' => $property['label'],
|
||||
'#description' => $property['description'],
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'#edit-properties-show-value-' . str_replace('_', '-', $key) => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (!empty($property['options list'])) {
|
||||
$form['properties'][$key]['#type'] = 'select';
|
||||
$form['properties'][$key]['#options'] = $property['options list']($key, array());
|
||||
|
||||
if ($property['type'] == 'list') {
|
||||
$form['properties'][$key]['#type'] = 'checkboxes';
|
||||
|
||||
$form['properties']['_append::' . $key] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add new value(s) to %label, instead of overwriting the existing values.', array('%label' => $property['label'])),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'#edit-properties-show-value-' . $key => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($bundles as $bundle_name => $bundle) {
|
||||
$bundle_key = $info['entity keys']['bundle'];
|
||||
$default_values = array();
|
||||
// If the bundle key exists, it must always be set on an entity.
|
||||
if (!empty($bundle_key)) {
|
||||
$default_values[$bundle_key] = $bundle_name;
|
||||
}
|
||||
$entity = entity_create($context['entity_type'], $default_values);
|
||||
$form_state['entities'][$bundle_name] = $entity;
|
||||
|
||||
// Show the more detailed label only if the entity type has multiple bundles.
|
||||
// Otherwise, it would just be confusing.
|
||||
if (count($info['bundles']) > 1) {
|
||||
$label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
|
||||
}
|
||||
else {
|
||||
$label = t('Fields');
|
||||
}
|
||||
|
||||
$form_key = 'bundle_' . $bundle_name;
|
||||
$form[$form_key] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => $label,
|
||||
'#parents' => array($form_key),
|
||||
);
|
||||
field_attach_form($context['entity_type'], $entity, $form[$form_key], $form_state, LANGUAGE_NONE);
|
||||
// Now that all the widgets have been added, sort them by #weight.
|
||||
// This ensures that they will stay in the correct order when they get
|
||||
// assigned new weights.
|
||||
uasort($form[$form_key], 'element_sort');
|
||||
|
||||
$display_values = $context['settings']['display_values'];
|
||||
$instances = field_info_instances($entity_type, $bundle_name);
|
||||
$weight = 0;
|
||||
foreach (element_get_visible_children($form[$form_key]) as $field_name) {
|
||||
// For our use case it makes no sense for any field widget to be required.
|
||||
$language = $form[$form_key][$field_name]['#language'];
|
||||
_views_bulk_operations_modify_action_unset_required($form[$form_key][$field_name][$language]);
|
||||
|
||||
// The admin has specified which fields to display, but this field didn't
|
||||
// make the cut. Hide it with #access => FALSE and move on.
|
||||
if (empty($display_values[VBO_MODIFY_ACTION_ALL]) && empty($display_values[$bundle_name . '::' . $field_name])) {
|
||||
$form[$form_key][$field_name]['#access'] = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
$field = $instances[$field_name];
|
||||
$form[$form_key]['show_value'][$field_name] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $field['label'],
|
||||
);
|
||||
$form[$form_key][$field_name]['#states'] = array(
|
||||
'visible' => array(
|
||||
'#edit-bundle-' . str_replace('_', '-', $bundle_name) . '-show-value-' . str_replace('_', '-', $field_name) => array('checked' => TRUE),
|
||||
),
|
||||
);
|
||||
// All field widgets get reassigned weights so that additional elements
|
||||
// added between them (such as "_append") can be properly ordered.
|
||||
$form[$form_key][$field_name]['#weight'] = $weight++;
|
||||
|
||||
$field_info = field_info_field($field_name);
|
||||
if ($field_info['cardinality'] != 1) {
|
||||
$form[$form_key]['_append::' . $field_name] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add new value(s) to %label, instead of overwriting the existing values.', array('%label' => $field['label'])),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
'#edit-bundle-' . str_replace('_', '-', $bundle_name) . '-show-value-' . str_replace('_', '-', $field_name) => array('checked' => TRUE),
|
||||
),
|
||||
),
|
||||
'#weight' => $weight++,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Add a clearfix below the checkboxes so that the widgets are not floated.
|
||||
$form[$form_key]['show_value']['#suffix'] = '<div class="clearfix"></div>';
|
||||
$form[$form_key]['show_value']['#weight'] = -1;
|
||||
}
|
||||
|
||||
// If the form has only one group (for example, "Properties"), remove the
|
||||
// title and the fieldset, since there's no need to visually group values.
|
||||
$form_elements = element_get_visible_children($form);
|
||||
if (count($form_elements) == 1) {
|
||||
$element_key = reset($form_elements);
|
||||
unset($form[$element_key]['#type']);
|
||||
unset($form[$element_key]['#title']);
|
||||
|
||||
// Get a list of all elements in the group, and filter out the non-values.
|
||||
$values = element_get_visible_children($form[$element_key]);
|
||||
foreach ($values as $index => $key) {
|
||||
if ($key == 'show_value' || substr($key, 0, 1) == '_') {
|
||||
unset($values[$index]);
|
||||
}
|
||||
}
|
||||
// If the group has only one value, no need to hide it through #states.
|
||||
if (count($values) == 1) {
|
||||
$value_key = reset($values);
|
||||
$form[$element_key]['show_value'][$value_key]['#type'] = 'value';
|
||||
$form[$element_key]['show_value'][$value_key]['#value'] = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (module_exists('token') && $context['settings']['show_all_tokens']) {
|
||||
$token_type = str_replace('_', '-', $entity_type);
|
||||
$form['tokens'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => 'Available tokens',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 998,
|
||||
);
|
||||
$form['tokens']['tree'] = array(
|
||||
'#theme' => 'token_tree',
|
||||
'#token_types' => array($token_type, 'site'),
|
||||
'#global_types' => array(),
|
||||
'#dialog' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Action form validate function.
|
||||
*
|
||||
* Checks that the user selected at least one value to modify, validates
|
||||
* properties and calls Field API to validate fields for each bundle.
|
||||
*/
|
||||
function views_bulk_operations_modify_action_validate($form, &$form_state) {
|
||||
// The form structure for "Show" checkboxes is a bit bumpy.
|
||||
$search = array('properties');
|
||||
foreach ($form_state['entities'] as $bundle => $entity) {
|
||||
$search[] = 'bundle_' . $bundle;
|
||||
}
|
||||
|
||||
$has_selected = FALSE;
|
||||
foreach ($search as $group) {
|
||||
// Store names of selected and appended entity values in a nicer format.
|
||||
$form_state['selected'][$group] = array();
|
||||
$form_state['append'][$group] = array();
|
||||
|
||||
// This group has no values, move on.
|
||||
if (!isset($form_state['values'][$group])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($form_state['values'][$group]['show_value'] as $key => $value) {
|
||||
if ($value) {
|
||||
$has_selected = TRUE;
|
||||
$form_state['selected'][$group][] = $key;
|
||||
}
|
||||
if (!empty($form_state['values'][$group]['_append::' . $key])) {
|
||||
$form_state['append'][$group][] = $key;
|
||||
unset($form_state['values'][$group]['_append::' . $key]);
|
||||
}
|
||||
}
|
||||
unset($form_state['values'][$group]['show_value']);
|
||||
}
|
||||
|
||||
if (!$has_selected) {
|
||||
form_set_error('', t('You must select at least one value to modify.'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Use the wrapper to validate property values.
|
||||
if (!empty($form_state['selected']['properties'])) {
|
||||
// The entity used is irrelevant, and we can't rely on
|
||||
// $form_state['entities'] being non-empty, so a new one is created.
|
||||
$info = entity_get_info($form_state['entity_type']);
|
||||
$bundle_key = $info['entity keys']['bundle'];
|
||||
$default_values = array();
|
||||
// If the bundle key exists, it must always be set on an entity.
|
||||
if (!empty($bundle_key)) {
|
||||
$bundle_names = array_keys($info['bundles']);
|
||||
$bundle_name = reset($bundle_names);
|
||||
$default_values[$bundle_key] = $bundle_name;
|
||||
}
|
||||
$entity = entity_create($form_state['entity_type'], $default_values);
|
||||
$wrapper = entity_metadata_wrapper($form_state['entity_type'], $entity);
|
||||
|
||||
$properties = _views_bulk_operations_modify_action_get_properties($form_state['entity_type']);
|
||||
foreach ($form_state['selected']['properties'] as $key) {
|
||||
$value = $form_state['values']['properties'][$key];
|
||||
if (!$wrapper->$key->validate($value)) {
|
||||
$label = $properties[$key]['label'];
|
||||
form_set_error('properties][' . $key, t('%label contains an invalid value.', array('%label' => $label)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($form_state['entities'] as $bundle_name => $entity) {
|
||||
field_attach_form_validate($form_state['entity_type'], $entity, $form['bundle_' . $bundle_name], $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action form submit function.
|
||||
*
|
||||
* Fills each constructed entity with property and field values, then
|
||||
* passes them to views_bulk_operations_modify_action().
|
||||
*/
|
||||
function views_bulk_operations_modify_action_submit($form, $form_state) {
|
||||
foreach ($form_state['entities'] as $bundle_name => $entity) {
|
||||
field_attach_submit($form_state['entity_type'], $entity, $form['bundle_' . $bundle_name], $form_state);
|
||||
}
|
||||
|
||||
return array(
|
||||
'append' => $form_state['append'],
|
||||
'selected' => $form_state['selected'],
|
||||
'entities' => $form_state['entities'],
|
||||
'properties' => isset($form_state['values']['properties']) ? $form_state['values']['properties'] : array(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all properties that can be modified.
|
||||
*
|
||||
* Properties that can't be changed are entity keys, timestamps, and the ones
|
||||
* without a setter callback.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The entity type whose properties will be fetched.
|
||||
* @param $display_values
|
||||
* An optional, admin-provided list of properties and fields that should be
|
||||
* displayed for editing, used to filter the returned list of properties.
|
||||
*/
|
||||
function _views_bulk_operations_modify_action_get_properties($entity_type, $display_values = NULL) {
|
||||
$properties = array();
|
||||
$info = entity_get_info($entity_type);
|
||||
|
||||
// List of properties that can't be modified.
|
||||
$disabled_properties = array('created', 'changed');
|
||||
foreach (array('id', 'bundle', 'revision') as $key) {
|
||||
if (!empty($info['entity keys'][$key])) {
|
||||
$disabled_properties[] = $info['entity keys'][$key];
|
||||
}
|
||||
}
|
||||
// List of supported types.
|
||||
$supported_types = array('text', 'token', 'integer', 'decimal', 'date', 'duration',
|
||||
'boolean', 'uri', 'list');
|
||||
|
||||
$property_info = entity_get_property_info($entity_type);
|
||||
foreach ($property_info['properties'] as $key => $property) {
|
||||
if (in_array($key, $disabled_properties)) {
|
||||
continue;
|
||||
}
|
||||
// Filter out properties that can't be set (they are usually generated by a
|
||||
// getter callback based on other properties, and not stored in the DB).
|
||||
if (empty($property['setter callback'])) {
|
||||
continue;
|
||||
}
|
||||
// Determine the property type. If it's empty (permitted), default to text.
|
||||
// If it's a list type such as list<boolean>, extract the "boolean" part.
|
||||
$property['type'] = empty($property['type']) ? 'text' : $property['type'];
|
||||
$type = $property['type'];
|
||||
if ($list_type = entity_property_list_extract_type($type)) {
|
||||
$type = $list_type;
|
||||
$property['type'] = 'list';
|
||||
}
|
||||
// Filter out non-supported types (such as the Field API fields that
|
||||
// Commerce adds to its entities so that they show up in tokens).
|
||||
if (!in_array($type, $supported_types)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$properties[$key] = $property;
|
||||
}
|
||||
|
||||
if (isset($display_values) && empty($display_values[VBO_MODIFY_ACTION_ALL])) {
|
||||
// Return only the properties that the admin specified.
|
||||
return array_intersect_key($properties, $display_values);
|
||||
}
|
||||
|
||||
return $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all bundles for which field widgets should be displayed.
|
||||
*
|
||||
* If the admin decided to limit the modify form to certain properties / fields
|
||||
* (through the action settings) then only bundles that have at least one field
|
||||
* selected are returned.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The entity type whose bundles will be fetched.
|
||||
* @param $context
|
||||
* The VBO context variable.
|
||||
*/
|
||||
function _views_bulk_operations_modify_action_get_bundles($entity_type, $context) {
|
||||
$bundles = array();
|
||||
|
||||
$view = $context['view'];
|
||||
$display_values = $context['settings']['display_values'];
|
||||
$info = entity_get_info($entity_type);
|
||||
$bundle_key = $info['entity keys']['bundle'];
|
||||
// Check if this View has a filter on the bundle key and assemble a list
|
||||
// of allowed bundles according to the filter.
|
||||
$filtered_bundles = array();
|
||||
if (!empty($bundle_key) && isset($view->filter[$bundle_key]) && !empty($view->filter[$bundle_key]->value)) {
|
||||
$operator = $view->filter[$bundle_key]->operator;
|
||||
if ($operator == 'in') {
|
||||
$filtered_bundles = $view->filter[$bundle_key]->value;
|
||||
}
|
||||
elseif ($operator == 'not in') {
|
||||
$bundle_names = array_keys($info['bundles']);
|
||||
$filtered_bundles = array_diff($bundle_names, $view->filter[$bundle_key]->value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($info['bundles'] as $bundle_name => $bundle) {
|
||||
// The view is limited to specific bundles, but this bundle isn't one of
|
||||
// them. Ignore it.
|
||||
if (!empty($filtered_bundles) && !in_array($bundle_name, $filtered_bundles)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$instances = field_info_instances($entity_type, $bundle_name);
|
||||
// Ignore bundles that don't have any field instances attached.
|
||||
if (empty($instances)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$has_enabled_fields = FALSE;
|
||||
foreach ($display_values as $key) {
|
||||
if (strpos($key, $bundle_name . '::') !== FALSE) {
|
||||
$has_enabled_fields = TRUE;
|
||||
}
|
||||
}
|
||||
// The admin has either specified that all values should be modifiable, or
|
||||
// selected at least one field belonging to this bundle.
|
||||
if (!empty($display_values[VBO_MODIFY_ACTION_ALL]) || $has_enabled_fields) {
|
||||
$bundles[$bundle_name] = $bundle;
|
||||
}
|
||||
}
|
||||
|
||||
return $bundles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that recursively strips #required from field widgets.
|
||||
*/
|
||||
function _views_bulk_operations_modify_action_unset_required(&$element) {
|
||||
unset($element['#required']);
|
||||
foreach (element_children($element) as $key) {
|
||||
_views_bulk_operations_modify_action_unset_required($element[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* VBO settings form function.
|
||||
*/
|
||||
function views_bulk_operations_modify_action_views_bulk_operations_form_options() {
|
||||
$options['show_all_tokens'] = TRUE;
|
||||
$options['display_values'] = array(VBO_MODIFY_ACTION_ALL);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings form for this action.
|
||||
*/
|
||||
function views_bulk_operations_modify_action_views_bulk_operations_form($options, $entity_type, $dom_id) {
|
||||
// Initialize default values.
|
||||
if (empty($options)) {
|
||||
$options = views_bulk_operations_modify_action_views_bulk_operations_form_options();
|
||||
}
|
||||
|
||||
$form['show_all_tokens'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Show available tokens'),
|
||||
'#description' => t('Check this to show a list of all available tokens in the bottom of the form. Requires the token module.'),
|
||||
'#default_value' => $options['show_all_tokens'],
|
||||
);
|
||||
|
||||
$info = entity_get_info($entity_type);
|
||||
$properties = _views_bulk_operations_modify_action_get_properties($entity_type);
|
||||
$values = array(VBO_MODIFY_ACTION_ALL => t('- All -'));
|
||||
foreach ($properties as $key => $property) {
|
||||
$label = t('Properties');
|
||||
$values[$label][$key] = $property['label'];
|
||||
}
|
||||
foreach ($info['bundles'] as $bundle_name => $bundle) {
|
||||
$bundle_key = $info['entity keys']['bundle'];
|
||||
// Show the more detailed label only if the entity type has multiple bundles.
|
||||
// Otherwise, it would just be confusing.
|
||||
if (count($info['bundles']) > 1) {
|
||||
$label = t('Fields for @bundle_key @label', array('@bundle_key' => $bundle_key, '@label' => $bundle['label']));
|
||||
}
|
||||
else {
|
||||
$label = t('Fields');
|
||||
}
|
||||
|
||||
$instances = field_info_instances($entity_type, $bundle_name);
|
||||
foreach ($instances as $field_name => $field) {
|
||||
$values[$label][$bundle_name . '::' . $field_name] = $field['label'];
|
||||
}
|
||||
}
|
||||
|
||||
$form['display_values'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Display values'),
|
||||
'#options' => $values,
|
||||
'#multiple' => TRUE,
|
||||
'#description' => t('Select which values the action form should present to the user.'),
|
||||
'#default_value' => $options['display_values'],
|
||||
);
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
function views_bulk_operations_script_action_info() {
|
||||
$actions = array();
|
||||
$actions['views_bulk_operations_script_action'] = array(
|
||||
'type' => 'entity',
|
||||
'label' => t('Execute arbitrary PHP script'),
|
||||
'configurable' => TRUE,
|
||||
'triggers' => array('any'),
|
||||
);
|
||||
// Provide a strict default permission if actions_permissions is disabled.
|
||||
if (!module_exists('actions_permissions')) {
|
||||
$actions['views_bulk_operations_script_action']['permissions'] = array('administer site configuration');
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
function views_bulk_operations_script_action($entity, $context) {
|
||||
$return = eval($context['script']);
|
||||
if ($return === FALSE) {
|
||||
$msg = 'Error in script.';
|
||||
$arg = array();
|
||||
$error = error_get_last();
|
||||
if ($error) {
|
||||
$msg = '!err in script: !msg in line \'%line\'.';
|
||||
$arg = array(
|
||||
'!msg' => $error['message'],
|
||||
'%line' => _views_bulk_operations_script_action_error_line($context['script'], $error['line']),
|
||||
'!err' => _views_bulk_operations_script_action_error_type($error['type']),
|
||||
);
|
||||
}
|
||||
drupal_set_message(t($msg, $arg), 'error', FALSE);
|
||||
watchdog('actions', $msg, $arg, WATCHDOG_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
function views_bulk_operations_script_action_form($context) {
|
||||
$form['script'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('PHP script'),
|
||||
'#description' => t('Type the PHP snippet that will run upon execution of this action. You can use variables <code>$entity</code> and <code>$context</code> in your snippet.
|
||||
Note that it is up to the script to save the $entity once it\'s done modifying it.'),
|
||||
'#default_value' => @$context['script'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function views_bulk_operations_script_action_validate($form, $form_state) {
|
||||
}
|
||||
|
||||
function views_bulk_operations_script_action_submit($form, $form_state) {
|
||||
return array(
|
||||
'script' => $form_state['values']['script'],
|
||||
);
|
||||
}
|
||||
|
||||
function _views_bulk_operations_script_action_error_line($script, $line) {
|
||||
$lines = preg_split("/(\r?\n)/", $script);
|
||||
if (isset($lines[$line-1])) {
|
||||
return $lines[$line-1];
|
||||
}
|
||||
else {
|
||||
return t('Line !line', array('!line' => $line));
|
||||
}
|
||||
}
|
||||
|
||||
function _views_bulk_operations_script_action_error_type($type) {
|
||||
$types = array(
|
||||
E_ERROR => 'Error',
|
||||
E_WARNING => 'Warning',
|
||||
E_PARSE => 'Parsing Error',
|
||||
E_NOTICE => 'Notice',
|
||||
E_CORE_ERROR => 'Core Error',
|
||||
E_CORE_WARNING => 'Core Warning',
|
||||
E_COMPILE_ERROR => 'Compile Error',
|
||||
E_COMPILE_WARNING => 'Compile Warning',
|
||||
E_USER_ERROR => 'User Error',
|
||||
E_USER_WARNING => 'User Warning',
|
||||
E_USER_NOTICE => 'User Notice',
|
||||
E_STRICT => 'Runtime Notice',
|
||||
E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
|
||||
);
|
||||
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
||||
$types += array(
|
||||
E_DEPRECATED => 'Deprecated Notice',
|
||||
E_USER_DEPRECATED => 'User Deprecated Notice',
|
||||
);
|
||||
}
|
||||
|
||||
return t($types[$type]);
|
||||
}
|
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
function views_bulk_operations_user_roles_action_info() {
|
||||
return array('views_bulk_operations_user_roles_action' => array(
|
||||
'type' => 'user',
|
||||
'label' => t('Modify user roles'),
|
||||
'configurable' => TRUE,
|
||||
'triggers' => array('any'),
|
||||
));
|
||||
}
|
||||
|
||||
function views_bulk_operations_user_roles_action_form($context) {
|
||||
$roles = user_roles(TRUE);
|
||||
unset($roles[DRUPAL_AUTHENTICATED_RID]); // Can't edit authenticated role.
|
||||
|
||||
$form['add_roles'] = array(
|
||||
'#type' => 'select',
|
||||
'#multiple' => TRUE,
|
||||
'#title' => t('Add roles'),
|
||||
'#description' => t('Choose one or more roles you would like to assign to the selected users.'),
|
||||
'#options' => $roles,
|
||||
'#size' => 5
|
||||
);
|
||||
$form['remove_roles'] = array(
|
||||
'#type' => 'select',
|
||||
'#multiple' => TRUE,
|
||||
'#title' => t('Remove roles'),
|
||||
'#description' => t('Choose one or more roles you would like to remove from the selected users.'),
|
||||
'#options' => $roles,
|
||||
'#size' => 5
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
function views_bulk_operations_user_roles_action_validate($form, $form_state) {
|
||||
if (!$form_state['values']['add_roles'] && !$form_state['values']['remove_roles']) {
|
||||
form_set_error('add_roles', t('You have not chosen any role to add or remove. Please select something to do.'));
|
||||
}
|
||||
}
|
||||
|
||||
function views_bulk_operations_user_roles_action_submit($form, $form_state) {
|
||||
return array(
|
||||
'add_roles' => array_filter($form_state['values']['add_roles']),
|
||||
'remove_roles' => array_filter($form_state['values']['remove_roles']),
|
||||
);
|
||||
}
|
||||
|
||||
function views_bulk_operations_user_roles_action(&$user, $context) {
|
||||
$roles = $user->roles;
|
||||
$selected = (is_array($context['add_roles']) ? $context['add_roles'] : array()) +
|
||||
(is_array($context['remove_roles']) ? $context['remove_roles'] : array());
|
||||
$result = db_query("SELECT rid, name FROM {role} WHERE rid IN (:selected)", array(':selected' => array_keys($selected)));
|
||||
foreach ($result as $role) {
|
||||
if (isset($context['add_roles'][$role->rid])) {
|
||||
$add_roles[$role->rid] = $role->name;
|
||||
}
|
||||
if (isset($context['remove_roles'][$role->rid])) {
|
||||
$remove_roles[$role->rid] = $role->name;
|
||||
}
|
||||
}
|
||||
if (!empty($add_roles)) {
|
||||
$roles += $add_roles;
|
||||
}
|
||||
if (!empty($remove_roles)) {
|
||||
$roles = array_diff($roles, $remove_roles);
|
||||
}
|
||||
user_save($user, array('roles' => $roles));
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
name = Actions permissions (VBO)
|
||||
description = Provides permission-based access control for actions. Used by Views Bulk Operations.
|
||||
package = Administration
|
||||
core = 7.x
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-12-03
|
||||
version = "7.x-3.1"
|
||||
core = "7.x"
|
||||
project = "views_bulk_operations"
|
||||
datestamp = "1354500015"
|
||||
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function actions_permissions_permission() {
|
||||
$permissions = array();
|
||||
$actions = actions_list() + _actions_permissions_advanced_actions_list();
|
||||
foreach ($actions as $key => $action) {
|
||||
$permission = actions_permissions_get_perm($action['label'], $key);
|
||||
|
||||
$permissions[$permission] = array(
|
||||
'title' => t('Execute %label', array('%label' => $action['label'])),
|
||||
);
|
||||
}
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of advanced actions (created through the Action UI).
|
||||
*/
|
||||
function _actions_permissions_advanced_actions_list() {
|
||||
$actions = array();
|
||||
// Actions provided by Drupal that aren't usable in a VBO context.
|
||||
$hidden_actions = array(
|
||||
'system_block_ip_action',
|
||||
'system_goto_action',
|
||||
'system_message_action',
|
||||
);
|
||||
|
||||
$result = db_query("SELECT * FROM {actions} WHERE parameters > ''");
|
||||
foreach ($result as $action) {
|
||||
if (in_array($action->callback, $hidden_actions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$parameters = unserialize($action->parameters);
|
||||
$actions[$action->aid] = array(
|
||||
'label' => $action->label,
|
||||
'type' => $action->type,
|
||||
);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the permission name used in user_access().
|
||||
*/
|
||||
function actions_permissions_get_perm($label, $key) {
|
||||
return "execute $key";
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
div[class*="show-value"] {
|
||||
float: left;
|
||||
margin-right: 20px;
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
.vbo-select-all-markup, .vbo-table-select-all-markup {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* "Select all" for table styles. */
|
||||
.vbo-views-form thead .form-type-checkbox {
|
||||
margin: 0;
|
||||
}
|
||||
.vbo-table-select-all {
|
||||
display: none;
|
||||
}
|
||||
.views-table-row-select-all {
|
||||
display: none;
|
||||
}
|
||||
.views-table-row-select-all td {
|
||||
text-align: center;
|
||||
}
|
||||
.vbo-table-select-all-pages, .vbo-table-select-this-page {
|
||||
margin: 0 !important;
|
||||
padding: 2px 5px !important;
|
||||
}
|
||||
|
||||
/* Generic "select all" */
|
||||
.vbo-fieldset-select-all {
|
||||
text-align: center;
|
||||
width: 210px;
|
||||
padding: 0.6em 0;
|
||||
}
|
||||
.vbo-fieldset-select-all .form-item {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.vbo-fieldset-select-all div {
|
||||
padding: 0 !important;
|
||||
margin: 0 !important;
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
(function ($) {
|
||||
Drupal.behaviors.vbo = {
|
||||
attach: function(context) {
|
||||
$('.vbo-views-form', context).each(function() {
|
||||
Drupal.vbo.initTableBehaviors(this);
|
||||
Drupal.vbo.initGenericBehaviors(this);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Drupal.vbo = Drupal.vbo || {};
|
||||
Drupal.vbo.initTableBehaviors = function(form) {
|
||||
// If the table is not grouped, "Select all on this page / all pages"
|
||||
// markup gets inserted below the table header.
|
||||
var selectAllMarkup = $('.vbo-table-select-all-markup', form);
|
||||
if (selectAllMarkup.length) {
|
||||
$('.views-table > tbody', form).prepend('<tr class="views-table-row-select-all even">></tr>');
|
||||
var colspan = $('table th', form).length;
|
||||
$('.views-table-row-select-all', form).html('<td colspan="' + colspan + '">' + selectAllMarkup.html() + '</td>');
|
||||
|
||||
$('.vbo-table-select-all-pages', form).click(function() {
|
||||
Drupal.vbo.tableSelectAllPages(form);
|
||||
return false;
|
||||
});
|
||||
$('.vbo-table-select-this-page', form).click(function() {
|
||||
Drupal.vbo.tableSelectThisPage(form);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
$('.vbo-table-select-all', form).show();
|
||||
// This is the "select all" checkbox in (each) table header.
|
||||
$('.vbo-table-select-all', form).click(function() {
|
||||
var table = $(this).closest('table')[0];
|
||||
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', table).attr('checked', this.checked);
|
||||
|
||||
// Toggle the visibility of the "select all" row (if any).
|
||||
if (this.checked) {
|
||||
$('.views-table-row-select-all', table).show();
|
||||
}
|
||||
else {
|
||||
$('.views-table-row-select-all', table).hide();
|
||||
// Disable "select all across pages".
|
||||
Drupal.vbo.tableSelectThisPage(form);
|
||||
}
|
||||
});
|
||||
|
||||
// Set up the ability to click anywhere on the row to select it.
|
||||
$('.views-table tbody tr', form).click(function(event) {
|
||||
if (event.target.tagName.toLowerCase() != 'input' && event.target.tagName.toLowerCase() != 'a') {
|
||||
$('input[id^="edit-views-bulk-operations"]:not(:disabled)', this).each(function() {
|
||||
var checked = this.checked;
|
||||
// trigger() toggles the checkmark *after* the event is set,
|
||||
// whereas manually clicking the checkbox toggles it *beforehand*.
|
||||
// that's why we manually set the checkmark first, then trigger the
|
||||
// event (so that listeners get notified), then re-set the checkmark
|
||||
// which the trigger will have toggled. yuck!
|
||||
this.checked = !checked;
|
||||
$(this).trigger('click');
|
||||
this.checked = !checked;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Drupal.vbo.tableSelectAllPages = function(form) {
|
||||
$('.vbo-table-this-page', form).hide();
|
||||
$('.vbo-table-all-pages', form).show();
|
||||
// Modify the value of the hidden form field.
|
||||
$('.select-all-rows', form).val('1');
|
||||
}
|
||||
Drupal.vbo.tableSelectThisPage = function(form) {
|
||||
$('.vbo-table-all-pages', form).hide();
|
||||
$('.vbo-table-this-page', form).show();
|
||||
// Modify the value of the hidden form field.
|
||||
$('.select-all-rows', form).val('0');
|
||||
}
|
||||
|
||||
Drupal.vbo.initGenericBehaviors = function(form) {
|
||||
// Show the "select all" fieldset.
|
||||
$('.vbo-select-all-markup', form).show();
|
||||
|
||||
$('.vbo-select-this-page', form).click(function() {
|
||||
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked);
|
||||
$('.vbo-select-all-pages', form).attr('checked', false);
|
||||
|
||||
// Toggle the "select all" checkbox in grouped tables (if any).
|
||||
$('.vbo-table-select-all', form).attr('checked', this.checked);
|
||||
});
|
||||
$('.vbo-select-all-pages', form).click(function() {
|
||||
$('input[id^="edit-views-bulk-operations"]', form).attr('checked', this.checked);
|
||||
$('.vbo-select-this-page', form).attr('checked', false);
|
||||
|
||||
// Toggle the "select all" checkbox in grouped tables (if any).
|
||||
$('.vbo-table-select-all', form).attr('checked', this.checked);
|
||||
|
||||
// Modify the value of the hidden form field.
|
||||
$('.select-all-rows', form).val(this.checked);
|
||||
});
|
||||
|
||||
$('.vbo-select', form).click(function() {
|
||||
// If a checkbox was deselected, uncheck any "select all" checkboxes.
|
||||
if (!this.checked) {
|
||||
$('.vbo-select-this-page', form).attr('checked', false);
|
||||
$('.vbo-select-all-pages', form).attr('checked', false);
|
||||
// Modify the value of the hidden form field.
|
||||
$('.select-all-rows', form).val('0')
|
||||
|
||||
var table = $(this).closest('table')[0];
|
||||
if (table) {
|
||||
// Uncheck the "select all" checkbox in the table header.
|
||||
$('.vbo-table-select-all', table).attr('checked', false);
|
||||
|
||||
// If there's a "select all" row, hide it.
|
||||
if ($('.vbo-table-select-this-page', table).length) {
|
||||
$('.views-table-row-select-all', table).hide();
|
||||
// Disable "select all across pages".
|
||||
Drupal.vbo.tableSelectThisPage(form);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
})(jQuery);
|
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines the class for core actions.
|
||||
* Belongs to the "action" operation type plugin.
|
||||
*/
|
||||
|
||||
class ViewsBulkOperationsAction extends ViewsBulkOperationsBaseOperation {
|
||||
|
||||
/**
|
||||
* Contains the options provided by the user in the configuration form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $formOptions = array();
|
||||
|
||||
/**
|
||||
* Returns the access bitmask for the operation, used for entity access checks.
|
||||
*/
|
||||
public function getAccessMask() {
|
||||
// Assume edit by default.
|
||||
if (!isset($this->operationInfo['behavior'])) {
|
||||
$this->operationInfo['behavior'] = array('changes_property');
|
||||
}
|
||||
|
||||
$mask = 0;
|
||||
if (in_array('views_property', $this->operationInfo['behavior'])) {
|
||||
$mask |= VBO_ACCESS_OP_VIEW;
|
||||
}
|
||||
if (in_array('changes_property', $this->operationInfo['behavior'])) {
|
||||
$mask |= VBO_ACCESS_OP_UPDATE;
|
||||
}
|
||||
if (in_array('creates_property', $this->operationInfo['behavior'])) {
|
||||
$mask |= VBO_ACCESS_OP_CREATE;
|
||||
}
|
||||
if (in_array('deletes_property', $this->operationInfo['behavior'])) {
|
||||
$mask |= VBO_ACCESS_OP_DELETE;
|
||||
}
|
||||
return $mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the provided account has access to execute the operation.
|
||||
*
|
||||
* @param $account
|
||||
*/
|
||||
public function access($account) {
|
||||
// Use actions_permissions if enabled.
|
||||
if (module_exists('actions_permissions')) {
|
||||
$perm = actions_permissions_get_perm($this->operationInfo['label'], $this->operationInfo['key']);
|
||||
if (!user_access($perm, $account)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
// Check against additional permissions.
|
||||
if (!empty($this->operationInfo['permissions'])) {
|
||||
foreach ($this->operationInfo['permissions'] as $perm) {
|
||||
if (!user_access($perm, $account)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Access granted.
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration form for the operation.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
* @param $context
|
||||
* An array of related data provided by the caller.
|
||||
*/
|
||||
public function form($form, &$form_state, array $context) {
|
||||
// Some modules (including this one) place their action callbacks
|
||||
// into separate files. At this point those files might no longer be
|
||||
// included due to an #ajax rebuild, so we call actions_list() to trigger
|
||||
// inclusion. The same thing is done by actions_do() on execute.
|
||||
actions_list();
|
||||
|
||||
$context['settings'] = $this->getAdminOption('settings', array());
|
||||
$form_callback = $this->operationInfo['callback'] . '_form';
|
||||
return $form_callback($context, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the configuration form.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
*/
|
||||
public function formValidate($form, &$form_state) {
|
||||
// Some modules (including this one) place their action callbacks
|
||||
// into separate files. At this point those files might no longer be
|
||||
// included due to a page reload, so we call actions_list() to trigger
|
||||
// inclusion. The same thing is done by actions_do() on execute.
|
||||
actions_list();
|
||||
|
||||
$validation_callback = $this->operationInfo['callback'] . '_validate';
|
||||
if (function_exists($validation_callback)) {
|
||||
$validation_callback($form, $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the submitted configuration form.
|
||||
* This is where the operation can transform and store the submitted data.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
*/
|
||||
public function formSubmit($form, &$form_state) {
|
||||
// Some modules (including this one) place their action callbacks
|
||||
// into separate files. At this point those files might no longer be
|
||||
// included due to a page reload, so we call actions_list() to trigger
|
||||
// inclusion. The same thing is done by actions_do() on execute.
|
||||
actions_list();
|
||||
|
||||
$submit_callback = $this->operationInfo['callback'] . '_submit';
|
||||
$this->formOptions = $submit_callback($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the admin options form for the operation.
|
||||
*
|
||||
* The admin options form is embedded into the VBO field settings and used
|
||||
* to configure operation behavior. The options can later be fetched
|
||||
* through the getAdminOption() method.
|
||||
*
|
||||
* @param $dom_id
|
||||
* The dom path to the level where the admin options form is embedded.
|
||||
* Needed for #dependency.
|
||||
*/
|
||||
public function adminOptionsForm($dom_id) {
|
||||
$form = parent::adminOptionsForm($dom_id);
|
||||
|
||||
$settings_form_callback = $this->operationInfo['callback'] . '_views_bulk_operations_form';
|
||||
if (function_exists($settings_form_callback)) {
|
||||
$settings = $this->getAdminOption('settings', array());
|
||||
|
||||
$form['settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Operation settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#dependency' => array(
|
||||
$dom_id . '-selected' => array(1),
|
||||
),
|
||||
);
|
||||
$settings_dom_id = $dom_id . '-settings';
|
||||
$form['settings'] += $settings_form_callback($settings, $this->entityType, $settings_dom_id);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the admin options form.
|
||||
*
|
||||
* @param $form
|
||||
* The admin options form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form. Note that this array
|
||||
* is constructed by the VBO views field handler, so it's not a real form
|
||||
* state, it contains only the 'values' key.
|
||||
* @param $error_element_base
|
||||
* The base to prepend to field names when using form_set_error().
|
||||
* Needed because the admin settings form is embedded into a bigger form.
|
||||
*/
|
||||
public function adminOptionsFormValidate($form, &$form_state, $error_element_base) {
|
||||
parent::adminOptionsFormValidate($form, $form_state, $error_element_base);
|
||||
|
||||
if (!empty($form['settings'])) {
|
||||
$settings_validation_callback = $this->operationInfo['callback'] . '_views_bulk_operations_form_validate';
|
||||
if (function_exists($settings_validation_callback)) {
|
||||
$fake_form = $form['settings'];
|
||||
$fake_form_state = array('values' => &$form_state['values']['settings']);
|
||||
$error_element_base .= 'settings][';
|
||||
|
||||
$settings_validation_callback($fake_form, $fake_form_state, $error_element_base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the submitted admin options form.
|
||||
* Note that there is no need to handle saving the options, that is done
|
||||
* by the VBO views field handler, which also injects the options into the
|
||||
* operation object upon instantiation.
|
||||
*
|
||||
* @param $form
|
||||
* The admin options form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form. Note that this array
|
||||
* is constructed by the VBO views field handler, so it's not a real form
|
||||
* state, it contains only the 'values' key.
|
||||
*/
|
||||
public function adminOptionsFormSubmit($form, &$form_state) {
|
||||
parent::adminOptionsFormSubmit($form, $form_state);
|
||||
|
||||
if (!empty($form['settings'])) {
|
||||
$settings_submit_callback = $this->operationInfo['callback'] . '_views_bulk_operations_form_submit';
|
||||
if (function_exists($settings_submit_callback)) {
|
||||
$fake_form = $form['settings'];
|
||||
$fake_form_state = array('values' => &$form_state['values']['settings']);
|
||||
|
||||
$settings_submit_callback($form, $form_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the operation needs the full selected views rows to be
|
||||
* passed to execute() as a part of $context.
|
||||
*/
|
||||
public function needsRows() {
|
||||
return !empty($this->operationInfo['pass rows']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the selected operation on the provided data.
|
||||
*
|
||||
* @param $data
|
||||
* The data to to operate on. An entity or an array of entities.
|
||||
* @param $context
|
||||
* An array of related data (selected views rows, etc).
|
||||
*/
|
||||
public function execute($data, array $context) {
|
||||
$context['entity_type'] = $this->entityType;
|
||||
$context['settings'] = $this->getAdminOption('settings', array());
|
||||
$context += $this->formOptions;
|
||||
$context += $this->operationInfo['parameters'];
|
||||
// Actions provided by the Drupal system module require the entity to be
|
||||
// present in $context, keyed by entity type.
|
||||
if (is_object($data)) {
|
||||
$context[$this->entityType] = $data;
|
||||
}
|
||||
|
||||
actions_do($this->operationInfo['callback'], $data, $context);
|
||||
|
||||
// The action might need to have its entities saved after execution.
|
||||
if (in_array('changes_property', $this->operationInfo['behavior'])) {
|
||||
$data = is_array($data) ? $data : array($data);
|
||||
foreach ($data as $entity) {
|
||||
entity_save($this->entityType, $entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CTools plugin. Provides support for core actions.
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t('Action'),
|
||||
'list callback' => 'views_bulk_operations_operation_action_list',
|
||||
'handler' => array(
|
||||
'file' => 'action.class.php',
|
||||
'class' => 'ViewsBulkOperationsAction',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a prepared list of available actions.
|
||||
*
|
||||
* Actions are fetched by invoking hook_action_info() and by loading
|
||||
* advanced actions from the database.
|
||||
*
|
||||
* @param $operation_id
|
||||
* The full, prefixed operation_id of the operation (in this case, action)
|
||||
* to return, or NULL to return an array with all operations.
|
||||
*/
|
||||
function views_bulk_operations_operation_action_list($operation_id = NULL) {
|
||||
$operations = &drupal_static(__FUNCTION__);
|
||||
|
||||
if (!isset($operations)) {
|
||||
// Combined list of all actions and advanced actions.
|
||||
$actions_list = actions_list() + views_bulk_operations_operation_advanced_action_list();
|
||||
// Actions provided by Drupal that aren't usable in a VBO context.
|
||||
$hidden_actions = array(
|
||||
'system_block_ip_action',
|
||||
'system_goto_action',
|
||||
'system_message_action',
|
||||
);
|
||||
|
||||
$operations = array();
|
||||
foreach ($actions_list as $key => $action) {
|
||||
// Actions are keyed by callback.
|
||||
// Advanced actions are keyed by aid and store the callback separately.
|
||||
$callback = isset($action['callback']) ? $action['callback'] : $key;
|
||||
// This action needs to be skipped.
|
||||
if (in_array($callback, $hidden_actions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// All operations must be prefixed with the operation type.
|
||||
$new_operation_id = 'action::' . $key;
|
||||
|
||||
$operations[$new_operation_id] = array(
|
||||
'operation_type' => 'action',
|
||||
'type' => $action['type'],
|
||||
// Keep the unprefixed key around, for internal use.
|
||||
'key' => $key,
|
||||
'callback' => $callback,
|
||||
'label' => isset($action['label']) ? $action['label'] : '',
|
||||
'parameters' => isset($action['parameters']) ? $action['parameters'] : array(),
|
||||
'configurable' => !empty($action['configurable']) || !empty($action['vbo_configurable']),
|
||||
'aggregate' => !empty($action['aggregate']),
|
||||
'behavior' => isset($action['behavior']) ? $action['behavior'] : array(),
|
||||
'permissions' => isset($action['permissions']) ? $action['permissions'] : NULL,
|
||||
'pass rows' => !empty($action['pass rows']),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($operation_id)) {
|
||||
return isset($operations[$operation_id]) ? $operations[$operation_id] : FALSE;
|
||||
}
|
||||
else {
|
||||
return $operations;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of advanced actions (created through the Action UI).
|
||||
*/
|
||||
function views_bulk_operations_operation_advanced_action_list() {
|
||||
$actions = array();
|
||||
$static_actions = actions_list();
|
||||
$result = db_query("SELECT * FROM {actions} WHERE parameters > ''");
|
||||
foreach ($result as $action) {
|
||||
$parameters = unserialize($action->parameters);
|
||||
$actions[$action->aid] = array(
|
||||
'label' => isset($action->label) ? $action->label : '',
|
||||
'callback' => $action->callback,
|
||||
'type' => $action->type,
|
||||
'configurable' => FALSE,
|
||||
'parameters' => $parameters,
|
||||
);
|
||||
foreach (array('aggregate', 'behavior', 'permissions', 'pass rows') as $attribute) {
|
||||
if (isset($static_actions[$action->callback][$attribute])) {
|
||||
$actions[$action->aid][$attribute] = $static_actions[$action->callback][$attribute];
|
||||
}
|
||||
}
|
||||
if (isset($static_actions[$action->callback]['parameters'])) {
|
||||
$actions[$action->aid]['parameters'] = array_merge($actions[$action->aid]['parameters'], $static_actions[$action->callback]['parameters']);
|
||||
}
|
||||
}
|
||||
return $actions;
|
||||
}
|
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines the base class for operations.
|
||||
*/
|
||||
|
||||
abstract class ViewsBulkOperationsBaseOperation {
|
||||
|
||||
/**
|
||||
* The id of the operation.
|
||||
*
|
||||
* Composed of the operation_type plugin name and the operation key,
|
||||
* divided by '::'. For example: action::node_publish_action.
|
||||
*/
|
||||
public $operationId;
|
||||
|
||||
/**
|
||||
* The entity type that the operation is operating on.
|
||||
*
|
||||
* Not the same as $operationInfo['type'] since that value can be just
|
||||
* "entity", which means "available to every entity type".
|
||||
*/
|
||||
public $entityType;
|
||||
|
||||
/**
|
||||
* Contains information about the current operation, as generated
|
||||
* by the "list callback" function in the plugin file.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $operationInfo;
|
||||
|
||||
/**
|
||||
* Contains the options set by the admin for the current operation.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $adminOptions;
|
||||
|
||||
/**
|
||||
* Constructs an operation object.
|
||||
*
|
||||
* @param $operationId
|
||||
* The id of the operation.
|
||||
* @param $entityType
|
||||
* The entity type that the operation is operating on.
|
||||
* @param $operationInfo
|
||||
* An array of information about the operation.
|
||||
* @param $adminOptions
|
||||
* An array of options set by the admin.
|
||||
*/
|
||||
public function __construct($operationId, $entityType, array $operationInfo, array $adminOptions) {
|
||||
$this->operationId = $operationId;
|
||||
$this->entityType = $entityType;
|
||||
$this->operationInfo = $operationInfo;
|
||||
$this->adminOptions = $adminOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of an admin option.
|
||||
*/
|
||||
public function getAdminOption($key, $default = NULL) {
|
||||
return isset($this->adminOptions[$key]) ? $this->adminOptions[$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the access bitmask for the operation, used for entity access checks.
|
||||
*/
|
||||
public function getAccessMask() {
|
||||
// Assume edit by default.
|
||||
return VBO_ACCESS_OP_UPDATE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id of the operation.
|
||||
*/
|
||||
public function id() {
|
||||
return $this->operationId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the operation_type plugin that provides the operation.
|
||||
*/
|
||||
public function type() {
|
||||
return $this->operationInfo['operation_type'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the human-readable name of the operation, meant to be shown
|
||||
* to the user.
|
||||
*/
|
||||
public function label() {
|
||||
$admin_label = $this->getAdminOption('label');
|
||||
if (!empty($admin_label)) {
|
||||
$label = t($admin_label);
|
||||
}
|
||||
else {
|
||||
// If the admin didn't specify any label, fallback to the default one.
|
||||
$label = $this->operationInfo['label'];
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the human-readable name of the operation, meant to be shown
|
||||
* to the admin.
|
||||
*/
|
||||
public function adminLabel() {
|
||||
return $this->operationInfo['label'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the operation is configurable. Used to determine
|
||||
* whether the operation's form methods should be invoked.
|
||||
*/
|
||||
public function configurable() {
|
||||
return !empty($this->operationInfo['configurable']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the provided account has access to execute the operation.
|
||||
*
|
||||
* @param $account
|
||||
*/
|
||||
public function access($account) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration form for the operation.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
* @param $context
|
||||
* An array of related data provided by the caller.
|
||||
*/
|
||||
abstract function form($form, &$form_state, array $context);
|
||||
|
||||
/**
|
||||
* Validates the configuration form.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
*/
|
||||
abstract function formValidate($form, &$form_state);
|
||||
|
||||
/**
|
||||
* Handles the submitted configuration form.
|
||||
* This is where the operation can transform and store the submitted data.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
*/
|
||||
abstract function formSubmit($form, &$form_state);
|
||||
|
||||
/**
|
||||
* Returns the admin options form for the operation.
|
||||
*
|
||||
* The admin options form is embedded into the VBO field settings and used
|
||||
* to configure operation behavior. The options can later be fetched
|
||||
* through the getAdminOption() method.
|
||||
*
|
||||
* @param $dom_id
|
||||
* The dom path to the level where the admin options form is embedded.
|
||||
* Needed for #dependency.
|
||||
*/
|
||||
public function adminOptionsForm($dom_id) {
|
||||
$label = $this->getAdminOption('label', '');
|
||||
|
||||
$form = array();
|
||||
$form['override_label'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Override label'),
|
||||
'#default_value' => $label !== '',
|
||||
'#dependency' => array(
|
||||
$dom_id . '-selected' => array(1),
|
||||
),
|
||||
);
|
||||
$form['label'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Provide label'),
|
||||
'#title_display' => 'invisible',
|
||||
'#default_value' => $label,
|
||||
'#dependency' => array(
|
||||
$dom_id . '-selected' => array(1),
|
||||
$dom_id . '-override-label' => array(1),
|
||||
),
|
||||
'#dependency_count' => 2,
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the admin options form.
|
||||
*
|
||||
* @param $form
|
||||
* The admin options form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form. Note that this array
|
||||
* is constructed by the VBO views field handler, so it's not a real form
|
||||
* state, it contains only the 'values' key.
|
||||
* @param $error_element_base
|
||||
* The base to prepend to field names when using form_set_error().
|
||||
* Needed because the admin options form is embedded into a bigger form.
|
||||
*/
|
||||
public function adminOptionsFormValidate($form, &$form_state, $error_element_base) {
|
||||
// No need to do anything, but make the function have a body anyway
|
||||
// so that it's callable by overriding methods.
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the submitted admin options form.
|
||||
* Note that there is no need to handle saving the options, that is done
|
||||
* by the VBO views field handler, which also injects the options into the
|
||||
* operation object upon instantiation.
|
||||
*
|
||||
* @param $form
|
||||
* The admin options form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form. Note that this array
|
||||
* is constructed by the VBO views field handler, so it's not a real form
|
||||
* state, it contains only the 'values' key.
|
||||
*/
|
||||
public function adminOptionsFormSubmit($form, &$form_state) {
|
||||
// If the "Override label" checkbox was deselected, clear the entered value.
|
||||
if (empty($form_state['values']['override_label'])) {
|
||||
$form_state['values']['label'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the selected entities should be aggregated
|
||||
* (loaded in bulk and passed in together).
|
||||
* To be avoided if possible, since aggregation makes it impossible to use
|
||||
* Batch API or the Drupal Queue for execution.
|
||||
*/
|
||||
public function aggregate() {
|
||||
return !empty($this->operationInfo['aggregate']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the operation needs the full selected views rows to be
|
||||
* passed to execute() as a part of $context.
|
||||
*/
|
||||
public function needsRows() {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the selected operation on the provided data.
|
||||
*
|
||||
* @param $data
|
||||
* The data to to operate on. An entity or an array of entities.
|
||||
* @param $context
|
||||
* An array of related data (selected views rows, etc).
|
||||
*/
|
||||
abstract function execute($data, array $context);
|
||||
}
|
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines the class for rules components (rule, ruleset, action).
|
||||
* Belongs to the "rules_component" operation type plugin.
|
||||
*/
|
||||
|
||||
class ViewsBulkOperationsRulesComponent extends ViewsBulkOperationsBaseOperation {
|
||||
|
||||
/**
|
||||
* Returns the access bitmask for the operation, used for entity access checks.
|
||||
*
|
||||
* Rules has its own permission system, so the lowest bitmask is enough.
|
||||
*/
|
||||
public function getAccessMask() {
|
||||
return VBO_ACCESS_OP_VIEW;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the provided account has access to execute the operation.
|
||||
*
|
||||
* @param $account
|
||||
*/
|
||||
public function access($account) {
|
||||
return rules_action('component_' . $this->operationInfo['key'])->access();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration form for the operation.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
* @param $context
|
||||
* An array of related data provided by the caller.
|
||||
*/
|
||||
public function form($form, &$form_state, array $context) {
|
||||
$entity_key = $this->operationInfo['parameters']['entity_key'];
|
||||
// List types need to match the original, so passing list<node> instead of
|
||||
// list<entity> won't work. However, passing 'node' instead of 'entity'
|
||||
// will work, and is needed in order to get the right tokens.
|
||||
$list_type = 'list<' . $this->operationInfo['type'] . '>';
|
||||
$entity_type = $this->aggregate() ? $list_type : $this->entityType;
|
||||
$info = entity_get_info($this->entityType);
|
||||
|
||||
// The component action is wrapped in an action set using the entity, so
|
||||
// that the action configuration form can make use of the entity e.g. for
|
||||
// tokens.
|
||||
$set = rules_action_set(array($entity_key => array('type' => $entity_type, 'label' => $info['label'])));
|
||||
$action = rules_action('component_' . $this->operationInfo['key'], array($entity_key . ':select' => $entity_key));
|
||||
$set->action($action);
|
||||
|
||||
// Embed the form of the component action, but default to "input" mode for
|
||||
// all parameters if available.
|
||||
foreach ($action->parameterInfo() as $name => $info) {
|
||||
$form_state['parameter_mode'][$name] = 'input';
|
||||
}
|
||||
$action->form($form, $form_state);
|
||||
|
||||
// Remove the configuration form element for the "entity" param, as it
|
||||
// should just use the passed in entity.
|
||||
unset($form['parameter'][$entity_key]);
|
||||
|
||||
// Tweak direct input forms to be more end-user friendly.
|
||||
foreach ($action->parameterInfo() as $name => $info) {
|
||||
// Remove the fieldset and move its title to the form element.
|
||||
if (isset($form['parameter'][$name]['settings'][$name]['#title'])) {
|
||||
$form['parameter'][$name]['#type'] = 'container';
|
||||
$form['parameter'][$name]['settings'][$name]['#title'] = $form['parameter'][$name]['#title'];
|
||||
}
|
||||
// Hide the switch button if it's there.
|
||||
if (isset($form['parameter'][$name]['switch_button'])) {
|
||||
$form['parameter'][$name]['switch_button']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the configuration form.
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
*/
|
||||
public function formValidate($form, &$form_state) {
|
||||
rules_ui_form_rules_config_validate($form, $form_state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the rules element added to the form state in form(), so that it
|
||||
* can be used in execute().
|
||||
* Only called if the operation is declared as configurable.
|
||||
*
|
||||
* @param $form
|
||||
* The views form.
|
||||
* @param $form_state
|
||||
* An array containing the current state of the form.
|
||||
*/
|
||||
public function formSubmit($form, &$form_state) {
|
||||
$this->rulesElement = $form_state['rules_element']->root();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the selected operation on the provided data.
|
||||
*
|
||||
* @param $data
|
||||
* The data to to operate on. An entity or an array of entities.
|
||||
* @param $context
|
||||
* An array of related data (selected views rows, etc).
|
||||
*/
|
||||
public function execute($data, array $context) {
|
||||
// If there was a config form, there's a rules_element.
|
||||
// If not, fallback to the component key.
|
||||
if ($this->configurable()) {
|
||||
$element = $this->rulesElement;
|
||||
}
|
||||
else {
|
||||
$element = rules_action('component_' . $this->operationInfo['parameters']['component_key']);
|
||||
}
|
||||
$element->execute($data);
|
||||
}
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* CTools plugin. Provides support for rules components (rule, ruleset, action).
|
||||
*/
|
||||
|
||||
$plugin = array(
|
||||
'title' => t('Rules component'),
|
||||
'list callback' => 'views_bulk_operations_operation_rules_component_list',
|
||||
'handler' => array(
|
||||
'file' => 'rules_component.class.php',
|
||||
'class' => 'ViewsBulkOperationsRulesComponent',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns a prepared list of available rules components.
|
||||
*
|
||||
* @param $operation_id
|
||||
* The full, prefixed operation_id of the operation (in this case, rules
|
||||
* component) to return, or NULL to return an array with all operations.
|
||||
*/
|
||||
function views_bulk_operations_operation_rules_component_list($operation_id = NULL) {
|
||||
if (!module_exists('rules')) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$entity_info = entity_get_info();
|
||||
$entity_types = array_keys($entity_info);
|
||||
$supported_types = array('entity', 'list<entity>');
|
||||
$list_types = array('list<entity>');
|
||||
foreach ($entity_types as $type) {
|
||||
$supported_types[] = $type;
|
||||
$supported_types[] = "list<$type>";
|
||||
$list_types[] = "list<$type>";
|
||||
}
|
||||
|
||||
$components = array();
|
||||
if (isset($operation_id)) {
|
||||
$id_fragments = explode('::', $operation_id);
|
||||
$components[$id_fragments[1]] = rules_config_load($id_fragments[1]);
|
||||
// No need to go any further if the component no longer exists.
|
||||
if (!$components[$id_fragments[1]]) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$components = rules_get_components(FALSE, 'action');
|
||||
}
|
||||
|
||||
$operations = array();
|
||||
foreach ($components as $name => $component) {
|
||||
$parameter_info = $component->parameterInfo();
|
||||
$first_parameter = reset($parameter_info);
|
||||
$parameter_keys = array_keys($parameter_info);
|
||||
$entity_key = reset($parameter_keys);
|
||||
// If the first param is not an entity type, skip the component.
|
||||
if (!in_array($first_parameter['type'], $supported_types)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// If the first parameter is a list type (list<node>, list<entity>, etc)
|
||||
// then turn aggregation on, and set the correct entity type.
|
||||
if (in_array($first_parameter['type'], $list_types)) {
|
||||
$type = str_replace(array('list<', '>'), '', $first_parameter['type']);
|
||||
$aggregate = TRUE;
|
||||
}
|
||||
else {
|
||||
$type = $first_parameter['type'];
|
||||
$aggregate = FALSE;
|
||||
}
|
||||
|
||||
// All operations must be prefixed with the operation type.
|
||||
$new_operation_id = 'rules_component::' . $name;
|
||||
$operations[$new_operation_id] = array(
|
||||
'operation_type' => 'rules_component',
|
||||
// Keep the unprefixed key around, for internal use.
|
||||
'key' => $name,
|
||||
'label' => $component->label,
|
||||
'parameters' => array('component_key' => $name, 'entity_key' => $entity_key),
|
||||
'configurable' => count($parameter_info) > 1,
|
||||
'type' => $type,
|
||||
'aggregate' => $aggregate,
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($operation_id)) {
|
||||
return isset($operations[$operation_id]) ? $operations[$operation_id] : FALSE;
|
||||
}
|
||||
else {
|
||||
return $operations;
|
||||
}
|
||||
}
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_views_data_alter().
|
||||
*/
|
||||
function views_bulk_operations_views_data_alter(&$data) {
|
||||
foreach (entity_get_info() as $entity_type => $info) {
|
||||
if (isset($info['base table']) && isset($data[$info['base table']]['table'])) {
|
||||
$data[$info['base table']]['views_bulk_operations'] = array(
|
||||
'title' => $data[$info['base table']]['table']['group'],
|
||||
'group' => t('Bulk operations'),
|
||||
'help' => t('Provide a checkbox to select the row for bulk operations.'),
|
||||
'real field' => $info['entity keys']['id'],
|
||||
'field' => array(
|
||||
'handler' => 'views_bulk_operations_handler_field_operations',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (isset($info['revision table']) && isset($data[$info['revision table']]['table'])) {
|
||||
$data[$info['revision table']]['views_bulk_operations'] = array(
|
||||
'title' => $data[$info['revision table']]['table']['group'],
|
||||
'group' => t('Bulk operations'),
|
||||
'help' => t('Provide a checkbox to select the row for bulk operations.'),
|
||||
'real field' => $info['entity keys']['revision'],
|
||||
'field' => array(
|
||||
'handler' => 'views_bulk_operations_handler_field_operations',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,301 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views field handler. Contains all relevant VBO options and related logic.
|
||||
* Implements the Views Form API.
|
||||
*/
|
||||
|
||||
class views_bulk_operations_handler_field_operations extends views_handler_field {
|
||||
var $revision = FALSE;
|
||||
|
||||
function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
|
||||
// Update old settings
|
||||
if (!empty($options['vbo']) && empty($this->options['vbo_operations'])) {
|
||||
$this->options['vbo_operations'] = $options['vbo']['operations'];
|
||||
unset($options['vbo']['operations']);
|
||||
$this->options['vbo_settings'] = $options['vbo'] + $this->options['vbo_settings'];
|
||||
}
|
||||
// When updating old Views it is possible for this value to stay empty.
|
||||
if (empty($this->options['vbo_settings']['entity_load_capacity'])) {
|
||||
$this->options['vbo_settings']['entity_load_capacity'] = 10;
|
||||
}
|
||||
|
||||
foreach ($this->options['vbo_operations'] as $operation_id => &$operation_options) {
|
||||
// Prefix all un-prefixed operations.
|
||||
if (strpos($operation_id, '::') === FALSE) {
|
||||
$operations = views_bulk_operations_get_operation_info();
|
||||
// Basically, guess.
|
||||
foreach (array('action', 'rules_component') as $operation_type) {
|
||||
$new_operation_id = $operation_type . '::' . $operation_id;
|
||||
if (isset($operations[$new_operation_id])) {
|
||||
$this->options['vbo_operations'][$new_operation_id] = $operation_options;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the old operation in any case.
|
||||
unset($this->options['vbo_operations'][$operation_id]);
|
||||
}
|
||||
|
||||
// Rename the use_queue setting.
|
||||
if (isset($operation_options['use_queue']) && !isset($operation_options['postpone_processing'])) {
|
||||
$operation_options['postpone_processing'] = $operation_options['use_queue'];
|
||||
unset($operation_options['use_queue']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['vbo_settings'] = array(
|
||||
'contains' => array(
|
||||
'display_type' => array('default' => 0),
|
||||
'enable_select_all_pages' => array('default' => TRUE),
|
||||
'force_single' => array('default' => FALSE),
|
||||
'entity_load_capacity' => array('default' => 10),
|
||||
),
|
||||
);
|
||||
$options['vbo_operations'] = array(
|
||||
'default' => array(),
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['vbo_settings'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Bulk operations settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['vbo_settings']['display_type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Display operations as'),
|
||||
'#default_value' => $this->options['vbo_settings']['display_type'],
|
||||
'#options' => array(
|
||||
t('Dropdown selectbox with Submit button'),
|
||||
t('Each action as a separate button'),
|
||||
),
|
||||
);
|
||||
$form['vbo_settings']['enable_select_all_pages'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable "Select all items on all pages"'),
|
||||
'#default_value' => $this->options['vbo_settings']['enable_select_all_pages'],
|
||||
'#description' => t('Check this box to enable the ability to select all items on all pages.'),
|
||||
);
|
||||
$form['vbo_settings']['force_single'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Force single'),
|
||||
'#default_value' => $this->options['vbo_settings']['force_single'],
|
||||
'#description' => t('Check this box to restrict selection to a single value.'),
|
||||
);
|
||||
$form['vbo_settings']['entity_load_capacity'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Number of entities to load at once'),
|
||||
'#description' => t("Improve execution performance at the cost of memory usage. Set to '1' if you're having problems."),
|
||||
'#default_value' => $this->options['vbo_settings']['entity_load_capacity'],
|
||||
);
|
||||
|
||||
// Display operations and their settings.
|
||||
$form['vbo_operations'] = array(
|
||||
'#tree' => TRUE,
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Selected bulk operations'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => FALSE,
|
||||
);
|
||||
|
||||
$entity_type = $this->get_entity_type();
|
||||
$options = $this->options['vbo_operations'];
|
||||
foreach (views_bulk_operations_get_applicable_operations($entity_type, $options) as $operation_id => $operation) {
|
||||
$operation_options = !empty($options[$operation_id]) ? $options[$operation_id] : array();
|
||||
|
||||
$dom_id = 'edit-options-vbo-operations-' . str_replace(array('_', ':'), array('-', ''), $operation_id);
|
||||
$form['vbo_operations'][$operation_id]['selected'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $operation->adminLabel(),
|
||||
'#default_value' => !empty($operation_options['selected']),
|
||||
);
|
||||
if (!$operation->aggregate()) {
|
||||
$form['vbo_operations'][$operation_id]['postpone_processing'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enqueue the operation instead of executing it directly'),
|
||||
'#default_value' => !empty($operation_options['postpone_processing']),
|
||||
'#dependency' => array(
|
||||
$dom_id . '-selected' => array(1),
|
||||
),
|
||||
);
|
||||
}
|
||||
$form['vbo_operations'][$operation_id]['skip_confirmation'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Skip confirmation step'),
|
||||
'#default_value' => !empty($operation_options['skip_confirmation']),
|
||||
'#dependency' => array(
|
||||
$dom_id . '-selected' => array(1),
|
||||
),
|
||||
);
|
||||
|
||||
$form['vbo_operations'][$operation_id] += $operation->adminOptionsForm($dom_id);
|
||||
}
|
||||
}
|
||||
|
||||
function options_validate(&$form, &$form_state) {
|
||||
parent::options_validate($form, $form_state);
|
||||
|
||||
$entity_type = $this->get_entity_type();
|
||||
foreach ($form_state['values']['options']['vbo_operations'] as $operation_id => &$options) {
|
||||
if (empty($options['selected'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
|
||||
$fake_form = $form['vbo_operations'][$operation_id];
|
||||
$fake_form_state = array('values' => &$options);
|
||||
$error_element_base = 'vbo_operations][' . $operation_id . '][';
|
||||
$operation->adminOptionsFormValidate($fake_form, $fake_form_state, $error_element_base);
|
||||
}
|
||||
}
|
||||
|
||||
function options_submit(&$form, &$form_state) {
|
||||
parent::options_submit($form, $form_state);
|
||||
|
||||
$entity_type = $this->get_entity_type();
|
||||
foreach ($form_state['values']['options']['vbo_operations'] as $operation_id => &$options) {
|
||||
if (empty($options['selected'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
|
||||
$fake_form = $form['vbo_operations'][$operation_id];
|
||||
$fake_form_state = array('values' => &$options);
|
||||
$operation->adminOptionsFormSubmit($fake_form, $fake_form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of a vbo option.
|
||||
*/
|
||||
function get_vbo_option($key, $default = NULL) {
|
||||
return isset($this->options['vbo_settings'][$key]) ? $this->options['vbo_settings'][$key] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the view is using a table style, provide a
|
||||
* placeholder for a "select all" checkbox.
|
||||
*/
|
||||
function label() {
|
||||
if (!empty($this->view->style_plugin) && $this->view->style_plugin instanceof views_plugin_style_table && !$this->options['vbo_settings']['force_single']) {
|
||||
return '<!--views-bulk-operations-select-all-->';
|
||||
}
|
||||
else {
|
||||
return parent::label();
|
||||
}
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
return '<!--form-item-' . $this->options['id'] . '--' . $this->view->row_index . '-->';
|
||||
}
|
||||
|
||||
/**
|
||||
* The form which replaces the placeholder from render().
|
||||
*/
|
||||
function views_form(&$form, &$form_state) {
|
||||
// The view is empty, abort.
|
||||
if (empty($this->view->result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$form[$this->options['id']] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
// At this point, the query has already been run, so we can access the results
|
||||
// in order to get the base key value (for example, nid for nodes).
|
||||
foreach ($this->view->result as $row_index => $row) {
|
||||
$entity_id = $this->get_value($row);
|
||||
|
||||
if ($this->options['vbo_settings']['force_single']) {
|
||||
$form[$this->options['id']][$row_index] = array(
|
||||
'#type' => 'radio',
|
||||
'#parents' => array($this->options['id']),
|
||||
'#return_value' => $entity_id,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form[$this->options['id']][$row_index] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#return_value' => $entity_id,
|
||||
'#default_value' => FALSE,
|
||||
'#attributes' => array('class' => array('vbo-select')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get_selected_operations() {
|
||||
global $user;
|
||||
$selected = drupal_static(__FUNCTION__);
|
||||
if (!isset($selected)) {
|
||||
$entity_type = $this->get_entity_type();
|
||||
$selected = array();
|
||||
foreach ($this->options['vbo_operations'] as $operation_id => $options) {
|
||||
if (empty($options['selected'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$operation = views_bulk_operations_get_operation($operation_id, $entity_type, $options);
|
||||
if (!$operation || !$operation->access($user)) {
|
||||
continue;
|
||||
}
|
||||
$selected[$operation_id] = $operation;
|
||||
}
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options stored for the provided operation id.
|
||||
*/
|
||||
public function get_operation_options($operation_id) {
|
||||
$options = $this->options['vbo_operations'];
|
||||
return isset($options[$operation_id]) ? $options[$operation_id] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine the base table of the VBO field, and then use it to determine
|
||||
* the entity type that VBO is operating on.
|
||||
*/
|
||||
public function get_entity_type() {
|
||||
$base_table = $this->view->base_table;
|
||||
|
||||
// If the current field is under a relationship you can't be sure that the
|
||||
// base table of the view is the base table of the current field.
|
||||
// For example a field from a node author on a node view does have users as base table.
|
||||
if (!empty($this->options['relationship']) && $this->options['relationship'] != 'none') {
|
||||
$relationships = $this->view->display_handler->get_option('relationships');
|
||||
$options = $relationships[$this->options['relationship']];
|
||||
$data = views_fetch_data($options['table']);
|
||||
$base_table = $data[$options['field']]['relationship']['base'];
|
||||
}
|
||||
// The base table is now known, use it to determine the entity type.
|
||||
foreach (entity_get_info() as $entity_type => $info) {
|
||||
if (isset($info['base table']) && $info['base table'] == $base_table) {
|
||||
return $entity_type;
|
||||
}
|
||||
elseif (isset($info['revision table']) && $info['revision table'] == $base_table) {
|
||||
$this->revision = TRUE;
|
||||
return $entity_type;
|
||||
}
|
||||
}
|
||||
// This should never happen.
|
||||
_views_bulk_operations_report_error("Could not determine the entity type for VBO field on views base table %table", array('%table' => $base_table));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by Views Bulk Operations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Perform alterations on the VBO form before it is rendered.
|
||||
*
|
||||
* Usually, if a module wanted to alter the VBO form through hook_form_alter(),
|
||||
* it would need to duplicate the views form checks from
|
||||
* views_bulk_operations_form_alter(), while making sure that the hook
|
||||
* runs after VBO's hook (by increasing the weight of the altering module's
|
||||
* system entry). In order to reduce that complexity, VBO provides this hook.
|
||||
*
|
||||
* @param $form
|
||||
* A step of the VBO form to be altered.
|
||||
* @param $form_state
|
||||
* Form state. Contains the name of the current step in $form_state['step'].
|
||||
* @param $vbo
|
||||
* The VBO views field. Contains a reference to the view in $vbo->view.
|
||||
*/
|
||||
function hook_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
|
||||
if ($form_state['step'] == 'views_form_views_form') {
|
||||
// Alter the first step of the VBO form (the selection page).
|
||||
$form['select']['#title'] = t('Bulk operations');
|
||||
}
|
||||
elseif ($form_state['step'] == 'views_bulk_operations_config_form') {
|
||||
// Alter the configuration step of the VBO form.
|
||||
}
|
||||
elseif ($form_state['step'] == 'views_bulk_operations_confirm_form') {
|
||||
// Alter the confirmation step of the VBO form.
|
||||
}
|
||||
}
|
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_drush_help().
|
||||
*/
|
||||
function views_bulk_operations_drush_help($section) {
|
||||
switch ($section) {
|
||||
case 'drush:vbo-list':
|
||||
return dt('List all Views Bulk Operations (VBO) views, along with the operations associated with each.');
|
||||
case 'drush:vbo-execute':
|
||||
return dt('Execute a bulk operation based on a Views Bulk Operations (VBO) view.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_drush_command().
|
||||
*/
|
||||
function views_bulk_operations_drush_command() {
|
||||
$items['vbo-list'] = array(
|
||||
'callback' => 'views_bulk_operations_drush_list',
|
||||
'description' => 'List all Views Bulk Operations (VBO) views, along with the operations associated with each.',
|
||||
);
|
||||
$items['vbo-execute'] = array(
|
||||
'callback' => 'views_bulk_operations_drush_execute',
|
||||
'description' => 'Execute a bulk operation based on a Views Bulk Operations (VBO) view.',
|
||||
'arguments' => array(
|
||||
'vid' => 'ID or name of the view to be executed.',
|
||||
'operation_id' => 'ID of the operation to be applied on the view results.',
|
||||
'type:[name=]value ...' => 'Parameters to be passed as view input filters, view arguments or operation arguments, where type is respectively {input, argument, operation}.',
|
||||
),
|
||||
'examples' => array(
|
||||
'$ drush vbo-execute action::admin_content node_publish_action' =>
|
||||
'Publish nodes returned by view admin_content.',
|
||||
'$ drush vbo-execute 44 action::node_assign_owner_action operation:owner_uid=3' =>
|
||||
'Change node ownership on nodes returned by view #44, passing argument owner_uid=3 to the action.',
|
||||
'$ drush vbo-execute admin_content action::node_unpublish_action input:type=expense argument:3' =>
|
||||
'Unpublish nodes returned by view admin_content, filtering results of type expense and passing value 3 as first view argument.',
|
||||
),
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of 'vbo list' command.
|
||||
*/
|
||||
function views_bulk_operations_drush_list() {
|
||||
// Impersonate admin.
|
||||
global $user;
|
||||
$user = user_load(1);
|
||||
drupal_save_session(FALSE);
|
||||
|
||||
// Find all VBO views and their associated operations.
|
||||
$rows = array(array(sprintf('%5s', dt('View ID')), dt('Name'), dt('Description'), dt('Operations')));
|
||||
foreach (views_get_all_views() as $name => $view) {
|
||||
$view->build();
|
||||
$vbo = _views_bulk_operations_get_field($view);
|
||||
if ($vbo) {
|
||||
$operations = array();
|
||||
foreach ($vbo->get_selected_operations() as $operation_id => $operation) {
|
||||
$operations[] = $operation->label() .' ('. $operation_id .')';
|
||||
}
|
||||
$operations[] = "---------------";
|
||||
$rows[] = array(
|
||||
sprintf('%5d', $view->vid),
|
||||
$view->name,
|
||||
$view->description,
|
||||
implode("\n", $operations),
|
||||
);
|
||||
}
|
||||
}
|
||||
drush_print_table($rows, TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of 'vbo execute' command.
|
||||
*/
|
||||
function views_bulk_operations_drush_execute($vid = NULL, $operation_id = NULL) {
|
||||
// Parse arguments.
|
||||
if (is_null($vid)) {
|
||||
drush_set_error('VIEWS_BULK_OPERATIONS_MISSING_VID', dt('Please specify a view ID to execute.'));
|
||||
return;
|
||||
}
|
||||
if (is_null($operation_id)) {
|
||||
drush_set_error('VIEWS_BULK_OPERATIONS_MISSING_OPERATION', dt('Please specify an operation to execute.'));
|
||||
return;
|
||||
}
|
||||
$args = func_get_args();
|
||||
$view_exposed_input = array();
|
||||
$operation_arguments = array();
|
||||
$view_arguments = array();
|
||||
if (count($args) > 2) for ($i=2; $i<count($args); $i++) {
|
||||
$parts = array();
|
||||
if (FALSE === preg_match('/^(?<type>\w+):(?:(?<name>\w+)=)?(?<value>(.*?))$/', $args[$i], $parts)) {
|
||||
drush_set_error('VIEWS_BULK_OPERATIONS_INVALID_PARAMETER', dt('The parameter %arg should be of the form type:[name=]value where type in {input, argument, operation}.', array('%arg' => $args[$i])));
|
||||
return;
|
||||
}
|
||||
switch ($parts['type']) {
|
||||
case 'input':
|
||||
$view_exposed_input[$parts['name']] = $parts['value'];
|
||||
break;
|
||||
case 'operation':
|
||||
$operation_arguments[$parts['name']] = $parts['value'];
|
||||
break;
|
||||
case 'argument':
|
||||
$view_arguments[] = $parts['value'];
|
||||
break;
|
||||
default:
|
||||
drush_set_error('VIEWS_BULK_OPERATIONS_UNKNOWN_PARAMETER', dt('The parameter type %type is unknown. Please specify either input, argument or operation.', array('%type' => $parts['type'])));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Impersonate admin.
|
||||
global $user;
|
||||
$user = user_load(1);
|
||||
drupal_save_session(FALSE);
|
||||
|
||||
// Load the view.
|
||||
$view = views_get_view($vid);
|
||||
if (!is_object($view)) {
|
||||
_views_bulk_operations_report_error('Could not find view %vid.', array('%vid' => $vid));
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the view, so that the VBO field can be found.
|
||||
$view->set_exposed_input($view_exposed_input);
|
||||
$view->set_arguments($view_arguments);
|
||||
$view->build();
|
||||
$view->query->set_limit(NULL); // reset the work done by the pager
|
||||
$view->query->set_offset(NULL);
|
||||
|
||||
// Find the VBO field.
|
||||
$vbo = _views_bulk_operations_get_field($view);
|
||||
if (!$vbo) {
|
||||
_views_bulk_operations_report_error('Could not find a VBO field in view %vid.', array('%vid' => $vid));
|
||||
return;
|
||||
}
|
||||
|
||||
$view->execute();
|
||||
|
||||
// Find the selected operation.
|
||||
$operations = $vbo->get_selected_operations();
|
||||
if (!isset($operations[$operation_id])) {
|
||||
_views_bulk_operations_report_error('Could not find operation %operation_id in view %vid.', array('%operation_id' => $operation_id, '%vid' => $vid));
|
||||
return;
|
||||
}
|
||||
$operation = views_bulk_operations_get_operation($operation_id, $vbo->get_entity_type(), $vbo->get_operation_options($operation_id));
|
||||
if ($operation_arguments) {
|
||||
$operation->formOptions = $operation_arguments;
|
||||
}
|
||||
|
||||
// Select all rows.
|
||||
$rows = array();
|
||||
$current = 1;
|
||||
foreach ($view->result as $row_index => $result) {
|
||||
$rows[$row_index] = array(
|
||||
'entity_id' => $vbo->get_value($result),
|
||||
'views_row' => array(),
|
||||
'position' => array(
|
||||
'current' => $current++,
|
||||
'total' => $view->total_rows,
|
||||
),
|
||||
);
|
||||
// Some operations require full selected rows.
|
||||
if ($operation->needsRows()) {
|
||||
$rows[$row_index]['views_row'] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
// Enqueue the fetched rows.
|
||||
$queue_name = 'views_bulk_operations_active_queue_' . db_next_id();
|
||||
$options = array(
|
||||
'revision' => $vbo->revision,
|
||||
'entity_load_capacity' => $vbo->get_vbo_option('entity_load_capacity', 10),
|
||||
);
|
||||
views_bulk_operations_enqueue_rows($queue_name, $rows, $operation, $options);
|
||||
|
||||
// Process the queue using Batch API.
|
||||
$batch = array(
|
||||
'file' => drupal_get_path('module', 'views_bulk_operations') . '/views_bulk_operations.module',
|
||||
'operations' => array(
|
||||
array('views_bulk_operations_active_queue_process', array($queue_name, $operation, $vbo->view->total_rows)),
|
||||
),
|
||||
'finished' => '_views_bulk_operations_execute_finished',
|
||||
'title' => t('Performing %operation on the selected items...', array('%operation' => $operation->label())),
|
||||
);
|
||||
batch_set($batch);
|
||||
drush_backend_batch_process();
|
||||
|
||||
// Looks like drush has no way to show messages set in subprocesses,
|
||||
// so all batch messages get lost. Setting a success message manually here.
|
||||
drush_log(dt('Performed "!operation" on @items.', array(
|
||||
'!operation' => $operation->label(),
|
||||
'@items' => format_plural($vbo->view->total_rows, '1 item', '@count items'),
|
||||
)), 'ok');
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
name = Views Bulk Operations
|
||||
description = Provides a way of selecting multiple rows and applying operations to them.
|
||||
dependencies[] = entity
|
||||
dependencies[] = views
|
||||
package = Views
|
||||
core = 7.x
|
||||
|
||||
files[] = plugins/operation_types/base.class.php
|
||||
files[] = views/views_bulk_operations_handler_field_operations.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-12-03
|
||||
version = "7.x-3.1"
|
||||
core = "7.x"
|
||||
project = "views_bulk_operations"
|
||||
datestamp = "1354500015"
|
||||
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Installation and update functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function views_bulk_operations_uninstall() {
|
||||
// Remove VBO actions that are now orphaned.
|
||||
actions_synchronize(TRUE);
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,298 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views Bulk Operations conditions and actions for Rules.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_rules_condition_info().
|
||||
*/
|
||||
function views_bulk_operations_rules_condition_info() {
|
||||
$conditions = array();
|
||||
$conditions['views_bulk_operations_condition_result_count'] = array(
|
||||
'label' => t('Check number of results returned by a VBO View'),
|
||||
'parameter' => array(
|
||||
'view' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('View and display'),
|
||||
'options list' => 'views_bulk_operations_views_list',
|
||||
'description' => t('Select the VBO view and display you want to check'),
|
||||
'restriction' => 'input',
|
||||
),
|
||||
'args' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Arguments'),
|
||||
'description' => t('Any arguments to pass to the view, one per line.
|
||||
You may use token replacement patterns.'),
|
||||
'optional' => TRUE,
|
||||
),
|
||||
'minimum' => array(
|
||||
'type' => 'integer',
|
||||
'label' => t('Minimum number of results'),
|
||||
'description' => t('This condition returns TRUE if the view has at
|
||||
least the given number of results.'),
|
||||
),
|
||||
),
|
||||
'group' => t('Views Bulk Operations'),
|
||||
);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_rules_action_info().
|
||||
*/
|
||||
function views_bulk_operations_rules_action_info() {
|
||||
$actions = array();
|
||||
$actions['views_bulk_operations_action_load_list'] = array(
|
||||
'label' => t('Load a list of entity objects from a VBO View.'),
|
||||
'parameter' => array(
|
||||
'view' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('View and display'),
|
||||
'options list' => 'views_bulk_operations_views_list',
|
||||
'description' => t('Select the view and display you want to use to
|
||||
create a list.'),
|
||||
'restriction' => 'input',
|
||||
),
|
||||
'args' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Arguments'),
|
||||
'description' => t('Any arguments to pass to the view, one per line.
|
||||
You may use token replacement patterns.'),
|
||||
'optional' => TRUE,
|
||||
),
|
||||
),
|
||||
'provides' => array(
|
||||
'entity_list' => array(
|
||||
'type' => 'list<entity>',
|
||||
'label' => t('A list of entities'),
|
||||
),
|
||||
),
|
||||
'group' => t('Views Bulk Operations'),
|
||||
);
|
||||
$actions['views_bulk_operations_action_load_id_list'] = array(
|
||||
'label' => t('Load a list of entity ids from a VBO View.'),
|
||||
'parameter' => array(
|
||||
'view' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('View and display'),
|
||||
'options list' => 'views_bulk_operations_views_list',
|
||||
'description' => t('Select the view and display you want to use to
|
||||
create a list.'),
|
||||
'restriction' => 'input',
|
||||
),
|
||||
'args' => array(
|
||||
'type' => 'text',
|
||||
'label' => t('Arguments'),
|
||||
'description' => t('Any arguments to pass to the view, one per line.
|
||||
You may use token replacement patterns.'),
|
||||
'optional' => TRUE,
|
||||
),
|
||||
),
|
||||
'provides' => array(
|
||||
'entity_id_list' => array(
|
||||
'type' => 'list<integer>',
|
||||
'label' => t('A list of entity ids'),
|
||||
),
|
||||
),
|
||||
'group' => t('Views Bulk Operations'),
|
||||
);
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all available VBO Views and their displays.
|
||||
* Naturally, only the displays that contain a VBO field are listed.
|
||||
*
|
||||
* @return array
|
||||
* An array of all views and their displays on the form 'view|display',
|
||||
* formatted to be used as an select list.
|
||||
*/
|
||||
function views_bulk_operations_views_list() {
|
||||
$selectable_displays = array();
|
||||
foreach (views_get_enabled_views() as $name => $view) {
|
||||
foreach ($view->display as $display_name => $display) {
|
||||
$view->build($display_name);
|
||||
$vbo = _views_bulk_operations_get_field($view);
|
||||
if ($vbo) {
|
||||
$selectable_displays[$view->name . '|' . $display_name] = check_plain($view->human_name) . ' | ' . check_plain($display->display_title);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $selectable_displays;
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'views_bulk_operations_condition_result_count' condition.
|
||||
*
|
||||
* @param $view
|
||||
* A string in the format "$view_name|$display_name".
|
||||
* @param $args
|
||||
* Arguments that should be passed to the View.
|
||||
* @param $minimum
|
||||
* An integer representing the minimum number of results that satisfies the
|
||||
* condition.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the view has more than $minimum results, FALSE otherwise.
|
||||
*/
|
||||
function views_bulk_operations_condition_result_count($view, $args, $minimum) {
|
||||
$vbo = _views_bulk_operations_rules_get_field($view, $args);
|
||||
return (count($vbo->view->result) >= $minimum);
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'views_bulk_operations_action_views_load_list' action.
|
||||
*
|
||||
* @param $view
|
||||
* A string in the format "$view_name|$display_name".
|
||||
* @param $args
|
||||
* Arguments that should be passed to the View.
|
||||
* @return array
|
||||
* Array containing the entity_list, an array of entity objects.
|
||||
* - array('entity_list' => array(...))
|
||||
*/
|
||||
function views_bulk_operations_action_load_list($view, $args) {
|
||||
$vbo = _views_bulk_operations_rules_get_field($view, $args);
|
||||
|
||||
// Get all entity ids.
|
||||
$ids = array();
|
||||
foreach ($vbo->view->result as $row_index => $result) {
|
||||
$ids[] = $vbo->get_value($result);
|
||||
}
|
||||
// And load the entity objects.
|
||||
$entities = entity_load($vbo->get_entity_type(), $ids);
|
||||
|
||||
return array('entity_list' => $entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* The 'views_bulk_operations_action_views_load_id_list' action.
|
||||
*
|
||||
* @param $view
|
||||
* A string in the format "$view_name|$display_name".
|
||||
* @param $args
|
||||
* Arguments that should be passed to the View.
|
||||
* @return array
|
||||
* Array containing the entity_id_list, an Array of entity ids as integer
|
||||
* values.
|
||||
* - array('entity_list' => array(...))
|
||||
*/
|
||||
function views_bulk_operations_action_load_id_list($view, $args) {
|
||||
$vbo = _views_bulk_operations_rules_get_field($view, $args);
|
||||
|
||||
// Get all entity ids.
|
||||
$ids = array();
|
||||
foreach ($vbo->view->result as $row_index => $result) {
|
||||
$ids[] = $vbo->get_value($result);
|
||||
}
|
||||
|
||||
return array('entity_id_list' => $ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Info alteration callback for the 'views_bulk_operations_action_views_load_list' action.
|
||||
*
|
||||
* The info hook specifies that the action returns a generic list of entities
|
||||
* (list<entity>). All actions that require entities of specific type can't
|
||||
* use such entities, so this alter hook specifies the exact entity type
|
||||
* after the action has been configured, allowing the view to be loaded
|
||||
* and its entity type extracted.
|
||||
*/
|
||||
function views_bulk_operations_action_load_list_info_alter(&$element_info, RulesAbstractPlugin $element) {
|
||||
// The action hasn't been configured yet, hence no view. Abort.
|
||||
if (empty($element->settings['view'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entity_type = _views_bulk_operations_rules_get_entity_type($element->settings['view']);
|
||||
if ($entity_type) {
|
||||
$element_info['provides']['entity_list']['type'] = "list<$entity_type>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that loads and builds (but doesn't execute) the specified view,
|
||||
* then determines the entity type on which the VBO field operates.
|
||||
*
|
||||
* @param $view_target
|
||||
* A string in the format "$view_name|$display_name".
|
||||
*
|
||||
* @return
|
||||
* The entity type on which the VBO field operates.
|
||||
*/
|
||||
function _views_bulk_operations_rules_get_entity_type($view_target) {
|
||||
$entity_types = &drupal_static(__FUNCTION__);
|
||||
|
||||
if (!isset($entity_types[$view_target])) {
|
||||
$views_settings = explode('|', $view_target);
|
||||
if ($view = views_get_view($views_settings[0])) {
|
||||
$view->set_display($views_settings[1]);
|
||||
$view->build();
|
||||
|
||||
$vbo = _views_bulk_operations_get_field($view);
|
||||
}
|
||||
$entity_type = !empty($vbo) ? $vbo->get_entity_type() : '';
|
||||
$entity_types[$view_target] = $entity_type;
|
||||
}
|
||||
|
||||
return $entity_types[$view_target];
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that loads, builds and executes the specified view,
|
||||
* then returns its VBO field.
|
||||
*
|
||||
* @param $view_target
|
||||
* A string in the format "$view_name|$display_name".
|
||||
* @param $args
|
||||
* Arguments that should be passed to the View.
|
||||
*
|
||||
* @return
|
||||
* The VBO field. Contains a reference to the View.
|
||||
*/
|
||||
function _views_bulk_operations_rules_get_field($view_target, $args) {
|
||||
$views = &drupal_static(__FUNCTION__);
|
||||
|
||||
$views_settings = explode('|', $view_target);
|
||||
$view_name = $views_settings[0];
|
||||
$display_name = $views_settings[1];
|
||||
// Create an array of arguments.
|
||||
$view_arguments = explode("\n", $args);
|
||||
$view_arguments = array_map('trim', $view_arguments);
|
||||
$view_arguments = array_filter($view_arguments, 'strlen');
|
||||
// Append the filtered list of arguments to $views_target, so that the correct
|
||||
// View is fetched from cache.
|
||||
if (!empty($view_arguments)) {
|
||||
$view_target .= '|' . implode('&', $view_arguments);
|
||||
}
|
||||
|
||||
// Don't execute the requested View more than once in a single page request.
|
||||
if (isset($views[$view_target])) {
|
||||
$vbo = _views_bulk_operations_get_field($views[$view_target]);
|
||||
return $vbo;
|
||||
}
|
||||
|
||||
// Load the view and set the properties.
|
||||
$view = views_get_view($view_name);
|
||||
$view->set_display($display_name);
|
||||
$view->set_arguments($view_arguments);
|
||||
$view->build();
|
||||
$vbo = _views_bulk_operations_get_field($view);
|
||||
// Unset every field except the VBO one (which holds the entity id).
|
||||
// That way the performance hit becomes much smaller, because there is no
|
||||
// chance of views_handler_field_field::post_execute() firing entity_load().
|
||||
foreach ($view->field as $field_name => $field) {
|
||||
if ($field_name != $vbo->options['id']) {
|
||||
unset($view->field[$field_name]);
|
||||
}
|
||||
}
|
||||
$view->execute($view->current_display);
|
||||
// Save the view in the static cache.
|
||||
$views[$view_target] = $view;
|
||||
|
||||
return $vbo;
|
||||
}
|
339
sites/all/modules/contrib/views/views_data_export/LICENSE.txt
Normal file
339
sites/all/modules/contrib/views/views_data_export/LICENSE.txt
Normal 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.
|
45
sites/all/modules/contrib/views/views_data_export/README.txt
Normal file
45
sites/all/modules/contrib/views/views_data_export/README.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
Views Data Export
|
||||
=================
|
||||
|
||||
Introduction
|
||||
------------
|
||||
|
||||
This module is designed to provide a way to export large amounts of data from
|
||||
views. It provides a display plugin that can rendered progressively in a batch.
|
||||
Style plugins are include that support exporting in the following types:
|
||||
|
||||
* CSV
|
||||
* Microsoft XLS
|
||||
* Microsoft Doc
|
||||
* Basic txt
|
||||
* Simple xml.
|
||||
|
||||
Using the "Views Data Export" module
|
||||
------------------------------------
|
||||
|
||||
1. Add a new "Data export" display to your view.
|
||||
2. Change its "Style" to the desired export type. e.g. "CSV file".
|
||||
3. Configure the options (such as name, quote, etc.). You can go back and do
|
||||
this at any time by clicking the gear icon next to the style plugin you just
|
||||
selected.
|
||||
4. Give it a path in the Feed settings such as "path/to/view/csv".
|
||||
5. Optionally, you can choose to attach this to another of your displays by
|
||||
updating the "Attach to:" option in feed settings.
|
||||
|
||||
Advanced usage
|
||||
--------------
|
||||
|
||||
This module also exposes a drush command that can execute the view and save its
|
||||
results to a file.
|
||||
|
||||
drush views-data-export [view-name] [display-id] [output-file]
|
||||
|
||||
|
||||
History
|
||||
-------
|
||||
|
||||
This module has its roots in the export module that was part of the views bonus
|
||||
pack (http://drupal.org/project/views_bonus). However, massive changes were
|
||||
needed to make the batch export functionality work, and so this fork was
|
||||
created. See: http://drupal.org/node/805960
|
||||
|
BIN
sites/all/modules/contrib/views/views_data_export/images/csv.png
Normal file
BIN
sites/all/modules/contrib/views/views_data_export/images/csv.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 637 B |
BIN
sites/all/modules/contrib/views/views_data_export/images/doc.png
Normal file
BIN
sites/all/modules/contrib/views/views_data_export/images/doc.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 549 B |
BIN
sites/all/modules/contrib/views/views_data_export/images/txt.png
Normal file
BIN
sites/all/modules/contrib/views/views_data_export/images/txt.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 362 B |
Binary file not shown.
BIN
sites/all/modules/contrib/views/views_data_export/images/xls.png
Normal file
BIN
sites/all/modules/contrib/views/views_data_export/images/xls.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 378 B |
BIN
sites/all/modules/contrib/views/views_data_export/images/xml.png
Normal file
BIN
sites/all/modules/contrib/views/views_data_export/images/xml.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 568 B |
@@ -0,0 +1,831 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains the bulk export display plugin.
|
||||
*
|
||||
* This allows views to be rendered in parts by batch API.
|
||||
*/
|
||||
|
||||
/**
|
||||
* The plugin that batches its rendering.
|
||||
*
|
||||
* We are based on a feed display for compatibility.
|
||||
*
|
||||
* @ingroup views_display_plugins
|
||||
*/
|
||||
class views_data_export_plugin_display_export extends views_plugin_display_feed {
|
||||
|
||||
/**
|
||||
* The batched execution state of the view.
|
||||
*/
|
||||
public $batched_execution_state;
|
||||
|
||||
/**
|
||||
* The alias of the weight field in the index table.
|
||||
*/
|
||||
var $weight_field_alias = '';
|
||||
|
||||
/**
|
||||
* A map of the index column names to the expected views aliases.
|
||||
*/
|
||||
var $field_aliases = array();
|
||||
|
||||
/**
|
||||
* Private variable that stores the filename to save the results to.
|
||||
*/
|
||||
var $_output_file = '';
|
||||
|
||||
var $views_data_export_cached_view_loaded;
|
||||
|
||||
var $errors = array();
|
||||
|
||||
/**
|
||||
* Return the type of styles we require.
|
||||
*/
|
||||
function get_style_type() { return 'data_export'; }
|
||||
|
||||
/**
|
||||
* Return the sections that can be defaultable.
|
||||
*/
|
||||
function defaultable_sections($section = NULL) {
|
||||
if (in_array($section, array('items_per_page', 'offset', 'use_pager', 'pager_element',))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return parent::defaultable_sections($section);
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the option for this view.
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['use_batch'] = array('default' => 'no_batch');
|
||||
$options['items_per_page'] = array('default' => '0');
|
||||
$options['style_plugin']['default'] = 'views_data_export_csv';
|
||||
|
||||
if (isset($options['defaults']['default']['items_per_page'])) {
|
||||
$options['defaults']['default']['items_per_page'] = FALSE;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the summary for page options in the views UI.
|
||||
*
|
||||
* This output is returned as an array.
|
||||
*/
|
||||
function options_summary(&$categories, &$options) {
|
||||
// It is very important to call the parent function here:
|
||||
parent::options_summary($categories, $options);
|
||||
|
||||
$categories['page']['title'] = t('Data export settings');
|
||||
|
||||
$options['use_batch'] = array(
|
||||
'category' => 'page',
|
||||
'title' => t('Batched export'),
|
||||
'value' => ($this->get_option('use_batch') == 'batch' ? t('Yes') : t('No')),
|
||||
);
|
||||
|
||||
if (!$this->is_compatible() && $this->get_option('use_batch')) {
|
||||
$options['use_batch']['value'] .= ' <strong>' . t('(Warning: incompatible)') . '</strong>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the default form for setting options.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
// It is very important to call the parent function here:
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
switch ($form_state['section']) {
|
||||
case 'use_batch':
|
||||
$form['#title'] .= t('Batched export');
|
||||
$form['use_batch'] = array(
|
||||
'#type' => 'radios',
|
||||
'#description' => t(''),
|
||||
'#default_value' => $this->get_option('use_batch'),
|
||||
'#options' => array(
|
||||
'no_batch' => t('Export data all in one segment. Possible time and memory limit issues.'),
|
||||
'batch' => t('Export data in small segments to build a complete export. Recommended for large exports sets (1000+ rows)'),
|
||||
),
|
||||
);
|
||||
if (!$this->is_compatible()) {
|
||||
$form['use_batch']['#disabled'] = TRUE;
|
||||
$form['use_batch']['#default_value'] = 'no_batch';
|
||||
$form['use_batch']['message'] = array (
|
||||
'#type' => 'markup',
|
||||
'#markup' => theme('views_data_export_message', array('message' => t('The underlying database (!db_driver) is incompatible with the batched export option and it has been disabled.', array('!db_driver' => $this->_get_database_driver())), 'type' => 'warning')),
|
||||
'#weight' => -10,
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the options from the options form.
|
||||
*/
|
||||
function options_submit(&$form, &$form_state) {
|
||||
// It is very important to call the parent function here:
|
||||
parent::options_submit($form, $form_state);
|
||||
switch ($form_state['section']) {
|
||||
case 'use_batch':
|
||||
$this->set_option('use_batch', $form_state['values']['use_batch']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if this view should run as a batch or not.
|
||||
*/
|
||||
function is_batched() {
|
||||
// The source of this option may change in the future.
|
||||
return ($this->get_option('use_batch') == 'batch') && empty($this->view->live_preview);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add HTTP headers for the file export.
|
||||
*/
|
||||
function add_http_headers() {
|
||||
// Ask the style plugin to add any HTTP headers if it wants.
|
||||
if (method_exists($this->view->style_plugin, 'add_http_headers')) {
|
||||
$this->view->style_plugin->add_http_headers();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute this display handler.
|
||||
*
|
||||
* This is the main entry point for this display. We do different things based
|
||||
* on the stage in the rendering process.
|
||||
*
|
||||
* If we are being called for the very first time, the user has usually just
|
||||
* followed a link to our view. For this phase we:
|
||||
* - Register a new batched export with our parent module.
|
||||
* - Build and execute the view, redirecting the output into a temporary table.
|
||||
* - Set up the batch.
|
||||
*
|
||||
* If we are being called during batch processing we:
|
||||
* - Set up our variables from the context into the display.
|
||||
* - Call the rendering layer.
|
||||
* - Return with the appropriate progress value for the batch.
|
||||
*
|
||||
* If we are being called after the batch has completed we:
|
||||
* - Remove the index table.
|
||||
* - Show the complete page with a download link.
|
||||
* - Transfer the file if the download link was clicked.
|
||||
*/
|
||||
function execute() {
|
||||
if (!$this->is_batched()) {
|
||||
return parent::execute();
|
||||
}
|
||||
|
||||
// Try and get a batch context if possible.
|
||||
$eid = !empty($_GET['eid']) ? $_GET['eid'] :
|
||||
(!empty($this->batched_execution_state->eid) ? $this->batched_execution_state->eid : FALSE);
|
||||
if ($eid) {
|
||||
$this->batched_execution_state = views_data_export_get($eid);
|
||||
}
|
||||
|
||||
// First time through
|
||||
if (empty($this->batched_execution_state)) {
|
||||
$output = $this->execute_initial();
|
||||
}
|
||||
|
||||
// Call me on the cached version of this view please
|
||||
// This allows this view to be programatically executed with nothing
|
||||
// more than the eid in $_GET in order for it to execute the next chunk
|
||||
// TODO: What is going on here?
|
||||
/*
|
||||
Jamsilver tells me this might be useful one day.
|
||||
if (!$this->views_data_export_cached_view_loaded) {
|
||||
$view = views_data_export_view_retrieve($this->batched_execution_state->eid);
|
||||
$view->set_display($this->view->current_display);
|
||||
$view->display_handler->batched_execution_state->eid = $this->batched_execution_state->eid;
|
||||
$view->display_handler->views_data_export_cached_view_loaded = TRUE;
|
||||
$ret = $view->execute_display($this->view->current_display);
|
||||
$this->batched_execution_state = &$view->display_handler->batched_execution_state;
|
||||
return $ret;
|
||||
}*/
|
||||
|
||||
// Last time through
|
||||
if ($this->batched_execution_state->batch_state == VIEWS_DATA_EXPORT_FINISHED) {
|
||||
$output = $this->execute_final();
|
||||
}
|
||||
// In the middle of processing
|
||||
else {
|
||||
$output = $this->execute_normal();
|
||||
}
|
||||
|
||||
//Ensure any changes we made to the database sandbox are saved
|
||||
views_data_export_update($this->batched_execution_state);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initializes the whole export process and starts off the batch process.
|
||||
*
|
||||
* Page execution will be ended at the end of this function.
|
||||
*/
|
||||
function execute_initial() {
|
||||
|
||||
// Register this export with our central table - get a unique eid
|
||||
// Also store our view in a cache to be retrieved with each batch call
|
||||
$this->batched_execution_state = views_data_export_new($this->view->name, $this->view->current_display, $this->outputfile_create());
|
||||
views_data_export_view_store($this->batched_execution_state->eid, $this->view);
|
||||
|
||||
// We need to build the index right now, before we lose $_GET etc.
|
||||
$this->initialize_index();
|
||||
//$this->batched_execution_state->fid = $this->outputfile_create();
|
||||
|
||||
// Initialize the progress counter
|
||||
$this->batched_execution_state->sandbox['max'] = db_query('SELECT COUNT(*) FROM {' . $this->index_tablename() . '}')->fetchField();
|
||||
// Record the time we started.
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
$this->batched_execution_state->sandbox['started'] = (float) $usec + (float) $sec;
|
||||
|
||||
// Build up our querystring for the final page callback.
|
||||
$querystring = array(
|
||||
'eid' => $this->batched_execution_state->eid,
|
||||
);
|
||||
// If we were attached to another view, grab that for the final URL.
|
||||
if (!empty($_GET['attach']) && isset($this->view->display[$_GET['attach']])) {
|
||||
// Get the path of the attached display:
|
||||
$querystring['return-url'] = $this->view->display[$_GET['attach']]->handler->get_path();
|
||||
}
|
||||
|
||||
//Set the batch off
|
||||
$batch = array(
|
||||
'operations' => array (
|
||||
array('_views_data_export_batch_process', array($this->batched_execution_state->eid, $this->view->current_display)),
|
||||
),
|
||||
'title' => t('Building export'),
|
||||
'init_message' => t('Export is starting up.'),
|
||||
'progress_message' => t('Exporting @percentage% complete,'),
|
||||
'error_message' => t('Export has encountered an error.'),
|
||||
);
|
||||
|
||||
// We do not return, so update database sandbox now
|
||||
views_data_export_update($this->batched_execution_state);
|
||||
|
||||
$final_destination = $this->view->get_url();
|
||||
|
||||
// Provide a way in for others at this point
|
||||
// e.g. Drush to grab this batch and yet execute it in
|
||||
// it's own special way
|
||||
$batch['view_name'] = $this->view->name;
|
||||
$batch['display_id'] = $this->view->current_display;
|
||||
$batch['eid'] = $this->batched_execution_state->eid;
|
||||
$batch_redirect = array($final_destination, array('query' => $querystring));
|
||||
drupal_alter('views_data_export_batch', $batch, $batch_redirect);
|
||||
|
||||
// Modules may have cleared out $batch, indicating that we shouldn't process further.
|
||||
if (!empty($batch)) {
|
||||
batch_set($batch);
|
||||
// batch_process exits
|
||||
batch_process($batch_redirect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compiles the next chunk of the output file
|
||||
*/
|
||||
function execute_normal() {
|
||||
|
||||
// Pass through to our render method,
|
||||
$output = $this->view->render();
|
||||
|
||||
// Append what was rendered to the output file.
|
||||
$this->outputfile_write($output);
|
||||
|
||||
// Store for convenience.
|
||||
$state = &$this->batched_execution_state;
|
||||
$sandbox = &$state->sandbox;
|
||||
|
||||
// Update progress measurements & move our state forward
|
||||
switch ($state->batch_state) {
|
||||
|
||||
case VIEWS_DATA_EXPORT_BODY:
|
||||
// Remove rendered results from our index
|
||||
if (count($this->view->result) && ($sandbox['weight_field_alias'])) {
|
||||
$last = end($this->view->result);
|
||||
db_delete($this->index_tablename())
|
||||
->condition($sandbox['weight_field_alias'], $last->{$sandbox['weight_field_alias']}, '<=')
|
||||
->execute();
|
||||
|
||||
// Update progress.
|
||||
$progress = db_query('SELECT COUNT(*) FROM {' . $this->index_tablename() . '}')->fetchField();
|
||||
// TODO: These next few lines are messy, clean them up.
|
||||
$progress = 0.99 - ($progress / $sandbox['max'] * 0.99);
|
||||
$progress = ((int)floor($progress * 100000));
|
||||
$progress = $progress / 100000;
|
||||
$sandbox['finished'] = $progress;
|
||||
}
|
||||
else {
|
||||
// No more results.
|
||||
$progress = 0.99;
|
||||
$state->batch_state = VIEWS_DATA_EXPORT_FOOTER;
|
||||
}
|
||||
break;
|
||||
|
||||
case VIEWS_DATA_EXPORT_HEADER:
|
||||
$sandbox['finished'] = 0;
|
||||
$state->batch_state = VIEWS_DATA_EXPORT_BODY;
|
||||
break;
|
||||
|
||||
case VIEWS_DATA_EXPORT_FOOTER:
|
||||
$sandbox['finished'] = 1;
|
||||
$state->batch_state = VIEWS_DATA_EXPORT_FINISHED;
|
||||
break;
|
||||
}
|
||||
|
||||
// Create a more helpful exporting message.
|
||||
$sandbox['message'] = $this->compute_time_remaining($sandbox['started'], $sandbox['finished']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renders the final page
|
||||
* We should be free of the batch at this point
|
||||
*/
|
||||
function execute_final() {
|
||||
// Should we download the file.
|
||||
if (!empty($_GET['download'])) {
|
||||
// This next method will exit.
|
||||
$this->transfer_file();
|
||||
}
|
||||
else {
|
||||
// Remove the index table.
|
||||
$this->remove_index();
|
||||
return $this->render_complete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the display.
|
||||
*
|
||||
* We basically just work out if we should be rendering the header, body or
|
||||
* footer and call the appropriate functions on the style plugins.
|
||||
*/
|
||||
function render() {
|
||||
|
||||
if (!$this->is_batched()) {
|
||||
$result = parent::render();
|
||||
if (empty($this->view->live_preview)) {
|
||||
$this->add_http_headers();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
$this->view->build();
|
||||
|
||||
switch ($this->batched_execution_state->batch_state) {
|
||||
case VIEWS_DATA_EXPORT_BODY:
|
||||
$output = $this->view->style_plugin->render_body();
|
||||
break;
|
||||
case VIEWS_DATA_EXPORT_HEADER:
|
||||
$output = $this->view->style_plugin->render_header();
|
||||
break;
|
||||
case VIEWS_DATA_EXPORT_FOOTER:
|
||||
$output = $this->view->style_plugin->render_footer();
|
||||
break;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Trick views into thinking that we have executed the query and got results.
|
||||
*
|
||||
* We are called in the build phase of the view, but short circuit straight to
|
||||
* getting the results and making the view think it has already executed the
|
||||
* query.
|
||||
*/
|
||||
function query() {
|
||||
|
||||
if (!$this->is_batched()) {
|
||||
return parent::query();
|
||||
}
|
||||
|
||||
// Make the query distinct if the option was set.
|
||||
if ($this->get_option('distinct')) {
|
||||
$this->view->query->set_distinct();
|
||||
}
|
||||
|
||||
if (!empty($this->batched_execution_state->batch_state) && !empty($this->batched_execution_state->sandbox['weight_field_alias'])) {
|
||||
|
||||
switch ($this->batched_execution_state->batch_state) {
|
||||
case VIEWS_DATA_EXPORT_BODY:
|
||||
case VIEWS_DATA_EXPORT_HEADER:
|
||||
case VIEWS_DATA_EXPORT_FOOTER:
|
||||
// Tell views its been executed.
|
||||
$this->view->executed = TRUE;
|
||||
|
||||
// Grab our results from the index, and push them into the view result.
|
||||
// TODO: Handle external databases.
|
||||
$result = db_query_range('SELECT * FROM {' . $this->index_tablename() . '} ORDER BY ' . $this->batched_execution_state->sandbox['weight_field_alias'] . ' ASC', 0, 100);
|
||||
$this->view->result = array();
|
||||
foreach ($result as $item_hashed) {
|
||||
$item = new stdClass();
|
||||
// We had to shorten some of the column names in the index, restore
|
||||
// those now.
|
||||
foreach ($item_hashed as $hash => $value) {
|
||||
if (isset($this->batched_execution_state->sandbox['field_aliases'][$hash])) {
|
||||
$item->{$this->batched_execution_state->sandbox['field_aliases'][$hash]} = $value;
|
||||
}
|
||||
else {
|
||||
$item->{$hash} = $value;
|
||||
}
|
||||
}
|
||||
// Push the restored $item in the views result array.
|
||||
$this->view->result[] = $item;
|
||||
}
|
||||
$this->view->_post_execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render the 'Export Finished' page with the link to the file on it.
|
||||
*/
|
||||
function render_complete() {
|
||||
$return_path = empty($_GET['return-url']) ? '' : $_GET['return-url'];
|
||||
|
||||
$query = array(
|
||||
'download' => 1,
|
||||
'eid' => $this->batched_execution_state->eid,
|
||||
);
|
||||
|
||||
return theme('views_data_export_complete_page', array(
|
||||
'file' => url($this->view->get_url(), array('query' => $query)),
|
||||
'errors' => $this->errors,
|
||||
'return_url' => $return_path));
|
||||
}
|
||||
|
||||
/**
|
||||
* TBD - What does 'preview' mean for bulk exports?
|
||||
* According to doc:
|
||||
* "Fully render the display for the purposes of a live preview or
|
||||
* some other AJAXy reason. [views_plugin_display.inc:1877]"
|
||||
*
|
||||
* Not sure it makes sense for Bulk exports to be previewed in this manner?
|
||||
* We need the user's full attention to run the batch. Suggestions:
|
||||
* 1) Provide a link to execute the view?
|
||||
* 2) Provide a link to the last file we generated??
|
||||
* 3) Show a table of the first 20 results?
|
||||
*/
|
||||
function preview() {
|
||||
if (!$this->is_batched()) {
|
||||
// Can replace with return parent::preview() when views 2.12 lands.
|
||||
if (!empty($this->view->live_preview)) {
|
||||
// Change the items per page.
|
||||
$this->view->set_items_per_page(20);
|
||||
// Force a pager to be used.
|
||||
$this->set_option('pager', array('type' => 'some'));
|
||||
return '<p>' . t('A maximum of 20 items will be shown here, all results will be shown on export.') . '</p><pre>' . check_plain($this->view->render()) . '</pre>';
|
||||
}
|
||||
return $this->view->render();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Transfer the output file to the client.
|
||||
*/
|
||||
function transfer_file() {
|
||||
// Build the view so we can set the headers.
|
||||
$this->view->build();
|
||||
// Arguments can cause the style to not get built.
|
||||
if (!$this->view->init_style()) {
|
||||
$this->view->build_info['fail'] = TRUE;
|
||||
}
|
||||
// Set the headers.
|
||||
$this->add_http_headers();
|
||||
file_transfer($this->outputfile_path(), array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on export initialization.
|
||||
*
|
||||
* Modifies the view query to insert the results into a table, which we call
|
||||
* the 'index', this means we essentially have a snapshot of the results,
|
||||
* which we can then take time over rendering.
|
||||
*
|
||||
* This method is essentially all the best bits of the view::execute() method.
|
||||
*/
|
||||
protected function initialize_index() {
|
||||
$view = &$this->view;
|
||||
// Get views to build the query.
|
||||
$view->build();
|
||||
|
||||
// Change the query object to use our custom one.
|
||||
$query = new views_data_export_plugin_query_default_batched();
|
||||
// Copy the query over:
|
||||
foreach ($view->query as $property => $value) {
|
||||
$query->$property = $value;
|
||||
}
|
||||
// Replace the query object.
|
||||
$view->query = $query;
|
||||
|
||||
$view->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a view, construct an map of hashed aliases to aliases.
|
||||
*
|
||||
* The keys of the returned array will have a maximum length of 33 characters.
|
||||
*/
|
||||
function field_aliases_create(&$view) {
|
||||
$all_aliases = array();
|
||||
foreach ($view->query->fields as $field) {
|
||||
if (strlen($field['alias']) > 32) {
|
||||
$all_aliases['a' . md5($field['alias'])] = $field['alias'];
|
||||
}
|
||||
else {
|
||||
$all_aliases[$field['alias']] = $field['alias'];
|
||||
}
|
||||
}
|
||||
return $all_aliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an alias for the weight field in the index.
|
||||
*
|
||||
* This method ensures that it isn't the same as any other alias in the
|
||||
* supplied view's fields.
|
||||
*/
|
||||
function _weight_alias_create(&$view) {
|
||||
$alias = 'vde_weight';
|
||||
$all_aliases = array();
|
||||
foreach ($view->query->fields as $field) {
|
||||
$all_aliases[] = $field['alias'];
|
||||
}
|
||||
// Keep appending '_' until we are unique.
|
||||
while (in_array($alias, $all_aliases)) {
|
||||
$alias .= '_';
|
||||
}
|
||||
return $alias;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the index.
|
||||
*/
|
||||
function remove_index() {
|
||||
$ret = array();
|
||||
if (db_table_exists($this->index_tablename())) {
|
||||
db_drop_table($this->index_tablename());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the unique table to store the index in.
|
||||
*/
|
||||
function index_tablename() {
|
||||
return VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX . $this->batched_execution_state->eid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the output file path.
|
||||
*/
|
||||
function outputfile_path() {
|
||||
if (empty($this->_output_file) && !empty($this->batched_execution_state->fid)) {
|
||||
// Return the filename associated with this file.
|
||||
$this->_output_file = $this->file_load($this->batched_execution_state->fid);
|
||||
}
|
||||
return $this->_output_file->uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on export initialization
|
||||
* Creates the output file, registers it as a temporary file with Drupal
|
||||
* and returns the fid
|
||||
*/
|
||||
protected function outputfile_create() {
|
||||
|
||||
$dir = 'temporary://views_plugin_display';
|
||||
|
||||
// Make sure the directory exists first.
|
||||
if (!file_prepare_directory($dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
|
||||
$this->abort_export(t('Could not create temporary directory for result export (@dir). Check permissions.', array ('@dir' => $dir)));
|
||||
}
|
||||
|
||||
$path = drupal_tempnam($dir, 'views_data_export');
|
||||
|
||||
// Save the file into the DB.
|
||||
$file = $this->file_save_file($path);
|
||||
|
||||
return $file->fid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to the output file.
|
||||
*/
|
||||
protected function outputfile_write($string) {
|
||||
$output_file = $this->outputfile_path();
|
||||
if (file_put_contents($output_file, $string, FILE_APPEND) === FALSE) {
|
||||
$this->abort_export(t('Could not write to temporary output file for result export (@file). Check permissions.', array ('@file' => $output_file)));
|
||||
}
|
||||
}
|
||||
|
||||
function abort_export($errors) {
|
||||
// Just cause the next batch to do the clean-up
|
||||
if (!is_array($errors)) {
|
||||
$errors = array($errors);
|
||||
}
|
||||
foreach ($errors as $error) {
|
||||
drupal_set_message($error . ' ['. t('Export Aborted') . ']', 'error');
|
||||
}
|
||||
$this->batched_execution_state->batch_state = VIEWS_DATA_EXPORT_FINISHED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a file from the database.
|
||||
*
|
||||
* @param $fid
|
||||
* A numeric file id or string containing the file path.
|
||||
* @return
|
||||
* A file object.
|
||||
*/
|
||||
function file_load($fid) {
|
||||
return file_load($fid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a file into a file node after running all the associated validators.
|
||||
*
|
||||
* This function is usually used to move a file from the temporary file
|
||||
* directory to a permanent location. It may be used by import scripts or other
|
||||
* modules that want to save an existing file into the database.
|
||||
*
|
||||
* @param $filepath
|
||||
* The local file path of the file to be saved.
|
||||
* @return
|
||||
* An array containing the file information, or 0 in the event of an error.
|
||||
*/
|
||||
function file_save_file($filepath) {
|
||||
return file_save_data('', $filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function that computes the time remaining
|
||||
*/
|
||||
function compute_time_remaining($started, $finished) {
|
||||
list($usec, $sec) = explode(' ', microtime());
|
||||
$now = (float) $usec + (float) $sec;
|
||||
$diff = round(($now - $started), 0);
|
||||
// So we've taken $diff seconds to get this far.
|
||||
if ($finished > 0) {
|
||||
$estimate_total = $diff / $finished;
|
||||
$stamp = max(1, $estimate_total - $diff);
|
||||
// Round up to nearest 30 seconds.
|
||||
$stamp = ceil($stamp / 30) * 30;
|
||||
// Set the message in the batch context.
|
||||
return t('Time remaining: about @interval.', array('@interval' => format_interval($stamp)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the driver of the database underlying
|
||||
* this query and returns FALSE if it is imcompatible
|
||||
* with the approach taken in this display.
|
||||
* Basically mysql & mysqli will be fine, pg will not
|
||||
*/
|
||||
function is_compatible() {
|
||||
$incompatible_drivers = array (
|
||||
'pgsql',
|
||||
);
|
||||
$db_driver = $this->_get_database_driver();
|
||||
return !in_array($db_driver, $incompatible_drivers);
|
||||
}
|
||||
|
||||
function _get_database_driver() {
|
||||
$name = !empty($this->view->base_database) ? $this->view->base_database : 'default';
|
||||
$conn_info = Database::getConnectionInfo($name);
|
||||
return $conn_info[$name]['driver'];
|
||||
}
|
||||
}
|
||||
|
||||
class views_data_export_plugin_query_default_batched extends views_plugin_query_default {
|
||||
|
||||
|
||||
/**
|
||||
* Executes the query and fills the associated view object with according
|
||||
* values.
|
||||
*
|
||||
* Values to set: $view->result, $view->total_rows, $view->execute_time,
|
||||
* $view->current_page.
|
||||
*/
|
||||
function execute(&$view) {
|
||||
$display_handler = &$view->display_handler;
|
||||
$external = FALSE; // Whether this query will run against an external database.
|
||||
$query = $view->build_info['query'];
|
||||
$count_query = $view->build_info['count_query'];
|
||||
|
||||
$query->addMetaData('view', $view);
|
||||
$count_query->addMetaData('view', $view);
|
||||
|
||||
if (empty($this->options['disable_sql_rewrite'])) {
|
||||
$base_table_data = views_fetch_data($this->base_table);
|
||||
if (isset($base_table_data['table']['base']['access query tag'])) {
|
||||
$access_tag = $base_table_data['table']['base']['access query tag'];
|
||||
$query->addTag($access_tag);
|
||||
$count_query->addTag($access_tag);
|
||||
}
|
||||
}
|
||||
|
||||
$items = array();
|
||||
if ($query) {
|
||||
$additional_arguments = module_invoke_all('views_query_substitutions', $view);
|
||||
|
||||
// Count queries must be run through the preExecute() method.
|
||||
// If not, then hook_query_node_access_alter() may munge the count by
|
||||
// adding a distinct against an empty query string
|
||||
// (e.g. COUNT DISTINCT(1) ...) and no pager will return.
|
||||
// See pager.inc > PagerDefault::execute()
|
||||
// http://api.drupal.org/api/drupal/includes--pager.inc/function/PagerDefault::execute/7
|
||||
// See http://drupal.org/node/1046170.
|
||||
$count_query->preExecute();
|
||||
|
||||
// Build the count query.
|
||||
$count_query = $count_query->countQuery();
|
||||
|
||||
// Add additional arguments as a fake condition.
|
||||
// XXX: this doesn't work... because PDO mandates that all bound arguments
|
||||
// are used on the query. TODO: Find a better way to do this.
|
||||
if (!empty($additional_arguments)) {
|
||||
// $query->where('1 = 1', $additional_arguments);
|
||||
// $count_query->where('1 = 1', $additional_arguments);
|
||||
}
|
||||
|
||||
$start = microtime(TRUE);
|
||||
|
||||
if ($this->pager->use_count_query() || !empty($view->get_total_rows)) {
|
||||
$this->pager->execute_count_query($count_query);
|
||||
}
|
||||
|
||||
// Let the pager modify the query to add limits.
|
||||
$this->pager->pre_execute($query);
|
||||
|
||||
if (!empty($this->limit) || !empty($this->offset)) {
|
||||
// We can't have an offset without a limit, so provide a very large limit instead.
|
||||
$limit = intval(!empty($this->limit) ? $this->limit : 999999);
|
||||
$offset = intval(!empty($this->offset) ? $this->offset : 0);
|
||||
$query->range($offset, $limit);
|
||||
}
|
||||
|
||||
try {
|
||||
// The $query is final and ready to go, we are going to redirect it to
|
||||
// become an insert into our table, sneaky!
|
||||
// Our query will look like:
|
||||
// CREATE TABLE {idx} SELECT @row := @row + 1 AS weight_alias, cl.* FROM
|
||||
// (-query-) AS cl, (SELECT @row := 0) AS r
|
||||
// We do some magic to get the row count.
|
||||
|
||||
$display_handler->batched_execution_state->sandbox['weight_field_alias'] = $display_handler->_weight_alias_create($view);
|
||||
|
||||
$display_handler->batched_execution_state->sandbox['field_aliases'] = $display_handler->field_aliases_create($view);
|
||||
$select_aliases = array();
|
||||
foreach ($display_handler->batched_execution_state->sandbox['field_aliases'] as $hash => $alias) {
|
||||
$select_aliases[] = "cl.$alias AS $hash";
|
||||
}
|
||||
|
||||
// TODO: this could probably be replaced with a query extender and new query type.
|
||||
$query->preExecute();
|
||||
$args = $query->getArguments();
|
||||
$insert_query = 'CREATE TABLE {' . $display_handler->index_tablename() . '} SELECT @row := @row + 1 AS ' . $display_handler->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . (string)$query . ') AS cl, (SELECT @row := 0) AS r';
|
||||
db_query($insert_query, $args);
|
||||
|
||||
|
||||
$view->result = array();
|
||||
|
||||
$this->pager->post_execute($view->result);
|
||||
|
||||
if ($this->pager->use_pager()) {
|
||||
$view->total_rows = $this->pager->get_total_items();
|
||||
}
|
||||
|
||||
// Now create an index for the weight field, otherwise the queries on the
|
||||
// index will take a long time to execute.
|
||||
db_add_unique_key($display_handler->index_tablename(), $display_handler->batched_execution_state->sandbox['weight_field_alias'], array($display_handler->batched_execution_state->sandbox['weight_field_alias']));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$view->result = array();
|
||||
debug('Exception: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
$view->execute_time = microtime(TRUE) - $start;
|
||||
}
|
||||
}
|
@@ -0,0 +1,361 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Plugin include file for export style plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generalized style plugin for export plugins.
|
||||
*
|
||||
* @ingroup views_style_plugins
|
||||
*/
|
||||
class views_data_export_plugin_style_export extends views_plugin_style {
|
||||
|
||||
/**
|
||||
* Set options fields and default values.
|
||||
*
|
||||
* @return
|
||||
* An array of options information.
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['attach_text'] = array(
|
||||
'default' => $this->definition['export feed text'],
|
||||
'translatable' => TRUE,
|
||||
);
|
||||
$options['provide_file'] = array(
|
||||
'default' => FALSE,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['filename'] = array(
|
||||
'default' => $this->definition['export feed file'],
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['parent_sort'] = array(
|
||||
'default' => FALSE,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options form mini callback.
|
||||
*
|
||||
* @param $form
|
||||
* Form array to add additional fields to.
|
||||
* @param $form_state
|
||||
* State of the form.
|
||||
* @return
|
||||
* None.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
$form['attach_text'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Attach text'),
|
||||
'#default_value' => $this->options['attach_text'],
|
||||
'#description' => t('This text is used in building the feed link. By default it is the "alt" text for the feed image.'),
|
||||
);
|
||||
$form['provide_file'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Provide as file'),
|
||||
'#default_value' => $this->options['provide_file'],
|
||||
'#description' => t('By deselecting this, the xml file will be provided as a feed instead of a file for download.'),
|
||||
);
|
||||
$form['filename'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Filename'),
|
||||
'#default_value' => $this->options['filename'],
|
||||
'#description' => t('The filename that will be suggested to the browser for downloading purposes. You may include replacement patterns from the list below.'),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array(
|
||||
'edit-style-options-provide-file' => array(TRUE),
|
||||
),
|
||||
);
|
||||
|
||||
// General token replacement.
|
||||
$output = t('<p>The following substitution patterns are available for this display. Use the pattern shown on the left to display the value indicated on the right.</p>');
|
||||
$items = array(
|
||||
'%view == ' . t('View name'),
|
||||
'%display == ' . t('Display name'),
|
||||
);
|
||||
|
||||
$output .= theme('item_list', array('items' => $items));
|
||||
|
||||
// Get a list of the available arguments for token replacement.
|
||||
$options = array();
|
||||
|
||||
$count = 0; // This lets us prepare the key as we want it printed.
|
||||
foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) {
|
||||
$options[t('Arguments')]['%' . ++$count . '-title'] = t('@argument title', array('@argument' => $handler->ui_name()));
|
||||
$options[t('Arguments')]['%' . $count . '-value'] = t('@argument value', array('@argument' => $handler->ui_name()));
|
||||
}
|
||||
|
||||
// Append the list with exposed filters stuff.
|
||||
$options[t('Exposed filters')]['%exposed'] = t('effective exposed filters, like <em>filter1_foo-filter2_bar</em>');
|
||||
|
||||
// ...and datestamp.
|
||||
$time = REQUEST_TIME;
|
||||
$parts = array(
|
||||
'full' => 'Y-m-d\TH-i-s',
|
||||
'yy' => 'y',
|
||||
'yyyy' => 'Y',
|
||||
'mm' => 'm',
|
||||
'mmm' => 'M',
|
||||
'dd' => 'd',
|
||||
'ddd' => 'D',
|
||||
'hh' => 'H',
|
||||
'ii' => 'i',
|
||||
'ss' => 's',
|
||||
);
|
||||
foreach ($parts as $part => $format) {
|
||||
$options[t('Timestamp')]['%timestamp-' . $part] = format_date($time, 'custom', $format);
|
||||
}
|
||||
|
||||
// We have some options, so make a list.
|
||||
if (!empty($options)) {
|
||||
foreach (array_keys($options) as $type) {
|
||||
if (!empty($options[$type])) {
|
||||
$items = array();
|
||||
foreach ($options[$type] as $key => $value) {
|
||||
$items[] = $key . ' == ' . $value;
|
||||
}
|
||||
$output .= theme('item_list', array('items' => $items, 'title' => $type));
|
||||
}
|
||||
}
|
||||
}
|
||||
$form['help'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Replacement patterns'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#value' => $output,
|
||||
'#dependency' => array(
|
||||
'edit-style-options-provide-file' => array(1),
|
||||
),
|
||||
);
|
||||
$form['parent_sort'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Parent sort'),
|
||||
'#default_value' => $this->options['parent_sort'],
|
||||
'#description' => t('Try to apply any additional sorting from the attached display like table sorting to the exported feed.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach this view to another display as a feed.
|
||||
*
|
||||
* Provide basic functionality for all export style views like attaching a
|
||||
* feed image link.
|
||||
*/
|
||||
function attach_to($display_id, $path, $title) {
|
||||
|
||||
$type = $this->definition['export feed type'];
|
||||
$theme_pattern = array(
|
||||
'views_data_export_feed_icon__' . $this->view->name . '__' . $display_id . '__' . $type,
|
||||
'views_data_export_feed_icon__' . $this->view->name . '__' . $display_id,
|
||||
'views_data_export_feed_icon__' . $this->view->name . '__' . $type,
|
||||
'views_data_export_feed_icon__' . $display_id . '__' . $type,
|
||||
'views_data_export_feed_icon__' . $display_id,
|
||||
'views_data_export_feed_icon__' . $type,
|
||||
'views_data_export_feed_icon',
|
||||
);
|
||||
$query = $this->view->get_exposed_input();
|
||||
// Stash the display id we're coming form in the url so we can hijack it later.
|
||||
if ($this->options['parent_sort']) {
|
||||
$query['attach'] = $display_id;
|
||||
}
|
||||
$this->view->feed_icon .= theme($theme_pattern, array(
|
||||
'image_path' => $this->definition['export feed icon'],
|
||||
'url' => $this->view->get_url(NULL, $path),
|
||||
'query' => $query,
|
||||
'text' => $this->options['attach_text'],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function build_sort() {
|
||||
|
||||
// Bypass doing any sort of testing if parent sorting is disabled.
|
||||
if (!$this->options['parent_sort']) {
|
||||
return parent::build_sort();
|
||||
}
|
||||
|
||||
$displays = $this->display->handler->get_option('displays');
|
||||
|
||||
// Here is later. We can get the passed argument and use it to know which
|
||||
// display we can from and then do some addition processing.
|
||||
// If the display exists and is attached these two tests will succeed.
|
||||
if (isset($_GET['attach']) && isset($displays[$_GET['attach']]) && $displays[$_GET['attach']]) {
|
||||
// Setup the second style we're going to be using to sort on.
|
||||
$plugin_id = $displays[$_GET['attach']];
|
||||
$parent_display = $this->view->display[$plugin_id];
|
||||
$style_name = $parent_display->handler->get_option('style_plugin');
|
||||
$style_options = $parent_display->handler->get_option('style_options');
|
||||
$this->extra_style = views_get_plugin('style', $style_name);
|
||||
$this->extra_style->init($this->view, $parent_display, $style_options);
|
||||
|
||||
// Call the second styles sort funciton and return the value.
|
||||
return $this->extra_style->build_sort();
|
||||
}
|
||||
}
|
||||
|
||||
function build_sort_post() {
|
||||
// If we found an extra style plugin earlier, pass off the build_sort_post call to it.
|
||||
if (isset($this->extra_style)) {
|
||||
return $this->extra_style->build_sort_post();
|
||||
}
|
||||
else {
|
||||
return parent::build_sort_post();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the display in this style.
|
||||
*/
|
||||
function render() {
|
||||
if ($this->uses_row_plugin() && empty($this->row_plugin)) {
|
||||
vpr('views_plugin_style_default: Missing row plugin');
|
||||
return;
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$rows['header'] = $this->render_header();
|
||||
$rows['body'] = $this->render_body();
|
||||
$rows['footer'] = $this->render_footer();
|
||||
$title = '';
|
||||
$output .= theme($this->theme_functions(), array('view' => $this->view, 'options' => $this->options, 'rows' => $rows, 'title' => $title));
|
||||
return $output;
|
||||
}
|
||||
|
||||
function render_header() {
|
||||
$rows = array();
|
||||
$title = '';
|
||||
$output = '';
|
||||
$output .= theme($this->theme_functions($this->definition['additional themes base'] . '_header'), array('view' => $this->view, 'options' => $this->options, 'rows' => $rows, 'title' => $title));
|
||||
return $output;
|
||||
}
|
||||
|
||||
function render_footer() {
|
||||
$rows = array();
|
||||
$title = '';
|
||||
$output = '';
|
||||
$output .= theme($this->theme_functions($this->definition['additional themes base'] . '_footer'), array('view' => $this->view, 'options' => $this->options, 'rows' => $rows, 'title' => $title));
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function render_body() {
|
||||
if ($this->uses_row_plugin() && empty($this->row_plugin)) {
|
||||
vpr('views_plugin_style_default: Missing row plugin');
|
||||
return;
|
||||
}
|
||||
|
||||
// Group the rows according to the grouping field, if specified.
|
||||
$sets = $this->render_grouping($this->view->result, $this->options['grouping']);
|
||||
|
||||
// Render each group separately and concatenate. Plugins may override this
|
||||
// method if they wish some other way of handling grouping.
|
||||
$output = '';
|
||||
foreach ($sets as $title => $records) {
|
||||
if ($this->uses_row_plugin()) {
|
||||
$rows = array();
|
||||
foreach ($records as $row_index => $row) {
|
||||
$this->view->row_index = $row_index;
|
||||
$rows[] = $this->row_plugin->render($row);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$rows = $records;
|
||||
}
|
||||
|
||||
$title = '';
|
||||
$output .= theme($this->theme_functions($this->definition['additional themes base'] . '_body'), array('view' => $this->view, 'options' => $this->options, 'rows' => $rows, 'title' => $title));
|
||||
}
|
||||
unset($this->view->row_index);
|
||||
return $output;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a full list of possible theme templates used by this style.
|
||||
*/
|
||||
function theme_functions($hook = NULL) {
|
||||
if (is_null($hook)) {
|
||||
$hook = $this->definition['theme'];
|
||||
}
|
||||
return views_theme_functions($hook, $this->view, $this->display);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any HTTP headers that this style plugin wants to.
|
||||
*/
|
||||
function add_http_headers() {
|
||||
$view = &$this->view;
|
||||
|
||||
drupal_add_http_header('Cache-Control', 'max-age=60, must-revalidate');
|
||||
|
||||
if (!empty($this->definition['export headers'])) {
|
||||
foreach ($this->definition['export headers'] as $name => $value) {
|
||||
drupal_add_http_header($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->options['filename']) && !empty($this->options['provide_file'])) {
|
||||
// General tokens.
|
||||
$tokens = array(
|
||||
'%view' => check_plain($view->name),
|
||||
'%display' => check_plain($view->current_display),
|
||||
);
|
||||
// Argument tokens.
|
||||
$count = 0;
|
||||
foreach ($view->display_handler->get_handlers('argument') as $arg => $handler) {
|
||||
$token = '%' . ++$count;
|
||||
$tokens[$token . '-title'] = check_plain($handler->title());
|
||||
$tokens[$token . '-value'] = isset($view->args[$count - 1]) ? check_plain($view->args[$count - 1]) : '';
|
||||
}
|
||||
|
||||
// Effective exposed filters token.
|
||||
$exposed = array();
|
||||
foreach ($view->display_handler->get_handlers('filter') as $arg => $handler) {
|
||||
if (!$handler->options['exposed']) {
|
||||
continue;
|
||||
}
|
||||
if (!empty($view->exposed_input[$handler->options['expose']['identifier']])) {
|
||||
$exposed[] = check_plain($handler->options['expose']['identifier']) . '_' . check_plain($view->exposed_input[$handler->options['expose']['identifier']]);
|
||||
}
|
||||
}
|
||||
if (!empty($exposed)) {
|
||||
$tokens['%exposed'] = implode('-', $exposed);
|
||||
}
|
||||
else {
|
||||
$tokens['%exposed'] = 'default' ;
|
||||
}
|
||||
|
||||
// Timestamp token.
|
||||
$time = REQUEST_TIME;
|
||||
$parts = array(
|
||||
'full' => 'Y-m-d\TH-i-s',
|
||||
'yy' => 'y',
|
||||
'yyyy' => 'Y',
|
||||
'mm' => 'm',
|
||||
'mmm' => 'M',
|
||||
'dd' => 'd',
|
||||
'ddd' => 'D',
|
||||
'hh' => 'H',
|
||||
'ii' => 'i',
|
||||
'ss' => 's',
|
||||
);
|
||||
foreach ($parts as $part => $format) {
|
||||
$tokens['%timestamp-' . $part] = format_date($time, 'custom', $format);
|
||||
}
|
||||
|
||||
$filename = strtr($this->options['filename'], $tokens);
|
||||
|
||||
|
||||
if ($filename) {
|
||||
drupal_add_http_header('Content-Disposition', 'attachment; filename="'. $filename .'"');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Plugin include file for export style plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generalized style plugin for export plugins.
|
||||
*
|
||||
* @ingroup views_style_plugins
|
||||
*/
|
||||
class views_data_export_plugin_style_export_csv extends views_data_export_plugin_style_export {
|
||||
|
||||
/**
|
||||
* Set options fields and default values.
|
||||
*
|
||||
* @return
|
||||
* An array of options information.
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['separator'] = array(
|
||||
'default' => ',',
|
||||
'translatable' => TRUE,
|
||||
);
|
||||
$options['quote'] = array(
|
||||
'default' => TRUE,
|
||||
'translatable' => TRUE,
|
||||
);
|
||||
$options['trim'] = array(
|
||||
'default' => FALSE,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['replace_newlines'] = array(
|
||||
'default' => FALSE,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['newline_replacement'] = array(
|
||||
'default' => ', ',
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['header'] = array(
|
||||
'default' => TRUE,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['encoding'] = array(
|
||||
'default' => '',
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options form mini callback.
|
||||
*
|
||||
* @param $form
|
||||
* Form array to add additional fields to.
|
||||
* @param $form_state
|
||||
* State of the form.
|
||||
* @return
|
||||
* None.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['separator'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Separator'),
|
||||
'#default_value' => !empty($this->options['separator']) ? $this->options['separator'] : ',',
|
||||
'#description' => t('This is the separator that is used to separate fields. CSV implies comma separated fields so this should not be changed unless you have specific requirements'),
|
||||
);
|
||||
$form['quote'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['quote']),
|
||||
'#title' => t('Quote values. Useful for output that might contain your separator as part of one of the values.'),
|
||||
);
|
||||
$form['trim'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['trim']),
|
||||
'#title' => t('Trim whitespace from rendered fields. Can be useful for some themes where output results in extra newlines.'),
|
||||
);
|
||||
$form['replace_newlines'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['replace_newlines']),
|
||||
'#title' => t('Replace newlines in rendered fields.'),
|
||||
);
|
||||
$form['newline_replacement'] = array(
|
||||
'#prefix' => '<div><div id="edit-options-newline-replacement">',
|
||||
'#suffix' => '</div></div>',
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Replacement'),
|
||||
'#default_value' => $this->options['newline_replacement'],
|
||||
'#process' => array('form_process_checkboxes', 'ctools_dependent_process'),
|
||||
'#dependency' => array('edit-style-options-replace-newlines' => array(TRUE)),
|
||||
);
|
||||
$form['header'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Make first row a list of column headers.'),
|
||||
'#default_value' => !empty($this->options['header']),
|
||||
);
|
||||
$form['encoding'] = array(
|
||||
'#type' => 'select',
|
||||
'#default_value' => !empty($this->options['encoding']) ? $this->options['encoding'] : '',
|
||||
'#title' => t('Character encoding conversion'),
|
||||
'#options' => array (
|
||||
'' => t('No conversion'),
|
||||
'ASCII' => t('ASCII'),
|
||||
),
|
||||
'#description' => t('Optionally specify a character conversion that some CSV file readers need. Note, using an external tool is always preferred and you should only use this option as a last resort. This feature requires the "iconv" PHP extension.'),
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Plugin include file for export style plugin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generalized style plugin for export plugins.
|
||||
*
|
||||
* @ingroup views_style_plugins
|
||||
*/
|
||||
class views_data_export_plugin_style_export_xml extends views_data_export_plugin_style_export {
|
||||
|
||||
/**
|
||||
* Set options fields and default values.
|
||||
*
|
||||
* @return
|
||||
* An array of options information.
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['transform'] = array(
|
||||
'default' => TRUE,
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
$options['transform_type'] = array(
|
||||
'default' => 'dash',
|
||||
'translatable' => FALSE,
|
||||
);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options form mini callback.
|
||||
*
|
||||
* @param $form
|
||||
* Form array to add additional fields to.
|
||||
* @param $form_state
|
||||
* State of the form.
|
||||
* @return
|
||||
* None.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form['transform'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Transform spaces'),
|
||||
'#default_value' => $this->options['transform'],
|
||||
'#description' => t('Transform spaces to valid XML in field labels (spaces create invalid XML markup). Note that invalid XML tag characters will always be converted.'),
|
||||
);
|
||||
$form['transform_type'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Transform type'),
|
||||
'#default_value' => $this->options['transform_type'],
|
||||
'#options' => array(
|
||||
'dash' => t('Dash'),
|
||||
'underline' => t('Underline'),
|
||||
'camel' => t('camelCase'),
|
||||
'pascal' => t('PascalCase'),
|
||||
),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array(
|
||||
'edit-style-options-transform' => array(TRUE),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
// Print out exported items.
|
||||
foreach ($themed_rows as $count => $item_row):
|
||||
print implode($separator, $item_row) . "\r\n";
|
||||
endforeach;
|
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CSV files don't really have a footer.
|
||||
*/
|
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
// Print out header row, if option was selected.
|
||||
if ($options['header']) {
|
||||
print implode($separator, $header) . "\r\n";
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php print $tbody; ?>
|
@@ -0,0 +1,4 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<?php print $header_row; ?>
|
||||
<tbody>
|
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* @file views-view-table.tpl.php
|
||||
* Template to display a view as a table.
|
||||
*
|
||||
* - $title : The title of this group of rows. May be empty.
|
||||
* - $rows: An array of row items. Each row is an array of content
|
||||
* keyed by field ID.
|
||||
* - $header: an array of haeaders(labels) for fields.
|
||||
* - $themed_rows: a array of rows with themed fields.
|
||||
* @ingroup views_templates
|
||||
*/
|
||||
|
||||
foreach ($themed_rows as $count => $row):
|
||||
foreach ($row as $field => $content):
|
||||
?>
|
||||
[<?php print $header[$field]; ?>]
|
||||
|
||||
<?php print strip_tags($content); // strip html so its plain txt. ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
----------------------------------------
|
||||
|
||||
<?php endforeach;
|
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* TXT files don't really have a footer.
|
||||
*/
|
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
// TXT files don't really have a footer.
|
@@ -0,0 +1 @@
|
||||
<?php print $tbody; ?>
|
@@ -0,0 +1,4 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<?php print $header_row; ?>
|
||||
<tbody>
|
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
/**
|
||||
* @file views-view-table.tpl.php
|
||||
* Template to display a view as a table.
|
||||
*
|
||||
* - $title : The title of this group of rows. May be empty.
|
||||
* - $rows: An array of row items. Each row is an array of content
|
||||
* keyed by field ID.
|
||||
* - $header: an array of headers(labels) for fields.
|
||||
* - $themed_rows: a array of rows with themed fields.
|
||||
* @ingroup views_templates
|
||||
*/
|
||||
?>
|
||||
<?php foreach ($themed_rows as $count => $row): ?>
|
||||
<<?php print $item_node; ?>>
|
||||
<?php foreach ($row as $field => $content): ?>
|
||||
<<?php print $xml_tag[$field]; ?>><?php print $content; ?></<?php print $xml_tag[$field]; ?>>
|
||||
<?php endforeach; ?>
|
||||
</<?php print $item_node; ?>>
|
||||
<?php endforeach; ?>
|
@@ -0,0 +1 @@
|
||||
</<?php print $root_node; ?>>
|
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @file views-view-table.tpl.php
|
||||
* Template to display a view as a table.
|
||||
*
|
||||
* - $title : The title of this group of rows. May be empty.
|
||||
* - $rows: An array of row items. Each row is an array of content
|
||||
* keyed by field ID.
|
||||
* - $header: an array of headers(labels) for fields.
|
||||
* - $themed_rows: a array of rows with themed fields.
|
||||
* @ingroup views_templates
|
||||
*/
|
||||
|
||||
// Short tags act bad below in the html so we print it here.
|
||||
print '<?xml version="1.0" encoding="UTF-8" ?>';
|
||||
?>
|
||||
|
||||
<<?php print $root_node; ?>>
|
@@ -0,0 +1,3 @@
|
||||
<?php print $header ?>
|
||||
<?php print $body ?>
|
||||
<?php print $footer ?>
|
@@ -0,0 +1,480 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Theme related functions for processing our output style plugins.
|
||||
*
|
||||
* Views bug: http://drupal.org/node/593336
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Theme a status message
|
||||
*/
|
||||
function theme_views_data_export_message($var) {
|
||||
$output = '';
|
||||
$output .= '<div class="messages status ' . $var['type'] . '">';
|
||||
$output .= $var['message'];
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme a feed link.
|
||||
*
|
||||
* This theme function uses the theme pattern system to allow it to be
|
||||
* overidden in a more specific manner. The options for overiding this include
|
||||
* providing per display id; per type; per display id and per type.
|
||||
*
|
||||
* e.g.
|
||||
* For the view "export_test" with the display "page_1" and the type "csv" you
|
||||
* would have the following options.
|
||||
* views_data_export_feed_icon__export_test__page_1__csv
|
||||
* views_data_export_feed_icon__export_test__page_1
|
||||
* views_data_export_feed_icon__export_test__csv
|
||||
* views_data_export_feed_icon__page_1__csv
|
||||
* views_data_export_feed_icon__page_1
|
||||
* views_data_export_feed_icon__csv
|
||||
* views_data_export_feed_icon
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_views_data_export_feed_icon($variables) {
|
||||
extract($variables, EXTR_SKIP);
|
||||
$url_options = array('html' => true);
|
||||
if ($query) {
|
||||
$url_options['query'] = $query;
|
||||
}
|
||||
$image = theme('image', array('path' => $image_path, 'alt' => $text, 'title' => $text));
|
||||
return l($image, $url, $url_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme callback for the export complete page.
|
||||
*
|
||||
* @param $file
|
||||
* Link to output file
|
||||
*/
|
||||
function theme_views_data_export_complete_page($variables) {
|
||||
extract($variables, EXTR_SKIP);
|
||||
drupal_set_title(t('Data export successful'));
|
||||
drupal_add_html_head(array('#tag' => 'meta', '#attributes' => array('http-equiv' =>"refresh", 'content' => '3;url='. $file)), 'views_data_export_download');
|
||||
$output = '';
|
||||
$output .= '<p>';
|
||||
$output .= t('Your export has been created. View/download the file <a href="@link">here</a> (will automatically download in 3 seconds.)', array('@link' => $file));
|
||||
$output .= '</p>';
|
||||
|
||||
if (!empty($return_url)) {
|
||||
$output .= '<p>';
|
||||
$output .= l(t('Return to previous page'), $return_url);
|
||||
$output .= '</p>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function template_preprocess_views_data_export(&$vars) {
|
||||
$vars['header'] = $vars['rows']['header'];
|
||||
$vars['body'] = $vars['rows']['body'];
|
||||
$vars['footer'] = $vars['rows']['footer'];
|
||||
|
||||
$view = $vars['view'];
|
||||
$fields = &$view->field;
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_csv_header(&$vars) {
|
||||
_views_data_export_header_shared_preprocess($vars);
|
||||
|
||||
// Make sure we catch saved options that are misspelled. LEGACY
|
||||
if (isset($vars['options']['seperator'])) {
|
||||
$vars['options']['separator'] = $vars['options']['seperator'];
|
||||
}
|
||||
// Support old misspelled templates. LEGACY
|
||||
$vars['seperator'] =
|
||||
$vars['separator'] = $vars['options']['separator'];
|
||||
|
||||
// Special handling when quoted values are involved.
|
||||
if ($vars['options']['quote']) {
|
||||
$wrap = '"';
|
||||
$replace_value = '""';
|
||||
}
|
||||
else {
|
||||
$wrap = '';
|
||||
$replace_value = '';
|
||||
}
|
||||
|
||||
// Format header values.
|
||||
foreach ($vars['header'] as $key => $value) {
|
||||
$output = decode_entities(strip_tags($value));
|
||||
if (!empty($vars['options']['trim'])) {
|
||||
$output = trim($output);
|
||||
}
|
||||
if (!empty($vars['options']['encoding']) && function_exists('iconv')) {
|
||||
switch($vars['options']['encoding']) {
|
||||
case 'ASCII':
|
||||
$converted = iconv("UTF-8", "ASCII//TRANSLIT", $output);
|
||||
if ($converted !== FALSE) {
|
||||
$output = $converted;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$vars['header'][$key] = $wrap . str_replace('"', $replace_value, $output) . $wrap;
|
||||
}
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_csv_body(&$vars) {
|
||||
_views_data_export_body_shared_preprocess($vars);
|
||||
|
||||
// Make sure we catch saved options that are misspelled. LEGACY
|
||||
if (isset($vars['options']['seperator'])) {
|
||||
$vars['options']['separator'] = $vars['options']['seperator'];
|
||||
}
|
||||
// Support old misspelled templates. LEGACY
|
||||
$vars['seperator'] =
|
||||
$vars['separator'] = $vars['options']['separator'];
|
||||
|
||||
// Special handling when quoted values are involved.
|
||||
if ($vars['options']['quote']) {
|
||||
$wrap = '"';
|
||||
$replace_value = '""';
|
||||
}
|
||||
else {
|
||||
$wrap = '';
|
||||
$replace_value = '';
|
||||
}
|
||||
|
||||
// Format row values.
|
||||
foreach ($vars['themed_rows'] as $i => $values) {
|
||||
foreach ($values as $j => $value) {
|
||||
$output = decode_entities(strip_tags($value));
|
||||
if (!empty($vars['options']['trim'])) {
|
||||
$output = trim($output);
|
||||
}
|
||||
|
||||
if (!empty($vars['options']['encoding']) && function_exists('iconv')) {
|
||||
switch($vars['options']['encoding']) {
|
||||
case 'ASCII':
|
||||
$converted = iconv("UTF-8", "ASCII//TRANSLIT", $output);
|
||||
if ($converted !== FALSE) {
|
||||
$output = $converted;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty($vars['options']['replace_newlines'])) {
|
||||
$output = str_replace("\n", $vars['options']['newline_replacement'], $output);
|
||||
}
|
||||
$vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, $output) . $wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess csv output template.
|
||||
*/
|
||||
function template_preprocess_views_data_export_csv(&$vars) {
|
||||
// TODO Replace items with themed_rows.
|
||||
_views_data_export_shared_preprocess($vars);
|
||||
|
||||
// Make sure we catch saved options that are misspelled. LEGACY
|
||||
if (isset($vars['options']['separator'])) {
|
||||
$vars['options']['separator'] = $vars['options']['seperator'];
|
||||
}
|
||||
// Support old misspelled templates. LEGACY
|
||||
$vars['seperator'] =
|
||||
$vars['separator'] = $vars['options']['separator'];
|
||||
|
||||
// Special handling when quoted values are involved.
|
||||
if ($vars['options']['quote']) {
|
||||
$wrap = '"';
|
||||
$replace_value = '""';
|
||||
}
|
||||
else {
|
||||
$wrap = '';
|
||||
$replace_value = '';
|
||||
}
|
||||
|
||||
// Format header values.
|
||||
foreach ($vars['header'] as $key => $value) {
|
||||
$output = decode_entities(strip_tags($value));
|
||||
if ($vars['options']['trim']) {
|
||||
$output = trim($output);
|
||||
}
|
||||
if (!empty($vars['options']['encoding']) && function_exists('iconv')) {
|
||||
switch($vars['options']['encoding']) {
|
||||
case 'ASCII':
|
||||
$converted = iconv("UTF-8", "ASCII//TRANSLIT", $output);
|
||||
if ($converted !== FALSE) {
|
||||
$output = $converted;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$vars['header'][$key] = $wrap . str_replace('"', $replace_value, $output) . $wrap;
|
||||
}
|
||||
|
||||
// Format row values.
|
||||
foreach ($vars['themed_rows'] as $i => $values) {
|
||||
foreach ($values as $j => $value) {
|
||||
$output = decode_entities(strip_tags($value));
|
||||
if ($vars['options']['trim']) {
|
||||
$output = trim($output);
|
||||
}
|
||||
if (!empty($vars['options']['encoding']) && function_exists('iconv')) {
|
||||
switch($vars['options']['encoding']) {
|
||||
case 'ASCII':
|
||||
$converted = iconv("UTF-8", "ASCII//TRANSLIT", $output);
|
||||
if ($converted !== FALSE) {
|
||||
$output = $converted;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$vars['themed_rows'][$i][$j] = $wrap . str_replace('"', $replace_value, $output) . $wrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess txt output template.
|
||||
*/
|
||||
function template_preprocess_views_data_export_txt_body(&$vars) {
|
||||
_views_data_export_header_shared_preprocess($vars);
|
||||
_views_data_export_body_shared_preprocess($vars);
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_doc_body(&$vars) {
|
||||
// Pass through the generic MS Office preprocess.
|
||||
template_preprocess_views_data_export_msoffice_body($vars);
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_xls_body(&$vars) {
|
||||
// Pass through the generic MS Office preprocess.
|
||||
template_preprocess_views_data_export_msoffice_body($vars);
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_msoffice_body(&$vars) {
|
||||
_views_data_export_header_shared_preprocess($vars);
|
||||
_views_data_export_body_shared_preprocess($vars);
|
||||
|
||||
$output = '';
|
||||
|
||||
// Construct the tbody of a table, see theme_table().
|
||||
|
||||
$ts = tablesort_init($vars['header']);
|
||||
|
||||
$flip = array(
|
||||
'even' => 'odd',
|
||||
'odd' => 'even',
|
||||
);
|
||||
$class = 'even';
|
||||
foreach ($vars['themed_rows'] as $number => $row) {
|
||||
$attributes = array();
|
||||
|
||||
// Check if we're dealing with a simple or complex row
|
||||
if (isset($row['data'])) {
|
||||
foreach ($row as $key => $value) {
|
||||
if ($key == 'data') {
|
||||
$cells = $value;
|
||||
}
|
||||
else {
|
||||
$attributes[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$cells = $row;
|
||||
}
|
||||
if (count($cells)) {
|
||||
// Add odd/even class
|
||||
$class = $flip[$class];
|
||||
if (isset($attributes['class'])) {
|
||||
$attributes['class'] .= ' ' . $class;
|
||||
}
|
||||
else {
|
||||
$attributes['class'] = $class;
|
||||
}
|
||||
|
||||
// Build row
|
||||
$output .= ' <tr' . drupal_attributes($attributes) . '>';
|
||||
$i = 0;
|
||||
foreach ($cells as $cell) {
|
||||
$cell = tablesort_cell($cell, $vars['header'], $ts, $i++);
|
||||
$output .= _theme_table_cell($cell);
|
||||
}
|
||||
$output .= " </tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$vars['tbody'] = preg_replace('/<\/?(a|span) ?.*?>/', '', $output); // strip 'a' and 'span' tags
|
||||
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_doc_header(&$vars) {
|
||||
// Pass through the generic MS Office preprocess.
|
||||
template_preprocess_views_data_export_msoffice_header($vars);
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_xls_header(&$vars) {
|
||||
// Pass through the generic MS Office preprocess.
|
||||
template_preprocess_views_data_export_msoffice_header($vars);
|
||||
}
|
||||
|
||||
function template_preprocess_views_data_export_msoffice_header(&$vars) {
|
||||
_views_data_export_header_shared_preprocess($vars);
|
||||
|
||||
// Need to do a little work to construct the table header, see theme_table().
|
||||
$vars['header_row'] = '';
|
||||
$vars['header_row'] .= '<thead><tr>';
|
||||
|
||||
$ts = tablesort_init($vars['header']);
|
||||
|
||||
foreach ($vars['header'] as $cell) {
|
||||
$cell = tablesort_header($cell, $vars['header'], $ts);
|
||||
$vars['header_row'] .= _theme_table_cell($cell, TRUE);
|
||||
}
|
||||
|
||||
$vars['header_row'] .= '</tr></thead>';
|
||||
|
||||
$vars['header_row'] = preg_replace('/<\/?(a|span) ?.*?>/', '', $vars['header_row']); // strip 'a' and 'span' tags
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess xml output template.
|
||||
*/
|
||||
function template_preprocess_views_data_export_xml_header(&$vars) {
|
||||
// Compute the root XML node, using the base table, and appending an 's' if needed.
|
||||
$root_node = $vars['view']->base_table;
|
||||
if (rtrim($root_node, 's') == $root_node) {
|
||||
$root_node .= 's';
|
||||
}
|
||||
$vars['root_node'] = _views_data_export_xml_tag_clean($root_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess xml output template.
|
||||
*/
|
||||
function template_preprocess_views_data_export_xml_footer(&$vars) {
|
||||
// Compute the root XML node, using the base table, and appending an 's' if needed.
|
||||
$root_node = $vars['view']->base_table;
|
||||
if (rtrim($root_node, 's') == $root_node) {
|
||||
$root_node .= 's';
|
||||
}
|
||||
$vars['root_node'] = _views_data_export_xml_tag_clean($root_node);
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocess xml output template.
|
||||
*/
|
||||
function template_preprocess_views_data_export_xml_body(&$vars) {
|
||||
_views_data_export_header_shared_preprocess($vars);
|
||||
_views_data_export_body_shared_preprocess($vars);
|
||||
|
||||
// Compute the tag name based on the views base table, minus any trailing 's'.
|
||||
$vars['item_node'] = _views_data_export_xml_tag_clean(rtrim($vars['view']->base_table, 's'));
|
||||
|
||||
foreach ($vars['themed_rows'] as $num => $row) {
|
||||
foreach ($row as $field => $content) {
|
||||
// Prevent double encoding of the ampersand. Look for the entities produced by check_plain().
|
||||
$content = preg_replace('/&(?!(amp|quot|#039|lt|gt);)/', '&', $content);
|
||||
// Convert < and > to HTML entities.
|
||||
$content = str_replace(
|
||||
array('<', '>'),
|
||||
array('<', '>'),
|
||||
$content);
|
||||
$vars['themed_rows'][$num][$field] = $content;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($vars['header'] as $field => $header) {
|
||||
// If there is no field label, use 'no name'.
|
||||
$vars['xml_tag'][$field] = !empty($header) ? $header : 'no name';
|
||||
if ($vars['options']['transform']) {
|
||||
switch ($vars['options']['transform_type']) {
|
||||
case 'dash':
|
||||
$vars['xml_tag'][$field] = str_replace(' ', '-', $header);
|
||||
break;
|
||||
case 'underline':
|
||||
$vars['xml_tag'][$field] = str_replace(' ', '_', $header);
|
||||
break;
|
||||
case 'camel':
|
||||
$vars['xml_tag'][$field] = str_replace(' ', '', ucwords(strtolower($header)));
|
||||
// Convert the very first character of the string to lowercase.
|
||||
$vars['xml_tag'][$field][0] = strtolower($vars['xml_tag'][$field][0]);
|
||||
break;
|
||||
case 'pascal':
|
||||
$vars['xml_tag'][$field] = str_replace(' ', '', ucwords(strtolower($header)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
// We should always try to output valid XML.
|
||||
$vars['xml_tag'][$field] = _views_data_export_xml_tag_clean($vars['xml_tag'][$field]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a valid XML tag formed from the given input.
|
||||
*
|
||||
* @param $tag The string that should be made into a valid XML tag.
|
||||
* @return The valid XML tag or an empty string if the string contained no valid
|
||||
* XML tag characters.
|
||||
*/
|
||||
function _views_data_export_xml_tag_clean($tag) {
|
||||
|
||||
// This regex matches characters that are not valid in XML tags, and the
|
||||
// unicode ones that are. We don't bother with unicode, because it would so
|
||||
// the preg_replace down a lot.
|
||||
static $invalid_tag_chars_regex = '#[^\:A-Za-z_\-.0-9]+#';
|
||||
|
||||
// These characters are not valid at the start of an XML tag:
|
||||
static $invalid_start_chars = '-.0123456789';
|
||||
|
||||
// Convert invalid chars to '-':
|
||||
$tag = preg_replace($invalid_tag_chars_regex, '-', $tag);
|
||||
|
||||
// Need to trim invalid characters from the start of the string:
|
||||
$tag = ltrim($tag, $invalid_start_chars);
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared helper function for export preprocess functions.
|
||||
*/
|
||||
function _views_data_export_header_shared_preprocess(&$vars) {
|
||||
$view = $vars['view'];
|
||||
$fields = &$view->field;
|
||||
|
||||
$vars['header'] = array();
|
||||
foreach ($fields as $key => $field) {
|
||||
if (empty($field->options['exclude'])) {
|
||||
$vars['header'][$key] = check_plain($field->label());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shared helper function for export preprocess functions.
|
||||
*/
|
||||
function _views_data_export_body_shared_preprocess(&$vars) {
|
||||
$view = $vars['view'];
|
||||
$fields = &$view->field;
|
||||
|
||||
$rows = $vars['rows'];
|
||||
|
||||
$vars['themed_rows'] = array();
|
||||
$keys = array_keys($fields);
|
||||
foreach ($rows as $num => $row) {
|
||||
$vars['themed_rows'][$num] = array();
|
||||
|
||||
foreach ($keys as $id) {
|
||||
if (empty($fields[$id]->options['exclude'])) {
|
||||
$vars['themed_rows'][$num][$id] = $view->style_plugin->rendered_fields[$num][$id];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_drush_command().
|
||||
*/
|
||||
function views_data_export_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$items['views-data-export'] = array (
|
||||
'aliases' => array (
|
||||
'vde',
|
||||
),
|
||||
'description' => 'Fully executes a views_data_export display of a view and writes the output to file.',
|
||||
'arguments' => array (
|
||||
'view_name' => 'The name of the view',
|
||||
'display_id' => 'The id of the views_data_export display to execute on the view',
|
||||
'output_file' => 'The file to write the results to - will be overwritten if it already exists',
|
||||
),
|
||||
'options' => array (
|
||||
'--format' => 'csv,doc,txt,xls or xml. These options are ignored if the display_id passed is a "views_data_export" display.',
|
||||
'--separator' => 'csv only: What character separates the fields (default:,)',
|
||||
'--trim-whitespace' => 'csv only: Trim whitespace from either side of fields (default:1)',
|
||||
'--header-row' => 'csv only: Make the first row a row of headers (default:1)',
|
||||
'--quote-values' => 'csv only: Surround each field in quotes (default:1)',
|
||||
),
|
||||
'examples' => array (
|
||||
'drush views-data-export myviewname views_data_export_1 output.csv' => 'Export myviewname:views_data_export_1 and write the output to output.csv in the current directory',
|
||||
),
|
||||
'drupal dependencies' => array (
|
||||
'views_data_export',
|
||||
),
|
||||
'core' => array('7'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_drush_help().
|
||||
*
|
||||
* This function is called whenever a drush user calls
|
||||
* 'drush help <name-of-your-command>'
|
||||
*
|
||||
* @param
|
||||
* A string with the help section (prepend with 'drush:')
|
||||
*
|
||||
* @return
|
||||
* A string with the help text for your command.
|
||||
*/
|
||||
function views_data_export_drush_help($section) {
|
||||
switch ($section) {
|
||||
case 'drush:views-data-export':
|
||||
return dt("This command may be used to fully execute a views_data_export display of a view, batched if need be, and write the output to a file.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of drush_hook_COMMAND_validate().
|
||||
*/
|
||||
function drush_views_data_export_validate() {
|
||||
// Because of a bug in the way that Drush 4 computes the name of functions to
|
||||
// call from a Drush command, we may end up getting called twice, so we just
|
||||
// don't do anything on subsequent invocations.
|
||||
static $already_run = FALSE;
|
||||
if ($already_run) {
|
||||
return;
|
||||
}
|
||||
$already_run = TRUE;
|
||||
|
||||
$args = drush_get_arguments();
|
||||
array_shift($args);
|
||||
|
||||
if (count($args) !== 3) {
|
||||
return drush_set_error('ARGUMENTS_REQUIRED', dt('All arguments are required.'));
|
||||
}
|
||||
|
||||
if (!$view = views_get_view($args[0])) {
|
||||
return drush_set_error('VIEW_DOES_NOT_EXIST', dt('The view !view does not exist.', array ('!view' => $args[0])));
|
||||
}
|
||||
|
||||
if (!$view->set_display($args[1])) {
|
||||
return drush_set_error('VIEW_DOES_NOT_EXIST', dt('The view !view does not have the !display display.', array ('!view' => $args[0], '!display' => $args[1])));
|
||||
}
|
||||
else {
|
||||
if ($view->current_display != $args[1]) {
|
||||
drush_log(dt('Using different display from specified display: @display', array('@display' => $view->current_display)), 'notice');
|
||||
}
|
||||
drush_set_option('views_data_export_display_id', $view->current_display);
|
||||
}
|
||||
|
||||
$format = drush_get_option('format');
|
||||
$valid_formats = array('csv', 'doc', 'txt', 'xls', 'xml');
|
||||
if (!empty($format) && !in_array($format, $valid_formats)) {
|
||||
return drush_set_error('VIEWS_DATA_EXPORT_INVALID_OPTION', dt('The "--format" option is invalid, please supply one of the following: !formats', array('!formats' => implode(', ', $valid_formats))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Drush command callback to export a views data to a file.
|
||||
*
|
||||
* @see drush_views_data_export_validate().
|
||||
* @see views_data_export_views_data_export_batch_alter().
|
||||
*/
|
||||
function drush_views_data_export($view_name, $display_id, $output_file) {
|
||||
// Because of a bug in the way that Drush 4 computes the name of functions to
|
||||
// call from a Drush command, we may end up getting called twice, so we just
|
||||
// don't do anything on subsequent invocations.
|
||||
static $already_run = FALSE;
|
||||
if ($already_run) {
|
||||
return;
|
||||
}
|
||||
$already_run = TRUE;
|
||||
|
||||
// Set the display to the one that we computed earlier.
|
||||
$display_id = drush_get_option('views_data_export_display_id', 'default');
|
||||
|
||||
$view = views_get_view($view_name);
|
||||
|
||||
// If the given display_id is not views_data_alter then
|
||||
// we programatically clone it to a views_data_alter display
|
||||
// and then execute that one instead
|
||||
if ($view->display[$display_id]->display_plugin != 'views_data_export') {
|
||||
//drush_log("Display '$display_id' is not views_data_export. Making one that is and executing that instead =).", 'success');
|
||||
|
||||
$format = drush_get_option('format');
|
||||
$settings = array();
|
||||
switch ($format) {
|
||||
case 'doc':
|
||||
case 'xls':
|
||||
case 'xml':
|
||||
case 'txt':
|
||||
$settings['display_options']['style_plugin'] = 'views_data_export_' . $format;
|
||||
break;
|
||||
case 'csv':
|
||||
default:
|
||||
$settings['display_options']['style_plugin'] = 'views_data_export_csv';
|
||||
if ($separator = drush_get_option('separator')) {
|
||||
$settings['display_options']['style_options']['separator'] = $separator;
|
||||
}
|
||||
if (!$trim = drush_get_option('trim-whitespace')) {
|
||||
$settings['display_options']['style_options']['trim'] = 0;
|
||||
}
|
||||
if (!$header = drush_get_option('header-row')) {
|
||||
$settings['display_options']['style_options']['header'] = 0;
|
||||
}
|
||||
if (!$quote = drush_get_option('quote-values')) {
|
||||
$settings['display_options']['style_options']['quote'] = 0;
|
||||
}
|
||||
// Seperator
|
||||
}
|
||||
|
||||
$display_id = _drush_views_data_export_clone_display($view, $display_id, $settings);
|
||||
}
|
||||
|
||||
$view->set_display($display_id);
|
||||
|
||||
// We execute the view normally, and take advantage
|
||||
// of an alter function to interject later and batch it ourselves
|
||||
|
||||
$options = array (
|
||||
'output_file' => realpath(drush_get_context('DRUSH_OLDCWD', getcwd())) . '/' . $output_file,
|
||||
);
|
||||
_drush_views_data_export_override_batch($view_name, $display_id, $options);
|
||||
$view->execute_display($display_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function that indicates that we want to
|
||||
* override the batch that the views_data_export view creates
|
||||
* on it's initial time through.
|
||||
*
|
||||
* Also provides a place to stash options that need to stay around
|
||||
* until the end of the batch
|
||||
*/
|
||||
function _drush_views_data_export_override_batch($view = NULL, $display = NULL, $options = TRUE) {
|
||||
static $_views;
|
||||
if (isset($view)) {
|
||||
$_views[$view][$display] = $options;
|
||||
}
|
||||
return $_views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_views_data_export_batch_alter()
|
||||
*/
|
||||
function views_data_export_views_data_export_batch_alter(&$batch, &$final_destination, &$querystring) {
|
||||
|
||||
// Copy the batch, because we're going to monkey with it, a lot!
|
||||
$new_batch = $batch;
|
||||
|
||||
$view_name = $new_batch['view_name'];
|
||||
$display_id = $new_batch['display_id'];
|
||||
|
||||
$ok_to_override = _drush_views_data_export_override_batch();
|
||||
|
||||
// Make sure we do nothing if we are called not following the execution of
|
||||
// our drush command. This could happen if the file with this function in it
|
||||
// is included during the normal execution of the view
|
||||
if (!$ok_to_override[$view_name][$display_id]) {
|
||||
return;
|
||||
}
|
||||
|
||||
$options = $ok_to_override[$view_name][$display_id];
|
||||
|
||||
// We actually never return from the drupal_alter, but
|
||||
// use drush's batch system to run the same batch
|
||||
|
||||
// Add a final callback
|
||||
$new_batch['operations'][] = array(
|
||||
'_drush_views_data_export_batch_finished', array($batch['eid'], $options['output_file']),
|
||||
);
|
||||
|
||||
batch_set($new_batch);
|
||||
$new_batch =& batch_get();
|
||||
// Drush handles the different processes, so instruct BatchAPI not to.
|
||||
$new_batch['progressive'] = FALSE;
|
||||
// Process the batch using drush.
|
||||
drush_backend_batch_process();
|
||||
|
||||
// Instruct the view display plugin that it shouldn't set a batch.
|
||||
$batch = array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get's called at the end of the drush batch process that generated our export
|
||||
*/
|
||||
function _drush_views_data_export_batch_finished($eid, $output_file, &$context) {
|
||||
// Fetch export info
|
||||
$export = views_data_export_get($eid);
|
||||
|
||||
// Perform cleanup
|
||||
$view = views_data_export_view_retrieve($eid);
|
||||
$view->set_display($export->view_display_id);
|
||||
$view->display_handler->batched_execution_state = $export;
|
||||
$view->display_handler->remove_index();
|
||||
|
||||
// Get path to temp file
|
||||
$temp_file = $view->display_handler->outputfile_path();
|
||||
|
||||
// Copy file over
|
||||
if (@drush_op('copy', $temp_file, $output_file)) {
|
||||
drush_log("Data export saved to " . $output_file, 'success');
|
||||
}
|
||||
else {
|
||||
drush_set_error('VIEWS_DATA_EXPORT_COPY_ERROR', dt("The file could not be copied to the selected destination"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function that takes a view and returns a clone of it
|
||||
* that has cloned a given display to one of type views_data_export
|
||||
*
|
||||
* @param &$view
|
||||
* Modified to contain the new display
|
||||
*
|
||||
* @return
|
||||
* The new display_id
|
||||
*/
|
||||
function _drush_views_data_export_clone_display(&$view, $display_id, $settings = array()) {
|
||||
|
||||
// Create the new display
|
||||
$new_display_id = _drush_views_data_export_generate_display_id($view, 'views_data_export');
|
||||
$view->display[$new_display_id] = clone $view->display[$display_id];
|
||||
|
||||
// Ensure we have settings we'll need for our display
|
||||
$default_settings = array (
|
||||
'id' => $new_display_id,
|
||||
'display_plugin' => 'views_data_export',
|
||||
'position' => 99,
|
||||
'display_options' => array (
|
||||
'style_plugin' => 'views_data_export_csv',
|
||||
'style_options' => array(
|
||||
'attach_text' => 'CSV',
|
||||
'provide_file' => 1,
|
||||
'filename' => 'view-%view.csv',
|
||||
'parent_sort' => 1,
|
||||
'separator' => ',',
|
||||
'quote' => 1,
|
||||
'trim' => 1,
|
||||
'header' => 1,
|
||||
),
|
||||
'use_batch' => 'batch',
|
||||
'path' => '',
|
||||
'displays' => array (
|
||||
'default' => 'default',
|
||||
),
|
||||
),
|
||||
);
|
||||
$settings = array_replace_recursive($default_settings, $settings);
|
||||
|
||||
$view->display[$new_display_id] = (object)array_replace_recursive((array)$view->display[$new_display_id], $settings);
|
||||
|
||||
return $new_display_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate a display id of a certain plugin type.
|
||||
* See http://drupal.org/files/issues/348975-clone-display.patch
|
||||
*
|
||||
* @param $type
|
||||
* Which plugin should be used for the new display id.
|
||||
*/
|
||||
function _drush_views_data_export_generate_display_id($view, $type) {
|
||||
// 'default' is singular and is unique, so just go with 'default'
|
||||
// for it. For all others, start counting.
|
||||
if ($type == 'default') {
|
||||
return 'default';
|
||||
}
|
||||
// Initial id.
|
||||
$id = $type . '_1';
|
||||
$count = 1;
|
||||
|
||||
// Loop through IDs based upon our style plugin name until
|
||||
// we find one that is unused.
|
||||
while (!empty($view->display[$id])) {
|
||||
$id = $type . '_' . ++$count;
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* If we're using PHP < 5.3.0 then we'll need
|
||||
* to define this function ourselves.
|
||||
* See: http://phpmyanmar.com/phpcodes/manual/function.array-replace-recursive.php
|
||||
*/
|
||||
if (!function_exists('array_replace_recursive')) {
|
||||
function array_replace_recursive($array, $array1) {
|
||||
// Get array arguments
|
||||
$arrays = func_get_args();
|
||||
|
||||
// Define the original array
|
||||
$original = array_shift($arrays);
|
||||
|
||||
// Loop through arrays
|
||||
foreach ($arrays as $array) {
|
||||
// Loop through array key/value pairs
|
||||
foreach ($array as $key => $value) {
|
||||
// Value is an array
|
||||
if (is_array($value)) {
|
||||
// Traverse the array; replace or add result to original array
|
||||
$original[$key] = array_replace_recursive($original[$key], $array[$key]);
|
||||
}
|
||||
|
||||
// Value is not an array
|
||||
else {
|
||||
// Replace or add current value to original array
|
||||
$original[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return the joined array
|
||||
return $original;
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
name = Views Data Export
|
||||
description = "Plugin to export views data into various file formats"
|
||||
|
||||
package = Views
|
||||
core = 7.x
|
||||
|
||||
files[] = views_data_export.module
|
||||
dependencies[] = views
|
||||
|
||||
; Plugins
|
||||
files[] = plugins/views_data_export_plugin_display_export.inc
|
||||
files[] = plugins/views_data_export_plugin_style_export.inc
|
||||
files[] = plugins/views_data_export_plugin_style_export_csv.inc
|
||||
files[] = plugins/views_data_export_plugin_style_export_doc.inc
|
||||
files[] = plugins/views_data_export_plugin_style_export_txt.inc
|
||||
files[] = plugins/views_data_export_plugin_style_export_xls.inc
|
||||
files[] = plugins/views_data_export_plugin_style_export_xml.inc
|
||||
|
||||
; Theme
|
||||
files[] = theme/views_data_export.theme.inc
|
||||
files[] = theme/views-data-export-csv-body.tpl.php
|
||||
files[] = theme/views-data-export-csv-footer.tpl.php
|
||||
files[] = theme/views-data-export-csv-header.tpl.php
|
||||
files[] = theme/views-data-export-doc-body.tpl.php
|
||||
files[] = theme/views-data-export-doc-footer.tpl.php
|
||||
files[] = theme/views-data-export-doc-header.tpl.php
|
||||
files[] = theme/views-data-export-txt-body.tpl.php
|
||||
files[] = theme/views-data-export-txt-footer.tpl.php
|
||||
files[] = theme/views-data-export-txt-header.tpl.php
|
||||
files[] = theme/views-data-export-xls-body.tpl.php
|
||||
files[] = theme/views-data-export-xls-footer.tpl.php
|
||||
files[] = theme/views-data-export-xls-header.tpl.php
|
||||
files[] = theme/views-data-export-xml-body.tpl.php
|
||||
files[] = theme/views-data-export-xml-footer.tpl.php
|
||||
files[] = theme/views-data-export-xml-header.tpl.php
|
||||
files[] = theme/views-data-export.tpl.php
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-05-10
|
||||
version = "7.x-3.0-beta6"
|
||||
core = "7.x"
|
||||
project = "views_data_export"
|
||||
datestamp = "1336632688"
|
||||
|
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema()
|
||||
*/
|
||||
function views_data_export_schema() {
|
||||
$schema = array();
|
||||
|
||||
$schema['views_data_export'] = array(
|
||||
'description' => t('Keep track of currently executing exports.'),
|
||||
'fields' => array(
|
||||
'eid' => array(
|
||||
'description' => 'Unique id for each on-going export.',
|
||||
'type' => 'serial',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
'view_name' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
'not null' => TRUE,
|
||||
'description' => 'The unique name of the view. This is the primary field views are loaded from, and is used so that views may be internal and not necessarily in the database. May only be alphanumeric characters plus underscores.',
|
||||
),
|
||||
'view_display_id' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => '32',
|
||||
'default' => '',
|
||||
'not null' => TRUE,
|
||||
'description' => 'The unique name of the view. This is the primary field views are loaded from, and is used so that views may be internal and not necessarily in the database. May only be alphanumeric characters plus underscores.',
|
||||
),
|
||||
'time_stamp' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The time this export started',
|
||||
),
|
||||
'fid' => array(
|
||||
'description' => 'Files ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE
|
||||
),
|
||||
'batch_state' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => '32',
|
||||
'default' => 'init',
|
||||
'not null' => TRUE,
|
||||
'description' => 'The current state of the batch.',
|
||||
),
|
||||
'sandbox' => array(
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'primary key' => array('eid'),
|
||||
);
|
||||
|
||||
$schema['views_data_export_object_cache'] = array(
|
||||
'description' => 'A modified version of the views_object_cache that ignores session id.',
|
||||
'fields' => array(
|
||||
'eid' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => '64',
|
||||
'description' => 'The export ID this view equates too.',
|
||||
),
|
||||
'updated' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
'description' => 'The time this cache was created or updated.',
|
||||
),
|
||||
'data' => array(
|
||||
'type' => 'text',
|
||||
'size' => 'big',
|
||||
'description' => 'Serialized data being stored.',
|
||||
'serialize' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'eid' => array('eid'),
|
||||
'updated' => array('updated'),
|
||||
),
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall()
|
||||
*/
|
||||
function views_data_export_uninstall() {
|
||||
// Clean up any tables we may have left around.
|
||||
module_load_include('module', 'views_data_export');
|
||||
views_data_export_garbage_collect(0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the data column in the object cache.
|
||||
*/
|
||||
function views_data_export_update_7100() {
|
||||
$new_field = array(
|
||||
'type' => 'text',
|
||||
'size' => 'big',
|
||||
'description' => 'Serialized data being stored.',
|
||||
'serialize' => TRUE,
|
||||
);
|
||||
|
||||
// Drop and re-add this field because there is a bug in
|
||||
// db_change_field that causes this to fail when trying to cast the data.
|
||||
db_drop_field('views_data_export_object_cache', 'data');
|
||||
db_add_field('views_data_export_object_cache', 'data', $new_field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function views_data_export_requirements($phase) {
|
||||
$requirements = array();
|
||||
|
||||
// Ensure translations don't break at install time
|
||||
$t = get_t();
|
||||
|
||||
switch ($phase) {
|
||||
case 'runtime':
|
||||
// Check the max allowed packet size.
|
||||
$max_allowed_packet = db_query('SHOW VARIABLES WHERE variable_name = :name', array(':name' => 'max_allowed_packet'))->fetchField(1);
|
||||
if (is_numeric($max_allowed_packet)) {
|
||||
if ($max_allowed_packet < (16 * 1024 * 1024)) {
|
||||
$requirements['views_data_export'] = array(
|
||||
'title' => $t('MySQL - max allowed packet'),
|
||||
'value' => format_size($max_allowed_packet),
|
||||
'description' => $t("Your MySQL 'max_allowed_packet' setting may be too low for Views data export to function correctly, Drupal's requirements recommend setting it to at least 16M. See: !link", array('!link' => l('http://drupal.org/requirements', 'http://drupal.org/requirements'))),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
@@ -0,0 +1,273 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provides the ability to export to specific
|
||||
*/
|
||||
|
||||
define('VIEWS_DATA_EXPORT_HEADER', 'header');
|
||||
define('VIEWS_DATA_EXPORT_BODY', 'body');
|
||||
define('VIEWS_DATA_EXPORT_FOOTER', 'footer');
|
||||
define('VIEWS_DATA_EXPORT_FINISHED', 'finished');
|
||||
|
||||
define('VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX', 'views_data_export_index_');
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*/
|
||||
function views_data_export_init() {
|
||||
// We have to include our theme preprocessors here until:
|
||||
// http://drupal.org/node/1096770 is fixed.
|
||||
module_load_include('inc', 'views_data_export', 'theme/views_data_export.theme');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_views_api().
|
||||
*/
|
||||
function views_data_export_views_api() {
|
||||
return array(
|
||||
'api' => 2,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_theme().
|
||||
*/
|
||||
function views_data_export_theme() {
|
||||
// Make sure that views picks up the preprocess functions.
|
||||
module_load_include('inc', 'views_data_export', 'theme/views_data_export.theme');
|
||||
$hooks = array();
|
||||
$hooks['views_data_export_feed_icon'] = array(
|
||||
'pattern' => 'views_data_export_feed_icon__',
|
||||
'variables' => array(
|
||||
'image_path' => NULL,
|
||||
'url' => NULL,
|
||||
'query' => '',
|
||||
'text' => '',
|
||||
),
|
||||
'file' => 'theme/views_data_export.theme.inc',
|
||||
);
|
||||
|
||||
$hooks['views_data_export_complete_page'] = array (
|
||||
'variables' => array(
|
||||
'file' => '',
|
||||
'errors' => array(),
|
||||
'return_url'=> '',
|
||||
),
|
||||
'file' => 'theme/views_data_export.theme.inc',
|
||||
);
|
||||
|
||||
$hooks['views_data_export_message'] = array (
|
||||
'variables' => array(
|
||||
'message' => '',
|
||||
'type' => 'info',
|
||||
),
|
||||
'file' => 'theme/views_data_export.theme.inc',
|
||||
);
|
||||
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_cron().
|
||||
*/
|
||||
function views_data_export_cron() {
|
||||
views_data_export_garbage_collect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any temporary index tables that have been left
|
||||
* behind. This is caused by batch processes which are
|
||||
* started but never finished.
|
||||
*
|
||||
* Removes all trace of exports from the database that
|
||||
* were created more than $expires seconds ago
|
||||
*
|
||||
* @param $expires
|
||||
* Seconds ago. Defaults to that given in the settings.
|
||||
* @param $chunk
|
||||
* The number of tables to test for and delete.
|
||||
* Defaults to that given in the settings. Pass -1
|
||||
* for this setting to remove any restriction and to
|
||||
* garbage collect all exports.
|
||||
*/
|
||||
function views_data_export_garbage_collect($expires = NULL, $chunk = NULL) {
|
||||
|
||||
if (!isset($expires)) {
|
||||
$expires = variable_get('views_data_export_gc_expires', 604800); // one week
|
||||
}
|
||||
if (!isset($chunk)) {
|
||||
$chunk = variable_get('views_data_export_gc_chunk', 30);
|
||||
}
|
||||
|
||||
if ($chunk == -1) {
|
||||
$result = db_query("SELECT eid FROM {views_data_export} WHERE time_stamp <= :timestamp ORDER BY time_stamp ASC", array(':timestamp' => REQUEST_TIME - $expires));
|
||||
}
|
||||
else {
|
||||
$result = db_query_range("SELECT eid FROM {views_data_export} WHERE time_stamp <= :timestamp ORDER BY time_stamp ASC", 0, $chunk, array(':timestamp' => REQUEST_TIME - $expires));
|
||||
}
|
||||
|
||||
$eids_to_clear = array();
|
||||
foreach ($result as $row) {
|
||||
$eids_to_clear[] = $row->eid;
|
||||
}
|
||||
|
||||
// We do two things to exports we want to garbage collect
|
||||
// 1. Delete the index table for it, if it is still around
|
||||
// 2. Delete the row from the exports table
|
||||
// 3. Delete the view from the object_cache
|
||||
if (count($eids_to_clear)) {
|
||||
foreach ($eids_to_clear as $eid) {
|
||||
// 1. Delete index table, if it is still around for some reason
|
||||
$table = VIEWS_DATA_EXPORT_INDEX_TABLE_PREFIX . $eid;
|
||||
if (db_table_exists($table)) {
|
||||
db_drop_table($table);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Delete the entries in the exports table.
|
||||
db_delete('views_data_export')
|
||||
->condition('eid', $eids_to_clear, 'IN')
|
||||
->execute();
|
||||
|
||||
// 3. Clear the cached views
|
||||
views_data_export_view_clear($eids_to_clear);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Batch API callback.
|
||||
* Handles all batching operations by executing the appropriate view.
|
||||
*/
|
||||
function _views_data_export_batch_process($export_id, $display_id, &$context) {
|
||||
// Don't show the admin menu on batch page, some people don't like it.
|
||||
if (module_exists('admin_menu')) {
|
||||
module_invoke('admin_menu', 'suppress');
|
||||
}
|
||||
|
||||
// Fetch the view in question from our cache
|
||||
$view = views_data_export_view_retrieve($export_id);
|
||||
$view->set_display($display_id);
|
||||
|
||||
// Inform the data_export display which export it corresponds to and execute
|
||||
if (!isset($view->display_handler->batched_execution_state)) {
|
||||
$view->display_handler->batched_execution_state = new stdClass();
|
||||
}
|
||||
$view->display_handler->batched_execution_state->eid = $export_id;
|
||||
$view->display_handler->views_data_export_cached_view_loaded = TRUE;
|
||||
$view->execute_display($display_id);
|
||||
|
||||
// Update batch api progress information
|
||||
$sandbox = $view->display_handler->batched_execution_state->sandbox;
|
||||
$context['finished'] = $sandbox['finished'];
|
||||
$context['message'] = $sandbox['message'];
|
||||
|
||||
views_data_export_view_store($export_id, $view);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**********/
|
||||
/** CRUD **/
|
||||
/**********/
|
||||
|
||||
/**
|
||||
* Save a new export into the database.
|
||||
*/
|
||||
function views_data_export_new($view_name, $view_display_id, $file) {
|
||||
// Insert new row into exports table
|
||||
$record = (object) array(
|
||||
'view_name' => $view_name,
|
||||
'view_display_id' => $view_display_id,
|
||||
'time_stamp' => REQUEST_TIME,
|
||||
'fid' => $file,
|
||||
'batch_state' => VIEWS_DATA_EXPORT_HEADER,
|
||||
'sandbox' => array(),
|
||||
);
|
||||
drupal_write_record('views_data_export', $record);
|
||||
return $record;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Update an export row in the database
|
||||
*/
|
||||
function views_data_export_update($state) {
|
||||
// Note, drupal_write_record handles serializing
|
||||
// the sandbox field as per our schema definition
|
||||
drupal_write_record('views_data_export', $state, 'eid');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get the information about a previous export.
|
||||
*/
|
||||
function views_data_export_get($export_id) {
|
||||
$object = db_query("SELECT * FROM {views_data_export} WHERE eid = :eid", array(':eid' => (int)$export_id))->fetch();
|
||||
if ($object) {
|
||||
$object->sandbox = unserialize($object->sandbox);
|
||||
}
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the information about an export.
|
||||
*/
|
||||
function views_data_export_clear($export_id) {
|
||||
db_delete('views_data_export')
|
||||
->condition('eid', $export_id)
|
||||
->execute();
|
||||
views_data_export_view_clear($export_id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Store a view in the object cache.
|
||||
*/
|
||||
function views_data_export_view_store($export_id, $view) {
|
||||
// Store a clean copy of the view.
|
||||
$_view = $view->clone_view();
|
||||
|
||||
views_data_export_view_clear($export_id);
|
||||
$record = array(
|
||||
'eid' => $export_id,
|
||||
'data' => $_view,
|
||||
'updated' => REQUEST_TIME,
|
||||
);
|
||||
drupal_write_record('views_data_export_object_cache', $record);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a view from the object cache.
|
||||
*/
|
||||
function views_data_export_view_retrieve($export_id) {
|
||||
views_include('view');
|
||||
$data = db_query("SELECT * FROM {views_data_export_object_cache} WHERE eid = :eid", array(':eid' => $export_id))->fetch();
|
||||
if ($data) {
|
||||
$view = unserialize($data->data);
|
||||
}
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a view from the object cache.
|
||||
*
|
||||
* @param $export_id
|
||||
* An export ID or an array of export IDs to clear from the object cache.
|
||||
*/
|
||||
function views_data_export_view_clear($export_id) {
|
||||
if (is_array($export_id)) {
|
||||
db_delete('views_data_export_object_cache')
|
||||
->condition('eid', $export_id, 'IN')
|
||||
->execute();
|
||||
}
|
||||
else {
|
||||
db_delete('views_data_export_object_cache')
|
||||
->condition('eid', $export_id)
|
||||
->execute();
|
||||
}
|
||||
}
|
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Views include file with views hooks.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_views_plugins().
|
||||
*/
|
||||
function views_data_export_views_plugins() {
|
||||
$path = drupal_get_path('module', 'views_data_export');
|
||||
|
||||
$style_defaults = array(
|
||||
'path' => $path . '/plugins',
|
||||
'parent' => 'views_data_export',
|
||||
'theme' => 'views_data_export',
|
||||
'theme path' => $path . '/theme',
|
||||
'theme file' => 'views_data_export.theme.inc',
|
||||
'uses row plugin' => FALSE,
|
||||
'uses fields' => TRUE,
|
||||
'uses options' => TRUE,
|
||||
'type' => 'data_export',
|
||||
);
|
||||
|
||||
return array(
|
||||
'display' => array (
|
||||
'views_data_export' => array(
|
||||
'title' => t('Data export'),
|
||||
'help' => t('Export the view results to a file. Can handle very large result sets.'),
|
||||
'path' => $path . '/plugins',
|
||||
'handler' => 'views_data_export_plugin_display_export',
|
||||
'parent' => 'feed',
|
||||
'uses hook menu' => TRUE,
|
||||
'use ajax' => FALSE,
|
||||
'use pager' => FALSE,
|
||||
'accept attachments' => FALSE,
|
||||
'admin' => t('Data export'),
|
||||
'help topic' => 'display-data-export',
|
||||
),
|
||||
),
|
||||
'style' => array(
|
||||
'views_data_export' => array(
|
||||
// this isn't really a display but is necessary so the file can
|
||||
// be included.
|
||||
'no ui' => TRUE,
|
||||
'handler' => 'views_data_export_plugin_style_export',
|
||||
'path' => $path . '/plugins',
|
||||
'theme path' => $path . '/theme',
|
||||
'theme file' => 'views_data_export.theme.inc',
|
||||
'type' => 'normal',
|
||||
),
|
||||
'views_data_export_csv' => array(
|
||||
'title' => t('CSV file'),
|
||||
'help' => t('Display the view as a comma separated list.'),
|
||||
'handler' => 'views_data_export_plugin_style_export_csv',
|
||||
// Views Data Export element that will be used to set additional headers when serving the feed.
|
||||
'export headers' => array('Content-type' => 'text/csv; charset=utf-8'),
|
||||
// Views Data Export element mostly used for creating some additional classes and template names.
|
||||
'export feed type' => 'csv',
|
||||
'export feed text' => 'CSV',
|
||||
'export feed file' => '%view.csv',
|
||||
'export feed icon' => drupal_get_path('module', 'views_data_export') . '/images/csv.png',
|
||||
'additional themes' => array(
|
||||
'views_data_export_csv_header' => 'style',
|
||||
'views_data_export_csv_body' => 'style',
|
||||
'views_data_export_csv_footer' => 'style',
|
||||
),
|
||||
'additional themes base' => 'views_data_export_csv',
|
||||
) + $style_defaults,
|
||||
'views_data_export_doc' => array(
|
||||
'title' => t('DOC file'),
|
||||
'help' => t('Display the view as a doc file.'),
|
||||
'handler' => 'views_data_export_plugin_style_export',
|
||||
'export headers' => array('Content-Type' => 'application/msword'),
|
||||
'export feed type' => 'doc',
|
||||
'export feed text' => 'Word Document',
|
||||
'export feed file' => '%view.doc',
|
||||
'export feed icon' => drupal_get_path('module', 'views_data_export') . '/images/doc.png',
|
||||
'additional themes' => array(
|
||||
'views_data_export_doc_header' => 'style',
|
||||
'views_data_export_doc_body' => 'style',
|
||||
'views_data_export_doc_footer' => 'style',
|
||||
),
|
||||
'additional themes base' => 'views_data_export_doc',
|
||||
) + $style_defaults,
|
||||
'views_data_export_txt' => array(
|
||||
'title' => t('TXT file'),
|
||||
'help' => t('Display the view as a txt file.'),
|
||||
'handler' => 'views_data_export_plugin_style_export',
|
||||
'export headers' => array('Content-Type' => 'text/plain'),
|
||||
'export feed type' => 'txt',
|
||||
'export feed text' => 'Plain Text Document',
|
||||
'export feed file' => '%view.txt',
|
||||
'export feed icon' => drupal_get_path('module', 'views_data_export') . '/images/txt.png',
|
||||
'additional themes' => array(
|
||||
'views_data_export_txt_header' => 'style',
|
||||
'views_data_export_txt_body' => 'style',
|
||||
'views_data_export_txt_footer' => 'style',
|
||||
),
|
||||
'additional themes base' => 'views_data_export_txt',
|
||||
) + $style_defaults,
|
||||
'views_data_export_xls' => array(
|
||||
'title' => t('XLS file'),
|
||||
'help' => t('Display the view as a xls file.'),
|
||||
'handler' => 'views_data_export_plugin_style_export',
|
||||
'export headers' => array('Content-Type' => 'application/vnd.ms-excel'),
|
||||
'export feed type' => 'xls',
|
||||
'export feed text' => 'XLS',
|
||||
'export feed file' => '%view.xls',
|
||||
'export feed icon' => drupal_get_path('module', 'views_data_export') . '/images/xls.png',
|
||||
'additional themes' => array(
|
||||
'views_data_export_xls_header' => 'style',
|
||||
'views_data_export_xls_body' => 'style',
|
||||
'views_data_export_xls_footer' => 'style',
|
||||
),
|
||||
'additional themes base' => 'views_data_export_xls',
|
||||
) + $style_defaults,
|
||||
'views_data_export_xml' => array(
|
||||
'title' => t('XML file'),
|
||||
'help' => t('Display the view as a txt file.'),
|
||||
'handler' => 'views_data_export_plugin_style_export_xml',
|
||||
'export headers' => array('Content-Type' => 'text/xml'),
|
||||
'export feed type' => 'xml',
|
||||
'export feed text' => 'XML',
|
||||
'export feed file' => '%view.xml',
|
||||
'export feed icon' => drupal_get_path('module', 'views_data_export') . '/images/xml.png',
|
||||
'additional themes' => array(
|
||||
'views_data_export_xml_header' => 'style',
|
||||
'views_data_export_xml_body' => 'style',
|
||||
'views_data_export_xml_footer' => 'style',
|
||||
),
|
||||
'additional themes base' => 'views_data_export_xml',
|
||||
) + $style_defaults,
|
||||
),
|
||||
);
|
||||
}
|
339
sites/all/modules/contrib/views/views_php/LICENSE.txt
Normal file
339
sites/all/modules/contrib/views/views_php/LICENSE.txt
Normal 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.
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A handler to provide an area that is constructed by the administrator using PHP.
|
||||
*
|
||||
* @ingroup views_area_handlers
|
||||
*/
|
||||
class views_php_handler_area extends views_handler_area {
|
||||
|
||||
/**
|
||||
* Implements views_object#option_definition().
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['php_output'] = array('default' => "<h4>Example PHP code</h4>\n<p>Time: <?php print date('H:i', time());?></p>\n");
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler#option_definition().
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_output', t('Output code'), t('Code to construct the output of this area.'), TRUE),
|
||||
array('$view', '$handler', '$results')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements views_handler_area#render().
|
||||
*/
|
||||
function render($empty = FALSE) {
|
||||
// Ecexute output PHP code.
|
||||
if ((!$empty || !empty($this->options['empty'])) && !empty($this->options['php_output'])) {
|
||||
$function = create_function('$view, $handler, $results', ' ?>' . $this->options['php_output'] . '<?php ');
|
||||
ob_start();
|
||||
$function($this->view, $this, $this->view->result);
|
||||
return ob_get_clean();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
@@ -0,0 +1,227 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A handler to provide a field that is constructed by the administrator using PHP.
|
||||
*
|
||||
* @ingroup views_field_handlers
|
||||
*/
|
||||
class views_php_handler_field extends views_handler_field {
|
||||
const CLICK_SORT_DISABLED = 0;
|
||||
const CLICK_SORT_NUMERIC = 1;
|
||||
const CLICK_SORT_ALPHA = 2;
|
||||
const CLICK_SORT_ALPHA_CASE = 3;
|
||||
const CLICK_SORT_NAT = 4;
|
||||
const CLICK_SORT_NAT_CASE = 5;
|
||||
const CLICK_SORT_PHP = 6;
|
||||
|
||||
protected $php_static_variable = NULL;
|
||||
|
||||
/**
|
||||
* Implements views_object#option_definition().
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['use_php_setup'] = array('default' => FALSE);
|
||||
$options['php_setup'] = array('default' => '');
|
||||
$options['php_value'] = array('default' => '');
|
||||
$options['php_output'] = array('default' => '');
|
||||
$options['use_php_click_sortable'] = array('default' => self::CLICK_SORT_DISABLED);
|
||||
$options['php_click_sortable'] = array('default' => FALSE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler#options_form().
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form += views_php_form_element($this,
|
||||
array('use_php_setup', t('Use setup code'), t('If checked, you can provide PHP code to be run once right before execution of the view. This may be useful to define functions to be re-used in the value and/or output code.')),
|
||||
array('php_setup', t('Setup code'), t('Code to run right before execution of the view.'), FALSE),
|
||||
array('$view', '$handler', '$static')
|
||||
);
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_value', t('Value code'), t('Code to construct the value of this field.'), FALSE),
|
||||
array('$view', '$handler', '$static', '$row', '$data')
|
||||
);
|
||||
$form += views_php_form_element($this,
|
||||
array('use_php_click_sortable', t('Enable click sort'), t('If checked, you can use PHP code to enable click sort on the field.')),
|
||||
array('php_click_sortable', t('Click sort code'), t('The comparison code must return an integer less than, equal to, or greater than zero if the first row should respectively appear before, stay where it was compared to, or appear after the second row.'), FALSE),
|
||||
array(
|
||||
'$view', '$handler', '$static',
|
||||
'$row1' => t('Data of row.'),
|
||||
'$row2' => t('Data of row to compare against.'),
|
||||
)
|
||||
);
|
||||
$form['use_php_click_sortable']['#type'] = 'select';
|
||||
$form['use_php_click_sortable']['#options'] = array(
|
||||
self::CLICK_SORT_DISABLED => t('No'),
|
||||
self::CLICK_SORT_NUMERIC => t('Sort numerically'),
|
||||
self::CLICK_SORT_ALPHA => t('Sort alphabetically'),
|
||||
self::CLICK_SORT_ALPHA_CASE => t('Sort alphabetically (case insensitive)'),
|
||||
self::CLICK_SORT_NAT => t('Sort using a "natural order" algorithm'),
|
||||
self::CLICK_SORT_NAT_CASE => t('Sort using a "natural order" algorithm (case insensitive)'),
|
||||
self::CLICK_SORT_PHP => t('Sort using custom PHP code'),
|
||||
);
|
||||
$form['use_php_click_sortable']['#default_value'] = $this->options['use_php_click_sortable'];
|
||||
$form['php_click_sortable']['#states'] = array(
|
||||
'visible' => array(
|
||||
':input[name="options[use_php_click_sortable]"]' => array('value' => (string)self::CLICK_SORT_PHP),
|
||||
),
|
||||
);
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_output', t('Output code'), t('Code to construct the output of this field.'), TRUE),
|
||||
array('$view', '$handler', '$static', '$row', '$data', '$value' => t('Value of this field.'))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_field#query().
|
||||
*
|
||||
* @see views_php_views_pre_execute()
|
||||
*/
|
||||
function query() {
|
||||
// Provide an field alias but don't actually alter the query.
|
||||
$this->field_alias = 'views_php_' . $this->position;
|
||||
// Inform views_php_views_pre_execute() to seize control over the query.
|
||||
$this->view->views_php = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_field#click_sortable().
|
||||
*/
|
||||
function click_sortable() {
|
||||
return $this->options['use_php_click_sortable'] != self::CLICK_SORT_DISABLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_field#click_sort().
|
||||
*
|
||||
* @see self::php_post_execute()
|
||||
*/
|
||||
function click_sort($order) {
|
||||
$this->php_click_sort_order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see views_php_views_pre_execute()
|
||||
* @see self::php_post_execute()
|
||||
*/
|
||||
function php_pre_execute() {
|
||||
// Ecexute static PHP code.
|
||||
if (!empty($this->options['php_setup'])) {
|
||||
$function = create_function('$view, $handler, &$static', $this->options['php_setup'] . ';');
|
||||
ob_start();
|
||||
$function($this->view, $this, $this->php_static_variable);
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see views_php_views_post_execute()
|
||||
*/
|
||||
function php_post_execute() {
|
||||
// Ecexute value PHP code.
|
||||
if (!empty($this->options['php_value'])) {
|
||||
$function = create_function('$view, $handler, &$static, $row, $data', $this->options['php_value'] . ';');
|
||||
ob_start();
|
||||
foreach ($this->view->result as $i => &$row) {
|
||||
$normalized_row = new stdClass;
|
||||
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
||||
$normalized_row->$field = isset($row->{$handler->field_alias}) ? $row->{$handler->field_alias} : NULL;
|
||||
}
|
||||
$row->{$this->field_alias} = $function($this->view, $this, $this->php_static_variable, $normalized_row, $row);
|
||||
}
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
// If we're sorting, do the actual sorting then fix the results as per the pager info.
|
||||
if (!empty($this->options['use_php_click_sortable']) && !empty($this->php_click_sort_order)) {
|
||||
if ($this->options['use_php_click_sortable'] == self::CLICK_SORT_PHP) {
|
||||
if (!empty($this->options['php_click_sortable'])) {
|
||||
$this->php_click_sort_function = create_function('$view, $handler, &$static, $row1, $row2', $this->options['php_click_sortable'] . ';');
|
||||
}
|
||||
}
|
||||
else {
|
||||
$predefined = array(
|
||||
self::CLICK_SORT_NUMERIC => array($this, 'php_click_sort_numeric'),
|
||||
self::CLICK_SORT_ALPHA => 'strcasecmp',
|
||||
self::CLICK_SORT_ALPHA_CASE => 'strcmp',
|
||||
self::CLICK_SORT_NAT => 'strnatcasecmp',
|
||||
self::CLICK_SORT_NAT_CASE => 'strnatcmp',
|
||||
);
|
||||
$this->php_click_sort_function = $predefined[$this->options['use_php_click_sortable']];
|
||||
}
|
||||
|
||||
if (isset($this->php_click_sort_function)) {
|
||||
usort($this->view->result, array($this, 'php_click_sort'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function; usort() callback for click sort support.
|
||||
*/
|
||||
function php_click_sort($row1, $row2) {
|
||||
$factor = strtoupper($this->php_click_sort_order) == 'ASC' ? 1 : -1;
|
||||
$function = $this->php_click_sort_function;
|
||||
if ($this->options['use_php_click_sortable'] == self::CLICK_SORT_PHP) {
|
||||
foreach (array('row1' => 'normalized_row1', 'row2' => 'normalized_row2') as $name => $normalized_name) {
|
||||
$$normalized_name = new stdClass;
|
||||
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
||||
$$normalized_name->$field = isset($$name->{$handler->field_alias}) ? $$name->{$handler->field_alias} : NULL;
|
||||
}
|
||||
}
|
||||
ob_start();
|
||||
$result = (int)$function($this->view, $this, $this->php_static_variable, $normalized_row1, $normalized_row2);
|
||||
ob_end_clean();
|
||||
}
|
||||
else {
|
||||
$result = $function($row1->{$this->field_alias}, $row2->{$this->field_alias});
|
||||
}
|
||||
return $factor * $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function; usort callback for numeric sort.
|
||||
*/
|
||||
function php_click_sort_numeric($a, $b) {
|
||||
return $a - $b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_field#pre_render().
|
||||
*/
|
||||
function pre_render(&$values) {
|
||||
if (!empty($this->options['php_output'])) {
|
||||
$this->php_output_lamda_function = create_function('$view, $handler, &$static, $row, $data, $value', ' ?>' . $this->options['php_output'] . '<?php ');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_field#render().
|
||||
*/
|
||||
function render($values) {
|
||||
// Ecexute output PHP code.
|
||||
if (!empty($this->options['php_output']) && isset($this->php_output_lamda_function)) {
|
||||
$normalized_row = new stdClass;
|
||||
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
||||
$normalized_row->$field = isset($values->{$handler->field_alias}) ? $values->{$handler->field_alias} : NULL;
|
||||
}
|
||||
|
||||
$function = $this->php_output_lamda_function;
|
||||
ob_start();
|
||||
$function($this->view, $this, $this->php_static_variable, $normalized_row, $values, isset($values->{$this->field_alias}) ? $values->{$this->field_alias} : NULL);
|
||||
$value = ob_get_clean();
|
||||
}
|
||||
else {
|
||||
$value = check_plain($values->{$this->field_alias});
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A handler to filter a view using PHP defined by the administrator.
|
||||
*
|
||||
* @ingroup views_filter_handlers
|
||||
*/
|
||||
class views_php_handler_filter extends views_handler_filter {
|
||||
|
||||
protected $php_static_variable = NULL;
|
||||
|
||||
/**
|
||||
* Implements views_handler#can_expose().
|
||||
*/
|
||||
function can_expose() { return FALSE; }
|
||||
|
||||
/**
|
||||
* Implements views_object#admin_summary().
|
||||
*/
|
||||
function admin_summary() {
|
||||
return t('PHP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_object#option_definition().
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['use_php_setup'] = array('default' => FALSE);
|
||||
$options['php_setup'] = array('default' => '');
|
||||
$options['php_filter'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler#option_definition().
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form += views_php_form_element($this,
|
||||
array('use_php_setup', t('Use setup code'), t('If checked, you can provide PHP code to be run once right before execution of the view. This may be useful to define functions to be re-used in the value and/or output code.')),
|
||||
array('php_setup', t('Setup code'), t('Code to run right before execution of the view.'), FALSE),
|
||||
array('$view', '$handler', '$static')
|
||||
);
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_filter', t('Filter code'), t('If the code returns TRUE the current row is removed from the results.'), FALSE),
|
||||
array('$view', '$handler', '$static', '$row', '$data')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_filter#query().
|
||||
*/
|
||||
function query() {
|
||||
// Inform views_php_views_pre_execute() to seize control over the query.
|
||||
$this->view->views_php = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see views_php_views_pre_execute()
|
||||
*/
|
||||
function php_pre_execute() {
|
||||
// Ecexute static PHP code.
|
||||
if (!empty($this->options['php_setup'])) {
|
||||
$function = create_function('$view, $handler, &$static', $this->options['php_setup'] . ';');
|
||||
ob_start();
|
||||
$function($this->view, $this, $this->php_static_variable);
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see views_php_views_post_execute()
|
||||
*/
|
||||
function php_post_execute() {
|
||||
// Evaluate the PHP code.
|
||||
if (!empty($this->options['php_filter'])) {
|
||||
$function = create_function('$view, $handler, &$static, $row, $data', $this->options['php_filter'] . ';');
|
||||
ob_start();
|
||||
foreach ($this->view->result as $i => $row) {
|
||||
$normalized_row = new stdClass;
|
||||
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
||||
$normalized_row->$field = isset($row->{$handler->field_alias}) ? $row->{$handler->field_alias} : NULL;
|
||||
}
|
||||
if ($function($this->view, $this, $this->php_static_variable, $normalized_row, $row)) {
|
||||
unset($this->view->result[$i]);
|
||||
}
|
||||
}
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A handler to sort a view using PHP defined by the administrator.
|
||||
*
|
||||
* @ingroup views_sort_handlers
|
||||
*/
|
||||
class views_php_handler_sort extends views_handler_sort {
|
||||
|
||||
protected $php_static_variable = NULL;
|
||||
|
||||
/**
|
||||
* Implements views_object#option_definition().
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['use_php_setup'] = array('default' => FALSE);
|
||||
$options['php_setup'] = array('default' => '');
|
||||
$options['php_sort'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler#option_definition().
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form += views_php_form_element($this,
|
||||
array('use_php_setup', t('Use setup code'), t('If checked, you can provide PHP code to be run once right before execution of the view. This may be useful to define functions to be re-used in the value and/or output code.')),
|
||||
array('php_setup', t('Setup code'), t('Code to run right before execution of the view.'), FALSE),
|
||||
array('$view', '$handler', '$static')
|
||||
);
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_sort', t('Sort code'), t('The comparison code must return an integer less than, equal to, or greater than zero if the first row should respectively appear before, stay where it was compared to, or appear after the second row.'), FALSE),
|
||||
array(
|
||||
'$view', '$handler', '$static',
|
||||
'$row1' => t('Data of row.'),
|
||||
'$row2' => t('Data of row to compare against.'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_handler_sort#query().
|
||||
*/
|
||||
function query() {
|
||||
// Inform views_php_views_pre_execute() to seize control over the query.
|
||||
$this->view->views_php = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see views_php_views_pre_execute()
|
||||
*/
|
||||
function php_pre_execute() {
|
||||
// Ecexute static PHP code.
|
||||
if (!empty($this->options['php_setup'])) {
|
||||
$function = create_function('$view, $handler, &$static', $this->options['php_setup'] . ';');
|
||||
ob_start();
|
||||
$function($this->view, $this, $this->php_static_variable);
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @see views_php_views_post_execute()
|
||||
*/
|
||||
function php_post_execute() {
|
||||
if (!empty($this->options['php_sort']) && $this->view->style_plugin->build_sort()) {
|
||||
$this->php_sort_function = create_function('$view, $handler, &$static, $row1, $row2', $this->options['php_sort'] . ';');
|
||||
ob_start();
|
||||
usort($this->view->result, array($this, 'php_sort'));
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function; usort() callback for sort support.
|
||||
*/
|
||||
function php_sort($row1, $row2) {
|
||||
$factor = strtoupper($this->options['order']) == 'ASC' ? 1 : -1;
|
||||
$function = $this->php_sort_function;
|
||||
foreach (array('row1' => 'normalized_row1', 'row2' => 'normalized_row2') as $name => $normalized_name) {
|
||||
$$normalized_name = new stdClass;
|
||||
foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) {
|
||||
$$normalized_name->$field = isset($$name->{$handler->field_alias}) ? $$name->{$handler->field_alias} : NULL;
|
||||
}
|
||||
}
|
||||
$result = (int)$function($this->view, $this, $this->php_static_variable, $normalized_row1, $normalized_row2);
|
||||
return $factor * $result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Access plugin that provides access control based on custom PHP code.
|
||||
*
|
||||
* @ingroup views_access_plugins
|
||||
*/
|
||||
class views_php_plugin_access extends views_plugin_access {
|
||||
|
||||
/**
|
||||
* Implements views_plugin_access#summary_title().
|
||||
*/
|
||||
function summary_title() {
|
||||
return t('PHP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_object#option_definition().
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['php_access'] = array('default' => '');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_plugin#options_form().
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_access', t('Access code'), t('If the code returns TRUE the requesting user is granted access to the view.'), FALSE),
|
||||
array(
|
||||
'$view_name' => t('The name of the view to check.'),
|
||||
'$display_id' => t('The ID of the display to check.'),
|
||||
'$account' => t('The account to check.'),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_plugin#options_submit().
|
||||
*/
|
||||
function options_submit(&$form, &$form_state) {
|
||||
$form_state['values']['access_options']['php_access'] = $form_state['values']['options']['php_access'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_plugin_access#access().
|
||||
*/
|
||||
function access($account) {
|
||||
if (!empty($this->options['php_access'])) {
|
||||
return views_php_check_access($this->options['php_access'], $this->view->name, $this->view->current_display, $account);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_plugin_access#get_access_callback().
|
||||
*/
|
||||
function get_access_callback() {
|
||||
if (!empty($this->options['php_access'])) {
|
||||
return array('views_php_check_access', array($this->options['php_access'], $this->view->name, $this->view->current_display));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
}
|
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Caching plugin that provides cache control based on custom PHP code.
|
||||
*
|
||||
* @ingroup views_cache_plugins
|
||||
*/
|
||||
class views_php_plugin_cache extends views_plugin_cache {
|
||||
|
||||
/**
|
||||
* Implements views_plugin_cache#summary_title().
|
||||
*/
|
||||
function summary_title() {
|
||||
return t('PHP');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_object#option_definition().
|
||||
*/
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['php_cache_results'] = array('default' => '');
|
||||
$options['php_cache_output'] = array('default' => '');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_plugin#options_form().
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_cache_results', t('Result cache code'), t('The code must return TRUE if the cache is still fresh, FALSE otherwise.'), FALSE),
|
||||
array('$view', '$plugin', '$cache')
|
||||
);
|
||||
$form += views_php_form_element($this,
|
||||
FALSE,
|
||||
array('php_cache_output', t('Output cache code'), t('The code must return TRUE if the cache is still fresh, FALSE otherwise.'), FALSE),
|
||||
array('$view', '$plugin', '$cache')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements views_plugin_cache#cache_get()
|
||||
*/
|
||||
function cache_get($type) {
|
||||
//$cutoff = $this->cache_expire($type);
|
||||
switch ($type) {
|
||||
case 'query':
|
||||
// Not supported currently, but this is certainly where we'd put it.
|
||||
return FALSE;
|
||||
case 'results':
|
||||
$cache = cache_get($this->get_results_key(), $this->table);
|
||||
$fresh = !empty($cache);
|
||||
if ($fresh && !empty($this->options['php_cache_results'])) {
|
||||
$function = create_function('$view, $plugin, $cache', $this->options['php_cache_results'] . ';');
|
||||
ob_start();
|
||||
$fresh = $function($this->view, $this, $cache);
|
||||
ob_end_clean();
|
||||
}
|
||||
// Values to set: $view->result, $view->total_rows, $view->execute_time,
|
||||
// $view->current_page.
|
||||
if ($fresh) {
|
||||
//if (!$cutoff || $cache->created > $cutoff) {
|
||||
$this->view->result = $cache->data['result'];
|
||||
$this->view->total_rows = $cache->data['total_rows'];
|
||||
$this->view->set_current_page = $cache->data['current_page'];
|
||||
$this->view->execute_time = 0;
|
||||
return TRUE;
|
||||
//}
|
||||
}
|
||||
return FALSE;
|
||||
case 'output':
|
||||
$cache = cache_get($this->get_output_key(), $this->table);
|
||||
$fresh = !empty($cache);
|
||||
if ($fresh && !empty($this->options['php_cache_output'])) {
|
||||
$function = create_function('$view, $plugin, $cache', $this->options['php_cache_output'] . ';');
|
||||
ob_start();
|
||||
$fresh = $function($this->view, $this, $cache);
|
||||
ob_end_clean();
|
||||
}
|
||||
if ($fresh) {
|
||||
//if (!$cutoff || $cache->created > $cutoff) {
|
||||
$this->storage = $cache->data;
|
||||
$this->view->display_handler->output = $cache->data['output'];
|
||||
$this->restore_headers();
|
||||
return TRUE;
|
||||
//}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A (fake) pager plugin that wraps around the actual pager.
|
||||
*
|
||||
* @ingroup views_pager_plugins
|
||||
*/
|
||||
class views_php_plugin_pager extends views_php_plugin_wrapper {
|
||||
|
||||
/**
|
||||
* Perform any needed actions just prior to the query executing.
|
||||
*/
|
||||
public function pre_execute($query) {
|
||||
$this->wrapped->pre_execute($query);
|
||||
|
||||
foreach (array(/*'argument',*/ 'field', 'filter', 'sort', /*'relationship'*/) as $type) {
|
||||
foreach ($this->wrapped->view->$type as $id => $handler) {
|
||||
if (is_callable(array($handler, 'php_pre_execute'))) {
|
||||
$handler->php_pre_execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->wrapped->view->query->set_limit(0);
|
||||
$this->wrapped->view->query->set_offset(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform any needed actions just after the query executing.
|
||||
*/
|
||||
public function post_execute(&$result) {
|
||||
foreach (array(/*'argument',*/ 'field', 'filter', 'sort', /*'relationship'*/) as $type) {
|
||||
foreach ($this->wrapped->view->$type as $id => $handler) {
|
||||
if (is_callable(array($handler, 'php_post_execute'))) {
|
||||
$handler->php_post_execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->wrapped->total_items = count($this->wrapped->view->result);
|
||||
$this->wrapped->update_page_info();
|
||||
|
||||
$item_per_page = $this->wrapped->get_items_per_page();
|
||||
if ($item_per_page > 0) {
|
||||
$offset = $this->wrapped->get_current_page() * $item_per_page + $this->wrapped->get_offset();
|
||||
$this->wrapped->view->result = array_slice($this->wrapped->view->result, $offset, $item_per_page);
|
||||
}
|
||||
$this->wrapped->post_execute($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute the count query, which will be done just prior to the query
|
||||
* itself being executed.
|
||||
*/
|
||||
function execute_count_query(&$count_query) {
|
||||
$this->wrapped->execute_count_query($count_query);
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A (fake) pager plugin that wraps around the actual query.
|
||||
*
|
||||
* @ingroup views_query_plugins
|
||||
*/
|
||||
class views_php_plugin_query extends views_php_plugin_wrapper {
|
||||
|
||||
/**
|
||||
* Implements views_plugin_query#execute().
|
||||
*/
|
||||
function execute(&$view) {
|
||||
$pager = new views_php_plugin_pager();
|
||||
$pager->php_wrap($this->wrapped->pager);
|
||||
|
||||
$this->wrapped->execute($view);
|
||||
|
||||
$pager->php_unwrap();
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A helper class that wraps around the actual views plugin.
|
||||
*
|
||||
* @see views_php_plugin_query
|
||||
* @see views_php_plugin_pager
|
||||
*/
|
||||
class views_php_plugin_wrapper {
|
||||
|
||||
protected $wrapped;
|
||||
protected $wrapped_link;
|
||||
|
||||
public function php_wrap(&$link) {
|
||||
$this->wrapped_link = &$link;
|
||||
$this->wrapped = $link;
|
||||
$link = $this;
|
||||
}
|
||||
|
||||
public function php_unwrap() {
|
||||
$this->wrapped_link = $this->wrapped;
|
||||
unset($this->wrapped);
|
||||
unset($this->wrapped_link);
|
||||
}
|
||||
|
||||
public function &__get($name) {
|
||||
return $this->wrapped->$name;
|
||||
}
|
||||
|
||||
public function __set($name, $value) {
|
||||
return $this->wrapped->$name = $value;
|
||||
}
|
||||
|
||||
public function __isset($name) {
|
||||
return isset($this->wrapped->$name);
|
||||
}
|
||||
|
||||
public function __unset($name) {
|
||||
unset($this->wrapped->$name);
|
||||
}
|
||||
|
||||
public function __call($name, $arguments) {
|
||||
return call_user_func_array(array($this->wrapped, $name), $arguments);
|
||||
}
|
||||
|
||||
/** As of PHP 5.3.0 */
|
||||
public static function __callStatic($name, $arguments) {
|
||||
return call_user_func_array(array(get_class($this->wrapped), $name), $arguments);
|
||||
}
|
||||
}
|
23
sites/all/modules/contrib/views/views_php/views_php.info
Normal file
23
sites/all/modules/contrib/views/views_php/views_php.info
Normal file
@@ -0,0 +1,23 @@
|
||||
name = Views PHP
|
||||
description = Allows the usage of PHP to construct a view.
|
||||
package = Views
|
||||
core = 7.x
|
||||
dependencies[] = views
|
||||
; Views handlers
|
||||
files[] = plugins/views/views_php_handler_area.inc
|
||||
files[] = plugins/views/views_php_handler_field.inc
|
||||
files[] = plugins/views/views_php_handler_filter.inc
|
||||
files[] = plugins/views/views_php_handler_sort.inc
|
||||
; Views plugins
|
||||
files[] = plugins/views/views_php_plugin_access.inc
|
||||
files[] = plugins/views/views_php_plugin_cache.inc
|
||||
files[] = plugins/views/views_php_plugin_pager.inc
|
||||
files[] = plugins/views/views_php_plugin_query.inc
|
||||
files[] = plugins/views/views_php_plugin_wrapper.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-09-11
|
||||
version = "7.x-1.x-dev"
|
||||
core = "7.x"
|
||||
project = "views_php"
|
||||
datestamp = "1378900545"
|
||||
|
31
sites/all/modules/contrib/views/views_php/views_php.js
Normal file
31
sites/all/modules/contrib/views/views_php/views_php.js
Normal file
@@ -0,0 +1,31 @@
|
||||
(function ($) {
|
||||
|
||||
/**
|
||||
* Attach views php clickable variables behavior.
|
||||
*/
|
||||
Drupal.behaviors.viewsPHPVariables = {
|
||||
attach: function (context) {
|
||||
$('.views-php-variables', context).delegate('a', 'click', function() {
|
||||
var textarea = $(this.href.replace(/^.*#/, '#'))[0];
|
||||
var text = $(this).text();
|
||||
textarea.focus();
|
||||
if (!isNaN(textarea.selectionStart)) {
|
||||
textarea.value = textarea.value.substring(0, textarea.selectionStart) + text + textarea.value.substring(textarea.selectionEnd);
|
||||
textarea.selectionStart = textarea.selectionStart + text.length;
|
||||
textarea.selectionEnd = textarea.selectionEnd + text.length;
|
||||
}
|
||||
// IE support.
|
||||
else if (document.selection) {
|
||||
document.selection.createRange().text = text;
|
||||
}
|
||||
else {
|
||||
textarea.value += text;
|
||||
}
|
||||
textarea.focus();
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
150
sites/all/modules/contrib/views/views_php/views_php.module
Normal file
150
sites/all/modules/contrib/views/views_php/views_php.module
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Allows to use PHP in views.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function views_php_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Menu access callback function; use PHP code to determine whether a user as
|
||||
* access.
|
||||
*/
|
||||
function views_php_check_access($php_access, $view_name, $display_id, $account = NULL) {
|
||||
global $user;
|
||||
static $function = array();
|
||||
|
||||
if (!isset($account)) {
|
||||
$account = $user;
|
||||
}
|
||||
|
||||
if (!isset($function[$view_name . ':' . $display_id])) {
|
||||
$function[$view_name . ':' . $display_id] = create_function('$view_name, $display_id, $account', $php_access . ';');
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$access = (bool) $function[$view_name . ':' . $display_id]($view_name, $display_id, $account);
|
||||
ob_end_clean();
|
||||
return $access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function; builds form for PHP code options of views handlers/plugins.
|
||||
*/
|
||||
function views_php_form_element($handler, $checkbox = FALSE, $input, $variables = array()) {
|
||||
static $default_variables;
|
||||
if (!isset($default_variables)) {
|
||||
$default_variables = array(
|
||||
'$view' => t('The view object.'),
|
||||
'$handler' => t('The handler object.'),
|
||||
'$plugin' => t('The plugin object.'),
|
||||
'$static' => t('A variable that can be used to store reusable data per row.'),
|
||||
'$row' => t('Contains the retrieved record from the database (e.g. $data->nid).'),
|
||||
'$data' => t('Contains the retrieved record from the database (e.g. $data->nid).'),
|
||||
'$results' => t('Array containing the view\'s result.'),
|
||||
'$cache' => t('The cache object.'),
|
||||
);
|
||||
}
|
||||
|
||||
list($name, $title, $description, $use_delimiters) = $input;
|
||||
$container = array(
|
||||
'#type' => 'container',
|
||||
// @todo #tree => FALSE doesn't work here.
|
||||
'#parents' => array('options'),
|
||||
);
|
||||
|
||||
if (!empty($checkbox)) {
|
||||
list($checkbox_name, $checkbox_title, $checkbox_description) = $checkbox;
|
||||
$checkbox = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $checkbox_title,
|
||||
'#description' => $checkbox_description,
|
||||
'#default_value' => $handler->options[$checkbox_name] && !empty($handler->options[$name]),
|
||||
);
|
||||
$container['#states'] = array(
|
||||
'invisible' => array(
|
||||
'input[name="options[use_' . $name . ']"]' => array('checked' => FALSE),
|
||||
),
|
||||
);
|
||||
}
|
||||
$container[$name] = array(
|
||||
'#type' => 'textarea',
|
||||
'#id' => drupal_html_id('edit-options-' . $name),
|
||||
'#title' => $title,
|
||||
'#default_value' => $handler->options[$name],
|
||||
'#rows' => 5,
|
||||
'#description' => $description . ' <strong>' . ($use_delimiters
|
||||
? t('Use <?php ?> delimiters to enclose PHP code.')
|
||||
: t('Do not use <?php ?> delimiters.'))
|
||||
. '</strong>',
|
||||
);
|
||||
// Only users with use PHP permission can set/modify input.
|
||||
if (!user_access('use PHP for settings')) {
|
||||
$container[$name]['#disabled'] = TRUE;
|
||||
$container[$name]['#value'] = $container[$name]['#default_value'];
|
||||
$container[$name]['#description'] .= ' <strong>' . t('You do not have permission to modify this.') . '</strong>';
|
||||
}
|
||||
|
||||
$items = array();
|
||||
foreach ($variables as $variable_name => $description) {
|
||||
if (is_int($variable_name)) {
|
||||
$variable_name = $description;
|
||||
$description = isset($default_variables[$description]) ? $default_variables[$description] : '';
|
||||
}
|
||||
$items[] = l($variable_name, '', array('fragment' => $container[$name]['#id'], 'external' => TRUE)) . ': ' . $description;
|
||||
|
||||
if (strpos($variable_name, '$row') === 0) {
|
||||
foreach ($handler->view->display_handler->get_handlers('field') as $field => $field_handler) {
|
||||
$items[] = l($variable_name . '->' . $field, '', array('fragment' => $container[$name]['#id'], 'external' => TRUE)) . ': ' . $field_handler->ui_name();
|
||||
}
|
||||
}
|
||||
}
|
||||
$container[$name . '_variables'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Available variables'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#attributes' => array('class' => array('views-php-variables')),
|
||||
'#attached' => array(
|
||||
'js' => array(drupal_get_path('module', 'views_php') . '/views_php.js'),
|
||||
)
|
||||
);
|
||||
$container[$name . '_variables']['variables'] = array(
|
||||
'#theme' => 'item_list',
|
||||
'#items' => $items,
|
||||
);
|
||||
|
||||
if (!empty($checkbox)) {
|
||||
return array($checkbox_name => $checkbox, $name => $container);
|
||||
}
|
||||
return array($name => $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_pre_execute().
|
||||
*/
|
||||
function views_php_views_pre_execute($view) {
|
||||
// Seize control over the query plugin if a views handler requested so.
|
||||
if (!empty($view->views_php)) {
|
||||
$query = new views_php_plugin_query();
|
||||
$query->php_wrap($view->query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_post_execute().
|
||||
*/
|
||||
function views_php_views_post_execute($view) {
|
||||
// Restore original query plugin if it was wrapped.
|
||||
if ($view->query instanceof views_php_plugin_wrapper) {
|
||||
$view->query->php_unwrap();
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide views handlers and plugins that allow usage of PHP.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function views_php_views_data() {
|
||||
$data['views']['php'] = array(
|
||||
'title' => t('PHP'),
|
||||
'help' => t('Use PHP code.'),
|
||||
'area' => array(
|
||||
'help' => t('Use PHP code to construct the output of an area.'),
|
||||
'handler' => 'views_php_handler_area',
|
||||
),
|
||||
'field' => array(
|
||||
'help' => t('Use PHP code to construct the output of a field.'),
|
||||
'handler' => 'views_php_handler_field',
|
||||
),
|
||||
'filter' => array(
|
||||
'help' => t('Use PHP code to filter the result of the view.'),
|
||||
'handler' => 'views_php_handler_filter',
|
||||
),
|
||||
'sort' => array(
|
||||
'help' => t('Use PHP code to sort the result of the view.'),
|
||||
'handler' => 'views_php_handler_sort',
|
||||
),
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins().
|
||||
*/
|
||||
function views_php_views_plugins() {
|
||||
$plugins = array(
|
||||
'access' => array(
|
||||
'php' => array(
|
||||
'title' => t('PHP'),
|
||||
'help' => t('Use PHP code to grant access.'),
|
||||
'handler' => 'views_php_plugin_access',
|
||||
'uses options' => TRUE,
|
||||
),
|
||||
),
|
||||
'cache' => array(
|
||||
'php' => array(
|
||||
'title' => t('PHP'),
|
||||
'help' => t('Use PHP code to determine whether a should be cached.'),
|
||||
'handler' => 'views_php_plugin_cache',
|
||||
'uses options' => TRUE,
|
||||
),
|
||||
),
|
||||
);
|
||||
return $plugins;
|
||||
}
|
Reference in New Issue
Block a user