vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Can I Output A PHP Widget In a HTML Widget or Allign PHP Output (https://vborg.vbsupport.ru/showthread.php?t=279100)

B16MCC 02-24-2012 07:39 AM

Can I Output A PHP Widget In a HTML Widget or Allign PHP Output
 
Hi guys, I've got an existing PHP Direct Exec widget using the following code :-

PHP Code:

ob_start();
include(
"radio_stats_martin.php");
echo 
"<br />\n";
$output .= ob_get_contents();
ob_end_clean(); 

This is working fine.

How would I display the output of that same radio_stats_martin.php in a Static HTML widget ?

Thanks
B16MCC.

kh99 02-24-2012 02:00 PM

I don't think you can. You can't run php as part of a static html widget. If the output never changes you could copy the output and paste it in an html widget. But if it's working the way it is, why would you want to change the widget type?

B16MCC 02-24-2012 02:32 PM

1 Attachment(s)
OK Thanks. The reason was to do with formatting the output. I'll expand on what I'm trying to do and perhaps approach it from a different angle.

I have this code in a PHP widget.

PHP Code:

ob_start();
include(
"radio_stats_martin.php");
echo 
"<br />\n";
$output .= ob_get_contents();
ob_end_clean();

ob_start();
include(
"radio_stats_alex.php");
echo 
"<br />\n";
$output .= ob_get_contents();
ob_end_clean(); 

As you can see, this is duplicate code but referring to 2 different php files.
The output is shown below.
https://vborg.vbsupport.ru/attachmen...1&d=1330097329

The php files are checking the status of 2 different shoutcast servers and outputting to my widget based on wether the server is broadcasting or not, so this output is dynamic.

Basically I want to arrange the 2 outputs side by side rather than one below the other. The reason I asked about a HTML widget is because I could put the outputs into tables, or so I thought. As you've now confirmed I can't do that.

Any help is greatly appreciated.

Thanks for reading.
B

kh99 02-24-2012 02:45 PM

Oh, OK. You can do that in a php widget. You can just do something like:

PHP Code:

ob_start(); 
include(
"radio_stats_martin.php"); 
$martin ob_get_contents(); 
ob_end_clean(); 

ob_start(); 
include(
"radio_stats_alex.php"); 
$alex ob_get_contents(); 
ob_end_clean();  

$output "<table><tr><td>$martin</td><td>$alex</td></tr></table>"


If you wanted you could use a template, maybe like this:

PHP Code:

ob_start(); 
include(
"radio_stats_martin.php"); 
$stats['martin'] = ob_get_contents(); 
ob_end_clean(); 

ob_start(); 
include(
"radio_stats_alex.php"); 
$stats['alex'] = ob_get_contents(); 
ob_end_clean();  

$templater vB_Template::create('radio_stats');
$templater->register('stats'$stats);
$output $templater->render(); 


Then create a radio_stats template with whatever html you want and put {vb:raw stats.martin} or {vb:raw stats.alex} wherever you want them.

BTW, I don't know why I used $martin and $alex in the first one but a $stats array in the second one - you could do it either way in either example).

B16MCC 02-24-2012 02:55 PM

Thanks a lot. Those options are really useful.. I'll work something out from your example.

--------------- Added [DATE]1330099902[/DATE] at [TIME]1330099902[/TIME] ---------------

Sorry to be a pain, I've looked at the template method but I'm a little confused.
Could you give a little more detail on how I create this please ?
I'm confused about wether the code goes in a php file or in the template ?

--------------- Added [DATE]1330102316[/DATE] at [TIME]1330102316[/TIME] ---------------

Nah, struggling coming up with the template method. I'm just posting again in hope that the thread will be highlighted again. Thanks.

B16MCC 02-24-2012 05:42 PM

1 Attachment(s)
Well eventually I got it looking how I want it. I've attached my code and a screen shot for anyone else it may help.

PHP Code:

ob_start();  
include(
"radio_stats_martin.php");  
$martin ob_get_contents();  
ob_end_clean();  

ob_start();  
include(
"radio_stats_alex.php");  
$alex ob_get_contents();  
ob_end_clean();   

$output "<center><table width='96%'><tr><td width='45%'><div class='cms_widget'>$martin</div></td><td width='10%'></td><td width='45%'><div class='cms_widget'>$alex</div></td></tr></table></center>"

https://vborg.vbsupport.ru/attachmen...1&d=1330108898

Don't worry about the 'Current Song' text, that's actually a moving marquee. So that's why it looks a little odd on a screen grab.

Thanks so much for your help. I'm learning a lot here, Cheers.

kh99 02-24-2012 06:06 PM

Thanks for posting your result.

Yeah, unfortunately I usually miss it when the auto-merge kicks in so I missed your previous questions. But to answer, the template method should have worked by putting all the code I posted in a php widget and creating the template using the Style Manager.


All times are GMT. The time now is 06:39 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01051 seconds
  • Memory Usage 1,744KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete