From 9ffa2e19313cef84eee862c2d6e1cc33a1324b11 Mon Sep 17 00:00:00 2001
From: Tobias Krais <tk@design-to-use.de>
Date: Sat, 15 Apr 2023 16:18:55 +0200
Subject: [PATCH] =?UTF-8?q?make=20360=C2=B0=20export=20optional?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 pages/setup.php                   |  2 +-
 plugins/export/install.php        |  1 +
 plugins/export/lang/de_de.lang    |  1 +
 plugins/export/lib/aftpexport.php | 10 ++++++----
 plugins/export/lib/openimmo.php   | 10 ++++++----
 plugins/export/lib/provider.php   | 10 ++++++----
 plugins/export/pages/provider.php |  2 ++
 7 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/pages/setup.php b/pages/setup.php
index b1c6dc0..4e94d2b 100644
--- a/pages/setup.php
+++ b/pages/setup.php
@@ -33,7 +33,7 @@
 
 <p>1.2.0:</p>
 <ul>
-	<li>Feld für 360° Bilder hinzugefügt.</li>
+	<li>Feld für 360° Bilder hinzugefügt. Der Export von 360° Bildern kann in den Einstellungen jedes Portals manuell aktiviert werden.</li>
 	<li>Feld "Property::rent_plus_vat" war seit Version 1.1.1 deprecated und ist nun entfernt.</li>
 	<li>Twitter Support endgültig entfernt.</li>
 	<li>Ca. 1400 rexstan Level 9 Anpassungen.</li>
diff --git a/plugins/export/install.php b/plugins/export/install.php
index 9c7c98c..8d89a0d 100644
--- a/plugins/export/install.php
+++ b/plugins/export/install.php
@@ -16,6 +16,7 @@
     ->ensureColumn(new \rex_sql_column('ftp_username', 'VARCHAR(50)', true))
     ->ensureColumn(new \rex_sql_column('ftp_password', 'VARCHAR(50)', true))
     ->ensureColumn(new \rex_sql_column('ftp_filename', 'VARCHAR(50)', true))
+    ->ensureColumn(new \rex_sql_column('ftp_supports_360_pictures', 'TINYINT(1)', true, '0'))
     ->ensureColumn(new \rex_sql_column('social_app_id', 'VARCHAR(191)', true))
     ->ensureColumn(new \rex_sql_column('social_app_secret', 'VARCHAR(191)', true))
     ->ensureColumn(new \rex_sql_column('social_oauth_token', 'VARCHAR(191)', true))
diff --git a/plugins/export/lang/de_de.lang b/plugins/export/lang/de_de.lang
index eb27a55..624dd9c 100644
--- a/plugins/export/lang/de_de.lang
+++ b/plugins/export/lang/de_de.lang
@@ -16,6 +16,7 @@ d2u_immo_export_ftp_filename = Dateiname (nur wenn Name vom Portal vorgeschriebe
 d2u_immo_export_ftp_password = FTP Passwort
 d2u_immo_export_ftp_server = FTP Server
 d2u_immo_export_ftp_settings = FTP Einstellungen für OpenImmo Schnittstellen
+d2u_immo_export_ftp_supports_360_pictures = Portal unterstützt die Darstellung von 360° Bildern
 d2u_immo_export_ftp_username = FTP Benutzername
 d2u_immo_export_last_export_date = Letzter Export am
 d2u_immo_export_image_too_large = Bilddatei ist zu groß um für den Export vorbereitet zu werden. Bitte ersetzen Sie das Bild im Medienpool mit einer verkleinerten Version.
diff --git a/plugins/export/lib/aftpexport.php b/plugins/export/lib/aftpexport.php
index 6604bcd..dc8732c 100644
--- a/plugins/export/lib/aftpexport.php
+++ b/plugins/export/lib/aftpexport.php
@@ -119,10 +119,12 @@ protected function preparePictures($max_pics = 10): void
                         ++$pics_counter;
                     }
                 }
