1. Clean up the content.php and content.tmpl.php to simplify the generation of AFA...
authorcindy li <cli@ocad.ca>
Thu, 2 Dec 2010 16:02:56 +0000 (16:02 -0000)
committercindy li <cli@ocad.ca>
Thu, 2 Dec 2010 16:02:56 +0000 (16:02 -0000)
2. Added a new function find_image() into vitals.inc.php to look up the given image in the theme folder then core image folder, if the theme image does not exist;
3. Modified ContentManager.class.php to use find_image().

docs/content.php
docs/include/classes/ContentManager.class.php
docs/include/vitals.inc.php
docs/themes/default/content.tmpl.php

index edb3898..48fd62b 100644 (file)
@@ -208,14 +208,28 @@ if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
                        
                        $content_array = get_content_table($content);
                        
+                       // Create the array of alternative information for generating the AFA tool bar
+                       $alt_infos = array();
+                       $pause_image = find_image("pause.png");
+                       
+                       if($has_text_alternative){
+                               $alt_infos['has_text_alternative'] = array('3', _AT('apply_text_alternatives'), _AT('stop_apply_text_alternatives'), $pause_image, find_image('text_alternative.png'));
+                       }
+                       if($has_audio_alternative){
+                               $alt_infos['has_audio_alternative'] = array('1', _AT('apply_audio_alternatives'), _AT('stop_apply_audio_alternatives'), $pause_image, find_image('audio_alternative.png'));
+                       }
+                       if($has_visual_alternative){
+                               $alt_infos['has_visual_alternative'] = array('4', _AT('apply_visual_alternatives'), _AT('stop_apply_visual_alternatives'), $pause_image, find_image('visual_alternative.png'));
+                       }
+                       if($has_sign_lang_alternative){
+                               $alt_infos['has_sign_lang_alternative'] = array('2', _AT('apply_sign_lang_alternatives'), _AT('stop_apply_sign_lang_alternatives'), $pause_image, find_image('sign_lang_alternative.png'));
+                       }
+                       
                        $savant->assign('content_table', $content_array[0]);
                        $savant->assign('body', $content_array[1]);
                        $savant->assign('cid', $cid);
-                       $savant->assign('has_text_alternative', $has_text_alternative);
-                       $savant->assign('has_audio_alternative', $has_audio_alternative);
-                       $savant->assign('has_visual_alternative', $has_visual_alternative);
-                       $savant->assign('has_sign_lang_alternative', $has_sign_lang_alternative);
-                                               
+                       $savant->assign('alt_infos', $alt_infos);
+                       
                        //assign test pages if there are tests associated with this content page
                        if (!empty($content_test_ids)){
                                $savant->assign('test_message', $content_row['test_message']);
@@ -225,8 +239,8 @@ if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
                                $savant->assign('test_ids', array());
                        }
        
