Location: PHPKode > scripts > Wysarea > wysarea/wysarea.class.php
<?php
/*******************************************************************************
Wysarea is a free PHP class, with it you can replace any textarea with the Wysiwyg Editor.
Wysarea is a JavaScript based PHP class that encapsulates a wysiwyg html editor.
You may add/edit your messages in visual or html mode and preview it real time!.
It was designed for administrator only. It is not secure since users may input any HTMLtags.
You must take care of security yourself.

Important: You may download full class archive (icons images, language files) http://kaurov.poltav.com/wysarea.zip


Kaurov Eugene
http://kaurov.poltav.com
hide@address.com
*******************************************************************************/
require_once './lng.php';
class wysarea
{
	var	$formname;
	var	$submit;
	var $butvalue;
	
	function wysarea($name)
	{
		$this->formname=$name;
	}

	function show($n_value="", $butvalue="Add", $width=650,$height=200,$submit_is=true)
	{
		global $lang;
		$n_value=str_replace("\r\n","<br>", $n_value);
        $n_value=str_replace("\n",  "<br>", $n_value);
		$n_value=str_replace("\r",  "<br>", $n_value);
        $n_value=str_replace('"', '&quot;', $n_value);
		$n_value=addslashes($n_value);
		$this->butvalue=$butvalue;
		if ($submit_is) $this->submit=$this->get_submit();
		echo"
		<SCRIPT language=Javascript src='./wysiwyg.js'></SCRIPT>
		<table width=650 cellspacing='0' cellpadding='0'>
		<tr>
			<td colspan=2 nowrap>
				<textarea style='overflow: hidden; visibility:hidden;WIDTH: 1px; HEIGHT: 1px' name='".$this->formname."' wrap='VIRTUAL'></textarea><br>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('cut');\" src=\"./editor/cut.gif\" ondragstart=\"return false;\" alt=\"$lang[cut]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('copy');\" src=\"editor/copy.gif\" ondragstart=\"return false;\" alt=\"$lang[copy]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('paste');\" src=\"editor/paste.gif\" ondragstart=\"return false;\" alt=\"$lang[paste]\" width=20 height=20>
				&nbsp;
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('undo');\" src=\"editor/undo.gif\" ondragstart=\"return false;\" alt=\"$lang[undo]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('redo');\" src=\"editor/redo.gif\" ondragstart=\"return false;\" alt=\"$lang[redo]\" width=20 height=20>
				&nbsp;
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('justifyleft')\" src=\"editor/left.gif\" ondragstart=\"return false;\" alt=\"$lang[left]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('justifycenter');\" src=\"editor/center.gif\" ondragstart=\"return false;\" alt=\"$lang[center]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('justifyright');\" src=\"editor/right.gif\" ondragstart=\"return false;\" alt=\"$lang[right]\" width=20 height=20>
				&nbsp;
				&nbsp;
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"CreateNewLink();\" src=\"editor/link.gif\" ondragstart=\"return false;\" alt=\"$lang[hyperlink]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertNewImage();\" src=\"editor/image.gif\" ondragstart=\"return false;\" alt=\"$lang[image]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertTable();\" src=\"editor/table.gif\" ondragstart=\"return false;\" alt=\"$lang[table]\" width=20 height=20>
				&nbsp;
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertForm();\" src=\"editor/form.gif\" ondragstart=\"return false;\" alt=\"$lang[form]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertFormControl('inserttextarea');\" src=\"editor/textarea.gif\" ondragstart=\"return false;\" alt=\"$lang[textarea]\" width=20 height=20>
		 		<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertFormControl('insertinputtext');\" src=\"editor/textbox.gif\" ondragstart=\"return false;\" alt=\"$lang[toolbox]\" width=20 height=20>
		 		<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertFormControl('insertinputbutton');\" src=\"editor/button.gif\" ondragstart=\"return false;\" alt=\"$lang[button]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertFormControl('insertinputradio');\" src=\"editor/option.gif\" ondragstart=\"return false;\" alt=\"$lang[radio]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertFormControl('insertinputcheckbox');\" src=\"editor/checkbox.gif\" ondragstart=\"return false;\" alt=\"$lang[checkbox]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertFormControl('insertselectdropdown');\" src=\"editor/select.gif\" ondragstart=\"return false;\" alt=\"$lang[select]\" width=20 height=20>
				&nbsp;
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('insertunorderedlist');\" src=\"editor/bullist.gif\" ondragstart=\"return false;\" alt=\"$lang[nodelist]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('insertorderedlist');\" src=\"editor/ordlist.gif\" ondragstart=\"return false;\" alt=\"$lang[numlist]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('inserthorizontalrule');\" src=\"editor/rule.gif\" ondragstart=\"return false;\" alt=\"$lang[hr]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"InsertBR();\" src=\"editor/paragraf.gif\" ondragstart=\"return false;\" alt=\"$lang[br]\" width=20 height=20>
			</td>
		</tr>
		<tr>
		<td colspan=2><img src='editor/spacer.gig' border=0 width=1 height=2></td>
		</tr>
		<tr>
			<td nowrap valign=top>
				<SELECT size=\"1\" name=\"ttypes\" style=\"left:3px;\" onchange=\"ChangeTType(this.options[this.options.selectedIndex].value);\">
					<OPTION selected>$lang[st_none]</OPTION>
					<OPTION value=\"PRE\">$lang[st_formatted]</OPTION>
					<OPTION value=\"H1\">$lang[st_h1]</OPTION>
					<OPTION value=\"H2\">$lang[st_h2]</OPTION>
					<OPTION value=\"H3\">$lang[st_h3]</OPTION>
					<OPTION value=\"H4\">$lang[st_h4]</OPTION>
					<OPTION value=\"H5\">$lang[st_h5]</OPTION>
					<OPTION value=\"H6\">$lang[st_h6]</OPTION>
					<OPTION value=\"UL\">$lang[st_numlist]</OPTION>
					<OPTION value=\"OL\">$lang[st_nodelist]</OPTION>
				</SELECT>

				<select size=\"1\" name=\"fonts\" onchange=\"ChangeFont(this.options[this.options.selectedIndex].value);\" >
					<option selected value>Default</option>
					<option value=\"Arial\">Arial</option>
					<option value=\"Comic Sans\">Comic Sans</option>
					<option value=\"Courier New\">Courier New</option>
					<option value=\"MS Sans Serif\">MS Sans Serif</option>
					<option value=\"Times New Roman\">Times New Roman</option>
				</select>

				<select size=\"1\" name=\"fontsize\" onchange=\"ChangeFontSize(this.options[this.options.selectedIndex].value);\" >
					<option selected value=\"3\">Normal</option>
					<option value=\"1\">1 (8pt)</option>
					<option value=\"2\">2 (10pt)</option>
					<option value=\"3\">3 (12pt)</option>
					<option value=\"4\">4 (14pt)</option>
					<option value=\"5\">5 (18pt)</option>
					<option value=\"6\">6 (24pt)</option>
					<option value=\"7\">7 (36pt)</option>
				</select>
			</td>
			<td nowrap valign=bottom align=right>
				<img src='./img/spacer.gif' width=4 height=1>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('bold');\" src=\"editor/bold.gif\" ondragstart=\"return false;\" alt=\"$lang[bold]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('italic');\" src=\"editor/italic.gif\" ondragstart=\"return false;\" alt=\"$lang[italic]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"DesignTools('underline');\" src=\"editor/underline.gif\" ondragstart=\"return false;\" alt=\"$lang[underline]\" width=20 height=20>
				&nbsp;
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"ChangeForeColor();\" src=\"editor/forecol.gif\" ondragstart=\"return false;\" alt=\"$lang[forecolor]\" width=20 height=20>
				<img border=0 style=\"border-width:1px; border-color:#D1D1D1; cursor:hand;\" onmouseover=\"ToolbarOn(true);\" onmouseout=\"ToolbarOn(false);\" onclick=\"ChangeBackColor();\" src=\"editor/bgcol.gif\" ondragstart=\"return false;\" alt=\"$lang[backcolor]\" width=20 height=20>
		 </td>
		</tr>
		<tr>
		<td colspan=2><img src='editor/spacer.gig' border=0 width=1 height=3></td>
		</tr>
		<tr>
		<td colspan=2 nowrap>
			<iframe id=\"maineditor\" src=\"about:blank\" style=\"height:".$height."px; width:".$width."px;\"></iframe>
		</td>
		</tr>
		<tr>
		<td colspan=2><img src='editor/spacer.gig' border=0 width=1 height=2></td>
		</tr>
		<tr>
		<td nowrap>
		<img src='editor/code.gif' onclick=\"EditorView(0);\" style=\"cursor:hand;\">
		<img src='editor/html.gif' onclick=\"EditorView(1);\" style=\"cursor:hand;\">
		<img src='editor/page.gif' onclick=\"EditorView(2);\" style=\"cursor:hand;\">
		<script language=\"JavaScript\">html=\"$n_value\"; var docmode=\"On\"; var enabletoolbar=true; InitEditor();</script>
		</td>
		<td align=right>".$this->submit."</td>
		</tr>
		</table>";
	}	
	
	
	function get_submit_code()
	{
		return "onClick=\"EditorView(3); ".$this->formname.".value=html;\"";
	}
	

	function get_submit($class='forms')
	{
		return "<input type='submit' name='Submit' value='".$this->butvalue."' class='$class' style='cursor:hand;' ".$this->get_submit_code().">";
	}
	

	
}





Return current item: Wysarea