diff options
author | Georg Ehrke <dev@georgswebsite.de> | 2012-07-11 10:47:30 +0200 |
---|---|---|
committer | Georg Ehrke <dev@georgswebsite.de> | 2012-07-11 10:47:30 +0200 |
commit | 55754939009a51da1ed8350d372d8d6f7e7768a5 (patch) | |
tree | 2f2d951d0d02aabfc7352f16a466fd61e0750635 /lib | |
parent | f875240b47823d28c5169b354ffe1a3e80aaf57e (diff) | |
parent | 0f0aa1827f446ca531732bb1c807c244ef66676a (diff) | |
download | nextcloud-server-55754939009a51da1ed8350d372d8d6f7e7768a5.tar.gz nextcloud-server-55754939009a51da1ed8350d372d8d6f7e7768a5.zip |
Merge branch 'master' into calendar_import
Diffstat (limited to 'lib')
-rw-r--r-- | lib/MDB2/Driver/Function/sqlite3.php | 1 | ||||
-rw-r--r-- | lib/MDB2/Driver/Manager/sqlite3.php | 1 | ||||
-rw-r--r-- | lib/MDB2/Driver/sqlite3.php | 2 | ||||
-rw-r--r-- | lib/connector/sabre/client.php | 171 | ||||
-rw-r--r-- | lib/connector/sabre/file.php | 2 | ||||
-rw-r--r-- | lib/image.php | 80 | ||||
-rw-r--r-- | lib/log/owncloud.php | 43 | ||||
-rw-r--r-- | lib/public/app.php | 3 | ||||
-rw-r--r-- | lib/public/config.php | 2 | ||||
-rw-r--r-- | lib/public/db.php | 2 | ||||
-rw-r--r-- | lib/public/files.php | 2 | ||||
-rw-r--r-- | lib/public/json.php | 2 | ||||
-rw-r--r-- | lib/public/response.php | 2 | ||||
-rw-r--r-- | lib/public/template.php | 3 | ||||
-rw-r--r-- | lib/public/user.php | 3 | ||||
-rw-r--r-- | lib/public/util.php | 2 | ||||
-rw-r--r-- | lib/setup.php | 2 | ||||
-rw-r--r-- | lib/updater.php | 1 | ||||
-rw-r--r-- | lib/user.php | 8 | ||||
-rw-r--r-- | lib/vcategories.php | 7 |
20 files changed, 278 insertions, 61 deletions
diff --git a/lib/MDB2/Driver/Function/sqlite3.php b/lib/MDB2/Driver/Function/sqlite3.php index a013aea165a..1af262fd7a7 100644 --- a/lib/MDB2/Driver/Function/sqlite3.php +++ b/lib/MDB2/Driver/Function/sqlite3.php @@ -134,4 +134,3 @@ class MDB2_Driver_Function_sqlite3 extends MDB2_Driver_Function_Common // }}} } -?> diff --git a/lib/MDB2/Driver/Manager/sqlite3.php b/lib/MDB2/Driver/Manager/sqlite3.php index 8f4e1312eb8..10255a3619a 100644 --- a/lib/MDB2/Driver/Manager/sqlite3.php +++ b/lib/MDB2/Driver/Manager/sqlite3.php @@ -1360,4 +1360,3 @@ class MDB2_Driver_Manager_sqlite3 extends MDB2_Driver_Manager_Common // }}} } -?> diff --git a/lib/MDB2/Driver/sqlite3.php b/lib/MDB2/Driver/sqlite3.php index 39d3fb6727d..25927aff637 100644 --- a/lib/MDB2/Driver/sqlite3.php +++ b/lib/MDB2/Driver/sqlite3.php @@ -1332,5 +1332,3 @@ class MDB2_Statement_sqlite3 extends MDB2_Statement_Common $this->free(); } } - -?> diff --git a/lib/connector/sabre/client.php b/lib/connector/sabre/client.php new file mode 100644 index 00000000000..87f9d59b3ae --- /dev/null +++ b/lib/connector/sabre/client.php @@ -0,0 +1,171 @@ +<?php
+
+/**
+ * ownCloud
+ *
+ * @author Bjoern Schiessle
+ * @copyright 2012 Bjoern Schiessle <schiessle@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/>.
+ *
+ */
+
+class OC_Connector_Sabre_Client extends Sabre_DAV_Client {
+
+ protected $trustedCertificates;
+
+ /**
+ * Add trusted root certificates to the webdav client.
+ *
+ * The parameter certificates should be a absulute path to a file which contains
+ * all trusted certificates
+ *
+ * @param string $certificates
+ */
+ public function addTrustedCertificates($certificates) {
+ $this->trustedCertificates = $certificates;
+ }
+
+ /**
+ * Copied from SabreDAV with some modification to use user defined curlSettings
+ * Performs an actual HTTP request, and returns the result.
+ *
+ * If the specified url is relative, it will be expanded based on the base
+ * url.
+ *
+ * The returned array contains 3 keys:
+ * * body - the response body
+ * * httpCode - a HTTP code (200, 404, etc)
+ * * headers - a list of response http headers. The header names have
+ * been lowercased.
+ *
+ * @param string $method
+ * @param string $url
+ * @param string $body
+ * @param array $headers
+ * @return array
+ */
+ public function request($method, $url = '', $body = null, $headers = array()) {
+
+ $url = $this->getAbsoluteUrl($url);
+
+ $curlSettings = array(
+ CURLOPT_RETURNTRANSFER => true,
+ // Return headers as part of the response
+ CURLOPT_HEADER => true,
+ CURLOPT_POSTFIELDS => $body,
+ // Automatically follow redirects
+ CURLOPT_FOLLOWLOCATION => true,
+ CURLOPT_MAXREDIRS => 5,
+ CURLOPT_SSL_VERIFYPEER => true,
+ //CURLOPT_SSL_VERIFYPEER => false,
+ );
+
+ if($this->trustedCertificates) {
+ $curlSettings[CURLOPT_CAINFO] = $this->trustedCertificates;
+ }
+
+ switch ($method) {
+ case 'PUT':
+ $curlSettings[CURLOPT_PUT] = true;
+ break;
+ case 'HEAD' :
+
+ // do not read body with HEAD requests (this is neccessary because cURL does not ignore the body with HEAD
+ // requests when the Content-Length header is given - which in turn is perfectly valid according to HTTP
+ // specs...) cURL does unfortunately return an error in this case ("transfer closed transfer closed with
+ // ... bytes remaining to read") this can be circumvented by explicitly telling cURL to ignore the
+ // response body
+ $curlSettings[CURLOPT_NOBODY] = true;
+ $curlSettings[CURLOPT_CUSTOMREQUEST] = 'HEAD';
+ break;
+
+ default:
+ $curlSettings[CURLOPT_CUSTOMREQUEST] = $method;
+ break;
+
+ }
+
+ // Adding HTTP headers
+ $nHeaders = array();
+ foreach($headers as $key=>$value) {
+
+ $nHeaders[] = $key . ': ' . $value;
+
+ }
+ $curlSettings[CURLOPT_HTTPHEADER] = $nHeaders;
+
+ if ($this->proxy) {
+ $curlSettings[CURLOPT_PROXY] = $this->proxy;
+ }
+
+ if ($this->userName) {
+ $curlSettings[CURLOPT_HTTPAUTH] = CURLAUTH_BASIC | CURLAUTH_DIGEST;
+ $curlSettings[CURLOPT_USERPWD] = $this->userName . ':' . $this->password;
+ }
+
+ list(
+ $response,
+ $curlInfo,
+ $curlErrNo,
+ $curlError
+ ) = $this->curlRequest($url, $curlSettings);
+
+ $headerBlob = substr($response, 0, $curlInfo['header_size']);
+ $response = substr($response, $curlInfo['header_size']);
+
+ // In the case of 100 Continue, or redirects we'll have multiple lists
+ // of headers for each separate HTTP response. We can easily split this
+ // because they are separated by \r\n\r\n
+ $headerBlob = explode("\r\n\r\n", trim($headerBlob, "\r\n"));
+
+ // We only care about the last set of headers
+ $headerBlob = $headerBlob[count($headerBlob)-1];
+
+ // Splitting headers
+ $headerBlob = explode("\r\n", $headerBlob);
+
+ $headers = array();
+ foreach($headerBlob as $header) {
+ $parts = explode(':', $header, 2);
+ if (count($parts)==2) {
+ $headers[strtolower(trim($parts[0]))] = trim($parts[1]);
+ }
+ }
+
+ $response = array(
+ 'body' => $response,
+ 'statusCode' => $curlInfo['http_code'],
+ 'headers' => $headers
+ );
+
+ if ($curlErrNo) {
+ throw new Sabre_DAV_Exception('[CURL] Error while making request: ' . $curlError . ' (error code: ' . $curlErrNo . ')');
+ }
+
+ if ($response['statusCode']>=400) {
+ switch ($response['statusCode']) {
+ case 404:
+ throw new Sabre_DAV_Exception_NotFound('Resource ' . $url . ' not found.');
+ break;
+
+ default:
+ throw new Sabre_DAV_Exception('HTTP error response. (errorcode ' . $response['statusCode'] . ')');
+ }
+ }
+
+ return $response;
+
+ }
+}
\ No newline at end of file diff --git a/lib/connector/sabre/file.php b/lib/connector/sabre/file.php index dd25df78c29..e4dc8c93445 100644 --- a/lib/connector/sabre/file.php +++ b/lib/connector/sabre/file.php @@ -42,7 +42,7 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D */ public function get() { - return OC_Filesystem::fopen($this->path,'r'); + return OC_Filesystem::readfile($this->path); } diff --git a/lib/image.php b/lib/image.php index e5c59bacdc5..01e843d8316 100644 --- a/lib/image.php +++ b/lib/image.php @@ -108,6 +108,56 @@ class OC_Image { } /** + * @brief Returns the width when the image orientation is top-left. + * @returns int + */ + public function widthTopLeft() { + $o = $this->getOrientation(); + OC_Log::write('core','OC_Image->widthTopLeft() Orientation: '.$o, OC_Log::DEBUG); + switch($o) { + case -1: + case 1: + case 2: // Not tested + case 3: + case 4: // Not tested + return $this->width(); + break; + case 5: // Not tested + case 6: + case 7: // Not tested + case 8: + return $this->height(); + break; + } + return $this->width(); + } + + /** + * @brief Returns the height when the image orientation is top-left. + * @returns int + */ + public function heightTopLeft() { + $o = $this->getOrientation(); + OC_Log::write('core','OC_Image->heightTopLeft() Orientation: '.$o, OC_Log::DEBUG); + switch($o) { + case -1: + case 1: + case 2: // Not tested + case 3: + case 4: // Not tested + return $this->height(); + break; + case 5: // Not tested + case 6: + case 7: // Not tested + case 8: + return $this->width(); + break; + } + return $this->height(); + } + + /** * @brief Outputs the image. * @returns bool */ @@ -209,34 +259,46 @@ class OC_Image { /** * (I'm open for suggestions on better method name ;) - * @brief Fixes orientation based on EXIF data. - * @returns bool. + * @brief Get the orientation based on EXIF data. + * @returns The orientation or -1 if no EXIF data is available. */ - public function fixOrientation() { + public function getOrientation() { if(!is_callable('exif_read_data')){ OC_Log::write('core','OC_Image->fixOrientation() Exif module not enabled.', OC_Log::DEBUG); - return false; + return -1; } if(!$this->valid()) { OC_Log::write('core','OC_Image->fixOrientation() No image loaded.', OC_Log::DEBUG); - return false; + return -1; } if(is_null($this->filepath) || !is_readable($this->filepath)) { OC_Log::write('core','OC_Image->fixOrientation() No readable file path set.', OC_Log::DEBUG); - return false; + return -1; } $exif = @exif_read_data($this->filepath, 'IFD0'); if(!$exif) { - return false; + return -1; } if(!isset($exif['Orientation'])) { - return true; // Nothing to fix + return -1; } - $o = $exif['Orientation']; + return $exif['Orientation']; + } + + /** + * (I'm open for suggestions on better method name ;) + * @brief Fixes orientation based on EXIF data. + * @returns bool. + */ + public function fixOrientation() { + $o = $this->getOrientation(); OC_Log::write('core','OC_Image->fixOrientation() Orientation: '.$o, OC_Log::DEBUG); $rotate = 0; $flip = false; switch($o) { + case -1: + return false; //Nothing to fix + break; case 1: $rotate = 0; $flip = false; diff --git a/lib/log/owncloud.php b/lib/log/owncloud.php index 92914af8fca..9eb21832c55 100644 --- a/lib/log/owncloud.php +++ b/lib/log/owncloud.php @@ -63,25 +63,40 @@ class OC_Log_Owncloud { self::init(); $minLevel=OC_Config::getValue( "loglevel", OC_Log::WARN ); $entries = array(); - $handle = @fopen(self::$logFile, 'r'); + $handle = @fopen(self::$logFile, 'rb'); if ($handle) { - // Just a guess to set the file pointer to the right spot - $maxLineLength = 150; - fseek($handle, -($limit * $maxLineLength + $offset * $maxLineLength), SEEK_END); - // Skip first line, because it is most likely a partial line - fgets($handle); - while (!feof($handle)) { - $line = fgets($handle); - if (!empty($line)) { - $entry = json_decode($line); - if ($entry->level >= $minLevel) { - $entries[] = $entry; + fseek($handle, 0, SEEK_END); + $pos = ftell($handle); + $line = ''; + $entriesCount = 0; + $lines = 0; + // Loop through each character of the file looking for new lines + while ($pos >= 0 && $entriesCount < $limit) { + fseek($handle, $pos); + $ch = fgetc($handle); + if ($ch == "\n" || $pos == 0) { + if ($line != '') { + // Add the first character if at the start of the file, because it doesn't hit the else in the loop + if ($pos == 0) { + $line = $ch.$line; + } + $entry = json_decode($line); + // Add the line as an entry if it is passed the offset and is equal or above the log level + if ($entry->level >= $minLevel) { + $lines++; + if ($lines > $offset) { + $entries[] = $entry; + $entriesCount++; + } + } + $line = ''; } + } else { + $line = $ch.$line; } + $pos--; } fclose($handle); - // Extract the needed entries and reverse the order - $entries = array_reverse(array_slice($entries, -($limit + $offset), $limit)); } return $entries; } diff --git a/lib/public/app.php b/lib/public/app.php index 9e2108818bf..38c51af9cdb 100644 --- a/lib/public/app.php +++ b/lib/public/app.php @@ -158,6 +158,3 @@ class App { } - - -?> diff --git a/lib/public/config.php b/lib/public/config.php index 9f5abe672cb..ab01902ffe6 100644 --- a/lib/public/config.php +++ b/lib/public/config.php @@ -134,5 +134,3 @@ class Config { } - -?> diff --git a/lib/public/db.php b/lib/public/db.php index f7564c0bb6a..3a33f7674d8 100644 --- a/lib/public/db.php +++ b/lib/public/db.php @@ -91,5 +91,3 @@ class DB { } - -?> diff --git a/lib/public/files.php b/lib/public/files.php index fc3004434ba..32b3f036744 100644 --- a/lib/public/files.php +++ b/lib/public/files.php @@ -115,5 +115,3 @@ class Files { } - -?> diff --git a/lib/public/json.php b/lib/public/json.php index b6edbd65bd5..1bc1e3ab4d5 100644 --- a/lib/public/json.php +++ b/lib/public/json.php @@ -105,5 +105,3 @@ class JSON { } } - -?> diff --git a/lib/public/response.php b/lib/public/response.php index cc2137c5cae..8dff3bcd354 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -105,5 +105,3 @@ class Response { } - -?> diff --git a/lib/public/template.php b/lib/public/template.php index b89088bdd06..a0ed618cb2c 100644 --- a/lib/public/template.php +++ b/lib/public/template.php @@ -104,6 +104,3 @@ function html_select_options($options, $selected, $params=array()) { class Template extends \OC_Template { } - - -?> diff --git a/lib/public/user.php b/lib/public/user.php index a0c069f7379..713e366b968 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -120,6 +120,3 @@ class User { } - - -?> diff --git a/lib/public/util.php b/lib/public/util.php index 41121091544..43f9e3cee5d 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -321,5 +321,3 @@ class Util { return(\OC_Helper::mb_str_replace($search, $replace, $subject, $encoding, $count)); } } - -?> diff --git a/lib/setup.php b/lib/setup.php index bad0f5301c7..2f73c486c9c 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -380,5 +380,3 @@ class OC_Setup { file_put_contents(OC_Config::getValue('datadirectory', OC::$SERVERROOT.'/data').'/index.html', ''); } } - -?> diff --git a/lib/updater.php b/lib/updater.php index 5d97178c30e..332cea03bfc 100644 --- a/lib/updater.php +++ b/lib/updater.php @@ -84,4 +84,3 @@ class OC_Updater{ } } -?> diff --git a/lib/user.php b/lib/user.php index d02c1208a8d..f1903093d6d 100644 --- a/lib/user.php +++ b/lib/user.php @@ -345,17 +345,13 @@ class OC_User { * @return boolean */ public static function userExists($uid){ - static $user_exists_checked = null;
- if (!is_null($user_exists_checked)) {
- return $user_exists_checked;
- } foreach(self::$_usedBackends as $backend){ $result=$backend->userExists($uid); if($result===true){ - return $user_exists_checked = true; + return true; } } - return $user_exists_checked = false; + return false; } /** diff --git a/lib/vcategories.php b/lib/vcategories.php index 8157c343868..d15b7b166ea 100644 --- a/lib/vcategories.php +++ b/lib/vcategories.php @@ -131,8 +131,10 @@ class OC_VCategories { * } * $categories->rescan($objects); */ - public function rescan($objects, $sync=true) { - $this->categories = array(); + public function rescan($objects, $sync=true, $reset=true) { + if($reset === true) { + $this->categories = array(); + } foreach($objects as $object) { //OC_Log::write('core','OC_VCategories::rescan: '.substr($object, 0, 100).'(...)', OC_Log::DEBUG); $vobject = OC_VObject::parse($object); @@ -221,4 +223,3 @@ class OC_VCategories { } } -?> |