dolibarr/htdocs/lib/doleditor.class.php

148 lines
5.5 KiB
PHP
Raw Permalink Normal View History

2006-07-22 18:09:48 +02:00
<?php
/* Copyright (C) 2006-2008 Laurent Destailleur <eldy@users.sourceforge.net>
2006-07-22 18:09:48 +02:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* or see http://www.gnu.org/
*/
/**
2008-08-07 08:33:35 +02:00
* \file htdocs/lib/doleditor.class.php
* \brief Class to manage a WYSIWYG editor
2008-08-07 08:33:35 +02:00
* \version $Id$
2006-07-22 18:09:48 +02:00
*/
/**
2009-10-13 23:46:09 +02:00
* \class DolEditor
* \brief Classe de gestion de FCKEditor
* \remarks Usage:
2008-08-07 08:33:35 +02:00
* \remarks $doleditor=new DolEditor('body',$message,320,'toolbar_mailing');
* \remarks $doleditor->Create();
*/
2006-07-22 18:09:48 +02:00
class DolEditor
{
var $tool; // Store the selected tool
// If using fckeditor
2006-07-22 18:09:48 +02:00
var $editor;
2009-01-31 03:55:32 +01:00
// If not using fckeditor
var $content;
var $htmlname;
var $rows;
var $cols;
2009-01-31 03:55:32 +01:00
2006-07-22 18:09:48 +02:00
/**
2010-08-27 01:28:05 +02:00
* DolEditor Create an object to build an HTML area to edit a large string content
* @param htmlname Nom formulaire html WYSIWIG
* @param content Contenu edition WYSIWIG
* @param height Hauteur en pixel de la zone edition
* @param toolbarname Nom barre de menu editeur
* @param toolbarlocation Emplacement de la barre de menu :
2010-06-24 21:00:21 +02:00
* 'In' chaque fenetre d'edition a la propre barre d'outils
* 'Out:nom' partage de la barre d'outils ou 'nom' est le nom du DIV qui affiche la barre
2010-08-27 01:28:05 +02:00
* @param toolbarstartexpanded visible ou non au demarrage
* @param uselocalbrowser Enabled to add links to local object with local browsers. If false, only external images can be added in content.
* @param okforextandededitor True=Allow usage of extended editor tool (like fckeditor)
* @param rows Size of rows for textarea tool
* @param cols Size of cols for textarea tool
2010-06-24 21:00:21 +02:00
*/
function DolEditor($htmlname,$content,$height=200,$toolbarname='Basic',$toolbarlocation='In',$toolbarstartexpanded=false,$uselocalbrowser=true,$okforextandededitor=true,$rows=0,$cols=0)
2006-07-22 18:09:48 +02:00
{
global $conf,$langs;
2009-01-31 03:55:32 +01:00
dol_syslog("DolEditor::DolEditor htmlname=".$htmlname." tool=".$tool);
2009-01-31 03:55:32 +01:00
$this->tool='fckeditor'; // By default
2009-01-31 03:55:32 +01:00
// Check fckeditor is ok
if ($this->tool == 'fckeditor' && (empty($conf->fckeditor->enabled) || ! $okforextandededitor))
{
$this->tool = 'textarea';
}
if ($this->tool == 'fckeditor')
{
require_once(DOL_DOCUMENT_ROOT."/includes/fckeditor/fckeditor.php");
$content=dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
$this->editor = new FCKeditor($htmlname);
$this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ;
$this->editor->Value = $content;
$this->editor->Height = $height;
$this->editor->ToolbarSet = $toolbarname;
$this->editor->Config['AutoDetectLanguage'] = 'true';
$this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
$this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded;
// Rem: Le forcage de ces 2 parametres ne semble pas fonctionner.
// Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart.
// Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ?
$modulepart='fckeditor';
$this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&file=';
$this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/' ;
$this->editor->Config['LinkBrowser']=($uselocalbrowser?'true':'false');
$this->editor->Config['ImageBrowser']=($uselocalbrowser?'true':'false');
if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js'))
{
$this->editor->Config['CustomConfigurationsPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js';
$this->editor->Config['SkinPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/';
}
}
if ($this->tool == 'textarea')
{
$this->content = $content;
$this->htmlname = $htmlname;
$this->rows=max(ROWS_3,$rows);
$this->cols=max(40,$cols);
}
2006-07-22 18:09:48 +02:00
}
/**
2010-08-27 01:28:05 +02:00
* Output edit area inside the HTML stream
2008-08-07 08:33:35 +02:00
*/
2006-07-22 18:09:48 +02:00
function Create()
{
$found=0;
if ($this->tool == 'fckeditor')
{
$found=1;
$this->editor->Create();
}
if ($this->tool == 'textarea')
{
$found=1;
2010-09-01 19:58:34 +02:00
print '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" rows="'.$this->rows.'" cols="'.$this->cols.'" class="flat">';
print $this->content;
print '</textarea>';
}
if (empty($found))
{
print 'Error, unknown value for tool in DolEditor constructor.';
}
2006-07-22 18:09:48 +02:00
}
}
?>