From ab64f0c21272833135012318e1c4bc602e797fc1 Mon Sep 17 00:00:00 2001 From: ECYaz Date: Thu, 30 Jul 2026 18:14:57 -0400 Subject: [PATCH] Limit the demo box to branches with an approved revision The manage page offered a demo URL field and install button for every branch open for uploads, so a style approved only for 3.3 still showed the 3.2 install box. Build the demo box and the details page demo menu from the branches that actually have an approved revision, the same source the download box uses, and preserve stored URLs for branches that are not open for editing when the form is saved. --- controller/contribution/base.php | 2 +- controller/contribution/manage.php | 7 ++-- includes/objects/contribution.php | 38 ++++++++++++++++--- .../contributions/contribution_manage.html | 2 +- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/controller/contribution/base.php b/controller/contribution/base.php index 1ab810483..35719c334 100644 --- a/controller/contribution/base.php +++ b/controller/contribution/base.php @@ -172,7 +172,7 @@ protected function generate_navigation($page) if ($this->contrib->contrib_demo) { $demo_menu = array(); - $allowed_branches = $this->contrib->type->get_allowed_branches(true); + $allowed_branches = $this->contrib->get_approved_branches(); krsort($allowed_branches); $is_external = $this->contrib->contrib_status != ext::TITANIA_CONTRIB_APPROVED || !$this->contrib->options['demo']; diff --git a/controller/contribution/manage.php b/controller/contribution/manage.php index a4ba5f753..4ff5e7a7b 100644 --- a/controller/contribution/manage.php +++ b/controller/contribution/manage.php @@ -125,7 +125,7 @@ public function manage($contrib_type, $contrib) ); $this->settings['custom'] = $this->contrib->get_custom_fields(); - foreach ($this->contrib->type->get_allowed_branches(true) as $branch => $name) + foreach ($this->contrib->get_approved_branches() as $branch => $name) { $this->settings['demo'][$branch] = $this->contrib->get_demo_url($branch); } @@ -145,7 +145,7 @@ public function manage($contrib_type, $contrib) )); $demos = $this->request->variable('demo', array(0 => '')); - foreach ($this->contrib->type->get_allowed_branches(true) as $branch => $name) + foreach ($this->contrib->get_approved_branches() as $branch => $name) { if (isset($demos[$branch])) { @@ -155,7 +155,8 @@ public function manage($contrib_type, $contrib) $this->contrib->post_data($this->message); $this->contrib->__set_array(array( - 'contrib_demo' => ($this->can_edit_demo) ? json_encode($this->settings['demo']) : $this->contrib->contrib_demo, + // Preserve stored URLs for branches not open for editing. + 'contrib_demo' => ($this->can_edit_demo) ? json_encode($this->settings['demo'] + $this->contrib->get_demo_urls()) : $this->contrib->contrib_demo, 'contrib_limited_support' => $this->settings['limited_support'], )); } diff --git a/includes/objects/contribution.php b/includes/objects/contribution.php index 9818f7db0..6ea50da98 100644 --- a/includes/objects/contribution.php +++ b/includes/objects/contribution.php @@ -1035,6 +1035,38 @@ public function get_url($page = '', $parameters = array()) return $this->controller_helper->route($controller, $parameters); } + /** + * Get the branches for which the contribution has an approved revision. + * + * @return array Branch names limited to the branches that have an approved + * revision, keyed by branch - example: 31 => 'phpBB 3.1.x' + */ + public function get_approved_branches() + { + $this->get_download(); + + return array_intersect_key( + $this->type->get_allowed_branches(true), + $this->download + ); + } + + /** + * Get all stored demo URLs. + * + * @return array Demo URLs keyed by branch - example: 31 => 'http://...' + */ + public function get_demo_urls() + { + if (empty($this->contrib_demo)) + { + return array(); + } + $demos = json_decode($this->contrib_demo, true); + + return (is_array($demos)) ? $demos : array(); + } + /** * Get demo URL. * @@ -1045,11 +1077,7 @@ public function get_url($page = '', $parameters = array()) */ public function get_demo_url($branch, $integrated_url = false) { - if (empty($this->contrib_demo)) - { - return ''; - } - $demos = json_decode($this->contrib_demo, true); + $demos = $this->get_demo_urls(); if (empty($demos[$branch])) { diff --git a/styles/prosilver/template/contributions/contribution_manage.html b/styles/prosilver/template/contributions/contribution_manage.html index 15b961d27..066fc2de1 100644 --- a/styles/prosilver/template/contributions/contribution_manage.html +++ b/styles/prosilver/template/contributions/contribution_manage.html @@ -143,7 +143,7 @@

{{ lang('OPTIONS') }}

- {% if S_CAN_EDIT_DEMO %} + {% if S_CAN_EDIT_DEMO and loops.demo|length %}

{{ lang('DEMO_URL_EXPLAIN') }}