Hook: Add HookDocumentItemView - refs BT#18599

pull/3859/head
Angel Fernando Quiroz Campos 5 years ago
parent cb5789fc65
commit 9ce60a3afe
  1. 26
      main/inc/lib/document.lib.php
  2. 34
      main/inc/lib/hook/HookDocumentItemView.php
  3. 11
      main/inc/lib/hook/interfaces/HookDocumentItemViewEventInterface.php
  4. 16
      main/inc/lib/hook/interfaces/HookDocumentItemViewObserverInterface.php

@ -5307,6 +5307,21 @@ class DocumentManager
Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), [], ICON_SIZE_SMALL).'&nbsp;&nbsp;</a>'; Display::return_icon('open_in_new_window.png', get_lang('OpenInANewWindow'), [], ICON_SIZE_SMALL).'&nbsp;&nbsp;</a>';
} }
$hook = HookDocumentItemView::create();
$hookItemViewTools = $hook->setEventData($document_data)->notifyDocumentItemView();
$rightTools = implode(
PHP_EOL,
[
$force_download_html,
$send_to,
$copyToMyFiles,
$open_in_new_window_link,
$pdf_icon,
$hookItemViewTools ? implode(PHP_EOL, $hookItemViewTools) : '',
]
);
if ($filetype === 'file') { if ($filetype === 'file') {
// Sound preview // Sound preview
if (preg_match('/mp3$/i', urldecode($checkExtension)) || if (preg_match('/mp3$/i', urldecode($checkExtension)) ||
@ -5315,7 +5330,7 @@ class DocumentManager
) { ) {
return '<span style="float:left" '.$visibility_class.'>'. return '<span style="float:left" '.$visibility_class.'>'.
$title. $title.
'</span>'.$force_download_html.$send_to.$copyToMyFiles.$open_in_new_window_link.$pdf_icon; '</span>'.$rightTools;
} elseif ( } elseif (
// Show preview // Show preview
preg_match('/swf$/i', urldecode($checkExtension)) || preg_match('/swf$/i', urldecode($checkExtension)) ||
@ -5343,8 +5358,7 @@ class DocumentManager
'style' => 'float:left;', 'style' => 'float:left;',
] ]
) )
.$force_download_html.$send_to.$copyToMyFiles .$rightTools;
.$open_in_new_window_link.$pdf_icon;
} else { } else {
// For a "PDF Download" of the file. // For a "PDF Download" of the file.
$pdfPreview = null; $pdfPreview = null;
@ -5359,11 +5373,11 @@ class DocumentManager
} }
// No plugin just the old and good showinframes.php page // No plugin just the old and good showinframes.php page
return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" style="float:left" '.$visibility_class.' >'.$title.'</a>'. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" style="float:left" '.$visibility_class.' >'.$title.'</a>'.
$pdfPreview.$force_download_html.$send_to.$copyToMyFiles.$open_in_new_window_link.$pdf_icon; $pdfPreview.$rightTools;
} }
} else { } else {
return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.$title.'</a>'. return '<a href="'.$url.'" title="'.$tooltip_title_alt.'" '.$visibility_class.' style="float:left">'.$title.'</a>'
$force_download_html.$send_to.$copyToMyFiles.$open_in_new_window_link.$pdf_icon; .$rightTools;
} }
// end copy files to users myfiles // end copy files to users myfiles
} else { } else {

@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Class HookDocumentItemView.
*/
class HookDocumentItemView extends HookEvent implements HookDocumentItemViewEventInterface
{
/**
* HookDocumentItemView constructor.
*
* @throws Exception
*/
protected function __construct()
{
parent::__construct('HookDocumentItemView');
}
/**
* @inheritDoc
*/
public function notifyDocumentItemView(): array
{
$tools = [];
/** @var HookDocumentItemViewObserverInterface $observer */
foreach ($this->observers as $observer) {
$tools[] = $observer->notifyDocumentItemView($this);
}
return $tools;
}
}

@ -0,0 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
interface HookDocumentItemViewEventInterface extends HookEventInterface
{
/**
* @return array
*/
public function notifyDocumentItemView(): array;
}

@ -0,0 +1,16 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Interface HookDocumentItemViewObserverInterface.
*/
interface HookDocumentItemViewObserverInterface extends HookObserverInterface
{
/**
* @param HookDocumentItemViewEventInterface $hookvent
*
* @return string
*/
public function notifyDocumentItemView(HookDocumentItemViewEventInterface $hookvent): string;
}
Loading…
Cancel
Save