diff options
Diffstat (limited to 'lib')
44 files changed, 1084 insertions, 505 deletions
diff --git a/lib/app.php b/lib/app.php index 28f1f16ebaf..7889339e420 100755 --- a/lib/app.php +++ b/lib/app.php @@ -40,7 +40,7 @@ class OC_App{ /** * @brief loads all apps * @param array $types - * @returns true/false + * @return bool * * This function walks through the owncloud directory and loads all apps * it can find. A directory contains an app if the file /appinfo/app.php @@ -77,7 +77,7 @@ class OC_App{ /** * load a single app - * @param string app + * @param string $app */ public static function loadApp($app) { if(is_file(self::getAppPath($app).'/appinfo/app.php')) { @@ -90,6 +90,7 @@ class OC_App{ * check if an app is of a specific type * @param string $app * @param string/array $types + * @return bool */ public static function isType($app,$types) { if(is_string($types)) { @@ -156,8 +157,8 @@ class OC_App{ /** * @brief checks whether or not an app is enabled - * @param $app app - * @returns true/false + * @param string $app app + * @return bool * * This function checks whether or not an app is enabled. */ @@ -171,8 +172,8 @@ class OC_App{ /** * @brief enables an app - * @param $app app - * @returns true/false + * @param mixed $app app + * @return bool * * This function set an app as enabled in appconfig. */ @@ -202,13 +203,12 @@ class OC_App{ }else{ return false; } - return $app; } /** * @brief disables an app - * @param $app app - * @returns true/false + * @param string $app app + * @return bool * * This function set an app as disabled in appconfig. */ @@ -219,8 +219,8 @@ class OC_App{ /** * @brief adds an entry to the navigation - * @param $data array containing the data - * @returns true/false + * @param string $data array containing the data + * @return bool * * This function adds a new entry to the navigation visible to users. $data * is an associative array. @@ -245,8 +245,8 @@ class OC_App{ /** * @brief marks a navigation entry as active - * @param $id id of the entry - * @returns true/false + * @param string $id id of the entry + * @return bool * * This function sets a navigation entry as active and removes the 'active' * property from all other entries. The templates can use this for @@ -259,7 +259,7 @@ class OC_App{ /** * @brief gets the active Menu entry - * @returns id or empty string + * @return string id or empty string * * This function returns the id of the active navigation entry (set by * setActiveNavigationEntry @@ -270,7 +270,7 @@ class OC_App{ /** * @brief Returns the Settings Navigation - * @returns associative array + * @return array * * This function returns an array containing all settings pages added. The * entries are sorted by the key 'order' ascending. @@ -291,7 +291,7 @@ class OC_App{ // personal menu $settings[] = array( "id" => "personal", "order" => 1, "href" => OC_Helper::linkTo( "settings", "personal.php" ), "name" => $l->t("Personal"), "icon" => OC_Helper::imagePath( "settings", "personal.svg" )); - // if there're some settings forms + // if there are some settings forms if(!empty(self::$settingsForms)) // settings menu $settings[]=array( "id" => "settings", "order" => 1000, "href" => OC_Helper::linkTo( "settings", "settings.php" ), "name" => $l->t("Settings"), "icon" => OC_Helper::imagePath( "settings", "settings.svg" )); @@ -361,6 +361,7 @@ class OC_App{ return $app_dir[$appid]=$dir; } } + return false; } /** * Get the directory for the given app. @@ -370,6 +371,7 @@ class OC_App{ if( ($dir = self::findAppInDirectories($appid)) != false) { return $dir['path'].'/'.$appid; } + return false; } /** @@ -380,6 +382,7 @@ class OC_App{ if( ($dir = self::findAppInDirectories($appid)) != false) { return OC::$WEBROOT.$dir['url'].'/'.$appid; } + return false; } /** @@ -397,10 +400,11 @@ class OC_App{ } /** - * @brief Read app metadata from the info.xml file + * @brief Read all app metadata from the info.xml file * @param string $appid id of the app or the path of the info.xml file - * @param boolean path (optional) - * @returns array + * @param boolean $path (optional) + * @return array + * @note all data is read from info.xml, not just pre-defined fields */ public static function getAppInfo($appid,$path=false) { if($path) { @@ -414,24 +418,36 @@ class OC_App{ $data=array(); $content=@file_get_contents($file); if(!$content) { - return; + return null; } $xml = new SimpleXMLElement($content); $data['info']=array(); $data['remote']=array(); $data['public']=array(); foreach($xml->children() as $child) { + /** + * @var $child SimpleXMLElement + */ if($child->getName()=='remote') { foreach($child->children() as $remote) { + /** + * @var $remote SimpleXMLElement + */ $data['remote'][$remote->getName()]=(string)$remote; } }elseif($child->getName()=='public') { foreach($child->children() as $public) { + /** + * @var $public SimpleXMLElement + */ $data['public'][$public->getName()]=(string)$public; } }elseif($child->getName()=='types') { $data['types']=array(); foreach($child->children() as $type) { + /** + * @var $type SimpleXMLElement + */ $data['types'][]=$type->getName(); } }elseif($child->getName()=='description') { @@ -442,12 +458,13 @@ class OC_App{ } } self::$appInfo[$appid]=$data; + return $data; } /** * @brief Returns the navigation - * @returns associative array + * @return array * * This function returns an array containing all entries added. The * entries are sorted by the key 'order' ascending. Additional to the keys @@ -492,6 +509,8 @@ class OC_App{ case 'personal': $source=self::$personalForms; break; + default: + return array(); } foreach($source as $form) { $forms[]=include $form; @@ -521,20 +540,90 @@ class OC_App{ } /** - * get a list of all apps in the apps folder + * @brief: get a list of all apps in the apps folder + * @return array or app names (string IDs) + * @todo: change the name of this method to getInstalledApps, which is more accurate */ public static function getAllApps() { + $apps=array(); - foreach(OC::$APPSROOTS as $apps_dir) { - $dh=opendir($apps_dir['path']); - while($file=readdir($dh)) { - if($file[0]!='.' and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php')) { - $apps[]=$file; + + foreach ( OC::$APPSROOTS as $apps_dir ) { + if(! is_readable($apps_dir['path'])) { + OC_Log::write('core', 'unable to read app folder : ' .$apps_dir['path'] , OC_Log::WARN); + continue; + } + $dh = opendir( $apps_dir['path'] ); + + while( $file = readdir( $dh ) ) { + + if ( + $file[0] != '.' + and is_file($apps_dir['path'].'/'.$file.'/appinfo/app.php' ) + ) { + + $apps[] = $file; + } + } + } + return $apps; } + + /** + * @brief: get a list of all apps on apps.owncloud.com + * @return array, multi-dimensional array of apps. Keys: id, name, type, typename, personid, license, detailpage, preview, changed, description + */ + public static function getAppstoreApps( $filter = 'approved' ) { + + $catagoryNames = OC_OCSClient::getCategories(); + + if ( is_array( $catagoryNames ) ) { + + // Check that categories of apps were retrieved correctly + if ( ! $categories = array_keys( $catagoryNames ) ) { + + return false; + + } + + $page = 0; + + $remoteApps = OC_OCSClient::getApplications( $categories, $page, $filter ); + + $app1 = array(); + + $i = 0; + + foreach ( $remoteApps as $app ) { + + $app1[$i] = $app; + + $app1[$i]['author'] = $app['personid']; + + $app1[$i]['ocs_id'] = $app['id']; + + $app1[$i]['internal'] = $app1[$i]['active'] = 0; + + $i++; + + } + + } + + if ( empty( $app1 ) ) { + + return false; + + } else { + + return $app1; + + } + } /** * check if the app need updating and update when needed @@ -550,7 +639,13 @@ class OC_App{ $installedVersion = $versions[$app]; if (version_compare($currentVersion, $installedVersion, '>')) { OC_Log::write($app, 'starting app upgrade from '.$installedVersion.' to '.$currentVersion, OC_Log::DEBUG); - OC_App::updateApp($app); + try { + OC_App::updateApp($app); + } + catch (Exception $e) { + echo 'Failed to upgrade "'.$app.'". Exception="'.$e->getMessage().'"'; + die; + } OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app)); } } @@ -596,7 +691,7 @@ class OC_App{ /** * update the database for the app and call the update script - * @param string appid + * @param string $appid */ public static function updateApp($appid) { if(file_exists(self::getAppPath($appid).'/appinfo/database.xml')) { @@ -610,7 +705,7 @@ class OC_App{ include self::getAppPath($appid).'/appinfo/update.php'; } - //set remote/public handelers + //set remote/public handlers $appData=self::getAppInfo($appid); foreach($appData['remote'] as $name=>$path) { OCP\CONFIG::setAppValue('core', 'remote_'.$name, $appid.'/'.$path); @@ -623,7 +718,7 @@ class OC_App{ } /** - * @param string appid + * @param string $appid * @return OC_FilesystemView */ public static function getStorage($appid) { @@ -640,7 +735,7 @@ class OC_App{ } }else{ OC_Log::write('core', 'Can\'t get app storage, app '.$appid.' not enabled', OC_Log::ERROR); - false; + return false; } } } diff --git a/lib/appconfig.php b/lib/appconfig.php index 7f58b878504..6604e854d55 100644 --- a/lib/appconfig.php +++ b/lib/appconfig.php @@ -40,7 +40,7 @@ class OC_Appconfig{ /** * @brief Get all apps using the config - * @returns array with app ids + * @return array with app ids * * This function returns a list of all apps that have at least one * entry in the appconfig table. @@ -60,8 +60,8 @@ class OC_Appconfig{ /** * @brief Get the available keys for an app - * @param $app the app we are looking for - * @returns array with key names + * @param string $app the app we are looking for + * @return array with key names * * This function gets all keys of an app. Please note that the values are * not returned. @@ -81,13 +81,13 @@ class OC_Appconfig{ /** * @brief Gets the config value - * @param $app app - * @param $key key - * @param $default = null, default value if the key does not exist - * @returns the value or $default + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default * * This function gets a value from the appconfig table. If the key does - * not exist the default value will be returnes + * not exist the default value will be returned */ public static function getValue( $app, $key, $default = null ) { // At least some magic in here :-) @@ -114,10 +114,10 @@ class OC_Appconfig{ /** * @brief sets a value in the appconfig - * @param $app app - * @param $key key - * @param $value value - * @returns true/false + * @param string $app app + * @param string $key key + * @param string $value value + * @return bool * * Sets a value. If the key did not exist before it will be created. */ @@ -135,9 +135,9 @@ class OC_Appconfig{ /** * @brief Deletes a key - * @param $app app - * @param $key key - * @returns true/false + * @param string $app app + * @param string $key key + * @return bool * * Deletes a key. */ @@ -151,8 +151,8 @@ class OC_Appconfig{ /** * @brief Remove app from appconfig - * @param $app app - * @returns true/false + * @param string $app app + * @return bool * * Removes all keys in appconfig belonging to the app. */ diff --git a/lib/base.php b/lib/base.php index 6b4dd789b2f..41ff1870059 100644 --- a/lib/base.php +++ b/lib/base.php @@ -240,6 +240,8 @@ class OC{ OC_Util::addScript( "jquery-tipsy" ); OC_Util::addScript( "oc-dialogs" ); OC_Util::addScript( "js" ); + // request protection token MUST be defined after the jquery library but before any $('document').ready() + OC_Util::addScript( "requesttoken" ); OC_Util::addScript( "eventsource" ); OC_Util::addScript( "config" ); //OC_Util::addScript( "multiselect" ); @@ -303,14 +305,14 @@ class OC{ //set http auth headers for apache+php-cgi work around if (isset($_SERVER['HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['HTTP_AUTHORIZATION'], $matches)) { - list($name, $password) = explode(':', base64_decode($matches[1])); + list($name, $password) = explode(':', base64_decode($matches[1]), 2); $_SERVER['PHP_AUTH_USER'] = strip_tags($name); $_SERVER['PHP_AUTH_PW'] = strip_tags($password); } //set http auth headers for apache+php-cgi work around if variable gets renamed by apache if (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) && preg_match('/Basic\s+(.*)$/i', $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], $matches)) { - list($name, $password) = explode(':', base64_decode($matches[1])); + list($name, $password) = explode(':', base64_decode($matches[1]), 2); $_SERVER['PHP_AUTH_USER'] = strip_tags($name); $_SERVER['PHP_AUTH_PW'] = strip_tags($password); } @@ -526,11 +528,7 @@ class OC{ } protected static function tryFormLogin() { - if(!isset($_POST["user"]) - || !isset($_POST['password']) - || !isset($_SESSION['sectoken']) - || !isset($_POST['sectoken']) - || ($_SESSION['sectoken']!=$_POST['sectoken']) ) { + if(!isset($_POST["user"]) || !isset($_POST['password'])) { return false; } @@ -551,7 +549,8 @@ class OC{ else { OC_User::unsetMagicInCookie(); } - OC_Util::redirectToDefaultPage(); + header( 'Location: '.$_SERVER['REQUEST_URI'] ); + exit(); } return true; } diff --git a/lib/cache/xcache.php b/lib/cache/xcache.php index cecdf46351c..9f380f870b9 100644 --- a/lib/cache/xcache.php +++ b/lib/cache/xcache.php @@ -44,6 +44,12 @@ class OC_Cache_XCache { } public function clear($prefix='') { + if(!function_exists('xcache_unset_by_prefix')) { + function xcache_unset_by_prefix($prefix) { + // Since we can't clear targetted cache, we'll clear all. :( + xcache_clear_cache(XC_TYPE_VAR, 0); + } + } xcache_unset_by_prefix($this->getNamespace().$prefix); return true; } diff --git a/lib/config.php b/lib/config.php index 032d401264c..cbea9199320 100644 --- a/lib/config.php +++ b/lib/config.php @@ -47,7 +47,7 @@ class OC_Config{ /** * @brief Lists all available config keys - * @returns array with key names + * @return array with key names * * This function returns all keys saved in config.php. Please note that it * does not return the values. @@ -60,9 +60,9 @@ class OC_Config{ /** * @brief Gets a value from config.php - * @param $key key - * @param $default = null default value - * @returns the value or $default + * @param string $key key + * @param string $default = null default value + * @return string the value or $default * * This function gets the value from config.php. If it does not exist, * $default will be returned. @@ -79,9 +79,9 @@ class OC_Config{ /** * @brief Sets a value - * @param $key key - * @param $value value - * @returns true/false + * @param string $key key + * @param string $value value + * @return bool * * This function sets the value and writes the config.php. If the file can * not be written, false will be returned. @@ -99,8 +99,8 @@ class OC_Config{ /** * @brief Removes a key from the config - * @param $key key - * @returns true/false + * @param string $key key + * @return bool * * This function removes a key from the config.php. If owncloud has no * write access to config.php, the function will return false. @@ -121,7 +121,7 @@ class OC_Config{ /** * @brief Loads the config file - * @returns true/false + * @return bool * * Reads the config file and saves it to the cache */ @@ -148,7 +148,7 @@ class OC_Config{ /** * @brief Writes the config file - * @returns true/false + * @return bool * * Saves the config to the config file. * diff --git a/lib/connector/sabre/directory.php b/lib/connector/sabre/directory.php index 39606577f6d..413efef73b7 100644 --- a/lib/connector/sabre/directory.php +++ b/lib/connector/sabre/directory.php @@ -50,12 +50,14 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa public function createFile($name, $data = null) { if (isset($_SERVER['HTTP_OC_CHUNKED'])) { $info = OC_FileChunking::decodeName($name); + if (empty($info)) { + throw new Sabre_DAV_Exception_NotImplemented(); + } $chunk_handler = new OC_FileChunking($info); $chunk_handler->store($info['index'], $data); if ($chunk_handler->isComplete()) { $newPath = $this->path . '/' . $info['name']; - $f = OC_Filesystem::fopen($newPath, 'w'); - $chunk_handler->assemble($f); + $chunk_handler->file_assemble($newPath); return OC_Connector_Sabre_Node::getETagPropertyForPath($newPath); } } else { @@ -91,10 +93,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa $path = $this->path . '/' . $name; if (is_null($info)) { - $info = OC_FileCache::get($path); + $info = OC_Files::getFileInfo($path); } - if (!$info) throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); + if (!$info) { + throw new Sabre_DAV_Exception_NotFound('File with name ' . $path . ' could not be located'); + } if ($info['mimetype'] == 'httpd/unix-directory') { $node = new OC_Connector_Sabre_Directory($path); @@ -113,7 +117,7 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa */ public function getChildren() { - $folder_content = OC_FileCache::getFolderContent($this->path); + $folder_content = OC_Files::getDirectoryContent($this->path); $paths = array(); foreach($folder_content as $info) { $paths[] = $this->path.'/'.$info['name']; diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index ecbbef81292..bdedc030c88 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -23,7 +23,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IProperties { const GETETAG_PROPERTYNAME = '{DAV:}getetag'; - + const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; + /** * The path to the current node * @@ -142,7 +143,6 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr public function updateProperties($properties) { $existing = $this->getProperties(array()); foreach($properties as $propertyName => $propertyValue) { - $propertyName = preg_replace("/^{.*}/", "", $propertyName); // remove leading namespace from property name // If it was null, we need to delete the property if (is_null($propertyValue)) { if(array_key_exists( $propertyName, $existing )) { @@ -151,7 +151,7 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } else { - if( strcmp( $propertyName, "lastmodified") === 0) { + if( strcmp( $propertyName, self::LASTMODIFIED_PROPERTYNAME) === 0 ) { $this->touch($propertyValue); } else { if(!array_key_exists( $propertyName, $existing )) { diff --git a/lib/db.php b/lib/db.php index 8598f659cad..db4aca19dbe 100644 --- a/lib/db.php +++ b/lib/db.php @@ -28,18 +28,30 @@ class OC_DB { const BACKEND_PDO=0; const BACKEND_MDB2=1; + /** + * @var MDB2_Driver_Common + */ static private $connection; //the prefered connection to use, either PDO or MDB2 static private $backend=null; - static private $MDB2=false; - static private $PDO=false; - static private $schema=false; + /** + * @var MDB2_Driver_Common + */ + static private $MDB2=null; + /** + * @var PDO + */ + static private $PDO=null; + /** + * @var MDB2_Schema + */ + static private $schema=null; static private $inTransaction=false; static private $prefix=null; static private $type=null; /** * check which backend we should use - * @return BACKEND_MDB2 or BACKEND_PDO + * @return int BACKEND_MDB2 or BACKEND_PDO */ private static function getDBBackend() { //check if we can use PDO, else use MDB2 (installation always needs to be done my mdb2) @@ -59,37 +71,41 @@ class OC_DB { /** * @brief connects to the database - * @returns true if connection can be established or nothing (die()) + * @param int $backend + * @return bool true if connection can be established or false on error * * Connects to the database as specified in config.php */ public static function connect($backend=null) { if(self::$connection) { - return; + return true; } if(is_null($backend)) { $backend=self::getDBBackend(); } if($backend==self::BACKEND_PDO) { - self::connectPDO(); + $success = self::connectPDO(); self::$connection=self::$PDO; self::$backend=self::BACKEND_PDO; }else{ - self::connectMDB2(); + $success = self::connectMDB2(); self::$connection=self::$MDB2; self::$backend=self::BACKEND_MDB2; } + return $success; } /** * connect to the database using pdo + * + * @return bool */ public static function connectPDO() { if(self::$connection) { if(self::$backend==self::BACKEND_MDB2) { self::disconnect(); }else{ - return; + return true; } } // The global data we need @@ -146,6 +162,8 @@ class OC_DB { $dsn = 'oci:dbname=//' . $host . '/' . $name; } break; + default: + return false; } try{ self::$PDO=new PDO($dsn, $user, $pass, $opts); @@ -168,7 +186,7 @@ class OC_DB { if(self::$backend==self::BACKEND_PDO) { self::disconnect(); }else{ - return; + return true; } } // The global data we need @@ -226,14 +244,18 @@ class OC_DB { 'phptype' => 'oci8', 'username' => $user, 'password' => $pass, + 'charset' => 'AL32UTF8', ); if ($host != '') { $dsn['hostspec'] = $host; $dsn['database'] = $name; } else { // use dbname for hostspec $dsn['hostspec'] = $name; + $dsn['database'] = $user; } break; + default: + return false; } // Try to establish connection @@ -244,7 +266,7 @@ class OC_DB { echo( '<b>can not connect to database, using '.$type.'. ('.self::$MDB2->getUserInfo().')</center>'); OC_Log::write('core', self::$MDB2->getUserInfo(), OC_Log::FATAL); OC_Log::write('core', self::$MDB2->getMessage(), OC_Log::FATAL); - die( $error ); + die(); } // We always, really always want associative arrays @@ -257,8 +279,10 @@ class OC_DB { /** * @brief Prepare a SQL query - * @param $query Query string - * @returns prepared SQL query + * @param string $query Query string + * @param int $limit + * @param int $offset + * @return MDB2_Statement_Common prepared SQL query * * SQL query via MDB2 prepare(), needs to be execute()'d! */ @@ -273,8 +297,10 @@ class OC_DB { //FIXME: check limit notation for other dbs //the following sql thus might needs to take into account db ways of representing it //(oracle has no LIMIT / OFFSET) - $limitsql = ' LIMIT ' . $limit; + $limit = (int)$limit; + $limitsql = ' LIMIT ' . $limit; if (!is_null($offset)) { + $offset = (int)$offset; $limitsql .= ' OFFSET ' . $offset; } //insert limitsql @@ -297,7 +323,7 @@ class OC_DB { // Die if we have an error (error means: bad query, not 0 results!) if( PEAR::isError($result)) { $entry = 'DB Error: "'.$result->getMessage().'"<br />'; - $entry .= 'Offending command was: '.$query.'<br />'; + $entry .= 'Offending command was: '.htmlentities($query).'<br />'; OC_Log::write('core', $entry,OC_Log::FATAL); error_log('DB error: '.$entry); die( $entry ); @@ -307,7 +333,7 @@ class OC_DB { $result=self::$connection->prepare($query); }catch(PDOException $e) { $entry = 'DB Error: "'.$e->getMessage().'"<br />'; - $entry .= 'Offending command was: '.$query.'<br />'; + $entry .= 'Offending command was: '.htmlentities($query).'<br />'; OC_Log::write('core', $entry,OC_Log::FATAL); error_log('DB error: '.$entry); die( $entry ); @@ -319,8 +345,8 @@ class OC_DB { /** * @brief gets last value of autoincrement - * @param $table string The optional table name (will replace *PREFIX*) and add sequence suffix - * @returns id + * @param string $table The optional table name (will replace *PREFIX*) and add sequence suffix + * @return int id * * MDB2 lastInsertID() * @@ -332,14 +358,14 @@ class OC_DB { if($table !== null) { $prefix = OC_Config::getValue( "dbtableprefix", "oc_" ); $suffix = OC_Config::getValue( "dbsequencesuffix", "_id_seq" ); - $table = str_replace( '*PREFIX*', $prefix, $table ); + $table = str_replace( '*PREFIX*', $prefix, $table ).$suffix; } - return self::$connection->lastInsertId($table.$suffix); + return self::$connection->lastInsertId($table); } /** * @brief Disconnect - * @returns true/false + * @return bool * * This is good bye, good bye, yeah! */ @@ -359,8 +385,9 @@ class OC_DB { /** * @brief saves database scheme to xml file - * @param $file name of file - * @returns true/false + * @param string $file name of file + * @param int $mode + * @return bool * * TODO: write more documentation */ @@ -381,8 +408,8 @@ class OC_DB { /** * @brief Creates tables from XML file - * @param $file file to read structure from - * @returns true/false + * @param string $file file to read structure from + * @return bool * * TODO: write more documentation */ @@ -443,11 +470,11 @@ class OC_DB { /** * @brief update the database scheme - * @param $file file to read structure from + * @param string $file file to read structure from + * @return bool */ public static function updateDbFromStructure($file) { $CONFIG_DBTABLEPREFIX = OC_Config::getValue( "dbtableprefix", "oc_" ); - $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); self::connectScheme(); @@ -493,7 +520,7 @@ class OC_DB { /** * @brief connects to a MDB2 database scheme - * @returns true/false + * @returns bool * * Connects to a MDB2 database scheme */ @@ -562,12 +589,12 @@ class OC_DB { } /** - * @brief does minor chages to query - * @param $query Query string - * @returns corrected query string + * @brief does minor changes to query + * @param string $query Query string + * @return string corrected query string * * This function replaces *PREFIX* with the value of $CONFIG_DBTABLEPREFIX - * and replaces the ` woth ' or " according to the database driver. + * and replaces the ` with ' or " according to the database driver. */ private static function processQuery( $query ) { self::connect(); @@ -602,7 +629,7 @@ class OC_DB { /** * @brief drop a table - * @param string $tableNamme the table to drop + * @param string $tableName the table to drop */ public static function dropTable($tableName) { self::connectMDB2(); @@ -663,6 +690,7 @@ class OC_DB { /** * Start a transaction + * @return bool */ public static function beginTransaction() { self::connect(); @@ -671,10 +699,12 @@ class OC_DB { } self::$connection->beginTransaction(); self::$inTransaction=true; + return true; } /** * Commit the database changes done during a transaction that is in progress + * @return bool */ public static function commit() { self::connect(); @@ -683,6 +713,7 @@ class OC_DB { } self::$connection->commit(); self::$inTransaction=false; + return true; } /** @@ -719,7 +750,11 @@ class OC_DB { $msg .= 'SQLSTATE = '.$errorInfo[0] . ', '; $msg .= 'Driver Code = '.$errorInfo[1] . ', '; $msg .= 'Driver Message = '.$errorInfo[2]; + }else{ + $msg = ''; } + }else{ + $msg = ''; } return $msg; } @@ -729,6 +764,9 @@ class OC_DB { * small wrapper around PDOStatement to make it behave ,more like an MDB2 Statement */ class PDOStatementWrapper{ + /** + * @var PDOStatement + */ private $statement=null; private $lastArguments=array(); diff --git a/lib/filecache.php b/lib/filecache.php index adcf97753ed..07099bcccd5 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -481,7 +481,7 @@ class OC_FileCache{ */ public static function clear($user='') { if($user) { - $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE user=?'); + $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache` WHERE `user`=?'); $query->execute(array($user)); }else{ $query=OC_DB::prepare('DELETE FROM `*PREFIX*fscache`'); diff --git a/lib/filechunking.php b/lib/filechunking.php index d03af226d8b..5ab33c77ad7 100644 --- a/lib/filechunking.php +++ b/lib/filechunking.php @@ -55,12 +55,13 @@ class OC_FileChunking { public function assemble($f) { $cache = $this->getCache(); $prefix = $this->getPrefix(); + $count = 0; for($i=0; $i < $this->info['chunkcount']; $i++) { $chunk = $cache->get($prefix.$i); $cache->remove($prefix.$i); - fwrite($f,$chunk); + $count += fwrite($f,$chunk); } - fclose($f); + return $count; } public function signature_split($orgfile, $input) { @@ -91,4 +92,57 @@ class OC_FileChunking { 'count' => $count, ); } + + public function file_assemble($path) { + $absolutePath = OC_Filesystem::normalizePath(OC_Filesystem::getView()->getAbsolutePath($path)); + $data = ''; + // use file_put_contents as method because that best matches what this function does + if (OC_FileProxy::runPreProxies('file_put_contents', $absolutePath, $data) && OC_Filesystem::isValidPath($path)) { + $path = OC_Filesystem::getView()->getRelativePath($absolutePath); + $exists = OC_Filesystem::file_exists($path); + $run = true; + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + if(!$run) { + return false; + } + $target = OC_Filesystem::fopen($path, 'w'); + if($target) { + $count = $this->assemble($target); + fclose($target); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array( OC_Filesystem::signal_param_path => $path) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path) + ); + OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); + return $count > 0; + }else{ + return false; + } + } + } } diff --git a/lib/fileproxy/quota.php b/lib/fileproxy/quota.php index adbff3d301a..5a0dbdb6fe2 100644 --- a/lib/fileproxy/quota.php +++ b/lib/fileproxy/quota.php @@ -26,6 +26,7 @@ */ class OC_FileProxy_Quota extends OC_FileProxy{ + static $rootView; private $userQuota=-1; /** @@ -86,7 +87,10 @@ class OC_FileProxy_Quota extends OC_FileProxy{ } public function preCopy($path1,$path2) { - return (OC_Filesystem::filesize($path1)<$this->getFreeSpace() or $this->getFreeSpace()==0); + if(!self::$rootView){ + self::$rootView = new OC_FilesystemView(''); + } + return (self::$rootView->filesize($path1)<$this->getFreeSpace() or $this->getFreeSpace()==0); } public function preFromTmpFile($tmpfile,$path) { @@ -96,4 +100,4 @@ class OC_FileProxy_Quota extends OC_FileProxy{ public function preFromUploadedFile($tmpfile,$path) { return (filesize($tmpfile)<$this->getFreeSpace() or $this->getFreeSpace()==0); } -}
\ No newline at end of file +} diff --git a/lib/files.php b/lib/files.php index 63dd96b9509..ac999a9bd15 100644 --- a/lib/files.php +++ b/lib/files.php @@ -29,6 +29,36 @@ class OC_Files { static $tmpFiles=array(); /** + * get the filesystem info + * @param string path + * @return array + * + * returns an associative array with the following keys: + * - size + * - mtime + * - ctime + * - mimetype + * - encrypted + * - versioned + */ + public static function getFileInfo($path) { + if (($path == '/Shared' || substr($path, 0, 8) == '/Shared/') && OC_App::isEnabled('files_sharing')) { + if ($path == '/Shared') { + $info = OCP\Share::getItemsSharedWith('file', OC_Share_Backend_File::FORMAT_FILE_APP_ROOT); + } + else { + $path = substr($path, 7); + $info = OCP\Share::getItemSharedWith('file', $path, OC_Share_Backend_File::FORMAT_FILE_APP); + } + $info = $info[0]; + } + else { + $info = OC_FileCache::get($path); + } + return $info; + } + + /** * get the content of a directory * @param dir $directory path under datadirectory */ @@ -78,7 +108,24 @@ class OC_Files { return $files; } - + public static function searchByMime($mimetype_filter) { + $files = array(); + $dirs_to_check = array(''); + while (!empty($dirs_to_check)) { + // get next subdir to check + $dir = array_pop($dirs_to_check); + $dir_content = self::getDirectoryContent($dir, $mimetype_filter); + foreach($dir_content as $file) { + if ($file['type'] == 'file') { + $files[] = $dir.'/'.$file['name']; + } + else { + $dirs_to_check[] = $dir.'/'.$file['name']; + } + } + } + return $files; + } /** * return the content of a file or return a zip file containning multiply files diff --git a/lib/filesystem.php b/lib/filesystem.php index 92eb4fa4778..c6da826a339 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -357,7 +357,7 @@ class OC_Filesystem{ * @return string */ static public function getLocalPath($path) { - $datadir = OC_User::getHome($user).'/files'; + $datadir = OC_User::getHome(OC_User::getUser()).'/files'; $newpath = $path; if (strncmp($newpath, $datadir, strlen($datadir)) == 0) { $newpath = substr($path, strlen($datadir)); @@ -521,12 +521,20 @@ class OC_Filesystem{ return self::$defaultInstance->hasUpdated($path,$time); } - static public function removeETagHook($params) { + static public function removeETagHook($params, $root = false) { if (isset($params['path'])) { $path=$params['path']; } else { $path=$params['oldpath']; } + + if ($root) { // reduce path to the required part of it (no 'username/files') + $fakeRootView = new OC_FilesystemView($root); + $count = 1; + $path=str_replace(OC_App::getStorage("files")->getAbsolutePath(), "", $fakeRootView->getAbsolutePath($path), $count); + } + + $path = self::normalizePath($path); OC_Connector_Sabre_Node::removeETagPropertyForPath($path); } diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 743f9403011..2950ced5f9e 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -263,24 +263,26 @@ class OC_FilesystemView { $path = $this->getRelativePath($absolutePath); $exists = $this->file_exists($path); $run = true; - if(!$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path, + OC_Filesystem::signal_param_run => &$run + ) + ); + } OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_create, + OC_Filesystem::signal_write, array( OC_Filesystem::signal_param_path => $path, OC_Filesystem::signal_param_run => &$run ) ); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_write, - array( - OC_Filesystem::signal_param_path => $path, - OC_Filesystem::signal_param_run => &$run - ) - ); if(!$run) { return false; } @@ -289,18 +291,20 @@ class OC_FilesystemView { $count=OC_Helper::streamCopy($data, $target); fclose($target); fclose($data); - if(!$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array( OC_Filesystem::signal_param_path => $path) + ); + } OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_create, + OC_Filesystem::signal_post_write, array( OC_Filesystem::signal_param_path => $path) ); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_write, - array( OC_Filesystem::signal_param_path => $path) - ); OC_FileProxy::runPostProxies('file_put_contents', $absolutePath, $count); return $count > 0; }else{ @@ -330,14 +334,16 @@ class OC_FilesystemView { return false; } $run=true; - OC_Hook::emit( - OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath => $path2, - OC_Filesystem::signal_param_run => &$run - ) - ); + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + OC_Hook::emit( + OC_Filesystem::CLASSNAME, OC_Filesystem::signal_rename, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + } if($run) { $mp1 = $this->getMountPoint($path1.$postFix1); $mp2 = $this->getMountPoint($path2.$postFix2); @@ -353,14 +359,16 @@ class OC_FilesystemView { $storage1->unlink($this->getInternalPath($path1.$postFix1)); $result = $count>0; } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_rename, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath => $path2 - ) - ); + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_rename, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath => $path2 + ) + ); + } return $result; } } @@ -378,35 +386,37 @@ class OC_FilesystemView { return false; } $run=true; - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_copy, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath=>$path2, - OC_Filesystem::signal_param_run => &$run - ) - ); - $exists=$this->file_exists($path2); - if($run and !$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_create, + OC_Filesystem::signal_copy, array( - OC_Filesystem::signal_param_path => $path2, - OC_Filesystem::signal_param_run => &$run - ) - ); - } - if($run) { - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_write, - array( - OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath=>$path2, OC_Filesystem::signal_param_run => &$run ) ); + $exists=$this->file_exists($path2); + if($run and !$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_create, + array( + OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + } + if($run) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_write, + array( + OC_Filesystem::signal_param_path => $path2, + OC_Filesystem::signal_param_run => &$run + ) + ); + } } if($run) { $mp1=$this->getMountPoint($path1.$postFix1); @@ -420,26 +430,31 @@ class OC_FilesystemView { $target = $this->fopen($path2.$postFix2, 'w'); $result = OC_Helper::streamCopy($source, $target); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_copy, - array( - OC_Filesystem::signal_param_oldpath => $path1, - OC_Filesystem::signal_param_newpath=>$path2 - ) - ); - if(!$exists) { + if( $this->fakeRoot==OC_Filesystem::getRoot() ){ OC_Hook::emit( OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_create, - array(OC_Filesystem::signal_param_path => $path2) + OC_Filesystem::signal_post_copy, + array( + OC_Filesystem::signal_param_oldpath => $path1, + OC_Filesystem::signal_param_newpath=>$path2 + ) ); + if(!$exists) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_create, + array(OC_Filesystem::signal_param_path => $path2) + ); + } + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_post_write, + array( OC_Filesystem::signal_param_path => $path2) + ); + } else { // no real copy, file comes from somewhere else, e.g. version rollback -> just update the file cache and the webdav properties without all the other post_write actions + OC_FileCache_Update::update($path2, $this->fakeRoot); + OC_Filesystem::removeETagHook(array("path" => $path2), $this->fakeRoot); } - OC_Hook::emit( - OC_Filesystem::CLASSNAME, - OC_Filesystem::signal_post_write, - array( OC_Filesystem::signal_param_path => $path2) - ); return $result; } } diff --git a/lib/group.php b/lib/group.php index b56a4ad456c..66892a99b60 100644 --- a/lib/group.php +++ b/lib/group.php @@ -35,12 +35,15 @@ */ class OC_Group { // The backend used for group management + /** + * @var OC_Group_Interface[] + */ private static $_usedBackends = array(); /** * @brief set the group backend * @param string $backend The backend to use for user managment - * @returns true/false + * @return bool */ public static function useBackend( $backend ) { if($backend instanceof OC_Group_Interface) { @@ -57,10 +60,10 @@ class OC_Group { /** * @brief Try to create a new group - * @param $gid The name of the group to create - * @returns true/false + * @param string $gid The name of the group to create + * @return bool * - * Trys to create a new group. If the group name already exists, false will + * Tries to create a new group. If the group name already exists, false will * be returned. Basic checking of Group name * * Allowed characters in the username are: "a-z", "A-Z", "0-9" and "_.@-" @@ -94,6 +97,7 @@ class OC_Group { return true; } + return false; }else{ return false; } @@ -101,8 +105,8 @@ class OC_Group { /** * @brief delete a group - * @param $gid gid of the group to delete - * @returns true/false + * @param string $gid gid of the group to delete + * @return bool * * Deletes a group and removes it from the group_user-table */ @@ -126,6 +130,7 @@ class OC_Group { return true; } + return false; }else{ return false; } @@ -133,9 +138,9 @@ class OC_Group { /** * @brief is user in group? - * @param $uid uid of the user - * @param $gid gid of the group - * @returns true/false + * @param string $uid uid of the user + * @param string $gid gid of the group + * @return bool * * Checks whether the user is member of a group or not. */ @@ -150,9 +155,9 @@ class OC_Group { /** * @brief Add a user to a group - * @param $uid Name of the user to add to group - * @param $gid Name of the group in which add the user - * @returns true/false + * @param string $uid Name of the user to add to group + * @param string $gid Name of the group in which add the user + * @return bool * * Adds a user to a group. */ @@ -167,7 +172,7 @@ class OC_Group { OC_Hook::emit( "OC_Group", "pre_addToGroup", array( "run" => &$run, "uid" => $uid, "gid" => $gid )); if($run) { - $succes=false; + $success=false; //add the user to the all backends that have the group foreach(self::$_usedBackends as $backend) { @@ -175,13 +180,13 @@ class OC_Group { continue; if($backend->groupExists($gid)) { - $succes|=$backend->addToGroup($uid, $gid); + $success|=$backend->addToGroup($uid, $gid); } } - if($succes) { + if($success) { OC_Hook::emit( "OC_User", "post_addToGroup", array( "uid" => $uid, "gid" => $gid )); } - return $succes; + return $success; }else{ return false; } @@ -189,9 +194,9 @@ class OC_Group { /** * @brief Removes a user from a group - * @param $uid Name of the user to remove from group - * @param $gid Name of the group from which remove the user - * @returns true/false + * @param string $uid Name of the user to remove from group + * @param string $gid Name of the group from which remove the user + * @return bool * * removes the user from a group. */ @@ -216,8 +221,8 @@ class OC_Group { /** * @brief Get all groups a user belongs to - * @param $uid Name of the user - * @returns array with group names + * @param string $uid Name of the user + * @return array with group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. @@ -275,7 +280,10 @@ class OC_Group { /** * @brief get a list of all users in several groups * @param array $gids - * @returns array with user ids + * @param string $search + * @param int $limit + * @param int $offset + * @return array with user ids */ public static function usersInGroups($gids, $search = '', $limit = -1, $offset = 0) { $users = array(); diff --git a/lib/group/backend.php b/lib/group/backend.php index 1ba34c940cf..9ff432d0663 100644 --- a/lib/group/backend.php +++ b/lib/group/backend.php @@ -47,7 +47,7 @@ abstract class OC_Group_Backend implements OC_Group_Interface { /** * @brief Get all supported actions - * @returns bitwise-or'ed actions + * @return int bitwise-or'ed actions * * Returns the supported actions as int to be * compared with OC_USER_BACKEND_CREATE_USER etc. @@ -65,8 +65,8 @@ abstract class OC_Group_Backend implements OC_Group_Interface { /** * @brief Check if backend implements actions - * @param $actions bitwise-or'ed actions - * @returns boolean + * @param int $actions bitwise-or'ed actions + * @return boolean * * Returns the supported actions as int to be * compared with OC_GROUP_BACKEND_CREATE_GROUP etc. @@ -77,9 +77,9 @@ abstract class OC_Group_Backend implements OC_Group_Interface { /** * @brief is user in group? - * @param $uid uid of the user - * @param $gid gid of the group - * @returns true/false + * @param string $uid uid of the user + * @param string $gid gid of the group + * @return bool * * Checks whether the user is member of a group or not. */ @@ -89,8 +89,8 @@ abstract class OC_Group_Backend implements OC_Group_Interface { /** * @brief Get all groups a user belongs to - * @param $uid Name of the user - * @returns array with group names + * @param string $uid Name of the user + * @return array with group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. @@ -101,7 +101,10 @@ abstract class OC_Group_Backend implements OC_Group_Interface { /** * @brief get a list of all groups - * @returns array with group names + * @param string $search + * @param int $limit + * @param int $offset + * @return array with group names * * Returns a list with all groups */ @@ -121,7 +124,11 @@ abstract class OC_Group_Backend implements OC_Group_Interface { /** * @brief get a list of all users in a group - * @returns array with user ids + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with user ids */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { return array(); diff --git a/lib/group/database.php b/lib/group/database.php index f3012563acf..6eca98ba019 100644 --- a/lib/group/database.php +++ b/lib/group/database.php @@ -44,10 +44,10 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief Try to create a new group - * @param $gid The name of the group to create - * @returns true/false + * @param string $gid The name of the group to create + * @return bool * - * Trys to create a new group. If the group name already exists, false will + * Tries to create a new group. If the group name already exists, false will * be returned. */ public function createGroup( $gid ) { @@ -70,28 +70,28 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief delete a group - * @param $gid gid of the group to delete - * @returns true/false + * @param string $gid gid of the group to delete + * @return bool * * Deletes a group and removes it from the group_user-table */ public function deleteGroup( $gid ) { // Delete the group $stmt = OC_DB::prepare( "DELETE FROM `*PREFIX*groups` WHERE `gid` = ?" ); - $result = $stmt->execute( array( $gid )); + $stmt->execute( array( $gid )); // Delete the group-user relation $stmt = OC_DB::prepare( "DELETE FROM `*PREFIX*group_user` WHERE `gid` = ?" ); - $result = $stmt->execute( array( $gid )); + $stmt->execute( array( $gid )); return true; } /** * @brief is user in group? - * @param $uid uid of the user - * @param $gid gid of the group - * @returns true/false + * @param string $uid uid of the user + * @param string $gid gid of the group + * @return bool * * Checks whether the user is member of a group or not. */ @@ -105,9 +105,9 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief Add a user to a group - * @param $uid Name of the user to add to group - * @param $gid Name of the group in which add the user - * @returns true/false + * @param string $uid Name of the user to add to group + * @param string $gid Name of the group in which add the user + * @return bool * * Adds a user to a group. */ @@ -124,9 +124,9 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief Removes a user from a group - * @param $uid Name of the user to remove from group - * @param $gid Name of the group from which remove the user - * @returns true/false + * @param string $uid Name of the user to remove from group + * @param string $gid Name of the group from which remove the user + * @return bool * * removes the user from a group. */ @@ -139,8 +139,8 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief Get all groups a user belongs to - * @param $uid Name of the user - * @returns array with group names + * @param string $uid Name of the user + * @return array with group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. @@ -160,7 +160,10 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief get a list of all groups - * @returns array with group names + * @param string $search + * @param int $limit + * @param int $offset + * @return array with group names * * Returns a list with all groups */ @@ -190,7 +193,11 @@ class OC_Group_Database extends OC_Group_Backend { /** * @brief get a list of all users in a group - * @returns array with user ids + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with user ids */ public function usersInGroup($gid, $search = '', $limit = null, $offset = null) { $stmt = OC_DB::prepare('SELECT `uid` FROM `*PREFIX*group_user` WHERE `gid` = ? AND `uid` LIKE ?', $limit, $offset); diff --git a/lib/group/interface.php b/lib/group/interface.php index 12cc07a5374..4ef3663837f 100644 --- a/lib/group/interface.php +++ b/lib/group/interface.php @@ -24,8 +24,8 @@ interface OC_Group_Interface { /** * @brief Check if backend implements actions - * @param $actions bitwise-or'ed actions - * @returns boolean + * @param int $actions bitwise-or'ed actions + * @return boolean * * Returns the supported actions as int to be * compared with OC_GROUP_BACKEND_CREATE_GROUP etc. @@ -34,9 +34,9 @@ interface OC_Group_Interface { /** * @brief is user in group? - * @param $uid uid of the user - * @param $gid gid of the group - * @returns true/false + * @param string $uid uid of the user + * @param string $gid gid of the group + * @return bool * * Checks whether the user is member of a group or not. */ @@ -44,8 +44,8 @@ interface OC_Group_Interface { /** * @brief Get all groups a user belongs to - * @param $uid Name of the user - * @returns array with group names + * @param string $uid Name of the user + * @return array with group names * * This function fetches all groups a user belongs to. It does not check * if the user exists at all. @@ -54,7 +54,10 @@ interface OC_Group_Interface { /** * @brief get a list of all groups - * @returns array with group names + * @param string $search + * @param int $limit + * @param int $offset + * @return array with group names * * Returns a list with all groups */ @@ -69,8 +72,12 @@ interface OC_Group_Interface { /** * @brief get a list of all users in a group - * @returns array with user ids + * @param string $gid + * @param string $search + * @param int $limit + * @param int $offset + * @return array with user ids */ public function usersInGroup($gid, $search = '', $limit = -1, $offset = 0); -}
\ No newline at end of file +} diff --git a/lib/helper.php b/lib/helper.php index 70b2f78862b..908a61b5a2d 100644 --- a/lib/helper.php +++ b/lib/helper.php @@ -30,10 +30,11 @@ class OC_Helper { /** * @brief Creates an url - * @param $app app - * @param $file file - * @param $args array with param=>value, will be appended to the returned url - * @returns the url + * @param string $app app + * @param string $file file + * @param array $args array with param=>value, will be appended to the returned url + * The value of $args will be urlencoded + * @return string the url * * Returns a url to the given app and file. */ @@ -62,8 +63,11 @@ class OC_Helper { } } - foreach($args as $k => $v) { - $urlLinkTo .= '&'.$k.'='.$v; + if (!empty($args)) { + $urlLinkTo .= '?'; + foreach($args as $k => $v) { + $urlLinkTo .= '&'.$k.'='.urlencode($v); + } } return $urlLinkTo; @@ -71,10 +75,11 @@ class OC_Helper { /** * @brief Creates an absolute url - * @param $app app - * @param $file file - * @param $args array with param=>value, will be appended to the returned url - * @returns the url + * @param string $app app + * @param string $file file + * @param array $args array with param=>value, will be appended to the returned url + * The value of $args will be urlencoded + * @return string the url * * Returns a absolute url to the given app and file. */ @@ -85,8 +90,8 @@ class OC_Helper { /** * @brief Makes an $url absolute - * @param $url the url - * @returns the absolute url + * @param string $url the url + * @return string the absolute url * * Returns a absolute url to the given app and file. */ @@ -97,8 +102,8 @@ class OC_Helper { /** * @brief Creates an absolute url for remote use - * @param $service id - * @returns the url + * @param string $service id + * @return string the url * * Returns a absolute url to the given service. */ @@ -108,8 +113,8 @@ class OC_Helper { /** * @brief Creates an absolute url for public use - * @param $service id - * @returns the url + * @param string $service id + * @return string the url * * Returns a absolute url to the given service. */ @@ -119,9 +124,9 @@ class OC_Helper { /** * @brief Creates path to an image - * @param $app app - * @param $image image name - * @returns the url + * @param string $app app + * @param string $image image name + * @return string the url * * Returns the path to the image. */ @@ -150,8 +155,8 @@ class OC_Helper { /** * @brief get path to icon of file type - * @param $mimetype mimetype - * @returns the url + * @param string $mimetype mimetype + * @return string the url * * Returns the path to the image of this file type. */ @@ -184,8 +189,8 @@ class OC_Helper { /** * @brief Make a human file size - * @param $bytes file size in bytes - * @returns a human readable file size + * @param int $bytes file size in bytes + * @return string a human readable file size * * Makes 2048 to 2 kB. */ @@ -209,15 +214,14 @@ class OC_Helper { /** * @brief Make a computer file size - * @param $str file size in a fancy format - * @returns a file size in bytes + * @param string $str file size in a fancy format + * @return int a file size in bytes * * Makes 2kB to 2048. * * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 */ public static function computerFileSize( $str ) { - $bytes = 0; $str=strtolower($str); $bytes_array = array( @@ -246,10 +250,10 @@ class OC_Helper { } /** - * @brief Recusive editing of file permissions - * @param $path path to file or folder - * @param $filemode unix style file permissions as integer - * + * @brief Recursive editing of file permissions + * @param string $path path to file or folder + * @param int $filemode unix style file permissions + * @return bool */ static function chmodr($path, $filemode) { if (!is_dir($path)) @@ -274,7 +278,7 @@ class OC_Helper { } /** - * @brief Recusive copying of folders + * @brief Recursive copying of folders * @param string $src source folder * @param string $dest target folder * @@ -296,9 +300,9 @@ class OC_Helper { } /** - * @brief Recusive deletion of folders + * @brief Recursive deletion of folders * @param string $dir path to the folder - * + * @return bool */ static function rmdirr($dir) { if(is_dir($dir)) { @@ -314,12 +318,14 @@ class OC_Helper { } if(file_exists($dir)) { return false; + }else{ + return true; } } /** * get the mimetype form a local file - * @param string path + * @param string $path * @return string * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead */ @@ -364,6 +370,7 @@ class OC_Helper { //trim the character set from the end of the response $mimeType=substr($reply,0,strrpos($reply,' ')); + $mimeType=substr($mimeType,0,strrpos($mimeType,"\n")); //trim ; if (strpos($mimeType, ';') !== false) { @@ -376,7 +383,7 @@ class OC_Helper { /** * get the mimetype form a data string - * @param string data + * @param string $data * @return string */ static function getStringMimeType($data) { @@ -396,9 +403,9 @@ class OC_Helper { /** * @brief Checks $_REQUEST contains a var for the $s key. If so, returns the html-escaped value of this var; otherwise returns the default value provided by $d. - * @param $s name of the var to escape, if set. - * @param $d default value. - * @returns the print-safe value. + * @param string $s name of the var to escape, if set. + * @param string $d default value. + * @return string the print-safe value. * */ @@ -412,7 +419,7 @@ class OC_Helper { } /** - * returns "checked"-attribut if request contains selected radio element OR if radio element is the default one -- maybe? + * returns "checked"-attribute if request contains selected radio element OR if radio element is the default one -- maybe? * @param string $s Name of radio-button element name * @param string $v Value of current radio-button element * @param string $d Value of default radio-button element @@ -425,8 +432,8 @@ class OC_Helper { /** * detect if a given program is found in the search PATH * - * @param string program name - * @param string optional search path, defaults to $PATH + * @param string $program name + * @param string $optional search path, defaults to $PATH * @return bool true if executable program found in path */ public static function canExecute($name, $path = false) { @@ -448,18 +455,16 @@ class OC_Helper { $dirs = explode(PATH_SEPARATOR, $path); // WARNING : We have to check if open_basedir is enabled : $obd = ini_get('open_basedir'); - if($obd != "none") + if($obd != "none"){ $obd_values = explode(PATH_SEPARATOR, $obd); - if(count($obd_values) > 0 and $obd_values[0]) - { - // open_basedir is in effect ! - // We need to check if the program is in one of these dirs : - $dirs = $obd_values; - } - foreach($dirs as $dir) - { - foreach($exts as $ext) - { + if(count($obd_values) > 0 and $obd_values[0]){ + // open_basedir is in effect ! + // We need to check if the program is in one of these dirs : + $dirs = $obd_values; + } + } + foreach($dirs as $dir){ + foreach($exts as $ext){ if($check_fn("$dir/$name".$ext)) return true; } @@ -469,8 +474,8 @@ class OC_Helper { /** * copy the contents of one stream to another - * @param resource source - * @param resource target + * @param resource $source + * @param resource $target * @return int the number of bytes copied */ public static function streamCopy($source,$target) { @@ -486,7 +491,7 @@ class OC_Helper { /** * create a temporary file with an unique filename - * @param string postfix + * @param string $postfix * @return string * * temporary files are automatically cleaned up after the script is finished @@ -550,10 +555,10 @@ class OC_Helper { $ext = substr($filename, $pos); } else { $name = $filename; + $ext = ''; } $newpath = $path . '/' . $filename; - $newname = $filename; $counter = 2; while (OC_Filesystem::file_exists($newpath)) { $newname = $name . ' (' . $counter . ')' . $ext; @@ -567,8 +572,8 @@ class OC_Helper { /* * checks if $sub is a subdirectory of $parent * - * @param $sub - * @param $parent + * @param string $sub + * @param string $parent * @return bool */ public static function issubdirectory($sub, $parent) { @@ -601,9 +606,9 @@ class OC_Helper { /** * @brief Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. * - * @param $input The array to work on - * @param $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) - * @param $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @param array $input The array to work on + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 * @return array * * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. @@ -622,11 +627,11 @@ class OC_Helper { /** * @brief replaces a copy of string delimited by the start and (optionally) length parameters with the string given in replacement. * - * @param $input The input string. .Opposite to the PHP build-in function does not accept an array. - * @param $replacement The replacement string. - * @param $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. - * @param $length Length of the part to be replaced - * @param $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @param string $input The input string. .Opposite to the PHP build-in function does not accept an array. + * @param string $replacement The replacement string. + * @param int $start If start is positive, the replacing will begin at the start'th offset into string. If start is negative, the replacing will begin at the start'th character from the end of string. + * @param int $length Length of the part to be replaced + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 * @return string * */ @@ -643,18 +648,18 @@ class OC_Helper { /** * @brief Replace all occurrences of the search string with the replacement string * - * @param $search The value being searched for, otherwise known as the needle. String. - * @param $replace The replacement string. - * @param $subject The string or array being searched and replaced on, otherwise known as the haystack. - * @param $encoding The encoding parameter is the character encoding. Defaults to UTF-8 - * @param $count If passed, this will be set to the number of replacements performed. + * @param string $search The value being searched for, otherwise known as the needle. + * @param string $replace The replacement + * @param string $subject The string or array being searched and replaced on, otherwise known as the haystack. + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 + * @param int $count If passed, this will be set to the number of replacements performed. * @return string * */ public static function mb_str_replace($search, $replace, $subject, $encoding = 'UTF-8', &$count = null) { $offset = -1; $length = mb_strlen($search, $encoding); - while(($i = mb_strrpos($subject, $search, $offset, $encoding))) { + while(($i = mb_strrpos($subject, $search, $offset, $encoding)) !== false ) { $subject = OC_Helper::mb_substr_replace($subject, $replace, $i, $length); $offset = $i - mb_strlen($subject, $encoding) - 1; $count++; @@ -664,10 +669,10 @@ class OC_Helper { /** * @brief performs a search in a nested array - * @param haystack the array to be searched - * @param needle the search string - * @param $index optional, only search this key name - * @return the key of the matching field, otherwise false + * @param array $haystack the array to be searched + * @param string $needle the search string + * @param string $index optional, only search this key name + * @return mixed the key of the matching field, otherwise false * * performs a search in a nested array * diff --git a/lib/hook.php b/lib/hook.php index 1bf80f604f6..26a53693748 100644 --- a/lib/hook.php +++ b/lib/hook.php @@ -9,11 +9,11 @@ class OC_Hook{ /** * @brief connects a function to a hook - * @param $signalclass class name of emitter - * @param $signalname name of signal - * @param $slotclass class name of slot - * @param $slotname name of slot - * @returns true/false + * @param string $signalclass class name of emitter + * @param string $signalname name of signal + * @param string $slotclass class name of slot + * @param string $slotname name of slot + * @return bool * * This function makes it very easy to connect to use hooks. * @@ -38,11 +38,11 @@ class OC_Hook{ } /** - * @brief emitts a signal - * @param $signalclass class name of emitter - * @param $signalname name of signal - * @param $params defautl: array() array with additional data - * @returns true if slots exists or false if not + * @brief emits a signal + * @param string $signalclass class name of emitter + * @param string $signalname name of signal + * @param array $params defautl: array() array with additional data + * @return bool, true if slots exists or false if not * * Emits a signal. To get data from the slot use references! * @@ -68,8 +68,8 @@ class OC_Hook{ /** * clear hooks - * @param string signalclass - * @param string signalname + * @param string $signalclass + * @param string $signalname */ static public function clear($signalclass='', $signalname='') { if($signalclass) { diff --git a/lib/l10n.php b/lib/l10n.php index 90877cbd747..4eb4c323d88 100644 --- a/lib/l10n.php +++ b/lib/l10n.php @@ -140,7 +140,7 @@ class OC_L10N{ /** * @brief Translating * @param $text String The text we need a translation for - * @param array|\default $parameters default:array() Parameters for sprintf + * @param array $parameters default:array() Parameters for sprintf * @return \OC_L10N_String Translation or the same text * * Returns the translation. If no translation is found, $text will be diff --git a/lib/l10n/da.php b/lib/l10n/da.php index 5c68174fa07..09124c18290 100644 --- a/lib/l10n/da.php +++ b/lib/l10n/da.php @@ -23,5 +23,6 @@ "last year" => "Sidste år", "years ago" => "år siden", "%s is available. Get <a href=\"%s\">more information</a>" => "%s er tilgængelig. Få <a href=\"%s\">mere information</a>", -"up to date" => "opdateret" +"up to date" => "opdateret", +"updates check is disabled" => "Check for opdateringer er deaktiveret" ); diff --git a/lib/l10n/de.php b/lib/l10n/de.php index 4a567003de2..8c81be16582 100644 --- a/lib/l10n/de.php +++ b/lib/l10n/de.php @@ -11,13 +11,13 @@ "Selected files too large to generate zip file." => "Die gewählten Dateien sind zu groß, um eine ZIP-Datei zu erstellen.", "Application is not enabled" => "Die Anwendung ist nicht aktiviert", "Authentication error" => "Authentifizierungs-Fehler", -"Token expired. Please reload page." => "Token abgelaufen. Bitte laden Sie die Seite neu.", +"Token expired. Please reload page." => "Token abgelaufen. Bitte lade die Seite neu.", "seconds ago" => "Vor wenigen Sekunden", "1 minute ago" => "Vor einer Minute", "%d minutes ago" => "Vor %d Minuten", "today" => "Heute", "yesterday" => "Gestern", -"%d days ago" => "Vor %d Tagen", +"%d days ago" => "Vor %d Tag(en)", "last month" => "Letzten Monat", "months ago" => "Vor Monaten", "last year" => "Letztes Jahr", diff --git a/lib/l10n/el.php b/lib/l10n/el.php index d9f272258e1..e4e12490711 100644 --- a/lib/l10n/el.php +++ b/lib/l10n/el.php @@ -11,7 +11,7 @@ "Selected files too large to generate zip file." => "Τα επιλεγμένα αρχεία είναι μεγάλα ώστε να δημιουργηθεί αρχείο zip.", "Application is not enabled" => "Δεν ενεργοποιήθηκε η εφαρμογή", "Authentication error" => "Σφάλμα πιστοποίησης", -"Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ επανα-φορτώστε την σελίδα.", +"Token expired. Please reload page." => "Το αναγνωριστικό έληξε. Παρακαλώ φορτώστε ξανά την σελίδα.", "seconds ago" => "δευτερόλεπτα πριν", "1 minute ago" => "1 λεπτό πριν", "%d minutes ago" => "%d λεπτά πριν", @@ -21,5 +21,8 @@ "last month" => "τον προηγούμενο μήνα", "months ago" => "μήνες πριν", "last year" => "τον προηγούμενο χρόνο", -"years ago" => "χρόνια πριν" +"years ago" => "χρόνια πριν", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s είναι διαθέσιμα. Δείτε <a href=\"%s\">περισσότερες πληροφορίες</a>", +"up to date" => "ενημερωμένο", +"updates check is disabled" => "ο έλεγχος ενημερώσεων είναι απενεργοποιημένος" ); diff --git a/lib/l10n/es_AR.php b/lib/l10n/es_AR.php new file mode 100644 index 00000000000..fd50027d8a1 --- /dev/null +++ b/lib/l10n/es_AR.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Ayuda", +"Personal" => "Personal", +"Settings" => "Ajustes", +"Users" => "Usuarios", +"Apps" => "Aplicaciones", +"Admin" => "Administración", +"ZIP download is turned off." => "La descarga en ZIP está desactivada.", +"Files need to be downloaded one by one." => "Los archivos deben ser descargados de a uno.", +"Back to Files" => "Volver a archivos", +"Selected files too large to generate zip file." => "Los archivos seleccionados son demasiado grandes para generar el archivo zip.", +"Application is not enabled" => "La aplicación no está habilitada", +"Authentication error" => "Error de autenticación", +"Token expired. Please reload page." => "Token expirado. Por favor, recargá la página.", +"seconds ago" => "hace unos segundos", +"1 minute ago" => "hace 1 minuto", +"%d minutes ago" => "hace %d minutos", +"today" => "hoy", +"yesterday" => "ayer", +"%d days ago" => "hace %d días", +"last month" => "este mes", +"months ago" => "hace meses", +"last year" => "este año", +"years ago" => "hace años", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s está disponible. Conseguí <a href=\"%s\">más información</a>", +"up to date" => "actualizado", +"updates check is disabled" => "comprobar actualizaciones está desactivado" +); diff --git a/lib/l10n/gl.php b/lib/l10n/gl.php new file mode 100644 index 00000000000..7a9de627c2d --- /dev/null +++ b/lib/l10n/gl.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Axuda", +"Personal" => "Personal", +"Settings" => "Preferencias", +"Users" => "Usuarios", +"Apps" => "Apps", +"Admin" => "Administración", +"ZIP download is turned off." => "Descargas ZIP está deshabilitadas", +"Files need to be downloaded one by one." => "Os ficheiros necesitan ser descargados de un en un", +"Back to Files" => "Voltar a ficheiros", +"Selected files too large to generate zip file." => "Os ficheiros seleccionados son demasiado grandes para xerar un ficheiro ZIP", +"Application is not enabled" => "O aplicativo non está habilitado", +"Authentication error" => "Erro na autenticación", +"Token expired. Please reload page." => "Testemuño caducado. Por favor recargue a páxina.", +"seconds ago" => "hai segundos", +"1 minute ago" => "hai 1 minuto", +"%d minutes ago" => "hai %d minutos", +"today" => "hoxe", +"yesterday" => "onte", +"%d days ago" => "hai %d días", +"last month" => "último mes", +"months ago" => "meses atrás", +"last year" => "último ano", +"years ago" => "anos atrás", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s está dispoñible. Obteña <a href=\"%s\">máis información</a>", +"up to date" => "ao día", +"updates check is disabled" => "comprobación de actualizacións está deshabilitada" +); diff --git a/lib/l10n/oc.php b/lib/l10n/oc.php new file mode 100644 index 00000000000..ffc0588becc --- /dev/null +++ b/lib/l10n/oc.php @@ -0,0 +1,24 @@ +<?php $TRANSLATIONS = array( +"Help" => "Ajuda", +"Personal" => "Personal", +"Settings" => "Configuracion", +"Users" => "Usancièrs", +"Apps" => "Apps", +"Admin" => "Admin", +"ZIP download is turned off." => "Avalcargar los ZIP es inactiu.", +"Files need to be downloaded one by one." => "Los fichièrs devan èsser avalcargats un per un.", +"Back to Files" => "Torna cap als fichièrs", +"Authentication error" => "Error d'autentificacion", +"seconds ago" => "segonda a", +"1 minute ago" => "1 minuta a", +"%d minutes ago" => "%d minutas a", +"today" => "uèi", +"yesterday" => "ièr", +"%d days ago" => "%d jorns a", +"last month" => "mes passat", +"months ago" => "meses a", +"last year" => "an passat", +"years ago" => "ans a", +"up to date" => "a jorn", +"updates check is disabled" => "la verificacion de mesa a jorn es inactiva" +); diff --git a/lib/l10n/pt_BR.php b/lib/l10n/pt_BR.php new file mode 100644 index 00000000000..1455eabbc94 --- /dev/null +++ b/lib/l10n/pt_BR.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Ajuda", +"Personal" => "Pessoal", +"Settings" => "Ajustes", +"Users" => "Usuários", +"Apps" => "Aplicações", +"Admin" => "Admin", +"ZIP download is turned off." => "Download ZIP está desligado.", +"Files need to be downloaded one by one." => "Arquivos precisam ser baixados um de cada vez.", +"Back to Files" => "Voltar para Arquivos", +"Selected files too large to generate zip file." => "Arquivos selecionados são muito grandes para gerar arquivo zip.", +"Application is not enabled" => "Aplicação não está habilitada", +"Authentication error" => "Erro de autenticação", +"Token expired. Please reload page." => "Token expirou. Por favor recarregue a página.", +"seconds ago" => "segundos atrás", +"1 minute ago" => "1 minuto atrás", +"%d minutes ago" => "%d minutos atrás", +"today" => "hoje", +"yesterday" => "ontem", +"%d days ago" => "%d dias atrás", +"last month" => "último mês", +"months ago" => "meses atrás", +"last year" => "último ano", +"years ago" => "anos atrás", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s está disponível. Obtenha <a href=\"%s\">mais informações</a>", +"up to date" => "atualizado", +"updates check is disabled" => "checagens de atualização estão desativadas" +); diff --git a/lib/l10n/ro.php b/lib/l10n/ro.php new file mode 100644 index 00000000000..5fffeec2335 --- /dev/null +++ b/lib/l10n/ro.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "Ajutor", +"Personal" => "Personal", +"Settings" => "Setări", +"Users" => "Utilizatori", +"Apps" => "Aplicații", +"Admin" => "Admin", +"ZIP download is turned off." => "Descărcarea ZIP este dezactivată.", +"Files need to be downloaded one by one." => "Fișierele trebuie descărcate unul câte unul.", +"Back to Files" => "Înapoi la fișiere", +"Selected files too large to generate zip file." => "Fișierele selectate sunt prea mari pentru a genera un fișier zip.", +"Application is not enabled" => "Aplicația nu este activată", +"Authentication error" => "Eroare la autentificare", +"Token expired. Please reload page." => "Token expirat. Te rugăm să reîncarci pagina.", +"seconds ago" => "secunde în urmă", +"1 minute ago" => "1 minut în urmă", +"%d minutes ago" => "%d minute în urmă", +"today" => "astăzi", +"yesterday" => "ieri", +"%d days ago" => "%d zile în urmă", +"last month" => "ultima lună", +"months ago" => "luni în urmă", +"last year" => "ultimul an", +"years ago" => "ani în urmă", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s este disponibil. Vezi <a href=\"%s\">mai multe informații</a>", +"up to date" => "la zi", +"updates check is disabled" => "verificarea după actualizări este dezactivată" +); diff --git a/lib/l10n/ru_RU.php b/lib/l10n/ru_RU.php new file mode 100644 index 00000000000..1e691993014 --- /dev/null +++ b/lib/l10n/ru_RU.php @@ -0,0 +1,27 @@ +<?php $TRANSLATIONS = array( +"Help" => "Помощь", +"Personal" => "Персональный", +"Settings" => "Настройки", +"Users" => "Пользователи", +"Apps" => "Приложения", +"Admin" => "Админ", +"Files need to be downloaded one by one." => "Файлы должны быть загружены один за другим.", +"Back to Files" => "Обратно к файлам", +"Selected files too large to generate zip file." => "Выбранные файлы слишком велики для генерации zip-архива.", +"Application is not enabled" => "Приложение не запущено", +"Authentication error" => "Ошибка аутентификации", +"Token expired. Please reload page." => "Маркер истек. Пожалуйста, перезагрузите страницу.", +"seconds ago" => "секунд назад", +"1 minute ago" => "1 минуту назад", +"%d minutes ago" => "%d минут назад", +"today" => "сегодня", +"yesterday" => "вчера", +"%d days ago" => "%d дней назад", +"last month" => "в прошлом месяце", +"months ago" => "месяц назад", +"last year" => "в прошлом году", +"years ago" => "год назад", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s доступно. Получите <a href=\"%s\">more information</a>", +"up to date" => "до настоящего времени", +"updates check is disabled" => "Проверка обновлений отключена" +); diff --git a/lib/l10n/sk_SK.php b/lib/l10n/sk_SK.php new file mode 100644 index 00000000000..33b329c30bb --- /dev/null +++ b/lib/l10n/sk_SK.php @@ -0,0 +1,25 @@ +<?php $TRANSLATIONS = array( +"Help" => "Pomoc", +"Personal" => "Osobné", +"Settings" => "Nastavenia", +"Users" => "Užívatelia", +"Apps" => "Aplikácie", +"Admin" => "Správca", +"ZIP download is turned off." => "Sťahovanie súborov ZIP je vypnuté.", +"Files need to be downloaded one by one." => "Súbory musia byť nahrávané jeden za druhým.", +"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.", +"Application is not enabled" => "Aplikácia nie je zapnutá", +"Authentication error" => "Chyba autentifikácie", +"1 minute ago" => "pred 1 minútou", +"%d minutes ago" => "pred %d minútami", +"today" => "dnes", +"yesterday" => "včera", +"%d days ago" => "pred %d dňami", +"last month" => "minulý mesiac", +"months ago" => "pred mesiacmi", +"last year" => "minulý rok", +"years ago" => "pred rokmi", +"up to date" => "aktuálny", +"updates check is disabled" => "sledovanie aktualizácií je vypnuté" +); diff --git a/lib/l10n/zh_CN.GB2312.php b/lib/l10n/zh_CN.GB2312.php new file mode 100644 index 00000000000..4b0a5e9f4d2 --- /dev/null +++ b/lib/l10n/zh_CN.GB2312.php @@ -0,0 +1,28 @@ +<?php $TRANSLATIONS = array( +"Help" => "帮助", +"Personal" => "私人", +"Settings" => "设置", +"Users" => "用户", +"Apps" => "程序", +"Admin" => "管理员", +"ZIP download is turned off." => "ZIP 下载已关闭", +"Files need to be downloaded one by one." => "需要逐个下载文件。", +"Back to Files" => "返回到文件", +"Selected files too large to generate zip file." => "选择的文件太大而不能生成 zip 文件。", +"Application is not enabled" => "应用未启用", +"Authentication error" => "验证错误", +"Token expired. Please reload page." => "会话过期。请刷新页面。", +"seconds ago" => "秒前", +"1 minute ago" => "1 分钟前", +"%d minutes ago" => "%d 分钟前", +"today" => "今天", +"yesterday" => "昨天", +"%d days ago" => "%d 天前", +"last month" => "上个月", +"months ago" => "月前", +"last year" => "去年", +"years ago" => "年前", +"%s is available. Get <a href=\"%s\">more information</a>" => "%s 不可用。获知 <a href=\"%s\">详情</a>", +"up to date" => "最新", +"updates check is disabled" => "更新检测已禁用" +); diff --git a/lib/migrate.php b/lib/migrate.php index 823b3574f16..611a935ee5d 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -84,21 +84,15 @@ class OC_Migrate{ $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( array( 'success' => false ) ) ); + return json_encode( array( 'success' => false ) ); } self::$exporttype = $type; // Userid? if( self::$exporttype == 'user' ) { // Check user exists - if( !is_null($uid) ) { - $db = new OC_User_Database; - if( !$db->userExists( $uid ) ) { - OC_Log::write('migration', 'User: '.$uid.' is not in the database and so cannot be exported.', OC_Log::ERROR); - return json_encode( array( 'success' => false ) ); - } - self::$uid = $uid; - } else { - self::$uid = OC_User::getUser(); + self::$uid = is_null($uid) ? OC_User::getUser() : $uid; + if(!OC_User::userExists(self::$uid)){ + return json_encode( array( 'success' => false) ); } } // Calculate zipname diff --git a/lib/migration/content.php b/lib/migration/content.php index 64b8168cd98..89b1e782d86 100644 --- a/lib/migration/content.php +++ b/lib/migration/content.php @@ -30,7 +30,7 @@ class OC_Migration_Content{ // Holds the MDB2 object private $db=null; // Holds an array of tmpfiles to delete after zip creation - private $tmpfiles=false; + private $tmpfiles=array(); /** * @brief sets up the @@ -43,18 +43,21 @@ class OC_Migration_Content{ $this->zip = $zip; $this->db = $db; - if( !is_null( $db ) ) { - // Get db path - $db = $this->db->getDatabase(); - $this->tmpfiles[] = $db; - } - } // @brief prepares the db // @param $query the sql query to prepare public function prepare( $query ) { - + + // Only add database to tmpfiles if actually used + if( !is_null( $this->db ) ) { + // Get db path + $db = $this->db->getDatabase(); + if(!in_array($db, $this->tmpfiles)){ + $this->tmpfiles[] = $db; + } + } + // Optimize the query $query = $this->processQuery( $query ); diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 8596ea0b3c7..6428a883679 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -53,7 +53,7 @@ class OC_OCSClient{ /** * @brief Get all the categories from the OCS server * @returns array with category ids - * + * @note returns NULL if config value appstoreenabled is set to false * This function returns a list of all the application categories on the OCS server */ public static function getCategories() { diff --git a/lib/preferences.php b/lib/preferences.php index 3d61887785c..b198a18415c 100644 --- a/lib/preferences.php +++ b/lib/preferences.php @@ -40,7 +40,7 @@ class OC_Preferences{ /** * @brief Get all users using the preferences - * @returns array with user ids + * @return array with user ids * * This function returns a list of all users that have at least one entry * in the preferences table. @@ -60,8 +60,8 @@ class OC_Preferences{ /** * @brief Get all apps of a user - * @param $user user - * @returns array with app ids + * @param string $user user + * @return array with app ids * * This function returns a list of all apps of the user that have at least * one entry in the preferences table. @@ -81,9 +81,9 @@ class OC_Preferences{ /** * @brief Get the available keys for an app - * @param $user user - * @param $app the app we are looking for - * @returns array with key names + * @param string $user user + * @param string $app the app we are looking for + * @return array with key names * * This function gets all keys of an app of an user. Please note that the * values are not returned. @@ -103,14 +103,14 @@ class OC_Preferences{ /** * @brief Gets the preference - * @param $user user - * @param $app app - * @param $key key - * @param $default = null, default value if the key does not exist - * @returns the value or $default + * @param string $user user + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default * - * This function gets a value from the prefernces table. If the key does - * not exist the default value will be returnes + * This function gets a value from the preferences table. If the key does + * not exist the default value will be returned */ public static function getValue( $user, $app, $key, $default = null ) { // Try to fetch the value, return default if not exists. @@ -127,11 +127,11 @@ class OC_Preferences{ /** * @brief sets a value in the preferences - * @param $user user - * @param $app app - * @param $key key - * @param $value value - * @returns true/false + * @param string $user user + * @param string $app app + * @param string $key key + * @param string $value value + * @return bool * * Adds a value to the preferences. If the key did not exist before, it * will be added automagically. @@ -155,63 +155,63 @@ class OC_Preferences{ /** * @brief Deletes a key - * @param $user user - * @param $app app - * @param $key key - * @returns true/false + * @param string $user user + * @param string $app app + * @param string $key key + * @return bool * * Deletes a key. */ public static function deleteKey( $user, $app, $key ) { // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ? AND `configkey` = ?' ); - $result = $query->execute( array( $user, $app, $key )); + $query->execute( array( $user, $app, $key )); return true; } /** * @brief Remove app of user from preferences - * @param $user user - * @param $app app - * @returns true/false + * @param string $user user + * @param string $app app + * @return bool * * Removes all keys in appconfig belonging to the app and the user. */ public static function deleteApp( $user, $app ) { // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `userid` = ? AND `appid` = ?' ); - $result = $query->execute( array( $user, $app )); + $query->execute( array( $user, $app )); return true; } /** * @brief Remove user from preferences - * @param $user user - * @returns true/false + * @param string $user user + * @return bool * * Removes all keys in appconfig belonging to the user. */ public static function deleteUser( $user ) { // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `userid` = ?' ); - $result = $query->execute( array( $user )); + $query->execute( array( $user )); return true; } /** * @brief Remove app from all users - * @param $app app - * @returns true/false + * @param string $app app + * @return bool * * Removes all keys in preferences belonging to the app. */ public static function deleteAppFromAllUsers( $app ) { // No need for more comments $query = OC_DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `appid` = ?' ); - $result = $query->execute( array( $app )); + $query->execute( array( $app )); return true; } diff --git a/lib/public/config.php b/lib/public/config.php index 377150115ff..1f163d52617 100644 --- a/lib/public/config.php +++ b/lib/public/config.php @@ -40,9 +40,9 @@ namespace OCP; class Config { /** * @brief Gets a value from config.php - * @param $key key - * @param $default = null default value - * @returns the value or $default + * @param string $key key + * @param string $default = null default value + * @return string the value or $default * * This function gets the value from config.php. If it does not exist, * $default will be returned. @@ -53,9 +53,9 @@ class Config { /** * @brief Sets a value - * @param $key key - * @param $value value - * @returns true/false + * @param string $key key + * @param string $value value + * @return bool * * This function sets the value and writes the config.php. If the file can * not be written, false will be returned. @@ -66,13 +66,13 @@ class Config { /** * @brief Gets the config value - * @param $app app - * @param $key key - * @param $default = null, default value if the key does not exist - * @returns the value or $default + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default * * This function gets a value from the appconfig table. If the key does - * not exist the default value will be returnes + * not exist the default value will be returned */ public static function getAppValue( $app, $key, $default = null ) { return(\OC_Appconfig::getValue( $app, $key, $default )); @@ -80,10 +80,10 @@ class Config { /** * @brief sets a value in the appconfig - * @param $app app - * @param $key key - * @param $value value - * @returns true/false + * @param string $app app + * @param string $key key + * @param string $value value + * @return string true/false * * Sets a value. If the key did not exist before it will be created. */ @@ -93,14 +93,14 @@ class Config { /** * @brief Gets the preference - * @param $user user - * @param $app app - * @param $key key - * @param $default = null, default value if the key does not exist - * @returns the value or $default + * @param string $user user + * @param string $app app + * @param string $key key + * @param string $default = null, default value if the key does not exist + * @return string the value or $default * - * This function gets a value from the prefernces table. If the key does - * not exist the default value will be returnes + * This function gets a value from the preferences table. If the key does + * not exist the default value will be returned */ public static function getUserValue( $user, $app, $key, $default = null ) { return(\OC_Preferences::getValue( $user, $app, $key, $default )); @@ -108,16 +108,16 @@ class Config { /** * @brief sets a value in the preferences - * @param $user user - * @param $app app - * @param $key key - * @param $value value - * @returns true/false + * @param string $user user + * @param string $app app + * @param string $key key + * @param string $value value + * @returns bool * * Adds a value to the preferences. If the key did not exist before, it * will be added automagically. */ public static function setUserValue( $user, $app, $key, $value ) { - return(\OC_Preferences::setValue( $user, $app, $key, $value )); + return(\OC_Preferences::setValue( $user, $app, $key, $value )); } } diff --git a/lib/public/share.php b/lib/public/share.php index b215d7f9389..1039d6f0dbf 100644 --- a/lib/public/share.php +++ b/lib/public/share.php @@ -418,11 +418,20 @@ class Share { } public static function setExpirationDate($itemType, $itemSource, $date) { - if ($item = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, 1, false)) { - error_log('setting'); - $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); - $query->execute(array($date, $item['id'])); - return true; + if ($items = self::getItems($itemType, $itemSource, null, null, \OC_User::getUser(), self::FORMAT_NONE, null, -1, false)) { + if (!empty($items)) { + if ($date == '') { + $date = null; + } else { + $date = new \DateTime($date); + $date = date('Y-m-d H:i', $date->format('U') - $date->getOffset()); + } + $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `id` = ?'); + foreach ($items as $item) { + $query->execute(array($date, $item['id'])); + } + return true; + } } return false; } diff --git a/lib/public/util.php b/lib/public/util.php index 747448e62eb..38da7e82171 100644 --- a/lib/public/util.php +++ b/lib/public/util.php @@ -116,6 +116,7 @@ class Util { * @param $app app * @param $file file * @param $args array with param=>value, will be appended to the returned url + * The value of $args will be urlencoded * @returns the url * * Returns a absolute url to the given app and file. @@ -151,6 +152,7 @@ class Util { * @param $app app * @param $file file * @param $args array with param=>value, will be appended to the returned url + * The value of $args will be urlencoded * @returns the url * * Returns a url to the given app and file. diff --git a/lib/search/provider/file.php b/lib/search/provider/file.php index 50e16457672..e21278f3918 100644 --- a/lib/search/provider/file.php +++ b/lib/search/provider/file.php @@ -5,29 +5,35 @@ class OC_Search_Provider_File extends OC_Search_Provider{ $files=OC_FileCache::search($query,true); $results=array(); foreach($files as $fileData) { - $file=$fileData['path']; - $mime=$fileData['mimetype']; + $path = $fileData['path']; + $mime = $fileData['mimetype']; + + $name = basename($path); + $text = ''; if($mime=='httpd/unix-directory') { - $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'index.php', array('dir' => $file)),'Files'); + $link = OC_Helper::linkTo( 'files', 'index.php', array('dir' => $path)); + $type = 'Files'; }else{ - $mimeBase=$fileData['mimepart']; + $link = OC_Helper::linkTo( 'files', 'download.php', array('file' => $path)); + $mimeBase = $fileData['mimepart']; switch($mimeBase) { case 'audio': break; case 'text': - $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('dir' => $file) ),'Text'); + $type = 'Text'; break; case 'image': - $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('dir' => $file) ),'Images'); + $type = 'Images'; break; default: if($mime=='application/xml') { - $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('dir' => $file) ),'Text'); + $type = 'Text'; }else{ - $results[]=new OC_Search_Result(basename($file),'',OC_Helper::linkTo( 'files', 'download.php', array('dir' => $file) ),'Files'); + $type = 'Files'; } } } + $results[] = new OC_Search_Result($name, $text, $link, $type); } return $results; } diff --git a/lib/setup.php b/lib/setup.php index c21c8be3957..16b9ec68df6 100644 --- a/lib/setup.php +++ b/lib/setup.php @@ -79,7 +79,7 @@ class OC_Setup { } //generate a random salt that is used to salt the local user passwords - $salt=mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000); + $salt = OC_Util::generate_random_bytes(30); OC_Config::setValue('passwordsalt', $salt); //write the config file diff --git a/lib/subadmin.php b/lib/subadmin.php index 363e4a97cad..9e83e6da430 100644 --- a/lib/subadmin.php +++ b/lib/subadmin.php @@ -172,7 +172,7 @@ class OC_SubAdmin{ } /** - * @brief delete all SubAdmins8 by gid + * @brief delete all SubAdmins by gid * @param $parameters * @return boolean */ diff --git a/lib/template.php b/lib/template.php index 8c872a2059b..681b3f0b140 100644 --- a/lib/template.php +++ b/lib/template.php @@ -23,10 +23,10 @@ /** * @brief make OC_Helper::linkTo available as a simple function - * @param $app app - * @param $file file - * @param $args array with param=>value, will be appended to the returned url - * @returns link to the file + * @param string $app app + * @param string $file file + * @param array $args array with param=>value, will be appended to the returned url + * @return string link to the file * * For further information have a look at OC_Helper::linkTo */ @@ -36,9 +36,9 @@ function link_to( $app, $file, $args = array() ) { /** * @brief make OC_Helper::imagePath available as a simple function - * @param $app app - * @param $image image - * @returns link to the image + * @param string $app app + * @param string $image image + * @return string link to the image * * For further information have a look at OC_Helper::imagePath */ @@ -48,8 +48,8 @@ function image_path( $app, $image ) { /** * @brief make OC_Helper::mimetypeIcon available as a simple function - * @param $mimetype mimetype - * @returns link to the image + * @param string $mimetype mimetype + * @return string link to the image * * For further information have a look at OC_Helper::mimetypeIcon */ @@ -59,8 +59,8 @@ function mimetype_icon( $mimetype ) { /** * @brief make OC_Helper::humanFileSize available as a simple function - * @param $bytes size in bytes - * @returns size as string + * @param int $bytes size in bytes + * @return string size as string * * For further information have a look at OC_Helper::humanFileSize */ @@ -139,10 +139,10 @@ class OC_Template{ /** * @brief Constructor - * @param $app app providing the template - * @param $file name of the template file (without suffix) - * @param $renderas = ""; produce a full page - * @returns OC_Template object + * @param string $app app providing the template + * @param string $file name of the template file (without suffix) + * @param string $renderas = ""; produce a full page + * @return OC_Template object * * This function creates an OC_Template object. * @@ -157,8 +157,10 @@ class OC_Template{ $this->vars = array(); if($renderas == 'user') { $this->vars['requesttoken'] = OC_Util::callRegister(); + $this->vars['requestlifespan'] = OC_Util::$callLifespan; } - $this->l10n = OC_L10N::get($app); + $parts = explode('/', $app); // fix translation when app is something like core/lostpassword + $this->l10n = OC_L10N::get($parts[0]); header('X-Frame-Options: Sameorigin'); header('X-XSS-Protection: 1; mode=block'); header('X-Content-Type-Options: nosniff'); @@ -167,7 +169,7 @@ class OC_Template{ } /** - * autodetects the formfactor of the used device + * autodetect the formfactor of the used device * default -> the normal desktop browser interface * mobile -> interface for smartphones * tablet -> interface for tablets @@ -225,7 +227,7 @@ class OC_Template{ /** * @brief find the template with the given name - * @param $name of the template file (without suffix) + * @param string $name of the template file (without suffix) * * Will select the template file for the selected theme and formfactor. * Checking all the possible locations. @@ -270,13 +272,13 @@ class OC_Template{ /** * @brief check Path For Template with and without $fext - * @param $path to check - * @param $name of the template file (without suffix) - * @param $fext formfactor extension + * @param string $path to check + * @param string $name of the template file (without suffix) + * @param string $fext formfactor extension * @return bool true when found * * Will set $this->template and $this->path if there is a template at - * the specifief $path + * the specific $path */ protected function checkPathForTemplate($path, $name, $fext) { @@ -297,10 +299,10 @@ class OC_Template{ /** * @brief Assign variables - * @param $key key - * @param $value value - * @param $sanitizeHTML false, if data shouldn't get passed through htmlentities - * @returns true + * @param string $key key + * @param string $value value + * @param bool $sanitizeHTML false, if data shouldn't get passed through htmlentities + * @return bool * * This function assigns a variable. It can be accessed via $_[$key] in * the template. @@ -315,9 +317,9 @@ class OC_Template{ /** * @brief Appends a variable - * @param $key key - * @param $value value - * @returns true + * @param string $key key + * @param string $value value + * @return bool * * This function assigns a variable in an array context. If the key already * exists, the value will be appended. It can be accessed via @@ -334,7 +336,7 @@ class OC_Template{ /** * @brief Add a custom element to the header - * @param string tag tag name of the element + * @param string $tag tag name of the element * @param array $attributes array of attrobutes for the element * @param string $text the text content for the element */ @@ -344,7 +346,7 @@ class OC_Template{ /** * @brief Prints the proceeded template - * @returns true/false + * @return bool * * This function proceeds the template and prints its output. */ @@ -361,7 +363,7 @@ class OC_Template{ /** * @brief Proceeds the template - * @returns content + * @return bool * * This function proceeds the template. If $this->renderas is set, it * will produce a full page. @@ -373,6 +375,7 @@ class OC_Template{ $page = new OC_TemplateLayout($this->renderas); if($this->renderas == 'user') { $page->assign('requesttoken', $this->vars['requesttoken']); + $page->assign('requestlifespan', $this->vars['requestlifespan']); } // Add custom headers @@ -391,7 +394,7 @@ class OC_Template{ /** * @brief doing the actual work - * @returns content + * @return string content * * Includes the template file, fetches its output */ @@ -412,13 +415,12 @@ class OC_Template{ /** * @brief Include template - * @returns returns content of included template + * @return string returns content of included template * * Includes another template. use <?php echo $this->inc('template'); ?> to * do this. */ public function inc( $file, $additionalparams = null ) { - // $_ erstellen $_ = $this->vars; $l = $this->l10n; @@ -438,10 +440,10 @@ class OC_Template{ /** * @brief Shortcut to print a simple page for users - * @param $application The application we render the template for - * @param $name Name of the template - * @param $parameters Parameters for the template - * @returns true/false + * @param string $application The application we render the template for + * @param string $name Name of the template + * @param array $parameters Parameters for the template + * @return bool */ public static function printUserPage( $application, $name, $parameters = array() ) { $content = new OC_Template( $application, $name, "user" ); @@ -453,10 +455,10 @@ class OC_Template{ /** * @brief Shortcut to print a simple page for admins - * @param $application The application we render the template for - * @param $name Name of the template - * @param $parameters Parameters for the template - * @returns true/false + * @param string $application The application we render the template for + * @param string $name Name of the template + * @param array $parameters Parameters for the template + * @return bool */ public static function printAdminPage( $application, $name, $parameters = array() ) { $content = new OC_Template( $application, $name, "admin" ); @@ -468,10 +470,10 @@ class OC_Template{ /** * @brief Shortcut to print a simple page for guests - * @param $application The application we render the template for - * @param $name Name of the template - * @param $parameters Parameters for the template - * @returns true/false + * @param string $application The application we render the template for + * @param string $name Name of the template + * @param string $parameters Parameters for the template + * @return bool */ public static function printGuestPage( $application, $name, $parameters = array() ) { $content = new OC_Template( $application, $name, "guest" ); diff --git a/lib/util.php b/lib/util.php index 5e39fd1f914..310ca6afec9 100755 --- a/lib/util.php +++ b/lib/util.php @@ -81,7 +81,7 @@ class OC_Util { */ public static function getVersion() { // hint: We only can count up. So the internal version number of ownCloud 4.5 will be 4,9,0. This is not visible to the user - return array(4,84,7); + return array(4,85,11); } /** @@ -89,7 +89,7 @@ class OC_Util { * @return string */ public static function getVersionString() { - return '4.5 beta 3a'; + return '4.5 RC 1'; } /** @@ -314,9 +314,6 @@ class OC_Util { $parameters["username"] = ''; $parameters['user_autofocus'] = true; } - $sectoken=rand(1000000,9999999); - $_SESSION['sectoken']=$sectoken; - $parameters["sectoken"] = $sectoken; if (isset($_REQUEST['redirect_url'])) { $redirect_url = OC_Util::sanitizeHTML($_REQUEST['redirect_url']); } else { @@ -344,7 +341,7 @@ class OC_Util { public static function checkLoggedIn() { // Check if we are a user if( !OC_User::isLoggedIn()) { - header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php', array('redirect_url' => urlencode($_SERVER["REQUEST_URI"])))); + header( 'Location: '.OC_Helper::linkToAbsolute( '', 'index.php', array('redirect_url' => $_SERVER["REQUEST_URI"]))); exit(); } } @@ -416,16 +413,31 @@ class OC_Util { } /** - * @brief Register an get/post call. This is important to prevent CSRF attacks - * Todo: Write howto + * @brief Static lifespan (in seconds) when a request token expires. + * @see OC_Util::callRegister() + * @see OC_Util::isCallRegistered() + * @description + * Also required for the client side to compute the piont in time when to + * request a fresh token. The client will do so when nearly 97% of the + * timespan coded here has expired. + */ + public static $callLifespan = 3600; // 3600 secs = 1 hour + + /** + * @brief Register an get/post call. Important to prevent CSRF attacks. + * @todo Write howto: CSRF protection guide * @return $token Generated token. + * @description + * Creates a 'request token' (random) and stores it inside the session. + * Ever subsequent (ajax) request must use such a valid token to succeed, + * otherwise the request will be denied as a protection against CSRF. + * The tokens expire after a fixed lifespan. + * @see OC_Util::$callLifespan + * @see OC_Util::isCallRegistered() */ public static function callRegister() { - //mamimum time before token exires - $maxtime=(60*60); // 1 hour - // generate a random token. - $token=mt_rand(1000,9000).mt_rand(1000,9000).mt_rand(1000,9000); + $token = self::generate_random_bytes(20); // store the token together with a timestamp in the session. $_SESSION['requesttoken-'.$token]=time(); @@ -436,7 +448,8 @@ class OC_Util { foreach($_SESSION as $key=>$value) { // search all tokens in the session if(substr($key,0,12)=='requesttoken') { - if($value+$maxtime<time()) { + // check if static lifespan has expired + if($value+self::$callLifespan<time()) { // remove outdated tokens unset($_SESSION[$key]); } @@ -447,14 +460,13 @@ class OC_Util { return($token); } - /** * @brief Check an ajax get/post call if the request token is valid. * @return boolean False if request token is not set or is invalid. + * @see OC_Util::$callLifespan + * @see OC_Util::calLRegister() */ public static function isCallRegistered() { - //mamimum time before token exires - $maxtime=(60*60); // 1 hour if(isset($_GET['requesttoken'])) { $token=$_GET['requesttoken']; }elseif(isset($_POST['requesttoken'])) { @@ -467,7 +479,8 @@ class OC_Util { } if(isset($_SESSION['requesttoken-'.$token])) { $timestamp=$_SESSION['requesttoken-'.$token]; - if($timestamp+$maxtime<time()) { + // check if static lifespan has expired + if($timestamp+self::$callLifespan<time()) { return false; }else{ //token valid @@ -535,4 +548,30 @@ class OC_Util { } } -} + /* + * @brief Generates random bytes with "openssl_random_pseudo_bytes" with a fallback for systems without openssl + * Inspired by gorgo on php.net + * @param Int with the length of the random + * @return String with the random bytes + */ + public static function generate_random_bytes($length = 30) { + if(function_exists('openssl_random_pseudo_bytes')) { + $pseudo_byte = bin2hex(openssl_random_pseudo_bytes($length, $strong)); + if($strong == TRUE) { + return substr($pseudo_byte, 0, $length); // Truncate it to match the length + } + } + + // fallback to mt_rand() + $characters = '0123456789'; + $characters .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; + $charactersLength = strlen($characters)-1; + $pseudo_byte = ""; + + // Select some random characters + for ($i = 0; $i < $length; $i++) { + $pseudo_byte .= $characters[mt_rand(0, $charactersLength)]; + } + return $pseudo_byte; + } +}
\ No newline at end of file |