src/classes/CCView/Builder/CCFTemplate.php
public function repair_expression( $exp )
	{
		$commands = explode( ' ', $exp );		

		// filter empty ones
		$commands = array_filter( $commands, function( $value ) 
		{
			return !is_null( $value );
		});

		// bracket starting command
		if ( in_array( $commands[0], $this->bracket_starting_commands ) )
		{
			// each = foreach
			if ( $commands[0] == 'each' )
			{
				$commands[0] = 'foreach';
			}
			// loop special
			elseif ( $commands[0] == 'loop' )
			{
				$commands[0] = 'for';
				$commands[1] = '$i=0;$i<'.$commands[1].';$i++';
			}

			// remove the opening duble point
			end($commands); $key = key($commands);
			if ( substr( $commands[$key], -1 ) == ':' )
			{
				$commands[$key] = substr( $commands[$key], 0, -1 );

				// is it now empty?
				if ( $commands[$key] == ' ' || empty( $commands[$key] ) )
				{
					unset( $commands[$key] );
				}
			}

			// do we have brackets?
			if ( substr( $commands[1], 0, 1 ) != '(' )
			{
				// add starting bracket
				$commands[1] = '( '.$commands[1];

				// add ending bracket
				end($commands); $key = key($commands);
				$commands[$key] .= ' )';
			}

			$commands[] = ':';
		}
		// bracket ending command
		elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_ending_commands ) )
		{
			// each = foreach
			if ( $commands[0] == 'endeach' )
			{
				$commands[0] = 'endforeach';
			}
			// loop special
			elseif ( $commands[0] == 'endloop' )
			{
				$commands[0] = 'endfor';
			}

			// check for semicolon
			if ( substr( $commands[0], 0, 1 ) != ';' )
			{
				$commands[0] .= ';';
			}
		}
		// bracket continue command
		elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_continue_commands ) )
		{		
			// remove the opening duble point
			end($commands); $key = key($commands);
			if ( substr( $commands[$key], -1 ) == ':' )
			{
				$commands[$key] = substr( $commands[$key], 0, -1 );

				// is it now empty?
				if ( $commands[$key] == ' ' || empty( $commands[$key] ) )
				{
					unset( $commands[$key] );
				}
			}

			// add the double point
			$commands[] = ':';
		}

		return implode( ' ', $commands );
	}
public function repair_expression( $exp )
	{
		$commands = explode( ' ', $exp );		

		// filter empty ones
		$commands = array_filter( $commands, function( $value ) 
		{
			return !is_null( $value );
		});

		// bracket starting command
		if ( in_array( $commands[0], $this->bracket_starting_commands ) )
		{
			// each = foreach
			if ( $commands[0] == 'each' )
			{
				$commands[0] = 'foreach';
			}
			// loop special
			elseif ( $commands[0] == 'loop' )
			{
				$commands[0] = 'for';
				$commands[1] = '$i=0;$i<'.$commands[1].';$i++';
			}

			// remove the opening duble point
			end($commands); $key = key($commands);
			if ( substr( $commands[$key], -1 ) == ':' )
			{
				$commands[$key] = substr( $commands[$key], 0, -1 );

				// is it now empty?
				if ( $commands[$key] == ' ' || empty( $commands[$key] ) )
				{
					unset( $commands[$key] );
				}
			}

			// do we have brackets?
			if ( substr( $commands[1], 0, 1 ) != '(' )
			{
				// add starting bracket
				$commands[1] = '( '.$commands[1];

				// add ending bracket
				end($commands); $key = key($commands);
				$commands[$key] .= ' )';
			}

			$commands[] = ':';
		}
		// bracket ending command
		elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_ending_commands ) )
		{
			// each = foreach
			if ( $commands[0] == 'endeach' )
			{
				$commands[0] = 'endforeach';
			}
			// loop special
			elseif ( $commands[0] == 'endloop' )
			{
				$commands[0] = 'endfor';
			}

			// check for semicolon
			if ( substr( $commands[0], 0, 1 ) != ';' )
			{
				$commands[0] .= ';';
			}
		}
		// bracket continue command
		elseif ( count( $commands == 1 ) && in_array( $commands[0], $this->bracket_continue_commands ) )
		{		
			// remove the opening duble point
			end($commands); $key = key($commands);
			if ( substr( $commands[$key], -1 ) == ':' )
			{
				$commands[$key] = substr( $commands[$key], 0, -1 );

				// is it now empty?
				if ( $commands[$key] == ' ' || empty( $commands[$key] ) )
				{
					unset( $commands[$key] );
				}
			}

			// add the double point
			$commands[] = ':';
		}

		return implode( ' ', $commands );
	}
public function repair_expression ( $ exp ) { $ commands = explode ( ' ' , $ exp ) ; // filter empty ones $ commands = array_filter ( $ commands , function ( $ value ) { return ! is_null ( $ value ) ; } ) ; // bracket starting command if ( in_array ( $ commands [ 0 ] , $ this -> bracket_starting_commands ) ) { // each = foreach if ( $ commands [ 0 ] == 'each' ) { $ commands [ 0 ] = 'foreach' ; } // loop special elseif ( $ commands [ 0 ] == 'loop' ) { $ commands [ 0 ] = 'for' ; $ commands [ 1 ] = '$i=0;$i<' . $ commands [ 1 ] . ';$i++' ; } // remove the opening duble point end ( $ commands ) ; $ key = key ( $ commands ) ; if ( substr ( $ commands [ $ key ] , - 1 ) == ':' ) { $ commands [ $ key ] = substr ( $ commands [ $ key ] , 0 , - 1 ) ; // is it now empty? if ( $ commands [ $ key ] == ' ' || empty ( $ commands [ $ key ] ) ) { unset ( $ commands [ $ key ] ) ; } } // do we have brackets? if ( substr ( $ commands [ 1 ] , 0 , 1 ) != '(' ) { // add starting bracket $ commands [ 1 ] = '( ' . $ commands [ 1 ] ; // add ending bracket end ( $ commands ) ; $ key = key ( $ commands ) ; $ commands [ $ key ] .= ' )' ; } $ commands [ ] = ':' ; } // bracket ending command elseif ( count ( $ commands == 1 ) && in_array ( $ commands [ 0 ] , $ this -> bracket_ending_commands ) ) { // each = foreach if ( $ commands [ 0 ] == 'endeach' ) { $ commands [ 0 ] = 'endforeach' ; } // loop special elseif ( $ commands [ 0 ] == 'endloop' ) { $ commands [ 0 ] = 'endfor' ; } // check for semicolon if ( substr ( $ commands [ 0 ] , 0 , 1 ) != ';' ) { $ commands [ 0 ] .= ';' ; } } // bracket continue command elseif ( count ( $ commands == 1 ) && in_array ( $ commands [ 0 ] , $ this -> bracket_continue_commands ) ) { // remove the opening duble point end ( $ commands ) ; $ key = key ( $ commands ) ; if ( substr ( $ commands [ $ key ] , - 1 ) == ':' ) { $ commands [ $ key ] = substr ( $ commands [ $ key ] , 0 , - 1 ) ; // is it now empty? if ( $ commands [ $ key ] == ' ' || empty ( $ commands [ $ key ] ) ) { unset ( $ commands [ $ key ] ) ; } } // add the double point $ commands [ ] = ':' ; } return implode ( ' ' , $ commands ) ; }
Repair an expression
Repair an expression