array( 'configbackend' => 'civicrm/admin/configtask', ), ); /** * Get the final, usable URL string (after interpolating any variables) * * @return FALSE|string */ public function gettingStartedUrl() { // Note: We use "*default*" as the default (rather than self::GETTING_STARTED_URL) so that future // developers can change GETTING_STARTED_URL without needing to update {civicrm_setting}. $url = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'gettingStartedUrl', NULL, '*default*'); if ($url === '*default*') { $url = self::GETTING_STARTED_URL; } return CRM_Utils_System::evalUrl($url); } /** * List gettingStarted page as dashlet. */ public function run() { $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'dashlet'); $this->assign('context', $context); $this->assign('gettingStarted', $this->_gettingStarted()); return parent::run(); } /** * Load gettingStarted page from cache. * Refresh cache if expired * * @return array */ private function _gettingStarted() { // Fetch data from cache $cache = CRM_Core_DAO::executeQuery("SELECT data, created_date FROM civicrm_cache WHERE group_name = 'dashboard' AND path = 'gettingStarted'"); if ($cache->fetch()) { $expire = time() - (60 * 60 * 24 * self::CACHE_DAYS); // Refresh data after CACHE_DAYS if (strtotime($cache->created_date) < $expire) { $new_data = $this->_getHtml($this->gettingStartedUrl()); // If fetching the new html was successful, return it // Otherwise use the old cached data - it's better than nothing if ($new_data) { return $new_data; } } return unserialize($cache->data); } return $this->_getHtml($this->gettingStartedUrl()); } /** * Get html and cache results. * * @param $url * * @return array|NULL * array of gettingStarted items; or NULL if not available */ public function _getHtml($url) { $httpClient = new CRM_Utils_HttpClient(self::CHECK_TIMEOUT); list ($status, $html) = $httpClient->get($url); if ($status !== CRM_Utils_HttpClient::STATUS_OK) { return NULL; } $tokensList = CRM_Utils_Token::getTokens($html); $this->replaceLinkToken($tokensList, $html); if ($html) { CRM_Core_BAO_Cache::setItem($html, 'dashboard', 'gettingStarted'); } return $html; } /** * @param array $tokensList * @param string $str * */ public function replaceLinkToken($tokensList, &$str) { foreach ($tokensList as $categories => $tokens) { foreach ($tokens as $token) { $value = ''; if (!empty(self::$_tokens[$categories][$token])) { $value = self::$_tokens[$categories][$token]; if ($categories == 'crmurl') { $value = CRM_Utils_System::url($value, "reset=1", FALSE, NULL, TRUE, TRUE); } } CRM_Utils_Token::token_replace($categories, $token, $value, $str); } } } }