php-general Digest 26 May 2009 14:54:50 -0000 Issue 6142

Topics (messages 293151 through 293159):

Re: templating engine options
        293151 by: Sancar Saran
        293152 by: Andrea Giammarchi
        293154 by: Nathan Rixham
        293159 by: tedd

Background Process
        293153 by: shahrzad khorrami
        293155 by: Nathan Rixham
        293156 by: kranthi

Re: html and password management
        293157 by: kranthi

Re: IE can't download, FF can: SSL ? Need special headers?
        293158 by: Ford, Mike

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
On Tuesday 26 May 2009 03:48:41 am Nathan Rixham wrote:
> Sancar Saran wrote:
> > <?php
> > $content = 'No Comments';
> > if(isset($comments) and is_array($comments) and count($comments) > 0 ) {
> >     $content = '';
> >     foreach( $comments as $index => $comment ) : $content. = "<a href='".
> > $comment->link."'>".$comment->title."</a>"; endforeach;
> > }
> > ?>
> >
> > <h2>Comments</h2>
> > <div id="comments">
> >     <?=$content?>
> > </div>
> >
> > index.php
> > ob_start();
> > require('template.php');
> > echo ob_get_clean();
> >
> >
> > I'm still do not understand for complex template system requirement.
>
> I just _need_ the two abstracted.
>
> php must have no html in it
> html template must contain no php
>
> > Why it have to be very complex system.
> >
> > Large data array, some conditions, lots of loops, and What else ?
> >
> > http://www.flytag.de/
> > http://urlaub-finder.de/
> > http://airportdirekt.de/
> >
> > All same system. With different css designs.
>
> yup, did this myself for a longgggg time; here is some very old code I
> used to use!
>
> newCage();
> $content = cage(include $file);
>
> function newCage() {
>       ob_start();
> }
> function cage() {
>       $includeOutput = ob_get_contents();
>       ob_end_clean();
>       return $includeOutput;
> }
>
> lol
Alright, my vote going to smarty.

After compilation, it running on native php.

And

When we use TYPO3 native marker model (which fits your requirement, no php in 
template) I found very dull. Load template to memory, fetch part of template, 
generate loop for processing template, feed template keys in the loop. 

After some time %75 of code become template feed. Like this

//--- Get Template
$this->templateFileContent = $this->cObj-
>fileResource('fileadmin/templates/travelit_booking.html');
$strCarLoop                = $this->cObj->getSubpart($this-
>templateFileContent,"###CAR_LOOP###");
$strPLoop                  = $this->cObj->getSubpart($this-
>templateFileContent,"###PASSANGER_LOOP###");
$strCarTable               = $this->cObj->getSubpart($this-
>templateFileContent,"###CAR_TABLE###");
$strHotelBooking           = $this->cObj->getSubpart($this-
>templateFileContent,"###HOTEL_BOOKING###");
$strFlightBooking          = $this->cObj->getSubpart($this-
>templateFileContent,"###FLIGHT_BOOKING###");

....

if(isset($arrData['MW']) && is_array($arrData['MW']['MWLIST']['CAR']))
{
        $intCarSize = sizeof($arrData['MW']['MWLIST']['CAR']);
        for($intX=0;$intX < $intCarSize;$intX++)
        {
                $arrSubst = '';
                $arrSubst['###CAR_OPTION_VALUE###'] = 
$arrData['MW']['MWLIST']['CAR'][$intX]
["@"]['GROUP']."-".$arrData['MW']['MWLIST']['CAR'][$intX]["@"]['ID1']."-".
$arrData['MW']['MWLIST']['CAR'][$intX]["@"]['ID2']."-".$arrData['MW']
['MWLIST']['CAR'][$intX]["@"]['NAME']."-".$arrData['MW']['MWLIST']['CAR']
[$intX]["@"]['PRICE'];
                $arrSubst['###CAR_OPTION_PRICE###'] = 
number_format($arrData['MW']['MWLIST']
['CAR'][$intX]["@"]['PRICE'], 0, ',', '.');
                $arrSubst['###CAR_OPTION_NAME###']  = 
$arrData['MW']['MWLIST']['CAR'][$intX]
["@"]['NAME'];
                $strCarss.= 
$this->cObj->substituteMarkerArrayCached($strCarLoop,$arrSubst);
        }
}

