/ */ namespace LibreOffice; use Files\Format\Handler as FormatHandler; use Zend\Mvc\MvcEvent; class Module { /** * Add a preview handler for types supported by LibreOffice */ public function onBootstrap(MvcEvent $event) { $application = $event->getApplication(); $services = $application->getServiceManager(); $config = $services->get('config'); $formats = $services->get('formats'); $formats->addHandler( new FormatHandler( // can-preview callback function ($file, $extension, $mimeType, $request) use ($config) { if (!in_array($extension, array('doc', 'docx', 'ppt', 'pptx', 'rtf', 'vsd', 'xls', 'xlsx'))) { return false; } // good to go if libre-office is installed $soffice = $config['libreoffice']['path']; exec('which ' . escapeshellarg($soffice), $output, $result); return !(bool) $result; }, // render-preview callback function ($file, $extension, $mimeType, $request) use ($services) { $helpers = $services->get('ViewHelperManager'); $escapeUrl = $helpers->get('escapeUrl'); $url = $helpers->get('url'); $te = $helpers->get('te'); $viewUrl = $url('libreoffice', array('path' => trim($file->getDepotFilename(), '/'))) . '?v=' . $escapeUrl($file->getRevspec()); return '
' . '' . '

' . $te('It appears you don\'t have a pdf plugin for this browser.') . '

' . '
' . '
'; } ), 'libreoffice' ); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } }