File CIFrame-class-coupling.patch of Package zabbix.25188

From cbf19382d1385f477015d4b1aa4004ef3779e73f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20T=C4=81lbergs?=
 <martins.talbergs@zabbix.com>
Date: Fri, 12 Jun 2020 17:20:47 +0300
Subject: [PATCH 1/4] ..F....... [DEV-1566] fixed CIFrame class coupling

---
 .../app/views/monitoring.widget.url.view.php  | 12 +++--
 .../php/include/classes/html/CIFrame.php      |  7 ---
 .../include/classes/screens/CScreenUrl.php    | 53 ++++++++++++-------
 3 files changed, 43 insertions(+), 29 deletions(-)

diff --git a/frontends/php/app/views/monitoring.widget.url.view.php b/frontends/php/app/views/monitoring.widget.url.view.php
index eb9d82c1694..5f5d1f47f61 100644
--- a/frontends/php/app/views/monitoring.widget.url.view.php
+++ b/frontends/php/app/views/monitoring.widget.url.view.php
@@ -18,10 +18,16 @@
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 **/
 
+if ($data['url']['error'] !== null) {
+	$item = (new CTableInfo())->setNoDataMessage($data['url']['error']);
+}
+else {
+	$item = (new CIFrame($data['url']['url'], '100%', '100%', 'auto'))->addClass(ZBX_STYLE_WIDGET_URL);
 
-$item = ($data['url']['error'] !== null)
-	? (new CTableInfo())->setNoDataMessage($data['url']['error'])
-	: (new CIFrame($data['url']['url'], '100%', '98%', 'auto')); // height is 98% to remove vertical scroll on widget
+	if (ZBX_IFRAME_SANDBOX !== false) {
+		$item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX);
+	}
+}
 
 $output = [
 	'header' => $data['name'],
diff --git a/frontends/php/include/classes/html/CIFrame.php b/frontends/php/include/classes/html/CIFrame.php
index 70f2ab53d88..32220cd201b 100644
--- a/frontends/php/include/classes/html/CIFrame.php
+++ b/frontends/php/include/classes/html/CIFrame.php
@@ -29,7 +29,6 @@ public function __construct($src = null, $width = '100%', $height = '100%', $scr
 		$this->setHeight($height);
 		$this->setScrolling($scrolling);
 		$this->setId($id);
-		$this->setSandbox();
 	}
 
 	public function setSrc($value = null) {
@@ -70,10 +69,4 @@ public function setScrolling($value) {
 		$this->setAttribute('scrolling', $value);
 		return $this;
 	}
-
-	private function setSandbox() {
-		if (ZBX_IFRAME_SANDBOX !== false) {
-			$this->setAttribute('sandbox', ZBX_IFRAME_SANDBOX);
-		}
-	}
 }
diff --git a/frontends/php/include/classes/screens/CScreenUrl.php b/frontends/php/include/classes/screens/CScreenUrl.php
index d82e5cd3d4b..43088840261 100644
--- a/frontends/php/include/classes/screens/CScreenUrl.php
+++ b/frontends/php/include/classes/screens/CScreenUrl.php
@@ -29,16 +29,23 @@ class CScreenUrl extends CScreenBase {
 	public function get() {
 		// prevent from resolving macros in configuration page
 		if ($this->mode != SCREEN_MODE_PREVIEW && $this->mode != SCREEN_MODE_SLIDESHOW) {
-			return $this->getOutput(
-				CHtmlUrlValidator::validate($this->screenitem['url'])
-					? new CIFrame($this->screenitem['url'], $this->screenitem['width'], $this->screenitem['height'],
-							'auto')
-					: makeMessageBox(false, [[
-								'type' => 'error',
-								'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
-							]]
-						)
-			);
+			if (CHtmlUrlValidator::validate($this->screenitem['url'])) {
+				$item = new CIFrame($this->screenitem['url'], $this->screenitem['width'], $this->screenitem['height'],
+					'auto'
+				);
+
+				if (ZBX_IFRAME_SANDBOX !== false) {
+					$item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX);
+				}
+			}
+			else {
+				$item = makeMessageBox(false, [[
+					'type' => 'error',
+					'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
+				]]);
+			}
+
+			return $this->getOutput($item);
 		}
 		elseif ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && $this->hostid == 0) {
 			return $this->getOutput((new CTableInfo())->setNoDataMessage(_('No host selected.')));
@@ -54,14 +61,22 @@ public function get() {
 
 		$this->screenitem['url'] = $url ? $url : $this->screenitem['url'];
 
-		return $this->getOutput(
-			CHtmlUrlValidator::validate($this->screenitem['url'])
-				? new CIFrame($this->screenitem['url'], $this->screenitem['width'], $this->screenitem['height'], 'auto')
-				: makeMessageBox(false, [[
-							'type' => 'error',
-							'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
-						]]
-					)
-		);
+		if (CHtmlUrlValidator::validate($this->screenitem['url'])) {
+			$item = new CIFrame($this->screenitem['url'], $this->screenitem['width'], $this->screenitem['height'],
+				'auto'
+			);
+
+			if (ZBX_IFRAME_SANDBOX !== false) {
+				$item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX);
+			}
+		}
+		else {
+			$item = makeMessageBox(false, [[
+				'type' => 'error',
+				'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
+			]]);
+		}
+
+		return $this->getOutput($item);
 	}
 }

