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 @@