From 04eee3f6f3a7944566d7bf0a94f14bab1fb8e854 Mon Sep 17 00:00:00 2001 From: sunil Date: Wed, 29 Jul 2015 18:22:37 +0530 Subject: [PATCH] Getting Started dashlet --- CRM/Core/xml/Menu/Contact.xml | 6 + CRM/Dashlet/Page/GettingStarted.php | 154 ++++++++++++++++++ templates/CRM/Dashlet/Page/GettingStarted.tpl | 27 +++ 3 files changed, 187 insertions(+) create mode 100644 CRM/Dashlet/Page/GettingStarted.php create mode 100644 templates/CRM/Dashlet/Page/GettingStarted.tpl diff --git a/CRM/Core/xml/Menu/Contact.xml b/CRM/Core/xml/Menu/Contact.xml index 729452ed1a..2cb4e153b4 100644 --- a/CRM/Core/xml/Menu/Contact.xml +++ b/CRM/Core/xml/Menu/Contact.xml @@ -250,6 +250,12 @@ CiviCRM Blog CRM_Dashlet_Page_Blog + + civicrm/dashlet/getting-started + CiviCRM Getting Started + CRM_Dashlet_Page_GettingStarted + + civicrm/ajax/relation CRM_Contact_Page_AJAX::relationship diff --git a/CRM/Dashlet/Page/GettingStarted.php b/CRM/Dashlet/Page/GettingStarted.php new file mode 100644 index 0000000000..170a365d30 --- /dev/null +++ b/CRM/Dashlet/Page/GettingStarted.php @@ -0,0 +1,154 @@ + 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; + } + + // Clean up description - remove tags that would break dashboard layout + $html = preg_replace('#]*>(.+?)]*>#s', '

$1

', $html); + $html = strip_tags($html, "


    • "); + $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); + } + } + } + +} diff --git a/templates/CRM/Dashlet/Page/GettingStarted.tpl b/templates/CRM/Dashlet/Page/GettingStarted.tpl new file mode 100644 index 0000000000..8cbf4c44fb --- /dev/null +++ b/templates/CRM/Dashlet/Page/GettingStarted.tpl @@ -0,0 +1,27 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.6 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2015 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} + +
      {$gettingStarted}
      -- 2.25.1