Some time ago, there was a question on the Drupal forums about wrapping content from another site to your site.
Here is a basic PHP code snippet that would do just that. You may need to fiddle with the HTML to make the paths absolute to the site that you are wrapping.
If you have improvements, please let me know.
Also, please do not use this to leech content from other sites, and obey their copyright rules.
Method 1: Using fopen on a URL
$url = "http://example.com";
$handle = @fopen ( $url, "r" );
if ( $handle ) {
while ( true ) {
$data = fgets ( $handle, 4096 );
print $data;
if ( true == feof( $handle ) ) {
break;
}
}
fclose ( $handle );
}
else {
$result .= t("Could not contact host: ") . $url;
}
Method 2: Using fopen on a URL - more concise way
After writing the above, Drupal hacker par excellance, Karoly Negyesi (a.k.a. chx), found a much more elegant and simple solution:
$url = "http://example.com/page.html";
print file_get_contents($url);
This is much less code for sure.
Method 3: Using IFRAMEs
You can use an IFRAMEs to wrap content from another site, or another application on your site.
To do this, all you need is to paste the following HTML snippet in the block or the node you want. You will have to experiment with the height and width until you get the size that works best for the site you are wrapping.
<iframe
src="http://www.example.com"
Frameborder=0
height="600"
width="640">
</iframe>
Comments
Marco (not verified)
Saving to node
Sat, 2005/12/10 - 22:28I was thinking of putting this code to practical use -
Perhaps by making a new content type that can do this sort of processing in Method 1.
I wonder if it were possible to implement the code so I could make a new content type when you input the URL to wrap - it would wrap it when you create the content and not every time you load the page, effectively saving the wrapped content into your database.
Can the be easily done?
Khalid
Yes, it can be done
Sun, 2005/12/11 - 00:12Yes, it can be done. The node type would only need to have a URL, and perhaps a title, and the authoring information. There is no need for a body.
The challenge is that if the wrapped page has path names relative to the domain/host name it is wrapped from. In that case, you have to do some adjusting to add that to each href tag.
tallship (not verified)
I'm still stumped...
Wed, 2010/07/14 - 04:32When I go to http://abc.com/node/16/ for example, where I created the node (page), I only see the following in the body of the page:
Pages