php-general Digest 1 Jun 2012 12:41:24 -0000 Issue 7835

Topics (messages 318066 through 318071):

is there a way to stop HTMLPurifier/CSStidy from forcing input CSS into all 
lowercase?
        318066 by: Govinda
        318067 by: Tommy Pham
        318068 by: Tommy Pham
        318069 by: Govinda
        318070 by: Tommy Pham

How to insert a file in a class?
        318071 by: LAMP

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hi guys

anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow users 
to create their own external style sheets via form input)

...for example, in the way this post's answer explains how to use HTMLpurifier 
and CSStidy together:

http://stackoverflow.com/questions/3241616/

If so, do you know how to set CSStidy's config options in that context?

I found how to set CSStidy's config options if I was running CSStidy from the 
command line, or on its _own_ from PHP runtime, but I do not know how to set 
the config options from within HTMLpurifier, or even how to hack/override 
either of those libraries to solve my particular issue.  I looked and hacked 
and thought for sure I would find the offending line of code.. but somehow, 
nothing I have tried is stopping one or both of those libraries from forcing 
all my input CSS into lowercase, which I do not want.  The issue is that I need 
the input CSS's case to be left as the user input it (so that for example 
background image paths in that CSS do not break).

more details, attempted fixes, etc.:
http://stackoverflow.com/questions/10843600/

Thanks for any thoughts/tips of any kind
-Govinda

--- End Message ---
--- Begin Message ---
On Thu, May 31, 2012 at 10:33 PM, Govinda <govinda.webdnat...@gmail.com> wrote:
> Hi guys
>
> anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow 
> users to create their own external style sheets via form input)
>
> ...for example, in the way this post's answer explains how to use 
> HTMLpurifier and CSStidy together:
>
> http://stackoverflow.com/questions/3241616/
>
> If so, do you know how to set CSStidy's config options in that context?
>
> I found how to set CSStidy's config options if I was running CSStidy from the 
> command line, or on its _own_ from PHP runtime, but I do not know how to set 
> the config options from within HTMLpurifier, or even how to hack/override 
> either of those libraries to solve my particular issue.  I looked and hacked 
> and thought for sure I would find the offending line of code.. but somehow, 
> nothing I have tried is stopping one or both of those libraries from forcing 
> all my input CSS into lowercase, which I do not want.  The issue is that I 
> need the input CSS's case to be left as the user input it (so that for 
> example background image paths in that CSS do not break).
>
> more details, attempted fixes, etc.:
> http://stackoverflow.com/questions/10843600/
>
> Thanks for any thoughts/tips of any kind
> -Govinda

Have you tried http://htmlpurifier.org/phorum/ and did you noticed
"Since the project has been suspended, please only contact me if you
intend to continue maintaining it." for CSSTidy?

Regards,
Tommy

--- End Message ---
--- Begin Message ---
On Thu, May 31, 2012 at 10:48 PM, Tommy Pham <tommy...@gmail.com> wrote:
> On Thu, May 31, 2012 at 10:33 PM, Govinda <govinda.webdnat...@gmail.com> 
> wrote:
>> Hi guys
>>
>> anyone here using HTMLpurifier and CSStidy together?  (like e.g. to allow 
>> users to create their own external style sheets via form input)
>>
>> ...for example, in the way this post's answer explains how to use 
>> HTMLpurifier and CSStidy together:
>>
>> http://stackoverflow.com/questions/3241616/
>>
>> If so, do you know how to set CSStidy's config options in that context?
>>
>> I found how to set CSStidy's config options if I was running CSStidy from 
>> the command line, or on its _own_ from PHP runtime, but I do not know how to 
>> set the config options from within HTMLpurifier, or even how to 
>> hack/override either of those libraries to solve my particular issue.  I 
>> looked and hacked and thought for sure I would find the offending line of 
>> code.. but somehow, nothing I have tried is stopping one or both of those 
>> libraries from forcing all my input CSS into lowercase, which I do not want. 
>>  The issue is that I need the input CSS's case to be left as the user input 
>> it (so that for example background image paths in that CSS do not break).

You need to get better tools.  I found this with Notepad++ for Windows
searching "case" within *.php files filter within the root directory
of the extracted zip/tarball:

  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
(6 hits)
        Line 45:         $lowercase_string = strtolower($string);
        Line 46:         if (isset($system_fonts[$lowercase_string])) {
        Line 47:             return $lowercase_string;
        Line 61:                 case 0:
        Line 77:                 case 1:
        Line 131:                 case 2:

Haven't looked at the entire file or source code but that looks close
enough to me... ;)

