| ');
$phpinfo = preg_replace('/ | ]*>([^<]+)<\/th>/', '\\1', $phpinfo);
$phpinfo = preg_replace('/ | ]*>([^<]+)<\/td>/', '\\1', $phpinfo);
$parsedInfo = preg_split('/([^<]+<\/h.>)/', $phpinfo, -1, PREG_SPLIT_DELIM_CAPTURE);
$match = '';
$version = '';
$returnInfo = array();
if (preg_match('/PHP Version ([^<]+)<\/h1>/', $phpinfo, $version)) {
$returnInfo['PHP Version'] = $version[1];
}
for ($i = 1; $i < count($parsedInfo); ++$i) {
if (preg_match('/([^<]+)<\/h.>/', $parsedInfo[$i], $match)) {
$vName = trim($match[1]);
$parsedInfo2 = explode("\n", $parsedInfo[$i + 1]);
foreach ($parsedInfo2 as $vOne) {
$vPat = '([^<]+)<\/info>';
$vPat3 = "/$vPat\s*$vPat\s*$vPat/";
$vPat2 = "/$vPat\s*$vPat/";
if (preg_match($vPat3, $vOne, $match)) { // 3cols
$returnInfo[$vName][trim($match[1])] = array(trim($match[2]), trim($match[3]));
} elseif (preg_match($vPat2, $vOne, $match)) { // 2cols
$returnInfo[$vName][trim($match[1])] = trim($match[2]);
}
}
} elseif (true) {
}
}
return $returnInfo;
}
/**
* This function will take a string that has tokens like {0}, {1} and will replace
* those tokens with the args provided.
*
* @param $format string to format
* @param $args args to replace
*
* @return $result a formatted string
*/
function string_format($format, $args, $escape = true)
{
$result = $format;
/* Bug47277 fix.
* If args array has only one argument, and it's empty, so empty single quotes are used '' . That's because
* IN () fails and IN ('') works.
*/
if (count($args) == 1) {
reset($args);
$singleArgument = current($args);
if (empty($singleArgument)) {
return str_replace('{0}', "''", $result);
}
}
/* End of fix */
if ($escape) {
$db = DBManagerFactory::getInstance();
}
for ($i = 0; $i < count($args); ++$i) {
if (strpos($args[$i], ',') !== false) {
$values = explode(',', $args[$i]);
if ($escape) {
foreach ($values as &$value) {
$value = $db->quote($value);
}
}
$args[$i] = implode("','", $values);
$result = str_replace('{'.$i.'}', $args[$i], $result);
}
else if ($escape){
$result = str_replace('{'.$i.'}', $db->quote($args[$i]), $result);
}
else{
$result = str_replace('{'.$i.'}', $args[$i], $result);
}
}
return $result;
}
/**
* Generate a string for displaying a unique identifier that is composed
* of a system_id and number. This is use to allow us to generate quote
* numbers using a DB auto-increment key from offline clients and still
* have the number be unique (since it is modified by the system_id.
*
* @deprecated This function is unused and will be removed in a future release.
*
* @param $num of bean
* @param $system_id from system
*
* @return $result a formatted string
*/
function format_number_display($num, $system_id)
{
global $sugar_config;
if (isset($num) && !empty($num)) {
$num = unformat_number($num);
if (isset($system_id) && $system_id == 1) {
return sprintf('%d', $num);
}
return sprintf('%d-%d', $num, $system_id);
}
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function checkLoginUserStatus()
{
}
/**
* This function will take a number and system_id and format.
*
* @param $url URL containing host to append port
* @param $port the port number - if '' is passed, no change to url
*
* @return $resulturl the new URL with the port appended to the host
*/
function appendPortToHost($url, $port)
{
$resulturl = $url;
// if no port, don't change the url
if ($port != '') {
$split = explode('/', $url);
//check if it starts with http, in case they didn't include that in url
if (str_begin($url, 'http')) {
//third index ($split[2]) will be the host
$split[2] .= ':' . $port;
} else {
// otherwise assumed to start with host name
//first index ($split[0]) will be the host
$split[0] .= ':' . $port;
}
$resulturl = implode('/', $split);
}
return $resulturl;
}
/**
* Singleton to return JSON object.
*
* @return JSON object
*/
function getJSONobj()
{
static $json = null;
if (!isset($json)) {
require_once 'include/JSON.php';
$json = new JSON();
}
return $json;
}
require_once 'include/utils/db_utils.php';
/**
* Set default php.ini settings for entry points.
*/
function setPhpIniSettings()
{
// zlib module
// Bug 37579 - Comment out force enabling zlib.output_compression, since it can cause problems on certain hosts
/*
if(function_exists('gzclose') && headers_sent() == false) {
ini_set('zlib.output_compression', 1);
}
*/
// mbstring module
//nsingh: breaks zip/unzip functionality. Commenting out 4/23/08
/* if(function_exists('mb_strlen')) {
ini_set('mbstring.func_overload', 7);
ini_set('mbstring.internal_encoding', 'UTF-8');
} */
// http://us3.php.net/manual/en/ref.pcre.php#ini.pcre.backtrack-limit
// starting with 5.2.0, backtrack_limit breaks JSON decoding
$backtrack_limit = ini_get('pcre.backtrack_limit');
if (!empty($backtrack_limit)) {
ini_set('pcre.backtrack_limit', '-1');
}
}
/**
* Identical to sugarArrayMerge but with some speed improvements and used specifically to merge
* language files. Language file merges do not need to account for null values so we can get some
* performance increases by using this specialized function. Note this merge function does not properly
* handle null values.
*
* @param $gimp
* @param $dom
*
* @return array
*/
function sugarLangArrayMerge($gimp, $dom)
{
if (is_array($gimp) && is_array($dom)) {
foreach ($dom as $domKey => $domVal) {
if (isset($gimp[$domKey])) {
if (is_array($domVal)) {
$tempArr = array();
foreach ($domVal as $domArrKey => $domArrVal) {
$tempArr[$domArrKey] = $domArrVal;
}
foreach ($gimp[$domKey] as $gimpArrKey => $gimpArrVal) {
if (!isset($tempArr[$gimpArrKey])) {
$tempArr[$gimpArrKey] = $gimpArrVal;
}
}
$gimp[$domKey] = $tempArr;
} else {
$gimp[$domKey] = $domVal;
}
} else {
$gimp[$domKey] = $domVal;
}
}
} // if the passed value for gimp isn't an array, then return the $dom
elseif (is_array($dom)) {
return $dom;
}
return $gimp;
}
/**
* like array_merge() but will handle array elements that are themselves arrays;
* PHP's version just overwrites the element with the new one.
*
* @internal Note that this function deviates from the internal array_merge()
* functions in that it does does not treat numeric keys differently
* than string keys. Additionally, it deviates from
* array_merge_recursive() by not creating an array when like values
* found.
*
* @param array gimp the array whose values will be overloaded
* @param array dom the array whose values will pwn the gimp's
*
* @return array beaten gimp
*/
function sugarArrayMerge($gimp, $dom)
{
if (is_array($gimp) && is_array($dom)) {
foreach ($dom as $domKey => $domVal) {
if (array_key_exists($domKey, $gimp)) {
if (is_array($domVal)) {
$tempArr = array();
foreach ($domVal as $domArrKey => $domArrVal) {
$tempArr[$domArrKey] = $domArrVal;
}
foreach ($gimp[$domKey] as $gimpArrKey => $gimpArrVal) {
if (!array_key_exists($gimpArrKey, $tempArr)) {
$tempArr[$gimpArrKey] = $gimpArrVal;
}
}
$gimp[$domKey] = $tempArr;
} else {
$gimp[$domKey] = $domVal;
}
} else {
$gimp[$domKey] = $domVal;
}
}
} // if the passed value for gimp isn't an array, then return the $dom
elseif (is_array($dom)) {
return $dom;
}
return $gimp;
}
/**
* Similiar to sugarArrayMerge except arrays of N depth are merged.
*
* @param array gimp the array whose values will be overloaded
* @param array dom the array whose values will pwn the gimp's
*
* @return array beaten gimp
*/
function sugarArrayMergeRecursive($gimp, $dom)
{
if (is_array($gimp) && is_array($dom)) {
foreach ($dom as $domKey => $domVal) {
if (array_key_exists($domKey, $gimp)) {
if (is_array($domVal) && is_array($gimp[$domKey])) {
$gimp[$domKey] = sugarArrayMergeRecursive($gimp[$domKey], $domVal);
} else {
$gimp[$domKey] = $domVal;
}
} else {
$gimp[$domKey] = $domVal;
}
}
} // if the passed value for gimp isn't an array, then return the $dom
elseif (is_array($dom)) {
return $dom;
}
return $gimp;
}
/**
* Finds the correctly working versions of PHP-JSON.
* @deprecated This function is unused and will be removed in a future release.
*
* @return bool True if NOT found or WRONG version
*/
function returnPhpJsonStatus()
{
if (function_exists('json_encode')) {
$phpInfo = getPhpInfo(8);
return version_compare($phpInfo['json']['json version'], '1.1.1', '<');
}
return true; // not found
}
/**
* getTrackerSubstring.
*
* Returns a [number]-char or less string for the Tracker to display in the header
* based on the tracker_max_display_length setting in config.php. If not set,
* or invalid length, then defaults to 15 for COM editions, 30 for others.
*
* @param string name field for a given Object
*
* @return string [number]-char formatted string if length of string exceeds the max allowed
*/
function getTrackerSubstring($name)
{
static $max_tracker_item_length;
//Trim the name
$name = html_entity_decode($name, ENT_QUOTES, 'UTF-8');
$strlen = function_exists('mb_strlen') ? mb_strlen($name) : strlen($name);
global $sugar_config;
if (!isset($max_tracker_item_length)) {
if (isset($sugar_config['tracker_max_display_length'])) {
$max_tracker_item_length = (is_int($sugar_config['tracker_max_display_length']) && $sugar_config['tracker_max_display_length'] > 0 && $sugar_config['tracker_max_display_length'] < 50) ? $sugar_config['tracker_max_display_length'] : 15;
} else {
$max_tracker_item_length = 15;
}
}
if ($strlen > $max_tracker_item_length) {
$chopped = function_exists('mb_substr') ? mb_substr($name, 0, $max_tracker_item_length - 3, 'UTF-8') : substr($name, 0, $max_tracker_item_length - 3);
$chopped .= '...';
} else {
$chopped = $name;
}
return $chopped;
}
/**
* @param array $field_list
* @param array $values
* @param array $bean
* @param bool $add_custom_fields
* @param string $module
* @return array
*/
function generate_search_where(
$field_list,
$values,
&$bean = null,
$add_custom_fields = false,
$module = ''
) {
$where_clauses = array();
$like_char = '%';
$table_name = $bean->object_name;
foreach ($field_list[$module] as $field => $parms) {
if (isset($values[$field]) && $values[$field] != '') {
$operator = 'like';
if (!empty($parms['operator'])) {
$operator = $parms['operator'];
}
if (is_array($values[$field])) {
$operator = 'in';
$field_value = '';
foreach ($values[$field] as $key => $val) {
if ($val != ' ' and $val != '') {
if (!empty($field_value)) {
$field_value .= ',';
}
$field_value .= "'" . DBManagerFactory::getInstance()->quote($val) . "'";
}
}
} else {
$field_value = DBManagerFactory::getInstance()->quote($values[$field]);
}
//set db_fields array.
if (!isset($parms['db_field'])) {
$parms['db_field'] = array($field);
}
if (isset($parms['my_items']) and $parms['my_items'] == true) {
global $current_user;
$field_value = DBManagerFactory::getInstance()->quote($current_user->id);
$operator = '=';
}
$where = '';
$itr = 0;
if ($field_value != '') {
foreach ($parms['db_field'] as $db_field) {
if (strstr($db_field, '.') === false) {
$db_field = $bean->table_name . '.' . $db_field;
}
if (DBManagerFactory::getInstance()->supports('case_sensitive') && isset($parms['query_type']) && $parms['query_type'] == 'case_insensitive') {
$db_field = 'upper(' . $db_field . ')';
$field_value = strtoupper($field_value);
}
++$itr;
if (!empty($where)) {
$where .= ' OR ';
}
switch (strtolower($operator)) {
case 'like':
$where .= $db_field . " like '" . $field_value . $like_char . "'";
break;
case 'in':
$where .= $db_field . ' in (' . $field_value . ')';
break;
case '=':
$where .= $db_field . " = '" . $field_value . "'";
break;
}
}
}
if (!empty($where)) {
if ($itr > 1) {
array_push($where_clauses, '( ' . $where . ' )');
} else {
array_push($where_clauses, $where);
}
}
}
}
if ($add_custom_fields) {
require_once 'modules/DynamicFields/DynamicField.php';
$bean->setupCustomFields($module);
$bean->custom_fields->setWhereClauses($where_clauses);
}
return $where_clauses;
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function add_quotes($str)
{
return "'{$str}'";
}
/**
* This function will rebuild the config file.
*
* @param $sugar_config
* @param $sugar_version
*
* @return bool true if successful
*/
function rebuildConfigFile($sugar_config, $sugar_version)
{
// add defaults to missing values of in-memory sugar_config
$sugar_config = sugarArrayMerge(get_sugar_config_defaults(), $sugar_config);
// need to override version with default no matter what
$sugar_config['sugar_version'] = $sugar_version;
ksort($sugar_config);
if (write_array_to_file('sugar_config', $sugar_config, 'config.php')) {
return true;
}
return false;
}
/**
* Loads clean configuration, not overridden by config_override.php.
*
* @return array
*/
function loadCleanConfig()
{
$sugar_config = array();
require 'config.php';
return $sugar_config;
}
/**
* getJavascriptSiteURL
* This function returns a URL for the client javascript calls to access
* the site. It uses $_SERVER['HTTP_REFERER'] in the event that Proxy servers
* are used to access the site. Thus, the hostname in the URL returned may
* not always match that of $sugar_config['site_url']. Basically, the
* assumption is that however the user accessed the website is how they
* will continue to with subsequent javascript requests. If the variable
* $_SERVER['HTTP_REFERER'] is not found then we default to old algorithm.
*
* @return $site_url The url used to refer to the website
*/
function getJavascriptSiteURL()
{
global $sugar_config;
if (!empty($_SERVER['HTTP_REFERER'])) {
$url = parse_url($_SERVER['HTTP_REFERER']);
$replacement_url = $url['scheme'] . '://' . $url['host'];
if (!empty($url['port'])) {
$replacement_url .= ':' . $url['port'];
}
$site_url = preg_replace('/^http[s]?\:\/\/[^\/]+/', $replacement_url, $sugar_config['site_url']);
} else {
$site_url = preg_replace('/^http(s)?\:\/\/[^\/]+/', 'http$1://' . $_SERVER['HTTP_HOST'], $sugar_config['site_url']);
if (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') {
$site_url = preg_replace('/^http\:/', 'https:', $site_url);
}
}
$GLOBALS['log']->debug('getJavascriptSiteURL(), site_url=' . $site_url);
return $site_url;
}
/**
* Works nicely with array_map() -- can be used to wrap single quotes around
* each element in an array.
*
* @deprecated This function is unused and will be removed in a future release.
*/
function add_squotes($str)
{
return "'" . $str . "'";
}
/**
* Recursive function to count the number of levels within an array.
* @deprecated This function is unused and will be removed in a future release.
*/
function array_depth($array, $depth_count = -1, $depth_array = array())
{
++$depth_count;
if (is_array($array)) {
foreach ($array as $key => $value) {
$depth_array[] = array_depth($value, $depth_count);
}
} else {
return $depth_count;
}
foreach ($depth_array as $value) {
$depth_count = $value > $depth_count ? $value : $depth_count;
}
return $depth_count;
}
/**
* Creates a new Group User.
*
* @param string $name Name of Group User
*
* @return string GUID of new Group User
*/
function createGroupUser($name)
{
$group = BeanFactory::newBean('Users');
$group->user_name = $name;
$group->last_name = $name;
$group->is_group = 1;
$group->deleted = 0;
$group->status = 'Active'; // cn: bug 6711
$group->setPreference('timezone', TimeDate::userTimezone());
$group->save();
return $group->id;
}
/*
* Helper function to locate an icon file given only a name
* Searches through the various paths for the file
* @param string iconFileName The filename of the icon
* @return string Relative pathname of the located icon, or '' if not found
*/
function _getIcon($iconFileName)
{
if (file_exists(SugarThemeRegistry::current()->getImagePath() . DIRECTORY_SEPARATOR . 'icon_' . $iconFileName . '.svg')) {
$iconName = "icon_{$iconFileName}.svg";
$iconFound = SugarThemeRegistry::current()->getImageURL($iconName, false);
} else {
$iconName = "icon_{$iconFileName}.gif";
$iconFound = SugarThemeRegistry::current()->getImageURL($iconName, false);
}
//First try un-ucfirst-ing the icon name
if (empty($iconFound)) {
$iconName = 'icon_' . strtolower(substr($iconFileName, 0, 1)) . substr($iconFileName, 1) . '.gif';
}
$iconFound = SugarThemeRegistry::current()->getImageURL($iconName, false);
//Next try removing the icon prefix
if (empty($iconFound)) {
$iconName = "{$iconFileName}.gif";
}
$iconFound = SugarThemeRegistry::current()->getImageURL($iconName, false);
if (empty($iconFound)) {
$iconName = '';
}
return $iconName;
}
/**
* Function to grab the correct icon image for Studio.
*
* @param string $iconFileName Name of the icon file
* @param string $altfilename Name of a fallback icon file (displayed if the imagefilename doesn't exist)
* @param string $width Width of image
* @param string $height Height of image
* @param string $align Alignment of image
* @param string $alt Alt tag of image
*
* @return string $string tag with corresponding image
*/
function getStudioIcon($iconFileName = '', $altFileName = '', $width = '48', $height = '48', $align = 'baseline', $alt = '')
{
global $app_strings, $theme;
$iconName = _getIcon($iconFileName);
if (empty($iconName)) {
$iconName = _getIcon($altFileName);
if (empty($iconName)) {
return $app_strings['LBL_NO_IMAGE'];
}
}
return SugarThemeRegistry::current()->getImage($iconName, "align=\"$align\" border=\"0\"", $width, $height);
}
/**
* Function to grab the correct icon image for Dashlets Dialog.
*
* @param string $filename Location of the icon file
* @param string $module Name of the module to fall back onto if file does not exist
* @param string $width Width of image
* @param string $height Height of image
* @param string $align Alignment of image
* @param string $alt Alt tag of image
*
* @return string $string tag with corresponding image
*/
function get_dashlets_dialog_icon($module = '', $width = '32', $height = '32', $align = 'absmiddle', $alt = '')
{
global $app_strings, $theme;
$iconName = _getIcon($module . '_32');
if (empty($iconName)) {
$iconName = _getIcon($module);
}
if (empty($iconName)) {
return $app_strings['LBL_NO_IMAGE'];
}
return $iconName;
}
// works nicely to change UTF8 strings that are html entities - good for PDF conversions
function html_entity_decode_utf8($string)
{
static $trans_tbl;
// replace numeric entities
//php will have issues with numbers with leading zeros, so do not include them in what we send to code2utf.
$string = preg_replace_callback('~*([0-9a-f]+);~i', function ($matches) {
return code2utf(hexdec($matches[1]));
}, $string);
$string = preg_replace_callback('~*([0-9]+);~', function ($matches) {
return code2utf($matches[1]);
}, $string);
// replace literal entities
if (!isset($trans_tbl)) {
$trans_tbl = array();
foreach (get_html_translation_table(HTML_ENTITIES) as $val => $key) {
$trans_tbl[$key] = utf8_encode($val);
}
}
return strtr($string, $trans_tbl);
}
// Returns the utf string corresponding to the unicode value
function code2utf($num)
{
if ($num < 128) {
return chr($num);
}
if ($num < 2048) {
return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
}
if ($num < 65536) {
return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
}
if ($num < 2097152) {
return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
}
return '';
}
/*
* @deprecated use DBManagerFactory::isFreeTDS
*/
function is_freetds()
{
return DBManagerFactory::isFreeTDS();
}
/**
* Chart dashlet helper function that returns the correct CSS file, dependent on the current theme.
*
* @deprecated This function is unused and will be removed in a future release.
*
* @todo this won't work completely right until we impliment css compression and combination
* for now, we'll just include the last css file found.
*
* @return chart.css file to use
*/
function chartStyle()
{
return SugarThemeRegistry::current()->getCSSURL('chart.css');
}
/**
* Chart dashlet helper functions that returns the correct XML color file for charts,
* dependent on the current theme.
*
* @deprecated This function is unused and will be removed in a future release.
* @return sugarColors.xml to use
*/
function chartColors()
{
if (SugarThemeRegistry::current()->getCSSURL('sugarColors.xml') == '') {
return SugarThemeRegistry::current()->getImageURL('sugarColors.xml');
}
return SugarThemeRegistry::current()->getCSSURL('sugarColors.xml');
}
/* End Chart Dashlet helper functions */
/**
* This function is designed to set up the php enviroment
* for AJAX requests.
*
* @deprecated This function is unused and will be removed in a future release.
*/
function ajaxInit()
{
//ini_set('display_errors', 'false');
}
/**
* Returns an absolute path from the given path, determining if it is relative or absolute.
*
* @param string $path
*
* @return string
*/
function getAbsolutePath(
$path,
$currentServer = false
) {
$path = trim($path);
// try to match absolute paths like \\server\share, /directory or c:\
if ((substr($path, 0, 2) == '\\\\') || ($path[0] == '/') || preg_match('/^[A-z]:/i', $path) || $currentServer
) {
return $path;
}
return getcwd() . '/' . $path;
}
/**
* Returns the bean object of the given module.
*
* @deprecated use SugarModule::loadBean() instead
*
* @param string $module
*
* @return object
*/
function loadBean(
$module
) {
return SugarModule::get($module)->loadBean();
}
/**
* Returns true if the application is being accessed on a touch screen interface ( like an iPad ).
*/
function isTouchScreen()
{
$ua = empty($_SERVER['HTTP_USER_AGENT']) ? 'undefined' : strtolower($_SERVER['HTTP_USER_AGENT']);
// first check if we have forced use of the touch enhanced interface
if (isset($_COOKIE['touchscreen']) && $_COOKIE['touchscreen'] == '1') {
return true;
}
// next check if we should use the touch interface with our device
if (strpos($ua, 'ipad') !== false) {
return true;
}
return false;
}
/**
* Returns the shortcut keys to access the shortcut links. Shortcut
* keys vary depending on browser versions and operating systems.
*
* @return string value of the shortcut keys
*/
function get_alt_hot_key()
{
$ua = '';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
}
$isMac = strpos($ua, 'mac') !== false;
$isLinux = strpos($ua, 'linux') !== false;
if (!$isMac && !$isLinux && strpos($ua, 'mozilla') !== false) {
if (preg_match('/firefox\/(\d)?\./', $ua, $matches)) {
return $matches[1] < 2 ? 'Alt+' : 'Alt+Shift+';
}
}
return $isMac ? 'Ctrl+' : 'Alt+';
}
function can_start_session()
{
if (!empty($_GET[session_name()])) {
return true;
}
$session_id = session_id();
return empty($session_id) ? true : false;
}
function load_link_class($properties)
{
$class = 'Link2';
if (!empty($properties['link_class']) && !empty($properties['link_file'])) {
if (!file_exists($properties['link_file'])) {
$GLOBALS['log']->fatal('File not found: ' . $properties['link_file']);
} else {
require_once $properties['link_file'];
$class = $properties['link_class'];
}
}
return $class;
}
function inDeveloperMode()
{
return isset($GLOBALS['sugar_config']['developerMode']) && $GLOBALS['sugar_config']['developerMode'];
}
/**
* Filter the protocol list for inbound email accounts.
*
* @param array $protocol
*/
function filterInboundEmailPopSelection($protocol)
{
if (!isset($GLOBALS['sugar_config']['allow_pop_inbound']) || !$GLOBALS['sugar_config']['allow_pop_inbound']) {
if (isset($protocol['pop3'])) {
unset($protocol['pop3']);
}
} else {
$protocol['pop3'] = 'POP3';
}
return $protocol;
}
/**
* Get Inbound Email protocols
*
* @return array
*/
function getInboundEmailProtocols(): array
{
global $app_list_strings, $sugar_config;
$protocols = $app_list_strings['dom_email_server_type'];
if (!isset($sugar_config['allow_pop_inbound']) || !$sugar_config['allow_pop_inbound']) {
if (isset($protocols['pop3'])) {
unset($protocols['pop3']);
}
} else {
$protocols['pop3'] = 'POP3';
}
return $protocols;
}
/**
* The function is used because currently we are not supporting mbstring.func_overload
* For some user using mssql without FreeTDS, they may store multibyte charaters in varchar using latin_general collation. It cannot store so many mutilbyte characters, so we need to use strlen.
* The varchar in MySQL, Orcale, and nvarchar in FreeTDS, we can store $length mutilbyte charaters in it. we need mb_substr to keep more info.
*
* @returns the substred strings.
*/
function sugar_substr($string, $length, $charset = 'UTF-8')
{
if (mb_strlen($string, $charset) > $length) {
$string = trim(mb_substr(trim($string), 0, $length, $charset));
}
return $string;
}
/**
* The function is used because on FastCGI enviroment, the ucfirst(Chinese Characters) will produce bad charcters.
* This will work even without setting the mbstring.*encoding.
*/
function sugar_ucfirst($string, $charset = 'UTF-8')
{
return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset) . mb_substr($string, 1, mb_strlen($string), $charset);
}
/**
* Given a multienum encoded as a string, convert it to an array of strings,
* e.g. `"^Monday^,^Tuesday^,^Wednesday^,^Thursday^"` becomes
* `["Monday", "Tuesday", "Wednesday", "Thursday"]`.
*
* @param string|string[] $string The encoded multienum value. If this is already an array, the array will be returned unchanged.
* @return string[] An array of strings representing the multienum's values.
*/
function unencodeMultienum($string)
{
if (is_array($string)) {
return $string;
}
if (substr($string, 0, 1) == '^' && substr($string, -1) == '^') {
$string = substr(substr($string, 1), 0, strlen($string) - 2);
}
return explode('^,^', $string);
}
function encodeMultienumValue($arr)
{
if (!is_array($arr)) {
return $arr;
}
if (empty($arr)) {
return '';
}
$string = '^' . implode('^,^', $arr) . '^';
return $string;
}
/**
* create_export_query is used for export and massupdate
* We haven't handle the these fields: $field['type'] == 'relate' && isset($field['link']
* This function will correct the where clause and output necessary join condition for them.
*
* @param $module : the module name
* @param $searchFields : searchFields which is got after $searchForm->populateFromArray()
* @param $where : where clauses
*
* @return array
*/
function create_export_query_relate_link_patch($module, $searchFields, $where)
{
if (file_exists('modules/' . $module . '/SearchForm.html')) {
$ret_array['where'] = $where;
return $ret_array;
}
$seed = BeanFactory::getBean($module);
foreach ($seed->field_defs as $name => $field) {
if ($field['type'] == 'relate' && isset($field['link']) && !empty($searchFields[$name]['value'])) {
$seed->load_relationship($field['link']);
$params = array();
if (empty($join_type)) {
$params['join_type'] = ' LEFT JOIN ';
} else {
$params['join_type'] = $join_type;
}
if (isset($data['join_name'])) {
$params['join_table_alias'] = $field['join_name'];
} else {
$params['join_table_alias'] = 'join_' . $field['name'];
}
if (isset($data['join_link_name'])) {
$params['join_table_link_alias'] = $field['join_link_name'];
} else {
$params['join_table_link_alias'] = 'join_link_' . $field['name'];
}
$fieldLink = $field['link'];
$join = $seed->$fieldLink->getJoin($params, true);
$join_table_alias = 'join_' . $field['name'];
if (isset($field['db_concat_fields'])) {
$db_field = DBManager::concat($join_table_alias, $field['db_concat_fields']);
$where = preg_replace('/' . $field['name'] . '/', $db_field, $where);
} else {
$where = preg_replace('/(^|[\s(])' . $field['name'] . '/', '${1}' . $join_table_alias . '.' . $field['rname'], $where);
}
}
}
$ret_array = array('where' => $where, 'join' => isset($join['join']) ? $join['join'] : '');
return $ret_array;
}
/**
* We need to clear all the js cache files, including the js language files in serval places in MB. So I extract them into a util function here.
*
* @Depends on QuickRepairAndRebuild.php
* @Relate bug 30642 ,23177
*/
function clearAllJsAndJsLangFilesWithoutOutput()
{
global $current_language, $mod_strings;
$MBmodStrings = $mod_strings;
$mod_strings = return_module_language($current_language, 'Administration');
include_once 'modules/Administration/QuickRepairAndRebuild.php';
$repair = new RepairAndClear();
$repair->module_list = array();
$repair->show_output = false;
$repair->clearJsLangFiles();
$repair->clearJsFiles();
$mod_strings = $MBmodStrings;
}
/**
* This function will allow you to get a variable value from query string.
*/
function getVariableFromQueryString($variable, $string)
{
$matches = array();
$number = preg_match("/{$variable}=([a-zA-Z0-9_-]+)[&]?/", $string, $matches);
if ($number) {
return $matches[1];
}
return false;
}
/**
* should_hide_iframes
* This is a helper method to determine whether or not to show iframes (My Sites) related
* information in the application.
*
* @return bool flag indicating whether or not iframes module should be hidden
*/
function should_hide_iframes()
{
//Remove the MySites module
if (file_exists('modules/iFrames/iFrame.php')) {
if (!class_exists('iFrame')) {
require_once 'modules/iFrames/iFrame.php';
}
return false;
}
return true;
}
/**
* Given a version such as 5.5.0RC1 return RC. If we have a version such as: 5.5 then return GA.
*
* @deprecated This function is unused and will be removed in a future release.
*
* @param string $version
* @return string RC, BETA, GA
*/
function getVersionStatus($version)
{
if (preg_match('/^[\d\.]+?([a-zA-Z]+?)[\d]*?$/si', $version, $matches)) {
return strtoupper($matches[1]);
}
return 'GA';
}
/**
* Return the numeric portion of a version. For example if passed 5.5.0RC1 then return 5.5. If given
* 5.5.1RC1 then return 5.5.1.
*
* @deprecated This function is unused and will be removed in a future release.
*
* @param string $version
*
* @return version
*/
function getMajorMinorVersion($version)
{
if (preg_match('/^([\d\.]+).*$/si', $version, $matches2)) {
$version = $matches2[1];
$arr = explode('.', $version);
if (count($arr) > 2) {
if ($arr[2] == '0') {
$version = substr($version, 0, 3);
}
}
}
return $version;
}
/**
* Return string composed of seconds & microseconds of current time, without dots.
*
* @return string
*/
function sugar_microtime()
{
$now = explode(' ', microtime());
$unique_id = $now[1] . str_replace('.', '', $now[0]);
return $unique_id;
}
/**
* Extract urls from a piece of text.
*
* @param $string
*
* @return array of urls found in $string
*/
function getUrls($string)
{
$lines = explode(' ', trim($string));
$urls = array();
foreach ($lines as $line) {
$regex = '/http?\:\/\/[^\" ]+/i';
preg_match_all($regex, $line, $matches);
foreach ($matches[0] as $match) {
$urls[] = $match;
}
}
return $urls;
}
/**
* Sanitize image file from hostile content.
*
* @param string $path Image file
* @param bool $jpeg Accept only JPEGs?
*/
function verify_image_file($path, $jpeg = false)
{
if (function_exists('imagepng') && function_exists('imagejpeg') && function_exists('imagecreatefromstring')) {
$img = imagecreatefromstring(file_get_contents($path));
if (!$img) {
return false;
}
$img_size = getimagesize($path);
$filetype = $img_size['mime'];
//if filetype is jpeg or if we are only allowing jpegs, create jpg image
if ($filetype == 'image/jpeg' || $jpeg) {
ob_start();
imagejpeg($img);
$image = ob_get_clean();
// not writing directly because imagejpeg does not work with streams
if (file_put_contents($path, $image)) {
return true;
}
} elseif ($filetype == 'image/png') {
// else if the filetype is png, create png
imagealphablending($img, true);
imagesavealpha($img, true);
ob_start();
imagepng($img);
$image = ob_get_clean();
if (file_put_contents($path, $image)) {
return true;
}
} else {
return false;
}
} else {
// check image manually
$fp = fopen($path, 'rb');
if (!$fp) {
return false;
}
$data = '';
// read the whole file in chunks
while (!feof($fp)) {
$data .= fread($fp, 8192);
}
fclose($fp);
if (preg_match("/<(\?php|html|!doctype|script|body|head|plaintext|table|img |pre(>| )|frameset|iframe|object|link|base|style|font|applet|meta|center|form|isindex)/i", $data, $m)) {
$GLOBALS['log']->fatal("Found {$m[0]} in $path, not allowing upload");
return false;
}
return true;
}
return false;
}
/**
* Verify uploaded image
* Verifies that image has proper extension, MIME type and doesn't contain hostile content.
*
* @param string $path Image path
* @param bool $jpeg_only Accept only JPEGs?
*/
function verify_uploaded_image($path, $jpeg_only = false)
{
$supportedExtensions = array('jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'tmp' => 'tmp');
if (!$jpeg_only) {
$supportedExtensions['png'] = 'image/png';
}
if (!file_exists($path) || !is_file($path)) {
return false;
}
$img_size = getimagesize($path);
$filetype = $img_size['mime'];
$tmpArray = explode('.', $path);
$ext = end($tmpArray);
if (substr_count('..', $path) > 0 || ($ext !== $path && !isset($supportedExtensions[strtolower($ext)])) ||
!in_array($filetype, array_values($supportedExtensions))
) {
return false;
}
return verify_image_file($path, $jpeg_only);
}
function cmp_beans($a, $b)
{
global $sugar_web_service_order_by;
//If the order_by field is not valid, return 0;
if (empty($sugar_web_service_order_by) || !isset($a->$sugar_web_service_order_by) || !isset($b->$sugar_web_service_order_by)) {
return 0;
}
if (is_object($a->$sugar_web_service_order_by) || is_object($b->$sugar_web_service_order_by) || is_array($a->$sugar_web_service_order_by) || is_array($b->$sugar_web_service_order_by)
) {
return 0;
}
if ($a->$sugar_web_service_order_by < $b->$sugar_web_service_order_by) {
return -1;
}
return 1;
}
function order_beans($beans, $field_name)
{
//Since php 5.2 doesn't include closures, we must use a global to pass the order field to cmp_beans.
global $sugar_web_service_order_by;
$sugar_web_service_order_by = $field_name;
usort($beans, 'cmp_beans');
return $beans;
}
/**
* Return search like string
* This function takes a user input string and returns a string that contains wild card(s) that can be used in db query.
*
* @param string $str string to be searched
* @param string $like_char Database like character, usually '%'
*
* @return string Returns a string to be searched in db query
*/
function sql_like_string($str, $like_char, $wildcard = '%', $appendWildcard = true)
{
// override default wildcard character
if (isset($GLOBALS['sugar_config']['search_wildcard_char']) &&
strlen($GLOBALS['sugar_config']['search_wildcard_char']) == 1
) {
$wildcard = $GLOBALS['sugar_config']['search_wildcard_char'];
}
// add wildcard at the beginning of the search string
if (isset($GLOBALS['sugar_config']['search_wildcard_infront']) &&
$GLOBALS['sugar_config']['search_wildcard_infront'] == true
) {
if (substr($str, 0, 1) != $wildcard) {
$str = $wildcard . $str;
}
}
// add wildcard at the end of search string (default)
if ($appendWildcard) {
if (substr($str, -1) != $wildcard) {
$str .= $wildcard;
}
}
return str_replace($wildcard, $like_char, $str);
}
//check to see if custom utils exists
if (file_exists('custom/include/custom_utils.php')) {
include_once 'custom/include/custom_utils.php';
}
//check to see if custom utils exists in Extension framework
if (file_exists('custom/application/Ext/Utils/custom_utils.ext.php')) {
include_once 'custom/application/Ext/Utils/custom_utils.ext.php';
}
/**
* @param $input - the input string to sanitize
* @param int $quotes - use quotes
* @param string $charset - the default charset
* @param bool $remove - strip tags or not
*
* @return string - the sanitized string
*/
function sanitize($input, $quotes = ENT_QUOTES, $charset = 'UTF-8', $remove = false)
{
return htmlentities($input, $quotes, $charset);
}
/**
* @return string - the full text search engine name
*/
function getFTSEngineType()
{
if (isset($GLOBALS['sugar_config']['full_text_engine']) && is_array($GLOBALS['sugar_config']['full_text_engine'])) {
foreach ($GLOBALS['sugar_config']['full_text_engine'] as $name => $defs) {
return $name;
}
}
return '';
}
/**
* @deprecated This function is unused and will be removed in a future release.
*
* @param string $optionName - name of the option to be retrieved from app_list_strings
* @return array - the array to be used in option element
*/
function getFTSBoostOptions($optionName)
{
if (isset($GLOBALS['app_list_strings'][$optionName])) {
return $GLOBALS['app_list_strings'][$optionName];
}
return array();
}
/**
* utf8_recursive_encode.
*
* This function walks through an Array and recursively calls utf8_encode on the
* values of each of the elements.
*
* @deprecated This function is unused and will be removed in a future release.
*
* @param $data Array of data to encode
*
* @return utf8 encoded Array data
*/
function utf8_recursive_encode($data)
{
$result = array();
foreach ($data as $key => $val) {
if (is_array($val)) {
$result[$key] = utf8_recursive_encode($val);
} else {
$result[$key] = utf8_encode($val);
}
}
return $result;
}
/**
* get_language_header.
*
* This is a utility function for 508 Compliance. It returns the lang=[Current Language] text string used
* inside the tag. If no current language is specified, it defaults to lang='en'.
*
* @return string The lang=[Current Language] markup to insert into the tag
*/
function get_language_header()
{
return isset($GLOBALS['current_language']) ? "lang='{$GLOBALS['current_language']}'" : "lang='en'";
}
/**
* get_custom_file_if_exists.
*
* This function handles the repetitive code we have where we first check if a file exists in the
* custom directory to determine whether we should load it, require it, include it, etc. This function returns the
* path of the custom file if it exists. It basically checks if custom/{$file} exists and returns this path if so;
* otherwise it return $file
*
* @param $file String of filename to check
*
* @return $file String of filename including custom directory if found
*/
function get_custom_file_if_exists($file)
{
return file_exists("custom/{$file}") ? "custom/{$file}" : $file;
}
/**
* get_help_url.
*
* This will return the URL used to redirect the user to the help documentation.
* It can be overriden completely by setting the custom_help_url or partially by setting the custom_help_base_url
* in config.php or config_override.php.
*
* @deprecated This function is unused and will be removed in a future release.
*
* @param string $send_edition
* @param string $send_version
* @param string $send_lang
* @param string $send_module
* @param string $send_action
* @param string $dev_status
* @param string $send_key
* @param string $send_anchor
*
* @return string the completed help URL
*/
function get_help_url($send_edition = '', $send_version = '', $send_lang = '', $send_module = '', $send_action = '', $dev_status = '', $send_key = '', $send_anchor = '')
{
global $sugar_config;
if (!empty($sugar_config['custom_help_url'])) {
$sendUrl = $sugar_config['custom_help_url'];
} else {
if (!empty($sugar_config['custom_help_base_url'])) {
$baseUrl = $sugar_config['custom_help_base_url'];
} else {
$baseUrl = 'http://www.sugarcrm.com/crm/product_doc.php';
}
$sendUrl = $baseUrl . "?edition={$send_edition}&version={$send_version}&lang={$send_lang}&module={$send_module}&help_action={$send_action}&status={$dev_status}&key={$send_key}";
if (!empty($send_anchor)) {
$sendUrl .= '&anchor=' . $send_anchor;
}
}
return $sendUrl;
}
/**
* generateETagHeader.
*
* This function generates the necessary cache headers for using ETags with dynamic content. You
* simply have to generate the ETag, pass it in, and the function handles the rest.
*
* @param string $etag ETag to use for this content.
*/
function generateETagHeader($etag)
{
header('cache-control:');
header('Expires: ');
header('ETag: ' . $etag);
header('Pragma:');
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
if ($etag == $_SERVER['HTTP_IF_NONE_MATCH']) {
ob_clean();
header('Status: 304 Not Modified');
header('HTTP/1.0 304 Not Modified');
die();
}
}
}
/**
* getReportNameTranslation.
*
* Translates the report name if a translation exists,
* otherwise just returns the name
*
* @param string $reportName
*
* @return string translated report name
*/
function getReportNameTranslation($reportName)
{
global $current_language;
// Used for translating reports
$mod_strings = return_module_language($current_language, 'Reports');
// Search for the report name in the default language and get the key
$key = array_search($reportName, return_module_language('', 'Reports'));
// If the key was found, use it to get a translation, otherwise just use report name
if (!empty($key)) {
$title = $mod_strings[$key];
} else {
$title = $reportName;
}
return $title;
}
/**
* Remove vars marked senstitive from array.
*
* @param array $defs
* @param SugarBean|array $data
*
* @return mixed $data without sensitive fields
*/
function clean_sensitive_data($defs, $data)
{
foreach ($defs as $field => $def) {
if (!empty($def['sensitive'])) {
if (is_array($data)) {
$data[$field] = '';
}
if ($data instanceof SugarBean) {
$data->$field = '';
}
}
}
return $data;
}
/**
* Return relations with labels for duplicates.
*
* @deprecated This function is unused and will be removed in a future release.
*/
function getDuplicateRelationListWithTitle($def, $var_def, $module)
{
global $current_language;
$select_array = array_unique($def);
if (count($select_array) < count($def)) {
$temp_module_strings = return_module_language($current_language, $module);
$temp_duplicate_array = array_diff_assoc($def, $select_array);
$temp_duplicate_array = array_merge($temp_duplicate_array, array_intersect($select_array, $temp_duplicate_array));
foreach ($temp_duplicate_array as $temp_key => $temp_value) {
// Don't add duplicate relationships
if (!empty($var_def[$temp_key]['relationship']) && array_key_exists($var_def[$temp_key]['relationship'], $select_array)) {
continue;
}
$select_array[$temp_key] = $temp_value;
}
// Add the relationship name for easier recognition
foreach ($select_array as $key => $value) {
$select_array[$key] .= ' (' . $key . ')';
}
}
asort($select_array);
return $select_array;
}
/**
* Gets the list of "*type_display*".
*
* @return array
*/
function getTypeDisplayList()
{
return array('record_type_display', 'parent_type_display', 'record_type_display_notes');
}
/**
* Breaks given string into substring according
* to 'db_concat_fields' from field definition
* and assigns values to corresponding properties
* of bean.
*
* @param SugarBean $bean
* @param array $fieldDef
* @param string $value
*/
function assignConcatenatedValue(SugarBean $bean, $fieldDef, $value)
{
$valueParts = explode(' ', $value);
$valueParts = array_filter($valueParts);
$fieldNum = count($fieldDef['db_concat_fields']);
if (count($valueParts) == 1 && $fieldDef['db_concat_fields'] == array('first_name', 'last_name')) {
$bean->last_name = $value;
} // elseif ($fieldNum >= count($valueParts))
else {
for ($i = 0; $i < $fieldNum; ++$i) {
$fieldValue = array_shift($valueParts);
$fieldName = $fieldDef['db_concat_fields'][$i];
$bean->$fieldName = $fieldValue !== false ? $fieldValue : '';
}
if (!empty($valueParts)) {
$bean->$fieldName .= ' ' . implode(' ', $valueParts);
}
}
}
/**
* Performs unserialization. Accepts all types except Objects.
*
* @param string $value Serialized value of any type except Object
*
* @return mixed False if Object, converted value for other cases
*/
function sugar_unserialize($value)
{
preg_match('/[oc]:[^:]*\d+:/i', $value, $matches);
if (count($matches)) {
return false;
}
return unserialize($value);
}
define('DEFAULT_UTIL_SUITE_ENCODING', 'UTF-8');
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function suite_strlen($input, $encoding = DEFAULT_UTIL_SUITE_ENCODING)
{
if (function_exists('mb_strlen')) {
return mb_strlen($input, $encoding);
}
return strlen($input);
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function suite_substr($input, $start, $length = null, $encoding = DEFAULT_UTIL_SUITE_ENCODING)
{
if (function_exists('mb_substr')) {
return mb_substr($input, $start, $length, $encoding);
}
return substr($input, $start, $length);
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function suite_strtoupper($input, $encoding = DEFAULT_UTIL_SUITE_ENCODING)
{
if (function_exists('mb_strtoupper')) {
return mb_strtoupper($input, $encoding);
}
return strtoupper($input);
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function suite_strtolower($input, $encoding = DEFAULT_UTIL_SUITE_ENCODING)
{
if (function_exists('mb_strtolower')) {
return mb_strtolower($input, $encoding);
}
return strtolower($input);
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function suite_strpos($haystack, $needle, $offset = 0, $encoding = DEFAULT_UTIL_SUITE_ENCODING)
{
if (function_exists('mb_strpos')) {
return mb_strpos($haystack, $needle, $offset, $encoding);
}
return strpos($haystack, $needle, $offset);
}
/**
* @deprecated This function is unused and will be removed in a future release.
*/
function suite_strrpos($haystack, $needle, $offset = 0, $encoding = DEFAULT_UTIL_SUITE_ENCODING)
{
if (function_exists('mb_strrpos')) {
return mb_strrpos($haystack, $needle, $offset, $encoding);
}
return strrpos($haystack, $needle, $offset);
}
/**
* @deprecated deprecated since version 7.10 please use the SuiteValidator class
*/
function isValidId($id)
{
$deprecatedMessage = 'isValidId method is deprecated please update your code';
if (isset($GLOBALS['log'])) {
$GLOBALS['log']->deprecated($deprecatedMessage);
} else {
trigger_error($deprecatedMessage, E_USER_DEPRECATED);
}
$isValidator = new \SuiteCRM\Utility\SuiteValidator();
$result = $isValidator->isValidId($id);
return $result;
}
function isValidEmailAddress($email, $message = 'Invalid email address given', $orEmpty = true, $logInvalid = 'error')
{
if ($orEmpty && !$email) {
return true;
}
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
return true;
}
if ($logInvalid) {
$trace = debug_backtrace();
$where = "Called at {$trace[1]['file']}:{$trace[1]['line']} from function {$trace[1]['function']}.";
\SuiteCRM\ErrorMessage::log("$message: [$email] $where", $logInvalid);
}
return false;
}
function displayAdminError($errorString)
{
SugarApplication::appendErrorMessage($errorString);
}
function getAppString($key)
{
global $app_strings;
if (!isset($app_strings[$key])) {
LoggerManager::getLogger()->warn('Language key not found: ' . $key);
return $key;
}
if (!$app_strings[$key]) {
LoggerManager::getLogger()->warn('Language string is empty at key: ' . $key);
return $key;
}
return $app_strings[$key];
}
function set_session_name(){
$sessionName = 'LEGACYSESSID';
if (!empty($GLOBALS['sugar_config']['session_name'])) {
$sessionName = $GLOBALS['sugar_config']['session_name'];
}
if (session_status() === PHP_SESSION_NONE) {
session_name($sessionName);
}
}
/**
* Check if has valid image extension
* @param string $fieldName
* @param string $value
* @return bool
*/
function has_valid_image_extension($fieldName, $name)
{
global $sugar_config;
$validExtensions = [
'gif',
'png',
'jpg',
'jpeg',
'svg'
];
if (isset($sugar_config['valid_image_ext']) && is_array($sugar_config['valid_image_ext'])){
$validExtensions = $sugar_config['valid_image_ext'];
}
return has_valid_extension($fieldName, $name, $validExtensions);
}
/**
* Check if has valid extension
* @param string $fieldName
* @param string $name
* @param array $validExtensions
* @return bool
*/
function has_valid_extension($fieldName, $name, $validExtensions)
{
if ($name === '.' || empty($name)) {
LoggerManager::getLogger()->security("Invalid ext $fieldName : '$name'.");
return false;
}
$validExtensions = array_map('strtolower', $validExtensions);
$parts = explode('.', $name);
if (empty($parts)) {
LoggerManager::getLogger()->security("Invalid ext $fieldName : '$name'.");
return false;
}
$ext = array_pop($parts);
$trimmedValue = preg_replace('/.*\.([^\.]+)$/', '\1', $ext);
if (!in_array(strtolower($trimmedValue), $validExtensions, true)) {
LoggerManager::getLogger()->security("Invalid $fieldName: '$name'.");
return false;
}
return true;
}
/**
* Check if value is one of the accepted true representations
* @param $value
* @return bool
*/
function isTrue($value): bool {
return $value === true || $value === 'true' || $value === 1 || $value === '1' || $value === 'on';
}
/**
* Check if value is one of the accepted false representations
* @param $value
* @return bool
*/
function isFalse($value): bool {
return $value === false || $value === 'false' || $value === 0 || $value === '0';
}
/**
* Get validation pattern
* @return string
*/
function get_id_validation_pattern(): string {
global $sugar_config;
$pattern = '/^[a-zA-Z0-9_-]*$/i';
if (!empty($sugar_config['id_validation_pattern'])){
$pattern = $sugar_config['id_validation_pattern'];
}
return $pattern;
}
/**
* Check if user has group and action acls defined
* @param string $module
* @param string $action
* @return bool
*/
function has_group_action_acls_defined(string $module, string $action): bool
{
global $current_user;
$hasGroupActionAcls = true;
$groups = SecurityGroup::getUserSecurityGroups($current_user->id);
$hasGroups = !empty($groups);
$aclActions = ACLAction::getUserActions($current_user->id, false, $module, 'module', $action);
$isDefaultListACL = !empty($aclActions['isDefault']) && isTrue($aclActions['isDefault']);
if (!$hasGroups) {
$hasGroupActionAcls = false;
}
if ($isDefaultListACL) {
$hasGroupActionAcls = false;
}
return $hasGroupActionAcls;
}
/**
* Check if is value is smtp in a case-insensitive way
* @param $value
* @return bool
*/
function isSmtp($value): bool {
if (empty($value) || !is_string($value)) {
return false;
}
return strtolower($value) === 'smtp';
}
/**
* Check if is string is an allowed module name
* @param string $value
* @return bool
*/
function isAllowedModuleName(string $value): bool {
if (empty($value)) {
return false;
}
$result = preg_match("/^[\w\-\_\.]+$/", $value);
if (!empty($result)) {
return true;
}
return false;
}
/**
* @param $endpoint
* @return bool
*/
function isSelfRequest($endpoint) : bool {
$domain = 'localhost';
if (isset($_SERVER["HTTP_HOST"])) {
$domain = $_SERVER["HTTP_HOST"];
}
$siteUrl = SugarConfig::getInstance()->get('site_url');
if (empty($siteUrl)){
$siteUrl = '';
}
return stripos($endpoint, $domain) !== false || stripos($endpoint, $siteUrl) !== false;
}
|