| // | Bertrand Mansion | // +----------------------------------------------------------------------+ // // $Id: wai_rendering.php,v 1.0 2006/10/07 20:12:17 avb Exp $ /** * @package chamilo.include */ /** * Code */ include_once ('../inc/global.inc.php'); include_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php'); /** * helper for WCAG rendering. * * @author Patrick Vandermaesen * @version 1.0 * @package chamilo.include */ class WCAG_Rendering { function editor_header() { return '
'.get_lang('WCAGEditor').'
'; } function editor_footer() { return '
'; } function prepareXHTML() { $text = $_POST['text']; $text = WCAG_Rendering::text_to_HTML ( $text ); $imageFile = $_POST['imagefile']; $imageLabel = $_POST['imageLabel']; $link = $_POST['link']; $linkLabel = $_POST['linkLabel']; if (strlen($linkLabel) == 0) { $linkLabel = $link; } $home_top='
'.$imageLabel.''.'

'.$text.'

'; if (strlen($link) > 0) { $home_top = $home_top.''.$linkLabel.''; } $home_top=$home_top."
"; return $home_top; } /** * this method validate the content of current request (from WCAG editor). * this function return the error msg. */ function request_validation() { $imageFile = $_POST['imagefile']; $imageLabel = $_POST['imageLabel']; if ((strlen($imageFile) > 0) and (strlen($imageLabel) == 0)) { return get_lang('ErrorNoLabel'); } return ''; } /** * Converter Plaintext to (x)HTML */ function text_to_HTML ($Text) { $t = $Text; $t = stripslashes($t); $t = str_replace(">", ">", $t); $t = str_replace("<", "<", $t); $t = preg_replace("/(\015\012)|(\015)|(\012)/", "
\n", $t); $t = str_replace(" ", "  ", $t); return $t; } function HTML_to_text ($xhtml) { // convert HTML to text. $text = str_replace("
", "", $xhtml); $text = str_replace("
", "", $text); $text = str_replace(" ", " ", $text); return $text; } function extract_data ($xhtml) { $text = $xhtml; if (stripos($xhtml, '

')) { $startP = stripos ($xhtml, "

"); $endP = stripos ($xhtml, "

"); $text = substr ($xhtml, $startP+3, $endP-$startP-3 ); } // convert HTML to text. $text = WCAG_Rendering::HTML_to_text($text); $url=''; if (stripos($xhtml, '"); $link = substr ($subxhtml, $startLinkURL+5, $endLinkURL-$startLinkURL-5 ); $endLinkLabel = stripos ($subxhtml, ""); $linkLabel = substr ( $subxhtml, $endLinkURL+2, $endLinkLabel-$endLinkURL-2 ); } $values = array("text"=>$text, "imagefile"=>$url, "imageLabel"=>$label, "link"=>$link, "linkLabel"=>$linkLabel); return $values; } /** * add a form for set WCAG content (replace FCK) * @version 1.1 */ function &prepare_admin_form( $xhtml, &$form ) { $values = WCAG_Rendering::extract_data($xhtml); if ($form == null) { $form = new FormValidator('waiForm'); } $form->addElement('textarea','text',get_lang('WCAGContent')); $file =& $form->addElement('text','imagefile',get_lang('WCAGImage')); $form->addElement('text','imageLabel',get_lang('WCAGLabel')); $form->addElement('text','link',get_lang('WCAGLink')); $form->addElement('text','linkLabel',get_lang('WCAGLinkLabel')); $form->setDefaults($values); $renderer =& $form->defaultRenderer(); $element_template = '* {label}
{error}
{element}
'; $renderer->setElementTemplate($element_template); return $form; } function &create_xhtml($xhtml) { $values = WCAG_Rendering::extract_data($xhtml); $xhtml = WCAG_Rendering::editor_header(); $xhtml .= get_lang('WCAGContent').'
'; $xhtml .= ''; $xhtml .= get_lang('WCAGImage').'
'; $xhtml .= ''; $xhtml .= '
'; $xhtml .= ''.get_lang('SelectPicture').''; $xhtml .= '
'; $xhtml .= get_lang('WCAGLabel').'
'; $xhtml .= ''; $xhtml .= get_lang('WCAGLink').'
'; $xhtml .= ''; $xhtml .= get_lang('WCAGLinkLabel').'
'; $xhtml .= ''; $xhtml .= WCAG_Rendering::editor_footer();; return $xhtml; } } // end class WAI_Rendering ?>