<?PHP
// +----------------------------------------------------------------------+
// | Der Dirigent 1.0                                                     |
// | Last update : 2005-11-24                                             |
// | Part of     : Update to Version 01.00.02                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2003-2004 the dedi-group <dedi-group@der-dirigent.de>  |
// +----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License                 |
// |                                                                      |
// | This program is subject to the GPL license, that is bundled with     |
// | this package in the file LICENSE.TXT.                                |
// | If you did not receive a copy of the GNU General Public License      |
// | along with this program write to the Free Software Foundation, Inc., |
// | 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA               |
// |                                                                      |
// | 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.                         |
// |                                                                      |
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
if (!defined('IS_DEDI')) die();
include_once($dedi_path.'inc/fnc.type_common.php');
include_once($dedi_path.'inc/class.stringparser_bbcode.php');

function type_output_text($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side, $dedi_edittype;
	global $con_side, $dedi_mod;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	// Content aus Array beziehen
	$mod_content = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['1'][$type_typenumber]['1'] : '';
	// HTML+PHP Tags modifizieren
	if($type_config['htmltags'] == 'convert' || empty($type_config['htmltags'])
  	   || ($type_config['htmltags'] != 'strip' && $type_config['htmltags'] != 'allow'))
		$mod_content = htmlspecialchars($mod_content);
	else if ($type_config['htmltags'] == 'strip')
		$mod_content = strip_tags($mod_content);

	// make global edit_all url
	if (_type_check_editall($dedi_side, $type_config))
		$dedi_edittype[$type_container][$type_number][] = '1-'.$type_typenumber;

	// Editiermodus
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'],
			isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {

		$title = (empty($type_config['title'])) ? $mod_lang['type_text'] : $type_config['title'];
		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if ($type_number != '1' || $mod_content != '') {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if ($mod_content != '' && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids[] = 1;
		$infos = array(
                    'container_number' => $type_container,
                    'deditag_id' => $type_typenumber,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$mod = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);


		//Wenn nur editbutton gefordert - Ausgabe BACKEND
		if($type_config['mode'] == 'editbutton') return $mod;
		//Content mit Editbutton erzeugen
		$mod = $mod_content . $mod;

	}
	else $mod = $mod_content;

	//Style
	$css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);
	$css['type'] = trim($css['type']);
	if (!empty($css['type']))
		$mod = '<span '. $css['fullstyle'] .'>'.$mod.'</span>';

	return $mod;
}

function type_output_textarea($type_container, $type_number, $type_typenumber, $type_config) {
	global $sess, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side;
	global $dedi_edittype, $dedi_mod, $con_side, $bbcode_class;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	// Content aus Array holen
	$mod_content = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['3'][$type_typenumber]['1'] : '';

	if($type_config['transform'] != 'bbcode') {
		// HTML Tags maskieren falls htmltags=convert
		if($type_config['htmltags'] == 'convert' || empty($type_config['htmltags']) || ($type_config['htmltags'] != 'strip' && $type_config['htmltags'] != 'allow')) $mod_content = htmlspecialchars($mod_content);

		// alle Tags entfernen
		if($type_config['htmltags'] == 'strip') $mod_content = strip_tags($mod_content);

		// nl2br
		if (($type_config['nl2br'] == 'true' || empty($type_config['nl2br']))) $mod_content = nl2br($mod_content);
	}

	/* BEGIN bbCode-Extension 2 */
	if ($type_config['transform'] == 'bbcode' || count($type_config) == 0) {
		if(!isset($bbcode_class)) {
			$bbcode_class = &new StringParser_BBCode();
			type_init_bbcode_class($bbcode_class, $type_config);
		}
		//echo '<pre style="background-color: #FFFFF5; border: 2px dashed #EEEEA0;">';
		$mod_content = $bbcode_class -> parse($mod_content);
		//echo '</pre>';
	}
	/* END bbCode-Extension 2 */

	// make global edit_all url
	if (_type_check_editall($dedi_side, $type_config))
		$dedi_edittype[$type_container][$type_number][] = '3-'.$type_typenumber;

	// Editiermodus
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'],
			isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {

		$title = (empty($type_config['title'])) ? $mod_lang['type_textarea'] : $type_config['title'];

		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if ($type_number != '1' || $mod_content != '') {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if ($mod_content != '' && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids[] = 3;
		$infos = array(
                    'container_number' => $type_container,
                    'deditag_id' => $type_typenumber,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$mod = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);

		//Wenn nur editbutton gefordert - Ausgabe BACKEND
		if($type_config['mode'] == 'editbutton') return $mod;
		//Content mit Editbutton erzeugen
		$mod = $mod_content . $mod;

	} else $mod = $mod_content;

	// Style
	$css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);
	$css['type'] = trim($css['type']);
	if (!empty($css['type'])) $mod = '<span '.$css['fullstyle'].'>'.$mod.'</span>';

	return $mod;
}


/**
 * Frontendausgabe DEDI:tag WYSIWYG
 *
 * @Args: int type_container -> id von dedi:tag <dedi:lay type="container" id="XX" />
 *        int type_number  -> Entspricht der Verdopplungsid eines Containers
 *        int type_typenumber -> Eindeutige Id des Contents
 *        array $type_config -> Attribute und deren Werte des dedi:tags
 * @Return String Content
 * @Access public
 */
function type_output_wysiwyg($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side, $sid_sniffer;
	global $dedi_edittype, $dedi_mod, $con_side, $lang;

	$unique_type_id = 2;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	return _type_output_wysiwyg_common($type_container, $type_number, $type_typenumber, $type_config, $unique_type_id);
}

/**
 * Frontendausgabe DEDI:tag WYSIWYG2
 *
 * @Args: int type_container -> id von dedi:tag <dedi:lay type="container" id="XX" />
 *        int type_number  -> Entspricht der Verdopplungsid eines Containers
 *        int type_typenumber -> Eindeutige Id des Contents
 *        array $type_config -> Attribute und deren Werte des dedi:tags
 * @Return String Content
 * @Access public
 */
function type_output_wysiwyg2($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side, $sid_sniffer;
	global $dedi_edittype, $dedi_mod, $con_side, $lang;

	$unique_type_id = 13;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	return _type_output_wysiwyg_common($type_container, $type_number, $type_typenumber, $type_config, $unique_type_id);
}

/**
 * Aufbereitung Content fuer Frontendausgabe WYSIWYG1 und WYSIWYG2. Da sich beide Editoren von
 * der Frontendausgabe nicht unterscheiden, koennen Sie zusammengefasst werden
 *
 * @Args: int type_container -> id von dedi:tag <dedi:lay type="container" id="XX" />
 *        int type_number  -> Entspricht der Verdopplungsid eines Containers
 *        int type_typenumber -> Eindeutige Id des Contents
 *        array $type_config -> Attribute und deren Werte des dedi:tags
 * @Return String Content
 * @Access private
 */
function _type_output_wysiwyg_common($type_container, $type_number, $type_typenumber, $type_config, $unique_type_id)
{
	global $sess, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side, $sid_sniffer;
	global $dedi_edittype, $dedi_mod, $con_side, $con_tree, $db, $dedi_db, $client, $lang;

	// Content holen
	$mod_content = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number][$unique_type_id][$type_typenumber]['1'] : '';
	$mod_content = rawurldecode($mod_content);

	// Text formatieren
	$mod_content = str_replace('<o:p>', '<p>', $mod_content);
	$mod_content = str_replace('</o:p>', '</p>', $mod_content);
	$mod_content = str_replace('<?', '<', $mod_content);
	$mod_content = str_replace('<xml>', '', $mod_content);
	$mod_content = str_replace('<xml:>', '', $mod_content);
	if ($type_config['striptags'] == 'true') $mod_content = strip_tags($mod_content);
	if (stristr ($type_config['striptags'], 'styletags')) $mod_content = preg_replace("/([\s\'\"])style=[^>]+/i", ' ', $mod_content);
	if (stristr ($type_config['striptags'], 'styleclasses')) $mod_content = preg_replace("/([\s\'\"])class=[^>]+/i", ' ', $mod_content);
	if (stristr ($type_config['striptags'], 'styleids')) $mod_content = preg_replace("/([\s\'\"])id=[^>]+/i", ' ', $mod_content);
	if (stristr ($type_config['striptags'], 'fontfaces')) $mod_content = preg_replace("/([\s\'\"])face=[^>]+/i", ' ', $mod_content);
	if (stristr ($type_config['striptags'], 'fontsizes')) $mod_content = preg_replace("/([\s\'\"])size=[^>]+/i", ' ', $mod_content);
	if (stristr ($type_config['striptags'], 'events')) $mod_content = preg_replace("/([\s\'\"])on[a-z]+=[^>]+/i", ' ', $mod_content);
	if ($type_config['tidyhtml'] != 'false') {
		$mod_content = preg_replace('/\s+/', ' ', $mod_content);
		$mod_content = preg_replace("!<p [^>]*BodyTextIndent[^>]*>([^\n|\n15|15\n]*)</p>!i",'<p>\\1</p>', $mod_content);
		$mod_content = preg_replace("!<p [^>]*margin-left[^>]*>([^\n|\n15|15\n]*)</p>!i",'<blockquote>\\1</blockquote>', $mod_content);
		$mod_content = preg_replace("!</?(html|body|xml:|[a-z]:)[^>]*>!i", '', $mod_content);
		$mod_content = preg_replace("!(<p></p>)!i", "<p />\n", $mod_content);
		$mod_content = preg_replace("/<![^>]*>/i", '', $mod_content);
		$mod_content = preg_replace('/\s+/', ' ', $mod_content);
		$mod_content = str_replace('<br>',"<br />\r", $mod_content);
		$mod_content = str_replace('> <', ">\r<", $mod_content);
	}

	// make global edit_all url
	if (_type_check_editall($dedi_side, $type_config)) $dedi_edittype[$type_container][$type_number][] = $unique_type_id . '-'.$type_typenumber;

	// Editiermodus
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'], isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {

		  $title = (empty($type_config['title'])) ? $mod_lang['type_wysiwyg'] : $type_config['title'];

		//extract sniffer vars
		if (!$tmp_sniffer) $tmp_sniffer = explode(',', $sid_sniffer);
		//build menu
		//inline editing?
		$inline = ($tmp_sniffer['18'] == 'true') ? true: false;

		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if ($mod_content != '') {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if ($mod_content != '' && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids = array($unique_type_id);
		$infos = array(
                    'container_number' => $type_container,
                    'deditag_id' => $type_typenumber,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$layermenu = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down, $inline);

		//IE inline mode
		if ($tmp_sniffer['18'] == 'true') {

			$in = array("!http://dedilink/fileid=(\d+)!",
				    "!http://dedilink/idcat=(\d+)!",
				    "!http://dedilink/idcatside=(\d+)!");
			$out = array("http://dedilink/temp_fileid=\\1",
				         "http://dedilink/temp_idcat=\\1",
				         "http://dedilink/temp_idcatside=\\1");

			$mod_content = preg_replace($in, $out, $mod_content);

			$mod = "<form name=\"editform_".$type_container.'_'.$type_number.'_'.$unique_type_id.'_'.$type_typenumber."\" method=\"post\" action=\"".$sess->url($cfg_client['contentfile']."?lang=$lang&view=edit&action=savex&idcatside=$idcatside")."\">\n".
		                 "<input type=\"hidden\" name=\"data\" value=\"\">\n";
			$mod .= "<div id=\"content_".$type_container.'_'.$type_number.'_'.$unique_type_id.'_'.$type_typenumber."\" onfocus=\"document.getElementById('content_".$type_container.'_'.$type_number.'_'.$unique_type_id.'_'.$type_typenumber."').className ='actEditFrame';\"".
			"onblur=\"document.getElementById('content_".$type_container.'_'.$type_number.'_'.$unique_type_id.'_'.$type_typenumber."').className ='editFrame';\" contentEditable=\"true\" class=\"editFrame\">$mod_content</div><div align=\"right\">$layermenu</div></form>";
		} else {
			$mod = $mod_content . $layermenu;
		}

	} else {
		$mod = $mod_content;
	}
	// Style
	$css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);
	$css['type'] = trim($css['type']);
	if (!empty($css['type'])) $mod = '<span '.$css['fullstyle'].'>'.$mod.'</span>';

	return $mod;
}



function type_output_image($type_container, $type_number, $type_typenumber, $type_config) {
	global $sess, $DB_dedi, $dedi_db, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side;
	global $client, $dedi_edittype, $dedi_mod, $con_side;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));


	// URL formatieren
	$mod_content = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['4'][$type_typenumber]['1'] : '';
	if ($mod_content != '') {
		$sql = "SELECT A.*, B.filetype, C.dirname FROM ". $dedi_db['upl'] ." AS A LEFT JOIN ". $dedi_db['filetype'] ." B USING(idfiletype) LEFT JOIN ". $dedi_db['directory'] ." C ON A.iddirectory=C.iddirectory WHERE A.idclient='$client' AND idupl='".$mod_content."'";
		$db = &new DB_dedi;
		$db->query($sql);
		if ($db->next_record()){
			$mod_url = $cfg_client['upl_htmlpath'].$db->f('dirname').$db->f('filename');
			$mod_path = $cfg_client['upl_path'].$db->f('dirname').$db->f('filename');
			$original_x = $db->f('pictwidth');
			$original_y = $db->f('pictheight');
			$pic_filetype = $db->f('filetype');
			$pic_dirname = $db->f('dirname');
			$pic_filename = $db->f('filename');
			$pic_idfiletype = $db->f('idfiletype');
			$pic_iddirectory = $db->f('iddirectory');
			$thumb_x = $db->f('pictthumbwidth');
			$thumb_y = $db->f('pictthumbheight');

			if ($type_config['mode'] == 'thumb' && $pic_filetype != 'gif'){
				$original_x = $thumb_x;
				$original_y = $thumb_y;
				$name_length = strlen($pic_filename);
				$extension_length = strlen($pic_filetype);
				$new_name = substr ($pic_filename, 0, ($name_length - $extension_length - 1) );
				$new_name .= $cfg_client['thumbext'].'.'. $pic_filetype;
				$mod_url = $cfg_client['upl_htmlpath'].$db->f('dirname').$new_name;
				$mod_path = $cfg_client['upl_path'].$db->f('dirname').$new_name;
				$pic_filename = $new_name;

			}
		}
	}

	if ($type_config['autoresize'] == 'true' && ! empty($mod_url)) {
		// Extract needed data
		$is_aspectratio = ($type_config['aspectratio'] != 'false') ? true:false;
		$extracted_size = _type_calculate_new_image_size($original_x, $original_y, $type_config['width'], $type_config['height'], $is_aspectratio);
		$new_x = $extracted_size['width'];
		$new_y = $extracted_size['height'];

		// Skip transform if new image have the same properties as the original image,
		if($new_x == $original_x && $new_y == $original_y){
			$skip_transform = true;
		}

		// If _type_calculate_new_image_size(..) throwed an error, new_x and new_y are not set, skip transform
		if(! empty($new_x) && ! empty($new_y) ){
			$name_length = strlen($pic_filename);
			$extension_length = strlen($pic_filetype);

			// New filename for image
			$new_name = substr ($pic_filename, 0, ($name_length - $extension_length - 1) );
			$new_name .= '_'. $new_x .'X'. $new_y .'.'. $pic_filetype;
			if( file_exists($cfg_client['upl_path'] . $pic_dirname . $new_name) ){

				// manipulate current DEDI:tag values with new transform values
				$mod_url = $cfg_client['upl_htmlpath'] . $pic_dirname . $new_name;
				$mod_path = $cfg_client['upl_path'].$pic_dirname . $new_name;
				$type_config['width'] = $original_x = $new_x;
				$type_config['height'] = $original_y = $new_y;
			} else if ($skip_transform || ($cfg_dedi['image_mode'] == 'gd' && $pic_filetype == 'gif') ) {
				$type_config['width'] =  $original_x = $new_x;
				$type_config['height'] = $original_y = $new_y;
			} else {
				// Create image only if file doesn't exist, isn't GD with filetype gif
				// and imagedriver isn't empty
				if (!($cfg_dedi['image_mode'] == 'gd' && $pic_filetype == 'gif' ) && ! empty($cfg_dedi['image_mode'])) {
					// IMAGE TRANSFORM
					global $dedi_image;
					require_once $cfg_dedi['dedi_path'].'external/pear/image/transform.php';
                    $dedi_image = ( is_object($dedi_image) ) ? $dedi_image: Image_Transform::factory( $cfg_dedi['image_mode'] );
                    $dedi_image -> load($mod_path);
					$dedi_image -> resize($new_x, $new_y);
					$dedi_image->save($cfg_client['upl_path'] . $pic_dirname . $new_name);
					$dedi_image->free();
                    global $fm;
					$fm -> insert_file((int)$client, $new_name, (int) $pic_iddirectory, (int) $pic_idfiletype);

					//manipulate current DEDI:tag values with new transform values
					$mod_url = $cfg_client['upl_htmlpath'] . $pic_dirname . $new_name;
					$mod_path = $cfg_client['upl_path'].$pic_dirname . $new_name;
					$type_config['width'] =  $original_x = $new_x;
					$type_config['height'] =  $original_y = $new_y;
				}
			}
		}
	}

	// Wenn amplitude angefordert - Ausgabe FRONTEND + BACKEND
	if ($type_config['mode'] == 'amplitude') return 'width="'. $original_x .'" height="'. $original_y . '"';

	// Wenn Bildhoehe angefordert - Ausgabe FRONTEND + BACKEND
	if ($type_config['mode'] == 'width') return $original_x;

	// Wenn Bildweite angefordert - Ausgabe FRONTEND + BACKEND
	if ($type_config['mode'] == 'height') return $original_y;

	// Wenn nur url gefordert - Ausgabe FRONTEND + BACKEND
	if ($type_config['mode'] == 'url') return $mod_url;

	// Wenn nur pfad gefordert - Ausgabe FRONTEND + BACKEND
	if ($type_config['mode'] == 'path') return $mod_path;

	// Beschreibung raussuchen
	$mod_descr = (is_array($content[$type_container][$type_number])) ? htmlspecialchars($content[$type_container][$type_number]['5'][$type_typenumber]['1']) : '';

	// Wenn nur Beschreibung gefordert - Ausgabe FRONTEND + BACKEND
	if ($type_config['mode'] == 'desc') return $mod_descr;

	// Bildgroesse ermitteln
	// Wenn defaultimage
	if (empty($mod_url)) {
		$pic_width  = (!empty($type_config['defaultwidth'])) ? $type_config['defaultwidth'] : $type_config['width'];
		$pic_height = (!empty($type_config['defaultheight'])) ? $type_config['defaultheight'] : $type_config['height'];

	// wenn schon ausgewaehltes Bild
	} else {
		$pic_width  = (empty($type_config['width']) ) ? '': $type_config['width'];
		$pic_height = (empty($type_config['height']) ) ? '': $type_config['height'];

	// Bildgroesse soll automatisch ermittelt werden
	} if( (empty($type_config['width']) || $type_config['width'] == 'true' || empty($type_config['height']) || $type_config['height'] == 'true') && ! empty($mod_url)) {

		//Bildweite aus der DB
		if($type_config['width'] == 'true' || empty($type_config['width'])) $pic_width = $original_x ;

		//Bildhoehe aus der DB
		if($type_config['height'] == 'true' || empty($type_config['height'])) $pic_height = $original_y ;
	}

	// defaultimage, wenn nicht gesetzt dann transparentes bild einsetzen
	if ($type_config['defaultimage']) $mod_def = $type_config['defaultimage'];
	else $mod_def = $cfg_client['space'];
	if (!$mod_url) $mod_url = $mod_def;

	// make global edit_all url
	if(_type_check_editall($dedi_side, $type_config)) $dedi_edittype[$type_container][$type_number][] = '4-'.$type_typenumber.',5-'.$type_typenumber;

	// CSS ausfindig machen
	$css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);

	// Wenn style angefordert oder default
	if($type_config['mode'] == 'style') return $css['style'];

	// Wenn styletype angefordert oder default
	if($type_config['mode'] == 'styletype')	return $css['type'];

	// Wenn fullstyle angefordert oder default
	if($type_config['mode'] == 'fullstyle') return $css['fullstyle'];

	// Bild generieren
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'], isset($dedi_side['edit_all']))) {

		// Bearbeitungsbutton / layer erzeugen
		if($type_config['menuoptions'] != 'false'){
			$title = (empty($type_config['title'])) ? $mod_lang['type_image'] : $type_config['title'];
			// advanced Modus
			if ($type_config['menuoptions'] == 'advanced') {
				$new=false; $delete=false; $up= false; $down=false;
				// neu anlegen & loeschen
				if ($type_number != '1' || $mod_url != $mod_def) {
		            $new = true;
		            $delete = true;
				}
				// nach oben verschieben
				if ($type_number != '1') $up = true;
				// nach unten verschieben
				if ($mod_url != $mod_def && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
			}

	        $ids = array(4,5);
			$infos = array(
	                    'container_number' => $type_container,
	                    'deditag_id' => $type_typenumber,
	                    'mod_repeat_id' => $type_number,
	                    'title' => $title,
	                    'base_url' => $con_side[$idcatside]['link'],
	                    'mode' => $type_config['menuoptions']
					);

			//menu erstellen
			$editbutton_image = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);
			//Wenn nur editbutton gefordert - Ausgabe BACKEND
			if($type_config['mode'] == 'editbutton') return $editbutton_image;
		}//

        if($type_config['menuoptions'] != 'false'){
			$mod_content = sprintf("<img src=\"$mod_url\"%s%s%s ". $css['fullstyle'] ." border=\"0\">", ($mod_descr != '') ? " alt=\"$mod_descr\" title=\"$mod_descr\"" : " alt=\"\"", ($pic_width) ? " width=\"".($pic_width-29)."\"" : '', ($pic_height) ? " height=\"".($pic_height-8)."\"" : '');
			$mod = '<span style="background-color: #DBE3EF; border: 1px solid black; padding: 3px;">'.$mod_content.'<span style="padding-left: 3px;">'.$editbutton_image.'</span></span>';
			$mod = $editbutton.$mod;
		}
		else{
			if ($type_config['mode'] == 'editbutton') return;
			return sprintf("<img src=\"$mod_url\"%s%s%s ". $css['fullstyle'] ." border=\"0\">", ($mod_descr != '') ? ' alt="'.$mod_descr.'" title="'.$mod_descr.'"' : " alt=\"\"", ($pic_width) ? ' width="'.$pic_width.'"' : '', ($pic_height) ? ' height="'.$pic_height.'"' : '');
		}
	} else {
		// Wenn nur editbutton gefordert - keine Ausgabe Frontend
		if ($type_config['mode'] == 'editbutton') return;

		// Ausgabe image - Frontend
	  $mod = sprintf("<img src=\"$mod_url\"%s%s%s ". $css['fullstyle'] ." />", ($mod_descr != '') ? ' alt="'.$mod_descr.'"' : " alt=\"\"", ($pic_width) ? ' width="'.$pic_width.'"' : '', ($pic_height) ? ' height="'.$pic_height.'"' : '');
	}
	return $mod;
}

