Wrap each equation part with code tag for readability
This commit is contained in:
@@ -414,11 +414,12 @@ if ( !function_exists( 'sp_get_post_equation' ) ) {
|
|||||||
function sp_get_post_equation( $post_id ) {
|
function sp_get_post_equation( $post_id ) {
|
||||||
$equation = get_post_meta ( $post_id, 'sp_equation', true );
|
$equation = get_post_meta ( $post_id, 'sp_equation', true );
|
||||||
if ( $equation ):
|
if ( $equation ):
|
||||||
return str_replace(
|
$equation = str_replace(
|
||||||
array( '/', '(', ')', '+', '-', '*', '$' ),
|
array( '/', '(', ')', '+', '-', '*', '$' ),
|
||||||
array( '<code>÷</code>', '<code>(</code>', '<code>)</code>', '<code>+</code>', '<code>−</code>', '<code>×</code>', '' ),
|
array( '÷', '(', ')', '+', '−', '×', '' ),
|
||||||
trim( $equation )
|
trim( $equation )
|
||||||
);
|
);
|
||||||
|
return '<code>' . implode( '</code> <code>', explode( ' ', $equation ) ) . '</code>';
|
||||||
else:
|
else:
|
||||||
return '—';
|
return '—';
|
||||||
endif;
|
endif;
|
||||||
@@ -1104,14 +1105,17 @@ if ( !function_exists( 'sp_solve' ) ) {
|
|||||||
include_once( SP()->plugin_path() . '/includes/libraries/class-eqeos.php' );
|
include_once( SP()->plugin_path() . '/includes/libraries/class-eqeos.php' );
|
||||||
$eos = new eqEOS();
|
$eos = new eqEOS();
|
||||||
|
|
||||||
// Clearance to begin calculating remains true if all equation variables are in vars
|
// Remove spaces from equation
|
||||||
$clearance = true;
|
$equation = str_replace( ' ', '', $equation );
|
||||||
|
|
||||||
|
// Create temporary equation replacing operators with spaces
|
||||||
|
$temp = str_replace( array( '+', '-', '*', '/', '(', ')' ), ' ', $equation );
|
||||||
|
|
||||||
// Check if each variable part is in vars
|
// Check if each variable part is in vars
|
||||||
$parts = explode( ' ', $equation );
|
$parts = explode( ' ', $temp );
|
||||||
foreach( $parts as $key => $value ):
|
foreach( $parts as $key => $value ):
|
||||||
if ( substr( $value, 0, 1 ) == '$' ):
|
if ( substr( $value, 0, 1 ) == '$' ):
|
||||||
if ( ! array_key_exists( preg_replace( "/[^a-z]/", '', $value ), $vars ) )
|
if ( ! array_key_exists( preg_replace( "/[^a-z0-9]/", '', $value ), $vars ) )
|
||||||
return 0;
|
return 0;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|||||||
Reference in New Issue
Block a user