From ab64f0c21272833135012318e1c4bc602e797fc1 Mon Sep 17 00:00:00 2001 From: ECYaz Date: Thu, 30 Jul 2026 18:14:57 -0400 Subject: [PATCH 1/3] 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') }}
From 34fd75e428ed642c5c40cf5381aa516ae5661a1f Mon Sep 17 00:00:00 2001 From: Zi <113608189+ECYaz@users.noreply.github.com> Date: Mon, 3 Aug 2026 17:02:51 -0400 Subject: [PATCH 2/3] Keep the demo visible when downloads are disabled Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- includes/objects/contribution.php | 54 +++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/includes/objects/contribution.php b/includes/objects/contribution.php index 6ea50da98..9ea3958c0 100644 --- a/includes/objects/contribution.php +++ b/includes/objects/contribution.php @@ -1041,16 +1041,58 @@ public function get_url($page = '', $parameters = array()) * @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() +public function get_approved_branches() +{ + $allowed_branches = $this->type->get_allowed_branches(true); + + $this->get_download(); + if (!empty($this->download)) { - $this->get_download(); + return array_intersect_key($allowed_branches, $this->download); + } - return array_intersect_key( - $this->type->get_allowed_branches(true), - $this->download - ); + // get_download() may intentionally return early (e.g. downloads disabled for non-team) + // so fall back to checking which branches have an approved, validated revision. + $sql = 'SELECT DISTINCT(phpbb_version_branch), MAX(revision_id) AS revision_id + FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' + WHERE contrib_id = ' . (int) $this->contrib_id . ' + AND revision_validated = 1 + GROUP BY phpbb_version_branch'; + $result = phpbb::$db->sql_query($sql); + $revisions = array(); + while ($row = phpbb::$db->sql_fetchrow($result)) + { + $revisions[(int) $row['phpbb_version_branch']] = (int) $row['revision_id']; + } + phpbb::$db->sql_freeresult($result); + + if (empty($revisions)) + { + return array(); } + $sql = 'SELECT revision_id + FROM ' . TITANIA_REVISIONS_TABLE . ' + WHERE contrib_id = ' . (int) $this->contrib_id . ' + AND ' . phpbb::$db->sql_in_set('revision_id', array_values($revisions)) . ' + AND revision_status = ' . ext::TITANIA_REVISION_APPROVED . ' + AND revision_submitted = 1'; + $result = phpbb::$db->sql_query($sql); + $revisions = array_flip($revisions); // revision_id => branch + $approved = array(); + while ($row = phpbb::$db->sql_fetchrow($result)) + { + $branch = (int) $revisions[(int) $row['revision_id']]; + if (isset($allowed_branches[$branch])) + { + $approved[$branch] = $allowed_branches[$branch]; + } + } + phpbb::$db->sql_freeresult($result); + + return $approved; +} + /** * Get all stored demo URLs. * From 1baf0bd9feda53bea67406ad64980c374e5ea6be Mon Sep 17 00:00:00 2001 From: ECYaz Date: Mon, 3 Aug 2026 18:43:12 -0400 Subject: [PATCH 3/3] Fix indentation --- includes/objects/contribution.php | 88 +++++++++++++++---------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/includes/objects/contribution.php b/includes/objects/contribution.php index 9ea3958c0..47d45a10e 100644 --- a/includes/objects/contribution.php +++ b/includes/objects/contribution.php @@ -1041,57 +1041,57 @@ public function get_url($page = '', $parameters = array()) * @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() -{ - $allowed_branches = $this->type->get_allowed_branches(true); - - $this->get_download(); - if (!empty($this->download)) + public function get_approved_branches() { - return array_intersect_key($allowed_branches, $this->download); - } + $allowed_branches = $this->type->get_allowed_branches(true); - // get_download() may intentionally return early (e.g. downloads disabled for non-team) - // so fall back to checking which branches have an approved, validated revision. - $sql = 'SELECT DISTINCT(phpbb_version_branch), MAX(revision_id) AS revision_id - FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' - WHERE contrib_id = ' . (int) $this->contrib_id . ' - AND revision_validated = 1 - GROUP BY phpbb_version_branch'; - $result = phpbb::$db->sql_query($sql); - $revisions = array(); - while ($row = phpbb::$db->sql_fetchrow($result)) - { - $revisions[(int) $row['phpbb_version_branch']] = (int) $row['revision_id']; - } - phpbb::$db->sql_freeresult($result); + $this->get_download(); + if (!empty($this->download)) + { + return array_intersect_key($allowed_branches, $this->download); + } - if (empty($revisions)) - { - return array(); - } + // get_download() may intentionally return early (e.g. downloads disabled for non-team) + // so fall back to checking which branches have an approved, validated revision. + $sql = 'SELECT DISTINCT(phpbb_version_branch), MAX(revision_id) AS revision_id + FROM ' . TITANIA_REVISIONS_PHPBB_TABLE . ' + WHERE contrib_id = ' . (int) $this->contrib_id . ' + AND revision_validated = 1 + GROUP BY phpbb_version_branch'; + $result = phpbb::$db->sql_query($sql); + $revisions = array(); + while ($row = phpbb::$db->sql_fetchrow($result)) + { + $revisions[(int) $row['phpbb_version_branch']] = (int) $row['revision_id']; + } + phpbb::$db->sql_freeresult($result); - $sql = 'SELECT revision_id - FROM ' . TITANIA_REVISIONS_TABLE . ' - WHERE contrib_id = ' . (int) $this->contrib_id . ' - AND ' . phpbb::$db->sql_in_set('revision_id', array_values($revisions)) . ' - AND revision_status = ' . ext::TITANIA_REVISION_APPROVED . ' - AND revision_submitted = 1'; - $result = phpbb::$db->sql_query($sql); - $revisions = array_flip($revisions); // revision_id => branch - $approved = array(); - while ($row = phpbb::$db->sql_fetchrow($result)) - { - $branch = (int) $revisions[(int) $row['revision_id']]; - if (isset($allowed_branches[$branch])) + if (empty($revisions)) { - $approved[$branch] = $allowed_branches[$branch]; + return array(); } - } - phpbb::$db->sql_freeresult($result); - return $approved; -} + $sql = 'SELECT revision_id + FROM ' . TITANIA_REVISIONS_TABLE . ' + WHERE contrib_id = ' . (int) $this->contrib_id . ' + AND ' . phpbb::$db->sql_in_set('revision_id', array_values($revisions)) . ' + AND revision_status = ' . ext::TITANIA_REVISION_APPROVED . ' + AND revision_submitted = 1'; + $result = phpbb::$db->sql_query($sql); + $revisions = array_flip($revisions); // revision_id => branch + $approved = array(); + while ($row = phpbb::$db->sql_fetchrow($result)) + { + $branch = (int) $revisions[(int) $row['revision_id']]; + if (isset($allowed_branches[$branch])) + { + $approved[$branch] = $allowed_branches[$branch]; + } + } + phpbb::$db->sql_freeresult($result); + + return $approved; + } /** * Get all stored demo URLs.