<!-- ###CAR_LOOP### begin -->
                        <option value='###CAR_OPTION_VALUE###' 
>&nbsp;###CAR_OPTION_PRICE####&nbsp;&euro;&nbsp;###CAR_OPTION_NAME###</option>
<!-- ###CAR_LOOP### end -->

<!-- ###CAR_TABLE### begin -->
                        <tr>
                                <td  colspan='5' style='text-align:center; 
font-size:14px;'>
                                        ###BOOKING_RENT_A_CAR_LABEL###
                                </td>
                        </tr>
                        <tr>
                                <td colspan='2'>
                                                
<center>###BOOKING_RENT_A_CAR_INFO###</center>
                                                <br/><br/>
                                                <center><a href='#' 
onClick='Open_Window("http://www.sunnycars.com/b2c.docs/deu.l/single_vehicledetails.html?"+getCarUrl(),"SUNNY","scrollbar=yes",800,600)'><img
 
src='/fileadmin/templates/img/scar.gif' border='0' />
                                                
<br/><br/>###BOOKING_CAR_INFO_LABEL###</a></center>
                                </td>
                                <td colspan='4'>
                                                <select name='MWTYP' size='10' >
                                                        <option 
value='-'>###BOOKING_I_DONT_WANT_TO_RENT_A_CAR###</option>
                                                        
###BOOKING_RENT_A_CAR_LOOP###
                                                </select>
                                </td>
                        </tr>
<!-- ###CAR_TABLE### end -->

Then I realize, doing some coding for data which I already have make me sick. 
and When you go with multi language site you will realize, every tiny bit of 
template have to template marker keys. And you have to do this mule job

And begin to use this.

<table border='0' cellpadding='0' cellspacing='0' class='dtable rbook-renta-
car'><tbody>
        <tr>
                <td class='rbook-element-label'><input type='radio' 
name='car_rental' 
value='no' checked='checked' onclick='toggle_carrental("disabled")' 
/>&nbsp;<?=evo::$lang['_i_dont_want_to_rent_a_car_'];?></td>
                <td>&nbsp;</td></tr>
        <tr>
                <td class='rbook-element-label'><input type='radio' 
name='car_rental' 
value='yes' onclick='toggle_carrental("enabled")' />&nbsp;<?=evo::
$lang['_i_want_to_rent_a_car_'];?></td>
                <td >&nbsp;</td></tr>
        <tr>
                <td class='rbook-rentacar-picture'>
                        <img 
src='http://www.sunnycars.de/item/img_photo13.jpg?lid=deu' width='80%' 
height='80%' alt='image'/>
                        <br/>
                        <a href='javascript:void(0);' 
class='cResponseCarInfo'><?=evo::
$lang['_car_info_'];?></a>
                        </td>
                <td class='rbook-rentacar-cars'>
                        <select name='car_list' id='car_list' size='10' 
class='ui-corner-all' 
onchange='updatePrice("rentacar","","");' disabled='disabled'><?=$this-
>get_rentacar($this->php_response['MW']['MWLIST']['CAR'])?></select>
                        <div class='page_br'>&nbsp;</div>
                </td></tr>
        </tbody></table>
</div>

(both of them doing same thing, second one had extended js.)

And no html in PHP was your code ability.  I had %5 percent html in my php 
code because making them separate file was unnecessary (to me) and all of them 
non themeable management markup.

Anyhow, in these days I'm trying to fit my code into jQuery's CSS framework. 
After one year usage of inline php template system. We almost forgot the 
templates. Most time consuming was Configuring TYPO3 and arrange CSS.

Regards

Sancar

--- End Message ---
--- Begin Message ---
Finally somebody mentioned XSL Transformations. Time is relative because as you 
need time to learn an API to produce quickly only after a while, thanks to 
knowledge and confidence, XSL is the same with the advantage that you transform 
a data structure, rather than work over raw programming language ( portability 
and re-usability )

I wrote a post in my blog about this long thread, hope you'll get some point:
http://webreflection.blogspot.com/2009/05/template-engine-why-bother-xml-xslt.html

Best Regards


