<?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>leftcolumn.net &#187; fckeditor</title>
	<atom:link href="http://www.leftcolumn.net/tags/fckeditor/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leftcolumn.net</link>
	<description>Covering Mac OS X, Mac Software, and other stuff</description>
	<lastBuildDate>Tue, 11 May 2010 12:51:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Zend Framework: How to add FCKeditor to a Zend_Form</title>
		<link>http://www.leftcolumn.net/2009/03/10/zend-framework-how-to-add-fckeditor-to-a-zend_form/</link>
		<comments>http://www.leftcolumn.net/2009/03/10/zend-framework-how-to-add-fckeditor-to-a-zend_form/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 00:39:18 +0000</pubDate>
		<dc:creator>Joe</dc:creator>
				<category><![CDATA[zend framework]]></category>
		<category><![CDATA[fckeditor]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[zend_form]]></category>

		<guid isPermaLink="false">http://www.leftcolumn.net/?p=157</guid>
		<description><![CDATA[There are around 1,083,367 JavaScript-based Rich-Text Editors out there, and I&#8217;m sure most are pretty good. But I&#8217;ve had good results with FCKeditor so I use it on all my projects.  Here&#8217;s a step-by-step guide to adding the FCKeditor to your Zend Form Elements. 
1 &#8211; The basics
Download FCKeditor and Upload it to your [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>There are around 1,083,367 JavaScript-based Rich-Text Editors out there, and I&#8217;m sure most are pretty good. But I&#8217;ve had good results with FCKeditor so I use it on all my projects.  Here&#8217;s a step-by-step guide to adding the FCKeditor to your Zend Form Elements. </em></strong></p>
<h3>1 &#8211; The basics</h3>
<p><span style="font-weight: normal;"><a href="http://www.fckeditor.net/">Download FCKeditor</a> and Upload it to your Web Server. It needs to be somewhere accessible to the world, for example: <strong>/js/fckeditor/</strong>, which on your server may be a path like <strong>/var/www/html/your_site/js/fckeditor/</strong>.</span></p>
<p><span style="font-weight: normal;"><br />
</span></p>
<h3>2 &#8211; .htaccess</h3>
<p><span style="font-weight: normal;">The .htaccess that sets up your index.php as the bootstrap needs to <em>exclude the files that FCKeditor uses</em>. If your bootstrap code in .htaccess looks like this:</span></p>
<pre>RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php</pre>
<p>you&#8217;ll need to change it. I typically only rewrite to /index.php if the requested file <em>really</em> doesn&#8217;t exist. So .htaccess should be something like this:</p>
<pre>RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1</pre>
<p><span style="font-weight: normal;"><br />
</span></p>
<h3>3 &#8211; Zend_Form Elements</h3>
<p>In the Form code, you need to make sure that you know the id of the Element (In this case the id is &#8216;body&#8217;), and that you are filtering out all tags and attributes that you don&#8217;t want to explicitly allow. Create an allowed_tags list like the one below and ensure that the FormElement has a StripTags filter applied to it:</p>
<pre>$allowed_tags = array(
	'a' =&gt;	array('href', 'title'),
	'strong',
	'img'	=&gt;	array('src', 'alt'),
	'ul',
	'ol',
	'li',
	'em',
	'u',
	'strike');

$body = new Zend_Form_Element_Textarea('body');
$body-&gt;setLabel('Body')
	-&gt;setAttrib('rows', 12)
	-&gt;setAttrib('cols', 40)
	-&gt;setRequired(true)
	-&gt;addFilter('StringTrim')
	-&gt;addFilter('StripTags', $allowed_tags);</pre>
<p><span style="font-weight: normal;"><br />
</span></p>
<h3>4 &#8211; View Script</h3>
<p>Let&#8217;s Assume that you use Layouts, and that you only want to use the FCKeditor on a couple of pages on your site. You don&#8217;t want to include the FCKeditor code on every page because it just adds to the page size, so we do something like this in the View Script <em>(Note: Wordpress is messing with the quote marks in this block, ensure you have single quotes after <strong>src=</strong> and before the last semicolon. The other quotes should be double quotes.)</em>:</p>
<pre>$this-&gt;custom_head .= '&lt;script src="/js/fckeditor/fckeditor.js" type="text/javascript"&gt;&lt;/script&gt;';
$this-&gt;custom_head = "&lt;script language='javascript' type='text/javascript' src='/js/customs.js'&gt;&lt;/script&gt;";
$this-&gt;custom_body = ' onload="setupFCK()"';</pre>
<p><span style="font-weight: normal;"><br />
</span></p>
<h3>5 &#8211; Layout Script</h3>
<p>The Layout Script needs to know about this new variable, so the Layout Script needs to know to refer to $this-&gt;custom_head if it is set. Drop the code below inside the &lt;head&gt; section of your layout script:</p>
<pre>&lt;?php

if ($this-&gt;custom_head) {
	echo $this-&gt;custom_head;
}
?&gt;</pre>
<p>&#8230;and change the html body element to look like this:</p>
<pre>&lt;body&lt;?php if ($this-&gt;custom_body) {
	echo $this-&gt;custom_body;
}?&gt;&gt;</pre>
<h3>6 &#8211; Loading the FCKEditor when the page loads</h3>
<p>Create /js/custom.js and put this in it:</p>
<pre><span style="font-weight: normal;">function setUpFCK() {
	if(document.getElementById('body')) {
        var oFCKeditor = new FCKeditor('body') ;
        oFCKeditor.BasePath = "/js/fckeditor/" ;
        oFCKeditor.Height = 400;
        oFCKeditor.ReplaceTextarea() ;
    }

}</span></pre>
<h3>7 &#8211; FCKeditor changes</h3>
<p>I like to implement FCKeditor as a single row of buttons for basic editing, just to keep it from looking too big and clunky. I use a set of icons like this:</p>
<pre>FCKConfig.ToolbarSets["Default"] = [
	['Bold','Italic','Underline','StrikeThrough','OrderedList','UnorderedList','Blockquote','Link','Unlink','Image', 'SpecialChar','SpellCheck']
] ;</pre>
<p>And I don&#8217;t want to enable any kind of file uploads, so I make sure these configs are all set to false (edited to show the relevant bits):</p>
<pre>FCKConfig.LinkBrowser = false ;
...
FCKConfig.ImageBrowser = false ;
...
FCKConfig.FlashBrowser = false ;
...
FCKConfig.LinkUpload = false ;
...
FCKConfig.ImageUpload = false ;
...
FCKConfig.FlashUpload = false ;</pre>
<p><span style="font-weight: normal;"><br />
</span></p>
<h3>8 &#8211; Anything else?</h3>
<p>Not really! There are no Controller changes, which is good because this stuff all belongs in Views anyway. The Models know about the allowed tags, which is good because that&#8217;s the kind of work that Models should do. So to me this solution fits the MVC pattern and is not too hack-like. Feedback welcome&#8230;</p>
<h3>Update: 25/3/09</h3>
<p>Fixed various problems with the instructions and it should now all work properly.</p>
<h3>Update: 20/3/09</h3>
<p>I&#8217;ve been doing a bit of reading about Ruby on Rails with the intention of moving to it as my primary development platform. I haven&#8217;t quite got my head around the integration of front-end stuff like FCKeditor yet but Rails really does look like it simplifies the creation and maintenance of forms, which is, after all, about 70% of the work in websites. Need an example? Well Rails has a sensible defaults approach to forms where they can be created automatically based on the model. So compare that to Zend Framework, where I create a separate class for the Form that must match the structure of the model (and be updated when the model changes)! For a big site, that is significant: only one class per table/model!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leftcolumn.net/2009/03/10/zend-framework-how-to-add-fckeditor-to-a-zend_form/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
