<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simian Enterprises &#187; wordpress</title>
	<atom:link href="https://www.simianenterprises.co.uk/blog/tag/wordpress/feed" rel="self" type="application/rss+xml" />
	<link>https://www.simianenterprises.co.uk/blog</link>
	<description>Web development, Coldfusion, CSS, a bit of this, a bit of that...</description>
	<lastBuildDate>Sat, 26 Apr 2014 00:42:55 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.7</generator>
	<item>
		<title>Integrate WordPress into your ColdFusion app</title>
		<link>https://www.simianenterprises.co.uk/blog/integrate-wordpress-into-your-coldfusion-app-148.html</link>
		<comments>https://www.simianenterprises.co.uk/blog/integrate-wordpress-into-your-coldfusion-app-148.html#comments</comments>
		<pubDate>Thu, 13 Jan 2011 12:57:04 +0000</pubDate>
		<dc:creator><![CDATA[Gary]]></dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Railo]]></category>
		<category><![CDATA[Website Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.simianenterprises.co.uk/blog/?p=148</guid>
		<description><![CDATA[Integrate a Wordpress blog into your CFML app, with functions to pull posts and comments from the Wordpress database, and embed CFM templates directly in your Wordpress theme.<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="https://www.simianenterprises.co.uk/blog/cache-and-display-multiple-twitter-feeds-in-coldfusion-cfc-131.html" rel="bookmark" title="Cache and display multiple Twitter feeds in ColdFusion &#8211; CFC">Cache and display multiple Twitter feeds in ColdFusion &#8211; CFC </a> <small>CFC to easily pull in and cache multiple Twitter feeds....</small></li>
<li><a href="https://www.simianenterprises.co.uk/blog/new-site-live-1.html" rel="bookmark" title="New site live&#8230; Vertical rhythm FTW!">New site live&#8230; Vertical rhythm FTW! </a> <small>After many sleepless nights, the new Simian Enterprises site is...</small></li>
<li><a href="https://www.simianenterprises.co.uk/blog/if-coldfusion-is-dead-its-adobe-that-killed-it-118.html" rel="bookmark" title="If ColdFusion is dead, it&#8217;s Adobe that killed it.">If ColdFusion is dead, it&#8217;s Adobe that killed it. </a> <small>You can't call yourself a CFML developer unless you have...</small></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on a few ColdFusion apps that require a comprehensive blog system. While I could easily install Mango Blog or Blog CFC, nothing really rivals the functionality of WordPress when it comes to blog apps &#8211; but of course, WordPress is a PHP based system.</p>
<p>Installing WordPress alongside a ColdFusion app isn&#8217;t too difficult, but I need to customise the blog so that it looks identical to the rest of the site, and allow the user to switch seamlessly between the two.</p>
<p>This level of integration requires two main bits of functionality. Firstly I need to use ColdFusion to connect to the WordPress database and pull out articles and comments for use in summary blocks around the rest of the site, and secondly I need to be able to embed CFML templates directly into the WordPress blog to generate headers and footers whilst keeping any session based information such as login status, cart contents etc. &#8211; Essentially I need a CFINCLUDE equivalent for PHP.</p>
<p><span id="more-148"></span></p>
<h2>Using ColdFusion to pull in WordPress content</h2>
<p>I created a few components to pull data from a WordPress database. One to grab published articles, one to grab approved comments and one to remove any formatting and strip out extra HTML such as embedded images or videos.</p>
<p>The components are fairly self explanatory, and for the moment provide only basic functionality. It would be possible to build on these to provide greater integration, but for now these do the job nicely.</p>
<h3>Pull published blog posts</h3>
<p>[coldfusion]<br />
<cffunction name="getBlogPosts" access="public" returntype="query" hint="Pulls published blog posts from a wordpress database (Tested in 2.7)"><br />
    <cfargument name="sDSN" type="string" required="yes" hint="Datasource name assigned to the WordPress database" /><br />
	<cfargument name="ID" type="numeric" default="0" hint="Blog post ID - Leave blank to pull all published posts" /><br />
    <cfargument name="iLimit" type="numeric" default="0" hint="Limit the number of posts to pull back" /></p>
<p>	<!--- Get blog posts ---><br />
	<cfquery name="Local.qGetBlogPosts" datasource="#Arguments.sDSN#"><br />
		SELECT		wp_posts.*<br />
		FROM		wp_posts</p>
<p>		WHERE		0 < 1
		
		<cfif Arguments.ID NEQ 0><br />
			AND		wp_posts.ID = <cfqueryparam value="#Arguments.ID#" cfsqltype="CF_SQL_INTEGER" /><br />
		</cfif></p>
<p>        AND			wp_posts.post_type = &#8220;post&#8221;</p>
<p>        AND 		wp_posts.post_status = &#8220;publish&#8221;</p>
<p>        ORDER BY	wp_posts.post_date DESC</p>
<p>        <cfif Arguments.iLimit GT 0><br />
        	LIMIT #Arguments.iLimit#<br />
		</cfif></p>
<p>		;<br />
	</cfquery></p>
<p>	<cfscript><br />
		// Return the query object<br />
		return Local.qGetBlogPosts;<br />
	</cfscript></p>
<p></cffunction></p>
<p>[/coldfusion]</p>
<h3>Pull approved comments</h3>
<p>[coldfusion]</p>
<p><cffunction name="getComments" access="public" returntype="query" hint="Pulls approved comments from a wordpress database (Tested in 2.8)"><br />
    <cfargument name="sDSN" type="string" required="yes" hint="Datasource name assigned to the WordPress database" /><br />
	<cfargument name="iCommentID" type="numeric" default="0" hint="Comment ID - use to pull back a specific comment record" /><br />
	<cfargument name="iPostID" type="numeric" default="0" hint="Post ID - Use to pull back all approved comments from a specific post" /><br />
    <cfargument name="iLimit" type="numeric" default="0" hint="Limit the number of comments pulled back" /></p>
<p>	<!--- Get comments ---><br />
	<cfquery name="Local.qGetBlogComments" datasource="#Arguments.sDSN#"><br />
		SELECT		wp_comments.*,<br />
        			wp_posts.post_name,<br />
                    wp_posts.ID,<br />
                    wp_posts.post_type,<br />
                    wp_posts.post_status,<br />
					wp_posts.post_title</p>
<p>		FROM		wp_comments</p>
<p>		INNER JOIN	wp_posts<br />
        ON			wp_comments.comment_post_ID = wp_posts.ID</p>
<p>		WHERE		0 < 1
		
		<cfif Arguments.iCommentID NEQ 0><br />
			AND		wp_comments.comment_ID = <cfqueryparam value="#Arguments.iCommentID#" cfsqltype="CF_SQL_INTEGER" /><br />
		</cfif></p>
<p>		<cfif Arguments.iPostID NEQ 0><br />
			AND		wp_comments.comment_post_ID = <cfqueryparam value="#Arguments.iPostID#" cfsqltype="CF_SQL_INTEGER" /><br />
		</cfif>      </p>
<p>        AND			wp_comments.comment_approved = 1</p>
<p>        AND			wp_posts.post_type = &#8220;post&#8221;</p>
<p>        AND 		wp_posts.post_status = &#8220;publish&#8221;</p>
<p>        ORDER BY	wp_comments.comment_date DESC</p>
<p>        <cfif Arguments.iLimit GT 0><br />
        	LIMIT #Arguments.iLimit#<br />
		</cfif></p>
<p>		;<br />
	</cfquery></p>
<p>	<cfscript><br />
		// Return the query object<br />
		return Local.qGetBlogComments;<br />
	</cfscript></p>
<p></cffunction></p>
<p>[/coldfusion]</p>
<h3>Strip HTML from posts</h3>
<p>This function uses the &#8216;TagStripper&#8217; custom tag by Rick Root / Ray Camden, available from http://www.cflib.org<br />
[coldfusion]</p>
<p><cffunction name="unformatPost" output="no" hint="Removes HTML from the string" access="public" returntype="string"><br />
	<cfargument name="sString" type="string" required="Yes" hint="Data to strip HTML from - pass the post contents here" /><br />
	<cfargument name="bShowSummary" type="boolean" default="0" hint="If you use the 'more' tag to split posts into summary and content, set this flag to pull back the summary only" />    </p>
<p>	<cfinclude template="/customTags/tagStripper.cfm" /></p>
<p>	<cfscript><br />
		// If we&#8217;re only showing a summary, strip out everything after wordpress&#8217; &#8216;<!--more-->&#8216; tag.<br />
		if (Arguments.bShowSummary) {<br />
			Arguments.sString = REReplace(Arguments.sString, &#8220;<!--more-->.*&#8221;, &#8220;&#8221;);<br />
		}</p>
<p>		// Stip out any HTML tags and return the output<br />
		return tagStripper(Arguments.sString,&#8217;strip&#8217;,&#8217;p,strong,em,a&#8217;);<br />
	</cfscript></p>
<p></cffunction><br />
[/coldfusion]</p>
<h2>Embedding CFM templates into WordPress / PHP</h2>
<p>I don’t know a great deal about PHP, but I can’t find any equivalent to CFINCLUDE – even if I could it would be safe to assume that the PHP version wouldn’t be able to parse the CFML code contained in my CFM pages – what’s needed is some equivalent to CFHTTP that can hit the CFM page as a standard HTTP request, let the CFML server parse the code and return HTML that is then displayed within the PHP template.</p>
<p>Currently I’m using a function in PHP which wraps around ‘fsockopen’ to do exactly this. I found this function a while ago on another project – I’m not sure who wrote it.</p>
<p>[php]<br />
<?php
 function fetchURL( $url ) {
   $url_parsed = parse_url($url);
   $host = $url_parsed["host"];
   $port = $url_parsed["port"];
   if ($port==0)
       $port = 80;
   $path = $url_parsed["path"];
   if ($url_parsed["query"] != "")
       $path .= "?".$url_parsed["query"];

   $out = "GET $path HTTP/1.0\r\nHost: $host\r\n\r\n";

   $fp = fsockopen($host, $port, $errno, $errstr, 30);

   fwrite($fp, $out);
   $body = false;
   while (!feof($fp)) {
       $s = fgets($fp, 1024);
       if ( $body )
           $in .= $s;
       if ( $s == "\r\n" )
           $body = true;
   }
 
   fclose($fp);
 
   return $in;
} 
  
 ?><br />
[/php]</p>
<p>With that function set up at the top of the php template, you can use the following code to embed a parsed CFM template.</p>
<p>[php]<br />
echo fetchURL(http://pathto.your.cfm);<br />
[/php]</p>
<p>Now the only issue remaining is session data. As it’s the PHP server hitting your CFML template and not the user’s browser, the ColdFusion server is assigning a new session to PHP, and so any session specific data such as the contents of the user’s cart or login status, is lost in the displayed page.<br />
So to combat this, we’ll need to check the user’s browser for a session cookie using PHP, and pass that along as a URL parameter to the CFML template.</p>
<p>[php]<br />
<?php
	$sURL = "http://pathto.your.cfm?CFID=" . $_COOKIE['CFID'] . "&#038;CFTOKEN=" . $_COOKIE['CFTOKEN'];
	echo fetchURL($sURL);
?><br />
[/php]</p>
<p>Now we should find that the contents of the CFML page is parsed correctly, using the current CF session.</p>
<p>It’s worth noting that while this technique could be used to pull in your CFML header and footer template, providing a quick way to skin the blog without delving too deeply into the WordPress theme you’re using, this is not the ideal way to go. WordPress themes use variables in the head section of the document to deal with Meta information and other internal functionality, and these often provide hooks for WordPress plugins. If you replace this information with parsed HTML from your CFML templates, you may run into difficulties down the line.<br />
A better method is to abstract individual elements of your site into separate CFML templates, and allow WordPress to create the finished page, pulling in elements where needed.</p>
<p>I’d love to hear what people think of these techniques and if anyone has a better way of integrating WordPress into their ColdFusion apps. Specifically, I’d be interested to know if anyone has combined the login functionality of WordPress with their CFML system – the holy grail, if you will!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="https://www.simianenterprises.co.uk/blog/cache-and-display-multiple-twitter-feeds-in-coldfusion-cfc-131.html" rel="bookmark" title="Cache and display multiple Twitter feeds in ColdFusion &#8211; CFC">Cache and display multiple Twitter feeds in ColdFusion &#8211; CFC </a> <small>CFC to easily pull in and cache multiple Twitter feeds....</small></li>
<li><a href="https://www.simianenterprises.co.uk/blog/new-site-live-1.html" rel="bookmark" title="New site live&#8230; Vertical rhythm FTW!">New site live&#8230; Vertical rhythm FTW! </a> <small>After many sleepless nights, the new Simian Enterprises site is...</small></li>
<li><a href="https://www.simianenterprises.co.uk/blog/if-coldfusion-is-dead-its-adobe-that-killed-it-118.html" rel="bookmark" title="If ColdFusion is dead, it&#8217;s Adobe that killed it.">If ColdFusion is dead, it&#8217;s Adobe that killed it. </a> <small>You can't call yourself a CFML developer unless you have...</small></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.simianenterprises.co.uk/blog/integrate-wordpress-into-your-coldfusion-app-148.html/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>New site live&#8230; Vertical rhythm FTW!</title>
		<link>https://www.simianenterprises.co.uk/blog/new-site-live-1.html</link>
		<comments>https://www.simianenterprises.co.uk/blog/new-site-live-1.html#comments</comments>
		<pubDate>Fri, 13 Mar 2009 02:48:10 +0000</pubDate>
		<dc:creator><![CDATA[Gary]]></dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[website]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://dev.simianenterprises.co.uk/blog/?p=1</guid>
		<description><![CDATA[After many sleepless nights, the new Simian Enterprises site is now live - complete with a lovely new back-end system as well as a *gasp* Wordpress blog!<div class='yarpp-related-rss yarpp-related-none'>

No related posts.
</div>
]]></description>
				<content:encoded><![CDATA[<p>After many sleepless nights, the new Simian Enterprises site is now live &#8211; complete with a lovely new back-end system as well as a *gasp* WordPress blog!</p>
<p>I know as a ColdFusion developer, I should probably be using <a title="Mango Blog" href="http://www.mangoblog.org/">Mango Blog</a> or <a title="Blog CFC" href="http://www.blogcfc.com/">BlogCFC</a> &#8211; Both of which are pretty awesome in their own right &#8211; but at the end of the day WordPress is simply a better tool for the job.<br />
I&#8217;ve heard it said before, but I&#8217;ll chuck my opinion out there too: The new WordPress UI is absolutely fantastic, and I have to say it&#8217;s that more than anything else that made me choose it over the other two.</p>
<p>Of course, integrating WordPress with the rest of my ColdFusion site proved interesting. Several things in the site template are achieved through ColdFusion and had to be replicated in PHP. I ended up writing a CFC to pull data from a WordPress blog, which has proved enormously helpful. If I get the chance, I&#8217;ll clean that up a bit and put it up as a download &#8211; I can&#8217;t be the only one wanting to use WordPress on a ColdFusion powered site.</p>
<p>Props go to Anthony at <a title="Afovea Design Studio" href="http://www.afovea.com">Afovea.com</a> for the lovely new design.<br />
Also, due largely to two fantastic talks by <a title="Jon Tan" href="http://jontangerine.com/">Jon Tan</a> and <a title="Richard Rutter" href="http://clagnut.com/">Richard Rutter</a> at <a title="Skillswap Brighton" href="http://skillswap-brighton.org/">Skillswap Brighton</a>, I have lovingly embraced typography and this site adheres strictly to a vertical rhythm. The math excites me. Really. It&#8217;s actually quite worrying.</p>
<p>That&#8217;s all for now. I&#8217;ve a few articles in the pipeline that I&#8217;ll be posting up here fairly soon. Until then, I&#8217;d love to hear any feedback on the new site.<br />
Use the lovely comments box below.</p>
<p>Awesomage.</p>
<div class='yarpp-related-rss yarpp-related-none'>
<p>No related posts.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>https://www.simianenterprises.co.uk/blog/new-site-live-1.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
