OC\Preview - outsource static methods

This commit is contained in:
Georg Ehrke 2013-07-11 20:35:55 +02:00
parent 1ffc42b4be
commit 14a35267c1
11 changed files with 43 additions and 33 deletions

View File

@ -42,12 +42,13 @@ $this->create('js_config', '/core/js/config.js')
// Routing
$this->create('core_ajax_routes', '/core/routes.json')
->action('OC_Router', 'JSRoutes');
OC::$CLASSPATH['OC\PreviewManager'] = 'lib/preview.php';
$this->create('core_ajax_preview', '/core/preview.png')
->action('OC\Preview', 'previewRouter');
->action('OC\PreviewManager', 'previewRouter');
$this->create('core_ajax_trashbin_preview', '/core/trashbinpreview.png')
->action('OC\Preview', 'trashbinPreviewRouter');
->action('OC\PreviewManager', 'trashbinPreviewRouter');
$this->create('core_ajax_public_preview', '/core/publicpreview.png')
->action('OC\Preview', 'publicPreviewRouter');
->action('OC\PreviewManager', 'publicPreviewRouter');
OC::$CLASSPATH['OC_Core_LostPassword_Controller'] = 'core/lostpassword/controller.php';
$this->create('core_lostpassword_index', '/lostpassword/')
->get()

View File

