first import
This commit is contained in:
40
sites/all/modules/filefield_paths/CHANGELOG.txt
Normal file
40
sites/all/modules/filefield_paths/CHANGELOG.txt
Normal file
@@ -0,0 +1,40 @@
|
||||
File (Field) Paths 7.x-1.x-dev, xxxx-xx-xx (development release)
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- #1429238 by ocanzillon: Fixed Drush command syntax error.
|
||||
- #1334448 by pianodavid, Deciphered: Fixed issue with revision flag.
|
||||
- Changed a large chunk of core functionality to simplify.
|
||||
|
||||
|
||||
File (Field) Paths 7.x-1.0-beta2, 2012-02-05
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- #1414090: Added Drush command for Retroactive updates.
|
||||
- #1335984: Removed debug code.
|
||||
- #1051736: Fixed issue with dirname().
|
||||
- Added support for URI Scheme changes via Updating.
|
||||
- Added support for Video module.
|
||||
|
||||
|
||||
File (Field) Paths 7.x-1.0-beta1, 2011-11-08
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
- #1328064: Fixed/Re-enabled Retroactive updates.
|
||||
- #1326094: Fixed coder issues.
|
||||
- #1308532: Fixed issue with empty tokens not being cleared.
|
||||
- #1278004: Fixed issue with New flag.
|
||||
- #1253168: Added more space for 'type' and 'field' columns.
|
||||
- #1233004 by maximpodorov: Fixed Pathauto integration.
|
||||
- #1225764 by joelstein, h0tw1r3: Fixed references in text fields not being
|
||||
updated.
|
||||
- #1225752 by joelstein: Removed packaging script information.
|
||||
- #1211038 by pillarsdotnet: Fixed issue with 'active_updating' field.
|
||||
- #1188074 by h0tw1r3: Fixed issue with schema change.
|
||||
- #1017830: Fixed issue with Transliteration support.
|
||||
- #578442 by szantog, mfb, deciphered: Added features support.
|
||||
- Added relevant tokens for Entity support.
|
||||
- Added Entity support.
|
||||
|
||||
|
||||
File (Field) Paths 7.x-1.0-alpha1, 2011-06-12
|
||||
--------------------------------------------------------------------------------
|
339
sites/all/modules/filefield_paths/LICENSE.txt
Normal file
339
sites/all/modules/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.
|
87
sites/all/modules/filefield_paths/README.txt
Normal file
87
sites/all/modules/filefield_paths/README.txt
Normal file
@@ -0,0 +1,87 @@
|
||||
The File (Field) Paths module extends the default functionality of Drupals core
|
||||
File module, Image module and many other File upload modules, by adding the
|
||||
ability to use entity based tokens in destination paths and filenames.
|
||||
|
||||
In simple terms, File (Field) Paths allows you to automatically sort and rename
|
||||
your uploaded files using token based replacement patterns to maintain a nice
|
||||
clean filesystem.
|
||||
|
||||
File (Field) Paths was written and is maintained by Stuart Clark (deciphered).
|
||||
- http://stuar.tc/lark
|
||||
- http://twitter.com/Decipher
|
||||
|
||||
|
||||
Features
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
* Configurable file paths now use entity tokens in addition to user tokens.
|
||||
* Configurable filenames.
|
||||
* Support for:
|
||||
* Drupal core File module.
|
||||
* Drupal core Image module.
|
||||
* Video module.
|
||||
* File path and filename cleanup options:
|
||||
* Filter out words and punctuation by taking advantage of the Pathauto module.
|
||||
* Convert unicode characters into US-ASCII with the Transliteration module.
|
||||
* Automatically updates unprocessed file paths in any Text fields on the entity.
|
||||
* Retroactive updates - rename and/or move previously uploaded files (Use with
|
||||
caution)
|
||||
|
||||
|
||||
Required Modules
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
* Token - http://drupal.org/project/token
|
||||
|
||||
|
||||
Recommended Modules
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
* Pathauto - http://drupal.org/project/pathauto
|
||||
* Transliteration - http://drupal.org/project/transliteration
|
||||
|
||||
|
||||
Usage/Configuration
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Once installed, File (Field) Paths needs to be configured for each file field
|
||||
you wish to use.
|
||||
|
||||
* Drupal core File/Image and other Field based supported modules
|
||||
Settings an be found on the fields configuration page.
|
||||
|
||||
Example:
|
||||
Administration > Structure > Content types > Article > Manage fields > Image
|
||||
http://[www.yoursite.com/path/to/drupal]/admin/structure/types/manage/article/fields/field_image
|
||||
|
||||
|
||||
|
||||
Frequently Asked Questions
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
Q. Aren't tokens already supported in the File module?
|
||||
|
||||
A. A limited selection of tokens are supported in the File module.
|
||||
|
||||
Entity based tokens allow you to use the Entity ID, Title, creation date and
|
||||
much more in your directory/filenames where you would otherwise be unable.
|
||||
|
||||
|
||||
Q. Why aren't my files in the correct folder?
|
||||
|
||||
A. When you are creating or updating an entity the full values for the tokens
|
||||
may not yet be known by Drupal, so the File (Field) Paths module will upload
|
||||
your files to the Fields old file path temporarily and then once you save the
|
||||
entity and Drupal is provided with the tokens values the file will be moved
|
||||
to the appropriate location.
|
||||
|
||||
|
||||
Q. Why is there a warning on the 'Retroactive updates' feature?
|
||||
|
||||
A. Retroactive updates will go through every single entity of the particular
|
||||
bundle and move and/or rename the files.
|
||||
|
||||
While there have been no reports of errors caused by the feature, it is quite
|
||||
possible that the moving/renaming of these files could break links. It is
|
||||
strongly advised that you only use this functionality on your developmental
|
||||
servers so that you can make sure not to introduce any linking issues.
|
25
sites/all/modules/filefield_paths/filefield_paths.info
Normal file
25
sites/all/modules/filefield_paths/filefield_paths.info
Normal file
@@ -0,0 +1,25 @@
|
||||
name = File (Field) 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/features.inc
|
||||
files[] = modules/file.inc
|
||||
files[] = modules/filefield_paths.drush.inc
|
||||
files[] = modules/filefield_paths.inc
|
||||
files[] = modules/image.inc
|
||||
files[] = modules/token.inc
|
||||
files[] = modules/video.inc
|
||||
|
||||
;files[] = tests/filefield_paths.test
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-07
|
||||
version = "7.x-1.0-beta3"
|
||||
core = "7.x"
|
||||
project = "filefield_paths"
|
||||
datestamp = "1328655041"
|
||||
|
191
sites/all/modules/filefield_paths/filefield_paths.install
Normal file
191
sites/all/modules/filefield_paths/filefield_paths.install
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the File (Field) Paths module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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' => ''
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed filefield_paths table/schema.
|
||||
*/
|
||||
function filefield_paths_update_7107() {
|
||||
// Remove filefield_paths table/schema.
|
||||
db_drop_table('filefield_paths');
|
||||
|
||||
// Update field instance settings.
|
||||
$field_types = array_keys(_filefield_paths_get_field_types());
|
||||
foreach (field_info_fields() as $field) {
|
||||
if (in_array($field['type'], $field_types)) {
|
||||
foreach ($field['bundles'] as $entity_type => $bundles) {
|
||||
foreach ($bundles as $bundle_name) {
|
||||
$instance = field_info_instance($entity_type, $field['field_name'], $bundle_name);
|
||||
if ($instance["ffp_{$field['field_name']}"] && !isset($instance['settings']['filefield_paths'])) {
|
||||
$instance['settings']['filefield_paths'] = array(
|
||||
'file_path' => array(
|
||||
'value' => $instance["ffp_{$field['field_name']}"]['file_path'],
|
||||
'options' => array(
|
||||
'pathauto' => $instance["ffp_{$field['field_name']}"]['file_path_cleanup']['file_path_pathauto'],
|
||||
'transliterate' => $instance["ffp_{$field['field_name']}"]['file_path_cleanup']['file_path_transliterate'],
|
||||
),
|
||||
),
|
||||
'file_name' => array(
|
||||
'value' => $instance["ffp_{$field['field_name']}"]['file_name'],
|
||||
'options' => array(
|
||||
'pathauto' => $instance["ffp_{$field['field_name']}"]['file_name_cleanup']['file_name_pathauto'],
|
||||
'transliterate' => $instance["ffp_{$field['field_name']}"]['file_name_cleanup']['file_name_transliterate'],
|
||||
),
|
||||
),
|
||||
'retroactive_update' => $instance["ffp_{$field['field_name']}"]['retroactive_update'],
|
||||
'active_updating' => $instance["ffp_{$field['field_name']}"]['active_updating'],
|
||||
);
|
||||
unset($instance["ffp_{$field['field_name']}"]);
|
||||
field_update_instance($instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
383
sites/all/modules/filefield_paths/filefield_paths.module
Normal file
383
sites/all/modules/filefield_paths/filefield_paths.module
Normal file
@@ -0,0 +1,383 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Contains core functions for the File (Field) 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) {
|
||||
$field_types = _filefield_paths_get_field_types();
|
||||
if (isset($form['#field']) && in_array($form['#field']['type'], array_keys($field_types))) {
|
||||
$entity_info = entity_get_info($form['#instance']['entity_type']);
|
||||
$settings = isset($form['#instance']['settings']['filefield_paths']) ? $form['#instance']['settings']['filefield_paths'] : array();
|
||||
|
||||
// Hide standard File directory field.
|
||||
$form['instance']['settings']['file_directory']['#access'] = FALSE;
|
||||
|
||||
// File (Field) Paths fieldset element.
|
||||
$form['instance']['settings']['filefield_paths'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('File (Field) Path settings'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 1,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
// Additional File (Field) Paths widget fields.
|
||||
$fields = module_invoke_all('filefield_paths_field_settings');
|
||||
foreach ($fields as $name => $field) {
|
||||
// Attach widget fields.
|
||||
$form['instance']['settings']['filefield_paths'][$name] = array(
|
||||
'#type' => 'container',
|
||||
);
|
||||
|
||||
// Attach widget field form elements.
|
||||
if (isset($field['form']) && is_array($field['form'])) {
|
||||
foreach (array_keys($field['form']) as $delta => $key) {
|
||||
$form['instance']['settings']['filefield_paths'][$name][$key] = array_merge(
|
||||
$field['form'][$key],
|
||||
array(
|
||||
'#element_validate' => array('token_element_validate'),
|
||||
'#token_types' => array('file', $entity_info['token type']),
|
||||
)
|
||||
);
|
||||
|
||||
// Fetch stored value from instance.
|
||||
if (isset($settings[$name][$key])) {
|
||||
$form['instance']['settings']['filefield_paths'][$name][$key]['#default_value'] = $settings[$name][$key];
|
||||
}
|
||||
}
|
||||
|
||||
// Field options.
|
||||
$form['instance']['settings']['filefield_paths'][$name]['options'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('@title options', array('@title' => $field['title'])),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#weight' => 1,
|
||||
'#attributes' => array(
|
||||
'class' => array("{$name} cleanup")
|
||||
),
|
||||
);
|
||||
// @TODO - Make this more modular.
|
||||
// Cleanup field with Pathauto module.
|
||||
$form['instance']['settings']['filefield_paths'][$name]['options']['pathauto'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Cleanup using Pathauto') . '.',
|
||||
'#default_value' => isset($settings[$name]['options']['pathauto']) && module_exists('pathauto')
|
||||
? $settings[$name]['options']['pathauto']
|
||||
: FALSE,
|
||||
'#description' => t('Cleanup @title using', array('@title' => $field['title'])) . ' ' . l(t('Pathauto settings'), 'admin/config/search/path/settings'),
|
||||
'#disabled' => !module_exists('pathauto'),
|
||||
);
|
||||
|
||||
// Transliterate field with Transliteration module.
|
||||
$form['instance']['settings']['filefield_paths'][$name]['options']['transliterate'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Transliterate') . '.',
|
||||
'#default_value' => isset($settings[$name]['options']['transliterate']) && module_exists('transliteration')
|
||||
? $settings[$name]['options']['transliterate']
|
||||
: 0,
|
||||
'#description' => t('Transliterate @title', array('@title' => $field['title'])) . '.',
|
||||
'#disabled' => !module_exists('transliteration'),
|
||||
);
|
||||
|
||||
// Replacement patterns for field.
|
||||
$form['instance']['settings']['filefield_paths']['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.
|
||||
$form['instance']['settings']['filefield_paths']['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.
|
||||
$form['instance']['settings']['filefield_paths']['active_updating'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Active updating'),
|
||||
'#default_value' => isset($settings['active_updating']) ? $settings['active_updating'] : FALSE,
|
||||
'#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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$form['#submit'][] = 'filefield_paths_form_submit';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit callback for File (Field) Paths settings form.
|
||||
*/
|
||||
function filefield_paths_form_submit($form, &$form_state) {
|
||||
// Retroactive updates.
|
||||
if ($form_state['values']['instance']['settings']['filefield_paths']['retroactive_update']) {
|
||||
filefield_paths_batch_update($form_state['values']['instance']);
|
||||
batch_process($form_state['redirect']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set batch process to update File (Field) Paths.
|
||||
*
|
||||
* @param $instance
|
||||
*/
|
||||
function filefield_paths_batch_update($instance) {
|
||||
$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']]);
|
||||
|
||||
// Create batch.
|
||||
$batch = array(
|
||||
'title' => t('Updating File (Field) 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']);
|
||||
$entity = current(entity_load($instance['entity_type'], array($oid)));
|
||||
|
||||
// Enable active updating if it isn't already enabled.
|
||||
$active_updating = $instance['settings']['filefield_paths']['active_updating'];
|
||||
if (!$active_updating) {
|
||||
$instance['settings']['filefield_paths']['active_updating'] = TRUE;
|
||||
field_update_instance($instance);
|
||||
}
|
||||
|
||||
// Invoke File (Field) Paths implementation of hook_entity_update().
|
||||
filefield_paths_entity_update($entity, $instance['entity_type']);
|
||||
|
||||
// Restore active updating to it's previous state if necessary.
|
||||
if (!$active_updating) {
|
||||
$instance['settings']['filefield_paths']['active_updating'] = $active_updating;
|
||||
field_update_instance($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) {
|
||||
$field_types = _filefield_paths_get_field_types();
|
||||
$entity_info = entity_get_info($type);
|
||||
$bundle_name = !empty($entity_info['entity keys']['bundle']) ? $entity->{$entity_info['entity keys']['bundle']} : $type;
|
||||
if ($entity_info['fieldable']) {
|
||||
foreach (field_info_fields($type, $bundle_name) as $field) {
|
||||
if (in_array($field['type'], array_keys($field_types))) {
|
||||
$files = array();
|
||||
$instance = field_info_instance($type, $field['field_name'], $bundle_name);
|
||||
if (isset($entity->{$field['field_name']})) {
|
||||
foreach ($entity->{$field['field_name']} as $langcode => &$deltas) {
|
||||
foreach ($deltas as $delta => &$file) {
|
||||
// Prepare file.
|
||||
if (function_exists($function = "{$field['module']}_field_load")) {
|
||||
$items = array(array(&$file));
|
||||
$function($type, array($entity), $field, array($instance), $langcode, $items, FIELD_LOAD_CURRENT);
|
||||
}
|
||||
$files[] = &$file;
|
||||
}
|
||||
}
|
||||
// Invoke hook_filefield_paths_process_file().
|
||||
foreach (module_implements('filefield_paths_process_file') as $module) {
|
||||
if (function_exists($function = "{$module}_filefield_paths_process_file")) {
|
||||
$function($type, $entity, $field, $instance, $langcode, $files);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($entity->revision)) {
|
||||
// Remember revision flag.
|
||||
$revision = $entity->revision;
|
||||
// Remove revision flag as long as fields already processed it, and no need
|
||||
// to create new revision for moved files.
|
||||
$entity->revision = FALSE;
|
||||
}
|
||||
// Save any changes back to the database.
|
||||
field_attach_update($type, $entity);
|
||||
if (isset($entity->revision)) {
|
||||
// Restore revision flag so that other modules can process it if needed.
|
||||
$entity->revision = $revision;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_file_presave().
|
||||
*/
|
||||
function filefield_paths_file_presave($file) {
|
||||
// Store original filename in the database.
|
||||
if (empty($file->origname)) {
|
||||
$file->origname = $file->filename;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run regular expression over all available text-based fields.
|
||||
*/
|
||||
function _filefield_paths_replace_path($old, $new, $entity) {
|
||||
// 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);
|
||||
$info['path'] = !empty($info['path']) ? $info['path'] : '';
|
||||
$replacement = "_filefield_paths_replace_path_uri_scheme('\\1', '{$old}', '{$new}') . '\\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/e", $replacement, $item['value']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for File (Field) Paths URI updater regular expression.
|
||||
*
|
||||
* Determines what format the old URI prefix was and returns the new URI prefix
|
||||
* in the same format.
|
||||
*/
|
||||
function _filefield_paths_replace_path_uri_scheme($prefix, $old, $new) {
|
||||
switch (TRUE) {
|
||||
case $prefix == file_uri_scheme($old) . '://':
|
||||
return file_uri_scheme($new) . '://';
|
||||
|
||||
case $prefix == file_create_url(file_uri_scheme($old) . '://'):
|
||||
return file_create_url(file_uri_scheme($new) . '://');
|
||||
|
||||
case $prefix == parse_url(file_create_url(file_uri_scheme($old) . '://'), PHP_URL_PATH):
|
||||
return parse_url(file_create_url(file_uri_scheme($new) . '://'), PHP_URL_PATH);
|
||||
}
|
||||
|
||||
return $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
// Ensure that there are no double-slash sequences due to empty token values.
|
||||
$value = preg_replace('/\/+/', '/', $value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function _filefield_paths_get_field_types($reset = FALSE) {
|
||||
$field_types = &drupal_static(__FUNCTION__);
|
||||
|
||||
if (empty($field_types) || $reset) {
|
||||
$field_types = module_invoke_all('filefield_paths_field_type_info');
|
||||
$field_types = array_flip($field_types);
|
||||
foreach (array_keys($field_types) as $type) {
|
||||
$info = field_info_field_types($type);
|
||||
$field_types[$type] = array(
|
||||
'label' => $info['label']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $field_types;
|
||||
}
|
21
sites/all/modules/filefield_paths/modules/features.inc
Normal file
21
sites/all/modules/filefield_paths/modules/features.inc
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Features module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_features_pipe_field_alter().
|
||||
*
|
||||
* This determines whether exported fields contain File (Field) Paths settings
|
||||
* and if so adds File (Field) Paths as a dependency.
|
||||
*/
|
||||
function filefield_paths_features_pipe_field_alter(&$pipe, $data, &$export) {
|
||||
foreach ($data as $field_identifier) {
|
||||
list($entity_type, $bundle_name, $field_name) = explode('-', $field_identifier);
|
||||
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
if (isset($instance['settings']['filefield_paths'])) {
|
||||
$export['dependencies']['filefield_paths'] = 'filefield_paths';
|
||||
}
|
||||
}
|
||||
}
|
12
sites/all/modules/filefield_paths/modules/file.inc
Normal file
12
sites/all/modules/filefield_paths/modules/file.inc
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* File module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_filed_type_info() on behalf of file.module.
|
||||
*/
|
||||
function file_filefield_paths_field_type_info() {
|
||||
return array('file');
|
||||
}
|
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Drush integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_drush_command().
|
||||
*/
|
||||
function filefield_paths_drush_command() {
|
||||
$items = array();
|
||||
|
||||
$items['ffp-update'] = array(
|
||||
'description' => 'Retroactively updates all File (Field) Paths of a chosen field instance.',
|
||||
'arguments' => array(
|
||||
'entity_type' => 'Entity type.',
|
||||
'bundle_name' => 'Bundle name.',
|
||||
'field_name' => 'Field name.'
|
||||
),
|
||||
'options' => array(
|
||||
'all' => 'Retroactively update all File (Field) Paths.',
|
||||
),
|
||||
'examples' => array(
|
||||
'drush ffp-update' => 'Retroactively updates the File (Field) Paths of the instances choosen via an interactive menu.',
|
||||
'drush ffp-update node article field_image' => 'Retroactively updates the File (Field) Paths of all instances of the Article content types Image field.',
|
||||
'drush ffp-update --all' => 'Retroactively update all File (Field) Paths.',
|
||||
),
|
||||
'aliases' => array('ffpu'),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retroactively updates all File (Field) Paths of a chosen field instance.
|
||||
*/
|
||||
function drush_filefield_paths_ffp_update($entity_type = NULL, $bundle_name = NULL, $field_name = NULL) {
|
||||
// Build array of information of all entity types, bundle names and field
|
||||
// names.
|
||||
$field_types = array_keys(_filefield_paths_get_field_types());
|
||||
$info = array();
|
||||
foreach (field_info_fields() as $field) {
|
||||
if (in_array($field['type'], $field_types)) {
|
||||
foreach ($field['bundles'] as $entity_type_name => $bundles) {
|
||||
if (!isset($info[$entity_type_name])) {
|
||||
$entity_type_info = entity_get_info($entity_type_name);
|
||||
$info[$entity_type_name] = array(
|
||||
'#label' => "{$entity_type_info['label']} ({$entity_type_name})",
|
||||
);
|
||||
}
|
||||
$bundles_info = field_info_bundles($entity_type_name);
|
||||
foreach ($bundles as $bundle) {
|
||||
if (!isset($info[$entity_type_name][$bundle])) {
|
||||
$info[$entity_type_name][$bundle] = array(
|
||||
'#label' => "{$bundles_info[$bundle]['label']} ({$bundle})",
|
||||
);
|
||||
}
|
||||
$field = field_info_instance($entity_type_name, $field['field_name'], $bundle);
|
||||
$info[$entity_type_name][$bundle][$field['field_name']] = "{$field['label']} ({$field['field_name']})";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (drush_get_option('all')) {
|
||||
$instances = array();
|
||||
foreach ($info as $entity_type => $bundles) {
|
||||
foreach (element_children($bundles) as $bundle_name) {
|
||||
foreach (element_children($info[$entity_type][$bundle_name]) as $field_name) {
|
||||
$instances[] = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
_filefield_paths_drush_ffp_update($instances);
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get entity type.
|
||||
if (empty($entity_type)) {
|
||||
$choices = array('all' => dt('All'));
|
||||
foreach ($info as $entity_type => $entity_type_info) {
|
||||
$choices[$entity_type] = $entity_type_info['#label'];
|
||||
}
|
||||
$entity_type = drush_choice($choices, dt("Choose an Entity type."));
|
||||
}
|
||||
if (empty($entity_type)) {
|
||||
return '';
|
||||
}
|
||||
if ($entity_type == 'all') {
|
||||
$instances = array();
|
||||
foreach ($info as $entity_type => $bundles) {
|
||||
foreach (element_children($bundles) as $bundle_name) {
|
||||
foreach (element_children($info[$entity_type][$bundle_name]) as $field_name) {
|
||||
$instances[] = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
_filefield_paths_drush_ffp_update($instances);
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get bundle.
|
||||
if (empty($bundle_name)) {
|
||||
$choices = array('all' => dt('All'));
|
||||
foreach (element_children($info[$entity_type]) as $bundle_name) {
|
||||
$choices[$bundle_name] = $info[$entity_type][$bundle_name]['#label'];
|
||||
}
|
||||
$bundle_name = drush_choice($choices, dt("Choose a Bundle."));
|
||||
}
|
||||
if (empty($bundle_name)) {
|
||||
return '';
|
||||
}
|
||||
if ($bundle_name == 'all') {
|
||||
$instances = array();
|
||||
foreach (element_children($info[$entity_type]) as $bundle_name) {
|
||||
foreach (element_children($info[$entity_type][$bundle_name]) as $field_name) {
|
||||
$instances[] = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
}
|
||||
}
|
||||
_filefield_paths_drush_ffp_update($instances);
|
||||
return '';
|
||||
}
|
||||
|
||||
// Get field.
|
||||
if (empty($field_name)) {
|
||||
$choices = array('all' => dt('All'));
|
||||
foreach (element_children($info[$entity_type][$bundle_name]) as $field_name) {
|
||||
$choices[$field_name] = $info[$entity_type][$bundle_name][$field_name];
|
||||
}
|
||||
$field_name = drush_choice($choices, dt("Choose a Field."));
|
||||
}
|
||||
if (empty($field_name)) {
|
||||
return '';
|
||||
}
|
||||
if ($field_name == 'all') {
|
||||
$instances = array();
|
||||
foreach (element_children($info[$entity_type][$bundle_name]) as $field_name) {
|
||||
$instances[] = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
}
|
||||
_filefield_paths_drush_ffp_update($instances);
|
||||
return '';
|
||||
}
|
||||
|
||||
// Invoke Retroactive update.
|
||||
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
|
||||
_filefield_paths_drush_ffp_update(array($instance));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function; Invokes File (Field) Paths Retroactive updates.
|
||||
*/
|
||||
function _filefield_paths_drush_ffp_update($instances) {
|
||||
foreach ($instances as $instance) {
|
||||
filefield_paths_batch_update($instance);
|
||||
$batch =& batch_get();
|
||||
$batch['progressive'] = FALSE;
|
||||
drush_backend_batch_process();
|
||||
drush_log(dt('!field_name File (Field) Paths updated.', array('!field_name' => "{$instance['label']} ({$instance['entity_type']}-{$instance['bundle']}-{$instance['field_name']})")), 'success');
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* File (Field) 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(
|
||||
'value' => array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('File path'),
|
||||
'#maxlength' => 512,
|
||||
'#size' => 128,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
'file_name' => array(
|
||||
'title' => 'File name',
|
||||
'sql' => 'filename',
|
||||
|
||||
'form' => array(
|
||||
'value' => 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($type, $entity, $field, $instance, $langcode, &$items) {
|
||||
$settings = $instance['settings']['filefield_paths'];
|
||||
foreach ($items as &$file) {
|
||||
if ($file['timestamp'] == REQUEST_TIME || $settings['active_updating']) {
|
||||
$token_data = array(
|
||||
'file' => (object) $file,
|
||||
$type => $entity
|
||||
);
|
||||
|
||||
// Copy the original file for comparision purposes.
|
||||
$old_file = $file;
|
||||
|
||||
// Process filename.
|
||||
$file['filename'] = !empty($settings['file_name']['value'])
|
||||
? filefield_paths_process_string($settings['file_name']['value'], $token_data, $settings['file_name']['options'])
|
||||
: $file['filename'];
|
||||
|
||||
// Process filepath.
|
||||
$file['uri'] = "{$field['settings']['uri_scheme']}://" . filefield_paths_process_string($settings['file_path']['value'] . "/{$file['filename']}", $token_data, $settings['file_path']['options']);
|
||||
|
||||
// Finalize file if necessary.
|
||||
if ($file !== $old_file) {
|
||||
if (file_prepare_directory(drupal_dirname($file['uri']), FILE_CREATE_DIRECTORY) && file_move((object) $old_file, $file['uri'])) {
|
||||
// Process regular expression.
|
||||
_filefield_paths_replace_path($old_file['uri'], $file['uri'], $entity);
|
||||
|
||||
// Remove any old empty directories.
|
||||
$scheme = file_uri_scheme($old_file['uri']);
|
||||
$paths = explode('/', str_replace("{$scheme}://", '', drupal_dirname($old_file['uri'])));
|
||||
while ($paths) {
|
||||
if (@drupal_rmdir("{$scheme}://" . implode('/', $paths)) == TRUE) {
|
||||
array_pop($paths);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
sites/all/modules/filefield_paths/modules/image.inc
Normal file
12
sites/all/modules/filefield_paths/modules/image.inc
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Image module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_field_type_info() on behalf of image.module.
|
||||
*/
|
||||
function image_filefield_paths_field_type_info() {
|
||||
return array('image');
|
||||
}
|
63
sites/all/modules/filefield_paths/modules/token.inc
Normal file
63
sites/all/modules/filefield_paths/modules/token.inc
Normal file
@@ -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;
|
||||
}
|
12
sites/all/modules/filefield_paths/modules/video.inc
Normal file
12
sites/all/modules/filefield_paths/modules/video.inc
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Video module integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_filefield_paths_field_type_info() on behalf of video.module.
|
||||
*/
|
||||
function video_filefield_paths_field_type_info() {
|
||||
return array('video');
|
||||
}
|
Reference in New Issue
Block a user