Buying 10$ to fix the following script

Discussion in 'Programming' started by schlogo, Sep 4, 2012.

  1. #1
    Hello

    Here s a quick problem, i am under Joomla trying to get the value of a variable in a plugin, inside a template. It looks more or less like this
    
    <?php           
    $extrafieldsid[$itemid->id] = $itemid->value;     
    }        
    $variable = $extrafieldsid[11];
    
    $plug1 ='{myplugin value1=\"<?php echo $variable;?>\"
                              value2=\"bart\" 
                              value3=\"Maggie\" 
                              value4=\"popup\" 
                              value5=\"alf\" 
                              value6=\"400\" 
                             /}';
      echo JHTML::_('content.prepare',$plug1);
    ?>
    Code (markup):
    if i test the value of $variable before or after the plugin, it works, but when the plugin returns value1 .. it returns the php code

    First person coming up with the right way to insert variable in the plugin code gets 10 by paypal. Other values are returned correctly .
     
    schlogo, Sep 4, 2012 IP
  2. Riboflavin

    Riboflavin Well-Known Member

    Messages:
    1,091
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    155
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    What value is it returning exactly?
     
    Riboflavin, Sep 4, 2012 IP
  3. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #3
    instead of the value, it returns the php code :

    <?php echo $variable;?>
     
    schlogo, Sep 4, 2012 IP
  4. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #4
    <?php
    $extrafieldsid[$itemid->id] = $itemid->value;
    }
    $variable = $extrafieldsid[11];

    $plug1 ='{myplugin value1=\ "$variable \"
    value2=\ "bart \"
    value3=\ "Maggie \"
    value4=\ "popup \"
    value5=\ "alf \"
    value6=\ "400 \"
    /}';
    echo JHTML::_('content.prepare',$plug1);
    ?>
     
    Codythebest, Sep 4, 2012 IP
  5. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #5
    Sorry Codythebest, it returns empty
     
    schlogo, Sep 4, 2012 IP
  6. nhl4000

    nhl4000 Well-Known Member

    Messages:
    479
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #6
    Please check your PM for my attempt. Hope it works!
     
    nhl4000, Sep 4, 2012 IP
  7. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #7
    hello, i ve tried, not working :-/
     
    schlogo, Sep 4, 2012 IP
  8. nhl4000

    nhl4000 Well-Known Member

    Messages:
    479
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    110
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #8
    Hmm, interesting. I've sent you some debugging options that may provide some valuable info.
     
    nhl4000, Sep 4, 2012 IP
  9. creativeGenius

    creativeGenius Well-Known Member

    Messages:
    273
    Likes Received:
    5
    Best Answers:
    1
    Trophy Points:
    120
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #9
    please change it to

    $plug1 ='{myplugin value1=\ "'.$variable .'\"
    value3=\ "Maggie \"
    value4=\ "popup \"
    value5=\ "alf \"
    value6=\ "400 \"
    /}';
     
    creativeGenius, Sep 4, 2012 IP
  10. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #10
    @creativeGenius someone proposed this my pm, it does not work either . Tks for your try
     
    schlogo, Sep 4, 2012 IP
  11. ~

    ~ Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #11
    Hi.

    What about using a randomized string marker, so you can replace it solely just before calling your plugin, at which point you should already have $variable set properly?

    Also, are you setting $variable in some PHP script/page, and then trying to access it from another one in the web? If so, then you would probably need to pass the value of the $variable via GET or POST at the very least.
    _____________________________
    _____________________________
    
    <?php           
    $extrafieldsid[$itemid->id] = $itemid->value;     
    //}  //<-- This curly bracket seems to be an error/typo, but if it's not, just uncomment it!
    $variable = $extrafieldsid[11];
    
    
    
    //BEFORE CALLING YOUR PLUGIN (Action 1 of 3):
    //Create a random marker as to
    //where to insert the '$variable' value:
    ///
     $plug1_rand="DOLLARvariable".mt_rand();
    
    
    
    //BEFORE CALLING YOUR PLUGIN (Action 2 of 3):
    //See how now we reference our randomized
    //string marker instead of '$variable' directly.
    //Now we can get the correct value just when
    //it is ready for use.
    //
    //Note also that now our double quotes are
    //used in a more readable way (escaping them isn't
    //necessary as this string is quoted by single quotes):
    ///
     $plug1 ='{myplugin value1="'.$plug1_rand.'"
                              value2="bart" 
                              value3="Maggie" 
                              value4="popup" 
                              value5="alf" 
                              value6="400" 
                             /}';
    
    
    
    //BEFORE CALLING YOUR PLUGIN (Action 3 of 3):
    //See how now we apply a string replacement
    //on the randomized string marker.
    //AT THIS POINT, '$variable' SHOULD BE SET;
    //OTHERWISE, THERE IS ANOTHER ADDITIONAL
    //ERROR SOMEWHERE ELSE:
    ///
      echo JHTML::_('content.prepare', str_replace($plug1_rand, $variable, $plug1));
    ?>
    
    Code (markup):
     
    Last edited: Sep 5, 2012
    ~, Sep 5, 2012 IP
  12. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #12
    sorry, not working
     
    schlogo, Sep 5, 2012 IP
  13. ~

    ~ Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #13
    Did you make sure to remove the apparently missing curly bracket at line 3, and that you aren't generating Error 500 at the server side, or the like?

    Did you make sure that $extrafieldsid[ 11 ] actually contains something that isn't a blank string, and that you didn't mean to use $extrafieldsid[ $itemid->id ] instead?

    Aren't you setting $variable in a PHP document and pretending to reuse it by navigating away to a completely different PHP document (in which case you should pass the variable via GET or POST at the very least, by something like $_GET["DOLLARvariable"])?

    Chances are that the code is working, and you have another problem in your actual PHP script, which isn't showing here.

    The raw code worked for me, because I don't have the actual plugin. It worked like the following so I know this is working in its raw form. You indeed have another problem, but this problem has been solved in its raw form:

    <?php
    
    //Create a random marker as to
    //where to insert the '$variable' value:
    ///
     $plug1_rand="DOLLARvariable".mt_rand();
     $variable="Change plug1_rand for me";
    
    $plug1 ='{myplugin value1="'.$plug1_rand.'"\n
                              value2="bart"\n
                              value3="Maggie"\n
                              value4="popup"\n
                              value5="alf"\n
                              value6="400"\n
                             /}';
    
      echo "<pre>".str_replace($plug1_rand, $variable, $plug1)."</pre>";
    
    ?>
    Code (markup):
     
    Last edited: Sep 5, 2012
    ~, Sep 5, 2012 IP
  14. Codythebest

    Codythebest Notable Member

    Messages:
    5,764
    Likes Received:
    253
    Best Answers:
    0
    Trophy Points:
    275
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #14
    If it returns empty, it's because $extrafieldsid is.
     
    Codythebest, Sep 5, 2012 IP
  15. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #15
    @cody It s not. outside the {}, i can echo it and the value is what is should be
     
    schlogo, Sep 5, 2012 IP
  16. Basti

    Basti Active Member

    Messages:
    625
    Likes Received:
    6
    Best Answers:
    3
    Trophy Points:
    90
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #16
    schlogo,
    ive have given it it a bit of research and it appears you cannot use php in the joomla content plugin tags without a extra extension like Jumi, directphp and the likes.

    As all our methods we have posted so far really do work (in a php point of view, excluding joomla ), i believe this is your issue here.
     
    Basti, Sep 5, 2012 IP
  17. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #17
    hello Basti i am going to check this out
     
    schlogo, Sep 5, 2012 IP
  18. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #18
    @Basti, actually, i guess php can't be used in content loke articles, but here, we are in the template, it should not be
     
    schlogo, Sep 5, 2012 IP
  19. ~

    ~ Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #19
    Please give an example of the value. Then try the following code. Now I use a static string marker for the value where $variable should be.

    With this, now you can place that exact string code in a separate PHP "template" if you need it, and include it from another PHP script.

    In any case, please provide us with more relevant code. We have already solved the problem according to the data you have given. At this point it has to be working unless there are errors you aren't showing us.


    <?php           
    $extrafieldsid[$itemid->id] = $itemid->value;     
    //}  //<-- This curly bracket seems to be an error/typo, but if it's not, just uncomment it!
    $variable = $extrafieldsid[11];
    
    
    
    //BEFORE CALLING YOUR PLUGIN (Action 1 of 3):
    //Create a constant string marker as to
    //where to insert the '$variable' value:
    ///
     $plug1_const="DOLLARvariable_112233445599";
    
    
    
    //BEFORE CALLING YOUR PLUGIN (Action 2 of 3):
    //See how now we reference our constant
    //string marker instead of '$variable' directly.
    //Now we can get the correct value just when
    //it is ready for use.
    //
    //Note also that now our double quotes are
    //used in a more readable way (escaping them isn't
    //necessary as this string is quoted by single quotes):
    ///
     $plug1 ='{myplugin value1="DOLLARvariable_112233445599"
                              value2="bart" 
                              value3="Maggie" 
                              value4="popup" 
                              value5="alf" 
                              value6="400" 
                             /}';
    
    
    
    //BEFORE CALLING YOUR PLUGIN (Action 3 of 3):
    //See how now we apply a string replacement
    //on the constant string marker.
    //AT THIS POINT, '$variable' SHOULD BE SET;
    //OTHERWISE, THERE IS ANOTHER ADDITIONAL
    //ERROR SOMEWHERE ELSE:
    ///
      echo JHTML::_('content.prepare', str_replace("DOLLARvariable_112233445599", $variable, $plug1));
    ?>
    
    
    Code (markup):
    Remember to make sure that all of the used variables are defined and useable in both scripts before echoing finally at the last shown line, if you are using more than one PHP script for this, remember to use the GET/POST suggestion if it applies, and then please report back.
     
    Last edited: Sep 5, 2012
    ~, Sep 5, 2012 IP
  20. schlogo

    schlogo Well-Known Member

    Messages:
    1,615
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    140
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #20
    ok, i try this now
     
    schlogo, Sep 5, 2012 IP