changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / conversion_service / include / classes / static_TxtFileTools_class.php
1 <?php\r
2 class TxtFileTools\r
3 {\r
4 \r
5 \r
6         /**\r
7          * Saves a String into a file and return the file URL\r
8          *\r
9          * @param String $theFileName The file Name\r
10          * @param String $theString The value to save as a String\r
11          * @return String $fullFileUrl The full path of where file is saved  \r
12          */\r
13         static public function stringToFile($theFileName, $theString) \r
14         {\r
15                 global $rosettaCCSettings;\r
16                 \r
17                 $fullFileUrl = $rosettaCCSettings['uploadDir'].'/'.$theFileName;\r
18                 \r
19                 // save file to disk \r
20                 file_put_contents($fullFileUrl, $theString);\r
21                 \r
22                         //echo '<br/><br/>Target Caption File saved in: <b>'.$theFileName.'</b> <a href="'.$fullFileUrl.'"> [Download Caption]</a>';\r
23                 \r
24                 return $fullFileUrl;\r
25                 \r
26         } // stringToFile\r
27 \r
28         /**\r
29          * Loads a Caption File and return it as String\r
30          * @param $theFileName The full URL of the file\r
31          * @return $ccString The caption file as String\r
32          */\r
33         static public function fileToString($theFileName) \r
34         {\r
35                 global $rosettaCCSettings;\r
36                 \r
37                 $ccString = file_get_contents($rosettaCCSettings['uploadDir'].'/'.$theFileName);\r
38                 \r
39                 /*\r
40           clean malformed pattern for ANSI files:\r
41           This is harmless for any well formed caption.\r
42           fixing captions saved in win notepad\r
43         */\r
44         $toSearch = array(chr(13).chr(10));\r
45         $toReplace = array(chr(10));\r
46         $contents = str_replace($toSearch,$toReplace,$ccString);\r
47         \r
48         return $ccString;\r
49         }       \r
50 \r
51         /**\r
52          * Forces a browser to download a file stored in the server \r
53          * @param $exfile The full URL of the file\r
54          */\r
55         static public function downloadFile($exfile) \r
56         {\r
57                 // verify if the file exists\r
58                 if (file_exists($exfile)) \r
59                 {\r
60                         header('Content-Description: File Transfer');\r
61                         header('Content-Type: application/octet-stream');\r
62                         header('Content-Disposition: attachment; filename='.basename($exfile));\r
63                         header('Content-Transfer-Encoding: binary');\r
64                         header('Expires: 0');\r
65                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');\r
66                         header('Pragma: public');\r
67                         header('Content-Length: ' . filesize($exfile));\r
68                         //header("Content-type: $type"); ????????\r
69                         ob_clean();\r
70                         flush();\r
71                         readfile($exfile);\r
72                         exit;\r
73                         \r
74                 } // end if\r
75                 \r
76         } // end downloadFile() \r
77 \r
78         /**\r
79          * Replaces all <br/> tags in a string with chr(10) characters\r
80          *\r
81          * @param String $theHtmlString The string containign <br> HTML tags \r
82          * @return unknown\r
83          */\r
84         static public function ccBrToNewLine($theHtmlString)\r
85         {\r
86                 $a = array(chr(10));\r
87                 $b = array('<br>','<BR>','<br/>','<BR/>' );\r
88                 $stringWithBreakLines = str_replace($a, $b, $theHtmlString);\r
89                 return $stringWithBreakLines;\r
90         }\r
91 \r
92         /**\r
93          * Replaces the break line character "char(10)" by a specified character \r
94          *\r
95          * @param String $theCaption The caption containing char(10) characters as line separators \r
96          * @param char $theChar The String used to replace the break line character\r
97          * @return unknown\r
98          */static public function ccNewLineToBr($theCaption, $theChar)\r
99         {\r
100                 $a = ''.chr(10);\r
101                 $b = $theChar;\r
102                 $newString = str_replace($a, $b, $theCaption);\r
103                 return $newString;\r
104         }\r
105         \r
106 } // end class TxtFileTools\r
107 ?>