Plugin Directory

Changeset 1078949


Ignore:
Timestamp:
01/30/2015 12:24:09 PM (11 years ago)
Author:
aercolino
Message:

Fixed / improved some code changed in the previous commit.
Improved readability of the special labels to force version 2 or 3 of the engine.
Renamed some identifiers to improve self documentation.
Added a couple of header comments.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • enzymes/trunk/src/Enzymes3.php

    r1077514 r1078949  
    88class Enzymes3
    99{
    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=';
    1515
    1616    /**
     
    334334     * Echo a script HTML tag to write data to the javascript console of the browser.
    335335     *
    336      * @param mixed $logs
    337      */
    338     protected
    339     function console_log( $logs )
     336     * @param array $logs
     337     */
     338    protected
     339    function console_log( array $logs )
    340340    {
    341341        if ( count($logs) == 0 ) {
     
    356356    protected $has_eval_recovered;
    357357
     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     */
    358366    protected
    359367    function decorate( $title, $output )
    360368    {
    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,
    363372                $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     */
    368380    public
    369381    function echo_last_eval_error()
     
    651663            list($result, $error, $output) = $this->safe_eval($code, $arguments);
    652664            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));
    657666                $result = null;
    658667            }
    659668            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));
    664670            }
    665671        } else {
     
    966972
    967973    /**
    968      * Detect the version of the injection post.
     974     * Detect the engine version of the injection post.
    969975     *
    970976     * @return int
    971977     */
    972978    protected
    973     function default_version()
     979    function post_engine_version()
    974980    {
    975981        // The injection_post at this point of the execution can be null only in version 3 because
     
    981987        // By looking at these dates we can only assume a post default version, because the user
    982988        // 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()
    984990                ? 2
    985991                : 3;
    986992        // Allow a user to specify a different default version by using an "enzymes" custom field
    987993        // 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.
    10001004     *
    10011005     * @param string $sequence
     
    10041008     */
    10051009    protected
    1006     function sequence_version( &$sequence )
     1010    function injection_engine_version( &$sequence )
    10071011    {
    10081012        $forced_2_prefix = self::FORCE_INJECTION_VERSION_2 . '|';
    10091013        $forced_3_prefix = self::FORCE_INJECTION_VERSION_3 . '|';
    10101014
    1011         $result = $this->default_version();
     1015        $result = $this->post_engine_version();
    10121016        switch (true) {
    10131017            case (0 === strpos($sequence, $forced_2_prefix)):
     
    10371041        if ( ! $there_are_only_chained_enzymes ) {
    10381042            $result = '{[' . $could_be_sequence . ']}';  // skip this injection AS IS
    1039         } elseif ( $this->sequence_version($sequence) == 2 ) {
     1043        } elseif ( $this->injection_engine_version($sequence) == 2 ) {
    10401044            $result = '{[' . $sequence . ']}';  // skip this injection
    10411045                                                // after stripping out the forced version from $sequence, if any
Note: See TracChangeset for help on using the changeset viewer.