Changeset 1078949
- Timestamp:
- 01/30/2015 12:24:09 PM (11 years ago)
- File:
-
- 1 edited
-
enzymes/trunk/src/Enzymes3.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
enzymes/trunk/src/Enzymes3.php
r1077514 r1078949 8 8 class Enzymes3 9 9 { 10 const FORCE_ DEFAULT_VERSION = 'enzymes';11 12 const FORCE_INJECTION_VERSION_2 = '=enzymes .2=';13 14 const FORCE_INJECTION_VERSION_3 = '=enzymes .3=';10 const FORCE_POST_VERSION = 'enzymes'; 11 12 const FORCE_INJECTION_VERSION_2 = '=enzymes 2='; 13 14 const FORCE_INJECTION_VERSION_3 = '=enzymes 3='; 15 15 16 16 /** … … 334 334 * Echo a script HTML tag to write data to the javascript console of the browser. 335 335 * 336 * @param mixed$logs337 */ 338 protected 339 function console_log( $logs )336 * @param array $logs 337 */ 338 protected 339 function console_log( array $logs ) 340 340 { 341 341 if ( count($logs) == 0 ) { … … 356 356 protected $has_eval_recovered; 357 357 358 /** 359 * Add a title and some context to the output. 360 * 361 * @param string $title 362 * @param mixed $output 363 * 364 * @return array 365 */ 358 366 protected 359 367 function decorate( $title, $output ) 360 368 { 361 $logs[] = $title; 362 $logs[] = sprintf(__('Post: %1$s - Enzyme: %3$s - Injection: {[%2$s]}'), $this->injection_post->ID, 369 $result = array(); 370 $result[] = $title; 371 $result[] = sprintf(__('Post: %1$s - Enzyme: %3$s - Injection: {[%2$s]}'), $this->injection_post->ID, 363 372 $this->current_sequence, $this->current_enzyme); 364 $logs[] = $output; 365 return $logs; 366 } 367 373 $result[] = $output; 374 return $result; 375 } 376 377 /** 378 * Send the last eval error to the browser. 379 */ 368 380 public 369 381 function echo_last_eval_error() … … 651 663 list($result, $error, $output) = $this->safe_eval($code, $arguments); 652 664 if ( $error ) { 653 $this->console_log(__('ENZYMES ERROR')); 654 $this->console_log(sprintf(__('post: %1$s - enzyme: %3$s - injection: {[%2$s]}'), 655 $this->injection_post->ID, $this->current_sequence, $this->current_enzyme)); 656 $this->console_log($error); 665 $this->console_log($this->decorate(__('ENZYMES ERROR'), $error)); 657 666 $result = null; 658 667 } 659 668 if ( $output ) { 660 $this->console_log(__('ENZYMES OUTPUT')); 661 $this->console_log(sprintf(__('post: %1$s - enzyme: %3$s - injection: {[%2$s]}'), 662 $this->injection_post->ID, $this->current_sequence, $this->current_enzyme)); 663 $this->console_log($output); 669 $this->console_log($this->decorate(__('ENZYMES OUTPUT'), $output)); 664 670 } 665 671 } else { … … 966 972 967 973 /** 968 * Detect the version of the injection post.974 * Detect the engine version of the injection post. 969 975 * 970 976 * @return int 971 977 */ 972 978 protected 973 function default_version()979 function post_engine_version() 974 980 { 975 981 // The injection_post at this point of the execution can be null only in version 3 because … … 981 987 // By looking at these dates we can only assume a post default version, because the user 982 988 // could have forced another default version or another injection version. -- 983 $ post_default = $this->injection_post->post_date_gmt <= EnzymesPlugin::activated_on()989 $result = $this->injection_post->post_date_gmt <= EnzymesPlugin::activated_on() 984 990 ? 2 985 991 : 3; 986 992 // Allow a user to specify a different default version by using an "enzymes" custom field 987 993 // set to 2 or 3. -- 988 $user_default = get_post_meta($this->injection_post->ID, self::FORCE_DEFAULT_VERSION, true); 989 if (! in_array($user_default, array(null, 2, 3))) { 990 $user_default = null; 991 } 992 993 $result = ! is_null($user_default) ? $user_default : $post_default; 994 return $result; 995 } 996 997 /** 998 * Detect the version of an injection with a sequence. 999 * Remove the forced version from the sequence, if any. 994 $forced_version = get_post_meta($this->injection_post->ID, self::FORCE_POST_VERSION, true); 995 if (in_array($forced_version, array(2, 3))) { 996 $result = $forced_version; 997 } 998 999 return $result; 1000 } 1001 1002 /** 1003 * Detect the version of an injection, and remove the forced version from the sequence, if any. 1000 1004 * 1001 1005 * @param string $sequence … … 1004 1008 */ 1005 1009 protected 1006 function sequence_version( &$sequence )1010 function injection_engine_version( &$sequence ) 1007 1011 { 1008 1012 $forced_2_prefix = self::FORCE_INJECTION_VERSION_2 . '|'; 1009 1013 $forced_3_prefix = self::FORCE_INJECTION_VERSION_3 . '|'; 1010 1014 1011 $result = $this-> default_version();1015 $result = $this->post_engine_version(); 1012 1016 switch (true) { 1013 1017 case (0 === strpos($sequence, $forced_2_prefix)): … … 1037 1041 if ( ! $there_are_only_chained_enzymes ) { 1038 1042 $result = '{[' . $could_be_sequence . ']}'; // skip this injection AS IS 1039 } elseif ( $this-> sequence_version($sequence) == 2 ) {1043 } elseif ( $this->injection_engine_version($sequence) == 2 ) { 1040 1044 $result = '{[' . $sequence . ']}'; // skip this injection 1041 1045 // after stripping out the forced version from $sequence, if any
Note: See TracChangeset
for help on using the changeset viewer.