diff options
author | kondou <kondou@ts.unde.re> | 2013-08-31 12:56:36 +0200 |
---|---|---|
committer | kondou <kondou@ts.unde.re> | 2013-08-31 12:56:36 +0200 |
commit | 5d653753bd8f6f1294dfbfa112757e5509ddc80d (patch) | |
tree | 54853c3cf28f4d3ec58d7f9230be68e8e70d4998 /lib | |
parent | 30526ded803e352f3f7322ed96ebc480d5e3f9c1 (diff) | |
parent | 92e90c8eb995c886b3e9cd77c14e3f0b25b95cd7 (diff) | |
download | nextcloud-server-5d653753bd8f6f1294dfbfa112757e5509ddc80d.tar.gz nextcloud-server-5d653753bd8f6f1294dfbfa112757e5509ddc80d.zip |
Merge branch 'master' into oc_avatars
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 35 | ||||
-rw-r--r-- | lib/connector/sabre/directory.php | 2 | ||||
-rw-r--r-- | lib/files/view.php | 1 | ||||
-rw-r--r-- | lib/helper.php | 54 | ||||
-rw-r--r-- | lib/image.php | 5 | ||||
-rw-r--r-- | lib/l10n/cs_CZ.php | 14 | ||||
-rw-r--r-- | lib/l10n/da.php | 14 | ||||
-rw-r--r-- | lib/l10n/de.php | 9 | ||||
-rw-r--r-- | lib/l10n/de_DE.php | 10 | ||||
-rw-r--r-- | lib/l10n/en_GB.php | 69 | ||||
-rw-r--r-- | lib/l10n/gl.php | 14 | ||||
-rw-r--r-- | lib/l10n/it.php | 13 | ||||
-rw-r--r-- | lib/l10n/sk_SK.php | 14 | ||||
-rw-r--r-- | lib/l10n/sv.php | 14 | ||||
-rwxr-xr-x | lib/preview.php | 627 | ||||
-rw-r--r-- | lib/preview/image.php | 36 | ||||
-rw-r--r-- | lib/preview/movies.php | 47 | ||||
-rw-r--r-- | lib/preview/mp3.php | 48 | ||||
-rw-r--r-- | lib/preview/office-cl.php | 134 | ||||
-rw-r--r-- | lib/preview/office-fallback.php | 142 | ||||
-rw-r--r-- | lib/preview/office.php | 22 | ||||
-rw-r--r-- | lib/preview/pdf.php | 40 | ||||
-rw-r--r-- | lib/preview/provider.php | 19 | ||||
-rw-r--r-- | lib/preview/svg.php | 46 | ||||
-rw-r--r-- | lib/preview/txt.php | 73 | ||||
-rw-r--r-- | lib/preview/unknown.php | 27 | ||||
-rw-r--r-- | lib/public/preview.php | 34 | ||||
-rw-r--r-- | lib/public/template.php | 19 | ||||
-rw-r--r-- | lib/template/functions.php | 16 | ||||
-rwxr-xr-x | lib/util.php | 2 |
30 files changed, 1581 insertions, 19 deletions
diff --git a/lib/base.php b/lib/base.php index 0473e25da96..9f16edd14f5 100644 --- a/lib/base.php +++ b/lib/base.php @@ -264,6 +264,7 @@ class OC { //OC_Util::addScript( "multiselect" ); OC_Util::addScript('search', 'result'); OC_Util::addScript('router'); + OC_Util::addScript("oc-requesttoken"); // defaultavatars \OC_Util::addScript('placeholder'); @@ -272,11 +273,12 @@ class OC { \OC_Util::addScript('avatar'); OC_Util::addStyle("styles"); + OC_Util::addStyle("apps"); + OC_Util::addStyle("fixes"); OC_Util::addStyle("multiselect"); OC_Util::addStyle("jquery-ui-1.10.0.custom"); OC_Util::addStyle("jquery-tipsy"); OC_Util::addStyle("jquery.ocdialog"); - OC_Util::addScript("oc-requesttoken"); } public static function initSession() { @@ -496,6 +498,7 @@ class OC { self::registerCacheHooks(); self::registerFilesystemHooks(); + self::registerPreviewHooks(); self::registerShareHooks(); self::registerLogRotate(); @@ -584,6 +587,14 @@ class OC { } /** + * register hooks for previews + */ + public static function registerPreviewHooks() { + OC_Hook::connect('OC_Filesystem', 'post_write', 'OC\Preview', 'post_write'); + OC_Hook::connect('OC_Filesystem', 'delete', 'OC\Preview', 'post_delete'); + } + + /** * register hooks for sharing */ public static function registerShareHooks() { @@ -797,14 +808,15 @@ class OC { self::$session->set('timezone', $_POST['timezone-offset']); } - self::cleanupLoginTokens($_POST['user']); + $userid = OC_User::getUser(); + self::cleanupLoginTokens($userid); if (!empty($_POST["remember_login"])) { if (defined("DEBUG") && DEBUG) { OC_Log::write('core', 'Setting remember login to cookie', OC_Log::DEBUG); } $token = OC_Util::generate_random_bytes(32); - OC_Preferences::setValue($_POST['user'], 'login_token', $token, time()); - OC_User::setMagicInCookie($_POST["user"], $token); + OC_Preferences::setValue($userid, 'login_token', $token, time()); + OC_User::setMagicInCookie($userid, $token); } else { OC_User::unsetMagicInCookie(); } @@ -820,11 +832,16 @@ class OC { ) { return false; } - OC_App::loadApps(array('authentication')); - if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) { - //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG); - OC_User::unsetMagicInCookie(); - $_SERVER['HTTP_REQUESTTOKEN'] = OC_Util::callRegister(); + // don't redo authentication if user is already logged in + // otherwise session would be invalidated in OC_User::login with + // session_regenerate_id at every page load + if (!OC_User::isLoggedIn()) { + OC_App::loadApps(array('authentication')); + if (OC_User::login($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"])) { + //OC_Log::write('core',"Logged in with HTTP Authentication", OC_Log::DEBUG); + OC_User::unsetMagicInCookie(); + $_SERVER['HTTP_REQUESTTOKEN'] = OC_Util::callRegister(); + } } return true; } diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 66cd2fcd4e3..3181a4b310f 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -236,7 +236,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $storageInfo = OC_Helper::getStorageInfo($this->path); return array( $storageInfo['used'], - $storageInfo['total'] + $storageInfo['free'] ); } diff --git a/lib/files/view.php b/lib/files/view.php index bb737f19ef8..8aee12bf6fe 100644 --- a/lib/files/view.php +++ b/lib/files/view.php @@ -249,6 +249,7 @@ class View { $hooks = array('touch'); if (!$this->file_exists($path)) { + $hooks[] = 'create'; $hooks[] = 'write'; } $result = $this->basicOperation('touch', $path, $hooks, $mtime); diff --git a/lib/helper.php b/lib/helper.php index dd2476eda5c..5fb8fed3459 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -185,7 +185,38 @@ class OC_Helper { * Returns the path to the image of this file type. */ public static function mimetypeIcon($mimetype) { - $alias = array('application/xml' => 'code/xml'); + $alias = array( + 'application/xml' => 'code/xml', + 'application/msword' => 'x-office/document', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'x-office/document', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' => 'x-office/document', + 'application/vnd.ms-word.document.macroEnabled.12' => 'x-office/document', + 'application/vnd.ms-word.template.macroEnabled.12' => 'x-office/document', + 'application/vnd.oasis.opendocument.text' => 'x-office/document', + 'application/vnd.oasis.opendocument.text-template' => 'x-office/document', + 'application/vnd.oasis.opendocument.text-web' => 'x-office/document', + 'application/vnd.oasis.opendocument.text-master' => 'x-office/document', + 'application/vnd.ms-powerpoint' => 'x-office/presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.presentation' => 'x-office/presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.template' => 'x-office/presentation', + 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.addin.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.template.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' => 'x-office/presentation', + 'application/vnd.oasis.opendocument.presentation' => 'x-office/presentation', + 'application/vnd.oasis.opendocument.presentation-template' => 'x-office/presentation', + 'application/vnd.ms-excel' => 'x-office/spreadsheet', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'x-office/spreadsheet', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.sheet.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.template.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.addin.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' => 'x-office/spreadsheet', + 'application/vnd.oasis.opendocument.spreadsheet' => 'x-office/spreadsheet', + 'application/vnd.oasis.opendocument.spreadsheet-template' => 'x-office/spreadsheet', + ); + if (isset($alias[$mimetype])) { $mimetype = $alias[$mimetype]; } @@ -220,6 +251,21 @@ class OC_Helper { } /** + * @brief get path to preview of file + * @param string $path path + * @return string the url + * + * Returns the path to the preview of the file. + */ + public static function previewIcon($path) { + return self::linkToRoute( 'core_ajax_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path) )); + } + + public static function publicPreviewIcon( $path, $token ) { + return self::linkToRoute( 'core_ajax_public_preview', array('x' => 36, 'y' => 36, 'file' => urlencode($path), 't' => $token)); + } + + /** * @brief Make a human file size * @param int $bytes file size in bytes * @return string a human readable file size @@ -858,10 +904,8 @@ class OC_Helper { } else { $total = $free; //either unknown or unlimited } - if ($total == 0) { - $total = 1; // prevent division by zero - } - if ($total >= 0) { + if ($total > 0) { + // prevent division by zero or error codes (negative values) $relative = round(($used / $total) * 10000) / 100; } else { $relative = 0; diff --git a/lib/image.php b/lib/image.php index 4bc38e20e56..840b744ad72 100644 --- a/lib/image.php +++ b/lib/image.php @@ -496,6 +496,11 @@ class OC_Image { return false; } $this->resource = @imagecreatefromstring($str); + if(is_resource($this->resource)) { + imagealphablending($this->resource, false); + imagesavealpha($this->resource, true); + } + if(!$this->resource) { OC_Log::write('core', 'OC_Image->loadFromData, couldn\'t load', OC_Log::DEBUG); return false; diff --git a/lib/l10n/cs_CZ.php b/lib/l10n/cs_CZ.php index 1a80fc78bb6..fed9ad03c01 100644 --- a/lib/l10n/cs_CZ.php +++ b/lib/l10n/cs_CZ.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Aplikace \"%s\" nemůže být nainstalována, protože není kompatibilní s touto verzí ownCloud.", +"No app name specified" => "Nebyl zadan název aplikace", "Help" => "Nápověda", "Personal" => "Osobní", "Settings" => "Nastavení", @@ -13,6 +15,18 @@ $TRANSLATIONS = array( "Back to Files" => "Zpět k souborům", "Selected files too large to generate zip file." => "Vybrané soubory jsou příliš velké pro vytvoření ZIP souboru.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Stáhněte soubory po menších částech, samostatně, nebo se obraťte na správce.", +"No source specified when installing app" => "Nebyl zadán zdroj při instalaci aplikace", +"No href specified when installing app from http" => "Nebyl zadán odkaz pro instalaci aplikace z HTTP", +"No path specified when installing app from local file" => "Nebyla zadána cesta pro instalaci aplikace z místního souboru", +"Archives of type %s are not supported" => "Archivy typu %s nejsou podporovány", +"Failed to open archive when installing app" => "Chyba při otevírání archivu během instalace aplikace", +"App does not provide an info.xml file" => "Aplikace neposkytuje soubor info.xml", +"App can't be installed because of not allowed code in the App" => "Aplikace nemůže být nainstalována, protože obsahuje nepovolený kód", +"App can't be installed because it is not compatible with this version of ownCloud" => "Aplikace nemůže být nainstalována, protože není kompatibilní s touto verzí ownCloud", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Aplikace nemůže být nainstalována, protože obsahuje značku\n<shipped>\n\ntrue\n</shipped>\n\ncož není povoleno pro nedodávané aplikace", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Aplikace nemůže být nainstalována, protože verze uvedená v info.xml/version nesouhlasí s verzí oznámenou z úložiště aplikací.", +"App directory already exists" => "Adresář aplikace již existuje", +"Can't create app folder. Please fix permissions. %s" => "Nelze vytvořit složku aplikace. Opravte práva souborů. %s", "Application is not enabled" => "Aplikace není povolena", "Authentication error" => "Chyba ověření", "Token expired. Please reload page." => "Token vypršel. Obnovte prosím stránku.", diff --git a/lib/l10n/da.php b/lib/l10n/da.php index 78859b08745..26903142763 100644 --- a/lib/l10n/da.php +++ b/lib/l10n/da.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "App'en \"%s\" kan ikke blive installeret, da den ikke er kompatibel med denne version af ownCloud.", +"No app name specified" => "Intet app-navn angivet", "Help" => "Hjælp", "Personal" => "Personligt", "Settings" => "Indstillinger", @@ -13,6 +15,18 @@ $TRANSLATIONS = array( "Back to Files" => "Tilbage til Filer", "Selected files too large to generate zip file." => "De markerede filer er for store til at generere en ZIP-fil.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Download filerne i små bider, seperat, eller kontakt venligst din administrator.", +"No source specified when installing app" => "Ingen kilde angivet under installation af app", +"No href specified when installing app from http" => "Ingen href angivet under installation af app via http", +"No path specified when installing app from local file" => "Ingen sti angivet under installation af app fra lokal fil", +"Archives of type %s are not supported" => "Arkiver af type %s understøttes ikke", +"Failed to open archive when installing app" => "Kunne ikke åbne arkiv under installation af appen", +"App does not provide an info.xml file" => "Der følger ingen info.xml-fil med appen", +"App can't be installed because of not allowed code in the App" => "Appen kan ikke installeres, da den indeholder ikke-tilladt kode", +"App can't be installed because it is not compatible with this version of ownCloud" => "Appen kan ikke installeres, da den ikke er kompatibel med denne version af ownCloud.", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Appen kan ikke installeres, da den indeholder taget\n<shipped>\n\ntrue\n</shipped>\n\nhvilket ikke er tilladt for ikke-medfølgende apps", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "App kan ikke installeres, da versionen i info.xml/version ikke er den samme som versionen rapporteret fra app-storen", +"App directory already exists" => "App-mappe findes allerede", +"Can't create app folder. Please fix permissions. %s" => "Kan ikke oprette app-mappe. Ret tilladelser. %s", "Application is not enabled" => "Programmet er ikke aktiveret", "Authentication error" => "Adgangsfejl", "Token expired. Please reload page." => "Adgang er udløbet. Genindlæs siden.", diff --git a/lib/l10n/de.php b/lib/l10n/de.php index 8670e1175c6..7a3e2c43e6b 100644 --- a/lib/l10n/de.php +++ b/lib/l10n/de.php @@ -1,7 +1,7 @@ <?php $TRANSLATIONS = array( "App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Applikation \"%s\" kann nicht installiert werden, da sie mit dieser ownCloud Version nicht kompatibel ist.", -"No app name specified" => "Es wurde kein App-Name angegeben", +"No app name specified" => "Es wurde kein Applikation-Name angegeben", "Help" => "Hilfe", "Personal" => "Persönlich", "Settings" => "Einstellungen", @@ -16,12 +16,15 @@ $TRANSLATIONS = array( "Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Lade die Dateien in kleineren, separaten, Stücken herunter oder bitte deinen Administrator.", "No source specified when installing app" => "Für die Installation der Applikation wurde keine Quelle angegeben", -"No href specified when installing app from http" => "href wurde nicht angegeben um die Applikation per http zu installieren", +"No href specified when installing app from http" => "Der Link (href) wurde nicht angegeben um die Applikation per http zu installieren", "No path specified when installing app from local file" => "Bei der Installation der Applikation aus einer lokalen Datei wurde kein Pfad angegeben", "Archives of type %s are not supported" => "Archive vom Typ %s werden nicht unterstützt", -"Failed to open archive when installing app" => "Das Archive konnte bei der Installation der Applikation nicht geöffnet werden", +"Failed to open archive when installing app" => "Das Archiv konnte bei der Installation der Applikation nicht geöffnet werden", "App does not provide an info.xml file" => "Die Applikation enthält keine info,xml Datei", "App can't be installed because of not allowed code in the App" => "Die Applikation kann auf Grund von unerlaubten Code nicht installiert werden", +"App can't be installed because it is not compatible with this version of ownCloud" => "Die Anwendung konnte nicht installiert werden, weil Sie nicht mit dieser Version von ownCloud kompatibel ist.", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Die Applikation konnte nicht installiert werden, da diese das <shipped>true</shipped> Tag beinhaltet und dieses, bei nicht mitausgelieferten Applikationen, nicht erlaubt ist ist", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Die Applikation konnte nicht installiert werden, da die Version in der info.xml nicht die gleiche Version wie im App-Store ist", "App directory already exists" => "Das Applikationsverzeichnis existiert bereits", "Can't create app folder. Please fix permissions. %s" => "Es kann kein Applikationsordner erstellt werden. Bitte passen sie die Berechtigungen an. %s", "Application is not enabled" => "Die Anwendung ist nicht aktiviert", diff --git a/lib/l10n/de_DE.php b/lib/l10n/de_DE.php index eafd76b7ee9..0a72f443e4d 100644 --- a/lib/l10n/de_DE.php +++ b/lib/l10n/de_DE.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Applikation \"%s\" kann nicht installiert werden, da sie mit dieser ownCloud Version nicht kompatibel ist.", +"No app name specified" => "Es wurde kein Applikation-Name angegeben", "Help" => "Hilfe", "Personal" => "Persönlich", "Settings" => "Einstellungen", @@ -13,8 +15,16 @@ $TRANSLATIONS = array( "Back to Files" => "Zurück zu \"Dateien\"", "Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Laden Sie die Dateien in kleineren, separaten, Stücken herunter oder bitten Sie Ihren Administrator.", +"No source specified when installing app" => "Für die Installation der Applikation wurde keine Quelle angegeben", +"No href specified when installing app from http" => "Der Link (href) wurde nicht angegeben um die Applikation per http zu installieren", +"No path specified when installing app from local file" => "Bei der Installation der Applikation aus einer lokalen Datei wurde kein Pfad angegeben", "Archives of type %s are not supported" => "Archive des Typs %s werden nicht unterstützt.", +"Failed to open archive when installing app" => "Das Archiv konnte bei der Installation der Applikation nicht geöffnet werden", +"App does not provide an info.xml file" => "Die Applikation enthält keine info,xml Datei", +"App can't be installed because of not allowed code in the App" => "Die Applikation kann auf Grund von unerlaubten Code nicht installiert werden", "App can't be installed because it is not compatible with this version of ownCloud" => "Die Anwendung konnte nicht installiert werden, weil Sie nicht mit dieser Version von ownCloud kompatibel ist.", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Die Applikation konnte nicht installiert werden, da diese das <shipped>true</shipped> Tag beinhaltet und dieses, bei nicht mitausgelieferten Applikationen, nicht erlaubt ist ist", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Die Applikation konnte nicht installiert werden, da die Version in der info.xml nicht die gleiche Version wie im App-Store ist", "App directory already exists" => "Der Ordner für die Anwendung existiert bereits.", "Can't create app folder. Please fix permissions. %s" => "Der Ordner für die Anwendung konnte nicht angelegt werden. Bitte überprüfen Sie die Ordner- und Dateirechte und passen Sie diese entsprechend an. %s", "Application is not enabled" => "Die Anwendung ist nicht aktiviert", diff --git a/lib/l10n/en_GB.php b/lib/l10n/en_GB.php new file mode 100644 index 00000000000..f799c071c76 --- /dev/null +++ b/lib/l10n/en_GB.php @@ -0,0 +1,69 @@ +<?php +$TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "App \"%s\" can't be installed because it is not compatible with this version of ownCloud.", +"No app name specified" => "No app name specified", +"Help" => "Help", +"Personal" => "Personal", +"Settings" => "Settings", +"Users" => "Users", +"Admin" => "Admin", +"Failed to upgrade \"%s\"." => "Failed to upgrade \"%s\".", +"web services under your control" => "web services under your control", +"cannot open \"%s\"" => "cannot open \"%s\"", +"ZIP download is turned off." => "ZIP download is turned off.", +"Files need to be downloaded one by one." => "Files need to be downloaded one by one.", +"Back to Files" => "Back to Files", +"Selected files too large to generate zip file." => "Selected files too large to generate zip file.", +"Download the files in smaller chunks, seperately or kindly ask your administrator." => "Download the files in smaller chunks, seperately or kindly ask your administrator.", +"No source specified when installing app" => "No source specified when installing app", +"No href specified when installing app from http" => "No href specified when installing app from http", +"No path specified when installing app from local file" => "No path specified when installing app from local file", +"Archives of type %s are not supported" => "Archives of type %s are not supported", +"Failed to open archive when installing app" => "Failed to open archive when installing app", +"App does not provide an info.xml file" => "App does not provide an info.xml file", +"App can't be installed because of not allowed code in the App" => "App can't be installed because of unallowed code in the App", +"App can't be installed because it is not compatible with this version of ownCloud" => "App can't be installed because it is not compatible with this version of ownCloud", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "App can't be installed because the version in info.xml/version is not the same as the version reported from the app store", +"App directory already exists" => "App directory already exists", +"Can't create app folder. Please fix permissions. %s" => "Can't create app folder. Please fix permissions. %s", +"Application is not enabled" => "Application is not enabled", +"Authentication error" => "Authentication error", +"Token expired. Please reload page." => "Token expired. Please reload page.", +"Files" => "Files", +"Text" => "Text", +"Images" => "Images", +"%s enter the database username." => "%s enter the database username.", +"%s enter the database name." => "%s enter the database name.", +"%s you may not use dots in the database name" => "%s you may not use dots in the database name", +"MS SQL username and/or password not valid: %s" => "MS SQL username and/or password not valid: %s", +"You need to enter either an existing account or the administrator." => "You need to enter either an existing account or the administrator.", +"MySQL username and/or password not valid" => "MySQL username and/or password not valid", +"DB Error: \"%s\"" => "DB Error: \"%s\"", +"Offending command was: \"%s\"" => "Offending command was: \"%s\"", +"MySQL user '%s'@'localhost' exists already." => "MySQL user '%s'@'localhost' exists already.", +"Drop this user from MySQL" => "Drop this user from MySQL", +"MySQL user '%s'@'%%' already exists" => "MySQL user '%s'@'%%' already exists", +"Drop this user from MySQL." => "Drop this user from MySQL.", +"Oracle connection could not be established" => "Oracle connection could not be established", +"Oracle username and/or password not valid" => "Oracle username and/or password not valid", +"Offending command was: \"%s\", name: %s, password: %s" => "Offending command was: \"%s\", name: %s, password: %s", +"PostgreSQL username and/or password not valid" => "PostgreSQL username and/or password not valid", +"Set an admin username." => "Set an admin username.", +"Set an admin password." => "Set an admin password.", +"Your web server is not yet properly setup to allow files synchronization because the WebDAV interface seems to be broken." => "Your web server is not yet properly setup to allow files synchronisation because the WebDAV interface seems to be broken.", +"Please double check the <a href='%s'>installation guides</a>." => "Please double check the <a href='%s'>installation guides</a>.", +"seconds ago" => "seconds ago", +"_%n minute ago_::_%n minutes ago_" => array("","%n minutes ago"), +"_%n hour ago_::_%n hours ago_" => array("","%n hours ago"), +"today" => "today", +"yesterday" => "yesterday", +"_%n day go_::_%n days ago_" => array("","%n days ago"), +"last month" => "last month", +"_%n month ago_::_%n months ago_" => array("","%n months ago"), +"last year" => "last year", +"years ago" => "years ago", +"Caused by:" => "Caused by:", +"Could not find category \"%s\"" => "Could not find category \"%s\"" +); +$PLURAL_FORMS = "nplurals=2; plural=(n != 1);"; diff --git a/lib/l10n/gl.php b/lib/l10n/gl.php index 4d92e89ebba..a8fee3b1bc1 100644 --- a/lib/l10n/gl.php +++ b/lib/l10n/gl.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Non é posíbel instalar o aplicativo «%s» por non seren compatíbel con esta versión do ownCloud.", +"No app name specified" => "Non se especificou o nome do aplicativo", "Help" => "Axuda", "Personal" => "Persoal", "Settings" => "Axustes", @@ -13,6 +15,18 @@ $TRANSLATIONS = array( "Back to Files" => "Volver aos ficheiros", "Selected files too large to generate zip file." => "Os ficheiros seleccionados son demasiado grandes como para xerar un ficheiro zip.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Descargue os ficheiros en cachos máis pequenos e por separado, ou pídallos amabelmente ao seu administrador.", +"No source specified when installing app" => "Non foi especificada ningunha orixe ao instalar aplicativos", +"No href specified when installing app from http" => "Non foi especificada ningunha href ao instalar aplicativos", +"No path specified when installing app from local file" => "Non foi especificada ningunha ruta ao instalar aplicativos desde un ficheiro local", +"Archives of type %s are not supported" => "Os arquivos do tipo %s non están admitidos", +"Failed to open archive when installing app" => "Non foi posíbel abrir o arquivo ao instalar aplicativos", +"App does not provide an info.xml file" => "O aplicativo non fornece un ficheiro info.xml", +"App can't be installed because of not allowed code in the App" => "Non é posíbel instalar o aplicativo por mor de conter código non permitido", +"App can't be installed because it is not compatible with this version of ownCloud" => "Non é posíbel instalar o aplicativo por non seren compatíbel con esta versión do ownCloud.", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Non é posíbel instalar o aplicativo por conter a etiqueta\n<shipped>\n\ntrue\n</shipped>\nque non está permitida para os aplicativos non enviados", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Non é posíbel instalar o aplicativo xa que a versión en info.xml/version non é a mesma que a versión informada desde a App Store", +"App directory already exists" => "Xa existe o directorio do aplicativo", +"Can't create app folder. Please fix permissions. %s" => "Non é posíbel crear o cartafol de aplicativos. Corrixa os permisos. %s", "Application is not enabled" => "O aplicativo non está activado", "Authentication error" => "Produciuse un erro de autenticación", "Token expired. Please reload page." => "Testemuña caducada. Recargue a páxina.", diff --git a/lib/l10n/it.php b/lib/l10n/it.php index 983152a14ca..a35027eb962 100644 --- a/lib/l10n/it.php +++ b/lib/l10n/it.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "L'applicazione \"%s\" non può essere installata poiché non è compatibile con questa versione di ownCloud.", +"No app name specified" => "Il nome dell'applicazione non è specificato", "Help" => "Aiuto", "Personal" => "Personale", "Settings" => "Impostazioni", @@ -13,6 +15,17 @@ $TRANSLATIONS = array( "Back to Files" => "Torna ai file", "Selected files too large to generate zip file." => "I file selezionati sono troppo grandi per generare un file zip.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Scarica i file in blocchi più piccoli, separatamente o chiedi al tuo amministratore.", +"No source specified when installing app" => "Nessuna fonte specificata durante l'installazione dell'applicazione", +"No href specified when installing app from http" => "Nessun href specificato durante l'installazione dell'applicazione da http", +"No path specified when installing app from local file" => "Nessun percorso specificato durante l'installazione dell'applicazione da file locale", +"Archives of type %s are not supported" => "Gli archivi di tipo %s non sono supportati", +"Failed to open archive when installing app" => "Apertura archivio non riuscita durante l'installazione dell'applicazione", +"App does not provide an info.xml file" => "L'applicazione non fornisce un file info.xml", +"App can't be installed because of not allowed code in the App" => "L'applicazione non può essere installata a causa di codice non consentito al suo interno", +"App can't be installed because it is not compatible with this version of ownCloud" => "L'applicazione non può essere installata poiché non è compatibile con questa versione di ownCloud", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "L'applicazione non può essere installata poiché la versione in info.xml/version non è la stessa riportata dall'app store", +"App directory already exists" => "La cartella dell'applicazione esiste già", +"Can't create app folder. Please fix permissions. %s" => "Impossibile creare la cartella dell'applicazione. Correggi i permessi. %s", "Application is not enabled" => "L'applicazione non è abilitata", "Authentication error" => "Errore di autenticazione", "Token expired. Please reload page." => "Token scaduto. Ricarica la pagina.", diff --git a/lib/l10n/sk_SK.php b/lib/l10n/sk_SK.php index 4101af247c2..13487b039d6 100644 --- a/lib/l10n/sk_SK.php +++ b/lib/l10n/sk_SK.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Aplikácia \"%s\" nemôže byť nainštalovaná kvôli nekompatibilite z danou verziou ownCloudu.", +"No app name specified" => "Nešpecifikované meno aplikácie", "Help" => "Pomoc", "Personal" => "Osobné", "Settings" => "Nastavenia", @@ -13,6 +15,18 @@ $TRANSLATIONS = array( "Back to Files" => "Späť na súbory", "Selected files too large to generate zip file." => "Zvolené súbory sú príliš veľké na vygenerovanie zip súboru.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Stiahnite súbory po menších častiach, samostatne, alebo sa obráťte na správcu.", +"No source specified when installing app" => "Nešpecifikovaný zdroj pri inštalácii aplikácie", +"No href specified when installing app from http" => "Nešpecifikovaný atribút \"href\" pri inštalácii aplikácie pomocou protokolu \"http\"", +"No path specified when installing app from local file" => "Nešpecifikovaná cesta pri inštalácii aplikácie z lokálneho súboru", +"Archives of type %s are not supported" => "Typ archívu %s nie je podporovaný", +"Failed to open archive when installing app" => "Zlyhanie pri otváraní archívu počas inštalácie aplikácie", +"App does not provide an info.xml file" => "Aplikácia neposkytuje súbor info.xml", +"App can't be installed because of not allowed code in the App" => "Aplikácia nemôže byť inštalovaná pre nepovolený kód v aplikácii", +"App can't be installed because it is not compatible with this version of ownCloud" => "Aplikácia nemôže byť inštalovaná pre nekompatibilitu z danou verziou ownCloudu", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Aplikácia nemôže byť inštalovaná pretože obsahuje <shipped>pravý</shipped> štítok, ktorý nie je povolený pre zaslané \"shipped\" aplikácie", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Aplikácia nemôže byť inštalovaná pretože verzia v info.xml/version nezodpovedá verzii špecifikovanej v aplikačnom obchode", +"App directory already exists" => "Aplikačný adresár už existuje", +"Can't create app folder. Please fix permissions. %s" => "Nemožno vytvoriť aplikačný priečinok. Prosím upravte povolenia. %s", "Application is not enabled" => "Aplikácia nie je zapnutá", "Authentication error" => "Chyba autentifikácie", "Token expired. Please reload page." => "Token vypršal. Obnovte, prosím, stránku.", diff --git a/lib/l10n/sv.php b/lib/l10n/sv.php index dd54e6ca5d3..e7c3420a85b 100644 --- a/lib/l10n/sv.php +++ b/lib/l10n/sv.php @@ -1,5 +1,7 @@ <?php $TRANSLATIONS = array( +"App \"%s\" can't be installed because it is not compatible with this version of ownCloud." => "Appen \"%s\" kan inte installeras eftersom att den inte är kompatibel med denna version av ownCloud.", +"No app name specified" => "Inget appnamn angivet", "Help" => "Hjälp", "Personal" => "Personligt", "Settings" => "Inställningar", @@ -13,6 +15,18 @@ $TRANSLATIONS = array( "Back to Files" => "Tillbaka till Filer", "Selected files too large to generate zip file." => "Valda filer är för stora för att skapa zip-fil.", "Download the files in smaller chunks, seperately or kindly ask your administrator." => "Ladda ner filerna i mindre bitar, separat eller fråga din administratör.", +"No source specified when installing app" => "Ingen källa angiven vid installation av app ", +"No href specified when installing app from http" => "Ingen href angiven vid installation av app från http", +"No path specified when installing app from local file" => "Ingen sökväg angiven vid installation av app från lokal fil", +"Archives of type %s are not supported" => "Arkiv av typen %s stöds ej", +"Failed to open archive when installing app" => "Kunde inte öppna arkivet när appen skulle installeras", +"App does not provide an info.xml file" => "Appen har ingen info.xml fil", +"App can't be installed because of not allowed code in the App" => "Appen kan inte installeras eftersom att den innehåller otillåten kod", +"App can't be installed because it is not compatible with this version of ownCloud" => "Appen kan inte installeras eftersom att den inte är kompatibel med denna version av ownCloud", +"App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps" => "Appen kan inte installeras eftersom att den innehåller etiketten <shipped>true</shipped> vilket inte är tillåtet för icke inkluderade appar", +"App can't be installed because the version in info.xml/version is not the same as the version reported from the app store" => "Appen kan inte installeras eftersom versionen i info.xml inte är samma som rapporteras från app store", +"App directory already exists" => "Appens mapp finns redan", +"Can't create app folder. Please fix permissions. %s" => "Kan inte skapa appens mapp. Var god åtgärda rättigheterna. %s", "Application is not enabled" => "Applikationen är inte aktiverad", "Authentication error" => "Fel vid autentisering", "Token expired. Please reload page." => "Ogiltig token. Ladda om sidan.", diff --git a/lib/preview.php b/lib/preview.php new file mode 100755 index 00000000000..b40ba191fba --- /dev/null +++ b/lib/preview.php @@ -0,0 +1,627 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + * + * Thumbnails: + * structure of filename: + * /data/user/thumbnails/pathhash/x-y.png + * + */ +namespace OC; + +require_once 'preview/image.php'; +require_once 'preview/movies.php'; +require_once 'preview/mp3.php'; +require_once 'preview/pdf.php'; +require_once 'preview/svg.php'; +require_once 'preview/txt.php'; +require_once 'preview/unknown.php'; +require_once 'preview/office.php'; + +class Preview { + //the thumbnail folder + const THUMBNAILS_FOLDER = 'thumbnails'; + + //config + private $maxScaleFactor; + private $configMaxX; + private $configMaxY; + + //fileview object + private $fileView = null; + private $userView = null; + + //vars + private $file; + private $maxX; + private $maxY; + private $scalingup; + + //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 + * @param string $root path of root + * @param string $file The path to the file where you want a thumbnail from + * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image + * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param bool $scalingUp Disable/Enable upscaling of previews + * @return mixed (bool / string) + * false if thumbnail does not exist + * path to thumbnail if thumbnail exists + */ + public function __construct($user='', $root='/', $file='', $maxX=1, $maxY=1, $scalingUp=true) { + //set config + $this->configMaxX = \OC_Config::getValue('preview_max_x', null); + $this->configMaxY = \OC_Config::getValue('preview_max_y', null); + $this->maxScaleFactor = \OC_Config::getValue('preview_max_scale_factor', 2); + + //save parameters + $this->setFile($file); + $this->setMaxX($maxX); + $this->setMaxY($maxY); + $this->setScalingUp($scalingUp); + + //init fileviews + if($user === ''){ + $user = \OC_User::getUser(); + } + $this->fileView = new \OC\Files\View('/' . $user . '/' . $root); + $this->userView = new \OC\Files\View('/' . $user); + + $this->preview = null; + + //check if there are preview backends + if(empty(self::$providers)) { + self::initProviders(); + } + + if(empty(self::$providers)) { + \OC_Log::write('core', 'No preview providers exist', \OC_Log::ERROR); + throw new \Exception('No preview providers'); + } + } + + /** + * @brief returns the path of the file you want a thumbnail from + * @return string + */ + public function getFile() { + return $this->file; + } + + /** + * @brief returns the max width of the preview + * @return integer + */ + public function getMaxX() { + return $this->maxX; + } + + /** + * @brief returns the max height of the preview + * @return integer + */ + public function getMaxY() { + return $this->maxY; + } + + /** + * @brief returns whether or not scalingup is enabled + * @return bool + */ + public function getScalingUp() { + return $this->scalingup; + } + + /** + * @brief returns the name of the thumbnailfolder + * @return string + */ + public function getThumbnailsFolder() { + return self::THUMBNAILS_FOLDER; + } + + /** + * @brief returns the max scale factor + * @return integer + */ + public function getMaxScaleFactor() { + return $this->maxScaleFactor; + } + + /** + * @brief returns the max width set in ownCloud's config + * @return integer + */ + public function getConfigMaxX() { + return $this->configMaxX; + } + + /** + * @brief returns the max height set in ownCloud's config + * @return integer + */ + public function getConfigMaxY() { + return $this->configMaxY; + } + + /** + * @brief set the path of the file you want a thumbnail from + * @param string $file + * @return $this + */ + public function setFile($file) { + $this->file = $file; + return $this; + } + + /** + * @brief set the the max width of the preview + * @param int $maxX + * @return $this + */ + public function setMaxX($maxX=1) { + if($maxX <= 0) { + throw new \Exception('Cannot set width of 0 or smaller!'); + } + $configMaxX = $this->getConfigMaxX(); + if(!is_null($configMaxX)) { + if($maxX > $configMaxX) { + \OC_Log::write('core', 'maxX reduced from ' . $maxX . ' to ' . $configMaxX, \OC_Log::DEBUG); + $maxX = $configMaxX; + } + } + $this->maxX = $maxX; + return $this; + } + + /** + * @brief set the the max height of the preview + * @param int $maxY + * @return $this + */ + public function setMaxY($maxY=1) { + if($maxY <= 0) { + throw new \Exception('Cannot set height of 0 or smaller!'); + } + $configMaxY = $this->getConfigMaxY(); + if(!is_null($configMaxY)) { + if($maxY > $configMaxY) { + \OC_Log::write('core', 'maxX reduced from ' . $maxY . ' to ' . $configMaxY, \OC_Log::DEBUG); + $maxY = $configMaxY; + } + } + $this->maxY = $maxY; + return $this; + } + + /** + * @brief set whether or not scalingup is enabled + * @param bool $scalingUp + * @return $this + */ + public function setScalingup($scalingUp) { + if($this->getMaxScaleFactor() === 1) { + $scalingUp = false; + } + $this->scalingup = $scalingUp; + return $this; + } + + /** + * @brief check if all parameters are valid + * @return bool + */ + public function isFileValid() { + $file = $this->getFile(); + if($file === '') { + \OC_Log::write('core', 'No filename passed', \OC_Log::DEBUG); + return false; + } + + if(!$this->fileView->file_exists($file)) { + \OC_Log::write('core', 'File:"' . $file . '" not found', \OC_Log::DEBUG); + return false; + } + + return true; + } + + /** + * @brief deletes previews of a file with specific x and y + * @return bool + */ + public function deletePreview() { + $file = $this->getFile(); + + $fileInfo = $this->fileView->getFileInfo($file); + $fileId = $fileInfo['fileid']; + + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/' . $this->getMaxX() . '-' . $this->getMaxY() . '.png'; + $this->userView->unlink($previewPath); + return !$this->userView->file_exists($previewPath); + } + + /** + * @brief deletes all previews of a file + * @return bool + */ + public function deleteAllPreviews() { + $file = $this->getFile(); + + $fileInfo = $this->fileView->getFileInfo($file); + $fileId = $fileInfo['fileid']; + + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + $this->userView->deleteAll($previewPath); + $this->userView->rmdir($previewPath); + return !$this->userView->is_dir($previewPath); + } + + /** + * @brief check if thumbnail or bigger version of thumbnail of file is cached + * @return mixed (bool / string) + * false if thumbnail does not exist + * path to thumbnail if thumbnail exists + */ + private function isCached() { + $file = $this->getFile(); + $maxX = $this->getMaxX(); + $maxY = $this->getMaxY(); + $scalingUp = $this->getScalingUp(); + $maxScaleFactor = $this->getMaxScaleFactor(); + + $fileInfo = $this->fileView->getFileInfo($file); + $fileId = $fileInfo['fileid']; + + if(is_null($fileId)) { + return false; + } + + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + if(!$this->userView->is_dir($previewPath)) { + return false; + } + + //does a preview with the wanted height and width already exist? + if($this->userView->file_exists($previewPath . $maxX . '-' . $maxY . '.png')) { + return $previewPath . $maxX . '-' . $maxY . '.png'; + } + + $wantedAspectRatio = (float) ($maxX / $maxY); + + //array for usable cached thumbnails + $possibleThumbnails = array(); + + $allThumbnails = $this->userView->getDirectoryContent($previewPath); + foreach($allThumbnails as $thumbnail) { + $name = rtrim($thumbnail['name'], '.png'); + $size = explode('-', $name); + $x = (int) $size[0]; + $y = (int) $size[1]; + + $aspectRatio = (float) ($x / $y); + if($aspectRatio !== $wantedAspectRatio) { + continue; + } + + if($x < $maxX || $y < $maxY) { + if($scalingUp) { + $scalefactor = $maxX / $x; + if($scalefactor > $maxScaleFactor) { + continue; + } + }else{ + continue; + } + } + $possibleThumbnails[$x] = $thumbnail['path']; + } + + if(count($possibleThumbnails) === 0) { + return false; + } + + if(count($possibleThumbnails) === 1) { + return current($possibleThumbnails); + } + + ksort($possibleThumbnails); + + if(key(reset($possibleThumbnails)) > $maxX) { + return current(reset($possibleThumbnails)); + } + + if(key(end($possibleThumbnails)) < $maxX) { + return current(end($possibleThumbnails)); + } + + foreach($possibleThumbnails as $width => $path) { + if($width < $maxX) { + continue; + }else{ + return $path; + } + } + } + + /** + * @brief return a preview of a file + * @return \OC_Image + */ + public function getPreview() { + if(!is_null($this->preview) && $this->preview->valid()){ + return $this->preview; + } + + $this->preview = null; + $file = $this->getFile(); + $maxX = $this->getMaxX(); + $maxY = $this->getMaxY(); + $scalingUp = $this->getScalingUp(); + + $fileInfo = $this->fileView->getFileInfo($file); + $fileId = $fileInfo['fileid']; + + $cached = $this->isCached(); + + if($cached) { + $image = new \OC_Image($this->userView->file_get_contents($cached, 'r')); + $this->preview = $image->valid() ? $image : null; + $this->resizeAndCrop(); + } + + if(is_null($this->preview)) { + $mimetype = $this->fileView->getMimeType($file); + $preview = null; + + foreach(self::$providers as $supportedMimetype => $provider) { + if(!preg_match($supportedMimetype, $mimetype)) { + continue; + } + + \OC_Log::write('core', 'Generating preview for "' . $file . '" with "' . get_class($provider) . '"', \OC_Log::DEBUG); + + $preview = $provider->getThumbnail($file, $maxX, $maxY, $scalingUp, $this->fileView); + + if(!($preview instanceof \OC_Image)) { + continue; + } + + $this->preview = $preview; + $this->resizeAndCrop(); + + $previewPath = $this->getThumbnailsFolder() . '/' . $fileId . '/'; + $cachePath = $previewPath . $maxX . '-' . $maxY . '.png'; + + if($this->userView->is_dir($this->getThumbnailsFolder() . '/') === false) { + $this->userView->mkdir($this->getThumbnailsFolder() . '/'); + } + + if($this->userView->is_dir($previewPath) === false) { + $this->userView->mkdir($previewPath); + } + + $this->userView->file_put_contents($cachePath, $preview->data()); + + break; + } + } + + if(is_null($this->preview)) { + $this->preview = new \OC_Image(); + } + + return $this->preview; + } + + /** + * @brief show preview + * @return void + */ + public function showPreview() { + \OCP\Response::enableCaching(3600 * 24); // 24 hours + if(is_null($this->preview)) { + $this->getPreview(); + } + $this->preview->show(); + return; + } + + /** + * @brief show preview + * @return void + */ + public function show() { + $this->showPreview(); + return; + } + + /** + * @brief resize, crop and fix orientation + * @return void + */ + private function resizeAndCrop() { + $image = $this->preview; + $x = $this->getMaxX(); + $y = $this->getMaxY(); + $scalingUp = $this->getScalingUp(); + $maxscalefactor = $this->getMaxScaleFactor(); + + if(!($image instanceof \OC_Image)) { + \OC_Log::write('core', '$this->preview is not an instance of OC_Image', \OC_Log::DEBUG); + return; + } + + $image->fixOrientation(); + + $realx = (int) $image->width(); + $realy = (int) $image->height(); + + if($x === $realx && $y === $realy) { + $this->preview = $image; + return; + } + + $factorX = $x / $realx; + $factorY = $y / $realy; + + if($factorX >= $factorY) { + $factor = $factorX; + }else{ + $factor = $factorY; + } + + if($scalingUp === false) { + if($factor > 1) { + $factor = 1; + } + } + + if(!is_null($maxscalefactor)) { + if($factor > $maxscalefactor) { + \OC_Log::write('core', 'scalefactor reduced from ' . $factor . ' to ' . $maxscalefactor, \OC_Log::DEBUG); + $factor = $maxscalefactor; + } + } + + $newXsize = (int) ($realx * $factor); + $newYsize = (int) ($realy * $factor); + + $image->preciseResize($newXsize, $newYsize); + + if($newXsize === $x && $newYsize === $y) { + $this->preview = $image; + return; + } + + if($newXsize >= $x && $newYsize >= $y) { + $cropX = floor(abs($x - $newXsize) * 0.5); + //don't crop previews on the Y axis, this sucks if it's a document. + //$cropY = floor(abs($y - $newYsize) * 0.5); + $cropY = 0; + + $image->crop($cropX, $cropY, $x, $y); + + $this->preview = $image; + return; + } + + if($newXsize < $x || $newYsize < $y) { + if($newXsize > $x) { + $cropX = floor(($newXsize - $x) * 0.5); + $image->crop($cropX, 0, $x, $newYsize); + } + + if($newYsize > $y) { + $cropY = floor(($newYsize - $y) * 0.5); + $image->crop(0, $cropY, $newXsize, $y); + } + + $newXsize = (int) $image->width(); + $newYsize = (int) $image->height(); + + //create transparent background layer + $backgroundlayer = imagecreatetruecolor($x, $y); + $white = imagecolorallocate($backgroundlayer, 255, 255, 255); + imagefill($backgroundlayer, 0, 0, $white); + + $image = $image->resource(); + + $mergeX = floor(abs($x - $newXsize) * 0.5); + $mergeY = floor(abs($y - $newYsize) * 0.5); + + imagecopy($backgroundlayer, $image, $mergeX, $mergeY, 0, 0, $newXsize, $newYsize); + + //$black = imagecolorallocate(0,0,0); + //imagecolortransparent($transparentlayer, $black); + + $image = new \OC_Image($backgroundlayer); + + $this->preview = $image; + return; + } + } + + /** + * @brief register a new preview provider to be used + * @param string $provider class name of a Preview_Provider + * @param array $options + * @return void + */ + public static function registerProvider($class, $options=array()) { + self::$registeredProviders[]=array('class'=>$class, 'options'=>$options); + } + + /** + * @brief create instances of all the registered preview providers + * @return void + */ + private static function initProviders() { + if(!\OC_Config::getValue('enable_previews', true)) { + $provider = new Preview\Unknown(array()); + self::$providers = array($provider->getMimeType() => $provider); + return; + } + + if(count(self::$providers)>0) { + return; + } + + foreach(self::$registeredProviders as $provider) { + $class=$provider['class']; + $options=$provider['options']; + + $object = new $class($options); + + self::$providers[$object->getMimeType()] = $object; + } + + $keys = array_map('strlen', array_keys(self::$providers)); + array_multisort($keys, SORT_DESC, self::$providers); + } + + public static function post_write($args) { + self::post_delete($args); + } + + public static function post_delete($args) { + $path = $args['path']; + if(substr($path, 0, 1) === '/') { + $path = substr($path, 1); + } + $preview = new Preview(\OC_User::getUser(), 'files/', $path); + $preview->deleteAllPreviews(); + } + + public static function isMimeSupported($mimetype) { + if(!\OC_Config::getValue('enable_previews', true)) { + return false; + } + + //check if there are preview backends + if(empty(self::$providers)) { + self::initProviders(); + } + + //remove last element because it has the mimetype * + $providers = array_slice(self::$providers, 0, -1); + foreach($providers as $supportedMimetype => $provider) { + if(preg_match($supportedMimetype, $mimetype)) { + return true; + } + } + return false; + } +}
\ No newline at end of file diff --git a/lib/preview/image.php b/lib/preview/image.php new file mode 100644 index 00000000000..9aec967282d --- /dev/null +++ b/lib/preview/image.php @@ -0,0 +1,36 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +class Image extends Provider { + + public function getMimeType() { + return '/image\/.*/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + //get fileinfo + $fileInfo = $fileview->getFileInfo($path); + if(!$fileInfo) { + return false; + } + + //check if file is encrypted + if($fileInfo['encrypted'] === true) { + $image = new \OC_Image(stream_get_contents($fileview->fopen($path, 'r'))); + }else{ + $image = new \OC_Image(); + $image->loadFromFile($fileview->getLocalFile($path)); + } + + return $image->valid() ? $image : false; + } +} + +\OC\Preview::registerProvider('OC\Preview\Image');
\ No newline at end of file diff --git a/lib/preview/movies.php b/lib/preview/movies.php new file mode 100644 index 00000000000..e2a1b8edddc --- /dev/null +++ b/lib/preview/movies.php @@ -0,0 +1,47 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); +$whichFFMPEG = shell_exec('which ffmpeg'); +$isFFMPEGAvailable = !empty($whichFFMPEG); + +if($isShellExecEnabled && $isFFMPEGAvailable) { + + class Movie extends Provider { + + public function getMimeType() { + return '/video\/.*/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $absPath = \OC_Helper::tmpFile(); + $tmpPath = \OC_Helper::tmpFile(); + + $handle = $fileview->fopen($path, 'rb'); + + $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 + file_put_contents($absPath, $firstmb); + + //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath; + $cmd = 'ffmpeg -an -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 ' . escapeshellarg($tmpPath); + + shell_exec($cmd); + + $image = new \OC_Image($tmpPath); + + unlink($absPath); + unlink($tmpPath); + + return $image->valid() ? $image : false; + } + } + + \OC\Preview::registerProvider('OC\Preview\Movie'); +}
\ No newline at end of file diff --git a/lib/preview/mp3.php b/lib/preview/mp3.php new file mode 100644 index 00000000000..1eed566315c --- /dev/null +++ b/lib/preview/mp3.php @@ -0,0 +1,48 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +class MP3 extends Provider { + + public function getMimeType() { + return '/audio\/mpeg/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + require_once('getid3/getid3.php'); + + $getID3 = new \getID3(); + + $tmpPath = $fileview->toTmpFile($path); + + $tags = $getID3->analyze($tmpPath); + \getid3_lib::CopyTagsToComments($tags); + if(isset($tags['id3v2']['APIC'][0]['data'])) { + $picture = @$tags['id3v2']['APIC'][0]['data']; + unlink($tmpPath); + $image = new \OC_Image($picture); + return $image->valid() ? $image : $this->getNoCoverThumbnail(); + } + + return $this->getNoCoverThumbnail(); + } + + private function getNoCoverThumbnail() { + $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png'; + + if(!file_exists($icon)) { + return false; + } + + $image = new \OC_Image($icon); + return $image->valid() ? $image : false; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MP3');
\ No newline at end of file diff --git a/lib/preview/office-cl.php b/lib/preview/office-cl.php new file mode 100644 index 00000000000..112909d6523 --- /dev/null +++ b/lib/preview/office-cl.php @@ -0,0 +1,134 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +//we need imagick to convert +class Office extends Provider { + + private $cmd; + + public function getMimeType() { + return null; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $this->initCmd(); + if(is_null($this->cmd)) { + return false; + } + + $absPath = $fileview->toTmpFile($path); + + $tmpDir = get_temp_dir(); + + $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir '; + $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters); + + $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); + $export = 'export HOME=/' . $tmpDir; + + shell_exec($export . "\n" . $exec); + + //create imagick object from pdf + try{ + $pdf = new \imagick($absPath . '.pdf' . '[0]'); + $pdf->setImageFormat('jpg'); + } catch (\Exception $e) { + unlink($absPath); + unlink($absPath . '.pdf'); + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; + } + + $image = new \OC_Image($pdf); + + unlink($absPath); + unlink($absPath . '.pdf'); + + return $image->valid() ? $image : false; + } + + private function initCmd() { + $cmd = ''; + + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); + } + + $whichLibreOffice = shell_exec('which libreoffice'); + if($cmd === '' && !empty($whichLibreOffice)) { + $cmd = 'libreoffice'; + } + + $whichOpenOffice = shell_exec('which openoffice'); + if($cmd === '' && !empty($whichOpenOffice)) { + $cmd = 'openoffice'; + } + + if($cmd === '') { + $cmd = null; + } + + $this->cmd = $cmd; + } +} + +//.doc, .dot +class MSOfficeDoc extends Office { + + public function getMimeType() { + return '/application\/msword/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MSOfficeDoc'); + +//.docm, .dotm, .xls(m), .xlt(m), .xla(m), .ppt(m), .pot(m), .pps(m), .ppa(m) +class MSOffice2003 extends Office { + + public function getMimeType() { + return '/application\/vnd.ms-.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MSOffice2003'); + +//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx +class MSOffice2007 extends Office { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\MSOffice2007'); + +//.odt, .ott, .oth, .odm, .odg, .otg, .odp, .otp, .ods, .ots, .odc, .odf, .odb, .odi, .oxt +class OpenDocument extends Office { + + public function getMimeType() { + return '/application\/vnd.oasis.opendocument.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\OpenDocument'); + +//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm +class StarOffice extends Office { + + public function getMimeType() { + return '/application\/vnd.sun.xml.*/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\StarOffice');
\ No newline at end of file diff --git a/lib/preview/office-fallback.php b/lib/preview/office-fallback.php new file mode 100644 index 00000000000..e69ab0ab8cb --- /dev/null +++ b/lib/preview/office-fallback.php @@ -0,0 +1,142 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +/* //There is no (good) php-only solution for converting 2003 word documents to pdfs / pngs ... +class DOC extends Provider { + + public function getMimeType() { + return '/application\/msword/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + require_once(''); + } + +} + +\OC\Preview::registerProvider('OC\Preview\DOC'); +*/ + +class DOCX extends Provider { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.wordprocessingml.document/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + require_once('phpdocx/classes/TransformDoc.inc'); + + $tmpDoc = $fileview->toTmpFile($path); + + $transformdoc = new \TransformDoc(); + $transformdoc->setStrFile($tmpDoc); + $transformdoc->generatePDF($tmpDoc); + + $pdf = new \imagick($tmpDoc . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($tmpDoc); + + $image = new \OC_Image($pdf); + + return $image->valid() ? $image : false; + } + +} + +\OC\Preview::registerProvider('OC\Preview\DOCX'); + +class MSOfficeExcel extends Provider { + + public function getMimeType() { + return null; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + require_once('PHPExcel/Classes/PHPExcel.php'); + require_once('PHPExcel/Classes/PHPExcel/IOFactory.php'); + + $absPath = $fileview->toTmpFile($path); + $tmpPath = \OC_Helper::tmpFile(); + + $rendererName = \PHPExcel_Settings::PDF_RENDERER_DOMPDF; + $rendererLibraryPath = \OC::$THIRDPARTYROOT . '/3rdparty/dompdf'; + + \PHPExcel_Settings::setPdfRenderer($rendererName, $rendererLibraryPath); + + $phpexcel = new \PHPExcel($absPath); + $excel = \PHPExcel_IOFactory::createWriter($phpexcel, 'PDF'); + $excel->save($tmpPath); + + $pdf = new \imagick($tmpPath . '[0]'); + $pdf->setImageFormat('jpg'); + + unlink($absPath); + unlink($tmpPath); + + $image = new \OC_Image($pdf); + + return $image->valid() ? $image : false; + } + +} + +class XLS extends MSOfficeExcel { + + public function getMimeType() { + return '/application\/vnd.ms-excel/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\XLS'); + +class XLSX extends MSOfficeExcel { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.spreadsheetml.sheet/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\XLSX'); + +/* //There is no (good) php-only solution for converting powerpoint documents to pdfs / pngs ... +class MSOfficePowerPoint extends Provider { + + public function getMimeType() { + return null; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + return false; + } + +} + +class PPT extends MSOfficePowerPoint { + + public function getMimeType() { + return '/application\/vnd.ms-powerpoint/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PPT'); + +class PPTX extends MSOfficePowerPoint { + + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.presentationml.presentation/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PPTX'); +*/
\ No newline at end of file diff --git a/lib/preview/office.php b/lib/preview/office.php new file mode 100644 index 00000000000..5287bbd6ac1 --- /dev/null +++ b/lib/preview/office.php @@ -0,0 +1,22 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +//both, libreoffice backend and php fallback, need imagick +if (extension_loaded('imagick')) { + $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); + $whichLibreOffice = shell_exec('which libreoffice'); + $isLibreOfficeAvailable = !empty($whichLibreOffice); + $whichOpenOffice = shell_exec('which libreoffice'); + $isOpenOfficeAvailable = !empty($whichOpenOffice); + //let's see if there is libreoffice or openoffice on this machine + if($isShellExecEnabled && ($isLibreOfficeAvailable || $isOpenOfficeAvailable || is_string(\OC_Config::getValue('preview_libreoffice_path', null)))) { + require_once('office-cl.php'); + }else{ + //in case there isn't, use our fallback + require_once('office-fallback.php'); + } +}
\ No newline at end of file diff --git a/lib/preview/pdf.php b/lib/preview/pdf.php new file mode 100644 index 00000000000..cc974b68818 --- /dev/null +++ b/lib/preview/pdf.php @@ -0,0 +1,40 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +if (extension_loaded('imagick')) { + + class PDF extends Provider { + + public function getMimeType() { + return '/application\/pdf/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $tmpPath = $fileview->toTmpFile($path); + + //create imagick object from pdf + try{ + $pdf = new \imagick($tmpPath . '[0]'); + $pdf->setImageFormat('jpg'); + } catch (\Exception $e) { + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; + } + + unlink($tmpPath); + + //new image object + $image = new \OC_Image($pdf); + //check if image object is valid + return $image->valid() ? $image : false; + } + } + + \OC\Preview::registerProvider('OC\Preview\PDF'); +} diff --git a/lib/preview/provider.php b/lib/preview/provider.php new file mode 100644 index 00000000000..e4a730bafc8 --- /dev/null +++ b/lib/preview/provider.php @@ -0,0 +1,19 @@ +<?php +namespace OC\Preview; + +abstract class Provider { + private $options; + + public function __construct($options) { + $this->options=$options; + } + + abstract public function getMimeType(); + + /** + * search for $query + * @param string $query + * @return + */ + abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); +} diff --git a/lib/preview/svg.php b/lib/preview/svg.php new file mode 100644 index 00000000000..b49e51720fa --- /dev/null +++ b/lib/preview/svg.php @@ -0,0 +1,46 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +if (extension_loaded('imagick')) { + + class SVG extends Provider { + + public function getMimeType() { + return '/image\/svg\+xml/'; + } + + public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) { + try{ + $svg = new \Imagick(); + $svg->setBackgroundColor(new \ImagickPixel('transparent')); + + $content = stream_get_contents($fileview->fopen($path, 'r')); + if(substr($content, 0, 5) !== '<?xml') { + $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content; + } + + $svg->readImageBlob($content); + $svg->setImageFormat('png32'); + } catch (\Exception $e) { + \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR); + return false; + } + + + //new image object + $image = new \OC_Image(); + $image->loadFromData($svg); + //check if image object is valid + return $image->valid() ? $image : false; + } + } + + \OC\Preview::registerProvider('OC\Preview\SVG'); + +}
\ No newline at end of file diff --git a/lib/preview/txt.php b/lib/preview/txt.php new file mode 100644 index 00000000000..a487330691e --- /dev/null +++ b/lib/preview/txt.php @@ -0,0 +1,73 @@ +<?php +/** + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +class TXT extends Provider { + + public function getMimeType() { + return '/text\/.*/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $content = $fileview->fopen($path, 'r'); + $content = stream_get_contents($content); + + //don't create previews of empty text files + if(trim($content) === '') { + return false; + } + + $lines = preg_split("/\r\n|\n|\r/", $content); + + $fontSize = 5; //5px + $lineSize = ceil($fontSize * 1.25); + + $image = imagecreate($maxX, $maxY); + imagecolorallocate($image, 255, 255, 255); + $textColor = imagecolorallocate($image, 0, 0, 0); + + foreach($lines as $index => $line) { + $index = $index + 1; + + $x = (int) 1; + $y = (int) ($index * $lineSize) - $fontSize; + + imagestring($image, 1, $x, $y, $line, $textColor); + + if(($index * $lineSize) >= $maxY) { + break; + } + } + + $image = new \OC_Image($image); + + return $image->valid() ? $image : false; + } +} + +\OC\Preview::registerProvider('OC\Preview\TXT'); + +class PHP extends TXT { + + public function getMimeType() { + return '/application\/x-php/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\PHP'); + +class JavaScript extends TXT { + + public function getMimeType() { + return '/application\/javascript/'; + } + +} + +\OC\Preview::registerProvider('OC\Preview\JavaScript');
\ No newline at end of file diff --git a/lib/preview/unknown.php b/lib/preview/unknown.php new file mode 100644 index 00000000000..9e6cd68d401 --- /dev/null +++ b/lib/preview/unknown.php @@ -0,0 +1,27 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OC\Preview; + +class Unknown extends Provider { + + public function getMimeType() { + return '/.*/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $mimetype = $fileview->getMimeType($path); + + $path = \OC_Helper::mimetypeIcon($mimetype); + $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT)); + + return new \OC_Image($path); + } +} + +\OC\Preview::registerProvider('OC\Preview\Unknown');
\ No newline at end of file diff --git a/lib/public/preview.php b/lib/public/preview.php new file mode 100644 index 00000000000..e488eade4da --- /dev/null +++ b/lib/public/preview.php @@ -0,0 +1,34 @@ +<?php +/** + * Copyright (c) 2013 Frank Karlitschek frank@owncloud.org + * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ +namespace OCP; + +/** + * This class provides functions to render and show thumbnails and previews of files + */ +class Preview { + + /** + * @brief return a preview of a file + * @param $file The path to the file where you want a thumbnail from + * @param $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image + * @param $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image + * @param $scaleup Scale smaller images up to the thumbnail size or not. Might look ugly + * @return image + */ + public static function show($file,$maxX=100,$maxY=75,$scaleup=false) { + return(\OC_Preview::show($file,$maxX,$maxY,$scaleup)); + } + + + + public static function isMimeSupported($mimetype='*') { + return \OC\Preview::isMimeSupported($mimetype); + } + +} diff --git a/lib/public/template.php b/lib/public/template.php index ab1089c332d..3b1a4ed4906 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -54,6 +54,25 @@ function mimetype_icon( $mimetype ) { return(\mimetype_icon( $mimetype )); } +/** + * @brief make preview_icon available as a simple function + * Returns the path to the preview of the image. + * @param $path path of file + * @returns link to the preview + */ +function preview_icon( $path ) { + return(\preview_icon( $path )); +} + +/** + * @brief make publicpreview_icon available as a simple function + * Returns the path to the preview of the image. + * @param $path path of file + * @returns link to the preview + */ +function publicPreview_icon ( $path, $token ) { + return(\publicPreview_icon( $path, $token )); +} /** * @brief make OC_Helper::humanFileSize available as a simple function diff --git a/lib/template/functions.php b/lib/template/functions.php index 717e197c1cb..501f8081bff 100644 --- a/lib/template/functions.php +++ b/lib/template/functions.php @@ -59,6 +59,22 @@ function mimetype_icon( $mimetype ) { } /** + * @brief make preview_icon available as a simple function + * Returns the path to the preview of the image. + * @param $path path of file + * @returns link to the preview + * + * For further information have a look at OC_Helper::previewIcon + */ +function preview_icon( $path ) { + return OC_Helper::previewIcon( $path ); +} + +function publicPreview_icon ( $path, $token ) { + return OC_Helper::publicPreviewIcon( $path, $token ); +} + +/** * @brief make OC_Helper::humanFileSize available as a simple function * @param int $bytes size in bytes * @return string size as string diff --git a/lib/util.php b/lib/util.php index e03667b0794..6195178701b 100755 --- a/lib/util.php +++ b/lib/util.php @@ -98,7 +98,7 @@ class OC_Util { public static function getVersion() { // hint: We only can count up. Reset minor/patchlevel when // updating major/minor version number. - return array(5, 80, 05); + return array(5, 80, 07); } /** |