> Date: Mon, 25 May 2009 23:44:43 +0100
> From: [email protected]
> To: [email protected]
> CC: [email protected]; [email protected]; [email protected]; 
> [email protected]
> Subject: Re: [PHP] templating engine options
> 
> Stuart wrote:
> > 2009/5/25 Robert Cummings <[email protected]>:
> >> I continued the discussion with Nathan.
> > 
> > I too have had an off-list discussion with Nathan on this topic, and a
> > productive one at that.
> > 
> 
> which would probably be a good time for me to step back in; having had a 
>   nice little inside in to both Robert and Stuarts template systems, and 
> indeed way(s) of doing things. Also thanks to everybody else who made 
> suggestions and gave input - it was all appreciated.
> 
> I'm far from making a final decision, as I've decided to approach this 
> by setting a few guidelines and a wishlist, then either finding / 
> modifying something to do the job, or creating something from scratch.
> 
> Both Rob and Stuarts systems were more in common than they may think, 
> focus in both was on performance, and only making set data available to 
> the templates (whether pushing or pulling).
> 
> The syntax did differ though, and functionality aside this is probably 
> one of the most important aspects (imho).
> 
> Markup & XML sits well with me (and most) because we are web developers 
> and use it daily.
> 
> PHP syntax also sits well because we also use it daily.
> 
> The fact remains though that this "feels like" (and possibly is) a 
> different job which requires something different. Both XHTML and PHP do 
> their job well - just as ecma(java)script and css do theirs.
> 
> However none of these technologies / languages are suited and dedicated 
> to converting provided data in to specified output; specifically, and 
> only, xhtml.
> 
> XSL Templates are near perfect, built for the job, and very powerful - 
> but time hasn't favoured them well; and until (if ever) a wide spread 
> adoption happens something else needs to fill the gap.
> 
> Template Specific Thoughts:
> 
> Smarty, Stuarts Engine, Robs Engine, PHPLIB and many more had one common 
> theme, they all limited the data available. My terminology of limited 
> perhaps sounds wrong, so maybe "make specified selected data available" 
> or "provide access to the view" will make more sense. Inline with 
> layered and tiered application design this makes perfect sense; thus..
> 
> A template /should/ only be able to access the data made available to 
> it, nothing else. Whether it requests the data or the data is provided 
> is covered later. If it doesn't have all the data needed then this needs 
> reviewed and the application needs changed to provide it. Not the 
> template engine bastardized to accommodate a limited app.
> 
> A template ~should~ have unique yet easy to understand syntax, something 
> that complements xhtml and provides all needed functionality. (IMHO it 
> should not be php syntax)
> 
> A template engine must stick within it's role boundaries, it's not a 
> cache engine, its not php, its not xhtml, its not for implementing 
> functionality - it is simply and purely to do its job - take data, 
> populate an xhtml template with it and return the result - nothing more, 
> nothing less.
> 
> 
> Push vs Pull.
> 
> This is a much bigger issue than I thought, and perhaps is the crux of 
> the whole thing. I can see two clear approaches;
> 
> Firstly, (the common one)
> - app passes data and a template to the template engine
> - template engine merges it together and passes back
> - app does as it pleases with data (sends it to client, caches it, fires 
> it in an email - whatever)
> 
> Secondly, (uncomment)
> [think modular]
> - app provides an api / gateway to views of data
> - template engine requests view(s) specified in template from app
> - template engine populates template modules with data & sends output to
> 
> I guess the first is template engine as a Util / Service - and the 
> second is template engine as a Layer / App.
> 
> There are pros and cons in each design, concentrating on the second 
> design for now - this brings in a lot of scope which seems to fit well 
> both practically and architecturally.
> 
> The freedom to be able to specify in template that...
> 
> this is template module "latest posts", it is bound to the data view (or 
> data provider) "latest posts(8)"
> whilst overall combining template (page) is comprised of modules x,y and 
> z - here, here and here.
> 
> ...really appeals to me; certainly in this scenario where you request 
> (pull) from the application rather than make it all available. This way 
> you only ever perform the business logic required for the information 
> available. The counter part of making everything available incase it may 
> be used is ridiculous (and makes me think coldfusion for some reason??).
> 
> Architecturally this appears to be good - it's the presentation tier 
> being a presentation tier, the logic tier knows nothing of the 
> presentation tier and simply serves up what is requested. However thats 
> only on the one side of the tier - on the other side we have a huge 
> gaping hole where functionality should be (cache, compilation, delivery) 
> etc, which would require another, as yet unknown layer (or 2).
> 
> The abstraction and separation of concerns in this setup really appeals 
> - but practically I'm not sure if the time spent implementing on a small 
> or even medium sized project would be worth it. Still appeals massively 
> though - pull makes more logical sense to me.
> 
> Meanwhile, we have the first option, the way it's done, "push" the data 
> - specify a template for that data and let template engine X do the 
> merging. IMHO a clean, simple, lightweight implementation wouldn't be 
> the hardest thing to make, and hundreds of apps are freely available all 
> ready.
> 
> 
> Push vs Pull Conclusion
> Mentally I'm sticking with "pull" for a long term goal, however 
> practically I'm going to look at creating "push"; which isn't hard and 
> focussing specifically on template syntax, which is were I'm going next :p
> 
> 
> Syntax
> 
> As mentioned previously I strongly feel all the current offerings I've 
> seen are not ideal, the syntax is just a bit wrong
> 
> preference goes to smarty/phplib style of syntax {$var.child} for only 
> one reason.. because it's not as intertwined as:
> echo '<li>'. $var->child . '</li>';
> //simple example but you know how messy this can get
> likewise it's not as ..?.. as xslt nor is it as potentially confusing as 
> two versions of markup in the same document.
> 
> however, I still don't like it - it's just a workaround imho, a 
> temporary measure.
> 
> between the last line and here there is a massive trail of thought I 
> can't even begin to type out, and it'd be v boring. BUT it leads me to 
> the following..
> 
> An extended version of xhtml, with a simple dtd, specifically for 
> templates. This isn't intertwined or alternative markup, it's enhanced 
> with more attributes.. consider
> 
> <div id="comments" datasource="blog.recentcomment">
>    <p>
>      <strong data="title" /><br /> ..PROBLEM..
>    </p>
> </div>
> 
> and here in and there in lies the great big feckin problems which means 
> we'll never have a proper solution.
> 
> ..PROBLEM.. how do we specify what the content of problem area is? 
> without introducing a new tag rather than just an attribute?
> 
> making a template syntax is simple, while you do block elements, the 
> second you hit inline elements you are stuffed.
> 
> <b> is the bane of our lives, because we can't represent inline elements 
> in any language bar xhtml, we work with blocks of everything. Consider 
> drawing API's, you can draw a circle inside a square easily, the code is 
> just:
> object.drawSquare( x , y , w , h );
> object.drawCircle( x , y , r);
> it's never
> object.drawSquare( x ,{object.drawCircle( x , y , r)} y , w , h ); //lol
> 
> back in xhtml world, to mark off a segment as <b> without using the 
> syntax or sending an xhtml fragment in a var we'd have to do it using an 
> instruction with offsets and positions.
> $string = 'some content here';
> $boldBit = substr( $string , 5 , 7);
> // .. more code
> 
> so the syntax of xhtml doesn't really fit any programming language (?)
> 
> interestingly I finished that ..PROBLEM.. off mentally and came up with 
> a tag like <data data="whatever" /> which may as well just be <value-of 
> data="whatever" /> which is just xslt.
> 
> square one.
> 
> sub thought.. is that an xslt pre processor which figured out what data 
> the xsl needs, then provides it as xml and delivers client side ready 
> for rendering would be nice.
> 
> ultimately though, I feel I'm getting no-where, syntax syntax syntax - I 
> re-iterate, I'll have the solution to this when this can be accomplished
> 
> <?php
> 
> if( isset($comments) && is_array($comments) && count($comments) > 0 ) {
>    echo '<h2>Comments</h2>';
>    echo '<div id="comments">';
>    foreach( $comments as $index => $comment ) {
>      echo '<a href="' . $comment->link . '">';
>      echo $comment->title;
>      echo '</a>';
>    }
>    echo '</div>';
> } else {
>    echo '<h3>No Comments</h3>';
> }
> ?>
> 
> without php and without xml style markup (unless it's by extension of 
> xhtml with data attributes)
> 
> that was a big one!
> 
> regards & any thoughts more than welcome.
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_________________________________________________________________
Windows Liveā„¢: Keep your life in sync. Check it out!
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t1_allup_explore_012009

