mirror of https://github.com/BOINC/boinc.git
Added HTML Purifier module; this is being tracked only because it otherwise requires manual installation of the HTMLPurifier library
(DBOINCP-188)
This commit is contained in:
parent
8a60393c8f
commit
8688e46439
|
@ -0,0 +1 @@
|
|||
library
|
|
@ -0,0 +1,40 @@
|
|||
6.x-2.4, released 2010-10-23
|
||||
- Fixed #839490; can't find library from install profile
|
||||
- Fixed #819728; make use of Filter.ExtractStyleBlocks. Thanks
|
||||
Vector- for contributing the patch.
|
||||
- Fixed #586746; Rate limit new version checks
|
||||
- Fixed #764974: Give friendly error message if running under PHP4
|
||||
- Deprecated Filter.YouTube in favor of SafeObject/FlashCompat.
|
||||
Thanks John Morahan for contributing the patch.
|
||||
|
||||
6.x-2.3, released 2010-06-09
|
||||
- Fixed #819914; version never updates
|
||||
|
||||
6.x-2.2, released 2010-06-04
|
||||
- More comprehensive cache clearing.
|
||||
- Fixed #659666; clearing caches missed HTML Purifier
|
||||
- Fixed #708266; decouple location of HTML Purifier library with
|
||||
libraries API.
|
||||
- Fixed #783066; new HTML Purifier version message too obnoxious.
|
||||
|
||||
6.x-2.1, released 2009-12-12
|
||||
- Ukranian translation by podarok
|
||||
- Renamed dashboard to HTML Purifier Dashboard, fixes bug #368468
|
||||
- Make installation process nicer by checking if library folder is setup, fixes bug #261874
|
||||
- Remove unnecessary version checks
|
||||
|
||||
6.x-2.0, released 2008-05-18
|
||||
# Drupal 6.x and HTML Purifier 3.1.0 are required
|
||||
! HTML Purifier now uses its native form function, so advanced configuration
|
||||
options are available. You can also define your own custom functions
|
||||
for configuration in the config/ directory.
|
||||
! Modified and better defaults selected for HTML Purifier.
|
||||
- HTML Purifier now maintains its own cache with a longer expiration time;
|
||||
this helps performance greatly.
|
||||
- DefinitionCache uses Drupal's caching system
|
||||
- HTML Purifier will check for new versions of the core library and display
|
||||
obnoxious warnings if it is out-of-date!
|
||||
- Uninstall function now obliterates HTML Purifier variables too.
|
||||
|
||||
1.0, released 2007-07-15 (not via Drupal.org)
|
||||
- Initial release, basic functionality implemented.
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
require_once 'HTMLPurifier/DefinitionCache.php';
|
||||
|
||||
/**
|
||||
* Cache handler that stores all data in drupals builtin cache
|
||||
*/
|
||||
class HTMLPurifier_DefinitionCache_Drupal extends HTMLPurifier_DefinitionCache
|
||||
{
|
||||
/**
|
||||
* Add an object to the cache without overwriting
|
||||
*/
|
||||
function add($def, $config) {
|
||||
if (!$this->checkDefType($def)) return;
|
||||
$key = $this->generateKey($config);
|
||||
|
||||
if ($this->fetchFromDrupalCache($key)) {
|
||||
// already cached
|
||||
return false;
|
||||
}
|
||||
$this->storeInDrupalCache($def, $key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unconditionally add an object to the cache, overwrites any existing object.
|
||||
*/
|
||||
function set($def, $config) {
|
||||
if (!$this->checkDefType($def)) return;
|
||||
$key = $this->generateKey($config);
|
||||
|
||||
$this->storeInDrupalCache($def, $key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace an object that already exists in the cache.
|
||||
*/
|
||||
function replace($def, $config) {
|
||||
if (!$this->checkDefType($def)) return;
|
||||
$key = $this->generateKey($config);
|
||||
|
||||
if (!$this->fetchFromDrupalCache($key)) {
|
||||
// object does not exist in cache
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->storeInDrupalCache($def, $key);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve an object from the cache
|
||||
*/
|
||||
function get($config) {
|
||||
$key = $this->generateKey($config);
|
||||
return $this->fetchFromDrupalCache($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an object from the cache
|
||||
*/
|
||||
function remove($config) {
|
||||
$key = $this->generateKey($config);
|
||||
cache_clear_all("htmlpurifier:$key", 'cache');
|
||||
return true;
|
||||
}
|
||||
|
||||
function flush($config) {
|
||||
cache_clear_all("htmlpurifier:*", 'cache', true);
|
||||
return true;
|
||||
}
|
||||
|
||||
function cleanup($config) {
|
||||
$res = db_query("SELECT cid FROM {cache} WHERE cid LIKE '%s%%'", 'htmlpurifier:');
|
||||
while ($row = db_fetch_object($res)) {
|
||||
$key = substr($row->cid, 13); // 13 == strlen('htmlpurifier:')
|
||||
if ($this->isOld($key, $config)) {
|
||||
cache_clear_all($row->cid, 'cache');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function fetchFromDrupalCache($key) {
|
||||
$cached = cache_get("htmlpurifier:$key");
|
||||
if ($cached) return unserialize($cached->data);
|
||||
return false;
|
||||
}
|
||||
|
||||
function storeInDrupalCache($def, $key) {
|
||||
cache_set("htmlpurifier:$key", serialize($def), 'cache', CACHE_PERMANENT);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
PREREQUISITES: Make sure you check HTML Purifier and make sure that you
|
||||
have fulfilled all of its requirements before running this. Specifically,
|
||||
you'll need the PHP extension ctype (in almost all PHP distributions),
|
||||
and it's nice to have dom and iconv.
|
||||
|
||||
* Place the htmlpurifier folder in your drupal modules directory.
|
||||
|
||||
* Download HTML Purifier from http://htmlpurifier.org/ You will need
|
||||
4.0.0 or later.
|
||||
|
||||
* There are two possible ways to install the HTML Purifier library.
|
||||
|
||||
1. Module directory installation. This means installing the library
|
||||
folder under the module directory. This way has the advantage of
|
||||
not depending on other modules. The issue is that when you
|
||||
upgrade the htmlpurifier module the HTML Purifier library gets
|
||||
removed and you have to re-extract the archive in the newly
|
||||
installed module directory.
|
||||
|
||||
2. The preferred way is making use of the libraries API,
|
||||
http://drupal.org/project/libraries. This makes the library
|
||||
available to all sites or to a specific site in a multisite
|
||||
Drupal setup. You'll need to download the libraries API module
|
||||
and enable it before enabling the htmlpurifier module so that in
|
||||
the install phase it can find the library.
|
||||
|
||||
Extract the library folder to sites/all/libraries or to
|
||||
sites/<site>/libraries for a specific site in a multisite Drupal
|
||||
setup.
|
||||
|
||||
The final setup should be, when making the library and module
|
||||
available to all sites:
|
||||
|
||||
sites/all/libraries/htmlpurifier/
|
||||
HTMLPurifier
|
||||
HTMLPurifier.autoload.php
|
||||
HTMLPurifier.auto.php
|
||||
HTMLPurifier.func.php
|
||||
HTMLPurifier.includes.php
|
||||
HTMLPurifier.kses.php
|
||||
HTMLPurifier.path.php
|
||||
HTMLPurifier.php
|
||||
HTMLPurifier.safe-includes.php
|
||||
|
||||
Now you can safely upgrade your htmlpurifier module without
|
||||
having to re-deploy the HTML Purifier library.
|
||||
|
||||
* Go to Administer > Site building > Modules and enable this module
|
||||
|
||||
* You can now create a new input format or add the HTML Purifier to an
|
||||
existing input format. It is recommended that you place HTML Purifier as
|
||||
the last filter in the input format. Reorder the filters if necessary.
|
||||
|
||||
WARNING: Due to HTML Purifier's caching mechanism, dynamic filters MUST NOT
|
||||
be placed before HTML Purifier.
|
|
@ -0,0 +1,274 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave,
|
||||
Cambridge, MA 02139, 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 Library 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
|
|
@ -0,0 +1,20 @@
|
|||
|
||||
TODO List
|
||||
|
||||
Non-code
|
||||
- Add better documentation about what's different about configuring
|
||||
the PHP and what's configuring the web interface
|
||||
- Make distinction between module and library clearer
|
||||
- Link to WYSIWYG editors, research integration prospects, and how
|
||||
they're handling security
|
||||
- http://drupal.org/project/htmlarea
|
||||
- http://drupal.org/project/fckeditor
|
||||
- http://drupal.org/project/tinymce
|
||||
- Competitors
|
||||
- http://drupal.org/project/safehtml
|
||||
|
||||
1.3
|
||||
- Improve help text (this might be a good addition to the HTML Purifier
|
||||
core). This would be for filter tips as well as for the form.
|
||||
- Compatibility
|
||||
- Paging comments
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
.hp-config {}
|
||||
|
||||
.hp-config tbody th {text-align:right; padding-right:0.5em; width:40%;}
|
||||
.hp-config thead {display:none;}
|
||||
.hp-config .namespace {background:#EDF1F3;}
|
||||
.hp-config .namespace th {text-align:center;}
|
||||
.hp-config .verbose {display:none;}
|
||||
.hp-config textarea {width:100%; max-width:30em;}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This file is a sample advanced PHP configuration file for the HTML Purifier
|
||||
* filter module. In reality, this file would be named N.php, where N is the
|
||||
* integer identifying the filter this is configuring. The configure page
|
||||
* for HTML Purifier (advanced) will tell you what file to copy this to.
|
||||
*
|
||||
* See this URI:
|
||||
*
|
||||
* http://htmlpurifier.org/live/configdoc/plain.html
|
||||
*
|
||||
* For full information about permitted directives. The most interesting ones
|
||||
* for custom configuration are ones with the 'mixed' type, as they cannot
|
||||
* be configured using the webform.
|
||||
*
|
||||
* @note
|
||||
* A number of directives have been predefined for you in order to better
|
||||
* work with Drupal. You can see what these defaults in the
|
||||
* _htmlpurifier_get_config() function in htmlpurifier.module.php.
|
||||
*
|
||||
* @warning
|
||||
* Please be mindful of the version of HTML Purifier you have installed!
|
||||
* All of the docs linked to are for the latest version of HTML Purifier;
|
||||
* your installation may or may not be up-to-date.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Accepts an HTMLPurifier_Config configuration object and configures it.
|
||||
*
|
||||
* @param $config
|
||||
* Instance of HTMLPurifier_Config to modify. See
|
||||
* http://htmlpurifier.org/doxygen/html/classHTMLPurifier__Config.html
|
||||
* for a full API.
|
||||
*
|
||||
* @note
|
||||
* No return value is needed, as PHP objects are passed by reference.
|
||||
*/
|
||||
function htmlpurifier_config_N($config) {
|
||||
// Set your configuration here:
|
||||
$config->set('Core', 'Lexer', 'DirectLex');
|
||||
// $config->set('Namespace', 'Directive', $value);
|
||||
|
||||
// Advanced users:
|
||||
// $def = $config->getDefinition('HTML');
|
||||
// For more information about this, see:
|
||||
// http://htmlpurifier.org/docs/enduser-customize.html
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
; $Id: htmlpurifier.info,v 1.6 2008/04/24 04:13:09 ezyang Exp $
|
||||
name = "HTML Purifier"
|
||||
description = "Filter that removes malicious HTML and ensures standards compliant output."
|
||||
core = 6.x
|
||||
php = 5.0.5
|
||||
|
||||
; Information added by drupal.org packaging script on 2010-10-23
|
||||
version = "6.x-2.4"
|
||||
core = "6.x"
|
||||
project = "htmlpurifier"
|
||||
datestamp = "1287798330"
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_schema().
|
||||
*/
|
||||
function htmlpurifier_schema() {
|
||||
$t = get_t();
|
||||
$schema['cache_htmlpurifier'] = drupal_get_schema_unprocessed('system', 'cache');
|
||||
$schema['cache_htmlpurifier']['description'] = $t(<<<DESCRIPTION
|
||||
Cache table for the HTML Purifier module just like cache_filter, except that
|
||||
cached text is stored permanently until flushed or manually invalidated.
|
||||
This helps prevent recurrent cache slams on pages with lots of segments of HTML.
|
||||
DESCRIPTION
|
||||
);
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_install().
|
||||
*/
|
||||
function htmlpurifier_install() {
|
||||
drupal_install_schema('htmlpurifier');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_uninstall().
|
||||
*/
|
||||
function htmlpurifier_uninstall() {
|
||||
drupal_uninstall_schema('htmlpurifier');
|
||||
db_query("DELETE FROM {variable} WHERE name LIKE 'htmlpurifier%%'");
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_requirements().
|
||||
*
|
||||
* Checks the version of HTML Purifier on install and issues an error if there is a problem
|
||||
*/
|
||||
function htmlpurifier_requirements($phase) {
|
||||
// This version of HTML Purifier is required
|
||||
static $req_version = '4.0.0';
|
||||
static $req_php_version = '5.0.0';
|
||||
$requirements = array();
|
||||
$t = get_t();
|
||||
|
||||
if (version_compare(phpversion(), $req_php_version) < 0) {
|
||||
$requirements['htmlpurifier_php'] = array (
|
||||
'title' => $t('PHP version for HTML Purifier library'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
'description' => $t('PHP version is too low to run HTML Purifier. HTML Purifier requires PHP 5 or later.'),
|
||||
);
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
// HACK: If libraries api module is not installed but available, load
|
||||
// it. This can arise when an install profile is installing multiple
|
||||
// modules, because the HTMLPurifier module does not publish a
|
||||
// libraries dependency in order to stay backwards-compatible. This
|
||||
// fixes Bug #839490.
|
||||
if (!function_exists('libraries_get_path') && file_exists(dirname(__FILE__) . '/../libraries/libraries.module')) {
|
||||
require_once(dirname(__FILE__) . '/../libraries/libraries.module');
|
||||
}
|
||||
|
||||
// If it's still not available, use something else
|
||||
$complain_loc = false;
|
||||
if (function_exists('libraries_get_path')) {
|
||||
$library_path = libraries_get_path('htmlpurifier');
|
||||
$using_libraries = true;
|
||||
if (!file_exists("$library_path/library/HTMLPurifier.auto.php")) {
|
||||
$library_path = dirname(__FILE__);
|
||||
$complain_loc = true;
|
||||
$using_libraries = false;
|
||||
}
|
||||
} else {
|
||||
$library_path = dirname(__FILE__);
|
||||
$using_libraries = false;
|
||||
}
|
||||
|
||||
$s = DIRECTORY_SEPARATOR;
|
||||
if (!file_exists("$library_path/library/HTMLPurifier.auto.php")) {
|
||||
$requirements['htmlpurifier_library'] = array (
|
||||
'title' => $t('HTML Purifier library'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
'description' => $t("Could not find HTML Purifier
|
||||
installation in @path. Please copy contents
|
||||
of the library folder in the HTML Purifier tarball or zip
|
||||
to this folder or ensure HTMLPurifier.auto.php exists.
|
||||
You can download HTML Purifier at
|
||||
<a href=\"http://htmlpurifier.org/download.html\">htmlpurifier.org</a>.", array('@path' => "$library_path{$s}library")
|
||||
),
|
||||
);
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
if ($complain_loc) {
|
||||
$requirements['htmlpurifier_library_loc'] = array(
|
||||
'title' => $t('HTML Purifier library location'),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
'description' => $t("The HTML Purifier library currently lives in
|
||||
<code>@oldpath</code>, but should actually be placed in the shared
|
||||
libraries API at <code>@newpath</code>. You should move the folder
|
||||
such that <code>@somefile</code> exists (you will need to create an
|
||||
<code>htmlpurifier</code> folder to hold the <code>library</code>
|
||||
folder). For future updates, you can simply replace the
|
||||
htmlpurifier folder with the htmlpurifier-x.y.z folder that a
|
||||
new HTML Purifier tarball unzips to (you'll be reminded in an
|
||||
update notification).",
|
||||
array(
|
||||
'@oldpath' => dirname(__FILE__) . '/library',
|
||||
'@newpath' => libraries_get_path('htmlpurifier') . '/library',
|
||||
'@somefile' => libraries_get_path('htmlpurifier') . '/library/HTMLPurifier.auto.php',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
if ($phase=='runtime') {
|
||||
$current = variable_get('htmlpurifier_version_current', FALSE);
|
||||
if (!$current) {
|
||||
$current = htmlpurifier_check_version();
|
||||
}
|
||||
$ours = variable_get('htmlpurifier_version_ours', FALSE);
|
||||
if (!$ours || version_compare($ours, $req_version, '<')) {
|
||||
// Can't use _htmlpurifier_load(), since it assumes a later
|
||||
// version
|
||||
require_once "$library_path/library/HTMLPurifier.auto.php";
|
||||
if (defined('HTMLPurifier::VERSION')) {
|
||||
$version = HTMLPurifier::VERSION;
|
||||
} else {
|
||||
$purifier = new HTMLPurifier;
|
||||
$version = $purifier->version;
|
||||
}
|
||||
variable_set('htmlpurifier_version_ours', $version);
|
||||
if (version_compare($version, $req_version, '<')) {
|
||||
|
||||
$requirements['htmlpurifier_library'] = array (
|
||||
'title' => $t('HTML Purifier library'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
'description' => $t("HTML Purifier @old is not compatible
|
||||
with this module: HTML Purifier <strong>@required</strong> or later is required.
|
||||
If the required version is a dev version, you will need to
|
||||
<a href=\"http://htmlpurifier.org/download.html#Git\">check
|
||||
code out of Git</a> or
|
||||
<a href=\"http://htmlpurifier.org/download.html#NightlyBuilds\">download a nightly</a>
|
||||
to use this module.", array('@old' => $version, '@required' => $req_version)
|
||||
),
|
||||
);
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$current) {
|
||||
$requirements['htmlpurifier_check'] = array(
|
||||
'title' => $t('HTML Purifier Library'),
|
||||
'value' => $ours,
|
||||
'description' => $t('Unable to check for the latest version of the
|
||||
HTML Purifier library. You will need to check manually at
|
||||
<a href="http://htmlpurifier.org">htmlpurifier.org</a> to find out if
|
||||
the version you are using is out of date.'),
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
);
|
||||
}
|
||||
elseif (!$ours || version_compare($current, $ours, '>')) {
|
||||
// Update our version number if it can't be found, or there's a
|
||||
// mismatch. This won't do anything if _htmlpurifier_load() has
|
||||
// already been called. An equivalent formulation would be
|
||||
// to always call _htmlpurifier_load() before retrieving the
|
||||
// variable, but this has the benefit of not always loading
|
||||
// HTML Purifier!
|
||||
_htmlpurifier_load();
|
||||
$ours = variable_get('htmlpurifier_version_ours', FALSE);
|
||||
}
|
||||
if ($current && $ours && version_compare($current, $ours, '>')) {
|
||||
$description = $t('Your HTML Purifier library is out of date. The
|
||||
latest version is %version, which you can download from <a
|
||||
href="http://htmlpurifier.org">htmlpurifier.org</a>. ',
|
||||
array('%version' => $current));
|
||||
if ($using_libraries) {
|
||||
$how_to_update = $t('To update, replace
|
||||
<code>%path</code> with the new directory the downloaded archive
|
||||
extracts into. ',
|
||||
array('%path' => libraries_get_path('htmlpurifier')));
|
||||
} else {
|
||||
$how_to_update = $t('To update, replace
|
||||
<code>%path/library/</code> with the <code>library/</code>
|
||||
directory from the downloaded archive. ',
|
||||
array('%path' => dirname(__FILE__)));
|
||||
}
|
||||
$warning = $t('If you do not perform this operation correctly,
|
||||
your Drupal installation will stop working. Ensure that
|
||||
<code>%path/library/HTMLPurifier.auto.php</code> exists after
|
||||
the upgrade.',
|
||||
array('%path' => $library_path));
|
||||
$requirements['htmlpurifier_version'] = array(
|
||||
'title' => $t('HTML Purifier Library'),
|
||||
'value' => $ours,
|
||||
'description' => $description . $how_to_update . $warning,
|
||||
'severity' => REQUIREMENT_WARNING,
|
||||
);
|
||||
}
|
||||
if (count($requirements) == 0) {
|
||||
$requirements['htmlpurifier'] = array(
|
||||
'severity' => REQUIREMENT_OK,
|
||||
'title' => $t('HTML Purifier Library'),
|
||||
'value' => $ours,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $requirements;
|
||||
}
|
||||
|
||||
// -- Update functions ------------------------------------------------------ //
|
||||
|
||||
function htmlpurifier_update_6200() {
|
||||
// Migrate any old-style filter variables to new style.
|
||||
$formats = filter_formats();
|
||||
foreach ($formats as $format => $info) {
|
||||
$filters = filter_list_format($format);
|
||||
if (!isset($filters['htmlpurifier/0'])) continue;
|
||||
$config_data = array(
|
||||
'URI.DisableExternalResources' => variable_get("htmlpurifier_externalresources_$format", TRUE),
|
||||
'Attr.EnableID' => variable_get("htmlpurifier_enableattrid_$format", FALSE),
|
||||
'AutoFormat.Linkify' => variable_get("htmlpurifier_linkify_$format", TRUE),
|
||||
'AutoFormat.AutoParagraph' => variable_get("htmlpurifier_autoparagraph_$format", TRUE),
|
||||
'Null_HTML.Allowed' => !variable_get("htmlpurifier_allowedhtml_enabled_$format", FALSE),
|
||||
'HTML.Allowed' => variable_get("htmlpurifier_allowedhtml_$format", ''),
|
||||
'Filter.YouTube' => variable_get("htmlpurifier_preserveyoutube_$format", FALSE),
|
||||
);
|
||||
if (defined('HTMLPurifier::VERSION') && version_compare(HTMLPurifier::VERSION, '3.1.0-dev', '>=')) {
|
||||
$config_data['HTML.ForbiddenElements'] = variable_get("htmlpurifier_forbiddenelements_$format", '');
|
||||
$config_data['HTML.ForbiddenAttributes'] = variable_get("htmlpurifier_forbiddenattributes_$format", '');
|
||||
}
|
||||
variable_set("htmlpurifier_config_$format", $config_data);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
function htmlpurifier_update_6201() {}
|
|
@ -0,0 +1,523 @@
|
|||
<?php
|
||||
// $Id: htmlpurifier.module,v 1.21 2010/09/28 14:55:02 ezyang Exp $
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Implements HTML Purifier as a Drupal filter.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// -- HOOK IMPLEMENTATIONS -------------------------------------------------- //
|
||||
|
||||
/**
|
||||
* Implementation of hook_flush_caches().
|
||||
*/
|
||||
function htmlpurifier_flush_caches() {
|
||||
return array('cache_htmlpurifier');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_help().
|
||||
*/
|
||||
function htmlpurifier_help($path, $arg) {
|
||||
$output = NULL;
|
||||
switch ($path) {
|
||||
case 'admin/modules#htmlpurifier':
|
||||
$output = t('Filter that removes malicious HTML and ensures standards compliant output.');
|
||||
break;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_cron().
|
||||
*/
|
||||
function htmlpurifier_cron() {
|
||||
// Force an attempt at checking for a new version; this is safe to do in
|
||||
// hook_cron because a slow timeout will not degrade the user experience.
|
||||
htmlpurifier_check_version(TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for updates to the HTML Purifier library.
|
||||
*/
|
||||
function htmlpurifier_check_version($force = FALSE) {
|
||||
if ($force || !variable_get('htmlpurifier_version_check_failed', FALSE)) {
|
||||
// Maybe this should be changed in the future:
|
||||
$result = drupal_http_request('http://htmlpurifier.org/live/VERSION');
|
||||
if ($result->code == 200) {
|
||||
$version = trim($result->data);
|
||||
variable_set('htmlpurifier_version_check_failed', FALSE);
|
||||
variable_set('htmlpurifier_version_current', $version);
|
||||
return $version;
|
||||
}
|
||||
else {
|
||||
variable_set('htmlpurifier_version_check_failed', TRUE);
|
||||
// Delete any previously known "latest" version so that people can be
|
||||
// alerted if a problem appears on a previously working site.
|
||||
variable_del('htmlpurifier_version_current');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_filter().
|
||||
*/
|
||||
function htmlpurifier_filter($op, $delta = 0, $format = -1, $text = '') {
|
||||
switch ($op) {
|
||||
case 'list':
|
||||
return array(0 => t('HTML Purifier'), 1 => t('HTML Purifier (advanced)'));
|
||||
|
||||
case 'no cache':
|
||||
// Since HTML Purifier implements its own caching layer, having filter
|
||||
// cache it again is wasteful. Returns FALSE if double caching is permitted.
|
||||
return !variable_get("htmlpurifier_doublecache", FALSE);
|
||||
|
||||
case 'description':
|
||||
$common = t(
|
||||
'Removes malicious HTML code and ensures that the output '.
|
||||
'is standards compliant. <strong>Warning:</strong> For performance '.
|
||||
'reasons, please ensure that there are no highly dynamic filters before HTML Purifier. '
|
||||
);
|
||||
switch ($delta) {
|
||||
case 0:
|
||||
return $common;
|
||||
case 1:
|
||||
return $common . t('<em>This version has advanced configuration options, do not enable both at the same time.</em>');
|
||||
}
|
||||
|
||||
case 'prepare':
|
||||
return $text;
|
||||
|
||||
case 'process':
|
||||
return _htmlpurifier_process($text, $format);
|
||||
|
||||
case 'settings':
|
||||
return _htmlpurifier_settings($delta, $format);
|
||||
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_filter_tips().
|
||||
*/
|
||||
function htmlpurifier_filter_tips($delta, $format, $long = FALSE) {
|
||||
if (variable_get("htmlpurifier_help_$format", TRUE)) {
|
||||
return t('HTML tags will be transformed to conform to HTML standards.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_nodeapi().
|
||||
*/
|
||||
function htmlpurifier_nodeapi(&$node, $op, $a3, $a4) {
|
||||
if ($op == 'view') {
|
||||
|
||||
// Should we load CSS cache data from teaser or body?
|
||||
if ($a3 == TRUE) {
|
||||
_htmlpurifier_add_css( $node->content['teaser']['#value'], $node->nid );
|
||||
}
|
||||
else {
|
||||
_htmlpurifier_add_css( $node->content['body']['#value'], $node->nid );
|
||||
}
|
||||
}
|
||||
// @todo: Deal with CCK fields - probably needs to go in op alter?
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for hook_nodeapi
|
||||
* Finds extracted style blocks based on a cache link left by hook_filter
|
||||
* Aggregates the extracted style blocks and adds them to the document head
|
||||
* Also removes the cache link left in hook_filter to the CSS cache
|
||||
*
|
||||
* @param string &$field
|
||||
* Field to process, this should be the actual field value
|
||||
* ex. $node->content['body']['#value']
|
||||
*
|
||||
* @param int $nid
|
||||
* Node ID of the node to which these stylesheets belong
|
||||
* Since filters don't know their node context, we have to use a token
|
||||
* to generate the stylesheet scope, and replace it in hook_nodeapi
|
||||
*/
|
||||
function _htmlpurifier_add_css( &$field, $nid ) {
|
||||
|
||||
// Some basic validation to assure we really got a rendered field
|
||||
if (!is_string($field)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cache_matches = array();
|
||||
$cache_match = preg_match('#<!-- HTML Purifier Cache \#([-\w]*:[\w]*) -->#', $field, $cache_matches);
|
||||
|
||||
// If there's an HTML Purifier Cache #, we need to load CSSTidy blocks
|
||||
if ($cache_match == 1) {
|
||||
$cid = 'css:' . $cache_matches[1];
|
||||
$old = cache_get($cid, 'cache_htmlpurifier');
|
||||
|
||||
// We should always have some cached style blocks to load, but if we don't, just bail
|
||||
if ($old) {
|
||||
$styles = array();
|
||||
$style_rendered = '';
|
||||
foreach($old->data as $i => $style) {
|
||||
|
||||
// Replace Node ID tokens if necessary, otherwise use cached CSSTidy blocks
|
||||
// NOTE: This token is forgeable, but we expect that if the user
|
||||
// is able to invoke this transformation, it will be relatively
|
||||
// harmless.
|
||||
if (strpos($style, '[%HTMLPURIFIER:NID%]') !== FALSE) {
|
||||
$styles[$i] = str_replace('[%HTMLPURIFIER:NID%]', (int) $nid, $style);
|
||||
}
|
||||
else {
|
||||
$styles[$i] = $style;
|
||||
}
|
||||
|
||||
// Save any CSSTidy blocks we find to be rendered in the document head
|
||||
if (!empty($style)) {
|
||||
$style_rendered .= $styles[$i] . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Add the rendered stylesheet to the document header
|
||||
if ($style_rendered != '') {
|
||||
drupal_set_html_head('<style type="text/css">' ."\n". '<!--' ."\n". $style_rendered . '--></style>');
|
||||
}
|
||||
|
||||
// Remove the HTML Purifier cache key from the field argument
|
||||
$field = str_replace($cache_matches[0], '', $field);
|
||||
|
||||
// If we had to update CSSTidy blocks, cache the results
|
||||
if ($old->data != $styles) {
|
||||
cache_set($cid, $styles, 'cache_htmlpurifier', CACHE_PERMANENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -- INTERNAL FUNCTIONS ---------------------------------------------------- //
|
||||
|
||||
/**
|
||||
* Processes HTML according to a format and returns purified HTML. Makes a
|
||||
* cache pass if possible.
|
||||
*
|
||||
* @param string $text
|
||||
* Text to purify
|
||||
* @param int $format
|
||||
* Input format corresponding to HTML Purifier's configuration.
|
||||
* @param boolean $cache
|
||||
* Whether or not to check the cache.
|
||||
*
|
||||
* @note
|
||||
* We ignore $delta because the only difference it makes is in the configuration
|
||||
* screen.
|
||||
*/
|
||||
function _htmlpurifier_process($text, $format, $cache = TRUE) {
|
||||
|
||||
if ($cache) {
|
||||
$cid = $format . ':' . md5($text);
|
||||
$old = cache_get($cid, 'cache_htmlpurifier');
|
||||
if ($old) return $old->data;
|
||||
}
|
||||
|
||||
_htmlpurifier_load();
|
||||
$config = _htmlpurifier_get_config($format);
|
||||
|
||||
// If ExtractStyleBlocks is enabled, we'll need to do a bit more for CSSTidy
|
||||
$config_extractstyleblocks = $config->get('Filter.ExtractStyleBlocks');
|
||||
|
||||
// Maybe this works if CSSTidy is at root? CSSTidy could be other places though
|
||||
if ($config_extractstyleblocks == true) {
|
||||
_htmlpurifier_load_csstidy();
|
||||
}
|
||||
|
||||
$purifier = new HTMLPurifier($config);
|
||||
$ret = $purifier->purify($text);
|
||||
|
||||
// If using Filter.ExtractStyleBlocks we need to handle the CSSTidy output
|
||||
if ($config_extractstyleblocks == true) {
|
||||
|
||||
// We're only going to bother if we're caching! - no caching? no style blocks!
|
||||
if ($cache) {
|
||||
|
||||
// Get style blocks, cache them, and help hook_nodeapi find the cache
|
||||
$styles = $purifier->context->get('StyleBlocks');
|
||||
cache_set('css:' . $cid, $styles, 'cache_htmlpurifier', CACHE_PERMANENT);
|
||||
$ret = '<!-- HTML Purifier Cache #' . $cid . ' -->' . $ret;
|
||||
}
|
||||
}
|
||||
|
||||
if ($cache) cache_set($cid, $ret, 'cache_htmlpurifier', CACHE_PERMANENT);
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the HTML Purifier library, and performs global initialization.
|
||||
*/
|
||||
function _htmlpurifier_load() {
|
||||
static $done = false;
|
||||
if ($done) {
|
||||
return;
|
||||
}
|
||||
$done = true;
|
||||
$module_path = drupal_get_path('module', 'htmlpurifier');
|
||||
$library_path = $module_path;
|
||||
if (function_exists('libraries_get_path')) {
|
||||
$library_path = libraries_get_path('htmlpurifier');
|
||||
// This may happen if the user has HTML Purifier installed under the
|
||||
// old configuration, but also installed libraries and forgot to
|
||||
// move it over. There is code for emitting errors in
|
||||
// htmlpurifier.install when this is the case.
|
||||
if (!file_exists("$library_path/library/HTMLPurifier.auto.php")) {
|
||||
$library_path = $module_path;
|
||||
}
|
||||
}
|
||||
|
||||
if (version_compare(phpversion(), '5') < 0) {
|
||||
// If your version of PHP is too old, you're going to fail anyway
|
||||
// when you attempt to include the HTML Purifier library, so we
|
||||
// might as well try to give a useful error message.
|
||||
echo 'Your version of PHP is too old to run HTML Purifier, needs PHP 5 or later';
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once "$library_path/library/HTMLPurifier.auto.php";
|
||||
require_once "$module_path/HTMLPurifier_DefinitionCache_Drupal.php";
|
||||
|
||||
$factory = HTMLPurifier_DefinitionCacheFactory::instance();
|
||||
$factory->register('Drupal', 'HTMLPurifier_DefinitionCache_Drupal');
|
||||
|
||||
// Register the version as a variable:
|
||||
variable_set('htmlpurifier_version_ours', HTMLPurifier::VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the HTMLPurifier_Config object corresponding to an input format.
|
||||
* @param int $format
|
||||
* Input format.
|
||||
* @return
|
||||
* Instance of HTMLPurifier_Config.
|
||||
*/
|
||||
function _htmlpurifier_get_config($format) {
|
||||
|
||||
$config = HTMLPurifier_Config::createDefault();
|
||||
|
||||
$config->set('AutoFormat.AutoParagraph', TRUE);
|
||||
$config->set('AutoFormat.Linkify', TRUE);
|
||||
$config->set('HTML.Doctype', 'XHTML 1.0 Transitional'); // Probably
|
||||
$config->set('Core.AggressivelyFixLt', TRUE);
|
||||
$config->set('Cache.DefinitionImpl', 'Drupal');
|
||||
|
||||
// Filter HTML doesn't allow external images, so neither will we...
|
||||
// for now. This can be configured off.
|
||||
$config->set('URI.DisableExternalResources', TRUE);
|
||||
|
||||
if (!empty($_SERVER['SERVER_NAME'])) {
|
||||
// SERVER_NAME is more reliable than HTTP_HOST
|
||||
$config->set('URI.Host', $_SERVER['SERVER_NAME']);
|
||||
}
|
||||
|
||||
if (defined('LANGUAGE_RTL') && $GLOBALS['language']->direction === LANGUAGE_RTL) {
|
||||
$config->set('Attr.DefaultTextDir', 'rtl');
|
||||
}
|
||||
|
||||
if ($config_function = _htmlpurifier_config_load($format)) {
|
||||
$config_function($config);
|
||||
} else {
|
||||
$config_data = variable_get("htmlpurifier_config_$format", FALSE);
|
||||
if (!empty($config_data['Filter.ExtractStyleBlocks'])) {
|
||||
if (!_htmlpurifier_load_csstidy()) {
|
||||
$config_data['Filter.ExtractStyleBlocks'] = '0';
|
||||
drupal_set_message("Could not enable ExtractStyleBlocks because CSSTidy was not installed. You can download CSSTidy module from <a href='http://drupal.org/project/csstidy'>http://drupal.org/project/csstidy</a>", 'error', FALSE);
|
||||
}
|
||||
}
|
||||
// {FALSE, TRUE, FALSE} = {no index, everything is allowed, don't do mq fix}
|
||||
$config->mergeArrayFromForm($config_data, FALSE, TRUE, FALSE);
|
||||
}
|
||||
|
||||
return $config;
|
||||
|
||||
}
|
||||
|
||||
function _htmlpurifier_load_csstidY() {
|
||||
// If CSSTidy module is installed, it should have a copy we can use
|
||||
$csstidy_path = drupal_get_path('module', 'csstidy') .'/csstidy';
|
||||
|
||||
// Some future-proofing for library path
|
||||
if (function_exists('libraries_get_path')) {
|
||||
$csstidy_library = libraries_get_path('csstidy');
|
||||
if (file_exists("$csstidy_library/class.csstidy.php")) {
|
||||
$csstidy_path = $csstidy_library;
|
||||
}
|
||||
}
|
||||
|
||||
// Load CSSTidy if we can find it
|
||||
if (file_exists("$csstidy_path/class.csstidy.php")) {
|
||||
require_once "$csstidy_path/class.csstidy.php";
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the configuration function for $format, or FALSE if none
|
||||
* exists. Function name will be htmlpurifier_config_N.
|
||||
*
|
||||
* @param int $format
|
||||
* Integer format to check function for.
|
||||
* @return
|
||||
* String function name for format, or FALSE if none.
|
||||
*/
|
||||
function _htmlpurifier_config_load($format) {
|
||||
$config_file = drupal_get_path('module', 'htmlpurifier') ."/config/$format.php";
|
||||
$config_function = "htmlpurifier_config_$format";
|
||||
if (
|
||||
!function_exists($config_function) &&
|
||||
file_exists($config_file)
|
||||
) {
|
||||
include_once $config_file;
|
||||
}
|
||||
return function_exists($config_function) ? $config_function : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a settings form for configuring HTML Purifier.
|
||||
* @param int $delta
|
||||
* Whether or not to use advanced form (1) or not (0).
|
||||
* @param int $format
|
||||
* Input format being configured.
|
||||
* @return
|
||||
* Form API array.
|
||||
*/
|
||||
function _htmlpurifier_settings($delta, $format) {
|
||||
_htmlpurifier_load();
|
||||
|
||||
// Dry run, testing for errors:
|
||||
_htmlpurifier_process('', $format, FALSE);
|
||||
|
||||
$module_path = drupal_get_path('module', 'htmlpurifier');
|
||||
drupal_add_css("$module_path/config-form.css");
|
||||
// Makes all configuration links open in new windows; can safe lots of grief!
|
||||
drupal_add_js('$(function(){$(".hp-config a").click(function(){window.open(this.href);return false;});});', 'inline');
|
||||
drupal_add_js(HTMLPurifier_Printer_ConfigForm::getJavaScript(), 'inline');
|
||||
|
||||
$form = array();
|
||||
|
||||
$form['dashboard'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('HTML Purifier Dashboard'),
|
||||
'#collapsible' => true,
|
||||
);
|
||||
$form['dashboard']["enter_hack"] = array(
|
||||
// hack to make normal form submission when <ENTER> is pressed
|
||||
'#value' => '<input type="submit" name="op" id="edit-submit" value="Save configuration" class="form-submit" style="display:none;" />',
|
||||
);
|
||||
$form['dashboard']["htmlpurifier_clear_cache"] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Clear cache (Warning: Can result in performance degradation)'),
|
||||
'#submit' => array('_htmlpurifier_clear_cache')
|
||||
);
|
||||
|
||||
$form['htmlpurifier'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('HTML Purifier'),
|
||||
'#collapsible' => TRUE,
|
||||
);
|
||||
$form['htmlpurifier']["htmlpurifier_help_$format"] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display help text'),
|
||||
'#default_value' => variable_get("htmlpurifier_help_$format", TRUE),
|
||||
'#description' => t('If enabled, a short note will be added to the filter tips explaining that HTML will be transformed to conform with HTML standards. You may want to disable this option when the HTML Purifier is used to check the output of another filter like BBCode.'),
|
||||
);
|
||||
if ($config_function = _htmlpurifier_config_load($format)) {
|
||||
$form['htmlpurifier']['notice'] = array(
|
||||
'#type' => 'markup',
|
||||
'#value' => t('<div>Configuration function <code>!function()</code> is already defined. To edit HTML Purifier\'s configuration, edit the corresponding configuration file, which is usually <code>htmlpurifier/config/!format.php</code>. To restore the web configuration form, delete or rename this file.</div>',
|
||||
array('!function' => $config_function, '!format' => $format)),
|
||||
);
|
||||
} else {
|
||||
if ($delta == 0) {
|
||||
$title = t('Configure HTML Purifier');
|
||||
$allowed = array(
|
||||
'URI.DisableExternalResources',
|
||||
'URI.DisableResources',
|
||||
'URI.Munge',
|
||||
'Attr.EnableID',
|
||||
'HTML.Allowed',
|
||||
'HTML.ForbiddenElements',
|
||||
'HTML.ForbiddenAttributes',
|
||||
'HTML.SafeObject',
|
||||
'Output.FlashCompat',
|
||||
'AutoFormat.RemoveEmpty',
|
||||
'AutoFormat.Linkify',
|
||||
'AutoFormat.AutoParagraph',
|
||||
);
|
||||
} else {
|
||||
$title = t('Advanced configuration options');
|
||||
$allowed = TRUE;
|
||||
$form['htmlpurifier']["htmlpurifier_doublecache"] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Allow double caching'),
|
||||
'#default_value' => variable_get("htmlpurifier_doublecache", FALSE),
|
||||
'#description' => t('If enabled, HTML Purifier will tell filter that its output is cacheable. This is not usually necessary, because HTML Purifier maintains its own cache, but may be helpful if you have later filters that need to be cached. Warning: this applies to ALL filters, not just this one'),
|
||||
);
|
||||
}
|
||||
|
||||
$intro =
|
||||
'<div class="form-item"><h3>'.
|
||||
$title.
|
||||
'</h3><div class="description">'.
|
||||
t('Please click on a directive name for more information on what it does before enabling or changing anything! Changes will not apply to old entries until you clear the cache (see the dashboard)').
|
||||
'</div></div>';
|
||||
|
||||
$config = _htmlpurifier_get_config($format);
|
||||
$config_form = new HTMLPurifier_Printer_ConfigForm(
|
||||
"htmlpurifier_config_$format", 'http://htmlpurifier.org/live/configdoc/plain.html#%s'
|
||||
);
|
||||
$form['htmlpurifier']["htmlpurifier_config_$format"] = array(
|
||||
'#value' => $intro . $config_form->render($config, $allowed, FALSE),
|
||||
'#after_build' => array('_htmlpurifier_config_hack'),
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills out the form state with extra post data originating from the
|
||||
* HTML Purifier configuration form. This is an #after_build hook function.
|
||||
*
|
||||
* @warning
|
||||
* If someone ever gets the smart idea of changing the parameters to
|
||||
* this function, I'm SOL! ;-)
|
||||
*/
|
||||
function _htmlpurifier_config_hack($form_element, &$form_state) {
|
||||
$key = $form_element['#parents'][0];
|
||||
if (!empty($form_element['#post']) && isset($form_element['#post'][$key])) {
|
||||
$form_state['values'][$key] = $form_element['#post'][$key];
|
||||
}
|
||||
foreach ($form_state['values'] as $i => $config_data) {
|
||||
if (!is_array($config_data)) continue;
|
||||
if (!empty($config_data['Filter.ExtractStyleBlocks'])) {
|
||||
if (!empty($config_data['Null_Filter.ExtractStyleBlocks.Scope'])) {
|
||||
drupal_set_message("You have not set <code>Filter.ExtractStyleBlocks.Scope</code>; this means that users can add CSS that affects all of your Drupal theme and not just their content block. It is recommended to set this to <code>#node-[%HTMLPURIFIER:NID%]</code> (including brackets) which will automatically ensure that CSS directives only apply to their node.", 'warning', FALSE);
|
||||
} elseif (!isset($config_data['Filter.ExtractStyleBlocks.Scope']) || $config_data['Filter.ExtractStyleBlocks.Scope'] !== '#node-[%HTMLPURIFIER:NID%]') {
|
||||
drupal_set_message("You have enabled Filter.ExtractStyleBlocks.Scope, but you did not set it to <code>#node-[%HTMLPURIFIER:NID%]</code>; CSS may not work unless you have special theme support.", 'warning', FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $form_element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the HTML Purifier internal Drupal cache.
|
||||
*/
|
||||
function _htmlpurifier_clear_cache($form, &$form_state) {
|
||||
drupal_set_message("Cache cleared");
|
||||
db_query("DELETE FROM {cache_htmlpurifier}");
|
||||
db_query("DELETE FROM {cache} WHERE cid LIKE '%s%%'", 'htmlpurifier:');
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
# $Id: uk.po,v 1.1.2.2 2009/09/16 17:31:54 podarok Exp $
|
||||
#
|
||||
# Ukrainian translation of Drupal (general)
|
||||
# Copyright YEAR NAME <EMAIL@ADDRESS>
|
||||
# Generated from files:
|
||||
# htmlpurifier.module,v 1.8 2009/07/09 23:57:44 ezyang
|
||||
# htmlpurifier.info,v 1.6 2008/04/24 04:13:09 ezyang
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: html purufuer drupal module\n"
|
||||
"POT-Creation-Date: 2009-09-16 20:13+0300\n"
|
||||
"PO-Revision-Date: 2009-09-16 20:24+0200\n"
|
||||
"Last-Translator: podarok <podarok@ua.fm>\n"
|
||||
"Language-Team: Ukrainian <podarok@ua.fm>\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=utf-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: nplurals=3; plural=((((n%10)==1)&&((n%100)!=11))?(0):(((((n%10)>=2)&&((n%10)<=4))&&(((n%100)<10)||((n%100)>=20)))?(1):2));\n"
|
||||
"X-Poedit-Language: Ukrainian\n"
|
||||
"X-Poedit-Country: UKRAINE\n"
|
||||
"X-Poedit-SourceCharset: utf-8\n"
|
||||
|
||||
#: htmlpurifier.module:20
|
||||
#: htmlpurifier.info:0
|
||||
msgid "Filter that removes malicious HTML and ensures standards compliant output."
|
||||
msgstr "Фільтр, що видаляє шкідливий HTML і сприяє збереженню стандартів виводу"
|
||||
|
||||
#: htmlpurifier.module:74;263
|
||||
#: htmlpurifier.info:0
|
||||
msgid "HTML Purifier"
|
||||
msgstr "HTML Чистильщик"
|
||||
|
||||
#: htmlpurifier.module:74
|
||||
msgid "HTML Purifier (advanced)"
|
||||
msgstr "HTML Чистильщик (розширений)"
|
||||
|
||||
#: htmlpurifier.module:91
|
||||
msgid "<em>This version has advanced configuration options, do not enable both at the same time.</em>"
|
||||
msgstr "<em>Ця версія має додаткові можливості, не вмикаєте обидві одночасно</em>"
|
||||
|
||||
#: htmlpurifier.module:113
|
||||
msgid "HTML tags will be transformed to conform to HTML standards."
|
||||
msgstr "HTML теги будуть перетворені у відповідності до стандартів HTML "
|
||||
|
||||
#: htmlpurifier.module:268
|
||||
msgid "Display help text"
|
||||
msgstr "Відображення тексту допомоги"
|
||||
|
||||
#: htmlpurifier.module:270
|
||||
msgid "If enabled, a short note will be added to the filter tips explaining that HTML will be transformed to conform with HTML standards. You may want to disable this option when the HTML Purifier is used to check the output of another filter like BBCode."
|
||||
msgstr "Якщо увімкнено, короткі нотатки будуть додані до підказок фільтрів, що пояснюватимуть яким чином HTML буде трансформовано до стандартів. Ви можете вимкнути це в випадках, якщо Чистильщик використовуватиметься для виводу інших фільтрів, наприклад BBCode."
|
||||
|
||||
#: htmlpurifier.module:276
|
||||
msgid "<div>Configuration function <code>!function()</code> is already defined. To edit HTML Purifier's configuration, edit the corresponding configuration file, which is usually <code>htmlpurifier/config/!format.php</code>. To restore the web configuration form, delete or rename this file.</div>"
|
||||
msgstr "<div>Функція налагодження <code>!function()</code> вже зазначена. Для правки параметрів HTML Чистильщика, змінюйте вкладений файл налаштувань, що зазвичай є <code>htmlpurifier/config/!format.php</code>. Для відновлення параметрів форми налаштування, стріть або перейменуйте цей файл.</div>"
|
||||
|
||||
#: htmlpurifier.module:281
|
||||
msgid "Configure HTML Purifier"
|
||||
msgstr "Управління модулем HTML Чистильщик"
|
||||
|
||||
#: htmlpurifier.module:296
|
||||
msgid "Advanced configuration options"
|
||||
msgstr "Розширені налагодження"
|
||||
|
||||
#: htmlpurifier.module:300
|
||||
msgid "Allow double caching"
|
||||
msgstr "Дозвіл на подвійне кешування"
|
||||
|
||||
#: htmlpurifier.module:302
|
||||
msgid "If enabled, HTML Purifier will tell filter that its output is cacheable. This is not usually necessary, because HTML Purifier maintains its own cache, but may be helpful if you have later filters that need to be cached."
|
||||
msgstr "Якщо увімкнено, HTML Чистильщик буде повідомляти, що вивід кешований. Це не є необхідно, бо HTML Чистильщик володіє власним кешуванням, але може бути корисно, якщо Ви маєте подальші фільтри, що потребують кешування."
|
||||
|
||||
#: htmlpurifier.module:310
|
||||
msgid "Please click on a directive name for more information on what it does before enabling or changing anything!"
|
||||
msgstr "Тисніть на імя для додаткової інформації для того, що це таке, переж вмиканням та змінюванням будь чого"
|
||||
|
||||
#: htmlpurifier.module:0
|
||||
msgid "htmlpurifier"
|
||||
msgstr "html-чистильщик"
|
||||
|
Loading…
Reference in New Issue