From 5c3c2030d8669c3d8833b6de2de73ccf583f7aac Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Mon, 7 May 2018 02:08:31 -0600 Subject: [PATCH] get_complex_component now has include option instead of omit --- lib/themefunctions.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/themefunctions.php b/lib/themefunctions.php index 418aef9..d9e23b5 100644 --- a/lib/themefunctions.php +++ b/lib/themefunctions.php @@ -140,7 +140,7 @@ function is_component_empty($name, $context = null) { return false; } -function get_complex_component($name, $context = null, $omit = []) { +function get_complex_component($name, $context = null, $include = []) { $db = getdatabase(); if ($context == null) { $context = get_page_slug(false); @@ -151,10 +151,19 @@ function get_complex_component($name, $context = null, $omit = []) { $content = json_decode($db->get("complex_components", "content", ["AND" => ["pageid" => $pageid, "name" => $name]]), true); } - foreach ($omit as $o) { - unset($content[$o]); + if (count($include) == 0) { + return $content; } - return $content; + + $filtered = []; + foreach ($include as $i) { + if (array_key_exists($i, $content)) { + $filtered[$i] = $content[$i]; + } else { + $filtered[$i] = ""; + } + } + return $filtered; } function is_complex_empty($name, $context = null) {