示例#1
0
	/**
	 * Returns the formatted UBB
	 */
	function converttoubb($parseresult, $allowedchildren = Array(null)) {
		$output = Array('');
		$bodycount = 0;

		$parseResultCount = sizeof($parseresult);
		for($i = 0; $i < $parseResultCount; $i++) {
			/* save the current allowedchildren */
			$saveallowedchildren = $allowedchildren;

			/* first get the tag results */
			if ($parseresult[$i]['tagname'] !== '') {
				$tagresult = NULL;

				/* Get the configuration for this tag, as it also includes the function
				 * to call when processing this tag */
				$tagconfig = TagHandler::gettagconfig($parseresult[$i]['tagname']);

				/* Are we allowed to run this tag? */
				if (($allowedchildren[0] === NULL) | 
					(array_search($parseresult[$i]['tagname'], $allowedchildren))) {

					$tagresult = TagHandler::process_tag($parseresult[$i]['tagname'],
									$parseresult[$i]['params'],
									$parseresult[$i]['content']);
				} // if 

				/* If tag result was NULL, the given tag is invalid, so reconstruct it */
				if ($tagresult === NULL) {
					if ($tagconfig['closetags'] !== Array(NULL)) {
						$appendclosetag = '[/' . $parseresult[$i]['tagname'] . ']';
					} else {
						$appendclosetag = '';
					} // else

					/* add the tag back in */
					$tagresult = Array('prepend' => '[' . $parseresult[$i]['tagname'] .
								$parseresult[$i]['params']['originalparams'] . ']',
							   'append' => $appendclosetag );

				} else {
					/* allow the tags to overwrite the content */
					$parseresult[$i]['content'] = $tagresult['content'];
				} // else

				/* Now append the allowed children */
				if ($tagconfig['allowedchildren'][0] === '') {
					/* deny all child tags */
					$allowedchildren = Array('');
				} else if ($tagconfig['allowedchildren'][0] !== NULL) {
					/* all tags are allowed */
					$allowedchildren = array_intersect($allowedchildren, $tagconfig['allowedchildren']);
				} // else 


			} else {
				$tagresult = Array('prepend' => '',
						   'append' => '');
			} // else

			$output[$bodycount] .= $tagresult['prepend'];
			if (is_array($parseresult[$i]['content'])) {
				$parsedchildcontent = $this->converttoubb($parseresult[$i]['content'], $allowedchildren);

				$output[$bodycount] .= $parsedchildcontent[0];
				if (count($parsedchildcontent) > 1) {
					array_shift($parsedchildcontent);
					$output = array_merge($output, $parsedchildcontent);
				} // if
			} else {
				$output[$bodycount] .= $parseresult[$i]['content'];
			} // else
			$output[$bodycount] .= $tagresult['append'];

			/* restore the saved allowed children */
			$allowedchildren = $saveallowedchildren;
		} // for

		return $output;
	} // converttoubb