View Full Version : Inserting PHP Twitter aggregation in footer help
clayton47
12-07-2011, 04:43 PM
I have a simple php script for twitter aggregation that I want to embed into the footer of my vbulletin site. I am very familiar with code, but its not displaying. It just shows the code like it wasn't wrapped in php tags. So I tried to create a php widget, and it displayed above the header of the site, and showed some errors referring to lines of code in its config file. I have the script working on a plain php page outside of vbulletin on the same server and it doesn't show any errors.
Does anyone know why it would not work correctly while inserted into the vbulletin site? All I am wanting to do is show some specific users latest tweets on my site. But displaying using php not javascript.
I had posted on vbulletin.com but they told me to post here.
Thanks for any help!
If you use the code in a php widget, you'd probably need to change it to save any output in a string called $output, otherwise it will come out at the top of the page as you saw. If you don't want to go though and change the code, you could also do something like this:
ob_start();
// put script code or include here
$output = ob_get_contents();
ob_end_clean();
You could also do the same thing without a widget (if you want), by putting that code in a plugin and registering the variable to a template, like
ob_start();
// put script code or include here
$my_output = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer', array("my_output" =>$my_output));
Then in the footer template use:
{vb:raw my_output}
clayton47
12-07-2011, 05:42 PM
Thank you for your reply. I am going to plug this stuff in and see what I run into. Thank you very much for your help!
--------------- Added 1323283861 at 1323283861 ---------------
One quick question. what should I specify as the "hook location"? This would be my first plugin to configure with vbulletin.
One quick question. what should I specify as the "hook location"? This would be my first plugin to configure with vbulletin.
For something going in the footer, parse_templates is probably a good one to use. It's called just before the header and footer templates are rendered (you can see where it is if you look in includes/class_bootstrap.php and search for parse_templates).
clayton47
12-07-2011, 06:25 PM
ob_start();
// put script code or include here
<?php
require("TwitterClass.php");
$twitter = new Twitter();
$user1 = $twitter->getTweetInfo("mxpimp47");
$user2 = $twitter->getTweetInfo("freestonemx");
foreach($user1 as $status)
{
$id = $status["id"]; // status ID
$text = $status["text"]; // actual status
echo "<p> $text </p>";
echo "<br />";
}
foreach($user2 as $status)
{
$id = $status["id"]; // status ID
$text = $status["text"]; // actual status
echo "<p> $text </p>";
echo "<br />";
}
?>
$my_output = ob_get_contents();
ob_end_clean();
vB_Template::preRegister('footer', array("my_output" =>$my_output));
I think I have some things mixed up, Im not quite sure working with this block you gave me. I also looked this- https://www.vbulletin.com/forum/showthread.php/173937-How-to-Include-a-PHP-or-HTML-File is this another way to insert a chunk of php or is this for like a whole page?
I think I have some things mixed up, Im not quite sure working with this block you gave me.
I think you need to get rid of the <?php and ?> around your code.
I also looked this- https://www.vbulletin.com/forum/showthread.php/173937-How-to-Include-a-PHP-or-HTML-File is this another way to insert a chunk of php or is this for like a whole page?
That looks like the same thing I mentioned above. It would work in either a plugin or a custom page.
clayton47
12-09-2011, 03:45 PM
Ok I got it working, but in vbulletin it gives me an error. installed in its own directory on my server it works fine and doesn't throw any errors.
Warning: file_get_contents(http://twitter.com/statuses/user_timeline/I.xml) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in [path]/TwitterClass.php on line 400
I know its relevant to the code I'm using to display the twitter feeds. But I didnt know if you could tell from the error what might be interfering.
Well, the url it's trying to open *is* invalid, so if it's working outside of vbulletin it must be because it's opening a different url. Maybe the url string is being built from some config information that it's not getting in the vb integrated "version".
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.