(no commit message)
[atutor.git] / mods / _standard / flowplayer / module_format_content.php
1 <?php
2 // input string. DO NOT CHANGE.
3 global $_input, $_content_base_href;
4
5 //Output for flowplayer module.
6 $media_replace = array();
7 $media_matches = array();
8 $flowplayerholder_class = "atutor.flowplayerholder";  // style class used to play flowplayer medias
9 $flowplayerholder_def = '$f("*.'.$flowplayerholder_class.'"';   // javascript definition for atutor.flowplayerholder 
10
11 // .flv
12 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+)\.flv\[/media\]#i",$_input,$media_matches[],PREG_SET_ORDER);
13 $media_replace[] ="<object>\n".
14                   "  <div>\n".
15                   "    <a class=\"".$flowplayerholder_class."\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"##MEDIA1##.flv\"></a>\n".
16                   "  </div>\n".
17                   "  <div style=\"margin-top:-2em;\">\n".
18                   "    <a href=\"##MEDIA1##.flv\">##MEDIA1##.flv</a>\n".
19                   "  </div>\n".
20                   "</object>";
21
22 // .mp4
23 preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+)\.mp4\[/media\]#i",$_input,$media_matches[],PREG_SET_ORDER);
24 //$media_replace[] ="<a class=\"".$flowplayerholder_class."\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".AT_BASE_HREF."get.php/".$_content_base_href."##MEDIA1##.mp4\"></a>";
25 $media_replace[] ="<object>\n".
26                   "  <div>\n".
27                   "    <a class=\"".$flowplayerholder_class."\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"##MEDIA1##.mp4\"></a>\n".
28                   "  </div>\n".
29                   "  <div style=\"margin-top:-3em;\">\n".
30                   "    <a href=\"##MEDIA1##.mp4\">##MEDIA1##.mp4</a>\n".
31                   "  </div>\n".
32                   "</object>";
33
34 //// .mov
35 //preg_match_all("#\[media[0-9a-z\|]*\]([.\w\d]+[^\s\"]+)\.mov\[/media\]#i",$_input,$media_matches[],PREG_SET_ORDER);
36 //$media_replace[] ="<a class=\"".$flowplayerholder_class."\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".AT_BASE_HREF."get.php/".$_content_base_href."##MEDIA1##.mov\"></a>";
37 //
38 //// .mp3
39 //preg_match_all("#\[media[0-9a-z\|]*\](.+[^\s\"]+)\.mp3\[/media\]#i",$_input,$media_matches[],PREG_SET_ORDER);
40 //$media_replace[] ="<a class=\"".$flowplayerholder_class."\" style=\"display:block;width:##WIDTH##px;height:##HEIGHT##px;\" href=\"".AT_BASE_HREF."get.php/".$_content_base_href."##MEDIA1##.mp3\"></a>";
41
42 // Executing the replace
43 for ($i=0;$i<count($media_replace);$i++){
44         foreach($media_matches[$i] as $media)
45         {
46                 //find width and height for each matched media
47                 if (preg_match("/\[media\|([0-9]*)\|([0-9]*)\]*/", $media[0], $matches)) 
48                 {
49                         $width = $matches[1];
50                         $height = $matches[2];
51                 }
52                 else
53                 {
54                         $width = 425;
55                         $height = 350;
56                 }
57                 
58                 //replace media tags with embedded media for each media tag
59                 $media_input = $media_replace[$i];
60                 $media_input = str_replace("##WIDTH##","$width",$media_input);
61                 $media_input = str_replace("##HEIGHT##","$height",$media_input);
62                 $media_input = str_replace("##MEDIA1##","$media[1]",$media_input);
63                 $media_input = str_replace("##MEDIA2##","$media[2]",$media_input);
64                 $_input = str_replace($media[0],$media_input,$_input);
65         }
66 }
67
68 // Include the javascript only if:
69 // 1. $flowplayerholder_class is used but not defined
70 // 2. exclude from export common cartridge or content package
71 if (strpos($_input, $flowplayerholder_class) 
72     && !strpos($_input, $flowplayerholder_def)
73     && !strpos($_SERVER['PHP_SELF'], "ims_export.php"))
74 {
75         $_input .= '<script type="text/javascript">
76 '.$flowplayerholder_def.', "'.AT_BASE_HREF.'mods/_standard/flowplayer/flowplayer-3.2.4.swf", { 
77   clip: { 
78   autoPlay: false,
79   baseUrl: \''.AT_BASE_HREF.'get.php/'.$_content_base_href.'\'},
80   plugins:  { 
81     controls: { 
82       buttons:true, 
83       play: true,  
84       scrubber: true, 
85       autoHide:false
86     }         
87   }
88 });
89 </script>'."\n";
90 }
91 ?>