3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
37 * Main page for getting started dashlet
39 class CRM_Dashlet_Page_GettingStarted
extends CRM_Core_Page
{
41 const CHECK_TIMEOUT
= 5;
43 const GETTING_STARTED_URL
= 'https://alert.civicrm.org/welcome?prot=1&ver={ver}&uf={uf}&sid={sid}&lang={lang}&co={co}';
46 * Define tokens available for getting started
48 static $_tokens = array(
50 'configbackend' => 'civicrm/admin/configtask',
55 * Get the final, usable URL string (after interpolating any variables)
57 * @return FALSE|string
59 public function gettingStartedUrl() {
60 // Note: We use "*default*" as the default (rather than self::GETTING_STARTED_URL) so that future
61 // developers can change GETTING_STARTED_URL without needing to update {civicrm_setting}.
62 $url = Civi
::settings()->get('gettingStartedUrl');
63 if ($url === '*default*') {
64 $url = self
::GETTING_STARTED_URL
;
66 return CRM_Utils_System
::evalUrl($url);
70 * List gettingStarted page as dashlet.
72 public function run() {
73 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this, FALSE, 'dashlet');
75 // Assign smarty variables.
76 $this->assign('context', $context);
77 $this->assign('gettingStarted', $this->_gettingStarted());
79 // Use smarty to generate page.
84 * Load gettingStarted page from cache.
85 * Refresh cache if expired
89 private function _gettingStarted() {
90 // Fetch data from cache
91 $cache = CRM_Core_DAO
::executeQuery("SELECT data, created_date FROM civicrm_cache
92 WHERE group_name = 'dashboard' AND path = 'gettingStarted'");
93 if ($cache->fetch()) {
94 $expire = time() - (60 * 60 * 24 * self
::CACHE_DAYS
);
95 // Refresh data after CACHE_DAYS
96 if (strtotime($cache->created_date
) < $expire) {
97 $new_data = $this->_getHtml($this->gettingStartedUrl());
98 // If fetching the new html was successful, return it
99 // Otherwise use the old cached data - it's better than nothing
104 return unserialize($cache->data
);
106 return $this->_getHtml($this->gettingStartedUrl());
110 * Get html and cache results.
115 * array of gettingStarted items; or NULL if not available
117 public function _getHtml($url) {
119 $httpClient = new CRM_Utils_HttpClient(self
::CHECK_TIMEOUT
);
120 list ($status, $html) = $httpClient->get($url);
121 if ($status !== CRM_Utils_HttpClient
::STATUS_OK
) {
125 $tokensList = CRM_Utils_Token
::getTokens($html);
126 $this->replaceLinkToken($tokensList, $html);
128 CRM_Core_BAO_Cache
::setItem($html, 'dashboard', 'gettingStarted');
135 * @param array $tokensList
139 public function replaceLinkToken($tokensList, &$str) {
140 foreach ($tokensList as $categories => $tokens) {
141 foreach ($tokens as $token) {
143 if (!empty(self
::$_tokens[$categories][$token])) {
144 $value = self
::$_tokens[$categories][$token];
145 if ($categories == 'crmurl') {
146 $value = CRM_Utils_System
::url($value, "reset=1");
149 CRM_Utils_Token
::token_replace($categories, $token, $value, $str);