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
19 * Main page for getting started dashlet
21 class CRM_Dashlet_Page_GettingStarted
extends CRM_Core_Page
{
23 const CHECK_TIMEOUT
= 5;
25 const GETTING_STARTED_URL
= 'https://alert.civicrm.org/welcome?prot=1&ver={ver}&uf={uf}&sid={sid}&lang={lang}&co={co}';
28 * Define tokens available for getting started
31 public static $_tokens = [
33 'configbackend' => 'civicrm/admin/configtask',
38 * Get the final, usable URL string (after interpolating any variables)
40 * @return FALSE|string
42 public function gettingStartedUrl() {
43 // Note: We use "*default*" as the default (rather than self::GETTING_STARTED_URL) so that future
44 // developers can change GETTING_STARTED_URL without needing to update {civicrm_setting}.
45 $url = Civi
::settings()->get('gettingStartedUrl');
46 if ($url === '*default*') {
47 $url = self
::GETTING_STARTED_URL
;
49 return CRM_Utils_System
::evalUrl($url);
53 * List gettingStarted page as dashlet.
55 public function run() {
56 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'dashlet');
58 // Assign smarty variables.
59 $this->assign('context', $context);
60 $this->assign('gettingStarted', $this->_gettingStarted());
62 // Use smarty to generate page.
67 * Load gettingStarted page from cache.
68 * Refresh cache if expired
72 private function _gettingStarted() {
73 $tsLocale = CRM_Core_I18n
::getLocale();
74 $key = 'dashboard_gettingStarted_' . $tsLocale;
75 $value = Civi
::cache('community_messages')->get($key);
78 $value = $this->_getHtml($this->gettingStartedUrl());
81 Civi
::cache('community_messages')->set($key, $value, (60 * 60 * 24 * self
::CACHE_DAYS
));
94 * array of gettingStarted items; or NULL if not available
96 public function _getHtml($url) {
97 $httpClient = new CRM_Utils_HttpClient(self
::CHECK_TIMEOUT
);
98 list ($status, $html) = $httpClient->get($url);
100 if ($status !== CRM_Utils_HttpClient
::STATUS_OK
) {
104 $tokensList = CRM_Utils_Token
::getTokens($html);
105 $this->replaceLinkToken($tokensList, $html);
110 * @param array $tokensList
114 public function replaceLinkToken($tokensList, &$str) {
115 foreach ($tokensList as $categories => $tokens) {
116 foreach ($tokens as $token) {
118 if (!empty(self
::$_tokens[$categories][$token])) {
119 $value = self
::$_tokens[$categories][$token];
120 if ($categories == 'crmurl') {
121 $value = CRM_Utils_System
::url($value, "reset=1");
124 CRM_Utils_Token
::token_replace($categories, $token, $value, $str);