├── .editorconfig ├── .github ├── ISSUE_TEMPLATE.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .svnignore ├── .travis.yml ├── Gruntfile.js ├── bin ├── install-dependencies.php └── install-wp-tests.sh ├── cf7-mautic.php ├── inc ├── class.admin.php ├── class.cf7-mautic.php ├── class.cf7-surveyor.php ├── class.environment-surveyor.php ├── class.php-surveyor.php └── class.submit.php ├── languages ├── cf7-mautic-extention.pot └── cf7-mautic.pot ├── package.json ├── phpunit.xml.dist ├── readme.txt └── tests ├── Test_CF7_Mautic_CF7_Surveyor.php ├── Test_CF7_Mautic_PHP_Surveyor.php ├── bootstrap.php └── dependencies-array.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | # WordPress Coding Standards 5 | # https://make.wordpress.org/core/handbook/coding-standards/ 6 | 7 | root = true 8 | 9 | [*] 10 | charset = utf-8 11 | end_of_line = lf 12 | insert_final_newline = true 13 | trim_trailing_whitespace = true 14 | indent_style = tab 15 | indent_size = 4 16 | 17 | [{.jshintrc,*.json,*.yml}] 18 | indent_style = space 19 | indent_size = 2 20 | 21 | [{*.txt,wp-config-sample.php}] 22 | end_of_line = crlf 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | What type of report is this: 2 | 3 | | Q | A 4 | | ---| --- 5 | | Bug report? | 6 | | Feature request? | 7 | | Enhancement? | 8 | 9 | ## Description: 10 | The more details the better... 11 | 12 | ## If a bug: 13 | 14 | | Q | A 15 | | --- | --- 16 | | WordPress version | 17 | | PHP version | 18 | 19 | ### Steps to reproduce: 20 | 1. 21 | 2. 22 | 23 | ### Log errors: 24 | 25 | _Please check for related errors in the latest log file (Example: /var/log/php-fpm/www-error.log) and post them here. Be sure to remove sensitive information if applicable._ 26 | 27 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | [//]: # ( Please answer the following questions: ) 2 | 3 | | Q | A 4 | | --- | --- 5 | | Bug fix? | 6 | | New feature? | 7 | | Issues addressed (#s or URLs) | 8 | | BC breaks? | 9 | | Deprecations? | 10 | | Your wordpress.org's username | 11 | 12 | [//]: # ( Note that all new features should have a related user and/or developer documentation PR in their respective repositories. ) 13 | 14 | [//]: # ( Required: ) 15 | #### Description: 16 | 17 | 18 | #### Steps to test this PR: 19 | 1. 20 | 2. 21 | 22 | [//]: # ( As applicable: ) 23 | #### Steps to reproduce the bug: 24 | 1. 25 | 2. 26 | 27 | #### List deprecations along with the new alternative: 28 | 1. 29 | 2. 30 | 31 | #### List backwards compatibility breaks: 32 | 1. 33 | 2. 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | output/ 4 | -------------------------------------------------------------------------------- /.svnignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .editorconfig 3 | .git 4 | .gitignore 5 | .travis.yml 6 | Gruntfile.js 7 | LINGUAS 8 | Makefile 9 | README.md 10 | _site 11 | bin 12 | composer.json 13 | composer.lock 14 | gulpfile.js 15 | node_modules 16 | npm-debug.log 17 | package.json 18 | phpunit.xml 19 | phpunit.xml.dist 20 | tests 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | notifications: 4 | email: 5 | on_success: never 6 | on_failure: change 7 | 8 | branches: 9 | only: 10 | - master 11 | 12 | php: 13 | - 5.3 14 | - 5.6 15 | 16 | env: 17 | - WP_VERSION=latest WP_MULTISITE=0 18 | - WP_VERSION=3.0.1 WP_MULTISITE=0 19 | - WP_VERSION=3.4 WP_MULTISITE=0 20 | 21 | matrix: 22 | include: 23 | - php: 5.3 24 | env: WP_VERSION=latest WP_MULTISITE=1 25 | 26 | before_script: 27 | - bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION 28 | 29 | script: phpunit 30 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function( grunt ) { 2 | 3 | 'use strict'; 4 | var banner = '/**\n * <%= pkg.homepage %>\n * Copyright (c) <%= grunt.template.today("yyyy") %>\n * This file is generated automatically. Do not edit.\n */\n'; 5 | // Project configuration 6 | grunt.initConfig( { 7 | 8 | pkg: grunt.file.readJSON( 'package.json' ), 9 | 10 | makepot: { 11 | target: { 12 | options: { 13 | domainPath: '/languages', 14 | mainFile: 'cf7-mautic.php', 15 | potFilename: 'cf7-mautic.pot', 16 | potHeaders: { 17 | poedit: true, 18 | 'x-poedit-keywordslist': true 19 | }, 20 | type: 'wp-plugin', 21 | updateTimestamp: true 22 | } 23 | } 24 | }, 25 | } ); 26 | 27 | grunt.loadNpmTasks( 'grunt-wp-i18n' ); 28 | grunt.registerTask( 'i18n', [ 'makepot'] ); 29 | 30 | grunt.util.linefeed = '\n'; 31 | 32 | }; 33 | -------------------------------------------------------------------------------- /bin/install-dependencies.php: -------------------------------------------------------------------------------- 1 | $dependency ) { 17 | if ( ! is_dir( $plugins_dir . $k ) ) { 18 | if ( download_plugin( $k, $dependency ) ) { 19 | echo "Downloaded $k\n"; 20 | } else { 21 | echo "FAILED to download $k\n"; 22 | } 23 | } else { 24 | echo "DIRECTORY EXISTS, skipped $plugins_dir$k\n"; 25 | } 26 | } 27 | } 28 | 29 | download_plugins(); 30 | -------------------------------------------------------------------------------- /bin/install-wp-tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ $# -lt 3 ]; then 4 | echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" 5 | exit 1 6 | fi 7 | 8 | DB_NAME=$1 9 | DB_USER=$2 10 | DB_PASS=$3 11 | DB_HOST=${4-localhost} 12 | WP_VERSION=${5-latest} 13 | SKIP_DB_CREATE=${6-false} 14 | 15 | WP_TESTS_DIR=${WP_TESTS_DIR-/tmp/wordpress-tests-lib} 16 | WP_CORE_DIR=${WP_CORE_DIR-/tmp/wordpress/} 17 | 18 | download() { 19 | if [ `which curl` ]; then 20 | curl -s "$1" > "$2"; 21 | elif [ `which wget` ]; then 22 | wget -nv -O "$2" "$1" 23 | fi 24 | } 25 | 26 | if [[ $WP_VERSION =~ [0-9]+\.[0-9]+(\.[0-9]+)? ]]; then 27 | WP_TESTS_TAG="tags/$WP_VERSION" 28 | elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then 29 | WP_TESTS_TAG="trunk" 30 | else 31 | # http serves a single offer, whereas https serves multiple. we only want one 32 | download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json 33 | grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json 34 | LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') 35 | if [[ -z "$LATEST_VERSION" ]]; then 36 | echo "Latest WordPress version could not be found" 37 | exit 1 38 | fi 39 | WP_TESTS_TAG="tags/$LATEST_VERSION" 40 | fi 41 | 42 | set -ex 43 | 44 | install_wp() { 45 | 46 | if [ -d $WP_CORE_DIR ]; then 47 | return; 48 | fi 49 | 50 | mkdir -p $WP_CORE_DIR 51 | 52 | if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then 53 | mkdir -p /tmp/wordpress-nightly 54 | download https://wordpress.org/nightly-builds/wordpress-latest.zip /tmp/wordpress-nightly/wordpress-nightly.zip 55 | unzip -q /tmp/wordpress-nightly/wordpress-nightly.zip -d /tmp/wordpress-nightly/ 56 | mv /tmp/wordpress-nightly/wordpress/* $WP_CORE_DIR 57 | else 58 | if [ $WP_VERSION == 'latest' ]; then 59 | local ARCHIVE_NAME='latest' 60 | else 61 | local ARCHIVE_NAME="wordpress-$WP_VERSION" 62 | fi 63 | download https://wordpress.org/${ARCHIVE_NAME}.tar.gz /tmp/wordpress.tar.gz 64 | tar --strip-components=1 -zxmf /tmp/wordpress.tar.gz -C $WP_CORE_DIR 65 | fi 66 | 67 | download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php 68 | } 69 | 70 | install_test_suite() { 71 | # portable in-place argument for both GNU sed and Mac OSX sed 72 | if [[ $(uname -s) == 'Darwin' ]]; then 73 | local ioption='-i .bak' 74 | else 75 | local ioption='-i' 76 | fi 77 | 78 | # set up testing suite if it doesn't yet exist 79 | if [ ! -d $WP_TESTS_DIR ]; then 80 | # set up testing suite 81 | mkdir -p $WP_TESTS_DIR 82 | svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes 83 | svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data 84 | fi 85 | 86 | if [ ! -f wp-tests-config.php ]; then 87 | download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php 88 | # remove all forward slashes in the end 89 | WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") 90 | sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php 91 | sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php 92 | sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php 93 | sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php 94 | sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php 95 | fi 96 | 97 | } 98 | 99 | install_db() { 100 | 101 | if [ ${SKIP_DB_CREATE} = "true" ]; then 102 | return 0 103 | fi 104 | 105 | # parse DB_HOST for port or socket references 106 | local PARTS=(${DB_HOST//\:/ }) 107 | local DB_HOSTNAME=${PARTS[0]}; 108 | local DB_SOCK_OR_PORT=${PARTS[1]}; 109 | local EXTRA="" 110 | 111 | if ! [ -z $DB_HOSTNAME ] ; then 112 | if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then 113 | EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" 114 | elif ! [ -z $DB_SOCK_OR_PORT ] ; then 115 | EXTRA=" --socket=$DB_SOCK_OR_PORT" 116 | elif ! [ -z $DB_HOSTNAME ] ; then 117 | EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" 118 | fi 119 | fi 120 | 121 | # create database 122 | mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA 123 | } 124 | 125 | install_wp 126 | install_test_suite 127 | install_db 128 | -------------------------------------------------------------------------------- /cf7-mautic.php: -------------------------------------------------------------------------------- 1 | 'Support PHP Version', 20 | ) ); 21 | 22 | define( 'CF7_MAUTIC_ROOT', __FILE__ ); 23 | define( 'CF7_MAUTIC_REQUIRE_PHP_VERSION', $cf7_mautic_plugin_info['minimum_php'] ); 24 | 25 | 26 | require_once 'inc/class.environment-surveyor.php'; 27 | require_once 'inc/class.php-surveyor.php'; 28 | require_once 'inc/class.cf7-surveyor.php'; 29 | 30 | 31 | /** 32 | * Initialize. 33 | */ 34 | function cf7_mautic_init() { 35 | require_once 'inc/class.cf7-mautic.php'; 36 | require_once 'inc/class.admin.php'; 37 | require_once 'inc/class.submit.php'; 38 | $cf7_mautic = CF7_Mautic::get_instance(); 39 | $cf7_mautic->init(); 40 | } 41 | 42 | /** 43 | * Check Environments. 44 | * 45 | * @return bool 46 | */ 47 | function cf7_mautic_check_environments() { 48 | $php_checker = new CF7_Mautic_PHP_Surveyor(); 49 | $php_checker->register_notice(); 50 | 51 | $cf7_checker = new CF7_Mautic_CF7_Surveyor(); 52 | $cf7_checker->register_notice(); 53 | 54 | if ( defined( 'WPCF7_PLUGIN' ) ) { 55 | $cf7_checker->set_cf7_plugin_basename( WPCF7_PLUGIN ); 56 | } 57 | 58 | if ( ! is_wp_error( $php_checker->check() ) and ! is_wp_error( $cf7_checker->check() ) ) { 59 | return true; 60 | } 61 | 62 | return false; 63 | } 64 | 65 | /** 66 | * Bootstrap. 67 | */ 68 | function cf7_mautic_bootstrap() { 69 | 70 | if ( cf7_mautic_check_environments() ) { 71 | cf7_mautic_init(); 72 | } 73 | } 74 | 75 | /** 76 | * Check on activation. 77 | */ 78 | function cf7_mautic_check_on_activation() { 79 | 80 | if ( ! cf7_mautic_check_environments() ) { 81 | deactivate_plugins( plugin_basename( __FILE__ ) ); 82 | wp_die( 'Opps, CF7 Mautic Extention require PHP 5.6 or higher and contact form 7.' ); 83 | } 84 | } 85 | 86 | add_action( 'plugins_loaded', 'cf7_mautic_bootstrap' ); 87 | 88 | register_activation_hook( __FILE__, 'cf7_mautic_check_on_activation' ); 89 | -------------------------------------------------------------------------------- /inc/class.admin.php: -------------------------------------------------------------------------------- 1 | cf7_mautic_settings = get_option( 'cf7_mautic_settings' ); 50 | } 51 | 52 | /** 53 | * Get Instance Class 54 | * 55 | * @return CF7_Mautic_Admin 56 | * @since 0.0.1 57 | */ 58 | public static function get_instance() { 59 | if ( ! isset( self::$instance ) ) { 60 | $c = __CLASS__; 61 | self::$instance = new $c(); 62 | } 63 | return self::$instance; 64 | } 65 | 66 | 67 | /** 68 | * Routing function 69 | * 70 | * @since 0.0.1 71 | */ 72 | public function settings_init() { 73 | $this->_register_admin_panels(); 74 | if ( empty( $_POST ) ) { 75 | return; 76 | } 77 | } 78 | 79 | /** 80 | * Register admin setting field 81 | * 82 | * @since 0.0.1 83 | */ 84 | private function _register_admin_panels() { 85 | register_setting( 'CF7_Mautic', 'cf7_mautic_settings' ); 86 | add_settings_section( 87 | 'cf7_mautic_RelatedScore_settings', 88 | __( 'Settings', self::$text_domain ), 89 | array( $this, 'cf7_mautic_settings_url_section_callback' ), 90 | 'CF7_Mautic' 91 | ); 92 | add_settings_field( 93 | 'url', 94 | __( 'Mautic URL', self::$text_domain ), 95 | array( $this, 'mautic_url_render' ), 96 | 'CF7_Mautic', 97 | 'cf7_mautic_RelatedScore_settings' 98 | ); 99 | add_settings_field( 100 | 'form_id', 101 | __( 'Mautic Form ID', self::$text_domain ), 102 | array( $this, 'mautic_form_id_render' ), 103 | 'CF7_Mautic', 104 | 'cf7_mautic_RelatedScore_settings' 105 | ); 106 | } 107 | 108 | /** 109 | * echo input field( Mautic Form ID) 110 | * 111 | * @since 0.0.1 112 | */ 113 | public function mautic_form_id_render() { 114 | if ( ! isset( $this->cf7_mautic_settings['form_id'] ) ) { 115 | $this->cf7_mautic_settings['form_id'] = ''; 116 | } 117 | $cf7_args = array( 118 | 'posts_per_page' => -1, 119 | 'orderby' => 'title', 120 | 'order' => 'ASC', 121 | 'offset' => 0, 122 | ); 123 | $forms = WPCF7_ContactForm::find( $cf7_args ); 124 | $html = ''; 125 | $html .= ''; 126 | $html .= ''; 127 | $html .= ''; 128 | $html .= ''; 130 | $html .= ''; 132 | $html .= ''; 133 | for ( $i = 0 ; $i < 5; $i++ ) { 134 | $html .= ''; 135 | $html .= ''; 136 | $html .= ''; 137 | if ( isset( $this->cf7_mautic_settings['form_id'] ) && isset( $this->cf7_mautic_settings['form_id'][ $i ] ) ) { 138 | $val = $this->cf7_mautic_settings['form_id'][ $i ]; 139 | } else { 140 | $val = ''; 141 | } 142 | $html .= ""; 143 | $html .= ''; 144 | } 145 | $html .= '
'. __( 'No.', self::$text_domain ). ''. __( 'Form Name', self::$text_domain ). '
'; 129 | $html .= __( '( Contact Form 7 )', self::$text_domain ). '
'. __( 'Form ID', self::$text_domain ). '
'; 131 | $html .= __( '( Mautic )', self::$text_domain ). '
'. __( 'Mapping-', self::$text_domain ). $i. ''. $this->_get_cf7_form_select_box ( $forms, $i ). '
'; 146 | echo $html; 147 | } 148 | 149 | /** 150 | * get select box html 151 | * 152 | * @access private 153 | * @return string 154 | * @param array $forms CF7 Form Object 155 | * @param int $i row number 156 | * @since 0.0.1 157 | */ 158 | private function _get_cf7_form_select_box ( $forms, $i ) { 159 | $html = ''; 160 | 161 | if ( isset( $this->cf7_mautic_settings['cf7_id'] ) && isset( $this->cf7_mautic_settings['cf7_id'][ $i ] ) ) { 162 | $selected = $this->cf7_mautic_settings['cf7_id'][ $i ]; 163 | } else { 164 | $selected = false; 165 | } 166 | $html .= "'; 173 | return $html; 174 | } 175 | 176 | /** 177 | * echo input field( Mautic URL) 178 | * 179 | * @since 0.0.1 180 | */ 181 | public function mautic_url_render() { 182 | if ( ! isset( $this->cf7_mautic_settings['url'] ) ) { 183 | $this->cf7_mautic_settings['url'] = ''; 184 | } 185 | echo ""; 186 | } 187 | 188 | /** 189 | * echo Search Score Field Dcf7_mauticiption 190 | * 191 | * @since 0.0.1 192 | */ 193 | public function cf7_mautic_settings_url_section_callback() { 194 | echo __( 'Set Mautic Information.', self::$text_domain ); 195 | } 196 | 197 | /** 198 | * echo form area 199 | * 200 | * @since 0.0.1 201 | */ 202 | public function cf7_mautic_options() { 203 | echo '

CF7 Mautic

'; 204 | echo "
"; 205 | settings_fields( 'CF7_Mautic' ); 206 | do_settings_sections( 'CF7_Mautic' ); 207 | submit_button(); 208 | echo '
'; 209 | } 210 | 211 | /** 212 | * Register Admin Option Page 213 | * 214 | * @since 0.0.1 215 | */ 216 | public function add_admin_menu() { 217 | add_options_page( 'CF7 Mautic', 'CF7 Mautic', 'manage_options', 'cf7_mautic', array( $this, 'cf7_mautic_options' ) ); 218 | } 219 | 220 | } 221 | -------------------------------------------------------------------------------- /inc/class.cf7-mautic.php: -------------------------------------------------------------------------------- 1 | 'Text Domain' ) ); 47 | $text_domain = $data['text_domain']; 48 | } 49 | return $text_domain; 50 | } 51 | 52 | /** 53 | * Initilize Plugin Settings 54 | * 55 | * @since 0.0.1 56 | */ 57 | public function init() { 58 | $admin = CF7_Mautic_Admin::get_instance(); 59 | add_action( 'admin_menu', array( $admin, 'add_admin_menu' ) ); 60 | add_action( 'admin_init', array( $admin, 'settings_init' ) ); 61 | $submit = CF7_Mautic_Submit::get_instance(); 62 | add_filter( 'wpcf7_before_send_mail', array( $submit, 'send_cf7_to_mautic' ) ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /inc/class.cf7-surveyor.php: -------------------------------------------------------------------------------- 1 | cf7_plugin_basename ) ) { 27 | return true; 28 | } 29 | 30 | $notice = __( 31 | 'Oops, this plugin need Contact Form 7 Plugin. Please install & activate it first.', 32 | 'cf7-mautic-extention' 33 | ); 34 | 35 | return new WP_Error( 'cf7_mautic_check_cf7_installed', $notice ); 36 | } 37 | 38 | /** 39 | * @param string $cf7_plugin_basename Contact Form 7 basename. 40 | */ 41 | public function set_cf7_plugin_basename( $cf7_plugin_basename ) { 42 | $this->cf7_plugin_basename = $cf7_plugin_basename; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /inc/class.environment-surveyor.php: -------------------------------------------------------------------------------- 1 | check(); 32 | if ( is_wp_error( $result ) ) { 33 | $message = sprintf( 34 | __( '[CF7 Mautic Extention] %s', 'cf7-mautic-extention' ), 35 | esc_html( $result->get_error_message() ) 36 | ); 37 | 38 | echo sprintf( '

%s

', esc_html( $message ) ); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /inc/class.php-surveyor.php: -------------------------------------------------------------------------------- 1 | set_support_php_version( CF7_MAUTIC_REQUIRE_PHP_VERSION ); 33 | } 34 | 35 | $this->set_current_php_version( phpversion() ); 36 | } 37 | 38 | /** 39 | * Setter for current_php_version. 40 | * 41 | * @param string $current_php_version php version. 42 | */ 43 | public function set_current_php_version( $current_php_version ) { 44 | $this->current_php_version = $current_php_version; 45 | } 46 | 47 | 48 | /** 49 | * Setter for support_php_version. 50 | * 51 | * @param string $support_php_version php version. 52 | */ 53 | public function set_support_php_version( $support_php_version ) { 54 | $this->support_php_version = $support_php_version; 55 | } 56 | 57 | /** 58 | * Check version. 59 | * 60 | * @return bool|WP_Error 61 | */ 62 | public function check() { 63 | if ( version_compare( $this->current_php_version, $this->support_php_version ) >= 0 ) { 64 | return true; 65 | } 66 | 67 | $notice = sprintf( 68 | __( 69 | 'Oops, this plugin will soon require PHP %1$s or higher. Your PHP version is %2$s', 70 | 'cf7-mautic-extention' 71 | ), 72 | CF7_MAUTIC_REQUIRE_PHP_VERSION, 73 | $this->current_php_version 74 | ); 75 | 76 | return new WP_Error( 'cf7_mautic_check_php_version', $notice ); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /inc/class.submit.php: -------------------------------------------------------------------------------- 1 | _create_query(); 62 | if ( $query ) { 63 | $this->_subscribe( $query ); 64 | } 65 | return $cf7; 66 | } 67 | 68 | /** 69 | * Create query form Contact Form 7's post params 70 | * 71 | * @return array 72 | * @since 0.0.1 73 | */ 74 | private function _create_query() { 75 | $query = array(); 76 | if ( $submission = WPCF7_Submission::get_instance() ) { 77 | $query = $submission->get_posted_data(); 78 | } 79 | return apply_filters( 'CF7_Mautic_query_mapping', $query ); 80 | } 81 | 82 | /** 83 | * Add Mautic Form ID 84 | * 85 | * @param array $query POST query 86 | * @return array 87 | * @since 0.0.1 88 | */ 89 | private function _add_mautic_form_id( $query ) { 90 | $cf7_form_id = $query['_wpcf7']; 91 | $settings = get_option( 'cf7_mautic_settings' ); 92 | $key = array_search( $cf7_form_id, $settings['cf7_id'] ); 93 | $query['formId'] = $settings['form_id'][ $key ]; 94 | return $query; 95 | } 96 | 97 | /** 98 | * POST to Mautic 99 | * 100 | * @param array $query POST query 101 | * @since 0.0.1 102 | */ 103 | private function _subscribe( $query ) { 104 | $ip = $this->_get_ip(); 105 | if ( ! isset( $query['return'] ) ) { 106 | $query['return'] = get_home_url(); 107 | } 108 | $settings = get_option( 'cf7_mautic_settings' ); 109 | $query = $this->_add_mautic_form_id( $query ); 110 | $query = $this->_remove_hyphen( $query ); 111 | $data = array( 112 | 'mauticform' => $query, 113 | ); 114 | $url = path_join( $settings['url'], "form/submit?formId={$query['formId']}" ); 115 | $response = wp_remote_post( 116 | $url, 117 | array( 118 | 'method' => 'POST', 119 | 'timeout' => 45, 120 | 'headers' => array( 121 | 'X-Forwarded-For' => $ip, 122 | ), 123 | 'body' => $data, 124 | 'cookies' => array() 125 | ) 126 | ); 127 | if ( is_wp_error( $response ) ) { 128 | $error_message = $response->get_error_message(); 129 | error_log( "CF7_Mautic Error: $error_message" ); 130 | error_log( " posted url: $url" ); 131 | } 132 | } 133 | 134 | /** 135 | * Remove hyphen to fields 136 | * 137 | * @return string 138 | * @since 0.0.3 139 | */ 140 | private function _remove_hyphen( $queries ) { 141 | $return = array(); 142 | foreach ( $queries as $label => $value ) { 143 | $label = str_replace( '-', '', $label ); 144 | $return[ $label ] = $value; 145 | } 146 | return $return; 147 | } 148 | 149 | /** 150 | * Get User's IP 151 | * 152 | * @return string 153 | * @since 0.0.1 154 | */ 155 | private function _get_ip() { 156 | $ip_list = [ 157 | 'REMOTE_ADDR', 158 | 'HTTP_CLIENT_IP', 159 | 'HTTP_X_FORWARDED_FOR', 160 | 'HTTP_X_FORWARDED', 161 | 'HTTP_X_CLUSTER_CLIENT_IP', 162 | 'HTTP_FORWARDED_FOR', 163 | 'HTTP_FORWARDED' 164 | ]; 165 | foreach ( $ip_list as $key ) { 166 | if ( ! isset( $_SERVER[ $key ] ) ) { 167 | continue; 168 | } 169 | $ip = esc_attr( $_SERVER[ $key ] ); 170 | if ( ! strpos( $ip, ',' ) ) { 171 | $ips = explode( ',', $ip ); 172 | foreach ( $ips as &$val ) { 173 | $val = trim( $val ); 174 | } 175 | $ip = end ( $ips ); 176 | } 177 | $ip = trim( $ip ); 178 | break; 179 | } 180 | return $ip; 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /languages/cf7-mautic-extention.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 2 | # This file is distributed under the same license as the package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: \n" 6 | "Report-Msgid-Bugs-To: " 7 | "https://wordpress.org/support/plugin/cf7-mautic-extention\n" 8 | "POT-Creation-Date: 2016-04-14 10:29:29+00:00\n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=utf-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "X-Generator: grunt-wp-i18n 0.5.4\n" 16 | "X-Poedit-KeywordsList: " 17 | "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_" 18 | "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n" 19 | "Language: en\n" 20 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 21 | "X-Poedit-Country: United States\n" 22 | "X-Poedit-SourceCharset: UTF-8\n" 23 | "X-Poedit-Basepath: ../\n" 24 | "X-Poedit-SearchPath-0: .\n" 25 | "X-Poedit-Bookmarks: \n" 26 | "X-Textdomain-Support: yes\n" 27 | 28 | #: inc/class.admin.php:85 29 | msgid "Settings" 30 | msgstr "" 31 | 32 | #: inc/class.admin.php:91 33 | msgid "Mautic URL" 34 | msgstr "" 35 | 36 | #: inc/class.admin.php:98 37 | msgid "Mautic Form ID" 38 | msgstr "" 39 | 40 | #: inc/class.admin.php:124 41 | msgid "No." 42 | msgstr "" 43 | 44 | #: inc/class.admin.php:125 45 | msgid "Form Name" 46 | msgstr "" 47 | 48 | #: inc/class.admin.php:126 49 | msgid "( Contact Form 7 )" 50 | msgstr "" 51 | 52 | #: inc/class.admin.php:127 53 | msgid "Form ID" 54 | msgstr "" 55 | 56 | #: inc/class.admin.php:128 57 | msgid "( Mautic )" 58 | msgstr "" 59 | 60 | #: inc/class.admin.php:132 61 | msgid "Mapping-" 62 | msgstr "" 63 | 64 | #: inc/class.admin.php:164 65 | msgid "none" 66 | msgstr "" 67 | 68 | #: inc/class.admin.php:191 69 | msgid "Set Mautic Information." 70 | msgstr "" -------------------------------------------------------------------------------- /languages/cf7-mautic.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2016 hideokamoto 2 | # This file is distributed under the same license as the CF7 Mautic Extention package. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: CF7 Mautic Extention 0.0.1\n" 6 | "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/cf7-mautic\n" 7 | "POT-Creation-Date: 2016-04-14 10:30:01+00:00\n" 8 | "MIME-Version: 1.0\n" 9 | "Content-Type: text/plain; charset=utf-8\n" 10 | "Content-Transfer-Encoding: 8bit\n" 11 | "PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n" 12 | "Last-Translator: FULL NAME \n" 13 | "Language-Team: LANGUAGE \n" 14 | "X-Generator: grunt-wp-i18n 0.5.4\n" 15 | "X-Poedit-KeywordsList: " 16 | "__;_e;_x:1,2c;_ex:1,2c;_n:1,2;_nx:1,2,4c;_n_noop:1,2;_nx_noop:1,2,3c;esc_" 17 | "attr__;esc_html__;esc_attr_e;esc_html_e;esc_attr_x:1,2c;esc_html_x:1,2c;\n" 18 | "Language: en\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | "X-Poedit-Country: United States\n" 21 | "X-Poedit-SourceCharset: UTF-8\n" 22 | "X-Poedit-Basepath: ../\n" 23 | "X-Poedit-SearchPath-0: .\n" 24 | "X-Poedit-Bookmarks: \n" 25 | "X-Textdomain-Support: yes\n" 26 | 27 | #: inc/class.admin.php:85 28 | msgid "Settings" 29 | msgstr "" 30 | 31 | #: inc/class.admin.php:91 32 | msgid "Mautic URL" 33 | msgstr "" 34 | 35 | #: inc/class.admin.php:98 36 | msgid "Mautic Form ID" 37 | msgstr "" 38 | 39 | #: inc/class.admin.php:124 40 | msgid "No." 41 | msgstr "" 42 | 43 | #: inc/class.admin.php:125 44 | msgid "Form Name" 45 | msgstr "" 46 | 47 | #: inc/class.admin.php:126 48 | msgid "( Contact Form 7 )" 49 | msgstr "" 50 | 51 | #: inc/class.admin.php:127 52 | msgid "Form ID" 53 | msgstr "" 54 | 55 | #: inc/class.admin.php:128 56 | msgid "( Mautic )" 57 | msgstr "" 58 | 59 | #: inc/class.admin.php:132 60 | msgid "Mapping-" 61 | msgstr "" 62 | 63 | #: inc/class.admin.php:164 64 | msgid "none" 65 | msgstr "" 66 | 67 | #: inc/class.admin.php:191 68 | msgid "Set Mautic Information." 69 | msgstr "" 70 | 71 | #. Plugin Name of the plugin/theme 72 | msgid "CF7 Mautic Extention" 73 | msgstr "" 74 | 75 | #. Plugin URI of the plugin/theme 76 | msgid "https://github.com/megumiteam/cf7-mautic/" 77 | msgstr "" 78 | 79 | #. Description of the plugin/theme 80 | msgid "Simple extention to subscribe Contact Form 7's information to Mautic Form." 81 | msgstr "" 82 | 83 | #. Author of the plugin/theme 84 | msgid "hideokamoto" 85 | msgstr "" 86 | 87 | #. Author URI of the plugin/theme 88 | msgid "http://wp-kyoto.net/" 89 | msgstr "" -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "name": "contact-form-7-mautic-extention", 4 | "version": "0.0.0", 5 | "main": "Gruntfile.js", 6 | "author": "YOUR NAME HERE", 7 | "devDependencies": { 8 | "grunt": "^0.4.5", 9 | "grunt-wp-i18n": "^0.5.0", 10 | "grunt-wp-readme-to-markdown": "~0.9.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests/ 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === CF7 Mautic Extension === 2 | Contributors: amimotoami,megumithemes,hideokamoto,kel-dc,felipeelia,toro_unit 3 | Tags: marketing,mautic,form 4 | Requires at least: 4.4.2 5 | Support PHP Version: 5.6 or later 6 | Tested up to:4.7.3 7 | Stable tag: 0.0.5 8 | License: GPLv2 or later 9 | License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 | 11 | Simple extension to subscribe Contact Form 7's information to Mautic Form. 12 | 13 | == Description == 14 | 15 | This is plugin Contact Form 7's extension connecting to Mautic (a marketing automation software - email, social & more). 16 | 17 | You can easily create customer lead list from what's received from Contact Form 7 form. 18 | 19 | [How it works](https://github.com/megumiteam/cf7-mautic/wiki/How-It-Works) 20 | [How to setup](https://github.com/megumiteam/cf7-mautic/wiki/Set-Up-Plugin) 21 | 22 | == Installation == 23 | 24 | 1. Upload this directory to `/wp-content/plugins/` directory. 25 | 2. Activate the plugin through the 'Plugins' menu in WordPress. 26 | 3. Set following information: 27 | 28 | |Name|Description|Example| 29 | |:--|:--|:--| 30 | |Mautic URL|Your Mautic Domain|https://mautic.example.com/| 31 | |Mautic Form Mapping|Mapping Your Mautic Form & Contact Form 7's form|--| 32 | 33 | Then, you can see the customer information in Mautic. 34 | 35 | == Changelog == 36 | 37 | = 0.0.5 = 38 | * Bug fix 39 | 40 | = 0.0.4 = 41 | * Bug fix 42 | * Check php version 43 | 44 | = 0.0.3 = 45 | * Bug Fix ( Remove hyphen ) 46 | 47 | = 0.0.2 = 48 | * Bug Fix 49 | 50 | = 0.0.1 = 51 | * Initialize Release 52 | 53 | == Upgrade Notice == 54 | 55 | = 0.0.3 = 56 | * Bug Fix ( Remove hyphen ) 57 | -------------------------------------------------------------------------------- /tests/Test_CF7_Mautic_CF7_Surveyor.php: -------------------------------------------------------------------------------- 1 | assertTrue( is_wp_error( $checker->check() ) ); 14 | } 15 | 16 | public function test_check_pass_when_installed_cf7() { 17 | 18 | $checker = new CF7_Mautic_CF7_Surveyor(); 19 | if ( defined( 'WPCF7_PLUGIN_BASENAME' ) ) { 20 | $checker->set_cf7_plugin_basename( WPCF7_PLUGIN_BASENAME ); 21 | } 22 | $this->assertTrue( $checker->check() ); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /tests/Test_CF7_Mautic_PHP_Surveyor.php: -------------------------------------------------------------------------------- 1 | set_current_php_version( '5.5' ); 14 | $this->assertTrue( is_wp_error( $php_checker->check() ) ); 15 | } 16 | 17 | public function test_check_pass_newer_php() { 18 | $php_checker = new CF7_Mautic_PHP_Surveyor(); 19 | $php_checker->set_current_php_version( '5.6' ); 20 | $this->assertTrue( $php_checker->check() ); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 | $dependency ){ 25 | if ( is_dir( $local_plugin_directory .'/' . $k ) ) { 26 | require $local_plugin_directory .'/' . $dependency['include']; 27 | echo "Loaded $k\n"; 28 | } elseif ( is_dir( WP_PLUGIN_DIR . '/' . $k ) ) { 29 | require WP_PLUGIN_DIR .'/' . $dependency['include']; 30 | echo "Loaded $k\n"; 31 | } else { 32 | echo "COULD NOT LOAD $k\n"; 33 | } 34 | } 35 | } 36 | tests_add_filter( 'muplugins_loaded', '_manually_load_dependencies' ); 37 | 38 | /** 39 | * Manually load the plugin being tested. 40 | */ 41 | function _manually_load_plugin() { 42 | require dirname( dirname( __FILE__ ) ) . '/cf7-mautic.php'; 43 | } 44 | tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); 45 | 46 | // Start up the WP testing environment. 47 | require $_tests_dir . '/includes/bootstrap.php'; 48 | -------------------------------------------------------------------------------- /tests/dependencies-array.php: -------------------------------------------------------------------------------- 1 | array( 4 | 'include' => 'contact-form-7/wp-contact-form-7.php', 5 | 'repo' => 'https://downloads.wordpress.org/plugin/contact-form-7.zip', 6 | ), 7 | ); 8 | --------------------------------------------------------------------------------