Util¶
-
class
OCP\
Util
¶ - This class provides different helper functions to make the life of a developer easier
Source: lib/public/Util.php#61
Constants¶
-
DEBUG = 0
Source: lib/public/Util.php#65 Deprecated: 14.0.0 use \OCP\ILogger::DEBUG
-
INFO = 1
Source: lib/public/Util.php#69 Deprecated: 14.0.0 use \OCP\ILogger::INFO
-
WARN = 2
Source: lib/public/Util.php#73 Deprecated: 14.0.0 use \OCP\ILogger::WARN
-
ERROR = 3
Source: lib/public/Util.php#77 Deprecated: 14.0.0 use \OCP\ILogger::ERROR
-
FATAL = 4
Source: lib/public/Util.php#81 Deprecated: 14.0.0 use \OCP\ILogger::FATAL
Properties¶
-
protected property
OCP\Util::$
needUpgradeCache
¶ Source: lib/public/Util.php#510
Methods¶
-
public static
OCP\Util::
getVersion
()¶ - get the current installed version of Nextcloud
Source: lib/public/Util.php#91 Returns: array Since: 4.0.0
-
public static
OCP\Util::
hasExtendedSupport
()¶ Source: lib/public/Util.php#98 Since: 17.0.0
-
public static
OCP\Util::
setChannel
($channel)¶ - Set current update channel
Source: Parameters: - $channel (string)
Since: 8.1.0
-
public static
OCP\Util::
getChannel
()¶ - Get current update channel
Source: lib/public/Util.php#122 Returns: string Since: 8.1.0
-
public static
OCP\Util::
writeLog
($app, $message, $level)¶ - write a message in the log
Source: Parameters: - $app (string)
- $message (string)
- $level (int)
Since: 4.0.0
Deprecated: 13.0.0 use log of \OCP\ILogger
-
public static
OCP\Util::
isSharingDisabledForUser
()¶ - check if sharing is disabled for the current user
Source: lib/public/Util.php#146 Returns: bool Since: 7.0.0 Deprecated: 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser
-
public static
OCP\Util::
getL10N
($application, $language=null)¶ - get l10n object
Source: Parameters: - $application (string)
- $language (string | null)
Returns: Since: 6.0.0 - parameter $language was added in 8.0.0
-
public static
OCP\Util::
addStyle
($application, $file=null)¶ - add a css file
Source: Parameters: - $application (string)
- $file (string)
Since: 4.0.0
-
public static
OCP\Util::
addScript
($application, $file=null)¶ - add a javascript file
Source: Parameters: - $application (string)
- $file (string)
Since: 4.0.0
-
public static
OCP\Util::
addTranslations
($application, $languageCode=null)¶ - Add a translation JS file
Source: Parameters: - $application (string) application id
- $languageCode (string) language code, defaults to the current locale
Since: 8.0.0
-
public static
OCP\Util::
addHeader
($tag, $attributes, $text=null)¶ - Add a custom element to the headerIf $text is null then the element will be written as empty element.So use “” to get a closing tag.
Source: Parameters: - $tag (string) tag name of the element
- $attributes (array) array of attributes for the element
- $text (string) the text content for the element
Since: 4.0.0
-
public static
OCP\Util::
linkToAbsolute
($app, $file, $args=[])¶ - Creates an absolute url to the given app and file.
Source: Parameters: - $app (string) app
- $file (string) file
- $args (array) array with param=>value, will be appended to the returned url
The value of $args will be urlencoded
Returns: string the url
Since: 4.0.0 - parameter $args was added in 4.5.0
-
public static
OCP\Util::
linkToRemote
($service)¶ - Creates an absolute url for remote use.
Source: Parameters: - $service (string) id
Returns: string the url
Since: 4.0.0
-
public static
OCP\Util::
linkToPublic
($service)¶ - Creates an absolute url for public use
Source: Parameters: - $service (string) id
Returns: string the url
Since: 4.5.0
Deprecated: 15.0.0 - use OCP\IURLGenerator
-
public static
OCP\Util::
getServerHostName
()¶ - Returns the server host name without an eventual port number
Source: lib/public/Util.php#263 Returns: string the server hostname Since: 5.0.0
-
public static
OCP\Util::
getDefaultEmailAddress
($user_part)¶ - Returns the default email address
Source: Parameters: - $user_part (string) the user part of the address
Returns: string the default email address
Assembles a default email address (using the server hostname and the given user part, and returns it Example: when given lostpassword-noreply as $user_part param,
and is currently accessed via http(s)://example.com/, it would return 'lostpassword-noreply@example.com‘
If the configuration value ‘mail_from_address’ is set in config.php, this value will override the $user_part that is passed to this function
Since: 5.0.0
-
public static
OCP\Util::
humanFileSize
($bytes)¶ - Make a human file size (2048 to 2 kB)
Source: Parameters: - $bytes (int) file size in bytes
Returns: string a human readable file size
Since: 4.0.0
-
public static
OCP\Util::
computerFileSize
($str)¶ - Make a computer file size (2 kB to 2048)
Source: Parameters: - $str (string) file size in a fancy format
Returns: float a file size in bytes
Inspired by: https://www.php.net/manual/en/function.filesize.php#92418
Since: 4.0.0
-
public static
OCP\Util::
connectHook
($signalClass, $signalName, $slotClass, $slotName)¶ - connects a function to a hook
Source: Parameters: - $signalClass (string) class name of emitter
- $signalName (string) name of signal
- $slotClass (string | object) class name of slot
- $slotName (string) name of slot
Returns: bool This function makes it very easy to connect to use hooks.
TODO: write example
Since: 4.0.0
Deprecated: 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener
-
public static
OCP\Util::
emitHook
($signalclass, $signalname, $params=[])¶ - Emits a signal. To get data from the slot use references!
Source: Parameters: - $signalclass (string) class name of emitter
- $signalname (string) name of signal
- $params (array) default: array() array with additional data
Returns: bool true if slots exists or false if not
TODO: write example
Since: 4.0.0
Deprecated: 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent
-
public static
OCP\Util::
callRegister
()¶ - Register an get/post call. This is important to prevent CSRF attacks
Source: lib/public/Util.php#373 Since: 4.5.0
-
public static
OCP\Util::
sanitizeHTML
($value)¶ - Used to sanitize HTMLThis function is used to sanitize HTML and should be applied on anystring or array of strings before displaying it on a web page.
Source: Parameters: - $value (string | array)
Returns: string | array an array of sanitized strings or a single sanitized string, depends on the input parameter.
Since: 4.5.0
-
public static
OCP\Util::
encodePath
($component)¶ - Public function to encode url parametersThis function is used to encode path to file before output.Encoding is done according to RFC 3986 with one exception:Character ‘/’ is preserved as is.
Source: Parameters: - $component (string) part of URI to encode
Returns: string
Since: 6.0.0
-
public static
OCP\Util::
mb_array_change_key_case
($input, $case=MB_CASE_LOWER, $encoding=UTF-8)¶ - Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is.
Source: Parameters: - $input (array) The array to work on
- $case (int) Either MB_CASE_UPPER or MB_CASE_LOWER (default)
- $encoding (string) The encoding parameter is the character encoding. Defaults to UTF-8
Returns: array
Since: 4.5.0
-
public static
OCP\Util::
recursiveArraySearch
($haystack, $needle, $index=null)¶ - performs a search in a nested array
Source: Parameters: - $haystack (array) the array to be searched
- $needle (string) the search string
- $index (mixed) optional, only search this key name
Returns: mixed the key of the matching field, otherwise false
Since: 4.5.0
Deprecated: 15.0.0
-
public static
OCP\Util::
maxUploadFilesize
($dir, $free=null)¶ - calculates the maximum upload size respecting system settings, free space and user quota
Source: Parameters: - $dir (string) the current folder where the user currently operates
- $free (int) the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly
Returns: int number of bytes representing
Since: 5.0.0
-
public static
OCP\Util::
freeSpace
($dir)¶ - Calculate free space left within user quota
Source: Parameters: - $dir (string) the current folder where the user currently operates
Returns: int number of bytes representing
Since: 7.0.0
-
public static
OCP\Util::
uploadLimit
()¶ - Calculate PHP upload limit
Source: lib/public/Util.php#464 Returns: int number of bytes representing Since: 7.0.0
-
public static
OCP\Util::
isValidFileName
($file)¶ - Returns whether the given file name is valid
Source: Parameters: - $file (string) file name to check
Returns: bool true if the file name is valid, false otherwise
Deprecated: 8.1.0 use \OC\Files\View::verifyPath()
Since: 7.0.0
-
public static
OCP\Util::
naturalSortCompare
($a, $b)¶ - Compare two strings to provide a natural sort
Source: Parameters: - $a (string) first string to compare
- $b (string) second string to compare
Returns: int -1 if $b comes before $a, 1 if $a comes before $b or 0 if the strings are identical
Since: 7.0.0
-
public static
OCP\Util::
isPublicLinkPasswordRequired
()¶ - check if a password is required for each public link
Source: lib/public/Util.php#497 Returns: bool Since: 7.0.0
-
public static
OCP\Util::
isDefaultExpireDateEnforced
()¶ - check if share API enforces a default expire date
Source: lib/public/Util.php#506 Returns: bool Since: 8.0.0
-
public static
OCP\Util::
needUpgrade
()¶ - Checks whether the current version needs upgrade.
Source: lib/public/Util.php#518 Returns: bool true if upgrade is needed, false otherwise Since: 7.0.0