<commit_before><?
set_error_handler(array('Cli', 'error_handler'), E_ALL);

Class Frontend_Controller extends Controller {

	public function __construct(){
		parent::__construct();
	}

	public function index(){
		echo "Configuring Frontend\n";
		echo "Reading application/config/frontend.xml\n";
		
		flush();
		ob_flush();
		
		foreach(mop::config('frontend', '//view') as $view ){
			touch('application/frontend/'.$view->getAttribute('name').'.php');
			ob_start();
			if($view->getAttribute('loadpage')=='true'){
				echo "<h1><?\$content['main']['title'];?></h1>\n\n";
				//this also implies that name is a templatename
				foreach(mop::config('backend', 
					sprintf('//template[@name="%s"]/elements/*', $view->getAttribute('name') )) as $element){
						$this->makeHtmlElement($element, 'main');
					}
			}
			if($eDataNodes = mop::config('frontend',"//view[@name=\"".$view->getAttribute('name')."\"]/extendeddata")){
				foreach($eDataNodes as $eDataConfig){
					$label = $eDataConfig->getAttribute('label');
					echo "<p>$label Content</p>";
					echo "<?foreach(\$content['$label'] as \$item):?>\n".
						"<ul>\n".
						"<?foreach(\$item as \$field=>\$value):?>\n".
						"<li><?=\$field;?>: <?=\$value;?></li>\n".
						"<?endforeach;?>\n".
						"</ul>\n".
						"<?endforeach;?>\n\n";
				}
			}
			if($subviews = mop::config('frontend',"//view[@name=\"".$view->getAttribute('name')."\"]/subview")){
				foreach($subviews as $subviewConfig){
					echo "\n<?=\$".$subviewConfig->getAttribute('label').";?>\n";
				}
			}
			$html = ob_get_contents();
			ob_end_clean();
			$file = fopen('application/frontend/'.$view->getAttribute('name').'.php', 'w');
			fwrite($file, $html);
			fclose($file);
		}



		echo "Done\n";
	}

	public function makeHtmlElement($element, $prefix){

		$field = $element->getAttribute('field');

		switch($element->nodeName){
		case 'list':
			$family = $element->getAttribute('family');
			$addables = mop::config('backend', 'addableObject', $element);		
			$addable = $addables->item(0);
			$templateName = $addable->getAttribute('templateName');
			$listItemElements = mop::config('backend', sprintf('//template[@name="%s"]', $templateName);		
			echo "<ul id=\"$family\" >\n"
			echo "<?foreach(\$content['$prefix']['$family'] as $label => {$family}ListItem):?>\n";
			echo " <li class=\"$template\">\n";
			foreach($listItemElements as $element){
				$this->makeHtmlElement($element, "$prefix']['$family");
			}
			echo " </li>\n";
			echo "</ul>\n\n";
			break;

		case 'singleImage':
			if(!($size=$element->getAttribute('size'))){
				$size = 'original';	
			}
			echo "<img id=\"$field\" src=\"<?=\$content['$prefix']['$field']->{$size}->fullpath;?>\" width=\"<?=\$content['$prefix']['$field']->{$size}->width;?>\" height=\"<?=\$content['$prefix']['$field']->{$size}->height;?>\" alt=\"<?=\$content['$prefix']['$field']->{$size}->filename;?>\" />";
			break;
		case 'singleFile':
			echo "<a href=\"\"></a>";
			break;
		default:
			echo "<p class=\"$field\"> <?=\$content['main']['$field'];?></p>\n";
			break;
		}

	}

}<commit_msg>modules: frontend<commit_after><?
set_error_handler(array('Cli', 'error_handler'), E_ALL);

Class Frontend_Controller extends Controller {

	public function __construct(){
		parent::__construct();
	}

	public function index(){
		echo "Configuring Frontend\n";
		echo "Reading application/config/frontend.xml\n";

		mop::config('backend', '//templates');
		
		flush();
		ob_flush();
		
		foreach(mop::config('frontend', '//view') as $view ){
			echo 'hey';
			touch('application/frontend/'.$view->getAttribute('name').'.php');
			echo 'application/frontend/'.$view->getAttribute('name').'.php';
			ob_start();
			if($view->getAttribute('loadpage')=='true'){
				echo "<h1><?\$content['main']['title'];?></h1>\n\n";
				//this also implies that name is a templatename
				foreach(mop::config('backend', 
					sprintf('//template[@name="%s"]/elements/*', $view->getAttribute('name') )) as $element){
						$this->makeHtmlElement($element, "\$content['main']");
					}
			}
			if($eDataNodes = mop::config('frontend',"//view[@name=\"".$view->getAttribute('name')."\"]/extendeddata")){
				foreach($eDataNodes as $eDataConfig){
					$label = $eDataConfig->getAttribute('label');
					echo "<p>$label Content</p>";
					echo "<?foreach(\$content['$label'] as \$item):?>\n".
						"<ul>\n".
						"<?foreach(\$item as \$field=>\$value):?>\n".
						"<li><?=\$field;?>: <?=\$value;?></li>\n".
						"<?endforeach;?>\n".
						"</ul>\n".
						"<?endforeach;?>\n\n";
				}
			}
			if($subviews = mop::config('frontend',"//view[@name=\"".$view->getAttribute('name')."\"]/subview")){
				foreach($subviews as $subviewConfig){
					echo "\n<?=\$".$subviewConfig->getAttribute('label').";?>\n";
				}
			}
			$html = ob_get_contents();
			ob_end_clean();
			$file = fopen('application/frontend/'.$view->getAttribute('name').'.php', 'w');
			fwrite($file, $html);
			fclose($file);
		}



		echo "Done\n";
	}

	public function makeHtmlElement($element, $prefix, $indent=''){

		$field = $element->getAttribute('field');

		switch($element->nodeName){
		case 'list':
			$family = $element->getAttribute('family');
			$addables = mop::config('backend', 'addableObject', $element);		
			$addable = $addables->item(0);
			$templateName = $addable->getAttribute('templateName');
			$listItemElements = mop::config('backend', sprintf('//template[@name="%s"]/elements/*', $templateName));		
			echo $indent."<ul id=\"$family\" >\n";
			echo $indent."<?foreach({$prefix}['$family'] as \$label => \${$family}ListItem):?>\n";
			echo $indent." <li class=\"$templateName\">\n";
			foreach($listItemElements as $element){
				$this->makeHtmlElement($element, "\${$family}ListItem", $indent.'  ');
			}
			echo $indent." </li>\n";
			echo $indent."</ul>\n\n";
			break;

		case 'singleImage':
			if(!($size=$element->getAttribute('size'))){
				$size = 'original';	
			}
			echo $indent."<img id=\"$field\" src=\"<?={$prefix}['$field']->{$size}->fullpath;?>\" width=\"<?={$prefix}['$field']->{$size}->width;?>\" height=\"<?={$prefix}['$field']->{$size}->height;?>\" alt=\"<?={$prefix}['$field']->{$size}->filename;?>\" />\n\n";
			break;
		case 'singleFile':
			echo $indent."<a href=\"\"></a>\n\n";
			break;
		default:
			echo $indent."<p class=\"$field\"> <?={$prefix}['$field'];?></p>\n\n";
			break;
		}

	}

}
{'fraction_non_alphanumeric': 0.2710163111668758, 'fraction_numerical': 0.0009410288582183187, 'mean_word_length': 4.1887713588283155, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 118, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3090454', 'n_tokens_mistral': 2563, 'n_tokens_neox': 2212, 'n_words': 328}