PluginProbe
Dynamics 365 Integration / 1.3.21
Dynamics 365 Integration v1.3.21
1.4.2 trunk 1.3.20 1.3.21 1.3.22 1.3.23 1.3.24 1.4 1.4.1
integration-dynamics / integration-dynamics.php

integration-dynamics.php in Dynamics 365 Integration 1.3.21, at integration-dynamics.php

164 lines 5.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Dynamics 365 Integration
4 * Plugin URI: https://wordpress.org/plugins/integration-dynamics/
5 * Description: The easiest way to connect Dynamics 365 and Dynamics CRM with WordPress.
6 * Version: 1.3.21
7 * Requires at least: 4.9
8 * Requires PHP: 7.2.5
9 * Author: AlexaCRM
10 * Author URI: https://alexacrm.com
11 * Text Domain: integration-dynamics
12 * Domain Path: /languages
13 */
14
15 if ( !defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly
17 }
18
19 define( 'WORDPRESSCRM_VERSION', '1.3.21' );
20
21 define( 'WORDPRESSCRM_DIR', __DIR__ );
22
23 $wpUploadDir = wp_upload_dir();
24 $wpcrmStorageDir = null;
25 if ( $wpUploadDir['error'] === false ) {
26 $wpcrmStorageDir = $wpUploadDir['basedir'] . '/wpcrm-storage';
27
28 /**
29 * Stop further initialization if the storage is not writable.
30 */
31 if ( !wp_mkdir_p( $wpcrmStorageDir ) || !is_writable( $wpcrmStorageDir ) ) {
32 add_action( 'admin_notices', function() use ( $wpcrmStorageDir ) {
33 $screen = get_current_screen();
34 if ( $screen->base === 'plugins' ) {
35 ?>
36 <div class="notice notice-error">
37 <p>
38 <?php printf( __( 'Dynamics 365 Integration detected that <code>%s</code> is not writable by the web server. Please fix it to complete the installation.', 'integration-dynamics' ), $wpcrmStorageDir ); ?>
39 </p>
40 </div>
41 <?php
42 }
43 } );
44
45 return;
46 }
47 }
48
49 define( 'WORDPRESSCRM_STORAGE', $wpcrmStorageDir );
50
51 require_once __DIR__ . '/vendor/autoload.php'; // Composer autoloader
52
53 function wpcrm_log_processor_sanitizer( $record ) {
54 if ( array_key_exists( 'request', $record['context'] ) ) {
55 $record['context']['request'] = preg_replace( '~<o:Password\s+Type=".*?">.*?</o:Password>~', '<o:Password/>', $record['context']['request'] );
56 $record['context']['request'] = preg_replace( '~<default:CipherValue>.*?</default:CipherValue>~', '<default:CipherValue/>', $record['context']['request'] );
57 }
58
59 return $record;
60 }
61
62 $logger = new \Monolog\Logger( 'wpcrm' );
63 $logLevel = WP_DEBUG? \Monolog\Logger::INFO : \Monolog\Logger::NOTICE;
64 $logLevel = get_option( 'wpcrm_log_level', $logLevel );
65 if ( defined( 'WORDPRESSCRM_LOG_LEVEL' ) ) {
66 $logLevel = WORDPRESSCRM_LOG_LEVEL;
67 }
68 define( 'WORDPRESSCRM_EFFECTIVE_LOG_LEVEL', $logLevel );
69
70 $logStream = new \Monolog\Handler\RotatingFileHandler( WORDPRESSCRM_STORAGE . '/integration-dynamics.log', 3, $logLevel );
71
72 $dateFormat = 'Y-m-d';
73 $uniqId = crc32( date( $dateFormat ) . ( defined( 'AUTH_KEY' ) ? AUTH_KEY : 'abcdefghijklmnopqrstuvwxyz123456' ) );
74 $logStream->setFilenameFormat( "{filename}-$uniqId-{date}", $dateFormat );
75
76 if ( !file_exists( $logStream->getUrl() ) || is_writable( $logStream->getUrl() ) ) {
77 $logger->pushHandler( $logStream );
78 }
79
80 $logger->pushProcessor( 'wpcrm_log_processor_sanitizer' );
81
82 /**
83 * Checking for the current PHP version.
84 * We support 5.4+
85 */
86 if ( version_compare( phpversion(), '5.4', '<' ) ) {
87 $logger->critical( 'PHP version is less than 5.4. Cannot proceed further.', array( 'phpversion' => phpversion() ) );
88
89 add_action( 'admin_notices', function() {
90 $screen = get_current_screen();
91 if ( $screen->base === 'plugins' ) {
92 ?>
93 <div class="notice notice-error">
94 <p>
95 <?php printf( __( 'Dynamics 365 Integration detected that your environment has PHP %1$s. The plugin requires at least PHP %2$s to work. Please upgrade your PHP installation to fully enable the plugin.', 'integration-dynamics' ), phpversion(), '5.4' ); ?>
96 </p>
97 </div>
98 <?php
99 }
100 } );
101 return;
102 }
103
104 /**
105 * Check whether cURL is installed.
106 */
107 if ( !function_exists( 'curl_version' ) ) {
108 $logger->critical( 'cURL is not installed. Cannot proceed further.' );
109
110 add_action( 'admin_notices', function() {
111 $screen = get_current_screen();
112 if ( $screen->base === 'plugins' ) {
113 ?>
114 <div class="notice notice-error">
115 <p>
116 <?php _e( 'cURL, a PHP extension, is not installed. <strong>Dynamics 365 Integration</strong> requires cURL to work properly.', 'integration-dynamics' ); ?>
117 </p>
118 </div>
119 <?php
120 }
121 } );
122
123 return;
124 }
125
126 // Run migrations
127 register_activation_hook( __FILE__, function() use ( $wpcrmStorageDir ) {
128 $update = new \AlexaCRM\WordpressCRM\Update();
129 $update->updateDeprecatedOptions();
130 $update->updateDataBoundPages();
131 $update->updateDataBinding();
132
133 function removeDir( $target ) {
134 try {
135 $iterator = new RecursiveDirectoryIterator( $target, RecursiveDirectoryIterator::SKIP_DOTS );
136 $fileIterator = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::CHILD_FIRST );
137 foreach ( $fileIterator as $file ) {
138 /** @var SplFileInfo $file */
139 if ( is_dir( $file ) ) {
140 rmdir( $file->getRealPath() );
141 continue;
142 }
143
144 unlink( $file->getRealPath() );
145 }
146
147 rmdir( $target );
148 } catch ( \Exception $e ) {} // Silence is golden.
149 }
150
151 // Drop the cache.
152 if ( is_dir( $wpcrmStorageDir . '/cache' ) ) {
153 removeDir( $wpcrmStorageDir . '/cache' );
154 }
155
156 // add .htaccess to prevent access to the storage directory
157 if ( !file_exists( $wpcrmStorageDir . '/.htaccess' ) ) {
158 $htaccessContent = "Order Deny,Allow\nDeny from all\nAllow from 127.0.0.1\n";
159 @file_put_contents( $wpcrmStorageDir . '/.htaccess', $htaccessContent );
160 }
161 } );
162
163 require_once __DIR__ . '/core.php';
164