FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/files/filefield_paths/LICENSE.txt
Normal file
339
sites/all/modules/contrib/files/filefield_paths/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,22 @@
|
||||
name = File<strike>Field</strike> Paths
|
||||
description = Adds improved Token based file sorting and renaming functionalities.
|
||||
dependencies[] = token
|
||||
package = Fields
|
||||
core = 7.x
|
||||
|
||||
files[] = filefield_paths.install
|
||||
files[] = filefield_paths.module
|
||||
|
||||
files[] = modules/file.inc
|
||||
files[] = modules/filefield_paths.inc
|
||||
files[] = modules/image.inc
|
||||
files[] = modules/token.inc
|
||||
|
||||
;files[] = tests/filefield_paths.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2011-11-14
|
||||
version = "7.x-1.x-dev"
|
||||
core = "7.x"
|
||||
project = "filefield_paths"
|
||||
datestamp = "1321229825"
|
||||
|
@@ -0,0 +1,194 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the FileField Paths module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function filefield_paths_schema() {
|
||||
$schema['filefield_paths'] = array(
|
||||
'fields' => array(
|
||||
'type' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
'default' => ''
|
||||
),
|
||||
'field' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
'default' => ''
|
||||
),
|
||||
'filename' => array(
|
||||
'type' => 'text',
|
||||
'size' => 'medium',
|
||||
'not null' => TRUE,
|
||||
'serialize' => TRUE
|
||||
),
|
||||
'filepath' => array(
|
||||
'type' => 'text',
|
||||
'size' => 'medium',
|
||||
'not null' => TRUE,
|
||||
'serialize' => TRUE
|
||||
),
|
||||
'active_updating' => array(
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'not null' => TRUE,
|
||||
'default' => 0
|
||||
),
|
||||
),
|
||||
'unique keys' => array(
|
||||
'type_field' => array('type', 'field'),
|
||||
),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_schema_alter().
|
||||
*
|
||||
* @param $schema
|
||||
* The system-wide schema
|
||||
*/
|
||||
function filefield_paths_schema_alter(&$schema) {
|
||||
$schema['file_managed']['fields']['origname'] = array(
|
||||
'description' => 'Original name of the file.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function filefield_paths_install() {
|
||||
// Add origname field to {file_managed}, and populate with the current
|
||||
// filenames.
|
||||
db_add_field('file_managed', 'origname', array(
|
||||
'description' => 'Original name of the file with no path components. Used by the filefield_paths module.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
db_update('file_managed')
|
||||
->expression('origname', 'filename')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function filefield_paths_uninstall() {
|
||||
db_drop_field('file_managed', 'origname');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_last_removed().
|
||||
*/
|
||||
function hook_update_last_removed() {
|
||||
return 6103;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_dependencies().
|
||||
*/
|
||||
function filefield_paths_dependencies() {
|
||||
// Update 7103 uses the {file_managed} table, so make sure it is available.
|
||||
$dependencies['filefield_paths'][7103] = array(
|
||||
'system' => 7034,
|
||||
);
|
||||
|
||||
return $dependencies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add origname field to {file_managed}.
|
||||
*/
|
||||
function filefield_paths_update_7103() {
|
||||
// Clean-up an unused variable.
|
||||
variable_del('filefield_paths_schema_version');
|
||||
|
||||
// Add origname field to {file_managed}, and populate with the current
|
||||
// filenames.
|
||||
if (!db_field_exists('file_managed', 'origname')) {
|
||||
db_add_field('file_managed', 'origname', array(
|
||||
'description' => 'Original name of the file with no path components. Used by the filefield_paths module.',
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
}
|
||||
db_update('file_managed')
|
||||
->expression('origname', 'filename')
|
||||
->condition('origname', '')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add active updating flag to {filefield_paths}
|
||||
*/
|
||||
function filefield_paths_update_7104() {
|
||||
db_add_field('filefield_paths', 'active_updating', array(
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'not null' => TRUE,
|
||||
'default' => '0'
|
||||
));
|
||||
|
||||
// migrate variable to filefield_paths table
|
||||
$result = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'ffp_%%_field_%%'");
|
||||
foreach ($result as $row) {
|
||||
if (preg_match('/ffp_(.+)_field_(.+)$/', $row->name, $match)) {
|
||||
$active_updating = unserialize($row->value);
|
||||
if ($active_updating) {
|
||||
db_update('filefield_paths')
|
||||
->fields(array(
|
||||
'active_updating' => $active_updating
|
||||
))
|
||||
->condition('type', $match[1])
|
||||
->condition('field', $match[2])
|
||||
->execute();
|
||||
}
|
||||
variable_del($row->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Correct the default value for {filefield_paths}.active_updating field.
|
||||
*/
|
||||
function filefield_paths_update_7105() {
|
||||
db_change_field('filefield_paths', 'active_updating', 'active_updating', array(
|
||||
'type' => 'int',
|
||||
'size' => 'tiny',
|
||||
'not null' => TRUE,
|
||||
'default' => 0
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase length of 'type' and 'field' columns.
|
||||
*/
|
||||
function filefield_paths_update_7106() {
|
||||
db_change_field('filefield_paths', 'type', 'type', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
'default' => ''
|
||||
));
|
||||
db_change_field('filefield_paths', 'field', 'field', array(
|
||||
'type' => 'varchar',
|
||||
'length' => 128,
|
||||
'not null' => TRUE,
|
||||
'default' => ''
|
||||
));
|
||||
}
|
@@ -0,0 +1,466 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains core functions for the FileField Paths module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Include additional files.
|
||||
*/
|
||||
foreach (module_list() as $module) {
|
||||
if (file_exists($file = dirname(__FILE__) . "/modules/{$module}.inc")) {
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function filefield_paths_form_alter(&$form, $form_state, $form_id) {
|
||||
$ffp = array();
|
||||
|
||||
// Invoke hook_filefield_paths_form_alter().
|
||||
foreach (module_implements('filefield_paths_form_alter') as $module) {
|
||||
$function = "{$module}_filefield_paths_form_alter";
|
||||
$function($form, $ffp);
|
||||
}
|
||||
|
||||
// If supporting module enabled, show FileField Paths settings form.
|
||||
if (count($ffp) > 0) {
|
||||
$entity_info = entity_get_info($form['#instance']['entity_type']);
|
||||
$fields = module_invoke_all('filefield_paths_field_settings');
|
||||
foreach ($ffp as $field_name => $field_data) {
|
||||
$active_updating = 0;
|
||||
|
||||
$results = db_select('filefield_paths', 'f')
|
||||
->fields('f')
|
||||
->condition('type', $field_data['type'])
|
||||
->condition('field', $field_name)
|
||||
->execute()
|
||||
->fetchAllAssoc('type');
|
||||
if (!empty($results[$field_data['type']])) {
|
||||
$result = $results[$field_data['type']];
|
||||
foreach ($fields as &$field) {
|
||||
$field['settings'] = unserialize($result->{$field['sql']});
|
||||
}
|
||||
unset($field);
|
||||
$active_updating = $result->active_updating;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ($fields as $name => $field) {
|
||||
$count++;
|
||||
|
||||
if (isset($field['form']) && is_array($field['form'])) {
|
||||
$keys = array_keys($field['form']);
|
||||
for ($i = 1; $i < count($field['form']); $i++) {
|
||||
$field['form'][$keys[$i]]['#weight'] = ($count - 1) * 3 + 2 + $i;
|
||||
$field['form'][$keys[$i]]['#element_validate'] = array('token_element_validate');
|
||||
$field['form'][$keys[$i]]['#token_types'] = array('file', $entity_info['token type']);
|
||||
}
|
||||
unset($keys);
|
||||
|
||||
$field_data['form_path'] = array_merge_recursive($field_data['form_path'], $field['form']);
|
||||
}
|
||||
|
||||
$field_data['form_path']['#tree'] = TRUE;
|
||||
$field_data['form_path'][$name]['#weight'] = ($count - 1) * 3;
|
||||
|
||||
// Set defualt value for patterns.
|
||||
if (isset($field['settings']['value'])) {
|
||||
$field_data['form_path'][$name]['#default_value'] = $field['settings']['value'];
|
||||
|
||||
if (isset($field['data'])) {
|
||||
foreach ($field['data'] as $key => $value) {
|
||||
$field_data['form_path'][$value]['#default_value'] = $field['settings'][$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$field_data['form_path']["{$name}_cleanup"] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('@title cleanup settings', array('@title' => $field['title'])),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => ($count - 1) * 3 + 1,
|
||||
'#attributes' => array(
|
||||
'class' => array("{$name} cleanup")
|
||||
)
|
||||
);
|
||||
|
||||
// Cleanup field with Pathauto module.
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_pathauto"] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Cleanup using Pathauto') . '.',
|
||||
'#default_value' => isset($field['settings']['pathauto'])
|
||||
? $field['settings']['pathauto']
|
||||
: 0
|
||||
,
|
||||
'#description' => t('Cleanup @title using', array('@title' => $field['title'])) . ' ' . l(t('Pathauto settings'), 'admin/config/search/path/settings'),
|
||||
);
|
||||
if (!module_exists('pathauto')) {
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_pathauto"]['#disabled'] = TRUE;
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_pathauto"]['#default_value'] = 0;
|
||||
}
|
||||
|
||||
// Convert field to lower case.
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_tolower"] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Convert to lower case') . '.',
|
||||
'#default_value' => isset($field['settings']['tolower'])
|
||||
? $field['settings']['tolower']
|
||||
: 0
|
||||
,
|
||||
'#description' => t('Convert @title to lower case', array('@title' => $field['title'])) . '.'
|
||||
);
|
||||
|
||||
// Transliterate field with Transliteration module.
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_transliterate"] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Transliterate') . '.',
|
||||
'#default_value' => isset($field['settings']['transliterate'])
|
||||
? $field['settings']['transliterate']
|
||||
: 0
|
||||
,
|
||||
'#description' => t('Transliterate @title', array('@title' => $field['title'])) . '.'
|
||||
);
|
||||
if (!module_exists('transliteration')) {
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_transliterate"]['#disabled'] = TRUE;
|
||||
$field_data['form_path']["{$name}_cleanup"]["{$name}_transliterate"]['#default_value'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Replacement patterns for field.
|
||||
$field_data['form_path']['token_tree'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Replacement patterns'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#description' => theme('token_tree', array('token_types' => array('file', $entity_info['token type']))),
|
||||
'#weight' => 10,
|
||||
);
|
||||
|
||||
// Retroactive updates.
|
||||
$field_data['form_path']['retroactive_update'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Retroactive update'),
|
||||
'#description' => t('Move and rename previously uploaded files') . '.' .
|
||||
'<br /> <strong style="color: #FF0000;">' . t('Warning') . ':</strong> ' .
|
||||
t('This feature should only be used on developmental servers or with extreme caution') . '.',
|
||||
'#weight' => 11
|
||||
);
|
||||
|
||||
// Active updating.
|
||||
$field_data['form_path']['active_updating'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Active updating'),
|
||||
'#default_value' => $active_updating,
|
||||
'#description' => t('Actively move and rename previously uploaded files as required') . '.' .
|
||||
'<br /> <strong style="color: #FF0000;">' . t('Warning') . ':</strong> ' .
|
||||
t('This feature should only be used on developmental servers or with extreme caution') . '.',
|
||||
'#weight' => 12
|
||||
);
|
||||
|
||||
if (!in_array('filefield_paths_form_submit', $form['#submit'])) {
|
||||
$form['#submit'][] = 'filefield_paths_form_submit';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_submit().
|
||||
*/
|
||||
function filefield_paths_form_submit($form, &$form_state) {
|
||||
$ffp = array();
|
||||
|
||||
// Invoke hook_filefield_paths_form_submit().
|
||||
foreach (module_implements('filefield_paths_form_submit') as $module) {
|
||||
$function = "{$module}_filefield_paths_form_submit";
|
||||
$function($form_state, $ffp);
|
||||
}
|
||||
|
||||
if (count($ffp) > 0) {
|
||||
$retroactive_update = FALSE;
|
||||
$fields = module_invoke_all('filefield_paths_field_settings');
|
||||
foreach ($ffp as $field_name => $field_data) {
|
||||
$cols = array(
|
||||
'type' => $field_data['type'],
|
||||
'field' => $field_name,
|
||||
'active_updating' => $form_state['values']["ffp_{$field_name}"]['active_updating'],
|
||||
);
|
||||
|
||||
foreach ($fields as $name => &$field) {
|
||||
$cols[$field['sql']] = array(
|
||||
'value' => $form_state['values']["ffp_{$field_name}"][$name],
|
||||
'tolower' => $form_state['values']["ffp_{$field_name}"]["{$name}_cleanup"]["{$name}_tolower"],
|
||||
'pathauto' => $form_state['values']["ffp_{$field_name}"]["{$name}_cleanup"]["{$name}_pathauto"],
|
||||
'transliterate' => $form_state['values']["ffp_{$field_name}"]["{$name}_cleanup"]["{$name}_transliterate"],
|
||||
);
|
||||
|
||||
// Store additional settings from add-on modules.
|
||||
if (isset($field['data'])) {
|
||||
foreach ($field['data'] as $key => $value) {
|
||||
$cols[$field['sql']][$key] = $form_state['values']["ffp_{$field_name}"][$value];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results = db_select('filefield_paths', 'f')
|
||||
->fields('f')
|
||||
->condition('type', $cols['type'])
|
||||
->condition('field', $cols['field'])
|
||||
->execute()
|
||||
->fetchAll();
|
||||
|
||||
// Update existing entry.
|
||||
if (!empty($results)) {
|
||||
drupal_write_record('filefield_paths', $cols, array('type', 'field'));
|
||||
}
|
||||
|
||||
// Create new entry.
|
||||
else {
|
||||
drupal_write_record('filefield_paths', $cols);
|
||||
}
|
||||
|
||||
if ($form_state['values']["ffp_{$field_name}"]['retroactive_update']) {
|
||||
$retroactive_update = TRUE;
|
||||
$module = isset($form['#field']) ? $form['#field']['module'] : $field_name;
|
||||
filefield_paths_batch_update($form_state['values']['instance']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($retroactive_update) {
|
||||
// Run batch.
|
||||
batch_process($form_state['redirect']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set batch process to update FileField Paths.
|
||||
*
|
||||
* @param $instance
|
||||
*/
|
||||
function filefield_paths_batch_update($instance) {
|
||||
$objects = array();
|
||||
|
||||
// Invoke hook_filefield_paths_batch_update().
|
||||
if (function_exists($function = "{$instance['widget']['module']}_filefield_paths_batch_update")) {
|
||||
$function($instance, $objects);
|
||||
}
|
||||
|
||||
// Create batch.
|
||||
$batch = array(
|
||||
'title' => t('Updating FileField Paths'),
|
||||
'operations' => array(
|
||||
array('_filefield_paths_batch_update_process', array($objects, $instance))
|
||||
),
|
||||
);
|
||||
batch_set($batch);
|
||||
}
|
||||
|
||||
function _filefield_paths_batch_update_process($objects, $instance, &$context) {
|
||||
if (!isset($context['sandbox']['progress'])) {
|
||||
$context['sandbox']['progress'] = 0;
|
||||
$context['sandbox']['max'] = count($objects);
|
||||
$context['sandbox']['objects'] = $objects;
|
||||
}
|
||||
|
||||
// Process nodes by groups of 5.
|
||||
$count = min(5, count($context['sandbox']['objects']));
|
||||
for ($i = 1; $i <= $count; $i++) {
|
||||
// For each oid, load the object, update the files and save it.
|
||||
$oid = array_shift($context['sandbox']['objects']);
|
||||
|
||||
// Invoke hook_filefield_paths_update().
|
||||
if (function_exists($function = "{$instance['widget']['module']}_filefield_paths_update")) {
|
||||
$function($oid, $instance);
|
||||
}
|
||||
|
||||
// Update our progress information.
|
||||
$context['sandbox']['progress']++;
|
||||
}
|
||||
|
||||
// Inform the batch engine that we are not finished,
|
||||
// and provide an estimation of the completion level we reached.
|
||||
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
|
||||
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_insert().
|
||||
*/
|
||||
function filefield_paths_entity_insert($entity, $type) {
|
||||
filefield_paths_entity_update($entity, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_entity_update().
|
||||
*/
|
||||
function filefield_paths_entity_update($entity, $type) {
|
||||
if (($ffp = filefield_paths_get_fields($entity, $type)) !== FALSE) {
|
||||
$update = new stdClass;
|
||||
$update->entity = FALSE;
|
||||
|
||||
// Process files.
|
||||
foreach ($ffp['#files'] as &$file) {
|
||||
// Invoke hook_filefield_paths_process_file().
|
||||
foreach (module_implements('filefield_paths_process_file') as $module) {
|
||||
$function = "{$module}_filefield_paths_process_file";
|
||||
$settings = isset($ffp['#settings'][$file['name']]) ? $ffp['#settings'][$file['name']] : NULL;
|
||||
if (!is_null($settings)) {
|
||||
$function(($file['new'] || $settings['active_updating']), $file, $settings, $entity, $type, $update);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($update->entity == TRUE) {
|
||||
field_attach_update($type, $entity);
|
||||
}
|
||||
|
||||
// Cleanup temporary paths.
|
||||
if ($ffp['#settings']) {
|
||||
foreach ($ffp['#settings'] as $name => $field) {
|
||||
// Invoke hook_filefield_paths_cleanup().
|
||||
foreach (module_implements('filefield_paths_cleanup') as $module) {
|
||||
$function = "{$module}_filefield_paths_cleanup";
|
||||
$function($ffp, $name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_presave().
|
||||
*/
|
||||
function filefield_paths_file_presave($file) {
|
||||
// Store original filename in the database.
|
||||
if (empty($file->origname)) {
|
||||
$file->origname = $file->filename;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_delete_instance().
|
||||
*/
|
||||
function filefield_paths_field_delete_instance($instance) {
|
||||
db_delete('filefield_paths')
|
||||
->condition('type', "{$instance['entity_type']}::{$instance['bundle']}")
|
||||
->condition('field', $instance['field_name'])
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function filefield_paths_get_fields(&$entity, $type, $op = NULL) {
|
||||
$ffp = array();
|
||||
$entity_info = entity_get_info();
|
||||
|
||||
// Invoke hook_filefield_paths_get_fields().
|
||||
foreach (module_implements('filefield_paths_get_fields') as $module) {
|
||||
$function = "{$module}_filefield_paths_get_fields";
|
||||
$function($entity, $ffp);
|
||||
}
|
||||
|
||||
if (count($ffp) == 0 || (isset($ffp['#types']) && !is_array($ffp['#types']))) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$fields = module_invoke_all('filefield_paths_field_settings');
|
||||
|
||||
// Load fields settings
|
||||
foreach (array_keys($ffp['#types']) as $name) {
|
||||
$field_type = isset($entity->{$entity_info[$type]['entity keys']['bundle']}) ? "{$type}::{$entity->{$entity_info[$type]['entity keys']['bundle']}}" : "{$type}::{$type}";
|
||||
$results = db_select('filefield_paths', 'f')
|
||||
->fields('f')
|
||||
->condition('type', $field_type)
|
||||
->condition('field', $name)
|
||||
->execute()
|
||||
->fetchAllAssoc('type');
|
||||
|
||||
if (!empty($results[$field_type])) {
|
||||
$result = $results[$field_type];
|
||||
foreach ($fields as $field) {
|
||||
$ffp['#settings'][$name][$field['sql']] = unserialize($result->$field['sql']);
|
||||
}
|
||||
$ffp['#settings'][$name]['active_updating'] = $result->active_updating;
|
||||
}
|
||||
}
|
||||
|
||||
return $ffp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run regular expression over all available text-based fields.
|
||||
*/
|
||||
function _filefield_paths_replace_path($old, $new, &$entity, &$update) {
|
||||
// Build regular expression.
|
||||
$info = parse_url($old);
|
||||
$info['path'] = !empty($info['path']) ? $info['path'] : '';
|
||||
$absolute = str_replace("{$info['host']}{$info['path']}", '', file_create_url($old));
|
||||
$relative = parse_url($absolute, PHP_URL_PATH);
|
||||
$regex = str_replace('/', '\/', "({$absolute}|{$relative}|{$info['scheme']}://)(styles/.*?/{$info['scheme']}/|)({$info['host']}{$info['path']})");
|
||||
|
||||
// Build replacement.
|
||||
$info = parse_url($new);
|
||||
$replacement = "\$1\$2{$info['host']}{$info['path']}";
|
||||
|
||||
$fields = field_info_fields();
|
||||
foreach ($fields as $name => $field) {
|
||||
if ($field['module'] == 'text' && isset($entity->{$field['field_name']}) && is_array($entity->{$field['field_name']})) {
|
||||
foreach ($entity->{$field['field_name']} as &$language) {
|
||||
foreach ($language as &$item) {
|
||||
$item['value'] = preg_replace("/$regex/", $replacement, $item['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process and cleanup strings.
|
||||
*/
|
||||
function filefield_paths_process_string($value, $data, $settings = array()) {
|
||||
$transliterate = module_exists('transliteration') && isset($settings['transliterate']) && $settings['transliterate'];
|
||||
$pathauto = module_exists('pathauto') && isset($settings['pathauto']) && $settings['pathauto'] == TRUE;
|
||||
if ($pathauto == TRUE) {
|
||||
module_load_include('inc', 'pathauto');
|
||||
}
|
||||
|
||||
$paths = explode('/', $value);
|
||||
foreach ($paths as &$path) {
|
||||
|
||||
// Process string tokens.
|
||||
$path = token_replace($path, $data, array('clear' => TRUE));
|
||||
|
||||
// Cleanup with pathauto.
|
||||
if ($pathauto == TRUE) {
|
||||
$path_parts = explode('.', $path);
|
||||
foreach ($path_parts as &$path_part) {
|
||||
$path_part = pathauto_cleanstring($path_part);
|
||||
}
|
||||
$path = implode('.', $path_parts);
|
||||
}
|
||||
|
||||
// Transliterate string.
|
||||
if ($transliterate == TRUE) {
|
||||
$path = transliteration_clean_filename($path);
|
||||
}
|
||||
}
|
||||
$value = implode('/', $paths);
|
||||
|
||||
// Convert string to lower case.
|
||||
if (isset($settings['tolower']) && $settings['tolower'] == TRUE) {
|
||||
$value = drupal_strtolower($value);
|
||||
}
|
||||
|
||||
// Ensure that there are no double-slash sequences due to empty token values.
|
||||
$value = preg_replace('/\/+/', '/', $value);
|
||||
|
||||
return $value;
|
||||
}
|
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_api().
|
||||
*
|
||||
* Main info hook that features uses to determine what components are provided
|
||||
*
|
||||
* The 'component' for this module is named 'filefield_paths' not just
|
||||
* 'filefield_paths' to follow recommended practice documented in features.api
|
||||
*
|
||||
* We export individual filefield_paths instances, although seldom on their
|
||||
* own, usually as part of a bigger package. When a content type or field is
|
||||
* being exported, these settings come along for the ride.
|
||||
*/
|
||||
function filefield_paths_features_api() {
|
||||
return array(
|
||||
'filefield_paths' => array(
|
||||
'name' => t('FileField Paths'),
|
||||
'default_hook' => 'default_filefield_paths',
|
||||
'feature_source' => TRUE,
|
||||
'default_file' => FEATURES_DEFAULTS_INCLUDED_COMMON,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_options().
|
||||
*
|
||||
* List all FileField Paths config settings currently available for export. This
|
||||
* adds each of the configurations to the features UI where they can be chosen
|
||||
* for bundling.
|
||||
*
|
||||
* This UI may be entirely unneccessary if we only ever export as a part of
|
||||
* something else (individual fields settings), but it's here for completeness.
|
||||
*
|
||||
* @return array A keyed array of items, suitable for use with a FormAPI select
|
||||
* or checkboxes element.
|
||||
*/
|
||||
function filefield_paths_features_export_options() {
|
||||
$options = array();
|
||||
$results = db_select('filefield_paths', 'f')
|
||||
->fields('f', array('type', 'field'))
|
||||
->execute();
|
||||
foreach ($results as $row) {
|
||||
// Generate the unique keys that can identify the row
|
||||
// "{entity_type}::{bundle}::{field_name}" eg "node::story::field_illustration"
|
||||
$key = "{$row->type}::{$row->field}";
|
||||
$options[$key] = $key;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export().
|
||||
*
|
||||
* Process the export array for a given component.
|
||||
*
|
||||
* Normally, we will be adding this as a child in the pipe of
|
||||
* field_features_export, so that when a filefield instance is exported, this
|
||||
* setting was published along with it.
|
||||
*/
|
||||
function filefield_paths_features_export($data, &$export, $module_name = '') {
|
||||
$export['dependencies']['filefield_paths'] = 'filefield_paths';
|
||||
|
||||
$pipe = array();
|
||||
foreach ($data as $identifier) {
|
||||
if ($wrapper = filefield_paths_load($identifier)) {
|
||||
$export['features']['filefield_paths'][$identifier] = $identifier;
|
||||
if ($wrapper['filename']['transliterate'] || $wrapper['filepath']['transliterate']) {
|
||||
$export['dependencies']['transliteration'] = 'transliteration';
|
||||
}
|
||||
if ($wrapper['filename']['pathauto'] || $wrapper['filepath']['pathauto']) {
|
||||
$export['dependencies']['pathauto'] = 'pathauto';
|
||||
}
|
||||
if (module_exists('strongarm')) {
|
||||
$variable_map = features_get_default_map('variable');
|
||||
$pipe['variable'][] = "ffp_{$wrapper['type']}_{$wrapper['field']}";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach our own export routine as a piped export that happens below any
|
||||
* filefield path that is getting exported.
|
||||
*
|
||||
* The component name for fields is 'field'.
|
||||
*
|
||||
* HOOK_features_pipe_COMPONENT_alter()
|
||||
*
|
||||
* This captures each field export, and adds ourself to the dependencies and
|
||||
* exports when that field is exported.
|
||||
*/
|
||||
function filefield_paths_features_pipe_field_alter(&$pipe, $data, $export) {
|
||||
foreach ($data as $field_identifier) {
|
||||
|
||||
// Convert field identifier to FileField Paths format.
|
||||
$field_identifier = str_replace('-', '::', $field_identifier);
|
||||
|
||||
// Field export is exporting a field named $field_identifier.
|
||||
// If that is a filefield, we should attach ourselves as a subprocess (pipe).
|
||||
// .. actually, don't need to check the field type,
|
||||
// just see if we have some filefield_path
|
||||
// settings that use the same $field_identifier key!
|
||||
|
||||
if (filefield_paths_load($field_identifier)) {
|
||||
// So add this setting as a piped child of the filed when it gets exported.
|
||||
$pipe['filefield_paths'][$field_identifier] = $field_identifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the required path settings for the named filefield instance.
|
||||
*
|
||||
* A CRUD utility for filefield_paths
|
||||
*
|
||||
* @param a unique identifier for the given field instance -
|
||||
* {$entity_type::$bundle::$field}.
|
||||
*
|
||||
* @return a row array from the filefield_paths DB table - with the 'serialized'
|
||||
* blobs unpacked.
|
||||
*/
|
||||
function filefield_paths_load($identifier) {
|
||||
list($entity_type, $bundle, $field_name) = explode('::', $identifier);
|
||||
$result = db_select('filefield_paths', 'f')
|
||||
->fields('f')
|
||||
->condition('type', "{$entity_type}::{$bundle}")
|
||||
->condition('field', $field_name)
|
||||
->execute();
|
||||
if ($row = $result->fetchAssoc()) {
|
||||
$ffp = array();
|
||||
// Each cell in the row gets exposed, retrieve the schema to figure this out.
|
||||
$schema = drupal_get_schema('filefield_paths');
|
||||
foreach ($schema['fields'] as $field => $field_def) {
|
||||
$ffp[$field] = empty($field_def['serialize']) ? $row[$field] : unserialize($row[$field]);
|
||||
}
|
||||
return $ffp;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the identified row
|
||||
*
|
||||
* A CRUD utility for filefield_paths
|
||||
*/
|
||||
function filefield_paths_delete($identifier) {
|
||||
list($entity_type, $bundle, $field_name) = explode('::', $identifier);
|
||||
db_delete('filefield_paths')
|
||||
->condition('type', "{$entity_type}::{$bundle}")
|
||||
->condition('field', $field_name)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_render()
|
||||
*
|
||||
* Return the PHP code that represents a dump of the settings listed as $data
|
||||
*/
|
||||
function filefield_paths_features_export_render($module, $data) {
|
||||
$code = array();
|
||||
$code[] = ' $settings = array();';
|
||||
$code[] = '';
|
||||
|
||||
$translatables = array();
|
||||
foreach ($data as $item_id) {
|
||||
$item = filefield_paths_load($item_id);
|
||||
if (empty($item)) {
|
||||
watchdog('filefield_paths', "Failed to retrieve the filefield path settings '%item_id' while preparing the feature export code.", array('%item_id' => $item_id), WATCHDOG_WARNING);
|
||||
continue;
|
||||
}
|
||||
$code[] = " // Exported {$item_id}";
|
||||
$export = features_var_export($item, ' ');
|
||||
$code[] = " \$settings['{$item_id}'] = {$export};";
|
||||
}
|
||||
|
||||
$code[] = '';
|
||||
$code[] = ' return $settings;';
|
||||
$code = implode("\n", $code);
|
||||
return array('default_filefield_paths' => $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_features_export_revert().
|
||||
*/
|
||||
function filefield_paths_features_revert($module) {
|
||||
filefield_paths_features_rebuild($module);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create/recreate the items based on the data array. Data should contain a
|
||||
* number of filefield_paths definitions.
|
||||
*
|
||||
* Implements hook_features_export_rebuild().
|
||||
*
|
||||
* Data just need to be put straight into the database as rows.
|
||||
*/
|
||||
function filefield_paths_features_rebuild($module) {
|
||||
if ($defaults = features_get_default('filefield_paths', $module)) {
|
||||
foreach ($defaults as $filefield_paths_id => $filefield_paths) {
|
||||
// Delete any previous settings for this item.
|
||||
if (filefield_paths_load($filefield_paths_id)) {
|
||||
filefield_paths_delete($filefield_paths_id);
|
||||
}
|
||||
drupal_write_record('filefield_paths', $filefield_paths);
|
||||
}
|
||||
}
|
||||
}
|
110
sites/all/modules/contrib/files/filefield_paths/modules/file.inc
Normal file
110
sites/all/modules/contrib/files/filefield_paths/modules/file.inc
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* File module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_form_alter().
|
||||
*/
|
||||
function file_filefield_paths_form_alter(&$form, &$ffp) {
|
||||
if (isset($form['#field']) && $form['#field']['type'] == 'file' && isset($form['instance']['settings']['file_directory'])) {
|
||||
$ffp[$form['#field']['field_name']] = array(
|
||||
'show' => TRUE,
|
||||
'type' => "{$form['instance']['entity_type']['#value']}::{$form['instance']['bundle']['#value']}",
|
||||
'form_path' => &$form['instance']["ffp_{$form['#field']['field_name']}"],
|
||||
'file_path_default' => $form['instance']['settings']['file_directory']['#default_value']
|
||||
);
|
||||
|
||||
// Create path settings fieldset
|
||||
$ffp[$form['#field']['field_name']]['form_path'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('File Path settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 1,
|
||||
);
|
||||
|
||||
$ffp[$form['#field']['field_name']]['form_path']['file_path'] = $form['instance']['settings']['file_directory'];
|
||||
$ffp[$form['#field']['field_name']]['form_path']['file_path']['#title'] = t('File path');
|
||||
$form['instance']['settings']['file_directory']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_form_submit().
|
||||
*/
|
||||
function file_filefield_paths_form_submit(&$form_state, &$ffp) {
|
||||
if (isset($form_state['values']['form_id']) && $form_state['values']['form_id'] == 'field_ui_field_edit_form') {
|
||||
$form_state['values']["ffp_{$form_state['values']['instance']['field_name']}"] = $form_state['values']['instance']["ffp_{$form_state['values']['instance']['field_name']}"];
|
||||
$ffp[$form_state['values']['instance']['field_name']] = array(
|
||||
'type' => "{$form_state['values']['instance']['entity_type']}::{$form_state['values']['instance']['bundle']}",
|
||||
);
|
||||
|
||||
$form_state['values']['instance']['settings']['file_directory'] = $form_state['values']["ffp_{$form_state['values']['instance']['field_name']}"]['file_path'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_get_fields().
|
||||
*/
|
||||
function file_filefield_paths_get_fields(&$entity, &$ffp) {
|
||||
if (is_object($entity)) {
|
||||
$fields = field_info_fields();
|
||||
foreach ($fields as $name => $field) {
|
||||
if ($field['type'] == 'file' && isset($entity->{$field['field_name']}) && is_array($entity->{$field['field_name']})) {
|
||||
foreach ($entity->{$field['field_name']} as $language) {
|
||||
foreach ($language as $file) {
|
||||
$new = isset($file['new']) ? $file['new'] : FALSE;
|
||||
$file = file_load($file['fid']);
|
||||
|
||||
$ffp['#files'][] = array(
|
||||
'field' => (array) $file,
|
||||
'module' => $field['module'],
|
||||
'name' => $field['field_name'],
|
||||
'new' => $new || $file->timestamp == REQUEST_TIME,
|
||||
);
|
||||
|
||||
$ffp['#types'][$field['field_name']] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_batch_update().
|
||||
*/
|
||||
function file_filefield_paths_batch_update($instance, &$objects) {
|
||||
$query = new EntityFieldQuery();
|
||||
$result = $query->entityCondition('entity_type', $instance['entity_type'])
|
||||
->entityCondition('bundle', array($instance['bundle']))
|
||||
->fieldCondition($instance['field_name'])
|
||||
->execute();
|
||||
|
||||
$objects = array_keys($result[$instance['entity_type']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_update().
|
||||
*/
|
||||
function file_filefield_paths_update($oid, $instance) {
|
||||
$entity = current(entity_load($instance['entity_type'], array($oid)));
|
||||
|
||||
// Flag files for update.
|
||||
if (isset($entity->{$instance['field_name']})) {
|
||||
foreach ($entity->{$instance['field_name']} as &$language) {
|
||||
foreach ($language as &$file) {
|
||||
if (!is_array($file) || empty($file['uri'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file['new'] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process Entity.
|
||||
filefield_paths_entity_update($entity, $instance['entity_type']);
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* FileField Paths module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_field_settings().
|
||||
*/
|
||||
function filefield_paths_filefield_paths_field_settings() {
|
||||
return array(
|
||||
'file_path' => array(
|
||||
'title' => 'File path',
|
||||
'sql' => 'filepath',
|
||||
|
||||
'form' => array(
|
||||
'file_path' => array(
|
||||
'#maxlength' => 512,
|
||||
'#size' => 128,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'file_name' => array(
|
||||
'title' => 'File name',
|
||||
'sql' => 'filename',
|
||||
|
||||
'form' => array(
|
||||
'file_name' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('File name'),
|
||||
'#default_value' => '[file:ffp-name-only-original].[file:ffp-extension-original]',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_process_file().
|
||||
*/
|
||||
function filefield_paths_filefield_paths_process_file($new, &$file, $settings, &$entity, $type, &$update) {
|
||||
if ($new && !empty($file['field']['filename'])) {
|
||||
$field = field_info_field($file['name']);
|
||||
$token_data = array('file' => file_load($file['field']['fid']), $type => $entity);
|
||||
|
||||
// Process filename.
|
||||
$file['filename']['old'] = $file['field']['filename'];
|
||||
$file['filename']['new'] = !empty($settings['filename']['value'])
|
||||
? filefield_paths_process_string($settings['filename']['value'], $token_data, $settings['filename'])
|
||||
: $file['field']['filename'];
|
||||
|
||||
// Process filepath.
|
||||
$file['filepath']['old'] = $file['field']['uri'];
|
||||
$file['filepath']['new'] = "{$field['settings']['uri_scheme']}://" . filefield_paths_process_string($settings['filepath']['value'] . "/{$file['filename']['new']}", $token_data, $settings['filepath']);
|
||||
|
||||
// Finalize files if necessary.
|
||||
$dirname = dirname($file['filepath']['new']);
|
||||
if ($dirname != dirname($file['field']['uri']) || $file['filename']['new'] != $file['field']['filename']) {
|
||||
if (file_prepare_directory($dirname, FILE_CREATE_DIRECTORY) && file_move((object) $file['field'], $file['filepath']['new'])) {
|
||||
$update->entity = TRUE;
|
||||
|
||||
// Fix reference to old paths.
|
||||
$file['filepath']['new'] = str_replace($file['filename']['old'], $file['filename']['new'], $file['filepath']['new']);
|
||||
|
||||
// Process regular expression.
|
||||
_filefield_paths_replace_path($file['filepath']['old'], $file['filepath']['new'], $entity, $update);
|
||||
|
||||
// Store new filename in file Array
|
||||
$file['field']['filename'] = $file['filename']['new'];
|
||||
$file['field']['uri'] = $file['filepath']['new'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_cleanup().
|
||||
*/
|
||||
function filefield_paths_filefield_paths_cleanup($ffp, $name) {
|
||||
foreach ($ffp['#files'] as $file) {
|
||||
if (isset($file['filepath'])) {
|
||||
$scheme = file_uri_scheme($file['filepath']['old']);
|
||||
$paths = explode('/', str_replace("{$scheme}://", '', dirname($file['filepath']['old'])));
|
||||
while ($paths) {
|
||||
if (drupal_rmdir("{$scheme}://" . implode('/', $paths)) == TRUE) {
|
||||
array_pop($paths);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Image module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_form_alter().
|
||||
*/
|
||||
function image_filefield_paths_form_alter(&$form, &$ffp) {
|
||||
if (isset($form['#field']) && $form['#field']['type'] == 'image' && isset($form['instance']['settings']['file_directory'])) {
|
||||
$ffp[$form['#field']['field_name']] = array(
|
||||
'show' => TRUE,
|
||||
'type' => "{$form['instance']['entity_type']['#value']}::{$form['instance']['bundle']['#value']}",
|
||||
'form_path' => &$form['instance']["ffp_{$form['#field']['field_name']}"],
|
||||
'file_path_default' => $form['instance']['settings']['file_directory']['#default_value']
|
||||
);
|
||||
|
||||
// Create path settings fieldset
|
||||
$ffp[$form['#field']['field_name']]['form_path'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Image Path settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 1,
|
||||
);
|
||||
|
||||
$ffp[$form['#field']['field_name']]['form_path']['file_path'] = $form['instance']['settings']['file_directory'];
|
||||
$ffp[$form['#field']['field_name']]['form_path']['file_path']['#title'] = t('File path');
|
||||
$form['instance']['settings']['file_directory']['#access'] = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_form_submit().
|
||||
*/
|
||||
function image_filefield_paths_form_submit(&$form_state, &$ffp) {
|
||||
if (isset($form_state['values']['form_id']) && $form_state['values']['form_id'] == 'field_ui_field_edit_form') {
|
||||
$form_state['values']["ffp_{$form_state['values']['instance']['field_name']}"] = $form_state['values']['instance']["ffp_{$form_state['values']['instance']['field_name']}"];
|
||||
$ffp[$form_state['values']['instance']['field_name']] = array(
|
||||
'type' => "{$form_state['values']['instance']['entity_type']}::{$form_state['values']['instance']['bundle']}",
|
||||
);
|
||||
|
||||
$form_state['values']['instance']['settings']['file_directory'] = $form_state['values']["ffp_{$form_state['values']['instance']['field_name']}"]['file_path'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_get_fields().
|
||||
*/
|
||||
function image_filefield_paths_get_fields(&$entity, &$ffp) {
|
||||
if (is_object($entity)) {
|
||||
$fields = field_info_fields();
|
||||
foreach ($fields as $name => $field) {
|
||||
if ($field['type'] == 'image' && isset($entity->{$field['field_name']}) && is_array($entity->{$field['field_name']})) {
|
||||
foreach ($entity->{$field['field_name']} as $language) {
|
||||
foreach ($language as $file) {
|
||||
$new = isset($file['new']) ? $file['new'] : FALSE;
|
||||
$file = file_load($file['fid']);
|
||||
|
||||
$ffp['#files'][] = array(
|
||||
'field' => (array) $file,
|
||||
'module' => $field['module'],
|
||||
'name' => $field['field_name'],
|
||||
'new' => $new || $file->timestamp == REQUEST_TIME,
|
||||
);
|
||||
|
||||
$ffp['#types'][$field['field_name']] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_batch_update().
|
||||
*/
|
||||
function image_filefield_paths_batch_update($instance, &$objects) {
|
||||
$query = new EntityFieldQuery();
|
||||
$result = $query->entityCondition('entity_type', $instance['entity_type'])
|
||||
->entityCondition('bundle', array($instance['bundle']))
|
||||
->fieldCondition($instance['field_name'])
|
||||
->execute();
|
||||
|
||||
$objects = array_keys($result[$instance['entity_type']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_update().
|
||||
*/
|
||||
function image_filefield_paths_update($oid, $instance) {
|
||||
$entity = current(entity_load($instance['entity_type'], array($oid)));
|
||||
|
||||
// Flag files for update.
|
||||
if (isset($entity->{$instance['field_name']})) {
|
||||
foreach ($entity->{$instance['field_name']} as &$language) {
|
||||
foreach ($language as &$file) {
|
||||
if (!is_array($file) || empty($file['uri'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$file['new'] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process Entity.
|
||||
filefield_paths_entity_update($entity, $instance['entity_type']);
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Token module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_token_info().
|
||||
*/
|
||||
function filefield_paths_token_info() {
|
||||
$info['tokens']['file']['ffp-name-only'] = array(
|
||||
'name' => t("File name"),
|
||||
'description' => t("File name without extension."),
|
||||
);
|
||||
$info['tokens']['file']['ffp-name-only-original'] = array(
|
||||
'name' => t("File name - original"),
|
||||
'description' => t("File name without extension - original."),
|
||||
);
|
||||
$info['tokens']['file']['ffp-extension-original'] = array(
|
||||
'name' => t("File extension - original"),
|
||||
'description' => t("File extension - original."),
|
||||
);
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_tokens().
|
||||
*/
|
||||
function filefield_paths_tokens($type, $tokens, array $data = array(), array $options = array()) {
|
||||
$url_options = array('absolute' => TRUE);
|
||||
if (isset($language)) {
|
||||
$url_options['language'] = $language;
|
||||
}
|
||||
$sanitize = !empty($options['sanitize']);
|
||||
|
||||
$replacements = array();
|
||||
|
||||
if ($type == 'file' && !empty($data['file'])) {
|
||||
$file = $data['file'];
|
||||
|
||||
foreach ($tokens as $name => $original) {
|
||||
switch ($name) {
|
||||
case 'ffp-name-only':
|
||||
$info = pathinfo($file->filename);
|
||||
$replacements[$original] = $info['filename'];
|
||||
break;
|
||||
|
||||
case 'ffp-name-only-original':
|
||||
$info = pathinfo($file->origname);
|
||||
$replacements[$original] = $info['filename'];
|
||||
break;
|
||||
|
||||
case 'ffp-extension-original':
|
||||
$info = pathinfo($file->origname);
|
||||
$replacements[$original] = $info['extension'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $replacements;
|
||||
}
|
Reference in New Issue
Block a user