From efceedd4bf9229c873f718a779368f0827b3e88d Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 29 Mar 2013 20:37:11 -0400 Subject: [PATCH] CRM-12193 - Extract CRM_Utils_System::evalUrl for use with extension-browser and community-messages ---------------------------------------- * CRM-12193: In-app fundraising for CiviCRM http://issues.civicrm.org/jira/browse/CRM-12193 --- CRM/Extension/System.php | 7 +------ CRM/Utils/System.php | 23 +++++++++++++++++++++++ tests/phpunit/CRM/Utils/SystemTest.php | 6 ++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/CRM/Extension/System.php b/CRM/Extension/System.php index 8da0688d51..6317cd9f81 100644 --- a/CRM/Extension/System.php +++ b/CRM/Extension/System.php @@ -222,12 +222,7 @@ class CRM_Extension_System { $this->_repoUrl = false; } else { - $vars = array( - '{ver}' => CRM_Utils_System::version(), - '{uf}' => $config->userFramework, - '{php}' => phpversion(), - ); - $this->_repoUrl = strtr($url, $vars); + $this->_repoUrl = CRM_Utils_System::evalUrl($url); } } return $this->_repoUrl; diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index 6d39137534..dda43997ba 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -1512,6 +1512,29 @@ class CRM_Utils_System { CRM_Utils_System::redirect($redirectUrl); } + /** + * Determine the URL which provides a feed of available extensions + * + * @param string|FALSE $url + * @return string|FALSE + */ + public static function evalUrl($url) { + // boolean false means don't try to check extensions + if ($url === FALSE) { + return FALSE; + } + else { + $config = CRM_Core_Config::singleton(); + $vars = array( + '{ver}' => CRM_Utils_System::version(), + '{uf}' => $config->userFramework, + '{php}' => phpversion(), + ); + return strtr($url, $vars); + } + } + + /** * Determine whether this is a developmental system. * diff --git a/tests/phpunit/CRM/Utils/SystemTest.php b/tests/phpunit/CRM/Utils/SystemTest.php index 0862d0af8d..23780e135f 100644 --- a/tests/phpunit/CRM/Utils/SystemTest.php +++ b/tests/phpunit/CRM/Utils/SystemTest.php @@ -34,4 +34,10 @@ class CRM_Utils_SystemTest extends CiviUnitTestCase { ), false, null, false); $this->assertEquals($expected, $actual); } + + public function testEvalUrl() { + $this->assertEquals(FALSE, CRM_Utils_System::evalUrl(FALSE)); + $this->assertEquals('http://example.com/', CRM_Utils_System::evalUrl('http://example.com/')); + $this->assertEquals('http://example.com/?cms=UnitTests', CRM_Utils_System::evalUrl('http://example.com/?cms={uf}')); + } } -- 2.25.1