// if one of the prerequisite test(s) has expired, student cannot view the content
if (intval($pre_test_id) != -1 || authenticate(AT_PRIV_CONTENT, AT_PRIV_RETURN))
{
- //Silvia: to provide appropriated content on the basis of users' preferences
- $content = provide_alternatives($cid, $content_row['text']);
-
+ // find whether the body has alternatives defined
+ list($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative)
+ = provide_alternatives($cid, $content_row['text'], true);
+
+ // apply alternatives
+ if (intval($_GET['alternative']) > 0) {
+ $content = provide_alternatives($cid, $content_row['text'], false, intval($_GET['alternative']));
+ } else {
+ $content = provide_alternatives($cid, $content_row['text']);
+ }
+
$content = format_content($content, $content_row['formatting'], $glossary);
$content_array = get_content_table($content);
$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);
+
//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']);
* @access public
* @param $cid: content id.
* @param $content: the original content page ($content_row['text'], from content.php).
+* @param $info_only: boolean. Default value is "false". When it's "true", returns an array of 4 values:
+* $has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative
+* @param $only_on_secondary_type: Default value is "". Accept one of the values: 1(auditory), 2(sign_language), 3(text), 4(visual)
+* When the value is given, ignore the alternative preference settings and only replace/append
+* (replace or append is still from session preference) the objects with the alternatives with
+* the given alternative types.
* @return string $content: the content page with the appropriated resources.
* @see $db from include/vitals.inc.php
* @author Cindy Qi Li
*/
-function provide_alternatives($cid, $content){
+function provide_alternatives($cid, $content, $info_only = false, $only_on_secondary_type = 0){
global $db;
$video_exts = array("mpg", "avi", "wmv", "mov", "swf", "mp3", "wav", "ogg", "mid", "mp4", "flv");
$txt_exts = array("txt", "html", "htm");
$image_exts = array("gif", "bmp", "png", "jpg", "jpeg", "png", "tif");
+ $only_on_secondary_type = intval($only_on_secondary_type);
- if (($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==0) && ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO']==0) && ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL']==0))
+ if (!$info_only && !$only_on_secondary_type &&
+ ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==0) &&
+ ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO']==0) &&
+ ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL']==0))
{
//No user's preferences related to content format are declared
return $content;
}
+
+ // intialize the 4 returned values when $info_only is on
+ if ($info_only)
+ {
+ $has_text_alternative = false;
+ $has_audio_alternative = false;
+ $has_visual_alternative = false;
+ $has_sign_lang_alternative = false;
+ }
// get all relations between primary resources and their alternatives
$sql = "SELECT c.content_path, pr.resource, prt.type_id primary_type, sr.secondary_resource, srt.type_id secondary_type
AND pr.primary_resource_id = sr.primary_resource_id
AND sr.language_code='".$_SESSION['prefs']['PREF_ALT_AUDIO_PREFER_LANG']."'
AND sr.secondary_resource_id = srt.secondary_resource_id
- AND pr.content_id = c.content_id
- ORDER BY pr.primary_resource_id, prt.type_id";
+ AND pr.content_id = c.content_id";
+ if ($only_on_secondary_type > 0) {
+ $sql .= " AND srt.type_id=".$only_on_secondary_type;
+ }
+ $sql .= " ORDER BY pr.primary_resource_id, prt.type_id";
+
$result = mysql_query($sql, $db);
//debug($sql);
if (mysql_num_rows($result) == 0) return $content;
while ($row = mysql_fetch_assoc($result))
{
- if (($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==1 && $row['primary_type']==3 &&
+ if ($info_only || $only_on_secondary_type ||
+ ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==1 && $row['primary_type']==3 &&
($_SESSION['prefs']['PREF_ALT_TO_TEXT']=="audio" && $row['secondary_type']==1 ||
$_SESSION['prefs']['PREF_ALT_TO_TEXT']=="visual" && $row['secondary_type']==4 ||
$_SESSION['prefs']['PREF_ALT_TO_TEXT']=="sign_lang" && $row['secondary_type']==2)) ||
$file_location = $row['secondary_resource'];
$file = AT_CONTENT_DIR.$_SESSION['course_id'] . '/'.$file_location;
- $target = file_get_contents($file);
+ $target = '<br />'.file_get_contents($file);
// check whether html file
if (preg_match('/.*\<html.*\<\/html\>.*/s', $target))
$pattern_replace_to = '${1}'.$target.'${3}';
else
$pattern_replace_to = '${1}${2}'.$target.'${3}';
-
+
+ // *** Alternative replace/append starts from here ***
+ $img_processed = false; // The indicator to tell the source image is found (or not)
+ // and processed (or not) in an <img> tag. If found and processed,
+ // SKIP the found/process for <a> tag because the source is a image
+ // and <a> is very likely the tag wrapping around <img>
+
// append/replace target alternative to [media]source[/media]
- $content = preg_replace("/(.*)(".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/").")(.*)/sU",
- $pattern_replace_to, $content);
-
- // append/replace target alternative to <a>...source...</a> or <a ...source...>...</a>
- if (preg_match("/\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>/sU", $content))
+ if (preg_match("/".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/")."/sU", $content))
{
- $content = preg_replace("/(.*)(\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>)(.*)/sU",
- $pattern_replace_to, $content);
+ if (!$info_only) {
+ $content = preg_replace("/(.*)(".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/").")(.*)/sU",
+ $pattern_replace_to, $content);
+ } else {
+ if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+ if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+ if ($row['secondary_type'] == 3) $has_text_alternative = true;
+ if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+ }
}
-
+
// append/replace target alternative to <img ... src="source" ...></a>
if (preg_match("/\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>/sU", $content))
{
- $content = preg_replace("/(.*)(\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>)(.*)/sU",
+ $img_processed = true;
+ if (!$info_only) {
+ $content = preg_replace("/(.*)(\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>)(.*)/sU",
$pattern_replace_to, $content);
+ } else {
+ if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+ if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+ if ($row['secondary_type'] == 3) $has_text_alternative = true;
+ if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+ }
}
+ // append/replace target alternative to <a>...source...</a> or <a ...source...>...</a>
+ // skip this "if" when the source object has been processed in aboved <img> tag
+ if (!$img_processed && preg_match("/\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>/sU", $content))
+ {
+ if (!$info_only) {
+ $content = preg_replace("/(.*)(\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>)(.*)/sU",
+ $pattern_replace_to, $content);
+ } else {
+ if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+ if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+ if ($row['secondary_type'] == 3) $has_text_alternative = true;
+ if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+ }
+ }
+
// append/replace target alternative to <object ... source ...></object>
if (preg_match("/\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>/sU", $content))
{
- $content = preg_replace("/(.*)(\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>)(.*)/sU",
+ if (!$info_only) {
+ $content = preg_replace("/(.*)(\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>)(.*)/sU",
$pattern_replace_to, $content);
+ } else {
+ if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+ if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+ if ($row['secondary_type'] == 3) $has_text_alternative = true;
+ if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+ }
}
// append/replace target alternative to <embed ... source ...>
if (preg_match("/\<embed.*".preg_quote($row['resource'], "/").".*\>/sU", $content))
{
- $content = preg_replace("/(.*)(\<embed.*".preg_quote($row['resource'], "/").".*\>)(.*)/sU",
+ if (!$info_only) {
+ $content = preg_replace("/(.*)(\<embed.*".preg_quote($row['resource'], "/").".*\>)(.*)/sU",
$pattern_replace_to, $content);
+ } else {
+ if ($row['secondary_type'] == 1) $has_audio_alternative = true;
+ if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
+ if ($row['secondary_type'] == 3) $has_text_alternative = true;
+ if ($row['secondary_type'] == 4) $has_visual_alternative = true;
+ }
}
}
}
- return $content;
+
+ if (!$info_only) {
+ return $content;
+ } else {
+ return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative);
+ }
}
/**
/****************************************************************/\r
if (!defined('AT_INCLUDE_PATH')) { exit; } ?>\r
\r
+<?php if ($this->has_text_alternative || $this->has_audio_alternative || $this->has_visual_alternative || $this->has_sign_lang_alternative): ?>\r
+<div id="alternatives_shortcuts">\r
+<?php if ($this->has_text_alternative) :?>\r
+ <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 3) ? '' : SEP.'alternative=3'); ?>">\r
+ <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 3) ? 'pause.png' : 'text_alternative.png'); ?>" \r
+ alt="<?php echo (($_GET['alternative'] == 3) ? _AT('stop_apply_text_alternatives') : _AT('apply_text_alternatives')); ?>" \r
+ title="<?php echo (($_GET['alternative'] == 3) ? _AT('stop_apply_text_alternatives') : _AT('apply_text_alternatives')); ?>" \r
+ border="0" />\r
+ </a>\r
+<?php endif; // END OF has text alternative?>\r
+<?php if ($this->has_audio_alternative) :?>\r
+ <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 1) ? '' : SEP.'alternative=1'); ?>">\r
+ <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 1) ? 'pause.png' : 'audio_alternative.png'); ?>" \r
+ alt="<?php echo (($_GET['alternative'] == 1) ? _AT('stop_apply_audio_alternatives') : _AT('apply_audio_alternatives')); ?>" \r
+ title="<?php echo (($_GET['alternative'] == 1) ? _AT('stop_apply_audio_alternatives') : _AT('apply_audio_alternatives')); ?>" \r
+ border="0" />\r
+ </a>\r
+<?php endif; // END OF has audio alternative?>\r
+<?php if ($this->has_visual_alternative) :?>\r
+ <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 4) ? '' : SEP.'alternative=4'); ?>">\r
+ <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 4) ? 'pause.png' : 'visual_alternative.png'); ?>" \r
+ alt="<?php echo (($_GET['alternative'] == 4) ? _AT('stop_apply_visual_alternatives') : _AT('apply_visual_alternatives')); ?>" \r
+ title="<?php echo (($_GET['alternative'] == 4) ? _AT('stop_apply_visual_alternatives') : _AT('apply_visual_alternatives')); ?>" \r
+ border="0" />\r
+ </a>\r
+<?php endif; // END OF has visual alternative?>\r
+<?php if ($this->has_sign_lang_alternative) :?>\r
+ <a href="<?php echo $_SERVER['PHP_SELF'].'?cid='.$this->cid.(($_GET['alternative'] == 2) ? '' : SEP.'alternative=2'); ?>">\r
+ <img src="<?php echo AT_BASE_HREF; ?>images/<?php echo (($_GET['alternative'] == 2) ? 'pause.png' : 'sign_lang_alternative.png'); ?>" \r
+ alt="<?php echo (($_GET['alternative'] == 2) ? _AT('stop_apply_sign_lang_alternatives') : _AT('apply_sign_lang_alternatives')); ?>" \r
+ title="<?php echo (($_GET['alternative'] == 2) ? _AT('stop_apply_sign_lang_alternatives') : _AT('apply_sign_lang_alternatives')); ?>" \r
+ border="0" />\r
+ </a>\r
+<?php endif; // END OF has sign language alternative?>\r
+</div>\r
+<?php endif; // END OF displaying alternative shortcut icons?>\r
+\r
<?php if ($this->shortcuts): ?>\r
<fieldset id="shortcuts"><legend><?php echo _AT('shortcuts'); ?></legend>\r
<ul>\r