--- End Message ---
--- Begin Message ---
Andrea Giammarchi wrote:
Finally somebody mentioned XSL Transformations. Time is relative because as you 
need time to learn an API to produce quickly only after a while, thanks to 
knowledge and confidence, XSL is the same with the advantage that you transform 
a data structure, rather than work over raw programming language ( portability 
and re-usability )

I wrote a post in my blog about this long thread, hope you'll get some point:
http://webreflection.blogspot.com/2009/05/template-engine-why-bother-xml-xslt.html

Best Regards


nice post, and nice choice!

love xsl, nothing else comes close and if more of my fellow developers and designers used xsl I wouldn't be asking about template engines.

IMHO I can't see any reason why _every_ developer (and app) doesn't use xsl.

--- End Message ---
--- Begin Message ---
At 12:46 PM -0400 5/25/09, Robert Cummings wrote:

I'm going to leave this discussion here since it's eating up too much of
my time :)

Cheers,
Rob.

Rob:

It's always been my experience to listen when you talk. -- so -- when you find some time AND have the inclination, could you prepare a simple example of what you are saying?

I know when I'm trying to explain a complex concept to someone I usually can reduce it down to the basics to demonstrate. As it is right now, I get some of what you are saying and then in the next line you lose me.

Thanks for your time.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hi,
I have two php scripts, first one must pass arguments to second(the php
script that will take more time to process for example inserting 1000000
records to db, data come from first script). I search around web and find
below function:



