CRM-12783 - CRM_Dashlet_Page_Blog - Get content via HTTPS
authorTim Otten <totten@civicrm.org>
Wed, 3 Jul 2013 14:48:06 +0000 (07:48 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 3 Jul 2013 14:55:13 +0000 (07:55 -0700)
Note: I did a simulation with enable_ssl=false, and it degraded well.

----------------------------------------
* CRM-12783: As of 4.3, civicrm pulls in content by default from non-authenticated web site (http instead of https)
  http://issues.civicrm.org/jira/browse/CRM-12783

CRM/Dashlet/Page/Blog.php

index c9007db2ec10cffbb59784b910b59769bf1d11e5..7be04dd73417af70ae4871ee2665d6050b004157 100644 (file)
@@ -38,7 +38,9 @@
  */
 class CRM_Dashlet_Page_Blog extends CRM_Core_Page {
 
-  const CHECK_TIMEOUT = 5, CACHE_DAYS = 1;
+  const CHECK_TIMEOUT = 5;
+  const CACHE_DAYS = 1;
+  const BLOG_URL = 'https://civicrm.org/blog/feed';
 
   /**
    * List blog articles as dashlet
@@ -85,14 +87,18 @@ class CRM_Dashlet_Page_Blog extends CRM_Core_Page {
   /**
    * Parse rss feed and cache results
    *
-   * @return array
+   * @return array|NULL array of blog items; or NULL if not available
    *
    * @access private
    */
   private function _getFeed() {
-    ini_set('default_socket_timeout', self::CHECK_TIMEOUT);
-    $feed = @simplexml_load_file('http://civicrm.org/blog/feed');
-    ini_restore('default_socket_timeout');
+    $httpClient = new CRM_Utils_HttpClient(self::CHECK_TIMEOUT);
+    list ($status, $rawFeed) = $httpClient->get(self::BLOG_URL);
+    if ($status !== CRM_Utils_HttpClient::STATUS_OK) {
+      return NULL;
+    }
+    $feed = @simplexml_load_string($rawFeed);
+
     $blog = array();
     if ($feed && !empty($feed->channel->item)) {
       foreach ($feed->channel->item as $item) {