@ -44,10 +44,6 @@ class Preview {
//preview images object
private $preview;
//preview providers
static private $providers = array();
static private $registeredProviders = array();
/**
* @brief check if thumbnail or bigger version of thumbnail of file is cached
* @param string $user userid - if no user is given, OC_User::getUser will be used
@ -82,11 +78,13 @@ class Preview {
$this->preview = null;
//check if there are preview backends
if(empty(self::$providers)) {
self::initProviders();
$providers = PreviewManager::getProviders();
if(empty($providers)) {
PreviewManager::initProviders();
}
if(empty(self::$providers)) {
$providers = PreviewManager::getProviders();
if(empty($providers)) {
\OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR);
throw new \Exception('No preview providers');
}
@ -380,7 +378,8 @@ class Preview {
$mimetype = $this->fileview->getMimeType($file);
$preview = null;
foreach(self::$providers as $supportedmimetype => $provider) {
$providers = PreviewManager::getProviders();
foreach($providers as $supportedmimetype => $provider) {
if(!preg_match($supportedmimetype, $mimetype)) {
continue;
}
@ -544,6 +543,16 @@ class Preview {
return;
}
}
}
class PreviewManager {
//preview providers
static private $providers = array();
static private $registeredProviders = array();
public static function getProviders() {
return self::$providers;
}
/**
* @brief register a new preview provider to be used
@ -559,7 +568,7 @@ class Preview {
* @brief create instances of all the registered preview providers
* @return void
*/
private static function initProviders() {
public static function initProviders() {
if(count(self::$providers)>0) {
return;
}
@ -766,7 +775,7 @@ class Preview {
$preview->deleteAllPreviews();
}
private static function showErrorPreview() {
public static function showErrorPreview() {
$path = \OC::$SERVERROOT . '/core/img/actions/delete.png';
$preview = new \OC_Image($path);
$preview->preciseResize(44, 44);

View File

@ -30,4 +30,4 @@ class Image extends Provider {
}
}
\OC\Preview::registerProvider('OC\Preview\Image');
\OC\PreviewManager::registerProvider('OC\Preview\Image');

View File

@ -80,7 +80,7 @@ class MSOfficeDoc extends Office {
}
\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc');
\OC\PreviewManager::registerProvider('OC\Preview\MSOfficeDoc');
//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m)
class MSOffice2003 extends Office {
@ -91,7 +91,7 @@ class MSOffice2003 extends Office {
}
\OC\Preview::registerProvider('OC\Preview\MSOffice2003');
\OC\PreviewManager::registerProvider('OC\Preview\MSOffice2003');
//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx
class MSOffice2007 extends Office {
@ -102,7 +102,7 @@ class MSOffice2007 extends Office {
}
\OC\Preview::registerProvider('OC\Preview\MSOffice2007');
\OC\PreviewManager::registerProvider('OC\Preview\MSOffice2007');
//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt
class OpenDocument extends Office {
@ -113,7 +113,7 @@ class OpenDocument extends Office {
}
\OC\Preview::registerProvider('OC\Preview\OpenDocument');
\OC\PreviewManager::registerProvider('OC\Preview\OpenDocument');
//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm
class StarOffice extends Office {
@ -124,4 +124,4 @@ class StarOffice extends Office {
}
\OC\Preview::registerProvider('OC\Preview\StarOffice');
\OC\PreviewManager::registerProvider('OC\Preview\StarOffice');

View File

@ -39,5 +39,5 @@ if(!is_null(shell_exec('ffmpeg -version'))) {
}
}
\OC\Preview::registerProvider('OC\Preview\Movie');
\OC\PreviewManager::registerProvider('OC\Preview\Movie');
}

View File

@ -43,4 +43,4 @@ class MP3 extends Provider {
}
\OC\Preview::registerProvider('OC\Preview\MP3');
\OC\PreviewManager::registerProvider('OC\Preview\MP3');

View File

@ -20,7 +20,7 @@ class DOC extends Provider {
}
\OC\Preview::registerProvider('OC\Preview\DOC');
\OC\PreviewManager::registerProvider('OC\Preview\DOC');
*/
class DOCX extends Provider {
@ -50,7 +50,7 @@ class DOCX extends Provider {
}
\OC\Preview::registerProvider('OC\Preview\DOCX');
\OC\PreviewManager::registerProvider('OC\Preview\DOCX');
class MSOfficeExcel extends Provider {
@ -95,7 +95,7 @@ class XLS extends MSOfficeExcel {
}
\OC\Preview::registerProvider('OC\Preview\XLS');
\OC\PreviewManager::registerProvider('OC\Preview\XLS');
class XLSX extends MSOfficeExcel {
@ -105,7 +105,7 @@ class XLSX extends MSOfficeExcel {
}
\OC\Preview::registerProvider('OC\Preview\XLSX');
\OC\PreviewManager::registerProvider('OC\Preview\XLSX');
/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ...
class MSOfficePowerPoint extends Provider {
@ -128,7 +128,7 @@ class PPT extends MSOfficePowerPoint {
}
\OC\Preview::registerProvider('OC\Preview\PPT');
\OC\PreviewManager::registerProvider('OC\Preview\PPT');
class PPTX extends MSOfficePowerPoint {
@ -138,5 +138,5 @@ class PPTX extends MSOfficePowerPoint {
}
\OC\Preview::registerProvider('OC\Preview\PPTX');
\OC\PreviewManager::registerProvider('OC\Preview\PPTX');
*/

View File

@ -36,5 +36,5 @@ if (extension_loaded('imagick')) {
}
}
\OC\Preview::registerProvider('OC\Preview\PDF');
\OC\PreviewManager::registerProvider('OC\Preview\PDF');
}

View File

@ -39,6 +39,6 @@ if (extension_loaded('imagick')) {
}
}
\OC\Preview::registerProvider('OC\Preview\SVG');
\OC\PreviewManager::registerProvider('OC\Preview\SVG');
}

View File

@ -46,7 +46,7 @@ class TXT extends Provider {
}
}
\OC\Preview::registerProvider('OC\Preview\TXT');
\OC\PreviewManager::registerProvider('OC\Preview\TXT');
class PHP extends TXT {
@ -56,7 +56,7 @@ class PHP extends TXT {
}
\OC\Preview::registerProvider('OC\Preview\PHP');
\OC\PreviewManager::registerProvider('OC\Preview\PHP');
class JavaScript extends TXT {
@ -66,4 +66,4 @@ class JavaScript extends TXT {
}
\OC\Preview::registerProvider('OC\Preview\JavaScript');
\OC\PreviewManager::registerProvider('OC\Preview\JavaScript');

View File

@ -40,4 +40,4 @@ class Unknown extends Provider {
}
}
\OC\Preview::registerProvider('OC\Preview\Unknown');
\OC\PreviewManager::registerProvider('OC\Preview\Unknown');