// Protect data directory here, so we can test if the protection is working | // Protect data directory here, so we can test if the protection is working | ||||
\OC_Setup::protectDataDirectory(); | \OC_Setup::protectDataDirectory(); | ||||
try { | try { | ||||
$htaccessWorking = \OC_Util::isHtAccessWorking(); | |||||
$htaccessWorking = \OC_Util::isHtaccessWorking(); | |||||
} catch (\OC\HintException $e) { | } catch (\OC\HintException $e) { | ||||
$errors[] = array( | $errors[] = array( | ||||
'error' => $e->getMessage(), | 'error' => $e->getMessage(), |
if (file_exists(self::$configDir . "/config.php") | if (file_exists(self::$configDir . "/config.php") | ||||
and !is_writable(self::$configDir . "/config.php") | and !is_writable(self::$configDir . "/config.php") | ||||
) { | ) { | ||||
$defaults = new OC_Defaults(); | |||||
if (self::$CLI) { | if (self::$CLI) { | ||||
echo "Can't write into config directory!\n"; | echo "Can't write into config directory!\n"; | ||||
echo "This can usually be fixed by giving the webserver write access to the config directory\n"; | echo "This can usually be fixed by giving the webserver write access to the config directory\n"; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Checks if the version requires an update and shows | |||||
* @param bool $showTemplate Whether an update screen should get shown | |||||
* @return bool|void | |||||
*/ | |||||
public static function checkUpgrade($showTemplate = true) { | public static function checkUpgrade($showTemplate = true) { | ||||
if (self::needUpgrade()) { | if (self::needUpgrade()) { | ||||
if ($showTemplate && !OC_Config::getValue('maintenance', false)) { | if ($showTemplate && !OC_Config::getValue('maintenance', false)) { | ||||
self::handleLogin(); | self::handleLogin(); | ||||
} | } | ||||
/** | |||||
* Load a PHP file belonging to the specified application | |||||
* @param array $param The application and file to load | |||||
* @return bool Whether the file has been found (will return 404 and false if not) | |||||
*/ | |||||
public static function loadAppScriptFile($param) { | public static function loadAppScriptFile($param) { | ||||
OC_App::loadApps(); | OC_App::loadApps(); | ||||
$app = $param['app']; | $app = $param['app']; | ||||
OC_Util::displayLoginPage(array_unique($error)); | OC_Util::displayLoginPage(array_unique($error)); | ||||
} | } | ||||
/** | |||||
* Remove outdated and therefore invalid tokens for a user | |||||
* @param string $user | |||||
*/ | |||||
protected static function cleanupLoginTokens($user) { | protected static function cleanupLoginTokens($user) { | ||||
$cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); | $cutoff = time() - OC_Config::getValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); | ||||
$tokens = OC_Preferences::getKeys($user, 'login_token'); | $tokens = OC_Preferences::getKeys($user, 'login_token'); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Try to login a user via HTTP authentication | |||||
* @return bool|void | |||||
*/ | |||||
protected static function tryApacheAuth() { | protected static function tryApacheAuth() { | ||||
$return = OC_User::handleApacheAuth(); | $return = OC_User::handleApacheAuth(); | ||||
return is_null($return) ? false : true; | return is_null($return) ? false : true; | ||||
} | } | ||||
/** | |||||
* Try to login a user using the remember me cookie. | |||||
* @return bool Whether the provided cookie was valid | |||||
*/ | |||||
protected static function tryRememberLogin() { | protected static function tryRememberLogin() { | ||||
if (!isset($_COOKIE["oc_remember_login"]) | if (!isset($_COOKIE["oc_remember_login"]) | ||||
|| !isset($_COOKIE["oc_token"]) | || !isset($_COOKIE["oc_token"]) | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* Tries to login a user using the formbased authentication | |||||
* @return bool|void | |||||
*/ | |||||
protected static function tryFormLogin() { | protected static function tryFormLogin() { | ||||
if (!isset($_POST["user"]) || !isset($_POST['password'])) { | if (!isset($_POST["user"]) || !isset($_POST['password'])) { | ||||
return false; | return false; | ||||
return true; | return true; | ||||
} | } | ||||
/** | |||||
* Try to login a user using HTTP authentication. | |||||
* @return bool | |||||
*/ | |||||
protected static function tryBasicAuthLogin() { | protected static function tryBasicAuthLogin() { | ||||
if (!isset($_SERVER["PHP_AUTH_USER"]) | if (!isset($_SERVER["PHP_AUTH_USER"]) | ||||
|| !isset($_SERVER["PHP_AUTH_PW"]) | || !isset($_SERVER["PHP_AUTH_PW"]) | ||||
} | } | ||||
if (!function_exists('get_temp_dir')) { | if (!function_exists('get_temp_dir')) { | ||||
/** | |||||
* Get the temporary dir to store uploaded data | |||||
* @return null|string Path to the temporary directory or null | |||||
*/ | |||||
function get_temp_dir() { | function get_temp_dir() { | ||||
if ($temp = ini_get('upload_tmp_dir')) return $temp; | if ($temp = ini_get('upload_tmp_dir')) return $temp; | ||||
if ($temp = getenv('TMP')) return $temp; | if ($temp = getenv('TMP')) return $temp; |
$type, | $type, | ||||
$priority); | $priority); | ||||
} catch (\Exception $ex) { | } catch (\Exception $ex) { | ||||
// TODO: log the excepetion | |||||
// TODO: log the exception | |||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* merge the returned result objects into one response | * merge the returned result objects into one response | ||||
* @param array $responses | * @param array $responses | ||||
* @return array|\OC_OCS_Result | |||||
*/ | */ | ||||
public static function mergeResponses($responses) { | public static function mergeResponses($responses) { | ||||
$response = array(); | |||||
// Sort into shipped and thirdparty | // Sort into shipped and thirdparty | ||||
$shipped = array( | $shipped = array( | ||||
'succeeded' => array(), | 'succeeded' => array(), | ||||
// Merge the successful responses | // Merge the successful responses | ||||
$data = array(); | $data = array(); | ||||
foreach($responses as $app => $response) { | |||||
foreach($responses as $response) { | |||||
if($response['shipped']) { | if($response['shipped']) { | ||||
$data = array_merge_recursive($response['response']->getData(), $data); | $data = array_merge_recursive($response['response']->getData(), $data); | ||||
} else { | } else { |
/** | /** | ||||
* @brief Returns the navigation | * @brief Returns the navigation | ||||
* @return string | |||||
* @return array | |||||
* | * | ||||
* This function returns an array containing all entries added. The | * This function returns an array containing all entries added. The | ||||
* entries are sorted by the key 'order' ascending. Additional to the keys | * entries are sorted by the key 'order' ascending. Additional to the keys |
/** | /** | ||||
* @param string $app | * @param string $app | ||||
* @return \string[] | |||||
*/ | */ | ||||
private function getAppValues($app) { | private function getAppValues($app) { | ||||
$appCache = $this->getAppCache($app); | $appCache = $this->getAppCache($app); |
/** | /** | ||||
* open any of the supported archive types | * open any of the supported archive types | ||||
* @param string $path | * @param string $path | ||||
* @return OC_Archive | |||||
* @return OC_Archive|void | |||||
*/ | */ | ||||
public static function open($path) { | public static function open($path) { | ||||
$ext=substr($path, strrpos($path, '.')); | $ext=substr($path, strrpos($path, '.')); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @param $source | |||||
*/ | |||||
abstract function __construct($source); | abstract function __construct($source); | ||||
/** | /** | ||||
* add an empty folder to the archive | * add an empty folder to the archive | ||||
/** | /** | ||||
* add a file to the archive | * add a file to the archive | ||||
* @param string $path | * @param string $path | ||||
* @param string source either a local file or string data | |||||
* @param string $source either a local file or string data | |||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
abstract function addFile($path, $source=''); | abstract function addFile($path, $source=''); |
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return array|bool|int|null|string | |||||
*/ | */ | ||||
function parsePHP($string) { | function parsePHP($string) { | ||||
$string = $this->stripPHPTags($string); | $string = $this->stripPHPTags($string); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return string | |||||
*/ | */ | ||||
function stripPHPTags($string) { | function stripPHPTags($string) { | ||||
$string = trim($string); | $string = trim($string); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return string | |||||
*/ | */ | ||||
function stripAssignAndReturn($string) { | function stripAssignAndReturn($string) { | ||||
$string = trim($string); | $string = trim($string); | ||||
return $string; | return $string; | ||||
} | } | ||||
/** | |||||
* @param string $string | |||||
* @return array|bool|int|null|string | |||||
*/ | |||||
function parse($string) { | function parse($string) { | ||||
$string = trim($string); | $string = trim($string); | ||||
$string = trim($string, ';'); | $string = trim($string, ';'); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return int | |||||
*/ | */ | ||||
function getType($string) { | function getType($string) { | ||||
$string = strtolower($string); | $string = strtolower($string); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return string | |||||
*/ | */ | ||||
function parseString($string) { | function parseString($string) { | ||||
return substr($string, 1, -1); | return substr($string, 1, -1); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return int | |||||
*/ | */ | ||||
function parseNum($string) { | function parseNum($string) { | ||||
return intval($string); | return intval($string); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return bool | |||||
*/ | */ | ||||
function parseBool($string) { | function parseBool($string) { | ||||
$string = strtolower($string); | $string = strtolower($string); | ||||
/** | /** | ||||
* @param string $string | * @param string $string | ||||
* @return array | |||||
*/ | */ | ||||
function parseArray($string) { | function parseArray($string) { | ||||
$body = substr($string, 5); | $body = substr($string, 5); | ||||
/** | /** | ||||
* @param string $body | * @param string $body | ||||
* @return array | |||||
*/ | */ | ||||
function splitArray($body) { | function splitArray($body) { | ||||
$inSingleQuote = false;//keep track if we are inside quotes | $inSingleQuote = false;//keep track if we are inside quotes |
* See the COPYING-README file. | * See the COPYING-README file. | ||||
*/ | */ | ||||
class OC_Geo{ | class OC_Geo{ | ||||
/* | |||||
* @brief returns the closest timezone to coordinates | |||||
* @param (string) $latitude - Latitude | |||||
* @param (string) $longitude - Longitude | |||||
* @return (string) $timezone - closest timezone | |||||
*/ | |||||
/** | /** | ||||
* @param integer $latitude | |||||
* @param integer $longitude | |||||
* @brief returns the closest timezone to coordinates | |||||
* @param $latitude | |||||
* @param $longitude | |||||
* @return mixed Closest timezone | |||||
*/ | */ | ||||
public static function timezone($latitude, $longitude) { | public static function timezone($latitude, $longitude) { | ||||
$alltimezones = DateTimeZone::listIdentifiers(); | $alltimezones = DateTimeZone::listIdentifiers(); |
/** | /** | ||||
* @brief get a list of all groups | * @brief get a list of all groups | ||||
* @param string $search | |||||
* @param int|null $limit | |||||
* @param int|null $offset | |||||
* @returns array with group names | * @returns array with group names | ||||
* | * | ||||
* Returns a list with all groups | * Returns a list with all groups | ||||
/** | /** | ||||
* @brief get a list of all users in a group | * @brief get a list of all users in a group | ||||
* @param string $gid | |||||
* @param string $search | |||||
* @param int $limit | |||||
* @param int $offset | |||||
* @returns array with user ids | * @returns array with user ids | ||||
*/ | */ | ||||
public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { | public static function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) { | ||||
/** | /** | ||||
* @brief get a list of all display names in a group | * @brief get a list of all display names in a group | ||||
* @param string $gid | |||||
* @param string $search | |||||
* @param int $limit | |||||
* @param int $offset | |||||
* @returns array with display names (value) and user ids(key) | * @returns array with display names (value) and user ids(key) | ||||
*/ | */ | ||||
public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { | public static function displayNamesInGroup($gid, $search = '', $limit = -1, $offset = 0) { |
* @param array $parameters | * @param array $parameters | ||||
* @return | * @return | ||||
* @internal param array $args with param=>value, will be appended to the returned url | * @internal param array $args with param=>value, will be appended to the returned url | ||||
* @returns the url | |||||
* @returns string the url | |||||
* | * | ||||
* Returns a url to the given app and file. | * Returns a url to the given app and file. | ||||
*/ | */ |
} | } | ||||
/** | /** | ||||
* @brief Check an ajax get/post call if the request token is valid. | |||||
* @return json Error msg if not valid. | |||||
* Check an ajax get/post call if the request token is valid, send json error msg if not. | |||||
*/ | */ | ||||
public static function callCheck() { | public static function callCheck() { | ||||
if( !OC_Util::isCallRegistered()) { | if( !OC_Util::isCallRegistered()) { | ||||
} | } | ||||
/** | /** | ||||
* Check if the user is a admin, send json error msg if not | |||||
* Check if the user is a admin, send json error msg if not. | |||||
*/ | */ | ||||
public static function checkAdminUser() { | public static function checkAdminUser() { | ||||
if( !OC_User::isAdminUser(OC_User::getUser())) { | if( !OC_User::isAdminUser(OC_User::getUser())) { |
$identifier = "_${text_singular}_::_${text_plural}_"; | $identifier = "_${text_singular}_::_${text_plural}_"; | ||||
if( array_key_exists($identifier, $this->translations)) { | if( array_key_exists($identifier, $this->translations)) { | ||||
return new OC_L10N_String( $this, $identifier, $parameters, $count ); | return new OC_L10N_String( $this, $identifier, $parameters, $count ); | ||||
} | |||||
else{ | |||||
}else{ | |||||
if($count === 1) { | if($count === 1) { | ||||
return new OC_L10N_String($this, $text_singular, $parameters, $count); | return new OC_L10N_String($this, $text_singular, $parameters, $count); | ||||
} | |||||
else{ | |||||
}else{ | |||||
return new OC_L10N_String($this, $text_plural, $parameters, $count); | return new OC_L10N_String($this, $text_plural, $parameters, $count); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @brief Translating | |||||
* @param $textArray The text array we need a translation for | |||||
* @returns Translation or the same text | |||||
* | |||||
* Returns the translation. If no translation is found, $textArray will be | |||||
* returned. | |||||
* | |||||
* | |||||
* @deprecated deprecated since ownCloud version 5.0 | |||||
* This method will probably be removed with ownCloud 6.0 | |||||
* | |||||
* | |||||
*/ | |||||
public function tA($textArray) { | |||||
OC_Log::write('core', 'DEPRECATED: the method tA is deprecated and will be removed soon.', OC_Log::WARN); | |||||
$result = array(); | |||||
foreach($textArray as $key => $text) { | |||||
$result[$key] = (string)$this->t($text); | |||||
} | |||||
return $result; | |||||
} | |||||
/** | /** | ||||
* @brief getTranslations | * @brief getTranslations | ||||
* @returns Fetch all translations | |||||
* @returns array Fetch all translations | |||||
* | * | ||||
* Returns an associative array with all translations | * Returns an associative array with all translations | ||||
*/ | */ | ||||
/** | /** | ||||
* @brief get localizations | * @brief get localizations | ||||
* @returns Fetch all localizations | |||||
* @returns array Fetch all localizations | |||||
* | * | ||||
* Returns an associative array with all localizations | * Returns an associative array with all localizations | ||||
*/ | */ |
/** | /** | ||||
* @brief exports a user, or owncloud instance | * @brief exports a user, or owncloud instance | ||||
* @param optional $uid string user id of user to export if export type is user, defaults to current | |||||
* @param ootional $type string type of export, defualts to user | |||||
* @param otional $path string path to zip output folder | |||||
* @param string $uid user id of user to export if export type is user, defaults to current | |||||
* @param string $type type of export, defualts to user | |||||
* @param string $path path to zip output folder | |||||
* @return string on error, path to zip on success | * @return string on error, path to zip on success | ||||
*/ | */ | ||||
public static function export( $uid=null, $type='user', $path=null ) { | public static function export( $uid=null, $type='user', $path=null ) { | ||||
} | } | ||||
/** | /** | ||||
* @brief imports a user, or owncloud instance | |||||
* @param $path string path to zip | |||||
* @param optional $type type of import (user or instance) | |||||
* @param optional $uid userid of new user | |||||
*/ | |||||
* @brief imports a user, or owncloud instance | |||||
* @param string $path path to zip | |||||
* @param string $type type of import (user or instance) | |||||
* @param string|null|int $uid userid of new user | |||||
* @return string | |||||
*/ | |||||
public static function import( $path, $type='user', $uid=null ) { | public static function import( $path, $type='user', $uid=null ) { | ||||
$datadir = OC_Config::getValue( 'datadirectory' ); | $datadir = OC_Config::getValue( 'datadirectory' ); | ||||
/** | /** | ||||
* @brief recursively deletes a directory | * @brief recursively deletes a directory | ||||
* @param string $dir string path of dir to delete | |||||
* $param optional $deleteRootToo bool delete the root directory | |||||
* @param string $dir path of dir to delete | |||||
* @param bool $deleteRootToo delete the root directory | |||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
private static function unlink_r( $dir, $deleteRootToo=true ) { | private static function unlink_r( $dir, $deleteRootToo=true ) { | ||||
/** | /** | ||||
* @brief generates json containing export info, and merges any data supplied | * @brief generates json containing export info, and merges any data supplied | ||||
* @param optional $array array of data to include in the returned json | |||||
* @param array $array of data to include in the returned json | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
static private function getExportInfo( $array=array() ) { | static private function getExportInfo( $array=array() ) { | ||||
/** | /** | ||||
* @brief connects to migration.db, or creates if not found | * @brief connects to migration.db, or creates if not found | ||||
* @param $db optional path to migration.db, defaults to user data dir | |||||
* @param string $path | |||||
* @param string $path to migration.db, defaults to user data dir | |||||
* @return bool whether the operation was successful | * @return bool whether the operation was successful | ||||
*/ | */ | ||||
static private function connectDB( $path=null ) { | static private function connectDB( $path=null ) { | ||||
/** | /** | ||||
* @brief creates the tables in migration.db from an apps database.xml | * @brief creates the tables in migration.db from an apps database.xml | ||||
* @param string $appid string id of the app | |||||
* @param string $appid id of the app | |||||
* @return bool whether the operation was successful | * @return bool whether the operation was successful | ||||
*/ | */ | ||||
static private function createAppTables( $appid ) { | static private function createAppTables( $appid ) { | ||||
/** | /** | ||||
* @brief tries to create the zip | * @brief tries to create the zip | ||||
* @param $path string path to zip destination | |||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
static private function createZip() { | static private function createZip() { | ||||
* @brief imports a new user | * @brief imports a new user | ||||
* @param string $db string path to migration.db | * @param string $db string path to migration.db | ||||
* @param $info object of migration info | * @param $info object of migration info | ||||
* @param $uid optional uid to use | |||||
* @param string|null|int $uid uid to use | |||||
* @return array of apps with import statuses, or false on failure. | * @return array of apps with import statuses, or false on failure. | ||||
*/ | */ | ||||
public static function importAppData( $db, $info, $uid=null ) { | public static function importAppData( $db, $info, $uid=null ) { | ||||
} | } | ||||
/* | |||||
* @brief creates a new user in the database | |||||
* @param $uid string user_id of the user to be created | |||||
* @param $hash string hash of the user to be created | |||||
/** | |||||
* creates a new user in the database | |||||
* @param string $uid user_id of the user to be created | |||||
* @param string $hash hash of the user to be created | |||||
* @return bool result of user creation | * @return bool result of user creation | ||||
*/ | */ | ||||
public static function createUser( $uid, $hash ) { | public static function createUser( $uid, $hash ) { |
* @brief sets up the | * @brief sets up the | ||||
* @param ZipArchive $zip ZipArchive object | * @param ZipArchive $zip ZipArchive object | ||||
* @param $db a database object (required for exporttype user) | * @param $db a database object (required for exporttype user) | ||||
* @return boolean|null | |||||
* @return bool|null | |||||
*/ | */ | ||||
public function __construct( $zip, $db=null ) { | public function __construct( $zip, $db=null ) { | ||||
* @return string Data or if the key is not found and no default is set it will exit with a 400 Bad request | * @return string Data or if the key is not found and no default is set it will exit with a 400 Bad request | ||||
*/ | */ | ||||
public static function readData($method, $key, $type = 'raw', $default = null) { | public static function readData($method, $key, $type = 'raw', $default = null) { | ||||
$data = false; | |||||
if ($method == 'get') { | if ($method == 'get') { | ||||
if (isset($_GET[$key])) { | if (isset($_GET[$key])) { | ||||
$data = $_GET[$key]; | $data = $_GET[$key]; | ||||
/** | /** | ||||
* generates the xml or json response for the API call from an multidimenional data array. | |||||
* @param string $format | |||||
* @param string $status | |||||
* @param string $statuscode | |||||
* @param string $message | |||||
* @param array $data | |||||
* @param string $tag | |||||
* @param string $tagattribute | |||||
* @param int $dimension | |||||
* @param int $itemscount | |||||
* @param int $itemsperpage | |||||
* @return string xml/json | |||||
*/ | |||||
* generates the xml or json response for the API call from an multidimenional data array. | |||||
* @param string $format | |||||
* @param string $status | |||||
* @param string $statuscode | |||||
* @param string $message | |||||
* @param array $data | |||||
* @param string $tag | |||||
* @param string $tagattribute | |||||
* @param int $dimension | |||||
* @param int|string $itemscount | |||||
* @param int|string $itemsperpage | |||||
* @return string xml/json | |||||
*/ | |||||
private static function generateXml($format, $status, $statuscode, | private static function generateXml($format, $status, $statuscode, | ||||
$message, $data=array(), $tag='', $tagattribute='', $dimension=-1, $itemscount='', $itemsperpage='') { | $message, $data=array(), $tag='', $tagattribute='', $dimension=-1, $itemscount='', $itemsperpage='') { | ||||
if($format=='json') { | if($format=='json') { | ||||
} | } | ||||
/** | /** | ||||
* @param $writer | |||||
* @param $data | |||||
* @param string $node | * @param string $node | ||||
*/ | */ | ||||
public static function toXml($writer, $data, $node) { | public static function toXml($writer, $data, $node) { |
* @returns array with application data | * @returns array with application data | ||||
* | * | ||||
* This function returns a list of all the applications on the OCS server | * This function returns a list of all the applications on the OCS server | ||||
* @param integer $page | |||||
* @param $categories | |||||
* @param int $page | |||||
* @param string $filter | * @param string $filter | ||||
*/ | */ | ||||
public static function getApplications($categories, $page, $filter) { | public static function getApplications($categories, $page, $filter) { | ||||
/** | /** | ||||
* @brief Get an the applications from the OCS server | * @brief Get an the applications from the OCS server | ||||
* @param string $id | |||||
* @returns array with application data | * @returns array with application data | ||||
* | * | ||||
* This function returns an applications from the OCS server | * This function returns an applications from the OCS server | ||||
} | } | ||||
/** | /** | ||||
* @brief Get the download url for an application from the OCS server | |||||
* @returns array with application data | |||||
* | |||||
* This function returns an download url for an applications from the OCS server | |||||
* @param integer $item | |||||
*/ | |||||
* @brief Get the download url for an application from the OCS server | |||||
* @returns array with application data | |||||
* | |||||
* This function returns an download url for an applications from the OCS server | |||||
* @param string $id | |||||
* @param integer $item | |||||
*/ | |||||
public static function getApplicationDownload($id, $item) { | public static function getApplicationDownload($id, $item) { | ||||
if(OC_Config::getValue('appstoreenabled', true)==false) { | if(OC_Config::getValue('appstoreenabled', true)==false) { | ||||
return null; | return null; |
* @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image | * @param int $maxX The maximum X size of the thumbnail. It can be smaller depending on the shape of the image | ||||
* @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image | * @param int $maxY The maximum Y size of the thumbnail. It can be smaller depending on the shape of the image | ||||
* @param bool $scalingUp Disable/Enable upscaling of previews | * @param bool $scalingUp Disable/Enable upscaling of previews | ||||
* @throws \Exception | |||||
* @return mixed (bool / string) | * @return mixed (bool / string) | ||||
* false if thumbnail does not exist | * false if thumbnail does not exist | ||||
* path to thumbnail if thumbnail exists | * path to thumbnail if thumbnail exists | ||||
return $this->configMaxY; | return $this->configMaxY; | ||||
} | } | ||||
/** | |||||
* @return false|Files\FileInfo|\OCP\Files\FileInfo | |||||
*/ | |||||
protected function getFileInfo() { | protected function getFileInfo() { | ||||
$absPath = $this->fileView->getAbsolutePath($this->file); | $absPath = $this->fileView->getAbsolutePath($this->file); | ||||
$absPath = Files\Filesystem::normalizePath($absPath); | $absPath = Files\Filesystem::normalizePath($absPath); | ||||
/** | /** | ||||
* @brief set the the max width of the preview | * @brief set the the max width of the preview | ||||
* @param int $maxX | * @param int $maxX | ||||
* @throws \Exception | |||||
* @return $this | * @return $this | ||||
*/ | */ | ||||
public function setMaxX($maxX = 1) { | public function setMaxX($maxX = 1) { | ||||
/** | /** | ||||
* @brief set the the max height of the preview | * @brief set the the max height of the preview | ||||
* @param int $maxY | * @param int $maxY | ||||
* @throws \Exception | |||||
* @return $this | * @return $this | ||||
*/ | */ | ||||
public function setMaxY($maxY = 1) { | public function setMaxY($maxY = 1) { | ||||
return $possibleThumbnails; | return $possibleThumbnails; | ||||
} | } | ||||
/** | |||||
* @param string $name | |||||
* @return array | |||||
*/ | |||||
private function getDimensionsFromFilename($name) { | private function getDimensionsFromFilename($name) { | ||||
$size = explode('-', $name); | $size = explode('-', $name); | ||||
$x = (int) $size[0]; | $x = (int) $size[0]; | ||||
return array($x, $y, $aspectRatio); | return array($x, $y, $aspectRatio); | ||||
} | } | ||||
/** | |||||
* @param int $x | |||||
* @param int $y | |||||
* @return bool | |||||
*/ | |||||
private function unscalable($x, $y) { | private function unscalable($x, $y) { | ||||
$maxX = $this->getMaxX(); | $maxX = $this->getMaxX(); | ||||
/** | /** | ||||
* @param string $mimeType | * @param string $mimeType | ||||
* @return bool | |||||
*/ | */ | ||||
public static function isMimeSupported($mimeType) { | public static function isMimeSupported($mimeType) { | ||||
if (!\OC_Config::getValue('enable_previews', true)) { | if (!\OC_Config::getValue('enable_previews', true)) { |
/** | /** | ||||
* @brief get Path info from request, not urldecoded | * @brief get Path info from request, not urldecoded | ||||
* @throws Exception | |||||
* @return string Path info or false when not found | * @return string Path info or false when not found | ||||
*/ | */ | ||||
public static function getRawPathInfo() { | public static function getRawPathInfo() { |
/** | /** | ||||
* @brief Set response status | * @brief Set response status | ||||
* @param $status a HTTP status code, see also the STATUS constants | |||||
* @param int $status a HTTP status code, see also the STATUS constants | |||||
*/ | */ | ||||
static public function setStatus($status) { | static public function setStatus($status) { | ||||
$protocol = $_SERVER['SERVER_PROTOCOL']; | $protocol = $_SERVER['SERVER_PROTOCOL']; |
/** | /** | ||||
* search all provider for $query | * search all provider for $query | ||||
* @param string query | |||||
* @param string $query | |||||
* @return array An array of OC_Search_Result's | * @return array An array of OC_Search_Result's | ||||
*/ | */ | ||||
public static function search($query) { | public static function search($query) { |
* @param string $theme | * @param string $theme | ||||
* @param string $app | * @param string $app | ||||
* @param string $fext | * @param string $fext | ||||
* @return array | |||||
*/ | */ | ||||
protected function findTemplate($theme, $app, $name, $fext) { | protected function findTemplate($theme, $app, $name, $fext) { | ||||
// Check if it is a app template or not. | // Check if it is a app template or not. | ||||
* @brief Shortcut to print a simple page for guests | * @brief Shortcut to print a simple page for guests | ||||
* @param string $application The application we render the template for | * @param string $application The application we render the template for | ||||
* @param string $name Name of the template | * @param string $name Name of the template | ||||
* @param string $parameters Parameters for the template | |||||
* @param array|string $parameters Parameters for the template | |||||
* @return bool | * @return bool | ||||
*/ | */ | ||||
public static function printGuestPage( $application, $name, $parameters = array() ) { | public static function printGuestPage( $application, $name, $parameters = array() ) { | ||||
* print error page using Exception details | * print error page using Exception details | ||||
* @param Exception $exception | * @param Exception $exception | ||||
*/ | */ | ||||
public static function printExceptionErrorPage(Exception $exception) { | public static function printExceptionErrorPage(Exception $exception) { | ||||
$error_msg = $exception->getMessage(); | $error_msg = $exception->getMessage(); | ||||
if ($exception->getCode()) { | if ($exception->getCode()) { |
<?php | <?php | ||||
use Assetic\Asset\AssetCollection; | use Assetic\Asset\AssetCollection; | ||||
use Assetic\Asset\FileAsset; | use Assetic\Asset\FileAsset; | ||||
use Assetic\Asset\GlobAsset; | |||||
use Assetic\AssetManager; | |||||
use Assetic\AssetWriter; | use Assetic\AssetWriter; | ||||
use Assetic\Filter\CssRewriteFilter; | use Assetic\Filter\CssRewriteFilter; | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @param $styles | |||||
* @return array | |||||
*/ | |||||
static public function findStylesheetFiles($styles) { | static public function findStylesheetFiles($styles) { | ||||
// Read the selected theme from the config file | // Read the selected theme from the config file | ||||
$theme = OC_Util::getTheme(); | $theme = OC_Util::getTheme(); | ||||
return $locator->getResources(); | return $locator->getResources(); | ||||
} | } | ||||
/** | |||||
* @param $scripts | |||||
* @return array | |||||
*/ | |||||
static public function findJavascriptFiles($scripts) { | static public function findJavascriptFiles($scripts) { | ||||
// Read the selected theme from the config file | // Read the selected theme from the config file | ||||
$theme = OC_Util::getTheme(); | $theme = OC_Util::getTheme(); | ||||
$this->append('cssfiles', OC_Helper::linkTo('assets', "$cssHash.css")); | $this->append('cssfiles', OC_Helper::linkTo('assets', "$cssHash.css")); | ||||
} | } | ||||
/** | |||||
* @param $files | |||||
* @return string | |||||
*/ | |||||
private static function hashScriptNames($files) | private static function hashScriptNames($files) | ||||
{ | { | ||||
$files = array_map(function ($item) { | $files = array_map(function ($item) { |
* @brief Creates path to an image | * @brief Creates path to an image | ||||
* @param string $app app | * @param string $app app | ||||
* @param string $image image name | * @param string $image image name | ||||
* @throws \RuntimeException If the image does not exist | |||||
* @return string the url | * @return string the url | ||||
* | * | ||||
* Returns the path to the image. | * Returns the path to the image. |
* logout() | * logout() | ||||
*/ | */ | ||||
class OC_User { | class OC_User { | ||||
/** | |||||
* @return \OC\User\Session | |||||
*/ | |||||
public static function getUserSession() { | public static function getUserSession() { | ||||
return OC::$server->getUserSession(); | return OC::$server->getUserSession(); | ||||
} | } | ||||
/** | /** | ||||
* @brief Try to login a user | * @brief Try to login a user | ||||
* @param $uid The username of the user to log in | |||||
* @param $password The password of the user | |||||
* @param string $uid The username of the user to log in | |||||
* @param string $password The password of the user | |||||
* @return boolean|null | * @return boolean|null | ||||
* | * | ||||
* Log in a user and regenerate a new session - if the password is ok | * Log in a user and regenerate a new session - if the password is ok | ||||
/** | /** | ||||
* @brief Sets user display name for session | * @brief Sets user display name for session | ||||
* @param string $uid | * @param string $uid | ||||
* @param null $displayName | |||||
* @return bool Whether the display name could get set | |||||
*/ | */ | ||||
public static function setDisplayName($uid, $displayName = null) { | public static function setDisplayName($uid, $displayName = null) { | ||||
if (is_null($displayName)) { | if (is_null($displayName)) { | ||||
* @returns array with all uids | * @returns array with all uids | ||||
* | * | ||||
* Get a list of all users. | * Get a list of all users. | ||||
* @param string $search | |||||
* @param integer $limit | * @param integer $limit | ||||
* @param integer $offset | * @param integer $offset | ||||
*/ | */ |
} | } | ||||
/** | /** | ||||
* Get the quota of a user | |||||
* @param string $user | * @param string $user | ||||
* @return int Quota bytes | |||||
*/ | */ | ||||
public static function getUserQuota($user){ | public static function getUserQuota($user){ | ||||
$config = \OC::$server->getConfig(); | $config = \OC::$server->getConfig(); | ||||
return $errors; | return $errors; | ||||
} | } | ||||
$defaults = new \OC_Defaults(); | |||||
$webServerRestart = false; | $webServerRestart = false; | ||||
//check for database drivers | //check for database drivers | ||||
if(!(is_callable('sqlite_open') or class_exists('SQLite3')) | if(!(is_callable('sqlite_open') or class_exists('SQLite3')) | ||||
} | } | ||||
/** | /** | ||||
* @return void | |||||
* @param array $errors | |||||
*/ | */ | ||||
public static function displayLoginPage($errors = array()) { | public static function displayLoginPage($errors = array()) { | ||||
$parameters = array(); | $parameters = array(); | ||||
foreach( $errors as $key => $value ) { | |||||
foreach( $errors as $value ) { | |||||
$parameters[$value] = true; | $parameters[$value] = true; | ||||
} | } | ||||
if (!empty($_POST['user'])) { | if (!empty($_POST['user'])) { | ||||
} | } | ||||
/** | /** | ||||
* @brief Check if the htaccess file is working | |||||
* @brief Check if the .htaccess file is working | |||||
* @throws OC\HintException If the testfile can't get written. | |||||
* @return bool | * @return bool | ||||
* @description Check if the htaccess file is working by creating a test | |||||
* @description Check if the .htaccess file is working by creating a test | |||||
* file in the data directory and trying to access via http | * file in the data directory and trying to access via http | ||||
*/ | */ | ||||
public static function isHtAccessWorking() { | |||||
public static function isHtaccessWorking() { | |||||
if (!\OC_Config::getValue("check_for_working_htaccess", true)) { | if (!\OC_Config::getValue("check_for_working_htaccess", true)) { | ||||
return true; | return true; | ||||
} | } |
/** | /** | ||||
* @brief Parses the VObject | * @brief Parses the VObject | ||||
* @param string VObject as string | |||||
* @returns Sabre_VObject or null | |||||
* @param string $data VObject as string | |||||
* @returns Sabre\VObject\Reader|null | |||||
*/ | */ | ||||
public static function parse($data) { | public static function parse($data) { | ||||
try { | try { | ||||
/** | /** | ||||
* @brief Escapes semicolons | * @brief Escapes semicolons | ||||
* @param string $value | |||||
* @param array $value | |||||
* @return string | * @return string | ||||
*/ | */ | ||||
public static function escapeSemicolons($value) { | public static function escapeSemicolons($value) { | ||||
} | } | ||||
/** | /** | ||||
* Constuctor | |||||
* Constructor | |||||
* @param Sabre\VObject\Component or string | * @param Sabre\VObject\Component or string | ||||
*/ | */ | ||||
public function __construct($vobject_or_name) { | public function __construct($vobject_or_name) { | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param $item | |||||
* @param null $itemValue | |||||
*/ | |||||
public function add($item, $itemValue = null) { | public function add($item, $itemValue = null) { | ||||
if ($item instanceof OC_VObject) { | if ($item instanceof OC_VObject) { | ||||
$item = $item->getVObject(); | $item = $item->getVObject(); | ||||
* @brief Add property to vobject | * @brief Add property to vobject | ||||
* @param object $name of property | * @param object $name of property | ||||
* @param object $value of property | * @param object $value of property | ||||
* @param object $parameters of property | |||||
* @returns Sabre_VObject_Property newly created | |||||
* @param array|object $parameters of property | |||||
* @returns Sabre\VObject\Property newly created | |||||
*/ | */ | ||||
public function addProperty($name, $value, $parameters=array()) { | public function addProperty($name, $value, $parameters=array()) { | ||||
if(is_array($value)) { | if(is_array($value)) { | ||||
$this->vobject->add('UID', $uid); | $this->vobject->add('UID', $uid); | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param mixed $name | |||||
* @param string $string | |||||
*/ | |||||
public function setString($name, $string) { | public function setString($name, $string) { | ||||
if ($string != '') { | if ($string != '') { | ||||
$string = strtr($string, array("\r\n"=>"\n")); | $string = strtr($string, array("\r\n"=>"\n")); | ||||
* When $datetime is set to 'now', use the current time | * When $datetime is set to 'now', use the current time | ||||
* When $datetime is null, unset the property | * When $datetime is null, unset the property | ||||
* | * | ||||
* @param string property name | |||||
* @param string $name | |||||
* @param DateTime $datetime | * @param DateTime $datetime | ||||
* @param int $dateType | * @param int $dateType | ||||
* @return void | * @return void | ||||
} | } | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param $name | |||||
* @return string | |||||
*/ | |||||
public function getAsString($name) { | public function getAsString($name) { | ||||
return $this->vobject->__isset($name) ? | return $this->vobject->__isset($name) ? | ||||
$this->vobject->__get($name)->value : | $this->vobject->__get($name)->value : | ||||
''; | ''; | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param $name | |||||
* @return array | |||||
*/ | |||||
public function getAsArray($name) { | public function getAsArray($name) { | ||||
$values = array(); | $values = array(); | ||||
if ($this->vobject->__isset($name)) { | if ($this->vobject->__isset($name)) { | ||||
return $values; | return $values; | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param $name | |||||
* @return array|OC_VObject|\Sabre\VObject\Property | |||||
*/ | |||||
public function &__get($name) { | public function &__get($name) { | ||||
if ($name == 'children') { | if ($name == 'children') { | ||||
return $this->vobject->children; | return $this->vobject->children; | ||||
return $return; | return $return; | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param string $name | |||||
* @param string $value | |||||
*/ | |||||
public function __set($name, $value) { | public function __set($name, $value) { | ||||
return $this->vobject->__set($name, $value); | return $this->vobject->__set($name, $value); | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param string $name | |||||
*/ | |||||
public function __unset($name) { | public function __unset($name) { | ||||
return $this->vobject->__unset($name); | return $this->vobject->__unset($name); | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param string $name | |||||
* @return bool | |||||
*/ | |||||
public function __isset($name) { | public function __isset($name) { | ||||
return $this->vobject->__isset($name); | return $this->vobject->__isset($name); | ||||
} | } | ||||
/** | |||||
* @todo Write documentation | |||||
* @param $function | |||||
* @param $arguments | |||||
* @return mixed | |||||
*/ | |||||
public function __call($function, $arguments) { | public function __call($function, $arguments) { | ||||
return call_user_func_array(array($this->vobject, $function), $arguments); | return call_user_func_array(array($this->vobject, $function), $arguments); | ||||
} | } |
* @param string $mailtext | * @param string $mailtext | ||||
* @param string $fromaddress | * @param string $fromaddress | ||||
* @param string $fromname | * @param string $fromname | ||||
* @param bool $html | |||||
* @param int $html | |||||
* @param string $altbody | * @param string $altbody | ||||
* @param string $ccaddress | * @param string $ccaddress | ||||
* @param string $ccname | * @param string $ccname | ||||
* write exception into the log. Include the stack trace | * write exception into the log. Include the stack trace | ||||
* if DEBUG mode is enabled | * if DEBUG mode is enabled | ||||
* @param string $app app name | * @param string $app app name | ||||
* @param Exception $ex exception to log | |||||
* @param \Exception $ex exception to log | |||||
*/ | */ | ||||
public static function logException( $app, \Exception $ex ) { | public static function logException( $app, \Exception $ex ) { | ||||
$class = get_class($ex); | $class = get_class($ex); | ||||
* formats a timestamp in the "right" way | * formats a timestamp in the "right" way | ||||
* @param int $timestamp $timestamp | * @param int $timestamp $timestamp | ||||
* @param bool $dateOnly option to omit time from the result | * @param bool $dateOnly option to omit time from the result | ||||
* @return string timestamp | |||||
*/ | */ | ||||
public static function formatDate( $timestamp, $dateOnly=false) { | public static function formatDate( $timestamp, $dateOnly=false) { | ||||
return(\OC_Util::formatDate( $timestamp, $dateOnly )); | return(\OC_Util::formatDate( $timestamp, $dateOnly )); | ||||
* Creates an url using a defined route | * Creates an url using a defined route | ||||
* @param $route | * @param $route | ||||
* @param array $parameters | * @param array $parameters | ||||
* @return | |||||
* @internal param array $args with param=>value, will be appended to the returned url | * @internal param array $args with param=>value, will be appended to the returned url | ||||
* @return the url | |||||
* @return string the url | |||||
*/ | */ | ||||
public static function linkToRoute( $route, $parameters = array() ) { | public static function linkToRoute( $route, $parameters = array() ) { | ||||
return \OC_Helper::linkToRoute($route, $parameters); | return \OC_Helper::linkToRoute($route, $parameters); | ||||
/** | /** | ||||
* Returns the request uri, even if the website uses one or more reverse proxies | * Returns the request uri, even if the website uses one or more reverse proxies | ||||
* | |||||
* @return the request uri | |||||
* @return string the request uri | |||||
*/ | */ | ||||
public static function getRequestUri() { | public static function getRequestUri() { | ||||
return(\OC_Request::requestUri()); | return(\OC_Request::requestUri()); | ||||
/** | /** | ||||
* Returns the script name, even if the website uses one or more reverse proxies | * Returns the script name, even if the website uses one or more reverse proxies | ||||
* | |||||
* @return the script name | |||||
* @returns string the script name | |||||
*/ | */ | ||||
public static function getScriptName() { | public static function getScriptName() { | ||||
return(\OC_Request::scriptName()); | return(\OC_Request::scriptName()); | ||||
* Emits a signal. To get data from the slot use references! | * Emits a signal. To get data from the slot use references! | ||||
* @param string $signalclass class name of emitter | * @param string $signalclass class name of emitter | ||||
* @param string $signalname name of signal | * @param string $signalname name of signal | ||||
* @param string $params defautl: array() array with additional data | |||||
* @param array $params default: array() array with additional data | |||||
* @return bool true if slots exists or false if not | * @return bool true if slots exists or false if not | ||||
* | * | ||||
* TODO: write example | * TODO: write example | ||||
/** | /** | ||||
* Calculate free space left within user quota | * Calculate free space left within user quota | ||||
* | |||||
* @param $dir the current folder where the user currently operates | |||||
* @return number of bytes representing | |||||
* @param string $dir the current folder where the user currently operates | |||||
* @return int number of bytes representing | |||||
*/ | */ | ||||
public static function freeSpace($dir) { | public static function freeSpace($dir) { | ||||
return \OC_Helper::freeSpace($dir); | return \OC_Helper::freeSpace($dir); |
$tmpl = new OC_Template( 'settings', 'admin', 'user'); | $tmpl = new OC_Template( 'settings', 'admin', 'user'); | ||||
$forms=OC_App::getForms('admin'); | $forms=OC_App::getForms('admin'); | ||||
$htaccessworking=OC_Util::isHtAccessWorking(); | |||||
$htaccessworking=OC_Util::isHtaccessWorking(); | |||||
$entries=OC_Log_Owncloud::getEntries(3); | $entries=OC_Log_Owncloud::getEntries(3); | ||||
$entriesremain = count(OC_Log_Owncloud::getEntries(4)) > 3; | $entriesremain = count(OC_Log_Owncloud::getEntries(4)) > 3; |
if (OC::$CLI) { | if (OC::$CLI) { | ||||
print_r($values); | print_r($values); | ||||
} else { | } else { | ||||
echo(json_encode($values)); | |||||
print_unescaped(json_encode($values)); | |||||
} | } | ||||
} catch (Exception $ex) { | } catch (Exception $ex) { |
<?php | <?php | ||||
// We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel when updating major/minor version number. | |||||
// We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades | |||||
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel | |||||
// when updating major/minor version number. | |||||
$OC_Version=array(6, 90, 0, 2); | $OC_Version=array(6, 90, 0, 2); | ||||
// The human readable string | // The human readable string |