From: Tim Otten Date: Sat, 30 Mar 2013 02:31:25 +0000 (-0400) Subject: CRM-12193 - Implement evalMarkup; tweak docs X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d1b6509755e7553b1260cf7eb4b22c005838d7bd;p=civicrm-core.git CRM-12193 - Implement evalMarkup; tweak docs ---------------------------------------- * CRM-12193: In-app fundraising for CiviCRM http://issues.civicrm.org/jira/browse/CRM-12193 --- diff --git a/CRM/Core/CommunityMessages.php b/CRM/Core/CommunityMessages.php index bf7ef91cb8..8df5a0c41c 100644 --- a/CRM/Core/CommunityMessages.php +++ b/CRM/Core/CommunityMessages.php @@ -69,7 +69,7 @@ class CRM_Core_CommunityMessages { } /** - * Get the messages document + * Get the messages document (either from the cache or by downloading) * * @return NULL|array */ @@ -98,6 +98,7 @@ class CRM_Core_CommunityMessages { $document['expires'] = CRM_Utils_Time::getTimeRaw() + $document['ttl']; } else { + // keep the old messages for now, try again later $document['expires'] = CRM_Utils_Time::getTimeRaw() + $document['retry']; } $isChanged = TRUE; @@ -129,10 +130,8 @@ class CRM_Core_CommunityMessages { } /** - * Pick one message + * Pick a message to display * - * @param callable $permChecker - * @param array $components * @return NULL|array */ public function pick() { @@ -168,7 +167,23 @@ class CRM_Core_CommunityMessages { * @return string */ public static function evalMarkup($markup) { - throw new Exception('not implemented'); + $config = CRM_Core_Config::singleton(); + $vals = array( + 'resourceUrl' => rtrim($config->resourceBase, '/'), + 'ver' => CRM_Utils_System::version(), + 'uf' => $config->userFramework, + 'php' => phpversion(), + 'sid' => md5('sid_' . (defined('CIVICRM_SITE_KEY') ? CIVICRM_SITE_KEY : '') . '_' . $config->userFrameworkBaseURL), + 'baseUrl' => $config->userFrameworkBaseURL, + 'lang' => $config->lcMessages, + 'co' => $config->defaultContactCountry, + ); + $vars = array(); + foreach ($vals as $k => $v) { + $vars['%%'.$k.'%%'] = $v; + $vars['{{'.$k.'}}'] = urlencode($v); + } + return strtr($markup, $vars); } /** diff --git a/tests/phpunit/CRM/Core/CommunityMessagesTest.php b/tests/phpunit/CRM/Core/CommunityMessagesTest.php index fccf92c302..2440e6000b 100644 --- a/tests/phpunit/CRM/Core/CommunityMessagesTest.php +++ b/tests/phpunit/CRM/Core/CommunityMessagesTest.php @@ -336,6 +336,14 @@ class CRM_Core_CommunityMessagesTest extends CiviUnitTestCase { $this->assertEquals($trials, $freq['

Two

']); } + function testEvalMarkup() { + $communityMessages = new CRM_Core_CommunityMessages( + $this->cache, + $this->expectNoHttpRequest() + ); + $this->assertEquals('cms=UnitTests cms=UnitTests', $communityMessages->evalMarkup('cms=%%uf%% cms={{uf}}')); + } + /** * Generate a mock HTTP client with the expectation that it is never called. *