Location: PHPKode > scripts > of_htmlarea > of_htmlarea/of_htmlarea.inc
<?php
  /**
   * An add-on for OOHForms family to include cross-browser wysiwyg editor.
   * Currently it works on Mozilla1.3+ (linuz as well) as IE 5.5+
   *
   * Vinay Yadav (vinayRas)
   * hide@address.com
   * http://www.sanisoft.com/ofhtmlarea/
   *
   *  Based on HTMLArea V3.0 alpha from
   *  http://www.interactivetools.com/
   *
   * NOTE: This editor works only with IE 5.5+ and Mozilla 1.3b+
   */

class of_htmlarea extends of_element {

  /**
  * Rows of textarea
  * default: 10
  */
  var $rows;
  /**
  * Not Used!
  */
  var $cols;
  /**
  * Width of the textarea and WYSIWYG editor
  * default: 100%
  */
  var $width;
  /**
  * Toggle wrapping of text in text area
  * default: off
  */
  var $wrap;
  /**
  * Path to images and js files.
  * Default: current script folder
  */
  var $path;

  /**
   * NOTE:
   *
   * On IE:
   *    It is better to let this be false;
   *
   * On Mozilla:
   *    true: You ned to call initEditor() in the onLoad event of body.
   *    false: This meant for faster connects and smaller pages. This may work but
   *             sometimes Mozilla loves to throw unknown internal exception.
   * default: true
   */
  var $initOnLoad = true;

  /**
   *  Constructor
   */
  function of_htmlarea($a) {

    $this->setup_element($a);
    $this->multiple=false;
    $this->path="You must provide the correct URL to wysiwyg directory...";
    $this->rows="10";
    $this->width="100%";
    $this->initOnLoad = true;

    if(isset($a["path"])) $this->path=$a["path"];
    if(isset($a["rows"])) $this->rows=$a["rows"];
    if(isset($a["cols"])) $this->cols=$a["cols"];
    if(isset($a["width"])) $this->width=$a["width"];
    if(isset($a["initOnLoad"])) $this->initOnLoad=$a["initOnLoad"];
  }

  /**
  *
  */
  function self_get($val,$which, &$count) {
    global $HTTP_USER_AGENT;
     $USER_AGENT =  $HTTP_USER_AGENT;
    if(empty($USER_AGENT)) {
       $USER_AGENT = $_SERVER["HTTP_USER_AGENT"];
    }
    $str  = "";
    $this->value=stripslashes($this->value);

    // check for browser
    if(eregi("gecko",$USER_AGENT)) {
        // netscape / Mozilla
        $ag_arr=explode("/",$USER_AGENT);
        if($ag_arr[count($ag_arr)-1] >= 20030210) {
            $is_com = 1;
        }
    } else {                 
        // other Browsers
        $ag_arr=explode(";",$USER_AGENT);
        foreach($ag_arr as $k1=>$v1) {
             $v2=0;
            if(eregi("MSIE",$v1)) {
                  if(eregi("6|5",$v1)) {
                         $is_com=1;
                  }
            }
        }
    }

    if($is_com) {   // check for compatible browser
     $str .="\n<LINK rel='stylesheet' type='text/css' href='$this->path/htmlarea.css'>";
     $str .="\n<script type='text/javascript' src='$this->path/htmlarea.js'></script>";
     $str .="\n<script type='text/javascript' src='$this->path/htmlarea-lang-en.js'></script>";
     $str .="\n<script type='text/javascript' src='$this->path/dialog.js'></script>";

     $str .="
               <SCRIPT LANGUAGE=javascript>
               <!--
                var editor = null;
                function initEditor() {
                    editor = new HTMLArea('$this->name','','$this->path/');
                    editor.generate();
                }
               //--></SCRIPT>";

     $str .="\n <textarea id='$this->name' name='$this->name' style='width: $this->width' rows='$this->rows' wrap='$this->wrap'>$this->value</textarea>";

      if(!$this->initOnLoad) {
        $str .="\n <script language='javascript'>
            setTimeout(function () { initEditor(); }, 500);
            </script>";
      }
    } else {
        $str .= "<textarea name='$this->name'";
        $str .= " rows='$this->rows' cols='$this->cols'";
        if ($this->wrap)
            $str .= " wrap='$this->wrap'";
        if ($this->extrahtml)
            $str .= " $this->extrahtml";
        $str .= ">" . htmlspecialchars($this->value) ."</textarea>";
    }
    $count = 1;
    return $str;
  }

  /**
  *
  */
  function self_get_frozen($val,$which, &$count) {
    $str  = "";
    $str .= "<input type='hidden' name='$this->name'";
    $str .= " value='$this->value'>\n";
    $str .= "<table border=0 width=100%><tr><td>\n";
    $str .=  nl2br($this->value);
    $str .= "\n</td></tr></table>\n";

    $count = 1;
    return $str;
  }

  /**
  *
  */
  function self_get_js($ndx_array) {
    $str = "";

    reset($ndx_array);
    while (list($k,$n) = each($ndx_array)) {
      if ($this->length_e) {
        $str .= "if (f.elements[${n}].value.length < $this->minlength) {\n";
        $str .= "  alert(\"$this->length_e\");\n";
        $str .= "  f.elements[${n}].focus();\n";
        $str .= "  return(false);\n}\n";
      }
    }
    return $str;
  }
} // end of class htmlarea
?>
Return current item: of_htmlarea