We appreciate your visit – thanks!
close this once-only message

We hope that you are finding this resource guide useful. If you may wish to return, please bookmark this page or the .

 Email if you need help on any topic in the Guide, have suggestions and comments, or can help by reporting a page bug.

Vital resources directly to your mailbox
Like to try our twice-monthly email newsletter Web Evangelism Bulletin? It will give you a unique range of evangelism strategies and news (for Web, church, and beyond), plus webmaster and page promotion tips:



close this once-only messageClose this once-only message box
 Design > Content sharing  < YOU ARE HERE  KEY:
 FAQs
Green link = offsite page 
Blue link = site page 
 Site
 search

 Meaning
 of life?
 
Help
flag



Syndicated content sharing with others

Automated PHP script for HTML to Javascript on-the-fly parse conversion

Definition – 'content sharing' means: offering the contents of a webpage to another website to directly insert into its own page. It is not the same as 'content management', the system by which a number of contributors automatically add or update content to a single website.

Content sharing has a number of advantages. The recipient site obtains added-value by the instant creation of additional pages, ready-written by other people. The donor writer receives additional readers for his or her material, and the donor site receives added exposure via a link on the shared page.

There are several ways of calling up the contents of a page into a recipient site. The method described here uses the Javascript insert method. The user adds a line of code which calls up a file containing the contents of the page, which has been 'parsed' (converted) into Javascript. This method of content sharing is explained here. If you only have a small number of unchanging pages to offer, then it is easy to convert them into Javascript, and place the files on your server for easy linking.

However, if you have a large number of pages that you wish to offer, which may also be frequently updated, there would be considerable work involved in maintaining and updating a duplicate set of pages as Javascript files. The system explained on this page uses PHP to automatically parse into Javascript, any page within a site. Once set up, it is therefore a great time-saver. All the pages on this site are available to insert using this method.

Uses

It can be used to offer relatively unchanging static pages, or those which change on a daily/weekly basis. In a general context, it will work for any useful page whose style of writing is appropriate for a third-party site. In a Christian context (which happens to be the focus of this Guide) it allows sharing of, for example, ready-made teaching, apologetics, or testimony pages.

Although there is a more elegant CSS solution, you could also use it to create a second version of a page within your own site which is 'printer-friendly'. It can remove graphics, navigation bars, etc., and allows CSS to set narrow margins and font size at say, 12pt serif – an ideal printer setup.

The search engine trap

Search engines are in a battle with unethical webmasters who try to increase page ranking and exposure. One trick that they will penalize is the existence of near-identical page content on two different pages or domains. The Javascript insertion method is safe, because text generated by Javascript is invisible to search engines. (And, of course, it is ethical, because the content is not spidered, and therefore is not generating duplicated search engine listings.)

Other methods of content sharing which involve text 'hard-coded' into the page (e.g. normal PHP insertion, or permission to copy/paste the text) are dangerous because they create duplicate content visible to search engines. Any system of content-sharing using 'hard-coding' must be combined with a no-robots meta tag on the page (or in the root directory). It is difficult to expect users to understand this issue and always add no-robots commands to their pages. Without such a guarantee, hard-coding is a dangerous option to offer.

How it works

The user adds a unique 'jump code' to their page, which includes the ID of the page to be parsed. A PHP script on the donor's server then grabs the content of this page, converts it to Javascript and serves it to recipient page. The page's webmaster should also add a <noscript> line to the page, for the small percentage of people who have Javascript disabled. You can view the instructions to potential users offered at the end of almost every page of this site, with an extra page of tips as a side link.

This system will capture web-pages with any file extension: .html, htm, .php, etc.

Absolute/relative links

There are two versions of the script. If the page content you wish to share contains no links to other pages on your site, or those links are absolute, use the shorter version of the script, which is slightly quicker. If you have relative links in your page content, use the second version. This will also convert graphic links from relative to absolute - but only if the graphics are in the same directory, or a directory below the one your page is in.

Can I use PHP?

Many servers are set up to handle PHP. Ask your provider. PHP is a very versatile system which also allows you to insert site-wide elements within all your webpages (eg a standard header, footer, and navigation bar). And that is only the beginning of its time-saving usefulness!

Furthermore, if you currently have webpages ending in the standard .html or .htm file extensions, it may be possible for you to use PHP without changing your page file extensions to 'php', which would spoil all your incoming links, bookmarks, search engine listings, etc. Talk to your site host. If you are not already routinely using PHP, this represents an incredible increase in versatility for you, without any of your page URLs needing to change.

If your server cannot handle PHP, all may not be lost! Find a friend with some spare bandwidth, whose server does handle PHP, and ask if they can host the single PHP script required to make this system work. The script will still work with full paths specified. You can still use a single site-wide insertion code, modified by Javascript, as explained later.

The PHP code


Absolute/no link version:
<?php

// this PHPtoJavascript converter is available from web-evangelism.com/resources/content-sharing.php

function getPageContent( $url ){
        return( implode( file( $url ), "" ) );
}
        function parseContentByTagName( $content ){
        preg_match_all( '/<div id="mycontentuniqueID">([\n\r\w\W.]*?)<\/div>/i', $content, $contentArray );
return( implode( $contentArray[0], "" ) ); }

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