>>
>> more details, attempted fixes, etc.:
>> http://stackoverflow.com/questions/10843600/
>>
>> Thanks for any thoughts/tips of any kind
>> -Govinda
>
> Have you tried http://htmlpurifier.org/phorum/ and did you noticed
> "Since the project has been suspended, please only contact me if you
> intend to continue maintaining it." for CSSTidy?
>
> Regards,
> Tommy

--- End Message ---
--- Begin Message ---
> 
> You need to get better tools.  I found this with Notepad++ for Windows
> searching "case" within *.php files filter within the root directory
> of the extracted zip/tarball:
> 
>  
> H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
> (6 hits)
>       Line 45:         $lowercase_string = strtolower($string);
>       Line 46:         if (isset($system_fonts[$lowercase_string])) {
>       Line 47:             return $lowercase_string;
>       Line 61:                 case 0:
>       Line 77:                 case 1:
>       Line 131:                 case 2:
> 
> Haven't looked at the entire file or source code but that looks close
> enough to me... ;)

Thanks a lot for taking a look Tommy,

I do have a decent text editor I use to code with... and had searched for 
possible places where is the culprit strtolower() ... and so far no matter 
which instances(s) I comment out, I cannot seem to turn off the behavior of the 
library as a whole (either of them, or both) which is forcing the input CSS to 
lowercase.

For example, I also just tried the exact place you suggested: this one:

[snip]htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php

...and changed line 45 to this:

        //$lowercase_string = strtolower($string);//Govinda hack
        $lowercase_string = $string;

but still no luck.


>> Have you tried http://htmlpurifier.org/phorum/ and did you noticed
>> "Since the project has been suspended, please only contact me if you
>> intend to continue maintaining it." for CSSTidy?

I hadn't posted on http://htmlpurifier.org/phorum because last time I did that 
when I has also posted on stackoverlfow (SO), then the developer of 
HTMLpurifier scolded me for the dupe ;-) ..  and he has already posted a 
comment on my (this new) SO post, saying just, "Hmm, that's silly of CSS Tidy. 
Maybe we should change that default.".  I assume he probably has a lot on his 
plate, to the point that his answers are incredibly terse and not necessarily 
very helpful.

I did see the message about CSStidy no longer being developed (if that is the 
meaning behind "suspended").  Yet when i was researching it, many people were 
still recommending it.  No?  Do you know/prefer something else for the purpose 
of cleaning user-input CSS bound for an external style sheet?

Thanks
-Govinda

--- End Message ---
--- Begin Message ---
On Thu, May 31, 2012 at 11:17 PM, Govinda <govinda.webdnat...@gmail.com> wrote:
>>
>> You need to get better tools.  I found this with Notepad++ for Windows
>> searching "case" within *.php files filter within the root directory
>> of the extracted zip/tarball:
>>
>>  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
>> (6 hits)
>>       Line 45:         $lowercase_string = strtolower($string);
>>       Line 46:         if (isset($system_fonts[$lowercase_string])) {
>>       Line 47:             return $lowercase_string;
>>       Line 61:                 case 0:
>>       Line 77:                 case 1:
>>       Line 131:                 case 2:
>>
>> Haven't looked at the entire file or source code but that looks close
>> enough to me... ;)
>
> Thanks a lot for taking a look Tommy,
>
> I do have a decent text editor I use to code with... and had searched for 
> possible places where is the culprit strtolower() ... and so far no matter 
> which instances(s) I comment out, I cannot seem to turn off the behavior of 
> the library as a whole (either of them, or both) which is forcing the input 
> CSS to lowercase.
>

Perhaps you should spend some time looking for a better text editor
for your OS. :)  When the current tools I use does not give
satisfactory progress in what I'd like to do, I replace the tool(s).

> For example, I also just tried the exact place you suggested: this one:
>
> [snip]htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
>
> ...and changed line 45 to this:
>
>        //$lowercase_string = strtolower($string);//Govinda hack
>        $lowercase_string = $string;
>
> but still no luck.
>
>
>>> Have you tried http://htmlpurifier.org/phorum/ and did you noticed
>>> "Since the project has been suspended, please only contact me if you
>>> intend to continue maintaining it." for CSSTidy?
>
> I hadn't posted on http://htmlpurifier.org/phorum because last time I did 
> that when I has also posted on stackoverlfow (SO), then the developer of 
> HTMLpurifier scolded me for the dupe ;-) ..  and he has already posted a 
> comment on my (this new) SO post, saying just, "Hmm, that's silly of CSS 
> Tidy. Maybe we should change that default.".  I assume he probably has a lot 
> on his plate, to the point that his answers are incredibly terse and not 
> necessarily very helpful.
>
> I did see the message about CSStidy no longer being developed (if that is the 
> meaning behind "suspended").  Yet when i was researching it, many people were 
> still recommending it.  No?  Do you know/prefer something else for the 
> purpose of cleaning user-input CSS bound for an external style sheet?
>
> Thanks
> -Govinda


