changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / include / classes / ATOC_ServerFiles.php
1 <?php\r
2 /****************************************************************/\r
3 /* Atutor-OpenCaps Module                                               \r
4 /****************************************************************/\r
5 /* Copyright (c) 2010                           \r
6 /* Written by Antonio Gamba                                             \r
7 /* Adaptive Technology Resource Centre / University of Toronto\r
8 /*\r
9 /* This program is free software. You can redistribute it and/or\r
10 /* modify it under the terms of the GNU General Public License\r
11 /* as published by the Free Software Foundation.\r
12 /****************************************************************/\r
13 \r
14 class ServerFiles\r
15 {\r
16         \r
17         /**\r
18          * @desc directoryToArray\r
19          * @param String $directory\r
20          * @param bool $recursive\r
21          * @return Array\r
22          */\r
23         public function directoryToArray($directory, $recursive) \r
24         {\r
25                 global $ocAtSettings;\r
26                 \r
27                 $rex = '/^.*\.('.$ocAtSettings['supportedMedia'].')$/i';\r
28                 $sep = '\\';\r
29                 $array_items = array();\r
30                 if ($handle = opendir($directory)) {\r
31                         while (false !== ($file = readdir($handle))) {\r
32                                 if ($file != "." && $file != "..") {\r
33                                         if (is_dir($directory. $sep . $file)) {\r
34                                                 if($recursive) \r
35                                                 {\r
36                                                         $array_items = array_merge($array_items,$this->directoryToArray($directory. $sep . $file, $recursive));\r
37                                                 }\r
38                                                 //add if add only known files\r
39                                                 if (preg_match($rex, $file))\r
40                                                 {\r
41                                                         //$file = $directory . $sep . $file;\r
42                                                         $array_items[] = preg_replace("/\/\//si", $sep, $file);\r
43                                                         //echo '<br/>'.$file;   \r
44                                                 }\r
45                                                 \r
46                                         } else {\r
47                                                 if (preg_match($rex, $file))\r
48                                                 {\r
49                                                         $file = $directory . $sep . $file;\r
50                                                         //$file = $sep . $file;\r
51                                                         $file = str_replace(AT_CONTENT_DIR.''.$_SESSION['course_id'].$sep, '', $file);\r
52                                                         $file = str_replace('\\', '/', $file);\r
53                                                         $array_items[] = preg_replace("/\/\//si", $sep, $file);\r
54                                                         //echo '<br/>'.$file;   \r
55                                                 }\r
56                                         }\r
57                                 }\r
58                         }\r
59                         closedir($handle);\r
60                 }\r
61                 return $array_items;\r
62         } // end directoryToArray\r
63         \r
64 } // end class ServerFiles\r
65 ?>\r