if( $pageContent == "" ) print( "document.write( \"<ul><li><a href='http://www.yoursite.com/pages/$pageID'>Click here for Yoursite Name 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=\'font-size=80%;margin-left:3em;\'>&copy; $copyrightDate web-evangelism.com. Used by permission. <a href=\'http://www.yoursite.com/pages/conditions.php\'>Conditions for re-use</a></span><p><ul style=\'margin-left:3em;\'><li>Visit the <a href=\'http://www.yoursite.com\'>Yoursite Name</a> for more pages on the subject of whatever</ul>"; print( "document.write( \"" . $pageContent . "\" );" ); } ?>

Relative-link version
then copy/paste (CTRL + C/CTRL + V) this code into your own page. Make the changes shown in red on the coding above, and also add in the extra full URL which, added to the page file name, will create an absolute URL
(in the line $mydomain = 'http://www.yoursite.com/directory/';):

User-changable code elements

The page insert code

Explain to the recipient how to add a specific insert code similar to this example, and offer them visible code to paste across in this form:
<script language="JavaScript" src="http://www.yoursite/pages/getPageContent.php?pageID=mypage.html" type=text/javascript>
</script>
and it is wise to encourage them to include a noscript line too, so that their page will make sense to people with Javascript disabled:
<noscript>Click here for <a href="http://www.yoursite.com/pages/mypage.html">Name of page here</a> - short explanation about page
</noscript>
where mypage.html is of course the specific file name of the page they wish to insert into their site.

You will see how this site offers the insert code at the end of nearly every page, within a small textarea from which it is easy to highlight and copy the coding.

Note that the insert script will not operate on your hard drive. The page must be viewed online in order for the script to operate. You must do testing online, unless you have a PHP emulator on your hard-disk.

Automating the insert code for users to copy

Using PHP

You can use PHP to insert the page file-name automatically, allowing you to insert a single site-wide set of instructions which work on any page. On this site (including this page) the page-end box entitled 'Free Content' is itself a site-wide PHP insert, and contains within it a PHP insert to grab the file name. It also uses PHP to grab a page name and description which are in the head of the page in this form: <?php $subject = "Design"; ?> and <?php $shorttitle = "Content sharing"; ?> which also customize the 'bread-crumb trail' at the top of the page. The inserts appear like this in the source code for this page:
src="http://guide.gospelcom.net/resources/getPageContent.php?pageID=<?php echo $file_name = basename($PHP_SELF); ?>"
and within the noscript tag:
Click here for <a href="http://guide.gospelcom.net/guide/resources/<?php echo $file_name = basename($PHP_SELF); ?>"><?php print $shorttitle; ?></a> a section within <b><?php print $subject; ?></b> subject area of the <b>Web Evangelism Guide</b>.
The actual source code on your page will have angle brackets coded by &lt; and &gt;, with the exception of the brackets around the PHP echo commands, in order to produce visible html code for users to copy, which will appear similar to that at the end of this page in the 'Free Content' box.

A second PHP way to grab the page title for insertion into the noscript text is demonstrated here.

Javascript method to grab the current page title and file name

If you are unable to use PHP to grab individual page titles in this way, you can either just leave it to the end user to devise a meaningful noscript description, or you can use Javascript to automatically customize the insert code with file-name and noscript description in a single site-wide block of code: demonstration and code.

Offering the code on a linked page

If you offer the custom insert code on a separate linked page rather than on the page itself, you can use a single page with code which is customized by a script which picks up the information from the referring page.

By PHP: Creates insert code by grabbing the both the file name of the referring page and its title, with PHP. This will automatically create a custom jump-code and <noscript> wording for users to copy: demonstration and code.

By Javascript: If you do not have access to PHP on your server, and have asked a friend to host your getPageContent.php file, you can also use a single site-wide explanation page, using Javascript to insert the file name of the page into the copy/paste jump-code, rather than PHP: demonstration and code.


Saying thank you

This script is helpware. It was generously created by Will Leingang in order to share this Guide's content.

Iif you are using this script on a page intended for a Christian readership, please could you include a link to the Guide homepage:
http://guide.gospelcom.net/index.php

If you use this script on any other sort of site, please consider a link to this page:
http://guide.gospelcom.net/resources/content-sharing.php

If you use the system, we may be able to list your site here as demonstration to others. Please .

If you have never thought about the meaning of life before, why not investigate.

 FREE AND SIMPLE: Syndicate this page's content into your site 
• Insert this page's text directly into your own website. then copy/paste (CTRL+C/CTRL+V) this Javascript code into your own page: help | example. (Please DO NOT copy the actual text of this page onto your own site: reasons.) Other options for re-use.
• Or please link to this page   • Add a Bulletin subscribe form to your site.
   Latest Bulletin:

 Add to My Yahoo! RSS feed


 Bookmark: this page | Web Evangelism Guide Overview    Link to this page?    Free newsletter    Free content/permissions        Poster    Page update alert  

© Dec 2008 Web Evangelism Guide   Contact us   Sitemap   Privacy   About us   Meaning of life

Bible Toolbox


More tools


BSafe filtering graphic

Gospelcom.net graphic
Printed from Web Evangelism Guide © 2008
Can be freely reproduced in print in any non-profit situation with attribution to web-evangelism.com. This page content can also be inserted into your own web-page by copying a simple Javascript insert code into your page - explained in the online version of this page: guide.gospelcom.net/resources/
Please do not copy the text of this page onto your own web-page - search engines do not like hard-copy duplicate content on different sites.
To receive the twice-monthly email newsletter Web Evangelism Bulletin, visit the Guide.