HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Creating Tempcode Symbols

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#38737 (In Topic #8705)
Joe
Avatar

Honoured member

The symbols basically replace some PHP code, correct? I want to add a PHP include statement to TOP.tpl, but obviously that's not possible.

Code (php)

case 'BLAH':
            $value=include("http://www.blah.com/");
            break;

Would this work if I added that code to symbols.php?

Back to the top
 
Posted
Rating:
#38740
Avatar

ocPortal has URL-includes disabled for security reasons, so that specific line of code you're trying to run wouldn't work unless you first turned them back on with @ini_set('allow_url_fopen','1');.

There's an alternative supported way to get PHP code into templates so you don't actually need to add a symbol.
You can do {$BLOCK,myblock} and then put normal PHP code into sources_custom/miniblocks/myblock.php.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#38745
Joe
Avatar

Honoured member

Ehh, do I type that in OcCLE?

Back to the top
 
Posted
Rating:
#38746
Joe
Avatar

Honoured member

Well, the PHP I'm trying to include is some query script that connects to my gaming server and outputs current players that are on the server.

I can only use an include statement because the server ocPortal is installed on doesn't allow UDP connections (which the query script requires), so I have to include the query script remotely.

Back to the top
 
Posted
Rating:
#38747
Joe
Avatar

Honoured member

I tried typing that into OcCLE, but I got an error. This seems to work though:

:ini_set('allow_url_fopen','1');

Same thing?

Back to the top
 
Posted
Rating:
#38748
Avatar

Code (php)

case 'BLAH':
            @ini_set('allow_url_fopen','1');
            $value=include("http://www.blah.com/");
            break;
 
and in the template:

Code

{$BLAH}


OR


In sources_custom/miniblocks/myblock.php

Code (php)

<?php
            @ini_set('allow_url_fopen','1');
            echo include("http://www.blah.com/");
?>
 
and in the template:

Code

{$BLOCK,myblock}


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#38749
Joe
Avatar

Honoured member

Oh, well I feel like a complete idiot. :P

Well, OcCLE accepted that last command…what should I do?

:ini_set('allow_url_fopen','0');

?

Back to the top
 
Posted
Rating:
#38750
Joe
Avatar

Honoured member

Hmm. I get a blank page... :(

Back to the top
 
Posted
Rating:
#38751
Avatar

None of this stuff is for OcCLE. You could type the 'ini_set' command into OcCLE but that command needs setting each time a script runs it doesn't help. In my examples above I've put the command before the include command you wrote, which is what's needed.


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: