We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 46 |
| Total Lines | 336 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 1 |
Complex classes like PageView often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use PageView, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class PageView extends \Kitodo\Dlf\Common\AbstractPlugin |
||
| 29 | { |
||
| 30 | public $scriptRelPath = 'Classes/Plugin/PageView.php'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Holds the controls to add to the map |
||
| 34 | * |
||
| 35 | * @var array |
||
| 36 | * @access protected |
||
| 37 | */ |
||
| 38 | protected $controls = []; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Holds the current images' URLs and MIME types |
||
| 42 | * |
||
| 43 | * @var array |
||
| 44 | * @access protected |
||
| 45 | */ |
||
| 46 | protected $images = []; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Holds the current fulltexts' URLs |
||
| 50 | * |
||
| 51 | * @var array |
||
| 52 | * @access protected |
||
| 53 | */ |
||
| 54 | protected $fulltexts = []; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Holds the current AnnotationLists / AnnotationPages |
||
| 58 | * |
||
| 59 | * @var array |
||
| 60 | * @access protected |
||
| 61 | */ |
||
| 62 | protected $annotationContainers = []; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Adds Viewer javascript |
||
| 66 | * |
||
| 67 | * @access protected |
||
| 68 | * |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | protected function addViewerJS() |
||
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Adds pageview interaction (crop, magnifier and rotation) |
||
| 112 | * |
||
| 113 | * @access protected |
||
| 114 | * |
||
| 115 | * @return array Marker array |
||
| 116 | */ |
||
| 117 | protected function addInteraction() |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Adds form to save cropping data to basket |
||
| 139 | * |
||
| 140 | * @access protected |
||
| 141 | * |
||
| 142 | * @return array Marker array |
||
| 143 | */ |
||
| 144 | protected function addBasketForm() |
||
| 182 | } |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Get image's URL and MIME type |
||
| 186 | * |
||
| 187 | * @access protected |
||
| 188 | * |
||
| 189 | * @param int $page: Page number |
||
| 190 | * |
||
| 191 | * @return array URL and MIME type of image file |
||
| 192 | */ |
||
| 193 | protected function getImage($page) |
||
| 194 | { |
||
| 195 | $image = []; |
||
| 196 | // Get @USE value of METS fileGrp. |
||
| 197 | $fileGrps = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->conf['fileGrps']); |
||
| 198 | while ($fileGrp = @array_pop($fileGrps)) { |
||
| 199 | // Get image link. |
||
| 200 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp])) { |
||
| 201 | $image['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]); |
||
| 202 | if ($this->conf['useInternalProxy']) { |
||
| 203 | // Configure @action URL for form. |
||
| 204 | $linkConf = [ |
||
| 205 | 'parameter' => $GLOBALS['TSFE']->id, |
||
| 206 | 'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
||
| 207 | 'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
||
| 208 | 'additionalParams' => '&eID=tx_dlf_pageview_proxy&url=' . urlencode($image['url']), |
||
| 209 | ]; |
||
| 210 | $image['url'] = $this->cObj->typoLink_URL($linkConf); |
||
| 211 | } |
||
| 212 | $image['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$fileGrp]); |
||
| 213 | break; |
||
| 214 | } else { |
||
| 215 | Helper::devLog('File not found in fileGrp "' . $fileGrp . '"', DEVLOG_SEVERITY_WARNING); |
||
| 216 | } |
||
| 217 | } |
||
| 218 | return $image; |
||
| 219 | } |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Get fulltext URL and MIME type |
||
| 223 | * |
||
| 224 | * @access protected |
||
| 225 | * |
||
| 226 | * @param int $page: Page number |
||
| 227 | * |
||
| 228 | * @return array URL and MIME type of fulltext file |
||
| 229 | */ |
||
| 230 | protected function getFulltext($page) |
||
| 231 | { |
||
| 232 | $fulltext = []; |
||
| 233 | // Get fulltext link. |
||
| 234 | if (!empty($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$this->conf['fileGrpFulltext']])) { |
||
| 235 | $fulltext['url'] = $this->doc->getFileLocation($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$this->conf['fileGrpFulltext']]); |
||
| 236 | if ($this->conf['useInternalProxy']) { |
||
| 237 | // Configure @action URL for form. |
||
| 238 | $linkConf = [ |
||
| 239 | 'parameter' => $GLOBALS['TSFE']->id, |
||
| 240 | 'forceAbsoluteUrl' => !empty($this->conf['forceAbsoluteUrl']) ? 1 : 0, |
||
| 241 | 'forceAbsoluteUrl.' => ['scheme' => !empty($this->conf['forceAbsoluteUrl']) && !empty($this->conf['forceAbsoluteUrlHttps']) ? 'https' : 'http'], |
||
| 242 | 'additionalParams' => '&eID=tx_dlf_pageview_proxy&url=' . urlencode($fulltext['url']), |
||
| 243 | ]; |
||
| 244 | $fulltext['url'] = $this->cObj->typoLink_URL($linkConf); |
||
| 245 | } |
||
| 246 | $fulltext['mimetype'] = $this->doc->getFileMimeType($this->doc->physicalStructureInfo[$this->doc->physicalStructure[$page]]['files'][$this->conf['fileGrpFulltext']]); |
||
| 247 | } else { |
||
| 248 | Helper::devLog('File not found in fileGrp "' . $this->conf['fileGrpFulltext'] . '"', DEVLOG_SEVERITY_WARNING); |
||
| 249 | } |
||
| 250 | return $fulltext; |
||
| 251 | } |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Get all AnnotationPages / AnnotationLists that contain text Annotations with motivation "painting" |
||
| 255 | * |
||
| 256 | * @access protected |
||
| 257 | * |
||
| 258 | * @param int $page: Page number |
||
| 259 | * @return array An array containing the IRIs of the AnnotationLists / AnnotationPages as well as |
||
| 260 | * some information about the canvas. |
||
| 261 | */ |
||
| 262 | protected function getAnnotationContainers($page) |
||
| 263 | { |
||
| 264 | if ($this->doc instanceof IiifManifest) { |
||
| 265 | $canvasId = $this->doc->physicalStructure[$page]; |
||
| 266 | $iiif = $this->doc->getIiif(); |
||
| 267 | if ($iiif instanceof ManifestInterface) { |
||
| 268 | $canvas = $iiif->getContainedResourceById($canvasId); |
||
| 269 | /* @var $canvas \Ubl\Iiif\Presentation\Common\Model\Resources\CanvasInterface */ |
||
| 270 | if ($canvas != null && !empty($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING))) { |
||
| 271 | $annotationContainers = []; |
||
| 272 | /* |
||
| 273 | * TODO Analyzing the annotations on the server side requires loading the annotation lists / pages |
||
| 274 | * just to determine wether they contain text annotations for painting. This will take time and lead to a bad user experience. |
||
| 275 | * It would be better to link every annotation and analyze the data on the client side. |
||
| 276 | * |
||
| 277 | * On the other hand, server connections are potentially better than client connections. Downloading annotation lists |
||
| 278 | */ |
||
| 279 | foreach ($canvas->getPossibleTextAnnotationContainers(Motivation::PAINTING) as $annotationContainer) { |
||
| 280 | if (($textAnnotations = $annotationContainer->getTextAnnotations(Motivation::PAINTING)) != null) { |
||
| 281 | foreach ($textAnnotations as $annotation) { |
||
| 282 | if ( |
||
| 283 | $annotation->getBody()->getFormat() == 'text/plain' |
||
| 284 | && $annotation->getBody()->getChars() != null |
||
| 285 | ) { |
||
| 286 | $annotationListData = []; |
||
| 287 | $annotationListData['uri'] = $annotationContainer->getId(); |
||
| 288 | $annotationListData['label'] = $annotationContainer->getLabelForDisplay(); |
||
| 289 | $annotationContainers[] = $annotationListData; |
||
| 290 | break; |
||
| 291 | } |
||
| 292 | } |
||
| 293 | } |
||
| 294 | } |
||
| 295 | $result = [ |
||
| 296 | 'canvas' => [ |
||
| 297 | 'id' => $canvas->getId(), |
||
| 298 | 'width' => $canvas->getWidth(), |
||
| 299 | 'height' => $canvas->getHeight(), |
||
| 300 | ], |
||
| 301 | 'annotationContainers' => $annotationContainers |
||
| 302 | ]; |
||
| 303 | return $result; |
||
| 304 | } |
||
| 305 | } |
||
| 306 | } |
||
| 307 | return []; |
||
| 308 | } |
||
| 309 | |||
| 310 | /** |
||
| 311 | * The main method of the PlugIn |
||
| 312 | * |
||
| 313 | * @access public |
||
| 314 | * |
||
| 315 | * @param string $content: The PlugIn content |
||
| 316 | * @param array $conf: The PlugIn configuration |
||
| 317 | * |
||
| 318 | * @return string The content that is displayed on the website |
||
| 319 | */ |
||
| 320 | public function main($content, $conf) |
||
| 364 | } |
||
| 365 | } |
||
| 366 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.