-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from timohund/task/master/85-allow-to-see-extr…
…acted-content-of-tika-in-the-backend [TASK] Allow to see the extraction content from the backend
- Loading branch information
Showing
25 changed files
with
530 additions
and
1,533 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<phpunit | ||
backupGlobals="false" | ||
backupStaticAttributes="false" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
forceCoversAnnotation="false" | ||
processIsolation="true" | ||
stopOnError="true" | ||
stopOnFailure="true" | ||
stopOnIncomplete="false" | ||
stopOnSkipped="false" | ||
verbose="false"> | ||
|
||
<testsuites> | ||
<testsuite name="tika-integration-tests"> | ||
<directory>../../Tests/Integration/</directory> | ||
</testsuite> | ||
|
||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="false"> | ||
<directory suffix=".php">../../Classes/</directory> | ||
</whitelist> | ||
</filter> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
namespace ApacheSolrForTypo3\Tika\ContextMenu; | ||
|
||
use TYPO3\CMS\Backend\ContextMenu\ItemProviders\AbstractProvider; | ||
use TYPO3\CMS\Core\Resource\File; | ||
|
||
class Preview extends AbstractProvider{ | ||
|
||
protected $itemsConfiguration = [ | ||
'tika_preview' => [ | ||
'type' => 'item', | ||
'label' => 'Tika Preview', // you can use "LLL:" syntax here | ||
'iconIdentifier' => 'actions-document-view', | ||
'callbackAction' => 'tikaPreview' | ||
] | ||
]; | ||
|
||
/** | ||
* Checks if this provider may be called to provide the list of context menu items for given table. | ||
* | ||
* @return bool | ||
*/ | ||
public function canHandle(): bool | ||
{ | ||
if (!$GLOBALS['BE_USER']->isAdmin()) { | ||
return false; | ||
} | ||
|
||
// Current table is: $this->table | ||
// Current UID is: $this->identifier | ||
if (!$this->table === 'sys_file') { | ||
return false; | ||
} | ||
|
||
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance(); | ||
$item = $resourceFactory->retrieveFileOrFolderObject($this->identifier); | ||
|
||
// we only handle files, no folders | ||
return ($item instanceof File); | ||
} | ||
|
||
/** | ||
* Returns the provider priority which is used for determining the order in which providers are processing items | ||
* to the result array. Highest priority means provider is evaluated first. | ||
* | ||
* This item provider should be called after PageProvider which has priority 100. | ||
* | ||
* BEWARE: Returned priority should logically not clash with another provider. | ||
* Please check @see \TYPO3\CMS\Backend\ContextMenu\ContextMenu::getAvailableProviders() if needed. | ||
* | ||
* @return int | ||
*/ | ||
public function getPriority(): int | ||
{ | ||
return 90; | ||
} | ||
|
||
/** | ||
* Registers the additional JavaScript RequireJS callback-module which will allow to display a notification | ||
* whenever the user tries to click on the "Hello World" item. | ||
* The method is called from AbstractProvider::prepareItems() for each context menu item. | ||
* | ||
* @param string $itemName | ||
* @return array | ||
*/ | ||
protected function getAdditionalAttributes(string $itemName): array | ||
{ | ||
return ['data-callback-module' => 'TYPO3/CMS/Tika/ContextMenuActions']; | ||
} | ||
|
||
/** | ||
* This method adds custom item to list of items generated by item providers with higher priority value (PageProvider) | ||
* You could also modify existing items here. | ||
* The new item is added after the 'info' item. | ||
* | ||
* @param array $items | ||
* @return array | ||
*/ | ||
public function addItems(array $items): array | ||
{ | ||
|
||
$this->initDisabledItems(); | ||
$localItems = $this->prepareItems($this->itemsConfiguration); | ||
$items = $items + $localItems; | ||
//passes array of items to the next item provider | ||
return $items; | ||
} | ||
|
||
/** | ||
* This method is called for each item this provider adds and checks if given item can be added | ||
* | ||
* @param string $itemName | ||
* @param string $type | ||
* @return bool | ||
*/ | ||
protected function canRender(string $itemName, string $type): bool | ||
{ | ||
// checking if item is disabled through TSConfig | ||
if (in_array($itemName, $this->disabledItems, true)) { | ||
return false; | ||
} | ||
switch ($itemName) { | ||
case 'tika_preview': | ||
$canRender = true; | ||
break; | ||
default: | ||
$canRender = false; | ||
} | ||
return $canRender; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
namespace ApacheSolrForTypo3\Tika\Controller\Backend; | ||
|
||
use ApacheSolrForTypo3\Tika\Service\Tika\AppService; | ||
use ApacheSolrForTypo3\Tika\Service\Tika\ServerService; | ||
use ApacheSolrForTypo3\Tika\Service\Tika\ServiceFactory; | ||
use ApacheSolrForTypo3\Tika\Service\Tika\SolrCellService; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use TYPO3\CMS\Core\Resource\ResourceFactory; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\CMS\Fluid\View\StandaloneView; | ||
|
||
/** | ||
* Class PreviewController | ||
* @package ApacheSolrForTypo3\Tika\Controller\Backend | ||
*/ | ||
class PreviewController { | ||
|
||
/** | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
* @return string | ||
*/ | ||
public function previewAction(ServerRequestInterface $request, ResponseInterface $response) | ||
{ | ||
if (!$this->getIsAdmin()) { | ||
$response->getBody()->write('Only admins can see the tika preview'); | ||
return $response; | ||
} | ||
|
||
$identifier = (string)$request->getQueryParams()['identifier']; | ||
$file = $this->getFileResourceFactory()->getFileObjectFromCombinedIdentifier($identifier); | ||
|
||
$tikaService = $this->getConfiguredTikaService(); | ||
$metadata = $tikaService->extractMetaData($file); | ||
$content = $tikaService->extractText($file); | ||
|
||
try { | ||
$language = $tikaService->detectLanguageFromFile($file); | ||
} catch (\Exception $e) { | ||
$language = 'not detectable'; | ||
} | ||
|
||
$view = $this->getInitializedPreviewView(); | ||
|
||
$view->assign('metadata', $metadata); | ||
$view->assign('content', $content); | ||
$view->assign('language', $language); | ||
|
||
$response->getBody()->write($view->render()); | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* @return AppService|ServerService|SolrCellService | ||
*/ | ||
protected function getConfiguredTikaService() | ||
{ | ||
return ServiceFactory::getConfiguredTika(); | ||
} | ||
|
||
/** | ||
* @return \TYPO3\CMS\Core\Resource\ResourceFactory | ||
*/ | ||
protected function getFileResourceFactory(): ResourceFactory | ||
{ | ||
return \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance(); | ||
} | ||
|
||
/** | ||
* @return StandaloneView | ||
*/ | ||
protected function getInitializedPreviewView(): StandaloneView | ||
{ | ||
/** @var $view StandaloneView */ | ||
$view = GeneralUtility::makeInstance(StandaloneView::class); | ||
$view->getRequest()->setControllerExtensionName('tika'); | ||
$templatePathAndFile = 'EXT:tika/Resources/Private/Templates/Backend/Preview.html'; | ||
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templatePathAndFile)); | ||
return $view; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
protected function getIsAdmin() | ||
{ | ||
return (bool)$GLOBALS['BE_USER']->isAdmin(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
namespace ApacheSolrForTypo3\Tika\Hooks; | ||
|
||
use TYPO3\CMS\Backend\Controller\BackendController; | ||
use TYPO3\CMS\Backend\Utility\BackendUtility; | ||
use TYPO3\CMS\Core\Page\PageRenderer; | ||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
|
||
/** | ||
* This class adds Filelist related JavaScript to the backend | ||
*/ | ||
class BackendControllerHook | ||
{ | ||
/** | ||
* Adds Filelist JavaScript used e.g. by context menu | ||
* | ||
* @param array $configuration | ||
* @param BackendController $backendController | ||
*/ | ||
public function addJavaScript(array $configuration, BackendController $backendController) | ||
{ | ||
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); | ||
$pageRenderer->addInlineSetting('TikaPreview', 'moduleUrl', BackendUtility::getModuleUrl('tika_preview')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
/** | ||
* Definitions for routes provided by EXT:backend | ||
* Contains all "regular" routes for entry points | ||
* | ||
* Please note that this setup is preliminary until all core use-cases are set up here. | ||
* Especially some more properties regarding modules will be added until TYPO3 CMS 7 LTS, and might change. | ||
* | ||
* Currently the "access" property is only used so no token creation + validation is made, | ||
* but will be extended further. | ||
*/ | ||
return [ | ||
// | ||
'tika_preview' => [ | ||
'path' => '/tika/preview', | ||
'target' => \ApacheSolrForTypo3\Tika\Controller\Backend\PreviewController::class . '::previewAction' | ||
], | ||
]; |
Oops, something went wrong.