WordPress.org

Plugin Directory

Changeset 1535401


Ignore:
Timestamp:
11/17/16 02:48:27 (3 months ago)
Author:
hideokamoto
Message:

update

Location:
mauticommerce/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • mauticommerce/trunk/inc/class.admin.php

    r1392590 r1535401  
    112112            $this->mauticommece_settings['form_id'] = ''; 
    113113        } 
    114         echo "<input type='text' name='mauticommece_settings[form_id]' value='". $this->mauticommece_settings['form_id']. "'>"; 
     114        echo "<input type='text' name='mauticommece_settings[form_id]' value='" . $this->mauticommece_settings['form_id'] . "'>"; 
    115115    } 
    116116 
     
    124124            $this->mauticommece_settings['url'] = ''; 
    125125        } 
    126         echo "<input type='url' name='mauticommece_settings[url]' value='". $this->mauticommece_settings['url']. "' style='width:100%;'>"; 
     126        echo "<input type='url' name='mauticommece_settings[url]' value='" . $this->mauticommece_settings['url'] . "' style='width:100%;'>"; 
    127127    } 
    128128 
  • mauticommerce/trunk/inc/class.order.php

    r1424450 r1535401  
    3737    } 
    3838 
     39    /** 
     40     * Subscribe order information to Mautic 
     41     * 
     42     * @param string $order_id Order 
     43     * @param string $status post status (default:'new') 
     44     * @param string $new_status new post status (default:'pending') 
     45     * @access public 
     46     * @since 0.0.1 
     47     **/ 
    3948    public function subscribe_to_mautic( $order_id, $status = 'new', $new_status = 'pending' ) { 
    4049        $order = wc_get_order( $order_id ); 
     
    4352    } 
    4453 
    45     private function _create_query( $order ) { 
     54    /** 
     55     * create query to send Mautic 
     56     * 
     57     * @param WC_Order $order WooCommerce order object 
     58     * @since 0.0.1 
     59     * @access private 
     60     * @return array $query posted mautic query 
     61     **/ 
     62    private function _create_query( WC_Order $order ) { 
    4663        $query = array( 
    4764            'address1' => $order->billing_address_1, 
     
    5875            'order_id' => $order->id, 
    5976        ); 
     77 
     78        /** 
     79         * Filter the query that customize Mautic query 
     80         * 
     81         * @since 0.0.1 
     82         * @param $query default mautic query 
     83         * @param WC_Order $order WooCommerce order object 
     84         **/ 
    6085        return apply_filters( 'mauticommerce_query_mapping', $query, $order ); 
    6186    } 
    6287 
     88    /** 
     89     * Get country name 
     90     * 
     91     * @since 0.0.1 
     92     * @access private 
     93     * @param string $country_code 
     94     * @return string $country_name | Exception 
     95     * @ 
     96     **/ 
    6397    private function _get_country_name( $country_code ) { 
    64         $countries = wp_remote_get( path_join( Mauticommerce__URL, 'inc/assets/json/country.json' ) ); 
     98        $countries = wp_remote_get( path_join( MAUTICOMMERCE_URL, 'inc/assets/json/country.json' ) ); 
    6599        try { 
    66  
    67  
    68100            if ( is_wp_error( $countries ) ) { 
    69101                throw new Exception( 'invalid json data.' ); 
     
    76108            return $country_name; 
    77109        } catch ( Exception $e ) { 
    78             $msg = "Mauticommerce Error:". $e->getMessage(); 
     110            $msg = 'Mauticommerce Error:' . $e->getMessage(); 
    79111            error_log( $msg ); 
    80             $WC_Country = new WC_Countries(); 
    81             return $WC_Country->get_countries()[$country_code]; 
    82         } 
    83     } 
    84  
     112            $wc_country = new WC_Countries(); 
     113            return $wc_country->get_countries()[ $country_code ]; 
     114        } 
     115    } 
     116 
     117    /** 
     118     * Get state name 
     119     * 
     120     * @since 0.0.1 
     121     * @access private 
     122     * @param string $country_code country code 
     123     * @param string $state_code state code 
     124     * @return string | Exception 
     125     **/ 
    85126    private function _get_states_name( $country_code, $state_code ) { 
    86         $states = wp_remote_get( path_join( Mauticommerce__URL, 'inc/assets/json/states.json' ) ); 
     127        $states = wp_remote_get( path_join( MAUTICOMMERCE_URL, 'inc/assets/json/states.json' ) ); 
    87128        try { 
    88129            if ( is_wp_error( $states ) ) { 
     
    96137            return $state_name; 
    97138        } catch ( Exception $e ) { 
    98             $msg = "Mauticommerce Error:". $e->getMessage(); 
     139            $msg = 'Mauticommerce Error:' . $e->getMessage(); 
    99140            error_log( $msg ); 
    100             $WC_Country = new WC_Countries(); 
    101             return $WC_Country->get_states( $country_code )[ $state_code ]; 
    102         } 
    103     } 
    104  
     141            $wc_country = new WC_Countries(); 
     142            return $wc_country->get_states( $country_code )[ $state_code ]; 
     143        } 
     144    } 
     145 
     146    /** 
     147     * Subscribe to Mautic 
     148     * 
     149     * @param array $query Posted mautic query 
     150     * @access private 
     151     * @since 0.0.1 
     152     **/ 
    105153    private function _subscribe( $query ) { 
    106154        $ip = $this->_get_ip(); 
     
    124172                ), 
    125173                'body' => $data, 
    126                 'cookies' => array() 
     174                'cookies' => array(), 
    127175            ) 
    128176        ); 
     
    133181    } 
    134182 
     183    /** 
     184     * get ip 
     185     * 
     186     * @access private 
     187     * @return string 
     188     * @since 0.0.1 
     189     **/ 
    135190    private function _get_ip() { 
    136191        $ip_list = [ 
     192            'REMOTE_ADDR', 
    137193            'HTTP_CLIENT_IP', 
    138194            'HTTP_X_FORWARDED_FOR', 
     
    140196            'HTTP_X_CLUSTER_CLIENT_IP', 
    141197            'HTTP_FORWARDED_FOR', 
    142             'HTTP_FORWARDED' 
     198            'HTTP_FORWARDED', 
    143199        ]; 
    144200        foreach ( $ip_list as $key ) { 
     
    148204            $ip = esc_attr( $_SERVER[ $key ] ); 
    149205            if ( ! strpos( $ip, ',' ) ) { 
    150                 $ips =  explode( ',', $ip ); 
     206                $ips = explode( ',', $ip ); 
    151207                foreach ( $ips as &$val ) { 
    152208                    $val = trim( $val ); 
    153209                } 
    154                 $ip = end ( $ips ); 
     210                $ip = end( $ips ); 
    155211            } 
    156212            $ip = trim( $ip ); 
  • mauticommerce/trunk/mauticommerce.php

    r1424450 r1535401  
    22/** 
    33 * Plugin Name: Mauticommerce 
    4  * Version: 0.1.0 
     4 * Version: 0.1.1 
    55 * Descrtiption: Senf Woo Wommerce customer information to Mautic Form. 
    66 * Author: hideokamoto 
     
    1212 */ 
    1313if ( ! mautic_is_activate_woocommerce() ) { 
    14     $Mauticommerce_Err = new Mauticommerce_Err(); 
    15     $msg = array( 
    16         __( 'MautiCommerce Need "WooCommerce" Plugin.' , 'mauticommerce' ), 
    17         __( 'Please Activate it.' , 'mauticommerce' ), 
    18     ); 
    19     $e = new WP_Error( 'MautiCommerce Activation Error', $msg ); 
    20     $Mauticommerce_Err->show_error_message( $e ); 
    21     add_action( 'admin_notices', array( $Mauticommerce_Err, 'admin_notices' ) ); 
     14    $mauticommerce_err = new Mauticommerce_Err(); 
     15    $mauticommerce_err->activation_fail(); 
    2216    return false; 
    2317} 
    24 define( 'Mauticommerce__PATH', plugin_dir_path( __FILE__ ) ); 
    25 define( 'Mauticommerce__URL', plugin_dir_url( __FILE__ ) ); 
    26 define( 'Mauticommerce_ROOT', __FILE__ ); 
     18define( 'MAUTICOMMERCE_PATH', plugin_dir_path( __FILE__ ) ); 
     19define( 'MAUTICOMMERCE_URL', plugin_dir_url( __FILE__ ) ); 
     20define( 'MAUTICOMMERCE_ROOT', __FILE__ ); 
    2721 
    2822require_once 'inc/class.admin.php'; 
    2923require_once 'inc/class.order.php'; 
    3024 
    31 $Mauticommerce = Mauticommerce::get_instance(); 
    32 $Mauticommerce->init(); 
     25$mauticommerce = Mauticommerce::get_instance(); 
     26$mauticommerce->init(); 
    3327 
    3428class Mauticommerce { 
    35     private $Base; 
    3629    private static $instance; 
    3730    private static $text_domain; 
     
    5851 
    5952        if ( ! $text_domain ) { 
    60             $data = get_file_data( Mauticommerce_ROOT , array( 'text_domain' => 'Text Domain' ) ); 
     53            $data = get_file_data( MAUTICOMMERCE_ROOT , array( 'text_domain' => 'Text Domain' ) ); 
    6154            $text_domain = $data['text_domain']; 
    6255        } 
     
    6962        add_action( 'admin_init', array( $admin, 'settings_init' ) ); 
    7063        $order = Mauticommerce_Order::get_instance(); 
    71         add_action( 'woocommerce_checkout_update_order_meta', array( $order, 'subscribe_to_mautic') ); 
     64        add_action( 'woocommerce_checkout_update_order_meta', array( $order, 'subscribe_to_mautic' ) ); 
    7265    } 
    7366} 
    7467 
    7568class Mauticommerce_Err { 
     69    /** 
     70     * Set Error to fail to Actiavation Plugin 
     71     * 
     72     * @since 0.1.1 
     73     **/ 
     74    public function activation_fail() { 
     75        $msg = array( 
     76            __( 'MautiCommerce Need "WooCommerce" Plugin.' , 'mauticommerce' ), 
     77            __( 'Please Activate it.' , 'mauticommerce' ), 
     78        ); 
     79        $e = new WP_Error( 'MautiCommerce Activation Error', $msg ); 
     80        $this->show_error_message( $e ); 
     81        add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
     82        return $e; 
     83    } 
    7684 
    7785    /** 
     
    8189     **/ 
    8290    public function admin_notices() { 
    83         if ( $messageList = get_transient( 'mautic-admin-errors' ) ) { 
    84             $this->show_notice_html( $messageList ); 
     91        if ( $message_list = get_transient( 'mautic-admin-errors' ) ) { 
     92            $this->show_notice_html( $message_list ); 
    8593        } 
    8694    } 
     
    108116     * @since 0.1.0 
    109117     */ 
    110     public function show_notice_html( $messageList ) { 
    111         foreach ( $messageList as $key => $messages ) { 
     118    public function show_notice_html( $message_list ) { 
     119        foreach ( $message_list as $key => $messages ) { 
    112120            $html  = "<div class='error'><ul>"; 
    113             foreach ( (array)$messages as $key => $message ) { 
     121            foreach ( (array) $messages as $key => $message ) { 
    114122                $html .= "<li>{$message}</li>"; 
    115123            } 
     
    127135 */ 
    128136function mautic_is_activate_woocommerce() { 
    129     $activePlugins = get_option('active_plugins'); 
     137    $active_plugins = get_option( 'active_plugins' ); 
    130138    $plugin = 'woocommerce/woocommerce.php'; 
    131     if ( ! array_search( $plugin, $activePlugins ) && file_exists( WP_PLUGIN_DIR. '/'. $plugin ) ) { 
     139    if ( ! array_search( $plugin, $active_plugins ) && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) ) { 
    132140        return false; 
    133141    } else { 
  • mauticommerce/trunk/readme.txt

    r1424450 r1535401  
    44Requires at least: 4.4.2 
    55Tested up to:4.4.2 
    6 Stable tag: 0.1.0 
     6Stable tag: 0.1.1 
    77License: GPLv2 or later 
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html 
     
    2121Mautic may or may not be installed before the Mauticommerce plugin. 
    2222You will need a functioning Mautic installation and a new Mautic Form for this plugin to work. 
     23 
     24## Document 
     25- [API reference: https://amimoto-ami.github.io/mauticommerce/index.html](https://amimoto-ami.github.io/mauticommerce/index.html) 
    2326 
    2427== Installation == 
     
    7477 
    7578== Changelog == 
     79= 0.1.1 = 
     80* Bug fix 
     81* Create document site 
    7682 
    7783= 0.1.0 = 
     
    8995== Upgrade Notice == 
    9096 
    91 = 0.1.0 = 
    92 * Country & State Mapping for Mautic 
     97= 0.1.1 = 
     98* Bug fix 
     99* Create document site 
Note: See TracChangeset for help on using the changeset viewer.