<commit_before><?php
/**
 * @copyright Copyright (c) 2012 The President and Fellows of Harvard College
 * @license Use of this source code is governed by the LICENSE file found in the root of this project.
 */

/**
 * creates the view string for fillin questions.  includes the input text fields
 *
 * Syntax:
 * {fillin question="roses are {red} violets are {blue}"}
 *
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_fillin($params, &$smarty){

	//error_log("fillin...");
	$question = $params['question'];
	$responses = null;
	if(isset($params['responses']))
		$responses = $params['responses'];
	//$question = "you put the {lime} in the {coconut} and {drink} it all up";
	//$responses = array(array(response=>lime), array(response=>coconut), array(response=>drink))
	$disabled = '';
	if(isset($params['disabled'])){
		$disabled = ' disabled="disabled" ';
	}
	
	preg_match_all("/\{[^}]*\}/", $question, $matches);
	$responses_index = 0;
	foreach($matches as $val){
		foreach($val as $key => $match){
			//error_log($match);
			//if($responses == null){
			if(!isset($responses[$responses_index])){
				$new_input = "<input class='input-small fillin-text' type='text' $disabled/>";				
			} else {
				//error_log("$response...");
				$response = $responses[$responses_index]['response'];
				$responses_index++;
				$new_input = "<input class='input-small fillin-text' type='text' value='$response' $disabled/>";
			}
			$question = preg_replace("/".addslashes($match)."/", $new_input, $question);
		}
		//error_log(var_export($match, 1));
	}
	

    return $question;
}<commit_msg>smarty plugin for fillins won't barf multiple inputs on a pipe<commit_after><?php
/**
 * @copyright Copyright (c) 2012 The President and Fellows of Harvard College
 * @license Use of this source code is governed by the LICENSE file found in the root of this project.
 */

/**
 * creates the view string for fillin questions.  includes the input text fields
 *
 * Syntax:
 * {fillin question="roses are {red} violets are {blue}"}
 *
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_fillin($params, &$smarty){

	//error_log("fillin...");
	$question = $params['question'];
	$responses = null;
	if(isset($params['responses']))
		$responses = $params['responses'];
	$disabled = '';
	if(isset($params['disabled'])){
		$disabled = ' disabled="disabled" ';
	}
	
	// removing the pipes, they seem to have an odd effect on the inputs
	$question = preg_replace("/\|/", "", $question);
	preg_match_all("/\{[^}]*\}/", $question, $matches);
	$responses_index = 0;
	foreach($matches as $val){
		foreach($val as $key => $match){
			//error_log($match);
			//if($responses == null){
			if(!isset($responses[$responses_index])){
				$new_input = "<input class='input-small fillin-text' type='text' $disabled/>";				
			} else {
				//error_log("$response...");
				$response = $responses[$responses_index]['response'];
				$responses_index++;
				$new_input = "<input class='input-small fillin-text' type='text' value='$response' $disabled/>";
			}
			// if the pipe is left in, this preg_replace matches more times than we want because of the OR in the match... 
			$question = preg_replace("/".htmlspecialchars($match)."/", $new_input, $question);
		}
		//error_log(var_export($match, 1));
	}
	
	error_log($question);
    return $question;
}
{'fraction_non_alphanumeric': 0.18099149310648283, 'fraction_numerical': 0.0035200938691698444, 'mean_word_length': 4.2786377708978325, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, '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': '1556678', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1094, 'n_words': 297}