Added a new parameter "actual_relative_path" into find_image() in vitals.inc.php...
authorcindy li <cli@ocad.ca>
Fri, 3 Dec 2010 16:10:08 +0000 (16:10 -0000)
committercindy li <cli@ocad.ca>
Fri, 3 Dec 2010 16:10:08 +0000 (16:10 -0000)
docs/include/classes/ContentManager.class.php
docs/include/vitals.inc.php
docs/jscripts/ATutor_js.php

index 861c475..208467c 100644 (file)
@@ -51,14 +51,14 @@ class ContentManager
 
                // Look for tree icons for displaying content navigation from theme image folder,
                // if the icon is not there, look up in atutor root image folder
-               $this->tree_collapse_icon = find_image($rtl.'tree/tree_collapse.gif');
-               $this->tree_expand_icon = find_image($rtl.'tree/tree_expand.gif');
-               $this->tree_vertline_icon = find_image($rtl.'tree/tree_vertline.gif');
-               $this->tree_horizontal_icon = find_image($rtl.'tree/tree_horizontal.gif');
-               $this->tree_split_icon = find_image($rtl.'tree/tree_split.gif');
-               $this->tree_disabled_icon = find_image($rtl.'tree/tree_disabled.gif');
-               $this->tree_end_icon = find_image($rtl.'tree/tree_end.gif');
-               $this->tree_space_icon = find_image($rtl.'tree/tree_space.gif');
+               $this->tree_collapse_icon = find_image($rtl.'tree/tree_collapse.gif', '');
+               $this->tree_expand_icon = find_image($rtl.'tree/tree_expand.gif', '');
+               $this->tree_vertline_icon = find_image($rtl.'tree/tree_vertline.gif', '');
+               $this->tree_horizontal_icon = find_image($rtl.'tree/tree_horizontal.gif', '');
+               $this->tree_split_icon = find_image($rtl.'tree/tree_split.gif', '');
+               $this->tree_disabled_icon = find_image($rtl.'tree/tree_disabled.gif', '');
+               $this->tree_end_icon = find_image($rtl.'tree/tree_end.gif', '');
+               $this->tree_space_icon = find_image($rtl.'tree/tree_space.gif', '');
        }
 
        function initContent( ) {
index e6eee82..ecc6f24 100644 (file)
@@ -1410,8 +1410,12 @@ if ( !function_exists('json_decode') ){
 /*
  * Finds the image in the theme image folder first. If the image does not exist, look up in 
  * core image folder.
- * @param: The relative path and name to the image. 
- *         "Relative" means relative to the "image" folder, with subfolders and image name.
+ * @param: image_name - The relative path and name to the image. 
+ *             "Relative" means relative to the "image" folder, with subfolders and image name.
+ *         actual_relative_path - Used when find_image() is called, for example in a class,
+ *             which is then called by different scripts that give different AT_INCLUDE_PATH. However,
+ *             the path to the image itself is consistent regardless of the caller script. This value
+ *             should be the consistent relative path to the image itself.
  * @return: The path to the image in the theme folder, if exists. 
  *          Otherwise, the path to the image in the core image folder.
  * Example: 
@@ -1420,20 +1424,22 @@ if ( !function_exists('json_decode') ){
  *      if the theme image does not exist, return the path to the image in the core "image" folder: include/../images/rtl_tree/tree/collapse.gif
  *      These pathes are relative to ATutor installation directory.
  */
-function find_image($image_name) {
+function find_image($image_name, $actual_relative_path = AT_INCLUDE_PATH) {
        // The returned path is determined by AT_INCLUDE_PATH. If AT_INCLUDE_PATH is undefined, return the parameter itself.
        if (!defined('AT_INCLUDE_PATH')) return $image_name;
        
        // remove leading "/"
        if (substr($image_name, 0, 1) == "/") $image_name = substr($image_name, 1);
        
-       $theme_image_folder = AT_INCLUDE_PATH.'../themes/'.$_SESSION['prefs']['PREF_THEME'].'/images/';
-       $atutor_image_folder = AT_INCLUDE_PATH.'../images/';
+       $theme_image_folder = 'themes/'.$_SESSION['prefs']['PREF_THEME'].'/images/';
+       $atutor_image_folder = 'images/';
        
-       if (file_exists($theme_image_folder.$image_name)) {
-               return $theme_image_folder.$image_name;
+       // Use the path that is relative to AT_INCLUDE_PATH in the caller script, to check the existence of the image
+       // but the return path is based on the pass-in actual path parameter.
+       if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.$image_name)) {
+               return $actual_relative_path.$theme_image_folder.$image_name;
        } else {
-               return $atutor_image_folder.$image_name;
+               return $actual_relative_path.$atutor_image_folder.$image_name;
        }
 }
 
index c86946b..7b4f64a 100644 (file)
@@ -20,8 +20,8 @@
 // if the icon is not there, look up in atutor root image folder
 global $rtl;
 
-$tree_collapse_icon = AT_BASE_HREF.find_image($rtl.'tree/tree_collapse.gif');
-$tree_expand_icon = AT_BASE_HREF.find_image($rtl.'tree/tree_expand.gif');
+$tree_collapse_icon = AT_BASE_HREF.find_image($rtl.'tree/tree_collapse.gif', '');
+$tree_expand_icon = AT_BASE_HREF.find_image($rtl.'tree/tree_expand.gif', '');
                
 ?>
 ATutor = ATutor || {};