<?php
/*
* Text Module for the CLN Class
*
* Copyright (c) 2003-4 St. Christopher House
*
* Developed by The Working Group Inc.
*
* 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.
*
* @version $Id: Text.php,v 1.50 2004/12/02 18:56:49 darcy Exp $
*
*/
require_once('Cln_Module.php');
if(!defined('TABLE_KB_text')) define('TABLE_KB_text', 'modtext');
class Cln_Module_Text extends Cln_Module
{
/*
*
* Class Attributes: Cln_Text_Module
*
* The attributes for this class are:
*
* TBD
*
*/
var $textId;
var $text;
/***********************************************************************************
*
* Externally accessed methods
*
**********************************************************************************/
/*
*
* Function: Cln_Module_Text()
*
* Class Constructor
*
* @access public
* @return TBD
*
*/
function Cln_Module_Text($textId, $passedData = FALSE)
{
d('TextId: ' . $textId . ': Cln_Module_Text Constructor');
$this->textId = $textId;
if ($passedData && isset($passedData['text'])) {
$this->text = $passedData['text'];
}
else {
$this->text = '';
}
}
/*
*
* Function: getContent()
*
* Returns the text content from the DB
*
* @access public
* @return TBD
*
*/
function getContent()
{
$this->registerStylesheet(CLN_CLEAN_URL_BASE . MOD_CLN_MODULE_TEXT_PATH . 'style/Text.css');
//:HACK: we're processing HTMLArea's output to make it XHTML compliant. this should be removed when they fix the problems with the project
//replace <font> tags with <span style="font-size">
//replace opening font size tags. increase
$sizePairs = array('1'=>'80','2'=>'90','3'=>'100','4'=>'110','5'=>'120','6'=>'140%; line-height: 130','7'=>'167%; line-height: 150');
foreach ($sizePairs as $oldSize => $newSize) {
$this->text = str_replace('<font size="'.$oldSize.'">', '<span style="font-size: '.$newSize.'%;">', $this->text);
}
//replace any font face tags
$this->text = str_replace('<font face="', '<span style="font-family: ', $this->text);
//replace all closing <font> tags
$this->text = str_replace('</font>', '</span>', $this->text);
//replace <p align> with <p style="text-align:>
$this->text = str_replace('<p align="', '<p style="text-align: ', $this->text);
//return text
d('-------------TextId: ' . $this->textId . ': Cln_Module_Text getContent()',3);
return '<div class="textColumn">'.$this->text.'</div>'; //$this->getFormattedText();
}
/*
*
* Function: getEditPanelGeneral()
*
* Returns the general edit panel components
*
* @access public
* @return String $message
*
*/
function getEditPanelGeneral()
{
$generalParts = Array();
return $generalParts;
}
/*
*
* Function: getEditPanelLanguages()
*
* Returns the language specific edit panel components
*
* @access public
* @return String $message
*
*/
function getEditPanelLanguages()
{
$specificParts[0]['title'] = 'Edit Text';
$specificParts[0]['description'] = 'Edit this text.';
return $specificParts;
}
/*
*
* Function: getEditContent()
*
* Returns the edit form for this module
*
* @access public
* @return TBD
*
*/
function getEditContent($override = FALSE)
{
d('TextId: ' . $this->textId . ': Cln_Module_Text getEditContent', 3);
if (isset($_POST['textSource'])) {
if($_POST['textSource'] == 'cancel') {
return FALSE;
}
$this->captureEditFormData();
if ($this->validateEditData()) {
// Only save now for existing objects, not new
if ($this->textId != 'NEW') {
$this->saveModuleData();
}
if (!$override) {
return FALSE;
}
else {
return $this->getInterface();
}
}
else {
return $this->getInterface();
}
}
else if (isset($_POST['textSubmitted']) && $_POST['textSubmitted']) {
if (!$override) {
return FALSE;
}
else {
return $this->getInterface();
}
}
else {
return $this->getInterface();
}
}
/*
*
* Function: getPublishData()
*
* Should return an array of all the data from an object that is needed by another
* object to publish it.
*
*
* @access public
* @return TBD
*
*/
function getPublishData()
{
$returnVal['text'] = $this->text;
return $returnVal;
}
/*
*
* Function: publish()
*
* Should take an array of all the data from an object that is needed by another
* object to publish it.
*
* @access public
* @return TBD
*
*/
function publish($publishData = FALSE)
{
if ($publishData) {
$this->text = $publishData['text'];
}
return $this->saveModuleData();
}
/*
*
* Function: saveModuleData()
*
* Saves the KO
*
* @access public
* @return TBD
*
*/
function saveModuleData()
{
d('TextId: ' . $this->textId . ': Cln_Module_Text saveModuleData');
$db = &Cln_Db::singleton(MAIN_CLN_DSN);
// New module
if ($this->textId == 'NEW') {
$this->textId = $db->nextId(TABLE_KB_text);
$sql = sprintf("INSERT INTO %s SET textId = '%s', text = '%s', created = NOW();",
TABLE_KB_text, $this->textId, addslashes($this->text));
}
// Existing module
else {
$sql = sprintf("UPDATE %s SET text = '%s' WHERE textId = %s",
TABLE_KB_text, addslashes($this->text), $this->textId);
}
$result = $db->query($sql);
if (PEAR::isError($result)) {
PEAR::raiseError('ADMIN_EM_DB_ERROR_INSERT', E_USER_ERROR);
PEAR::raiseError("Error on text ko insert/update: $sql", E_ERROR);
return FALSE;
}
else {
$this->updateModified();
return $this->textId;
}
}
/***********************************************************************************
*
* Internally accessed methods
*
**********************************************************************************/
/*
*
* Function: loadModuleData()
*
* Loads the Database data
*
* @access public
* @return TBD
*
*/
function loadModuleData()
{
d('TextId: ' . $this->textId . ': Cln_Module_Text loadModuleData');
// Load for existing modules
if ($this->textId != 'NEW' && is_numeric($this->textId)) {
$sql = 'SELECT text FROM '.TABLE_KB_text.' WHERE textId = \''. $this->textId . '\'';
$result = &Cln_Db::singleton(MAIN_CLN_DSN, $sql);
$row = $result->fetchRow(DB_FETCHMODE_OBJECT);
$this->text = stripslashes($row->text);
return TRUE;
}
else {
return TRUE;
}
}
/*
*
* Function: getFormattedText()
*
* Returns the formatted text content that is loaded in the object
*
* @access public
* @return TBD
*
*/
function getFormattedText()
{
$content = '<koContainer><p class="ClnText" id="NEW">' . $this->text . "</p></koContainer>\n";
$findText = "\r\n";
$replaceText = "</p>\n<p class=\"ClnText\" id=\"NEW\">";
$content = ereg_replace($findText,$replaceText,$content);
return $content;
}
/*
*
* Function: getInterface()
*
* Returns the edit form for this module
*
* @access public
* @return TBD
*
*/
function getInterface()
{
$this->loadEditLanguage();
ob_start();
include(MOD_CLN_MODULE_TEXT_PATH.'TextEditForm.html');
$form = ob_get_contents();
ob_end_clean();
return $form;
}
/*
*
* Function: captureEditFormData()
*
* Captures the form data for the edit form
*
* @access public
* @return TBD
*
*/
function captureEditFormData()
{
d('TextId: ' . $this->textId . ': Cln_Module_Text captureEditFormData');
d('TextId: ' . $this->textId . ': Cln_Module_Text - captured: ' . $_POST['textSource']);
$this->text = trim($_POST['textSource']);
return TRUE;
}
/*
*
* Function: validateEditData()
*
* Validates the data for validity
*
* @access public
* @return TBD
*
*/
function validateEditData()
{
$this->loadEditLanguage();
if ($this->text == '') {
PEAR::raiseError(ADMIN_EM_NO_TEXT,E_USER_WARNING);
return FALSE;
} else {
return TRUE;
}
}
/***********************************************************************************
*
* Private methods
*
**********************************************************************************/
/*
*
* Function: prepopulateModuleMetadata()
*
* Prepopulates metadata for the object
*
* @access public
* @return String $content
*
*/
function prepopulateModuleMetadata()
{
$titleArray = explode("\n", $this->text);
$title = $titleArray[0];
$metadata['title'] = substr($title, 0, 50);
return $metadata;
}
/*
*
* Function: loadEditLanguage()
*
* Loads the edit language required
*
* @access public
* @return TBD
*
*/
function loadEditLanguage()
{
includeLangFile(MOD_CLN_MODULE_TEXT_PATH.'lang/Text');
}
/*
*
* Function: delete()
*
* Deletes the object
*
* @access public
* @return TBD
*
*/
function delete()
{
$sql = sprintf("DELETE FROM `%s` WHERE textId = '%d'", TABLE_KB_text, $this->textId);
$db = &Cln_Db::singleton(MAIN_CLN_DSN);
$result = $db->query($sql);
if (PEAR::isError($result)) {
PEAR::raiseError("There was an error deleting the Text mod part: $sql", E_ERROR);
return FALSE;
}
else {
return TRUE;
}
}
}
//********************************************************************
?>