2 namespace TYPO3\CMS\Documentation\Domain\Repository;
44 $documents = $this->findSphinxDocuments();
45 $openOfficeDocuments = $this->findOpenOfficeDocuments();
48 foreach ($openOfficeDocuments as $documentKey => $document) {
49 if (!isset($documents[$documentKey])) {
50 $documents[$documentKey] = $document;
63 public function findByLanguage($language)
65 $allDocuments = $this->
findAll();
68 $languageDependencies = array();
72 $shortLanguage = $language;
73 if (!in_array($shortLanguage,
$locales->getLocales()) && strpos($shortLanguage,
'_') !==
false) {
74 list($shortLanguage, $_) = explode(
'_', $shortLanguage);
76 if (in_array($shortLanguage,
$locales->getLocales())) {
77 $languageDependencies[] = $language;
78 if ($language !== $shortLanguage) {
79 $languageDependencies[] = $shortLanguage;
81 foreach (
$locales->getLocaleDependencies($shortLanguage) as $languageDependency) {
82 $languageDependencies[] = $languageDependency;
85 if ($language !==
'default') {
86 $languageDependencies[] =
'default';
89 foreach ($allDocuments as $document) {
91 $selectedTranslation = null;
92 $highestPriorityLanguageIndex = count($languageDependencies);
94 $translations = $document->getTranslations();
95 foreach ($translations as $translation) {
96 $languageIndex = array_search($translation->getLanguage(), $languageDependencies);
97 if ($languageIndex !==
false) {
98 if ($languageIndex < $highestPriorityLanguageIndex) {
99 $selectedTranslation = $translation;
100 $highestPriorityLanguageIndex = $languageIndex;
105 if (strpos($translation->getLanguage(),
'_') !==
false) {
106 list($translationLanguage, $_) = explode(
'_', $translation->getLanguage());
107 $languageIndex = array_search($translationLanguage, $languageDependencies);
108 if ($languageIndex !==
false && $languageIndex < $highestPriorityLanguageIndex) {
109 $selectedTranslation = $translation;
110 $highestPriorityLanguageIndex = $languageIndex;
116 $newTranslations = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
117 $document->setTranslations($newTranslations);
118 if ($selectedTranslation !== null) {
119 $document->addTranslation($selectedTranslation);
123 return $allDocuments;
131 protected function findSphinxDocuments()
133 $basePath =
'typo3conf/Documentation/';
135 $documents = array();
138 if (!is_array($documentKeys)) {
142 foreach ($documentKeys as $documentKey) {
143 $icon = \TYPO3\CMS\Documentation\Utility\MiscUtility::getIcon($documentKey);
146 $document = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\Document::class)
147 ->setPackageKey($documentKey)
150 $languagePath = $basePath . $documentKey .
'/';
152 foreach ($languages as $language) {
153 $metadata = $this->
getMetadata($documentKey, $language);
154 if (!empty($metadata[
'extensionKey'])) {
155 $document->setExtensionKey($metadata[
'extensionKey']);
159 $documentTranslation = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation::class)
160 ->setLanguage($language)
161 ->setTitle($metadata[
'title'])
162 ->setDescription($metadata[
'description']);
164 $formatPath = $languagePath . $language .
'/';
166 foreach ($formats as $format) {
171 $indexFiles = array(
'Index.html',
'index.html',
'index.htm');
172 foreach ($indexFiles as $indexFile) {
173 if (file_exists(PATH_site . $formatPath . $format .
'/' . $indexFile)) {
174 $documentFile = $indexFile;
182 if (is_array($files) && !empty($files)) {
183 $documentFile = current($files);
187 if (!empty($documentFile)) {
189 $documentFormat = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentFormat::class)
191 ->setPath($formatPath . $format .
'/' . $documentFile);
193 $documentTranslation->addFormat($documentFormat);
197 if (!empty($documentTranslation->getFormats())) {
198 $document->addTranslation($documentTranslation);
199 $documents[$documentKey] = $document;
212 protected function findOpenOfficeDocuments()
214 $documents = array();
215 $language =
'default';
217 foreach (
$GLOBALS[
'TYPO3_LOADED_EXT'] as $extensionKey => $extensionData) {
218 $path = $extensionData[
'siteRelPath'] .
'doc/';
219 if (is_file(PATH_site . $path .
'manual.sxw')) {
220 $documentKey =
'typo3cms.extensions.' . $extensionKey;
221 $icon = \TYPO3\CMS\Documentation\Utility\MiscUtility::getIcon($documentKey);
224 $document = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\Document::class)
225 ->setPackageKey($documentKey)
226 ->setExtensionKey($extensionKey)
229 $metadata = $this->
getMetadata($documentKey, $language);
231 $documentTranslation = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation::class)
232 ->setLanguage($language)
233 ->setTitle($metadata[
'title'])
234 ->setDescription($metadata[
'description']);
237 $documentFormat = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentFormat::class)
239 ->setPath($path .
'manual.sxw');
241 $documentTranslation->addFormat($documentFormat);
242 $document->addTranslation($documentTranslation);
243 $documents[$documentKey] = $document;
259 $documentPath = PATH_site .
'typo3conf/Documentation/' . $documentKey .
'/' . $language .
'/';
261 'title' => $documentKey,
265 $extensionKey = substr($documentKey, 20);
266 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extensionKey)) {
267 $metadata = \TYPO3\CMS\Documentation\Utility\MiscUtility::getExtensionMetaData($extensionKey);
269 }
elseif (is_file($documentPath .
'composer.json')) {
270 $info = json_decode(file_get_contents($documentPath .
'composer.json'),
true);
271 if (is_array($info)) {
272 $metadata[
'title'] = $info[
'name'];
273 $metadata[
'description'] = $info[
'description'];