FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/mail/mailsystem/LICENSE.txt
Normal file
339
sites/all/modules/contrib/mail/mailsystem/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.
|
113
sites/all/modules/contrib/mail/mailsystem/README.html
Normal file
113
sites/all/modules/contrib/mail/mailsystem/README.html
Normal file
@@ -0,0 +1,113 @@
|
||||
<h2 id="mail-system"><a href="http://drupal.org/project/mailsystem">Mail System</a></h2>
|
||||
<p>Provides an Administrative UI and Developers API for safely updating the <a href="http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7">mail_system</a> configuration variable.</p>
|
||||
<h3 id="administrative-ui">Administrative UI</h3>
|
||||
<p>The administrative interface is at <code>admin/config/system/mailsystem</code>. A <a href="http://drupal.org/node/1134044">screenshot</a> is available.</p>
|
||||
<h3 id="used-by">Used by:</h3>
|
||||
<ul>
|
||||
<li><a href="http://drupal.org/project/htmlmail">HTML Mail</a></li>
|
||||
<li><a href="http://drupal.org/project/mimemail">Mime Mail 7.x-1.x-dev</a></li>
|
||||
<li><a href="http://drupal.org/project/postmark">Postmark 7.x-1.x</a></li>
|
||||
</ul>
|
||||
<h3 id="developers-api">Developers API</h3>
|
||||
<p>A module <code>example</code> with a <a href="http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7"><code>MailSystemInterface</code></a> implementation called <code>ExampleMailSystem</code> should add the following in its <code>example.install</code> file:</p>
|
||||
<pre>
|
||||
<code>/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example' => 'ExampleMailSystem'));
|
||||
}
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example' => 'ExampleMailSystem'));
|
||||
}
|
||||
</code>
|
||||
</pre>
|
||||
<p>The above settings allow mail sent by <code>example</code> to use <code>ExampleMailSystem</code>. To make <code>ExampleMailSystem</code> the site-wide default for sending mail:</p>
|
||||
<pre>
|
||||
<code>mailsystem_set(array(mailsystem_default_id() => 'ExampleMailSystem'));
|
||||
</code>
|
||||
</pre>
|
||||
<p>To restore the default mail system:</p>
|
||||
<pre>
|
||||
<code>mailsystem_set(array(mailsystem_default_id() => mailsystem_default_value()));
|
||||
</code>
|
||||
</pre>
|
||||
<p>Or simply:</p>
|
||||
<pre>
|
||||
<code>mailsystem_set(mailsystem_defaults());
|
||||
</code>
|
||||
</pre>
|
||||
<p>If module <code>example</code> relies on dependency <code>foo</code> and its <code>FooMailSystem</code> class, then the <code>example.install</code> code should like like this:</p>
|
||||
<pre>
|
||||
<code>/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example' => 'FooMailSystem'));
|
||||
}
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example' => ''));
|
||||
}
|
||||
</code>
|
||||
</pre>
|
||||
<p>If module <code>example</code> only wants to use <code>FooMailSystem</code> when sending emails with a key of <code>examail</code>, then the <code>example.install</code> code should look like this:</p>
|
||||
<pre>
|
||||
<code>/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example_examail' => 'FooMailSystem'));
|
||||
}
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example_examail' => ''));
|
||||
}
|
||||
</code>
|
||||
</pre>
|
||||
<h4 id="new-in-2.x-branch"><em>(New in 2.x branch)</em></h4>
|
||||
<p>To change the site-wide defaults to use the <code>FooMailSystem</code> for formatting messages and the <code>BarMailSystem</code> for sending them:</p>
|
||||
<pre>
|
||||
<code>mailsystem_set(
|
||||
array(
|
||||
mailsystem_default_id() => array(
|
||||
'format' => 'FooMailSystem',
|
||||
'mail' => 'BarMailSystem',
|
||||
),
|
||||
)
|
||||
);
|
||||
</code>
|
||||
</pre>
|
||||
<p>To change the site-wide defaults to use the <code>FooMailSystem</code> for sending messages, while continuing to use the current system for formatting them:</p>
|
||||
<pre>
|
||||
<code>mailsystem_set(
|
||||
array(
|
||||
mailsystem_default_id() => array(
|
||||
'mail' => 'FooMailsystem',
|
||||
),
|
||||
)
|
||||
);
|
||||
</code>
|
||||
</pre>
|
||||
<h3 id="references">References</h3>
|
||||
<dl>
|
||||
<dt><strong><a href="http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7"><code>drupal_mail_system()</code> API documentation</a></strong>:</dt>
|
||||
<dd>
|
||||
<p><a href="http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7">api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7</a></p>
|
||||
</dd>
|
||||
<dt><strong><a href="http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7"><code>MailSystemInterface</code> API documentation</a></strong>:</dt>
|
||||
<dd>
|
||||
<p><a href="http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7">api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7</a></p>
|
||||
</dd>
|
||||
<dt><strong><a href="http://drupal.org/node/900794">Creating HTML formatted mails in Drupal 7</a></strong>:</dt>
|
||||
<dd>
|
||||
<p><a href="http://drupal.org/node/900794">drupal.org/node/900794</a></p>
|
||||
</dd>
|
||||
</dl>
|
118
sites/all/modules/contrib/mail/mailsystem/README.markdown
Normal file
118
sites/all/modules/contrib/mail/mailsystem/README.markdown
Normal file
@@ -0,0 +1,118 @@
|
||||
## [Mail System](http://drupal.org/project/mailsystem)
|
||||
|
||||
Provides an Administrative UI and Developers API for safely updating the
|
||||
[mail_system](http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7)
|
||||
configuration variable.
|
||||
|
||||
### Administrative UI
|
||||
|
||||
The administrative interface is at `admin/config/system/mailsystem`.
|
||||
A [screenshot](http://drupal.org/node/1134044) is available.
|
||||
|
||||
### Used by:
|
||||
|
||||
* [HTML Mail](http://drupal.org/project/htmlmail)
|
||||
* [Mime Mail 7.x-1.x-dev](http://drupal.org/project/mimemail)
|
||||
* [Postmark 7.x-1.x](http://drupal.org/project/postmark)
|
||||
|
||||
### Developers API
|
||||
|
||||
A module `example` with a
|
||||
[`MailSystemInterface`](http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7)
|
||||
implementation called `ExampleMailSystem` should add the following in its
|
||||
`example.install` file:
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example' =\> 'ExampleMailSystem'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example' =\> 'ExampleMailSystem'));
|
||||
}
|
||||
|
||||
The above settings allow mail sent by `example` to use `ExampleMailSystem`. To make
|
||||
`ExampleMailSystem` the site-wide default for sending mail:
|
||||
|
||||
mailsystem_set(array(mailsystem_default_id() =\> 'ExampleMailSystem'));
|
||||
|
||||
To restore the default mail system:
|
||||
|
||||
mailsystem_set(array(mailsystem_default_id() =\> mailsystem_default_value()));
|
||||
|
||||
Or simply:
|
||||
|
||||
mailsystem_set(mailsystem_defaults());
|
||||
|
||||
If module `example` relies on dependency `foo` and its `FooMailSystem` class, then
|
||||
the `example.install` code should like like this:
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example' =\> 'FooMailSystem'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example' =\> ''));
|
||||
}
|
||||
|
||||
If module `example` only wants to use `FooMailSystem` when sending emails with a key
|
||||
of `examail`, then the `example.install` code should look like this:
|
||||
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example_examail' =\> 'FooMailSystem'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example_examail' =\> ''));
|
||||
}
|
||||
|
||||
#### *(New in 2.x branch)*
|
||||
|
||||
To change the site-wide defaults to use the `FooMailSystem` for formatting messages and the `BarMailSystem` for sending them:
|
||||
|
||||
mailsystem_set(
|
||||
array(
|
||||
mailsystem_default_id() => array(
|
||||
'format' => 'FooMailSystem',
|
||||
'mail' => 'BarMailSystem',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
To change the site-wide defaults to use the `FooMailSystem` for sending messages, while continuing to use the current system for formatting them:
|
||||
|
||||
mailsystem_set(
|
||||
array(
|
||||
mailsystem_default_id() => array(
|
||||
'mail' => 'FooMailsystem',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
### References
|
||||
|
||||
**[`drupal_mail_system()` API documentation](http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7)**:
|
||||
: [api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7](http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7)
|
||||
|
||||
**[`MailSystemInterface` API documentation](http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7)**:
|
||||
: [api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7](http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7)
|
||||
|
||||
**[Creating HTML formatted mails in Drupal 7](http://drupal.org/node/900794)**:
|
||||
: [drupal.org/node/900794](http://drupal.org/node/900794)
|
134
sites/all/modules/contrib/mail/mailsystem/README.txt
Normal file
134
sites/all/modules/contrib/mail/mailsystem/README.txt
Normal file
@@ -0,0 +1,134 @@
|
||||
[1]Mail System
|
||||
|
||||
Provides an Administrative UI and Developers API for safely updating
|
||||
the [2]mail_system configuration variable.
|
||||
|
||||
Administrative UI
|
||||
|
||||
The administrative interface is at admin/config/system/mailsystem. A
|
||||
[3]screenshot is available.
|
||||
|
||||
Used by:
|
||||
|
||||
* [4]HTML Mail
|
||||
* [5]Mime Mail 7.x-1.x-dev
|
||||
* [6]Postmark 7.x-1.x
|
||||
|
||||
Developers API
|
||||
|
||||
A module example with a [7]MailSystemInterface implementation called
|
||||
ExampleMailSystem should add the following in its example.install file:
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example' => 'ExampleMailSystem'));
|
||||
}
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example' => 'ExampleMailSystem'));
|
||||
}
|
||||
|
||||
|
||||
The above settings allow mail sent by example to use ExampleMailSystem.
|
||||
To make ExampleMailSystem the site-wide default for sending mail:
|
||||
mailsystem_set(array(mailsystem_default_id() => 'ExampleMailSystem'));
|
||||
|
||||
|
||||
To restore the default mail system:
|
||||
mailsystem_set(array(mailsystem_default_id() => mailsystem_default_value()));
|
||||
|
||||
|
||||
Or simply:
|
||||
mailsystem_set(mailsystem_defaults());
|
||||
|
||||
|
||||
If module example relies on dependency foo and its FooMailSystem class,
|
||||
then the example.install code should like like this:
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example' => 'FooMailSystem'));
|
||||
}
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example' => ''));
|
||||
}
|
||||
|
||||
|
||||
If module example only wants to use FooMailSystem when sending emails
|
||||
with a key of examail, then the example.install code should look like
|
||||
this:
|
||||
/**
|
||||
* Implements hook_enable().
|
||||
*/
|
||||
function example_enable() {
|
||||
mailsystem_set(array('example_examail' => 'FooMailSystem'));
|
||||
}
|
||||
/**
|
||||
* Implements hook_disable().
|
||||
*/
|
||||
function example_disable() {
|
||||
mailsystem_clear(array('example_examail' => ''));
|
||||
}
|
||||
|
||||
|
||||
(New in 2.x branch)
|
||||
|
||||
To change the site-wide defaults to use the FooMailSystem for
|
||||
formatting messages and the BarMailSystem for sending them:
|
||||
mailsystem_set(
|
||||
array(
|
||||
mailsystem_default_id() => array(
|
||||
'format' => 'FooMailSystem',
|
||||
'mail' => 'BarMailSystem',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
To change the site-wide defaults to use the FooMailSystem for sending
|
||||
messages, while continuing to use the current system for formatting
|
||||
them:
|
||||
mailsystem_set(
|
||||
array(
|
||||
mailsystem_default_id() => array(
|
||||
'mail' => 'FooMailsystem',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
References
|
||||
|
||||
[8]drupal_mail_system() API documentation:
|
||||
[9]api.drupal.org/api/drupal/includes--mail.inc/function/drupal_
|
||||
mail_system/7
|
||||
|
||||
[10]MailSystemInterface API documentation:
|
||||
[11]api.drupal.org/api/drupal/includes--mail.inc/interface/MailS
|
||||
ystemInterface/7
|
||||
|
||||
[12]Creating HTML formatted mails in Drupal 7:
|
||||
[13]drupal.org/node/900794
|
||||
|
||||
References
|
||||
|
||||
1. http://drupal.org/project/mailsystem
|
||||
2. http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7
|
||||
3. http://drupal.org/node/1134044
|
||||
4. http://drupal.org/project/htmlmail
|
||||
5. http://drupal.org/project/mimemail
|
||||
6. http://drupal.org/project/postmark
|
||||
7. http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7
|
||||
8. http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7
|
||||
9. http://api.drupal.org/api/drupal/includes--mail.inc/function/drupal_mail_system/7
|
||||
10. http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7
|
||||
11. http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7
|
||||
12. http://drupal.org/node/900794
|
||||
13. http://drupal.org/node/900794
|
742
sites/all/modules/contrib/mail/mailsystem/html_to_text.inc
Normal file
742
sites/all/modules/contrib/mail/mailsystem/html_to_text.inc
Normal file
@@ -0,0 +1,742 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Copy of drupal_html_to_text improvements from issue #299138.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Perform format=flowed soft wrapping for mail (RFC 3676).
|
||||
*
|
||||
* We use delsp=yes wrapping, but only break non-spaced languages when
|
||||
* absolutely necessary to avoid compatibility issues.
|
||||
*
|
||||
* We deliberately use variable_get('mail_line_endings', MAIL_LINE_ENDINGS)
|
||||
* rather than "\r\n".
|
||||
*
|
||||
* @param $text
|
||||
* The plain text to process.
|
||||
* @param array $options
|
||||
* (optional) An array containing one or more of the following keys:
|
||||
* - indent: A string to indent the text with. Only '>' characters are
|
||||
* repeated on subsequent wrapped lines. Others are replaced by spaces.
|
||||
* - max: The maximum length at which to wrap each line. Defaults to 80.
|
||||
* - stuff: Whether to space-stuff special lines. Defaults to TRUE.
|
||||
* - hard: Whether to enforce the maximum line length even if no convenient
|
||||
* space character is available. Defaults to FALSE.
|
||||
* - pad: A string to use for padding short lines to 'max' characters. If
|
||||
* more than one character, only the last will be repeated.
|
||||
* - break: The line break sequence to insert. The default is one of the
|
||||
* following:
|
||||
* - "\r\n": Windows, when $text does not contain a space character.
|
||||
* - "\n": Non-Windows, when $text does not contain a space character.
|
||||
* - " \r\n": On Windows, when $text contains at least one space.
|
||||
* - " \n": Non-Windows, when $text contains at least one space.
|
||||
*
|
||||
* @see drupal_mail()
|
||||
*/
|
||||
function mailsystem_wrap_mail($text, array $options = array()) {
|
||||
static $defaults;
|
||||
if (!isset($defaults)) {
|
||||
$defaults = array(
|
||||
'indent' => '',
|
||||
'pad' => '',
|
||||
'pad_repeat' => '',
|
||||
'max' => 80,
|
||||
'stuff' => TRUE,
|
||||
'hard' => FALSE,
|
||||
'eol' => variable_get('mail_line_endings', MAIL_LINE_ENDINGS),
|
||||
);
|
||||
}
|
||||
$options += $defaults;
|
||||
if (!isset($options['break'])) {
|
||||
// Allow soft-wrap spaces only when $text contains at least one space.
|
||||
$options['break'] = (strpos($text, ' ') === FALSE ? '' : ' ') . $defaults['eol'];
|
||||
}
|
||||
$options['wrap'] = $options['max'] - drupal_strlen($options['indent']);
|
||||
if ($options['pad']) {
|
||||
$options['pad_repeat'] = drupal_substr($options['pad'], -1, 1);
|
||||
}
|
||||
// The 'clean' indent is applied to all lines after the first one.
|
||||
$options['clean'] = _mailsystem_html_to_text_clean($options['indent']);
|
||||
// Wrap lines according to RFC 3676.
|
||||
$lines = explode($defaults['eol'], $text);
|
||||
array_walk($lines, '_mailsystem_wrap_mail_line', $options);
|
||||
// Expand the lines array on newly-inserted line breaks.
|
||||
$lines = explode($defaults['eol'], implode($defaults['eol'], $lines));
|
||||
// Apply indentation, space-stuffing, and padding.
|
||||
array_walk($lines, '_mailsystem_indent_mail_line', $options);
|
||||
return implode($defaults['eol'], $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an HTML string into plain text, preserving the structure of the
|
||||
* markup. Useful for preparing the body of a node to be sent by e-mail.
|
||||
*
|
||||
* The output will be suitable for use as 'format=flowed; delsp=yes' text
|
||||
* (RFC 3676) and can be passed directly to drupal_mail() for sending.
|
||||
*
|
||||
* We deliberately use variable_get('mail_line_endings', MAIL_LINE_ENDINGS)
|
||||
* rather than "\r\n".
|
||||
*
|
||||
* This function provides suitable alternatives for the following tags:
|
||||
*
|
||||
* <a> <address> <b> <blockquote> <br /> <caption> <cite> <dd> <div> <dl> <dt>
|
||||
* <em> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <ol> <p> <pre> <strong>
|
||||
* <table> <tbody> <td> <tfoot> <thead> <tr> <u> <ul>
|
||||
*
|
||||
* The following tag attributes are supported:
|
||||
* - <a href=...>: Hyperlink destination urls.
|
||||
* - <li value=...>: Ordered list item numbers.
|
||||
* - <ol start=...>: Ordered list start number.
|
||||
*
|
||||
* @param $string
|
||||
* The string to be transformed.
|
||||
* @param $allowed_tags
|
||||
* (optional) If supplied, a list of tags that will be transformed. If
|
||||
* omitted, all supported tags are transformed.
|
||||
*
|
||||
* @return
|
||||
* The transformed string.
|
||||
*
|
||||
* @see drupal_mail()
|
||||
*/
|
||||
function mailsystem_html_to_text($string, $allowed_tags = NULL) {
|
||||
$eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
|
||||
// Cache list of supported tags.
|
||||
static $supported_tags;
|
||||
if (!isset($supported_tags)) {
|
||||
$supported_tags = array(
|
||||
'a', 'address', 'b', 'blockquote', 'br', 'cite', 'dd', 'div', 'dl',
|
||||
'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'li',
|
||||
'ol', 'p', 'pre', 'strong', 'table', 'td', 'tr', 'u', 'ul',
|
||||
);
|
||||
}
|
||||
|
||||
// Make sure only supported tags are kept.
|
||||
$allowed_tags = isset($allowed_tags) ? array_intersect($supported_tags, $allowed_tags) : $supported_tags;
|
||||
|
||||
// Parse $string into a DOM tree.
|
||||
$dom = filter_dom_load($string);
|
||||
$notes = array();
|
||||
// Recursively convert the DOM tree into plain text.
|
||||
$text = _mailsystem_html_to_text($dom->documentElement, $allowed_tags, $notes);
|
||||
// Hard-wrap at 1000 characters (including the line break sequence)
|
||||
// and space-stuff special lines.
|
||||
$text = mailsystem_wrap_mail($text, array('max' => 1000 - strlen($eol), 'hard' => TRUE));
|
||||
// Change non-breaking spaces back to regular spaces, and trim line breaks.
|
||||
// chr(160) is the non-breaking space character.
|
||||
$text = str_replace(chr(160), ' ', trim($text, $eol));
|
||||
// Add footnotes;
|
||||
if ($notes) {
|
||||
// Add a blank line before the footnote list.
|
||||
$text .= $eol;
|
||||
foreach ($notes as $url => $note) {
|
||||
$text .= $eol . '[' . $note . '] ' . $url;
|
||||
}
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for drupal_html_to_text().
|
||||
*
|
||||
* Recursively converts $node to text, wrapping and indenting as necessary.
|
||||
*
|
||||
* @param $node
|
||||
* The source DOMNode.
|
||||
* @param $allowed_tags
|
||||
* A list of tags that will be transformed.
|
||||
* @param array &$notes
|
||||
* A writeable array of footnote reference numbers, keyed by their
|
||||
* respective hyperlink destination urls.
|
||||
* @param $line_length
|
||||
* The maximum length of a line, for wrapping. Defaults to 80 characters.
|
||||
* @param array $parents
|
||||
* The list of ancestor tags, from nearest to most distant. Defaults to an
|
||||
* empty array().
|
||||
* @param $count
|
||||
* The number to use for the next list item within an ordered list. Defaults
|
||||
* to 1.
|
||||
*/
|
||||
function _mailsystem_html_to_text(DOMNode $node, array $allowed_tags, array &$notes, $line_length = 80, array $parents = array(), &$count = NULL) {
|
||||
if (!isset($count)) {
|
||||
$count = 1;
|
||||
}
|
||||
$eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
|
||||
if ($node->nodeType === XML_TEXT_NODE) {
|
||||
// For text nodes, we just copy the text content.
|
||||
$text = $node->textContent;
|
||||
// Convert line breaks and trim trailing spaces.
|
||||
$text = preg_replace('/ *\r?\n/', $eol, $text);
|
||||
if (in_array('pre', $parents)) {
|
||||
// Within <pre> tags, all spaces become non-breaking.
|
||||
// chr(160) is the non-breaking space character.
|
||||
$text = str_replace(' ', chr(160), $text);
|
||||
}
|
||||
else {
|
||||
// Outside <pre> tags, collapse whitespace.
|
||||
$text = preg_replace('/[[:space:]]+/', ' ', $text);
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
// Non-text node.
|
||||
$tag = '';
|
||||
$text = '';
|
||||
$child_text = '';
|
||||
$child_count = 1;
|
||||
$indent = '';
|
||||
$prefix = '';
|
||||
$suffix = '';
|
||||
$pad = '';
|
||||
if (isset($node->tagName) && in_array($node->tagName, $allowed_tags)) {
|
||||
$tag = $node->tagName;
|
||||
switch ($tag) {
|
||||
// Turn links with valid hrefs into footnotes.
|
||||
case 'a':
|
||||
$test = !empty($node->attributes);
|
||||
$test = $test && ($href = $node->attributes->getNamedItem('href'));
|
||||
$test = $test && ($url = url(preg_replace('|^' . base_path() . '|', '', $href->nodeValue), array('absolute' => TRUE)));
|
||||
$test = $test && valid_url($url);
|
||||
if ($test) {
|
||||
// Only add links that have not already been added.
|
||||
if (isset($notes[$url])) {
|
||||
$note = $notes[$url];
|
||||
}
|
||||
else {
|
||||
$note = count($notes) + 1;
|
||||
$notes[$url] = $note;
|
||||
}
|
||||
$suffix = ' [' . $note . ']';
|
||||
}
|
||||
break;
|
||||
|
||||
// Generic block-level tags.
|
||||
case 'address':
|
||||
case 'caption':
|
||||
case 'div':
|
||||
case 'p':
|
||||
case 'pre':
|
||||
// Start on a new line except as the first child of a list item.
|
||||
if (!isset($parents[0]) || $parents[0] !== 'li' || !$node->isSameNode($node->parentNode->firstChild)) {
|
||||
$text = $eol;
|
||||
}
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Forced line break.
|
||||
case 'br':
|
||||
$text = $eol;
|
||||
break;
|
||||
|
||||
// Boldface by wrapping with "*" characters.
|
||||
case 'b':
|
||||
case 'strong':
|
||||
$prefix = '*';
|
||||
$suffix = '*';
|
||||
break;
|
||||
|
||||
// Italicize by wrapping with "/" characters.
|
||||
case 'cite':
|
||||
case 'em':
|
||||
case 'i':
|
||||
$prefix = '/';
|
||||
$suffix = '/';
|
||||
break;
|
||||
|
||||
// Underline by wrapping with "_" characters.
|
||||
case 'u':
|
||||
$prefix = '_';
|
||||
$suffix = '_';
|
||||
break;
|
||||
|
||||
// Blockquotes are indented by "> " at each level.
|
||||
case 'blockquote':
|
||||
$text = $eol;
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '>' . chr(160);
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Dictionary definitions are indented by four spaces.
|
||||
case 'dd':
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = chr(160) . chr(160) . chr(160) . chr(160);
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Dictionary list.
|
||||
case 'dl':
|
||||
// Start on a new line as the first child of a list item.
|
||||
if (!isset($parents[0]) || $parents[0] !== 'li' || !$node->isSameNode($node->parentNode->firstChild)) {
|
||||
$text = $eol;
|
||||
}
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Dictionary term.
|
||||
case 'dt':
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Header level 1 is prefixed by eight "=" characters.
|
||||
case 'h1':
|
||||
$text = "$eol$eol";
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '========' . chr(160);
|
||||
$pad = chr(160) . '=';
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Header level 2 is prefixed by six "-" characters.
|
||||
case 'h2':
|
||||
$text = "$eol$eol";
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '------' . chr(160);
|
||||
$pad = chr(160) . '-';
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Header level 3 is prefixed by four "." characters and a space.
|
||||
case 'h3':
|
||||
$text = "$eol$eol";
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '....' . chr(160);
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Header level 4 is prefixed by three "." characters and a space.
|
||||
case 'h4':
|
||||
$text = "$eol$eol";
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '...' . chr(160);
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Header level 5 is prefixed by two "." character and a space.
|
||||
case 'h5':
|
||||
$text = "$eol$eol";
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '..' . chr(160);
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Header level 6 is prefixed by one "." character and a space.
|
||||
case 'h6':
|
||||
$text = "$eol$eol";
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = '.' . chr(160);
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Horizontal rulers become a line of "-" characters.
|
||||
case 'hr':
|
||||
$text = $eol;
|
||||
$child_text = '-';
|
||||
$pad = '-';
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// List items are treated differently depending on the parent tag.
|
||||
case 'li':
|
||||
// Ordered list item.
|
||||
if (reset($parents) === 'ol') {
|
||||
// Check the value attribute.
|
||||
$test = !empty($node->attributes);
|
||||
$test = $test && ($value = $node->attributes->getNamedItem('value'));
|
||||
if ($test) {
|
||||
$count = $value->nodeValue;
|
||||
}
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = ($count < 10 ? chr(160) : '') . chr(160) . "$count)" . chr(160);
|
||||
$count++;
|
||||
}
|
||||
// Unordered list item.
|
||||
else {
|
||||
// chr(160) is the non-breaking space character.
|
||||
$indent = chr(160) . '*' . chr(160);
|
||||
}
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Ordered lists.
|
||||
case 'ol':
|
||||
// Start on a new line as the first child of a list item.
|
||||
if (!isset($parents[0]) || $parents[0] !== 'li' || !$node->isSameNode($node->parentNode->firstChild)) {
|
||||
$text = $eol;
|
||||
}
|
||||
// Check the start attribute.
|
||||
$test = !empty($node->attributes);
|
||||
$test = $test && ($value = $node->attributes->getNamedItem('start'));
|
||||
if ($test) {
|
||||
$child_count = $value->nodeValue;
|
||||
}
|
||||
break;
|
||||
|
||||
// Tables require special handling.
|
||||
case 'table':
|
||||
return _mailsystem_html_to_text_table($node, $allowed_tags, $notes, $line_length);
|
||||
|
||||
// Separate adjacent table cells by two non-breaking spaces.
|
||||
case 'td':
|
||||
if (!empty($node->nextSibling)) {
|
||||
// chr(160) is the non-breaking space character.
|
||||
$suffix = chr(160) . chr(160);
|
||||
}
|
||||
break;
|
||||
|
||||
// End each table row with a newline.
|
||||
case 'tr':
|
||||
$suffix = $eol;
|
||||
break;
|
||||
|
||||
// Unordered lists.
|
||||
case 'ul':
|
||||
// Start on a new line as the first child of a list item.
|
||||
if (!isset($parents[0]) || $parents[0] !== 'li' || !$node->isSameNode($node->parentNode->firstChild)) {
|
||||
$text = $eol;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Coder review complains if there is no default case.
|
||||
break;
|
||||
}
|
||||
// Only add allowed tags to the $parents array.
|
||||
array_unshift($parents, $tag);
|
||||
}
|
||||
// Copy each child node to output.
|
||||
if ($node->hasChildNodes()) {
|
||||
foreach ($node->childNodes as $child) {
|
||||
$child_text .= _mailsystem_html_to_text($child, $allowed_tags, $notes, $line_length - drupal_strlen($indent), $parents, $child_count); }
|
||||
}
|
||||
// We only add prefix and suffix if the child nodes were non-empty.
|
||||
if ($child_text > '') {
|
||||
// We capitalize the contents of h1 and h2 tags.
|
||||
if ($tag === 'h1' || $tag === 'h2') {
|
||||
$child_text = drupal_strtoupper($child_text);
|
||||
}
|
||||
// Don't add a newline to an existing newline.
|
||||
if ($suffix === $eol && drupal_substr($child_text, - drupal_strlen($eol)) === $eol) {
|
||||
$suffix = '';
|
||||
}
|
||||
// Trim spaces around newlines except with <pre> or inline tags.
|
||||
if (!in_array($tag, array('a', 'b', 'cite', 'em', 'i', 'pre', 'strong', 'u'))) {
|
||||
$child_text = preg_replace('/ *' . $eol . ' */', $eol, $child_text);
|
||||
}
|
||||
// Soft-wrap at effective line length, but don't space-stuff.
|
||||
$child_text = mailsystem_wrap_mail(
|
||||
$prefix . $child_text,
|
||||
array(
|
||||
// chr(160) is the non-breaking space character.
|
||||
'break' => chr(160) . $eol,
|
||||
'indent' => $indent,
|
||||
'max' => $line_length,
|
||||
'pad' => $pad,
|
||||
'stuff' => FALSE,
|
||||
)
|
||||
) . $suffix;
|
||||
if ($tag === 'pre') {
|
||||
// Perform RFC-3676 soft-wrapping.
|
||||
// chr(160) is the non-breaking space character.
|
||||
$child_text = str_replace(chr(160), ' ', $child_text);
|
||||
$child_text = mailsystem_wrap_mail(
|
||||
$child_text,
|
||||
array('max' => $line_length, 'stuff' => FALSE)
|
||||
);
|
||||
// chr(160) is the non-breaking space character.
|
||||
$child_text = str_replace(' ', chr(160), $child_text);
|
||||
}
|
||||
$text .= $child_text;
|
||||
}
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for _mailsystem_html_to_text().
|
||||
*
|
||||
* Renders a <table> DOM Node into plain text. Attributes such as rowspan,
|
||||
* colspan, padding, border, etc. are ignored.
|
||||
*
|
||||
* @param DOMNode $node
|
||||
* The DOMNode corresponding to the <table> tag and its contents.
|
||||
* @param $allowed_tags
|
||||
* The list of allowed tags passed to _mailsystem_html_to_text().
|
||||
* @param array &$notes
|
||||
* A writeable array of footnote reference numbers, keyed by their
|
||||
* respective hyperlink destination urls.
|
||||
* @param $table_width
|
||||
* The desired maximum table width, after word-wrapping each table cell.
|
||||
*
|
||||
* @return
|
||||
* A plain text representation of the table.
|
||||
*
|
||||
* @see _mailsystem_html_to_text()
|
||||
*/
|
||||
function _mailsystem_html_to_text_table(DOMNode $node, $allowed_tags = NULL, array &$notes = array(), $table_width = 80) {
|
||||
$eol = variable_get('mail_line_endings', MAIL_LINE_ENDINGS);
|
||||
$header = array();
|
||||
$footer = array();
|
||||
$body = array();
|
||||
$text = $eol;
|
||||
$current = $node;
|
||||
while (TRUE) {
|
||||
if (isset($current->tagName)) {
|
||||
switch ($current->tagName) {
|
||||
case 'caption': // The table caption is added first.
|
||||
$text = _mailsystem_html_to_text($current, $allowed_tags, $notes, $table_width);
|
||||
break;
|
||||
|
||||
case 'tr':
|
||||
switch ($current->parentNode->tagName) {
|
||||
case 'thead':
|
||||
$header[] = $current;
|
||||
break;
|
||||
|
||||
case 'tfoot':
|
||||
$footer[] = $current;
|
||||
break;
|
||||
|
||||
default: // Either 'tbody' or 'table'
|
||||
$body[] = $current;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if ($current->hasChildNodes()) {
|
||||
$current = $current->firstChild;
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
do {
|
||||
if ($current->nextSibling) {
|
||||
$current = $current->nextSibling;
|
||||
continue 2;
|
||||
}
|
||||
$current = $current->parentNode;
|
||||
} while ($current && !$current->isSameNode($node));
|
||||
break;
|
||||
}
|
||||
// Merge the thead, tbody, and tfoot sections together.
|
||||
if ($rows = array_merge($header, $body, $footer)) {
|
||||
$num_rows = count($rows);
|
||||
// First just count the number of columns.
|
||||
$num_cols = 0;
|
||||
foreach ($rows as $row) {
|
||||
$row_cols = 0;
|
||||
foreach ($row->childNodes as $cell) {
|
||||
if (isset($cell->tagName) && in_array($cell->tagName, array('td', 'th'))) {
|
||||
$row_cols++;
|
||||
}
|
||||
}
|
||||
$num_cols = max($num_cols, $row_cols);
|
||||
}
|
||||
// If any columns were found, calculate each column height and width.
|
||||
if ($num_cols) {
|
||||
// Set up a binary search for best wrap width for each column.
|
||||
$max = max($table_width - $num_cols - 1, 1);
|
||||
$max_wraps = array_fill(0, $num_cols, $max);
|
||||
$try = max(intval(($table_width - 1) / $num_cols - 1), 1);
|
||||
$try_wraps = array_fill(0, $num_cols, $try);
|
||||
$min_wraps = array_fill(0, $num_cols, 1);
|
||||
// Start searching...
|
||||
$change = FALSE;
|
||||
do {
|
||||
$change = FALSE;
|
||||
$widths = array_fill(0, $num_cols, 0);
|
||||
$heights = array_fill(0, $num_rows, 0);
|
||||
$table = array_fill(0, $num_rows, array_fill(0, $num_cols, ''));
|
||||
$breaks = array_fill(0, $num_cols, FALSE);
|
||||
foreach ($rows as $i => $row) {
|
||||
$j = 0;
|
||||
foreach ($row->childNodes as $cell) {
|
||||
if (!isset($cell->tagName) || !in_array($cell->tagName, array('td', 'th'))) {
|
||||
// Skip text nodes.
|
||||
continue;
|
||||
}
|
||||
// Render the cell contents.
|
||||
$cell = _mailsystem_html_to_text($cell, $allowed_tags, $notes, $try_wraps[$j]);
|
||||
// Trim leading line-breaks and trailing whitespace.
|
||||
// chr(160) is the non-breaking space character.
|
||||
$cell = rtrim(ltrim($cell, $eol), ' ' . $eol . chr(160));
|
||||
$table[$i][$j] = $cell;
|
||||
if ($cell > '') {
|
||||
// Split the cell into lines.
|
||||
$lines = explode($eol, $cell);
|
||||
// The row height is the maximum number of lines among all the
|
||||
// cells in that row.
|
||||
$heights[$i] = max($heights[$i], count($lines));
|
||||
foreach ($lines as $line) {
|
||||
$this_width = drupal_strlen($line);
|
||||
// The column width is the maximum line width among all the
|
||||
// lines in that column.
|
||||
if ($this_width > $widths[$j]) {
|
||||
$widths[$j] = $this_width;
|
||||
// If the longest line in a column contains at least one
|
||||
// space character, then the table can be made narrower.
|
||||
$breaks[$j] = strpos(' ', $line) !== FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
// Calculate the total table width;
|
||||
$this_width = array_sum($widths) + $num_cols + 1;
|
||||
if ($this_width > $table_width) {
|
||||
// Wider than desired.
|
||||
if (!in_array(TRUE, $breaks)) {
|
||||
// If there are no more break points, then the table is already as
|
||||
// narrow as it can get, so we're done.
|
||||
break;
|
||||
}
|
||||
foreach ($try_wraps as $i => $wrap) {
|
||||
$max_wraps[$i] = min($max_wraps[$i], $wrap);
|
||||
if ($breaks[$i]) {
|
||||
$new_wrap = intval(($min_wraps[$i] + $max_wraps[$i]) / 2);
|
||||
$new_wrap = min($new_wrap, $widths[$i] - 1);
|
||||
$new_wrap = max($new_wrap, $min_wraps[$i]);
|
||||
}
|
||||
else {
|
||||
// There's no point in trying to make the column narrower than
|
||||
// the widest un-wrappable line in the column.
|
||||
$min_wraps[$i] = $widths[$i];
|
||||
$new_wrap = $widths[$i];
|
||||
}
|
||||
if ($try_wraps[$i] > $new_wrap) {
|
||||
$try_wraps[$i] = $new_wrap;
|
||||
$change = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
elseif ($this_width < $table_width) {
|
||||
// Narrower than desired.
|
||||
foreach ($try_wraps as $i => $wrap) {
|
||||
if ($min_wraps[$i] < $wrap) {
|
||||
$min_wraps[$i] = $wrap;
|
||||
}
|
||||
$new_wrap = intval(($min_wraps[$i] + $max_wraps[$i]) / 2);
|
||||
$new_wrap = max($new_wrap, $widths[$i] + 1);
|
||||
$new_wrap = min($new_wrap, $max_wraps[$i]);
|
||||
if ($try_wraps[$i] < $new_wrap) {
|
||||
$try_wraps[$i] = $new_wrap;
|
||||
$change = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while ($change);
|
||||
// Pad each cell to column width and line height.
|
||||
for ($i = 0; $i < $num_rows; $i++) {
|
||||
if ($heights[$i]) {
|
||||
for ($j = 0; $j < $num_cols; $j++) {
|
||||
$cell = $table[$i][$j];
|
||||
// Pad each cell to the maximum number of lines in that row.
|
||||
$lines = array_pad(explode($eol, $cell), $heights[$i], '');
|
||||
foreach ($lines as $k => $line) {
|
||||
// Pad each line to the maximum width in that column.
|
||||
$repeat = $widths[$j] - drupal_strlen($line);
|
||||
if ($repeat > 0) {
|
||||
// chr(160) is the non-breaking space character.
|
||||
$lines[$k] .= str_repeat(chr(160), $repeat);
|
||||
}
|
||||
}
|
||||
$table[$i][$j] = $lines;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Generate the row separator line.
|
||||
$separator = '+';
|
||||
for($i = 0; $i < $num_cols; $i++) {
|
||||
$separator .= str_repeat('-', $widths[$i]) . '+';
|
||||
}
|
||||
$separator .= $eol;
|
||||
for ($i = 0; $i < $num_rows; $i++) {
|
||||
$text .= $separator;
|
||||
if (!$heights[$i]) {
|
||||
continue;
|
||||
}
|
||||
$row = $table[$i];
|
||||
// For each row, iterate first by lines within the row.
|
||||
for ($k = 0; $k < $heights[$i]; $k++) {
|
||||
// Add a vertical-bar at the beginning of each row line.
|
||||
$row_line = '|';
|
||||
$trimmed = '';
|
||||
// Within each row line, iterate by cells within that line.
|
||||
for ($j = 0; $j < $num_cols; $j++) {
|
||||
// Add a vertical bar at the end of each cell line.
|
||||
$row_line .= $row[$j][$k] . '|';
|
||||
// chr(160) is the non-breaking space character.
|
||||
$trimmed .= trim($row[$j][$k], ' ' . $eol . chr(160));
|
||||
}
|
||||
if ($trimmed > '') {
|
||||
// Only print rows that are non-empty.
|
||||
$text .= $row_line . $eol;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Final output ends with a row separator.
|
||||
$text .= $separator;
|
||||
}
|
||||
}
|
||||
// Make sure formatted table content doesn't line-wrap.
|
||||
// chr(160) is the non-breaking space character.
|
||||
return str_replace(' ', chr(160), $text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for array_walk in drupal_wrap_mail().
|
||||
*
|
||||
* Inserts $values['break'] sequences to break up $line into parts of no more
|
||||
* than $values['wrap'] characters. Only breaks at space characters, unless
|
||||
* $values['hard'] is TRUE.
|
||||
*/
|
||||
function _mailsystem_wrap_mail_line(&$line, $key, $values) {
|
||||
$line = wordwrap($line, $values['wrap'], $values['break'], $values['hard']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for array_walk in drupal_wrap_mail().
|
||||
*
|
||||
* If $values['pad'] is non-empty, $values['indent'] will be added at the start
|
||||
* of each line, and $values['pad'] at the end, repeating the last character of
|
||||
* $values['pad'] until the line length equals $values['max'].
|
||||
*
|
||||
* If $values['pad'] is empty, $values['indent'] will be added at the start of
|
||||
* the first line, and $values['clean'] at the start of subsequent lines.
|
||||
*
|
||||
* If $values['stuff'] is true, then an extra space character will be added at
|
||||
* the start of any line beginning with a space, a '>', or the word 'From'.
|
||||
*
|
||||
* @see http://www.ietf.org/rfc/rfc3676.txt
|
||||
*/
|
||||
function _mailsystem_indent_mail_line(&$line, $key, $values) {
|
||||
if ($line == '') {
|
||||
return;
|
||||
}
|
||||
if ($values['pad']) {
|
||||
$line = $values['indent'] . $line;
|
||||
$count = $values['max'] - drupal_strlen($line) - drupal_strlen($values['pad']);
|
||||
if ($count >= 0) {
|
||||
$line .= $values['pad'] . str_repeat($values['pad_repeat'], $count);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$line = $values[$key === 0 ? 'indent' : 'clean'] . $line;
|
||||
}
|
||||
if ($values['stuff']) {
|
||||
// chr(160) is the non-breaking space character.
|
||||
$line = preg_replace('/^(' . chr(160) . '| |>|From)/', ' $1', $line);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for drupal_wrap_mail() and drupal_html_to_text().
|
||||
*
|
||||
* Replace all non-quotation markers from a given piece of indentation with
|
||||
* non-breaking space characters.
|
||||
*/
|
||||
function _mailsystem_html_to_text_clean($indent) {
|
||||
// chr(160) is the non-breaking space character.
|
||||
return preg_replace('/[^>]/', chr(160), $indent);
|
||||
}
|
202
sites/all/modules/contrib/mail/mailsystem/mailsystem.admin.inc
Normal file
202
sites/all/modules/contrib/mail/mailsystem/mailsystem.admin.inc
Normal file
@@ -0,0 +1,202 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administrative form for setting the mail_system variable.
|
||||
*/
|
||||
function mailsystem_admin_settings() {
|
||||
$args = array(
|
||||
'!interface' => url('http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7'),
|
||||
'@interface' => 'MailSystemInterface',
|
||||
'!format' => url('http://api.drupal.org/api/drupal/includes--mail.inc/function/MailSystemInterface%3A%3Aformat/7'),
|
||||
'@format' => 'format()',
|
||||
'!mail' => url('http://api.drupal.org/api/drupal/includes--mail.inc/function/MailSystemInterface%3A%3Amail/7'),
|
||||
'@mail' => 'mail()',
|
||||
'!default_class' => url('http://api.drupal.org/api/drupal/modules--system--system.mail.inc/class/DefaultMailSystem/7'),
|
||||
'@default_class' => mailsystem_default_value(),
|
||||
'%module' => 'module',
|
||||
'%key' => 'key',
|
||||
);
|
||||
$form = array('#submit' => array('mailsystem_admin_settings_submit'));
|
||||
$mail_system = mailsystem_get();
|
||||
$mail_defaults = mailsystem_defaults();
|
||||
$mailsystem_classes = mailsystem_get_classes();
|
||||
$descriptions = array();
|
||||
foreach (system_rebuild_module_data() as $item) {
|
||||
if ($item->status) {
|
||||
$descriptions[$item->name] = (
|
||||
empty($item->info['package'])
|
||||
? '' : $item->info['package']
|
||||
) . ' » ' . t('!module module', array('!module' => $item->info['name']));
|
||||
}
|
||||
}
|
||||
asort($descriptions);
|
||||
$form['mailsystem'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Mail System Settings'),
|
||||
'#description' => t(
|
||||
'Drupal provides a default <a href="!interface"><code>@interface</code></a> class called <a href="!default_class"><code>@default_class</code></a>. Modules may provide additional classes. Each <a href="!interface"><code>@interface</code></a> class may be associated with one or more identifiers, composed of a %module and an optional %key. Each email being sent also has a %module and a %key. To decide which class to use, Drupal uses the following search order: <ol><li>The class associated with the %module and %key, if any.</li><li>The class associated with the %module, if any.</li><li>The site-wide default <a href="!interface"><code>@interface</code></a> class.</li></ol>', $args
|
||||
),
|
||||
'#collapsible' => FALSE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$form['mailsystem'][mailsystem_default_id()] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t(
|
||||
'Site-wide default <a href="!interface"><code>@interface</code></a> class', $args
|
||||
),
|
||||
'#options' => $mailsystem_classes,
|
||||
'#default_value' => $mail_system[mailsystem_default_id()],
|
||||
);
|
||||
$mailsystem_classes = array(
|
||||
mailsystem_default_id() => t('Remove this setting.')
|
||||
) + $mailsystem_classes;
|
||||
foreach (array_diff_key($mail_system, $mail_defaults) as $id => $class) {
|
||||
// Separate $id into $module and $key.
|
||||
$module = $id;
|
||||
while ($module && empty($descriptions[$module])) {
|
||||
// Remove a key from the end
|
||||
$module = implode('_', explode('_', $module, -1));
|
||||
}
|
||||
// If an array key of the $mail_system variable is neither "default-system"
|
||||
// nor begins with a module name, then it should be unset.
|
||||
if (empty($module)) {
|
||||
watchdog('mailsystem', "Removing bogus mail_system key %id.", array('%id' => $id), WATCHDOG_WARNING);
|
||||
unset($mail_system[$id]);
|
||||
continue;
|
||||
}
|
||||
// Set $title to the human-readable module name.
|
||||
$title = preg_replace('/^.* » /', '', $descriptions[$module]);
|
||||
if ($key = substr($id, strlen($module) + 1)) {
|
||||
$title .= " ($key key)";
|
||||
}
|
||||
$title .= ' class';
|
||||
$form['mailsystem'][$id] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => $title,
|
||||
'#options' => $mailsystem_classes,
|
||||
'#default_value' => $class,
|
||||
);
|
||||
}
|
||||
// Generate a list of themes which may used to render emails.
|
||||
$theme_options = array('current' => t('Current'), 'default' => t('Default'));
|
||||
if (module_exists('domain_theme')) {
|
||||
$theme_options['domain'] = t('Domain Theme');
|
||||
}
|
||||
// Get a list of all themes.
|
||||
$themes = list_themes();
|
||||
foreach ($themes as $name => $theme) {
|
||||
if ($theme->status == 1) {
|
||||
$theme_options[$name] = $theme->info['name'];
|
||||
}
|
||||
}
|
||||
$form['mailsystem']['mailsystem_theme'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Theme to render the emails'),
|
||||
'#description' => t('Select the theme that will be used to render the emails. This can be either the current theme, the default theme, the domain theme or any active theme.'),
|
||||
'#options' => $theme_options,
|
||||
'#default_value' => variable_get('mailsystem_theme', 'current'),
|
||||
);
|
||||
$form['class'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('New Class'),
|
||||
'#description' => t(
|
||||
'Create a new <a href="!interface"><code>@interface</code></a> that inherits its methods from other classes. The new class will be named after the other classes it uses.', $args
|
||||
),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
$mailsystem_classes[mailsystem_default_id()] = '--Select--';
|
||||
$form['class']['format'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t(
|
||||
'Class to use for the <a href="!format"><code>@format</code></a> method', $args
|
||||
),
|
||||
'#options' => $mailsystem_classes,
|
||||
);
|
||||
$form['class']['mail'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t(
|
||||
'Class to use for the <a href="!mail"><code>@mail</code></a> method', $args
|
||||
),
|
||||
'#options' => $mailsystem_classes,
|
||||
);
|
||||
$form['identifier'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('New Setting'),
|
||||
'#description' => t('Add a new %module and %key to the settings list.',
|
||||
array(
|
||||
'%module' => 'module',
|
||||
'%key' => 'key',
|
||||
)
|
||||
),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
array_unshift($descriptions, t('-- Select --'));
|
||||
$form['identifier']['module'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Module'),
|
||||
'#options' => $descriptions,
|
||||
);
|
||||
$form['identifier']['key'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Key'),
|
||||
'#size' => 80,
|
||||
);
|
||||
$form['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Save settings'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes mailsystem_admin_settings form.
|
||||
*/
|
||||
function mailsystem_admin_settings_submit($form, &$form_state) {
|
||||
variable_set('mailsystem_theme', $form_state['values']['mailsystem']['mailsystem_theme']);
|
||||
// Rebuild the theme registry to make changes needed by theme rendering.
|
||||
drupal_theme_rebuild();
|
||||
unset($form_state['values']['mailsystem']['mailsystem_theme']);
|
||||
|
||||
$default_id = mailsystem_default_id();
|
||||
$mail_system = array(
|
||||
$default_id => (
|
||||
empty($form_state['values'][$default_id])
|
||||
? mailsystem_default_value()
|
||||
: $form_state['values'][$default_id]
|
||||
)
|
||||
);
|
||||
foreach (element_children($form_state['values']['mailsystem']) as $module) {
|
||||
$class = $form_state['values']['mailsystem'][$module];
|
||||
if (!empty($class) && $class != $default_id) {
|
||||
$mail_system[$module] = $class;
|
||||
}
|
||||
}
|
||||
unset($form_state['values']['mailsystem']);
|
||||
if ($form_state['values']['class']['format'] === mailsystem_default_id()) {
|
||||
unset($form_state['values']['class']['format']);
|
||||
}
|
||||
if ($form_state['values']['class']['mail'] === mailsystem_default_id()) {
|
||||
unset($form_state['values']['class']['mail']);
|
||||
}
|
||||
if ($form_state['values']['class']) {
|
||||
$new_class = mailsystem_create_class($form_state['values']['class']);
|
||||
}
|
||||
else {
|
||||
$new_class = $mail_system[mailsystem_default_id()];
|
||||
}
|
||||
unset($form_state['values']['class']);
|
||||
if ($id = $form_state['values']['identifier']['module']) {
|
||||
if (!empty($form_state['values']['identifier']['key'])) {
|
||||
$id .= '_' . $form_state['values']['identifier']['key'];
|
||||
}
|
||||
$mail_system[$id] = $new_class;
|
||||
}
|
||||
unset($form_state['values']['identifier']);
|
||||
variable_set('mail_system', $mail_system);
|
||||
drupal_set_message(t('The configuration options have been saved.'));
|
||||
}
|
14
sites/all/modules/contrib/mail/mailsystem/mailsystem.info
Normal file
14
sites/all/modules/contrib/mail/mailsystem/mailsystem.info
Normal file
@@ -0,0 +1,14 @@
|
||||
package = Mail
|
||||
name = Mail System
|
||||
description = Provides a user interface for per-module and site-wide mail_system selection.
|
||||
php = 5.0
|
||||
core = 7.x
|
||||
configure = admin/config/system/mailsystem
|
||||
dependencies[] = filter
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-04-10
|
||||
version = "7.x-2.34"
|
||||
core = "7.x"
|
||||
project = "mailsystem"
|
||||
datestamp = "1334082653"
|
||||
|
353
sites/all/modules/contrib/mail/mailsystem/mailsystem.module
Normal file
353
sites/all/modules/contrib/mail/mailsystem/mailsystem.module
Normal file
@@ -0,0 +1,353 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide UI for controlling the mail_system variable.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_init().
|
||||
*
|
||||
* Caches the list of MailSystemInterface classes, and removes classes
|
||||
* from the mail_system variable which are no longer available.
|
||||
*
|
||||
* @see mailsystem_get_classes()
|
||||
*/
|
||||
function mailsystem_init() {
|
||||
mailsystem_get_classes();
|
||||
// @todo Remove this when issue #299138 gets resolved.
|
||||
if (!function_exists('mailsystem_html_to_text')) {
|
||||
module_load_include('inc', 'mailsystem', 'html_to_text');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*
|
||||
* Defines a permission for managing the mail_system variable.
|
||||
*/
|
||||
function mailsystem_permission() {
|
||||
return array(
|
||||
'administer mailsystem' => array(
|
||||
'title' => t('Administer Mail System'),
|
||||
'description' => t(
|
||||
'Select the default, per-module, and per-mailing <a href="!interface"><code>@interface</code></a> to use for formatting and sending email messages.',
|
||||
array(
|
||||
'!interface' => url('http://api.drupal.org/api/drupal/includes--mail.inc/interface/MailSystemInterface/7'),
|
||||
'@interface' => 'MailSystemInterface',
|
||||
)
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function mailsystem_menu() {
|
||||
$items['admin/config/system/mailsystem'] = array(
|
||||
'title' => 'Mail System',
|
||||
'description' => 'Configure per-module Mail System settings.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('mailsystem_admin_settings'),
|
||||
'access arguments' => array('administer mailsystem'),
|
||||
'file' => 'mailsystem.admin.inc',
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the id for the default mail_system setting.
|
||||
*/
|
||||
function mailsystem_default_id() {
|
||||
// @todo: Is there a way to get this from core?
|
||||
return 'default-system';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value for the default mail_system setting.
|
||||
*/
|
||||
function mailsystem_default_value() {
|
||||
// @todo: Is there a way to get this from core?
|
||||
return 'DefaultMailSystem';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default settings for the mail_system variable.
|
||||
*/
|
||||
function mailsystem_defaults() {
|
||||
return array(mailsystem_default_id() => mailsystem_default_value());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current mail_system settings.
|
||||
*
|
||||
* @return The contents of the mail_system variable merged with its defaults.
|
||||
*/
|
||||
function mailsystem_get() {
|
||||
return array_merge(
|
||||
mailsystem_defaults(),
|
||||
variable_get('mail_system', mailsystem_defaults())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default list of MailSystemInterface methods.
|
||||
*
|
||||
* @return
|
||||
* An array whose keys are the names of the methods defined by
|
||||
* MailSystemInterface and whose values are the default class used to
|
||||
* provide that method.
|
||||
*/
|
||||
function mailsystem_default_methods() {
|
||||
$mail_system = mailsystem_get();
|
||||
$default_class = $mail_system[mailsystem_default_id()];
|
||||
$methods = get_class_methods('MailSystemInterface');
|
||||
return array_combine(
|
||||
$methods,
|
||||
array_fill(0, count($methods), $default_class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and registers a new MailSystemInterface class.
|
||||
*
|
||||
* The newly-created class gets its name and each of its class methods from the
|
||||
* other classes specified by the $class parameter.
|
||||
*
|
||||
* @param $class An associative array of ($method_name => $class_name) tuples,
|
||||
* where each $method_name is the name of a class method to be created, and
|
||||
* each $class_name is the name of a class to use for that method.
|
||||
*
|
||||
* @return
|
||||
* The name of the newly-created class if successful; otherwise FALSE.
|
||||
*/
|
||||
function mailsystem_create_class($classes) {
|
||||
// Merge in defaults.
|
||||
$classes += mailsystem_default_methods();
|
||||
ksort($classes);
|
||||
// Do not create a new class whose methods all derive from the same class.
|
||||
if (count(array_unique($classes)) === 1) {
|
||||
return FALSE;
|
||||
}
|
||||
$class_name = implode('__', $classes);
|
||||
// Ensure that the mailsystem directory exists.
|
||||
$class_dir = file_build_uri('mailsystem');
|
||||
if (!file_prepare_directory($class_dir, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
|
||||
return FALSE;
|
||||
}
|
||||
// Build the class filename.
|
||||
$class_file = drupal_realpath($class_dir) . DIRECTORY_SEPARATOR . "$class_name.mail.inc";
|
||||
// Strip DRUPAL_ROOT.
|
||||
$drupal_root = drupal_realpath(DRUPAL_ROOT) . DIRECTORY_SEPARATOR;
|
||||
$class_file = preg_replace('#^' . preg_quote($drupal_root, '#') . '#', '', $class_file);
|
||||
// Build the class implementation as a string.
|
||||
$class_contents = '<?php
|
||||
class ' . $class_name . ' implements MailSystemInterface {';
|
||||
// Create a protected variable to hold each method class.
|
||||
foreach (array_keys($classes) as $method) {
|
||||
$class_contents .= '
|
||||
protected $' . $method . 'Class;';
|
||||
}
|
||||
// Create a class construction function to populate the variables.
|
||||
$class_contents .= '
|
||||
public function __construct() {';
|
||||
foreach ($classes as $method => $class) {
|
||||
$class_contents .= '
|
||||
if (drupal_autoload_class(\'' . $class . '\')) {
|
||||
$this->' . $method . 'Class = new ' . $class . ';
|
||||
}
|
||||
else {
|
||||
$this->' . $method . 'Class = new ' . mailsystem_default_value() . ';
|
||||
}';
|
||||
}
|
||||
$class_contents .= '
|
||||
}';
|
||||
// Create each class method.
|
||||
foreach (array_keys($classes) as $method) {
|
||||
$class_contents .= '
|
||||
public function ' . $method . '(array $message) {
|
||||
return $this->' . $method . 'Class->' . $method . '($message);
|
||||
}';
|
||||
}
|
||||
$class_contents .= '
|
||||
}
|
||||
';
|
||||
if (file_unmanaged_save_data($class_contents, $class_file, FILE_EXISTS_REPLACE)) {
|
||||
// Remove any conflicting registry entries to avoid a database error.
|
||||
$class_condition = db_and()
|
||||
->condition('name', $class_name)
|
||||
->condition('type', 'class');
|
||||
$file_condition = db_and()
|
||||
->condition('filename', $class_file);
|
||||
db_delete('registry_file')
|
||||
->condition($file_condition);
|
||||
db_delete('registry')->condition(
|
||||
db_or()->condition($class_condition)
|
||||
->condition($file_condition)
|
||||
);
|
||||
// Make sure that registry functions are available.
|
||||
require_once 'includes/registry.inc';
|
||||
// Parse the newly-created class file and add it to the registry.
|
||||
_registry_parse_file($class_file, $class_contents, 'mailsystem');
|
||||
// Clear the mailsystem cache so that it will pick up the new class.
|
||||
drupal_static_reset('mailsystem_get_classes');
|
||||
drupal_set_message(
|
||||
t('Class <code>%class</code> written to <code>%file</code>.',
|
||||
array('%class' => $class_name, '%file' => $class_file)
|
||||
)
|
||||
);
|
||||
}
|
||||
return $class_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps other modules safely set their own key within mail_system. This
|
||||
* function should be called from hook_enable() implementations.
|
||||
*
|
||||
* @param $setting An associative array ($id => $value) where:
|
||||
* - $id is the machine-readable module name optionally followed by '_'
|
||||
* and a key.
|
||||
* - $value is one of
|
||||
* - (string) The name of a class that implements MailSystemInterface.
|
||||
* - (array) An associative array whose keys are the names of methods
|
||||
* defined by MailSystemInterface and whose values are the names of
|
||||
* the class to use for that method.
|
||||
*
|
||||
* @see drupal_mail(), mailsystem_default_methods()
|
||||
*/
|
||||
function mailsystem_set(array $setting) {
|
||||
$mail_system = mailsystem_get();
|
||||
foreach ($setting as $key => $class) {
|
||||
if (is_array($class)) {
|
||||
unset($setting[$key]);
|
||||
if ($new_class = mailsystem_create_class($class)) {
|
||||
$setting[$key] = $new_class;
|
||||
}
|
||||
}
|
||||
}
|
||||
variable_set('mail_system', array_merge(mailsystem_get(), $setting));
|
||||
}
|
||||
|
||||
/**
|
||||
* Helps other modules safely remove their settings from mail_system. This
|
||||
* function should be called from the other module's hook_disable() function.
|
||||
*
|
||||
* @param $setting An associative array ($module => $classname) describing
|
||||
* a module and associated MailSystemInterface class that are being disabled.
|
||||
* - $module is the machine-readable module name.
|
||||
* - $classname is a class that implements MailSystemInterface.
|
||||
*
|
||||
* If $classname is empty, only the $module entry is removed.
|
||||
*
|
||||
* @param $class
|
||||
* The name of the class to be removed, if any.
|
||||
*/
|
||||
function mailsystem_clear(array $setting) {
|
||||
variable_set(
|
||||
'mail_system',
|
||||
array_merge(
|
||||
mailsystem_defaults(),
|
||||
array_diff_key(array_diff(mailsystem_get(), $setting), $setting)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of classes which implement MailSystemInterface.
|
||||
*/
|
||||
function &mailsystem_get_classes() {
|
||||
$mailsystem_classes = &drupal_static(__FUNCTION__);
|
||||
if (!isset($mailsystem_classes)) {
|
||||
$mailsystem_classes = array();
|
||||
// @todo Is there a better way to find all mail-related classes?
|
||||
$declared_classes = get_declared_classes();
|
||||
$all_classes = array_combine(
|
||||
$declared_classes,
|
||||
array_fill(0, count($declared_classes), 0)
|
||||
);
|
||||
$mail_classes = db_select('registry', 'registry')
|
||||
->distinct()
|
||||
->fields('registry', array('name', 'filename'))
|
||||
->where("type=:type AND ( filename like :filename OR name like :name )",
|
||||
// Making the HUGE assumption that all classes which implement
|
||||
// MailSystemInterface have filenames containing '.mail.' or
|
||||
// classnames ending in 'MailSystem'.
|
||||
array(
|
||||
':type' => 'class',
|
||||
':name' => '%MailSystem',
|
||||
':filename' => '%.mail.%',
|
||||
)
|
||||
)
|
||||
->execute()
|
||||
->fetchAllKeyed();
|
||||
foreach ($mail_classes as $classname => $classfile) {
|
||||
if ( file_exists($classfile)
|
||||
&& drupal_autoload_class($classname)
|
||||
) {
|
||||
$all_classes[$classname] = 1;
|
||||
}
|
||||
}
|
||||
foreach ($all_classes as $classname => $autoload) {
|
||||
if ( ($autoload || preg_match('/MailSystem/', $classname))
|
||||
&& ($object = new $classname)
|
||||
&& ($object instanceof MailSystemInterface)
|
||||
) {
|
||||
$mailsystem_classes[$classname] = $classname;
|
||||
}
|
||||
elseif ($autoload) {
|
||||
// Clear classes that are no longer available.
|
||||
db_delete('registry')
|
||||
->condition('name', $classname)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
foreach (array_unique(mailsystem_get()) as $classname) {
|
||||
if (class_exists($classname)) {
|
||||
$mailsystem_classes[$classname] = $classname;
|
||||
}
|
||||
else {
|
||||
mailsystem_clear(array(mailsystem_default_id() => $classname));
|
||||
}
|
||||
}
|
||||
ksort($mailsystem_classes);
|
||||
}
|
||||
return $mailsystem_classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme_registry_alter().
|
||||
*/
|
||||
function mailsystem_theme_registry_alter(&$theme_registry) {
|
||||
module_load_include('inc', 'mailsystem', 'mailsystem.theme');
|
||||
return mailsystem_theme_theme_registry_alter($theme_registry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the key of the theme used to render the emails.
|
||||
*
|
||||
* @todo Add some kind of hook to let other modules alter this behavior.
|
||||
*/
|
||||
function mailsystem_get_mail_theme() {
|
||||
global $theme_key;
|
||||
$theme = variable_get('mailsystem_theme', 'current');
|
||||
switch ($theme) {
|
||||
case 'default':
|
||||
$theme = variable_get('theme_default', NULL);
|
||||
break;
|
||||
case 'current':
|
||||
$theme = $theme_key;
|
||||
break;
|
||||
case 'domain':
|
||||
// Fetch the theme for the current domain.
|
||||
if (module_exists('domain_theme')) {
|
||||
// Assign the selected theme, based on the active domain.
|
||||
global $_domain;
|
||||
$domain_theme = domain_theme_lookup($_domain['domain_id']);
|
||||
// The above returns -1 on failure.
|
||||
$theme = ($domain_theme != -1) ? $domain_theme['theme'] : $theme_key;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return $theme;
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* The theme system, which controls the output of email messages.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_theme_registry_alter().
|
||||
*/
|
||||
function mailsystem_theme_theme_registry_alter(&$theme_registry) {
|
||||
global $theme_key;
|
||||
static $recursion_prevention = FALSE;
|
||||
|
||||
// Prevent recursive execution.
|
||||
if ($recursion_prevention) {
|
||||
return;
|
||||
}
|
||||
$recursion_prevention = TRUE;
|
||||
$mailsystem_theme = mailsystem_get_mail_theme();
|
||||
|
||||
// Only take action if the mailsystem theme is not the current theme.
|
||||
if ($mailsystem_theme != $theme_key) {
|
||||
$themes = list_themes();
|
||||
// Get the mailsystem theme to be used for rendering emails.
|
||||
if (isset($themes[$mailsystem_theme])) {
|
||||
$theme = clone $themes[$mailsystem_theme];
|
||||
if (isset($theme)) {
|
||||
// Establish variables for further processing.
|
||||
$base_theme = array();
|
||||
if (isset($theme->base_themes)) {
|
||||
foreach (array_keys($theme->base_themes) as $base) {
|
||||
$base_theme[$base] = clone $themes[$base];
|
||||
}
|
||||
}
|
||||
if (isset($theme->base_theme) && !isset($base_theme[$theme->base_theme])) {
|
||||
$base_theme[$theme->base_theme] = clone $themes[$theme->base_theme];
|
||||
}
|
||||
if (isset($theme->engine)) {
|
||||
$theme_engine = $theme->engine;
|
||||
}
|
||||
|
||||
// Include template files to let _theme_load_registry add preprocess
|
||||
// functions.
|
||||
include_once(drupal_get_path('theme', $theme->name) . '/template.php');
|
||||
foreach ($base_theme as $base) {
|
||||
include_once(drupal_get_path('theme', $base->name) . '/template.php');
|
||||
}
|
||||
|
||||
// Get the theme_registry cache.
|
||||
$cache = _theme_load_registry($theme, $base_theme, $theme_engine);
|
||||
|
||||
// Change the registry for hooks with a 'mail theme' element.
|
||||
foreach ($theme_registry as $name => $hook) {
|
||||
if (!empty($hook['mail theme'])) {
|
||||
if (isset($cache[$name])) {
|
||||
$cache[$name]['includes'][] = drupal_get_path('theme', $theme->name) . '/template.php';
|
||||
foreach ($base_theme as $base) {
|
||||
$cache[$name]['includes'][] = drupal_get_path('theme', $base->name) . '/template.php';
|
||||
}
|
||||
// Change the current registry for the new record.
|
||||
$theme_registry[$name] = $cache[$name];
|
||||
}
|
||||
|
||||
// Look for template suggestions.
|
||||
foreach ($cache as $cache_name => $cache_hook) {
|
||||
if (strpos($cache_name, $name . '__') !== FALSE) {
|
||||
$cache_hook['includes'][] = drupal_get_path('theme', $theme->name) . '/template.php';
|
||||
foreach ($base_theme as $base) {
|
||||
$cache_hook['includes'][] = drupal_get_path('theme', $base->name) . '/template.php';
|
||||
}
|
||||
// Change the current registry for the new record.
|
||||
$theme_registry[$cache_name] = $cache_hook;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$recursion_prevention = FALSE;
|
||||
}
|
Reference in New Issue
Block a user