-                       /*TODO***************BOLOGNA***************REMOVE ME**********/
-                       //assign forum pages if there are forums associated with this content page
+                       /*TODO***************BOLOGNA***************REMOVE ME**********/
+                       //assign forum pages if there are forums associated with this content page
                        if (!empty($content_forum_ids)){
                                $savant->assign('forum_message','');
                                $savant->assign('forum_ids', $content_forum_ids);
@@ -242,45 +256,6 @@ if ($released_status === TRUE || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
        unset($infos);
 }
 
-//Create has_alternatives array for generating the AFA tool bar
-$alt_parts = array();
-$theme_image_path = "themes/".$_SESSION['prefs']['PREF_THEME']."/images/";
-if($has_text_alternative){
-       if(file_exists($theme_image_path.'text_alternative.png')){
-               $img_path = '../'.$theme_image_path;
-       }else{
-               $img_path = '../images/';
-       }
-               $alt_parts['has_text_alternative'] = array('3', $img_path,_AT('apply_text_alternatives'),_AT('stop_apply_text_alternatives'),'pause.png','text_alternative.png');
-}
-if($has_audio_alternative){
-       if(is_file($theme_image_path.'audio_alternative.png')){
-               $img_path = '../'.$theme_image_path;
-       }else{
-               $img_path = '../images/';
-       }
-               $alt_parts['has_audio_alternative'] = array('1', $img_path,_AT('apply_audio_alternatives'),_AT('stop_apply_audio_alternatives'),'pause.png','audio_alternative.png');
-}
-if($has_visual_alternative){
-       if(is_file($theme_image_path.'visual_alternative.png')){
-               $img_path = '../'.$theme_image_path;
-       }else{
-               $img_path = '../images/';
-       }
-               $alt_parts['has_visual_alternative'] = array('4', $img_path,_AT('apply_visual_alternatives'),_AT('stop_apply_visual_alternatives'),'pause.png','visual_alternative.png');
-}
-if($has_sign_lang_alternative){
-       if(is_file($theme_image_path.'sign_lang_alternative.png')){
-               $img_path = '../'.$theme_image_path;
-       }else{
-               $img_path = '../images/';
-       }
-               $alt_parts['has_sign_lang_alternative'] = array('2', $img_path,_AT('apply_sign_lang_alternatives'),_AT('stop_apply_sign_lang_alternatives'),'pause.png','sign_lang_alternative.png');
-}
-
-
-$savant->assign('theme_image_path', $has_text_alternative);
-$savant->assign('alt_parts', $alt_parts);
 $savant->assign('content_info', _AT('page_info', AT_date(_AT('inbox_date_format'), $content_row['last_modified'], AT_DATE_MYSQL_DATETIME), $content_row['revision'], AT_date(_AT('inbox_date_format'), $content_row['release_date'], AT_DATE_MYSQL_DATETIME)));
 
 require(AT_INCLUDE_PATH.'header.inc.php');
@@ -291,28 +266,4 @@ $savant->display('content.tmpl.php');
 $_SESSION['last_visited_page'] = $server_protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
 
 require (AT_INCLUDE_PATH.'footer.inc.php');
-
-
-/**
-* Creates the AccessForAll Toolbar based on the $alt_parts array
-* See the $alt_parts array generated above
-* @param       $cid the content id used to check if alternatiove are available
-* @param       $theme_image_path the path to the theme image directory, checked to see if custom icons exist for the toolbar
-* @param       $alt_parts the array of images, paths, and text used to construct the AFA toolbar
-* @param    $has_sign_lang_alternative returns TRUE if sign alternatives are available for the current cid
-* @param    $has_visual_alternative returns TRUE if visual alternatives are available for the current cid
-* @param    $has_audio_lang_alternative returns TRUE if audio alternatives are available for the current cid
-* @param    $has_sign_lang_alternative returns TRUE if text alternatives are available for the current cidy
-* @author      Greg Gay/Cindy Li
-*/
-
-function print_alternative_tools($cid,$theme_image_path,$alt_parts,$has_sign_lang_alternative,$has_visual_alternative,$has_audio_alternative,$has_text_alternative){
-
-if ($has_text_alternative || $has_audio_alternative || $has_visual_alternative || $has_sign_lang_alternative){
-       foreach ($alt_parts as $alt_part){
-               echo '<a href="'.$_SERVER['PHP_SELF'].'?cid='.$cid.(($_GET['alternative'] == $alt_part['0']) ? '' : htmlentities_utf8(SEP).'alternative='.$alt_part[0]).'">
-                       <img src="'.$alt_part[1].(($_GET['alternative'] == $alt_part['0']) ? $alt_part['4'] : $alt_part['5']).'" alt="'.(($_GET['alternative'] == $alt_part['0']) ? $alt_part['3'] : $alt_part['2']).'" title="'.(($_GET['alternative'] == $alt_part['0']) ? $alt_part['3'] : $alt_part['2']).'" border="0" class="img1616"/></a>';
-               } 
-       }
-}
 ?>
\ No newline at end of file
index a843ec8..b86806e 100644 (file)
@@ -51,56 +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
-               $theme_image_folder = 'themes/'.$_SESSION['prefs']['PREF_THEME'].'/images/';
-               $atutor_image_folder = 'images/';
-               
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.$rtl.'tree/tree_collapse.gif')) {
-                       $this->tree_collapse_icon = $theme_image_folder.$rtl.'tree/tree_collapse.gif';
-               } else {
-                       $this->tree_collapse_icon = $atutor_image_folder.$rtl.'tree/tree_collapse.gif';
-               }
-
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_expand.gif')) {
-                       $this->tree_expand_icon = $theme_image_folder.$rtl.'tree/tree_expand.gif';
-               } else {
-                       $this->tree_expand_icon = $atutor_image_folder.$rtl.'tree/tree_expand.gif';
-               }
-               
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_vertline.gif')) {
-                       $this->tree_vertline_icon = $theme_image_folder.$rtl.'tree/tree_vertline.gif';
-               } else {
-                       $this->tree_vertline_icon = $atutor_image_folder.$rtl.'tree/tree_vertline.gif';
-               }
-               
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_horizontal.gif')) {
-                       $this->tree_horizontal_icon = $theme_image_folder.$rtl.'tree/tree_horizontal.gif';
-               } else {
-                       $this->tree_horizontal_icon = $atutor_image_folder.$rtl.'tree/tree_horizontal.gif';
-               }
-
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_split.gif')) {
-                       $this->tree_split_icon = $theme_image_folder.$rtl.'tree/tree_split.gif';
-               } else {
-                       $this->tree_split_icon = $atutor_image_folder.$rtl.'tree/tree_split.gif';
-               }
-               
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_disabled.gif')) {
-                       $this->tree_disabled_icon = $theme_image_folder.$rtl.'tree/tree_disabled.gif';
-               } else {
-                       $this->tree_disabled_icon = $atutor_image_folder.$rtl.'tree/tree_disabled.gif';
-               }
-       
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_end.gif')) {
-                       $this->tree_end_icon = $theme_image_folder.$rtl.'tree/tree_end.gif';
-               } else {
-                       $this->tree_end_icon = $atutor_image_folder.$rtl.'tree/tree_end.gif';
-               }
-       
-               if (file_exists(AT_INCLUDE_PATH.'../'.$theme_image_folder.'tree/tree_space.gif')) {
-                       $this->tree_space_icon = $theme_image_folder.$rtl.'tree/tree_space.gif';
-               } else {
-                       $this->tree_space_icon = $atutor_image_folder.$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 aa4dd38..e6eee82 100644 (file)
@@ -1370,7 +1370,6 @@ function htmlentities_utf8($str, $use_nl2br=true){
        return $return;
 }
 
-
 /**
  * Convert all '&' to '&amp;' from the input
  * @param   string  any string input, mainly URLs.
@@ -1408,6 +1407,35 @@ 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.
+ * @return: The path to the image in the theme folder, if exists. 
+ *          Otherwise, the path to the image in the core image folder.
+ * Example: 
+ *   1. pass in "rtl_tree/tree/collapse.gif"
+ *   2. return the path to this image in the theme folder: include/../themes/default/images/rtl_tree/tree/collapse.gif
+ *      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) {
+       // 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/';
+       
+       if (file_exists($theme_image_folder.$image_name)) {
+               return $theme_image_folder.$image_name;
+       } else {
+               return $atutor_image_folder.$image_name;
+       }
+}
 
 require(AT_INCLUDE_PATH . '../mods/_core/modules/classes/Module.class.php');
 
index b0231bb..3c08cb4 100644 (file)
@@ -15,11 +15,19 @@ if (!defined('AT_INCLUDE_PATH')) { exit; }
 // print the AccessForAll alternatives tool bar\r
 // see /content.php for details of the alt_parts() array\r
 // images for the toolbar can be customized by adding images of the same name to a theme's images directory\r
-echo '<div id="alternatives_shortcuts">';\r
-print_alternative_tools($this->cid,$this->theme_image_path,$this->alt_parts,$this->has_sign_lang_alternative,$this->has_visual_alternative,$this->has_audio_alternative,$this->has_text_alternative);\r
-echo '</div>';\r
-if ($_SESSION["prefs"]["PREF_SHOW_CONTENTS"] && $this->content_table <> "") \r
+?>\r
+<div id="alternatives_shortcuts">\r
+<?php \r
+       foreach ($this->alt_infos as $alt_info){\r
+               echo '<a href="'.$_SERVER['PHP_SELF'].'?cid='.$cid.(($_GET['alternative'] == $alt_info['0']) ? '' : htmlentities_utf8(SEP).'alternative='.$alt_info[0]).'">\r
+                       <img src="'.AT_BASE_HREF.(($_GET['alternative'] == $alt_info[0]) ? $alt_info[3] : $alt_info[4]).'" alt="'.(($_GET['alternative'] == $alt_info[0]) ? $alt_info[2] : $alt_info[1]).'" title="'.(($_GET['alternative'] == $alt_info[0]) ? $alt_info[2] : $alt_info[1]).'" border="0" class="img1616"/></a>';\r
+       } \r
+?>\r
+</div>\r
+<?php \r
+if ($_SESSION["prefs"]["PREF_SHOW_CONTENTS"] && $this->content_table <> "") {\r
        echo $this->content_table;\r
+}\r
 ?>\r
 \r
 <div id="content-text">\r