function execInBackground($path, $exe, $additional) {
    global $conf;

    if (file_exists($path . $exe)) {
        chdir($path);
        if (substr(php_uname(), 0, 7) == "Windows"){
            echo 'going Windows';
            pclose(popen("start \"bla\" \"" . $exe . "\" "  . $additional,
"r"));           } else {
                exec("./" . $exe . " " .  $additional . " > /dev/null
&");           }
    }
}

But I don't know how to pass variables to the second file? and how to use of
this function?
in *windows* enviroment... and return value of second file to first..

Thanks in advance
shahrzad

--- End Message ---
--- Begin Message ---
shahrzad khorrami wrote:
Hi,
I have two php scripts, first one must pass arguments to second(the php
script that will take more time to process for example inserting 1000000
records to db, data come from first script). I search around web and find
below function:



function execInBackground($path, $exe, $additional) {
    global $conf;

    if (file_exists($path . $exe)) {
        chdir($path);
        if (substr(php_uname(), 0, 7) == "Windows"){
            echo 'going Windows';
            pclose(popen("start \"bla\" \"" . $exe . "\" "  . $additional,
"r"));           } else {
                exec("./" . $exe . " " .  $additional . " > /dev/null
&");           }
    }
}

But I don't know how to pass variables to the second file? and how to use of
this function?
in *windows* enviroment... and return value of second file to first..

Thanks in advance
shahrzad


after following your recent threads, can I ask have you considered using the tools made available by the db? something like

LOAD DATA LOCAL INFILE '/importfile.csv'
INTO TABLE test_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, filed2, field3);

this will be 100x faster than anything you can write with php

regards!

--- End Message ---
--- Begin Message ---
popen will allow you to read/write data to a file but not execute the php code.

i am assuming that you want to execute the php script like
include/require does.. if that is the case system() will serve your
purpose....but this requires php to be installed as a CLI
<?php
$res = system("path/to/php.exe /path/to/second/file.php");
?>

but as Nathan suggested it would be best for you if you considered
alternative options. for example you can make an AJAX  request to the
second file.
Kranthi.

--- End Message ---
--- Begin Message ---
seems more of a firefox question than a PHP question...

just replace <form id="formemail" method="post" action="UserPrefs">
with <form id="formemail" method="post" action="UserPrefs"
autocomplete="off">

https://developer.mozilla.org/en/How_to_Turn_Off_form_Autocompletion

--- End Message ---
--- Begin Message ---
On 22 May 2009 20:41, Dee Ayy advised:

> That's what I had in my first post.  What are the rest of
> your headers?
> 
> This is what is now deployed and I consider this issue resolved, but
> allowing spaces in the filename across IE, FF, and Safari browsers
> would be the real solution.

Haven't tried this, but does URL encoding spaces with %20 rather than +
help any? If so, you might want to consider using rawurlencode().

>  It's untested on other browsers:
> 
> header('Content-Description: File Transfer');
> header('Content-Type: '.$type);
> header('Content-Disposition: attachment;
> filename='.basename(str_replace(' ', '_', $name)));
> header('Content-Transfer-Encoding: binary');
> header('Expires: 0');
> header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
> header('Pragma: public'); header('Content-Length: '.$size);
> echo $data;

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [email protected]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--- End Message ---

Reply via email to