|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SitemapProvider Images |
|
4
|
|
|
* |
|
5
|
|
|
* @author Ercüment Topal <[email protected]> |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace FRUIT\GoogleServices\Service\SitemapProvider; |
|
9
|
|
|
|
|
10
|
|
|
use FRUIT\GoogleServices\Controller\SitemapController; |
|
11
|
|
|
use FRUIT\GoogleServices\Domain\Model\Node; |
|
12
|
|
|
use FRUIT\GoogleServices\Domain\Model\Node\ImageNode; |
|
13
|
|
|
use FRUIT\GoogleServices\Service\SitemapDataService; |
|
14
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
|
15
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class Images |
|
19
|
|
|
* |
|
20
|
|
|
* @author Ercüment Topal <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class FalImages extends Pages |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Resource factory to build objects |
|
27
|
|
|
* |
|
28
|
|
|
* @var \TYPO3\CMS\Core\Resource\ResourceFactory |
|
29
|
|
|
* @inject |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $resourceFactory; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Page repository for manipulate the SQL queries |
|
35
|
|
|
* |
|
36
|
|
|
* @var \TYPO3\CMS\Frontend\Page\PageRepository |
|
37
|
|
|
* @inject |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $pageRepository; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get the records |
|
43
|
|
|
* |
|
44
|
|
|
* @param int $startPage |
|
45
|
|
|
* @param array $basePages |
|
46
|
|
|
* @param SitemapController $obj |
|
47
|
|
|
* |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getRecords($startPage, $basePages, SitemapController $obj): array |
|
51
|
|
|
{ |
|
52
|
|
|
$nodes = []; |
|
53
|
|
|
foreach ($basePages as $uid) { |
|
54
|
|
|
$images = $this->getImagesByPages([$uid]); |
|
55
|
|
|
if (!sizeof($images)) { |
|
56
|
|
|
continue; |
|
57
|
|
|
} |
|
58
|
|
|
$imageNodes = []; |
|
59
|
|
|
foreach ($images as $imageReference) { |
|
60
|
|
|
/** @var $imageReference \TYPO3\CMS\Core\Resource\FileReference */ |
|
61
|
|
|
$url = GeneralUtility::getIndpEnv('TYPO3_REQUEST_HOST') . '/' . $imageReference->getOriginalFile() |
|
62
|
|
|
->getPublicUrl(); |
|
63
|
|
|
|
|
64
|
|
|
// Build Node |
|
65
|
|
|
$nodeImage = new ImageNode(); |
|
66
|
|
|
$nodeImage->setLoc($url); |
|
67
|
|
|
$nodeImage->setTitle($imageReference->getTitle()); |
|
68
|
|
|
$nodeImage->setCaption($imageReference->getDescription()); |
|
69
|
|
|
$imageNodes[] = $nodeImage; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// Build URL |
|
73
|
|
|
$url = $obj->getUriBuilder() |
|
74
|
|
|
->setTargetPageUid($uid) |
|
75
|
|
|
->build(); |
|
76
|
|
|
|
|
77
|
|
|
// can't generate a valid url |
|
78
|
|
|
if (!strlen($url)) { |
|
79
|
|
|
continue; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
// Get Record |
|
83
|
|
|
$record = BackendUtility::getRecord('pages', $uid); |
|
84
|
|
|
|
|
85
|
|
|
// exclude Doctypes |
|
86
|
|
|
if (in_array($record['doktype'], [4])) { |
|
87
|
|
|
continue; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
// Build Node |
|
91
|
|
|
$node = new Node(); |
|
92
|
|
|
$node->setLoc($url); |
|
93
|
|
|
$node->setPriority($this->getPriority($startPage, $record)); |
|
94
|
|
|
$node->setChangefreq(SitemapDataService::mapTimeout2Period($record['cache_timeout'])); |
|
95
|
|
|
$node->setLastmod($this->getModifiedDate($record)); |
|
96
|
|
|
$node->setImages($imageNodes); |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$nodes[] = $node; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $nodes; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get alle images on the given pages |
|
107
|
|
|
* |
|
108
|
|
|
* @param array $pages |
|
109
|
|
|
* |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
|
protected function getImagesByPages(array $pages) |
|
113
|
|
|
{ |
|
114
|
|
|
$images = []; |
|
115
|
|
|
|
|
116
|
|
|
if (!sizeof($pages)) { |
|
117
|
|
|
return $images; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$enabledFields = $this->pageRepository->enableFields('sys_file_reference'); |
|
121
|
|
|
$enabledFields .= $this->pageRepository->enableFields('tt_content'); |
|
122
|
|
|
$enabledFields .= $this->pageRepository->enableFields('pages'); |
|
123
|
|
|
|
|
124
|
|
|
$database = $this->getDatabaseConnection(); |
|
125
|
|
|
$rows = $database->exec_SELECTgetRows( |
|
126
|
|
|
'sys_file_reference.*', |
|
127
|
|
|
'sys_file_reference, tt_content, pages', |
|
128
|
|
|
'sys_file_reference.tablenames=' . $database->fullQuoteStr( |
|
129
|
|
|
'tt_content', |
|
130
|
|
|
'sys_file_reference' |
|
131
|
|
|
) . ' AND sys_file_reference.fieldname=' . $database->fullQuoteStr( |
|
132
|
|
|
'image', |
|
133
|
|
|
'sys_file_reference' |
|
134
|
|
|
) . ' AND sys_file_reference.uid_foreign=tt_content.uid AND tt_content.pid=pages.uid AND pages.uid IN (' . implode( |
|
135
|
|
|
',', |
|
136
|
|
|
$pages |
|
137
|
|
|
) . ') ' . $enabledFields |
|
138
|
|
|
); |
|
139
|
|
|
|
|
140
|
|
|
foreach ($rows as $row) { |
|
|
|
|
|
|
141
|
|
|
$images[] = $this->resourceFactory->getFileReferenceObject($row['uid'], $row); |
|
142
|
|
|
} |
|
143
|
|
|
return $images; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Get the database connection |
|
148
|
|
|
* |
|
149
|
|
|
* @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
150
|
|
|
*/ |
|
151
|
|
|
protected function getDatabaseConnection() |
|
152
|
|
|
{ |
|
153
|
|
|
return $GLOBALS['TYPO3_DB']; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.