Share page content between sites using RSS

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Share page content between sites using RSS

Post by kermit »

Share any page's {content} block with other site(s) via RSS.

In the absence of multisite capabilities and until that feature is added at some point in 2.0 (see roadmap); I've come up with a Quick-and-Dirty way to share (duplicate) a page's content between different sites using some template modifications and RSS.

Test configuration: Apache 1.3.xx and PHP/cgi 5.1.xx on Linux 2.6.xx running CMSMS 1.3 with mod_rewrite enabled.

Notes:

1. You need to know what IP address your ("destination") server uses for outgoing http requests. We will be modifying the output template(s) on the "origin" site based upon this IP.

2. May require slight modifications to work on configurations other than above.

3. The entire content of the "origin" page's {content} block (as generated and output) is inserted into the resulting RSS feed. As this includes links, you need to ensure you're using FULL domain/path in your links (including images) pointing elsewhere on the "origin" site.

4. What will happen on pages with forms or other complex content is unknown and untested. Has been tested with simple static content (html, text, images) only.

Main use here is a half-dozen sites of same client with shared pages that include things like contact and company info, a list of events (in static html), some simple online shopping pages (that use paypal cart), etc.. This shared content can now be edited via only ONE of the CMSMS installs instead of having to copy/paste it into the other five after every editing session.


Step 1. Modify site template(s) in ORIGIN site's CMSMS:

At the very beginning, before and on the SAME line as DOCTYPE if you have one, add:

Code: Select all

{if $smarty.server.REMOTE_ADDR neq 'xx.xx.xx.xx'}
where xx.xx.xx.xx is the IP address the REQUESTING server's http requests come from.

At the very end, starting after and on the SAME line as your closing tag, add:

Code: Select all

{else}<?xml version="1.0"?>
<rss version="2.0">
    <channel>
    <title>{title} on {sitename}</title>
    <link>{root_url}</link>
    <description>The {title} page from {sitename}</description>
    <language>en-us</language>
    <pubDate>{modified_date format="%A, %d %b %Y %H:%M:%S %z"}</pubDate>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>

    <item>
        <title>{title}</title>
        <link>{root_url}{$smarty.server.REQUEST_URI}</link>
        <description>{content|escape:'html'}</description>
        <pubDate>{modified_date format="%A, %d %b %Y %H:%M:%S %z"}</pubDate>
        <guid isPermaLink="true">{root_url}{$smarty.server.REQUEST_URI}</guid>
    </item>

    </channel>
</rss>
{/if}

Step 2. Import feed to other site using RSS feed importer. For this example and CMSMS, we'll be using RSS2HTML.

Install RSS2HTML and add the following as a new template, RSSimport:

Code: Select all

{foreach from=$rss->items item=item}
{$item.summary}
{/foreach}
For each page on the "origin" site you wish to use on the "destination" site, add a RSS feed to RSS2HTML (on "destination" site) using the standard URL to access that page via a browser.

In a ("destination" site) page's content area, use the following module call to bring in the content from the "origin" site via the RSS feed:

Code: Select all

{cms_module module="RSS2html" feed='feednamehere' template='RSSimport'}
Note that each page to be "shared" will have its own feed in RSS2HTML.


Step 3. As necessary...

1. add CSS to destination site to format imported content to fit design

2. adjust internal links on origin site's pages so images and links work as desired on destination site.


EOF 10JUN08/0430CST draft1

EDIT 11JUN08/0555CST draft2 replace UDTs with Smarty variables; eliminates a step and a couple queries.

(attachment is contents of this post as a text file)
Attachments

[The extension txt has been deactivated and can no longer be displayed.]

Last edited by kermit on Wed Jun 11, 2008 12:00 pm, edited 1 time in total.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
alby

Re: Share page content between sites using RSS

Post by alby »

kermit wrote: Step 1. Add a couple of UDTs to ORIGIN site's CMSMS:

UDT: requesturl

Code: Select all

echo $_SERVER["REQUEST_URI"];
UDT: remotehost

Code: Select all

echo $_SERVER["REMOTE_ADDR"];
Cool, well done kermit.
Only a note:

