3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Main page for getting started dashlet
23 class CRM_Dashlet_Page_GettingStarted
extends CRM_Core_Page
{
25 const CHECK_TIMEOUT
= 5;
27 const GETTING_STARTED_URL
= 'https://alert.civicrm.org/welcome?prot=1&ver={ver}&uf={uf}&sid={sid}&lang={lang}&co={co}';
30 * Define tokens available for getting started
33 public static $_tokens = [
35 'configbackend' => 'civicrm/admin/configtask',
40 * Get the final, usable URL string (after interpolating any variables)
42 * @return FALSE|string
44 public function gettingStartedUrl() {
45 // Note: We use "*default*" as the default (rather than self::GETTING_STARTED_URL) so that future
46 // developers can change GETTING_STARTED_URL without needing to update {civicrm_setting}.
47 $url = Civi
::settings()->get('gettingStartedUrl');
48 if ($url === '*default*') {
49 $url = self
::GETTING_STARTED_URL
;
51 return CRM_Utils_System
::evalUrl($url);
55 * List gettingStarted page as dashlet.
57 public function run() {
58 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'dashlet');
60 // Assign smarty variables.
61 $this->assign('context', $context);
62 $this->assign('gettingStarted', $this->_gettingStarted());
64 // Use smarty to generate page.
69 * Load gettingStarted page from cache.
70 * Refresh cache if expired
74 private function _gettingStarted() {
75 $tsLocale = CRM_Core_I18n
::getLocale();
76 $key = 'dashboard_gettingStarted_' . $tsLocale;
77 $value = Civi
::cache('community_messages')->get($key);
80 $value = $this->_getHtml($this->gettingStartedUrl());
83 Civi
::cache('community_messages')->set($key, $value, (60 * 60 * 24 * self
::CACHE_DAYS
));
96 * array of gettingStarted items; or NULL if not available
98 public function _getHtml($url) {
99 $httpClient = new CRM_Utils_HttpClient(self
::CHECK_TIMEOUT
);
100 list ($status, $html) = $httpClient->get($url);
102 if ($status !== CRM_Utils_HttpClient
::STATUS_OK
) {
106 $tokensList = CRM_Utils_Token
::getTokens($html);
107 $this->replaceLinkToken($tokensList, $html);
112 * @param array $tokensList
116 public function replaceLinkToken($tokensList, &$str) {
117 foreach ($tokensList as $categories => $tokens) {
118 foreach ($tokens as $token) {
120 if (!empty(self
::$_tokens[$categories][$token])) {
121 $value = self
::$_tokens[$categories][$token];
122 if ($categories == 'crmurl') {
123 $value = CRM_Utils_System
::url($value, "reset=1");
126 CRM_Utils_Token
::token_replace($categories, $token, $value, $str);