// Ausgabeaufbereitung fuer mod:tag link
function type_output_link($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $DB_dedi, $dedi_db, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side;
	global $client, $dedi_edittype, $dedi_mod, $con_side;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	// Linkurl extrahieren
	$link_url = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['6'][$type_typenumber]['1'] : '';
	if (is_numeric($link_url) && $link_url != '0') $link_url = "http://dedilink/idcatside=".$link_url;
	else if (substr($link_url,0,7) != 'http://' && $link_url != '0' && ! empty($link_url)) $link_url = 'http://'.$link_url;

	// Wenn nur URL gefordert, Ausgabe - FRONTEND und BACKEND
	if ($type_config['mode'] == 'url') {
		if($link_url == '0') return;
		else return $link_url;
	}

	// Linktarget extrahieren
	$link_target = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['8'][$type_typenumber]['1'] : '';

	// Wenn nur target gefordert, Ausgabe - FRONTEND und BACKEND
	if ($type_config['mode'] == 'target') return $link_target;

	// Linkbeschreibung extrahieren
	$link_desc = (is_array($content[$type_container][$type_number])) ? htmlspecialchars($content[$type_container][$type_number]['7'][$type_typenumber]['1']) : '';

	// Wenn nur Beschreibung gefordert, Ausgabe - FRONTEND und BACKEND
	if ($type_config['mode'] == 'desc') return $link_desc;

	// make global edit_all url
	if (_type_check_editall($dedi_side, $type_config)) $dedi_edittype[$type_container][$type_number][] = '6-'.$type_typenumber.',7-'.$type_typenumber.',8-'.$type_typenumber;

	//Editbutton erzeugen fuer BACKEND
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'],
			isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {

		$title = (empty($type_config['title'])) ? $mod_lang['type_link'] : $type_config['title'];

		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if (type_number != '1' || !empty($link_url)) {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if (!empty($link_url) && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids = array(6,7,8);
		$infos = array(
                    'container_number' => $type_container,
                    'deditag_id' => $type_typenumber,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$layer_menu = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);

		// Wenn Editbutton angefordert wurde, ausgeben - BACKEND
		if($type_config['mode'] == 'editbutton') return $layer_menu;
	}

	// Vollstaendigen Link bauen
	// CSS ausfindig machen
	$css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);

	// Wenn style angefordert oder default
	if ($type_config['mode'] == 'style') return $css['style'];

	// Wenn styletype angefordert oder default
	if ($type_config['mode'] == 'styletype') return $css['type'];

	// Wenn fullstyle angefordert oder default
	if ($type_config['mode'] == 'fullstyle') return $css['fullstyle'];

	$target = (empty($link_target)) ? '':'target="'. $link_target .'"';
	$desc = (empty($link_desc)) ? $link_url : $link_desc;
  $link_textlink = '<a href="'.$link_url.'" '. $css['fullstyle'] .'  '. $target .' >'. $desc .'</a>';

	// Wenn textlink angefordert oder default FRONTEND und BACKEND
	if (($type_config['mode'] == 'textlink' || empty($type_config['mode'])) ) {
		if (!empty($link_url) && $link_url != '0') return $link_textlink . $layer_menu;
		else return $layer_menu;
	}
}

// Ausgabeaufbereitung fuer mod:tag file
function type_output_file($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $DB_dedi, $dedi_db, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side;
	global $client, $dedi_edittype, $dedi_mod, $con_side;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	// Fileid extrahieren
	$file_id = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['10'][$type_typenumber]['1'] : '';

	// Wenn idupl gefordert, Ausgabe - FRONTEND, BACKEND
	if($type_config['mode'] == 'id') return $file_id;

	// Filebeschreibung extrahieren
	$file_desc = (is_array($content[$type_container][$type_number])) ? htmlspecialchars($content[$type_container][$type_number]['11'][$type_typenumber]['1']) : '';

	// Wenn nur Beschreibung gefordert, Ausgabe - FRONTEND und BACKEND
	if($type_config['mode'] == 'desc') return $file_desc;

	// Filetarget extrahieren
	$file_target = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['12'][$type_typenumber]['1'] : '';

	// Wenn nur target gefordert, Ausgabe - FRONTEND und BACKEND
	if($type_config['mode'] == 'target') return $file_target;

	//Benoetigte Dateiinformationen aus der Datenbank holen
	$db = &new DB_dedi;
	$sql = "SELECT
				A.*, B.filetype, C.dirname
			FROM
				".$dedi_db['upl']." AS A
				left join ". $dedi_db['filetype'] ." B USING(idfiletype)
				LEFT JOIN ". $dedi_db['directory'] ." C ON A.iddirectory=C.iddirectory
			WHERE
				A.idclient='$client'
				AND idupl='".$file_id."'";
	$db->query($sql);
	if ($db->next_record()) {
		$file_url = $cfg_client['upl_htmlpath'].$db->f('dirname').$db->f('filename');
		$file_path = $cfg_client['upl_path'].$db->f('dirname').$db->f('filename');
	}

	// Wenn nur path gefordert, Ausgabe - FRONTEND und BACKEND
	if ($type_config['mode'] == 'path') return $file_path;

	// Wenn nur url gefordert, Ausgabe - FRONTEND und BACKEND
	if ($type_config['mode'] == 'url') return $file_url;

	// make global edit_all url
	if (_type_check_editall($dedi_side, $type_config) )
		$dedi_edittype[$type_container][$type_number][] = '10-'.$type_typenumber.',11-'.$type_typenumber.',12-'.$type_typenumber;

	// Editbutton erzeugen fuer BACKEND
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'],
			isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {

		$title = (empty($type_config['title'])) ? $mod_lang['type_file'] : $type_config['title'];

		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if (type_number != '1' || !empty($file_url)) {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if (!empty($file_url) && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids = array(10,11,12);
		$infos = array(
                    'container_number' => $type_container,
                    'deditag_id' => $type_typenumber,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$layer_menu = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);

		// Wenn Editbutton angefordert wurde, ausgeben - BACKEND
		if($type_config['mode'] == 'editbutton') return $layer_menu;
	}

	// Vollstaendigen Dateilink bauen
	// CSS ausfindig machen
	$css = _type_get_style($type_config['styleclass'], $type_config['styleid'], $type_config['styledb']);

	// Wenn style angefordert oder default
	if($type_config['mode'] == 'style') return $css['style'];

	// Wenn styletype angefordert oder default
	if($type_config['mode'] == 'styletype')	return $css['type'];

	// Wenn fullstyle angefordert oder default
	if($type_config['mode'] == 'fullstyle') return $css['fullstyle'];
	$target = ( empty($file_target) ) ? '':'target="'. $file_target .'"';
	$desc = ( empty($file_desc) ) ? $file_url : $file_desc;
  $file_textlink = '<a href="'. $file_url .'" '. $css['fullstyle'] .'  '. $target .' >'. $desc .'</a>';

	// Wenn textlink angefordert oder default
	if($type_config['mode'] == 'textlink' || empty($type_config['mode'])) {
		if(! empty($file_url)) return $file_textlink . $layer_menu;
		else return $layer_menu;
	}
}

function type_output_sourcecode($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side, $dedi_edittype;
	global $dedi_mod, $con_side;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	//content auslesen
	$mod_content = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['9'][$type_typenumber]['1'] : '';

	//nl2br
	if ($type_config['nl2br'] == 'true') {
		$mod_content = nl2br($mod_content);
	}

	// make global edit_all url
	if(_type_check_editall($dedi_side, $type_config)) $dedi_edittype[$type_container][$type_number][] = '9-'.$type_typenumber;

	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'], isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {
		$title = (empty($type_config['title'])) ? $mod_lang['type_sourcecode'] : $type_config['title'];

		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if ($type_number != '1' || $mod_content != '') {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if ($mod_content != '' && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids = array(9);
		$infos = array(
                    'container_number' => $type_container,
                    'deditag_id' => $type_typenumber,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$layer_menu = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);

		$mod = $mod_content.$layer_menu;
	} else $mod = $mod_content;
	return $mod;
}


// Ausgabeaufbereitung fuer mod:tag file
function type_output_typegroup($type_container, $type_number, $type_typenumber, $type_config)
{
	global $sess, $DB_dedi, $dedi_db, $cfg_dedi, $cfg_client, $idcatside, $mod_lang, $content, $dedi_side;
	global $client, $dedi_edittype, $dedi_mod, $con_side;

	// Wenn keine Elemente uebergeben wurden abbrechen
	if (empty($type_config['elements'])) return 'Kein Element in typegroup';

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	// Puefen ob bearbeitet werden darf
	if (!_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'], isset($dedi_side['edit_all']))) return false;

	// Elementstring aufbereiten
	$elements = $type_config['elements'];
	preg_match_all("/(\w*)\[([^\]]*)\]/", $elements , $matches);
	$menustring = '_';
	$link_edit = '';
	$link_new = '';
	$is_empty = true;
	$mc = count($matches['1']);
	for($dedi_inc=0; $dedi_inc<$mc; $dedi_inc++) {
		$e_name = $matches['1'][$dedi_inc];
		$e_id = $matches['2'][$dedi_inc];
		if(! is_numeric($e_id) ){
			$to_eval = "global $e_id;\n". '$extracted_var'."= $e_id;";
			eval($to_eval);
			$e_id = $extracted_var;
		}
		switch($e_name)	{
			case 'text':
				$link_edit[]  = '1-'.$e_id;
				$mod_content['1'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['1'][$e_id]['1'] : '';
				if(!empty($mod_content['1'])) $is_empty = false;
				break;
			case 'wysiwyg':
				$link_edit[]  = '2-'.$e_id;
				$mod_content['2'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['2'][$e_id]['1'] : '';
				if(!empty($mod_content['2'])) $is_empty = false;
				break;
			case 'textarea':
				$link_edit[]  = '3-'.$e_id;
				$mod_content['3'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['3'][$e_id]['1'] : '';
				if(!empty($mod_content['3'])) $is_empty = false;
				break;
			case 'image':
				$link_edit[]  = '4-'.$e_id.',5-'.$e_id;
				$mod_content['4'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['4'][$e_id]['1'] : '';
				if(!empty($mod_content['4'])) $is_empty = false;
				break;
			case 'link':
				$link_edit[]  = '6-'.$e_id.',7-'.$e_id.',8-'.$e_id;
				$mod_content['6'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['6'][$e_id]['1'] : '';
				if(!empty($mod_content['6'])) $is_empty = false;
				break;
			case 'sourcecode':
				$link_edit[]  = '9-'.$e_id;
				$mod_content['9'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['9'][$e_id]['1'] : '';
				if(!empty($mod_content['9'])) $is_empty = false;
				break;
			case 'file':
				$link_edit[]  = '10-'.$e_id.',11-'.$e_id.',12-'.$e_id;
				$mod_content['10'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['10'][$e_id]['1'] : '';
				if(!empty($mod_content['10'])) $is_empty = false;
				break;
			case 'wysiwyg2':
				$link_edit[]  = '13-'.$e_id;
				$mod_content['13'] = (is_array($content[$type_container][$type_number])) ? $content[$type_container][$type_number]['13'][$e_id]['1'] : '';
				if(!empty($mod_content['13'])) $is_empty = false;
				break;
		}
	}

	$full_edit_link = implode(',', $link_edit);
	//$linkset_unique_identifier = str_replace(',', '-', $full_edit_link);

	// Editbutton erzeugen
	if (_type_check_editable($dedi_side['edit'], $type_config['editable'], $dedi_side['view'],
		isset($dedi_side['edit_all'])) && $type_config['menuoptions'] != 'false') {

		$title = ( empty($type_config['title']) ) ? $mod_lang['type_typegroup'] : $type_config['title'];
		// advanced Modus
		if ($type_config['menuoptions'] == 'advanced') {
			$new=false; $delete=false; $up= false; $down=false;
			// neu anlegen & loeschen
			if ($is_empty != true) {
	            $new = true;
	            $delete = true;
			}
			// nach oben verschieben
			if ($type_number != '1') $up = true;
			// nach unten verschieben
			if ($dedi_mod['modul']['lastentry'] != 'true') $down = true;
		}

        $ids = array(NULL);
		$infos = array(
                    'container_number' => $type_container,
                    'pre_compiled' => $full_edit_link,
                    'mod_repeat_id' => $type_number,
                    'title' => $title,
                    'base_url' => $con_side[$idcatside]['link'],
                    'mode' => $type_config['menuoptions']
				);
		//menu erstellen
		$layer_menu = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);

		return $editbutton_image.$layer_menu;
	}
}

// edit whole side button - only for pros
function type_output_edit_container($type_container, $type_number, $type_typenumber, $type_config) {
	global $dedi_side, $DB_dedi, $dedi_db, $dedi_edittype, $sess, $cfg_client, $mod_lang, $idcatside;
	global $cfg_dedi, $idcatside, $con_side, $dedi_mod;

	if (($dedi_side['edit_all'] || ($type_config['editable'] == 'true' && $dedi_side['view'] == 'edit'))
		&& $type_config['editable'] != 'false' && is_array($dedi_edittype[$type_container])) {

		//catch vars and arrays from the tag attributes
		eval(_type_get_dynamic_val_string($type_config));

  		$edit_content = $type_container.'.'.$type_number.'.';
		foreach ($dedi_edittype[$type_container][$type_number] as $value)
		{
			$edit_content .= $value.',';
		}
		$edit_content = substr ($edit_content,  0, strlen ($edit_content)-1);
		//echo $edit_content .'<br>';

		// nur Edit-URL
		if ($type_config['mode'] == 'editurl') return $con_side[$idcatside]['link']."&action=edit&content=$edit_content";
		if ($type_config['menuoptions'] != 'false') {

			$title = (empty($type_config['title'])) ? $mod_lang['type_container'] : $type_config['title'];

			// advanced Modus
			if ($type_config['menuoptions'] == 'advanced') {
				$new=false; $delete=false; $up= false; $down=false;

				// gibt es schon einen Eintrag?
				$sql = "SELECT
							*
						FROM
							$dedi_db[content]
						WHERE
							idsidelang='".$con_side[$idcatside]['idsidelang']."'
							AND container='$type_container'
							AND number='$type_number'";
				$db = &new DB_dedi;
				$db->query($sql);

				// neu anlegen & loeschen
				if ($type_number != '1' || $db->affected_rows()) {
		            $new = true;
		            $delete = true;
				}
				// nach oben verschieben
				if ($type_number != '1') $up = true;
				// nach unten verschieben
				if ($db->affected_rows() && $dedi_mod['modul']['lastentry'] != 'true') $down = true;
			}

	        $ids = array(NULL);
			$infos = array(
	                    'container_number' => $type_container,
	                    'pre_compiled' => $edit_content,
	                    'tag_type' => 'edit_container',
	                    'mod_repeat_id' => $type_number,
	                    'title' => $title,
	                    'base_url' => $con_side[$idcatside]['link'],
	                    'mode' => $type_config['menuoptions']
					);
			//menu erstellen
			$layer_menu = _type_get_layer_menu($ids, $infos, $delete, $new, $up, $down);
		}

		return $layer_menu;
	}
}

function type_output_cache($type_container, $type_number, $type_typenumber, $type_config)
{
	global $idcatside;

	// gucken ob eingabe ok ist
	if (is_integer($type_config['expires'])) return;
	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

	$expires =  time() + $type_config['expires'];
	return '<DEDIPHP>check_cache_is_expired('.$expires.')</DEDIPHP>';
}

function type_output_dependency($type_container, $type_number, $type_typenumber, $type_config)
{
	global $con_side, $db, $dedi_db, $idcatside, $dedi, $sess, $lang;

	//nur im backend ausfuehren
	if (empty($dedi)) return;
	// gucken ob eingabe ok ist
	if (empty($type_config['idcatside'])) return;

	//catch vars and arrays from the tag attributes
	eval(_type_get_dynamic_val_string($type_config));

    $type_config['idcatside'] = str_replace(' ', '', $type_config['idcatside']);
    $temp_sess = $idcatside .'__'. str_replace(',', '_', $type_config['idcatside']);
	global ${'dependency'.$temp_sess};

	if( empty(${'dependency'.$temp_sess}) ){
		$sess->register('dependency'.$temp_sess);
		${'dependency'.$temp_sess} = $con_side[$idcatside]['lastmodified'];
	}
	else{
		// letztes aenderungsdatum aus datenbank auslesen, da nach einer gerade
		// gemachten aenderung die daten noch nicht im array $con_side sind
		$sql = "SELECT
					SL.lastmodified
				FROM
					".$dedi_db['side_lang'] ." SL, ". $dedi_db['cat_side'] ." CS
				WHERE
					SL.idside= CS.idside
					AND CS.idcatside=$idcatside
					AND idlang=$lang";
		$db->query($sql);
		$db->next_record();

		if(${'dependency'.$temp_sess} < $db->f('lastmodified') ){
			${'dependency'.$temp_sess} = $db->f('lastmodified');
			change_code_status($type_config['idcatside'], 1, 'idcatside');
		}
	}
}

function type_init_bbcode_class(&$class, $type_config) {
	// Analyze typ_config
	$featurestext = $type_config['features'];
	$features = array();
	if (!empty($featurestext) && $featurestext != 'true') {
		$features = explode(',', $type_config['features']);
		$features = array_map('trim', $features);
	}

	$fonts = array();

	if (!empty($type_config['fonts'])) {
		$fontsstring = str_replace('  ', ' ', $type_config['fonts']);
		$fonts = explode(',', $fontsstring);
		$fonts = array_map('trim', $fonts);
	}

	$classes = array(); $classespre = array();
	if (!empty($type_config['classes'])) {
		$classesstring = str_replace('  ', ' ', $type_config['classes']);
		$classespre = explode(',', $classesstring);
		foreach($classespre as $v) {
			list($n, $v) = explode('=', $v, 2);
			$n = trim($n); $v = trim($v);
			$classes[$n]= $v;
		}
	}

	if (!empty($type_config['classids'])) {
		$style_array = _type_get_stylelist($type_config['classids']);
		$c = count($style_array);
		if ($c > 0) {
			for($i=0; $i<$c; $i++) {
				$classes[$style_array[$i]['name']] = $style_array[$i]['autodesc'];
			}
		}
	}

	$sizemin 		= (int)$type_config['sizemin'];
	$sizemin 		= (empty($sizemin)) ? 75 : $sizemin;
	$sizemax 		= (int)$type_config['sizemax'];
	$sizemax 		= (empty($sizemax)) ? 125 : $sizemax;

	$nl2br 			= ($type_config['paragraphs'] == 'br' || empty($type_config['paragraphs']));
	$paragraphs 	= ($type_config['paragraphs'] == 'p');

	$notarget		= $type_config['notarget'] == 'true';

	$container 		= $type_config['classescontainer'] == 'block' ? 'block' : 'inline';
	$classelement 	= $type_config['classescontainer'] == 'block' ? 'div' : 'span';

	$linkexternal 	= $type_config['linkexternal'] != 'false';
	$imgexternal 	= $type_config['imgexternal'] != 'false';

	$linktpl 		= ((isset($type_config['linktpl']) && !empty($type_config['linktpl'])) 					? $type_config['linktpl'] 		: '[link="{url}"]{text}[/link]');
	$filelinktpl 	= ((isset($type_config['filelinktpl']) && !empty($type_config['filelinktpl'])) 			? $type_config['filelinktpl'] 		: $linktpl);
	$extlinktpl 	= ((isset($type_config['extlinktpl']) && !empty($type_config['extlinktpl'])) 			? $type_config['extlinktpl'] 		: $linktpl);
	$maillinktpl 	= ((isset($type_config['maillinktpl']) && !empty($type_config['maillinktpl'])) 			? $type_config['maillinktpl'] 		: $linktpl);
	$footnotelinktpl= ((isset($type_config['footnotelinktpl']) && !empty($type_config['footnotelinktpl'])) 	? $type_config['footnotelinktpl'] 	: '[{id}]');

	$singleenter 	= $type_config['singleenter'] == 'true';
	$imgalwaysalt	= $type_config['imgalwaysalt'] != 'false';
	$htmlmode 		= $type_config['htmlmode'] == 'HTML4' ? 'HTML' : 'XHTML';
	$allowanchor 	= (in_array('anchor', $features) && in_array('link', $features)) || empty($type_config['features']) || $type_config['features'] == 'true';

	$namedEntities	= $type_config['namedentities'] != 'false';
	if($namedEntities) initNamedEntities();

	// Define Basic Tags (for Parsing Filelink-Template)
	if(in_array('bold', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('b', 	'simple_replace', 	 null, 				 array(
		'start_tag' 	=> '<strong>',
		'end_tag' 		=> '</strong>'
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('italic', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('i', 	'simple_replace', 	 null, 				 array(
		'start_tag' 	=> '<em>',
		'end_tag' 		=> '</em>'
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('underline', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('u', 	'simple_replace', 	 null, 				 array(
		'start_tag' 	=> '<ins>',
		'end_tag' 		=> '</ins>'
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('strike', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('s', 	'simple_replace', 	 null, 				 array(
		'start_tag' 	=> '<del>',
		'end_tag' 		=> '</del>'
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('sub', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('sub', 	'simple_replace', 	 null, 			 array(
		'start_tag' 	=> '<sub>',
		'end_tag' 		=> '</sub>'
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('sup', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('sup', 	'simple_replace', 	 null, 			 array(
		'start_tag' 	=> '<sup>',
		'end_tag' 		=> '</sup>'
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('size', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('size', 	'callback_replace', 	 'type_bbcode_callback', array(
		'sizemin' 		=> $sizemin,
		'sizemax' 		=> $sizemax,
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if((in_array('font', $features) && count($fonts)) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('font', 	'callback_replace', 	 'type_bbcode_callback', array(
		'fonts' 		=> $fonts
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if((in_array('class', $features) && count($classes)) || empty($featurestext) || $featurestext == "true") {
	$class -> addCode('class', 	'callback_replace', 	 'type_bbcode_callback', array(
		'classes' 		=> &$classes,
		'element' 		=> $classelement
	), 	$container, 	array ('block', 'inline', 'link', 'listitem'), 	array()); }

	if(in_array('forecol', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('forecol', 	'callback_replace', 	 'type_bbcode_callback', array(
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('backcol', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('backcol', 	'callback_replace', 	 'type_bbcode_callback', array(
	), 	'inline', 	array ('block', 'inline', 'link', 'listitem'), 	array());

	if(in_array('img', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('img', 	'usecontent',	'type_bbcode_callback', array(
		'allowexternal'	=> $imgexternal,
		'imgalwaysalt'	=> $imgalwaysalt,
		'htmlmode'		=> $htmlmode,
		'classes' 		=> &$classes
	), 	'image', 	array ('block', 'inline', 'listitem', 'link'), 	array());

	if(in_array('abbr', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('abbr', 	'callback_replace',	'type_bbcode_callback', array(
		'htmlmode'		=> $htmlmode
	), 	'inline', 	array ('block', 'inline', 'listitem', 'link'), 	array());

	if(in_array('acronym', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('acronym', 	'callback_replace',	'type_bbcode_callback', array(
		'htmlmode'		=> $htmlmode

	), 	'inline', 	array ('block', 'inline', 'listitem', 'link'), 	array());

	$footnotelinktpl = $class -> parse($footnotelinktpl);

	if(in_array('link', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('link', 	'usecontent?',	'type_bbcode_callback', array(
		'usecontent_param'	=> array('dest', 'default'),
		'notarget'			=> $notarget,
		'allowexternal'		=> $linkexternal,
		'allowanchor'		=> $allowanchor,
		'classes' 			=> &$classes
	), 	'link', 	array ('block', 'inline', 'listitem'), 		array());

	$class -> setCodeFlag('link', 'dedi.parsetpl', true);

	// Parse Templates with these Basic-Tags
	$filelinktpl = $class -> parse($filelinktpl);
	$linktpl = $class -> parse($linktpl);
	$extlinktpl = $class -> parse($extlinktpl);
	$maillinktpl = $class -> parse($maillinktpl);

	$class -> setCodeFlag('link', 'dedi.parsetpl', false);

	// Define Enhanced Tags
	$class -> addCode('hr', 	'callback_replace_single',		'type_bbcode_callback', array(
		'classes' 		=> &$classes,
		'htmlmode'		=> $htmlmode
	), 	'block', 	array ('block'), 	array());

	if((in_array('br', $features) || empty($featurestext) || $featurestext == "true") && $paragraphs) {
		$class -> addCode('br',	 'simple_replace_single', 	 null, 			 array(
			'start_tag' 	=> '<br' . (($htmlmode == 'XHTML') ? ' /' : '') . '>'
		), 	'block', 	array ('block'), 			array());
	}

	if(in_array('email', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('email', 		'usecontent?', 	 'type_bbcode_callback', array(
		'classes' 	=> &$classes,
		'usecontent_param' => array('adress', 'default')
	), 	'inline', 	array ('block', 'inline', 'listitem'), 		array());

	if($allowanchor)
	$class -> addCode('anchor', 	'usecontent?',	'type_bbcode_callback', array(
		'usecontent_param'	=> array('id', 'default'),
		'htmlmode'		=> $htmlmode
	), 	'link', 	array ('block', 'inline'), 	array());

	if(in_array('filelink', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('filelink', 	'usecontent?',	'type_bbcode_callback', array(
		'classes' 	=> &$classes,
		'usecontent_param'	=> array('id', 'default'),
		'tpl'			=> $filelinktpl,
	), 	'link', 	array ('block', 'inline', 'listitem'), 		array());

	if(in_array('list', $features) || empty($featurestext) || $featurestext == "true") {
		$class -> addCode('list', 	'callback_replace', 	 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'list', 	array ('block'), 		array());

		$class -> addCode('*',	 	'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'listitem', 	array ('list'), 	array());
	}

	if(in_array('footnote', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('footnote', 	'callback_replace', 	 'type_bbcode_callback', array(
		'htmlmode'		=> $htmlmode
	), 	'block', 	array ('block'), 			array());

	if(in_array('code', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('code',	 'usecontent', 		 'type_bbcode_callback', array(
	), 	'code', 	array ('block'), 			array());

	if(in_array('source', $features) || empty($featurestext) || $featurestext == "true")
	$class -> addCode('source',	 'usecontent', 		 'type_bbcode_callback', array(
	), 	'source', 	array ('block'), 			array());

	if(in_array('table', $features) || empty($featurestext) || $featurestext == "true") {
		$class -> addCode('table',	'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'table', 	array ('block'), 		array());
		$class -> addCode('row',	'callback_replace', 'type_bbcode_callback', array(
			'classes' 		=> &$classes
		), 	'tablerow', array ('table'), 		array());
		$class -> addCode('tr',		'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'tablerow', array ('table'), 		array());
		$class -> addCode('cell',	'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'block', array ('tablerow'), 		array());
		$class -> addCode('td',		'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'block', array ('tablerow'), 		array());
		$class -> addCode('head',	'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'block', array ('tablerow'), 		array());
		$class -> addCode('th',		'callback_replace', 'type_bbcode_callback', array(
			'classes' 	=> &$classes
		), 	'block', array ('tablerow'), 		array());
	}


	// SetUp PreParsed Templates

	$class -> setCodeFlag('link', 'dedi.tpl', $linktpl);
	$class -> setCodeFlag('link', 'dedi.exttpl', $extlinktpl);
	$class -> setCodeFlag('filelink', 'dedi.tpl', $filelinktpl);
	$class -> setCodeFlag('footnote', 'dedi.tpl', $footnotelinktpl);
	$class -> setCodeFlag('email', 'dedi.tpl', $maillinktpl);

	// SetUp Parser, Filter & Flags
	if($type_config['htmltags'] == 'allow')
		$class -> addParser(array('block', 'inline', 'link', 'listitem'), 'type_convert_php');
	elseif($type_config['htmltags'] == 'strip')
		$class -> addParser(array('block', 'inline', 'link', 'listitem'), 'strip_tags');

	$class -> addParser(array('block', 'inline', 'link', 'listitem'), 'specialchars');

	if($nl2br) $class -> addParser(array('block', 'inline', 'link'), 'type_replace_nls' . (($htmlmode == 'XHTML') ? '_xhtml' : ''));
	$class -> addFilter(STRINGPARSER_FILTER_PRE, 'type_convertlinebreaks');
	$class -> setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL);

	$class -> setCodeFlag('table', 'validate_again', true);
	$class -> setCodeFlag('row', 'validate_again', true);


	// SetUp Paragraphhandling
	if($paragraphs) {
		$class -> setCodeFlag('hr', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
		$class -> setCodeFlag('hr', 'opentag.newline.before', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('hr', 'closetag.newline.after', BBCODE_NEWLINE_DROP);

		$class -> setCodeFlag('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
		$class -> setCodeFlag('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('list', 'opentag.after.newline', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('list', 'closetag.after.newline', BBCODE_NEWLINE_DROP);

		$class -> setCodeFlag('code', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
		$class -> setCodeFlag('code', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('code', 'closetag.afte.newliner', BBCODE_NEWLINE_DROP);

		$class -> setCodeFlag('table', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
		$class -> setCodeFlag('table', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('table', 'closetag.afte.newliner', BBCODE_NEWLINE_DROP);

		$class -> setCodeFlag('source', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
		$class -> setCodeFlag('source', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
		$class -> setCodeFlag('source', 'closetag.afte.newliner', BBCODE_NEWLINE_DROP);

		$class -> setCodeFlag('link', 'paragraph_type', BBCODE_PARAGRAPH_ALLOW_INSIDE);
		$class -> setCodeFlag('filelink', 'paragraph_type', BBCODE_PARAGRAPH_ALLOW_INSIDE);

		$class -> addParser(array('link'), 'nl2br');

		if($singleenter) $class -> setParagraphHandlingParameters("\n", "<p>", "</p>");
		$class -> setRootParagraphHandling(true);
	}
}

$__bbcode_footnotes = array();
function type_bbcode_callback($action, $attributes, &$content, $params, &$node_object) {
	global $cfg_client, $__bbcode_footnotes;

	$parsetpl = $node_object -> _flags['dedi.parsetpl'];
	$name = $node_object -> name();

	$usecontent = false;	// Usecontent?-Tag
	$ppar = '';				// Primärparameter
	// 1. Schritt - Primärparameter einlesen
	switch($name) {
		case 'size':		$ppar = 'percent'; 							break;
		case 'font':		$ppar = 'family'; 							break;
		case 'class':		$ppar = 'class'; 							break;
		case 'forecol':		$ppar = 'color'; 							break;
		case 'backcol':		$ppar = 'color'; 							break;
		case 'email':		$ppar = 'adress'; 	$usecontent = true; 	break;
		case 'anchor':		$ppar = 'id'; 		$usecontent = true; 	break;
		case 'link':		$ppar = 'dest';	 	$usecontent = true; 	break;
		case 'filelink':	$ppar = 'id'; 		$usecontent = true; 	break;
		case 'list':		$ppar = 'format'; 							break;
		case 'code':		$ppar = 'format';							break;
		case 'img':			$ppar = 'title';							break;
		case 'abbr':		$ppar = 'title';							break;
		case 'acronym':		$ppar = 'title';							break;
		case 'table':		$ppar = 'caption';							break;
		case 'footnote':												break;
		case 'row':														break;
		case 'tr':														break;
		case 'cell':													break;
		case 'td':														break;
		case 'head':													break;
		case 'th':														break;
		case 'source':													break;
		case 'hr':														break;
		case '*':														break;
		default:			return false;
	}

	if(!empty($ppar)) {
		if(isset($attributes[$ppar]) && !empty($attributes[$ppar])) {
			$ppar = $attributes[$ppar];
		} else {
			if(isset($attributes['default']) && !empty($attributes['default'])) {
				$ppar = $attributes['default'];
			} else {
				// Usecontent-Tags werden auch ersetzt, wenn die Usecontent-
				// Option deaktiviert wurde, da der identische Effekt auch ohne
				// Usecontent-Option möglich ist und somit NoText nur einen
				// optischen Hintergrund (weniger Elemente auf den Formularen)
				// hat.
				if($usecontent) {
					$ppar_from_content = true;
					$ppar = $content;
				} else $ppar = '';
			}
		}
	}

	// 2. Schritt - Validieren oder Ausgeben?
	if($action == 'validate') {
		// 3. Schritt - Parameter validieren
		// Im TplParse-Modus darf nicht Validiert werden, da nur Platzhalter übergeben werden.
		if($parsetpl) return true;
		switch($name) {
			case 'size':
				$ok = (((int)$ppar >= $params['sizemin']) &&
					((int)$ppar <= $params['sizemax']));
				break;

			case 'font':
				$ok = in_array($ppar, $params['fonts']);
				break;

			case 'class':
				$ok = isset($params['classes'][$ppar]);
				break;

			case 'backcol':
			case 'forecol':
				$ok = type_validate_color($ppar);
				break;

			case 'email':
				$ok = type_validate_email($ppar);
				break;

			case 'anchor':
				$ok = type_validate_anchorid($ppar);
				break;

			case 'link':
				if($parsetpl) $ok = true; else {
					if($params['allowanchor'] && $attributes['anchor'] != '') {
						//echo "ppar: $ppar; ppar-from-content: $ppar_from_content;<br />\n";
						$ok = (($ppar == '') || $ppar_from_content || type_validate_linkdest($ppar, $params['allowexternal'])) && type_validate_anchorid($attributes['anchor']);
					} else {
						$ok = type_validate_linkdest($ppar, $params['allowexternal']);
					}
				}
				break;

			case 'filelink':
				$ok = is_numeric($ppar);
				break;

			case 'img':
				$ok = type_validate_imgsrc($content);
				break;

			case 'table':
			case 'row':
			case 'tr':
			case 'cell':
			case 'td':
			case 'head':
			case 'th':
			case 'list':
			case 'code':
			case 'abbr':
			case 'source':
			case 'footnote':
			case 'acronym':
			case 'hr':
			case '*': $ok = true;
		}

		// 4. Schritt - Validierung beenden
		return $ok;
	} elseif($action == 'validate_again') {
		for ($i = 0; $i < count($node_object->_children); $i++) {
			$ctype = $node_object->_children[$i]->type();

			if ($ctype == STRINGPARSER_NODE_TEXT) {
				if(strlen(trim($node_object->_children[$i]->content))) {
					$node_object->_children[$i]->content = '';
				}
			} elseif($ctype == STRINGPARSER_BBCODE_NODE_ELEMENT) {
				$cname = $node_object->_children[$i]->name();
				switch($name) {
					case 'table':
						if($cname == 'row' || $cname == 'tr') {
							$ok = true;
							break;
						}
						break;
					case 'row':
						if($cname == 'cell' || $cname == 'td' || $cname == 'head' || $cname == 'th') {
							$ok = true;
							break;
						}
						break;
				}
			}
		}

		return $ok;
	} elseif($action == 'output') {
		// 3. Schritt - HTML-Code konstruieren und ausgeben
		switch($name) {
			case 'size':
				return '<span style="font-size: ' . (int)$ppar . '%;">' . $content . '</span>';

			case 'font':
				return '<span style="font-family: \'' . $ppar . '\';">' . $content . '</span>';

			case 'class':
				return '<' . $params['element'] . ' class="' . $ppar . '">' . $content . '</' . $params['element'] . '>';

			case 'forecol':
				return '<span style="color: ' . $ppar . ';">' . $content . '</span>';

			case 'backcol':
				return '<span style="background-color: ' . $ppar . ';">' . $content . '</span>';

			case 'email':
				$s = $ppar; $p = '';
				$tpl = $node_object -> _flags['dedi.tpl'];
				if(isset($attributes['name']) && !empty($attributes['name'])) $s = $attributes['name'] . ' &lt;' . $s . '&gt;';
				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $p = ' class="' . $attributes['style'] . '"';


				if(isset($attributes['subject']) && !empty($attributes['subject']))
					$s .= '?subject=' . $attributes['subject'];

				//return '<a href="mailto:' . $s . '"' . $p . '>' . (($notext_used || empty($content))  ? htmlspecialchars($ppar) : $content) . '</a>';
				$tpl = str_replace('{url}', 'mailto:' . $s, $tpl);
				$tpl = str_replace('{text}', (($notext_used || empty($content))  ? htmlspecialchars($ppar) : $content), $tpl);
				$tpl = str_replace('{_style_}', $p, $tpl);
				$tpl = str_replace('{_target_}', '', $tpl);
				return $tpl;

			case 'anchor':
				switch($params['htmlmode']) {
					case 'HTML':
						$s = 'name';
						break;
					case 'XHTML':
						$s = 'id';
						break;
				}
				return '<a ' . $s . '="' . $ppar . '">' . (($notext_used || empty($content))  ? '' : $content) . '</a>';
				return $content;

			case 'link':
				//echo $params['allowexternal'] ? 'OK' : 'BAD';
				if($parsetpl) {
					return '<a href="' . $ppar . '"' . ((isset($attributes['target']) && !empty($attributes['target'])) ? ' target="' . $attributes['target'] . '"' : '{_target_}') . ((isset($attributes['style']) && !empty($attributes['style'])) ? ' class="' . $attributes['style'] . '"' : '{_style_}') . '>' . $content . '</a>';
				} else {
					$isinternal = false;
					if(type_validate_linkdest($ppar, $params['allowexternal']) && (isset($attributes['anchor']) ? !$ppar_from_content : true)) {
						if(type_validate_linkdest($ppar, false)) {
							// Interne Seite (SeitenID)
							$isinternal = true;
							$link = type_get_sideurl((int)$ppar);
							$linkname = (!$ppar_from_content && !empty($content)) ? $content : type_get_sidename((int)$ppar);
						} else {
							// Externe Seite (sonstige Adresse, s. type_validate_url)
							$isinternal = false;
							$link = $ppar;
							$linkname = (!$ppar_from_content && !empty($content)) ? $content : $ppar;
						}
						if(isset($attributes['anchor'])) {
							// zusätzlich anchor angegeben
							if(substr($attributes['anchor'], 0, 1) == '#') $attributes['anchor'] = substr($attributes['anchor'], 1);
							$link .= '#' . $attributes['anchor'];
							$linkname = (empty($linkname) ? '#' . $attributes['anchor'] : $linkname);
						}
					} else if(isset($attributes['anchor']) && type_validate_anchorid($attributes['anchor'])) {
						// Nur anchor
						if(substr($attributes['anchor'], 0, 1) == '#') $attributes['anchor'] = substr($attributes['anchor'], 1);
						$isinternal = true;
						$link = '#' . $attributes['anchor'];
						$linkname = (empty($content) ? (empty($ppar) ? $link : $ppar) : $content);
					}
					//$linkname = (empty($content) ? $attributes['anchor'] : (type_validate_linkdest((int)$content, false) ? type_get_sidename((int)$content) : $content));
					//echo "$link; Linkname = $linkname<br />\n";

					$tpl = $isinternal ? $node_object -> _flags['dedi.tpl'] : $node_object -> _flags['dedi.exttpl'];
					$tpl = str_replace('{_target_}', ((isset($attributes['target']) && !empty($attributes['target']) && !$params['notarget']) ? ' target="' . $attributes['target'] . '"' : ''), $tpl);
					$tpl = str_replace('{_style_}',  ((isset($attributes['style'])  && !empty($attributes['style'])  && isset($params['classes'][$attributes['style']])) ? ' class="' . $attributes['style'] . '"' : ''), $tpl);
					$tpl = str_replace('{url}', $link, $tpl);
					$tpl = str_replace('{text}', $linkname, $tpl);
					return $tpl;
				}
				return $content;

			case 'filelink':
				$tpl = $node_object -> _flags['dedi.tpl'];
				$tpl = str_replace('{url}',  type_get_fileurl((int)$ppar), $tpl);
				$tpl = str_replace('{text}', ($ppar_from_content || empty($content) ? type_get_filename((int)$ppar) : $content), $tpl);
				$tpl = str_replace('{size}', type_get_filesize((int)$ppar), $tpl);
				$tpl = str_replace('{file}', type_get_filename((int)$ppar), $tpl);
				$tpl = str_replace('{title}', type_get_filetitle((int)$ppar), $tpl);
				$tpl = str_replace('{desc}', type_get_filedesc((int)$ppar), $tpl);
				$tpl = str_replace('{type}', type_get_filetype((int)$ppar), $tpl);
				$tpl = str_replace('{typedesc}', type_get_filetypedesc((int)$ppar), $tpl);
				$tpl = str_replace('{_target_}', ((isset($attributes['target']) && !empty($attributes['target']) && !$params['notarget']) ? ' target="' . $attributes['target'] . '"' : ''), $tpl);
				$tpl = str_replace('{_style_}',  ((isset($attributes['style'])  && !empty($attributes['style'])  && isset($params['classes'][$attributes['style']])) ? ' class="' . $attributes['style'] . '"' : ''), $tpl);
				return $tpl;

			case 'img':
				if(is_numeric($content)) $content = type_get_fileurl((int)$content);
				$content = str_replace('{mediapath}', $cfg_client['upl_htmlpath'], $content);
				if(isset($ppar) && !empty($ppar)) {
					$s .= ' alt="' . $ppar . '"';
					$s .= ' title="' . $ppar . '"';
				} else if($params['imgalwaysalt'])
					$s .= ' alt=""';

				if(isset($attributes['width']) && !empty($attributes['width'])) $s .= ' width="' . intval($attributes['width']) . 'px"';
				if(isset($attributes['height']) && !empty($attributes['height'])) $s .= ' height="' . intval($attributes['height']) . 'px"';

				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s .= ' class="' . $attributes['style'] . '"';

				if($params['htmlmode'] == 'XHTML') $s .= ' /';
				return '<img src="' . $content . '"' . $s . '>';
				return $content;

			case 'list':
				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s = ' class="' . $attributes['style'] . '"';
				if($ppar == 'numbered') {
					return '<ol' . $s . ">\n" . $content . "</ol>\n";
				} else {
					return '<ul' . $s . ">\n" . $content . "</ul>\n";
				}
				return $content;

			case '*':
				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s = ' class="' . $attributes['style'] . '"';
				return '<li' . $s . '>' . $content . '</li>';

			case 'code':
				if($ppar == 'php') {
					$content = type_xhtml_highlight($content);
				} else {
					$content = htmlspecialchars($content);
				}
				return '<pre>' . $content . '</pre>';

			case 'abbr':
			case 'acronym':
				if(empty($content)) return '';
				if(isset($ppar) && !empty($ppar)) $s .= ' title="' . $ppar . '"';
				if(isset($attributes['lang']) && !empty($attributes['lang'])) {
					switch($params['htmlmode']) {
						case 'HTML':
							$s .= ' lang';
							break;
						case 'XHTML':
							$s .= ' xml:lang';
							break;
					}
					$s .= '="' . $attributes['lang'] . '"';
				}

				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s .= ' class="' . $attributes['style'] . '"';

				return '<' . $name . $s . '>' . $content . '</' . $name . '>';

			case 'source':
				return str_replace('<?', '&lt;?', str_replace('?&gt;', '?>', $content));

			case 'footnote':
				$__bbcode_footnotes[] = $content;
				$id = count($__bbcode_footnotes);
				$s = '<a href="#footnote_' . $id . '"';
				switch($params['htmlmode']) {
					case 'HTML':
						$s .= ' name';
						break;
					case 'XHTML':
						$s .= ' id';
						break;
				}
				$s .= '="footnote_o_' . $id . '">' . str_replace('{id}', $id, $node_object -> _flags['dedi.tpl']) . '</a>';
				return $s;

			case 'table':
				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s .= ' class="' . $attributes['style'] . '"';
				$s = '<table' . $s . '>';
				if(!empty($ppar)) $s .= '<caption>' . $ppar . '</caption>';
				$s .= $content . '</table>';
				return $s;

			case 'tr':
			case 'row':
				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s .= ' class="' . $attributes['style'] . '"';
				return '<tr' . $s . '>'. $content .'</tr>';

			case 'td':
			case 'cell':
				$code = 'td';
			case 'th':
			case 'head':
				if(empty($code)) $code = 'th';

				if(isset($attributes['rowspan'])) $s .= ' rowspan="'. $attributes['rowspan'] .'"';
				if(isset($attributes['colspan']))
					$s .= ' colspan="'. $attributes['colspan'] .'"';
				elseif(isset($attributes['span']))
					$s .= ' colspan="'. $attributes['span'] .'"';

				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s .= ' class="' . $attributes['style'] . '"';

				return '<'. $code . $s .'>'. $content .'</'. $code .'>';

			case 'hr':
				if(isset($attributes['style']) && !empty($attributes['style']) && isset($params['classes'][$attributes['style']])) $s = ' class="' . $attributes['style'] . '"';
				if($params['htmlmode'] == 'XHTML') $s .= ' /';
				return '<hr' . $s . '>';
			break;
		}
	}
}
?>