1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Get data for focuspoint. |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
namespace HDNET\Focuspoint\Hooks; |
8
|
|
|
|
9
|
|
|
use HDNET\Autoloader\Annotation\Hook; |
10
|
|
|
use TYPO3\CMS\Core\Resource\FileReference; |
11
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
12
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectGetDataHookInterface; |
13
|
|
|
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Get data for focuspoint. |
17
|
|
|
* |
18
|
|
|
* @Hook("TYPO3_CONF_VARS|SC_OPTIONS|tslib/class.tslib_content.php|getData") |
19
|
|
|
*/ |
20
|
|
|
class GetData implements ContentObjectGetDataHookInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Extends the getData()-Method of ContentObjectRenderer to process more/other commands. |
24
|
|
|
* |
25
|
|
|
* @param string $getDataString Full content of getData-request e.g. "TSFE:id // field:title // field:uid |
26
|
|
|
* @param array $fields Current field-array |
27
|
|
|
* @param string $sectionValue Currently examined section value of the getData request e.g. "field:title |
28
|
|
|
* @param string $returnValue Current returnValue that was processed so far by getData |
29
|
|
|
* @param ContentObjectRenderer $parentObject Parent content object |
30
|
|
|
* |
31
|
|
|
* @return string Get data result |
32
|
|
|
*/ |
33
|
|
|
public function getDataExtension( |
34
|
|
|
$getDataString, |
35
|
|
|
array $fields, |
36
|
|
|
$sectionValue, |
37
|
|
|
$returnValue, |
38
|
|
|
ContentObjectRenderer &$parentObject |
39
|
|
|
) { |
40
|
|
|
$parts = \explode(':', $getDataString); |
41
|
|
|
if (isset($parts[0], $parts[1]) && 'fp' === $parts[0]) { |
42
|
|
|
$fileObject = $parentObject->getCurrentFile(); |
43
|
|
|
if (!($fileObject instanceof FileReference)) { |
44
|
|
|
return $returnValue; |
45
|
|
|
} |
46
|
|
|
$originalFile = $fileObject->getOriginalFile(); |
47
|
|
|
switch ($parts[1]) { |
48
|
|
|
case 'x': |
49
|
|
|
case 'y': |
50
|
|
|
$metaData = $originalFile->_getMetaData(); |
51
|
|
|
|
52
|
|
|
return $metaData['focus_point_' . $parts[1]] / 100; |
53
|
|
|
case 'xp': |
54
|
|
|
case 'yp': |
55
|
|
|
$metaData = $originalFile->_getMetaData(); |
56
|
|
|
|
57
|
|
|
return (float) $metaData['focus_point_' . \mb_substr($parts[1], 0, 1)]; |
58
|
|
|
case 'xp_positive': |
59
|
|
|
case 'yp_positive': |
60
|
|
|
$metaData = $originalFile->_getMetaData(); |
61
|
|
|
if ('xp_positive' === $parts[1]) { |
62
|
|
|
return (int) (\abs($metaData['focus_point_' . \mb_substr($parts[1], 0, 1)] + 100) / 2); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return (int) (\abs($metaData['focus_point_' . \mb_substr($parts[1], 0, 1)] - 100) / 2); |
66
|
|
|
case 'w': |
67
|
|
|
case 'h': |
68
|
|
|
$fileName = GeneralUtility::getFileAbsFileName($fileObject->getPublicUrl(true)); |
69
|
|
|
if (\file_exists($fileName)) { |
70
|
|
|
$sizes = \getimagesize($fileName); |
71
|
|
|
|
72
|
|
|
return $sizes[('w' === $parts[1] ? 0 : 1)]; |
73
|
|
|
} |
74
|
|
|
break; |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $returnValue; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|