TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
Advertisement
Associates
Associates
techtuts Darkmindz
CSS Tutorials Tutorialsphere.com - Free Online Tutorials
Boston PHP SurfnLearn
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-24-2008, 09:01 AM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2008
Posts: 16
Thanks: 0
oscargodson is on a distinguished road
Help Building Template and Stuck... Help?

I'll try to explain this as best as I can, but what I am trying to do isn't exactly easy to explain

I have a base XML file (plugins.xml) In this file I have a root <plugins> node. Inside of that are <plugin> nodes. I have a form (deploy_form.php) which uses this XML sheet. To make it easy for people to add plugins to this application they can add some basic nodes to this xml sheet and the form will create a new checkbox option on the deploy_form.php file. Here is what code I have for the form:

PHP Code:
            <?php
                
foreach($pluginData->plugin as $plugin){
                    
$name $plugin->name;
                    echo 
'
                    <li><input type="checkbox" value="'
.$name.'_plugin" name="jquery_plugin_'.$name.'" />'.$name.'</li>
                    '
;
                }
            
?>
My trouble however is on the next page after the user submits this form.

I need to create a new script tag for each new plugin they add. These are jQuery plugins and so they need to make new script tags one after another in a new html/php page. My application creates (among many other things) an index html or php file with default settings such as CSS, image directories, js, jQuery library etc. Here is some more PHP code:
PHP Code:
$html_temp ''.$html_doctype.'

<html '
.$html_attr.'>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>'
.$html_title.'</title>
    '
.$css.'
    '
.$jquery.'
    
</head>

<body>
    
</body>
</html>
'

I use that variable in an fwrite function below. I need to do a foreach statement like this and put it after where I have the $jquery var

PHP Code:
foreach($pluginData->plugin as $plugin){
    
$name $plugin->name;
    
$filename $plugin->name['filename'];
    
$dir $plugin->dir;
    
$css $plugin->css;
    
$images $plugin->images;

    if(isset(
$_GET["jquery_plugin_$name"])){
        
exec("cp -r files/JavaScript/jQuery/plugins/$dir/$filename $deploy_download/js/$filename");
        if(isset(
$css)){

        }
        if(isset(
$images)){

        }
    }
    echo 
'<script type="text/javascript" src="js/'.$filename.'"></script>';

I took out a lot of code so it makes it easier for you guys to help so there is a lot more options going into this but I need that final echo below to be repeated for every checked checkbox the user checked for their plugin choice. So, for example, lets say they choose 2 of 3 plugins. Then there would be a total of 2 <script> tags underneath the $jquery variable that needs to be written to a final .html or .php template.
oscargodson is offline  
Reply With Quote
Old 08-24-2008, 10:26 PM   #2 (permalink)
The Contributor
 
mortisimus's Avatar
 
Join Date: Sep 2007
Location: United Kingdom
Posts: 41
Thanks: 4
mortisimus is on a distinguished road
Default

I don't really understand what you want going on here. From what I understand, you want a page created for a user where the user specifies what jquery plugins they want on the page.

If I am correct then you might want something like:
PHP Code:
                foreach($pluginData->plugin as $plugin){
                    
$name $plugin->name;
                    echo 
'
                    <li><input type="checkbox" value="'
.$name.'_plugin" name="plugin[]" />'.$name.'</li>
                    '
;
                } 
Then for the tags:
PHP Code:
$plugin $_POST['plugin'];
for(
$i=0;$i<count($plugin);$i++){
   
$tags[$i] = $plugin[$i];
}

foreach(
$tags as $jqsrc){
   echo 
"<script src=\"js/" $jqsrc ".js\" type=\"text/javascript\"></script>";

So the script tag will link to the plugin.js file specified in the checkbox and this will loop through all the values in the tag array.

However, I have a horrible feeling I may have misunderstood you..
__________________
LONG time talkphp member. Short time poster :-)
Send a message via Skype™ to mortisimus
mortisimus is offline  
Reply With Quote
Old 08-24-2008, 11:21 PM   #3 (permalink)
The Wanderer
 
Join Date: Jun 2008
Posts: 16
Thanks: 0
oscargodson is on a distinguished road
Default

Well, I can get my foreach statement to work alone. I can't however get it to place the data into that final html_temp variable.

So, for example the final template would look something like:

PHP Code:
$html_temp ''.$html_doctype.'

<html '
.$html_attr.'>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>'
.$html_title.'</title>
    '
.$css.'
    '
.$jquery.'
    <script type="text/javascript" src="js/jquery.color.js"></script>
    <script type="text/javascript" src="js/jquery.corner.js"></script>
    
</head>

<body>
    
</body>
</html>
'

How can I get those sript tags inside the template so when I go to write it to the .html or .php file at the end of the script they will be in $html_temp variable as the are above?

Last edited by oscargodson : 08-24-2008 at 11:22 PM. Reason: HTML error
oscargodson is offline  
Reply With Quote
Old 08-26-2008, 05:11 AM   #4 (permalink)
The Wanderer
 
Join Date: Jun 2008
Posts: 16
Thanks: 0
oscargodson is on a distinguished road
Default Fixed it

I finally fixed it. It was pretty simple and here is the code. I removed some of the extra code such as the css and images code.

PHP Code:
if(isset($_GET['jquery'])) {
    
$jquery_plugins '';
    foreach(
$pluginData->plugin as $plugin){
        
$name $plugin->name;
        
$filename $plugin->name['filename'];
        
$dir $plugin->dir;
        
$css $plugin->css;
        
$images $plugin->images;
        
        if(isset(
$_GET["jquery_plugin_$name"])){
            
exec("cp -r files/JavaScript/jQuery/plugins/$dir/$filename $deploy_download/js/$filename");
            
$jquery_plugins $jquery_plugins."\n\t<script type=\"text/javascript\" src=\"js/$filename\"></script>";
            if(isset(
$css)){

            }
            if(isset(
$images)){

            }
        }
    }
}
else {
    
$jquery_plugins '';

oscargodson is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 10:07 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0