CRM_Utils_System
class CRM_Utils_System
System wide utilities.
Provides a collection of Civi utilities + access to the CMS-dependant utilities
FIXME: This is a massive and random collection that could be split into smaller services
Properties
static | $_callbacks | ||
static string | $title |
Methods
Access methods in the appropriate CMS class
Compose a new URL string from the current URL string.
Get the query string and clean it up.
If we are using a theming system, invoke theme, else just print the content.
Generate a query string if input is an array.
Generate an internal CiviCRM URL.
Path of the current page e.g. 'civicrm/contact/view'
Get href.
What menu path are we currently on. Called for the primary tpl.
Called from a template to compose a url.
Sets the title of the page.
Figures and sets the userContext.
Gets a class name for an object.
Redirect to another URL.
Redirect to another URL using JavaScript.
Get the base URL of the system.
Authenticate or abort.
Authenticate key.
Authenticate script.
Authenticate the user against the uf db.
Set a message in the UF to display to a user.
Determine whether a value is null-ish.
Obscure all but the last few digits of a credit card number.
Get a setting from a loaded PHP module.
Do something no-one bothered to document.
Download something or other.
Gather and print (and possibly log) amount of used memory.
Take a URL (or partial URL) and make it better.
Make sure a callback is valid in the current context.
Like PHP's built-in explode(), but always return an array of $limit items.
Check url.
Assert that we are running on a particular PHP version.
Format wiki url.
Encode url.
Return the running civicrm version.
Gives the first two parts of the version string E.g. 6.1.
Determines whether a string is a valid CiviCRM version string.
Wraps or emulates PHP's getallheaders() function.
Get request headers.
Determine whether this is an SSL request.
Redirect to SSL.
Get logged in user's IP address.
Get the referring / previous page URL.
Get the documentation base URL.
Returns wiki (alternate) documentation URL base.
Returns URL or link to documentation page, based on provided parameters.
Returns URL or link to documentation page, based on provided parameters.
Add language and version parameters to the doc url.
Exit with provided exit code.
Reset the various system caches and some important static variables.
Load CMS bootstrap.
Get Base CMS url.
Given a URL, return a relative URL if possible.
Produce an absolute URL from a possibly-relative URL.
Clean url, replaces first '&' with '?'.
Format the url as per language Negotiation.
Append the contents of an 'extra' smarty template file.
Get a list of all files that are found within the directories.
Get a list of all "plugins".
Execute scheduled jobs.
Evaluate any tokens in a URL.
Returns the unique identifier for this site, as used by community messages.
Determine whether this is a developmental system.
Is in upgrade mode.
Determine the standard URL for viewing or editing the specified link.
Return an HTTP Response with appropriate content and status code set.
Append an additional breadcrumb tag to the existing breadcrumbs.
Reset an additional breadcrumb tag to the existing breadcrumb.
Append a string to the head of the HTML file.
Set http header.
Callback for hook_civicrm_coreResourceList.
Callback for hook_civicrm_getAssetUrl.
Details
at line 74
static mixed
__callStatic($name, $arguments)
Access methods in the appropriate CMS class
at line 99
static string
makeURL(string $urlVar, bool $includeReset = FALSE, bool $includeForce = TRUE, string $path = NULL, bool|string $absolute = FALSE)
Compose a new URL string from the current URL string.
Used by all the framework components, specifically, pager, sort and qfc
at line 135
static string
getLinksUrl(string $urlVar, bool $includeReset = FALSE, bool $includeForce = TRUE, bool $skipUFVar = TRUE)
Get the query string and clean it up.
Strips some variables that should not be propagated, specifically variables like 'reset'. Also strips any side-affect actions (e.g. export).
This function is copied mostly verbatim from Pager.php (_getLinksUrl)
at line 214
static string
theme(string $content, bool $print = FALSE, bool $maintenance = FALSE)
If we are using a theming system, invoke theme, else just print the content.
at line 229
static string
makeQueryString(array|string $query)
Generate a query string if input is an array.
at line 263
static string
url(string $path = NULL, array|string $query = NULL, bool $absolute = FALSE, string $fragment = NULL, bool $htmlize = TRUE, bool $frontend = FALSE, bool $forceBackend = FALSE)
Generate an internal CiviCRM URL.
at line 308
static string|null
getUrlPath()
Path of the current page e.g. 'civicrm/contact/view'
at line 329
static string
href(string $text, string $path = NULL, string|array $query = NULL, bool $absolute = TRUE, string $fragment = NULL, bool $htmlize = TRUE, bool $frontend = FALSE, bool $forceBackend = FALSE)
Get href.
at line 343
static string
currentPath()
What menu path are we currently on. Called for the primary tpl.
at line 357
static string
crmURL(array $params)
Called from a template to compose a url.
at line 382
static
setTitle(string $title, string $pageTitle = NULL)
Sets the title of the page.
at line 398
static
setUserContext(array $names, string $default = NULL)
Figures and sets the userContext.
Uses the referrer if valid else uses the default.
at line 427
static string
getClassName(object $object)
Gets a class name for an object.
at line 439
static
redirect(string $url = NULL, array $context = [])
Redirect to another URL.
at line 478
static
jsRedirect(string $url = NULL, string $title = NULL, string $message = NULL)
Redirect to another URL using JavaScript.
Use an html based file with javascript embedded to redirect to another url This prevent the too many redirect errors emitted by various browsers
at line 516
static string
baseURL()
Get the base URL of the system.
at line 529
static bool
authenticateAbort(string $message, bool $abort)
Authenticate or abort.
at line 547
static bool
authenticateKey(bool $abort = TRUE)
Authenticate key.
at line 598
static bool
authenticateScript(bool $abort = TRUE, string $name = NULL, string $pass = NULL, bool $storeInSession = TRUE, bool $loadCMSBootstrap = TRUE, bool $requireKey = TRUE)
Authenticate script.
at line 659
static false|array
authenticate(string $name, string $password, bool $loadCMSBootstrap = FALSE, string $realPath = NULL)
Authenticate the user against the uf db.
In case of successful authentication, returns an array consisting of (contactID, ufID, unique string). Returns FALSE if authentication is unsuccessful.
at line 686
static
setUFMessage(string $message)
Set a message in the UF to display to a user.
at line 699
static bool
isNull(mixed $value)
Determine whether a value is null-ish.
at line 727
static string
mungeCreditCard(string $number, int $keep = 4)
Obscure all but the last few digits of a credit card number.
at line 782
static mixed
getModuleSetting(string $pModuleName, string $pSetting)
Get a setting from a loaded PHP module.
at line 795
static mixed|string
memory(string $title = NULL)
Do something no-one bothered to document.
at line 819
static
download(string $name, string $mimeType, string $buffer, string $ext = NULL, bool $output = TRUE, string $disposition = 'attachment')
Download something or other.
at line 861
static
xMemory(string $title = NULL, bool $log = FALSE)
Gather and print (and possibly log) amount of used memory.
at line 887
static string
fixURL(string $url)
Take a URL (or partial URL) and make it better.
Currently, URLs pass straight through unchanged unless they are "seriously malformed" (see http://us2.php.net/parse_url).
at line 907
static bool
validCallback(string $callback)
Make sure a callback is valid in the current context.
at line 952
static string[]
explode(string $separator, string $string, int $limit)
Like PHP's built-in explode(), but always return an array of $limit items.
This serves as a wrapper to the PHP explode() function. In the event that PHP's explode() returns an array with fewer than $limit elements, pad the end of the array with NULLs.
at line 970
static mixed
checkURL(string $url, bool $addCookie = FALSE)
Check url.
at line 1000
static bool
checkPHPVersion(int $ver = 5, bool $abort = TRUE)
Assert that we are running on a particular PHP version.
at line 1022
static string
formatWikiURL(string $string, bool $encode = FALSE)
Format wiki url.
at line 1043
static null|string
urlEncode(string $url)
Encode url.
at line 1079
static string
version()
Return the running civicrm version.
at line 1106
static string
majorVersion()
Gives the first two parts of the version string E.g. 6.1.
at line 1119
static bool
isVersionFormatValid(string $version)
Determines whether a string is a valid CiviCRM version string.
at line 1126
static
getAllHeaders()
Wraps or emulates PHP's getallheaders() function.
at line 1154
static array|false
getRequestHeaders()
Get request headers.
at line 1169
static
isSSL()
Determine whether this is an SSL request.
Note that we inline this function in install/civicrm.php, so if you change this function, please go and change the code in the install script as well.
at line 1182
static
redirectToSSL(bool|FALSE $abort = FALSE)
Redirect to SSL.
at line 1222
static string
ipAddress(bool $strictIPV4 = TRUE)
Get logged in user's IP address.
Get IP address from HTTP REMOTE_ADDR header. If the CMS is Drupal then use the Drupal function as this also handles reverse proxies (based on proper configuration in settings.php)
at line 1255
static string
refererPath()
Get the referring / previous page URL.
at line 1265
static string
getDocBaseURL()
Get the documentation base URL.
at line 1276
static string
getWikiBaseURL()
Returns wiki (alternate) documentation URL base.
at line 1304
static string
docURL2(string $page, bool $URLonly = FALSE, string $text = NULL, string $title = NULL, string $style = NULL, null $resource = NULL)
Returns URL or link to documentation page, based on provided parameters.
For use in PHP code. WARNING: Always returns URL, if ts function is not defined ($URLonly has no effect).
at line 1341
static null|string
docURL(array $params)
Returns URL or link to documentation page, based on provided parameters.
For use in templates code.
at line 1388
static mixed
formatDocUrl($url)
Add language and version parameters to the doc url.
Note that this function may run before CiviCRM is initialized and so should not call ts() or perform any db lookups.
at line 1400
static
civiExit(int $status = 0, array $testParameters = [])
Exit with provided exit code.
at line 1425
static
flushCache()
Reset the various system caches and some important static variables.
at line 1480
static
loadBootStrap(array $params = [], bool $loadUser = TRUE, bool $throwError = TRUE, string $realPath = NULL)
Load CMS bootstrap.
at line 1497
static mixed|string
baseCMSURL()
Get Base CMS url.
at line 1545
static string
relativeURL(string $url)
Given a URL, return a relative URL if possible.
at line 1572
static string
absoluteURL(string $url, bool $removeLanguagePart = FALSE)
Produce an absolute URL from a possibly-relative URL.
at line 1598
static string
cleanUrl(string $url)
Clean url, replaces first '&' with '?'.
at line 1621
static string
languageNegotiationURL(string $url, bool $addLanguagePart = TRUE, bool $removeLanguagePart = FALSE)
Format the url as per language Negotiation.
at line 1643
static
appendTPLFile(string $fileName, string $content, string $overideFileName = NULL)
Append the contents of an 'extra' smarty template file.
It must be present in the custom template directory. This does not work if there are multiple custom template directories
at line 1678
static array
listIncludeFiles(string $relpath)
Get a list of all files that are found within the directories.
Files must be the result of appending the provided relative path to each component of the PHP include path.
at line 1717
static array
getPluginList(string $relpath, string $fext = '.php', array $skipList = [])
Get a list of all "plugins".
(PHP classes that implement a piece of functionality using a well-defined interface) that are found in a particular CiviCRM directory (both custom and core are searched).
at line 1735
static
executeScheduledJobs()
Execute scheduled jobs.
at line 1755
static string|FALSE
evalUrl(string|FALSE $url)
Evaluate any tokens in a URL.
at line 1781
static string
getSiteID()
Returns the unique identifier for this site, as used by community messages.
SiteID will be generated if it is not already stored in the settings table.
at line 1796
static bool
isDevelopment()
Determine whether this is a developmental system.
at line 1810
static bool
isInUpgradeMode()
Is in upgrade mode.
at line 1840
static array|NULL
createDefaultCrudLink(array $crudLinkSpec)
Determine the standard URL for viewing or editing the specified link.
This function delegates the decision-making to (a) the hook system and (b) the BAO system.
at line 1878
static
sendResponse(ResponseInterface $response)
Return an HTTP Response with appropriate content and status code set.
at line 57
static
appendBreadCrumb(array $breadCrumbs)
Append an additional breadcrumb tag to the existing breadcrumbs.
at line 57
static
resetBreadCrumb()
Reset an additional breadcrumb tag to the existing breadcrumb.
at line 57
static
addHTMLHead(string $bc)
Append a string to the head of the HTML file.
at line 57
static
setHttpHeader(string $name, string $value)
Set http header.
at line 57
static
appendCoreResources(GenericHookEvent $e)
Callback for hook_civicrm_coreResourceList.
at line 57
static
alterAssetUrl(GenericHookEvent $e)
Callback for hook_civicrm_getAssetUrl.