Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
  #1  
Old 12-07-2011, 04:43 PM
clayton47 clayton47 is offline
 
Join Date: Oct 2011
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Inserting PHP Twitter aggregation in footer help

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!
Reply With Quote
  #2  
Old 12-07-2011, 05:23 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:

PHP Code:
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

PHP Code:
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:

Code:
{vb:raw my_output}
Reply With Quote
  #3  
Old 12-07-2011, 05:42 PM
clayton47 clayton47 is offline
 
Join Date: Oct 2011
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 [DATE]1323283861[/DATE] at [TIME]1323283861[/TIME] ---------------

One quick question. what should I specify as the "hook location"? This would be my first plugin to configure with vbulletin.
Reply With Quote
  #4  
Old 12-07-2011, 06:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by clayton47 View Post
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).
Reply With Quote
  #5  
Old 12-07-2011, 06:25 PM
clayton47 clayton47 is offline
 
Join Date: Oct 2011
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
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/show...P-or-HTML-File is this another way to insert a chunk of php or is this for like a whole page?
Reply With Quote
  #6  
Old 12-07-2011, 06:57 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by clayton47 View Post
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.


Quote:
I also looked this- https://www.vbulletin.com/forum/show...P-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.
Reply With Quote
  #7  
Old 12-09-2011, 03:45 PM
clayton47 clayton47 is offline
 
Join Date: Oct 2011
Posts: 33
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #8  
Old 12-09-2011, 03:54 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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".
Reply With Quote
Reply

Thread Tools
Display Modes

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

Forum Jump


All times are GMT. The time now is 05:19 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04496 seconds
  • Memory Usage 2,244KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (3)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete