prepareActivityDirectory($exportDir, 'url', $effectiveModuleId); $urlData = $this->getData((int) $activityId, (int) $sectionId, $effectiveModuleId); if (empty($urlData)) { return; } $this->createUrlXml($urlData, $urlDir); $this->createModuleXml($urlData, $urlDir); $this->createGradesXml($urlData, $urlDir); $this->createGradeHistoryXml($urlData, $urlDir); $this->createInforefXml($urlData, $urlDir); $this->createRolesXml($urlData, $urlDir); $this->createCommentsXml($urlData, $urlDir); $this->createCalendarXml($urlData, $urlDir); $this->createFiltersXml($urlData, $urlDir); } /** * Get URL data for the course. */ public function getData(int $activityId, int $sectionId): ?array { $url = $this->course->resources['link'][$activityId] ?? null; if (null === $url) { return [ 'id' => $activityId, 'moduleid' => $activityId, 'modulename' => 'url', 'contextid' => (int) ($this->course->info['real_id'] ?? 0), 'name' => 'URL '.$activityId, 'description' => '', 'externalurl' => '', 'display' => 6, 'displayoptions' => $this->buildUrlDisplayOptions(), 'timecreated' => time(), 'timemodified' => time(), 'sectionid' => $sectionId, 'sectionnumber' => 0, 'users' => [], 'files' => [], ]; } $src = isset($url->obj) ? $url->obj : $url; return [ 'id' => (int) $activityId, 'moduleid' => (int) $activityId, 'modulename' => 'url', 'contextid' => (int) $this->course->info['real_id'], 'name' => (string) ($src->title ?: $src->url), 'description' => (string) ($src->description ?? ''), 'externalurl' => (string) $src->url, 'display' => 6, 'displayoptions' => $this->buildUrlDisplayOptions(), 'timecreated' => time(), 'timemodified' => time(), 'sectionid' => $sectionId, 'sectionnumber' => 0, 'users' => [], 'files' => [], ]; } /** * Create the XML file for the URL. */ private function createUrlXml(array $urlData, string $urlDir): void { $xml = ''.PHP_EOL; $xml .= ''.PHP_EOL; $xml .= ' '.PHP_EOL; $xml .= ' '.htmlspecialchars((string) $urlData['name']).''.PHP_EOL; $xml .= ' '.PHP_EOL; $xml .= ' 1'.PHP_EOL; $xml .= ' '.htmlspecialchars((string) $urlData['externalurl']).''.PHP_EOL; $xml .= ' '.(int) ($urlData['display'] ?? 6).''.PHP_EOL; $xml .= ' '.htmlspecialchars((string) ($urlData['displayoptions'] ?? 'a:0:{}')).''.PHP_EOL; $xml .= ' a:0:{}'.PHP_EOL; $xml .= ' '.(int) $urlData['timemodified'].''.PHP_EOL; $xml .= ' '.PHP_EOL; $xml .= ''.PHP_EOL; $this->createXmlFile('url', $xml, $urlDir); } /** * Build a stable embedded file id for URL intro files. */ private function buildUrlEmbeddedFileId(int $moduleId, int $sequence): int { return 1200000000 + max(0, $moduleId) + max(1, $sequence); } private function buildUrlDisplayOptions(): string { return serialize([ 'popupwidth' => 1024, 'popupheight' => 768, ]); } }