in smarty you did not need the two UDT, you may use superglobal variables PHP: $smarty.server.XXXX
example: {if $smarty.server.REMOTE_ADDR neq 'xx.xx.xx.xx'}

Alby
cyberman

Re: Share page content between sites using RSS

Post by cyberman »

Great work - thanx.
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Re: Share page content between sites using RSS

Post by kermit »

alby wrote:
in smarty you did not need the two UDT, you may use superglobal variables PHP: $smarty.server.XXXX
example: {if $smarty.server.REMOTE_ADDR neq 'xx.xx.xx.xx'}
thanks for that. by same token, i find that the other one can be replaced with {$smarty.server.REQUEST_URI}. modified original post.

i had looked for a 'definitive list' of server vars available to smarty.. but didn't find one when i was working on this, so i had used php instead (and udt's to keep from having to enable php in content via config.php).
Last edited by kermit on Wed Jun 11, 2008 12:01 pm, edited 1 time in total.
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
Pierre M.

Re: Share page content between sites using RSS

Post by Pierre M. »

Hello,

thank you for the {content|escape:'html'} tip. Smarty is unlimited...

I would have designed the content syndication another way : separate links by type (one for html, one rss), not type by IP. Oups, thought too quickly... better separate by user agent ? nevermind, thx.

Have fun with CMSms :-)

Pierre M.
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Re: Share page content between sites using RSS

Post by kermit »

Pierre M. wrote:
I would have designed the content syndication another way : separate links by type (one for html, one rss), not type by IP. Oups, thought too quickly... better separate by user agent ? nevermind, thx.
i was GOING to go by URL requested instead of IP but i have absolutely no idea if/how you can override a page's template in the URI  -- something like this: domain.com/index.php?page=somepage&template_id=22

so i settled on using IP addresses instead. since the feeds weren't meant to be 'public', no big deal. and by restricting the feeds to only those systems configured by the cmsms admin.. we get extra protection against misuse/abuse of the feeds compared to just using a different URL (which could potentially be discovered even if they aren't posted on the site).
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: Share page content between sites using RSS

Post by calguy1000 »

in cms 1.3 (and probably a bit earlier) you can extract the default content block from any page with a
url like:

http://mysite.com/index.php?page=tests& ... late=false

which you can access with the smarty fetch plugin.

{fetch file='http://mysite.com/index.php?page=tests& ... late=false'}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
kermit
Power Poster
Power Poster
Posts: 693
Joined: Thu Jan 26, 2006 11:46 am

Re: Share page content between sites using RSS

Post by kermit »

calguy1000 wrote: in cms 1.3 (and probably a bit earlier) you can extract the default content block from any page with a
url like:

http://mysite.com/index.php?page=tests& ... late=false

which you can access with the smarty fetch plugin.

{fetch file='http://mysite.com/index.php?page=tests& ... late=false'}
will smarty cache that or fetch it on every pageview?
eternity (n); 1. infinite time, 2. a seemingly long or endless time, 3. the length of time it takes a frozen pizza to cook when you're starving.
4,930,000,000 (n); 1. a very large number, 2. the approximate world population in 1986 when Microsoft Corp issued its IPO. 3. Microsoft's net profit (USD) for the quarter (3 months) ending 31 March 2007.
CMSMS migration and setup services | Hosting with CMSMS installed and ready to go | PM me for Info
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

Re: Share page content between sites using RSS

Post by essexboyracer »

I tried {fetch file='http://www.mywebsite.co.uk/index.php?pa ... late=false'} on a 1.3 and between 1.3 / 1.4.1.1 installs and both occasions it also pulled in the template as well as content, thus creating the full page, within the other sites main template? if that makes sense? Any ideas?
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

Re: Share page content between sites using RSS

Post by essexboyracer »

my bad, it was fcukeditor changing the & in the query string to &
essexboyracer
Forum Members
Forum Members
Posts: 85
Joined: Wed Jun 20, 2007 5:40 pm

Re: Share page content between sites using RSS

Post by essexboyracer »

Actually, maybe not. Have upgraded the 1.4.1.1 to 1.2.5 and it still pulls in the whole page rather than just the content area
Post Reply

Return to “Tips and Tricks”