From e1eada40ac64f4cc231932d64966a710645aea09 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20T=C4=81lbergs?=
 <martins.talbergs@zabbix.com>
Date: Fri, 12 Jun 2020 17:53:27 +0300
Subject: [PATCH 2/4] ..F....... [DEV-1566] fixed coding style

---
 frontends/php/app/views/monitoring.widget.url.view.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/frontends/php/app/views/monitoring.widget.url.view.php b/frontends/php/app/views/monitoring.widget.url.view.php
index 5f5d1f47f61..276ad8b0e45 100644
--- a/frontends/php/app/views/monitoring.widget.url.view.php
+++ b/frontends/php/app/views/monitoring.widget.url.view.php
@@ -18,6 +18,7 @@
 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 **/
 
+
 if ($data['url']['error'] !== null) {
 	$item = (new CTableInfo())->setNoDataMessage($data['url']['error']);
 }

From e4a9673bee68f1ff544972f8c5077ec28d8b00fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20T=C4=81lbergs?=
 <martins.talbergs@zabbix.com>
Date: Fri, 26 Jun 2020 11:24:02 +0300
Subject: [PATCH 3/4] ..F....... [DEV-1566] fixed coding style

---
 .../include/classes/screens/CScreenUrl.php    | 30 +++++++------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/frontends/php/include/classes/screens/CScreenUrl.php b/frontends/php/include/classes/screens/CScreenUrl.php
index 43088840261..7ae31507600 100644
--- a/frontends/php/include/classes/screens/CScreenUrl.php
+++ b/frontends/php/include/classes/screens/CScreenUrl.php
@@ -29,25 +29,10 @@ class CScreenUrl extends CScreenBase {
 	public function get() {
 		// prevent from resolving macros in configuration page
 		if ($this->mode != SCREEN_MODE_PREVIEW && $this->mode != SCREEN_MODE_SLIDESHOW) {
-			if (CHtmlUrlValidator::validate($this->screenitem['url'])) {
-				$item = new CIFrame($this->screenitem['url'], $this->screenitem['width'], $this->screenitem['height'],
-					'auto'
-				);
-
-				if (ZBX_IFRAME_SANDBOX !== false) {
-					$item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX);
-				}
-			}
-			else {
-				$item = makeMessageBox(false, [[
-					'type' => 'error',
-					'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
-				]]);
-			}
-
-			return $this->getOutput($item);
+			return $this->getOutput($this->prepareElement());
 		}
-		elseif ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && $this->hostid == 0) {
+
+		if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && $this->hostid == 0) {
 			return $this->getOutput((new CTableInfo())->setNoDataMessage(_('No host selected.')));
 		}
 
@@ -61,6 +46,13 @@ public function get() {
 
 		$this->screenitem['url'] = $url ? $url : $this->screenitem['url'];
 
+		return $this->getOutput($this->prepareElement());
+	}
+
+	/**
+	 * @return CTag
+	 */
+	public function prepareElement() {
 		if (CHtmlUrlValidator::validate($this->screenitem['url'])) {
 			$item = new CIFrame($this->screenitem['url'], $this->screenitem['width'], $this->screenitem['height'],
 				'auto'
@@ -77,6 +69,6 @@ public function get() {
 			]]);
 		}
 
-		return $this->getOutput($item);
+		return $item;
 	}
 }

From a4d07ce01b39f3f1a9f942f6648ce67f0dcaca1c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?M=C4=81rti=C5=86=C5=A1=20T=C4=81lbergs?=
 <martins.talbergs@zabbix.com>
Date: Fri, 26 Jun 2020 16:08:21 +0300
Subject: [PATCH 4/4] ..F....... [DEV-1566] fixed coding style

(cherry picked from commit 9f48a659f3dddaa38b9b99cac5e7238009f9aabb)
---
 .../php/include/classes/screens/CScreenUrl.php      | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/frontends/php/include/classes/screens/CScreenUrl.php b/frontends/php/include/classes/screens/CScreenUrl.php
index 7ae31507600..c37afe08d01 100644
--- a/frontends/php/include/classes/screens/CScreenUrl.php
+++ b/frontends/php/include/classes/screens/CScreenUrl.php
@@ -61,14 +61,13 @@ public function prepareElement() {
 			if (ZBX_IFRAME_SANDBOX !== false) {
 				$item->setAttribute('sandbox', ZBX_IFRAME_SANDBOX);
 			}
-		}
-		else {
-			$item = makeMessageBox(false, [[
-				'type' => 'error',
-				'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
-			]]);
+
+			return $item;
 		}
 
-		return $item;
+		return makeMessageBox(false, [[
+			'type' => 'error',
+			'message' => _s('Provided URL "%1$s" is invalid.', $this->screenitem['url'])
+		]]);
 	}
 }
openSUSE Build Service is sponsored by