Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-22-2006, 12:31 PM
optrex optrex is offline
 
Join Date: Sep 2005
Posts: 344
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default PHP in Templates?

Can PHP scripts be added to templates?

I am looking to add the follwing (or similar) to the footer area of my pages. It basically scrapes an area of code from a given webpage. Whats the best way of doing it?

PHP Code:
<?php
$fp 
fsockopen ("domain.co.uk"80$errno$errstr30);
    if (!
$fp) {
        echo 
"$errstr ($errno)<br>\n";
    } else {
        
fputs ($fp"GET /webpage.php HTTP/1.0\r\nHost: domain.co.uk\r\nUser-Agent: MS Internet Explorer\r\n\r\n");
        while (!
feof($fp)) {
            
$content .= fgets($fp,1024);
        }
        
fclose ($fp);
    }
    
    
$start "<!-- Comment Start -->";
$end "<!-- Comment End -->";
    
$null eregi("$start(.*)$end"$content$contentarray);
$item $contentarray[1];
echo 
$item
?>
Reply With Quote
  #2  
Old 06-22-2006, 02:02 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No php in templates. There is a way to do it, but leeching via scraping I have no desire to support or help with. I believe scraping is illegal technically?

Unless you are scraping your own site for the lack of a better method to retrive the data?
Reply With Quote
  #3  
Old 06-22-2006, 02:12 PM
optrex optrex is offline
 
Join Date: Sep 2005
Posts: 344
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Its the latter, I am scraping from my own site.
Reply With Quote
  #4  
Old 06-22-2006, 04:53 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I would suggest you use curl. You can put the hook in global and store the response in a variable after ya process it. Put that variable in the footer template and you're all set.

The advantage is, curl will sort out the socket, the headers, the responses for you. You can set a timeout and do different things if you don't get the response fast enough.

So here's a piece of code I have shared before to do about the same thing, fetch remote data from a website to integrate with vBulletin.

PHP Code:
ob_start();
// set the url
$cf_url 'http://www.example.com/?website_id=xxx';
// wait x seconds if no connection, fail and move on.
$cf_timeout 1;
// inits
$cf_data '';
$cf_gotdata true;
// set up curl
$cf_handle curl_init();
curl_setopt$cf_handleCURLOPT_URL$cf_url );
curl_setopt$cf_handleCURLOPT_CONNECTTIMEOUT$cf_timeout );
curl_setopt$cf_handleCURLOPT_HEADERfalse );
curl_setopt$cf_handleCURLOPT_FAILONERRORtrue );
curl_setopt$cf_handleCURLOPT_FOLLOWLOCATIONfalse );
curl_setopt$cf_handleCURLOPT_RETURNTRANSFERtrue );
$cf_data curl_exec$cf_handle );
if (
curl_errno($cf_handle)) 
{
   
$cf_gotdata false
}
curl_close$cf_handle );
if ( 
$cf_data != '' && $cf_gotdata )
{
    
// display the ads for capture and/or process fetched data
    
echo $cf_data;
}
else
{
    
// do stuff here if no data fetched
}
unset(
$cf_data);
unset(
$cf_handle);
unset(
$cf_timeout);
unset(
$cf_gotdata);
echo 
'<br />';
// put $cf_data in the footer template where you want the returned data displayed.
$cf_data ob_get_contents();
ob_end_clean(); 
Reply With Quote
  #5  
Old 06-23-2006, 09:32 AM
optrex optrex is offline
 
Join Date: Sep 2005
Posts: 344
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Noppid, I'll have a play with that and see how it goes.
Reply With Quote
Reply


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 07:24 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.06115 seconds
  • Memory Usage 2,217KB
  • 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
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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