Register Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools
  #1  
Old 25 Jul 2014, 21:46
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Cool where to place my safe custom functions?

Hi...

Possibly a new security feature of my vBulletin is stopping me from including my custom php file which has a custom-function within it and then using that function in a custom template, where should I place my 'safe' function and get my template working again?

The error I'm having is:

Fatal error: Call to undefined function customfunction() in /home/www/xxx/includes/adminfunctions_template.php(3950) : eval()'d code(277) : eval()'d code on line 47

please advise
Reply With Quote
  #2  
Old 25 Jul 2014, 21:52
tbworld tbworld is offline
 
Join Date: Oct 2008
Use hook: template_safe_faunctions


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Hopefully, I understood your question correctly.
Reply With Quote
  #3  
Old 25 Jul 2014, 23:19
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Originally Posted by tbworld View Post
Use hook: template_safe_faunctions


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Hopefully, I understood your question correctly.
Yes I think you have...Not sure where to use it, but i'll try thanks
Reply With Quote
  #4  
Old 25 Jul 2014, 23:28
tbworld tbworld is offline
 
Join Date: Oct 2008
This should help.

http://www.vbulletin.com/docs/html/f...n_conditionals

If you have a specific question and you can show your work, then I can be of more assistance.
Reply With Quote
  #5  
Old 25 Jul 2014, 23:37
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Thank you...

Yes were on the right track...

I have a custom php file in my forums directory which through a template is being included, all that php file really has in it is that function, the template is not being saved telling me it's undefined...

So in the php file I've included the line : $safe_functions[] = 'myFunction';
but it's a no show still...

It all used to work using vBulletin 3.8.7 Patch Level 4 - Just need to let vB know that myFunction is a good'un and I'm golden.. the custom php file is being included, just can't save the template without an error....

Thanks for the help.

\
EDIT, I'm getting it now I think....
Reply With Quote
  #6  
Old 25 Jul 2014, 23:54
tbworld tbworld is offline
 
Join Date: Oct 2008
Originally Posted by b6gm6n View Post
Thank you...

Yes were on the right track...

I have a custom php file in my forums directory which through a template is being included, all that php file really has in it is that function, the template is not being saved telling me it's undefined...

So in the php file I've included the line : $safe_functions[] = 'myFunction';
but it's a no show still...

It all used to work using vBulletin 3.8.7 Patch Level 4 - Just need to let vB know that myFunction is a good'un and I'm golden.. the custom php file is being included, just can't save the template without an error....

Thanks for the help.

\
EDIT, I'm getting it now I think....

"Safe Functions" allows a PHP function or user function to be accessible via a template. It's main purpose was to limit harmful functions from being executed at presentation. "$safe_function" is an array that you can add the name of your function to, this is added to the array at template hook: "template_safe_functions". (See .. "/includes/adminfunctions_template.php" around line ~1888.

I have a notion that you are trying to send information to the template through output buffering, but cannot be sure without seeing your code. My forte' lies with vb4, so you could be still doing something I am not familiar with.

Last edited by tbworld; 26 Jul 2014 at 00:07.
Reply With Quote
  #7  
Old 25 Jul 2014, 23:59
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Yeah I dunno...

just want a function included simple as...

so I see in my 'adminfunctions_template.php' this line:

($hook = vBulletinHook::fetch_hook('template_safe_functions')) ? eval($hook) : false;

What's a hook? do I need to create a new plugin for my function? insert some code into my custom php file to allow vB to accept it? or insert more code into my custom template? or create a new template with proper allowed custom functions? - I'm confused...

I'll explain, this should be easier you know

Got a custom php file, it's being included, here's the code

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So in my custom template I have this line:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

It's all commented out at the moment as I can't save it without that error

Thanks ever so for the help, I just can't seem to understand what's what with this, cheers

--------------- Added 26 Jul 2014 at 00:28 ---------------

I placed in the admin_functions template near those lines you mentioned

'$safe_functions = array(
'paginateRecords', // test
);


so it's like this now:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

just to add my function at the end, still can't save my template.. same error

Last edited by b6gm6n; 26 Jul 2014 at 00:29.
Reply With Quote
  #8  
Old 26 Jul 2014, 00:44
kh99 kh99 is offline
 
Join Date: Aug 2009
Real name: Kevin
Originally Posted by b6gm6n View Post
What's a hook? do I need to create a new plugin for my function? insert some code into my custom php file to allow vB to accept it? or insert more code into my custom template? or create a new template with proper allowed custom functions? - I'm confused...
Other than using variables to build the output html, in general you cannot put php in a template. The exception is in a conditon (i.e <if condition="....), and then you can only put what would go in a php 'if' statement, and you can only use the "safe" functions.

But I don't think that's what you want. It looks to me like you are trying to call your custom function to do some formatting, in which case you would want to use a plugin. Your code would then create one or more variables and you'd use them in a template.

So, which hook location should you use? It depends on what you're trying to do. Hooks are just places in the vbulletin scripts where addon code can be called, so you need to find one in a location that's allows you to do what you want to do.
Reply With Quote
  #9  
Old 26 Jul 2014, 01:12
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Originally Posted by kh99 View Post
Other than using variables to build the output html, in general you cannot put php in a template. The exception is in a conditon (i.e <if condition="....), and then you can only put what would go in a php 'if' statement, and you can only use the "safe" functions.

But I don't think that's what you want. It looks to me like you are trying to call your custom function to do some formatting, in which case you would want to use a plugin. Your code would then create one or more variables and you'd use them in a template.

So, which hook location should you use? It depends on what you're trying to do. Hooks are just places in the vbulletin scripts where addon code can be called, so you need to find one in a location that's allows you to do what you want to do.
Got ya... might need a little help, I'm getting there, I've created a plugin with that function, see below:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

no errors, in my template which I can save now shows nothing on the page itself, just a white screen...

My template (incidentally I have php plugin which allows me to use php in templates, so for the 'echo' statement I'm hoping is all ok)


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

So I'm getting there, do I need to call the hook/function in a different way within my custom template? please advise, thank you
Reply With Quote
  #10  
Old 26 Jul 2014, 01:31
tbworld tbworld is offline
 
Join Date: Oct 2008
Couple questions:
What modification are you using to include PHP in templates?
What template are you inserting this into?

You do not need "$safe_functions" for what you are doing, since you are circumventing the template system.

Give me a few minutes to get my bearing on this with VB3.
Reply With Quote
  #11  
Old 26 Jul 2014, 01:57
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
OK thanks for the help...

The plugin to allow PHP is called 'Product : Let PHP Live!' and looks like this:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Seems to work OK or did...
The template I'm using is a custom one, see below:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.


On my forum I just link to my php file which calls up my template:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I've got that plugin with the custom-functions I want installed and there's no errors there, but my php top10 page is pure white at the moment, nothing shown... so dunno what to try next actually, but thanks for the help thus far.

--------------- Added 26 Jul 2014 at 16:59 ---------------

Adding the hooks etc seems to work... just blank output


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

That function when included from that file seemed relative to that $page variable on the next line down and so the echo was easy, but because the now safe function is running all the time for some reason the $page line isn't relative to that function anymore... and so balks and echos nothing... not sure.

Last edited by b6gm6n; 26 Jul 2014 at 17:00.
Reply With Quote
  #12  
Old 26 Jul 2014, 19:25
tbworld tbworld is offline
 
Join Date: Oct 2008
* Removed *

Last edited by tbworld; 27 Jul 2014 at 22:18.
Reply With Quote
  #13  
Old 26 Jul 2014, 23:05
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Lovely... would you believe I was going along similar lines...

Anyway, if you could clear a few things up... I've followed everything here and it's very clear, getting a good understanding, I have one more template/php-file to do like this and I'll apply your enlightening way to that also...

Right, well it's working, kinda... I can see what's happening, top10.php seems fine, template is fine, when called I see my forum header, the outout header and graphic and the footer graphic and then the forum footer itself, but nothing inbetween...

What I'm doing as you would of guessed is reading a file from ftp, putting a 100 lines of it into a text file/flat-file and then trying to read it out nicely... seems like the fault of the 'top10.txt' which checking now is zero bytes, so it's making the file, putting nothing into it and then reading nothing out, so it's either my ftp url which I'm sure is right or line 94 of the top10.php which is:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

Before it was actually connecting via ftp and making the file for reading, so that line above would that need the full ftp url? I'm reading a text file (well a lua file) the ftpurl line is similar to this:


Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

almost there old boy... but yeah I did think of putting everything into my php file and using a string to output it all, but you have done a much nicer job and I'll follow this way in future, thanks ever so for helping me.
Reply With Quote
  #14  
Old 27 Jul 2014, 01:08
tbworld tbworld is offline
 
Join Date: Oct 2008
Remove that line it is a typo. That was for my local test data. I will remove it from the message above, sorry.

Most of your html code could have easily been placed into the template. Which would have made it easier to code, once you get the hang of things.

Last edited by tbworld; 27 Jul 2014 at 01:23.
Reply With Quote
  #15  
Old 27 Jul 2014, 01:18
b6gm6n's Avatar
b6gm6n b6gm6n is offline
 
Join Date: Aug 2002
Real name: Ant
Thanks, Done...

I'm still trying to work out why it's creating a zero-byte 'top10.txt' file and putting nothing into it for reading... hmmm so I'm getting an output of zilch, Can't see anything obvious...

EDIT, ahh right, removed the top10.txt and it worked, showing records... but all of them

Up to 95 records before it breaks... no pagenation

Example shown:

Block Disabled:      (Update License Status)  
Suspended or Unlicensed Members Cannot View Code.

I was using the underscore _ to split the data

Last edited by b6gm6n; 29 Jul 2014 at 17:37.
Reply With Quote
Reply



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

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


New To Site? Need Help?

All times are GMT. The time now is 07:42.

Layout Options | Width: Wide Color: