diff options
author | Robin Appelman <icewind@owncloud.com> | 2012-12-15 02:21:26 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2012-12-15 02:21:26 +0100 |
commit | 946d58eaa8f93eb612a277fad1d7f870554b578e (patch) | |
tree | 18ad2ac0c504eb283d70c040ce449b259d88f97f /lib | |
parent | 7969d6e64617235744889df42d0e671085a779a8 (diff) | |
parent | 6ff38624a717316d7992c81db6d4dbf8f5d86f3a (diff) | |
download | nextcloud-server-946d58eaa8f93eb612a277fad1d7f870554b578e.tar.gz nextcloud-server-946d58eaa8f93eb612a277fad1d7f870554b578e.zip |
merge master into filesystem
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/app.php | 20 | ||||
-rw-r--r-- | lib/base.php | 3 | ||||
-rw-r--r-- | lib/connector/sabre/auth.php | 17 | ||||
-rw-r--r-- | lib/connector/sabre/quotaplugin.php | 2 | ||||
-rw-r--r-- | lib/db.php | 6 | ||||
-rw-r--r-- | lib/files.php | 1 | ||||
-rw-r--r-- | lib/helper.php | 2 | ||||
-rw-r--r-- | lib/l10n.php | 20 | ||||
-rw-r--r-- | lib/migrate.php | 162 | ||||
-rw-r--r-- | lib/ocsclient.php | 8 | ||||
-rw-r--r-- | lib/public/contacts.php | 208 | ||||
-rw-r--r-- | lib/public/iaddressbook.php | 74 | ||||
-rw-r--r-- | lib/public/user.php | 6 | ||||
-rwxr-xr-x | lib/request.php | 6 | ||||
-rw-r--r-- | lib/setup.php | 6 | ||||
-rw-r--r-- | lib/templatelayout.php | 30 | ||||
-rw-r--r-- | lib/updater.php | 18 | ||||
-rw-r--r-- | lib/user.php | 36 | ||||
-rwxr-xr-x | lib/util.php | 61 |
19 files changed, 447 insertions, 239 deletions
diff --git a/lib/app.php b/lib/app.php index c6aef3f5b04..0460a15502a 100755 --- a/lib/app.php +++ b/lib/app.php @@ -597,16 +597,16 @@ class OC_App{ $app1[$i]['internal'] = $app1[$i]['active'] = 0; // rating img - if($app['score']>=0 and $app['score']<5) $img=OC_Helper::imagePath( "core", "rating/s1.png" ); - elseif($app['score']>=5 and $app['score']<15) $img=OC_Helper::imagePath( "core", "rating/s2.png" ); - elseif($app['score']>=15 and $app['score']<25) $img=OC_Helper::imagePath( "core", "rating/s3.png" ); - elseif($app['score']>=25 and $app['score']<35) $img=OC_Helper::imagePath( "core", "rating/s4.png" ); - elseif($app['score']>=35 and $app['score']<45) $img=OC_Helper::imagePath( "core", "rating/s5.png" ); - elseif($app['score']>=45 and $app['score']<55) $img=OC_Helper::imagePath( "core", "rating/s6.png" ); - elseif($app['score']>=55 and $app['score']<65) $img=OC_Helper::imagePath( "core", "rating/s7.png" ); - elseif($app['score']>=65 and $app['score']<75) $img=OC_Helper::imagePath( "core", "rating/s8.png" ); - elseif($app['score']>=75 and $app['score']<85) $img=OC_Helper::imagePath( "core", "rating/s9.png" ); - elseif($app['score']>=85 and $app['score']<95) $img=OC_Helper::imagePath( "core", "rating/s10.png" ); + if($app['score']>=0 and $app['score']<5) $img=OC_Helper::imagePath( "core", "rating/s1.png" ); + elseif($app['score']>=5 and $app['score']<15) $img=OC_Helper::imagePath( "core", "rating/s2.png" ); + elseif($app['score']>=15 and $app['score']<25) $img=OC_Helper::imagePath( "core", "rating/s3.png" ); + elseif($app['score']>=25 and $app['score']<35) $img=OC_Helper::imagePath( "core", "rating/s4.png" ); + elseif($app['score']>=35 and $app['score']<45) $img=OC_Helper::imagePath( "core", "rating/s5.png" ); + elseif($app['score']>=45 and $app['score']<55) $img=OC_Helper::imagePath( "core", "rating/s6.png" ); + elseif($app['score']>=55 and $app['score']<65) $img=OC_Helper::imagePath( "core", "rating/s7.png" ); + elseif($app['score']>=65 and $app['score']<75) $img=OC_Helper::imagePath( "core", "rating/s8.png" ); + elseif($app['score']>=75 and $app['score']<85) $img=OC_Helper::imagePath( "core", "rating/s9.png" ); + elseif($app['score']>=85 and $app['score']<95) $img=OC_Helper::imagePath( "core", "rating/s10.png" ); elseif($app['score']>=95 and $app['score']<100) $img=OC_Helper::imagePath( "core", "rating/s11.png" ); $app1[$i]['score'] = '<img src="'.$img.'"> Score: '.$app['score'].'%'; diff --git a/lib/base.php b/lib/base.php index 79d0ed87d7a..1e35f176802 100644 --- a/lib/base.php +++ b/lib/base.php @@ -292,6 +292,9 @@ class OC{ // prevents javascript from accessing php session cookies ini_set('session.cookie_httponly', '1;'); + // set the session name to the instance id - which is unique + session_name(OC_Util::getInstanceId()); + // (re)-initialize session session_start(); diff --git a/lib/connector/sabre/auth.php b/lib/connector/sabre/auth.php index db8f005745a..6990d928cff 100644 --- a/lib/connector/sabre/auth.php +++ b/lib/connector/sabre/auth.php @@ -32,7 +32,7 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { */ protected function validateUserPass($username, $password) { if (OC_User::isLoggedIn()) { - OC_Util::setupFS($username); + OC_Util::setupFS(OC_User::getUser()); return true; } else { OC_Util::setUpFS();//login hooks may need early access to the filesystem @@ -45,4 +45,19 @@ class OC_Connector_Sabre_Auth extends Sabre_DAV_Auth_Backend_AbstractBasic { } } } + + /** + * Returns information about the currently logged in username. + * + * If nobody is currently logged in, this method should return null. + * + * @return string|null + */ + public function getCurrentUser() { + $user = OC_User::getUser(); + if(!$user) { + return null; + } + return $user; + } } diff --git a/lib/connector/sabre/quotaplugin.php b/lib/connector/sabre/quotaplugin.php index a56a65ad863..fbbb4a3cf6f 100644 --- a/lib/connector/sabre/quotaplugin.php +++ b/lib/connector/sabre/quotaplugin.php @@ -51,7 +51,7 @@ class OC_Connector_Sabre_QuotaPlugin extends Sabre_DAV_ServerPlugin { } list($parentUri, $newName) = Sabre_DAV_URLUtil::splitPath($uri); if ($length > OC_Filesystem::free_space($parentUri)) { - throw new Sabre_DAV_Exception('Quota exceeded. File is too big.'); + throw new Sabre_DAV_Exception_InsufficientStorage(); } } return true; diff --git a/lib/db.php b/lib/db.php index 6524db7581a..7e60b41d230 100644 --- a/lib/db.php +++ b/lib/db.php @@ -445,9 +445,9 @@ class OC_DB { * http://www.sqlite.org/lang_createtable.html * http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions037.htm */ - if( $CONFIG_DBTYPE == 'pgsql' ) { //mysql support it too but sqlite doesn't - $content = str_replace( '<default>0000-00-00 00:00:00</default>', '<default>CURRENT_TIMESTAMP</default>', $content ); - } + if( $CONFIG_DBTYPE == 'pgsql' ) { //mysql support it too but sqlite doesn't + $content = str_replace( '<default>0000-00-00 00:00:00</default>', '<default>CURRENT_TIMESTAMP</default>', $content ); + } file_put_contents( $file2, $content ); diff --git a/lib/files.php b/lib/files.php index a2387368241..768a2ad2191 100644 --- a/lib/files.php +++ b/lib/files.php @@ -282,7 +282,6 @@ class OC_Files { } else { OC_Log::write('files', 'Can\'t write upload limit to ' . OC::$SERVERROOT . '/.htaccess. Please check the file permissions', OC_Log::WARN); } - return false; } } diff --git a/lib/helper.php b/lib/helper.php index 269850e7810..2dcf0c6de79 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -540,7 +540,7 @@ class OC_Helper { mkdir($tmpDirNoClean); } $file=$tmpDirNoClean.md5(time().rand()).$postfix; - $fh=fopen($file,'w'); + $fh=fopen($file, 'w'); fclose($fh); return $file; } diff --git a/lib/l10n.php b/lib/l10n.php index f172710e5d7..f70dfa5e34e 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -115,10 +115,12 @@ class OC_L10N{ $i18ndir = self::findI18nDir($app); // Localization is in /l10n, Texts are in $i18ndir // (Just no need to define date/time format etc. twice) - if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') || - OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') || - OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/') || - OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings')) && file_exists($i18ndir.$lang.'.php')) { + if((OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC_App::getAppPath($app).'/l10n/') + || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/core/l10n/') + || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/lib/l10n/') + || OC_Helper::issubdirectory($i18ndir.$lang.'.php', OC::$SERVERROOT.'/settings') + ) + && file_exists($i18ndir.$lang.'.php')) { // Include the file, save the data from $CONFIG include strip_tags($i18ndir).strip_tags($lang).'.php'; if(isset($TRANSLATIONS) && is_array($TRANSLATIONS)) { @@ -294,8 +296,14 @@ class OC_L10N{ } foreach($accepted_languages as $i) { $temp = explode(';', $i); - if(array_search($temp[0], $available) !== false) { - return $temp[0]; + $temp[0] = str_replace('-', '_', $temp[0]); + if( ($key = array_search($temp[0], $available)) !== false) { + return $available[$key]; + } + foreach($available as $l) { + if ( $temp[0] == substr($l, 0, 2) ) { + return $l; + } } } } diff --git a/lib/migrate.php b/lib/migrate.php index 2cc0a3067b8..5ff8e338a44 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -78,67 +78,67 @@ class OC_Migrate{ * @param otional $path string path to zip output folder * @return false on error, path to zip on success */ - public static function export( $uid=null, $type='user', $path=null ) { + public static function export( $uid=null, $type='user', $path=null ) { $datadir = OC_Config::getValue( 'datadirectory' ); - // Validate export type - $types = array( 'user', 'instance', 'system', 'userfiles' ); - if( !in_array( $type, $types ) ) { - OC_Log::write( 'migration', 'Invalid export type', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - self::$exporttype = $type; - // Userid? - if( self::$exporttype == 'user' ) { - // Check user exists - self::$uid = is_null($uid) ? OC_User::getUser() : $uid; - if(!OC_User::userExists(self::$uid)) { - return json_encode( array( 'success' => false) ); - } - } - // Calculate zipname - if( self::$exporttype == 'user' ) { - $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip'; - } else { - $zipname = 'oc_export_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '.zip'; - } - // Calculate path - if( self::$exporttype == 'user' ) { - self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname; - } else { - if( !is_null( $path ) ) { - // Validate custom path - if( !file_exists( $path ) || !is_writeable( $path ) ) { - OC_Log::write( 'migration', 'Path supplied is invalid.', OC_Log::ERROR ); - return json_encode( array( 'success' => false ) ); - } - self::$zippath = $path . $zipname; - } else { - // Default path - self::$zippath = get_temp_dir() . '/' . $zipname; - } - } - // Create the zip object - if( !self::createZip() ) { - return json_encode( array( 'success' => false ) ); - } - // Do the export - self::findProviders(); - $exportdata = array(); - switch( self::$exporttype ) { - case 'user': - // Connect to the db - self::$dbpath = $datadir . '/' . self::$uid . '/migration.db'; - if( !self::connectDB() ) { - return json_encode( array( 'success' => false ) ); - } - self::$content = new OC_Migration_Content( self::$zip, self::$MDB2 ); - // Export the app info - $exportdata = self::exportAppData(); + // Validate export type + $types = array( 'user', 'instance', 'system', 'userfiles' ); + if( !in_array( $type, $types ) ) { + OC_Log::write( 'migration', 'Invalid export type', OC_Log::ERROR ); + return json_encode( array( 'success' => false ) ); + } + self::$exporttype = $type; + // Userid? + if( self::$exporttype == 'user' ) { + // Check user exists + self::$uid = is_null($uid) ? OC_User::getUser() : $uid; + if(!OC_User::userExists(self::$uid)) { + return json_encode( array( 'success' => false) ); + } + } + // Calculate zipname + if( self::$exporttype == 'user' ) { + $zipname = 'oc_export_' . self::$uid . '_' . date("y-m-d_H-i-s") . '.zip'; + } else { + $zipname = 'oc_export_' . self::$exporttype . '_' . date("y-m-d_H-i-s") . '.zip'; + } + // Calculate path + if( self::$exporttype == 'user' ) { + self::$zippath = $datadir . '/' . self::$uid . '/' . $zipname; + } else { + if( !is_null( $path ) ) { + // Validate custom path + if( !file_exists( $path ) || !is_writeable( $path ) ) { + OC_Log::write( 'migration', 'Path supplied is invalid.', OC_Log::ERROR ); + return json_encode( array( 'success' => false ) ); + } + self::$zippath = $path . $zipname; + } else { + // Default path + self::$zippath = get_temp_dir() . '/' . $zipname; + } + } + // Create the zip object + if( !self::createZip() ) { + return json_encode( array( 'success' => false ) ); + } + // Do the export + self::findProviders(); + $exportdata = array(); + switch( self::$exporttype ) { + case 'user': + // Connect to the db + self::$dbpath = $datadir . '/' . self::$uid . '/migration.db'; + if( !self::connectDB() ) { + return json_encode( array( 'success' => false ) ); + } + self::$content = new OC_Migration_Content( self::$zip, self::$MDB2 ); + // Export the app info + $exportdata = self::exportAppData(); // Add the data dir to the zip self::$content->addDir(OC_User::getHome(self::$uid), true, '/' ); - break; - case 'instance': - self::$content = new OC_Migration_Content( self::$zip ); + break; + case 'instance': + self::$content = new OC_Migration_Content( self::$zip ); // Creates a zip that is compatable with the import function $dbfile = tempnam( get_temp_dir(), "owncloud_export_data_" ); OC_DB::getDbStructure( $dbfile, 'MDB2_SCHEMA_DUMP_ALL'); @@ -155,32 +155,32 @@ class OC_Migrate{ foreach(OC_User::getUsers() as $user) { self::$content->addDir(OC_User::getHome($user), true, "/userdata/" ); } - break; + break; case 'userfiles': self::$content = new OC_Migration_Content( self::$zip ); // Creates a zip with all of the users files foreach(OC_User::getUsers() as $user) { self::$content->addDir(OC_User::getHome($user), true, "/" ); } - break; + break; case 'system': self::$content = new OC_Migration_Content( self::$zip ); // Creates a zip with the owncloud system files self::$content->addDir( OC::$SERVERROOT . '/', false, '/'); foreach (array(".git", "3rdparty", "apps", "core", "files", "l10n", "lib", "ocs", "search", "settings", "tests") as $dir) { - self::$content->addDir( OC::$SERVERROOT . '/' . $dir, true, "/"); + self::$content->addDir( OC::$SERVERROOT . '/' . $dir, true, "/"); } - break; - } - if( !$info = self::getExportInfo( $exportdata ) ) { - return json_encode( array( 'success' => false ) ); - } - // Add the export info json to the export zip - self::$content->addFromString( $info, 'export_info.json' ); - if( !self::$content->finish() ) { - return json_encode( array( 'success' => false ) ); - } - return json_encode( array( 'success' => true, 'data' => self::$zippath ) ); + break; + } + if( !$info = self::getExportInfo( $exportdata ) ) { + return json_encode( array( 'success' => false ) ); + } + // Add the export info json to the export zip + self::$content->addFromString( $info, 'export_info.json' ); + if( !self::$content->finish() ) { + return json_encode( array( 'success' => false ) ); + } + return json_encode( array( 'success' => true, 'data' => self::$zippath ) ); } /** @@ -254,7 +254,7 @@ class OC_Migrate{ OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR ); } return json_encode( array( 'success' => true, 'data' => $appsimported ) ); - break; + break; case 'instance': /* * EXPERIMENTAL @@ -281,7 +281,7 @@ class OC_Migrate{ // Done return json_encode( array( 'success' => true ) ); */ - break; + break; } } @@ -319,10 +319,10 @@ class OC_Migrate{ static private function extractZip( $path ) { self::$zip = new ZipArchive; // Validate path - if( !file_exists( $path ) ) { - OC_Log::write( 'migration', 'Zip not found', OC_Log::ERROR ); - return false; - } + if( !file_exists( $path ) ) { + OC_Log::write( 'migration', 'Zip not found', OC_Log::ERROR ); + return false; + } if ( self::$zip->open( $path ) != true ) { OC_Log::write( 'migration', "Failed to open zip file", OC_Log::ERROR ); return false; @@ -555,9 +555,9 @@ class OC_Migrate{ if ( self::$zip->open( self::$zippath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE ) !== true ) { OC_Log::write('migration', 'Failed to create the zip with error: '.self::$zip->getStatusString(), OC_Log::ERROR); return false; - } else { - return true; - } + } else { + return true; + } } /** diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 12e5026a877..24081425f1e 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -44,10 +44,10 @@ class OC_OCSClient{ * @returns string of the KB server * This function returns the url of the OCS knowledge base server. It´s possible to set it in the config file or it will fallback to the default */ - private static function getKBURL() { - $url = OC_Config::getValue('knowledgebaseurl', 'http://api.apps.owncloud.com/v1'); - return($url); - } + private static function getKBURL() { + $url = OC_Config::getValue('knowledgebaseurl', 'http://api.apps.owncloud.com/v1'); + return($url); + } /** * @brief Get the content of an OCS url call. diff --git a/lib/public/contacts.php b/lib/public/contacts.php index 5762fd28e02..88d812e735a 100644 --- a/lib/public/contacts.php +++ b/lib/public/contacts.php @@ -28,76 +28,160 @@ // use OCP namespace for all classes that are considered public. // This means that they should be used by apps instead of the internal ownCloud classes -namespace OCP; +namespace OCP { -/** - * This class provides access to the contacts app. Use this class exclusively if you want to access contacts. - * - * Contacts in general will be expressed as an array of key-value-pairs. - * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1 - * - * Proposed workflow for working with contacts: - * - search for the contacts - * - manipulate the results array - * - createOrUpdate will save the given contacts overwriting the existing data - * - * For updating it is mandatory to keep the id. - * Without an id a new contact will be created. - * - */ -class Contacts -{ /** - * This function is used to search and find contacts within the users address books. - * In case $pattern is empty all contacts will be returned. + * This class provides access to the contacts app. Use this class exclusively if you want to access contacts. + * + * Contacts in general will be expressed as an array of key-value-pairs. + * The keys will match the property names defined in https://tools.ietf.org/html/rfc2426#section-1 + * + * Proposed workflow for working with contacts: + * - search for the contacts + * - manipulate the results array + * - createOrUpdate will save the given contacts overwriting the existing data + * + * For updating it is mandatory to keep the id. + * Without an id a new contact will be created. * - * @param string $pattern which should match within the $searchProperties - * @param array $searchProperties defines the properties within the query pattern should match - * @param array $options - for future use. One should always have options! - * @return array of contacts which are arrays of key-value-pairs */ - public static function search($pattern, $searchProperties = array(), $options = array()) { + class Contacts { - // dummy results - return array( - array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'), - array('id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => array('d@e.f', 'g@h.i')), - ); - } + /** + * This function is used to search and find contacts within the users address books. + * In case $pattern is empty all contacts will be returned. + * + * Example: + * Following function shows how to search for contacts for the name and the email address. + * + * public static function getMatchingRecipient($term) { + * // The API is not active -> nothing to do + * if (!\OCP\Contacts::isEnabled()) { + * return array(); + * } + * + * $result = \OCP\Contacts::search($term, array('FN', 'EMAIL')); + * $receivers = array(); + * foreach ($result as $r) { + * $id = $r['id']; + * $fn = $r['FN']; + * $email = $r['EMAIL']; + * if (!is_array($email)) { + * $email = array($email); + * } + * + * // loop through all email addresses of this contact + * foreach ($email as $e) { + * $displayName = $fn . " <$e>"; + * $receivers[] = array( + * 'id' => $id, + * 'label' => $displayName, + * 'value' => $displayName); + * } + * } + * + * return $receivers; + * } + * + * + * @param string $pattern which should match within the $searchProperties + * @param array $searchProperties defines the properties within the query pattern should match + * @param array $options - for future use. One should always have options! + * @return array of contacts which are arrays of key-value-pairs + */ + public static function search($pattern, $searchProperties = array(), $options = array()) { + $result = array(); + foreach(self::$address_books as $address_book) { + $r = $address_book->search($pattern, $searchProperties, $options); + $result = array_merge($result, $r); + } - /** - * This function can be used to delete the contact identified by the given id - * - * @param object $id the unique identifier to a contact - * @return bool successful or not - */ - public static function delete($id) { - return false; - } + return $result; + } - /** - * This function is used to create a new contact if 'id' is not given or not present. - * Otherwise the contact will be updated by replacing the entire data set. - * - * @param array $properties this array if key-value-pairs defines a contact - * @return array representing the contact just created or updated - */ - public static function createOrUpdate($properties) { + /** + * This function can be used to delete the contact identified by the given id + * + * @param object $id the unique identifier to a contact + * @param $address_book_key + * @return bool successful or not + */ + public static function delete($id, $address_book_key) { + if (!array_key_exists($address_book_key, self::$address_books)) + return null; - // dummy - return array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', - 'PHOTO' => 'VALUE=uri:http://www.abc.com/pub/photos/jqpublic.gif', - 'ADR' => ';;123 Main Street;Any Town;CA;91921-1234' - ); - } + $address_book = self::$address_books[$address_book_key]; + if ($address_book->getPermissions() & \OCP\PERMISSION_DELETE) + return null; - /** - * Check if contacts are available (e.g. contacts app enabled) - * - * @return bool true if enabled, false if not - */ - public static function isEnabled() { - return false; - } + return $address_book->delete($id); + } + + /** + * This function is used to create a new contact if 'id' is not given or not present. + * Otherwise the contact will be updated by replacing the entire data set. + * + * @param array $properties this array if key-value-pairs defines a contact + * @param $address_book_key string to identify the address book in which the contact shall be created or updated + * @return array representing the contact just created or updated + */ + public static function createOrUpdate($properties, $address_book_key) { + + if (!array_key_exists($address_book_key, self::$address_books)) + return null; + + $address_book = self::$address_books[$address_book_key]; + if ($address_book->getPermissions() & \OCP\PERMISSION_CREATE) + return null; + return $address_book->createOrUpdate($properties); + } + + /** + * Check if contacts are available (e.g. contacts app enabled) + * + * @return bool true if enabled, false if not + */ + public static function isEnabled() { + return !empty(self::$address_books); + } + + /** + * @param \OCP\IAddressBook $address_book + */ + public static function registerAddressBook(\OCP\IAddressBook $address_book) { + self::$address_books[$address_book->getKey()] = $address_book; + } + + /** + * @param \OCP\IAddressBook $address_book + */ + public static function unregisterAddressBook(\OCP\IAddressBook $address_book) { + unset(self::$address_books[$address_book->getKey()]); + } + + /** + * @return array + */ + public static function getAddressBooks() { + $result = array(); + foreach(self::$address_books as $address_book) { + $result[$address_book->getKey()] = $address_book->getDisplayName(); + } + + return $result; + } + + /** + * removes all registered address book instances + */ + public static function clear() { + self::$address_books = array(); + } + + /** + * @var \OCP\IAddressBook[] which holds all registered address books + */ + private static $address_books = array(); + } } diff --git a/lib/public/iaddressbook.php b/lib/public/iaddressbook.php new file mode 100644 index 00000000000..14943747f48 --- /dev/null +++ b/lib/public/iaddressbook.php @@ -0,0 +1,74 @@ +<?php +/** + * ownCloud + * + * @author Thomas Müller + * @copyright 2012 Thomas Müller thomas.mueller@tmit.eu + * + * 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/>. + * + */ + +// use OCP namespace for all classes that are considered public. +// This means that they should be used by apps instead of the internal ownCloud classes +namespace OCP { + interface IAddressBook { + + /** + * @return string defining the technical unique key + */ + public function getKey(); + + /** + * In comparison to getKey() this function returns a human readable (maybe translated) name + * @return mixed + */ + public function getDisplayName(); + + /** + * @param string $pattern which should match within the $searchProperties + * @param array $searchProperties defines the properties within the query pattern should match + * @param array $options - for future use. One should always have options! + * @return array of contacts which are arrays of key-value-pairs + */ + public function search($pattern, $searchProperties, $options); +// // dummy results +// return array( +// array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', 'GEO' => '37.386013;-122.082932'), +// array('id' => 5, 'FN' => 'Thomas Tanghus', 'EMAIL' => array('d@e.f', 'g@h.i')), +// ); + + /** + * @param array $properties this array if key-value-pairs defines a contact + * @return array representing the contact just created or updated + */ + public function createOrUpdate($properties); +// // dummy +// return array('id' => 0, 'FN' => 'Thomas Müller', 'EMAIL' => 'a@b.c', +// 'PHOTO' => 'VALUE=uri:http://www.abc.com/pub/photos/jqpublic.gif', +// 'ADR' => ';;123 Main Street;Any Town;CA;91921-1234' +// ); + + /** + * @return mixed + */ + public function getPermissions(); + + /** + * @param object $id the unique identifier to a contact + * @return bool successful or not + */ + public function delete($id); + } +} diff --git a/lib/public/user.php b/lib/public/user.php index b320ce8ea0c..9e50115ab70 100644 --- a/lib/public/user.php +++ b/lib/public/user.php @@ -65,12 +65,12 @@ class User { /** * @brief check if a user exists * @param string $uid the username + * @param string $excludingBackend (default none) * @return boolean */ - public static function userExists( $uid ) { - return \OC_USER::userExists( $uid ); + public static function userExists( $uid, $excludingBackend = null ) { + return \OC_USER::userExists( $uid, $excludingBackend ); } - /** * @brief Loggs the user out including all the session data * @returns true diff --git a/lib/request.php b/lib/request.php index c975c84a711..99a77e1b59e 100755 --- a/lib/request.php +++ b/lib/request.php @@ -18,7 +18,7 @@ class OC_Request { if(OC::$CLI) { return 'localhost'; } - if(OC_Config::getValue('overwritehost', '')<>''){ + if(OC_Config::getValue('overwritehost', '')<>'') { return OC_Config::getValue('overwritehost'); } if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { @@ -43,7 +43,7 @@ class OC_Request { * Returns the server protocol. It respects reverse proxy servers and load balancers */ public static function serverProtocol() { - if(OC_Config::getValue('overwriteprotocol', '')<>''){ + if(OC_Config::getValue('overwriteprotocol', '')<>'') { return OC_Config::getValue('overwriteprotocol'); } if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { @@ -74,7 +74,7 @@ class OC_Request { switch($encoding) { case 'ISO-8859-1' : - $path_info = utf8_encode($path_info); + $path_info = utf8_encode($path_info); } // end copy diff --git a/lib/setup.php b/lib/setup.php index 264cd55795e..fdd10be6824 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -319,9 +319,11 @@ class OC_Setup { $entry.='Offending command was: '.$query.'<br />'; echo($entry); } + else { + $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC"; + $result = pg_query($connection, $query); + } } - $query = "REVOKE ALL PRIVILEGES ON DATABASE \"$e_name\" FROM PUBLIC"; - $result = pg_query($connection, $query); } private static function pg_createDBUser($name, $password, $connection) { diff --git a/lib/templatelayout.php b/lib/templatelayout.php index 1a0570a270d..4173e008ba7 100644 --- a/lib/templatelayout.php +++ b/lib/templatelayout.php @@ -97,13 +97,13 @@ class OC_TemplateLayout extends OC_Template { * @param $web base for path * @param $file the filename */ - static public function appendIfExist(&$files, $root, $webroot, $file) { - if (is_file($root.'/'.$file)) { + static public function appendIfExist(&$files, $root, $webroot, $file) { + if (is_file($root.'/'.$file)) { $files[] = array($root, $webroot, $file); return true; - } - return false; - } + } + return false; + } static public function findStylesheetFiles($styles) { // Read the selected theme from the config file @@ -130,8 +130,14 @@ class OC_TemplateLayout extends OC_Template { // or in apps? foreach( OC::$APPSROOTS as $apps_dir) { - if(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style$fext.css")) { $append =true; break; } - elseif(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style.css")) { $append =true; break; } + if(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style$fext.css")) { + $append = true; + break; + } + elseif(self::appendIfExist($files, $apps_dir['path'], $apps_dir['url'], "$style.css")) { + $append = true; + break; + } } if(! $append) { echo('css file not found: style:'.$style.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); @@ -192,8 +198,14 @@ class OC_TemplateLayout extends OC_Template { // Is it part of an app? $append = false; foreach( OC::$APPSROOTS as $apps_dir) { - if(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script$fext.js")) { $append =true; break; } - elseif(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script.js")) { $append =true; break; } + if(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script$fext.js")) { + $append = true; + break; + } + elseif(self::appendIfExist($files, $apps_dir['path'], OC::$WEBROOT.$apps_dir['url'], "$script.js")) { + $append = true; + break; + } } if(! $append) { echo('js file not found: script:'.$script.' formfactor:'.$fext.' webroot:'.OC::$WEBROOT.' serverroot:'.OC::$SERVERROOT); diff --git a/lib/updater.php b/lib/updater.php index 11081eded63..d44ac108380 100644 --- a/lib/updater.php +++ b/lib/updater.php @@ -52,18 +52,18 @@ class OC_Updater{ ) ); $xml=@file_get_contents($url, 0, $ctx); - if($xml==false) { - return array(); - } - $data=@simplexml_load_string($xml); + if($xml==false) { + return array(); + } + $data=@simplexml_load_string($xml); $tmp=array(); - $tmp['version'] = $data->version; - $tmp['versionstring'] = $data->versionstring; - $tmp['url'] = $data->url; - $tmp['web'] = $data->web; + $tmp['version'] = $data->version; + $tmp['versionstring'] = $data->versionstring; + $tmp['url'] = $data->url; + $tmp['web'] = $data->web; - return $tmp; + return $tmp; } public static function ShowUpdatingHint() { diff --git a/lib/user.php b/lib/user.php index 31c93740d77..80f88ca7052 100644 --- a/lib/user.php +++ b/lib/user.php @@ -86,8 +86,9 @@ class OC_User { */ public static function useBackend( $backend = 'database' ) { if($backend instanceof OC_User_Interface) { + OC_Log::write('core', 'Adding user backend instance of '.get_class($backend).'.', OC_Log::DEBUG); self::$_usedBackends[get_class($backend)]=$backend; - }else{ + } else { // You'll never know what happens if( null === $backend OR !is_string( $backend )) { $backend = 'database'; @@ -98,15 +99,17 @@ class OC_User { case 'database': case 'mysql': case 'sqlite': + OC_Log::write('core', 'Adding user backend '.$backend.'.', OC_Log::DEBUG); self::$_usedBackends[$backend] = new OC_User_Database(); break; default: + OC_Log::write('core', 'Adding default user backend '.$backend.'.', OC_Log::DEBUG); $className = 'OC_USER_' . strToUpper($backend); self::$_usedBackends[$backend] = new $className(); break; } } - true; + return true; } /** @@ -124,15 +127,19 @@ class OC_User { foreach($backends as $i=>$config) { $class=$config['class']; $arguments=$config['arguments']; - if(class_exists($class) and array_search($i, self::$_setupedBackends)===false) { - // make a reflection object - $reflectionObj = new ReflectionClass($class); - - // use Reflection to create a new instance, using the $args - $backend = $reflectionObj->newInstanceArgs($arguments); - self::useBackend($backend); - $_setupedBackends[]=$i; - }else{ + if(class_exists($class)) { + if(array_search($i, self::$_setupedBackends)===false) { + // make a reflection object + $reflectionObj = new ReflectionClass($class); + + // use Reflection to create a new instance, using the $args + $backend = $reflectionObj->newInstanceArgs($arguments); + self::useBackend($backend); + $_setupedBackends[]=$i; + } else { + OC_Log::write('core', 'User backend '.$class.' already initialized.', OC_Log::DEBUG); + } + } else { OC_Log::write('core', 'User backend '.$class.' not found.', OC_Log::ERROR); } } @@ -407,10 +414,15 @@ class OC_User { /** * @brief check if a user exists * @param string $uid the username + * @param string $excludingBackend (default none) * @return boolean */ - public static function userExists($uid) { + public static function userExists($uid, $excludingBackend=null) { foreach(self::$_usedBackends as $backend) { + if (!is_null($excludingBackend) && !strcmp(get_class($backend),$excludingBackend)) { + OC_Log::write('OC_User', $excludingBackend . 'excluded from user existance check.', OC_Log::DEBUG); + continue; + } $result=$backend->userExists($uid); if($result===true) { return true; diff --git a/lib/util.php b/lib/util.php index 7cbac3a572b..0f6ead24190 100755 --- a/lib/util.php +++ b/lib/util.php @@ -311,8 +311,7 @@ class OC_Util { $parameters[$value] = true; } if (!empty($_POST['user'])) { - $parameters["username"] = - OC_Util::sanitizeHTML($_POST['user']).'"'; + $parameters["username"] = OC_Util::sanitizeHTML($_POST['user']).'"'; $parameters['user_autofocus'] = false; } else { $parameters["username"] = ''; @@ -580,7 +579,7 @@ class OC_Util { /** * Check if the ownCloud server can connect to the internet */ - public static function isinternetconnectionworking() { + public static function isinternetconnectionworking() { // try to connect to owncloud.org to see if http connections to the internet are possible. $connected = @fsockopen("www.owncloud.org", 80); @@ -679,34 +678,34 @@ class OC_Util { * If not, file_get_element is used. */ - public static function getUrlContent($url){ + public static function getUrlContent($url){ - if (function_exists('curl_init')) { - - $curl = curl_init(); - - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); - $data = curl_exec($curl); - curl_close($curl); - - } else { - - $ctx = stream_context_create( - array( - 'http' => array( - 'timeout' => 10 - ) - ) - ); - $data=@file_get_contents($url, 0, $ctx); - - } - - return $data; - } + if (function_exists('curl_init')) { + + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_USERAGENT, "ownCloud Server Crawler"); + $data = curl_exec($curl); + curl_close($curl); + + } else { + + $ctx = stream_context_create( + array( + 'http' => array( + 'timeout' => 10 + ) + ) + ); + $data=@file_get_contents($url, 0, $ctx); + + } + + return $data; + } } |