From 7884dd8389c6c6f1f8243f34b8fbcfd482b38ed8 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 31 Jan 2016 14:02:31 -0500 Subject: [PATCH] - Updates code to work with PHP 5.3. Closes #307 --- lib/Config/Env.php | 14 ++++---- lib/Mailer/Methods/SendGrid.php | 3 +- lib/Segments/WP.php | 4 +-- .../ImportExport/Import/Import.php | 32 +++++++++---------- 4 files changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/Config/Env.php b/lib/Config/Env.php index 07af9cc1ed..60476dbd07 100644 --- a/lib/Config/Env.php +++ b/lib/Config/Env.php @@ -36,8 +36,9 @@ class Env { self::$views_path = self::$path . '/views'; self::$assets_path = self::$path . '/assets'; self::$assets_url = plugins_url('/assets', $file); - self::$temp_path = wp_upload_dir()['path']; - self::$temp_URL = wp_upload_dir()['url']; + $wp_upload_dir = wp_upload_dir(); + self::$temp_path = $wp_upload_dir['path']; + self::$temp_URL = $wp_upload_dir['url']; self::$languages_path = self::$path . '/lang'; self::$lib_path = self::$path . '/lib'; self::$plugin_prefix = 'mailpoet_'; @@ -74,15 +75,16 @@ class Env { } static function isPluginActivated() { - $activatesPlugins = get_option('active_plugins'); + $activated_plugins = get_option('active_plugins'); + $plugin_basename = plugin_basename(__FILE__); $isActivated = ( in_array( sprintf('%s/%s.php', basename(self::$path), self::$plugin_name), - $activatesPlugins + $activated_plugins ) || in_array( - sprintf('%s/%s.php', explode('/', plugin_basename(__FILE__))[0], self::$plugin_name), - $activatesPlugins + sprintf('%s/%s.php', explode('/', $plugin_basename[0]), self::$plugin_name), + $activated_plugins ) ); return ($isActivated) ? true : false; diff --git a/lib/Mailer/Methods/SendGrid.php b/lib/Mailer/Methods/SendGrid.php index bedc80e58a..9c990b2085 100644 --- a/lib/Mailer/Methods/SendGrid.php +++ b/lib/Mailer/Methods/SendGrid.php @@ -20,10 +20,11 @@ class SendGrid { $this->url, $this->request($newsletter, $subscriber) ); + $result_body = json_decode($result['body'], true); return ( !is_wp_error($result) === true && !preg_match('!invalid!', $result['body']) === true && - !isset(json_decode($result['body'], true)['errors']) === true && + !isset($result_body['errors']) === true && wp_remote_retrieve_response_code($result) === 200 ); } diff --git a/lib/Segments/WP.php b/lib/Segments/WP.php index 6f54f6db58..5b92e1dfd3 100644 --- a/lib/Segments/WP.php +++ b/lib/Segments/WP.php @@ -61,10 +61,10 @@ class WP { $segment = Segment::getWPUsers(); // count WP users - $users_count = \count_users()['total_users']; + $users_count = \count_users(); $linked_subscribers_count = $segment->subscribers()->count(); - if($users_count !== $linked_subscribers_count) { + if($users_count['total_users'] !== $linked_subscribers_count) { $linked_subscribers = Subscriber::select('wp_user_id') ->whereNotNull('wp_user_id') ->findArray(); diff --git a/lib/Subscribers/ImportExport/Import/Import.php b/lib/Subscribers/ImportExport/Import/Import.php index 0f3d5f4322..c9175eece5 100644 --- a/lib/Subscribers/ImportExport/Import/Import.php +++ b/lib/Subscribers/ImportExport/Import/Import.php @@ -16,7 +16,7 @@ class Import { public $subscribers_count; public $import_time; public $profiler_start; - + public function __construct($data) { $this->subscribers_data = $data['subscribers']; $this->segments = $data['segments']; @@ -31,7 +31,7 @@ class Import { $this->import_time = date('Y-m-d H:i:s'); $this->profiler_start = microtime(true); } - + function process() { $subscriber_fields = $this->subscriber_fields; $subscriber_custom_fields = $this->subscriber_custom_fields; @@ -89,7 +89,7 @@ class Import { 'profiler' => $this->timeExecution() ); } - + function filterExistingAndNewSubscribers($subscribers_data) { $existing_records = array_filter( array_map(function($subscriber_emails) { @@ -126,7 +126,7 @@ class Import { }, $new_records); }, $subscribers_data) ); - + $existing_subscribers = array_map(function($subscriber) use ($new_records) { return array_values( // reindex array @@ -142,7 +142,7 @@ class Import { $new_subscribers ); } - + function deleteExistingTrashedSubscribers($subscribers_data) { $existing_trashed_records = array_filter( array_map(function($subscriber_emails) { @@ -161,7 +161,7 @@ class Import { ->deleteMany(); } } - + function extendSubscribersAndFields($subscribers_data, $subscriber_fields) { $subscribers_data['created_at'] = $this->filterSubscriberCreatedAtDate(); $subscriber_fields[] = 'created_at'; @@ -170,7 +170,7 @@ class Import { $subscriber_fields ); } - + function getSubscriberFields($subscriber_fields) { return array_values( array_filter( @@ -180,7 +180,7 @@ class Import { ) ); } - + function getCustomSubscriberFields($subscriber_fields) { return array_values( array_filter( @@ -190,11 +190,11 @@ class Import { ) ); } - + function filterSubscriberCreatedAtDate() { return array_fill(0, $this->subscribers_count, $this->import_time); } - + function filterSubscriberStatus($subscribers_data, $subscriber_fields) { if(!in_array('status', $subscriber_fields)) { $subscribers_data['status'] = @@ -242,7 +242,7 @@ class Import { $subscriber_fields ); } - + function createOrUpdateSubscribers( $action, $subscribers_data, @@ -295,7 +295,7 @@ class Import { ); return $result; } - + function createOrUpdateCustomFields( $action, $db_subscribers, @@ -318,8 +318,8 @@ class Import { $value ); }, $count, $subscribers_data[$column]); - }, $subscriber_custom_fields)[0]; - foreach(array_chunk($subscribers, 200) as $data) { + }, $subscriber_custom_fields); + foreach(array_chunk($subscribers[0], 200) as $data) { if($action === 'create') { SubscriberCustomField::createMultiple( $data @@ -332,13 +332,13 @@ class Import { } } } - + function addSubscribersToSegments($subscribers, $segments) { foreach(array_chunk($subscribers, 200) as $data) { SubscriberSegment::createMultiple($segments, $data); } } - + function timeExecution() { $profiler_end = microtime(true); return ($profiler_end - $this->profiler_start) / 60;