changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / conversion_service / include / classes / ccformats / cc_JSONcc_format.php
1 <?php\r
2 /**\r
3  * JSONcc Class\r
4  */\r
5 class JSONcc extends CaptionFormat\r
6 {\r
7         /**\r
8          * Imports a caption string into a CaptionCollection \r
9          *\r
10          * @param String $theCCString the caption file as string\r
11          * @return CaptionCollection $myCcCollection A CaptionCollection Object\r
12          */\r
13         public function importCC($theJsonString)\r
14         {               \r
15                 $theCcArray = json_decode($theJsonString,true);\r
16                 \r
17                 // Create a Caption Collection Object\r
18                 $theCollection = new CaptionCollection();\r
19         \r
20                 // set all global text styles using JSON-decoded array ???????\r
21                 $theCollection->setTxtStylesGlobal($theCcArray['global_caption_styles']);\r
22 \r
23                 // check if there are captions in the captionCollection array and then add them to the Collection\r
24                 if (count($theCcArray['clip_collection']['clips'])!=0 )\r
25                 {                       \r
26                         foreach ($theCcArray['clip_collection']['clips'] as $CapArray)\r
27                         {\r
28                                 // create a Caption Object\r
29                                 $newCaptionObj = new Caption($CapArray['inTime'],$CapArray['outTime'],$CapArray['caption_text'],$CapArray['caption_styles']);\r
30                                                                 \r
31                                 // add caption object to the CaptionCollection \r
32                                 $theCollection->addCaption($newCaptionObj);\r
33                         } // end foreach        \r
34                 }// end if\r
35                                 \r
36                 return $theCollection; \r
37                 \r
38         } // end importCC()\r
39         \r
40         \r
41         /**\r
42          * Exports a CaptionCollection object into a string\r
43          *\r
44          * @param CaptionCollection $theCollection A CaptionCollection Object\r
45          * @return String $captionString The caption as a String\r
46          */\r
47         public function exportCC($theCollection)\r
48         {\r
49                 $ccExport = '';\r
50   \r
51                 // Use php built-in json encoder\r
52                 $ccExport = json_encode($theCollection);\r
53 \r
54                 return $ccExport;\r
55                 \r
56         } // end  exportCC()\r
57         \r
58         /**\r
59          * Verify if the caption file is a JSON caption file \r
60         */\r
61         public function checkFormat($theCCString)\r
62         {\r
63                 \r
64         } // end checkFormat()\r
65 \r
66         /*\r
67          * Here functions to re-define\r
68          */\r
69         public function getName()\r
70         {\r
71                 return 'JSON';\r
72         }\r
73         \r
74         public function getAbout()\r
75         {\r
76                 return 'JSON is a data representation model + much more. Captions can be played on any browser/OS using JavaScrinpt. However, plaing the video/audio binary files will require additional plugins such as QuickTime, Windows Media Player, etc... in order to load in a browser ';\r
77         }\r
78         \r
79         public function getVersion()\r
80         {\r
81                 return '1.0';\r
82         }\r
83                 \r
84         public function getFileExtension()\r
85         {\r
86                 return 'JSON';\r
87         }\r
88         \r
89         public function getIdPattern()\r
90         {\r
91                 //$idPattern = '/(.*)/'; // match any pattern\r
92                 $idPattern = '/"clips":\[/'; \r
93                 \r
94                 \r
95                 return $idPattern;\r
96         }\r
97 \r
98         public function allowsTextStyles()\r
99         {\r
100                 return '1';\r
101         }\r
102         \r
103         public function template()\r
104         {\r
105                 $ccTemplate = '';\r
106                 \r
107                 return $ccTemplate;\r
108         }\r
109 \r
110         \r
111         \r
112 } // end CCJSON Class\r
113 ?>