Welcome! » Log In » Create A New Profile

Using the MODx plug in

Posted by betoranaldi 
Using the MODx plug in
June 04, 2008 12:11PM

Using the directions found on http://htmlpurifier.org/svnroot/htmlpurifier/trunk/plugins/modx.txt I installed a plug in with my modxcms installation.

now when I try to save content I get the following error:

Fatal error: Class 'HTMLPurifier_Config' not found in /home/canvasli/public_html/dev/assets/plugins/htmlpurifier/library/HTMLPurifier.php on line 90

Also how would I go about customizing this plugin to linkify and other items? something like this?

$e = &$modx->Event;
if ($e->name == 'OnBeforeDocFormSave') {
    global $content;
    
    set_include_path('../assets/plugins/htmlpurifier/library/'
       . PATH_SEPARATOR . get_include_path());
    include_once 'HTMLPurifier.php';
    $purifier = new HTMLPurifier();
	
	$config = HTMLPurifier_Config::createDefault();
	$config->set('HTML', 'DefinitionID', 'filtro xuletas');
	$config->set('HTML', 'DefinitionRev', 1);
	$def = $config->getHTMLDefinition(true);
		
		class HTMLPurifier_AttrTransform_AValidator extends HTMLPurifier_AttrTransform
		{
			var $name = 'Link validation';

			function transform($attr, $config, $context) {
				$attr['target'] = '_blank';
				$attr['rel'] = 'nofollow';
				return $attr;
			}
		}

	$a = $def->addBlankElement('a');
	$a->attr['rel'] = 'Enum#nofollow';
	$a->attr['target'] = 'Enum#_blank';
	$a->attr_transform_post[] = new HTMLPurifier_AttrTransform_AValidator();
	
	
    static $magic_quotes = null;
    if ($magic_quotes === null) {
        // this is an ugly hack because this hook hasn't
        // had the backslashes removed yet when magic_quotes_gpc is on,
        // but HTMLPurifier must not have the quotes slashed.
        $magic_quotes = get_magic_quotes_gpc();
    }
    
    if ($magic_quotes) $content = stripslashes($content);
    $content = $purifier->purify($content);
    if ($magic_quotes) $content = addslashes($content);
	
}
Re: Using the MODx plug in
June 04, 2008 06:27PM

Replace:

set_include_path('../assets/plugins/htmlpurifier/library/'
       . PATH_SEPARATOR . get_include_path());
    include_once 'HTMLPurifier.php';

with

    include_once '../assets/plugins/htmlpurifier/library/HTMLPurifier.php';

The plugin is definitely due for some updating. If it still doesn't work, punt it back here please.

As for customization, you'll want to add calls to $config (usually set) based on the configuration documentation. See http://htmlpurifier.org/docs.html . Ideally, however, Modx should be using our shiny and ultra-convenient configuration form. Will look into that as well.

Re: Using the MODx plug in
June 04, 2008 06:52PM

I'm afraid that didn't fix my problem. I still get:

Fatal error: Class 'HTMLPurifier_Config' not found in /home/canvasli/public_html/dev/assets/plugins/htmlpurifier/library/HTMLPurifier.php on line 90

I will try to fool around with it some more tonight and see if I can resolve the issue.

-Brian

Re: Using the MODx plug in
June 04, 2008 06:54PM

Big typo, my apologies.

 include_once '../assets/plugins/htmlpurifier/library/HTMLPurifier.auto.php';

The .auto was what was going to fix the issue ^^".

Re: Using the MODx plug in
June 06, 2008 09:21AM

Well I got it working and all seems well but it is doing something very weird...

When I have the following content in my editor and click save:

<pre><![CDATA[ <p>By this time, you've no doubt heard of NIMBYs-people who subscribe to the Not in My Backyard philosophy. But how about BANANAs (Build Absolutely Nothing Anywhere Near Anyone)? Or CAVE, for Citizens Against Virtually Everything?</p> <p>For the longest time, any of those terms could be slapped onto the collective identity of Long Islanders, whose parochial interests quickly downed or dismantled plans that would dare threaten to bring higher-density, mixed-use developments, transportation that didn’t come with four wheels or, good heavens, sewers. Never mind the positive effects on the economy, the environment, or the lifestyles of average folks-especially young professionals and retired seniors.</p> ]]></pre>

It replaces it with:

<pre><![CDATA[ <p>rnBy this time, you've no doubt heard of NIMBYs-people who subscribe to the Not in My Backyard philosophy. But how about BANANAs (Build Absolutely Nothing Anywhere Near Anyone)? Or CAVE, for Citizens Against Virtually Everything?rn</p><p>rn</p><p>rnFor the longest time, any of those terms could be slapped onto the collective identity of Long Islanders, whose parochial interests quickly downed or dismantled plans that would dare threaten to bring higher-density, mixed-use developments, transportation that didn’t come with four wheels or, good heavens, sewers. Never mind the positive effects on the economy, the environment, or the lifestyles of average folks- especially young professionals and retired seniors.rn</p> ]]></pre>

does anyone have any idea where all of these "rn" characters are coming from?

Re: Using the MODx plug in
June 06, 2008 01:38PM

In theory, that would be your end of line \r\n. I don't know why it's turning into that. What's the value of $content before and after purification (in the PHP code; use a var_dump)

Re: Using the MODx plug in
June 06, 2008 03:48PM

before plugin...

<pre><![CDATA[ \r\nRussia, earth’s largest country spans 11 time zones that are unified by their capital, Moscow. Since the 1991 Soviet Union collapse, Moscow has evolved into a bewildering contradiction of lingering Communist-era hangovers and upmarket chic. I begin with the end, Novodevichy Cemetery, where hundreds of Russia’s most famous literary, artistic, musical, and political figures are buried. (Note: Cemeteries adjoin churches; graveyards don’t.) An uncanny, stirring stroll through Russian history, a walk through this hall-of-fame memorial stages not gravestones but row upon row of elaborate sculptures and images depicting the legends in telling poses. Famed comedian Yury Nikulin relaxes with his dog, while the ex-presidents’ monuments portray significantly less lighthearted souls.\r\n \r\n

\r\nVodka was stumbled upon 500 years ago when grain was distilled into what became Russia’s state beverage. No fancy mixers at these parties that define bracketed indulgences, a straight vodka shot (or three) accompanies every celebratory meal here. It’s telling that Russian chemist-extraordinaire Mendeleev, who tortured us in high school with his creation—the periodic table of the elements—is best known amongst Russians for purifying the vodka standard, and pegging it at 40-proof. \r\n \r\n]]></pre>

after plugin

<pre><![CDATA[ rnRussia, earth’s largest country spans 11 time zones that are unified by their capital, Moscow. Since the 1991 Soviet Union collapse, Moscow has evolved into a bewildering contradiction of lingering Communist-era hangovers and upmarket chic. I begin with the end, Novodevichy Cemetery, where hundreds of Russia’s most famous literary, artistic, musical, and political figures are buried. (Note: Cemeteries adjoin churches; graveyards don’t.) An uncanny, stirring stroll through Russian history, a walk through this hall-of-fame memorial stages not gravestones but row upon row of elaborate sculptures and images depicting the legends in telling poses. Famed comedian Yury Nikulin relaxes with his dog, while the ex-presidents’ monuments portray significantly less lighthearted souls.rn

rn

rnVodka was stumbled upon 500 years ago when grain was distilled into what became Russia’s state beverage. No fancy mixers at these parties that define bracketed indulgences, a straight vodka shot (or three) accompanies every celebratory meal here. It’s telling that Russian chemist-extraordinaire Mendeleev, who tortured us in high school with his creation—the periodic table of the elements—is best known amongst Russians for purifying the vodka standard, and pegging it at 40-proof. rn

rn]]></pre>

I wonder if it has something to do with tinyMCE.

when i remove the following from the plugin it seems to fix the rn problem

<pre><![CDATA[ // Magic Quotes Hack // this is an ugly hack because this hook hasn't had // the backslashes removed yet when magic_quotes_gpc is on, // but HTMLPurifier must not have the quotes slashed. static $magic_quotes = null; if ($magic_quotes === null) { $magic_quotes = get_magic_quotes_gpc(); } if ($magic_quotes) $content = stripslashes($content); $content = $purifier->purify($content); //I add this back in so that it will process it. if ($magic_quotes) $content = addslashes($content);

]]></pre>

Re: Using the MODx plug in
June 07, 2008 09:45PM

Yeah, ModX is doing something weird with the input and literal-izing the carriage returns and newlines. Can you ask on their forums about this behavior?

Author:
Your Email:

Subject:

HTML input is enabled. Make sure you escape all HTML and angled brackets with < and >.

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single newlines, use the pre tag.

Allowed tags: a, abbr, acronym, b, blockquote, caption, cite, code, dd, del, dfn, div, dl, dt, em, i, ins, kbd, li, ol, p, pre, s, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, var.

For inputting literal code such as HTML and PHP for display, use CDATA tags to auto-escape your angled brackets, and pre to preserve newlines:

<pre><![CDATA[
Place code here
]]></pre>

Power users, you can hide this notice with:

.htmlpurifier-help {display:none;}

Message: