Forums / Developer / Tidy output extension?

Tidy output extension?

Author Message

kracker (the)

Thursday 01 February 2007 9:48:47 pm

I wanted to thank everyone for creating such a lively discussion in this thread.

My next request would be that the next person who implements a simple tidy template operator consider posting it as a code contribution on ez.no to share with others who seek the start of a solution in this topic, perhaps even to extend and return those improvements back to the community again.

//kracker

<i>Sylver - Hold me in your arms</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Paul Forsyth

Friday 02 February 2007 1:55:02 am

I agree Bruce. Arguably the $module_result is the hardest bit to control :)

I guess you can do the following for pagelayout

{set-block variable=$page_top}{include ... page_top, page_head.tpl}{/set-block}
{$page_top|tidy(top)}
{$module_result.content|tidy(body)}
{set-block variable=$page_bottom}{include ... page_bottom, footer.tpl}{/set-block}
{$page_bottom|tidy(bottom)}

where the parameter to tidy tells the operator which bits of html to substitute for. this is a <b>gross</b> simplification but it should work...

p

Andrew K

Friday 02 February 2007 8:24:46 am

I've been planning on starting the project this weekend, but there was a death in the family, so I'm having to travel. I hope to start working on it next week. I can't promise that it will be any good, being my first extension, but it would be a start.

Question: There are two ways to access tidy in PHP. Either call the actual command from exec() (or the like) or use the PHP tidy functions (http://us2.php.net/manual/en/ref.tidy.php), but that requires the user to install those functions from pecl (http://pecl.php.net/package/tidy). Which method would be best? Or should there be the ability to choose in the settings?

--Andrew

Paul Forsyth

Friday 02 February 2007 8:52:25 am

Hi Andrew,

Sorry to hear that :( All my best.

For tidy the pecl extension is my preference. You have to install it either way. With pecl at least the tidy library is ready for php.

You could code it both ways. Test for the pecl extension and if its not then fall back to the binary.

Good luck!

Paul

Claudia Kosny

Friday 02 February 2007 11:57:12 am

Hi Andrew

I have an extension which implements an template operator for tidy halfways done. If you are interested, write me at ckosny [at] gmx [dot] net.

Claudia

Bruce Morrison

Monday 05 February 2007 1:22:27 am

Hi Andrew

Sorry to hear about your loss.

The discussion of the solution has been bothering the engineer in me a lot. While a template operator is probably the best way to handle this currently in eZ it's not an idea solution. It's starting to look like a case of the "The Complicator's Gloves" ( http://thedailywtf.com/Articles/The_Complicator's_Gloves.aspx )

This looks to be something that will do what you want:
http://mod-tidy.sourceforge.net/

To do it on the browser side
http://users.skynet.be/mgueury/mozilla/

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Paul Forsyth

Monday 05 February 2007 2:19:22 am

hehe, the glove analogy does ring a few bells :)

i think that it totally depends on your need.

mod_tidy and the validator are essentially have the same purpose and can be used during development. validator is a little safer for production sites since its client side.

however, if you are not interested in finding and fixing issues ( which is difficutl with the many ez templates) and just want well formatted html then perhaps use the apache mod or this eZ extension.

on top of that consider that unless you control the web server its unlikely you can add such a mod which leaves you only with the eZ extension...

paul

Andrew K

Monday 05 February 2007 8:20:24 am

All, thanks for your kind words about my family's loss. The funeral was very nice and the trip went well.

Bruce, thanks for the mod_tidy reference, I didn't know that existed. I may try that out, but I think I still would like to try my hand at this extension. If for nothing else, to at least try creating an contributed extension. Plus Paul has a good point about being in a shared hosting environment.

I'll get cracking this week and let you know my progress.

--Andrew

Andrew K

Thursday 08 February 2007 5:49:39 pm

Ok. I know I missing something obvious. I keep getting a operator not registered error. Here's are my code so far (not much to look at).

eztemplateautoload.php...

<?php

$eZTemplateOperatorArray = array();
$eZTemplateOperatorArray[] = array(
        'script' => 'extension/eztidy/autoloads/eztidyoperator.php',
        'class' => 'EztidyOperator',
        'operator_names' => array('eztidy'));

?>

eztidyoperator.php...

<?php
class EztidyOperator
{
    function EztidyOperator()
    {
        $this->Operators = array('eztidy');
    }
    function operatorList()
    {
        return $this->Operators;
    }
    function namedParameterPerOperator()
    {
        return true;
    }
    function namedParameterList()
    {
        return array( 'eztidy' => array( 'first_param' => array( 'type' => 'string',
                                                                 'required' => false,
                                                                 'default' => 'default text' ),
                                         'second_param' => array( 'type' => 'integer',
                                                                  'required' => false,
                                                                  'default' => 0 ) ) );
    }
    function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        $firstParam = $namedParameters['first_param'];
        $secondParam = $namedParameters['second_param'];
        switch ( $operatorName )
        {
            case 'eztidy':
            {
                $operatorValue = $this->tidyup($firstParam);
            } break;
        }
    }
    function tidyup($originalMarkup){
        $tidy = new tidy;
        $tidy->parseString($originalMarkup);
        $tidy->cleanRepair();
        return $tidy;
    }
    var %Operators;
}
?>

site.ini.append.php

[TemplateSettings]
ExtentionAutoloadPath[]=eztidy

I have the extension enabled in the admin.

Thanks.

--Andrew

Kristof Coomans

Friday 09 February 2007 12:29:49 am

Hi Andy

I think you have a typo in site.ini.append.php. Exten<b>t</b>ionAutoloadPath[]=eztidy should be Exten<b>s</b>ionAutoloadPath[]=eztidy

independent eZ Publish developer and service provider | http://blog.coomanskristof.be | http://ezpedia.org

Andrew K

Friday 09 February 2007 7:13:22 am

Man! If I could spell, I'd be dangerous!

Thanks.

--Andrew

Andrew K

Friday 09 February 2007 10:34:17 am

Ok. So far so good. I need to figure out the best way to store the tidy settings for a user to make changes. There are quite a few options a user can tweak and I want those in a separate config file. What is the best way to do this and adhear to ez coding standards? Should they be held in an array? They wouldn't go in an regular ini file, right?

For now, I'll put them in an array in the main php class file, but I'd like it to be user friendly for others.

Thanks.

--Andrew

Andrew K

Friday 09 February 2007 11:37:12 am

Woohoo! It works!

I put the eztidy operator on the $module_result.content output in pagelayout.tpl. You can easily see where tidy kicks in in the source...

http://www.trinitychapelbc.org/

Now for clean up and getting ready for contribution. Any thoughts on where to keep the Tidy Options?

--Andrew

kracker (the)

Friday 09 February 2007 5:42:55 pm

Congratulation! Your source code sure looks much tighter!
And with a little more work you can get the rest of the blocks
of source even more clearer.

Have you considered a tidy.ini file with all your tidy specific options?

If you put your version in pubsvn I have another version which
I believe supports the use of all the tidy options via ini settings,
Perhaps we all could collaborate.

Though isn't it worth renaming the extension and operator
to simply 'tidy' for simplicity and brevity? Lets keep it simple.

//kracker

<i>* Requiem for a dream soundtrack - 06 - Ghosts of things to come
* John martyn - Stormbringer
* led Zeppelin - That's the Way

Made up to fill a void - Nothing important left to say anyway...</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Andrew K

Saturday 10 February 2007 9:56:48 am

I agree that the eztidy.ini would be the best, I know how to access it in a template, I just didn't know how to access it within the php code.

Ok. So are there instructions for committing code to the pubsvn. I'm familiar with SVN, I just need the connection info.

Thanks.

--Andrew

Andrew K

Saturday 10 February 2007 10:15:45 am

Ok. I found the pubsvn url, but I'm not sure where to put my code. Plus I don't think I have permissions to write.

--Andrew

kracker (the)

Saturday 10 February 2007 10:28:49 am

Hello Andrew,

You may find the information you seek to request commit access to the community repositories documented in the following article.

<i>http://ezpedia.org/wiki/en/ez/using_pubsvn_subversion_repositories#eztoc909_3</i>

//kracker

<i>len - beautiful day approach</i>

Member since: 2001.07.13 || http://ezpedia.se7enx.com/

Andrew K

Saturday 10 February 2007 10:44:28 am

Wow. How did I not know about ezpedia?

Thanks. I'll let you know when the code is uploaded.

--Andrew

Bruce Morrison

Sunday 11 February 2007 2:42:47 pm

@Andrew
See http://pubsvn.ez.no/doxygen/classeZINI.html for info on accessing ini files from php code.

HTH
Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Andrew K

Sunday 11 February 2007 5:49:19 pm

Ok. I got everything set up and ready to upload to pubsvn, but when I try to commit I get this error...

Error: Error while performing action: MKACTIVITY of '/community/!svn/act/1c900356-aa57-fa44-b61f-61bffc9a4fa7': 400 Bad Request (http://pubsvn.ez.no)

I've got a username and password and I'm using tortoisesvn. I know this may not be the place to ask.

Thanks.

--Andrew