first import
This commit is contained in:
339
sites/all/modules/plup/LICENSE.txt
Normal file
339
sites/all/modules/plup/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.
|
BIN
sites/all/modules/plup/add.png
Normal file
BIN
sites/all/modules/plup/add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 830 B |
BIN
sites/all/modules/plup/cancel.png
Normal file
BIN
sites/all/modules/plup/cancel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
156
sites/all/modules/plup/plup.css
Normal file
156
sites/all/modules/plup/plup.css
Normal file
@@ -0,0 +1,156 @@
|
||||
.plup-list {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.plup-list {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
background-color: #f7f7f7;
|
||||
}
|
||||
|
||||
.plup-list li {
|
||||
margin: 3px 3px 3px 0;
|
||||
padding: 1px;
|
||||
float: left;
|
||||
font-size: 8pt;
|
||||
list-style: none;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.plupload.has-title .plup-list li,
|
||||
.plupload.has-alt .plup-list li {
|
||||
padding-bottom: 2em;
|
||||
}
|
||||
|
||||
.plupload.has-title.has-alt .plup-list li {
|
||||
padding-bottom: 4em;
|
||||
}
|
||||
|
||||
.plup-thumb-wrapper {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.plup-list li input.form-text {
|
||||
width: 90%;
|
||||
height: 1.1em;
|
||||
bottom: 0px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.plupload.has-title.has-alt .plup-list li input.form-text.plup-title {
|
||||
bottom: 1.7em;
|
||||
}
|
||||
|
||||
.plup-bar {
|
||||
background-color: #EEEEEE;
|
||||
height: 20px;
|
||||
padding: 5px 10px;
|
||||
}
|
||||
|
||||
.plup-progress {
|
||||
width: 60px;
|
||||
height: 10px;
|
||||
margin-right: 5px;
|
||||
margin-left: 40px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.plup-file-progressbar {
|
||||
width: 50px;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
.plup-select, .plup-upload, .plup-progress-value {
|
||||
display: block;
|
||||
width: 80px;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.plup-select, .plup-upload,
|
||||
.plup-remove-file, .plup-remove-item {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.plup-select > div, .plup-upload > div {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
background-repeat: no-repeat;
|
||||
display: inline-block;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.plup-select > div {
|
||||
background-image: url('add.png');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
margin-bottom: -2px;
|
||||
}
|
||||
|
||||
.plup-upload > div {
|
||||
background-image: url('upload.png');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
margin-bottom: -2px;
|
||||
}
|
||||
|
||||
.plup-files-done {
|
||||
display: block;
|
||||
width: 50px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.ui-progressbar-value {
|
||||
background-image: none;
|
||||
background-color: #78E567;
|
||||
}
|
||||
|
||||
.plup-remove-file,
|
||||
.plup-remove-item {
|
||||
display: block;
|
||||
background-image: url('cancel.png');
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
float: right;
|
||||
}
|
||||
|
||||
.plup-remove-item {
|
||||
opacity: 0.5;
|
||||
position: absolute;
|
||||
right: 5px;
|
||||
top: 5px;
|
||||
}
|
||||
|
||||
.plup-remove-item:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.plup-filelist {
|
||||
background-color: #f7f7f7;
|
||||
min-height: 50px;
|
||||
border-top: 1px solid #bbb;
|
||||
max-height: 400px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.plup-filelist table {
|
||||
margin: 0px;
|
||||
}
|
||||
|
||||
.plup-filelist table tbody {
|
||||
border-top: 0px;
|
||||
}
|
||||
|
||||
.plup-filelist tr:hover td {
|
||||
background-color: #fafafa;
|
||||
}
|
||||
|
||||
.plup-drag-info .drag-main {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.plup-drag-info .drag-more {
|
||||
font-size: 0.75em;
|
||||
}
|
9
sites/all/modules/plup/plup.info
Normal file
9
sites/all/modules/plup/plup.info
Normal file
@@ -0,0 +1,9 @@
|
||||
name = Plupload widget
|
||||
description = Provides multiple upload functionality.
|
||||
dependencies[] = libraries
|
||||
; Information added by drupal.org packaging script on 2012-07-04
|
||||
version = "7.x-1.0-alpha1+5-dev"
|
||||
core = "7.x"
|
||||
project = "plup"
|
||||
datestamp = "1341362315"
|
||||
|
217
sites/all/modules/plup/plup.js
Normal file
217
sites/all/modules/plup/plup.js
Normal file
@@ -0,0 +1,217 @@
|
||||
(function ($) {
|
||||
|
||||
// Bind removing of file to selector elements
|
||||
function plup_remove_item(selector) {
|
||||
$(selector).bind('click', function(event) {
|
||||
var parent = $(this).parent();
|
||||
var parentsParent = parent.parent();
|
||||
parent.remove();
|
||||
parentsParent.trigger('formUpdated');
|
||||
});
|
||||
}
|
||||
|
||||
// Bind resize effect on title and alt fields on focus
|
||||
function plup_resize_input(selector) {
|
||||
var w = $(selector).outerWidth();
|
||||
if (w < 300) {
|
||||
$(selector).bind('focus', function(event) {
|
||||
$(this).css('z-index', 10).animate({'width': '300px'}, 300);
|
||||
});
|
||||
$(selector).bind('blur', function(event) {
|
||||
$(this).removeAttr('style');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Drupal.behaviors.plup = {
|
||||
attach: function(context, settings) {
|
||||
|
||||
// Apply Plupload to each form element instance
|
||||
$.each(settings.plup, function(plupName, plupInstance) {
|
||||
var cid = plupInstance.container;
|
||||
var id = '#' + cid;
|
||||
|
||||
|
||||
// Apply setting only once
|
||||
$(id).once('plup', function() {
|
||||
/**
|
||||
* Initial tasks
|
||||
*/
|
||||
|
||||
$(id +' .plup-list').sortable(); // Activate sortable
|
||||
$(id +'-plup-upload').hide(); // Hide upload button
|
||||
var uploader = new plupload.Uploader(plupInstance); // Create Plupload instance
|
||||
plup_remove_item(id +' .plup-remove-item'); // Bind remove functionality on existing images
|
||||
plup_resize_input(id +' .plup-list > li > input.form-text'); // Bind resizing effect on existing inputs
|
||||
|
||||
|
||||
/**
|
||||
* Events
|
||||
*/
|
||||
|
||||
// Initialization
|
||||
uploader.bind('Init', function(up, params) {
|
||||
// Nothing to do, just reminder of the presence for this event
|
||||
});
|
||||
|
||||
|
||||
// Starting upload
|
||||
uploader.bind('Start', function(up, files) {
|
||||
// Nothing to do, just reminder of the presence for this event
|
||||
});
|
||||
|
||||
|
||||
// Upload process state
|
||||
uploader.bind('StateChanged', function(up) {
|
||||
if (up.state == 2) {
|
||||
$(id +' .plup-progress').progressbar(); // Activate progressbar
|
||||
}
|
||||
if (up.state == 1) {
|
||||
$(id +' .plup-progress').progressbar('destroy'); // Destroy progressbar
|
||||
$(id +'-plup-upload').hide(); // Hide upload button
|
||||
$(id +' .plup-drag-info').show(); // Show info
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// Files were added into queue(only CURRENTLY added files)
|
||||
uploader.bind('FilesAdded', function(up, files) {
|
||||
$(id +' .plup-drag-info').hide(); // Hide info
|
||||
$(id +'-plup-upload').show(); // Show upload button
|
||||
|
||||
// Put files visually into queue
|
||||
$.each(files, function(i, file) {
|
||||
$(id +'-plup-filelist table').append('<tr id="' + file.id + '">' +
|
||||
'<td class="plup-filelist-file">' + file.name + '</td>' +
|
||||
'<td class="plup-filelist-size">' + plupload.formatSize(file.size) + '</td>' +
|
||||
'<td class="plup-filelist-message"></td>' +
|
||||
'<td class="plup-filelist-remove"><a class="plup-remove-file"></a></td>' +
|
||||
'</tr>');
|
||||
|
||||
// Bind "remove" functionality to files added into queue
|
||||
$(id +' #' + file.id + ' .plup-filelist-remove > a').bind('click', function(event) {
|
||||
$('#' + file.id).remove();
|
||||
up.removeFile(file);
|
||||
});
|
||||
});
|
||||
|
||||
up.refresh(); // Refresh for flash or silverlight
|
||||
});
|
||||
|
||||
|
||||
// File was removed from queue
|
||||
// Doc states this ARE files but actually it IS a file
|
||||
uploader.bind('FilesRemoved', function(up, file) {
|
||||
// If there are not files in queue
|
||||
if (up.files.length == 0) {
|
||||
$(id +'-plup-upload').hide(); // Hide upload button
|
||||
$(id +' .plup-drag-info').show(); // Show info
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// File is being uploaded
|
||||
uploader.bind('UploadProgress', function(up, file) {
|
||||
// Refresh progressbar
|
||||
$(id +' .plup-progress').progressbar({value: uploader.total.percent});
|
||||
});
|
||||
|
||||
|
||||
// Error event
|
||||
uploader.bind('Error', function(up, err) {
|
||||
$(id +' #' + err.file.id + ' > .plup-filelist-message').append('<b>Error: ' + err.message + '</b>');
|
||||
up.refresh(); // Refresh for flash or silverlight
|
||||
});
|
||||
|
||||
|
||||
// Event after a file has been uploaded from queue
|
||||
uploader.bind('FileUploaded', function(up, file, response) {
|
||||
// Response is an object with response parameter so 2x response
|
||||
var fileSaved = $.parseJSON(response.response);
|
||||
var delta = $(id +' .plup-list li').length;
|
||||
var name = plupName +'[' + delta + ']';
|
||||
|
||||
// Plupload has weird error handling behavior so we have to check for errors here
|
||||
if (fileSaved.error_message) {
|
||||
$(id +' #' + file.id + ' > .plup-filelist-message').append('<b>Error: ' + fileSaved.error_message + '</b>');
|
||||
up.refresh(); // Refresh for flash or silverlight
|
||||
return;
|
||||
}
|
||||
|
||||
$(id +'-plup-filelist #' + file.id).remove(); // Remove uploaded file from queue
|
||||
var title_field = plupInstance.title_field ? '<input title="'+ Drupal.t('Title') +'" type="text" class="form-text plup-title" name="'+ name + '[title]" value="" />' : '';
|
||||
var alt_field = plupInstance.alt_field ? '<input title="'+ Drupal.t('Alternative text') +'" type="text" class="form-text plup-alt" name="'+ name + '[alt]" value="" />' : '';
|
||||
|
||||
// Add image thumbnail into list of uploaded items
|
||||
$(id +' .plup-list').append(
|
||||
'<li class="ui-state-default">' +
|
||||
'<div class="plup-thumb-wrapper"><img src="'+ plupInstance.image_style_path + file.target_name + '" title="'+ Drupal.checkPlain(file.target_name) +'" /></div>' +
|
||||
'<a class="plup-remove-item"></a>' +
|
||||
title_field +
|
||||
alt_field +
|
||||
'<input type="hidden" name="' + name + '[fid]" value="' + fileSaved.fid + '" />' +
|
||||
'<input type="hidden" name="' + name + '[weight]" value="' + delta + '" />' +
|
||||
'<input type="hidden" name="' + name + '[rename]" value="' + file.name +'" />' +
|
||||
'</li>');
|
||||
|
||||
// Bind remove functionality to uploaded file
|
||||
var new_element = $('input[name="'+ name +'[fid]"]');
|
||||
var remove_element = $(new_element).siblings('.plup-remove-item');
|
||||
plup_remove_item(remove_element);
|
||||
|
||||
// Bind resize effect to inputs of uploaded file
|
||||
var text_element = $(new_element).siblings('input.form-text');
|
||||
plup_resize_input(text_element);
|
||||
|
||||
// Tell Drupal that form has been updated
|
||||
new_element.trigger('formUpdated');
|
||||
});
|
||||
|
||||
|
||||
// All fields from queue has been uploaded
|
||||
uploader.bind('UploadComplete', function(up, files) {
|
||||
$(id +' .plup-list').sortable('refresh'); // Refresh sortable
|
||||
$(id +' .plup-drag-info').show(); // Show info
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Additional tasks
|
||||
*/
|
||||
|
||||
// Upload button functionality
|
||||
$('#'+ plupInstance.upload).click(function(e) {
|
||||
// Forbid uploading more than the allowed number of files, if set
|
||||
if (plupInstance.max_files > 0) {
|
||||
var uploaded = $(id +' .plup-list li').length;
|
||||
var selected = $(id +'-plup-filelist td.plup-filelist-file').length;
|
||||
var allowed = plupInstance.max_files - uploaded;
|
||||
if ((selected + uploaded) > plupInstance.max_files) {
|
||||
alert(Drupal.formatPlural(allowed, 'You can upload only 1 file.', 'You can upload only @count files.'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
uploader.start();
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
// Initialize Plupload
|
||||
uploader.init();
|
||||
|
||||
|
||||
// Change weight values for images when reordering using sortable
|
||||
$(id +' .plup-list').bind('sortupdate', function(event, ui) {
|
||||
$(this).find('li').each(function(index) {
|
||||
$(this).find('input[name$="[weight]"]').val(index);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
634
sites/all/modules/plup/plup.module
Normal file
634
sites/all/modules/plup/plup.module
Normal file
@@ -0,0 +1,634 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* _menu
|
||||
*/
|
||||
function plup_menu() {
|
||||
$items = array();
|
||||
|
||||
$items['plupload'] = array(
|
||||
'title' => 'Plupload upload page',
|
||||
'page callback' => 'plup_upload_page',
|
||||
'access callback' => 'plup_upload_access',
|
||||
'access arguments' => array('access content', 'allow plupload'),
|
||||
'type' => MENU_CALLBACK
|
||||
);
|
||||
|
||||
$items['plupload/%'] = array(
|
||||
'title' => 'Plupload upload page',
|
||||
'page callback' => 'plup_upload_page',
|
||||
'access callback' => 'plup_upload_access',
|
||||
'access arguments' => array('access content', 'allow plupload'),
|
||||
'type' => MENU_CALLBACK
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Verifies the token for this request.
|
||||
*/
|
||||
function plup_upload_access() {
|
||||
foreach(func_get_args() as $permission) {
|
||||
if (!user_access($permission)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return !empty($_REQUEST['plupload_token']) && drupal_valid_token($_REQUEST['plupload_token'], 'plupload-handle-uploads');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _permission
|
||||
*/
|
||||
function plup_permission() {
|
||||
return array(
|
||||
'allow plupload' => array(
|
||||
'title' => t('Allow Plupload'),
|
||||
'description' => t('Allow user to upload files via Plupload.'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _library
|
||||
*/
|
||||
function plup_library() {
|
||||
$module = drupal_get_path('module', 'plup');
|
||||
$plupload = libraries_get_path('plupload');
|
||||
|
||||
$lib['plupload'] = array(
|
||||
'title' => 'Plupload',
|
||||
'website' => 'http://www.plupload.com',
|
||||
'version' => '1.5.1.1',
|
||||
'js' => array(
|
||||
"$plupload/js/plupload.full.js" => array(),
|
||||
"$module/plup.js" => array(),
|
||||
),
|
||||
'css' => array(
|
||||
"$module/plup.css" => array(
|
||||
'type' => 'file',
|
||||
'media' => 'screen',
|
||||
),
|
||||
),
|
||||
'dependencies' => array(
|
||||
array('system', 'ui.progressbar'),
|
||||
array('system', 'ui.sortable')
|
||||
),
|
||||
);
|
||||
|
||||
return $lib;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _element_info
|
||||
*/
|
||||
function plup_element_info() {
|
||||
$plupload = libraries_get_path('plupload');
|
||||
|
||||
$types['plupload_file'] = array(
|
||||
'#input' => TRUE,
|
||||
'#title' => NULL,
|
||||
'#process' => array('plup_process_element'),
|
||||
'#value_callback' => 'plup_value_element',
|
||||
'#element_validate' => array('plup_validate_element'),
|
||||
'#pre_render' => array('plup_pre_render_element'),
|
||||
'#default_value' => NULL,
|
||||
'#required' => FALSE,
|
||||
'#autocomplete_path' => FALSE,
|
||||
'#theme_wrappers' => array('form_element'),
|
||||
'#theme' => 'plup_plupload',
|
||||
'#upload_location' => NULL,
|
||||
'#info' => array(),
|
||||
'#attached' => array(
|
||||
'library' => array(
|
||||
array('plup', 'plupload')
|
||||
)
|
||||
),
|
||||
'#plup' => array(
|
||||
'container' => NULL,
|
||||
'browse_button' => NULL,
|
||||
'upload' => NULL,
|
||||
'runtimes' => 'html5,gears,flash,silverlight,browserplus,html4',
|
||||
'max_file_size' => '512MB',
|
||||
'url' => url('plupload', array('query' => array('plupload_token' => drupal_get_token('plupload-handle-uploads')))),
|
||||
'filters' => array(),
|
||||
'chunk_size' => '512K',
|
||||
'unique_names' => TRUE,
|
||||
'flash_swf_url' => base_path() ."$plupload/js/plupload.flash.swf",
|
||||
'silverlight_xap_url' => base_path() ."$plupload/js/plupload.silverlight.xap",
|
||||
'drop_element' => NULL,
|
||||
'multipart' => FALSE,
|
||||
'dragdrop' => TRUE,
|
||||
'multiple_queues' => TRUE,
|
||||
'urlstream_upload' => FALSE,
|
||||
'image_style' => 'thumbnail',
|
||||
'image_style_path' => '',
|
||||
'max_files' => -1
|
||||
),
|
||||
'#plup_override' => array()
|
||||
);
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Value callback needed for removing all items.
|
||||
*/
|
||||
function plup_value_element(&$element, $input = FALSE, $form_state = NULL) {
|
||||
// Default state - no new data
|
||||
if ($input === FALSE) {
|
||||
return NULL;
|
||||
}
|
||||
// Field was emptied - user deleted all files
|
||||
if (is_null($input)) {
|
||||
return array(array('fid' => 0));
|
||||
}
|
||||
// Field has new data
|
||||
return $input;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process callback to set JS settings before Plupload init.
|
||||
*/
|
||||
function plup_process_element($element, &$form_state, $form) {
|
||||
$element['#default_value'] = isset($element['#value']) ? $element['#value'] : $element['#default_value'];
|
||||
|
||||
$element['#plup']['container'] = $element['#id'];
|
||||
$element['#plup']['browse_button'] = $element['#id'] .'-plup-select';
|
||||
$element['#plup']['upload'] = $element['#id'] .'-plup-upload';
|
||||
$element['#plup']['drop_element'] = $element['#id'] .'-plup-filelist';
|
||||
|
||||
$element['#plup']['name'] = $element['#name'];
|
||||
$element['#plup'] = array_merge($element['#plup'], $element['#plup_override']);
|
||||
$files = variable_get('file_public_path', 'sites/default/files');
|
||||
$element['#plup']['image_style_path'] = base_path() . $files .'/styles/'. $element['#plup']['image_style'] .'/temporary/';
|
||||
$element['#attached']['js'][] = array(
|
||||
'data' => array('plup' => array($element['#name'] => $element['#plup'])),
|
||||
'type' => 'setting',
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pre-render callback to load existing items.
|
||||
*/
|
||||
function plup_pre_render_element($element) {
|
||||
if (isset($element['#default_value']) && !empty($element['#default_value'])) {
|
||||
foreach ($element['#default_value'] AS $delta => $item) {
|
||||
$element['#default_value'][$delta] = array_merge($item, (array) file_load($item['fid']));
|
||||
}
|
||||
}
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Element validation callback.
|
||||
*/
|
||||
function plup_validate_element($element, &$form_state, $form) {
|
||||
$item = reset($element['#value']);
|
||||
if ($element['#required'] == TRUE && $item['fid'] == 0 && count($element['#value']) == 1) {
|
||||
form_error($element, t("@field field is required.", array('@field' => $element['#title'])));
|
||||
}
|
||||
|
||||
$cardinality = isset($element['#plup_override']['max_files']) ? $element['#plup_override']['max_files'] : $element['#plup']['max_files'];
|
||||
if ($cardinality > 0 && count($element['#value']) > $cardinality) {
|
||||
form_error($element, t("Only !num items are allowed.", array('!num' => $cardinality)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _theme
|
||||
*/
|
||||
function plup_theme() {
|
||||
return array(
|
||||
'plup_plupload' => array(
|
||||
'render element' => 'element',
|
||||
),
|
||||
'plup_items' => array(
|
||||
'render element' => 'element'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Theme Plupload widget.
|
||||
*/
|
||||
function theme_plup_plupload($variables) {
|
||||
$element = $variables['element'];
|
||||
|
||||
$attributes = array();
|
||||
if (isset($element['#id'])) {
|
||||
$attributes['id'] = $element['#id'];
|
||||
}
|
||||
if (!empty($element['#attributes']['class'])) {
|
||||
$attributes['class'] = (array) $element['#attributes']['class'];
|
||||
}
|
||||
$attributes['class'][] = 'plupload';
|
||||
|
||||
$hasTitle = (bool) (isset($element['#plup_override']['title_field']) && $element['#plup_override']['title_field'] == 1);
|
||||
$hasAlt = (bool) (isset($element['#plup_override']['alt_field']) && $element['#plup_override']['alt_field'] == 1);
|
||||
if ($hasTitle) {
|
||||
$attributes['class'][] = 'has-title';
|
||||
}
|
||||
if ($hasAlt) {
|
||||
$attributes['class'][] = 'has-alt';
|
||||
}
|
||||
|
||||
$output = '<div' . drupal_attributes($attributes) . '>';
|
||||
$output .= '<div id="'. $element['#id'] .'-plupload-container" class="plupload-container">';
|
||||
$output .= '<div class="plup-list-wrapper"><ul class="plup-list clearfix">';
|
||||
$output .= theme('plup_items', array('element' => $element));
|
||||
$output .= '</ul></div>';
|
||||
$output .= '<div id="'. $element['#id'] .'-plup-filelist" class="plup-filelist"><table><tr class="plup-drag-info"><td><div class="drag-main">'. t('Drag files here') .'</div><div class="drag-more">'. implode("\n", $element['#info']) .'</div></td></tr></table></div>';
|
||||
$output .= '<div class="plup-bar clearfix">';
|
||||
$output .= '<a id="'. $element['#id'] .'-plup-select" class="plup-select"><div></div>'. t('Add') .'</a>';
|
||||
$output .= '<a id="'. $element['#id'] .'-plup-upload" class="plup-upload"><div></div>'. t('Upload') .'</a>';
|
||||
$output .= '<div class="plup-progress"></div>';
|
||||
$output .= '</div>';
|
||||
$output .= '</div>';
|
||||
|
||||
$output .= '</div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Theme Plupload items within widget.
|
||||
*/
|
||||
function theme_plup_items($vars) {
|
||||
$element = &$vars['element'];
|
||||
if (isset($element['#default_value']) && !empty($element['#default_value'])) {
|
||||
$items = &$element['#default_value'];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
$output = '';
|
||||
foreach ($items AS $delta => $item) {
|
||||
// If user deleted all items I'll get array('fid' => 0)
|
||||
if ($item['fid'] > 0) {
|
||||
$hasTitle = (bool) (isset($element['#plup_override']['title_field']) && $element['#plup_override']['title_field'] == 1);
|
||||
$hasAlt = (bool) (isset($element['#plup_override']['alt_field']) && $element['#plup_override']['alt_field'] == 1);
|
||||
$name = $element['#name'] .'['. $delta .']';
|
||||
$output .= '<li class="ui-state-default">';
|
||||
$output .= '<div class="plup-thumb-wrapper">'. theme('image_style', array('style_name' => $element['#plup']['image_style'], 'path' => $item['uri'], 'title' => $item['filename'])) .'</div>';
|
||||
$output .= '<a class="plup-remove-item"></a>';
|
||||
if ($hasTitle) {
|
||||
$output .= '<input title="'. t('Title') .'" type="text" class="form-text plup-title" name="'. $name .'[title]" value="'. $item['title'] .'" />';
|
||||
}
|
||||
if ($hasAlt) {
|
||||
$output .= '<input title="'. t('Alternative text') .'" type="text" class="form-text plup-alt" name="'. $name .'[alt]" value="'. $item['alt'] .'" />';
|
||||
}
|
||||
$output .= '<input type="hidden" name="'. $name .'[fid]" value="'. $item['fid'] .'" />';
|
||||
$output .= '<input type="hidden" name="'. $name .'[weight]" value="'. $delta .'" />';
|
||||
if (isset($item['rename'])) {
|
||||
$output .= '<input type="hidden" name="'. $name .'[rename]" value="'. $item['rename'] .'" />';
|
||||
}
|
||||
$output .= '</li>';
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plupload's upload function.
|
||||
*/
|
||||
function plup_upload_page() {
|
||||
drupal_add_http_header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT', TRUE);
|
||||
drupal_add_http_header('Last-Modified', gmdate("D, d M Y H:i:s") . ' GMT', TRUE);
|
||||
drupal_add_http_header('Cache-Control', 'no-store, no-cache, must-revalidate post-check=0, pre-check=0', TRUE);
|
||||
drupal_add_http_header('Pragma', 'no-cache', TRUE);
|
||||
|
||||
// Settings
|
||||
$targetDir = $GLOBALS['conf']['file_temporary_path'] .'/';
|
||||
// 5 minutes execution time
|
||||
@set_time_limit(5 * 60);
|
||||
// Uncomment this one to fake upload time
|
||||
// usleep(5000);
|
||||
|
||||
// Get parameters
|
||||
$chunk = isset($_REQUEST['chunk']) ? $_REQUEST['chunk'] : 0;
|
||||
$chunks = isset($_REQUEST['chunks']) ? $_REQUEST['chunks'] : 0;
|
||||
$filename = isset($_REQUEST['name']) ? $_REQUEST['name'] : '';
|
||||
|
||||
// Clean the fileName for security reasons
|
||||
$extensions = 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp';
|
||||
$filename = file_munge_filename($filename, $extensions, FALSE);
|
||||
|
||||
// Make sure the fileName is unique but only if chunking is disabled
|
||||
if ($chunks < 2 && file_exists($targetDir . DIRECTORY_SEPARATOR . $filename)) {
|
||||
$ext = strrpos($filename, '.');
|
||||
$filename_a = substr($filename, 0, $ext);
|
||||
$filename_b = substr($filename, $ext);
|
||||
|
||||
$count = 1;
|
||||
while (file_exists($targetDir . DIRECTORY_SEPARATOR . $filename_a . '_' . $count . $filename_b))
|
||||
$count++;
|
||||
|
||||
$filename = $filename_a . '_' . $count . $filename_b;
|
||||
}
|
||||
|
||||
|
||||
// Look for the content type header
|
||||
if (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
|
||||
$contentType = $_SERVER['HTTP_CONTENT_TYPE'];
|
||||
}
|
||||
|
||||
if (isset($_SERVER['CONTENT_TYPE'])) {
|
||||
$contentType = $_SERVER['CONTENT_TYPE'];
|
||||
}
|
||||
|
||||
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5
|
||||
if (strpos($contentType, 'multipart') !== false) {
|
||||
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
|
||||
// Open temp file
|
||||
$out = fopen($targetDir . DIRECTORY_SEPARATOR . $filename, $chunk == 0 ? 'wb' : 'ab');
|
||||
if ($out) {
|
||||
// Read binary input stream and append it to temp file
|
||||
$in = fopen($_FILES['file']['tmp_name'], 'rb');
|
||||
|
||||
if ($in) {
|
||||
while ($buff = fread($in, 4096))
|
||||
fwrite($out, $buff);
|
||||
} else {
|
||||
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
||||
}
|
||||
|
||||
fclose($in);
|
||||
fclose($out);
|
||||
@unlink($_FILES['file']['tmp_name']);
|
||||
} else {
|
||||
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
||||
}
|
||||
} else {
|
||||
die('{"jsonrpc" : "2.0", "error" : {"code": 103, "message": "Failed to move uploaded file."}, "id" : "id"}');
|
||||
}
|
||||
} else {
|
||||
// Open temp file
|
||||
$out = fopen($targetDir . DIRECTORY_SEPARATOR . $filename, $chunk == 0 ? 'wb' : 'ab');
|
||||
if ($out) {
|
||||
// Read binary input stream and append it to temp file
|
||||
$in = fopen("php://input", 'rb');
|
||||
|
||||
if ($in) {
|
||||
while ($buff = fread($in, 4096)) {
|
||||
fwrite($out, $buff);
|
||||
}
|
||||
} else {
|
||||
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "Failed to open input stream."}, "id" : "id"}');
|
||||
}
|
||||
|
||||
fclose($in);
|
||||
fclose($out);
|
||||
} else {
|
||||
die('{"jsonrpc" : "2.0", "error" : {"code": 102, "message": "Failed to open output stream."}, "id" : "id"}');
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($_GET['chunk']) && ($_GET['chunk'] + 1) == $_GET['chunks']) || (!isset($_GET['chunk']))) {
|
||||
$source = 'temporary://'. $filename;
|
||||
$file = new stdClass();
|
||||
$file->uid = $GLOBALS['user']->uid;
|
||||
$file->status = 0;
|
||||
$file->filename = $filename;
|
||||
$file->uri = $source;
|
||||
$file->filemime = file_get_mimetype($file->filename);
|
||||
$file->filesize = filesize($source);
|
||||
// Save url argument(instance_id) so we can validate file by instance settings
|
||||
$file->arg = arg(1);
|
||||
|
||||
$e = FALSE;
|
||||
// Here we validate file
|
||||
drupal_alter('plup_file_validation', $file, $e);
|
||||
|
||||
if ($e === FALSE) {
|
||||
$return = file_save($file);
|
||||
} else {
|
||||
file_unmanaged_delete($file->uri);
|
||||
$return = (object) array('error_message' => $e);
|
||||
}
|
||||
|
||||
drupal_json_output($return);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default validation function.
|
||||
* In most cases Pluplaod will be used for images so we use image-specific validation.
|
||||
* Non-image files has no support right now.
|
||||
*/
|
||||
function plup_plup_file_validation_alter(&$file, &$e) {
|
||||
if (!isset($file->arg) || (isset($file->arg) && is_numeric($file->arg))) {
|
||||
$instance = db_select('field_config_instance','i')->fields('i', array('data'))->condition('id', $file->arg)->execute()->fetchField();
|
||||
$instance = unserialize($instance);
|
||||
$settings = $instance['settings'];
|
||||
|
||||
// Check if file is image
|
||||
$passImage = file_validate_is_image($file);
|
||||
if (!empty($passImage)) {
|
||||
$e = reset($passImage);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if file has allowed extension
|
||||
$passExt = file_validate_extensions($file, $settings['file_extensions']);
|
||||
if (!empty($passExt)) {
|
||||
$e = reset($passExt);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if file doesn't exceed the maximal allowed size
|
||||
$passSize = file_validate_size($file, parse_size($settings['max_filesize']), 0);
|
||||
if (!empty($passSize)) {
|
||||
$e = reset($passSize);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if file name isn't too long
|
||||
$passLength = file_validate_name_length($file);
|
||||
if (!empty($passLength)) {
|
||||
$e = reset($passLength);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if file meet the resolution restrictions
|
||||
$passRes = file_validate_image_resolution($file, $settings['max_resolution'], $settings['min_resolution']);
|
||||
if (!empty($passRes)) {
|
||||
$e = reset($passRes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************
|
||||
* FIELD WIDGET
|
||||
********************************************/
|
||||
|
||||
/**
|
||||
* _field_widget_info
|
||||
*/
|
||||
function plup_field_widget_info() {
|
||||
return array(
|
||||
'image_plupload' => array(
|
||||
'label' => t('Plupload'),
|
||||
'field types' => array('image'),
|
||||
'behaviors' => array(
|
||||
'multiple values' => FIELD_BEHAVIOR_CUSTOM,
|
||||
'default value' => FIELD_BEHAVIOR_NONE,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _field_widget_settings_form
|
||||
*/
|
||||
function plup_field_widget_settings_form($field, $instance) {
|
||||
$styles = array();
|
||||
foreach (image_styles() as $name => $style) {
|
||||
$styles[$name] = $style['name'];
|
||||
}
|
||||
|
||||
$form['image_style'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Image style'),
|
||||
'#default_value' => isset($instance['widget']['settings']['image_style']) ? $instance['widget']['settings']['image_style'] : 'thumbnail',
|
||||
'#options' => $styles
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _field_widget_form
|
||||
*/
|
||||
function plup_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
$parents = array_merge(array('values', $element['#field_name'], $element['#language']), $element['#field_parents']);
|
||||
$state_data = drupal_array_get_nested_value($form_state, $parents);
|
||||
|
||||
if (isset($state_data)) {
|
||||
$default_values = $state_data;
|
||||
} else if (isset($items)) {
|
||||
$default_values = $items;
|
||||
} else {
|
||||
$default_values = array();
|
||||
}
|
||||
|
||||
// We inform user about restrictions
|
||||
$info = array();
|
||||
if ($field['cardinality'] > 0) {
|
||||
$info[] = '<div>'. t("You can upload up to !num files.", array('!num' => '<strong>'. $field['cardinality'] .'</strong>')) .'</div>';
|
||||
}
|
||||
if (isset($instance['settings']['max_filesize']) && !empty($instance['settings']['max_filesize'])) {
|
||||
$info[] = '<div>'. t("Maximal file size: !size", array('!size' => '<strong>'. $instance['settings']['max_filesize'] .'</strong>')) .'</div>';
|
||||
}
|
||||
$info[] = '<div>'. t("Allowed files types: !types.", array('!types' => '<strong>'. $instance['settings']['file_extensions'] .'</strong>')) .'</div>';
|
||||
$max = $instance['settings']['max_resolution'];
|
||||
$min = $instance['settings']['min_resolution'];
|
||||
if ($min && $max && $min == $max) {
|
||||
$info[] = '<div>'. t('Images must be exactly !size pixels.', array('!size' => '<strong>' . $max . '</strong>')) .'</div>';
|
||||
}
|
||||
elseif ($min && $max) {
|
||||
$info[] = '<div>'. t('Images must be between !min and !max pixels.', array('!min' => '<strong>' . $min . '</strong>', '!max' => '<strong>' . $max . '</strong>')) .'</div>';
|
||||
}
|
||||
elseif ($min) {
|
||||
$info[] = '<div>'. t('Images must be larger than !min pixels.', array('!min' => '<strong>' . $min . '</strong>')) .'</div>';
|
||||
}
|
||||
elseif ($max) {
|
||||
$info[] = '<div>'. t('Images must be smaller than !max pixels.', array('!max' => '<strong>' . $max . '</strong>')) .'</div>';
|
||||
}
|
||||
|
||||
|
||||
$images = array(
|
||||
'#type' => 'plupload_file',
|
||||
'#default_value' => $default_values,
|
||||
'#info' => $info
|
||||
);
|
||||
|
||||
// Allowed file types(extensions) needs to be set here
|
||||
$ext = new stdClass();
|
||||
$ext->title = 'Allowed extensions'; // This won't show up anywhere so no t()
|
||||
$ext->extensions = (isset($instance['settings']['file_extensions']) && !empty($instance['settings']['file_extensions'])) ? strtr($instance['settings']['file_extensions'], ' ', ',') : 'jpg,png,gif';
|
||||
$images['#plup_override']['filters'] = array($ext);
|
||||
// Maximal file size
|
||||
if (isset($instance['settings']['max_filesize']) && !empty($instance['settings']['max_filesize'])) {
|
||||
$images['#plup_override']['max_file_size'] = $instance['settings']['max_filesize'];
|
||||
}
|
||||
// URL callback for Plupload library has to be altered so we can get instance ID for later validation
|
||||
$images['#plup_override']['url'] = url('plupload/'. $instance['id'], array('query' => array('plupload_token' => drupal_get_token('plupload-handle-uploads'))));
|
||||
// We set image style to present uploaded images in Plupload widget
|
||||
$images['#plup_override']['image_style'] = isset($instance['widget']['settings']['image_style']) ? $instance['widget']['settings']['image_style'] : 'thumbnail';
|
||||
// We set if we want to enable title and alt fields for images
|
||||
$images['#plup_override']['alt_field'] = (int) $instance['settings']['alt_field'];
|
||||
$images['#plup_override']['title_field'] = (int) $instance['settings']['title_field'];
|
||||
// We set the maximum files user can upload
|
||||
$images['#plup_override']['max_files'] = (int) $field['cardinality'];
|
||||
|
||||
$element += $images;
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _field_attach_presave
|
||||
* Somehow Drupal 7 doesn't have proper field hooks so we have to use
|
||||
* this big global hook so we can move files to their desiganted folder
|
||||
* because image module won't pick on #upload_location attribute(don't know why yet).
|
||||
* We also rename files back to their original name.
|
||||
*/
|
||||
function plup_field_attach_presave($entity_type, $entity) {
|
||||
$entityInfo = entity_get_info($entity_type);
|
||||
$bundleKey = (isset($entityInfo['entity keys']['bundle']) && !empty($entityInfo['entity keys']['bundle'])) ? $entityInfo['entity keys']['bundle'] : $entity_type;
|
||||
$bundle = isset($entity->{$bundleKey}) ? $entity->{$bundleKey} : $entity_type;
|
||||
$instances = field_info_instances();
|
||||
$entityFields = $instances[$entity_type][$bundle];
|
||||
|
||||
if (!is_array($entityFields) || empty($entityFields)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($entityFields AS $field_name => $instance) {
|
||||
if ($instance['widget']['type'] == 'image_plupload' && $instance['widget']['module'] == 'plup') {
|
||||
$items = field_get_items($entity_type, $entity, $field_name);
|
||||
if ($items && $items[0]['fid'] > 0) {
|
||||
$field = field_info_field($instance['field_name']);
|
||||
$destination = file_field_widget_uri($field, $instance);
|
||||
foreach ($items AS $delta => $item) {
|
||||
$file = file_load($item['fid']);
|
||||
// Filefield paths integration
|
||||
if (module_exists('filefield_paths') && isset($item['rename'])) {
|
||||
$file->origname = $item['rename'];
|
||||
file_save($file);
|
||||
} else {
|
||||
$fileName = isset($item['rename']) ? $item['rename'] : $file->filename;
|
||||
$dir = isset($instance['settings']['file_directory']) ? $instance['settings']['file_directory'] .'/' : '';
|
||||
$location = token_replace($field['settings']['uri_scheme'] .'://'. $dir);
|
||||
$filePath = $location . $fileName;
|
||||
if ($file->uri !== $filePath) {
|
||||
file_prepare_directory($location, FILE_CREATE_DIRECTORY);
|
||||
file_move($file, $filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
sites/all/modules/plup/upload.png
Normal file
BIN
sites/all/modules/plup/upload.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1022 B |
Reference in New Issue
Block a user