Are you sure you fixed ALL of the offending lines containing
strtolower?  This is what Notepad++ returns when I search for
"strtolower":

Search "strtolower" (48 hits in 28 files)
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Background.php
(1 hits)
        Line 35:         $bits = explode(' ', strtolower($string)); // bits to 
process
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\BackgroundPosition.php
(1 hits)
        Line 80:             $lbit = ctype_lower($bit) ? $bit : 
strtolower($bit);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Color.php
(1 hits)
        Line 17:         $lower = strtolower($color);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\Font.php
(1 hits)
        Line 45:         $lowercase_string = strtolower($string);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\ListStyle.php
(1 hits)
        Line 30:         $bits = explode(' ', strtolower($string)); // bits to 
process
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS\TextDecoration.php
(1 hits)
        Line 19:         $string = strtolower($this->parseCDATA($string));
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\CSS.php
(2 hits)
        Line 51:                 $property = strtolower($property);
        Line 59:             if (strtolower(trim($value)) !== 'inherit') {
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\Enum.php
(2 hits)
        Line 7:  *          built-in strtolower and ctype_lower functions, 
which may
        Line 40:             $string = ctype_lower($string) ? $string :
strtolower($string);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\HTML\Color.php
(1 hits)
        Line 17:         if (isset($colors[strtolower($string)])) return
$colors[$string];
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\HTML\LinkTypes.php
(1 hits)
        Line 39:             $part = strtolower(trim($part));
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrDef\Lang.php
(3 hits)
        Line 35:                     $subtags[0] = strtolower($subtags[0]);
        Line 50:         if (!ctype_lower($subtags[1])) $subtags[1] =
strtolower($subtags[1]);
        Line 62:                 $subtags[$i] = strtolower($subtags[$i]);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrTransform\EnumToCSS.php
(1 hits)
        Line 44:         if (!$this->caseSensitive) $value = strtolower($value);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\AttrTransform\Input.php
(1 hits)
        Line 17:         else $t = strtolower($attr['type']);
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\Encoder.php
(1 hits)
        Line 507:             $lenc = strtolower($encoding);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\Filter\ExtractStyleBlocks.php
(1 hits)
        Line 194:                                     if ($y === '*' ||
isset($html_definition->info[$y = strtolower($y)])) {
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\HTMLModule.php
(1 hits)
        Line 197:         $content_model_type = 
strtolower(trim($content_model_type));
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\Length.php
(1 hits)
        Line 62:         if (!ctype_lower($this->unit)) $this->unit =
strtolower($this->unit);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\Lexer\PH5P.php
(8 hits)
        Line 328:                         'name'  => strtolower($char),
        Line 368:         $next_node = strtolower($this->characters('A-Za-z',
$this->char + 1));
        Line 410:                     'name'  => strtolower($char),
        Line 479:             $this->token['name'] .= strtolower($char);
        Line 525:                 'name'  => strtolower($char),
        Line 578:             $this->token['attr'][$last]['name'] .= 
strtolower($char);
        Line 630:                 'name'  => strtolower($char),
        Line 848:         } elseif(strtolower($this->character($this->char +
1, 7)) === 'doctype') {
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\Printer.php
(2 hits)
        Line 138:         if (!$five) $prefix = strtolower($prefix);
        Line 140:         $lclass = strtolower($class);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\Token\Tag.php
(2 hits)
        Line 37:         $this->name = ctype_lower($name) ? $name : 
strtolower($name);
        Line 41:                 $new_key = strtolower($key);
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\URI.php
(1 hits)
        Line 20:         $this->scheme = is_null($scheme) ||
ctype_lower($scheme) ? $scheme : strtolower($scheme);
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\library\HTMLPurifier\VarParser.php
(1 hits)
        Line 79:                 if ($type == self::ISTRING || $type ==
self::ITEXT) $var = strtolower($var);
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\maintenance\PH5P.php (8 hits)
        Line 266:                         'name'  => strtolower($char),
        Line 306:         $next_node = strtolower($this->characters('A-Za-z',
$this->char + 1));
        Line 348:                     'name'  => strtolower($char),
        Line 417:             $this->token['name'] .= strtolower($char);
        Line 463:                 'name'  => strtolower($char),
        Line 516:             $this->token['attr'][$last]['name'] .= 
strtolower($char);
        Line 568:                 'name'  => strtolower($char),
        Line 785:         } elseif(strtolower($this->character($this->char +
1, 7)) === 'doctype') {
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\maintenance\update-freshmeat.php
(1 hits)
        Line 110:             else $method .= '_' . strtolower($v);
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\plugins\phorum\config.default.php
(1 hits)
        Line 53: if (strtolower($GLOBALS['PHORUM']['DATA']['CHARSET']) !== 
'utf-8') {
  
H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\plugins\phorum\settings\migrate-sigs.php
(1 hits)
        Line 7:         if (!isset($_POST['confirmation']) ||
strtolower($_POST['confirmation']) !== 'yes') {
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\tests\common.php (1 hits)
        Line 104:                     $lopt = strtolower($opt);
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\tests\HTMLPurifier\Harness.php
(1 hits)
        Line 80:             if (strtolower(substr($method, 0, 10)) == 
'__onlytest') {


Given the above filenames, that pretty much takes care of all CSS...
Searching without file filters gives this in addition to above:

Search "strtolower" (51 hits in 30 files)
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\docs\dev-code-quality.txt
(1 hits)
        Line 13: a lot of strtolower() calls, no legit casing
  H:\data\Downloads\dev\PHP\htmlpurifier-4.4.0\docs\enduser-utf8.html (2 hits)
        Line 1006:         <li>...convert case (strtolower, strtoupper,
ucfirst, ucwords)</li>
        Line 1019: <code>strtolower</code> (HTML Purifier uses this 
function.)</p>


Those above 2 filenames seems rather interesting...  Then there's the
csstidy search for strtolower:

Search "strtolower" (12 hits in 4 files)
  H:\data\Downloads\dev\PHP\csstidy-1.3\class.csstidy.php (3 hits)
        Line 706:                         $this->selector =
strtolower($this->selector);
        Line 708:                     $this->property = 
strtolower($this->property);
        Line 977:       $istring = strtolower(trim(substr($istring,0,$pos)));
  H:\data\Downloads\dev\PHP\csstidy-1.3\class.csstidy_optimise.php (6 hits)
        Line 300:         if(strtolower(substr($color,0,4)) == 'rgb(')
        Line 325:         if(isset($replace_colors[strtolower($color)]))
        Line 327:             $color = $replace_colors[strtolower($color)];
        Line 333:             $color_temp = strtolower($color);
        Line 340:         switch(strtolower($color))
        Line 408:                     if
(strpos(strtolower($temp[$l]),$units[$m]) !== FALSE)
  H:\data\Downloads\dev\PHP\csstidy-1.3\class.csstidy_print.php (2 hits)
        Line 169:
if($this->parser->get_cfg('lowercase_s')) $token[1] =
strtolower($token[1]);
        Line 176:
if($this->parser->get_cfg('case_properties') == 1) $token[1] =
strtolower($token[1]);
  H:\data\Downloads\dev\PHP\csstidy-1.3\lang.inc.php (1 hits)
        Line 6:         $l = strtolower(substr($l,0,2));


HTH,
Tommy

--- End Message ---
--- Begin Message ---
Hi to all.

Let's say there is a class

class Box
{
        var $box_title;
        var $box_content;

        function __construct()
        {
                $this->box = '';
        }


        function box_title($title)
        {
                $this->title = $title;
        }

        function box_content($content)
        {
                $this->content = $content;
        }

        function make_box()
        {
                $this->box = '<h3>'.$this->box_title.'</h3>'.$this->box_content;
        }


        function get_box()
        {
                return $this->box;
        }
}


$box = new Box();
$box->box_title('PHP Classes');
$box->box_content('Starting with PHP 5, the object model was rewritten to allow for better performance and more features. This was a major change from PHP 4. PHP 5 has a full object model.')
$box->make_box();
echo $box->get_box();

This works fine.

The problem I have is how to "include" a file as box_content? it could be plain text, but it could be a form or some kind of code. $box->box_include(include(/path/to/file/file.php)) doesn't work, of course.

Wrapping up the whole code in a variable doesn't make a sense too:
# file.php
$content = '
        <form method="post" action="$_SERVER['PHP_SELF']">
                Email = <input type=text name=email>
                Pass = <input type=password name=pass>
                <input type=submit value=Submit>
        </form>';

# main.php
$box = new Box();
$box->box_title('PHP Classes');
include(file.php);
$box->box_content($content);
$box->make_box();
echo $box->get_box();


Also, I'm sure I read once it's not correct to print directly from a class. First return a value/result to "main" code and then print. Correct?

LAMP


--- End Message ---

Reply via email to