View Full Version : [Solved] variables in settings of product not work
omardealo
06-03-2013, 12:06 PM
Hello ,
in my product ,i have a textarea setting and print it in a template
i try to put a vb variables in this option
like this
$vboptions[bburl]
$bbuserinfo[userid]
but not worked ...
https://vborg.vbsupport.ru/attachment.php?attachmentid=145258&stc=1&d=1370264714
If you want to allow variables in your setting text, you need to use a plugin to eval() the text before using it in a template. For example:
eval('$my_setting = "' . $vbulletin->options[my_option] . '";');
Then use $my_setting in your template. If you do this, you should be aware that anyone who has access to the settings can execute any php code they want.
Using eval will allow you to use variables in your text. If you also want to use template tags (for example, <if condition=...), then you would need to use the template compiler.
omardealo
06-03-2013, 01:35 PM
Thank you very much kh99 ,
i do this but not worked too
i used $points_pages in a templat ... text does not appear at all
eval('$points_pages = "' . $vbulletin->options[points_pages] . '";');
Which hook did you use for your plugin, and which template are you putting the variable in?
omardealo
06-03-2013, 01:51 PM
Which hook did you use for your plugin, and which template are you putting the variable in?
hook : misc_start
code :
if ($_REQUEST['do'] == 'points')
{
$navbits = construct_navbits(array(
'' => 'points'
));
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('points_page') . '");');
eval('$pointspages = "' . $vbulletin->options[pointspages] . '";');
}
i also try only eval() in hook : golbal_start and i put the variable $pointspages in header template ,to make sure the code is right but not worked too .
Thank you again
Hmm...OK, try this:
require_once(DIR . '/includes/functions_misc.php');
eval('$points_pages = "' . replace_template_variables($vbulletin->options[points_pages], true) . '";');
I think the variables $vboptions and $bbuserinfo may be shortcuts that only work templates, so the function replace_template_variables() will replace them with the longer version. (I haven't tried the above code, hopefully there aren't any errors).
omardealo
06-03-2013, 02:56 PM
thnx , kh99
i'm Sorry ... this code not worked too
Oh, I didn't notice before, in your code you've done the eval() after the template eval() and it would have to be before. So try this code:
if ($_REQUEST['do'] == 'points')
{
$navbits = construct_navbits(array(
'' => 'points'
));
require_once(DIR . '/includes/functions_misc.php');
eval('$pointspages = "' . replace_template_variables($vbulletin->options[points_pages], true) . '";');
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('points_page') . '");');
}
And use $pointspages in your template (you have $point_pages above - of course you can use either one but make sure it is the same everywhere).
omardealo
06-03-2013, 03:38 PM
yes i know names of variables it not a problem , i take care and sure a bout it
look , i try everything
when i used ur code , and i put $vboptions[bbtitle] in setting
show me this error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in misc.php(100) : eval()'d code(7) : eval()'d code on line 1
and if i used code like this not show me error but also not show anthing
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('points_page') . '");');
require_once(DIR . '/includes/functions_misc.php');
eval('$pointspages = "' . replace_template_variables($vbulletin->options[points_pages], true) . '";');
Thank you for your interest and suggestion!
As I mentioned before, your eval for $pointspages must be before the eval for your template. In fact, the function print_output() ends the script and never returns, so anything you put after that will not be executed (which is probably why the error goes away).
I'm trying to do this without trying it myself, so I'm not sure what the issue is. Maybe try this code:
require_once(DIR . '/includes/functions_misc.php');
eval('$pointspages = replace_template_variables("' . $vbulletin->options[points_pages] . '");');
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('points_page') . '");');
What is the text in your pointpages option? Is the text you posted above what you're using now? I'm asking because if it contains any quote characters that could cause problems.
omardealo
06-03-2013, 05:15 PM
yes now is okay ...
but if put html in this setting option must be like this
<a href=\"$vboptions[bburl]\">$vboptions[bbtitle]</a>
befor every " must put \ like PHP files
i think There is another way
by put variable setting in another template and print it in first template
i think this worked too ..
kh99 , God bless you :up:
Your Help make us not despair of finding a solution !
OK, try this:
eval('$pointspages = replace_template_variables("' . addcslashes($vbulletin->options[points_pages], '"') . '");');
I get confused by things like this - I don't know if there are any characters other than " that you should be escaping. But start with that and see what happens.
omardealo
06-03-2013, 07:45 PM
OK, try this:
eval('$pointspages = replace_template_variables("' . addcslashes($vbulletin->options[points_pages], '"') . '");');
I get confused by things like this - I don't know if there are any characters other than " that you should be escaping. But start with that and see what happens.
Erorr function
Fatal error: Call to undefined function pointspages() in misc.php(100) : eval()'d code(8) : eval()'d code on line 1
i hope found way to put html code without escaping any characters
i put simple html code in setting option like this ..
bla bla bla <a href="$vboptions[bburl]">$vboptions[bbtitle]</a>
bla bla bla bla
<ul>
<li>bla bla bla</li>
<li>bla bla bla</li>
<ul>
<br />
bla bla bla .....
Are you saying you've got it working now?
If not, I don't see why you'd get that error. You'd have to post your exact code.
omardealo
06-04-2013, 05:21 AM
Are you saying you've got it working now?
If not, I don't see why you'd get that error. You'd have to post your exact code.
Sorry , You are right , I made a mistake in something
now no erorr but also data not show
code
if ($_REQUEST['do'] == 'points')
{
$navbits = construct_navbits(array(
'' => 'points'
));
require_once(DIR . '/includes/functions_misc.php');
eval('$pointspages = replace_template_variables("' . addcslashes($vbulletin->options[pointspages], '"') . '");');
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('points_pages') . '");');
}
Zachery
06-04-2013, 05:22 AM
shouldn't addcslashes be addslashes
omardealo
06-04-2013, 05:46 AM
shouldn't addcslashes be addslashes
thnx ... i try it
if ($_REQUEST['do'] == 'points')
{
$navbits = construct_navbits(array(
'' => 'points'
));
require_once(DIR . '/includes/functions_misc.php');
eval('$pointspages = replace_template_variables("' . addslashes($vbulletin->options[pointspages], '"') . '");');
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('points_pages') . '");');
}
show to me erorr
Warning: Wrong parameter count for addslashes() in [path]\misc.php(100) : eval()'d code on line 12
--------------- Added 1370328837 at 1370328837 ---------------
sorry i update it by one Parameter
do not show me erorr but data also don't show
eval('$pointspages = replace_template_variables("' . addslashes($vbulletin->options[pointspages]) . '");');
--------------- Added 1370330612 at 1370330612 ---------------
shouldn't addcslashes be addslashes
Maybe, I'm not sure. But addslashes() (http://us2.php.net/manual/en/function.addslashes.php) escapes ', ", \, and null characters. addcslashes() (http://us2.php.net/manual/en/function.addcslashes.php) escapes the characters you list as the second parameter, so I think addcslahses() will work if you provide the correct list of chars. This code is taking the setting text and using it as a double-quoted string. So I know double quotes need to be escaped, but I'm not sure what else might need to be. I don't think single quotes need to be, and I think if you escaped backslashes you couldn't use things like \n in the text.
OK, try this:
eval('$pointspages = "' . replace_template_variables(addcslashes($vbulletin->options[pointspages], '"')) . '";');
omardealo
06-05-2013, 04:05 AM
OK, try this:
eval('$pointspages = "' . replace_template_variables(addcslashes($vbulletin->options[pointspages], '"')) . '";');
Now i'm So HaPpy :D
the code very excellent and works wonderfully
Thank you , kh99
Zachery
06-05-2013, 04:30 PM
Maybe, I'm not sure. But addslashes() (http://us2.php.net/manual/en/function.addslashes.php) escapes ', ", \, and null characters. addcslashes() (http://us2.php.net/manual/en/function.addcslashes.php) escapes the characters you list as the second parameter, so I think addcslahses() will work if you provide the correct list of chars. This code is taking the setting text and using it as a double-quoted string. So I know double quotes need to be escaped, but I'm not sure what else might need to be. I don't think single quotes need to be, and I think if you escaped backslashes you couldn't use things like \n in the text.
That was my fault, I'd never actually seen or used addcslashes, so I was thinking it was a typo. My bad.
omardealo
06-05-2013, 06:24 PM
That was my fault, I'd never actually seen or used addcslashes, so I was thinking it was a typo. My bad.
There is not anything wrong from you, you just want to help
Thank you !
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.