diff options
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/app.php | 10 | ||||
-rw-r--r-- | lib/private/appconfig.php | 6 | ||||
-rw-r--r-- | lib/private/connector/sabre/server.php | 235 | ||||
-rw-r--r-- | lib/private/davclient.php | 46 | ||||
-rw-r--r-- | lib/private/db/mdb2schemamanager.php | 22 | ||||
-rw-r--r-- | lib/private/log/owncloud.php | 1 | ||||
-rw-r--r-- | lib/private/preview/movies.php | 52 | ||||
-rw-r--r-- | lib/private/preview/office-cl.php | 160 | ||||
-rw-r--r-- | lib/private/preview/office.php | 25 | ||||
-rw-r--r-- | lib/private/preview/provider.php | 12 | ||||
-rw-r--r-- | lib/private/preview/txt.php | 35 | ||||
-rw-r--r-- | lib/private/preview/unknown.php | 26 | ||||
-rwxr-xr-x | lib/private/util.php | 11 |
13 files changed, 495 insertions, 146 deletions
diff --git a/lib/private/app.php b/lib/private/app.php index 1a242ad968e..6f45b6e6dd7 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -770,12 +770,12 @@ class OC_App{ } // prio 2: shipped - if ($a['shipped'] != $b['shipped']) { - $atemp = ($a['shipped'] == true ? 1 : 0); - $btemp = ($b['shipped'] == true ? 1 : 0); - return ($btemp - $atemp); + $ashipped = (array_key_exists('shipped', $a) && $a['shipped'] === 'true') ? 1 : 0; + $bshipped = (array_key_exists('shipped', $b) && $b['shipped'] === 'true') ? 1 : 0; + if ($ashipped !== $bshipped) { + return ($bshipped - $ashipped); } - + // prio 3: recommended if ($a['internalclass'] != $b['internalclass']) { $atemp = ($a['internalclass'] == 'recommendedapp' ? 1 : 0); diff --git a/lib/private/appconfig.php b/lib/private/appconfig.php index e615d838173..4f170e054e9 100644 --- a/lib/private/appconfig.php +++ b/lib/private/appconfig.php @@ -134,6 +134,12 @@ class OC_Appconfig{ .' WHERE `appid` = ? AND `configkey` = ?' ); $query->execute( array( $value, $app, $key )); } + // TODO where should this be documented? + \OC_Hook::emit('OC_Appconfig', 'post_set_value', array( + 'app' => $app, + 'key' => $key, + 'value' => $value + )); } /** diff --git a/lib/private/connector/sabre/server.php b/lib/private/connector/sabre/server.php new file mode 100644 index 00000000000..41e8885917a --- /dev/null +++ b/lib/private/connector/sabre/server.php @@ -0,0 +1,235 @@ +<?php +/** + * ownCloud / SabreDAV + * + * @author Markus Goetz + * + * @copyright Copyright (C) 2007-2013 Rooftop Solutions. All rights reserved. + * @author Evert Pot (http://www.rooftopsolutions.nl/) + * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + */ + +/** + * Class OC_Connector_Sabre_Server + * + * This class reimplements some methods from @see Sabre_DAV_Server. + * + * Basically we add handling of depth: infinity. + * + * The right way to handle this would have been to submit a patch to the upstream project + * and grab the corresponding version one merged. + * + * Due to time constrains and the limitations where we don't want to upgrade 3rdparty code in + * this stage of the release cycle we did choose this approach. + * + * For ownCloud 7 we will upgrade SabreDAV and submit the patch - if needed. + * + * @see Sabre_DAV_Server + */ +class OC_Connector_Sabre_Server extends Sabre_DAV_Server { + + /** + * @see Sabre_DAV_Server + */ + protected function httpPropfind($uri) { + + // $xml = new Sabre_DAV_XMLReader(file_get_contents('php://input')); + $requestedProperties = $this->parsePropFindRequest($this->httpRequest->getBody(true)); + + $depth = $this->getHTTPDepth(1); + // The only two options for the depth of a propfind is 0 or 1 + // if ($depth!=0) $depth = 1; + + $newProperties = $this->getPropertiesForPath($uri,$requestedProperties,$depth); + + // This is a multi-status response + $this->httpResponse->sendStatus(207); + $this->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8'); + $this->httpResponse->setHeader('Vary','Brief,Prefer'); + + // Normally this header is only needed for OPTIONS responses, however.. + // iCal seems to also depend on these being set for PROPFIND. Since + // this is not harmful, we'll add it. + $features = array('1','3', 'extended-mkcol'); + foreach($this->plugins as $plugin) { + $features = array_merge($features,$plugin->getFeatures()); + } + + $this->httpResponse->setHeader('DAV',implode(', ',$features)); + + $prefer = $this->getHTTPPrefer(); + $minimal = $prefer['return-minimal']; + + $data = $this->generateMultiStatus($newProperties, $minimal); + $this->httpResponse->sendBody($data); + + } + + /** + * Small helper to support PROPFIND with DEPTH_INFINITY. + */ + private function addPathNodesRecursively(&$nodes, $path) { + foreach($this->tree->getChildren($path) as $childNode) { + $nodes[$path . '/' . $childNode->getName()] = $childNode; + if ($childNode instanceof Sabre_DAV_ICollection) + $this->addPathNodesRecursively($nodes, $path . '/' . $childNode->getName()); + } + } + + public function getPropertiesForPath($path, $propertyNames = array(), $depth = 0) { + + // if ($depth!=0) $depth = 1; + + $path = rtrim($path,'/'); + + $returnPropertyList = array(); + + $parentNode = $this->tree->getNodeForPath($path); + $nodes = array( + $path => $parentNode + ); + if ($depth==1 && $parentNode instanceof Sabre_DAV_ICollection) { + foreach($this->tree->getChildren($path) as $childNode) + $nodes[$path . '/' . $childNode->getName()] = $childNode; + } else if ($depth == self::DEPTH_INFINITY && $parentNode instanceof Sabre_DAV_ICollection) { + $this->addPathNodesRecursively($nodes, $path); + } + + // If the propertyNames array is empty, it means all properties are requested. + // We shouldn't actually return everything we know though, and only return a + // sensible list. + $allProperties = count($propertyNames)==0; + + foreach($nodes as $myPath=>$node) { + + $currentPropertyNames = $propertyNames; + + $newProperties = array( + '200' => array(), + '404' => array(), + ); + + if ($allProperties) { + // Default list of propertyNames, when all properties were requested. + $currentPropertyNames = array( + '{DAV:}getlastmodified', + '{DAV:}getcontentlength', + '{DAV:}resourcetype', + '{DAV:}quota-used-bytes', + '{DAV:}quota-available-bytes', + '{DAV:}getetag', + '{DAV:}getcontenttype', + ); + } + + // If the resourceType was not part of the list, we manually add it + // and mark it for removal. We need to know the resourcetype in order + // to make certain decisions about the entry. + // WebDAV dictates we should add a / and the end of href's for collections + $removeRT = false; + if (!in_array('{DAV:}resourcetype',$currentPropertyNames)) { + $currentPropertyNames[] = '{DAV:}resourcetype'; + $removeRT = true; + } + + $result = $this->broadcastEvent('beforeGetProperties',array($myPath, $node, &$currentPropertyNames, &$newProperties)); + // If this method explicitly returned false, we must ignore this + // node as it is inaccessible. + if ($result===false) continue; + + if (count($currentPropertyNames) > 0) { + + if ($node instanceof Sabre_DAV_IProperties) { + $nodeProperties = $node->getProperties($currentPropertyNames); + + // The getProperties method may give us too much, + // properties, in case the implementor was lazy. + // + // So as we loop through this list, we will only take the + // properties that were actually requested and discard the + // rest. + foreach($currentPropertyNames as $k=>$currentPropertyName) { + if (isset($nodeProperties[$currentPropertyName])) { + unset($currentPropertyNames[$k]); + $newProperties[200][$currentPropertyName] = $nodeProperties[$currentPropertyName]; + } + } + + } + + } + + foreach($currentPropertyNames as $prop) { + + if (isset($newProperties[200][$prop])) continue; + + switch($prop) { + case '{DAV:}getlastmodified' : if ($node->getLastModified()) $newProperties[200][$prop] = new Sabre_DAV_Property_GetLastModified($node->getLastModified()); break; + case '{DAV:}getcontentlength' : + if ($node instanceof Sabre_DAV_IFile) { + $size = $node->getSize(); + if (!is_null($size)) { + $newProperties[200][$prop] = (int)$node->getSize(); + } + } + break; + case '{DAV:}quota-used-bytes' : + if ($node instanceof Sabre_DAV_IQuota) { + $quotaInfo = $node->getQuotaInfo(); + $newProperties[200][$prop] = $quotaInfo[0]; + } + break; + case '{DAV:}quota-available-bytes' : + if ($node instanceof Sabre_DAV_IQuota) { + $quotaInfo = $node->getQuotaInfo(); + $newProperties[200][$prop] = $quotaInfo[1]; + } + break; + case '{DAV:}getetag' : if ($node instanceof Sabre_DAV_IFile && $etag = $node->getETag()) $newProperties[200][$prop] = $etag; break; + case '{DAV:}getcontenttype' : if ($node instanceof Sabre_DAV_IFile && $ct = $node->getContentType()) $newProperties[200][$prop] = $ct; break; + case '{DAV:}supported-report-set' : + $reports = array(); + foreach($this->plugins as $plugin) { + $reports = array_merge($reports, $plugin->getSupportedReportSet($myPath)); + } + $newProperties[200][$prop] = new Sabre_DAV_Property_SupportedReportSet($reports); + break; + case '{DAV:}resourcetype' : + $newProperties[200]['{DAV:}resourcetype'] = new Sabre_DAV_Property_ResourceType(); + foreach($this->resourceTypeMapping as $className => $resourceType) { + if ($node instanceof $className) $newProperties[200]['{DAV:}resourcetype']->add($resourceType); + } + break; + + } + + // If we were unable to find the property, we will list it as 404. + if (!$allProperties && !isset($newProperties[200][$prop])) $newProperties[404][$prop] = null; + + } + + $this->broadcastEvent('afterGetProperties',array(trim($myPath,'/'),&$newProperties, $node)); + + $newProperties['href'] = trim($myPath,'/'); + + // Its is a WebDAV recommendation to add a trailing slash to collectionnames. + // Apple's iCal also requires a trailing slash for principals (rfc 3744), though this is non-standard. + if ($myPath!='' && isset($newProperties[200]['{DAV:}resourcetype'])) { + $rt = $newProperties[200]['{DAV:}resourcetype']; + if ($rt->is('{DAV:}collection') || $rt->is('{DAV:}principal')) { + $newProperties['href'] .='/'; + } + } + + // If the resourcetype property was manually added to the requested property list, + // we will remove it again. + if ($removeRT) unset($newProperties[200]['{DAV:}resourcetype']); + + $returnPropertyList[] = $newProperties; + + } + + return $returnPropertyList; + + } +} diff --git a/lib/private/davclient.php b/lib/private/davclient.php new file mode 100644 index 00000000000..28f48f3b921 --- /dev/null +++ b/lib/private/davclient.php @@ -0,0 +1,46 @@ +<?php +/** + * ownCloud + * + * @author Vincent Petry + * @copyright 2013 Vincent Petry <pvince81@owncloud.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/** + * This class extends the SabreDAV client with additional functionality + * like request timeout. + */ + +class OC_DAVClient extends \Sabre_DAV_Client { + + protected $requestTimeout; + + /** + * @brief Sets the request timeout or 0 to disable timeout. + * @param int timeout in seconds or 0 to disable + */ + public function setRequestTimeout($timeout) { + $this->requestTimeout = (int)$timeout; + } + + protected function curlRequest($url, $settings) { + if ($this->requestTimeout > 0) { + $settings[CURLOPT_TIMEOUT] = $this->requestTimeout; + } + return parent::curlRequest($url, $settings); + } +} diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index 8e76f46c78f..fc13e881bff 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -53,7 +53,7 @@ class MDB2SchemaManager { * @param string $file file to read structure from * @return bool */ - public function updateDbFromStructure($file) { + public function updateDbFromStructure($file, $generateSql = false) { $sm = $this->conn->getSchemaManager(); $fromSchema = $sm->createSchema(); @@ -82,6 +82,10 @@ class MDB2SchemaManager { $tableDiff->name = $platform->quoteIdentifier($tableDiff->name); } + if ($generateSql) { + return $this->generateChangeScript($schemaDiff); + } + return $this->executeSchemaChange($schemaDiff); } @@ -147,4 +151,20 @@ class MDB2SchemaManager { $this->conn->commit(); return true; } + + /** + * @param \Doctrine\DBAL\Schema\Schema $schema + * @return string + */ + public function generateChangeScript($schema) { + + $script = ''; + $sqls = $schema->toSql($this->conn->getDatabasePlatform()); + foreach($sqls as $sql) { + $script .= $sql . ';'; + $script .= PHP_EOL; + } + + return $script; + } } diff --git a/lib/private/log/owncloud.php b/lib/private/log/owncloud.php index a408e3830d6..036c93cd8e1 100644 --- a/lib/private/log/owncloud.php +++ b/lib/private/log/owncloud.php @@ -61,6 +61,7 @@ class OC_Log_Owncloud { $entry=array('app'=>$app, 'message'=>$message, 'level'=>$level, 'time'=> $time->format($format)); $entry = json_encode($entry); $handle = @fopen(self::$logFile, 'a'); + @chmod(self::$logFile, 0640); if ($handle) { fwrite($handle, $entry."\n"); fclose($handle); diff --git a/lib/private/preview/movies.php b/lib/private/preview/movies.php index c318137ff0e..4d85e23c63c 100644 --- a/lib/private/preview/movies.php +++ b/lib/private/preview/movies.php @@ -8,40 +8,44 @@ */ namespace OC\Preview; -$isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); -$whichAVCONV = shell_exec('which avconv'); -$isAVCONVAvailable = !empty($whichAVCONV); +// movie preview is currently not supported on Windows +if (!\OC_Util::runningOnWindows()) { + $isShellExecEnabled = !in_array('shell_exec', explode(', ', ini_get('disable_functions'))); + $whichAVCONV = ($isShellExecEnabled ? shell_exec('which avconv') : ''); + $isAVCONVAvailable = !empty($whichAVCONV); -if($isShellExecEnabled && $isAVCONVAvailable) { + if($isShellExecEnabled && $isAVCONVAvailable) { - class Movie extends Provider { + class Movie extends Provider { - public function getMimeType() { - return '/video\/.*/'; - } + public function getMimeType() { + return '/video\/.*/'; + } + + public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { + $absPath = \OC_Helper::tmpFile(); + $tmpPath = \OC_Helper::tmpFile(); - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $absPath = \OC_Helper::tmpFile(); - $tmpPath = \OC_Helper::tmpFile(); + $handle = $fileview->fopen($path, 'rb'); - $handle = $fileview->fopen($path, 'rb'); + $firstmb = stream_get_contents($handle, 1048576); //1024 * 1024 = 1048576 + file_put_contents($absPath, $firstmb); - $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 = 'avconv -an -y -ss 1 -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath); - //$cmd = 'ffmpeg -y -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 -ss 1 -s ' . escapeshellarg($maxX) . 'x' . escapeshellarg($maxY) . ' ' . $tmpPath; - $cmd = 'avconv -an -y -ss 1 -i ' . escapeshellarg($absPath) . ' -f mjpeg -vframes 1 ' . escapeshellarg($tmpPath); - - shell_exec($cmd); + shell_exec($cmd); - $image = new \OC_Image($tmpPath); + $image = new \OC_Image($tmpPath); - unlink($absPath); - unlink($tmpPath); + unlink($absPath); + unlink($tmpPath); - return $image->valid() ? $image : false; + return $image->valid() ? $image : false; + } } + + \OC\Preview::registerProvider('OC\Preview\Movie'); } +} - \OC\Preview::registerProvider('OC\Preview\Movie'); -}
\ No newline at end of file diff --git a/lib/private/preview/office-cl.php b/lib/private/preview/office-cl.php index 112909d6523..8f2e06c050b 100644 --- a/lib/private/preview/office-cl.php +++ b/lib/private/preview/office-cl.php @@ -7,128 +7,132 @@ */ namespace OC\Preview; -//we need imagick to convert -class Office extends Provider { +// office preview is currently not supported on Windows +if (!\OC_Util::runningOnWindows()) { - private $cmd; + //we need imagick to convert + class Office extends Provider { - public function getMimeType() { - return null; - } + private $cmd; - public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $this->initCmd(); - if(is_null($this->cmd)) { - return false; + public function getMimeType() { + return null; } - $absPath = $fileview->toTmpFile($path); + 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(); - $tmpDir = get_temp_dir(); + $defaultParameters = ' --headless --nologo --nofirststartwizard --invisible --norestore -convert-to pdf -outdir '; + $clParameters = \OCP\Config::getSystemValue('preview_office_cl_parameters', $defaultParameters); - $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; - $exec = $this->cmd . $clParameters . escapeshellarg($tmpDir) . ' ' . escapeshellarg($absPath); - $export = 'export HOME=/' . $tmpDir; + shell_exec($export . "\n" . $exec); - 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); - //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; + + return $image->valid() ? $image : false; } - $image = new \OC_Image($pdf); + private function initCmd() { + $cmd = ''; - unlink($absPath); - unlink($absPath . '.pdf'); + if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { + $cmd = \OC_Config::getValue('preview_libreoffice_path', null); + } - return $image->valid() ? $image : false; - } + $whichLibreOffice = shell_exec('which libreoffice'); + if($cmd === '' && !empty($whichLibreOffice)) { + $cmd = 'libreoffice'; + } - private function initCmd() { - $cmd = ''; + $whichOpenOffice = shell_exec('which openoffice'); + if($cmd === '' && !empty($whichOpenOffice)) { + $cmd = 'openoffice'; + } - if(is_string(\OC_Config::getValue('preview_libreoffice_path', null))) { - $cmd = \OC_Config::getValue('preview_libreoffice_path', null); - } + if($cmd === '') { + $cmd = null; + } - $whichLibreOffice = shell_exec('which libreoffice'); - if($cmd === '' && !empty($whichLibreOffice)) { - $cmd = 'libreoffice'; + $this->cmd = $cmd; } + } - $whichOpenOffice = shell_exec('which openoffice'); - if($cmd === '' && !empty($whichOpenOffice)) { - $cmd = 'openoffice'; - } + //.doc, .dot + class MSOfficeDoc extends Office { - if($cmd === '') { - $cmd = null; + public function getMimeType() { + return '/application\/msword/'; } - $this->cmd = $cmd; - } -} - -//.doc, .dot -class MSOfficeDoc extends Office { - - public function getMimeType() { - return '/application\/msword/'; } -} + \OC\Preview::registerProvider('OC\Preview\MSOfficeDoc'); -\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 { -//.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-.*/'; + } - public function getMimeType() { - return '/application\/vnd.ms-.*/'; } -} + \OC\Preview::registerProvider('OC\Preview\MSOffice2003'); -\OC\Preview::registerProvider('OC\Preview\MSOffice2003'); + //.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx + class MSOffice2007 extends Office { -//.docx, .dotx, .xlsx, .xltx, .pptx, .potx, .ppsx -class MSOffice2007 extends Office { + public function getMimeType() { + return '/application\/vnd.openxmlformats-officedocument.*/'; + } - public function getMimeType() { - return '/application\/vnd.openxmlformats-officedocument.*/'; } -} + \OC\Preview::registerProvider('OC\Preview\MSOffice2007'); -\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 { -//.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.*/'; + } - public function getMimeType() { - return '/application\/vnd.oasis.opendocument.*/'; } -} + \OC\Preview::registerProvider('OC\Preview\OpenDocument'); -\OC\Preview::registerProvider('OC\Preview\OpenDocument'); + //.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm + class StarOffice extends Office { -//.sxw, .stw, .sxc, .stc, .sxd, .std, .sxi, .sti, .sxg, .sxm -class StarOffice extends Office { + public function getMimeType() { + return '/application\/vnd.sun.xml.*/'; + } - public function getMimeType() { - return '/application\/vnd.sun.xml.*/'; } + \OC\Preview::registerProvider('OC\Preview\StarOffice'); } - -\OC\Preview::registerProvider('OC\Preview\StarOffice');
\ No newline at end of file diff --git a/lib/private/preview/office.php b/lib/private/preview/office.php index 5287bbd6ac1..318ab51f851 100644 --- a/lib/private/preview/office.php +++ b/lib/private/preview/office.php @@ -8,15 +8,22 @@ //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{ + + // LibreOffice preview is currently not supported on Windows + if (!\OC_Util::runningOnWindows()) { + $whichLibreOffice = ($isShellExecEnabled ? shell_exec('which libreoffice') : ''); + $isLibreOfficeAvailable = !empty($whichLibreOffice); + $whichOpenOffice = ($isShellExecEnabled ? 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'); + } + } else { //in case there isn't, use our fallback require_once('office-fallback.php'); } -}
\ No newline at end of file +} diff --git a/lib/private/preview/provider.php b/lib/private/preview/provider.php index e4a730bafc8..65d09705f40 100644 --- a/lib/private/preview/provider.php +++ b/lib/private/preview/provider.php @@ -11,9 +11,15 @@ abstract class Provider { abstract public function getMimeType(); /** - * search for $query - * @param string $query - * @return + * get thumbnail for file at path $path + * @param string $path Path of file + * @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 + * @param object $fileview fileview object of user folder + * @return mixed + * false if no preview was generated + * OC_Image object of the preview */ abstract public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview); } diff --git a/lib/private/preview/txt.php b/lib/private/preview/txt.php index 77e728eb364..c9aa20968d8 100644 --- a/lib/private/preview/txt.php +++ b/lib/private/preview/txt.php @@ -9,20 +9,19 @@ namespace OC\Preview; class TXT extends Provider { - private static $blacklist = array( - 'text/calendar', - 'text/vcard', - ); - public function getMimeType() { - return '/text\/.*/'; + return '/text\/plain/'; } + /** + * @param string $path + * @param int $maxX + * @param int $maxY + * @param boolean $scalingup + * @param \OC\Files\View $fileview + * @return bool|\OC_Image + */ public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) { - $mimetype = $fileview->getMimeType($path); - if(in_array($mimetype, self::$blacklist)) { - return false; - } $content = $fileview->fopen($path, 'r'); $content = stream_get_contents($content); @@ -62,22 +61,12 @@ class TXT extends Provider { \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 { +class MarkDown extends TXT { public function getMimeType() { - return '/application\/javascript/'; + return '/text\/(x-)?markdown/'; } } -\OC\Preview::registerProvider('OC\Preview\JavaScript');
\ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\MarkDown'); diff --git a/lib/private/preview/unknown.php b/lib/private/preview/unknown.php index 9e6cd68d401..4747f9e25ed 100644 --- a/lib/private/preview/unknown.php +++ b/lib/private/preview/unknown.php @@ -20,8 +20,30 @@ class Unknown extends Provider { $path = \OC_Helper::mimetypeIcon($mimetype); $path = \OC::$SERVERROOT . substr($path, strlen(\OC::$WEBROOT)); - return new \OC_Image($path); + $svgPath = substr_replace($path, 'svg', -3); + + if (extension_loaded('imagick') && file_exists($svgPath)) { + + // http://www.php.net/manual/de/imagick.setresolution.php#85284 + $svg = new \Imagick(); + $svg->readImage($svgPath); + $res = $svg->getImageResolution(); + $x_ratio = $res['x'] / $svg->getImageWidth(); + $y_ratio = $res['y'] / $svg->getImageHeight(); + $svg->removeImage(); + $svg->setResolution($maxX * $x_ratio, $maxY * $y_ratio); + $svg->setBackgroundColor(new \ImagickPixel('transparent')); + $svg->readImage($svgPath); + $svg->setImageFormat('png32'); + + $image = new \OC_Image(); + $image->loadFromData($svg); + } else { + $image = new \OC_Image($path); + } + + return $image; } } -\OC\Preview::registerProvider('OC\Preview\Unknown');
\ No newline at end of file +\OC\Preview::registerProvider('OC\Preview\Unknown'); diff --git a/lib/private/util.php b/lib/private/util.php index 6c0a8d7bab5..885cce87541 100755 --- a/lib/private/util.php +++ b/lib/private/util.php @@ -754,6 +754,10 @@ class OC_Util { * file in the data directory and trying to access via http */ public static function isHtAccessWorking() { + if (!\OC_Config::getValue("check_for_working_htaccess", true)) { + return true; + } + // testdata $fileName = '/htaccesstest.txt'; $testContent = 'testcontent'; @@ -802,11 +806,16 @@ class OC_Util { if (!function_exists('curl_init')) { return true; } + if (!\OC_Config::getValue("check_for_working_webdav", true)) { + return true; + } $settings = array( 'baseUri' => OC_Helper::linkToRemote('webdav'), ); - $client = new \Sabre_DAV_Client($settings); + $client = new \OC_DAVClient($settings); + + $client->setRequestTimeout(10); // for this self test we don't care if the ssl certificate is self signed and the peer cannot be verified. $client->setVerifyPeer(false); |