X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FUtils%2FSystem.php;h=91fc83dd25e7078316edb8e0160eb4b5d93480ab;hb=d44c681d9105af668449d16d9f53832d7982f47e;hp=d42f699ac17cc2d828cc76ee18f50eebe99ca824;hpb=252e6dbc5d4e377efeff99ee785276ca36e690b8;p=civicrm-core.git diff --git a/CRM/Utils/System.php b/CRM/Utils/System.php index d42f699ac1..91fc83dd25 100644 --- a/CRM/Utils/System.php +++ b/CRM/Utils/System.php @@ -183,6 +183,8 @@ class CRM_Utils_System { * @param bool $maintenance * (optional) For maintenance mode. * + * @return string + * * @access public */ static function theme( @@ -252,6 +254,18 @@ class CRM_Utils_System { return $config->userSystem->url($path, $query, $absolute, $fragment, $htmlize, $frontend, $forceBackend); } + /** + * @param $text + * @param null $path + * @param null $query + * @param bool $absolute + * @param null $fragment + * @param bool $htmlize + * @param bool $frontend + * @param bool $forceBackend + * + * @return string + */ static function href($text, $path = NULL, $query = NULL, $absolute = TRUE, $fragment = NULL, $htmlize = TRUE, $frontend = FALSE, $forceBackend = FALSE ) { @@ -259,11 +273,17 @@ class CRM_Utils_System { return "$text"; } + /** + * @return mixed + */ static function permissionDenied() { $config = CRM_Core_Config::singleton(); return $config->userSystem->permissionDenied(); } + /** + * @return mixed + */ static function logout() { $config = CRM_Core_Config::singleton(); return $config->userSystem->logout(); @@ -959,9 +979,10 @@ class CRM_Utils_System { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // lets capture the return stuff rather than echo - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE ); - return curl_exec($ch); + // CRM-13227, CRM-14744: only return the SSL error status + return (curl_exec($ch) !== FALSE); } /** @@ -1146,7 +1167,7 @@ class CRM_Utils_System { return (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) && - strtolower($_SERVER['HTTPS']) != 'off') ? true : false; + strtolower($_SERVER['HTTPS']) != 'off') ? TRUE : FALSE; } /** @@ -1188,6 +1209,11 @@ class CRM_Utils_System { * @return string * IP address of logged in user. */ + /** + * @param bool $strictIPV4 + * + * @return mixed|string + */ static function ipAddress($strictIPV4 = TRUE) { $address = CRM_Utils_Array::value('REMOTE_ADDR', $_SERVER); @@ -1369,7 +1395,7 @@ class CRM_Utils_System { * Response from URL. */ static function getServerResponse($url, $addCookie = TRUE) { - $errorScope = CRM_Core_TemporaryErrorScope::ignoreException(); + CRM_Core_TemporaryErrorScope::ignoreException(); require_once 'HTTP/Request.php'; $request = new HTTP_Request($url); @@ -1493,8 +1519,7 @@ class CRM_Utils_System { * @param bool $throwError * @param $realPath */ - static function loadBootStrap($params = array( - ), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) { + static function loadBootStrap($params = array(), $loadUser = TRUE, $throwError = TRUE, $realPath = NULL) { if (!is_array($params)) { $params = array(); } @@ -1596,7 +1621,6 @@ class CRM_Utils_System { * @param string $url * @param bool $removeLanguagePart * - * @internal param bool $remoteLanguagePart * @return string */ static function absoluteURL($url, $removeLanguagePart = FALSE) { @@ -1618,7 +1642,7 @@ class CRM_Utils_System { } /** - * Function to clean url, replaces first '&' with '?' + * clean url, replaces first '&' with '?' * * @param string $url * @@ -1740,10 +1764,9 @@ class CRM_Utils_System { * each element. * @access public */ - static function getPluginList($relpath, $fext = '.php', $skipList = array( - )) { - $fext_len = strlen($fext); - $plugins = array(); + static function getPluginList($relpath, $fext = '.php', $skipList = array()) { + $fext_len = strlen($fext); + $plugins = array(); $inc_files = CRM_Utils_System::listIncludeFiles($relpath); foreach ($inc_files as $inc_file) { if (substr($inc_file, 0 - $fext_len) == $fext) { @@ -1816,6 +1839,9 @@ class CRM_Utils_System { return $cache; } + /** + * @return bool + */ static function isInUpgradeMode() { $args = explode('/', $_GET['q']); $upgradeInProcess = CRM_Core_Session::singleton()->get('isUpgradePending'); @@ -1826,4 +1852,54 @@ class CRM_Utils_System { return FALSE; } } -} \ No newline at end of file + + /** + * 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. + * + * @param array $crudLinkSpec with keys: + * - action: int, CRM_Core_Action::UPDATE or CRM_Core_Action::VIEW [default: VIEW] + * - entity_table: string, eg "civicrm_contact" + * - entity_id: int + * @return array|NULL NULL if unavailable, or an array. array has keys: + * - path: string + * - query: array + * - title: string + * - url: string + */ + static function createDefaultCrudLink($crudLinkSpec) { + $crudLinkSpec['action'] = CRM_Utils_Array::value('action', $crudLinkSpec, CRM_Core_Action::VIEW); + $daoClass = CRM_Core_DAO_AllCoreTables::getClassForTable($crudLinkSpec['entity_table']); + if (!$daoClass) { + return NULL; + } + + $baoClass = str_replace('_DAO_', '_BAO_', $daoClass); + if (!class_exists($baoClass)) { + return NULL; + } + + $bao = new $baoClass(); + $bao->id = $crudLinkSpec['entity_id']; + if (!$bao->find(TRUE)) { + return NULL; + } + + $link = array(); + CRM_Utils_Hook::crudLink($crudLinkSpec, $bao, $link); + if (empty($link) && is_callable(array($bao, 'createDefaultCrudLink'))) { + $link = $bao->createDefaultCrudLink($crudLinkSpec); + } + + if (!empty($link)) { + if (!isset($link['url'])) { + $link['url'] = self::url($link['path'], $link['query'], TRUE, NULL, FALSE); + } + return $link; + } + + return NULL; + } +}