-                foreach ($property->pictures_360 as $picture_360) {
-                    if (strlen($picture_360) > 3 && $pics_counter < $max_pics) {
-                        $this->preparePicture($picture_360);
-                        ++$pics_counter;
+                if ($this->provider->ftp_supports_360_pictures) {
+                    foreach ($property->pictures_360 as $picture_360) {
+                        if (strlen($picture_360) > 3 && $pics_counter < $max_pics) {
+                            $this->preparePicture($picture_360);
+                            ++$pics_counter;
+                        }
                     }
                 }
                 foreach ($property->ground_plans as $groundplan) {
diff --git a/plugins/export/lib/openimmo.php b/plugins/export/lib/openimmo.php
index 4b0a67d..d82e23e 100644
--- a/plugins/export/lib/openimmo.php
+++ b/plugins/export/lib/openimmo.php
@@ -961,10 +961,12 @@ public function createXML()
                     ++$zaehler;
                 }
             }
-            foreach ($property->pictures_360 as $bild) {
-                if (strlen($bild) > 3) {
-                    $objekt_anhaenge[$zaehler] = ['PANORAMA' => $bild];
-                    ++$zaehler;
+            if ($this->provider->ftp_supports_360_pictures) {
+                foreach ($property->pictures_360 as $bild) {
+                    if (strlen($bild) > 3) {
+                        $objekt_anhaenge[$zaehler] = ['PANORAMA' => $bild];
+                        ++$zaehler;
+                    }
                 }
             }
             // Grundrisse auslesen
diff --git a/plugins/export/lib/provider.php b/plugins/export/lib/provider.php
index 573029f..b71e1a3 100644
--- a/plugins/export/lib/provider.php
+++ b/plugins/export/lib/provider.php
@@ -31,10 +31,7 @@ class Provider
     /** @var string provider interface name */
     public string $type = '';
 
-    /**
-     * @var int Redaxo language id. Represents the language, the object should
-     * be exported.
-     */
+    /** @var int Redaxo language id. Represents the language, the object should be exported. */
     public int $clang_id = 0;
 
     /** @var string Company name (your company name) */
@@ -58,6 +55,9 @@ class Provider
     /** @var string FTP filename (including file type, normally .zip) */
     public string $ftp_filename = '';
 
+    /** @var bool If true, 360° pictures are supported */
+    public bool $ftp_supports_360_pictures = false;
+
     /** @var string media manager type for exporting pictures */
     public string $media_manager_type = 'd2u_immo_list_tile';
 
@@ -108,6 +108,7 @@ public function __construct($provider_id)
             $this->ftp_username = (string) $result->getValue('ftp_username');
             $this->ftp_password = (string) $result->getValue('ftp_password');
             $this->ftp_filename = (string) $result->getValue('ftp_filename');
+            $this->ftp_supports_360_pictures = 1 === (int) $result->getValue('ftp_supports_360_pictures') ? true : false;
             $this->company_name = (string) $result->getValue('company_name');
             $this->company_email = (string) $result->getValue('company_email');
             $this->media_manager_type = (string) $result->getValue('media_manager_type');
@@ -416,6 +417,7 @@ public function save()
                 ."ftp_username = '". $this->ftp_username ."', "
                 ."ftp_password = '". $this->ftp_password ."', "
                 ."ftp_filename = '". $this->ftp_filename ."', "
+                .'ftp_supports_360_pictures = '. (int) $this->ftp_supports_360_pictures .', '
                 ."social_app_id = '". $this->social_app_id ."', "
                 ."social_app_secret = '". $this->social_app_secret ."', "
                 ."social_oauth_token = '". $this->social_oauth_token ."', "
diff --git a/plugins/export/pages/provider.php b/plugins/export/pages/provider.php
index a1f6592..3e82e42 100644
--- a/plugins/export/pages/provider.php
+++ b/plugins/export/pages/provider.php
@@ -25,6 +25,7 @@
     $provider->ftp_username = $form['ftp_username'];
     $provider->ftp_password = $form['ftp_password'];
     $provider->ftp_filename = $form['ftp_filename'];
+    $provider->ftp_supports_360_pictures = array_key_exists('ftp_supports_360_pictures', $form);
     $provider->social_app_id = $form['social_app_id'];
     $provider->social_app_secret = $form['social_app_secret'];
     $provider->linkedin_email = $form['linkedin_email'];
@@ -113,6 +114,7 @@
                             d2u_addon_backend_helper::form_input('d2u_immo_export_ftp_username', 'form[ftp_username]', $provider->ftp_username, false, $readonly, 'text');
                             d2u_addon_backend_helper::form_input('d2u_immo_export_ftp_password', 'form[ftp_password]', $provider->ftp_password, false, $readonly, 'text');
                             d2u_addon_backend_helper::form_input('d2u_immo_export_ftp_filename', 'form[ftp_filename]', $provider->ftp_filename, false, $readonly, 'text');
+                            d2u_addon_backend_helper::form_checkbox('d2u_immo_export_ftp_supports_360_pictures', 'form[ftp_supports_360_pictures]', 'true', $provider->ftp_supports_360_pictures, $readonly);
                         ?>
 					</div>
 				</fieldset>