<commit_before><?php

/**
 * Handler class for Text
 * 
 * Letter key: ~t~
 *
 */
class Tracker_Field_Text extends Tracker_Field_Abstract
{
	function getFieldData(array $requestData = array())
	{
		$data = $this->processMultilingual($requestData, $this->getInsertId());

		return $data;
	}

	function renderInput($context = array())
	{
		return $this->renderTemplate('trackerinput/text.tpl', $context);
	}

	function renderInnerOutput($context = array())
	{
		$pre = '';
		$post = '';

		if ($this->getOption(2)) {
			$pre = '<span class="formunit">' . $this->getOption(2) . '</span>';
		}

		if ($this->getOption(3)) {
			$pre = '<span class="formunit">' . $this->getOption(3) . '</span>';
		}

		return $pre . parent::renderInnerOutput($context) . $post;
	}

	protected function processMultilingual($requestData, $id_string) {
		global $prefs, $language;

		if (!isset($requestData[$id_string])) {
			$requestData[$id_string] = $this->getValue();
		}
		
		if (is_array($requestData[$id_string])) {
			$thisVal = $requestData[$id_string][$language];
		} else {
			$thisVal = $requestData[$id_string];
		}

		$data = array(
			'value' => $thisVal,
			'pvalue' => TikiLib::lib('tiki')->parse_data(htmlspecialchars($thisVal)),
		);

		if ($this->getConfiguration("isMultilingual") == 'y') {
			$data['isMultilingual'] = 'y';
			foreach($prefs['available_languages'] as $num => $tmplang) {	// TODO add a limit on number of langs - 40+ makes this blow up

				if (!isset($requestData[$id_string][$tmplang])) {	// Case convert normal -> multilingual
					$requestData[$id_string][$tmplang] = $this->getValue($data['value'], $tmplang);
				}

				$data['lingualvalue'][$num]['lang'] = $tmplang;
				$data['lingualvalue'][$num]['value'] = $requestData[$id_string][$tmplang];
				$data['lingualpvalue'][$num]['lang'] = $tmplang;
				$data['lingualpvalue'][$num]['value'] = TikiLib::lib('tiki')->parse_data(htmlspecialchars($requestData[$id_string][$tmplang]));

				if ($prefs['language'] == $tmplang) {
					$data['value'] = $data['lingualvalue'][$num]['value'];<commit_msg>[FIX] Multilingual text field not always displaying the data correctly<commit_after><?php

/**
 * Handler class for Text
 * 
 * Letter key: ~t~
 *
 */
class Tracker_Field_Text extends Tracker_Field_Abstract
{
	function getFieldData(array $requestData = array())
	{
		$data = $this->processMultilingual($requestData, $this->getInsertId());

		return $data;
	}

	function renderInput($context = array())
	{
		return $this->renderTemplate('trackerinput/text.tpl', $context);
	}

	function renderInnerOutput($context = array())
	{
		$pre = '';
		$post = '';

		if ($this->getOption(2)) {
			$pre = '<span class="formunit">' . $this->getOption(2) . '</span>';
		}

		if ($this->getOption(3)) {
			$pre = '<span class="formunit">' . $this->getOption(3) . '</span>';
		}

		return $pre . parent::renderInnerOutput($context) . $post;
	}

	protected function processMultilingual($requestData, $id_string) {
		global $prefs, $language;

		if (!isset($requestData[$id_string])) {
			$requestData[$id_string] = $this->getValue();
		}
		
		if (is_array($requestData[$id_string])) {
			$thisVal = $requestData[$id_string][$language];
		} else {
			$thisVal = $requestData[$id_string];
		}

		$data = array(
			'value' => $thisVal,
			'pvalue' => TikiLib::lib('tiki')->parse_data(htmlspecialchars($thisVal)),
			'lingualvalue' => array(),
			'lingualpvalue' => array(),
		);

		if ($this->getConfiguration("isMultilingual") == 'y') {
			if (! is_array($requestData[$id_string])) {
				$out = array();
				foreach($prefs['available_languages'] as $num => $tmplang) {	// TODO add a limit on number of langs - 40+ makes this blow up
					if (!isset($out[$tmplang])) {	// Case convert normal -> multilingual
						$out[$tmplang] = $this->getValue($data['value'], $tmplang);
					}
				}

				$requestData[$id_string] = $out;
			}

			foreach($prefs['available_languages'] as $num => $tmplang) {	// TODO add a limit on number of langs - 40+ makes this blow up
				if (!isset($requestData[$id_string][$tmplang])) {	// Case convert normal -> multilingual
					$requestData[$id_string][$tmplang] = $this->getValue($data['value'], $tmplang);
				}

				$data['lingualvalue'][$num]['lang'] = $tmplang;
				$data['lingualvalue'][$num]['value'] = $requestData[$id_string][$tmplang];
				$data['lingualpvalue'][$num]['lang'] = $tmplang;
				$data['lingualpvalue'][$num]['value'] = TikiLib::lib('tiki')->parse_data(htmlspecialchars($requestData[$id_string][$tmplang]));

				if ($prefs['language'] == $tmplang) {
					$data['value'] = $data['lingualvalue'][$num]['value'];
{'fraction_non_alphanumeric': 0.20607375271149675, 'fraction_numerical': 0.003036876355748373, 'mean_word_length': 4.713754646840148, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '948198', 'n_tokens_mistral': 1780, 'n_tokens_neox': 1564, 'n_words': 278}