PHP javascript syndicator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soon
Forum Newbie
Posts: 2
Joined: Thu Jan 01, 2004 3:59 pm
Location: Derby UK

PHP javascript syndicator

Post by soon »

Hi

With the help of a friend, I have a nice script which allows other people to use my page content. It automatically parses any page of mine between two markers, turns it into javascript, so the end user can just put a javascript insert code on his or her page, and pull down the content. Please use it on your own pages if you find it useful!

One thing I still need to do is get over the problem of relative links. Obviously when it parses a relative link, it stays relative on the end-users site - no use. So what is needed is the script to look at a link, and if it containts a href but no http://, it will need to add my specified base url to each link.

A further need is that offsite links on my site are made in this form:

Code: Select all

href="frameforlinks.php?id=http://www.offsitelink.org.uk/&referer=<? echo $_SERVER&#1111;"SCRIPT_URL"];?>
because they link via a removable narrow top frame. Currently, the script just displays the code

Code: Select all

<? echo $_SERVER&#1111;"SCRIPT_URL"];?>
visibly in the parsed javascript content. So there is also a need for the script to replace that code any time it comes to it, with nothing, as it parses the page.


If anyone can see the way to do these things - AND tell me just where to put the code into the existing code below - I'm not that bright - I'd be very grateful!

Code: Select all

<?php

function getPageContent( $url )&#123;
	return( implode( file( $url ), "" ) );
&#125;

function parseContentByTagName( $content )&#123;
	preg_match_all( '/<div id="mycontentuniqueID">(&#1111;\n\r\w\W.]*?)<\/div>/i', $content, $contentArray );
	return( implode( $contentArray&#1111;0], "" ) );
&#125;

if( $pageID == "" )
	print( "You have passed an invalid page, please include the paramater: pageID" );
else&#123;
	$pageContent = getPageContent( $pageID );
	$pageContent = parseContentByTagName( $pageContent );

	if( $pageContent == "" )
		print( "document.write( "<ul><li><a href='http://www.gospelcom.net/guide/resources/$pageID'>Click here for Web Evangelism Guide page: $pageID</a></ul>" );");
	
	$pageContent = str_replace( '"', '"', $pageContent );
	$pageContent = str_replace( "\n", " ", $pageContent );
	$pageContent = str_replace( "\r", " ", $pageContent );
	$copyrightDate = date("Y"); $pageContent = $pageContent . "<p><span style=''color:black;font-size=80%;margin-left:3em;''>&copy; $copyrightDate web-evangelism.com. Used by permission. <a href=''http://www.mysite.com/conditions.php''>Conditions for re-use</a></span><p><ul style=''margin-left:3em;''><li>Visit the <a href=''http://www.mysite.com''>This site</a> for more pages.</ul>";
	print( "document.write( "" . $pageContent . "" );" );
&#125;
?>
best wishes and thanks for any wisdom

Tony
Post Reply