Browse Source

Fix issue with HTTP links not opening in learning paths on HTTPS portals - additional change in case non-multi-url - refs BT#9874

Yannick Warnier 9 years ago
parent
commit
2e42d86292
2 changed files with 22 additions and 3 deletions
  1. 21 2
      main/inc/lib/api.lib.php
  2. 1 1
      main/newscorm/learnpath.class.php

+ 21 - 2
main/inc/lib/api.lib.php

@@ -5078,11 +5078,12 @@ function api_get_access_urls($from = 0, $to = 1000000, $order = 'url', $directio
 /**
  * Gets the access url info in an array
  * @param int $id Id of the access url
+ * @param bool $returnDefault Set to false if you want the real URL if URL 1 is still 'http://localhost/'
  * @return array All the info (url, description, active, created_by, tms)
  * from the access_url table
  * @author Julio Montoya
  */
-function api_get_access_url($id)
+function api_get_access_url($id, $returnDefault = true)
 {
     global $_configuration;
     $id = intval($id);
@@ -5090,11 +5091,29 @@ function api_get_access_url($id)
     //$table_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
     $table = 'access_url';
     $database = $_configuration['main_database'];
-    $table_access_url =  "".$database.".".$table."";
+    $table_access_url = "" . $database . "." . $table . "";
     $sql = "SELECT url, description, active, created_by, tms
             FROM $table_access_url WHERE id = '$id' ";
     $res = Database::query($sql);
     $result = @Database::fetch_array($res);
+    // If the result url is 'http://localhost/' (the default) and the root_web
+    // (=current url) is different, and the $id is = 1 (which might mean
+    // api_get_current_access_url_id() returned 1 by default), then return the
+    // root_web setting instead of the current URL
+    // This is provided as an option to avoid breaking the storage of URL-specific
+    // homepages in home/localhost/
+    if ($id === 1 && $returnDefault === false) {
+        $currentUrl = api_get_current_access_url_id();
+        // only do this if we are on the main URL (=1), otherwise we could get
+        // information on another URL instead of the one asked as parameter
+        if ($currentUrl === 1) {
+            $rootWeb = api_get_path(WEB_PATH);
+            $default = 'http://localhost/';
+            if ($result['url'] === $default && $rootWeb != $default) {
+                $result['url'] = $rootWeb;
+            }
+        }
+    }
     return $result;
 }
 

+ 1 - 1
main/newscorm/learnpath.class.php

@@ -3436,7 +3436,7 @@ class learnpath
                                 // If the current site is HTTPS and the link is
                                 // HTTP, browsers will refuse opening the link
                                 $urlId = api_get_current_access_url_id();
-                                $url = api_get_access_url($urlId);
+                                $url = api_get_access_url($urlId, false);
                                 $protocol = substr($url['url'], 0, 5);
                                 if ($protocol === 'https') {
                                     $linkProtocol = substr($file, 0, 5);