2013-03-11 11:00:33 -04:00
< ? php
2012-10-18 15:17:21 -04:00
2017-08-14 16:13:46 -04:00
use ProcessMaker\Core\System ;
2018-01-15 12:00:22 +00:00
use ProcessMaker\AuditLog\AuditLog ;
2017-08-10 12:10:42 -04:00
use ProcessMaker\Plugins\PluginRegistry ;
2018-01-15 12:00:22 +00:00
use ProcessMaker\Services\OAuth2\Server ;
2018-08-28 09:34:11 -04:00
use ProcessMaker\Validation\ValidationUploadedFiles ;
2012-10-18 15:17:21 -04:00
class G
{
2016-08-04 14:56:58 -04:00
const hashFx = 'md5' ;
2016-09-01 15:43:01 -04:00
const hash = 'hash' ;
2016-08-04 14:56:58 -04:00
const hashFile = 'md5_file' ;
const hashCrc = 'crc32' ;
2018-01-15 12:00:22 +00:00
BUG 10087 "PM functions y Web Services de ProcessMaker no..." SOLVED
- Problem with the variable $_SESSION
- The variable $_SESSION should not lose the default values ..set
- Added functions to save and restore the values ..of the variable $_SESSION
- Revised class.pmFunctions.php functions and class.wsBase.php
- The QA team should test this functions (most of these functions running
triggers, try running triggers):
PMFAddInputDocument
PMFGenerateOutputDocument
PMFDerivateCase, WSDerivateCase, wsBase::derivateCase
PMFNewCase, WSNewCase, wsBase::newCase
PMFRedirectToStep
PMFDeleteCase, WSDeleteCase, wsBase::deleteCase
PMFCancelCase, WSCancelCase, wsBase::cancelCase
PMFPauseCase, WSPauseCase, wsBase::pauseCase
PMFUnpauseCase, WSUnpauseCase, wsBase::unpauseCase
wsBase::executeTrigger
wsBase::reassignCase
* Available from version 2.0.46
2012-11-29 17:04:31 -04:00
public $sessionVar = array (); //SESSION temporary array store.
2016-09-09 11:09:02 -04:00
public static $sysSys ;
public static $sysSkin ;
public static $pathDataSite ;
public static $pathDocument ;
public static $memcachedEnabled ;
public static $pathDataPublic ;
public static $httpHost ;
BUG 10087 "PM functions y Web Services de ProcessMaker no..." SOLVED
- Problem with the variable $_SESSION
- The variable $_SESSION should not lose the default values ..set
- Added functions to save and restore the values ..of the variable $_SESSION
- Revised class.pmFunctions.php functions and class.wsBase.php
- The QA team should test this functions (most of these functions running
triggers, try running triggers):
PMFAddInputDocument
PMFGenerateOutputDocument
PMFDerivateCase, WSDerivateCase, wsBase::derivateCase
PMFNewCase, WSNewCase, wsBase::newCase
PMFRedirectToStep
PMFDeleteCase, WSDeleteCase, wsBase::deleteCase
PMFCancelCase, WSCancelCase, wsBase::cancelCase
PMFPauseCase, WSPauseCase, wsBase::pauseCase
PMFUnpauseCase, WSUnpauseCase, wsBase::unpauseCase
wsBase::executeTrigger
wsBase::reassignCase
* Available from version 2.0.46
2012-11-29 17:04:31 -04:00
2017-08-17 17:19:43 -04:00
/**
* Adapters used for different services inside Processmaker .
*
* @ var string [] $adapters
*/
private static $adapters = [
2018-01-15 12:00:22 +00:00
'ldap' => LDAP :: class ,
'ldapadvanced' => LdapAdvanced :: class ,
'dashletopenvscompleted' => DashletOpenVsCompleted :: class ,
'dashletrssreader' => DashletRssReader :: class ,
2017-08-17 18:24:05 -04:00
'dashletprocessmakerenterprise' => DashletProcessMakerEnterprise :: class ,
2018-01-15 12:00:22 +00:00
'dashletprocessmakercommunity' => DashletProcessMakerCommunity :: class ,
2017-08-17 17:19:43 -04:00
];
2017-08-04 10:38:28 -04:00
/**
2017-09-12 14:42:10 -04:00
* This function verify if exist file name in the PATH_GULLIVER
* @ param string $strClass
* @ return boolean
2017-08-04 10:38:28 -04:00
*/
2018-01-25 20:32:51 +00:00
public static function LoadSystemExist ( $strClass )
2017-08-04 10:38:28 -04:00
{
2017-12-04 13:25:35 +00:00
if ( file_exists ( PATH_GULLIVER . 'class.' . $strClass . '.php' )) {
2017-09-12 14:42:10 -04:00
return true ;
} else {
return false ;
}
2017-08-04 10:38:28 -04:00
}
/**
2017-08-10 12:35:35 -04:00
* @ deprecated 3.2 . 2 , We keep this function only for backwards compatibility because is used in the plugin manager
2017-08-04 10:38:28 -04:00
*/
2017-09-12 14:42:10 -04:00
public static function LoadSystem ( $strClass )
2017-08-04 10:38:28 -04:00
{
//For backward compatibilities
}
/**
2017-08-10 12:35:35 -04:00
* @ deprecated 3.2 . 2 , We keep this function only for backwards compatibility because is used in the plugin manager
2017-08-04 10:38:28 -04:00
*/
2017-08-04 16:48:01 -04:00
public function LoadInclude ( $strClass )
2017-08-04 10:38:28 -04:00
{
//For backward compatibilities
}
/**
2017-08-10 12:35:35 -04:00
* @ deprecated 3.2 . 2 , We keep this function only for backwards compatibility because is used in the plugin manager
2017-08-04 10:38:28 -04:00
*/
2017-08-04 16:48:01 -04:00
public function LoadClassRBAC ( $strClass )
2017-08-04 10:38:28 -04:00
{
//For backward compatibilities
}
/**
2017-08-10 12:35:35 -04:00
* @ deprecated 3.2 . 2 , We keep this function only for backwards compatibility because is used in the plugin manager
2017-08-04 10:38:28 -04:00
*/
2017-08-04 16:42:40 -04:00
public static function LoadClass ( $strClass )
2017-08-04 10:38:28 -04:00
{
//For backward compatibilities
}
/**
2017-08-10 12:35:35 -04:00
* @ deprecated 3.2 . 2 , We keep this function only for backwards compatibility because is used in the plugin manager
2017-08-04 10:38:28 -04:00
*/
2017-08-04 16:48:01 -04:00
public static function LoadThirdParty ( $sPath , $sFile )
2017-08-04 10:38:28 -04:00
{
//For backward compatibilities
}
/**
2017-08-04 16:42:40 -04:00
* Include all model files
2017-08-04 10:38:28 -04:00
* @ access public
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function LoadAllModelClasses ()
2017-08-04 10:38:28 -04:00
{
2017-08-04 16:42:40 -04:00
$baseDir = PATH_CORE . 'classes' . PATH_SEP . 'model' ;
2017-12-04 13:25:35 +00:00
if ( $handle = opendir ( $baseDir )) {
while ( false !== ( $file = readdir ( $handle ))) {
2018-01-15 12:00:22 +00:00
if ( strpos ( $file , '.php' , 1 ) && ! strpos ( $file , 'Peer.php' , 1 )) {
2017-12-04 13:25:35 +00:00
require_once ( $baseDir . PATH_SEP . $file );
2017-08-04 16:42:40 -04:00
}
}
}
2017-08-04 10:38:28 -04:00
}
2012-10-18 15:17:21 -04:00
/**
* is_https
2017-02-10 13:50:52 -04:00
* @ return bool
*/
2016-04-07 15:34:02 -04:00
public static function is_https ()
2012-10-18 15:17:21 -04:00
{
2017-02-10 13:50:52 -04:00
$is_http = false ;
2018-01-15 12:00:22 +00:00
if (( isset ( $_SERVER [ 'HTTPS' ]) && $_SERVER [ 'HTTPS' ] == 'on' ) ||
2017-02-10 13:50:52 -04:00
( isset ( $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ]) && $_SERVER [ 'HTTP_X_FORWARDED_PROTO' ] == 'https' )) {
$is_http = true ;
2012-10-18 15:17:21 -04:00
}
2017-02-10 13:50:52 -04:00
return $is_http ;
2012-10-18 15:17:21 -04:00
}
/**
* Fill array values ( recursive )
* @ access public
* @ param Array $arr
* @ param Void $value
* @ param Boolean $recursive
* @ return Array
*/
2018-01-25 20:32:51 +00:00
public static function array_fill_value ( $arr = array (), $value = '' , $recursive = false )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( is_array ( $arr )) {
2012-10-18 15:17:21 -04:00
foreach ( $arr as $key => $val ) {
2017-12-04 13:25:35 +00:00
if ( is_array ( $arr [ $key ])) {
$arr [ $key ] = ( $recursive === true ) ? G :: array_fill_value ( $arr [ $key ], $value , true ) : $val ;
2012-10-18 15:17:21 -04:00
} else {
$arr [ $key ] = $value ;
}
}
} else {
2017-12-04 13:25:35 +00:00
$arr = array ();
2012-10-18 15:17:21 -04:00
}
return $arr ;
}
/**
* Generate Password Random
2016-07-07 12:00:14 -04:00
* $availableSets set next options :
* l : lowercase set a - z
* u : uppercase set A - Z
* n : numbers set 0 - 9
* s : symbols set _ -+=!@ #$%*&,.;:?^()[]{}<>
2017-12-04 13:25:35 +00:00
*
2016-07-07 12:00:14 -04:00
* $symbol is source symbol generate
2017-12-04 13:25:35 +00:00
*
2016-07-07 12:00:14 -04:00
* @ param int $length
* @ param string $availableSets
* @ param string $symbol
* @ return string
2012-10-18 15:17:21 -04:00
*/
2017-12-04 13:25:35 +00:00
public static function generate_password ( $length = 15 , $availableSets = " luns " , $symbol = " _- $ ! " )
2012-10-18 15:17:21 -04:00
{
2016-07-07 12:00:14 -04:00
$chars = " " ;
if ( strpos ( $availableSets , " l " ) !== false ) {
$chars = $chars . " abcdefghjkmnpqrstuvwxyz " ;
}
if ( strpos ( $availableSets , " u " ) !== false ) {
$chars = $chars . " ABCDEFGHJKMNPQRSTUVWXYZ " ;
}
if ( strpos ( $availableSets , " n " ) !== false ) {
$chars = $chars . " 0123456789 " ;
}
if ( strpos ( $availableSets , " s " ) !== false ) {
$chars = $chars . $symbol ;
}
$n = strlen ( $chars );
do {
2017-12-04 13:25:35 +00:00
$password = " " ;
2016-07-07 12:00:14 -04:00
$i = 0 ;
while ( $i < $length ) {
$chars = str_shuffle ( $chars );
$char = substr ( $chars , mt_rand ( 0 , $n - 1 ), 1 );
2017-12-04 13:25:35 +00:00
if ( ! strstr ( $password , $char )) {
2016-07-07 12:00:14 -04:00
$password = $password . $char ;
2017-12-04 13:25:35 +00:00
$i ++ ;
}
2016-07-07 12:00:14 -04:00
$password = str_shuffle ( $password );
2017-12-04 13:25:35 +00:00
}
2016-07-07 12:00:14 -04:00
$info = G :: check_password ( $password , $length , $length , $availableSets );
} while ( ! $info -> isValid );
2012-10-18 15:17:21 -04:00
return $password ;
}
2016-07-07 12:00:14 -04:00
/**
* Check password strong
2017-12-04 13:25:35 +00:00
*
2016-07-07 12:00:14 -04:00
* $availableSets set next options :
* l : lowercase set a - z
* u : uppercase set A - Z
* n : numbers set 0 - 9
* s : symbols set _ -+=!@ #$%*&,.;:?^()[]{}<>
2017-12-04 13:25:35 +00:00
*
2016-07-07 12:00:14 -04:00
* @ param string $password
* @ param int $min
* @ param int $max
* @ param string $availableSets
* @ return \stdClass
*/
2017-12-04 13:25:35 +00:00
public static function check_password ( $password , $min = 2 , $max = 20 , $availableSets = " luns " )
2016-07-07 12:00:14 -04:00
{
$info = new stdClass ();
$info -> isValid = true ;
$info -> error = " " ;
if ( strlen ( $password ) < $min ) {
$info -> error .= G :: LoadTranslation ( " ID_PASSWORD_TOO_SHORT " ) . " " ;
$info -> isValid = false ;
}
if ( strlen ( $password ) > $max ) {
$info -> error .= G :: LoadTranslation ( " ID_PASSWORD_TOO_LONG " ) . " " ;
$info -> isValid = false ;
}
if ( strpos ( $availableSets , " l " ) !== false && ! preg_match ( " #[a-z]+# " , $password )) {
$info -> error .= G :: LoadTranslation ( " ID_PASSWORD_MUST_INCLUDE_AT_LEAST_ONE_LETTER " ) . " " ;
$info -> isValid = false ;
}
if ( strpos ( $availableSets , " u " ) !== false && ! preg_match ( " #[A-Z]+# " , $password )) {
$info -> error .= G :: LoadTranslation ( " ID_PASSWORD_MUST_INCLUDE_AT_LEAST_ONE_CAPS " ) . " " ;
$info -> isValid = false ;
}
if ( strpos ( $availableSets , " n " ) !== false && ! preg_match ( " #[0-9]+# " , $password )) {
$info -> error .= G :: LoadTranslation ( " ID_PASSWORD_MUST_INCLUDE_AT_LEAST_ONE_NUMBER " ) . " " ;
$info -> isValid = false ;
}
if ( strpos ( $availableSets , " s " ) !== false && ! preg_match ( " # \ W+# " , $password )) {
$info -> error .= G :: LoadTranslation ( " ID_PASSWORD_MUST_INCLUDE_AT_LEAST_ONE_SYMBOL " ) . " " ;
$info -> isValid = false ;
}
return $info ;
}
2012-10-18 15:17:21 -04:00
/**
* Array concat
* array_concat ( ArrayToConcat , ArrayOriginal );
*
* @ access public
* @ param Array
* @ return Array
*/
2018-01-25 20:32:51 +00:00
public static function array_concat ()
2012-10-18 15:17:21 -04:00
{
$nums = func_num_args ();
$vars = func_get_args ();
2017-12-04 13:25:35 +00:00
$ret = array ();
2012-10-18 15:17:21 -04:00
for ( $i = 0 ; $i < $nums ; $i ++ ) {
2017-12-04 13:25:35 +00:00
if ( is_array ( $vars [ $i ])) {
2012-10-18 15:17:21 -04:00
foreach ( $vars [ $i ] as $key => $value ) {
$ret [ $key ] = $value ;
}
}
}
return $ret ;
}
/**
* Compare Variables
* var_compare ( value ,[ var1 , var2 , varN ]);
* @ access public
* @ param void $value
* @ param void $var1 - N
* @ return Boolean
*/
2018-01-25 20:32:51 +00:00
public static function var_compare ( $value = true )
2012-10-18 15:17:21 -04:00
{
$nums = func_num_args ();
if ( $nums < 2 ) {
2017-12-04 13:25:35 +00:00
return true ;
2012-10-18 15:17:21 -04:00
}
$vars = func_get_args ();
2017-12-04 13:25:35 +00:00
$ret = array ();
2012-10-18 15:17:21 -04:00
for ( $i = 1 ; $i < $nums ; $i ++ ) {
if ( $vars [ $i ] !== $value ) {
return false ;
}
}
return true ;
}
/**
* Emulate variable selector
* @ access public
* @ param void
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function var_probe ()
2012-10-18 15:17:21 -04:00
{
//return (!$variable)?
$nums = func_num_args ();
$vars = func_get_args ();
for ( $i = 0 ; $i < $nums ; $i ++ ) {
if ( $vars [ $i ]) {
return $vars [ $i ];
}
}
return 1 ;
}
/**
* Get the current version of gulliver classes
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function & getVersion ()
2012-10-18 15:17:21 -04:00
{
//majorVersion.minorVersion-SvnRevision
return '3.0-1' ;
}
/**
* getIpAddress
* @ return string $ip
*/
2017-12-04 13:25:35 +00:00
public static function getIpAddress ()
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( getenv ( 'HTTP_CLIENT_IP' )) {
$ip = getenv ( 'HTTP_CLIENT_IP' );
} elseif ( getenv ( 'HTTP_X_FORWARDED_FOR' )) {
$ip = getenv ( 'HTTP_X_FORWARDED_FOR' );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$ip = getenv ( 'REMOTE_ADDR' );
2012-10-18 15:17:21 -04:00
}
return $ip ;
}
/**
* getMacAddress
*
* @ return string $mac
*/
2017-12-04 13:25:35 +00:00
public function getMacAddress ()
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( strstr ( getenv ( 'OS' ), 'Windows' )) {
2012-10-18 15:17:21 -04:00
$ipconfig = `ipconfig /all` ;
2017-12-04 13:25:35 +00:00
preg_match ( '/[\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}/i' , $ipconfig , $mac );
2012-10-18 15:17:21 -04:00
} else {
$ifconfig = `/sbin/ifconfig` ;
2017-12-04 13:25:35 +00:00
preg_match ( '/[\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}[\:-][\dA-Z]{2,2}/i' , $ifconfig , $mac );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
return isset ( $mac [ 0 ]) ? $mac [ 0 ] : '00:00:00:00:00:00' ;
2012-10-18 15:17:21 -04:00
}
/**
* microtime_float
*
* @ return array_sum ( explode ( ' ' , microtime ()))
*/
2018-01-25 20:32:51 +00:00
public static function microtime_float ()
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
return array_sum ( explode ( ' ' , microtime ()));
2012-10-18 15:17:21 -04:00
}
/**
* * Encrypt and decrypt functions ***
*/
2017-11-24 13:39:33 -04:00
2012-10-18 15:17:21 -04:00
/**
* Encrypt string
*
* @ access public
2018-01-25 20:32:51 +00:00
*
2012-10-18 15:17:21 -04:00
* @ param string $string
* @ param string $key
2017-11-24 13:39:33 -04:00
* @ param bool $urlSafe if it is used in url
*
2012-10-18 15:17:21 -04:00
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function encrypt ( $string , $key , $urlSafe = false )
2012-10-18 15:17:21 -04:00
{
2017-11-24 13:39:33 -04:00
if ( strpos ( $string , '|' , 0 ) !== false ) {
2012-10-18 15:17:21 -04:00
return $string ;
}
$result = '' ;
2017-11-24 13:39:33 -04:00
for ( $i = 0 ; $i < strlen ( $string ); $i ++ ) {
$char = substr ( $string , $i , 1 );
$keychar = substr ( $key , ( $i % strlen ( $key )) - 1 , 1 );
$char = chr ( ord ( $char ) + ord ( $keychar ));
2012-10-18 15:17:21 -04:00
$result .= $char ;
}
2017-11-24 13:39:33 -04:00
$result = base64_encode ( $result );
2017-11-27 12:00:58 -04:00
$search = [ '/' => '°' , '=' => '' ];
2017-11-24 13:39:33 -04:00
if ( $urlSafe ) {
2017-11-27 12:00:58 -04:00
$search [ '+' ] = '-' ;
2017-11-24 13:39:33 -04:00
}
2017-11-27 12:00:58 -04:00
return strtr ( $result , $search );
2012-10-18 15:17:21 -04:00
}
/**
* Decrypt string
*
* @ access public
2018-01-25 20:32:51 +00:00
*
2012-10-18 15:17:21 -04:00
* @ param string $string
* @ param string $key
2017-11-24 13:39:33 -04:00
* @ param bool $urlSafe if it is used in url
*
2012-10-18 15:17:21 -04:00
* @ return string
*/
2017-11-24 13:39:33 -04:00
public static function decrypt ( $string , $key , $urlSafe = false )
2012-10-18 15:17:21 -04:00
{
$result = '' ;
2017-11-27 12:00:58 -04:00
$search = [ '°' => '/' ];
2017-11-24 13:39:33 -04:00
if ( $urlSafe ) {
2017-11-27 12:00:58 -04:00
$search [ '-' ] = '+' ;
2017-11-24 13:39:33 -04:00
}
2017-11-27 12:00:58 -04:00
$string = strtr ( $string , $search );
$complement = explode ( '?' , $string );
$string = base64_decode ( $complement [ 0 ]);
2017-11-24 13:39:33 -04:00
for ( $i = 0 ; $i < strlen ( $string ); $i ++ ) {
$char = substr ( $string , $i , 1 );
$keychar = substr ( $key , ( $i % strlen ( $key )) - 1 , 1 );
$char = chr ( ord ( $char ) - ord ( $keychar ));
2012-10-18 15:17:21 -04:00
$result .= $char ;
}
2017-11-27 12:00:58 -04:00
if ( ! empty ( $complement [ 1 ])) {
$result .= '?' . $complement [ 1 ];
2012-10-18 15:17:21 -04:00
}
return $result ;
}
/**
* Look up an IP address direction
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $target
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function lookup ( $target )
2012-10-18 15:17:21 -04:00
{
//Made compatible to PHP 5.3
2017-12-04 13:25:35 +00:00
if ( preg_match ( " [a-zA-Z] " , $target )) {
$ntarget = gethostbyname ( $target );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$ntarget = gethostbyaddr ( $target );
2012-10-18 15:17:21 -04:00
}
return ( $ntarget );
}
/**
* ************* path functions ****************
*/
2017-12-04 13:25:35 +00:00
public static function mk_dir ( $strPath , $rights = 0770 )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$folder_path = array ( $strPath );
$oldumask = umask ( 0 );
2018-01-15 12:00:22 +00:00
while ( !@ is_dir ( dirname ( end ( $folder_path ))) && dirname ( end ( $folder_path )) != '/' && dirname ( end ( $folder_path )) != '.' && dirname ( end ( $folder_path )) != '' ) {
2017-12-04 13:25:35 +00:00
array_push ( $folder_path , dirname ( end ( $folder_path ))); //var_dump($folder_path); die;
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
while ( $parent_folder_path = array_pop ( $folder_path )) {
2018-01-15 12:00:22 +00:00
if ( !@ is_dir ( $parent_folder_path )) {
if ( !@ mkdir ( $parent_folder_path , $rights )) {
2017-12-04 13:25:35 +00:00
error_log ( " Can't create folder \" $parent_folder_path\ " " );
2013-04-29 16:48:29 -04:00
//umask( $oldumask );
2012-10-18 15:17:21 -04:00
}
}
}
2013-04-29 16:48:29 -04:00
umask ( $oldumask );
2012-10-18 15:17:21 -04:00
}
/**
* rm_dir
*
* @ param string $dirName
*
* @ return void
*/
2017-12-04 13:25:35 +00:00
public static function rm_dir ( $dirName )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! is_writable ( $dirName )) {
2012-10-18 15:17:21 -04:00
return false ;
}
2017-12-04 13:25:35 +00:00
if ( is_dir ( $dirName )) {
foreach ( glob ( $dirName . '/{,.}*' , GLOB_BRACE ) as $file ) {
2012-10-18 15:17:21 -04:00
if ( $file == $dirName . '/.' || $file == $dirName . '/..' ) {
continue ;
}
2013-09-02 14:40:03 -04:00
2017-12-04 13:25:35 +00:00
if ( is_dir ( $file )) {
G :: rm_dir ( $file );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
@ unlink ( $file );
2012-10-18 15:17:21 -04:00
}
}
2013-09-02 14:40:03 -04:00
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === " WIN " ) {
$dirName = str_replace ( " / " , " \\ " , $dirName );
exec ( " DEL /F /S /Q " . $dirName . " " , $res );
exec ( " RD /S /Q " . $dirName . " " , $res );
} else {
@ rmdir ( $dirName );
}
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
@ unlink ( $dirName );
2012-10-18 15:17:21 -04:00
}
}
2013-04-29 16:48:29 -04:00
/**
* Delete all the directory tree cotents .
* @ param string $dir
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function delTree ( $dir )
2013-04-29 16:48:29 -04:00
{
2017-12-04 13:25:35 +00:00
$files = glob ( $dir . '*' , GLOB_MARK );
foreach ( $files as $file ) {
if ( substr ( $file , - 1 ) == '/' ) {
self :: delTree ( $file );
2013-04-29 16:48:29 -04:00
} else {
2017-12-04 13:25:35 +00:00
unlink ( $file );
2013-04-29 16:48:29 -04:00
}
}
if ( is_dir ( $dir )) {
2017-12-04 13:25:35 +00:00
rmdir ( $dir );
2013-04-29 16:48:29 -04:00
}
}
/**
* Recursive copy
* @ param string $source
* @ param string $destination
* @ return boolean
*/
2018-01-25 20:32:51 +00:00
public static function recursive_copy ( $source , $destination )
2017-12-04 13:25:35 +00:00
{
2013-04-29 16:48:29 -04:00
if ( $source == $destination ) {
return false ;
}
$dir = opendir ( $source );
2013-07-12 15:57:54 -04:00
if ( ! file_exists ( $destination )) {
G :: mk_dir ( $destination , 0777 );
2013-04-29 16:48:29 -04:00
}
2013-07-12 15:57:54 -04:00
2017-12-04 13:25:35 +00:00
while ( false !== ( $file = readdir ( $dir ))) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir ( $source . '/' . $file )) {
2013-04-29 16:48:29 -04:00
self :: recursive_copy ( $source . '/' . $file , $destination . '/' . $file );
} else {
copy ( $source . '/' . $file , $destination . '/' . $file );
}
}
}
closedir ( $dir );
return true ;
}
2012-10-18 15:17:21 -04:00
/**
* verify path
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $strPath path
* @ param boolean $createPath if true this public function will create the path
* @ return boolean
*/
2017-12-04 13:25:35 +00:00
public static function verifyPath ( $strPath , $createPath = false )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$folder_path = strstr ( $strPath , '.' ) ? dirname ( $strPath ) : $strPath ;
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( file_exists ( $strPath ) || @ is_dir ( $strPath )) {
2012-10-18 15:17:21 -04:00
return true ;
} else {
if ( $createPath ) {
//TODO:: Define Environment constants: Devel (0777), Production (0770), ...
2017-12-04 13:25:35 +00:00
G :: mk_dir ( $strPath , 0777 );
2012-10-18 15:17:21 -04:00
} else {
return false ;
}
}
return false ;
}
/**
* Expand the path using the path constants
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $strPath
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function expandPath ( $strPath = '' )
2012-10-18 15:17:21 -04:00
{
$res = " " ;
$res = PATH_CORE ;
if ( $strPath != " " ) {
$res .= $strPath . " / " ;
}
return $res ;
}
/**
* Render Page
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param object $objContent
* @ param string $strTemplate
* @ param string $strSkin
* @ return void
*/
2017-12-04 13:25:35 +00:00
public static function RenderPage ( $strTemplate = " default " , $strSkin = SYS_SKIN , $objContent = null , $layout = '' )
2012-10-18 15:17:21 -04:00
{
global $G_CONTENT ;
global $G_TEMPLATE ;
global $G_SKIN ;
global $G_PUBLISH ;
$G_CONTENT = $objContent ;
$G_TEMPLATE = $strTemplate ;
$G_SKIN = $strSkin ;
try {
2017-12-04 13:25:35 +00:00
$file = G :: ExpandPath ( 'skinEngine' ) . 'skinEngine.php' ;
2012-10-18 15:17:21 -04:00
include $file ;
2017-12-04 13:25:35 +00:00
$skinEngine = new SkinEngine ( $G_TEMPLATE , $G_SKIN , $G_CONTENT );
$skinEngine -> setLayout ( $layout );
2012-10-18 15:17:21 -04:00
$skinEngine -> dispatch ();
} catch ( Exception $e ) {
global $G_PUBLISH ;
2017-12-04 13:25:35 +00:00
if ( is_null ( $G_PUBLISH )) {
2012-10-18 15:17:21 -04:00
$G_PUBLISH = new Publisher ();
}
2017-12-04 13:25:35 +00:00
if ( count ( $G_PUBLISH -> Parts ) == 1 ) {
array_shift ( $G_PUBLISH -> Parts );
2012-10-18 15:17:21 -04:00
}
global $oHeadPublisher ;
$leimnudInitString = $oHeadPublisher -> leimnudInitString ;
$oHeadPublisher -> clearScripts ();
$oHeadPublisher -> leimnudInitString = $leimnudInitString ;
2017-12-04 13:25:35 +00:00
$oHeadPublisher -> addScriptFile ( '/js/maborak/core/maborak.js' );
$G_PUBLISH -> AddContent ( 'xmlform' , 'xmlform' , 'login/showMessage' , null , array ( 'MESSAGE' => self :: getErrorMessage ( $e )
));
if ( class_exists ( 'SkinEngine' )) {
$skinEngine = new SkinEngine ( 'publish' , 'blank' , '' );
2012-10-18 15:17:21 -04:00
$skinEngine -> dispatch ();
} else {
2017-12-04 13:25:35 +00:00
die ( self :: getErrorMessage ( $e ));
2012-10-18 15:17:21 -04:00
}
}
}
/**
* Load a skin
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $strSkinName
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function LoadSkin ( $strSkinName )
2012-10-18 15:17:21 -04:00
{
//print $strSkinName;
//now, we are using the skin, a skin is a file in engine/skin directory
2017-12-04 13:25:35 +00:00
$file = G :: ExpandPath ( " skins " ) . $strSkinName . " .php " ;
2012-10-18 15:17:21 -04:00
//G::pr($file);
2017-12-04 13:25:35 +00:00
if ( file_exists ( $file )) {
require_once ( $file );
2012-10-18 15:17:21 -04:00
return ;
} else {
2017-12-04 13:25:35 +00:00
if ( file_exists ( PATH_HTML . 'errors/error703.php' )) {
header ( 'location: /errors/error703.php' );
2012-10-18 15:17:21 -04:00
die ();
} else {
$text = " The Skin $file does not exist, please review the Skin Definition " ;
2017-12-04 13:25:35 +00:00
throw ( new Exception ( $text ));
2012-10-18 15:17:21 -04:00
}
}
}
/**
* Include all model plugin files
*
* LoadAllPluginModelClasses
*
* @ author Hugo Loza < hugo @ colosa . com >
* @ access public
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function LoadAllPluginModelClasses ()
2012-10-18 15:17:21 -04:00
{
//Get the current Include path, where the plugins directories should be
2018-01-15 12:00:22 +00:00
if ( ! defined ( 'PATH_SEPARATOR' )) {
2017-12-04 13:25:35 +00:00
define ( 'PATH_SEPARATOR' , ( substr ( PHP_OS , 0 , 3 ) == 'WIN' ) ? ';' : ':' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$path = explode ( PATH_SEPARATOR , get_include_path ());
2012-10-18 15:17:21 -04:00
foreach ( $path as $possiblePath ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $possiblePath , " plugins " )) {
2012-10-18 15:17:21 -04:00
$baseDir = $possiblePath . 'classes' . PATH_SEP . 'model' ;
2017-12-04 13:25:35 +00:00
if ( file_exists ( $baseDir )) {
if ( $handle = opendir ( $baseDir )) {
while ( false !== ( $file = readdir ( $handle ))) {
2018-01-15 12:00:22 +00:00
if ( strpos ( $file , '.php' , 1 ) && ! strpos ( $file , 'Peer.php' , 1 )) {
2017-12-04 13:25:35 +00:00
require_once ( $baseDir . PATH_SEP . $file );
2012-10-18 15:17:21 -04:00
}
}
}
}
}
}
}
/**
* Load a template
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $strTemplateName
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function LoadTemplate ( $strTemplateName )
2012-10-18 15:17:21 -04:00
{
if ( $strTemplateName == '' ) {
return ;
}
$temp = $strTemplateName . " .php " ;
2017-12-04 13:25:35 +00:00
$file = G :: ExpandPath ( 'templates' ) . $temp ;
2012-10-18 15:17:21 -04:00
// Check if its a user template
2017-12-04 13:25:35 +00:00
if ( file_exists ( $file )) {
2012-10-18 15:17:21 -04:00
//require_once( $file );
2017-12-04 13:25:35 +00:00
include ( $file );
2012-10-18 15:17:21 -04:00
} else {
// Try to get the global system template
$file = PATH_TEMPLATE . PATH_SEP . $temp ;
//require_once( $file );
2017-12-04 13:25:35 +00:00
if ( file_exists ( $file )) {
include ( $file );
2012-10-18 15:17:21 -04:00
}
}
}
/**
* Encrypt URL
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $urlLink
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function encryptlink ( $url )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) {
return urlencode ( G :: encrypt ( $url , URL_KEY ));
2012-10-18 15:17:21 -04:00
} else {
return $url ;
}
}
/**
* Parsing the URI
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $urlLink
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function parseURI ( $uri , $isRestRequest = false )
2012-10-18 15:17:21 -04:00
{
//*** process the $_POST with magic_quotes enabled
// The magic_quotes_gpc feature has been DEPRECATED as of PHP 5.3.0.
if ( get_magic_quotes_gpc () === 1 ) {
2017-12-04 13:25:35 +00:00
$_POST = G :: strip_slashes ( $_POST );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$aRequestUri = explode ( '/' , $uri );
2012-10-18 15:17:21 -04:00
if ( $isRestRequest ) {
2017-12-04 13:25:35 +00:00
$args = self :: parseRestUri ( $aRequestUri );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$args = self :: parseNormalUri ( $aRequestUri );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
define ( " SYS_LANG " , $args [ 'SYS_LANG' ]);
define ( " SYS_SKIN " , $args [ 'SYS_SKIN' ]);
define ( 'SYS_COLLECTION' , $args [ 'SYS_COLLECTION' ]);
define ( 'SYS_TARGET' , $args [ 'SYS_TARGET' ]);
2012-10-18 15:17:21 -04:00
if ( $args [ 'SYS_COLLECTION' ] == 'js2' ) {
print " ERROR " ;
die ();
}
}
2018-01-25 20:32:51 +00:00
public static function parseNormalUri ( $aRequestUri )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( substr ( $aRequestUri [ 1 ], 0 , 3 ) == 'sys' ) {
define ( 'SYS_TEMP' , substr ( $aRequestUri [ 1 ], 3 ));
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
define ( " ENABLE_ENCRYPT " , 'yes' );
define ( 'SYS_TEMP' , $aRequestUri [ 1 ]);
2012-10-18 15:17:21 -04:00
$plain = '/sys' . SYS_TEMP ;
2017-12-04 13:25:35 +00:00
for ( $i = 2 ; $i < count ( $aRequestUri ); $i ++ ) {
$decoded = G :: decrypt ( urldecode ( $aRequestUri [ $i ]), URL_KEY );
2015-04-28 16:10:10 -04:00
if ( $decoded == 'sWì› ' ) {
2012-10-18 15:17:21 -04:00
$decoded = $VARS [ $i ]; //this is for the string "../"
}
$plain .= '/' . $decoded ;
}
$_SERVER [ " REQUEST_URI " ] = $plain ;
}
2017-12-04 13:25:35 +00:00
$work = explode ( '?' , $_SERVER [ " REQUEST_URI " ]);
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( count ( $work ) > 1 ) {
define ( 'SYS_CURRENT_PARMS' , $work [ 1 ]);
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
define ( 'SYS_CURRENT_PARMS' , '' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
define ( 'SYS_CURRENT_URI' , $work [ 0 ]);
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
if ( ! defined ( 'SYS_CURRENT_PARMS' )) {
2017-12-04 13:25:35 +00:00
define ( 'SYS_CURRENT_PARMS' , $work [ 1 ]);
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$preArray = explode ( '&' , SYS_CURRENT_PARMS );
$buffer = explode ( '.' , $work [ 0 ]);
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( count ( $buffer ) == 1 ) {
2012-10-18 15:17:21 -04:00
$buffer [ 1 ] = '' ;
}
//request type
2017-12-04 13:25:35 +00:00
define ( 'REQUEST_TYPE' , ( $buffer [ 1 ] != " " ? $buffer [ 1 ] : 'html' ));
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$toparse = substr ( $buffer [ 0 ], 1 , strlen ( $buffer [ 0 ]) - 1 );
$uriVars = explode ( '/' , $toparse );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
unset ( $work );
unset ( $buffer );
unset ( $toparse );
array_shift ( $uriVars );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$args = array ();
$args [ 'SYS_LANG' ] = array_shift ( $uriVars );
$args [ 'SYS_SKIN' ] = array_shift ( $uriVars );
$args [ 'SYS_COLLECTION' ] = array_shift ( $uriVars );
$args [ 'SYS_TARGET' ] = array_shift ( $uriVars );
2012-10-18 15:17:21 -04:00
//to enable more than 2 directories...in the methods structure
2017-12-04 13:25:35 +00:00
while ( count ( $uriVars ) > 0 ) {
$args [ 'SYS_TARGET' ] .= '/' . array_shift ( $uriVars );
2012-10-18 15:17:21 -04:00
}
/* Fix to prevent use uxs skin outside siplified interface ,
because that skin is not compatible with others interfaces */
if ( $args [ 'SYS_SKIN' ] == 'uxs' && $args [ 'SYS_COLLECTION' ] != 'home' && $args [ 'SYS_COLLECTION' ] != 'cases' ) {
2017-08-14 16:13:46 -04:00
$config = System :: getSystemConfiguration ();
2012-10-18 15:17:21 -04:00
$args [ 'SYS_SKIN' ] = $config [ 'default_skin' ];
}
return $args ;
}
2018-01-25 20:32:51 +00:00
public static function parseRestUri ( $requestUri )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$args = array ();
2012-10-18 15:17:21 -04:00
//$args['SYS_TEMP'] = $requestUri[1];
2017-12-04 13:25:35 +00:00
define ( 'SYS_TEMP' , $requestUri [ 2 ]);
2012-10-18 15:17:21 -04:00
$restUri = '' ;
2017-12-04 13:25:35 +00:00
for ( $i = 3 ; $i < count ( $requestUri ); $i ++ ) {
2012-10-18 15:17:21 -04:00
$restUri .= '/' . $requestUri [ $i ];
}
$args [ 'SYS_LANG' ] = 'en' ; // TODO, this can be set from http header
$args [ 'SYS_SKIN' ] = '' ;
$args [ 'SYS_COLLECTION' ] = '' ;
$args [ 'SYS_TARGET' ] = $restUri ;
return $args ;
}
2018-01-25 20:32:51 +00:00
public static function strip_slashes ( $vVar )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( is_array ( $vVar )) {
2012-10-18 15:17:21 -04:00
foreach ( $vVar as $sKey => $vValue ) {
2017-12-04 13:25:35 +00:00
if ( is_array ( $vValue )) {
G :: strip_slashes ( $vVar [ $sKey ]);
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$vVar [ $sKey ] = stripslashes ( $vVar [ $sKey ]);
2012-10-18 15:17:21 -04:00
}
}
} else {
2017-12-04 13:25:35 +00:00
$vVar = stripslashes ( $vVar );
2012-10-18 15:17:21 -04:00
}
return $vVar ;
}
/**
* function to calculate the time used to render a page
*/
2018-01-25 20:32:51 +00:00
public static function logTimeByPage ()
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! defined ( PATH_DATA )) {
2012-10-18 15:17:21 -04:00
return false ;
}
$serverAddr = $_SERVER [ 'SERVER_ADDR' ];
global $startingTime ;
2017-12-04 13:25:35 +00:00
$endTime = microtime ( true );
2012-10-18 15:17:21 -04:00
$time = $endTime - $startingTime ;
2017-12-04 13:25:35 +00:00
$fpt = fopen ( PATH_DATA . 'log/time.log' , 'a' );
fwrite ( $fpt , sprintf ( " %s.%03d %15s %s %5.3f %s \n " , date ( 'Y-m-d H:i:s' ), $time , getenv ( 'REMOTE_ADDR' ), substr ( $serverAddr , - 4 ), $time , $_SERVER [ 'REQUEST_URI' ]));
fclose ( $fpt );
2012-10-18 15:17:21 -04:00
}
/**
* streaming a big JS file with small js files
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $file
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function streamCSSBigFile ( $filename )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
header ( 'Content-Type: text/css' );
2012-10-18 15:17:21 -04:00
//First get Skin info
2017-12-04 13:25:35 +00:00
$filenameParts = explode ( " - " , $filename );
2012-10-18 15:17:21 -04:00
$skinName = $filenameParts [ 0 ];
$skinVariant = " skin " ;
2017-12-04 13:25:35 +00:00
if ( isset ( $filenameParts [ 1 ])) {
$skinVariant = strtolower ( $filenameParts [ 1 ]);
2012-10-18 15:17:21 -04:00
}
2012-10-26 17:46:16 -04:00
$configurationFile = '' ;
2012-10-18 15:17:21 -04:00
if ( $skinName == " jscolors " ) {
$skinName = " classic " ;
}
if ( $skinName == " xmlcolors " ) {
$skinName = " classic " ;
}
if ( $skinName == " classic " ) {
2017-12-04 13:25:35 +00:00
$configurationFile = G :: ExpandPath ( " skinEngine " ) . 'base' . PATH_SEP . 'config.xml' ;
2012-10-18 15:17:21 -04:00
} else {
$configurationFile = PATH_CUSTOM_SKINS . $skinName . PATH_SEP . 'config.xml' ;
2018-01-15 12:00:22 +00:00
if ( ! is_file ( $configurationFile )) {
2017-12-04 13:25:35 +00:00
$configurationFile = G :: ExpandPath ( " skinEngine " ) . $skinName . PATH_SEP . 'config.xml' ;
2012-10-18 15:17:21 -04:00
}
}
//Read Configuration File
2017-12-04 13:25:35 +00:00
$xmlConfiguration = file_get_contents ( $configurationFile );
$xmlConfigurationObj = G :: xmlParser ( $xmlConfiguration );
$baseSkinDirectory = dirname ( $configurationFile );
$directorySize = G :: getDirectorySize ( $baseSkinDirectory );
2012-10-18 15:17:21 -04:00
$mtime = $directorySize [ 'maxmtime' ];
$outputHeader = " /* Autogenerated CSS file by gulliver framework \n " ;
$outputHeader .= " Skin: $filename\n " ;
2017-12-04 13:25:35 +00:00
$mtimeNow = date ( 'U' );
$gmt_mtimeNow = gmdate ( " D, d M Y H:i:s " , $mtimeNow ) . " GMT " ;
2012-10-18 15:17:21 -04:00
$outputHeader .= " Date: $gmt_mtimeNow */ \n " ;
$output = " " ;
//Base files
2017-12-04 13:25:35 +00:00
switch ( strtolower ( $skinVariant )) {
2012-10-18 15:17:21 -04:00
case " extjs " :
//Base
$baseCSSPath = PATH_SKIN_ENGINE . " base " . PATH_SEP . " baseCss " . PATH_SEP ;
2017-12-04 13:25:35 +00:00
$output .= file_get_contents ( $baseCSSPath . 'ext-all-notheme.css' );
2012-10-18 15:17:21 -04:00
//Classic Skin
$extJsSkin = 'xtheme-gray' ;
break ;
default :
break ;
}
//Get Browser Info
2017-12-04 13:25:35 +00:00
$infoBrowser = G :: browser_detection ( 'full_assoc' );
2012-10-18 15:17:21 -04:00
$browserName = $infoBrowser [ 'browser_working' ];
2017-12-04 13:25:35 +00:00
if ( isset ( $infoBrowser [ $browserName . '_data' ])) {
2012-10-18 15:17:21 -04:00
if ( $infoBrowser [ $browserName . '_data' ][ 0 ] != " " ) {
$browserName = $infoBrowser [ $browserName . '_data' ][ 0 ];
}
}
//Read Configuration File
2017-12-04 13:25:35 +00:00
$xmlConfiguration = file_get_contents ( $configurationFile );
2012-11-07 17:09:51 -04:00
$xmlConfigurationObj = G :: xmlParser ( $xmlConfiguration );
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
$skinFilesArray = $xmlConfigurationObj -> result [ 'skinConfiguration' ][ '__CONTENT__' ][ 'cssFiles' ][ '__CONTENT__' ][ $skinVariant ][ '__CONTENT__' ][ 'cssFile' ];
2012-10-18 15:17:21 -04:00
foreach ( $skinFilesArray as $keyFile => $cssFileInfo ) {
2018-01-15 12:00:22 +00:00
$enabledBrowsers = explode ( " , " , $cssFileInfo [ '__ATTRIBUTES__' ][ 'enabledBrowsers' ]);
2012-11-07 17:09:51 -04:00
$disabledBrowsers = explode ( " , " , $cssFileInfo [ '__ATTRIBUTES__' ][ 'disabledBrowsers' ]);
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
if ((( in_array ( $browserName , $enabledBrowsers )) || ( in_array ( 'ALL' , $enabledBrowsers ))) && ( ! ( in_array ( $browserName , $disabledBrowsers )))) {
2012-10-18 15:17:21 -04:00
if ( $cssFileInfo [ '__ATTRIBUTES__' ][ 'file' ] == 'rtl.css' ) {
2017-12-04 13:25:35 +00:00
$oServerConf = ServerConf :: getSingleton ();
2012-10-18 15:17:21 -04:00
if ( ! ( defined ( 'SYS_LANG' ))) {
if ( isset ( $_SERVER [ 'HTTP_REFERER' ])) {
$syss = explode ( '://' , $_SERVER [ 'HTTP_REFERER' ]);
2018-01-15 12:00:22 +00:00
$sysObjets = explode ( '/' , $syss [ '1' ]);
2012-10-18 15:17:21 -04:00
$sysLang = $sysObjets [ '2' ];
} else {
$sysLang = 'en' ;
}
} else {
$sysLang = SYS_LANG ;
}
if ( $oServerConf -> isRtl ( $sysLang )) {
2018-01-15 12:00:22 +00:00
$output .= file_get_contents ( $baseSkinDirectory . PATH_SEP . 'css' . PATH_SEP . $cssFileInfo [ '__ATTRIBUTES__' ][ 'file' ]);
2012-10-18 15:17:21 -04:00
}
} else {
2018-01-15 12:00:22 +00:00
$output .= file_get_contents ( $baseSkinDirectory . PATH_SEP . 'css' . PATH_SEP . $cssFileInfo [ '__ATTRIBUTES__' ][ 'file' ]);
2012-10-18 15:17:21 -04:00
}
}
}
//Remove comments..
2018-01-15 12:00:22 +00:00
$regex = array ( " `^([ \t \ s]+)`ism " => '' , " `^ \ / \ *(.+?) \ * \ /`ism " => " " , " `([ \n \ A;]+) \ / \ *(.+?) \ * \ /`ism " => " $ 1 " , " `([ \n \ A; \ s]+)//(.+?)[ \n \r ]`ism " => " $ 1 \n " , " `(^[ \r \n ]*|[ \r \n ]+)[ \ s \t ]*[ \r \n ]+`ism " => " \n " );
2017-12-04 13:25:35 +00:00
$output = preg_replace ( array_keys ( $regex ), $regex , $output );
2012-10-18 15:17:21 -04:00
$output = $outputHeader . $output ;
return $output ;
}
/**
2012-11-07 17:09:51 -04:00
* streaming the translation .< lang >. js file
* take the WEB - INF / translation .< lang > file and append it to file js / widgets / lang /< lang >. js file
2012-10-18 15:17:21 -04:00
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $file
* @ param boolean $download
* @ param string $downloadFileName
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function streamJSTranslationFile ( $filename , $locale = 'en' )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$defaultTranslations = array ();
$foreignTranslations = array ();
2012-10-18 15:17:21 -04:00
2012-11-07 17:09:51 -04:00
//if the default translations table doesn't exist we can't proceed
2018-01-15 12:00:22 +00:00
if ( ! is_file ( PATH_LANGUAGECONT . 'translation.en' )) {
return ;
2012-10-18 15:17:21 -04:00
}
2012-11-07 17:09:51 -04:00
//load the translations table
2017-12-04 13:25:35 +00:00
require_once ( PATH_LANGUAGECONT . 'translation.en' );
2012-11-07 17:09:51 -04:00
$defaultTranslations = $translation ;
2012-10-18 15:17:21 -04:00
2012-11-07 17:09:51 -04:00
//if some foreign language was requested and its translation file exists
2017-12-04 13:25:35 +00:00
if ( $locale != 'en' && file_exists ( PATH_LANGUAGECONT . 'translation.' . $locale )) {
require_once ( PATH_LANGUAGECONT . 'translation.' . $locale ); //load the foreign translations table
2012-11-07 17:09:51 -04:00
$foreignTranslations = $translation ;
}
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( defined ( " SHOW_UNTRANSLATED_AS_TAG " ) && SHOW_UNTRANSLATED_AS_TAG != 0 ) {
2012-11-07 17:09:51 -04:00
$translation = $foreignTranslations ;
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$translation = array_merge ( $defaultTranslations , $foreignTranslations );
2012-10-18 15:17:21 -04:00
}
2012-11-07 17:09:51 -04:00
$calendarJs = '' ;
2018-01-15 12:00:22 +00:00
$calendarJsFile = PATH_GULLIVER_HOME . " js/widgets/js-calendar/lang/ " . $locale . " .js " ;
if ( ! file_exists ( $calendarJsFile )) {
2012-11-16 17:16:01 -04:00
$calendarJsFile = PATH_GULLIVER_HOME . " js/widgets/js-calendar/lang/en.js " ;
2012-10-18 15:17:21 -04:00
}
2012-11-19 11:16:43 -04:00
$calendarJs = file_get_contents ( $calendarJsFile ) . " \n " ;
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
return $calendarJs . 'var TRANSLATIONS = ' . G :: json_encode ( $translation ) . ';' ;
2012-10-18 15:17:21 -04:00
}
/**
* streaming a file
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $file
* @ param boolean $download
* @ param string $downloadFileName
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function streamFile ( $file , $download = false , $downloadFileName = '' )
2012-10-18 15:17:21 -04:00
{
2015-03-17 09:29:04 -04:00
$filter = new InputFilter ();
$file = $filter -> xssFilterHard ( $file );
2017-12-04 13:25:35 +00:00
if ( isset ( $_SERVER [ 'REQUEST_URI' ])) {
$_SERVER [ 'REQUEST_URI' ] = $filter -> xssFilterHard ( $_SERVER [ 'REQUEST_URI' ], " url " );
2015-03-16 15:24:35 -04:00
}
2017-12-04 13:25:35 +00:00
require_once ( PATH_THIRDPARTY . 'jsmin/jsmin.php' );
$folderarray = explode ( '/' , $file );
$typearray = explode ( '.' , basename ( $file ));
$typefile = $typearray [ count ( $typearray ) - 1 ];
2012-10-18 15:17:21 -04:00
$filename = $file ;
2012-11-07 17:09:51 -04:00
//trick to generate the translation.language.js file , merging two files
2017-12-04 13:25:35 +00:00
if ( strtolower ( $typefile ) == 'js' && $typearray [ 0 ] == 'translation' ) {
2015-03-16 15:24:35 -04:00
$download = $filter -> xssFilterHard ( $download );
2015-03-17 09:29:04 -04:00
$downloadFileName = $filter -> xssFilterHard ( $downloadFileName );
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/javascript' , $download , $downloadFileName );
$output = G :: streamJSTranslationFile ( $filename , $typearray [ 1 ]);
2015-03-17 09:29:04 -04:00
$output = $filter -> xssFilterHard ( $output );
2012-10-18 15:17:21 -04:00
print $output ;
return ;
}
//trick to generate the big css file for ext style .
2017-12-04 13:25:35 +00:00
if ( strtolower ( $typefile ) == 'css' && $folderarray [ count ( $folderarray ) - 2 ] == 'css' ) {
G :: sendHeaders ( $filename , 'text/css' , $download , $downloadFileName );
$output = G :: streamCSSBigFile ( $typearray [ 0 ]);
2015-03-17 09:29:04 -04:00
$output = $filter -> xssFilterHard ( $output );
2012-10-18 15:17:21 -04:00
print $output ;
return ;
}
2017-12-04 13:25:35 +00:00
if ( file_exists ( $filename )) {
switch ( strtolower ( $typefile )) {
2012-10-18 15:17:21 -04:00
case 'swf' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'application/x-shockwave-flash' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'js' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/javascript' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'htm' :
case 'html' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/html' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'htc' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/plain' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'json' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/plain' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'gif' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'image/gif' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'png' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'image/png' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'jpg' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'image/jpg' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'css' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/css' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'xml' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/xml' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'txt' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/html' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'pdf' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'application/pdf' , $download , $downloadFileName );
2017-01-19 10:27:02 -04:00
break ;
case 'doc' :
2012-10-18 15:17:21 -04:00
case 'pm' :
case 'po' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'application/octet-stream' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
case 'php' :
if ( $download ) {
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'text/plain' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
} else {
2017-02-08 16:01:52 -04:00
if ( \Bootstrap :: getDisablePhpUploadExecution () === 0 ) {
\Bootstrap :: registerMonologPhpUploadExecution ( 'phpExecution' , 200 , 'Php Execution' , $filename );
2017-12-04 13:25:35 +00:00
require_once ( $filename );
2017-02-08 16:01:52 -04:00
} else {
2018-08-28 09:34:11 -04:00
$message = G :: LoadTranslation ( 'ID_THE_PHP_FILES_EXECUTION_WAS_DISABLED' );
2017-02-08 16:01:52 -04:00
\Bootstrap :: registerMonologPhpUploadExecution ( 'phpExecution' , 550 , $message , $filename );
echo $message ;
}
2012-10-18 15:17:21 -04:00
return ;
}
break ;
case 'tar' :
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'application/x-tar' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
default :
//throw new Exception ( "Unknown type of file '$file'. " );
2017-12-04 13:25:35 +00:00
G :: sendHeaders ( $filename , 'application/octet-stream' , $download , $downloadFileName );
2012-10-18 15:17:21 -04:00
break ;
}
} else {
2017-12-04 13:25:35 +00:00
if ( strpos ( $file , 'gulliver' ) !== false ) {
list ( $path , $filename ) = explode ( 'gulliver' , $file );
2012-10-18 15:17:21 -04:00
}
$_SESSION [ 'phpFileNotFound' ] = $file ;
2017-12-04 13:25:35 +00:00
G :: header ( " location: /errors/error404.php?l= " . $_SERVER [ 'REQUEST_URI' ]);
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
if ( substr ( $filename , - 10 ) == " ext-all.js " ) {
2012-11-12 14:44:44 -04:00
$filename = PATH_GULLIVER_HOME . 'js/ext/min/ext-all.js' ;
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
@ readfile ( $filename );
2012-10-18 15:17:21 -04:00
}
/**
* sendHeaders
*
* @ param string $filename
* @ param string $contentType default value ''
* @ param boolean $download default value false
* @ param string $downloadFileName default value ''
*
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function sendHeaders ( $filename , $contentType = '' , $download = false , $downloadFileName = '' )
2012-10-18 15:17:21 -04:00
{
if ( $download ) {
if ( $downloadFileName == '' ) {
2017-01-19 10:27:02 -04:00
$aAux = explode ( '/' , $filename );
$downloadFileName = $aAux [ count ( $aAux ) - 1 ];
2012-10-18 15:17:21 -04:00
}
2017-01-19 10:27:02 -04:00
header ( 'Content-Disposition: attachment; filename="' . $downloadFileName . '"' );
} else {
header ( 'Content-Disposition: inline; filename="' . $downloadFileName . '"' );
2012-10-18 15:17:21 -04:00
}
2017-01-19 10:27:02 -04:00
header ( 'Content-Type: ' . $contentType );
2012-10-18 15:17:21 -04:00
//if userAgent (BROWSER) is MSIE we need special headers to avoid MSIE behaivor.
2017-12-04 13:25:35 +00:00
$userAgent = strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ]);
if ( preg_match ( " /msie/i " , $userAgent )) {
2012-10-18 15:17:21 -04:00
//if ( ereg("msie", $userAgent)) {
2017-12-04 13:25:35 +00:00
header ( 'Pragma: cache' );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( file_exists ( $filename )) {
$mtime = filemtime ( $filename );
2012-11-08 15:47:14 -04:00
} else {
2017-12-04 13:25:35 +00:00
$mtime = date ( 'U' );
2012-11-08 15:47:14 -04:00
}
2017-12-04 13:25:35 +00:00
$gmt_mtime = gmdate ( " D, d M Y H:i:s " , $mtime ) . " GMT " ;
header ( 'ETag: "' . G :: encryptOld ( $mtime . $filename ) . '"' );
header ( " Last-Modified: " . $gmt_mtime );
header ( 'Cache-Control: public' );
header ( " Expires: " . gmdate ( " D, d M Y H:i:s " , time () + 60 * 10 ) . " GMT " ); //ten minutes
2012-10-18 15:17:21 -04:00
return ;
}
if ( ! $download ) {
2017-12-04 13:25:35 +00:00
header ( 'Pragma: cache' );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( file_exists ( $filename )) {
$mtime = filemtime ( $filename );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$mtime = date ( 'U' );
}
$gmt_mtime = gmdate ( " D, d M Y H:i:s " , $mtime ) . " GMT " ;
header ( 'ETag: "' . G :: encryptOld ( $mtime . $filename ) . '"' );
header ( " Last-Modified: " . $gmt_mtime );
header ( 'Cache-Control: public' );
header ( " Expires: " . gmdate ( " D, d M Y H:i:s " , time () + 90 * 60 * 60 * 24 ) . " GMT " );
if ( isset ( $_SERVER [ 'HTTP_IF_MODIFIED_SINCE' ])) {
2012-10-18 15:17:21 -04:00
if ( $_SERVER [ 'HTTP_IF_MODIFIED_SINCE' ] == $gmt_mtime ) {
2017-12-04 13:25:35 +00:00
header ( 'HTTP/1.1 304 Not Modified' );
2012-10-18 15:17:21 -04:00
exit ();
}
}
2017-12-04 13:25:35 +00:00
if ( isset ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ])) {
if ( str_replace ( '"' , '' , stripslashes ( $_SERVER [ 'HTTP_IF_NONE_MATCH' ])) == G :: encryptOld ( $mtime . $filename )) {
header ( " HTTP/1.1 304 Not Modified " );
2012-10-18 15:17:21 -04:00
exit ();
}
}
}
}
/**
* Transform a public URL into a local path .
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param string $url
* @ param string $corvertionTable
* @ param string $realPath = local path
* @ return boolean
*/
2018-01-25 20:32:51 +00:00
public static function virtualURI ( $url , $convertionTable , & $realPath )
2012-10-18 15:17:21 -04:00
{
foreach ( $convertionTable as $urlPattern => $localPath ) {
// $urlPattern = addcslashes( $urlPattern , '/');
2017-12-04 13:25:35 +00:00
$urlPattern = addcslashes ( $urlPattern , './' );
2018-01-15 12:00:22 +00:00
$urlPattern = '/^' . str_replace ( array ( '*' , '?'
), array ( '.*' , '.?'
2017-12-04 13:25:35 +00:00
), $urlPattern ) . '$/' ;
if ( preg_match ( $urlPattern , $url , $match )) {
2012-10-18 15:17:21 -04:00
if ( $localPath === false ) {
$realPath = $url ;
return false ;
}
if ( $localPath != 'jsMethod' ) {
$realPath = $localPath . $match [ 1 ];
} else {
$realPath = $localPath ;
}
return true ;
}
}
$realPath = $url ;
return false ;
}
/**
* Create an encrypted unique identifier based on $id and the selected scope id .
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param string $scope
* @ param string $id
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function createUID ( $scope , $id )
2012-10-18 15:17:21 -04:00
{
$e = $scope . $id ;
2017-12-04 13:25:35 +00:00
$e = G :: encrypt ( $e , URL_KEY );
$e = str_replace ( array ( '+' , '/' , '='
), array ( '__' , '_' , '___'
), base64_encode ( $e ));
2012-10-18 15:17:21 -04:00
return $e ;
}
/**
* ( Create an encrypted unique identificator based on $id and the selected scope id . ) ^- 1
* getUIDName
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param string $id
* @ param string $scope
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function getUIDName ( $uid , $scope = '' )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
$e = str_replace ( array ( '=' , '+' , '/'
), array ( '___' , '__' , '_'
2017-12-04 13:25:35 +00:00
), $uid );
$e = base64_decode ( $e );
$e = G :: decrypt ( $e , URL_KEY );
$e = substr ( $e , strlen ( $scope ));
2012-10-18 15:17:21 -04:00
return $e ;
}
2019-03-07 16:02:13 -04:00
/**
2018-01-15 12:00:22 +00:00
* formatNumber
2012-10-18 15:17:21 -04:00
*
* @ author David Callizaya < calidavidx21 @ yahoo . com . ar >
* @ param int / string $num
* @ return string number
*/
2018-01-25 20:32:51 +00:00
public static function formatNumber ( $num , $language = 'latin' )
2012-10-18 15:17:21 -04:00
{
switch ( $language ) {
default :
$snum = $num ;
}
return $snum ;
}
2019-03-07 16:02:13 -04:00
/**
2018-01-15 12:00:22 +00:00
* Returns a date formatted according to the given format string
2012-10-18 15:17:21 -04:00
* @ author David Callizaya < calidavidx21 @ hotmail . com >
* @ param string $format The format of the outputted date string
* @ param string $datetime Date in the format YYYY - MM - DD HH : MM : SS
*/
2017-12-04 13:25:35 +00:00
public function formatDate ( $datetime , $format = 'Y-m-d' , $lang = '' )
2012-10-18 15:17:21 -04:00
{
if ( $lang === '' ) {
2017-12-04 13:25:35 +00:00
$lang = defined ( SYS_LANG ) ? SYS_LANG : 'en' ;
}
$aux = explode ( ' ' , $datetime ); //para dividir la fecha del dia
$date = explode ( '-' , isset ( $aux [ 0 ]) ? $aux [ 0 ] : '00-00-00' ); //para obtener los dias, el mes, y el año.
$time = explode ( ':' , isset ( $aux [ 1 ]) ? $aux [ 1 ] : '00:00:00' ); //para obtener las horas, minutos, segundos.
$date [ 0 ] = ( int ) (( isset ( $date [ 0 ])) ? $date [ 0 ] : '0' );
$date [ 1 ] = ( int ) (( isset ( $date [ 1 ])) ? $date [ 1 ] : '0' );
$date [ 2 ] = ( int ) (( isset ( $date [ 2 ])) ? $date [ 2 ] : '0' );
$time [ 0 ] = ( int ) (( isset ( $time [ 0 ])) ? $time [ 0 ] : '0' );
$time [ 1 ] = ( int ) (( isset ( $time [ 1 ])) ? $time [ 1 ] : '0' );
$time [ 2 ] = ( int ) (( isset ( $time [ 2 ])) ? $time [ 2 ] : '0' );
2012-10-18 15:17:21 -04:00
// Spanish months
2018-01-15 12:00:22 +00:00
$ARR_MONTHS [ 'es' ] = array ( " Enero " , " Febrero " , " Marzo " , " Abril " , " Mayo " , " Junio " , " Julio " , " Agosto " , " Septiembre " , " Octubre " , " Noviembre " , " Diciembre " );
2012-10-18 15:17:21 -04:00
// English months
2018-01-15 12:00:22 +00:00
$ARR_MONTHS [ 'en' ] = array ( " January " , " February " , " March " , " April " , " May " , " June " , " July " , " August " , " September " , " October " , " November " , " December " );
2012-10-18 15:17:21 -04:00
// Spanish days
2018-01-15 12:00:22 +00:00
$ARR_WEEKDAYS [ 'es' ] = array ( " Domingo " , " Lunes " , " Martes " , " Miércoles " , " Jueves " , " Viernes " , " Sábado " );
2012-10-18 15:17:21 -04:00
// English days
2018-01-15 12:00:22 +00:00
$ARR_WEEKDAYS [ 'en' ] = array ( " Sunday " , " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " );
2012-10-18 15:17:21 -04:00
if ( $lang == 'fa' ) {
$number = 'persian' ;
} else {
$number = 'latin' ;
}
$d = '0' . $date [ 2 ];
2017-12-04 13:25:35 +00:00
$d = G :: formatNumber ( substr ( $d , strlen ( $d ) - 2 , 2 ), $number );
$j = G :: formatNumber ( $date [ 2 ], $number );
$F = isset ( $ARR_MONTHS [ $lang ][ $date [ 1 ] - 1 ]) ? $ARR_MONTHS [ $lang ][ $date [ 1 ] - 1 ] : '' ;
2012-10-18 15:17:21 -04:00
$m = '0' . $date [ 1 ];
2017-12-04 13:25:35 +00:00
$m = G :: formatNumber ( substr ( $m , strlen ( $m ) - 2 , 2 ), $number );
$n = G :: formatNumber ( $date [ 1 ], $number );
$y = G :: formatNumber ( substr ( $date [ 0 ], strlen ( $date [ 0 ]) - 2 , 2 ), $number );
2012-10-18 15:17:21 -04:00
$Y = '0000' . $date [ 0 ];
2017-12-04 13:25:35 +00:00
$Y = G :: formatNumber ( substr ( $Y , strlen ( $Y ) - 4 , 4 ), $number );
2012-10-18 15:17:21 -04:00
$g = ( $time [ 0 ] % 12 );
if ( $g === 0 ) {
$g = 12 ;
}
$G = $time [ 0 ];
$h = '0' . $g ;
2017-12-04 13:25:35 +00:00
$h = G :: formatNumber ( substr ( $h , strlen ( $h ) - 2 , 2 ), $number );
2012-10-18 15:17:21 -04:00
$H = '0' . $G ;
2017-12-04 13:25:35 +00:00
$H = G :: formatNumber ( substr ( $H , strlen ( $H ) - 2 , 2 ), $number );
2012-10-18 15:17:21 -04:00
$i = '0' . $time [ 1 ];
2017-12-04 13:25:35 +00:00
$i = G :: formatNumber ( substr ( $i , strlen ( $i ) - 2 , 2 ), $number );
2012-10-18 15:17:21 -04:00
$s = '0' . $time [ 2 ];
2017-12-04 13:25:35 +00:00
$s = G :: formatNumber ( substr ( $s , strlen ( $s ) - 2 , 2 ), $number );
2018-01-15 12:00:22 +00:00
$names = array ( 'd' , 'j' , 'F' , 'm' , 'n' , 'y' , 'Y' , 'g' , 'G' , 'h' , 'H' , 'i' , 's' );
$values = array ( $d , $j , $F , $m , $n , $y , $Y , $g , $G , $h , $H , $i , $s );
2017-12-04 13:25:35 +00:00
$_formatedDate = str_replace ( $names , $values , $format );
2012-10-18 15:17:21 -04:00
return $_formatedDate ;
}
/**
* getformatedDate
*
* @ param date $date
* @ param string $format default value 'yyyy-mm-dd' ,
* @ param string $lang default value ''
*
* @ return string $ret
*/
2017-12-04 13:25:35 +00:00
public static function getformatedDate ( $date , $format = 'yyyy-mm-dd' , $lang = '' )
2012-10-18 15:17:21 -04:00
{
/**
* ******************************************************************************************************
* if the year is 2008 and the format is yy then -> 08
* if the year is 2008 and the format is yyyy then -> 2008
*
* if the month is 05 and the format is mm then -> 05
* if the month is 05 and the format is m and the month is less than 10 then -> 5 else digit normal
* if the month is 05 and the format is MM or M then -> May
*
* if the day is 5 and the format is dd then -> 05
* if the day is 5 and the format is d and the day is less than 10 then -> 5 else digit normal
* if the day is 5 and the format is DD or D then -> five
* *******************************************************************************************************
*/
//scape the literal
switch ( $lang ) {
case 'es' :
2017-12-04 13:25:35 +00:00
$format = str_replace ( ' del ' , '[ofl]' , $format );
$format = str_replace ( ' de ' , '[of]' , $format );
2012-10-18 15:17:21 -04:00
break ;
}
//first we must formatted the string
2017-12-04 13:25:35 +00:00
$format = str_replace ( 'h' , '{h}' , $format );
$format = str_replace ( 'i' , '{i}' , $format );
$format = str_replace ( 's' , '{s}' , $format );
2013-01-15 15:56:43 -04:00
2017-12-04 13:25:35 +00:00
$format = str_replace ( 'yyyy' , '{YEAR}' , $format );
$format = str_replace ( 'yy' , '{year}' , $format );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$format = str_replace ( 'mm' , '{YONTH}' , $format );
$format = str_replace ( 'm' , '{month}' , $format );
$format = str_replace ( 'M' , '{XONTH}' , $format );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$format = str_replace ( 'dd' , '{DAY}' , $format );
$format = str_replace ( 'd' , '{day}' , $format );
2012-10-18 15:17:21 -04:00
if ( $lang === '' ) {
2017-12-04 13:25:35 +00:00
$lang = defined ( SYS_LANG ) ? SYS_LANG : 'en' ;
2012-10-18 15:17:21 -04:00
}
2013-04-23 17:18:39 +00:00
2017-12-04 13:25:35 +00:00
$aux = explode ( ' ' , $date ); //para dividir la fecha del dia
$date = explode ( '-' , isset ( $aux [ 0 ]) ? $aux [ 0 ] : '00-00-00' ); //para obtener los dias, el mes, y el año.
$time = explode ( ':' , isset ( $aux [ 1 ]) ? $aux [ 1 ] : '00:00:00' ); //para obtener las horas, minutos, segundos.
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$year = ( int ) (( isset ( $date [ 0 ])) ? $date [ 0 ] : '0' ); //year
$month = ( int ) (( isset ( $date [ 1 ])) ? $date [ 1 ] : '0' ); //month
$day = ( int ) (( isset ( $date [ 2 ])) ? $date [ 2 ] : '0' ); //day
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$h = isset ( $time [ 0 ]) ? $time [ 0 ] : '00' ; //hour
$i = isset ( $time [ 1 ]) ? $time [ 1 ] : '00' ; //minute
$s = isset ( $time [ 2 ]) ? $time [ 2 ] : '00' ; //second
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$MONTHS = array ();
2013-04-23 17:18:39 +00:00
for ( $j = 1 ; $j <= 12 ; $j ++ ) {
2017-12-04 13:25:35 +00:00
$MONTHS [ $j ] = G :: LoadTranslation ( " ID_MONTH_ $j " , $lang );
2012-10-18 15:17:21 -04:00
}
$d = ( int ) $day ;
2017-12-04 13:25:35 +00:00
$dd = G :: complete_field ( $day , 2 , 1 );
2012-10-18 15:17:21 -04:00
//missing D
$M = $MONTHS [ $month ];
$m = ( int ) $month ;
2017-12-04 13:25:35 +00:00
$mm = G :: complete_field ( $month , 2 , 1 );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$yy = substr ( $year , strlen ( $year ) - 2 , 2 );
2012-10-18 15:17:21 -04:00
$yyyy = $year ;
2018-01-15 12:00:22 +00:00
$names = array ( '{day}' , '{DAY}' , '{month}' , '{YONTH}' , '{XONTH}' , '{year}' , '{YEAR}' , '{h}' , '{i}' , '{s}' );
$values = array ( $d , $dd , $m , $mm , $M , $yy , $yyyy , $h , $i , $s );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$ret = str_replace ( $names , $values , $format );
2012-10-18 15:17:21 -04:00
//recovering the original literal
switch ( $lang ) {
case 'es' :
2017-12-04 13:25:35 +00:00
$ret = str_replace ( '[ofl]' , ' del ' , $ret );
$ret = str_replace ( '[of]' , ' de ' , $ret );
2012-10-18 15:17:21 -04:00
break ;
}
return $ret ;
}
/**
* By < erik @ colosa . com >
* Here ' s a little wrapper for array_diff - I found myself needing
* to iterate through the edited array , and I didn ' t need to original keys for anything .
*/
2018-01-25 20:32:51 +00:00
public static function arrayDiff ( $array1 , $array2 )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $array1 )) {
2012-10-18 15:17:21 -04:00
$array1 = ( array ) $array1 ;
}
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $array2 )) {
2012-10-18 15:17:21 -04:00
$array2 = ( array ) $array2 ;
}
// This wrapper for array_diff rekeys the array returned
2017-12-04 13:25:35 +00:00
$valid_array = array_diff ( $array1 , $array2 );
2012-10-18 15:17:21 -04:00
// reinstantiate $array1 variable
2017-12-04 13:25:35 +00:00
$array1 = array ();
2012-10-18 15:17:21 -04:00
// loop through the validated array and move elements to $array1
// this is necessary because the array_diff function returns arrays that retain their original keys
foreach ( $valid_array as $valid ) {
$array1 [] = $valid ;
}
return $array1 ;
}
/**
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ name complete_field ( $string , $lenght , $type = { 1 : number / 2 : string / 3 : float })
*/
2017-12-04 13:25:35 +00:00
public static function complete_field ( $campo , $long , $tipo )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$campo = trim ( $campo );
2012-10-18 15:17:21 -04:00
switch ( $tipo ) {
case 1 : //number
2017-12-04 13:25:35 +00:00
$long = $long - strlen ( $campo );
2012-10-18 15:17:21 -04:00
for ( $i = 1 ; $i <= $long ; $i ++ ) {
$campo = " 0 " . $campo ;
}
break ;
case 2 : //string
2017-12-04 13:25:35 +00:00
$long = $long - strlen ( $campo );
2012-10-18 15:17:21 -04:00
for ( $i = 1 ; $i <= $long ; $i ++ ) {
$campo = " " . $campo ;
}
break ;
case 3 : //float
if ( $campo != " 0 " ) {
2017-12-04 13:25:35 +00:00
$vals = explode ( " . " , $long );
2012-10-18 15:17:21 -04:00
$ints = $vals [ 0 ];
$decs = $vals [ 1 ];
2017-12-04 13:25:35 +00:00
$valscampo = explode ( " . " , $campo );
2012-10-18 15:17:21 -04:00
$intscampo = $valscampo [ 0 ];
$decscampo = $valscampo [ 1 ];
2017-12-04 13:25:35 +00:00
$ints = $ints - strlen ( $intscampo );
2012-10-18 15:17:21 -04:00
for ( $i = 1 ; $i <= $ints ; $i ++ ) {
$intscampo = " 0 " . $intscampo ;
}
//los decimales pueden ser 0 uno o dos
2017-12-04 13:25:35 +00:00
$decs = $decs - strlen ( $decscampo );
2012-10-18 15:17:21 -04:00
for ( $i = 1 ; $i <= $decs ; $i ++ ) {
$decscampo = $decscampo . " 0 " ;
}
$campo = $intscampo . " . " . $decscampo ;
} else {
2017-12-04 13:25:35 +00:00
$vals = explode ( " . " , $long );
2012-10-18 15:17:21 -04:00
$ints = $vals [ 0 ];
$decs = $vals [ 1 ];
$campo = " " ;
for ( $i = 1 ; $i <= $ints ; $i ++ ) {
$campo = " 0 " . $campo ;
}
$campod = " " ;
for ( $i = 1 ; $i <= $decs ; $i ++ ) {
$campod = " 0 " . $campod ;
}
$campo = $campo . " . " . $campod ;
}
break ;
}
return $campo ;
}
2019-03-07 16:02:13 -04:00
/**
2018-01-15 12:00:22 +00:00
* Escapes special characters in a string for use in a SQL statement
2019-06-11 10:14:02 -04:00
* @ param string $sqlString The string to be escaped
* @ param string $DBEngine Target DBMS
*/
2019-06-17 09:33:30 -04:00
public static function sqlEscape ( $sqlString , $DBEngine = DB_ADAPTER )
2012-10-18 15:17:21 -04:00
{
2019-06-11 10:14:02 -04:00
$DBEngine = DB_ADAPTER ;
switch ( $DBEngine ) {
2012-10-18 15:17:21 -04:00
case 'mysql' :
2017-12-04 13:25:35 +00:00
$con = Propel :: getConnection ( 'workflow' );
return mysqli_real_escape_string ( $con -> getResource (), stripslashes ( $sqlString ));
2012-10-18 15:17:21 -04:00
break ;
case 'myxml' :
2017-12-04 13:25:35 +00:00
$sqlString = str_replace ( '"' , '""' , $sqlString );
return str_replace ( " ' " , " '' " , $sqlString );
2012-10-18 15:17:21 -04:00
break ;
default :
2017-12-04 13:25:35 +00:00
return addslashes ( stripslashes ( $sqlString ));
2012-10-18 15:17:21 -04:00
break ;
}
}
/**
* Function MySQLSintaxis
*
* @ access public
* @ return Boolean
*
*/
2018-01-25 20:32:51 +00:00
public static function MySQLSintaxis ()
2012-10-18 15:17:21 -04:00
{
$DBEngine = DB_ADAPTER ;
switch ( $DBEngine ) {
case 'mysql' :
return true ;
break ;
case 'mssql' :
default :
return false ;
break ;
}
}
2019-03-07 16:02:13 -04:00
/**
2018-01-15 12:00:22 +00:00
* Returns a sql string with @@ parameters replaced with its values defined
2012-10-18 15:17:21 -04:00
* in array $result using the next notation :
* NOTATION :
* @@ Quoted parameter acording to the SYSTEM ' s Database
* @ Q Double quoted parameter \\ \ "
* @ q Single quoted parameter \\ \ '
* @% URL string
* @ # Non-quoted parameter
* @! Evaluate string : Replace the parameters in value and then in the sql string
* @ fn () Evaluate string with the function " fn "
2019-06-11 10:14:02 -04:00
* @ author David Callizaya < calidavidx21 @ hotmail . com >
2012-10-18 15:17:21 -04:00
*/
2019-06-11 10:14:02 -04:00
public static function replaceDataField ( $sqlString , $result , $DBEngine = 'mysql' )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $result )) {
2017-12-04 13:25:35 +00:00
$result = array ();
2012-10-18 15:17:21 -04:00
}
$result = $result + G :: getSystemConstants ();
$__textoEval = " " ;
$u = 0 ;
2017-12-04 13:25:35 +00:00
$count = preg_match_all ( '/\@(?:([\@\%\#\?\$\=\&Qq\!])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+|\-\>([a-zA-Z\_]\w*))?/' , $sqlString , $match , PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
2012-10-18 15:17:21 -04:00
if ( $count ) {
for ( $r = 0 ; $r < $count ; $r ++ ) {
2018-01-15 12:00:22 +00:00
if ( ! isset ( $result [ $match [ 2 ][ $r ][ 0 ]])) {
2012-10-18 15:17:21 -04:00
$result [ $match [ 2 ][ $r ][ 0 ]] = '' ;
}
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $result [ $match [ 2 ][ $r ][ 0 ]])) {
2017-12-04 13:25:35 +00:00
$__textoEval .= substr ( $sqlString , $u , $match [ 0 ][ $r ][ 1 ] - $u );
$u = $match [ 0 ][ $r ][ 1 ] + strlen ( $match [ 0 ][ $r ][ 0 ]);
2012-10-18 15:17:21 -04:00
//Mysql quotes scape
2017-12-04 13:25:35 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == '@' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
2019-06-11 10:14:02 -04:00
$__textoEval .= " \" " . G :: sqlEscape ( $result [ $match [ 2 ][ $r ][ 0 ]], $DBEngine ) . " \" " ;
2012-10-18 15:17:21 -04:00
continue ;
}
//URL encode
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == '%' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
$__textoEval .= urlencode ( $result [ $match [ 2 ][ $r ][ 0 ]]);
2012-10-18 15:17:21 -04:00
continue ;
}
//Double quoted parameter
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == 'Q' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
$__textoEval .= '"' . addcslashes ( $result [ $match [ 2 ][ $r ][ 0 ]], '\\"' ) . '"' ;
2012-10-18 15:17:21 -04:00
continue ;
}
//Single quoted parameter
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == 'q' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
$__textoEval .= " ' " . addcslashes ( $result [ $match [ 2 ][ $r ][ 0 ]], '\\\'' ) . " ' " ;
2012-10-18 15:17:21 -04:00
continue ;
}
//Substring (Sub replaceDataField)
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == '!' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
2019-06-11 10:14:02 -04:00
$__textoEval .= G :: replaceDataField ( $result [ $match [ 2 ][ $r ][ 0 ]], $result );
2012-10-18 15:17:21 -04:00
continue ;
}
//Call function
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] === '' ) && ( $match [ 2 ][ $r ][ 0 ] === '' ) && ( $match [ 3 ][ $r ][ 0 ] !== '' )) {
2017-12-04 13:25:35 +00:00
eval ( '$strAux = ' . $match [ 3 ][ $r ][ 0 ] . '(\'' . addcslashes ( G :: replaceDataField ( stripslashes ( $match [ 4 ][ $r ][ 0 ]), $result ), '\\\'' ) . '\');' );
2012-10-18 15:17:21 -04:00
if ( $match [ 3 ][ $r ][ 0 ] == " G::LoadTranslation " ) {
2018-01-15 12:00:22 +00:00
$arraySearch = array ( " ' " );
2012-10-18 15:17:21 -04:00
$arrayReplace = array ( " \\ ' " );
$strAux = str_replace ( $arraySearch , $arrayReplace , $strAux );
}
$__textoEval .= $strAux ;
continue ;
}
//Non-quoted
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == '#' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
2019-06-17 09:33:30 -04:00
$__textoEval .= $result [ $match [ 2 ][ $r ][ 0 ]];
2012-10-18 15:17:21 -04:00
continue ;
}
//Non-quoted =
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == '=' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
2019-06-17 09:33:30 -04:00
$__textoEval .= $result [ $match [ 2 ][ $r ][ 0 ]];
2012-10-18 15:17:21 -04:00
continue ;
}
2016-11-17 06:54:34 -05:00
//Objects attributes
2018-01-15 12:00:22 +00:00
if (( $match [ 1 ][ $r ][ 0 ] == '&' ) && ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]]))) {
2016-11-17 06:54:34 -05:00
if ( isset ( $result [ $match [ 2 ][ $r ][ 0 ]] -> { $match [ 6 ][ $r ][ 0 ]})) {
2019-06-11 10:14:02 -04:00
$__textoEval .= $result [ $match [ 2 ][ $r ][ 0 ]] -> { $match [ 6 ][ $r ][ 0 ]};
2016-11-17 06:54:34 -05:00
}
continue ;
}
2012-10-18 15:17:21 -04:00
}
}
}
2018-01-15 12:00:22 +00:00
$__textoEval .= substr ( $sqlString , $u );
2012-10-18 15:17:21 -04:00
return $__textoEval ;
}
/**
2019-06-11 10:14:02 -04:00
* Replace Grid Values
* The tag @> GRID - NAME to open the grid and @< GRID - NAME to close the grid ,
*
* @ param type String $sContent
* @ param type Array $aFields
* @ return type String
*/
public static function replaceDataGridField ( $sContent , $aFields , $nl2brRecursive = true )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
$nrt = array ( " \n " , " \r " , " \t " );
2013-01-10 16:18:38 -04:00
$nrthtml = array ( " (n /) " , " (r /) " , " (t /) " );
2019-06-11 10:14:02 -04:00
$sContent = G :: unhtmlentities ( $sContent );
$strContentAux = str_replace ( $nrt , $nrthtml , $sContent );
2013-01-10 16:18:38 -04:00
2019-06-11 10:14:02 -04:00
$iOcurrences = preg_match_all ( '/\@(?:([\>])([a-zA-Z\_]\w*)|([a-zA-Z\_][\w\-\>\:]*)\(((?:[^\\\\\)]*(?:[\\\\][\w\W])?)*)\))((?:\s*\[[\'"]?\w+[\'"]?\])+)?/' , $strContentAux , $arrayMatch1 , PREG_PATTERN_ORDER | PREG_OFFSET_CAPTURE );
2012-10-18 15:17:21 -04:00
2019-06-11 10:14:02 -04:00
if ( $iOcurrences ) {
2012-10-18 15:17:21 -04:00
$arrayGrid = array ();
2013-01-10 16:18:38 -04:00
2019-06-11 10:14:02 -04:00
for ( $i = 0 ; $i <= $iOcurrences - 1 ; $i ++ ) {
2012-10-18 15:17:21 -04:00
$arrayGrid [] = $arrayMatch1 [ 2 ][ $i ][ 0 ];
}
$arrayGrid = array_unique ( $arrayGrid );
2017-12-04 13:25:35 +00:00
//Given the set: 'valueOne', 'valueOneTwo', where the second string
//contains the first string, this causes the larger string to take
//the second, resulting in a delimitation error, to avoid this problem
2017-08-08 09:53:00 -04:00
//we first search the string larger size.
2017-12-04 13:25:35 +00:00
usort ( $arrayGrid , function ( $a , $b ) {
2017-08-08 09:53:00 -04:00
return strlen ( $b ) - strlen ( $a );
});
2012-10-18 15:17:21 -04:00
foreach ( $arrayGrid as $index => $value ) {
2017-12-04 13:25:35 +00:00
if ( $value !== " " ) {
2013-09-10 10:31:08 -04:00
$grdName = $value ;
2013-01-10 16:18:38 -04:00
2013-09-10 10:31:08 -04:00
$strContentAux1 = $strContentAux ;
2018-01-15 12:00:22 +00:00
$strContentAux = null ;
2013-01-10 16:18:38 -04:00
2013-09-10 10:31:08 -04:00
$ereg = " /^(.*)@> " . $grdName . " (.*)@< " . $grdName . " (.*) $ / " ;
2012-10-18 15:17:21 -04:00
2013-09-10 10:31:08 -04:00
while ( preg_match ( $ereg , $strContentAux1 , $arrayMatch2 )) {
$strData = null ;
2012-10-18 15:17:21 -04:00
2019-06-11 10:14:02 -04:00
if ( isset ( $aFields [ $grdName ]) && is_array ( $aFields [ $grdName ])) {
foreach ( $aFields [ $grdName ] as $aRow ) {
2014-01-22 09:59:52 -04:00
if ( $nl2brRecursive ) {
2019-06-11 10:14:02 -04:00
foreach ( $aRow as $sKey => $vValue ) {
if ( ! is_array ( $vValue )) {
$aRow [ $sKey ] = str_replace ( $nrt , $nrthtml , nl2br ( $aRow [ $sKey ]));
2014-01-22 09:59:52 -04:00
}
}
}
2019-06-11 10:14:02 -04:00
$strData = $strData . G :: replaceDataField ( $arrayMatch2 [ 2 ], $aRow );
2013-09-10 10:31:08 -04:00
}
2012-10-18 15:17:21 -04:00
}
2013-09-10 10:31:08 -04:00
$strContentAux1 = $arrayMatch2 [ 1 ];
2018-01-15 12:00:22 +00:00
$strContentAux = $strData . $arrayMatch2 [ 3 ] . $strContentAux ;
2012-10-18 15:17:21 -04:00
}
2013-01-10 16:18:38 -04:00
2013-09-10 10:31:08 -04:00
$strContentAux = $strContentAux1 . $strContentAux ;
2012-10-18 15:17:21 -04:00
}
}
}
2013-01-10 16:18:38 -04:00
2012-10-18 15:17:21 -04:00
$strContentAux = str_replace ( $nrthtml , $nrt , $strContentAux );
2013-01-10 16:18:38 -04:00
2019-06-11 10:14:02 -04:00
$sContent = $strContentAux ;
2012-10-18 15:17:21 -04:00
2014-01-22 09:59:52 -04:00
if ( $nl2brRecursive ) {
2019-06-11 10:14:02 -04:00
foreach ( $aFields as $sKey => $vValue ) {
if ( ! is_array ( $vValue ) && ! is_object ( $vValue )) {
$aFields [ $sKey ] = nl2br ( $aFields [ $sKey ]);
2014-01-22 09:59:52 -04:00
}
}
}
2019-06-11 10:14:02 -04:00
$sContent = G :: replaceDataField ( $sContent , $aFields );
2012-10-18 15:17:21 -04:00
2019-06-11 10:14:02 -04:00
return $sContent ;
2012-10-18 15:17:21 -04:00
}
2019-03-07 16:02:13 -04:00
/**
2018-01-15 12:00:22 +00:00
* Load strings from a XMLFile .
2012-10-18 15:17:21 -04:00
* @ author David Callizaya < davidsantos @ colosa . com >
* @ parameter $languageFile An xml language file .
* @ parameter $languageId ( es | en |... ) .
* @ parameter $forceParse Force to read and parse the xml file .
*/
2018-01-25 20:32:51 +00:00
public static function loadLanguageFile ( $filename , $languageId = '' , $forceParse = false )
2012-10-18 15:17:21 -04:00
{
global $arrayXmlMessages ;
if ( $languageId === '' ) {
2017-12-04 13:25:35 +00:00
$languageId = defined ( 'SYS_LANG' ) ? SYS_LANG : 'en' ;
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$languageFile = basename ( $filename , '.xml' );
$cacheFile = substr ( $filename , 0 , - 3 ) . $languageId ;
2018-01-15 12:00:22 +00:00
if (( $forceParse ) || ( ! file_exists ( $cacheFile )) || ( filemtime ( $filename ) > filemtime ( $cacheFile ))) {
2012-10-18 15:17:21 -04:00
$languageDocument = new Xml_document ();
2017-12-04 13:25:35 +00:00
$languageDocument -> parseXmlFile ( $filename );
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $arrayXmlMessages )) {
2017-12-04 13:25:35 +00:00
$arrayXmlMessages = array ();
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$arrayXmlMessages [ $languageFile ] = array ();
for ( $r = 0 ; $r < sizeof ( $languageDocument -> children [ 0 ] -> children ); $r ++ ) {
$n = $languageDocument -> children [ 0 ] -> children [ $r ] -> findNode ( $languageId );
2012-10-18 15:17:21 -04:00
if ( $n ) {
$k = $languageDocument -> children [ 0 ] -> children [ $r ] -> name ;
$arrayXmlMessages [ $languageFile ][ $k ] = $n -> value ;
}
}
2017-12-04 13:25:35 +00:00
$f = fopen ( $cacheFile , 'w' );
fwrite ( $f , " <?php \n " );
fwrite ( $f , '$arrayXmlMessages[\'' . $languageFile . '\']=' . 'unserialize(\'' . addcslashes ( serialize ( $arrayXmlMessages [ $languageFile ]), '\\\'' ) . " '); \n " );
fwrite ( $f , " ?> " );
fclose ( $f );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
require ( $cacheFile );
2012-10-18 15:17:21 -04:00
}
}
2019-03-07 16:02:13 -04:00
/**
2018-01-15 12:00:22 +00:00
* Funcion auxiliar Temporal :
* Registra en la base de datos los labels xml usados en el sistema
2012-10-18 15:17:21 -04:00
* @ author David Callizaya < calidavidx21 @ hotmail . com >
*/
2018-01-25 20:32:51 +00:00
public static function registerLabel ( $id , $label )
2012-10-18 15:17:21 -04:00
{
return 1 ;
$dbc = new DBConnection ();
2017-12-04 13:25:35 +00:00
$ses = new DBSession ( $dbc );
$ses -> Execute ( G :: replaceDataField (
2012-10-18 15:17:21 -04:00
' REPLACE INTO `TRANSLATION` ( `TRN_CATEGORY` , `TRN_ID` , `TRN_LANG` , `TRN_VALUE` ) VALUES
2017-12-04 13:25:35 +00:00
( " LABEL " , @@ ID , " ' . SYS_LANG . ' " , @@ LABEL ); ' ,
array ( 'ID' => $id , 'LABEL' => ( $label !== null ? $label : '' )
)
));
2012-10-18 15:17:21 -04:00
}
/**
* Function LoadMenuXml
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param eter string msgID
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function LoadMenuXml ( $msgID )
2012-10-18 15:17:21 -04:00
{
global $arrayXmlMessages ;
2018-01-15 12:00:22 +00:00
if ( ! isset ( $arrayXmlMessages [ 'menus' ])) {
2017-12-04 13:25:35 +00:00
G :: loadLanguageFile ( G :: ExpandPath ( 'content' ) . 'languages/menus.xml' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
G :: registerLabel ( $msgID , $arrayXmlMessages [ 'menus' ][ $msgID ]);
2012-10-18 15:17:21 -04:00
return $arrayXmlMessages [ 'menus' ][ $msgID ];
}
/**
* Function SendMessageXml
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param eter string msgID
* @ param eter string strType
* @ param eter string file
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function SendMessageXml ( $msgID , $strType , $file = " labels " )
2012-10-18 15:17:21 -04:00
{
global $arrayXmlMessages ;
2018-01-15 12:00:22 +00:00
if ( ! isset ( $arrayXmlMessages [ $file ])) {
2017-12-04 13:25:35 +00:00
G :: loadLanguageFile ( G :: ExpandPath ( 'content' ) . 'languages/' . $file . '.xml' );
2012-10-18 15:17:21 -04:00
}
$_SESSION [ 'G_MESSAGE_TYPE' ] = $strType ;
2017-12-04 13:25:35 +00:00
G :: registerLabel ( $msgID , $arrayXmlMessages [ $file ][ $msgID ]);
$_SESSION [ 'G_MESSAGE' ] = nl2br ( $arrayXmlMessages [ $file ][ $msgID ]);
2012-10-18 15:17:21 -04:00
}
/**
* SendTemporalMessage
*
* @ param string $msgID
* @ param string $strType
* @ param string $sType default value 'LABEL'
* @ param date $time default value null
* @ param integer $width default value null
* @ param string $customLabels default value null
*
* @ return void
*/
2017-12-04 13:25:35 +00:00
public static function SendTemporalMessage ( $msgID , $strType , $sType = 'LABEL' , $time = null , $width = null , $customLabels = null )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( isset ( $width )) {
2012-10-18 15:17:21 -04:00
$_SESSION [ 'G_MESSAGE_WIDTH' ] = $width ;
}
2017-12-04 13:25:35 +00:00
if ( isset ( $time )) {
2012-10-18 15:17:21 -04:00
$_SESSION [ 'G_MESSAGE_TIME' ] = $time ;
}
2017-12-04 13:25:35 +00:00
switch ( strtolower ( $sType )) {
2012-10-18 15:17:21 -04:00
case 'label' :
case 'labels' :
$_SESSION [ 'G_MESSAGE_TYPE' ] = $strType ;
2017-12-04 13:25:35 +00:00
$_SESSION [ 'G_MESSAGE' ] = nl2br ( G :: LoadTranslation ( $msgID ));
2012-10-18 15:17:21 -04:00
break ;
case 'string' :
$_SESSION [ 'G_MESSAGE_TYPE' ] = $strType ;
2017-12-04 13:25:35 +00:00
$_SESSION [ 'G_MESSAGE' ] = nl2br ( $msgID );
2012-10-18 15:17:21 -04:00
break ;
}
if ( $customLabels != null ) {
$message = $_SESSION [ 'G_MESSAGE' ];
foreach ( $customLabels as $key => $val ) {
2017-12-04 13:25:35 +00:00
$message = str_replace ( '{' . nl2br ( $key ) . '}' , nl2br ( $val ), $message );
2012-10-18 15:17:21 -04:00
}
$_SESSION [ 'G_MESSAGE' ] = $message ;
}
}
/**
* SendMessage
*
* @ param string $msgID
* @ param string $strType
* @ param string $file default value " labels "
*
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function SendMessage ( $msgID , $strType , $file = " labels " )
2012-10-18 15:17:21 -04:00
{
global $arrayXmlMessages ;
$_SESSION [ 'G_MESSAGE_TYPE' ] = $strType ;
2017-12-04 13:25:35 +00:00
$_SESSION [ 'G_MESSAGE' ] = nl2br ( G :: LoadTranslation ( $msgID ));
2012-10-18 15:17:21 -04:00
}
/**
* SendMessageText
* Just put the $text in the message text
*
* @ param string $text
* @ param string $strType
*
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function SendMessageText ( $text , $strType )
2012-10-18 15:17:21 -04:00
{
global $arrayXmlMessages ;
$_SESSION [ 'G_MESSAGE_TYPE' ] = $strType ;
2017-12-04 13:25:35 +00:00
$_SESSION [ 'G_MESSAGE' ] = nl2br ( $text );
2012-10-18 15:17:21 -04:00
}
/**
* Render message from XML file
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $msgID
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function LoadMessage ( $msgID , $file = " messages " )
2012-10-18 15:17:21 -04:00
{
global $_SESSION ;
global $arrayXmlMessages ;
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $arrayXmlMessages )) {
2017-12-04 13:25:35 +00:00
$arrayXmlMessages = G :: LoadArrayFile ( G :: ExpandPath ( 'content' ) . $file . " . " . SYS_LANG );
2012-10-18 15:17:21 -04:00
}
$aux = $arrayXmlMessages [ $msgID ];
$msg = " " ;
2017-12-04 13:25:35 +00:00
for ( $i = 0 ; $i < strlen ( $aux ); $i ++ ) {
2012-10-18 15:17:21 -04:00
if ( $aux [ $i ] == " $ " ) {
$token = " " ;
$i ++ ;
2017-12-04 13:25:35 +00:00
while ( $i < strlen ( $aux ) && $aux [ $i ] != " " && $aux [ $i ] != " . " && $aux [ $i ] != " ' " && $aux [ $i ] != '"' ) {
2012-10-18 15:17:21 -04:00
$token .= $aux [ $i ++ ];
}
2017-12-04 13:25:35 +00:00
eval ( " \$ msg.= \$ _SESSION[' " . $token . " '] ; " );
2012-10-18 15:17:21 -04:00
$msg .= $aux [ $i ];
} else {
$msg = $msg . $aux [ $i ];
}
}
return $msg ;
}
/**
* Function LoadXmlLabel
* deprecated
*/
2017-12-04 13:25:35 +00:00
public function LoadXmlLabel ( $msgID , $file = 'labels' )
2012-10-18 15:17:21 -04:00
{
return 'xxxxxx' ;
}
/**
* Function LoadMessageXml
*
* @ author David S . Callizaya S . < davidsantos @ colosa . com >
* @ access public
* @ param eter string msgID
* @ param eter string file
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function LoadMessageXml ( $msgID , $file = 'labels' )
2012-10-18 15:17:21 -04:00
{
global $arrayXmlMessages ;
2018-01-15 12:00:22 +00:00
if ( ! isset ( $arrayXmlMessages [ $file ])) {
2017-12-04 13:25:35 +00:00
G :: loadLanguageFile ( G :: ExpandPath ( 'content' ) . 'languages/' . $file . '.xml' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
if ( isset ( $arrayXmlMessages [ $file ][ $msgID ])) {
G :: registerLabel ( $msgID , $arrayXmlMessages [ $file ][ $msgID ]);
2012-10-18 15:17:21 -04:00
return $arrayXmlMessages [ $file ][ $msgID ];
} else {
2017-12-04 13:25:35 +00:00
G :: registerLabel ( $msgID , '' );
2012-10-18 15:17:21 -04:00
return null ;
}
}
/**
* Function LoadTranslationObject
* It generates a global Translation variable that will be used in all the system .
2012-11-07 17:09:51 -04:00
* this script check the file translation in folder shared / META - INF /
*
* deprecated
2012-10-18 15:17:21 -04:00
*
* @ access public
2012-11-07 17:09:51 -04:00
* @ param string lang
2012-10-18 15:17:21 -04:00
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function LoadTranslationObject ( $lang = SYS_LANG )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$defaultTranslations = array ();
$foreignTranslations = array ();
2012-10-18 15:17:21 -04:00
//if the default translations table doesn't exist we can't proceed
2018-01-15 12:00:22 +00:00
if ( ! is_file ( PATH_LANGUAGECONT . 'translation.en' )) {
2012-10-18 15:17:21 -04:00
return null ;
}
2012-11-07 17:09:51 -04:00
//load the translations table
2017-12-04 13:25:35 +00:00
require_once ( PATH_LANGUAGECONT . 'translation.en' );
2012-10-18 15:17:21 -04:00
$defaultTranslations = $translation ;
//if some foreign language was requested and its translation file exists
2017-12-04 13:25:35 +00:00
if ( $lang != 'en' && file_exists ( PATH_LANGUAGECONT . 'translation.' . $lang )) {
require_once ( PATH_LANGUAGECONT . 'translation.' . $lang ); //load the foreign translations table
2012-10-18 15:17:21 -04:00
$foreignTranslations = $translation ;
}
global $translation ;
2017-12-04 13:25:35 +00:00
if ( defined ( " SHOW_UNTRANSLATED_AS_TAG " ) && SHOW_UNTRANSLATED_AS_TAG != 0 ) {
2012-10-18 15:17:21 -04:00
$translation = $foreignTranslations ;
} else {
2017-12-04 13:25:35 +00:00
$translation = array_merge ( $defaultTranslations , $foreignTranslations );
2012-10-18 15:17:21 -04:00
}
return true ;
}
/**
* Function LoadTranslation
*
* @ author Aldo Mauricio Veliz Valenzuela . < mauricio @ colosa . com >
* @ access public
* @ param eter string msgID
* @ param eter string file
* @ param eter array data // erik: associative array within data input to replace for formatted string i.e "any messsage {replaced_label} that contains a replace label"
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function LoadTranslation ( $msgID , $lang = SYS_LANG , $data = null )
2012-10-18 15:17:21 -04:00
{
global $translation ;
2015-04-27 15:49:30 -04:00
// if the second parameter ($lang) is an array, it was specified to use as data
2017-12-04 13:25:35 +00:00
if ( is_array ( $lang )) {
2012-10-18 15:17:21 -04:00
$data = $lang ;
$lang = SYS_LANG ;
}
2017-12-04 13:25:35 +00:00
if ( isset ( $translation [ $msgID ])) {
$translationString = preg_replace ( " [ \n | \r | \n \r ] " , ' ' , $translation [ $msgID ]);
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( isset ( $data ) && is_array ( $data )) {
2012-10-18 15:17:21 -04:00
foreach ( $data as $label => $value ) {
2017-12-04 13:25:35 +00:00
$translationString = str_replace ( '{' . $label . '}' , $value , $translationString );
2012-10-18 15:17:21 -04:00
}
}
return $translationString ;
} else {
2017-12-04 13:25:35 +00:00
if ( defined ( " UNTRANSLATED_MARK " )) {
$untranslatedMark = strip_tags ( UNTRANSLATED_MARK );
2012-10-18 15:17:21 -04:00
} else {
$untranslatedMark = " ** " ;
}
return $untranslatedMark . $msgID . $untranslatedMark ;
}
2013-03-11 10:29:33 -04:00
}
/**
* Function LoadTranslation
*
* @ author Brayan Osmar Pereyra Suxo " Cochalo " . < brayan @ colosa . com >
* @ access public
* @ param eter string name plugin
* @ param eter string id msg
* @ param eter array data
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function LoadTranslationPlugin ( $namePlugin , $msgID , $data = null )
2013-03-11 10:29:33 -04:00
{
eval ( 'global $translation' . $namePlugin . ';' );
$existId = false ;
eval ( 'if (isset( $translation' . $namePlugin . '[$msgID])) { $existId = true; }' );
if ( $existId ) {
eval ( '$translationString = preg_replace( "[\n|\r|\n\r]", " ", $translation' . $namePlugin . '[$msgID] );' );
2017-12-04 13:25:35 +00:00
if ( isset ( $data ) && is_array ( $data )) {
2013-03-11 10:29:33 -04:00
foreach ( $data as $label => $value ) {
2017-12-04 13:25:35 +00:00
$translationString = str_replace ( '{' . $label . '}' , $value , $translationString );
2013-03-11 10:29:33 -04:00
}
}
2012-10-18 15:17:21 -04:00
2013-03-11 10:29:33 -04:00
return $translationString ;
} else {
2017-12-04 13:25:35 +00:00
if ( defined ( " UNTRANSLATED_MARK " )) {
$untranslatedMark = strip_tags ( UNTRANSLATED_MARK );
2013-03-11 10:29:33 -04:00
} else {
$untranslatedMark = " ** " ;
}
return $untranslatedMark . $msgID . $untranslatedMark ;
}
2012-10-18 15:17:21 -04:00
}
/**
* Function getTranslations
*
* @ author Erik Amaru O . < erik @ colosa . com >
* @ access public
* @ param eter array msgIDs
* @ param eter string file
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function getTranslations ( $msgIDs , $lang = SYS_LANG )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $msgIDs )) {
2012-10-18 15:17:21 -04:00
return null ;
}
2017-12-04 13:25:35 +00:00
$translations = array ();
2012-10-18 15:17:21 -04:00
foreach ( $msgIDs as $mID ) {
2017-12-04 13:25:35 +00:00
$translations [ $mID ] = self :: LoadTranslation ( $mID , $lang );
2012-10-18 15:17:21 -04:00
}
return $translations ;
}
/**
* Load an array File Content
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $strFile
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function LoadArrayFile ( $strFile = '' )
2012-10-18 15:17:21 -04:00
{
$res = null ;
if ( $strFile != '' ) {
2017-12-04 13:25:35 +00:00
$src = file ( $strFile );
if ( is_array ( $src )) {
2012-10-18 15:17:21 -04:00
foreach ( $src as $key => $val ) {
2017-12-04 13:25:35 +00:00
$res [ $key ] = trim ( $val );
2012-10-18 15:17:21 -04:00
}
}
}
2017-12-04 13:25:35 +00:00
unset ( $src );
2012-10-18 15:17:21 -04:00
return $res ;
}
/**
* Expand an uri based in the current URI
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $methodPage the method directory and the page
* @ return the expanded uri , later , will encryt the uri ...
*/
2018-01-25 20:32:51 +00:00
public static function expandUri ( $methodPage )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$uri = explode ( '/' , getenv ( 'REQUEST_URI' ));
2012-10-18 15:17:21 -04:00
$sw = 0 ;
$newUri = '' ;
2018-01-15 12:00:22 +00:00
if ( ! defined ( 'SYS_SKIN' )) {
2017-12-04 13:25:35 +00:00
for ( $i = 0 ; $i < count ( $uri ); $i ++ ) {
2012-10-18 15:17:21 -04:00
if ( $sw == 0 ) {
$newUri .= $uri [ $i ] . PATH_SEP ;
}
if ( $uri [ $i ] == SYS_SKIN ) {
$sw = 1 ;
}
}
} else {
for ( $i = 0 ; $i < 4 ; $i ++ ) {
if ( $sw == 0 ) {
$newUri .= $uri [ $i ] . PATH_SEP ;
}
if ( $uri [ $i ] == SYS_SKIN ) {
$sw = 1 ;
}
}
}
$newUri .= $methodPage ;
return $newUri ;
}
/**
* Forces login for generic applications
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $userid
* @ param string $permission
* @ param string $urlNoAccess
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function genericForceLogin ( $permission , $urlNoAccess , $urlLogin = 'login/login' )
2012-10-18 15:17:21 -04:00
{
global $RBAC ;
//the session is expired, go to login page,
//the login page is login/login.html
2018-01-15 12:00:22 +00:00
if ( ! isset ( $_SESSION )) {
2017-12-04 13:25:35 +00:00
header ( 'location: ' . G :: expandUri ( $urlLogin ));
2012-10-18 15:17:21 -04:00
die ();
}
//$permission is an array, we'll verify all permission to allow access.
2017-12-04 13:25:35 +00:00
if ( is_array ( $permission )) {
2012-10-18 15:17:21 -04:00
$aux = $permission ;
} else {
$aux [ 0 ] = $permission ;
}
$sw = 0 ;
2017-12-04 13:25:35 +00:00
for ( $i = 0 ; $i < count ( $aux ); $i ++ ) {
$res = $RBAC -> userCanAccess ( $aux [ $i ]);
2012-10-18 15:17:21 -04:00
if ( $res == 1 ) {
$sw = 1 ;
}
}
//you don't have access to this page
if ( $sw == 0 ) {
2017-12-04 13:25:35 +00:00
header ( 'location: ' . G :: expandUri ( $urlNoAccess ));
2012-10-18 15:17:21 -04:00
die ();
}
}
/**
* capitalize
*
* @ param string $string
*
* @ return string $string
*/
2018-01-25 20:32:51 +00:00
public static function capitalize ( $string )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
return ucfirst ( $string );
2012-10-18 15:17:21 -04:00
}
/**
* toUpper
*
* @ param string $sText
*
* @ return string strtoupper ( $sText )
*/
2017-12-04 13:25:35 +00:00
public static function toUpper ( $sText )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
return strtoupper ( $sText );
2012-10-18 15:17:21 -04:00
}
/**
* toLower
*
* @ param string $sText
* @ return string strtolower ( $sText )
*/
2017-12-04 13:25:35 +00:00
public static function toLower ( $sText )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
return strtolower ( $sText );
2012-10-18 15:17:21 -04:00
}
/**
* http_build_query
*
* @ param string $formdata ,
* @ param string $numeric_prefix default value null ,
* @ param string $key default value null
*
* @ return array $res
*/
2018-01-25 20:32:51 +00:00
public static function http_build_query ( $formdata , $numeric_prefix = null , $key = null )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$res = array ();
2012-10-18 15:17:21 -04:00
foreach (( array ) $formdata as $k => $v ) {
2017-12-04 13:25:35 +00:00
$tmp_key = rawurlencode ( is_int ( $k ) ? $numeric_prefix . $k : $k );
2012-10-18 15:17:21 -04:00
if ( $key ) {
$tmp_key = $key . '[' . $tmp_key . ']' ;
}
2017-12-04 13:25:35 +00:00
if ( is_array ( $v ) || is_object ( $v )) {
$res [] = G :: http_build_query ( $v , null /* or $numeric_prefix if you want to add numeric_prefix to all indexes in array*/ , $tmp_key );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$res [] = $tmp_key . " = " . rawurlencode ( $v );
2012-10-18 15:17:21 -04:00
}
/*
If you want , you can write this as one string :
$res [] = ( ( is_array ( $v ) || is_object ( $v ) ) ? G :: http_build_query ( $v , null , $tmp_key ) : $tmp_key . " = " . urlencode ( $v ) );
*/
}
2017-12-04 13:25:35 +00:00
$separator = ini_get ( 'arg_separator.output' );
return implode ( $separator , $res );
2012-10-18 15:17:21 -04:00
}
/**
* Redirect URL
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $parameter
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function header ( $parameter )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( defined ( 'ENABLE_ENCRYPT' ) && ( ENABLE_ENCRYPT == 'yes' ) && ( substr ( $parameter , 0 , 9 ) == 'location:' )) {
$url = G :: encryptUrl ( substr ( $parameter , 10 ), URL_KEY );
header ( 'location:' . $url );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
header ( $parameter );
2012-10-18 15:17:21 -04:00
}
return ;
}
/**
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $permission
* @ param string $urlNoAccess
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function forceLogin ( $permission = " " , $urlNoAccess = " " )
2012-10-18 15:17:21 -04:00
{
global $RBAC ;
2018-01-15 12:00:22 +00:00
if ( isset ( $_SESSION [ 'USER_LOGGED' ]) && $_SESSION [ 'USER_LOGGED' ] == '' ) {
2017-10-10 12:33:25 -04:00
$sys = ( ENABLE_ENCRYPT == 'yes' ? config ( " system.workspace " ) : " sys " . config ( " system.workspace " ));
2018-01-15 12:00:22 +00:00
$lang = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( SYS_LANG ), URL_KEY ) : SYS_LANG );
$skin = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( SYS_SKIN ), URL_KEY ) : SYS_SKIN );
$login = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( 'login' ), URL_KEY ) : 'login' );
$loginhtml = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( 'login.html' ), URL_KEY ) : 'login.html' );
2012-10-18 15:17:21 -04:00
$direction = " / $sys / $lang / $skin / $login / $loginhtml " ;
die ();
}
$Connection = new DBConnection ();
2017-12-04 13:25:35 +00:00
$ses = new DBSession ( $Connection );
2012-10-18 15:17:21 -04:00
$stQry = " SELECT LOG_STATUS FROM LOGIN WHERE LOG_SID = ' " . session_id () . " ' " ;
2017-12-04 13:25:35 +00:00
$dset = $ses -> Execute ( $stQry );
2012-10-18 15:17:21 -04:00
$row = $dset -> read ();
2017-12-04 13:25:35 +00:00
$sessionPc = defined ( 'SESSION_PC' ) ? SESSION_PC : '' ;
$sessionBrowser = defined ( 'SESSION_BROWSER' ) ? SESSION_BROWSER : '' ;
2012-10-18 15:17:21 -04:00
if (( $sessionPc == " 1 " ) or ( $sessionBrowser == " 1 " )) {
if ( $row [ 'LOG_STATUS' ] == 'X' ) {
2017-10-10 12:33:25 -04:00
$sys = ( ENABLE_ENCRYPT == 'yes' ? config ( " system.workspace " ) : " sys " . config ( " system.workspace " ));
2018-01-15 12:00:22 +00:00
$lang = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( SYS_LANG ), URL_KEY ) : SYS_LANG );
$skin = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( SYS_SKIN ), URL_KEY ) : SYS_SKIN );
$login = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( 'login' ), URL_KEY ) : 'login' );
$loginhtml = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( 'login.html' ), URL_KEY ) : 'login.html' );
2012-10-18 15:17:21 -04:00
$direction = " / $sys / $lang / $skin / $login / $loginhtml " ;
2017-12-04 13:25:35 +00:00
G :: SendMessageXml ( 'ID_CLOSE_SESSION' , " warning " );
header ( " location: $direction " );
2012-10-18 15:17:21 -04:00
die ();
return ;
}
}
2017-12-04 13:25:35 +00:00
if ( defined ( 'SIN_COMPATIBILIDAD_RBAC' ) and SIN_COMPATIBILIDAD_RBAC == 1 ) {
2012-10-18 15:17:21 -04:00
return ;
}
if ( $permission == " " ) {
return ;
}
2017-12-04 13:25:35 +00:00
if ( is_array ( $permission )) {
2012-10-18 15:17:21 -04:00
$aux = $permission ;
} else {
$aux [ 0 ] = $permission ;
}
$sw = 0 ;
2017-12-04 13:25:35 +00:00
for ( $i = 0 ; $i < count ( $aux ); $i ++ ) {
$res = $RBAC -> userCanAccess ( $aux [ $i ]);
2012-10-18 15:17:21 -04:00
if ( $res == 1 ) {
$sw = 1 ;
}
}
if ( $sw == 0 && $urlNoAccess != " " ) {
2018-01-15 12:00:22 +00:00
$aux = explode ( '/' , $urlNoAccess );
2017-10-10 12:33:25 -04:00
$sys = ( ENABLE_ENCRYPT == 'yes' ? config ( " system.workspace " ) : " /sys " . SYS_LANG );
2018-01-15 12:00:22 +00:00
$lang = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( SYS_LANG ), URL_KEY ) : SYS_LANG );
$skin = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( SYS_SKIN ), URL_KEY ) : SYS_SKIN );
$login = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( $aux [ 0 ]), URL_KEY ) : $aux [ 0 ]);
$loginhtml = ( ENABLE_ENCRYPT == 'yes' ? G :: encrypt ( urldecode ( $aux [ 1 ]), URL_KEY ) : $aux [ 1 ]);
2012-10-18 15:17:21 -04:00
//header ("location: /$sys/$lang/$skin/$login/$loginhtml");
2017-12-04 13:25:35 +00:00
header ( " location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw " );
2012-10-18 15:17:21 -04:00
die ();
}
if ( $sw == 0 ) {
2017-12-04 13:25:35 +00:00
header ( " location: /fluid/mNE/o9A/mNGm1aLiop3V4qU/dtij4J°gmaLPwKDU3qNn2qXanw " );
2012-10-18 15:17:21 -04:00
die ();
}
}
/**
* Add slashes to a string
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $val_old
* @ return string
*/
2017-12-04 13:25:35 +00:00
public function add_slashes ( $val_old )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( ! is_string ( $val_old )) {
2012-10-18 15:17:21 -04:00
$val_old = " $val_old " ;
}
2017-12-04 13:25:35 +00:00
$tamano_cadena = strlen ( $val_old );
2012-10-18 15:17:21 -04:00
$contador_cadena = 0 ;
$new_val = " " ;
for ( $contador_cadena = 0 ; $contador_cadena < $tamano_cadena ; $contador_cadena ++ ) {
$car = $val_old [ $contador_cadena ];
2017-12-04 13:25:35 +00:00
if ( $car != chr ( 34 ) && $car != chr ( 39 ) && $car != chr ( 92 )) {
2012-10-18 15:17:21 -04:00
$new_val .= $car ;
} else {
2017-12-04 13:25:35 +00:00
if ( $car2 != chr ( 92 )) {
2012-10-18 15:17:21 -04:00
//print " xmlvar: $new_val -- $car -- $car2 <br>";
2017-12-04 13:25:35 +00:00
$new_val .= chr ( 92 ) . $car ;
2012-10-18 15:17:21 -04:00
} else {
$new_val .= $car ;
}
}
}
return $new_val ;
}
2013-04-29 16:48:29 -04:00
/**
* Extract the structure version value from serializated table field and check it .
* @ return true if the version is bigger than 1
*/
2018-01-25 20:32:51 +00:00
public static function gotDirectoryStructureVer2 ()
2013-04-29 16:48:29 -04:00
{
$configuration = new Configurations ();
2017-10-10 12:33:25 -04:00
if ( ! empty ( config ( " system.workspace " )) && $configuration -> exists ( " ENVIRONMENT_SETTINGS " )) {
2013-04-29 16:48:29 -04:00
return ( $configuration -> getDirectoryStructureVer () > 1 );
}
return false ;
}
/**
* Get the default blank directory 0 for external files
*/
2018-01-25 20:32:51 +00:00
public static function getBlackHoleDir ()
2013-04-29 16:48:29 -04:00
{
//len32:12345678901234567890123456789012
return " 00000000000000000000000000000000 " ;
}
/**
2017-10-24 12:57:09 -04:00
* Function used to fix 32 K issue related to ext3 max subdirectory storage , but checking Version first .
*
2013-04-29 16:48:29 -04:00
* @ param string $uid
* @ param int $splitSize
* @ param int $pieces
2017-10-24 12:57:09 -04:00
*
2013-04-29 16:48:29 -04:00
* @ return string xxx / xxx / xxx / xxxxxxxxxxxxxxxxxxxxx
*/
2017-10-24 12:57:09 -04:00
public static function getPathFromUID ( $uid , $splitSize = 3 , $pieces = 3 )
2013-04-29 16:48:29 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! G :: gotDirectoryStructureVer2 ()) {
2013-04-29 16:48:29 -04:00
return $uid ;
}
return G :: getPathFromUIDPlain ( $uid , $splitSize , $pieces );
}
/**
* Funtion used to fix 32 K issue related to ext3 max subdirectory storage .
* @ param string $uid
* @ param int $splitSize
* @ param int $pieces
* @ return string xxx / xxx / xxx / xxxxxxxxxxxxxxxxxxxxx
*/
2017-10-24 12:57:09 -04:00
public static function getPathFromUIDPlain ( $uid , $splitSize = 3 , $pieces = 3 )
2013-04-29 16:48:29 -04:00
{
$dirArray = array ();
if ( is_string ( $uid ) && strlen ( $uid ) >= 32 && $uid != G :: getBlackHoleDir ()) {
for ( $i = 0 ; $i < $pieces ; $i ++ ) {
$dirArray [] = substr ( $uid , 0 , $splitSize );
$len = strlen ( $uid );
$uid = substr ( $uid , $splitSize , $len );
}
}
$dirArray [] = $uid ;
$newfileStructure = implode ( $dirArray , '/' );
return $newfileStructure ;
}
/**
* Get the uid from the splitted directory + filename .
* @ param string $path
* @ return string
*/
2017-10-24 12:57:09 -04:00
public static function getUIDfromPath ( $path )
2013-04-29 16:48:29 -04:00
{
$uid = '' ;
$item = explode ( $path , '/' );
$len = sizeof ( $item );
for ( $i = 0 ; $i < $len ; $i ++ ) {
$uid .= $item [ $i ];
}
2017-12-04 13:25:35 +00:00
if ( strlen ( $uid ) != 32 ) {
2013-04-29 16:48:29 -04:00
return " invalid " ;
}
return $uid ;
}
/**
* Get the file stored in '0' dir as splitted , but checking version first .
* @ param string $appUid
* @ param string $fileUid
* @ param int $splitSize
* @ param int $pieces
* @ return array index : 0 got the path , index : 1 got the filename
*/
2017-10-24 12:57:09 -04:00
public static function getPathFromFileUID ( $appUid , $fileUid , $splitSize = 3 , $pieces = 3 )
2013-04-29 16:48:29 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! G :: gotDirectoryStructureVer2 ()) {
2013-04-29 16:48:29 -04:00
$response = array ();
$response [] = '' ;
$response [] = $fileUid ;
return $response ;
}
return G :: getPathFromFileUIDPlain ( $appUid , $fileUid , $splitSize , $pieces );
}
/**
* Get the file stored in '0' dir as splitted .
* @ param string $appUid
* @ param string $fileUid
* @ param int $splitSize
* @ param int $pieces
* @ return array index : 0 got the path , index : 1 got the filename
*/
2018-01-25 20:32:51 +00:00
public static function getPathFromFileUIDPlain ( $appUid , $fileUid , $splitSize = 3 , $pieces = 3 )
2013-04-29 16:48:29 -04:00
{
$response = array ();
if ( $appUid == G :: getBlackHoleDir ()) {
$dirArray = array ();
if ( is_string ( $fileUid ) && strlen ( $fileUid ) >= 32 ) {
for ( $i = 0 ; $i < $pieces ; $i ++ ) {
$dirArray [] = substr ( $fileUid , 0 , $splitSize );
$len = strlen ( $fileUid );
$fileUid = substr ( $fileUid , $splitSize , $len );
}
}
$response [] = implode ( $dirArray , '/' ) . '/' ;
$response [] = $fileUid ;
} else {
$response [] = '' ;
$response [] = $fileUid ;
}
return $response ;
}
2012-10-18 15:17:21 -04:00
/**
* Upload a file and then copy to path + nameToSave
*
* @ author Mauricio Veliz < mauricio @ colosa . com >
* @ access public
* @ param string $file
* @ param string $path
* @ param string $nameToSave
* @ param integer $permission
* @ return void
*/
2017-12-04 13:25:35 +00:00
public static function uploadFile ( $file , $path , $nameToSave , $permission = 0755 )
2012-10-18 15:17:21 -04:00
{
try {
if ( $file == '' ) {
2017-12-04 13:25:35 +00:00
throw new Exception ( 'The filename is empty!' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
if ( filesize ( $file ) > (( intval ( ini_get ( 'upload_max_filesize' )) * 1024 ) * 1024 )) {
throw new Exception ( 'The size of upload file exceeds the allowed by the server!' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$oldumask = umask ( 0 );
2018-01-15 12:00:22 +00:00
if ( ! is_dir ( $path )) {
2017-12-04 13:25:35 +00:00
G :: verifyPath ( $path , true );
2015-04-27 12:16:42 -04:00
}
2015-04-09 11:42:33 -04:00
if ( strtoupper ( substr ( PHP_OS , 0 , 3 )) === 'WIN' ) {
2017-12-04 13:25:35 +00:00
$file = str_replace ( " \\ \\ " , " \\ " , $file , $count );
if ( ! $count ) {
$winPath = explode ( " \\ " , $file );
2015-04-09 11:50:46 -04:00
$file = " " ;
2017-12-04 13:25:35 +00:00
foreach ( $winPath as $k => $v ) {
if ( $v != " " ) {
2018-01-15 12:00:22 +00:00
$file .= $v . " \\ " ;
2015-04-09 11:42:33 -04:00
}
2015-04-09 11:50:46 -04:00
}
2017-12-04 13:25:35 +00:00
$file = substr ( $file , 0 , - 1 );
2015-04-27 12:16:42 -04:00
}
2015-04-09 11:42:33 -04:00
}
2015-04-27 12:16:42 -04:00
2017-08-02 16:06:56 -04:00
2015-03-26 17:41:41 -04:00
$filter = new InputFilter ();
2015-04-28 16:10:10 -04:00
$file = $filter -> validateInput ( $file , " path " );
$path = $filter -> validateInput ( $path , " path " );
2015-04-27 12:16:42 -04:00
2017-12-04 13:25:35 +00:00
move_uploaded_file ( $file , $path . " / " . $nameToSave );
2015-05-11 16:36:07 -04:00
$nameToSave = $filter -> validateInput ( $nameToSave , " path " );
2017-12-04 13:25:35 +00:00
@ chmod ( $path . " / " . $nameToSave , $permission );
umask ( $oldumask );
2012-10-18 15:17:21 -04:00
} catch ( Exception $oException ) {
throw $oException ;
}
}
/**
* resizeImage
*
* @ param string $path ,
* @ param string $resWidth
* @ param string $resHeight
* @ param string $saveTo default value null
*
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function resizeImage ( $path , $resWidth , $resHeight , $saveTo = null )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$imageInfo = @ getimagesize ( $path );
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
if ( ! $imageInfo ) {
2017-12-04 13:25:35 +00:00
throw new Exception ( " Could not get image information " );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
list ( $width , $height ) = $imageInfo ;
2012-10-18 15:17:21 -04:00
$percentHeight = $resHeight / $height ;
$percentWidth = $resWidth / $width ;
$percent = ( $percentWidth < $percentHeight ) ? $percentWidth : $percentHeight ;
$resWidth = $width * $percent ;
$resHeight = $height * $percent ;
// Resample
2017-12-04 13:25:35 +00:00
$image_p = imagecreatetruecolor ( $resWidth , $resHeight );
imagealphablending ( $image_p , false );
imagesavealpha ( $image_p , true );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$background = imagecolorallocate ( $image_p , 0 , 0 , 0 );
ImageColorTransparent ( $image_p , $background ); // make the new temp image all transparent
2012-10-18 15:17:21 -04:00
//Assume 3 channels if we can't find that information
2018-01-15 12:00:22 +00:00
if ( ! array_key_exists ( " channels " , $imageInfo )) {
2012-10-18 15:17:21 -04:00
$imageInfo [ " channels " ] = 3 ;
}
2017-12-04 13:25:35 +00:00
$memoryNeeded = Round (( $imageInfo [ 0 ] * $imageInfo [ 1 ] * $imageInfo [ 'bits' ] * $imageInfo [ 'channels' ] + Pow ( 2 , 16 )) * 1.95 ) / ( 1024 * 1024 );
2012-10-18 15:17:21 -04:00
if ( $memoryNeeded < 80 ) {
$memoryNeeded = 80 ;
}
2017-12-04 13:25:35 +00:00
ini_set ( 'memory_limit' , intval ( $memoryNeeded ) . 'M' );
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
$functions = array ( IMAGETYPE_GIF => array ( 'imagecreatefromgif' , 'imagegif'
), IMAGETYPE_JPEG => array ( 'imagecreatefromjpeg' , 'imagejpeg' ), IMAGETYPE_PNG => array ( 'imagecreatefrompng' , 'imagepng' ));
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
if ( ! array_key_exists ( $imageInfo [ 2 ], $functions )) {
2017-12-04 13:25:35 +00:00
throw new Exception ( " Image format not supported " );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
list ( $inputFn , $outputFn ) = $functions [ $imageInfo [ 2 ]];
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$image = $inputFn ( $path );
imagecopyresampled ( $image_p , $image , 0 , 0 , 0 , 0 , $resWidth , $resHeight , $width , $height );
$outputFn ( $image_p , $saveTo );
2019-03-07 16:02:13 -04:00
2017-12-04 13:25:35 +00:00
if ( ! is_null ( $saveTo )) {
2015-05-05 09:55:39 -04:00
$filter = new InputFilter ();
$saveTo = $filter -> validateInput ( $saveTo , " path " );
}
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
@ chmod ( $saveTo , 0666 );
2012-10-18 15:17:21 -04:00
}
/**
* Merge 2 arrays
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ return array
*/
HOR-1293 "Create PMFunction to Send Message to Group PMFSendMessageToGroup" SOLVED
Issue:
Create PMFunction to Send Message to Group PMFSendMessageToGroup
Cause:
Nuevo requerimiento de funcion
Solution:
Se a implementado la nueva funcion:
function PMFSendMessageToGroup(
$groupId,
$caseId,
$from,
$subject,
$template,
$arrayField = [],
$arrayAttachment = [],
$showMessage = true,
$delIndex = 0,
$config = [],
$limit = 100
)
2016-07-21 10:07:00 -04:00
public static function array_merges ()
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$array = array ();
$arrays = func_get_args ();
2012-10-18 15:17:21 -04:00
foreach ( $arrays as $array_i ) {
2017-12-04 13:25:35 +00:00
if ( is_array ( $array_i )) {
G :: array_merge_2 ( $array , $array_i );
2012-10-18 15:17:21 -04:00
}
}
return $array ;
}
/**
* Merge 2 arrays
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ param string $array
* @ param string $array_i
* @ return array
*/
2018-05-09 14:56:16 -04:00
public static function array_merge_2 ( & $array , & $array_i )
2012-10-18 15:17:21 -04:00
{
foreach ( $array_i as $k => $v ) {
2017-12-04 13:25:35 +00:00
if ( is_array ( $v )) {
2018-01-15 12:00:22 +00:00
if ( ! isset ( $array [ $k ])) {
2017-12-04 13:25:35 +00:00
$array [ $k ] = array ();
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
G :: array_merge_2 ( $array [ $k ], $v );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
if ( isset ( $array [ $k ]) && is_array ( $array [ $k ])) {
2012-10-18 15:17:21 -04:00
$array [ $k ][ 0 ] = $v ;
} else {
2018-01-15 12:00:22 +00:00
if ( isset ( $array ) && ! is_array ( $array )) {
2012-10-18 15:17:21 -04:00
$temp = $array ;
$array = array ();
$array [ 0 ] = $temp ;
}
$array [ $k ] = $v ;
}
}
}
}
/**
* Generate random number
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ return int
*/
2017-12-04 13:25:35 +00:00
public static function generateUniqueID ()
2012-10-18 15:17:21 -04:00
{
do {
2017-12-04 13:25:35 +00:00
$sUID = str_replace ( '.' , '0' , uniqid ( rand ( 0 , 999999999 ), true ));
} while ( strlen ( $sUID ) != 32 );
2012-10-18 15:17:21 -04:00
return $sUID ;
//return strtoupper(substr(uniqid(rand(0, 9), false),0,14));
}
/**
* Generate a numeric or alphanumeric code
*
2015-05-05 10:04:26 -04:00
* @ author Julio Cesar Laura Avendaힼjuliocesar @ colosa . com >
2012-10-18 15:17:21 -04:00
* @ access public
* @ return string
*/
2017-12-04 13:25:35 +00:00
public static function generateCode ( $iDigits = 4 , $sType = 'NUMERIC' )
2012-10-18 15:17:21 -04:00
{
if (( $iDigits < 4 ) || ( $iDigits > 50 )) {
$iDigits = 4 ;
}
if (( $sType != 'NUMERIC' ) && ( $sType != 'ALPHA' ) && ( $sType != 'ALPHANUMERIC' )) {
$sType = 'NUMERIC' ;
}
2018-01-15 12:00:22 +00:00
$aValidCharacters = array ( '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'A' , 'B' , 'C' , 'D' , 'E' , 'F' , 'G' , 'H' , 'I' , 'J' , 'K' , 'L' , 'M' , 'N' , 'O' , 'P' , 'Q' , 'R' , 'S' , 'T' , 'U' , 'V' , 'W' , 'X' , 'Y' , 'Z' );
2012-10-18 15:17:21 -04:00
switch ( $sType ) {
case 'NUMERIC' :
$iMin = 0 ;
$iMax = 9 ;
break ;
case 'ALPHA' :
$iMin = 10 ;
$iMax = 35 ;
break ;
case 'ALPHANUMERIC' :
$iMin = 0 ;
$iMax = 35 ;
break ;
}
$sCode = '' ;
for ( $i = 0 ; $i < $iDigits ; $i ++ ) {
2017-12-04 13:25:35 +00:00
$sCode .= $aValidCharacters [ rand ( $iMin , $iMax )];
2012-10-18 15:17:21 -04:00
}
return $sCode ;
}
/**
* Verify if the input string is a valid UID
*
* @ author David Callizaya < davidsantos @ colosa . com >
* @ access public
* @ return int
*/
2017-12-04 13:25:35 +00:00
public function verifyUniqueID ( $uid )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
return ( bool ) preg_match ( '/^[0-9A-Za-z]{14,}/' , $uid );
2012-10-18 15:17:21 -04:00
}
2017-08-08 09:53:00 -04:00
/**
* Verify if the input string is a valid UID of size 32
* @ param string $uid
* @ return boolean
*/
public static function verifyUniqueID32 ( $uid )
{
return ( bool ) preg_match ( '/^[0-9A-Za-z]{32,32}$/' , $uid );
}
2012-10-18 15:17:21 -04:00
/**
* is_utf8
*
* @ param string $string
*
* @ return string utf8_encode ()
*/
2018-01-25 20:32:51 +00:00
public static function is_utf8 ( $string )
2012-10-18 15:17:21 -04:00
{
2017-08-08 09:53:00 -04:00
if ( preg_match ( '//u' , $string )) {
return true ;
2012-10-18 15:17:21 -04:00
} else {
2017-08-08 09:53:00 -04:00
return false ;
2012-10-18 15:17:21 -04:00
}
}
/**
* Return date in Y - m - d format
*
* @ author Fernando Ontiveros Lira < fernando @ colosa . com >
* @ access public
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function CurDate ( $sFormat = '' )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
$sFormat = ( $sFormat != '' ) ? $sFormat : 'Y-m-d H:i:s' ;
2012-10-18 15:17:21 -04:00
return date ( $sFormat );
}
/**
* Return the System defined constants and Application variables
* Constants : SYS_ *
* Sessions : USER_ * , URS_ *
*/
HOR-1293 "Create PMFunction to Send Message to Group PMFSendMessageToGroup" SOLVED
Issue:
Create PMFunction to Send Message to Group PMFSendMessageToGroup
Cause:
Nuevo requerimiento de funcion
Solution:
Se a implementado la nueva funcion:
function PMFSendMessageToGroup(
$groupId,
$caseId,
$from,
$subject,
$template,
$arrayField = [],
$arrayAttachment = [],
$showMessage = true,
$delIndex = 0,
$config = [],
$limit = 100
)
2016-07-21 10:07:00 -04:00
public static function getSystemConstants ( $params = null )
2012-10-18 15:17:21 -04:00
{
$t1 = G :: microtime_float ();
$sysCon = array ();
if ( defined ( " SYS_LANG " )) {
$sysCon [ " SYS_LANG " ] = SYS_LANG ;
}
if ( defined ( " SYS_SKIN " )) {
$sysCon [ " SYS_SKIN " ] = SYS_SKIN ;
}
2017-10-10 12:33:25 -04:00
if ( ! empty ( config ( " system.workspace " ))) {
$sysCon [ " SYS_SYS " ] = config ( " system.workspace " );
2012-10-18 15:17:21 -04:00
}
2018-01-15 12:00:22 +00:00
$sysCon [ " APPLICATION " ] = ( isset ( $_SESSION [ " APPLICATION " ])) ? $_SESSION [ " APPLICATION " ] : " " ;
$sysCon [ " PROCESS " ] = ( isset ( $_SESSION [ " PROCESS " ])) ? $_SESSION [ " PROCESS " ] : " " ;
$sysCon [ " TASK " ] = ( isset ( $_SESSION [ " TASK " ])) ? $_SESSION [ " TASK " ] : " " ;
$sysCon [ " INDEX " ] = ( isset ( $_SESSION [ " INDEX " ])) ? $_SESSION [ " INDEX " ] : " " ;
$sysCon [ " USER_LOGGED " ] = ( isset ( $_SESSION [ " USER_LOGGED " ])) ? $_SESSION [ " USER_LOGGED " ] : " " ;
$sysCon [ " USR_USERNAME " ] = ( isset ( $_SESSION [ " USR_USERNAME " ])) ? $_SESSION [ " USR_USERNAME " ] : " " ;
2012-10-18 15:17:21 -04:00
//###############################################################################################
// Added for compatibility betweek aplication called from web Entry that uses just WS functions
//###############################################################################################
if ( $params != null ) {
if ( isset ( $params -> option )) {
switch ( $params -> option ) {
case " STORED SESSION " :
if ( isset ( $params -> SID )) {
$oSessions = new Sessions ( $params -> SID );
$sysCon = array_merge ( $sysCon , $oSessions -> getGlobals ());
}
break ;
}
}
if ( isset ( $params -> appData ) && is_array ( $params -> appData )) {
$sysCon [ " APPLICATION " ] = $params -> appData [ " APPLICATION " ];
2018-01-15 12:00:22 +00:00
$sysCon [ " PROCESS " ] = $params -> appData [ " PROCESS " ];
$sysCon [ " TASK " ] = $params -> appData [ " TASK " ];
$sysCon [ " INDEX " ] = $params -> appData [ " INDEX " ];
2012-10-18 15:17:21 -04:00
if ( empty ( $sysCon [ " USER_LOGGED " ])) {
2018-01-15 12:00:22 +00:00
$sysCon [ " USER_LOGGED " ] = $params -> appData [ " USER_LOGGED " ];
2012-10-18 15:17:21 -04:00
$sysCon [ " USR_USERNAME " ] = $params -> appData [ " USR_USERNAME " ];
}
}
}
return $sysCon ;
}
/*
* Return the Friendly Title for a string , capitalize every word and remove spaces
* param : text string
*/
2018-01-25 20:32:51 +00:00
public static function capitalizeWords ( $text )
2012-10-18 15:17:21 -04:00
{
2013-01-11 09:00:59 -04:00
return mb_convert_case ( $text , MB_CASE_TITLE , 'UTF-8' );
2012-10-18 15:17:21 -04:00
}
/**
* unhtmlentities
*
* @ param string $string
*
* @ return string substring
*/
2018-01-25 20:32:51 +00:00
public static function unhtmlentities ( $string )
2012-10-18 15:17:21 -04:00
{
2014-10-27 13:38:36 -04:00
if ( version_compare ( PHP_VERSION , '5.4.0' , '<' )) {
2017-12-04 13:25:35 +00:00
$trans_tbl = get_html_translation_table ( HTML_ENTITIES );
2014-10-27 13:38:36 -04:00
} else {
2017-12-04 13:25:35 +00:00
$trans_tbl = get_html_translation_table ( HTML_ENTITIES , ENT_COMPAT , 'ISO-8859-1' );
2014-10-27 13:38:36 -04:00
}
2012-10-18 15:17:21 -04:00
foreach ( $trans_tbl as $k => $v ) {
2017-12-04 13:25:35 +00:00
$ttr [ $v ] = utf8_encode ( $k );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
return strtr ( $string , $ttr );
2012-10-18 15:17:21 -04:00
}
/**
* ************************************* init **********************************************
* Xml parse collection functions
* Returns a associative array within the xml structure and data
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
*/
2018-01-25 20:32:51 +00:00
public static function xmlParser ( & $string )
2012-10-18 15:17:21 -04:00
{
$parser = xml_parser_create ();
2017-12-04 13:25:35 +00:00
xml_parser_set_option ( $parser , XML_OPTION_CASE_FOLDING , 0 );
xml_parse_into_struct ( $parser , $string , $vals , $index );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$mnary = array ();
2012-10-18 15:17:21 -04:00
$ary = & $mnary ;
foreach ( $vals as $r ) {
$t = $r [ 'tag' ];
if ( $r [ 'type' ] == 'open' ) {
2017-12-04 13:25:35 +00:00
if ( isset ( $ary [ $t ])) {
if ( isset ( $ary [ $t ][ 0 ])) {
$ary [ $t ][] = array ();
2012-10-18 15:17:21 -04:00
} else {
2018-01-15 12:00:22 +00:00
$ary [ $t ] = array ( $ary [ $t ], array ());
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$cv = & $ary [ $t ][ count ( $ary [ $t ]) - 1 ];
2012-10-18 15:17:21 -04:00
} else {
$cv = & $ary [ $t ];
}
2017-12-04 13:25:35 +00:00
if ( isset ( $r [ 'attributes' ])) {
2012-10-18 15:17:21 -04:00
foreach ( $r [ 'attributes' ] as $k => $v ) {
$cv [ '__ATTRIBUTES__' ][ $k ] = $v ;
}
}
// note by gustavo cruz gustavo[at]colosa[dot]com
// minor adjustments to validate if an open node have a value attribute.
// for example a dropdown has many childs, but also can have a value attribute.
2017-12-04 13:25:35 +00:00
if ( isset ( $r [ 'value' ]) && trim ( $r [ 'value' ]) != '' ) {
2012-10-18 15:17:21 -04:00
$cv [ '__VALUE__' ] = $r [ 'value' ];
}
// end added code
2017-12-04 13:25:35 +00:00
$cv [ '__CONTENT__' ] = array ();
2012-10-18 15:17:21 -04:00
$cv [ '__CONTENT__' ][ '_p' ] = & $ary ;
$ary = & $cv [ '__CONTENT__' ];
} elseif ( $r [ 'type' ] == 'complete' ) {
2017-12-04 13:25:35 +00:00
if ( isset ( $ary [ $t ])) {
if ( isset ( $ary [ $t ][ 0 ])) {
$ary [ $t ][] = array ();
2012-10-18 15:17:21 -04:00
} else {
2018-01-15 12:00:22 +00:00
$ary [ $t ] = array ( $ary [ $t ], array ());
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$cv = & $ary [ $t ][ count ( $ary [ $t ]) - 1 ];
2012-10-18 15:17:21 -04:00
} else {
$cv = & $ary [ $t ];
}
2017-12-04 13:25:35 +00:00
if ( isset ( $r [ 'attributes' ])) {
2012-10-18 15:17:21 -04:00
foreach ( $r [ 'attributes' ] as $k => $v ) {
$cv [ '__ATTRIBUTES__' ][ $k ] = $v ;
}
}
2017-12-04 13:25:35 +00:00
$cv [ '__VALUE__' ] = ( isset ( $r [ 'value' ]) ? $r [ 'value' ] : '' );
2012-10-18 15:17:21 -04:00
} elseif ( $r [ 'type' ] == 'close' ) {
$ary = & $ary [ '_p' ];
}
}
2017-12-04 13:25:35 +00:00
self :: _del_p ( $mnary );
2012-10-18 15:17:21 -04:00
2013-01-31 11:56:38 -04:00
$obj_resp = new stdclass ();
2017-12-04 13:25:35 +00:00
$obj_resp -> code = xml_get_error_code ( $parser );
$obj_resp -> message = xml_error_string ( $obj_resp -> code );
2012-10-18 15:17:21 -04:00
$obj_resp -> result = $mnary ;
2017-12-04 13:25:35 +00:00
xml_parser_free ( $parser );
2012-10-18 15:17:21 -04:00
return $obj_resp ;
}
/**
* _del_p
*
* @ param string & $ary
*
* @ return void
*/
// _Internal: Remove recursion in result array
2018-01-25 20:32:51 +00:00
public static function _del_p ( & $ary )
2012-10-18 15:17:21 -04:00
{
foreach ( $ary as $k => $v ) {
if ( $k === '_p' ) {
2017-12-04 13:25:35 +00:00
unset ( $ary [ $k ]);
} elseif ( is_array ( $ary [ $k ])) {
self :: _del_p ( $ary [ $k ]);
2012-10-18 15:17:21 -04:00
}
}
}
/**
* ary2xml
*
* Array to XML
*
* @ param string $cary
* @ param string $d = 0
* @ param string $forcetag default value ''
*
* @ return void
*/
// Array to XML
2018-01-25 20:32:51 +00:00
public static function ary2xml ( $cary , $d = 0 , $forcetag = '' )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$res = array ();
2012-10-18 15:17:21 -04:00
foreach ( $cary as $tag => $r ) {
2017-12-04 13:25:35 +00:00
if ( isset ( $r [ 0 ])) {
$res [] = self :: ary2xml ( $r , $d , $tag );
2012-10-18 15:17:21 -04:00
} else {
if ( $forcetag ) {
$tag = $forcetag ;
}
2017-12-04 13:25:35 +00:00
$sp = str_repeat ( " \t " , $d );
2012-10-18 15:17:21 -04:00
$res [] = " $sp < $tag " ;
2017-12-04 13:25:35 +00:00
if ( isset ( $r [ '_a' ])) {
2012-10-18 15:17:21 -04:00
foreach ( $r [ '_a' ] as $at => $av ) {
$res [] = " $at = \" $av\ " " ;
}
}
2017-12-04 13:25:35 +00:00
$res [] = " > " . (( isset ( $r [ '_c' ])) ? " \n " : '' );
if ( isset ( $r [ '_c' ])) {
$res [] = ary2xml ( $r [ '_c' ], $d + 1 );
} elseif ( isset ( $r [ '_v' ])) {
2012-10-18 15:17:21 -04:00
$res [] = $r [ '_v' ];
}
2017-12-04 13:25:35 +00:00
$res [] = ( isset ( $r [ '_c' ]) ? $sp : '' ) . " </ $tag > \n " ;
2012-10-18 15:17:21 -04:00
}
}
2017-12-04 13:25:35 +00:00
return implode ( '' , $res );
2012-10-18 15:17:21 -04:00
}
/**
* ins2ary
*
* Insert element into array
*
* @ param string & $ary
* @ param string $element
* @ param string $pos
*
* @ return void
*/
// Insert element into array
2017-12-04 13:25:35 +00:00
public function ins2ary ( & $ary , $element , $pos )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$ar1 = array_slice ( $ary , 0 , $pos );
2012-10-18 15:17:21 -04:00
$ar1 [] = $element ;
2017-12-04 13:25:35 +00:00
$ary = array_merge ( $ar1 , array_slice ( $ary , $pos ));
2012-10-18 15:17:21 -04:00
}
2018-01-15 12:00:22 +00:00
/**
* Xml parse collection functions
*/
2012-10-18 15:17:21 -04:00
/**
* evalJScript
*
* @ param string $c
*
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function evalJScript ( $c )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
print ( '<script language="javascript">' . $c . '</script>' );
2012-10-18 15:17:21 -04:00
}
/**
* Inflects a string with accented characters and other characteres not suitable for file names , by defaul replace with undescore
*
* @ author Erik Amaru Ortiz < erik @ colosa . com , aortiz . erik @ gamil . com >
2019-03-07 16:02:13 -04:00
* @ param string $string to convert
* @ param string $replacement character for replace
* @ param array $map additional characteres map
* @ return string | string [] | null
* @ see PMXPublisher :: truncateName , Processes :: saveSerializedProcess , XmlExporter :: truncateName
2012-10-18 15:17:21 -04:00
*/
2018-01-25 20:32:51 +00:00
public static function inflect ( $string , $replacement = '_' , $map = array ())
2012-10-18 15:17:21 -04:00
{
2017-08-07 08:51:02 -04:00
if ( is_array ( $replacement )) {
2012-10-18 15:17:21 -04:00
$map = $replacement ;
$replacement = '_' ;
}
2017-08-07 08:51:02 -04:00
$default = array ( '/à|á|å|â/' => 'a' ,
'/è|é|ê|ẽ|ë/' => 'e' ,
'/ì|í|î/' => 'i' ,
'/ò|ó|ô|ø/' => 'o' ,
'/ù|ú|ů|û/' => 'u' ,
'/ç/' => 'c' ,
'/ñ/' => 'n' ,
'/ä|æ/' => 'ae' ,
'/ö/' => 'oe' ,
'/ü/' => 'ue' ,
'/Ä/' => 'Ae' ,
'/Ü/' => 'Ue' ,
'/Ö/' => 'Oe' ,
'/ß/' => 'ss' ,
'/[\.|\,|\+|\"|\:|\;|\-|\\|\/]/' => " " ,
'/\\s+/' => $replacement );
$map = array_merge ( $default , $map );
return preg_replace ( array_keys ( $map ), array_values ( $map ), $string );
2012-10-18 15:17:21 -04:00
}
/**
* pr
*
* @ param string $var
*
* @ return void
*/
2018-01-25 20:32:51 +00:00
public static function pr ( $var )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
print ( " <pre> " );
2017-12-04 13:25:35 +00:00
print_r ( $var );
2018-01-15 12:00:22 +00:00
print ( " </pre> " );
2012-10-18 15:17:21 -04:00
}
/**
* dump
*
* @ param string $var
*
* @ return void
*/
2017-12-04 13:25:35 +00:00
public function dump ( $var )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
print ( " <pre> " );
2017-12-04 13:25:35 +00:00
var_dump ( $var );
2018-01-15 12:00:22 +00:00
print ( " </pre> " );
2012-10-18 15:17:21 -04:00
}
/**
* stripCDATA
*
* @ param string $string
*
* @ return string str_replace
*/
2018-01-25 20:32:51 +00:00
public static function stripCDATA ( $string )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
preg_match_all ( '/<!\[cdata\[(.*?)\]\]>/is' , $string , $matches );
return str_replace ( $matches [ 0 ], $matches [ 1 ], $string );
2012-10-18 15:17:21 -04:00
}
/**
* Get the temporal directory path on differents O . S .
* i . e . / temp -> linux , C :/ Temp -> win
*
* @ author < erik @ colosa . com >
*/
2018-01-25 20:32:51 +00:00
public static function sys_get_temp_dir ()
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! function_exists ( 'sys_get_temp_dir' )) {
2012-10-18 15:17:21 -04:00
// Based on http://www.phpit.net/
// article/creating-zip-tar-archives-dynamically-php/2/
// Try to get from environment variable
2018-01-15 12:00:22 +00:00
if ( ! empty ( $_ENV [ 'TMP' ])) {
2017-12-04 13:25:35 +00:00
return realpath ( $_ENV [ 'TMP' ]);
2018-01-15 12:00:22 +00:00
} elseif ( ! empty ( $_ENV [ 'TMPDIR' ])) {
2017-12-04 13:25:35 +00:00
return realpath ( $_ENV [ 'TMPDIR' ]);
2018-01-15 12:00:22 +00:00
} elseif ( ! empty ( $_ENV [ 'TEMP' ])) {
2017-12-04 13:25:35 +00:00
return realpath ( $_ENV [ 'TEMP' ]);
2012-10-18 15:17:21 -04:00
} else {
// Detect by creating a temporary file
// Try to use system's temporary directory as random name shouldn't exist
2017-12-04 13:25:35 +00:00
$temp_file = tempnam ( G :: encryptOld ( uniqid ( rand (), true )), '' );
2012-10-18 15:17:21 -04:00
if ( $temp_file ) {
2017-12-04 13:25:35 +00:00
$temp_dir = realpath ( dirname ( $temp_file ));
unlink ( $temp_file );
2012-10-18 15:17:21 -04:00
return $temp_dir ;
} else {
return false ;
}
}
} else {
return sys_get_temp_dir ();
}
}
/**
* Get the content of a compose pmos web service response
* Returns an array when has a valid reponse , if the response is invalid returns an object containing a status_code and message properties .
*
* @ author < erik @ colosa . com >
*/
2018-01-25 20:32:51 +00:00
public static function PMWSCompositeResponse ( $oResp , $prop )
2012-10-18 15:17:21 -04:00
{
$Resp = new stdClass ();
2017-12-04 13:25:35 +00:00
if ( is_object ( $oResp ) && isset ( $oResp -> { $prop })) {
2012-10-18 15:17:21 -04:00
$list = $oResp -> { $prop };
2017-12-04 13:25:35 +00:00
if ( is_object ( $list )) {
2012-10-18 15:17:21 -04:00
$aList [ 0 ] = $list ;
} else {
$aList = $list ;
}
$result = true ;
2017-12-04 13:25:35 +00:00
if ( is_array ( $aList )) {
2012-10-18 15:17:21 -04:00
foreach ( $aList as $item ) {
2018-01-15 12:00:22 +00:00
if ( ! isset ( $item -> guid )) {
2012-10-18 15:17:21 -04:00
$result = false ;
break ;
}
}
} else {
$Resp -> status_code = - 1 ;
$Resp -> message = " Bad respose type for ( { $prop } ) " ;
}
if ( $result ) {
//verifing if the response has a composite response into a guid value of the first row.
2017-12-04 13:25:35 +00:00
$tmp = explode ( ' ' , trim ( $aList [ 0 ] -> guid ));
if ( sizeof ( $tmp ) >= 2 ) {
2012-10-18 15:17:21 -04:00
//the guid can't has a space, so this should be a ws response
$Resp -> status_code = $tmp [ 0 ];
2017-12-04 13:25:35 +00:00
$Resp -> message = substr ( $aList [ 0 ] -> guid , strpos ( $aList [ 0 ] -> guid , ' ' ) + 1 );
2012-10-18 15:17:21 -04:00
} else {
return $aList ;
}
} else {
$Resp -> status_code = - 2 ;
$Resp -> message = " Bad respose, the response has not a uniform struct. " ;
}
2017-12-04 13:25:35 +00:00
} elseif ( is_object ( $oResp )) {
return array ();
2012-10-18 15:17:21 -04:00
} else {
$Resp -> status_code = - 1 ;
$Resp -> message = " 1 Bad respose type for ( { $prop } ) " ;
}
return $Resp ;
}
/**
* Validate and emai address in complete forms ,
*
2012-11-12 14:44:44 -04:00
* @ author Erik A . O . < erik @ colosa . com >
2012-10-18 15:17:21 -04:00
* i . e . if the param . is 'erik a.o. <erik@colosa.com>'
* -> returns a object within $o -> email => erik @ colosa . com and $o -> name => erik A . O . in other case returns false
*
*/
2018-01-25 20:32:51 +00:00
public static function emailAddress ( $sEmail )
2012-10-18 15:17:21 -04:00
{
$o = new stdClass ();
2017-12-04 13:25:35 +00:00
if ( strpos ( $sEmail , '<' ) !== false ) {
2012-10-18 15:17:21 -04:00
preg_match ( '/([\"\w@\.-_\s]*\s*)?(<(\w+[\.-]?\w+]*@\w+([\.-]?\w+)*\.\w{2,3})+>)/' , $sEmail , $matches );
2017-12-04 13:25:35 +00:00
if ( isset ( $matches [ 1 ]) && $matches [ 3 ]) {
2012-10-18 15:17:21 -04:00
$o -> email = $matches [ 3 ];
$o -> name = $matches [ 1 ];
return $o ;
}
return false ;
} else {
preg_match ( '/\w+[\.-]?\w+]*@\w+([\.-]?\w+)*\.\w{2,3}+/' , $sEmail , $matches );
2017-12-04 13:25:35 +00:00
if ( isset ( $matches [ 0 ])) {
2012-10-18 15:17:21 -04:00
$o -> email = $matches [ 0 ];
$o -> name = '' ;
return $o ;
}
return false ;
}
}
/**
* JSON encode
*
2012-11-12 14:44:44 -04:00
* @ author Erik A . O . < erik @ colosa . com >
2012-10-18 15:17:21 -04:00
*/
2014-02-12 17:01:19 -04:00
public static function json_encode ( $Json )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'json_encode' )) {
2012-10-18 15:17:21 -04:00
return json_encode ( $Json );
} else {
$oJSON = new Services_JSON ();
return $oJSON -> encode ( $Json );
}
}
/**
* JSON decode
*
2012-11-12 14:44:44 -04:00
* @ author Erik A . O . < erik @ colosa . com >
2012-10-18 15:17:21 -04:00
*/
2016-03-01 19:12:13 -04:00
public static function json_decode ( $Json , $assoc = false )
2012-10-18 15:17:21 -04:00
{
if ( function_exists ( 'json_decode' )) {
2015-03-13 16:48:12 -04:00
return json_decode ( $Json , $assoc );
2012-10-18 15:17:21 -04:00
} else {
$oJSON = new Services_JSON ();
return $oJSON -> decode ( $Json );
}
}
/**
* isHttpRequest
*
* @ return boolean true or false
*/
2015-02-26 17:02:34 -04:00
public static function isHttpRequest ()
2012-10-18 15:17:21 -04:00
{
if ( isset ( $_SERVER [ 'SERVER_SOFTWARE' ]) && strpos ( strtolower ( $_SERVER [ 'SERVER_SOFTWARE' ]), 'apache' ) !== false ) {
return true ;
}
return false ;
}
/**
* Send a mail using phpmailer
* this method use the global smtp server connection stored on Configuration table
* this information is retrieved by the PMFunction getEmailConfiguration ()
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ param string $from address that is sending the email
* @ param string $fromName name of sender
* @ param mixed $address the possibles values are :
* string
* array ( 'email1' , 'some name <email2>' )
* array ( 'to' => array ( 'email1' , 'some name <email2>' ), 'cc' => array ( ... ), 'bcc' => array ( ... ))
* @ param string $subject contains the email subject
* @ param string $body contains the email body ( text plain or html )
* @ return mixed boolean or string : if the email was sent successfully returns true , otherwise returns a string within error message
*/
2018-01-25 20:32:51 +00:00
public static function sendMail ( $from , $fromName , $address , $subject , $body )
2012-10-18 15:17:21 -04:00
{
// require_once "classes/class.pmFunctions.php";
2017-08-02 16:06:56 -04:00
2012-10-18 15:17:21 -04:00
$setup = getEmailConfiguration ();
2012-11-16 17:16:01 -04:00
if ( $setup [ 'MESS_RAUTH' ] == false || ( is_string ( $setup [ 'MESS_RAUTH' ]) && $setup [ 'MESS_RAUTH' ] == 'false' )) {
$setup [ 'MESS_RAUTH' ] = 0 ;
} else {
$setup [ 'MESS_RAUTH' ] = 1 ;
2012-11-15 10:10:04 -04:00
}
BUG 10087 "PM functions y Web Services de ProcessMaker no..." SOLVED
- Problem with the variable $_SESSION
- The variable $_SESSION should not lose the default values ..set
- Added functions to save and restore the values ..of the variable $_SESSION
- Revised class.pmFunctions.php functions and class.wsBase.php
- The QA team should test this functions (most of these functions running
triggers, try running triggers):
PMFAddInputDocument
PMFGenerateOutputDocument
PMFDerivateCase, WSDerivateCase, wsBase::derivateCase
PMFNewCase, WSNewCase, wsBase::newCase
PMFRedirectToStep
PMFDeleteCase, WSDeleteCase, wsBase::deleteCase
PMFCancelCase, WSCancelCase, wsBase::cancelCase
PMFPauseCase, WSPauseCase, wsBase::pauseCase
PMFUnpauseCase, WSUnpauseCase, wsBase::unpauseCase
wsBase::executeTrigger
wsBase::reassignCase
* Available from version 2.0.46
2012-11-29 17:04:31 -04:00
2012-10-18 15:17:21 -04:00
if ( count ( $setup ) == 0 || ! isset ( $setup [ 'MESS_ENGINE' ]) || ! isset ( $setup [ 'MESS_SERVER' ])
|| ! isset ( $setup [ 'MESS_ENABLED' ]) || ! isset ( $setup [ 'MESS_RAUTH' ]) || $setup [ 'MESS_SERVER' ] == '' ) {
return G :: LoadTranslation ( 'ID_EMAIL_ENGINE_IS_NOT_CONFIGURED' );
}
if ( ! $setup [ 'MESS_ENABLED' ]) {
return G :: LoadTranslation ( 'ID_EMAIL_ENGINE_IS_NOT_ENABLED' );
}
2018-01-15 12:00:22 +00:00
$passwd = $setup [ 'MESS_PASSWORD' ];
2017-12-04 13:25:35 +00:00
$passwdDec = G :: decrypt ( $passwd , 'EMAILENCRYPT' );
2012-10-18 15:17:21 -04:00
$auxPass = explode ( 'hash:' , $passwdDec );
if ( count ( $auxPass ) > 1 ) {
if ( count ( $auxPass ) == 2 ) {
$passwd = $auxPass [ 1 ];
} else {
array_shift ( $auxPass );
$passwd = implode ( '' , $auxPass );
}
}
$setup [ 'MESS_PASSWORD' ] = $passwd ;
$mail = new PHPMailer ( true );
$mail -> From = $from != '' && $from ? $from : $setup [ 'MESS_ACCOUNT' ];
$mail -> FromName = $fromName ;
$mail -> Subject = $subject ;
$mail -> Body = $body ;
2017-12-04 13:25:35 +00:00
$mail -> IsHTML ( true );
2012-10-18 15:17:21 -04:00
$mail -> IsSMTP ();
$mail -> Host = $setup [ 'MESS_SERVER' ];
$mail -> Port = $setup [ 'MESS_PORT' ];
$mail -> SMTPAuth = isset ( $setup [ 'MESS_RAUTH' ]) && $setup [ 'MESS_RAUTH' ] ? true : false ;
$mail -> Username = $setup [ 'MESS_ACCOUNT' ];
$mail -> Password = $setup [ 'MESS_PASSWORD' ];
$mail -> SMTPSecure = $setup [ 'SMTPSecure' ];
$emailAddressList = G :: envelopEmailAddresses ( $address );
foreach ( $emailAddressList [ 'to' ] as $emails ) {
$mail -> AddAddress ( $emails [ 0 ], $emails [ 1 ]);
}
foreach ( $emailAddressList [ 'cc' ] as $emails ) {
$mail -> AddCC ( $emails [ 0 ], $emails [ 1 ]);
}
foreach ( $emailAddressList [ 'bcc' ] as $emails ) {
2017-12-04 13:25:35 +00:00
$mail -> AddBCC ( $emails [ 0 ], $emails [ 1 ]);
2012-10-18 15:17:21 -04:00
}
return $mail -> Send () ? true : $mail -> ErrorInfo ;
}
/**
* Envelope a emails collection from a string or array
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ param mixed $address the possibles values are :
* string
* array ( 'email1' , 'some name <email2>' )
* array ( 'to' => array ( 'email1' , 'some name <email2>' ), 'cc' => array ( ... ), 'bcc' => array ( ... ))
* @ return array contains :
* array (
* 'to' => array ( 'email@host.com' , 'some name or empty string' , array ( 'email@host.com' , '..' ), ... ),
* 'cc' => array ( 'email@host.com' , 'some name or empty string' , ... ),
* 'bcc' => array ( 'email@host.com' , 'some name or empty string' , ... )
* )
*/
2018-01-25 20:32:51 +00:00
public static function envelopEmailAddresses ( $address )
2012-10-18 15:17:21 -04:00
{
$emailAddressList = array ();
$emailAddressList [ 'to' ] = array ();
$emailAddressList [ 'cc' ] = array ();
$emailAddressList [ 'bcc' ] = array ();
$ereg = '/([\"\w\W\s]*\s*)?(<([\w\-\.]+@[\.-\w]+\.\w{2,3})+>)/' ;
if ( ! is_array ( $address )) {
if ( preg_match ( $ereg , $address , $match )) {
$emailAddressList [ 'to' ][] = array ( $match [ 3 ], $match [ 1 ]);
} else {
$emailAddressList [ 'to' ][] = array ( $address , '' );
}
} else {
foreach ( $address as $type => $emails ) {
if ( ! is_array ( $emails )) {
if ( preg_match ( $ereg , $emails , $match )) {
$emailAddressList [ 'to' ][] = array ( $match [ 3 ], $match [ 1 ]);
} else {
$emailAddressList [ 'to' ][] = array ( $emails , '' );
}
} else {
switch ( $type ) {
case 'cc' :
foreach ( $emails as $email ) {
if ( preg_match ( $ereg , $email , $match )) {
$emailAddressList [ 'cc' ][] = array ( $match [ 3 ], $match [ 1 ]);
} else {
$emailAddressList [ 'cc' ][] = array ( $email , '' );
}
}
break ;
case 'bcc' :
foreach ( $emails as $email ) {
if ( preg_match ( $ereg , $email , $match )) {
$emailAddressList [ 'bcc' ][] = array ( $match [ 3 ], $match [ 1 ]);
} else {
$emailAddressList [ 'bcc' ][] = array ( $email , '' );
}
}
break ;
case 'to' :
default :
foreach ( $emails as $email ) {
if ( preg_match ( $ereg , $email , $match )) {
$emailAddressList [ 'to' ][] = array ( $match [ 3 ], $match [ 1 ]);
} else {
$emailAddressList [ 'to' ][] = array ( $email , '' );
}
}
break ;
}
}
}
}
return $emailAddressList ;
}
/**
* Get the type of a variable
* Returns the type of the PHP variable var .
*
* @ author Erik A . Ortiz . < erik @ colosa . com >
* @ return ( string ) type of variable
*/
public function gettype ( $var )
{
switch ( $var ) {
case is_null ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'NULL' ;
2012-10-18 15:17:21 -04:00
break ;
case is_bool ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'boolean' ;
2012-10-18 15:17:21 -04:00
break ;
case is_float ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'double' ;
2012-10-18 15:17:21 -04:00
break ;
case is_int ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'integer' ;
2012-10-18 15:17:21 -04:00
break ;
case is_string ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'string' ;
2012-10-18 15:17:21 -04:00
break ;
case is_array ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'array' ;
2012-10-18 15:17:21 -04:00
break ;
case is_object ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'object' ;
2012-10-18 15:17:21 -04:00
break ;
case is_resource ( $var ) :
2018-01-15 12:00:22 +00:00
$type = 'resource' ;
2012-10-18 15:17:21 -04:00
break ;
default :
2018-01-15 12:00:22 +00:00
$type = 'unknown type' ;
2012-10-18 15:17:21 -04:00
break ;
}
return $type ;
}
public function removeComments ( $buffer )
{
/* remove comments */
$buffer = preg_replace ( '!/\*[^*]*\*+([^/][^*]*\*+)*/!' , '' , $buffer );
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace ( array ( " \r \n " , " \r " , " \n " , " \t " , ' ' , ' ' , ' ' ), '' , $buffer );
return $buffer ;
}
public function getMemoryUsage ()
{
$size = memory_get_usage ( true );
2018-01-15 12:00:22 +00:00
$unit = array ( 'B' , 'Kb' , 'Mb' , 'Gb' , 'Tb' , 'Pb' );
return @ round ( $size / pow ( 1024 , ( $i = floor ( log ( $size , 1024 )))), 2 ) . ' ' . $unit [ $i ];
2012-10-18 15:17:21 -04:00
}
2018-01-25 20:32:51 +00:00
public static function getFormatUserList ( $format , $aUserInfo )
2012-10-18 15:17:21 -04:00
{
switch ( $format ) {
case '@firstName @lastName' :
$infoUser = str_replace ( '@firstName' , $aUserInfo [ 'USR_FIRSTNAME' ], $format );
$infoUser = str_replace ( '@lastName' , $aUserInfo [ 'USR_LASTNAME' ], $infoUser );
break ;
case '@firstName @lastName (@userName)' :
$infoUser = str_replace ( '@firstName' , $aUserInfo [ 'USR_FIRSTNAME' ], $format );
$infoUser = str_replace ( '@lastName' , $aUserInfo [ 'USR_LASTNAME' ], $infoUser );
$infoUser = str_replace ( '@userName' , $aUserInfo [ 'USR_USERNAME' ], $infoUser );
break ;
case '@userName' :
$infoUser = str_replace ( '@userName' , $aUserInfo [ 'USR_USERNAME' ], $format );
break ;
case '@userName (@firstName @lastName)' :
$infoUser = str_replace ( '@userName' , $aUserInfo [ 'USR_USERNAME' ], $format );
$infoUser = str_replace ( '@firstName' , $aUserInfo [ 'USR_FIRSTNAME' ], $infoUser );
$infoUser = str_replace ( '@lastName' , $aUserInfo [ 'USR_LASTNAME' ], $infoUser );
break ;
case '@lastName @firstName' :
$infoUser = str_replace ( '@lastName' , $aUserInfo [ 'USR_LASTNAME' ], $format );
$infoUser = str_replace ( '@firstName' , $aUserInfo [ 'USR_FIRSTNAME' ], $infoUser );
break ;
case '@lastName, @firstName' :
$infoUser = str_replace ( '@lastName' , $aUserInfo [ 'USR_LASTNAME' ], $format );
$infoUser = str_replace ( '@firstName' , $aUserInfo [ 'USR_FIRSTNAME' ], $infoUser );
break ;
case '@lastName, @firstName (@userName)' :
$infoUser = str_replace ( '@lastName' , $aUserInfo [ 'USR_LASTNAME' ], $format );
$infoUser = str_replace ( '@firstName' , $aUserInfo [ 'USR_FIRSTNAME' ], $infoUser );
$infoUser = str_replace ( '@userName' , $aUserInfo [ 'USR_USERNAME' ], $infoUser );
break ;
default :
$infoUser = str_replace ( '@userName' , $aUserInfo [ 'USR_USERNAME' ], '@userName' );
break ;
}
return $infoUser ;
}
/**
* Recursive Is writeable function
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
*
* @ param $path path to scan recursively the write permission
2015-04-27 15:49:30 -04:00
* @ param $pattern pattern to filter some specified files
2012-10-18 15:17:21 -04:00
* @ return < boolean > if the $path , assuming that is a directory -> all files in it are writeables or not
*/
2018-01-25 20:32:51 +00:00
public static function is_rwritable ( $path , $pattern = '*' )
2012-10-18 15:17:21 -04:00
{
$files = G :: rglob ( $pattern , 0 , $path );
foreach ( $files as $file ) {
2018-01-15 12:00:22 +00:00
if ( ! is_writable ( $file )) {
2012-10-18 15:17:21 -04:00
return false ;
}
}
return true ;
}
/**
* Recursive version of glob php standard function
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
*
* @ param $path path to scan recursively the write permission
* @ param $flags to notive glob function
2015-04-27 15:49:30 -04:00
* @ param $pattern pattern to filter some specified files
2012-10-18 15:17:21 -04:00
* @ return < array > array containing the recursive glob results
*/
2014-02-28 19:11:34 -04:00
public static function rglob ( $pattern = '*' , $flags = 0 , $path = '' )
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
$paths = glob ( $path . '*' , GLOB_MARK | GLOB_ONLYDIR | GLOB_NOSORT );
$files = glob ( $path . $pattern , $flags );
2012-10-18 15:17:21 -04:00
foreach ( $paths as $path ) {
$files = array_merge ( $files , G :: rglob ( $pattern , $flags , $path ));
}
return $files ;
}
2018-01-25 20:32:51 +00:00
public static function browser_detection ( $which_test , $test_excludes = '' , $external_ua_string = '' )
2012-10-18 15:17:21 -04:00
{
G :: script_time (); // set script timer to start timing
static $a_full_assoc_data , $a_mobile_data , $a_moz_data , $a_webkit_data , $b_dom_browser , $b_repeat , $b_safe_browser , $browser_name , $browser_number , $browser_math_number , $browser_user_agent , $browser_working , $ie_version , $mobile_test , $moz_number , $moz_rv , $moz_rv_full , $moz_release_date , $moz_type , $os_number , $os_type , $true_ie_number , $ua_type , $webkit_type , $webkit_type_number ;
// switch off the optimization for external ua string testing.
2017-12-04 13:25:35 +00:00
if ( $external_ua_string ) {
2012-10-18 15:17:21 -04:00
$b_repeat = false ;
}
/*
this makes the test only run once no matter how many times you call it since
all the variables are filled on the first run through , it ' s only a matter of
returning the the right ones
*/
2017-12-04 13:25:35 +00:00
if ( ! $b_repeat ) {
2012-10-18 15:17:21 -04:00
//initialize all variables with default values to prevent error
$a_browser_math_number = '' ;
$a_full_assoc_data = '' ;
$a_full_data = '' ;
$a_mobile_data = '' ;
$a_moz_data = '' ;
$a_os_data = '' ;
$a_unhandled_browser = '' ;
$a_webkit_data = '' ;
$b_dom_browser = false ;
$b_os_test = true ;
$b_mobile_test = true ;
$b_safe_browser = false ;
2018-01-15 12:00:22 +00:00
$b_success = false ; // boolean for if browser found in main test
2012-10-18 15:17:21 -04:00
$browser_math_number = '' ;
$browser_temp = '' ;
$browser_working = '' ;
$browser_number = '' ;
$ie_version = '' ;
$mobile_test = '' ;
$moz_release_date = '' ;
$moz_rv = '' ;
$moz_rv_full = '' ;
$moz_type = '' ;
$moz_number = '' ;
$os_number = '' ;
$os_type = '' ;
$run_time = '' ;
$true_ie_number = '' ;
2018-01-15 12:00:22 +00:00
$ua_type = 'bot' ; // default to bot since you never know with bots
2012-10-18 15:17:21 -04:00
$webkit_type = '' ;
$webkit_type_number = '' ;
// set the excludes if required
2017-12-04 13:25:35 +00:00
if ( $test_excludes ) {
switch ( $test_excludes ) {
2012-10-18 15:17:21 -04:00
case '1' :
$b_os_test = false ;
break ;
case '2' :
$b_mobile_test = false ;
break ;
case '3' :
$b_os_test = false ;
$b_mobile_test = false ;
break ;
default :
2017-12-04 13:25:35 +00:00
die ( 'Error: bad $test_excludes parameter 2 used: ' . $test_excludes );
2012-10-18 15:17:21 -04:00
break ;
}
}
/*
make navigator user agent string lower case to make sure all versions get caught
isset protects against blank user agent failure . tolower also lets the script use
strstr instead of stristr , which drops overhead slightly .
*/
2017-12-04 13:25:35 +00:00
if ( $external_ua_string ) {
$browser_user_agent = strtolower ( $external_ua_string );
} elseif ( isset ( $_SERVER [ 'HTTP_USER_AGENT' ])) {
$browser_user_agent = strtolower ( $_SERVER [ 'HTTP_USER_AGENT' ]);
2012-10-18 15:17:21 -04:00
} else {
$browser_user_agent = '' ;
}
// known browsers, list will be updated routinely, check back now and then
$a_browser_types = array (
2018-01-15 12:00:22 +00:00
array ( 'opera' , true , 'op' , 'bro' ),
array ( 'msie' , true , 'ie' , 'bro' ),
2012-10-18 15:17:21 -04:00
// webkit before gecko because some webkit ua strings say: like gecko
2018-01-15 12:00:22 +00:00
array ( 'webkit' , true , 'webkit' , 'bro' ),
2012-10-18 15:17:21 -04:00
// konq will be using webkit soon
2018-01-15 12:00:22 +00:00
array ( 'konqueror' , true , 'konq' , 'bro' ),
2012-10-18 15:17:21 -04:00
// covers Netscape 6-7, K-Meleon, Most linux versions, uses moz array below
2018-01-15 12:00:22 +00:00
array ( 'gecko' , true , 'moz' , 'bro' ),
array ( 'netpositive' , false , 'netp' , 'bbro' ), // beos browser
array ( 'lynx' , false , 'lynx' , 'bbro' ), // command line browser
array ( 'elinks ' , false , 'elinks' , 'bbro' ), // new version of links
array ( 'elinks' , false , 'elinks' , 'bbro' ), // alternate id for it
array ( 'links2' , false , 'links2' , 'bbro' ), // alternate links version
array ( 'links ' , false , 'links' , 'bbro' ), // old name for links
array ( 'links' , false , 'links' , 'bbro' ), // alternate id for it
array ( 'w3m' , false , 'w3m' , 'bbro' ), // open source browser, more features than lynx/links
array ( 'webtv' , false , 'webtv' , 'bbro' ), // junk ms webtv
array ( 'amaya' , false , 'amaya' , 'bbro' ), // w3c browser
array ( 'dillo' , false , 'dillo' , 'bbro' ), // linux browser, basic table support
array ( 'ibrowse' , false , 'ibrowse' , 'bbro' ), // amiga browser
array ( 'icab' , false , 'icab' , 'bro' ), // mac browser
array ( 'crazy browser' , true , 'ie' , 'bro' ), // uses ie rendering engine
2012-10-18 15:17:21 -04:00
// search engine spider bots:
2018-01-15 12:00:22 +00:00
array ( 'bingbot' , false , 'bing' , 'bot' ), // bing
array ( 'exabot' , false , 'exabot' , 'bot' ), // exabot
array ( 'googlebot' , false , 'google' , 'bot' ), // google
array ( 'google web preview' , false , 'googlewp' , 'bot' ), // google preview
array ( 'mediapartners-google' , false , 'adsense' , 'bot' ), // google adsense
array ( 'yahoo-verticalcrawler' , false , 'yahoo' , 'bot' ), // old yahoo bot
array ( 'yahoo! slurp' , false , 'yahoo' , 'bot' ), // new yahoo bot
array ( 'yahoo-mm' , false , 'yahoomm' , 'bot' ), // gets Yahoo-MMCrawler and Yahoo-MMAudVid bots
array ( 'inktomi' , false , 'inktomi' , 'bot' ), // inktomi bot
array ( 'slurp' , false , 'inktomi' , 'bot' ), // inktomi bot
array ( 'fast-webcrawler' , false , 'fast' , 'bot' ), // Fast AllTheWeb
array ( 'msnbot' , false , 'msn' , 'bot' ), // msn search
array ( 'ask jeeves' , false , 'ask' , 'bot' ), //jeeves/teoma
array ( 'teoma' , false , 'ask' , 'bot' ), //jeeves teoma
array ( 'scooter' , false , 'scooter' , 'bot' ), // altavista
array ( 'openbot' , false , 'openbot' , 'bot' ), // openbot, from taiwan
array ( 'ia_archiver' , false , 'ia_archiver' , 'bot' ), // ia archiver
array ( 'zyborg' , false , 'looksmart' , 'bot' ), // looksmart
array ( 'almaden' , false , 'ibm' , 'bot' ), // ibm almaden web crawler
array ( 'baiduspider' , false , 'baidu' , 'bot' ), // Baiduspider asian search spider
array ( 'psbot' , false , 'psbot' , 'bot' ), // psbot image crawler
array ( 'gigabot' , false , 'gigabot' , 'bot' ), // gigabot crawler
array ( 'naverbot' , false , 'naverbot' , 'bot' ), // naverbot crawler, bad bot, block
array ( 'surveybot' , false , 'surveybot' , 'bot' ), //
array ( 'boitho.com-dc' , false , 'boitho' , 'bot' ), //norwegian search engine
array ( 'objectssearch' , false , 'objectsearch' , 'bot' ), // open source search engine
array ( 'answerbus' , false , 'answerbus' , 'bot' ), // http://www.answerbus.com/, web questions
array ( 'sohu-search' , false , 'sohu' , 'bot' ), // chinese media company, search component
array ( 'iltrovatore-setaccio' , false , 'il-set' , 'bot' ),
2012-10-18 15:17:21 -04:00
// various http utility libaries
2018-01-15 12:00:22 +00:00
array ( 'w3c_validator' , false , 'w3c' , 'lib' ), // uses libperl, make first
array ( 'wdg_validator' , false , 'wdg' , 'lib' ), //
array ( 'libwww-perl' , false , 'libwww-perl' , 'lib' ),
array ( 'jakarta commons-httpclient' , false , 'jakarta' , 'lib' ),
array ( 'python-urllib' , false , 'python-urllib' , 'lib' ),
2012-10-18 15:17:21 -04:00
// download apps
2018-01-15 12:00:22 +00:00
array ( 'getright' , false , 'getright' , 'dow' ),
array ( 'wget' , false , 'wget' , 'dow' ), // open source downloader, obeys robots.txt
2012-10-18 15:17:21 -04:00
// netscape 4 and earlier tests, put last so spiders don't get caught
2018-01-15 12:00:22 +00:00
array ( 'mozilla/4.' , false , 'ns' , 'bbro' ),
array ( 'mozilla/3.' , false , 'ns' , 'bbro' ),
array ( 'mozilla/2.' , false , 'ns' , 'bbro' )
2012-10-18 15:17:21 -04:00
);
//array( '', false ); // browser array template
/*
moz types array
note the order , netscape6 must come before netscape , which is how netscape 7 id ' s itself .
rv comes last in case it is plain old mozilla . firefox / netscape / seamonkey need to be later
Thanks to : http :// www . zytrax . com / tech / web / firefox - history . html
*/
2018-01-15 12:00:22 +00:00
$a_moz_types = array ( 'bonecho' , 'camino' , 'epiphany' , 'firebird' , 'flock' , 'galeon' , 'iceape' , 'icecat' , 'k-meleon' , 'minimo' , 'multizilla' , 'phoenix' , 'songbird' , 'swiftfox' , 'seamonkey' , 'shiretoko' , 'iceweasel' , 'firefox' , 'minefield' , 'netscape6' , 'netscape' , 'rv' );
2012-10-18 15:17:21 -04:00
/*
webkit types , this is going to expand over time as webkit browsers spread
konqueror is probably going to move to webkit , so this is preparing for that
It will now default to khtml . gtklauncher is the temp id for epiphany , might
change . Defaults to applewebkit , and will all show the webkit number .
*/
2018-01-15 12:00:22 +00:00
$a_webkit_types = array ( 'arora' , 'chrome' , 'epiphany' , 'gtklauncher' , 'konqueror' , 'midori' , 'omniweb' , 'safari' , 'uzbl' , 'applewebkit' , 'webkit' );
2012-10-18 15:17:21 -04:00
/*
run through the browser_types array , break if you hit a match , if no match , assume old browser
or non dom browser , assigns false value to $b_success .
*/
2017-12-04 13:25:35 +00:00
$i_count = count ( $a_browser_types );
2012-10-18 15:17:21 -04:00
for ( $i = 0 ; $i < $i_count ; $i ++ ) {
//unpacks browser array, assigns to variables, need to not assign til found in string
2018-01-15 12:00:22 +00:00
$browser_temp = $a_browser_types [ $i ][ 0 ]; // text string to id browser from array
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( strstr ( $browser_user_agent , $browser_temp )) {
2012-10-18 15:17:21 -04:00
/*
it defaults to true , will become false below if needed
this keeps it easier to keep track of what is safe , only
explicit false assignment will make it false .
*/
$b_safe_browser = true ;
2018-01-15 12:00:22 +00:00
$browser_name = $browser_temp ; // text string to id browser from array
2012-10-18 15:17:21 -04:00
// assign values based on match of user agent string
2018-01-15 12:00:22 +00:00
$b_dom_browser = $a_browser_types [ $i ][ 1 ]; // hardcoded dom support from array
$browser_working = $a_browser_types [ $i ][ 2 ]; // working name for browser
$ua_type = $a_browser_types [ $i ][ 3 ]; // sets whether bot or browser
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
switch ( $browser_working ) {
2012-10-18 15:17:21 -04:00
// this is modified quite a bit, now will return proper netscape version number
// check your implementation to make sure it works
case 'ns' :
$b_safe_browser = false ;
2017-12-04 13:25:35 +00:00
$browser_number = G :: get_item_version ( $browser_user_agent , 'mozilla' );
2012-10-18 15:17:21 -04:00
break ;
case 'moz' :
/*
note : The 'rv' test is not absolute since the rv number is very different on
different versions , for example Galean doesn ' t use the same rv version as Mozilla ,
neither do later Netscapes , like 7. x . For more on this , read the full mozilla
numbering conventions here : http :// www . mozilla . org / releases / cvstags . html
*/
// this will return alpha and beta version numbers, if present
2017-12-04 13:25:35 +00:00
$moz_rv_full = G :: get_item_version ( $browser_user_agent , 'rv' );
2012-10-18 15:17:21 -04:00
// this slices them back off for math comparisons
2017-12-04 13:25:35 +00:00
$moz_rv = substr ( $moz_rv_full , 0 , 3 );
2012-10-18 15:17:21 -04:00
// this is to pull out specific mozilla versions, firebird, netscape etc..
2017-12-04 13:25:35 +00:00
$j_count = count ( $a_moz_types );
2012-10-18 15:17:21 -04:00
for ( $j = 0 ; $j < $j_count ; $j ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $browser_user_agent , $a_moz_types [ $j ])) {
2012-10-18 15:17:21 -04:00
$moz_type = $a_moz_types [ $j ];
2017-12-04 13:25:35 +00:00
$moz_number = G :: get_item_version ( $browser_user_agent , $moz_type );
2012-10-18 15:17:21 -04:00
break ;
}
}
/*
this is necesary to protect against false id 'ed moz' es and new moz ' es .
this corrects for galeon , or any other moz browser without an rv number
*/
2017-12-04 13:25:35 +00:00
if ( ! $moz_rv ) {
2012-10-18 15:17:21 -04:00
// you can use this if you are running php >= 4.2
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'floatval' )) {
$moz_rv = floatval ( $moz_number );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$moz_rv = substr ( $moz_number , 0 , 3 );
2012-10-18 15:17:21 -04:00
}
$moz_rv_full = $moz_number ;
}
// this corrects the version name in case it went to the default 'rv' for the test
2017-12-04 13:25:35 +00:00
if ( $moz_type == 'rv' ) {
2012-10-18 15:17:21 -04:00
$moz_type = 'mozilla' ;
}
//the moz version will be taken from the rv number, see notes above for rv problems
$browser_number = $moz_rv ;
// gets the actual release date, necessary if you need to do functionality tests
2017-12-04 13:25:35 +00:00
G :: get_set_count ( 'set' , 0 );
$moz_release_date = G :: get_item_version ( $browser_user_agent , 'gecko/' );
2012-10-18 15:17:21 -04:00
/*
Test for mozilla 0.9 . x / netscape 6. x
test your javascript / CSS to see if it works in these mozilla releases , if it
does , just default it to : $b_safe_browser = true ;
*/
2017-12-04 13:25:35 +00:00
if (( $moz_release_date < 20020400 ) || ( $moz_rv < 1 )) {
2012-10-18 15:17:21 -04:00
$b_safe_browser = false ;
}
break ;
case 'ie' :
/*
note we ' re adding in the trident / search to return only first instance in case
of msie 8 , and we ' re triggering the break last condition in the test , as well
as the test for a second search string , trident /
*/
2017-12-04 13:25:35 +00:00
$browser_number = G :: get_item_version ( $browser_user_agent , $browser_name , true , 'trident/' );
2012-10-18 15:17:21 -04:00
// construct the proper real number if it's in compat mode and msie 8.0/9.0
2017-12-04 13:25:35 +00:00
if ( strstr ( $browser_number , '7.' ) && strstr ( $browser_user_agent , 'trident/5' )) {
2012-10-18 15:17:21 -04:00
// note that 7.0 becomes 9 when adding 1, but if it's 7.1 it will be 9.1
$true_ie_number = $browser_number + 2 ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $browser_number , '7.' ) && strstr ( $browser_user_agent , 'trident/4' )) {
2012-10-18 15:17:21 -04:00
// note that 7.0 becomes 8 when adding 1, but if it's 7.1 it will be 8.1
$true_ie_number = $browser_number + 1 ;
}
// the 9 series is finally standards compatible, html 5 etc, so worth a new id
2017-12-04 13:25:35 +00:00
if ( $browser_number >= 9 ) {
2012-10-18 15:17:21 -04:00
$ie_version = 'ie9x' ;
2017-12-04 13:25:35 +00:00
} elseif ( $browser_number >= 7 ) {
2012-10-18 15:17:21 -04:00
$ie_version = 'ie7x' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $browser_user_agent , 'mac' )) {
2012-10-18 15:17:21 -04:00
$ie_version = 'ieMac' ;
2017-12-04 13:25:35 +00:00
} elseif ( $browser_number >= 5 ) {
2012-10-18 15:17:21 -04:00
$ie_version = 'ie5x' ;
2017-12-04 13:25:35 +00:00
} elseif (( $browser_number > 3 ) && ( $browser_number < 5 )) {
2012-10-18 15:17:21 -04:00
$b_dom_browser = false ;
$ie_version = 'ie4' ;
// this depends on what you're using the script for, make sure this fits your needs
$b_safe_browser = true ;
} else {
$ie_version = 'old' ;
$b_dom_browser = false ;
$b_safe_browser = false ;
}
break ;
case 'op' :
2017-12-04 13:25:35 +00:00
$browser_number = G :: get_item_version ( $browser_user_agent , $browser_name );
2012-10-18 15:17:21 -04:00
// opera is leaving version at 9.80 (or xx) for 10.x - see this for explanation
// http://dev.opera.com/articles/view/opera-ua-string-changes/
2017-12-04 13:25:35 +00:00
if ( strstr ( $browser_number , '9.' ) && strstr ( $browser_user_agent , 'version/' )) {
G :: get_set_count ( 'set' , 0 );
$browser_number = G :: get_item_version ( $browser_user_agent , 'version/' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
if ( $browser_number < 5 ) {
2012-10-18 15:17:21 -04:00
$b_safe_browser = false ;
}
break ;
case 'webkit' :
// note that this is the Webkit version number
2017-12-04 13:25:35 +00:00
$browser_number = G :: get_item_version ( $browser_user_agent , $browser_name );
2012-10-18 15:17:21 -04:00
// this is to pull out specific webkit versions, safari, google-chrome etc..
2017-12-04 13:25:35 +00:00
$j_count = count ( $a_webkit_types );
2012-10-18 15:17:21 -04:00
for ( $j = 0 ; $j < $j_count ; $j ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $browser_user_agent , $a_webkit_types [ $j ])) {
2012-10-18 15:17:21 -04:00
$webkit_type = $a_webkit_types [ $j ];
2017-12-04 13:25:35 +00:00
if ( $webkit_type == 'omniweb' ) {
G :: get_set_count ( 'set' , 2 );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$webkit_type_number = G :: get_item_version ( $browser_user_agent , $webkit_type );
2012-10-18 15:17:21 -04:00
// epiphany hack
2017-12-04 13:25:35 +00:00
if ( $a_webkit_types [ $j ] == 'gtklauncher' ) {
2012-10-18 15:17:21 -04:00
$browser_name = 'epiphany' ;
} else {
$browser_name = $a_webkit_types [ $j ];
}
break ;
}
}
break ;
default :
2017-12-04 13:25:35 +00:00
$browser_number = G :: get_item_version ( $browser_user_agent , $browser_name );
2012-10-18 15:17:21 -04:00
break ;
}
// the browser was id'ed
$b_success = true ;
break ;
}
}
//assigns defaults if the browser was not found in the loop test
2017-12-04 13:25:35 +00:00
if ( ! $b_success ) {
2012-10-18 15:17:21 -04:00
/*
this will return the first part of the browser string if the above id ' s failed
usually the first part of the browser string has the navigator useragent name / version in it .
This will usually correctly id the browser and the browser number if it didn ' t get
caught by the above routine .
If you want a '' to do a if browser == '' type test , just comment out all lines below
except for the last line , and uncomment the last line . If you want undefined values ,
the browser_name is '' , you can always test for that
*/
// delete this part if you want an unknown browser returned
2017-12-04 13:25:35 +00:00
$browser_name = substr ( $browser_user_agent , 0 , strcspn ( $browser_user_agent , '();' ));
2012-10-18 15:17:21 -04:00
// this extracts just the browser name from the string, if something usable was found
2017-12-04 13:25:35 +00:00
if ( $browser_name && preg_match ( '/[^0-9][a-z]*-*\ *[a-z]*\ *[a-z]*/' , $browser_name , $a_unhandled_browser )) {
2012-10-18 15:17:21 -04:00
$browser_name = $a_unhandled_browser [ 0 ];
2017-12-04 13:25:35 +00:00
if ( $browser_name == 'blackberry' ) {
G :: get_set_count ( 'set' , 0 );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$browser_number = G :: get_item_version ( $browser_user_agent , $browser_name );
2012-10-18 15:17:21 -04:00
} else {
$browser_name = 'NA' ;
$browser_number = 'NA' ;
}
}
// get os data, mac os x test requires browser/version information, this is a change from older scripts
if ( $b_os_test ) {
2017-12-04 13:25:35 +00:00
$a_os_data = G :: get_os_data ( $browser_user_agent , $browser_working , $browser_number );
2018-01-15 12:00:22 +00:00
$os_type = $a_os_data [ 0 ]; // os name, abbreviated
$os_number = $a_os_data [ 1 ]; // os number or version if available
2012-10-18 15:17:21 -04:00
}
/*
this ends the run through once if clause , set the boolean
to true so the function won ' t retest everything
*/
$b_repeat = true ;
2017-12-04 13:25:35 +00:00
if ( $browser_number && preg_match ( '/[0-9]*\.*[0-9]*/' , $browser_number , $a_browser_math_number )) {
2012-10-18 15:17:21 -04:00
$browser_math_number = $a_browser_math_number [ 0 ];
}
2017-12-04 13:25:35 +00:00
if ( $b_mobile_test ) {
$mobile_test = G :: check_is_mobile ( $browser_user_agent );
if ( $mobile_test ) {
$a_mobile_data = G :: get_mobile_data ( $browser_user_agent );
2012-10-18 15:17:21 -04:00
$ua_type = 'mobile' ;
}
}
}
switch ( $which_test ) {
case 'math_number' :
$which_test = 'browser_math_number' ;
break ;
case 'number' :
$which_test = 'browser_number' ;
break ;
case 'browser' :
$which_test = 'browser_working' ;
break ;
case 'moz_version' :
$which_test = 'moz_data' ;
break ;
case 'true_msie_version' :
$which_test = 'true_ie_number' ;
break ;
case 'type' :
$which_test = 'ua_type' ;
break ;
case 'webkit_version' :
$which_test = 'webkit_data' ;
break ;
}
/*
assemble these first so they can be included in full return data , using static variables
Note that there ' s no need to keep repacking these every time the script is called
*/
if ( ! $a_moz_data ) {
2018-01-15 12:00:22 +00:00
$a_moz_data = array ( $moz_type , $moz_number , $moz_rv , $moz_rv_full , $moz_release_date );
2012-10-18 15:17:21 -04:00
}
if ( ! $a_webkit_data ) {
2018-01-15 12:00:22 +00:00
$a_webkit_data = array ( $webkit_type , $webkit_type_number , $browser_number );
2012-10-18 15:17:21 -04:00
}
$run_time = G :: script_time ();
2017-12-04 13:25:35 +00:00
if ( ! $a_full_assoc_data ) {
2012-10-18 15:17:21 -04:00
$a_full_assoc_data = array (
'browser_working' => $browser_working ,
'browser_number' => $browser_number ,
'ie_version' => $ie_version ,
'dom' => $b_dom_browser ,
'safe' => $b_safe_browser ,
'os' => $os_type ,
'os_number' => $os_number ,
'browser_name' => $browser_name ,
'ua_type' => $ua_type ,
'browser_math_number' => $browser_math_number ,
'moz_data' => $a_moz_data ,
'webkit_data' => $a_webkit_data ,
'mobile_test' => $mobile_test ,
'mobile_data' => $a_mobile_data ,
'true_ie_number' => $true_ie_number ,
'run_time' => $run_time
);
}
// return parameters, either full data arrays, or by associative array index key
switch ( $which_test ) {
// returns all relevant browser information in an array with standard numberic indexes
case 'full' :
$a_full_data = array (
$browser_working ,
$browser_number ,
$ie_version ,
$b_dom_browser ,
$b_safe_browser ,
$os_type ,
$os_number ,
$browser_name ,
$ua_type ,
$browser_math_number ,
$a_moz_data ,
$a_webkit_data ,
$mobile_test ,
$a_mobile_data ,
$true_ie_number ,
$run_time
);
return $a_full_data ;
break ;
case 'full_assoc' :
return $a_full_assoc_data ;
break ;
default :
# check to see if the data is available, otherwise it's user typo of unsupported option
2017-12-04 13:25:35 +00:00
if ( isset ( $a_full_assoc_data [ $which_test ])) {
2012-10-18 15:17:21 -04:00
return $a_full_assoc_data [ $which_test ];
} else {
2017-12-04 13:25:35 +00:00
die ( " You passed the browser detector an unsupported option for parameter 1: " . $which_test );
2012-10-18 15:17:21 -04:00
}
break ;
}
}
// gets which os from the browser string
2018-01-25 20:32:51 +00:00
public static function get_os_data ( $pv_browser_string , $pv_browser_name , $pv_version_number )
2012-10-18 15:17:21 -04:00
{
// initialize variables
$os_working_type = '' ;
$os_working_number = '' ;
/*
packs the os array . Use this order since some navigator user agents will put 'macintosh'
in the navigator user agent string which would make the nt test register true
*/
2018-01-15 12:00:22 +00:00
$a_mac = array ( 'intel mac' , 'ppc mac' , 'mac68k' ); // this is not used currently
2012-10-18 15:17:21 -04:00
// same logic, check in order to catch the os's in order, last is always default item
2018-01-15 12:00:22 +00:00
$a_unix_types = array ( 'dragonfly' , 'freebsd' , 'openbsd' , 'netbsd' , 'bsd' , 'unixware' , 'solaris' , 'sunos' , 'sun4' , 'sun5' , 'suni86' , 'sun' , 'irix5' , 'irix6' , 'irix' , 'hpux9' , 'hpux10' , 'hpux11' , 'hpux' , 'hp-ux' , 'aix1' , 'aix2' , 'aix3' , 'aix4' , 'aix5' , 'aix' , 'sco' , 'unixware' , 'mpras' , 'reliant' , 'dec' , 'sinix' , 'unix' );
2012-10-18 15:17:21 -04:00
// only sometimes will you get a linux distro to id itself...
2018-01-15 12:00:22 +00:00
$a_linux_distros = array ( 'ubuntu' , 'kubuntu' , 'xubuntu' , 'mepis' , 'xandros' , 'linspire' , 'winspire' , 'jolicloud' , 'sidux' , 'kanotix' , 'debian' , 'opensuse' , 'suse' , 'fedora' , 'redhat' , 'slackware' , 'slax' , 'mandrake' , 'mandriva' , 'gentoo' , 'sabayon' , 'linux' );
$a_linux_process = array ( 'i386' , 'i586' , 'i686' ); // not use currently
2012-10-18 15:17:21 -04:00
// note, order of os very important in os array, you will get failed ids if changed
2018-01-15 12:00:22 +00:00
$a_os_types = array ( 'android' , 'blackberry' , 'iphone' , 'palmos' , 'palmsource' , 'symbian' , 'beos' , 'os2' , 'amiga' , 'webtv' , 'mac' , 'nt' , 'win' , $a_unix_types , $a_linux_distros );
2012-10-18 15:17:21 -04:00
//os tester
2017-12-04 13:25:35 +00:00
$i_count = count ( $a_os_types );
2012-10-18 15:17:21 -04:00
for ( $i = 0 ; $i < $i_count ; $i ++ ) {
// unpacks os array, assigns to variable $a_os_working
$os_working_data = $a_os_types [ $i ];
/*
assign os to global os variable , os flag true on success
! strstr ( $pv_browser_string , " linux " ) corrects a linux detection bug
*/
2017-12-04 13:25:35 +00:00
if ( ! is_array ( $os_working_data ) && strstr ( $pv_browser_string , $os_working_data ) && ! strstr ( $pv_browser_string , " linux " )) {
2012-10-18 15:17:21 -04:00
$os_working_type = $os_working_data ;
switch ( $os_working_type ) {
// most windows now uses: NT X.Y syntax
case 'nt' :
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_string , 'nt 6.1' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 6.1 ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'nt 6.0' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 6.0 ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'nt 5.2' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 5.2 ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'nt 5.1' ) || strstr ( $pv_browser_string , 'xp' )) {
2018-01-15 12:00:22 +00:00
$os_working_number = 5.1 ; //
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'nt 5' ) || strstr ( $pv_browser_string , '2000' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 5.0 ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'nt 4' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 4 ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'nt 3' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 3 ;
}
break ;
case 'win' :
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_string , 'vista' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 6.0 ;
$os_working_type = 'nt' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'xp' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 5.1 ;
$os_working_type = 'nt' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , '2003' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = 5.2 ;
$os_working_type = 'nt' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , 'windows ce' )) { // windows CE
2012-10-18 15:17:21 -04:00
$os_working_number = 'ce' ;
$os_working_type = 'nt' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , '95' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = '95' ;
2017-12-04 13:25:35 +00:00
} elseif (( strstr ( $pv_browser_string , '9x 4.9' )) || ( strstr ( $pv_browser_string , ' me' ))) {
2012-10-18 15:17:21 -04:00
$os_working_number = 'me' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , '98' )) {
2012-10-18 15:17:21 -04:00
$os_working_number = '98' ;
2017-12-04 13:25:35 +00:00
} elseif ( strstr ( $pv_browser_string , '2000' )) { // windows 2000, for opera ID
2012-10-18 15:17:21 -04:00
$os_working_number = 5.0 ;
$os_working_type = 'nt' ;
}
break ;
case 'mac' :
if ( strstr ( $pv_browser_string , 'os x' )) {
if ( strstr ( $pv_browser_string , 'os x ' )) {
2017-12-04 13:25:35 +00:00
$os_working_number = str_replace ( '_' , '.' , G :: get_item_version ( $pv_browser_string , 'os x' ));
2012-10-18 15:17:21 -04:00
} else {
$os_working_number = 10 ;
}
2017-12-04 13:25:35 +00:00
} elseif (( $pv_browser_name == 'saf' ) || ( $pv_browser_name == 'cam' ) ||
(( $pv_browser_name == 'moz' ) && ( $pv_version_number >= 1.3 )) ||
(( $pv_browser_name == 'ie' ) && ( $pv_version_number >= 5.2 ))) {
2012-10-18 15:17:21 -04:00
$os_working_number = 10 ;
}
break ;
case 'iphone' :
$os_working_number = 10 ;
break ;
default :
break ;
}
break ;
2017-12-04 13:25:35 +00:00
} elseif ( is_array ( $os_working_data ) && ( $i == ( $i_count - 2 ))) {
2012-10-18 15:17:21 -04:00
$j_count = count ( $os_working_data );
for ( $j = 0 ; $j < $j_count ; $j ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_string , $os_working_data [ $j ])) {
2012-10-18 15:17:21 -04:00
$os_working_type = 'unix' ; //if the os is in the unix array, it's unix, obviously...
2018-01-15 12:00:22 +00:00
$os_working_number = ( $os_working_data [ $j ] != 'unix' ) ? $os_working_data [ $j ] : '' ; // assign sub unix version from the unix array
2012-10-18 15:17:21 -04:00
break ;
}
}
2017-12-04 13:25:35 +00:00
} elseif ( is_array ( $os_working_data ) && ( $i == ( $i_count - 1 ))) {
2012-10-18 15:17:21 -04:00
$j_count = count ( $os_working_data );
for ( $j = 0 ; $j < $j_count ; $j ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_string , $os_working_data [ $j ])) {
2012-10-18 15:17:21 -04:00
$os_working_type = 'lin' ;
// assign linux distro from the linux array, there's a default
//search for 'lin', if it's that, set version to ''
2017-12-04 13:25:35 +00:00
$os_working_number = ( $os_working_data [ $j ] != 'linux' ) ? $os_working_data [ $j ] : '' ;
2012-10-18 15:17:21 -04:00
break ;
}
}
}
}
// pack the os data array for return to main function
2018-01-15 12:00:22 +00:00
$a_os_data = array ( $os_working_type , $os_working_number );
2012-10-18 15:17:21 -04:00
return $a_os_data ;
}
2018-01-25 20:32:51 +00:00
public static function get_item_version ( $pv_browser_user_agent , $pv_search_string , $pv_b_break_last = '' , $pv_extra_search = '' )
2012-10-18 15:17:21 -04:00
{
$substring_length = 15 ;
$start_pos = 0 ; // set $start_pos to 0 for first iteration
$string_working_number = '' ;
for ( $i = 0 ; $i < 4 ; $i ++ ) {
//start the search after the first string occurrence
2017-12-04 13:25:35 +00:00
if ( strpos ( $pv_browser_user_agent , $pv_search_string , $start_pos ) !== false ) {
$start_pos = strpos ( $pv_browser_user_agent , $pv_search_string , $start_pos ) + strlen ( $pv_search_string );
if ( ! $pv_b_break_last || ( $pv_extra_search && strstr ( $pv_browser_user_agent , $pv_extra_search ))) {
2012-10-18 15:17:21 -04:00
break ;
}
} else {
break ;
}
}
2017-12-04 13:25:35 +00:00
$start_pos += G :: get_set_count ( 'get' );
$string_working_number = substr ( $pv_browser_user_agent , $start_pos , $substring_length );
$string_working_number = substr ( $string_working_number , 0 , strcspn ( $string_working_number , ' );/' ));
if ( ! is_numeric ( substr ( $string_working_number , 0 , 1 ))) {
2012-10-18 15:17:21 -04:00
$string_working_number = '' ;
}
return $string_working_number ;
}
2018-01-25 20:32:51 +00:00
public static function get_set_count ( $pv_type , $pv_value = '' )
2012-10-18 15:17:21 -04:00
{
static $slice_increment ;
$return_value = '' ;
2017-12-04 13:25:35 +00:00
switch ( $pv_type ) {
2012-10-18 15:17:21 -04:00
case 'get' :
2017-12-04 13:25:35 +00:00
if ( is_null ( $slice_increment )) {
2012-10-18 15:17:21 -04:00
$slice_increment = 1 ;
}
$return_value = $slice_increment ;
$slice_increment = 1 ; // reset to default
return $return_value ;
break ;
case 'set' :
$slice_increment = $pv_value ;
break ;
}
}
2018-01-25 20:32:51 +00:00
public static function check_is_mobile ( $pv_browser_user_agent )
2012-10-18 15:17:21 -04:00
{
$mobile_working_test = '' ;
$a_mobile_search = array (
'android' , 'epoc' , 'linux armv' , 'palmos' , 'palmsource' , 'windows ce' , 'windows phone os' , 'symbianos' , 'symbian os' , 'symbian' , 'webos' ,
// devices - ipod before iphone or fails
'benq' , 'blackberry' , 'danger hiptop' , 'ddipocket' , ' droid' , 'ipad' , 'ipod' , 'iphone' , 'kindle' , 'lge-cx' , 'lge-lx' , 'lge-mx' , 'lge vx' , 'lge ' , 'lge-' , 'lg;lx' , 'nintendo wii' , 'nokia' , 'palm' , 'pdxgw' , 'playstation' , 'sagem' , 'samsung' , 'sec-sgh' , 'sharp' , 'sonyericsson' , 'sprint' , 'zune' , 'j-phone' , 'n410' , 'mot 24' , 'mot-' , 'htc-' , 'htc_' , 'htc ' , 'sec-' , 'sie-m' , 'sie-s' , 'spv ' , 'vodaphone' , 'smartphone' , 'armv' , 'midp' , 'mobilephone' ,
// browsers
2018-01-15 12:00:22 +00:00
'avantgo' , 'blazer' , 'elaine' , 'eudoraweb' , 'iemobile' , 'minimo' , 'mobile safari' , 'mobileexplorer' , 'opera mobi' , 'opera mini' , 'netfront' , 'opwv' , 'polaris' , 'semc-browser' , 'up.browser' , 'webpro' , 'wms pie' , 'xiino' ,
2012-10-18 15:17:21 -04:00
// services - astel out of business
2018-01-15 12:00:22 +00:00
'astel' , 'docomo' , 'novarra-vision' , 'portalmmm' , 'reqwirelessweb' , 'vodafone'
2012-10-18 15:17:21 -04:00
);
// then do basic mobile type search, this uses data from: get_mobile_data()
2017-12-04 13:25:35 +00:00
$j_count = count ( $a_mobile_search );
2012-10-18 15:17:21 -04:00
for ( $j = 0 ; $j < $j_count ; $j ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_user_agent , $a_mobile_search [ $j ])) {
2012-10-18 15:17:21 -04:00
$mobile_working_test = $a_mobile_search [ $j ];
break ;
}
}
return $mobile_working_test ;
}
2018-01-25 20:32:51 +00:00
public static function get_mobile_data ( $pv_browser_user_agent )
2012-10-18 15:17:21 -04:00
{
$mobile_browser = '' ;
$mobile_browser_number = '' ;
$mobile_device = '' ;
$mobile_device_number = '' ;
$mobile_os = '' ; // will usually be null, sorry
$mobile_os_number = '' ;
$mobile_server = '' ;
$mobile_server_number = '' ;
2018-01-15 12:00:22 +00:00
$a_mobile_browser = array ( 'avantgo' , 'blazer' , 'elaine' , 'eudoraweb' , 'iemobile' , 'minimo' , 'mobile safari' , 'mobileexplorer' , 'opera mobi' , 'opera mini' , 'netfront' , 'opwv' , 'polaris' , 'semc-browser' , 'up.browser' , 'webpro' , 'wms pie' , 'xiino' );
$a_mobile_device = array ( 'benq' , 'blackberry' , 'danger hiptop' , 'ddipocket' , ' droid' , 'htc_dream' , 'htc espresso' , 'htc hero' , 'htc halo' , 'htc huangshan' , 'htc legend' , 'htc liberty' , 'htc paradise' , 'htc supersonic' , 'htc tattoo' , 'ipad' , 'ipod' , 'iphone' , 'kindle' , 'lge-cx' , 'lge-lx' , 'lge-mx' , 'lge vx' , 'lg;lx' , 'nintendo wii' , 'nokia' , 'palm' , 'pdxgw' , 'playstation' , 'sagem' , 'samsung' , 'sec-sgh' , 'sharp' , 'sonyericsson' , 'sprint' , 'zunehd' , 'zune' , 'j-phone' , 'milestone' , 'n410' , 'mot 24' , 'mot-' , 'htc-' , 'htc_' , 'htc ' , 'lge ' , 'lge-' , 'sec-' , 'sie-m' , 'sie-s' , 'spv ' , 'smartphone' , 'armv' , 'midp' , 'mobilephone' );
$a_mobile_os = array ( 'android' , 'epoc' , 'cpu os' , 'iphone os' , 'palmos' , 'palmsource' , 'windows phone os' , 'windows ce' , 'symbianos' , 'symbian os' , 'symbian' , 'webos' , 'linux armv' );
$a_mobile_server = array ( 'astel' , 'docomo' , 'novarra-vision' , 'portalmmm' , 'reqwirelessweb' , 'vodafone' );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$k_count = count ( $a_mobile_browser );
2012-10-18 15:17:21 -04:00
for ( $k = 0 ; $k < $k_count ; $k ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_user_agent , $a_mobile_browser [ $k ])) {
2012-10-18 15:17:21 -04:00
$mobile_browser = $a_mobile_browser [ $k ];
2017-12-04 13:25:35 +00:00
$mobile_browser_number = G :: get_item_version ( $pv_browser_user_agent , $mobile_browser );
2012-10-18 15:17:21 -04:00
break ;
}
}
2017-12-04 13:25:35 +00:00
$k_count = count ( $a_mobile_device );
2012-10-18 15:17:21 -04:00
for ( $k = 0 ; $k < $k_count ; $k ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_user_agent , $a_mobile_device [ $k ])) {
$mobile_device = trim ( $a_mobile_device [ $k ], '-_' ); // but not space trims yet
2012-10-18 15:17:21 -04:00
if ( $mobile_device == 'blackberry' ) {
2017-12-04 13:25:35 +00:00
G :: get_set_count ( 'set' , 0 );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$mobile_device_number = G :: get_item_version ( $pv_browser_user_agent , $mobile_device );
$mobile_device = trim ( $mobile_device ); // some of the id search strings have white space
2012-10-18 15:17:21 -04:00
break ;
}
}
2017-12-04 13:25:35 +00:00
$k_count = count ( $a_mobile_os );
2012-10-18 15:17:21 -04:00
for ( $k = 0 ; $k < $k_count ; $k ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_user_agent , $a_mobile_os [ $k ])) {
2012-10-18 15:17:21 -04:00
$mobile_os = $a_mobile_os [ $k ];
2017-12-04 13:25:35 +00:00
$mobile_os_number = str_replace ( '_' , '.' , G :: get_item_version ( $pv_browser_user_agent , $mobile_os ));
2012-10-18 15:17:21 -04:00
break ;
}
}
2017-12-04 13:25:35 +00:00
$k_count = count ( $a_mobile_server );
2012-10-18 15:17:21 -04:00
for ( $k = 0 ; $k < $k_count ; $k ++ ) {
2017-12-04 13:25:35 +00:00
if ( strstr ( $pv_browser_user_agent , $a_mobile_server [ $k ])) {
2012-10-18 15:17:21 -04:00
$mobile_server = $a_mobile_server [ $k ];
2017-12-04 13:25:35 +00:00
$mobile_server_number = G :: get_item_version ( $pv_browser_user_agent , $mobile_server );
2012-10-18 15:17:21 -04:00
break ;
}
}
// just for cases where we know it's a mobile device already
2017-12-04 13:25:35 +00:00
if ( ! $mobile_os && ( $mobile_browser || $mobile_device || $mobile_server ) && strstr ( $pv_browser_user_agent , 'linux' )) {
2012-10-18 15:17:21 -04:00
$mobile_os = 'linux' ;
2017-12-04 13:25:35 +00:00
$mobile_os_number = G :: get_item_version ( $pv_browser_user_agent , 'linux' );
2012-10-18 15:17:21 -04:00
}
2018-01-15 12:00:22 +00:00
$a_mobile_data = array ( $mobile_device , $mobile_browser , $mobile_browser_number , $mobile_os , $mobile_os_number , $mobile_server , $mobile_server_number , $mobile_device_number );
2012-10-18 15:17:21 -04:00
return $a_mobile_data ;
}
2018-01-25 20:32:51 +00:00
public static function getBrowser ()
2012-10-18 15:17:21 -04:00
{
$u_agent = $_SERVER [ 'HTTP_USER_AGENT' ];
$bname = 'Unknown' ;
$platform = 'Unknown' ;
$version = " " ;
2014-10-23 16:18:07 -04:00
$ub = " other " ;
2012-10-18 15:17:21 -04:00
//First get the platform?
2017-12-04 13:25:35 +00:00
if ( preg_match ( '/linux/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$platform = 'linux' ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/macintosh|mac os x/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$platform = 'mac' ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/windows|win32/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$platform = 'windows' ;
}
// Next get the name of the useragent yes seperately and for good reason
2018-01-15 12:00:22 +00:00
if (( preg_match ( '~Trident/7.0; rv:11.0~' , $u_agent ) || preg_match ( '/MSIE/i' , $u_agent )) && ! preg_match ( '/Opera/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$bname = 'Internet Explorer' ;
$ub = " MSIE " ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/Firefox/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$bname = 'Mozilla Firefox' ;
$ub = " Firefox " ;
2017-12-04 13:25:35 +00:00
} elseif (( preg_match ( '/Opera/i' , $u_agent )) || ( preg_match ( '/OPR/i' , $u_agent ))) {
2014-10-27 13:38:36 -04:00
$bname = 'Opera' ;
$ub = " Opera " ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/Chrome/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$bname = 'Google Chrome' ;
$ub = " Chrome " ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/Safari/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$bname = 'Apple Safari' ;
$ub = " Safari " ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/Netscape/i' , $u_agent )) {
2012-10-18 15:17:21 -04:00
$bname = 'Netscape' ;
$ub = " Netscape " ;
2017-12-04 13:25:35 +00:00
} elseif ( preg_match ( '/bingbot/i' , $u_agent )) {
2014-10-23 16:18:07 -04:00
$bname = 'Bing Bot' ;
$ub = " bingbot " ;
2012-10-18 15:17:21 -04:00
}
// finally get the correct version number
2018-01-15 12:00:22 +00:00
$known = array ( 'Version' , $ub , 'other' );
2017-12-04 13:25:35 +00:00
$pattern = '#(?P<browser>' . join ( '|' , $known ) . ')[/ ]+(?P<version>[0-9.|a-zA-Z.]*)#' ;
@ preg_match_all ( $pattern , $u_agent , $matches );
2012-10-18 15:17:21 -04:00
// see how many we have
2017-12-04 13:25:35 +00:00
$i = count ( $matches [ 'browser' ]);
2012-10-18 15:17:21 -04:00
if ( $i != 1 ) {
//we will have two since we are not using 'other' argument yet
//see if version is before or after the name
2017-12-04 13:25:35 +00:00
if ( strripos ( $u_agent , " Version " ) < strripos ( $u_agent , $ub )) {
2012-10-18 15:17:21 -04:00
$version = $matches [ 'version' ][ 0 ];
} else {
2014-09-03 13:41:00 -04:00
$version = isset ( $matches [ 'version' ][ 1 ]) ? $matches [ 'version' ][ 1 ] : '' ;
2012-10-18 15:17:21 -04:00
}
} else {
$version = $matches [ 'version' ][ 0 ];
}
// check if we have a number
if ( $version == null || $version == " " ) {
2017-12-04 13:25:35 +00:00
if ( $ub == 'MSIE' ) {
$parent = 'RV' ;
} elseif ( $ub == 'Opera' ) {
$parent = 'OPR' ;
}
if ( isset ( $parent ) && $parent != " " ) {
$s = strpos ( strtoupper ( $u_agent ), $parent );
$f = $s + strlen ( $parent );
$version = substr ( $u_agent , $f , 15 );
$version = preg_replace ( '/[^0-9,.]/' , '' , $version );
} else {
2014-10-22 09:16:14 -04:00
$version = " ? " ;
2017-12-04 13:25:35 +00:00
}
2012-10-18 15:17:21 -04:00
}
2018-01-15 12:00:22 +00:00
return array ( 'userAgent' => $u_agent , 'name' => strtolower ( $ub ), 'longName' => $bname , 'version' => $version , 'platform' => $platform , 'pattern' => $pattern );
2012-10-18 15:17:21 -04:00
}
// track total script execution time
2018-01-25 20:32:51 +00:00
public static function script_time ()
2012-10-18 15:17:21 -04:00
{
static $script_time ;
$elapsed_time = '' ;
/*
note that microtime ( true ) requires php 5 or greater for microtime ( true )
*/
2017-12-04 13:25:35 +00:00
if ( sprintf ( " %01.1f " , phpversion ()) >= 5 ) {
if ( is_null ( $script_time )) {
$script_time = microtime ( true );
2012-10-18 15:17:21 -04:00
} else {
// note: (string)$var is same as strval($var)
// $elapsed_time = (string)( microtime(true) - $script_time );
2017-12-04 13:25:35 +00:00
$elapsed_time = ( microtime ( true ) - $script_time );
$elapsed_time = sprintf ( " %01.8f " , $elapsed_time );
2012-10-18 15:17:21 -04:00
$script_time = null ; // can't unset a static variable
return $elapsed_time ;
}
}
}
2018-01-25 20:32:51 +00:00
public static function getDirectorySize ( $path , $maxmtime = 0 )
2012-10-18 15:17:21 -04:00
{
$totalsize = 0 ;
$totalcount = 0 ;
$dircount = 0 ;
2017-12-04 13:25:35 +00:00
if ( $handle = opendir ( $path )) {
while ( false !== ( $file = readdir ( $handle ))) {
2012-10-18 15:17:21 -04:00
$nextpath = $path . '/' . $file ;
2018-01-15 12:00:22 +00:00
if ( $file != '.' && $file != '..' && ! is_link ( $nextpath ) && $file != '.svn' ) {
2017-12-04 13:25:35 +00:00
if ( is_dir ( $nextpath )) {
2012-10-18 15:17:21 -04:00
$dircount ++ ;
2017-12-04 13:25:35 +00:00
$result = G :: getDirectorySize ( $nextpath , $maxmtime );
2012-10-18 15:17:21 -04:00
$totalsize += $result [ 'size' ];
$totalcount += $result [ 'count' ];
$dircount += $result [ 'dircount' ];
$maxmtime = $result [ 'maxmtime' ] > $maxmtime ? $result [ 'maxmtime' ] : $maxmtime ;
2017-12-04 13:25:35 +00:00
} elseif ( is_file ( $nextpath )) {
$totalsize += filesize ( $nextpath );
2012-10-18 15:17:21 -04:00
$totalcount ++ ;
2017-12-04 13:25:35 +00:00
$mtime = filemtime ( $nextpath );
2012-10-18 15:17:21 -04:00
if ( $mtime > $maxmtime ) {
$maxmtime = $mtime ;
}
}
}
}
}
2017-12-04 13:25:35 +00:00
closedir ( $handle );
2012-10-18 15:17:21 -04:00
$total [ 'size' ] = $totalsize ;
$total [ 'count' ] = $totalcount ;
$total [ 'dircount' ] = $dircount ;
$total [ 'maxmtime' ] = $maxmtime ;
return $total ;
}
/**
* Get checksum from multiple files
*
* @ author erik amaru ortiz < erik @ colosa . com >
*/
2017-12-04 13:25:35 +00:00
public function getCacheFileNameByPattern ( $path , $pattern )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( $file = glob ( $path . $pattern )) {
preg_match ( '/[a-f0-9]{32}/' , $file [ 0 ], $match );
2012-10-18 15:17:21 -04:00
} else {
$file [ 0 ] = '' ;
}
2018-01-15 12:00:22 +00:00
return array ( 'filename' => $file [ 0 ], 'checksum' => ( isset ( $match [ 0 ]) ? $match [ 0 ] : '' ));
2012-10-18 15:17:21 -04:00
}
/**
* Get checksum from multiple files
*
* @ author erik amaru ortiz < erik @ colosa . com >
*/
2017-12-04 13:25:35 +00:00
public function getCheckSum ( $files )
2012-10-18 15:17:21 -04:00
{
2017-08-14 16:13:46 -04:00
$key = System :: getVersion ();
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
if ( ! is_array ( $files )) {
2012-10-18 15:17:21 -04:00
$tmp = $files ;
2017-12-04 13:25:35 +00:00
$files = array ();
2012-10-18 15:17:21 -04:00
$files [ 0 ] = $tmp ;
}
$checkSum = '' ;
foreach ( $files as $file ) {
2017-12-04 13:25:35 +00:00
if ( is_file ( $file )) {
$checkSum .= G :: encryptFileOld ( $file );
2012-10-18 15:17:21 -04:00
}
}
2017-12-04 13:25:35 +00:00
return G :: encryptOld ( $checkSum . $key );
2012-10-18 15:17:21 -04:00
}
/**
* parse_ini_string
* Define parse_ini_string if it doesn ' t exist .
* Does accept lines starting with ; as comments
* Does not accept comments after values
*/
2017-12-04 13:25:35 +00:00
public static function parse_ini_string ( $string )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( function_exists ( 'parse_ini_string' )) {
return parse_ini_string ( $string );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$array = array ();
$lines = explode ( " \n " , $string );
2012-10-18 15:17:21 -04:00
foreach ( $lines as $line ) {
2017-12-04 13:25:35 +00:00
$statement = preg_match ( " /^(?!;)(?P<key>[ \ w+ \ . \ -]+?) \ s*= \ s*(?P<value>.+?) \ s* $ / " , $line , $match );
2012-10-18 15:17:21 -04:00
if ( $statement ) {
$key = $match [ 'key' ];
$value = $match [ 'value' ];
//Remove quote
2017-12-04 13:25:35 +00:00
if ( preg_match ( " /^ \" .* \" $ / " , $value ) || preg_match ( " /^'.*' $ / " , $value )) {
$value = mb_substr ( $value , 1 , mb_strlen ( $value ) - 2 );
2012-10-18 15:17:21 -04:00
}
$array [ $key ] = $value ;
}
}
return $array ;
}
}
/**
* disableEnableINIvariable
* disable or enable a variable in ini file , this is useful for editing the env . ini file
* automatically get the value , and change to inverse value , I mean from true to false and viceversa
*/
2017-12-04 13:25:35 +00:00
public function disableEnableINIvariable ( $inifile , $variable )
2012-10-18 15:17:21 -04:00
{
$enabled = 'false' ;
2017-12-04 13:25:35 +00:00
if ( file_exists ( $inifile )) {
$fp = fopen ( $inifile , 'r' );
$line = fgets ( $fp );
2012-10-18 15:17:21 -04:00
$found = false ;
$buffer = null ;
2018-01-15 12:00:22 +00:00
while ( ! feof ( $fp )) {
2017-12-04 13:25:35 +00:00
$config = G :: parse_ini_string ( $line );
if ( isset ( $config [ $variable ])) {
2012-10-18 15:17:21 -04:00
$enabled = $config [ $variable ];
2017-12-04 13:25:35 +00:00
$buffer .= sprintf ( " %s = %d \n " , $variable , 1 - $enabled );
2012-10-18 15:17:21 -04:00
$found = true ;
} else {
2017-12-04 13:25:35 +00:00
$buffer .= trim ( $line ) . " \n " ;
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$line = fgets ( $fp );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
fclose ( $fp );
2018-01-15 12:00:22 +00:00
if ( ! $found ) {
2017-12-04 13:25:35 +00:00
$buffer .= sprintf ( " \n %s = 1 \n " , $variable );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
@ file_put_contents ( $inifile , $buffer );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$contents = file_put_contents ( $inifile , sprintf ( " \n %s = 1 \n " , $variable ));
2012-10-18 15:17:21 -04:00
}
}
/**
* set a variable in ini file
*/
2017-12-04 13:25:35 +00:00
public function setINIvariable ( $inifile , $variable , $value )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( file_exists ( $inifile )) {
$fp = fopen ( $inifile , 'r' );
$line = fgets ( $fp );
2012-10-18 15:17:21 -04:00
$found = false ;
$buffer = null ;
2018-01-15 12:00:22 +00:00
while ( ! feof ( $fp )) {
2017-12-04 13:25:35 +00:00
$config = G :: parse_ini_string ( $line );
if ( isset ( $config [ $variable ])) {
2012-10-18 15:17:21 -04:00
$enabled = $config [ $variable ];
2017-12-04 13:25:35 +00:00
$buffer .= sprintf ( " %s = %s \n " , $variable , $value );
2012-10-18 15:17:21 -04:00
$found = true ;
} else {
2017-12-04 13:25:35 +00:00
$buffer .= trim ( $line ) . " \n " ;
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$line = fgets ( $fp );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
fclose ( $fp );
2018-01-15 12:00:22 +00:00
if ( ! $found ) {
2017-12-04 13:25:35 +00:00
$buffer .= sprintf ( " \n %s = %s \n " , $variable , $value );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
file_put_contents ( $inifile , $buffer );
2012-10-18 15:17:21 -04:00
} else {
2017-12-04 13:25:35 +00:00
$contents = file_put_contents ( $inifile , sprintf ( " \n %s = $s\n " , $variable , $value ));
2012-10-18 15:17:21 -04:00
}
}
2017-12-04 13:25:35 +00:00
public function write_php_ini ( $file , $array )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$res = array ();
2012-10-18 15:17:21 -04:00
foreach ( $array as $key => $val ) {
2017-12-04 13:25:35 +00:00
if ( is_array ( $val )) {
2012-10-18 15:17:21 -04:00
$res [] = " [ $key ] " ;
foreach ( $val as $skey => $sval ) {
2017-12-04 13:25:35 +00:00
$res [] = " $skey = " . ( is_numeric ( $sval ) ? $sval : '"' . $sval . '"' );
2012-10-18 15:17:21 -04:00
}
} else {
2017-12-04 13:25:35 +00:00
$res [] = " $key = " . ( is_numeric ( $val ) ? $val : '"' . $val . '"' );
2012-10-18 15:17:21 -04:00
}
}
2017-12-04 13:25:35 +00:00
file_put_contents ( $file , implode ( " \r \n " , $res ));
2012-10-18 15:17:21 -04:00
}
/**
* verify if all files & directories passed by param .
* are writable
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ param $resources array a list of files to verify write access
*/
2018-01-25 20:32:51 +00:00
public static function verifyWriteAccess ( $resources )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$noWritable = array ();
2012-10-18 15:17:21 -04:00
foreach ( $resources as $i => $resource ) {
2018-01-15 12:00:22 +00:00
if ( ! is_writable ( $resource )) {
2012-10-18 15:17:21 -04:00
$noWritable [] = $resource ;
}
}
2017-12-04 13:25:35 +00:00
if ( count ( $noWritable ) > 0 ) {
$e = new Exception ( " Write access not allowed for ProcessMaker resources " );
2012-10-18 15:17:21 -04:00
$e -> files = $noWritable ;
throw $e ;
}
}
/**
* render a smarty template
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ param $template string containing the template filename on / gulliver / templates / directory
* @ param $data associative array containig the template data
*/
2018-01-25 20:32:51 +00:00
public static function renderTemplate ( $template , $data = array ())
2012-10-18 15:17:21 -04:00
{
2018-01-15 12:00:22 +00:00
if ( ! defined ( 'PATH_THIRDPARTY' )) {
2017-12-04 13:25:35 +00:00
throw new Exception ( 'System constant (PATH_THIRDPARTY) is not defined!' );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$fInfo = pathinfo ( $template );
2012-10-18 15:17:21 -04:00
$tplExists = true ;
// file has absolute path
2013-02-07 16:55:06 -04:00
if ( strpos ( $template , PATH_TRUNK ) === false ) {
$template = PATH_TPL . $template ;
2012-10-18 15:17:21 -04:00
}
// fix for template that have dot in its name but is not a valid extension
2017-12-04 13:25:35 +00:00
if ( isset ( $fInfo [ 'extension' ]) && ( $fInfo [ 'extension' ] != 'tpl' || $fInfo [ 'extension' ] != 'html' )) {
unset ( $fInfo [ 'extension' ]);
2012-10-18 15:17:21 -04:00
}
2018-01-15 12:00:22 +00:00
if ( ! isset ( $fInfo [ 'extension' ])) {
2017-12-04 13:25:35 +00:00
if ( file_exists ( $template . '.tpl' )) {
2012-10-18 15:17:21 -04:00
$template .= '.tpl' ;
2017-12-04 13:25:35 +00:00
} elseif ( file_exists ( $template . '.html' )) {
2012-10-18 15:17:21 -04:00
$template .= '.html' ;
} else {
$tplExists = false ;
}
} else {
2018-01-15 12:00:22 +00:00
if ( ! file_exists ( $template )) {
2012-10-18 15:17:21 -04:00
$tplExists = false ;
}
}
2018-01-15 12:00:22 +00:00
if ( ! $tplExists ) {
2017-12-04 13:25:35 +00:00
throw new Exception ( " Template: $template , doesn't exist! " );
2012-10-18 15:17:21 -04:00
}
$smarty = new Smarty ();
$smarty -> compile_dir = G :: sys_get_temp_dir ();
$smarty -> cache_dir = G :: sys_get_temp_dir ();
$smarty -> config_dir = PATH_THIRDPARTY . 'smarty/configs' ;
$smarty -> template_dir = PATH_TEMPLATE ;
$smarty -> force_compile = true ;
foreach ( $data as $key => $value ) {
2017-12-04 13:25:35 +00:00
$smarty -> assign ( $key , $value );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
$smarty -> display ( $template );
2012-10-18 15:17:21 -04:00
}
/**
* parse a smarty template and return teh result as string
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ param $template string containing the template filename on / gulliver / templates / directory
* @ param $data associative array containig the template data
* @ return $content string containing the parsed template content
*/
2018-01-25 20:32:51 +00:00
public static function parseTemplate ( $template , $data = array ())
2012-10-18 15:17:21 -04:00
{
$content = '' ;
ob_start ();
2017-12-04 13:25:35 +00:00
G :: renderTemplate ( $template , $data );
2012-10-18 15:17:21 -04:00
$content = ob_get_contents ();
ob_get_clean ();
return $content ;
}
/**
* Update a ini file passing a array values , this function don ' t remove the original comments
*
* @ author Erik Amaru Ortiz < erik @ colosa . com >
* @ licence GPL v2 ( http :// www . gnu . org / licenses / gpl - 2.0 . html )
*
* @ param $file string containing the ini file to update
* @ param $array associative array containing the config data
*/
2017-12-04 13:25:35 +00:00
public static function update_php_ini ( $file , $array )
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
$iniLines = array ();
$iniContent = array ();
2012-10-18 15:17:21 -04:00
2018-01-15 12:00:22 +00:00
if ( file_exists ( $file ) && ! is_writable ( $file )) {
2017-12-04 13:25:35 +00:00
throw new Exception ( " File $file , is not writable. " );
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
if ( file_exists ( $file )) {
$iniContent = file ( $file );
2012-10-18 15:17:21 -04:00
}
foreach ( $iniContent as $line ) {
2017-12-04 13:25:35 +00:00
$line = trim ( $line );
$lineParts = explode ( ';' , $line );
$setting = G :: parse_ini_string ( $lineParts [ 0 ]);
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( is_array ( $setting ) && count ( $setting ) > 0 ) {
list ( $key , ) = array_keys ( $setting );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( isset ( $array [ $key ])) {
2012-10-18 15:17:21 -04:00
$value = $array [ $key ];
2017-12-04 13:25:35 +00:00
$line = " $key = " . ( is_numeric ( $value ) ? $value : '"' . $value . '"' );
$line .= isset ( $lineParts [ 1 ]) ? ' ;' . $lineParts [ 1 ] : '' ;
unset ( $array [ $key ]);
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
$lastComment = array_pop ( $iniLines );
if ( strpos ( $lastComment , " Setting $key " ) === false ) {
2012-10-18 15:17:21 -04:00
$iniLines [] = $lastComment ;
}
2017-12-04 13:25:35 +00:00
$iniLines [] = " ;Setting $key - Updated by System on " . date ( 'D d M, Y H:i:s' );
2012-10-18 15:17:21 -04:00
}
}
$iniLines [] = $line ;
}
// inserting new values
foreach ( $array as $key => $value ) {
2017-12-04 13:25:35 +00:00
$line = " $key = " . ( is_numeric ( $value ) ? $value : '"' . $value . '"' );
2012-10-18 15:17:21 -04:00
$iniLines [] = '' ;
2017-12-04 13:25:35 +00:00
$iniLines [] = " ;Setting $key - Created by System on " . date ( 'D d M, Y H:i:s' );
2012-10-18 15:17:21 -04:00
$iniLines [] = $line ;
}
2017-12-04 13:25:35 +00:00
$content = implode ( " \r \n " , $iniLines );
2012-10-18 15:17:21 -04:00
2017-12-04 13:25:35 +00:00
if ( @ file_put_contents ( $file , $content ) === false ) {
throw new Exception ( " G::update_php_ini() -> can't update file: $file " );
} else {
2013-05-08 15:39:59 -04:00
//first a raw permission check
2017-12-04 13:25:35 +00:00
if ( fileperms ( $file ) != 33200 ) {
@ chmod ( $file , 0660 );
2013-05-08 15:39:59 -04:00
}
2012-10-18 15:17:21 -04:00
}
}
/**
* recursive file & directories write permission detect
*
* @ licence GPL v2 ( http :// www . gnu . org / licenses / gpl - 2.0 . html )
*
* @ param $path string of directory or file to verify recursively
* @ param $noWritableFiles ( alternative ) array passed by reference to store all no - writable files
* @ return bool true if all files inside a directory path are writable , false in another case
*/
2017-12-04 13:25:35 +00:00
public static function is_writable_r ( $path , & $noWritableFiles = array ())
2012-10-18 15:17:21 -04:00
{
2017-12-04 13:25:35 +00:00
if ( is_writable ( $path )) {
2018-01-15 12:00:22 +00:00
if ( ! is_dir ( $path )) {
2012-10-18 15:17:21 -04:00
return true ;
}
2017-12-04 13:25:35 +00:00
$list = glob ( rtrim ( $path , DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . '*' );
2012-10-18 15:17:21 -04:00
$sw = true ;
2017-12-04 13:25:35 +00:00
if ( is_array ( $list )) {
2015-12-11 12:40:55 -04:00
foreach ( $list as $f ) {
2018-01-15 12:00:22 +00:00
if ( ! G :: is_writable_r ( $f , $noWritableFiles )) {
2015-12-11 12:40:55 -04:00
$sw = false ;
}
2012-10-18 15:17:21 -04:00
}
2015-12-11 12:40:55 -04:00
} else {
$sw = false ;
2012-10-18 15:17:21 -04:00
}
return $sw ;
} else {
2018-01-15 12:00:22 +00:00
if ( ! in_array ( $path , $noWritableFiles )) {
2012-10-18 15:17:21 -04:00
$noWritableFiles [] = $path ;
}
return false ;
}
}
/**
* This method allow dispatch rest services using 'Restler' thirdparty library
*
* @ author Erik Amaru Ortiz < aortiz . erik @ gmail . com >
*/
2018-01-25 20:32:51 +00:00
public static function dispatchRestService ( $uri , $config , $apiClassesPath = '' )
2012-10-18 15:17:21 -04:00
{
require_once 'restler/restler.php' ;
$rest = new Restler ();
2017-12-04 13:25:35 +00:00
$rest -> setSupportedFormats ( 'JsonFormat' , 'XmlFormat' );
2012-10-18 15:17:21 -04:00
// getting all services class
2017-12-04 13:25:35 +00:00
$restClasses = array ();
$restClassesList = G :: rglob ( '*' , 0 , PATH_CORE . 'services/' );
2012-10-18 15:17:21 -04:00
foreach ( $restClassesList as $classFile ) {
2017-12-04 13:25:35 +00:00
if ( substr ( $classFile , - 4 ) === '.php' ) {
$restClasses [ str_replace ( '.php' , '' , basename ( $classFile ))] = $classFile ;
2012-10-18 15:17:21 -04:00
}
}
2018-01-15 12:00:22 +00:00
if ( ! empty ( $apiClassesPath )) {
2017-12-04 13:25:35 +00:00
$pluginRestClasses = array ();
$restClassesList = G :: rglob ( '*' , 0 , $apiClassesPath . 'services/' );
2012-10-18 15:17:21 -04:00
foreach ( $restClassesList as $classFile ) {
2017-12-04 13:25:35 +00:00
if ( substr ( $classFile , - 4 ) === '.php' ) {
$pluginRestClasses [ str_replace ( '.php' , '' , basename ( $classFile ))] = $classFile ;
2012-10-18 15:17:21 -04:00
}
}
2017-12-04 13:25:35 +00:00
$restClasses = array_merge ( $restClasses , $pluginRestClasses );
2012-10-18 15:17:21 -04:00
}
// hook to get rest api classes from plugins
2017-12-04 13:25:35 +00:00
if ( class_exists ( 'ProcessMaker\Plugins\PluginRegistry' )) {
2017-08-10 12:10:42 -04:00
$pluginRegistry = PluginRegistry :: loadSingleton ();
$pluginClasses = $pluginRegistry -> getRegisteredRestServices ();
2017-12-04 13:25:35 +00:00
$restClasses = array_merge ( $restClasses , $pluginClasses );
2012-10-18 15:17:21 -04:00
}
foreach ( $restClasses as $key => $classFile ) {
2018-01-15 12:00:22 +00:00
if ( ! file_exists ( $classFile )) {
2017-12-04 13:25:35 +00:00
unset ( $restClasses [ $key ]);
2012-10-18 15:17:21 -04:00
continue ;
}
//load the file, and check if exist the class inside it.
require_once $classFile ;
$namespace = 'Services_Rest_' ;
2017-12-04 13:25:35 +00:00
$className = str_replace ( '.php' , '' , basename ( $classFile ));
2012-10-18 15:17:21 -04:00
// if the core class does not exists try resolve the for a plugin
2018-01-15 12:00:22 +00:00
if ( ! class_exists ( $namespace . $className )) {
2012-10-18 15:17:21 -04:00
$namespace = 'Plugin_Services_Rest_' ;
// Couldn't resolve the class name, just skipp it
2018-01-15 12:00:22 +00:00
if ( ! class_exists ( $namespace . $className )) {
2017-12-04 13:25:35 +00:00
unset ( $restClasses [ $key ]);
2012-10-18 15:17:21 -04:00
continue ;
}
}
// verify if there is an auth class implementing 'iAuthenticate'
$classNameAuth = $namespace . $className ;
2017-12-04 13:25:35 +00:00
$reflClass = new ReflectionClass ( $classNameAuth );
2012-10-18 15:17:21 -04:00
// that wasn't from plugin
2017-12-04 13:25:35 +00:00
if ( $reflClass -> implementsInterface ( 'iAuthenticate' ) && $namespace != 'Plugin_Services_Rest_' ) {
2012-10-18 15:17:21 -04:00
// auth class found, set as restler authentication class handler
2017-12-04 13:25:35 +00:00
$rest -> addAuthenticationClass ( $classNameAuth );
2012-10-18 15:17:21 -04:00
} else {
// add api class
2017-12-04 13:25:35 +00:00
$rest -> addAPIClass ( $classNameAuth );
2012-10-18 15:17:21 -04:00
}
}
//end foreach rest class
// resolving the class for current request
2017-12-04 13:25:35 +00:00
$uriPart = explode ( '/' , $uri );
2012-10-18 15:17:21 -04:00
$requestedClass = '' ;
2017-12-04 13:25:35 +00:00
if ( isset ( $uriPart [ 1 ])) {
$requestedClass = ucfirst ( $uriPart [ 1 ]);
2012-10-18 15:17:21 -04:00
}
2017-12-04 13:25:35 +00:00
if ( class_exists ( 'Services_Rest_' . $requestedClass )) {
2012-10-18 15:17:21 -04:00
$namespace = 'Services_Rest_' ;
2017-12-04 13:25:35 +00:00
} elseif ( class_exists ( 'Plugin_Services_Rest_' . $requestedClass )) {
2012-10-18 15:17:21 -04:00
$namespace = 'Plugin_Services_Rest_' ;
} else {
$namespace = '' ;
}
// end resolv.
// Send additional headers (if exists) configured on rest-config.ini
2017-12-04 13:25:35 +00:00
if ( array_key_exists ( 'HEADERS' , $config )) {
2012-10-18 15:17:21 -04:00
foreach ( $config [ 'HEADERS' ] as $name => $value ) {
2017-12-04 13:25:35 +00:00
header ( " $name : $value " );
2012-10-18 15:17:21 -04:00
}
}
// to handle a request with "OPTIONS" method
2018-01-15 12:00:22 +00:00
if ( ! empty ( $namespace ) && $_SERVER [ 'REQUEST_METHOD' ] === 'OPTIONS' ) {
2017-12-04 13:25:35 +00:00
$reflClass = new ReflectionClass ( $namespace . $requestedClass );
2012-10-18 15:17:21 -04:00
// if the rest class has not a "options" method
2018-01-15 12:00:22 +00:00
if ( ! $reflClass -> hasMethod ( 'options' )) {
2017-12-04 13:25:35 +00:00
header ( 'Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, HEADERS' );
header ( 'Access-Control-Allow-Headers: authorization, content-type' );
header ( " Access-Control-Allow-Credentials " , " false " );
header ( 'Access-Control-Max-Age: 60' );
2012-10-18 15:17:21 -04:00
exit ();
}
}
// override global REQUEST_URI to pass to Restler library
2017-12-04 13:25:35 +00:00
$_SERVER [ 'REQUEST_URI' ] = '/' . strtolower ( $namespace ) . ltrim ( $uri , '/' );
2012-10-18 15:17:21 -04:00
// handle the rest request
$rest -> handle ();
}
2017-12-04 13:25:35 +00:00
public static function reservedWordsSql ()
2012-10-18 15:17:21 -04:00
{
//Reserved words SQL
2017-12-04 13:25:35 +00:00
$reservedWordsSql = array ( " ACCESSIBLE " , " ACTION " , " ADD " , " ALL " , " ALTER " , " ANALYZE " , " AND " , " ANY " , " AS " , " ASC " , " ASENSITIVE " , " AUTHORIZATION " , " BACKUP " , " BEFORE " , " BEGIN " , " BETWEEN " , " BIGINT " , " BINARY " , " BIT " , " BLOB " , " BOTH " , " BREAK " , " BROWSE " , " BULK " , " BY " , " CALL " , " CASCADE " , " CASE " , " CHANGE " , " CHAR " , " CHARACTER " , " CHECK " , " CHECKPOINT " , " CLOSE " , " CLUSTERED " , " COALESCE " , " COLLATE " , " COLUMN " , " COMMIT " , " COMPUTE " , " CONDITION " , " CONSTRAINT " , " CONTAINS " , " CONTAINSTABLE " , " CONTINUE " , " CONVERT " , " CREATE " , " CROSS " , " CURRENT " , " CURRENT_DATE " , " CURRENT_TIME " , " CURRENT_TIMESTAMP " , " CURRENT_USER " , " CURSOR " , " DATABASE " , " DATABASES " , " DATE " , " DAY_HOUR " , " DAY_MICROSECOND " , " DAY_MINUTE " , " DAY_SECOND " , " DBCC " , " DEALLOCATE " , " DEC " , " DECIMAL " , " DECLARE " , " DEFAULT " , " DELAYED " , " DELETE " , " DENY " , " DESC " , " DESCRIBE " , " DETERMINISTIC " , " DISK " , " DISTINCT " , " DISTINCTROW " ,
2012-10-18 15:17:21 -04:00
" DISTRIBUTED " , " DIV " , " DOUBLE " , " DROP " , " DUAL " , " DUMMY " , " DUMP " , " EACH " , " ELSE " , " ELSEIF " , " ENCLOSED " , " END " , " ENUM " , " ERRLVL " , " ESCAPE " , " ESCAPED " , " EXCEPT " , " EXEC " , " EXECUTE " , " EXISTS " , " EXIT " , " EXPLAIN " , " FALSE " , " FETCH " , " FILE " , " FILLFACTOR " , " FLOAT " , " FLOAT4 " , " FLOAT8 " , " FOR " , " FORCE " , " FOREIGN " , " FREETEXT " , " FREETEXTTABLE " , " FROM " , " FULL " , " FULLTEXT " , " FUNCTION " , " GENERAL " , " GOTO " , " GRANT " , " GROUP " , " HAVING " , " HIGH_PRIORITY " , " HOLDLOCK " , " HOUR_MICROSECOND " , " HOUR_MINUTE " , " HOUR_SECOND " , " IDENTITY " , " IDENTITYCOL " , " IDENTITY_INSERT " , " IF " , " IGNORE " , " IGNORE_SERVER_IDS " , " IN " , " INDEX " , " INFILE " , " INNER " , " INOUT " , " INSENSITIVE " , " INSERT " , " INT " , " INT1 " , " INT2 " , " INT3 " , " INT4 " , " INT8 " , " INTEGER " , " INTERSECT " , " INTERVAL " , " INTO " , " IS " , " ITERATE " , " JOIN " , " KEY " , " KEYS " , " KILL " , " LEADING " , " LEAVE " , " LEFT " , " LIKE " , " LIMIT " , " LINEAR " , " LINENO " , " LINES " ,
" LOAD " , " LOCALTIME " , " LOCALTIMESTAMP " , " LOCK " , " LONG " , " LONGBLOB " , " LONGTEXT " , " LOOP " , " LOW_PRIORITY " , " MASTER_HEARTBEAT_PERIOD " , " MASTER_SSL_VERIFY_SERVER_CERT " , " MATCH " , " MAXVALUE " , " MEDIUMBLOB " , " MEDIUMINT " , " MEDIUMTEXT " , " MIDDLEINT " , " MINUTE_MICROSECOND " , " MINUTE_SECOND " , " MOD " , " MODIFIES " , " NATIONAL " , " NATURAL " , " NO " , " NOCHECK " , " NONCLUSTERED " , " NOT " , " NO_WRITE_TO_BINLOG " , " NULL " , " NULLIF " , " NUMERIC " , " OF " , " OFF " , " OFFSETS " , " ON " , " OPEN " , " OPENDATASOURCE " , " OPENQUERY " , " OPENROWSET " , " OPENXML " , " OPTIMIZE " , " OPTION " , " OPTIONALLY " , " OR " , " ORDER " , " OUT " , " OUTER " , " OUTFILE " , " OVER " , " PERCENT " , " PLAN " , " PRECISION " , " PRIMARY " , " PRINT " , " PROC " , " PROCEDURE " , " PUBLIC " , " PURGE " , " RAISERROR " , " RANGE " , " READ " , " READS " , " READTEXT " , " READ_WRITE " , " REAL " , " RECONFIGURE " , " REFERENCES " , " REGEXP " , " RELEASE " , " RENAME " , " REPEAT " , " REPLACE " ,
" REPLICATION " , " REQUIRE " , " RESIGNAL " , " RESTORE " , " RESTRICT " , " RETURN " , " REVOKE " , " RIGHT " , " RLIKE " , " ROLLBACK " , " ROWCOUNT " , " ROWGUIDCOL " , " RULE " , " SAVE " , " SCHEMA " , " SCHEMAS " , " SECOND_MICROSECOND " , " SELECT " , " SENSITIVE " , " SEPARATOR " , " SESSION_USER " , " SET " , " SETUSER " , " SHOW " , " SHUTDOWN " , " SIGNAL " , " SLOW " , " SMALLINT " , " SOME " , " SPATIAL " , " SPECIFIC " , " SQL " , " SQLEXCEPTION " , " SQLSTATE " , " SQLWARNING " , " SQL_BIG_RESULT " , " SQL_CALC_FOUND_ROWS " , " SQL_SMALL_RESULT " , " SSL " , " STARTING " , " STATISTICS " , " STRAIGHT_JOIN " , " SYSTEM_USER " , " TABLE " , " TERMINATED " , " TEXT " , " TEXTSIZE " , " THEN " , " TIME " , " TIMESTAMP " , " TINYBLOB " , " TINYINT " , " TINYTEXT " , " TO " , " TOP " , " TRAILING " , " TRAN " , " TRANSACTION " , " TRIGGER " , " TRUE " , " TRUNCATE " , " TSEQUAL " , " UNDO " , " UNION " , " UNIQUE " , " UNLOCK " , " UNSIGNED " , " UPDATE " , " UPDATETEXT " , " USAGE " , " USE " , " USER " , " USING " , " UTC_DATE " , " UTC_TIME " ,
" UTC_TIMESTAMP " , " VALUES " , " VARBINARY " , " VARCHAR " , " VARCHARACTER " , " VARYING " , " VIEW " , " WAITFOR " , " WHEN " , " WHERE " , " WHILE " , " WITH " , " WRITE " , " WRITETEXT " , " XOR " , " YEAR_MONTH " , " ZEROFILL " );
return $reservedWordsSql ;
}
/**
* isPMUnderUpdating , Used to set a file flag to check if PM is upgrading .
*
* @ setFlag Contains the flag to set or unset the temporary file :
* 0 to delete the temporary file flag
* 1 to set the temporary file flag .
* 2 or bigger to check if the temporary file exists .
2016-07-19 13:41:10 -04:00
* @ content Contains the content of the temporary file
* true to all workspace
* nameWorkspace to specific workspace
2012-10-18 15:17:21 -04:00
* return true if the file exists , otherwise false .
*/
2018-01-15 12:00:22 +00:00
public static function isPMUnderUpdating ( $setFlag = 2 , $content = " true " )
2012-10-18 15:17:21 -04:00
{
2012-11-12 13:19:32 -04:00
if ( ! defined ( 'PATH_DATA' )) {
return false ;
}
2018-01-15 12:00:22 +00:00
$fileCheck = PATH_DATA . " UPDATE.dat " ;
2012-10-18 15:17:21 -04:00
if ( $setFlag == 0 ) {
if ( file_exists ( $fileCheck )) {
2017-12-04 13:25:35 +00:00
unlink ( $fileCheck );
2012-10-18 15:17:21 -04:00
}
} elseif ( $setFlag == 1 ) {
2017-12-04 13:25:35 +00:00
$fp = fopen ( $fileCheck , 'w' );
$line = fputs ( $fp , $content );
2012-10-18 15:17:21 -04:00
}
//checking temporary file
if ( $setFlag >= 1 ) {
if ( file_exists ( $fileCheck )) {
2016-07-19 13:41:10 -04:00
$res [ 'action' ] = true ;
$fp = fopen ( $fileCheck , " r " );
$res [ 'workspace' ] = fread ( $fp , filesize ( $fileCheck ));
fclose ( $fp );
return $res ;
2012-10-18 15:17:21 -04:00
}
}
return false ;
}
BUG 10087 "PM functions y Web Services de ProcessMaker no..." SOLVED
- Problem with the variable $_SESSION
- The variable $_SESSION should not lose the default values ..set
- Added functions to save and restore the values ..of the variable $_SESSION
- Revised class.pmFunctions.php functions and class.wsBase.php
- The QA team should test this functions (most of these functions running
triggers, try running triggers):
PMFAddInputDocument
PMFGenerateOutputDocument
PMFDerivateCase, WSDerivateCase, wsBase::derivateCase
PMFNewCase, WSNewCase, wsBase::newCase
PMFRedirectToStep
PMFDeleteCase, WSDeleteCase, wsBase::deleteCase
PMFCancelCase, WSCancelCase, wsBase::cancelCase
PMFPauseCase, WSPauseCase, wsBase::pauseCase
PMFUnpauseCase, WSUnpauseCase, wsBase::unpauseCase
wsBase::executeTrigger
wsBase::reassignCase
* Available from version 2.0.46
2012-11-29 17:04:31 -04:00
/**
* Save the $_SESSION variables into $sessionVar array , to unset them temporary .
*
*/
public function sessionVarSave ()
{
//Unset any variable
$this -> sessionVar = array ();
if ( isset ( $_SESSION [ " APPLICATION " ])) {
$this -> sessionVar [ " APPLICATION " ] = $_SESSION [ " APPLICATION " ];
}
if ( isset ( $_SESSION [ " INDEX " ])) {
$this -> sessionVar [ " INDEX " ] = $_SESSION [ " INDEX " ];
}
if ( isset ( $_SESSION [ " PROCESS " ])) {
$this -> sessionVar [ " PROCESS " ] = $_SESSION [ " PROCESS " ];
}
if ( isset ( $_SESSION [ " TASK " ])) {
$this -> sessionVar [ " TASK " ] = $_SESSION [ " TASK " ];
}
if ( isset ( $_SESSION [ " USER_LOGGED " ])) {
$this -> sessionVar [ " USER_LOGGED " ] = $_SESSION [ " USER_LOGGED " ];
}
if ( isset ( $_SESSION [ " USR_USERNAME " ])) {
$this -> sessionVar [ " USR_USERNAME " ] = $_SESSION [ " USR_USERNAME " ];
}
if ( isset ( $_SESSION [ " STEP_POSITION " ])) {
$this -> sessionVar [ " STEP_POSITION " ] = $_SESSION [ " STEP_POSITION " ];
}
}
/**
* Restore the session variables with values of $sessionVar array , if this is set .
*
*/
public function sessionVarRestore ()
{
if ( count ( $this -> sessionVar ) > 0 ) {
//Restore original values
unset ( $_SESSION [ " APPLICATION " ]);
unset ( $_SESSION [ " INDEX " ]);
unset ( $_SESSION [ " PROCESS " ]);
unset ( $_SESSION [ " TASK " ]);
unset ( $_SESSION [ " USER_LOGGED " ]);
unset ( $_SESSION [ " USR_USERNAME " ]);
unset ( $_SESSION [ " STEP_POSITION " ]);
if ( isset ( $this -> sessionVar [ " APPLICATION " ])) {
$_SESSION [ " APPLICATION " ] = $this -> sessionVar [ " APPLICATION " ];
}
if ( isset ( $this -> sessionVar [ " INDEX " ])) {
$_SESSION [ " INDEX " ] = $this -> sessionVar [ " INDEX " ];
}
if ( isset ( $this -> sessionVar [ " PROCESS " ])) {
$_SESSION [ " PROCESS " ] = $this -> sessionVar [ " PROCESS " ];
}
if ( isset ( $this -> sessionVar [ " TASK " ])) {
$_SESSION [ " TASK " ] = $this -> sessionVar [ " TASK " ];
}
if ( isset ( $this -> sessionVar [ " USER_LOGGED " ])) {
$_SESSION [ " USER_LOGGED " ] = $this -> sessionVar [ " USER_LOGGED " ];
}
if ( isset ( $this -> sessionVar [ " USR_USERNAME " ])) {
$_SESSION [ " USR_USERNAME " ] = $this -> sessionVar [ " USR_USERNAME " ];
}
if ( isset ( $this -> sessionVar [ " STEP_POSITION " ])) {
$_SESSION [ " STEP_POSITION " ] = $this -> sessionVar [ " STEP_POSITION " ];
}
}
}
2013-04-12 16:48:23 -04:00
2013-04-16 17:11:25 -04:00
public static function browserCacheFilesGetLibraryJs ()
{
$arrayLibrary = array ();
2013-04-25 12:42:30 -04:00
//Translations /js/ext/translation.en.js
2013-06-12 16:58:48 -04:00
//Translations /js/ext/translation.xxx.en.js //xxx is an plugin
$arrayLibrary [ " translation " ] = 1 ; //Not use null
2013-04-25 12:42:30 -04:00
//Translation environment /jscore/labels/en.js
2013-06-12 16:58:48 -04:00
if ( file_exists ( PATH_DATA . " META-INF " . PATH_SEP . " translations.env " )) {
$arrayData = unserialize ( file_get_contents ( PATH_DATA . " META-INF " . PATH_SEP . " translations.env " ));
2013-04-25 12:42:30 -04:00
foreach ( $arrayData as $index1 => $value1 ) {
foreach ( $value1 as $index2 => $value2 ) {
$record = $value2 ;
2013-06-12 16:58:48 -04:00
if ( file_exists ( PATH_CORE . " js " . PATH_SEP . " labels " . PATH_SEP . $record [ " LOCALE " ] . " .js " )) {
$arrayLibrary [ $record [ " LOCALE " ]] = 1 ;
2013-04-25 12:42:30 -04:00
}
}
}
}
//Libraries
2013-04-23 13:16:54 -04:00
$library = G :: json_decode ( file_get_contents ( PATH_HOME . " engine " . PATH_SEP . " bin " . PATH_SEP . " tasks " . PATH_SEP . " libraries.json " ));
2013-04-16 17:11:25 -04:00
foreach ( $library as $index => $value ) {
$lib = $value ;
if ( $lib -> build ) {
if ( substr ( $lib -> build_js_to , - 1 ) != " / " ) {
$lib -> build_js_to = $lib -> build_js_to . " / " ;
}
2013-06-12 16:58:48 -04:00
$arrayLibrary [ $lib -> name ] = 1 ;
2013-04-16 17:11:25 -04:00
}
}
return $arrayLibrary ;
}
2013-04-12 16:48:23 -04:00
public static function browserCacheFilesSetUid ()
{
2013-04-16 17:11:25 -04:00
$uid = G :: generateUniqueID ();
2013-04-12 16:48:23 -04:00
$arrayData = array ();
2013-04-16 17:11:25 -04:00
$arrayData [ " browser_cache_files_uid " ] = $uid ;
2013-04-12 16:48:23 -04:00
G :: update_php_ini ( PATH_CONFIG . " env.ini " , $arrayData );
}
public static function browserCacheFilesGetUid ()
{
2017-08-14 16:13:46 -04:00
$sysConf = System :: getSystemConfiguration ( PATH_CONFIG . " env.ini " );
2013-04-12 16:48:23 -04:00
2018-01-15 12:00:22 +00:00
return ( isset ( $sysConf [ " browser_cache_files_uid " ])) ? $sysConf [ " browser_cache_files_uid " ] : null ;
2013-04-12 16:48:23 -04:00
}
2013-04-16 17:11:25 -04:00
public static function browserCacheFilesUrl ( $url )
2013-04-12 16:48:23 -04:00
{
$browserCacheFilesUid = self :: browserCacheFilesGetUid ();
if ( $browserCacheFilesUid != null ) {
2013-04-16 17:11:25 -04:00
$arrayAux = explode ( " / " , $url );
$n = count ( $arrayAux );
2013-04-12 16:48:23 -04:00
2013-04-16 17:11:25 -04:00
if ( $n > 0 && ! empty ( $arrayAux [ $n - 1 ])) {
2013-04-25 12:42:30 -04:00
$arrayAux = explode ( " ? " , $arrayAux [ $n - 1 ]);
$name = $arrayAux [ 0 ];
2013-04-12 16:48:23 -04:00
2013-04-16 17:11:25 -04:00
if ( preg_match ( " /^(.*) \ .js $ /i " , $name , $arrayMatch )) {
2013-04-25 12:42:30 -04:00
$index = $arrayMatch [ 1 ];
2018-01-15 12:00:22 +00:00
$index = ( preg_match ( " /^translation \ ..* $ / " , $index )) ? " translation " : $index ;
2013-04-25 12:42:30 -04:00
2013-04-16 17:11:25 -04:00
$arrayLibrary = G :: browserCacheFilesGetLibraryJs ();
2013-04-12 16:48:23 -04:00
2013-04-25 12:42:30 -04:00
if ( isset ( $arrayLibrary [ $index ])) {
2013-06-12 16:58:48 -04:00
$url = str_replace ( $name , $arrayMatch [ 1 ] . " . " . $browserCacheFilesUid . " .js " , $url );
2013-04-16 17:11:25 -04:00
}
}
2013-04-12 16:48:23 -04:00
}
}
return $url ;
}
2013-06-18 22:14:40 +00:00
2013-07-01 16:39:09 +00:00
public static function skinGetPathToSrcByVirtualUri ( $option , $sysConf )
2013-06-18 22:14:40 +00:00
{
$path = " " ;
$ereg = " " ;
$strSearch = " " ;
switch ( $option ) {
case " errors " :
$ereg = " /^ \ /errors \ /.* $ / " ;
$strSearch = " /errors/ " ;
break ;
case " update " :
$ereg = " /^ \ /update \ /.* $ / " ;
$strSearch = " /update/ " ;
break ;
}
if ( preg_match ( $ereg , $_SERVER [ " REQUEST_URI " ])) {
$strAux = str_replace ( $strSearch , null , $_SERVER [ " REQUEST_URI " ]);
if ( $strAux != " " ) {
2013-07-01 16:39:09 +00:00
$skin = " base " ; //classic
2013-06-24 20:42:29 +00:00
if ( isset ( $_SESSION [ " currentSkin " ])) {
$skin = $_SESSION [ " currentSkin " ];
} else {
if ( isset ( $sysConf [ " default_skin " ])) {
$skin = $sysConf [ " default_skin " ];
}
}
2013-06-18 22:14:40 +00:00
$arrayAux = explode ( " ? " , $strAux );
$fileTemplate = $arrayAux [ 0 ];
2013-06-24 20:42:29 +00:00
if ( file_exists ( PATH_SKIN_ENGINE . " base " . PATH_SEP . $fileTemplate )) {
$path = PATH_SKIN_ENGINE . " base " . PATH_SEP ;
}
if ( file_exists ( PATH_SKIN_ENGINE . $skin . PATH_SEP . $fileTemplate )) {
$path = PATH_SKIN_ENGINE . $skin . PATH_SEP ;
2013-06-18 22:14:40 +00:00
}
2013-06-24 20:42:29 +00:00
if ( file_exists ( PATH_SKINS . $skin . PATH_SEP . $fileTemplate )) {
$path = PATH_SKINS . $skin . PATH_SEP ;
2013-06-18 22:14:40 +00:00
}
2013-06-24 20:42:29 +00:00
if ( file_exists ( PATH_CUSTOM_SKINS . $skin . PATH_SEP . $fileTemplate )) {
$path = PATH_CUSTOM_SKINS . $skin . PATH_SEP ;
2013-06-18 22:14:40 +00:00
}
}
}
return $path ;
}
2013-10-30 20:01:43 -04:00
2018-01-25 20:32:51 +00:00
public static function isUserFunction ( $functionName )
2017-12-04 13:25:35 +00:00
{
2013-10-30 20:01:43 -04:00
$allFunctions = get_defined_functions ();
if ( ! isset ( $allFunctions [ 'user' ])) {
$allFunctions [ 'user' ] = array ();
}
2014-05-16 16:58:10 -04:00
$allFunctions [ 'user' ][] = 'sort' ;
2013-10-30 20:01:43 -04:00
return in_array ( strtolower ( $functionName ), $allFunctions [ 'user' ]);
}
2013-11-15 15:29:07 -04:00
2013-12-23 17:14:04 -04:00
/**
2013-11-15 15:29:07 -04:00
* Constructor for inputFilter class . Only first parameter is required .
* @ access constructor
* @ data Mixed - input string / array - of - string to be 'cleaned'
* @ param Array $tagsArray - list of user - defined tags
* @ param Array $attrArray - list of user - defined attributes
* @ param int $tagsMethod - 0 = allow just user - defined , 1 = allow all but user - defined
* @ param int $attrMethod - 0 = allow just user - defined , 1 = allow all but user - defined
* @ param int $xssAuto - 0 = only auto clean essentials , 1 = allow clean blacklisted tags / attr
*/
2018-01-25 20:32:51 +00:00
public static function sanitizeInput ( $data , $tagsArray = array (), $attrArray = array (), $tagsMethod = 0 , $attrMethod = 0 , $xssAuto = 1 )
2013-11-15 15:29:07 -04:00
{
2017-12-04 13:25:35 +00:00
$filtro = new InputFilter ( $tagsArray , $attrArray , $tagsMethod , $attrMethod , $xssAuto );
2013-11-15 15:29:07 -04:00
return $filtro -> process ( $data );
}
2013-12-23 17:14:04 -04:00
2013-11-22 17:05:10 -04:00
/**
2013-12-23 17:14:04 -04:00
* Stores a message in the log file , if the file size exceeds
2013-11-22 17:05:10 -04:00
* specified log file is renamed and a new one is created .
2013-12-23 17:14:04 -04:00
*
2013-11-22 17:05:10 -04:00
* @ param type $message
* @ param type $pathData
* @ param type $file
*/
2014-10-13 16:33:39 -04:00
public static function log ( $message , $pathData = PATH_DATA , $file = 'cron.log' )
2013-11-22 17:05:10 -04:00
{
2017-08-14 16:13:46 -04:00
$config = System :: getSystemConfiguration ();
2017-08-02 16:06:56 -04:00
2013-12-23 17:14:04 -04:00
2014-10-13 16:33:39 -04:00
$oLogger = Logger :: getSingleton ( $pathData , PATH_SEP , $file );
2013-12-23 17:14:04 -04:00
$oLogger -> limitFile = $config [ 'number_log_file' ];
2013-11-22 17:05:10 -04:00
$oLogger -> limitSize = $config [ 'size_log_file' ];
$oLogger -> write ( $message );
}
2013-12-23 17:14:04 -04:00
2014-10-07 15:58:46 -04:00
/**
2017-08-08 09:53:00 -04:00
* This function save history about some actions in the file audit . log
* The data is used in the Audit Log functionality
*
* @ param string $actionToLog
* @ param string $valueToLog
* @ return void
2017-08-02 16:06:56 -04:00
*/
2014-10-13 15:13:34 -04:00
public static function auditLog ( $actionToLog , $valueToLog = " " )
{
2016-08-18 12:21:29 -04:00
$conf = new Configurations ();
2018-01-15 12:00:22 +00:00
$flag = $conf -> getConfiguration ( 'AUDIT_LOG' , 'log' );
$flagAudit = $flag == 'true' ? true : false ;
2015-05-22 11:35:51 -04:00
/*----------------------------------********---------------------------------*/
2016-08-18 12:21:29 -04:00
$licensedFeatures = PMLicensedFeatures :: getSingleton ();
2018-01-15 12:00:22 +00:00
if ( $flagAudit && $licensedFeatures -> verifyfeature ( 'vtSeHNhT0JnSmo1bTluUVlTYUxUbUFSVStEeXVqc1pEUG5EeXc0MGd2Q3ErYz0=' )) {
$userUid = 'Unknow User' ;
$fullName = '-' ;
2017-08-08 09:53:00 -04:00
if ( isset ( $_SESSION [ 'USER_LOGGED' ]) && $_SESSION [ 'USER_LOGGED' ] != '' ) {
$userUid = $_SESSION [ 'USER_LOGGED' ];
} else {
2018-01-15 12:00:22 +00:00
$userUid = Server :: getUserId ();
2017-08-08 09:53:00 -04:00
if ( ! empty ( $userUid )) {
2018-01-15 12:00:22 +00:00
$users = new Users ();
$user = $users -> loadDetails ( $userUid );
2017-08-08 09:53:00 -04:00
$fullName = $user [ 'USR_FULLNAME' ];
}
}
2018-01-15 12:00:22 +00:00
$fullName = empty ( $_SESSION [ 'USR_FULLNAME' ]) ? $fullName : $_SESSION [ 'USR_FULLNAME' ];
$auditLog = new AuditLog ();
$auditLog -> setUserLogged ( $userUid );
$auditLog -> setUserFullname ( $fullName );
$auditLog -> register ( $actionToLog , $valueToLog );
2014-10-13 15:13:34 -04:00
}
2015-05-22 11:35:51 -04:00
/*----------------------------------********---------------------------------*/
2014-10-07 15:58:46 -04:00
}
2013-12-23 17:14:04 -04:00
/**
* Changes all keys in an array and sub - arrays
*
* @ param array $arrayData The array to work on
* @ param int $case Either CASE_UPPER or CASE_LOWER ( default )
*
* return array Returns an array with its keys lower or uppercased , or false if $arrayData is not an array
*/
public static function array_change_key_case2 ( $arrayData , $case = CASE_LOWER )
{
$arrayData = array_change_key_case ( $arrayData , $case );
foreach ( $arrayData as $key => $value ) {
if ( is_array ( $value )) {
$arrayData [ $key ] = self :: array_change_key_case2 ( $value , $case );
}
}
return $arrayData ;
}
2014-04-30 02:59:55 -04:00
2017-12-04 13:25:35 +00:00
public static function buildFrom ( $configuration , $from = '' )
{
2014-04-30 09:59:09 -04:00
if ( ! isset ( $configuration [ 'MESS_FROM_NAME' ])) {
$configuration [ 'MESS_FROM_NAME' ] = '' ;
}
if ( ! isset ( $configuration [ 'MESS_FROM_MAIL' ])) {
$configuration [ 'MESS_FROM_MAIL' ] = '' ;
}
2014-04-30 02:59:55 -04:00
if ( $from != '' ) {
if ( ! preg_match ( '/(.+)@(.+)\.(.+)/' , $from , $match )) {
if ( $configuration [ 'MESS_FROM_MAIL' ] != '' ) {
$from .= ' <' . $configuration [ 'MESS_FROM_MAIL' ] . '>' ;
2017-12-04 13:25:35 +00:00
} elseif ( $configuration [ 'MESS_ENGINE' ] == 'PHPMAILER' && preg_match ( '/(.+)@(.+)\.(.+)/' , $configuration [ 'MESS_ACCOUNT' ], $match )) {
2014-04-30 02:59:55 -04:00
$from .= ' <' . $configuration [ 'MESS_ACCOUNT' ] . '>' ;
} else {
2018-10-19 17:01:49 -04:00
$from .= ' <info@' . System :: getDefaultMailDomain () . '>' ;
2014-04-30 02:59:55 -04:00
}
}
} else {
if ( $configuration [ 'MESS_FROM_NAME' ] != '' && $configuration [ 'MESS_FROM_MAIL' ] != '' ) {
$from = $configuration [ 'MESS_FROM_NAME' ] . ' <' . $configuration [ 'MESS_FROM_MAIL' ] . '>' ;
2017-12-04 13:25:35 +00:00
} elseif ( $configuration [ 'MESS_FROM_NAME' ] != '' && $configuration [ 'MESS_ENGINE' ] == 'PHPMAILER' && preg_match ( '/(.+)@(.+)\.(.+)/' , $configuration [ 'MESS_ACCOUNT' ], $match )) {
2014-04-30 02:59:55 -04:00
$from = $configuration [ 'MESS_FROM_NAME' ] . ' <' . $configuration [ 'MESS_ACCOUNT' ] . '>' ;
2017-12-04 13:25:35 +00:00
} elseif ( $configuration [ 'MESS_FROM_NAME' ] != '' ) {
2018-10-19 17:01:49 -04:00
$from = $configuration [ 'MESS_FROM_NAME' ] . ' <info@' . System :: getDefaultMailDomain () . '>' ;
2017-12-04 13:25:35 +00:00
} elseif ( $configuration [ 'MESS_FROM_MAIL' ] != '' ) {
2014-04-30 02:59:55 -04:00
$from = $configuration [ 'MESS_FROM_MAIL' ];
2017-12-04 13:25:35 +00:00
} elseif ( $configuration [ 'MESS_ENGINE' ] == 'PHPMAILER' && preg_match ( '/(.+)@(.+)\.(.+)/' , $configuration [ 'MESS_ACCOUNT' ], $match )) {
2014-04-30 02:59:55 -04:00
$from = $configuration [ 'MESS_ACCOUNT' ];
2017-12-04 13:25:35 +00:00
} elseif ( $configuration [ 'MESS_ENGINE' ] == 'PHPMAILER' && $configuration [ 'MESS_ACCOUNT' ] != '' && ! preg_match ( '/(.+)@(.+)\.(.+)/' , $configuration [ 'MESS_ACCOUNT' ], $match )) {
2018-10-19 17:01:49 -04:00
$from = $configuration [ 'MESS_ACCOUNT' ] . ' <info@' . System :: getDefaultMailDomain () . '>' ;
2014-04-30 02:59:55 -04:00
} else {
2018-10-19 17:01:49 -04:00
$from = 'info@' . System :: getDefaultMailDomain ();
2014-04-30 02:59:55 -04:00
}
}
return $from ;
}
2014-08-29 15:17:43 -04:00
2017-12-04 13:25:35 +00:00
public function getRealExtension ( $extensionInpDoc )
{
2014-10-29 13:40:17 -04:00
$aux = explode ( '.' , strtolower ( $extensionInpDoc ));
return isset ( $aux [ 1 ]) ? $aux [ 1 ] : '' ;
}
2017-12-04 13:25:35 +00:00
/**
* Verify the InputDoc extension , cheking the file name extension ( . pdf , . ppt ) and the file content .
*
*
*
*/
2018-01-25 20:32:51 +00:00
public static function verifyInputDocExtension ( $InpDocAllowedFiles , $fileName , $filesTmpName )
2014-10-21 15:35:39 -04:00
{
2018-08-28 09:34:11 -04:00
$error = null ;
2018-12-13 14:42:05 -04:00
ValidationUploadedFiles :: getValidationUploadedFiles () -> dispatch ( function ( $validator ) use ( & $error ) {
2018-08-28 09:34:11 -04:00
$error = new stdclass ();
$error -> status = false ;
$error -> message = $validator -> getMessage ();
});
if ( ! is_null ( $error )) {
return $error ;
}
2014-10-29 13:40:17 -04:00
// Initialize variables
2014-10-21 15:35:39 -04:00
$res = new stdclass ();
2016-08-24 15:42:39 -04:00
$res -> status = false ;
2015-08-18 12:19:41 -04:00
$allowedTypes = array_map ( 'G::getRealExtension' , explode ( ',' , $InpDocAllowedFiles ));
2014-10-29 13:40:17 -04:00
2017-02-08 16:01:52 -04:00
// Get the file extension
$aux = pathinfo ( $fileName );
$fileExtension = isset ( $aux [ 'extension' ]) ? strtolower ( $aux [ 'extension' ]) : '' ;
2014-10-29 13:40:17 -04:00
// If required extension is *.* don't validate
if ( in_array ( '*' , $allowedTypes )) {
$res -> status = true ;
return $res ;
}
2014-10-21 15:35:39 -04:00
2014-10-29 13:40:17 -04:00
// If no valid extension finish (unnecesary check file content)
$validExtension = in_array ( $fileExtension , $allowedTypes );
if ( ! $validExtension ) {
$res -> status = false ;
2017-12-04 13:25:35 +00:00
$res -> message = G :: LoadTranslation ( 'ID_UPLOAD_ERR_NOT_ALLOWED_EXTENSION' ) . ' ' . $fileName ;
2014-10-29 13:40:17 -04:00
return $res ;
}
// If not enabled fileinfo extension finish validation
2014-10-21 15:35:39 -04:00
if ( ! extension_loaded ( 'fileinfo' )) {
2014-10-29 13:40:17 -04:00
$res -> status = true ;
return $res ;
}
// If enabled fileinfo extension check the content
$finfo = new finfo ( FILEINFO_MIME_TYPE );
2017-12-04 13:25:35 +00:00
$mimeType = $finfo -> file ( $filesTmpName );
2014-10-29 13:40:17 -04:00
$docType = explode ( '/' , $mimeType );
2014-10-21 15:35:39 -04:00
2014-10-29 13:40:17 -04:00
// If is a empty file finish validation
if ( $docType [ 1 ] == 'x-empty' ) {
$res -> status = true ;
return $res ;
}
// Check file content
foreach ( $allowedTypes as $allowedType ) {
switch ( $allowedType ) {
case 'xls' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'vnd.ms-excel' || ( $fileExtension == 'xls' && $docType [ 1 ] == 'plain' )) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'doc' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'msword' || ( $fileExtension == 'doc' && $docType [ 1 ] == 'html' )) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'ppt' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'vnd.ms-office' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'docx' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'vnd.openxmlformats-officedocument.wordprocessingml.document' ) {
$res -> status = true ;
break 2 ;
}
2015-12-03 10:16:21 -04:00
break ;
2014-10-29 13:40:17 -04:00
case 'pptx' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'vnd.openxmlformats-officedocument.presentationml.presentation' ) {
$res -> status = true ;
break 2 ;
}
2015-12-03 10:16:21 -04:00
break ;
2014-10-29 13:40:17 -04:00
case 'xlsx' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'exe' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'x-msdownload' || $docType [ 1 ] == 'x-dosexec' ) {
$res -> status = true ;
break 2 ;
}
2015-12-03 10:16:21 -04:00
break ;
2014-10-29 13:40:17 -04:00
case 'wmv' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'x-ms-asf' || $docType [ 1 ] == 'x-ms-wmv' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'jpg' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'jpeg' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'mp3' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'mpeg' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'rar' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'x-rar' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'txt' :
case 'pm' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'plain' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'htm' :
case 'html' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'html' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'po' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == 'x-po' ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
case 'pdf' :
case 'png' :
case 'jpeg' :
case 'gif' :
case 'zip' :
case 'mp4' :
2016-08-24 15:42:39 -04:00
if ( $docType [ 1 ] == $allowedType ) {
$res -> status = true ;
break 2 ;
}
2014-10-29 13:40:17 -04:00
break ;
default :
2016-08-24 15:42:39 -04:00
$res -> status = $validExtension ;
2014-10-29 13:40:17 -04:00
break ;
2014-10-21 15:35:39 -04:00
}
}
2014-10-29 13:40:17 -04:00
// If content don't match return error
2016-08-24 15:42:39 -04:00
if ( ! $res -> status ) {
2017-12-04 13:25:35 +00:00
$res -> message = G :: LoadTranslation ( 'ID_UPLOAD_ERR_NOT_ALLOWED_EXTENSION' ) . ' ' . $fileName ;
2016-08-24 15:42:39 -04:00
}
2014-10-29 13:40:17 -04:00
return $res ;
2014-08-29 15:17:43 -04:00
}
2014-10-20 17:41:47 -04:00
2014-10-27 13:38:36 -04:00
/**
2018-01-09 10:25:28 -04:00
* Check the browser compatibility
*
* @ param string $browser
* @ param integer $version
*
* @ return boolean
*/
2018-01-25 20:32:51 +00:00
public static function checkBrowserCompatibility ( $browser = null , $version = null )
2018-01-09 10:25:28 -04:00
{
if ( $browser == null || $version == null ) {
$info = G :: getBrowser ();
$browser = $info [ 'name' ];
$version = $info [ 'version' ];
}
if (
(( $browser == 'msie' ) && (( $version >= 8 ) && ( $version <= 11 ))) ||
(( $browser == 'chrome' ) && ( $version >= 26 )) ||
(( $browser == 'firefox' ) && ( $version >= 20 )) ||
(( $browser == 'safari' ) && ( $version >= 10 ))
) {
return true ;
}
return false ;
2014-10-20 17:41:47 -04:00
}
2014-10-21 15:35:39 -04:00
2018-01-09 10:25:28 -04:00
/**
* This function sanitizes the string
*
* @ param string $string , The string to sanitize .
* @ param boolean $lowercase , Force the string to lowercase
* @ param boolean $alpha , If set to * true * , will remove all non - alphanumeric characters .
*
* @ return string
*/
2018-01-25 20:32:51 +00:00
public static function sanitizeString ( $string , $lowercase = true , $alpha = false )
2014-10-21 15:35:39 -04:00
{
2017-12-04 13:25:35 +00:00
$strip = array ( " ~ " , " ` " , " ! " , " @ " , " # " , " $ " , " % " , " ^ " , " & " , " * " , " ( " , " ) " , " _ " , " = " , " + " , " [ " , " { " , " ] " ,
2014-10-21 15:35:39 -04:00
" } " , " \\ " , " | " , " ; " , " : " , " \" " , " ' " , " ‘ " , " ’ " , " “ " , " ” " , " – " , " — " ,
2015-04-28 16:10:10 -04:00
" — " , " – " , " , " , " < " , " . " , " > " , " / " , " ? " );
2017-12-04 13:25:35 +00:00
$clean = trim ( str_replace ( $strip , " " , strip_tags ( $string )));
$clean = preg_replace ( '/\s+/' , " - " , $clean );
2018-01-15 12:00:22 +00:00
$clean = ( $alpha ) ? preg_replace ( " /[^a-zA-Z0-9]/ " , " " , $clean ) : $clean ;
2017-12-04 13:25:35 +00:00
$clean = ( $lowercase ) ? ( function_exists ( 'mb_strtolower' )) ? mb_strtolower ( $clean , 'UTF-8' ) : strtolower ( $clean ) : $clean ;
return $clean ;
}
2018-01-15 12:00:22 +00:00
2017-12-04 13:25:35 +00:00
/**
* Out the result
*
* @ param string $sVar
*
* @ return showRes ( $string )
*/
public static function outRes ( $sInfVar )
2016-07-27 16:37:21 -04:00
{
echo $sInfVar ;
}
2018-01-15 12:00:22 +00:00
2017-12-04 13:25:35 +00:00
/**
* encryptOld
*
* @ param string $string
*
* @ return md5 ( $string )
*/
HOR-1293 "Create PMFunction to Send Message to Group PMFSendMessageToGroup" SOLVED
Issue:
Create PMFunction to Send Message to Group PMFSendMessageToGroup
Cause:
Nuevo requerimiento de funcion
Solution:
Se a implementado la nueva funcion:
function PMFSendMessageToGroup(
$groupId,
$caseId,
$from,
$subject,
$template,
$arrayField = [],
$arrayAttachment = [],
$showMessage = true,
$delIndex = 0,
$config = [],
$limit = 100
)
2016-07-21 10:07:00 -04:00
public static function encryptOld ( $string )
2015-03-25 15:56:21 -04:00
{
2016-08-04 14:56:58 -04:00
$consthashFx = self :: hashFx ;
return $consthashFx ( $string );
2015-03-25 15:56:21 -04:00
}
2018-01-15 12:00:22 +00:00
2016-09-01 15:43:01 -04:00
/**
* encryptSha
*
* @ param string $string
*
* @ return sha256 ( $string )
*/
public static function encryptHash ( $string )
{
$consthash = self :: hash ;
return $consthash ( 'sha256' , $string );
}
2018-01-15 12:00:22 +00:00
2015-03-25 15:56:21 -04:00
/**
2015-04-21 12:03:52 -04:00
* encryptFileOld
*
* @ param string $string
*
* @ return md5_file ( $string )
*/
2018-01-25 20:32:51 +00:00
public static function encryptFileOld ( $string )
2015-04-21 12:03:52 -04:00
{
2016-08-04 14:56:58 -04:00
$consthashFx = self :: hashFile ;
return $consthashFx ( $string );
2015-04-21 12:03:52 -04:00
}
2018-01-15 12:00:22 +00:00
2015-04-21 12:03:52 -04:00
/**
2015-03-25 15:56:21 -04:00
* crc32
*
* @ param string $string
*
* @ return crc32 ( $string )
*/
2017-12-04 13:25:35 +00:00
public static function encryptCrc32 ( $string )
2015-03-25 15:56:21 -04:00
{
2016-08-04 14:56:58 -04:00
$consthashFx = self :: hashCrc ;
return $consthashFx ( $string );
2016-04-25 10:59:21 -04:00
}
/**
* this function get the Message
* @ access public
* @ param string $e
* @ return string
*
*/
public static function getErrorMessage ( $e )
{
return $e -> getMessage ();
2017-04-19 11:30:54 -04:00
}
/**
2017-08-04 08:11:58 -04:00
* Add log of execution of triggers
* @ param $data
* @ param string $error
* @ param string $typeError
* @ param int $executionTime
2017-04-19 11:30:54 -04:00
*/
2017-08-04 08:11:58 -04:00
public static function logTriggerExecution ( $data , $error = 'NO-ERROR' , $typeError = '' , $executionTime = 0 )
{
if (( ! empty ( $data [ '_CODE_' ]) || $typeError == 'FATAL_ERROR' ) && isset ( $data [ '_DATA_TRIGGER_' ]) &&
! isset ( $data [ '_DATA_TRIGGER_' ][ '_TRI_LOG_' ])
) {
$lg = Bootstrap :: getDefaultContextLog ();
$lg [ 'TRI_TITLE' ] = isset ( $data [ '_DATA_TRIGGER_' ][ 'TRI_TITLE' ]) ? $data [ '_DATA_TRIGGER_' ][ 'TRI_TITLE' ] : '' ;
$lg [ 'TRI_UID' ] = isset ( $data [ '_DATA_TRIGGER_' ][ 'TRI_UID' ]) ? $data [ '_DATA_TRIGGER_' ][ 'TRI_UID' ] : '' ;
$lg [ 'TRI_CODE' ] = isset ( $data [ '_DATA_TRIGGER_' ][ 'TRI_WEBBOT' ]) ? $data [ '_DATA_TRIGGER_' ][ 'TRI_WEBBOT' ] : '' ;
$lg [ 'TRI_EXECUTION_TIME' ] = $executionTime ;
$lg [ 'TRI_MSG_ERROR' ] = $error ;
$lg [ 'APP_UID' ] = isset ( $data [ 'APPLICATION' ]) ? $data [ 'APPLICATION' ] : '' ;
$lg [ 'PRO_UID' ] = isset ( $data [ 'PROCESS' ]) ? $data [ 'PROCESS' ] : '' ;
$lg [ 'TAS_UID' ] = isset ( $data [ 'TASK' ]) ? $data [ 'TASK' ] : '' ;
$lg [ 'USR_UID' ] = isset ( $data [ 'USER_LOGGED' ]) ? $data [ 'USER_LOGGED' ] : '' ;
Bootstrap :: registerMonolog (
( empty ( $sError )) ? 'TriggerExecution' : 'TriggerExecutionError' ,
( empty ( $sError )) ? 200 : 400 ,
( empty ( $sError )) ? 'Trigger Execution' : 'Trigger Execution Error' ,
2017-12-04 13:25:35 +00:00
$lg ,
$lg [ 'workspace' ],
'processmaker.log'
);
2017-08-04 08:11:58 -04:00
$_SESSION [ '_DATA_TRIGGER_' ][ '_TRI_LOG_' ] = true ;
2017-04-19 11:30:54 -04:00
}
2017-08-11 15:11:24 -04:00
}
/**
* Define the Processmaker constants .
*
*/
public static function defineConstants ()
{
//Moved from Enterprise class.
if ( file_exists ( PATH_METHODS . " login/version-pmos.php " )) {
2017-12-04 13:25:35 +00:00
include ( PATH_METHODS . " login/version-pmos.php " );
2017-08-11 15:11:24 -04:00
}
2017-08-11 15:49:39 -04:00
//Removed default version from code.
2019-03-07 16:02:13 -04:00
2017-08-16 16:15:08 -04:00
/**
* The constants defined comes from the file :
* processmaker / workflow / engine / classes / class . plugin . php , the loading of this
* file is not done by 'require' in this version of ProcessMaker . Therefore ,
* these definitions have been moved to this class .
*/
define ( 'G_PLUGIN_CLASS' , 1 );
define ( 'PM_CREATE_CASE' , 1001 );
define ( 'PM_UPLOAD_DOCUMENT' , 1002 );
define ( 'PM_CASE_DOCUMENT_LIST' , 1003 );
define ( 'PM_BROWSE_CASE' , 1004 );
define ( 'PM_NEW_PROCESS_LIST' , 1005 );
define ( 'PM_NEW_PROCESS_SAVE' , 1006 );
define ( 'PM_NEW_DYNAFORM_LIST' , 1007 );
define ( 'PM_NEW_DYNAFORM_SAVE' , 1008 );
define ( 'PM_EXTERNAL_STEP' , 1009 );
define ( 'PM_CASE_DOCUMENT_LIST_ARR' , 1010 );
define ( 'PM_LOGIN' , 1011 );
define ( 'PM_UPLOAD_DOCUMENT_BEFORE' , 1012 );
define ( 'PM_CREATE_NEW_DELEGATION' , 1013 );
define ( 'PM_SINGLE_SIGN_ON' , 1014 );
define ( 'PM_GET_CASES_AJAX_LISTENER' , 1015 );
define ( 'PM_BEFORE_CREATE_USER' , 1016 );
define ( 'PM_AFTER_LOGIN' , 1017 );
define ( 'PM_HASH_PASSWORD' , 1018 );
define ( 'PM_SCHEDULER_CREATE_CASE_BEFORE' , 1019 );
define ( 'PM_SCHEDULER_CREATE_CASE_AFTER' , 1020 );
2015-03-25 15:56:21 -04:00
}
2012-10-18 15:17:21 -04:00
2017-08-17 17:19:43 -04:00
/**
* Instanciate an adapter by name .
*
2017-08-17 18:24:05 -04:00
* @ param string $name Adapter name or class name : P
2017-12-04 13:25:35 +00:00
*
2017-08-17 17:19:43 -04:00
* @ param string [] $parameters Constructor parameters
*/
public static function factory ( $name , ... $parameters )
{
$key = strtolower ( $name );
$class = isset ( self :: $adapters [ $key ]) ? self :: $adapters [ $key ] : $name ;
$rc = new ReflectionClass ( $class );
return $rc -> newInstanceArgs ( $parameters );
2012-10-18 15:17:21 -04:00
}
2017-08-17 18:24:05 -04:00
/**
* Return current class
*
* @ param $name string name class
* @ return string name of class
*/
public static function nameClass ( $name )
{
$key = strtolower ( $name );
return isset ( self :: $adapters [ $key ]) ? self :: $adapters [ $key ] : $name ;
}
/**
* Verify class exists
*
* @ param $name
* @ return bool true or false
*/
public static function classExists ( $name )
{
$key = strtolower ( $name );
$class = isset ( self :: $adapters [ $key ]) ? self :: $adapters [ $key ] : $name ;
return class_exists ( $class );
}
2019-01-03 14:22:58 -04:00
/**
* Fix string corrupted related to PMC - 336.
* To do , this method should be removed . Related to PMC - 336.
2019-03-07 16:02:13 -04:00
*
2019-01-03 14:22:58 -04:00
* @ param string $string
* @ return string
*/
public static function fixStringCorrupted ( $string )
{
$string = preg_replace_callback ( " /iconv \\ ( \\ 'UCS \\ -4LE \\ ', \\ 'UTF \\ -8 \\ ',pack \\ ( \\ 'V \\ ', hexdec \\ ( \\ 'U[a-f0-9] { 4} \\ ' \\ ) \\ ) \\ )/ " , function ( $result ) {
//This looks for the following pattern:
//iconv('UCS-4LE','UTF-8',pack('V', hexdec('U062f')))iconv('UCS-4LE','UTF-8',pack('V', hexdec('U0631')))
//So making this replacement is safe.
$portion = $result [ 0 ];
$portion = str_replace ( " iconv('UCS-4LE','UTF-8',pack('V', hexdec('U " , " \ u " , $portion );
$portion = str_replace ( " '))) " , " " , $portion );
return $portion ;
}, $string );
return $string ;
}
2012-10-18 15:17:21 -04:00
}