2 /************************************************************************/
\r
4 /************************************************************************/
\r
5 /* Copyright (c) 2010 */
\r
6 /* Inclusive Design Institute */
\r
8 /* This program is free software. You can redistribute it and/or */
\r
9 /* modify it under the terms of the GNU General Public License */
\r
10 /* as published by the Free Software Foundation. */
\r
11 /************************************************************************/
\r
14 * Content Utility functions
\r
16 * @author Cindy Qi Li
\r
19 if (!defined('TR_INCLUDE_PATH')) exit;
\r
21 class ContentUtility {
\r
24 * This function cuts out html body
\r
26 * @param $text html text
\r
27 * @author Cindy Qi Li
\r
29 public static function getHtmlBody($text) {
\r
30 /* strip everything before <body> */
\r
31 $start_pos = strpos(strtolower($text), '<body');
\r
32 if ($start_pos !== false) {
\r
33 $start_pos += strlen('<body');
\r
34 $end_pos = strpos(strtolower($text), '>', $start_pos);
\r
35 $end_pos += strlen('>');
\r
37 $text = substr($text, $end_pos);
\r
40 /* strip everything after </body> */
\r
41 $end_pos = strpos(strtolower($text), '</body>');
\r
42 if ($end_pos !== false) {
\r
43 $text = trim(substr($text, 0, $end_pos));
\r
50 * This function cuts out requested tag information from html head
\r
52 * @param $text html text
\r
53 * @param $tags a string or an array of requested tags
\r
54 * @author Cindy Qi Li
\r
56 public static function getHtmlHeadByTag($text, $tags)
\r
58 $head = ContentUtility::getHtmlHead($text);
\r
61 if (!is_array($tags) && strlen(trim($tags)) > 0)
\r
63 $tags = array(trim($tags));
\r
65 foreach ($tags as $tag)
\r
67 $tag = strtolower($tag);
\r
69 /* strip everything before <{tag}> */
\r
70 $start_pos = stripos($head, '<'.$tag);
\r
73 while ($start_pos !== false)
\r
75 $temp_text = substr($temp_head, $start_pos);
\r
77 /* strip everything after </{tag}> or />*/
\r
78 $end_pos = stripos($temp_text, '</' . $tag . '>');
\r
80 if ($end_pos !== false)
\r
82 $end_pos += strlen('</' . $tag . '>');
\r
84 // add an empty line after each tag information
\r
85 $rtn_text .= trim(substr($temp_text, 0, $end_pos)) . '
\r
89 else // match /> as ending tag if </tag> is not found
\r
91 $end_pos = stripos($temp_text, '/>');
\r
93 if($end_pos === false && stripos($temp_text, $tag.'>')===false){
\r
94 //if /> is not found, then this is not a valid XHTML
\r
95 //text iff it's not tag>
\r
96 $end_pos = stripos($temp_text, '>');
\r
97 $end_pos += strlen('>');
\r
99 $end_pos += strlen('/>');
\r
101 // add an empty line after each tag information
\r
102 $rtn_text .= trim(substr($temp_text, 0, $end_pos)) . '
\r
107 // initialize vars for next round of matching
\r
108 $temp_head = substr($temp_text, $end_pos);
\r
109 $start_pos = stripos($temp_head, '<'.$tag);
\r
116 * This function cuts out html head
\r
118 * @param $text html text
\r
119 * @author Cindy Qi Li
\r
121 private static function getHtmlHead ($text) {
\r
122 /* strip everything before <head> */
\r
123 $start_pos = stripos($text, '<head');
\r
124 if ($start_pos !== false) {
\r
125 $start_pos += strlen('<head');
\r
126 $end_pos = stripos($text, '>', $start_pos);
\r
127 $end_pos += strlen('>');
\r
129 $text = substr($text, $end_pos);
\r
132 /* strip everything after </head> */
\r
133 $end_pos = stripos($text, '</head');
\r
134 if ($end_pos !== false) {
\r
135 $text = trim(substr($text, 0, $end_pos));
\r
140 private static function embedFLV($text) {
\r
141 global $content_base_href;
\r
143 $media_replace = array();
\r
144 $media_matches = array();
\r
146 // .flv (playing file via full URL)
\r
147 preg_match_all("#\[media[0-9a-z\|]*\]http://([\w\./-]+)\.flv\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
148 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"http://##MEDIA1##.flv\"></a>";
\r
150 // .flv (playing file from TR_content_dir)
\r
151 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+)\.flv\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
152 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".TR_BASE_HREF."get.php/".$content_base_href."##MEDIA1##.flv\"></a>";
\r
154 // .mp4 (playing file via full URL)
\r
155 preg_match_all("#\[media[0-9a-z\|]*\]http://([\w\./-]+)\.mp4\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
156 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"http://##MEDIA1##.mp4\"></a>";
\r
158 // .mp4 (playing file from TR_content_dir)
\r
159 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+)\.mp4\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
160 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".TR_BASE_HREF."get.php/".$content_base_href."##MEDIA1##.mp4\"></a>";
\r
162 // .mov (playing file via full URL)
\r
163 preg_match_all("#\[media[0-9a-z\|]*\]http://([\w\./-]+)\.mov\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
164 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"http://##MEDIA1##.mov\"></a>";
\r
166 // .mov (playing file from TR_content_dir)
\r
167 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+)\.mov\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
168 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".TR_BASE_HREF."get.php/".$content_base_href."##MEDIA1##.mov\"></a>";
\r
170 // .mp3 (playing file via full URL)
\r
171 preg_match_all("#\[media[0-9a-z\|]*\]http://([\w\./-]+)\.mp3\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
172 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"http://##MEDIA1##.mp3\"></a>";
\r
174 // .mp3 (playing file from TR_content_dir)
\r
175 preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+)\.mp3\[/media\]#i",$text,$media_matches[],PREG_SET_ORDER);
\r
176 $media_replace[] ="<a class=\"flowplayerholder\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".TR_BASE_HREF."get.php/".$content_base_href."##MEDIA1##.mp3\"></a>";
\r
179 // Executing the replace
\r
180 for ($i=0;$i<count($media_replace);$i++){
\r
181 foreach($media_matches[$i] as $media)
\r
183 if (is_array($media)) $has_flv = true;
\r
185 //find width and height for each matched media
\r
186 if (preg_match("/\[media\|([0-9]*)\|([0-9]*)\]*/", $media[0], $matches))
\r
188 $width = $matches[1];
\r
189 $height = $matches[2];
\r
197 //replace media tags with embedded media for each media tag
\r
198 $media_input = $media_replace[$i];
\r
199 $media_input = str_replace("##WIDTH##","$width",$media_input);
\r
200 $media_input = str_replace("##HEIGHT##","$height",$media_input);
\r
201 $media_input = str_replace("##MEDIA1##","$media[1]",$media_input);
\r
202 $media_input = str_replace("##MEDIA2##","$media[2]",$media_input);
\r
203 $text = str_replace($media[0],$media_input,$text);
\r
210 <script language="JavaScript">
\r
211 $f("a.flowplayerholder", "'.TR_BASE_HREF.'include/jscripts/flowplayer/flowplayer-3.2.5.swf", {
\r
212 clip: { autoPlay: false },
\r
229 * This function converts the youtube playable url used in <object> tag (for instance: http://www.youtube.com/v/a0ryB0m0MiM)
\r
230 * to youtube url that is used to browse (for instance: http://www.youtube.com/watch?v=a0ryB0m0MiM)
\r
231 * @param: youtube playable URL. For instance, http://www.youtube.com/v/a0ryB0m0MiM
\r
232 * @return: if the param is a youtube playable url, return the according youtube URL used to browse.
\r
233 * For instance: http://www.youtube.com/watch?v=a0ryB0m0MiM
\r
234 * Otherwise, return the original send-in parameter.
\r
236 function convertYoutubePlayURLToWatchURL($youtube_playURL) {
\r
237 return preg_replace("/(http:\/\/[a-z0-9\.]*)?youtube.com\/v\/(.*)/",
\r
238 "\\1youtube.com/watch?v=\\2", $youtube_playURL);
\r
242 * This function converts the youtube url that is used to browse (for instance: http://www.youtube.com/watch?v=a0ryB0m0MiM)
\r
243 * to youtube playable url used in <object> tag (for instance: http://www.youtube.com/v/a0ryB0m0MiM)
\r
244 * @param: the youtube URL used to browse.
\r
245 * For instance: http://www.youtube.com/watch?v=a0ryB0m0MiM
\r
246 * @return: if the param is a youtube url used to browse, return the according youtube playable URL.
\r
247 * For instance, http://www.youtube.com/v/a0ryB0m0MiM
\r
248 * Otherwise, return the original send-in parameter.
\r
250 function convertYoutubeWatchURLToPlayURL($youtube_watchURL) {
\r
251 return preg_replace("/(http:\/\/[a-z0-9\.]*)?youtube.com\/watch\?v=(.*)/",
\r
252 "\\1youtube.com/v/\\2", $youtube_watchURL);
\r
255 public static function embedMedia($text) {
\r
256 if (preg_match("/\[media(\|[0-9]+\|[0-9]+)?\]*/", $text)==0){
\r
260 // remove the spaces in [media] tag, otherwise, the next line converts URL inside [media] into <a> tag
\r
261 $text = preg_replace("/(\[media\])([\s]*)(.*)(\[\/media\])/", '$1$3$4', $text);
\r
262 $text = preg_replace("/(\[media\])(.*)([\s]*)(\[\/media\])/U", '$1$2$4', $text);
\r
264 $media_matches = Array();
\r
266 // First, we search though the text for all different kinds of media defined by media tags and store the results in $media_matches.
\r
267 // Then the different replacements for the different media tags are stored in $media_replace.
\r
268 // Lastly, we loop through all $media_matches / $media_replaces. (We choose $media_replace as index because $media_matches is multi-dimensioned.) It is important that for each $media_matches there is a $media_replace with the same index. For each media match we check the width/height, or we use the default value of 425x350. We then replace the height/width/media1/media2 parameter placeholders in $media_replace with the correct ones, before running a str_replace on $text, replacing the given media with its correct replacement.
\r
271 preg_match_all("#\[media[0-9a-z\|]*\]http://([a-z0-9\.]*)?youtube.com/watch\?v=(.*)\[/media\]#iU",$text,$media_matches[1],PREG_SET_ORDER);
\r
272 $media_replace[1] = '<object width="##WIDTH##" height="##HEIGHT##"><param name="movie" value="http://##MEDIA1##youtube.com/v/##MEDIA2##"></param><embed src="http://##MEDIA1##youtube.com/v/##MEDIA2##" type="application/x-shockwave-flash" width="##WIDTH##" height="##HEIGHT##"></embed></object>';
\r
275 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).mpg\[/media\]#i",$text,$media_matches[2],PREG_SET_ORDER);
\r
276 $media_replace[2] = "<object data=\"##MEDIA1##.mpg\" type=\"video/mpeg\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.mpg\"><param name=\"autoplay\" value=\"false\"><param name=\"autoStart\" value=\"0\"><a href=\"##MEDIA1##.mpg\">##MEDIA1##.mpg</a></object>";
\r
279 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).avi\[/media\]#i",$text,$media_matches[3],PREG_SET_ORDER);
\r
280 $media_replace[3] = "<object data=\"##MEDIA1##.avi\" type=\"video/x-msvideo\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.avi\"><param name=\"autoplay\" value=\"false\"><param name=\"autoStart\" value=\"0\"><a href=\"##MEDIA1##.avi\">##MEDIA1##.avi</a></object>";
\r
283 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).wmv\[/media\]#i",$text,$media_matches[4],PREG_SET_ORDER);
\r
284 $media_replace[4] = "<object data=\"##MEDIA1##.wmv\" type=\"video/x-ms-wmv\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.wmv\"><param name=\"autoplay\" value=\"false\"><param name=\"autoStart\" value=\"0\"><a href=\"##MEDIA1##.wmv\">##MEDIA1##.wmv</a></object>";
\r
287 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+).swf\[/media\]#i",$text,$media_matches[5],PREG_SET_ORDER);
\r
288 $media_replace[5] = "<object type=\"application/x-shockwave-flash\" data=\"##MEDIA1##.swf\" width=\"##WIDTH##\" height=\"##HEIGHT##\"> <param name=\"movie\" value=\"##MEDIA1##.swf\"><param name=\"loop\" value=\"false\"><a href=\"##MEDIA1##.swf\">##MEDIA1##.swf</a></object>";
\r
291 preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).wav\[/media\]#i",$text,$media_matches[6],PREG_SET_ORDER);
\r
292 $media_replace[6] ="<object type=\"audio/x-wav\" data=\"##MEDIA1##.wav\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.wav\"><param name=\"autoplay\" value=\"false\"><param name=\"autoStart\" value=\"0\"><a href=\"##MEDIA1##.wav\">##MEDIA1##.wav</a></object>";
\r
295 preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).ogg\[/media\]#i",$text,$media_matches[7],PREG_SET_ORDER);
\r
296 $media_replace[7] ="<object type=\"application/ogg\" data=\"##MEDIA1##.ogg\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.ogg\"><a href=\"##MEDIA1##.ogg\">##MEDIA1##.ogg</a></object>";
\r
299 preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).ogm\[/media\]#i",$text,$media_matches[8],PREG_SET_ORDER);
\r
300 $media_replace[8] ="<object type=\"application/ogm\" data=\"##MEDIA1##.ogm\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.ogm\"><a href=\"##MEDIA1##.ogg\">##MEDIA1##.ogm</a></object>";
\r
303 preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+).mid\[/media\]#i",$text,$media_matches[9],PREG_SET_ORDER);
\r
304 $media_replace[9] ="<object type=\"application/x-midi\" data=\"##MEDIA1##.mid\" width=\"##WIDTH##\" height=\"##HEIGHT##\"><param name=\"src\" value=\"##MEDIA1##.mid\"><a href=\"##MEDIA1##.mid\">##MEDIA1##.mid</a></object>";
\r
306 $text = preg_replace("#\[media[0-9a-z\|]*\](.+[^\s\"]+).mid\[/media\]#i", "<object type=\"application/x-midi\" data=\"\\1.mid\" width=\"".$width."\" height=\"".$height."\"><param name=\"src\" value=\"\\1.mid\"><a href=\"\\1.mid\">\\1.mid</a></object>", $text);
\r
308 // Executing the replace
\r
309 for ($i=1;$i<=count($media_replace);$i++){
\r
310 foreach($media_matches[$i] as $media)
\r
313 //find width and height for each matched media
\r
314 if (preg_match("/\[media\|([0-9]*)\|([0-9]*)\]*/", $media[0], $matches))
\r
316 $width = $matches[1];
\r
317 $height = $matches[2];
\r
325 //replace media tags with embedded media for each media tag
\r
326 $media_input = $media_replace[$i];
\r
327 $media_input = str_replace("##WIDTH##","$width",$media_input);
\r
328 $media_input = str_replace("##HEIGHT##","$height",$media_input);
\r
329 $media_input = str_replace("##MEDIA1##","$media[1]",$media_input);
\r
330 $media_input = str_replace("##MEDIA2##","$media[2]",$media_input);
\r
331 $text = str_replace($media[0],$media_input,$text);
\r
338 public static function makeClickable($text) {
\r
339 $text = ContentUtility::embedMedia($text);
\r
341 // convert plain text URL to clickable URL.
\r
342 // Limited conversion: It doesn't cover the case when the stuff in front of the URL is not a word. For example:
\r
343 // <p>http://google.ca</p>
\r
344 // "http://google.ca"
\r
345 $text = preg_replace('/(^|[\n ])([\w]*?)((?<!(\[media\]))http(s)?:\/\/[\w]+[^ \,\"\n\r\t\)<]*)/is',
\r
346 '$1$2<a href="$3">$3</a>', $text);
\r
348 // convert email address to clickable URL that pops up "send email" interface with the address filled in
\r
349 $text = preg_replace('/(?|<a href="mailto[\s]*:[\s]*([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'\@'
\r
350 .'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+)">(.*)<\/a>'
\r
351 .'|((((([_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'\@'
\r
352 .'[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]+)*'.'(\.[a-zA-Z]{1,6})+))))))/i',
\r
353 "<a href=\"mailto:\\1\">\\5</a>",
\r
356 // flv conversion needs to come after url conversion (2 lines above) otherwise the url to flowplayer swf file
\r
357 // in the script for a.flowplayerholder is converted
\r
358 $text = ContentUtility::embedFLV($text);
\r
363 public static function myCodes($text, $html = false) {
\r
364 global $_base_path;
\r
365 global $HTTP_USER_AGENT;
\r
367 if (substr($HTTP_USER_AGENT,0,11) == 'Mozilla/4.7') {
\r
368 $text = str_replace('[quote]','</p><p class="block">',$text);
\r
369 $text = str_replace('[/quote]','</p><p>',$text);
\r
371 $text = str_replace('[reply]','</p><p class="block">',$text);
\r
372 $text = str_replace('[/reply]','</p><p>',$text);
\r
374 $text = str_replace('[quote]','<blockquote>',$text);
\r
375 $text = str_replace('[/quote]','</blockquote><p>',$text);
\r
377 $text = str_replace('[reply]','</p><blockquote class="block"><p>',$text);
\r
378 $text = str_replace('[/reply]','</p></blockquote><p>',$text);
\r
381 $text = str_replace('[b]','<strong>',$text);
\r
382 $text = str_replace('[/b]','</strong>',$text);
\r
384 $text = str_replace('[i]','<em>',$text);
\r
385 $text = str_replace('[/i]','</em>',$text);
\r
387 $text = str_replace('[u]','<u>',$text);
\r
388 $text = str_replace('[/u]','</u>',$text);
\r
390 $text = str_replace('[center]','<center>',$text);
\r
391 $text = str_replace('[/center]','</center><p>',$text);
\r
394 $text = str_replace('[blue]','<span style="color: blue;">',$text);
\r
395 $text = str_replace('[/blue]','</span>',$text);
\r
397 $text = str_replace('[orange]','<span style="color: orange;">',$text);
\r
398 $text = str_replace('[/orange]','</span>',$text);
\r
400 $text = str_replace('[red]','<span style="color: red;">',$text);
\r
401 $text = str_replace('[/red]','</span>',$text);
\r
403 $text = str_replace('[purple]','<span style="color: purple;">',$text);
\r
404 $text = str_replace('[/purple]','</span>',$text);
\r
406 $text = str_replace('[green]','<span style="color: green;">',$text);
\r
407 $text = str_replace('[/green]','</span>',$text);
\r
409 $text = str_replace('[gray]','<span style="color: gray;">',$text);
\r
410 $text = str_replace('[/gray]','</span>',$text);
\r
412 $text = str_replace('[op]','<span class="bigspacer"></span> <a href="',$text);
\r
413 $text = str_replace('[/op]','">'._AT('view_entire_post').'</a>',$text);
\r
415 $text = str_replace('[head1]','<h2>',$text);
\r
416 $text = str_replace('[/head1]','</h2>',$text);
\r
418 $text = str_replace('[head2]','<h3>',$text);
\r
419 $text = str_replace('[/head2]','</h3>',$text);
\r
421 $text = str_replace('[cid]',$_base_path.'content.php?_cid='.$_SESSION['s_cid'],$text);
\r
423 global $sequence_links, $_course_id, $_content_id;
\r
424 if ($_course_id > 0 && !isset($sequence_links) && $_content_id > 0) {
\r
425 global $contentManager;
\r
426 $sequence_links = $contentManager->generateSequenceCrumbs($_content_id);
\r
428 if (isset($sequence_links['previous']) && $sequence_links['previous']['url']) {
\r
429 $text = str_replace('[pid]', $sequence_links['previous']['url'], $text);
\r
431 if (isset($sequence_links['next']) && $sequence_links['next']['url']) {
\r
432 $text = str_replace('[nid]', $sequence_links['next']['url'], $text);
\r
434 if (isset($sequence_links['resume']) && $sequence_links['resume']['url']) {
\r
435 $text = str_replace('[nid]', $sequence_links['resume']['url'], $text);
\r
437 if (isset($sequence_links['first']) && $sequence_links['first']['url']) {
\r
438 $text = str_replace('[fid]', $sequence_links['first']['url'], $text);
\r
441 /* contributed by Thomas M. Duffey <tduffey at homeboyz.com> */
\r
442 $html = !$html ? 0 : 1;
\r
444 // little hack added by greg to add syntax highlighting without using <?php \?\>
\r
446 $text = str_replace("[code]","[code]<?php",$text);
\r
447 $text = str_replace("[/code]","?>[/code]",$text);
\r
449 $text = preg_replace("/\[code\]\s*(.*)\s*\[\\/code\]/Usei", "ContentUtility::highlightCode(ContentUtility::fixQuotes('\\1'), $html)", $text);
\r
450 // now remove the <?php added above and leave the syntax colour behind.
\r
451 $text = str_replace("<?php", "", $text);
\r
452 $text = str_replace("?>", "", $text);
\r
457 /* contributed by Thomas M. Duffey <tduffey at homeboyz.com> */
\r
458 private static function highlightCode($code, $html) {
\r
459 // XHTMLize PHP highlight_string output until it gets fixed in PHP
\r
460 static $search = array(
\r
466 static $replace = array(
\r
472 $code = str_replace('<', '<', $code);
\r
473 $code = str_replace("\r", '', $code);
\r
476 return str_replace($search, $replace, highlight_string($code, true));
\r
479 /* contributed by Thomas M. Duffey <tduffey at homeboyz.com> */
\r
480 private static function fixQuotes($text){
\r
481 return str_replace('\\"', '"', $text);
\r
484 public static function imageReplace($text) {
\r
485 /* image urls do not require http:// */
\r
487 // $text = eregi_replace("\[image(\|)?([[:alnum:][:space:]]*)\]" .
\r
489 // "([[:alnum:]#?/&=:\"'_.-]+)" .
\r
491 // "((\[/image\])|(.*\[/image\]))",
\r
492 // "<img src=\"\\3\" alt=\"\\2\" />",
\r
495 $text = preg_replace("/\[image(\|)?([a-zA-Z0-9\s]*)\]".
\r
497 "([a-zA-Z0-9\#\?\/\&\=\:\\\"\'\_\.\-]+)[\s]*".
\r
498 "((\[\/image\])|(.*\[\/image\]))/i",
\r
499 "<img src=\"\\3\" alt=\"\\2\" />",
\r
505 private static function formatFinalOutput($text, $nl2br = true) {
\r
506 global $_base_path;
\r
508 $text = str_replace('CONTENT_DIR/', '', $text);
\r
510 return nl2br(ContentUtility::imageReplace(ContentUtility::makeClickable(ContentUtility::myCodes(' '.$text, false))));
\r
513 return ContentUtility::imageReplace(ContentUtility::makeClickable(ContentUtility::myCodes(' '.$text, true)));
\r
517 * This function converts the input string into AContent html content string
\r
519 * @param $input: input string
\r
520 * $html: whether the input is in html
\r
521 * @return converted AContent html content string
\r
522 * @author Cindy Qi Li
\r
524 public static function formatContent($input, $html = 0) {
\r
525 global $_base_path, $_config;
\r
528 $input = str_replace('<', '<', $input);
\r
529 $input = str_replace('<?php', '<?php', $input); // for bug #2087
\r
530 } elseif ($html==2) {
\r
531 $output = '<iframe width="100%" frameborder="0" id="content_frame" marginheight="0" marginwidth="0" src="'.$input.'"></iframe>';
\r
532 $output .= '<script type="text/javascript">
\r
533 function resizeIframe() {
\r
534 var height = document.documentElement.clientHeight;
\r
536 // not sure how to get this dynamically
\r
537 height -= 20; /* whatever you set your body bottom margin/padding to be */
\r
539 document.getElementById(\'content_frame\').style.height = height +"px";
\r
542 document.getElementById(\'content_frame\').onload = resizeIframe;
\r
543 window.onresize = resizeIframe;
\r
548 /* Commented by Cindy Qi Li on Jan 12, 2010
\r
549 * AContent does not support glossary
\r
550 // do the glossary search and replace:
\r
551 if (is_array($glossary)) {
\r
552 foreach ($glossary as $k => $v) {
\r
553 $k = urldecode($k);
\r
554 $v = str_replace("\n", '<br />', $v);
\r
555 $v = str_replace("\r", '', $v);
\r
557 // escape special characters
\r
558 $k = preg_quote($k);
\r
560 $k = str_replace('<', '<', $k);
\r
561 $k = str_replace('/', '\/', $k);
\r
563 $original_term = $k;
\r
564 $term = $original_term;
\r
566 $term = '(\s*'.$term.'\s*)';
\r
567 $term = str_replace(' ','((<br \/>)*\s*)', $term);
\r
569 $def = htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
\r
571 $input = preg_replace
\r
572 ("/(\[\?\])$term(\[\/\?\])/i",
\r
573 '<a href="'.$simple.'glossary.html#'.urlencode($original_term).'" target="body" class="at-term">\\2</a>',
\r
576 $input = preg_replace
\r
577 ("/(\[\?\])$term(\[\/\?\])/i",
\r
578 '\\2<sup><a class="tooltip" href="'.$_base_path.'mods/_core/glossary/index.php?g_cid='.$_SESSION['s_cid'].htmlentities(SEP).'w='.urlencode($original_term).'#term" title="'.addslashes($original_term).': '.$def.'">?</a></sup>',$input);
\r
581 } else if (!$user_glossary) {
\r
582 $input = str_replace(array('[?]','[/?]'), '', $input);
\r
587 $input = str_replace('CONTENT_DIR', '', $input);
\r
589 if (isset($_config['latex_server']) && $_config['latex_server']) {
\r
590 // see: http://www.forkosh.com/mimetex.html
\r
591 $input = preg_replace('/\[tex\](.*?)\[\/tex\]/sie', "'<img src=\"'.\$_config['latex_server'].rawurlencode('$1').'\" align=\"middle\">'", $input);
\r
595 $x = ContentUtility::formatFinalOutput($input, false);
\r
599 $output = ContentUtility::formatFinalOutput($input);
\r
601 $output = '<p>'.$input.'</p>';
\r
607 * This function returns html string of "table of content"
\r
609 * @param: $content: a string
\r
610 * @return: a html string of "table of content"
\r
612 public static function getContentTable($content)
\r
614 preg_match_all("/<(h[\d]+)[^>]*>(.*)<\/(\s*)\\1(\s*)>/i", $content, $found_headers, PREG_SET_ORDER);
\r
616 if (count($found_headers) == 0) return array("", $content);
\r
619 $num_of_headers = 0;
\r
621 for ($i = 0; $i < count($found_headers); $i++)
\r
623 $div_id = "_header_" . $num_of_headers++;
\r
627 $content_table = "<div id=\"toc\">\n<fieldset id=\"toc\"><legend>". _AT("table_of_contents")."</legend>\n";
\r
630 $content = str_replace($found_headers[$i][0], '<div id="'.$div_id.'">'.$found_headers[$i][0].'</div>', $content);
\r
631 $content_table .= '<a href="'.$_SERVER["REQUEST_URI"].'#'.$div_id.'" class="'.$found_headers[$i][1].'">'. $found_headers[$i][2]."</a>\n";
\r
633 if ($i == count($found_headers) - 1)
\r
635 $content_table .= "</fieldset></div><br />";
\r
638 return array($content_table, $content);
\r
643 * This function returns an array of content tools' shortcuts
\r
645 * @param: $content_row: an array of the current content information
\r
646 * @return: an array of all the tool short cuts that apply to the current content or content folder
\r
648 public static function getToolShortcuts($content_row)
\r
650 global $_current_user, $_base_href, $contentManager, $_course_id;
\r
652 if (((!$content_row['content_parent_id'] && ($_SESSION['packaging'] == 'top'))
\r
653 || ($_SESSION['packaging'] == 'all'))
\r
654 || (isset($_current_user) && $_current_user->isAuthor($_course_id))) {
\r
656 $tool_shortcuts[] = array(
\r
657 'title' => _AT('export_content_in_cp'),
\r
658 'url' => $_base_href . 'home/ims/ims_export.php?_cid='.$content_row['content_id'],
\r
659 'icon' => $_base_href . 'themes/'.$_SESSION['prefs']['PREF_THEME'].'/images/export.png');
\r
660 $tool_shortcuts[] = array(
\r
661 'title' => _AT('export_content_in_cc'),
\r
662 'url' => $_base_href . 'home/imscc/ims_export.php?_cid='.$content_row['content_id'].SEP.'to_a4a=1',
\r
663 'icon' => $_base_href . 'themes/'.$_SESSION['prefs']['PREF_THEME'].'/images/export_cc.png');
\r
666 if (isset($_current_user) && $_current_user->isAuthor($_course_id)) {
\r
667 if ($content_row['content_type'] == CONTENT_TYPE_CONTENT || $content_row['content_type'] == CONTENT_TYPE_WEBLINK) {
\r
668 $tool_shortcuts[] = array(
\r
669 'title' => _AT('edit_this_page'),
\r
670 'url' => $_base_href . 'home/editor/edit_content.php?_cid='.$content_row['content_id'],
\r
671 'icon' => $_base_href . 'images/medit.gif');
\r
674 $tool_shortcuts[] = array(
\r
675 'title' => _AT('add_sibling_folder'),
\r
676 'url' => $_base_href .
\r
677 'home/editor/edit_content_folder.php?pid='.$contentManager->_menu_info[$content_row['content_id']]['content_parent_id'].SEP.'_course_id='.$_course_id,
\r
678 'icon' => $_base_href . 'images/add_sibling_folder.gif');
\r
680 if ($content_row['content_type'] == CONTENT_TYPE_FOLDER || $content_row['content_type'] == CONTENT_TYPE_WEBLINK) {
\r
681 $tool_shortcuts[] = array(
\r
682 'title' => _AT('add_sub_folder'),
\r
683 'url' => $_base_href .
\r
684 'home/editor/edit_content_folder.php?_course_id='.$_course_id.SEP.'pid='.$content_row['content_id'],
\r
685 'icon' => $_base_href . 'images/add_sub_folder.gif');
\r
688 $tool_shortcuts[] = array(
\r
689 'title' => _AT('add_sibling_page'),
\r
690 'url' => $_base_href .
\r
691 'home/editor/edit_content.php?pid='.$contentManager->_menu_info[$content_row['content_id']]['content_parent_id'].SEP.'_course_id='.$_course_id,
\r
692 'icon' => $_base_href . 'images/add_sibling_page.gif');
\r
694 if ($content_row['content_type'] == CONTENT_TYPE_CONTENT || $content_row['content_type'] == CONTENT_TYPE_WEBLINK) {
\r
695 $tool_shortcuts[] = array(
\r
696 'title' => _AT('delete_this_page'),
\r
697 'url' => $_base_href . 'home/editor/delete_content.php?_cid='.$content_row['content_id'],
\r
698 'icon' => $_base_href . 'images/page_delete.gif');
\r
700 else if ($content_row['content_type'] == CONTENT_TYPE_FOLDER) {
\r
701 $tool_shortcuts[] = array(
\r
702 'title' => _AT('add_sub_page'),
\r
703 'url' => $_base_href . 'home/editor/edit_content.php?_course_id='.$_course_id.SEP.'pid='.$content_row['content_id'],
\r
704 'icon' => $_base_href . 'images/add_sub_page.gif');
\r
706 $tool_shortcuts[] = array(
\r
707 'title' => _AT('delete_this_folder'),
\r
708 'url' => $_base_href . 'home/editor/delete_content.php?_cid='.$content_row['content_id'],
\r
709 'icon' => $_base_href . 'images/page_delete.gif');
\r
712 return $tool_shortcuts;
\r
714 // if (isset($_current_user) && $_current_user->isAuthor($_course_id)) {
\r
715 // $shortcuts[] = array('title' => _AT('add_sub_folder'), 'url' => $_base_href . 'home/editor/edit_content_folder.php?_course_id='.$_course_id.'pid='.$cid);
\r
717 //// $shortcuts[] = array('title' => _AT('add_top_page'), 'url' => $_base_href . 'home/editor/edit_content.php?_course_id='.$_course_id, 'icon' => $_base_href . 'images/page_add.gif');
\r
718 // if ($contentManager->_menu_info[$cid]['content_parent_id']) {
\r
719 // $shortcuts[] = array('title' => _AT('add_sibling_page'), 'url' => $_base_href .
\r
720 // 'home/editor/edit_content.php?_course_id='.$_course_id.SEP.'pid='.$contentManager->_menu_info[$cid]['content_parent_id'], 'icon' => $_base_href . 'images/page_add_sibling.gif');
\r
723 // $shortcuts[] = array('title' => _AT('add_sub_page'), 'url' => $_base_href . 'home/editor/edit_content.php?_course_id='.$_course_id.SEP.'pid='.$cid);
\r
724 // $shortcuts[] = array('title' => _AT('delete_this_folder'), 'url' => $_base_href . 'home/editor/delete_content.php?_cid='.$cid, 'icon' => $_base_href . 'images/page_delete.gif');
\r
729 * replace source object with alternatives according to user's preferences
\r
731 * @param $cid: content id.
\r
732 * @param $content: the original content page ($content_row['text'], from content.php).
\r
733 * @param $info_only: when "true", return the array of info (has_text_alternative, has_audio_alternative, has_visual_alternative, has_sign_lang_alternative)
\r
734 * @param $only_on_secondary_type:
\r
735 * @return string $content: the content page with the appropriated resources.
\r
736 * @see $db from include/vitals.inc.php
\r
737 * @author Cindy Qi Li
\r
739 public static function applyAlternatives($cid, $content, $info_only = false, $only_on_secondary_type = 0){
\r
740 global $db, $_course_id;
\r
742 include_once(TR_INCLUDE_PATH.'classes/DAO/DAO.class.php');
\r
745 // All a4a resources have "&" converted to "&". To match content with resources,
\r
746 // need the same conversion on content.
\r
747 $content = convertAmp($content);
\r
749 // keep < (content saved in plain text format) as it is instead of &lt;
\r
750 $content = str_replace('&lt;', '<', $content);
\r
752 $video_exts = array("mpg", "avi", "wmv", "mov", "swf", "mp4", "flv");
\r
754 $audio_exts = array("mp3", "wav", "ogg", "mid");
\r
755 $audio_width = 425;
\r
756 $audio_height = 27;
\r
758 $txt_exts = array("txt", "html", "htm");
\r
759 $image_exts = array("gif", "bmp", "png", "jpg", "jpeg", "png", "tif");
\r
760 $only_on_secondary_type = intval($only_on_secondary_type);
\r
762 // intialize the 4 returned values when $info_only is on
\r
765 $has_text_alternative = false;
\r
766 $has_audio_alternative = false;
\r
767 $has_visual_alternative = false;
\r
768 $has_sign_lang_alternative = false;
\r
771 if (!$info_only && !$only_on_secondary_type &&
\r
772 ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==0) &&
\r
773 ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO']==0) &&
\r
774 ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL']==0))
\r
776 //No user's preferences related to content format are declared
\r
780 return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative);
\r
783 // get all relations between primary resources and their alternatives
\r
784 $sql = "SELECT DISTINCT c.content_path, pr.resource, ";
\r
786 // ignore primary resource type if the request is on particular secondary type.
\r
787 // otherwise, if the primary resource is defined with multiple primary types,
\r
788 // the primary resource would be replaced/appended multiple times.
\r
789 if ($only_on_secondary_type == 0) {
\r
790 $sql .= "prt.type_id primary_type, ";
\r
792 $sql .= "sr.secondary_resource, srt.type_id secondary_type
\r
793 FROM ".TABLE_PREFIX."primary_resources pr, ".
\r
794 TABLE_PREFIX."primary_resources_types prt,".
\r
795 TABLE_PREFIX."secondary_resources sr,".
\r
796 TABLE_PREFIX."secondary_resources_types srt,".
\r
797 TABLE_PREFIX."content c
\r
798 WHERE pr.content_id=".$cid."
\r
799 AND pr.primary_resource_id = prt.primary_resource_id
\r
800 AND pr.primary_resource_id = sr.primary_resource_id
\r
801 AND sr.language_code='".$_SESSION['lang']."'
\r
802 AND sr.secondary_resource_id = srt.secondary_resource_id
\r
803 AND pr.content_id = c.content_id";
\r
804 if ($only_on_secondary_type > 0) {
\r
805 $sql .= " AND srt.type_id=".$only_on_secondary_type;
\r
807 $sql .= " ORDER BY pr.primary_resource_id, prt.type_id";
\r
809 $rows = $dao->execute($sql);
\r
811 if (!is_array($rows)) {
\r
815 return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative);
\r
819 foreach ($rows as $row) {
\r
820 $alternative_rows[] = $row;
\r
822 $youtube_playURL = ContentUtility::convertYoutubeWatchURLToPlayURL($row['resource']);
\r
824 if ($row['resource'] <> $youtube_playURL) {
\r
825 $row['resource'] = $youtube_playURL;
\r
826 $alternative_rows[] = $row;
\r
830 foreach ($alternative_rows as $row)
\r
832 if ($info_only || $only_on_secondary_type ||
\r
833 ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_TEXT']==1 && $row['primary_type']==3 &&
\r
834 ($_SESSION['prefs']['PREF_ALT_TO_TEXT']=="audio" && $row['secondary_type']==1 ||
\r
835 $_SESSION['prefs']['PREF_ALT_TO_TEXT']=="visual" && $row['secondary_type']==4 ||
\r
836 $_SESSION['prefs']['PREF_ALT_TO_TEXT']=="sign_lang" && $row['secondary_type']==2)) ||
\r
838 ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_AUDIO']==1 && $row['primary_type']==1 &&
\r
839 ($_SESSION['prefs']['PREF_ALT_TO_AUDIO']=="visual" && $row['secondary_type']==4 ||
\r
840 $_SESSION['prefs']['PREF_ALT_TO_AUDIO']=="text" && $row['secondary_type']==3 ||
\r
841 $_SESSION['prefs']['PREF_ALT_TO_AUDIO']=="sign_lang" && $row['secondary_type']==2)) ||
\r
843 ($_SESSION['prefs']['PREF_USE_ALTERNATIVE_TO_VISUAL']==1 && $row['primary_type']==4 &&
\r
844 ($_SESSION['prefs']['PREF_ALT_TO_VISUAL']=="audio" && $row['secondary_type']==1 ||
\r
845 $_SESSION['prefs']['PREF_ALT_TO_VISUAL']=="text" && $row['secondary_type']==3 ||
\r
846 $_SESSION['prefs']['PREF_ALT_TO_VISUAL']=="sign_lang" && $row['secondary_type']==2))
\r
849 $ext = substr($row['secondary_resource'], strrpos($row['secondary_resource'], '.')+1);
\r
851 // alternative is video
\r
852 if (in_array($ext, $video_exts)|| in_array($ext, $audio_exts) ||
\r
853 preg_match("/http:\/\/.*youtube.com\/watch.*/", $row['secondary_resource'])) {
\r
854 if (in_array($ext, $audio_exts)) {
\r
855 // display audio medias in a smaller width/height (425 * 27)
\r
856 // A hack for now to handle audio media player size
\r
857 $target = '[media|'.$audio_width.'|'.$audio_height.']'.$row['secondary_resource'].'[/media]';
\r
859 // use default media size for video medias
\r
860 $target = '[media]'.$row['secondary_resource'].'[/media]';
\r
862 $target = ContentUtility::embedFLV(ContentUtility::embedMedia($target));
\r
864 // a text primary to be replaced by a visual alternative
\r
865 else if (in_array($ext, $txt_exts))
\r
867 if ($row['content_path'] <> '')
\r
868 $file_location = $row['content_path'].'/'.$row['secondary_resource'];
\r
870 $file_location = $row['secondary_resource'];
\r
872 $file = TR_CONTENT_DIR.$_SESSION['course_id'] . '/'.$file_location;
\r
873 $target = '<br />'.file_get_contents($file);
\r
875 // check whether html file
\r
876 if (preg_match('/.*\<html.*\<\/html\>.*/s', $target))
\r
877 { // is a html file, use iframe to display
\r
878 // get real path to the text file
\r
879 if (defined('TR_FORCE_GET_FILE') && TR_FORCE_GET_FILE) {
\r
880 $course_base_href = 'get.php/';
\r
882 $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
\r
885 $file = TR_BASE_HREF . $course_base_href.$file_location;
\r
887 $target = '<iframe width="100%" frameborder="0" class="autoHeight" scrolling="auto" src="'.$file.'"></iframe>';
\r
890 { // is a text file, insert/replace into content
\r
891 $target = nl2br($target);
\r
894 else if (in_array($ext, $image_exts))
\r
895 $target = '<img border="0" alt="'._AT('alternate_text').'" src="'.$row['secondary_resource'].'"/>';
\r
898 $target = '<p><a href="'.$row['secondary_resource'].'">'.$row['secondary_resource'].'</a></p>';
\r
900 // replace or append the target alternative to the source
\r
901 if (($row['primary_type']==3 && $_SESSION['prefs']['PREF_ALT_TO_TEXT_APPEND_OR_REPLACE'] == 'replace') ||
\r
902 ($row['primary_type']==1 && $_SESSION['prefs']['PREF_ALT_TO_AUDIO_APPEND_OR_REPLACE']=='replace') ||
\r
903 ($row['primary_type']==4 && $_SESSION['prefs']['PREF_ALT_TO_VISUAL_APPEND_OR_REPLACE']=='replace'))
\r
904 $pattern_replace_to = '${1}'."\n".$target."\n".'${3}';
\r
906 $pattern_replace_to = '${1}${2}'."<br /><br />\n".$target."\n".'${3}';
\r
908 // *** Alternative replace/append starts from here ***
\r
909 $processed = false; // one primary resource is only processed once
\r
911 // append/replace target alternative to [media]source[/media]
\r
912 if (!$processed && preg_match("/".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/")."/sU", $content))
\r
916 $content = preg_replace("/(.*)(".preg_quote("[media").".*".preg_quote("]".$row['resource']."[/media]", "/").")(.*)/sU",
\r
917 $pattern_replace_to, $content);
\r
919 if ($row['secondary_type'] == 1) $has_audio_alternative = true;
\r
920 if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
\r
921 if ($row['secondary_type'] == 3) $has_text_alternative = true;
\r
922 if ($row['secondary_type'] == 4) $has_visual_alternative = true;
\r
926 // append/replace target alternative to <img ... src="source" ...></a>
\r
927 if (!$processed && preg_match("/\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>/sU", $content))
\r
931 $content = preg_replace("/(.*)(\<img.*src=\"".preg_quote($row['resource'], "/")."\".*\/\>)(.*)/sU",
\r
932 $pattern_replace_to, $content);
\r
934 if ($row['secondary_type'] == 1) $has_audio_alternative = true;
\r
935 if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
\r
936 if ($row['secondary_type'] == 3) $has_text_alternative = true;
\r
937 if ($row['secondary_type'] == 4) $has_visual_alternative = true;
\r
941 // append/replace target alternative to <object ... source ...></object>
\r
942 if (!$processed && preg_match("/\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>/sU", $content))
\r
946 $content = preg_replace("/(.*)(\<object.*".preg_quote($row['resource'], "/").".*\<\/object\>)(.*)/sU",
\r
947 $pattern_replace_to, $content);
\r
949 if ($row['secondary_type'] == 1) $has_audio_alternative = true;
\r
950 if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
\r
951 if ($row['secondary_type'] == 3) $has_text_alternative = true;
\r
952 if ($row['secondary_type'] == 4) $has_visual_alternative = true;
\r
956 // append/replace target alternative to <a>...source...</a> or <a ...source...>...</a>
\r
957 // skip this "if" when the source object has been processed in aboved <img> tag
\r
958 if (!$processed && preg_match("/\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>/sU", $content))
\r
962 $content = preg_replace("/(.*)(\<a.*".preg_quote($row['resource'], "/").".*\<\/a\>)(.*)/sU",
\r
963 $pattern_replace_to, $content);
\r
965 if ($row['secondary_type'] == 1) $has_audio_alternative = true;
\r
966 if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
\r
967 if ($row['secondary_type'] == 3) $has_text_alternative = true;
\r
968 if ($row['secondary_type'] == 4) $has_visual_alternative = true;
\r
972 // append/replace target alternative to <embed ... source ...>
\r
973 if (!$processed && preg_match("/\<embed.*".preg_quote($row['resource'], "/").".*\>/sU", $content))
\r
977 $content = preg_replace("/(.*)(\<embed.*".preg_quote($row['resource'], "/").".*\>)(.*)/sU",
\r
978 $pattern_replace_to, $content);
\r
980 if ($row['secondary_type'] == 1) $has_audio_alternative = true;
\r
981 if ($row['secondary_type'] == 2) $has_sign_lang_alternative = true;
\r
982 if ($row['secondary_type'] == 3) $has_text_alternative = true;
\r
983 if ($row['secondary_type'] == 4) $has_visual_alternative = true;
\r
992 return array($has_text_alternative, $has_audio_alternative, $has_visual_alternative, $has_sign_lang_alternative);
\r
997 * This function save the last content_id accessed by current user on a course into db and set $_SESSION['s_cid']
\r
999 * @param: $content_id
\r
1000 * @return: save $content_id, the last visited one of the current user, into db and session
\r
1002 public static function saveLastCid($content_id)
\r
1004 global $_course_id;
\r
1006 if (!$content_id || !isset($_SESSION['user_id'])) return;
\r
1008 include_once(TR_INCLUDE_PATH.'classes/DAO/UserCoursesDAO.class.php');
\r
1010 $userCoursesDAO = new UserCoursesDAO();
\r
1011 if ($userCoursesDAO->isExist($_SESSION['user_id'], $_course_id))
\r
1013 $userCoursesDAO->UpdateLastCid($_SESSION['user_id'], $_course_id, $content_id);
\r
1014 $_SESSION['s_cid'] = $content_id;
\r