public static function scan($url, $currentFolderDepth) { // debug : echo getRequest("https://docs.google.com/feeds/default/private/full?prettyprint=true"); $result = Connection::getRequest($url); //."?prettyprint=true" $folderContent = simplexml_load_string(str_replace('gd:etag', 'etag', $result)); $foldersArray = array(); $pagesArray = array(); // foldersArray: key:name => value:sub-folder // pagesArray: key:menu_position => value:name foreach ($folderContent->entry as $file) { $type = (string) $file->content['type']; $name = (string) $file->title; $name = str_replace('"', '\\"', str_replace('$', '\\$', $name)); $srcUrl = (string) $file->content['src']; $lastModified = (string) $file->updated; $etag = (string) $file['etag']; $path = $currentFolderDepth . ($currentFolderDepth == '' ? '' : '/') . StringTools::urlFormat(StringTools::indexClean($name)); $isNew = LAST_UPDATE_DATE < $lastModified; if ($type == 'application/atom+xml;type=feed') { if (!is_dir($path)) { Output::createFolder($path); Output::println("Folder: {$path}"); } $foldersArray[$name . '!$!'] = self::scan($srcUrl, $path); // Recursively store the sub folder. } else { if (substr($srcUrl, 0, strlen('https://docs.g')) == 'https://docs.g') { $pagesArray[] = $name . '!$!'; // !$! is a end of name protection. It's removed in StringTools::serializeForInclude() Output::println("Page: {$path}"); PageDownloader::download($srcUrl, $etag, $path . '.php'); } else { if ($isNew || !file_exists($path)) { Output::store(Connection::getRequest($srcUrl), $path); Output::println("File: {$path}"); } } } } // Sort folders and pages by name ksort($foldersArray); sort($pagesArray); // Remove indexes foreach ($foldersArray as $key => $value) { $cleanKey = StringTools::indexClean($key); if ($key != $cleanKey) { $foldersArray[$cleanKey] = $foldersArray[$key]; unset($foldersArray[$key]); } } foreach ($pagesArray as $key => $value) { $cleanValue = StringTools::indexClean($pagesArray[$key]); $pagesArray[$key] = $cleanValue; } return array('folders' => $foldersArray, 'pages' => $pagesArray); }